From 3c34085a21511610477f555cebf3f6fa42272402 Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期二, 07 十一月 2023 18:32:53 +0800 Subject: [PATCH] 产品结构导入数据 --- /dev/null | 81 ------------- mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java | 22 ++- mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java | 64 +++------- mes-basic/src/main/java/com/chinaztt/mes/basic/mapper/ParamMapper.java | 2 mes-basic/src/main/resources/mapper/ParamMapper.xml | 6 + mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadListener.java | 21 --- mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java | 88 ++++++-------- mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureData.java | 41 ------ mes-web/src/main/resources/bootstrap.yml | 2 9 files changed, 85 insertions(+), 242 deletions(-) diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/mapper/ParamMapper.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/mapper/ParamMapper.java index 972fd65..63eef7f 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/mapper/ParamMapper.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/mapper/ParamMapper.java @@ -86,4 +86,6 @@ * @return */ List<ParamDTO> getLastParamById(@org.apache.ibatis.annotations.Param("paramDTO") ParamDTO paramDTO); + + List<String> getNos(String code); } diff --git a/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java b/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java index ca71185..3ec470e 100644 --- a/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java +++ b/mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/ParamServiceImpl.java @@ -17,9 +17,6 @@ package com.chinaztt.mes.basic.service.impl; import cn.hutool.core.collection.CollectionUtil; -import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.ExcelWriter; -import com.alibaba.excel.support.ExcelTypeEnum; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -33,9 +30,6 @@ import com.chinaztt.mes.basic.mapper.ParamMapper; import com.chinaztt.mes.basic.service.ParamService; import com.chinaztt.mes.basic.util.DictUtils; -import com.chinaztt.mes.common.util.easyexcel.CustemHandler; -import com.chinaztt.mes.common.util.easyexcel.EasyExcelUtils; -import com.chinaztt.mes.common.util.easyexcel.template.ParamTemplate; import com.chinaztt.ztt.admin.api.entity.SysDictItem; import com.chinaztt.ztt.common.core.util.R; import lombok.AllArgsConstructor; @@ -43,8 +37,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.stream.Collectors; @@ -163,4 +157,16 @@ } } + private String codeMake() { + // 鍥哄畾瀛楃涓� GX + 骞存湀鏃� + 01 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); + String yrar = formatter.format(LocalDateTime.now()); + String code = "GX" + yrar; + List<String> parameterItem = baseMapper.getNos(code); + if (CollectionUtil.isEmpty(parameterItem)) { + code = code + "01"; + } + return code; + } + } diff --git a/mes-basic/src/main/resources/mapper/ParamMapper.xml b/mes-basic/src/main/resources/mapper/ParamMapper.xml index 7a69747..3f12f92 100644 --- a/mes-basic/src/main/resources/mapper/ParamMapper.xml +++ b/mes-basic/src/main/resources/mapper/ParamMapper.xml @@ -117,4 +117,10 @@ WHERE A."id" = #{paramDTO.technologyOperationTemplateId} ORDER BY B.sort </select> + + <select id="getNos" resultType="java.lang.String"> + SELECT parameter_item + FROM basic_param + WHERE code=#{code} + </select> </mapper> diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java index 67f390b..1cb0c7a 100644 --- a/mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java +++ b/mes-technology/src/main/java/com/chinaztt/mes/technology/controller/StructureController.java @@ -68,29 +68,9 @@ */ @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 { - excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService, dictUtils)).build(); + excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService)).build(); ReadSheet readSheet = EasyExcel.readSheet(0).build(); ReadSheet readSheet2 = EasyExcel.readSheet(1).build(); excelReader.read(readSheet,readSheet2); @@ -110,27 +90,27 @@ * 绔栫潃瀵煎叆 * * @param file - * @return - */ - @PostMapping("/upload") - public R simpleRead(@RequestParam("file") MultipartFile file) { - ExcelReader excelReader = null; - try { - 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()); - } finally { - if (excelReader != null) { - // 杩欓噷鍗冧竾鍒繕璁板叧闂紝璇荤殑鏃跺�欎細鍒涘缓涓存椂鏂囦欢锛屽埌鏃剁鐩樹細宕╃殑 - excelReader.finish(); - } - } - return R.ok(); - } +// * @return +// */ +// @PostMapping("/upload") +// public R simpleRead(@RequestParam("file") MultipartFile file) { +// ExcelReader excelReader = null; +// try { +// excelReader = EasyExcel.read(file.getInputStream(), StructureData.class, new StructureUploadListener(structureService)).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()); +// } finally { +// if (excelReader != null) { +// // 杩欓噷鍗冧竾鍒繕璁板叧闂紝璇荤殑鏃跺�欎細鍒涘缓涓存椂鏂囦欢锛屽埌鏃剁鐩樹細宕╃殑 +// excelReader.finish(); +// } +// } +// return R.ok(); +// } /** * 鏍规嵁闆朵欢鍙锋煡璇㈤粯璁OM diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureData.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureData.java index 3b85722..f359e3f 100644 --- a/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureData.java +++ b/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureData.java @@ -25,6 +25,9 @@ @ExcelProperty(value = "瀛愪欢鍚嶇О锛堝彲澶氬~锛�") private String sonPartName; + @ExcelProperty(value = "娑堣�楀伐搴�") + private String operationName; + @ExcelProperty(value = "妯″叿缂栧彿") private String sharpenerNo; @@ -55,45 +58,7 @@ @ExcelProperty(value = "鍖呰淇℃伅") private String packingInfo; - @ExcelProperty(value = "鐖朵欢") - private String fatherPartNo; - @ExcelProperty(value = "绯荤粺鎻忚堪") - private String remark; - @ExcelProperty(value = "鐗堟湰") - private String fatherVersion; - @ExcelProperty(value = "缁撴瀯绫诲瀷") - private String structureType; - - @ExcelProperty(value = "鏇夸唬") - private String alternativeNo; - - @ExcelProperty(value = "鏇夸唬鎻忚堪") - private String alternativeDesc; - - @ExcelProperty(value = "琛岄」鍙�") - private String lineItemNo; - - @ExcelProperty(value = "瀛愪欢") - private String childPartNo; - - @ExcelProperty(value = "瀛愪欢鐗堟湰") - private String childVersion; - - @ExcelProperty(value = "瀛愪欢鎻忚堪") - private String childRemark; - - @ExcelProperty(value = "鍗曚綅鏁伴噺") - private String qpa; - - @ExcelProperty(value = "鍗曚綅") - private String unit; - - @ExcelProperty(value = "鐩樻暟") - private String diskNum; - - @ExcelProperty(value = "娑堣�楀伐搴�") - private String operationName; } diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadExtListener.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadExtListener.java deleted file mode 100644 index 1345d0a..0000000 --- a/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadExtListener.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.chinaztt.mes.technology.excel; - -import com.alibaba.excel.context.AnalysisContext; -import com.alibaba.excel.event.AnalysisEventListener; -import com.chinaztt.mes.technology.service.StructureService; -import lombok.extern.slf4j.Slf4j; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @Author: liuth - * @Date: 2020-11-30 9:46 - */ -@Slf4j -public class StructureUploadExtListener extends AnalysisEventListener<Map<Integer, String>> { - - private static final int BATCH_COUNT = 1000; - - /** - * 琛ㄥご鏁版嵁 - */ - private Map<Integer, String> headMap = new HashMap<>(); - /** - * 鏁版嵁浣� - */ - private List<Map<Integer, String>> dataList = new ArrayList<>(); - - private StructureService structureService; - - public StructureUploadExtListener(StructureService structureService) { - this.structureService = structureService; - } - - - /** - * 閲嶅啓invokeHeadMap鏂规硶锛岃幏鍘昏〃澶达紝濡傛灉鏈夐渶瑕佽幏鍙栫涓�琛岃〃澶村氨閲嶅啓杩欎釜鏂规硶锛屼笉闇�瑕佸垯涓嶉渶瑕侀噸鍐� - * @param headMap 姣忚瑙f瀽鐨勬暟鎹负Map<Integer, String>绫诲瀷锛孖nteger鏄疎xcel鐨勫垪绱㈠紩,String涓篍xcel鐨勫崟鍏冩牸鍊� - * @param context context鑳借幏鍙栦竴浜涗笢瑗匡紝姣斿context.readRowHolder().getRowIndex()涓篍xcel鐨勮绱㈠紩锛岃〃澶寸殑琛岀储寮曚负0锛�0涔嬪悗鐨勯兘瑙f瀽鎴愭暟鎹� - */ - @Override - public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) { - log.info("瑙f瀽鍒颁竴鏉″ご鏁版嵁锛歿}, currentRowHolder: {}", headMap.toString(), context.readRowHolder().getRowIndex()); - this.headMap = headMap; - } - - - - /** - * 閲嶅啓invoke鏂规硶鑾峰緱闄xcel绗竴琛岃〃澶翠箣鍚庣殑鏁版嵁 - * 濡傛灉Excel绗簩琛屼篃鏄〃澶达紝閭d箞涔熶細瑙f瀽鍒拌繖閲岋紝濡傛灉涓嶉渶瑕佸氨閫氳繃鍒ゆ柇context.readRowHolder().getRowIndex()璺宠繃 - * @param data - * @param analysisContext - */ - @Override - public void invoke(Map<Integer, String> data, AnalysisContext analysisContext) { - log.info("瑙f瀽鍒颁竴鏉℃暟鎹細{}, currentRowIndex: {}----", data.toString(), analysisContext.readRowHolder().getRowIndex()); - dataList.add(data); - if (dataList.size() >= BATCH_COUNT) { - save(); - dataList.clear(); - } - } - - /** - * 瑙f瀽鍒版渶鍚庝細杩涘叆杩欎釜鏂规硶锛岄渶瑕侀噸鍐欒繖涓猟oAfterAllAnalysed鏂规硶锛岀劧鍚庨噷闈㈣皟鐢ㄨ嚜宸卞畾涔夊ソ淇濆瓨鏂规硶 - * @param analysisContext - */ - @Override - public void doAfterAllAnalysed(AnalysisContext analysisContext) { - save(); - log.info("鎵�鏈夋暟鎹В鏋愬畬鎴愶紒"); - } - - - private void save() { - structureService.importExcelExt(headMap, dataList); - } -} diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadListener.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadListener.java index 89d7a99..a923db7 100644 --- a/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadListener.java +++ b/mes-technology/src/main/java/com/chinaztt/mes/technology/excel/StructureUploadListener.java @@ -21,16 +21,14 @@ * 鍋囪杩欎釜鏄竴涓狣AO锛屽綋鐒舵湁涓氬姟閫昏緫杩欎釜涔熷彲浠ユ槸涓�涓猻ervice銆傚綋鐒跺鏋滀笉鐢ㄥ瓨鍌ㄨ繖涓璞℃病鐢ㄣ�� */ private StructureService structureService; - private DictUtils dictUtils; /** * 濡傛灉浣跨敤浜唖pring,璇蜂娇鐢ㄨ繖涓瀯閫犳柟娉曘�傛瘡娆″垱寤篖istener鐨勬椂鍊欓渶瑕佹妸spring绠$悊鐨勭被浼犺繘鏉� * * @param structureService */ - public StructureUploadListener(StructureService structureService,DictUtils dictUtils) { + public StructureUploadListener(StructureService structureService) { this.structureService = structureService; - this.dictUtils = dictUtils; } /** @@ -41,23 +39,6 @@ */ @Override public void invoke(StructureData data, AnalysisContext context) { - Map<String, String> dicbomtype = dictUtils.getDicKey("bom_type_db"); - 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("缂哄皯宸ュ簭"); - //} - data.setStructureType(StringUtils.isEmpty(data.getStructureType()) ? "M" : dicbomtype.get(data.getStructureType())); list.add(data); // 杈惧埌BATCH_COUNT浜嗭紝闇�瑕佸幓瀛樺偍涓�娆℃暟鎹簱锛岄槻姝㈡暟鎹嚑涓囨潯鏁版嵁鍦ㄥ唴瀛橈紝瀹规槗OOM if (list.size() >= BATCH_COUNT) { diff --git a/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java b/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java index 8f54259..a6243fe 100644 --- a/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java +++ b/mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java @@ -48,6 +48,7 @@ import com.chinaztt.ztt.common.core.util.R; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -257,58 +258,41 @@ @Override public void importExcel(List<StructureData> list) { - 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()); - //} + if (CollectionUtil.isEmpty(list)) { + return; + } + for (StructureData data : list) { + List<Part> parts = partMapper.selectList(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getPartNo())); + Part part = parts.get(0); + if (part == null) { + throw new RuntimeException("闆朵欢鍙�:" + data.getPartNo() + "涓嶅瓨鍦�"); + } + Structure structure = baseMapper.selectOne(Wrappers.<Structure>lambdaQuery().eq(Structure::getPartId, part.getId())); + if (structure == null) { + structure = new Structure(); + BeanUtils.copyProperties(data, structure); + structure.setPartId(part.getId()); + structure.setActive(true); + structure.setBomTypeDb("M"); + structure.setIfsSync(false); + structure.setAlternativeNo("*"); + baseMapper.insert(structure); + } + List<Part> childParts = partMapper.selectList(Wrappers.<Part>lambdaQuery().eq(Part::getPartNo, data.getSonPartNo())); + Part childPart = childParts.get(0); + if (childPart == null) { + throw new RuntimeException("闆朵欢鍙�:" + data.getSonPartNo() + "涓嶅瓨鍦�"); + } + List<Operation> operations = operationMapper.selectList(Wrappers.<Operation>lambdaQuery().eq(Operation::getName, data.getOperationName())); + Operation operation = operations.get(0); + StructureComponent component = new StructureComponent(); + component.setStructureId(structure.getId()); + component.setPartId(childPart.getId()); + component.setPlanningMethod(childPart.getPlanningMethod()); + component.setQpa(new BigDecimal(1));// todo: 浜у搧缁撴瀯瀵煎叆鏁伴噺,杩樼己涓�涓鍙� + component.setOperationId(operation.getId()); + structureComponentMapper.insert(component); + } } @Override diff --git a/mes-web/src/main/resources/bootstrap.yml b/mes-web/src/main/resources/bootstrap.yml index 1d6e43d..8947b51 100644 --- a/mes-web/src/main/resources/bootstrap.yml +++ b/mes-web/src/main/resources/bootstrap.yml @@ -8,7 +8,7 @@ # password: postgres123 password: root2022 # 灏勯寮�鍙戞暟鎹簱 - url: jdbc:postgresql://127.0.0.1:5432/postgres + url: jdbc:postgresql://106.13.194.57:9015/postgres application: name: ztt-mes cloud: -- Gitblit v1.9.3