mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/PartServiceImpl.java
@@ -517,10 +517,6 @@ } } public void asyncExcel(MultipartFile file,Map<String, String> dicmattype,Map<String, String> dicunit){ File file1 = MultipartFileToFile.multipartFileToFile(file); CsvReader reader = CsvUtil.getReader(); mes-technology/src/main/java/com/chinaztt/mes/technology/controller/BomController.java
@@ -21,9 +21,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.mes.technology.dto.BomDTO; import com.chinaztt.mes.technology.dto.StructureTree; import com.chinaztt.mes.technology.entity.Bom; import com.chinaztt.mes.technology.entity.Operation; import com.chinaztt.mes.technology.entity.Structure; import com.chinaztt.mes.technology.excel.BomData; import com.chinaztt.mes.technology.excel.BomUploadListener; @@ -42,8 +40,6 @@ import java.io.IOException; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** @@ -199,6 +195,7 @@ public R addByStructure() { // 获取需要进行构建BOM的产品结构 List<Structure> structures = structureService.getBuildBom(); structures.forEach(System.out::println); return bomService.saveALLBom(structures); } } mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java
@@ -19,14 +19,14 @@ import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.read.builder.ExcelReaderBuilder; import com.alibaba.excel.read.metadata.ReadSheet; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.chinaztt.mes.basic.util.DictUtils; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.mes.technology.excel.*; import com.chinaztt.mes.technology.dto.StructureDTO; import com.chinaztt.mes.technology.entity.StructureComponent; import com.chinaztt.mes.technology.excel.StructureData; import com.chinaztt.mes.technology.excel.StructureUploadListener; import com.chinaztt.mes.technology.service.StructureService; import com.chinaztt.ztt.admin.api.entity.SysDictItem; import com.chinaztt.ztt.admin.api.feign.RemoteDictService; @@ -41,7 +41,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -69,17 +68,32 @@ */ @PostMapping("/uploadExt") public R uploadExt(@RequestParam("file") MultipartFile file) { //ExcelReader excelReader = null; //try { // ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file.getInputStream()); // excelReader = excelReaderBuilder.build(); // List<ReadSheet> sheets = excelReader.excelExecutor().sheetList(); // List<ReadSheet> readSheetList = new ArrayList<>(); // for (ReadSheet sheet : sheets) { // ReadSheet readSheet = EasyExcel.readSheet(sheet.getSheetName()).registerReadListener(new StructureUploadExtListener(structureService)).build(); // readSheetList.add(readSheet); // } // excelReader.read(readSheetList); //} catch (IOException e) { // e.printStackTrace(); // return R.failed(e.getMessage()); //} finally { // if (excelReader != null) { // // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的 // excelReader.finish(); // } //} ExcelReader excelReader = null; try { ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file.getInputStream()); excelReader = excelReaderBuilder.build(); List<ReadSheet> sheets = excelReader.excelExecutor().sheetList(); List<ReadSheet> readSheetList = new ArrayList<>(); for (ReadSheet sheet : sheets) { ReadSheet readSheet = EasyExcel.readSheet(sheet.getSheetName()).registerReadListener(new StructureUploadExtListener(structureService)).build(); readSheetList.add(readSheet); } excelReader.read(readSheetList); excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService, dictUtils)).build(); ReadSheet readSheet = EasyExcel.readSheet(0).build(); ReadSheet readSheet2 = EasyExcel.readSheet(1).build(); excelReader.read(readSheet,readSheet2); } catch (IOException e) { e.printStackTrace(); return R.failed(e.getMessage()); @@ -104,7 +118,8 @@ try { excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService, dictUtils)).build(); ReadSheet readSheet = EasyExcel.readSheet(0).build(); excelReader.read(readSheet); ReadSheet readSheet2 = EasyExcel.readSheet(1).build(); excelReader.read(readSheet,readSheet2); } catch (IOException e) { e.printStackTrace(); return R.failed(e.getMessage()); mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureData.java
@@ -1,7 +1,6 @@ package com.chinaztt.mes.technology.excel; import com.alibaba.excel.annotation.ExcelProperty; import jdk.nashorn.internal.objects.annotations.Property; import lombok.Data; /** @@ -11,6 +10,51 @@ @Data public class StructureData { @ExcelProperty(value = "客户") private String custom; @ExcelProperty(value = "零件号") private String partNo; @ExcelProperty(value = "零件名称") private String partName; @ExcelProperty(value = "子件编号") private String sonPartNo; @ExcelProperty(value = "子件名称(可多填)") private String sonPartName; @ExcelProperty(value = "模具编号") private String sharpenerNo; @ExcelProperty(value = "每模穴数") private String caveNum; @ExcelProperty(value = "产品克重(kg)") private String gramWeight; @ExcelProperty(value = "浇口克重(kg)") private String gateGramWeight; @ExcelProperty(value = "成型周期(S)") private String moldingCycle; @ExcelProperty(value = "机台(吨)") private String machine; @ExcelProperty(value = "回料比例(%)") private String scale; @ExcelProperty(value= "烘料时间(H)") private String dryingTime; @ExcelProperty(value = "烘料温度(℃)") private String dryingTemperature; @ExcelProperty(value = "包装信息") private String packingInfo; @ExcelProperty(value = "父件") private String fatherPartNo; mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadListener.java
@@ -45,18 +45,18 @@ if (StringUtils.isEmpty(data.getAlternativeNo())) { data.setAlternativeNo("*"); } if (StringUtils.isEmpty(data.getChildPartNo()) || StringUtils.isEmpty(data.getChildVersion()) || StringUtils.isEmpty(data.getFatherPartNo()) || StringUtils.isEmpty(data.getFatherVersion())) { throw new RuntimeException("缺少零件数据编号或者版本"); } if (StringUtils.isEmpty(data.getQpa())) { throw new RuntimeException("缺少数量"); } if (StringUtils.isEmpty(data.getLineItemNo())) { throw new RuntimeException("缺少行项号"); } if (StringUtils.isEmpty(data.getOperationName())) { throw new RuntimeException("缺少工序"); } //if (StringUtils.isEmpty(data.getChildPartNo()) || StringUtils.isEmpty(data.getChildVersion()) || StringUtils.isEmpty(data.getFatherPartNo()) || StringUtils.isEmpty(data.getFatherVersion())) { // throw new RuntimeException("缺少零件数据编号或者版本"); //} //if (StringUtils.isEmpty(data.getQpa())) { // throw new RuntimeException("缺少数量"); //} //if (StringUtils.isEmpty(data.getLineItemNo())) { // throw new RuntimeException("缺少行项号"); //} //if (StringUtils.isEmpty(data.getOperationName())) { // throw new RuntimeException("缺少工序"); //} data.setStructureType(StringUtils.isEmpty(data.getStructureType()) ? "M" : dicbomtype.get(data.getStructureType())); list.add(data); // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/BomServiceImpl.java
@@ -40,6 +40,7 @@ import com.chinaztt.mes.technology.state.bom.constant.BomStates; import com.chinaztt.ztt.common.core.util.R; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; @@ -66,6 +67,7 @@ @Service @AllArgsConstructor @Transactional(rollbackFor = Exception.class) @Slf4j public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomService { private NumberGenerator<Bom> numberGenerator; @@ -162,10 +164,13 @@ bom.setVersion(structure.getVersion()); bom.setAlternativeNo(structure.getAlternativeNo()); bom.setAlternativeDesc(structure.getAlternativeDesc()); StructureTree tree = getAllBomExt(bom, 998); //log.info("第一层========================》"+bom); StructureTree tree = getAllBomExt(bom, 999); BomDTO bomDTO = new BomDTO(); BeanUtils.copyProperties(bom, bomDTO); bomDTO.setTree(tree); //BomDTO bomDTO = getBomDtoById(structure.getPartId()); log.info("bomDto============>"+bomDTO); saveBom(bomDTO); }); return R.ok(); @@ -221,12 +226,14 @@ return; } Part parentPart = partMapper.selectById(parentPartId); //"P" 虚拟件的意思 在一个BOM中,除根节点外,其余节点若不是虚拟件(零件【计划方法】不为P 和 K),则禁止为其增加子件。 if (!bom.getPartId().equals(parentPartId)) { if (!"P".equals(parentPart.getPlanningMethod()) && !"K".equals(parentPart.getPlanningMethod())) { throw new RuntimeException(parentPart.getPartNo() + parentPart.getPartName() + "为非虚拟件,不可添加子件"); } } log.error("parentId=======>"+parentPartId); log.error("bomParentId====>"+bom); ////"P" 虚拟件的意思 在一个BOM中,除根节点外,其余节点若不是虚拟件(零件【计划方法】不为P 和 K),则禁止为其增加子件。 //if (!bom.getPartId().equals(parentPartId)) { // if (!"P".equals(parentPart.getPlanningMethod()) && !"K".equals(parentPart.getPlanningMethod())) { // throw new RuntimeException(parentPart.getPartNo() + parentPart.getPartName() + "为非虚拟件,不可添加子件"); // } //} for (StructureTree child : children) { BomComponent bomComp = new BomComponent(); bomComp.setQpa(child.getQpa()); @@ -263,6 +270,7 @@ */ @Override public StructureTree getAllBomExt(Bom bom, int bomLayers) { log.info("生成树=======》"); Long partId = bom.getPartId(); String version = bom.getVersion(); String alternativeNo = bom.getAlternativeNo(); @@ -288,7 +296,9 @@ * @Date: 2022-06-01 */ private StructureTree getRootNode(Long partId) { log.info("获取bom根节点====》"+partId); Part part = partMapper.selectById(partId); log.info("父级零件====》"+part); StructureTree root = new StructureTree(); root.setPartName(part.getPartName()); root.setPlanningMethod(part.getPlanningMethod()); @@ -352,13 +362,16 @@ @Override public BomDTO getBomDtoById(Long id) { Bom bom = baseMapper.selectById(id); log.info("getBomDtoById=>>>"+bom); //如果存在未绑定工序的 工艺路线 则会为空 List<StructureTree> nodes = baseMapper.getBomComponents4Tree(id); if (CollectionUtil.isEmpty(nodes)) { return null; } StructureTree root = nodes.stream().filter(e -> e.getParentId() == null || e.getParentId() == 0).findFirst().get(); log.info("root=======>"+root); setChildren(root, nodes); log.info("setChildren后========》"+root); Part part = partMapper.selectById(bom.getPartId()); BomDTO bomDto = new BomDTO(); BeanUtils.copyProperties(bom, bomDto); @@ -557,6 +570,7 @@ */ private void getStructureByPartId(StructureTree parent, Long partId, Map<Long, Integer> cache, String version, String alternativeNo, String bomType, int bomLayers) { log.info("每层树===================》"+parent); Integer cycleCount = cache.get(partId) == null ? 0 : cache.get(partId); if (cycleCount >= CYCLE_DEEP) { return; @@ -565,6 +579,7 @@ } //根据零件找到结构主表 List<Structure> structures = getRootNodes(partId, version, alternativeNo, bomType); log.info("得到结构=========》"+structures); if (CollectionUtil.isNotEmpty(structures)) { for (Structure structure : structures) { @@ -598,6 +613,7 @@ } // 填充child节点数据 StructureTree child = fillChildNode(parent, component, structure, part); log.info("节点数据====================》"+child); if (bomLayers == 999) { getStructureByPartId(child, component.getPartId(), cache, "ALL", "ALL", bomType, bomLayers); // 判断到第几层了,制造类型为1-已制造,计划方法为P-虚拟件 mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java
@@ -257,55 +257,58 @@ @Override public void importExcel(List<StructureData> list) { if (CollectionUtil.isEmpty(list)) { return; } List<String> uinck = new ArrayList<>(); for (StructureData data : list) { Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getFatherPartNo()).eq(Part::getEngChgLevel, data.getFatherVersion())); if (part == null) { throw new RuntimeException("零件号:" + data.getFatherPartNo() + "不存在"); } Structure structure = baseMapper.selectOne(Wrappers.<Structure>lambdaQuery() .eq(Structure::getPartId, part.getId()) .eq(Structure::getBomTypeDb, data.getStructureType()) .eq(Structure::getAlternativeNo, data.getAlternativeNo())); if (structure == null) { structure = new Structure(); structure.setPartId(part.getId()); structure.setVersion(data.getFatherVersion()); structure.setAlternativeDesc(data.getAlternativeDesc()); structure.setActive(true); structure.setBomTypeDb(data.getStructureType()); structure.setIfsSync(false); structure.setAlternativeNo(data.getAlternativeNo()); baseMapper.insert(structure); } if (uinck.contains(structure.getId() + "_" + data.getLineItemNo())) { throw new RuntimeException("零件号:" + part.getPartNo() + "行项号重复"); } Part childPart = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getChildPartNo()).eq(Part::getEngChgLevel, data.getChildVersion())); if (childPart == null) { throw new RuntimeException("零件号:" + data.getChildPartNo() + "不存在"); } StructureComponent component = new StructureComponent(); component.setStructureId(structure.getId()); component.setPartId(childPart.getId()); component.setPlanningMethod(childPart.getPlanningMethod()); component.setQpa(new BigDecimal(data.getQpa())); component.setLineItemNo(Integer.valueOf(data.getLineItemNo())); component.setDiscNum(StringUtils.isEmpty(data.getDiskNum()) ? null : new Long(data.getDiskNum())); //查询工序 如果有多个获取第一个 List<Operation> operationList = operationMapper.selectList(Wrappers.<Operation>lambdaQuery() .eq(Operation::getName, data.getOperationName()) .eq(Operation::getActive, true).orderByAsc(Operation::getId)); if (CollectionUtil.isEmpty(operationList)) { throw new RuntimeException("工序" + data.getOperationName() + "不存在"); } component.setOperationId(operationList.get(0).getId()); structureComponentMapper.insert(component); uinck.add(structure.getId() + "_" + data.getLineItemNo()); } list.forEach(System.out::println); System.out.println("================================"); return; //if (CollectionUtil.isEmpty(list)) { // return; //} //List<String> uinck = new ArrayList<>(); //for (StructureData data : list) { // Part part = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getFatherPartNo()).eq(Part::getEngChgLevel, data.getFatherVersion())); // if (part == null) { // throw new RuntimeException("零件号:" + data.getFatherPartNo() + "不存在"); // } // Structure structure = baseMapper.selectOne(Wrappers.<Structure>lambdaQuery() // .eq(Structure::getPartId, part.getId()) // .eq(Structure::getBomTypeDb, data.getStructureType()) // .eq(Structure::getAlternativeNo, data.getAlternativeNo())); // if (structure == null) { // structure = new Structure(); // structure.setPartId(part.getId()); // structure.setVersion(data.getFatherVersion()); // structure.setAlternativeDesc(data.getAlternativeDesc()); // structure.setActive(true); // structure.setBomTypeDb(data.getStructureType()); // structure.setIfsSync(false); // structure.setAlternativeNo(data.getAlternativeNo()); // baseMapper.insert(structure); // } // if (uinck.contains(structure.getId() + "_" + data.getLineItemNo())) { // throw new RuntimeException("零件号:" + part.getPartNo() + "行项号重复"); // } // Part childPart = partMapper.selectOne(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getChildPartNo()).eq(Part::getEngChgLevel, data.getChildVersion())); // if (childPart == null) { // throw new RuntimeException("零件号:" + data.getChildPartNo() + "不存在"); // } // StructureComponent component = new StructureComponent(); // component.setStructureId(structure.getId()); // component.setPartId(childPart.getId()); // component.setPlanningMethod(childPart.getPlanningMethod()); // component.setQpa(new BigDecimal(data.getQpa())); // component.setLineItemNo(Integer.valueOf(data.getLineItemNo())); // component.setDiscNum(StringUtils.isEmpty(data.getDiskNum()) ? null : new Long(data.getDiskNum())); // //查询工序 如果有多个获取第一个 // List<Operation> operationList = operationMapper.selectList(Wrappers.<Operation>lambdaQuery() // .eq(Operation::getName, data.getOperationName()) // .eq(Operation::getActive, true).orderByAsc(Operation::getId)); // if (CollectionUtil.isEmpty(operationList)) { // throw new RuntimeException("工序" + data.getOperationName() + "不存在"); // } // component.setOperationId(operationList.get(0).getId()); // structureComponentMapper.insert(component); // uinck.add(structure.getId() + "_" + data.getLineItemNo()); //} } @Override