feat: 保存数据前将表中的版本设置为历史版本
This commit is contained in:
parent
1a0caf4017
commit
e3a25f1ddc
|
|
@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import nflg.product.common.constant.STATE;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -92,8 +93,10 @@ public class DQBomImportService {
|
|||
BOMMAP.remove(SessionUtil.getUserCode());
|
||||
}
|
||||
|
||||
private void save(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
||||
checkExceptionStatus(parents, children);
|
||||
dQBomParentService.setLastVersionIs0(parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList()));
|
||||
dQBomParentService.saveBatch(parents);
|
||||
dQBomChildService.saveBatch(children);
|
||||
}
|
||||
|
|
@ -196,8 +199,12 @@ public class DQBomImportService {
|
|||
|
||||
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(dQBomParentService.lambdaQuery().eq(BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo())
|
||||
.orderByDesc(BomNewDQbomParentEntity::getRowId).list().stream().findFirst().orElse(null)
|
||||
.orElse(dQBomParentService.lambdaQuery()
|
||||
.eq(BomNewDQbomParentEntity::getLastVersionIs, 1)
|
||||
.eq(BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo())
|
||||
.orderByDesc(BomNewDQbomParentEntity::getRowId)
|
||||
.list()
|
||||
.stream().findFirst().orElse(null)
|
||||
);
|
||||
if (parent == null) {
|
||||
parent = new BomNewDQbomParentEntity();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.nflg.product.bomnew.mapper.master.BomNewDQbomParentMapper;
|
|||
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -17,4 +18,11 @@ public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, Bom
|
|||
public List<BomNewDQbomParentEntity> getWorkSheet(String materialNo) {
|
||||
return this.getBaseMapper().getWorkSheet(materialNo);
|
||||
}
|
||||
|
||||
public void setLastVersionIs0(List<String> materialNo) {
|
||||
this.lambdaUpdate().in(BomNewDQbomParentEntity::getMaterialNo, materialNo)
|
||||
.set(BomNewDQbomParentEntity::getLastVersionIs, 0)
|
||||
.set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
package com.nflg.product.bomnew.service.test;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewLogEntity;
|
||||
import com.nflg.product.bomnew.util.BomUtil;
|
||||
import com.nflg.product.bomnew.util.StringUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author 曹鹏飞
|
||||
* @date 2024-03-06 14:24:10
|
||||
|
|
@ -75,4 +80,33 @@ public class OtherTest {
|
|||
String data2="";
|
||||
Assert.assertEquals(data2,StringUtil.trimText(data1,0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test10() {
|
||||
BigDecimal num = BigDecimal.valueOf(1.2);
|
||||
BigDecimal unitWeight = BigDecimal.valueOf(23.5656224);
|
||||
BigDecimal totalWeight = BigDecimal.valueOf(28.27874688);
|
||||
System.out.println("计算结果:" + NumberUtil.mul(num, unitWeight));
|
||||
Assert.assertEquals(totalWeight, num.multiply(unitWeight));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11() {
|
||||
BigDecimal num = BigDecimal.valueOf(3);
|
||||
BigDecimal unitWeight = BigDecimal.valueOf(23.5000);
|
||||
BigDecimal totalWeight = BomUtil.calculateTotalWeight(num, unitWeight);
|
||||
System.out.println("计算结果:" + totalWeight);
|
||||
System.out.println("显示结果:" + BomUtil.totalWeightToDisplay(totalWeight));
|
||||
Assert.assertEquals("70.5", Objects.requireNonNull(BomUtil.totalWeightToDisplay(totalWeight)).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test12() {
|
||||
BigDecimal num = BigDecimal.valueOf(3);
|
||||
BigDecimal unitWeight = BigDecimal.valueOf(23.552560);
|
||||
BigDecimal totalWeight = BomUtil.calculateTotalWeight(num, unitWeight);
|
||||
System.out.println("计算结果:" + totalWeight);
|
||||
System.out.println("显示结果:" + BomUtil.totalWeightToDisplay(totalWeight));
|
||||
Assert.assertEquals("70.6577", Objects.requireNonNull(BomUtil.totalWeightToDisplay(totalWeight)).toString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue