创建Bom最新版本限制

This commit is contained in:
jing's 2024-04-01 22:56:30 +08:00
parent f0b0edf6bf
commit 6c1a7d22a8
2 changed files with 49 additions and 46 deletions

View File

@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference; import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
@ -38,7 +37,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.ttzero.excel.entity.ListSheet; import org.ttzero.excel.entity.ListSheet;
import org.ttzero.excel.entity.Workbook;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -51,6 +49,7 @@ import java.util.*;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask; import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BinaryOperator; import java.util.function.BinaryOperator;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -1592,6 +1591,9 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
} }
/** /**
* 暂存 * 暂存
* <p> * <p>
@ -1621,24 +1623,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
if (eBomEdit.getParentEntity() != null) { if (eBomEdit.getParentEntity() != null) {
//同一物料且存在一个 lastVersionIs=1 eBomEdit.nextVersion();
if(ObjectUtil.isNotNull(eBomEdit.getParentEntity().getLastVersionIs())
&& ObjectUtil.equal(eBomEdit.getParentEntity().getLastVersionIs(),1L)) {
List<BomNewEbomParentEntity> oldParent= this.lambdaQuery()
.eq(BomNewEbomParentEntity::getMaterialNo, eBomEdit.getParentEntity().getMaterialNo())
.eq(BomNewEbomParentEntity::getLastVersionIs,1)
//.ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.ne(BomNewEbomParentEntity::getRowId, eBomEdit.getParentEntity().getRowId())
.list();
if(CollUtil.isNotEmpty(oldParent)){
// oldParent.setLastVersionIs(0);
oldParent.forEach(u->{
u.setLastVersionIs(0);
});
this.updateBatchById(oldParent);
}
}
this.saveOrUpdate(eBomEdit.getParentEntity()); this.saveOrUpdate(eBomEdit.getParentEntity());
} }
@ -1694,24 +1679,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
if (eBomEdit.getParentEntity() != null) { if (eBomEdit.getParentEntity() != null) {
//同一物料且存在一个 lastVersionIs=1 eBomEdit.nextVersion();
if(ObjectUtil.isNotNull(eBomEdit.getParentEntity().getLastVersionIs())
&& ObjectUtil.equal(eBomEdit.getParentEntity().getLastVersionIs(),1L)) {
List<BomNewEbomParentEntity> oldParent= this.lambdaQuery()
.eq(BomNewEbomParentEntity::getMaterialNo, eBomEdit.getParentEntity().getMaterialNo())
.eq(BomNewEbomParentEntity::getLastVersionIs,1)
//.ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.ne(BomNewEbomParentEntity::getRowId, eBomEdit.getParentEntity().getRowId())
.list();
if(CollUtil.isNotEmpty(oldParent)){
// oldParent.setLastVersionIs(0);
oldParent.forEach(u->{
u.setLastVersionIs(0);
});
this.updateBatchById(oldParent);
}
}
this.saveOrUpdate(eBomEdit.getParentEntity()); this.saveOrUpdate(eBomEdit.getParentEntity());

View File

@ -25,6 +25,7 @@ import com.nflg.product.bomnew.service.MaterialMainService;
import com.nflg.product.bomnew.service.UserRoleService; import com.nflg.product.bomnew.service.UserRoleService;
import com.nflg.product.bomnew.util.ListCommonUtil; import com.nflg.product.bomnew.util.ListCommonUtil;
import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VUtils;
import com.nflg.product.bomnew.util.VersionUtil;
import lombok.Getter; import lombok.Getter;
import nflg.product.common.constant.STATE; import nflg.product.common.constant.STATE;
@ -85,18 +86,25 @@ public class EBomEdit {
parent.setModifyTime(LocalDateTime.now()); parent.setModifyTime(LocalDateTime.now());
parent.setExpireEndTime( LocalDateTime.parse("9999-12-31 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") )); parent.setExpireEndTime( LocalDateTime.parse("9999-12-31 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") ));
parent.setRootIs(0);
parent.setUserRootIs(0);
// Integer rootIs =SpringUtil.getBean(BomNewEbomParentService.class).getBaseMapper().checkIsRoot(parent.getMaterialNo());
Integer rootIs =SpringUtil.getBean(BomNewEbomParentService.class).getBaseMapper().checkIsRoot(parent.getMaterialNo()); // Integer userRootIs = SpringUtil.getBean(BomNewEbomParentService.class).getBaseMapper().checkIsUserRoot(parent.getMaterialNo(), parent.getCreatedBy());
Integer userRootIs = SpringUtil.getBean(BomNewEbomParentService.class).getBaseMapper().checkIsUserRoot(parent.getMaterialNo(), parent.getCreatedBy()); // parent.setRootIs(rootIs > 0 ? 0 : 1);
parent.setRootIs(rootIs > 0 ? 0 : 1); // parent.setUserRootIs(userRootIs > 0 ? 0 : 1);
parent.setUserRootIs(userRootIs > 0 ? 0 : 1);
return parent; return parent;
} }
/**
* 如果有定版后才能新建bom
* @param materialNo
*/
void checkHadBom(String materialNo){ void checkHadBom(String materialNo){
QueryWrapper<BomNewEbomParentEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<BomNewEbomParentEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(BomNewEbomParentEntity::getMaterialNo, materialNo); queryWrapper.lambda().eq(BomNewEbomParentEntity::getMaterialNo, materialNo)
.ne(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue());
List<BomNewEbomParentEntity> existBomlist = SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper); List<BomNewEbomParentEntity> existBomlist = SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper);
VUtils.isTure(CollUtil.isNotEmpty(existBomlist)).throwMessage(materialNo+"该物料已存在BOM"); VUtils.isTure(CollUtil.isNotEmpty(existBomlist)).throwMessage(materialNo+"该物料已存在BOM");
} }
@ -107,7 +115,7 @@ public class EBomEdit {
void createRootBom(BomNewEBomParentEditDTO createDTO) { void createRootBom(BomNewEBomParentEditDTO createDTO) {
// checkHadBom(createDTO.getParent().getMaterialNo()); checkHadBom(createDTO.getParent().getMaterialNo());
parentEntity = createParentBomInfo(createDTO.getParent()); parentEntity = createParentBomInfo(createDTO.getParent());
parentEntity.setEditStatus(createDTO.getOpType()); parentEntity.setEditStatus(createDTO.getOpType());
@ -291,7 +299,7 @@ public class EBomEdit {
//缺bom //缺bom
if (dto.getParent().getBomRowId() == null || dto.getParent().getBomRowId().longValue() == 0) { if (dto.getParent().getBomRowId() == null || dto.getParent().getBomRowId().longValue() == 0) {
// checkHadBom(dto.getParent().getMaterialNo()); checkHadBom(dto.getParent().getMaterialNo());
dto.getParent().setBomRowId(dto.getParent().getRowId()); dto.getParent().setBomRowId(dto.getParent().getRowId());
parentEntity = createParentBomInfo(dto.getParent()); parentEntity = createParentBomInfo(dto.getParent());
@ -317,6 +325,33 @@ public class EBomEdit {
} }
public void nextVersion(){
//同一物料且存在一个 lastVersionIs=1
if(ObjectUtil.isNotNull(getParentEntity().getLastVersionIs())
&& ObjectUtil.equal(getParentEntity().getLastVersionIs(),1)) {
QueryWrapper<BomNewEbomParentEntity> queryWrapper=new QueryWrapper<>();
queryWrapper.lambda()
.eq(BomNewEbomParentEntity::getMaterialNo, getParentEntity().getMaterialNo())
.eq(BomNewEbomParentEntity::getLastVersionIs,1)
// .eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.orderByDesc(BomNewEbomParentEntity::getCurrentVersion);
List<BomNewEbomParentEntity> oldParent=SpringUtil.getBean(BomNewEbomParentService.class).list(queryWrapper);
if(CollUtil.isNotEmpty(oldParent)){
// oldParent.setLastVersionIs(0);
BomNewEbomParentEntity lastParent=oldParent.get(0);
for (BomNewEbomParentEntity u:
oldParent) {
u.setLastVersionIs(0);
lastParent=u;
}
getParentEntity().setCurrentVersion(VersionUtil.getNextVersion(lastParent.getCurrentVersion()));
SpringUtil.getBean(BomNewEbomParentService.class).updateBatchById(oldParent);
}
}
}
/** /**
* 废弃 * 废弃
* @param dto * @param dto