Merge remote-tracking branch 'origin/feature/DM/nflg-bom-transition' into feature/DM/nflg-bom-transition
This commit is contained in:
commit
bc4a83b0f4
|
|
@ -1,25 +1,26 @@
|
|||
package com.nflg.product.bomnew.api.user;
|
||||
|
||||
import com.mzt.logapi.context.LogRecordContext;
|
||||
import com.mzt.logapi.starter.annotation.LogRecord;
|
||||
import com.nflg.product.base.core.api.BaseApi;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.OriginalStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomChildMapper;
|
||||
import com.nflg.product.bomnew.pojo.vo.ImportOriginalBomVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
||||
import com.nflg.product.bomnew.service.BomNewEbomParentService;
|
||||
import com.nflg.product.bomnew.service.BomNewOriginalParentService;
|
||||
import com.nflg.product.bomnew.service.BomNewOriginalParentV2Service;
|
||||
import com.nflg.product.bomnew.service.EBomImportService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
||||
|
|
@ -42,6 +43,8 @@ public class EbomV2Api extends BaseApi {
|
|||
BomNewOriginalParentService originalParentService;
|
||||
@Resource
|
||||
BomNewEbomParentService ebomParentService;
|
||||
@Resource
|
||||
EBomImportService eBomImportService;
|
||||
|
||||
|
||||
@GetMapping("pullFromCadAndToEBom")
|
||||
|
|
@ -63,4 +66,23 @@ public class EbomV2Api extends BaseApi {
|
|||
return ResultVO.success(result);
|
||||
}
|
||||
|
||||
@ApiOperation("导入")
|
||||
@PostMapping("importBom")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(success = "原始BOM-导入:文件名:{{#fileNme}},操作结果:{{#_ret}}",
|
||||
bizNo = "", type = "原始BOM导入")
|
||||
public ResultVO<List<OperationErrorMsgVO>> importBom(@RequestParam(value = "file") MultipartFile file) throws IOException {
|
||||
if (file != null && !file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) {
|
||||
return ResultVO.error("请上传Excel文件");
|
||||
}
|
||||
LogRecordContext.putVariable("fileNme", file.getOriginalFilename());
|
||||
List<OperationErrorMsgVO> result = eBomImportService.importBom(file);
|
||||
|
||||
//计算层级
|
||||
originalParentService.computeLevelNumAndRootState();
|
||||
|
||||
//更新物料使用
|
||||
originalParentService.getBaseMapper().upOriginalMaterialUse();
|
||||
return ResultVO.success(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.nflg.product.bomnew.mapper.master;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.ChildMaxExceptionStateVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
|
@ -24,4 +25,10 @@ public interface BomNewEbomChildMapper extends BaseMapper<BomNewEbomChildEntity>
|
|||
void updateEBomMaterialUse();
|
||||
|
||||
List<ChildMaxExceptionStateVO> getChildMaxExceptionState(@Param("bomRowIds") List<Long> bomRowIds);
|
||||
|
||||
Integer shouldSetRootIs(String materialNo);
|
||||
|
||||
List<BomNewEbomParentVO> getBom(Long parentRowId, String materialNo);
|
||||
|
||||
void deleteAllChildren(Long rowId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public interface BomNewEbomParentMapper extends BaseMapper<BomNewEbomParentEntit
|
|||
* @param query
|
||||
* @return
|
||||
*/
|
||||
Page<BomNewEbomParentVO> formalWorksheet(Page<BomNewEbomParentVO> page, @Param("query") BomNewEbomParentQuery query);
|
||||
Page<BomNewEbomParentVO> formalWorksheet(Page<BomNewEbomParentVO> page, @Param("query") BomNewEbomParentQuery query, String userCode);
|
||||
|
||||
Page<BomNewEbomUpgradeChangeVO> getUpgradeChangeList(Page<BomNewEbomUpgradeChangeVO> page, @Param("query") BomNewEbomParentQuery query);
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
package com.nflg.product.bomnew.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.ttzero.excel.annotation.ExcelColumn;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author 曹鹏飞
|
||||
* @date 2024/5/8 09:07:23
|
||||
*/
|
||||
@Data
|
||||
public class EbomExcelDTO extends BaseImportExcelDTO {
|
||||
|
||||
/**
|
||||
* 父级物料编号
|
||||
*/
|
||||
@ExcelColumn("抬头物料")
|
||||
private String parentMaterialNo;
|
||||
|
||||
/**
|
||||
* 父级物料描述
|
||||
*/
|
||||
@ExcelColumn("物料描述")
|
||||
private String parentMaterialDesc;
|
||||
|
||||
/**
|
||||
* 项目类别
|
||||
*/
|
||||
@ExcelColumn("项目类别")
|
||||
private String projectType;
|
||||
|
||||
/**
|
||||
* 物料编号
|
||||
*/
|
||||
@ExcelColumn("项目物料")
|
||||
private String materialNo;
|
||||
|
||||
/**
|
||||
* 物料描述
|
||||
*/
|
||||
@ExcelColumn("项目物料描述")
|
||||
private String materialDesc;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@ExcelColumn("数量")
|
||||
private BigDecimal num;
|
||||
|
||||
/**
|
||||
* 物料单位
|
||||
*/
|
||||
@ExcelColumn("单位")
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 排序顺序
|
||||
*/
|
||||
@ExcelColumn("排序顺序")
|
||||
private String orderNum;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ExcelColumn("备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 图号
|
||||
*/
|
||||
private String drawingNo;
|
||||
}
|
||||
|
|
@ -338,6 +338,9 @@ public class BomNewEbomParentVO extends BaseMaterialVO implements Serializable {
|
|||
return (StrUtil.isBlank(getMaterialNo())?"":getMaterialNo())+(StrUtil.isBlank(getProjectType())?"":getProjectType());
|
||||
}
|
||||
|
||||
@ApiModelProperty(value = "导入SAP状态")
|
||||
private Integer sapState;
|
||||
|
||||
private List<BomNewEbomParentVO> childNodes = Collections.emptyList();
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -263,6 +263,9 @@ public class BomNewPbomParentVO extends BaseMaterialVO implements Serializable {
|
|||
@ApiModelProperty("层级数字")
|
||||
private BigDecimal levelNumber;
|
||||
|
||||
@ApiModelProperty(value = "导入SAP状态")
|
||||
private Integer sapState;
|
||||
|
||||
private String levelNo;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ package com.nflg.product.bomnew.service;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomChildMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* t_bom_new_ebom_child 表服务实现类
|
||||
|
|
@ -16,4 +19,11 @@ import org.springframework.stereotype.Service;
|
|||
@Service
|
||||
public class BomNewEbomChildService extends ServiceImpl<BomNewEbomChildMapper, BomNewEbomChildEntity> {
|
||||
|
||||
public List<BomNewEbomParentVO> getBom(Long parentRowId, String materialNo) {
|
||||
return baseMapper.getBom(parentRowId, materialNo);
|
||||
}
|
||||
|
||||
public void deleteAllChildren(Long parentRowId) {
|
||||
baseMapper.deleteAllChildren(parentRowId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
* @return
|
||||
*/
|
||||
public Page<BomNewEbomParentVO> formalWorksheet(BomNewEbomParentQuery query) {
|
||||
Page<BomNewEbomParentVO> result = this.getBaseMapper().formalWorksheet(new Page<>(query.getPage(), query.getPageSize()), query);
|
||||
Page<BomNewEbomParentVO> result = this.getBaseMapper().formalWorksheet(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode());
|
||||
|
||||
|
||||
if (CollUtil.isNotEmpty(result.getRecords())) {
|
||||
|
|
@ -405,6 +405,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
child.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
}
|
||||
}
|
||||
child.setChildBomRowId(child.getRowId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -961,7 +962,7 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
lambdaUpdate().eq(BomNewEbomParentEntity::getRowId, rootBomRowId)
|
||||
.set(BomNewEbomParentEntity::getSapTime, LocalDateTime.now())
|
||||
.set(BomNewEbomParentEntity::getSapState, sapState)
|
||||
.set(BomNewEbomParentEntity::getSapState, sapState.getValue())
|
||||
.update();
|
||||
}
|
||||
|
||||
|
|
@ -1562,7 +1563,8 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
|
||||
parentVO.setBomRowId(parentVO.getRowId());
|
||||
parentVO.setProjectType(projectType);
|
||||
parentVO.setParentRowId(0l);
|
||||
parentVO.setParentRowId(0L);
|
||||
parentVO.setChildBomRowId(rowId);
|
||||
materialMainService.intiMaterialInfo(ImmutableList.of(parentVO), EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT2);
|
||||
vo.setDatas(getChild(bomRowId));
|
||||
}
|
||||
|
|
@ -2313,4 +2315,26 @@ public class BomNewEbomParentService extends ServiceImpl<BomNewEbomParentMapper,
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BomNewEbomParentEntity getLatestByMaterialNo(String materialNo) {
|
||||
return this.lambdaQuery()
|
||||
.eq(BomNewEbomParentEntity::getMaterialNo, materialNo)
|
||||
.orderByDesc(BomNewEbomParentEntity::getRowId)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
}
|
||||
|
||||
public List<BomNewEbomParentEntity> getLatestByMaterialNo(Collection<String> materialNos) {
|
||||
return this.lambdaQuery()
|
||||
.in(BomNewEbomParentEntity::getMaterialNo, materialNos)
|
||||
.eq(BomNewEbomParentEntity::getLastVersionIs, 1)
|
||||
.list();
|
||||
}
|
||||
|
||||
public void setLastVersionIs0(Set<String> pMaterialNos) {
|
||||
this.lambdaUpdate().in(BomNewEbomParentEntity::getMaterialNo, pMaterialNos)
|
||||
.set(BomNewEbomParentEntity::getLastVersionIs, 0)
|
||||
.set(BomNewEbomParentEntity::getModifyTime, LocalDateTime.now())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ public class BomNewMbomParentService extends ServiceImpl<BomNewMbomParentMapper,
|
|||
private void updateSapState(Long rootBomRowId, SapStatusEnum sapState) {
|
||||
lambdaUpdate().eq(BomNewMbomParentEntity::getRowId, rootBomRowId)
|
||||
.set(BomNewMbomParentEntity::getSysnSapTime, LocalDateTime.now())
|
||||
.set(BomNewMbomParentEntity::getStatus, sapState)
|
||||
.set(BomNewMbomParentEntity::getStatus, sapState.getValue())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -379,6 +379,9 @@ public class DQBomImportService {
|
|||
dQbomExcelVO.setProjectType(BomConstant.PROJECT_TYPE_TEMPORARY);
|
||||
}
|
||||
dQbomExcelVO.setCurrentVersion("");
|
||||
if (StrUtil.isBlank(dQbomExcelVO.getProjectType())) {
|
||||
dQbomExcelVO.setProjectType("L");
|
||||
}
|
||||
|
||||
excelContextTL.get().add(dQbomExcelVO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,404 @@
|
|||
package com.nflg.product.bomnew.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.EbomExcelDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
|
||||
import com.nflg.product.bomnew.util.*;
|
||||
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;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 曹鹏飞
|
||||
* @date 2024/5/8 09:02:12
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EBomImportService {
|
||||
|
||||
public static final ThreadLocal<Integer> rowNum = new ThreadLocal<>();
|
||||
|
||||
public static final ThreadLocal<List<EbomExcelDTO>> excelContextTL = new ThreadLocal<>();
|
||||
|
||||
@Resource
|
||||
private MaterialMainService materialMainService;
|
||||
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@Resource
|
||||
private BomNewEbomParentService bomNewEbomParentService;
|
||||
|
||||
@Resource
|
||||
private BomNewEbomChildService bomNewEbomChildService;
|
||||
|
||||
public List<OperationErrorMsgVO> importBom(MultipartFile file) throws IOException {
|
||||
try {
|
||||
rowNum.set(1);
|
||||
excelContextTL.set(new ArrayList<>());
|
||||
EecExcelUtil.handlerExcel(file.getInputStream(), EbomExcelDTO.class, this::handlerExcelRow);
|
||||
|
||||
List<EbomExcelDTO> datas = excelContextTL.get();
|
||||
|
||||
List<OperationErrorMsgVO> errorMsg = checkExcel(datas);
|
||||
if (!errorMsg.isEmpty()) {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
Pair<List<BomNewEbomParentEntity>, List<BomNewEbomChildEntity>> pcs = convertToBom(datas);
|
||||
VUtils.isTure(pcs.getLeft().stream().filter(p -> p.getRootIs() == 1).count() > 1)
|
||||
.throwMessage("文件中存在多个根节点");
|
||||
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()))
|
||||
.throwMessage("导入的数据已存在,请勿重复导入");
|
||||
|
||||
save(pcs.getLeft(), pcs.getRight());
|
||||
|
||||
return Collections.emptyList();
|
||||
} finally {
|
||||
excelContextTL.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(List<BomNewEbomParentEntity> parents, List<BomNewEbomChildEntity> children) {
|
||||
BomNewEbomParentEntity root = parents.stream()
|
||||
.filter(p -> p.getRootIs() == 1)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在"));
|
||||
Set<String> pMaterialNos = parents.stream().map(BomNewEbomParentEntity::getMaterialNo).collect(Collectors.toSet());
|
||||
List<BomNewEbomParentEntity> oldParents = bomNewEbomParentService.getLatestByMaterialNo(pMaterialNos);
|
||||
parents.forEach(p -> {
|
||||
BomNewEbomParentEntity oldParent = oldParents.stream()
|
||||
.filter(op -> op.getMaterialNo().equals(p.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (!Objects.isNull(oldParent) && !Objects.equals(oldParent.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) {
|
||||
bomNewEbomParentService.getBaseMapper().deleteById(oldParent.getRowId());
|
||||
bomNewEbomChildService.deleteAllChildren(oldParent.getRowId());
|
||||
}
|
||||
});
|
||||
bomNewEbomParentService.setLastVersionIs0(pMaterialNos);
|
||||
bomNewEbomParentService.saveBatch(parents);
|
||||
bomNewEbomChildService.saveBatch(children);
|
||||
}
|
||||
|
||||
private boolean checkInconsistentData(BomNewEbomParentEntity parent, List<BomNewEbomParentEntity> parents,
|
||||
List<BomNewEbomChildEntity> children) throws JsonProcessingException {
|
||||
log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(parent));
|
||||
BomNewEbomParentEntity oldParent = bomNewEbomParentService.getLatestByMaterialNo(parent.getMaterialNo());
|
||||
boolean isSame = true;
|
||||
if (Objects.isNull(oldParent)) {
|
||||
return false;
|
||||
}
|
||||
isSame = Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit())
|
||||
&& NumberUtil.equals(parent.getNum(), oldParent.getNum())
|
||||
&& Objects.equals(parent.getMaterialTexture(), oldParent.getMaterialTexture());
|
||||
|
||||
if (isSame) {
|
||||
List<BomNewEbomChildEntity> cc = children.stream()
|
||||
.filter(c -> c.getParentRowId().equals(parent.getRowId()))
|
||||
.collect(Collectors.toList());
|
||||
List<BomNewEbomChildEntity> oc = bomNewEbomChildService.lambdaQuery()
|
||||
.eq(BomNewEbomChildEntity::getParentRowId, oldParent.getRowId())
|
||||
.list();
|
||||
|
||||
isSame = cc.size() == oc.size()
|
||||
&& Sets.difference(cc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet())
|
||||
, oc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty();
|
||||
for (BomNewEbomChildEntity ccc : cc) {
|
||||
if (!checkInconsistentData(parent.getRowId(), ccc, parents, children)) {
|
||||
isSame = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isSame) {
|
||||
if (Objects.equals(oldParent.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) {
|
||||
parent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion()));
|
||||
} else {
|
||||
VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode()))
|
||||
.throwMessage(StrUtil.format("{}正由{}编辑中,请联系Ta处理", oldParent.getMaterialNo(), oldParent.getCreatedBy()));
|
||||
}
|
||||
} else {
|
||||
parents.remove(parent);
|
||||
children.removeIf(c -> c.getParentRowId().equals(parent.getRowId()));
|
||||
}
|
||||
return isSame;
|
||||
}
|
||||
|
||||
private boolean checkInconsistentData(Long parentRowId, BomNewEbomChildEntity child, List<BomNewEbomParentEntity> parents,
|
||||
List<BomNewEbomChildEntity> children) throws JsonProcessingException {
|
||||
log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(child));
|
||||
List<BomNewEbomParentVO> oldChildren = bomNewEbomChildService.getBom(parentRowId, child.getMaterialNo());
|
||||
boolean isSame = true;
|
||||
if (CollUtil.isEmpty(oldChildren)) return false;
|
||||
BomNewEbomParentVO oldChild;
|
||||
if (oldChildren.size() == 1) {
|
||||
oldChild = oldChildren.get(0);
|
||||
} else {
|
||||
oldChild = oldChildren.stream().filter(c -> Objects.equals(c.getOrderNumber(), child.getOrderNumber())).findFirst().orElse(null);
|
||||
if (Objects.isNull(oldChild)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
isSame = Objects.equals(child.getMaterialUnit(), oldChild.getMaterialUnit())
|
||||
&& NumberUtil.equals(child.getNum(), oldChild.getNum())
|
||||
&& Objects.equals(child.getMaterialTexture(), oldChild.getMaterialTexture());
|
||||
|
||||
if (isSame) {
|
||||
BomNewEbomParentEntity cp = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().orElse(null);
|
||||
if (!Objects.isNull(cp)) {
|
||||
List<BomNewEbomChildEntity> cc = children.stream()
|
||||
.filter(c -> c.getParentRowId().equals(cp.getRowId()))
|
||||
.collect(Collectors.toList());
|
||||
List<BomNewEbomChildEntity> oc = bomNewEbomChildService.lambdaQuery()
|
||||
.eq(BomNewEbomChildEntity::getParentRowId, oldChild.getBomRowId())
|
||||
.list();
|
||||
Set<String> ccm = cc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet());
|
||||
|
||||
isSame = cc.size() == oc.size()
|
||||
&& Sets.difference(ccm, oc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty();
|
||||
//VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入");
|
||||
|
||||
for (BomNewEbomChildEntity ccc : cc) {
|
||||
if (!checkInconsistentData(cp.getRowId(), ccc, parents, children)) {
|
||||
isSame = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isSame) {
|
||||
if (!Objects.equals(oldChild.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) {
|
||||
VUtils.isTure(!Objects.equals(oldChild.getCreatedBy(), SessionUtil.getUserCode()))
|
||||
.throwMessage(StrUtil.format("{}正由{}编辑中,请联系Ta处理", oldChild.getMaterialNo(), oldChild.getCreatedBy()));
|
||||
}
|
||||
}
|
||||
return isSame;
|
||||
}
|
||||
|
||||
private void handlerExcelRow(EbomExcelDTO dQbomExcelVO) {
|
||||
rowNum.set(rowNum.get() + 1);
|
||||
log.debug("ebom导入excel,第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO));
|
||||
|
||||
dQbomExcelVO.setRowNum(rowNum.get());
|
||||
|
||||
excelContextTL.get().add(dQbomExcelVO);
|
||||
}
|
||||
|
||||
private List<OperationErrorMsgVO> checkExcel(List<EbomExcelDTO> datas) {
|
||||
List<OperationErrorMsgVO> errorMsg = new ArrayList<>();
|
||||
|
||||
List<Integer> numError = datas.stream().filter(u -> StrUtil.isBlank(u.getParentMaterialNo()))
|
||||
.map(BaseImportExcelDTO::getRowNum)
|
||||
.collect(Collectors.toList());
|
||||
if (!numError.isEmpty()) {
|
||||
errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "抬头物料为空"))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
numError = datas.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo()))
|
||||
.map(BaseImportExcelDTO::getRowNum)
|
||||
.collect(Collectors.toList());
|
||||
if (!numError.isEmpty()) {
|
||||
errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "项目物料为空"))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
numError = datas.stream().filter(u -> Objects.isNull(u.getNum()) || BigDecimal.ZERO.compareTo(u.getNum()) >= 0)
|
||||
.map(BaseImportExcelDTO::getRowNum)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!numError.isEmpty()) {
|
||||
errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "数量不正确"))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
numError = datas.stream().filter(u -> StringUtil.CountForMysql(u.getRemark()) > 200)
|
||||
.map(BaseImportExcelDTO::getRowNum)
|
||||
.collect(Collectors.toList());
|
||||
if (!numError.isEmpty()) {
|
||||
errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "备注超出200字"))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
private Pair<List<BomNewEbomParentEntity>, List<BomNewEbomChildEntity>> convertToBom(List<EbomExcelDTO> datas) {
|
||||
List<BomNewEbomParentEntity> parents = new ArrayList<>();
|
||||
List<BomNewEbomChildEntity> children = new ArrayList<>();
|
||||
|
||||
List<String> materialNos = datas.stream().map(EbomExcelDTO::getMaterialNo).collect(Collectors.toList());
|
||||
materialNos.addAll(datas.stream().map(EbomExcelDTO::getParentMaterialNo).collect(Collectors.toList()));
|
||||
materialNos = materialNos.stream().distinct().collect(Collectors.toList());
|
||||
List<BaseMaterialVO> materialBaseInfos = materialMainService.getMaterialBaseInfo(materialNos);
|
||||
|
||||
BomNewEbomParentEntity parent;
|
||||
for (EbomExcelDTO data : datas) {
|
||||
parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (Objects.isNull(parent)) {
|
||||
parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc()));
|
||||
}
|
||||
|
||||
parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (Objects.isNull(parent)) {
|
||||
parent = buildParent(materialBaseInfos, data);
|
||||
children.add(buildChild(materialBaseInfos, parent, data.getProjectType()));
|
||||
parents.add(parent);
|
||||
}
|
||||
}
|
||||
return Pair.of(parents, children);
|
||||
}
|
||||
|
||||
private BomNewEbomChildEntity buildChild(List<BaseMaterialVO> materialBaseInfos, BomNewEbomParentEntity parent, String projectType) {
|
||||
BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent);
|
||||
parent.setOrderNumber("");
|
||||
child.setRowId(IdWorker.getId());
|
||||
child.setParentRowId(parent.getRowId());
|
||||
child.setProjectType(projectType);
|
||||
child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue());
|
||||
child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId());
|
||||
BaseMaterialVO vo = materialBaseInfos.stream()
|
||||
.filter(m -> m.getMaterialNo().equals(child.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (!Objects.isNull(vo)) {
|
||||
child.setMaterialCategoryCode(vo.getMaterialCategoryCode());
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
private BomNewEbomParentEntity buildParent(List<BaseMaterialVO> materialBaseInfos, EbomExcelDTO data) {
|
||||
BomNewEbomParentEntity parent = new BomNewEbomParentEntity();
|
||||
parent.setRowId(IdWorker.getId());
|
||||
|
||||
BaseMaterialVO vo = materialBaseInfos.stream()
|
||||
.filter(m -> m.getMaterialNo().equals(data.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (!Objects.isNull(vo)) {
|
||||
parent.setDrawingNo(vo.getDrawingNo());
|
||||
parent.setUnitWeight(vo.getMaterialWeight());
|
||||
}
|
||||
|
||||
parent.setMaterialNo(data.getMaterialNo());
|
||||
parent.setMaterialDesc(data.getMaterialDesc());
|
||||
parent.setMaterialTexture("");
|
||||
parent.setMaterialUnit(data.getUnit());
|
||||
parent.setNum(data.getNum());
|
||||
parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight()));
|
||||
//parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setUserRootIs(0);
|
||||
parent.setRootIs(0);
|
||||
if (userRoleService.technician()) {
|
||||
//工艺人员
|
||||
parent.setStatus(EBomStatusEnum.CHECKED.getValue());
|
||||
parent.setCreatedJob(UserJobEnum.ENGINEER.getValue());
|
||||
parent.setAuditUserName(SessionUtil.getUserCode());
|
||||
parent.setAuditTime(LocalDateTime.now());
|
||||
} else {
|
||||
//设计人员
|
||||
parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue());
|
||||
parent.setCreatedJob(UserJobEnum.DESIGNER.getValue());
|
||||
parent.setRootIsForWaitReview(1);
|
||||
}
|
||||
parent.setDeviseName(SessionUtil.getRealName());
|
||||
parent.setDeviseUserCode(SessionUtil.getUserCode());
|
||||
parent.setLastVersionIs(1);
|
||||
parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue());
|
||||
parent.setCreatedBy(SessionUtil.getUserCode());
|
||||
parent.setRemark(data.getRemark());
|
||||
parent.setOrderNumber(data.getOrderNum());
|
||||
parent.setDeptName(SessionUtil.getDepartName());
|
||||
parent.setSource(EBomSourceEnum.FROM_EXCE.getValue());
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建顶级
|
||||
* @param materialBaseInfos 主物料数据
|
||||
* @param materialNo 物料编号
|
||||
* @param materialDesc 物料描述
|
||||
* @return 父级
|
||||
*/
|
||||
private BomNewEbomParentEntity buildRoot(List<BaseMaterialVO> materialBaseInfos, String materialNo, String materialDesc) {
|
||||
BomNewEbomParentEntity parent = new BomNewEbomParentEntity();
|
||||
parent.setRowId(IdWorker.getId());
|
||||
|
||||
BaseMaterialVO vo = materialBaseInfos.stream()
|
||||
.filter(m -> m.getMaterialNo().equals(materialNo))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (!Objects.isNull(vo)) {
|
||||
parent.setDrawingNo(vo.getDrawingNo());
|
||||
parent.setUnitWeight(vo.getMaterialWeight());
|
||||
}
|
||||
|
||||
parent.setMaterialNo(materialNo);
|
||||
parent.setMaterialDesc(materialDesc);
|
||||
parent.setMaterialTexture("");
|
||||
parent.setMaterialUnit("PC");
|
||||
//parent.setUnitWeight(BigDecimal.ZERO);
|
||||
parent.setNum(BigDecimal.ONE);
|
||||
//parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight()));
|
||||
//parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setUserRootIs(1);
|
||||
if (userRoleService.technician()) {
|
||||
//工艺人员
|
||||
parent.setStatus(EBomStatusEnum.CHECKED.getValue());
|
||||
parent.setCreatedJob(UserJobEnum.ENGINEER.getValue());
|
||||
parent.setAuditUserName(SessionUtil.getUserCode());
|
||||
parent.setAuditTime(LocalDateTime.now());
|
||||
parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo));
|
||||
} else {
|
||||
//设计人员
|
||||
parent.setRootIs(1);
|
||||
parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue());
|
||||
parent.setCreatedJob(UserJobEnum.DESIGNER.getValue());
|
||||
parent.setRootIsForWaitReview(1);
|
||||
}
|
||||
parent.setDeviseName(SessionUtil.getRealName());
|
||||
parent.setDeviseUserCode(SessionUtil.getUserCode());
|
||||
parent.setLastVersionIs(1);
|
||||
parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue());
|
||||
parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue());
|
||||
parent.setCreatedBy(SessionUtil.getUserCode());
|
||||
parent.setRemark("");
|
||||
parent.setDeptName(SessionUtil.getDepartName());
|
||||
parent.setSource(EBomSourceEnum.FROM_EXCE.getValue());
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
|
@ -113,10 +113,10 @@ public class CheckEBomException {
|
|||
&& unCheckExcept.contains(vo.getExceptionStatus())) {
|
||||
continue;
|
||||
}
|
||||
BaseMaterialVO mainVO = materialBaseInfo.stream()
|
||||
.filter(u -> StrUtil.equals(u.getMaterialNo(), vo.getMaterialNo()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
// BaseMaterialVO mainVO = materialBaseInfo.stream()
|
||||
// .filter(u -> StrUtil.equals(u.getMaterialNo(), vo.getMaterialNo()))
|
||||
// .findFirst()
|
||||
// .orElse(null);
|
||||
vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
|
||||
// }
|
||||
if (StrUtil.isNotBlank(vo.getMaterialNo())
|
||||
|
|
@ -130,13 +130,14 @@ public class CheckEBomException {
|
|||
} else if (StrUtil.isBlank(vo.getProjectType()) && !Objects.equals(vo.getRootIs(), 1)
|
||||
&& !Objects.equals(vo.getUserRootIs(), 1) && !Objects.equals(vo.getRootIsForWaitReview(), 1)) {
|
||||
vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_8.getValue());
|
||||
} else if ((StrUtil.equals("KG", StringUtil.toUpperCase(vo.getMaterialUnit())) && !StrUtil.equals(StringUtil.toUpperCase(vo.getMaterialUnit()), "PC"))
|
||||
|| (!Objects.isNull(mainVO) && !StrUtil.equals(vo.getMaterialUnit(), mainVO.getMaterialUnit()))) {
|
||||
} else if ((!StrUtil.equals("KG", StringUtil.toUpperCase(vo.getMaterialUnit())) && !StrUtil.equals(StringUtil.toUpperCase(vo.getMaterialUnit()), "PC"))
|
||||
//|| (!Objects.isNull(mainVO) && !StrUtil.equals(vo.getMaterialUnit(), mainVO.getMaterialUnit()))) {
|
||||
&& (StrUtil.isBlank(vo.getExceptionTag()) || (!vo.getExceptionTag().contains("16")) && !vo.getExceptionTag().contains("12"))) {
|
||||
vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_12.getValue());
|
||||
} else if (StrUtil.isNotBlank(vo.getNoticeNums()) && EBomExceptionStatusEnum.EXCEPT_NO_11.equalsValue(vo.getExceptionStatus())) {
|
||||
vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
|
||||
}
|
||||
else if (!StrUtil.equals(vo.getMaterialUnit(), vo.getMaterialOriginalUnit()) && StrUtil.isBlank(vo.getExceptionTag())){
|
||||
} else if (!StrUtil.equals(vo.getMaterialUnit(), vo.getMaterialOriginalUnit())
|
||||
&& (StrUtil.isBlank(vo.getExceptionTag()) || !vo.getExceptionTag().contains("16"))) {
|
||||
vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_16.getValue());
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +216,7 @@ public class CheckEBomException {
|
|||
k.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_14.getValue());
|
||||
}
|
||||
}
|
||||
List<BomNewEbomParentVO> root = allBomDetail.stream().filter(u -> u.getLevelNumber().compareTo(BigDecimal.ZERO) == 0 && EBomExceptionStatusEnum.OK.equalsValue(u.getExceptionStatus())).collect(Collectors.toList());
|
||||
List<BomNewEbomParentVO> root = allBomDetail.stream().filter(u -> Objects.nonNull(u.getLevelNumber()) && u.getLevelNumber().compareTo(BigDecimal.ZERO) == 0 && EBomExceptionStatusEnum.OK.equalsValue(u.getExceptionStatus())).collect(Collectors.toList());
|
||||
root.forEach(k->{
|
||||
k.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_14.getValue());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.AddVirtrualMaterialDTO;
|
||||
|
|
|
|||
|
|
@ -74,4 +74,33 @@
|
|||
</foreach>
|
||||
group by parent_row_id
|
||||
</select>
|
||||
|
||||
<select id="shouldSetRootIs" resultType="java.lang.Integer">
|
||||
SELECT CASE
|
||||
WHEN EXISTS
|
||||
(SELECT *
|
||||
FROM t_bom_new_ebom_parent p
|
||||
INNER JOIN t_bom_new_ebom_child c ON p.row_id = c.parent_row_id
|
||||
AND p.STATUS < 4
|
||||
WHERE c.material_no = #{materialNo}) THEN 1
|
||||
ELSE 0
|
||||
END AS result;
|
||||
</select>
|
||||
|
||||
<select id="getBom" resultType="com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO">
|
||||
SELECT c.*, p.row_id AS bomRowId
|
||||
FROM t_bom_new_ebom_child c
|
||||
LEFT JOIN t_bom_new_ebom_parent p ON p.material_no = c.material_no
|
||||
WHERE c.parent_row_id = #{parentRowId}
|
||||
AND c.material_no = #{materialNo}
|
||||
</select>
|
||||
|
||||
<delete id="deleteAllChildren">
|
||||
DELETE
|
||||
FROM t_bom_new_ebom_child
|
||||
WHERE parent_row_id = #{parentRowId};
|
||||
UPDATE t_bom_new_ebom_parent
|
||||
SET bom_exist=0
|
||||
WHERE row_id = #{parentRowId};
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -394,24 +394,26 @@
|
|||
SELECT *,row_id as bomRowId
|
||||
FROM t_bom_new_ebom_parent
|
||||
<!-- WHERE (root_is=1 OR ((user_root_is=1 OR root_is_for_wait_review=1) AND created_by=#{userCode}))-->
|
||||
<if test="query.showMySelfOnly == 1">
|
||||
AND created_by = #{userCode}
|
||||
</if>
|
||||
<if test="userJob==0">
|
||||
WHERE status IN (1,3) AND (user_root_is=1 OR root_is_for_wait_review=1) AND created_by=#{userCode}
|
||||
</if>
|
||||
<if test="userJob==1 and query.dataType==0">
|
||||
WHERE root_is=1 AND status=2
|
||||
</if>
|
||||
<if test="userJob==1 and query.dataType==1">
|
||||
WHERE root_is=1 AND status=4
|
||||
</if>
|
||||
<if test="query.deviseName!=null and query.deviseName!=''">
|
||||
AND devise_name=#{query.deviseName}
|
||||
</if>
|
||||
<if test="query.startDate!=null and query.startDate!=''">
|
||||
AND created_time BETWEEN #{query.startDate} AND DATE_ADD(#{query.endDate}, INTERVAL 1 DAY)
|
||||
</if>
|
||||
<where>
|
||||
<if test="query.showMySelfOnly == 1">
|
||||
AND created_by = #{userCode}
|
||||
</if>
|
||||
<if test="userJob==0">
|
||||
AND status IN (1,3) AND (user_root_is=1 OR root_is_for_wait_review=1) AND created_by=#{userCode}
|
||||
</if>
|
||||
<if test="userJob==1 and query.dataType==0">
|
||||
AND root_is=1 AND status=2
|
||||
</if>
|
||||
<if test="userJob==1 and query.dataType==1">
|
||||
AND root_is=1 AND status=4
|
||||
</if>
|
||||
<if test="query.deviseName!=null and query.deviseName!=''">
|
||||
AND devise_name=#{query.deviseName}
|
||||
</if>
|
||||
<if test="query.startDate!=null and query.startDate!=''">
|
||||
AND created_time BETWEEN #{query.startDate} AND DATE_ADD(#{query.endDate}, INTERVAL 1 DAY)
|
||||
</if>
|
||||
</where>
|
||||
order by row_id desc
|
||||
</select>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue