diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/excel/jx/UpdatePartExtExcelService.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/excel/jx/UpdatePartExtExcelService.java new file mode 100644 index 0000000..313b25e --- /dev/null +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/excel/jx/UpdatePartExtExcelService.java @@ -0,0 +1,903 @@ +package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel.jx; + +import cn.estsh.i3plus.ext.mes.api.base.IExcelImportExtService; +import cn.estsh.i3plus.ext.mes.api.base.IPartExtDataService; +import cn.estsh.i3plus.ext.mes.api.base.bu.IMesTravelMenuFieldConfigService; +import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.CommonExtService; +import cn.estsh.i3plus.ext.mes.pojo.bean.MesModuleFileImportLot; +import cn.estsh.i3plus.ext.mes.pojo.bean.MesPartExt; +import cn.estsh.i3plus.ext.mes.pojo.bean.MesTravelMenuFieldConfig; +import cn.estsh.i3plus.ext.mes.pojo.model.ExcelImportErrorExtModel; +import cn.estsh.i3plus.ext.mes.pojo.model.ExcelImportResultExtModel; +import cn.estsh.i3plus.ext.mes.pojo.model.MesPartExtModel; +import cn.estsh.i3plus.ext.mes.pojo.repository.MesModuleFileImportLotRepository; +import cn.estsh.i3plus.ext.mes.pojo.repository.MesPartExtRepository; +import cn.estsh.i3plus.ext.mes.pojo.util.ConvertBeanExt; +import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords; +import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil; +import cn.estsh.i3plus.mes.apiservice.util.MesCommonUtil; +import cn.estsh.i3plus.platform.common.convert.ConvertBean; +import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum; +import cn.estsh.i3plus.platform.common.tool.MathOperation; +import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; +import cn.estsh.i3plus.pojo.base.enumutil.MesEnumUtil; +import cn.estsh.i3plus.pojo.mes.bean.MesPartCategory; +import cn.estsh.i3plus.pojo.mes.repository.MesPartCategoryRepository; +import cn.estsh.i3plus.pojo.mes.repository.MesPartProduceTypeRepository; +import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; +import org.apache.poi.ss.usermodel.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author yumingxing + * @version 1.0 + * @date 2021/4/13 13:09 + **/ +@Service +public class UpdatePartExtExcelService implements IExcelImportExtService { + + @Autowired + private MesPartCategoryRepository partCategoryRepository; + + @Autowired + private MesPartExtRepository partExtRepository; + + @Autowired + private MesPartProduceTypeRepository partProduceTypeRepository; + + @Autowired + private MesModuleFileImportLotRepository moduleFileImportLotRepository; + + @Autowired + private CommonExtService commonExtService; + + @Autowired + private IMesTravelMenuFieldConfigService travelMenuFieldConfigService; + + @Autowired + private IPartExtDataService partExtDataService; + + @Override + public ExcelImportResultExtModel insertDataByExcel(Workbook workbook, String organizeCode, String userName) { + ExcelImportResultExtModel excelImportResultModel = this.sheetExtractMesPart(workbook.getSheetAt(0), organizeCode, userName); + this.insertExcelMesPart(excelImportResultModel); + return excelImportResultModel; + } + + private ExcelImportResultExtModel sheetExtractMesPart(Sheet sheetAt, String organizeCode, String userName) { + //从0行开始读取 + int totalNumberOfRows = sheetAt.getLastRowNum() + 1; + + //批次号 + String lotNo = getCellData(getExcelRow(sheetAt, 3), 1, "B", "批次号", 3, false, "checkLotNoMethod", organizeCode); + + //MesPartExt集合 + List partExtList = new ArrayList<>(); + + //成功数量 + Integer successRowNum = 0; + //失败数量 + Integer failRowNum = 0; + //错误的行号 + String errorRows = ""; + + //错误行信息集合 + List excelImportErrorExtModels = new ArrayList<>(); + + //用于EXCEL表中的物料代码唯一校验,key:partNo,value:row + Map existMap = new HashMap<>(); + + List partList = partExtRepository.findByProperty( + new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED}, + new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()}); + Map> partNoMap = CollectionUtils.isEmpty(partList) ? null : + partList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesPartExt::getPartNo)); + + List partCategoryList = partCategoryRepository.findByProperty( + new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID}, + new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue()}); + Map> partCategoryMap = CollectionUtils.isEmpty(partCategoryList) ? null : + partCategoryList.stream().filter(o -> null != o).collect(Collectors.groupingBy(o -> o.getCategoryCode() + "&" + o.getCategoryType())); + + List travelMenuFieldConfigList = travelMenuFieldConfigService.getTravelMenuFieldConfigList(organizeCode, MesExtEnumUtil.FIELD_MENU_TYPE.PART.getValue()); + + Map partProduceTypeEntityMap; + try { + partProduceTypeEntityMap = MesCommonUtil.getCodeEntityMap(partProduceTypeRepository, MesExtConstWords.PPT_CODE, organizeCode, "产品生产类型表"); + } catch (Exception var84) { + partProduceTypeEntityMap = null; + } + + //从excel表的第5行数据开始导入,getFirstRowNum是从0行开始读取 + for (int i = (sheetAt.getFirstRowNum() + 4); i < totalNumberOfRows; i ++) { + Row row = sheetAt.getRow(i); + //空行跳过 + if (null == row) { + continue; + } + //获取总列数 + Short lastCellNum = row.getLastCellNum(); + if (lastCellNum > 0) { + + int rowNum = i + 1; //当前行号 + int errorNum = 0; //错误数量 + String cellNum = ""; //错误列号 + String errorInfo = ""; //错误信息 + + //物料代码 + String partNo; + try { + partNo = new DataFormatter().formatCellValue(row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + continue; + } + + //物料名称 + String partName = null; + try { + partName = new DataFormatter().formatCellValue(row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //物料简称 + String briefText = null; + try { + briefText = new DataFormatter().formatCellValue(row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //单位 + String unit = null; + try { + unit = new DataFormatter().formatCellValue(row.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //物料类型1 + String categoryCode1 = null; + try { + categoryCode1 = new DataFormatter().formatCellValue(row.getCell(4, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //物料类型2 + String categoryCode2 = null; + try { + categoryCode2 = new DataFormatter().formatCellValue(row.getCell(5, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //物料类型3 + String categoryCode3 = null; + try { + categoryCode3 = new DataFormatter().formatCellValue(row.getCell(6, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //产品编码匹配类型 + String processMatchType = null; + try { + processMatchType = new DataFormatter().formatCellValue(row.getCell(7, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //产品编码匹配类型 + String productMatchType = null; + try { + productMatchType = new DataFormatter().formatCellValue(row.getCell(8, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //包装编码匹配类型 + String packageMatchType = null; + try { + packageMatchType = new DataFormatter().formatCellValue(row.getCell(9, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //包装数量 + String qty2 = null; + try { + qty2 = new DataFormatter().formatCellValue(row.getCell(10, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //产品生产类型 + String pptCode = null; + try { + pptCode = new DataFormatter().formatCellValue(row.getCell(11, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //颜色代码 + String colorCode = null; + try { + colorCode = new DataFormatter().formatCellValue(row.getCell(12, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //颜色名称 + String colorName = null; + try { + colorName = new DataFormatter().formatCellValue(row.getCell(13, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //销售向 + String salesTo = null; + try { + salesTo = new DataFormatter().formatCellValue(row.getCell(14, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //是否出货检验 + String isOqc = null; + try { + isOqc = new DataFormatter().formatCellValue(row.getCell(15, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //是否生成条码 + String isCreateSn = null; + try { + isCreateSn = new DataFormatter().formatCellValue(row.getCell(16, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //是否PS部件 + String isPSParts = null; + try { + isPSParts = new DataFormatter().formatCellValue(row.getCell(17, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //标准工数(min) + String standardWork = null; + try { + standardWork = new DataFormatter().formatCellValue(row.getCell(18, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //日文描述 + String japanDesc = null; + try { + japanDesc = new DataFormatter().formatCellValue(row.getCell(19, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //商品码 + String goodsCode = null; + try { + goodsCode = new DataFormatter().formatCellValue(row.getCell(20, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //前缀 + String prefix = null; + try { + prefix = new DataFormatter().formatCellValue(row.getCell(21, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //质保书码 + String qualityAssureCode = null; + try { + qualityAssureCode = new DataFormatter().formatCellValue(row.getCell(22, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //物料识别码 + String identifyCode = null; + try { + identifyCode = new DataFormatter().formatCellValue(row.getCell(23, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //条码末位数 + String snLastCode = null; + try { + snLastCode = new DataFormatter().formatCellValue(row.getCell(24, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //文件原名 + String fileOriginName = null; + try { + fileOriginName = new DataFormatter().formatCellValue(row.getCell(25, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //包装条码打印张数 + String packNoPrintTimes = null; + try { + packNoPrintTimes = new DataFormatter().formatCellValue(row.getCell(26, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //本体条码打印张数 + String snPrintTimes = null; + try { + snPrintTimes = new DataFormatter().formatCellValue(row.getCell(27, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //本体条码打印列数 + String printColumnNumber = null; + try { + printColumnNumber = new DataFormatter().formatCellValue(row.getCell(28, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //大本体条码匹配类型 + String bigProcessMatchType = null; + try { + bigProcessMatchType = new DataFormatter().formatCellValue(row.getCell(29, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //是否打印质保书 + String isPrintQualityAssureIndia = null; + try { + isPrintQualityAssureIndia = new DataFormatter().formatCellValue(row.getCell(30, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //仕向地代码 + String shiXiangDiCode = null; + try { + shiXiangDiCode = new DataFormatter().formatCellValue(row.getCell(31, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //型号 + String model = null; + try { + model = new DataFormatter().formatCellValue(row.getCell(32, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //品番 + String productNumber = null; + try { + productNumber = new DataFormatter().formatCellValue(row.getCell(33, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //大包装条码张数 + String snPackagePrintColumnNumber = null; + try { + snPackagePrintColumnNumber = new DataFormatter().formatCellValue(row.getCell(34, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //大包装条码匹配类型 + String bigPackageMatchType = null; + try { + bigPackageMatchType = new DataFormatter().formatCellValue(row.getCell(35, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //是否补件确认 + String isRepairWorkReport = null; + try { + isRepairWorkReport = new DataFormatter().formatCellValue(row.getCell(36, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + //是否可手动报工 + String isManualReport = null; + try { + isManualReport = new DataFormatter().formatCellValue(row.getCell(37, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)).trim(); + } catch (Exception e) { + } + + boolean isExist = false; + //校验物料代码不重复 + if (!existMap.containsKey(partNo)) { + existMap.put(partNo, String.valueOf(rowNum)); + //校验 物料代码 是否已经存在数据库 + if (CollectionUtils.isEmpty(partNoMap) || !partNoMap.containsKey(partNo)) { + errorNum ++; + cellNum += "A;"; + errorInfo += "第A列数据" + partNo + "重复不存在;"; + } + } else { + errorNum ++; + cellNum += "A;"; + errorInfo += "第A列数据跟第" + existMap.get(partNo) + "行的第A列数据重复;"; + } + + if (StringUtils.isEmpty(partName)) { + ++errorNum; + cellNum = cellNum + "B;"; + errorInfo = errorInfo + "第B列数据必填;"; + } + + if (StringUtils.isEmpty(categoryCode1)) { + ++errorNum; + cellNum = cellNum + "E;"; + errorInfo = errorInfo + "第E列数据必填;"; + } else if (!StringUtils.isEmpty(categoryCode1) && (CollectionUtils.isEmpty(partCategoryMap) || !CollectionUtils.isEmpty(partCategoryMap) && !partCategoryMap.containsKey(categoryCode1 + "&" + MesEnumUtil.PART_CATEGORY_TYPE.CATEGORY_ONE.getValue()))) { + ++errorNum; + cellNum = cellNum + "E;"; + errorInfo = errorInfo + "第E列数据无效;"; + } + + if (!StringUtils.isEmpty(categoryCode2) && (CollectionUtils.isEmpty(partCategoryMap) || !CollectionUtils.isEmpty(partCategoryMap) && !partCategoryMap.containsKey(categoryCode2 + "&" + MesEnumUtil.PART_CATEGORY_TYPE.CATEGORY_TWO.getValue()))) { + ++errorNum; + cellNum = cellNum + "F;"; + errorInfo = errorInfo + "第F列数据无效;"; + } + + if (!StringUtils.isEmpty(categoryCode3) && (CollectionUtils.isEmpty(partCategoryMap) || !CollectionUtils.isEmpty(partCategoryMap) && !partCategoryMap.containsKey(categoryCode3 + "&" + MesEnumUtil.PART_CATEGORY_TYPE.CATEGORY_THREE.getValue()))) { + ++errorNum; + cellNum = cellNum + "G;"; + errorInfo = errorInfo + "第G列数据无效;"; + } + + if (!StringUtils.isEmpty(processMatchType) && StringUtils.isEmpty(MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(processMatchType))) { + ++errorNum; + cellNum = cellNum + "H;"; + errorInfo = errorInfo + "第H列数据无效;"; + } + + if (!StringUtils.isEmpty(productMatchType) && StringUtils.isEmpty(MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(productMatchType))) { + ++errorNum; + cellNum = cellNum + "I;"; + errorInfo = errorInfo + "第I列数据无效;"; + } + + if (!StringUtils.isEmpty(packageMatchType) && StringUtils.isEmpty(MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(packageMatchType))) { + ++errorNum; + cellNum = cellNum + "J;"; + errorInfo = errorInfo + "第J列数据无效;"; + } + + if (!StringUtils.isEmpty(qty2)) { + try { + Integer.valueOf(qty2); + } catch (NumberFormatException var83) { + ++errorNum; + cellNum = cellNum + "K;"; + errorInfo = errorInfo + "第K列数据无效;"; + } + } + + if (!StringUtils.isEmpty(pptCode) && (CollectionUtils.isEmpty(partProduceTypeEntityMap) || !CollectionUtils.isEmpty(partProduceTypeEntityMap) && !partProduceTypeEntityMap.containsKey(pptCode))) { + ++errorNum; + cellNum = cellNum + "L;"; + errorInfo = errorInfo + "第L列数据无效;"; + } + + if (!StringUtils.isEmpty(salesTo) && StringUtils.isEmpty(MesExtEnumUtil.SALES_TO.descriptionOfValue(salesTo))) { + ++errorNum; + cellNum = cellNum + "O;"; + errorInfo = errorInfo + "第O列数据无效;"; + } + + if (StringUtils.isEmpty(isOqc)) { + ++errorNum; + cellNum = cellNum + "P;"; + errorInfo = errorInfo + "第P列数据必填;"; + } else { + if (StringUtils.isEmpty(CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isOqc))) { + ++errorNum; + cellNum = cellNum + "P"; + errorInfo = errorInfo + "第P列数据无效;"; + } + } + + if (StringUtils.isEmpty(isCreateSn)) { + ++errorNum; + cellNum = cellNum + "Q;"; + errorInfo = errorInfo + "第Q列数据必填;"; + } else { + if (StringUtils.isEmpty(CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isCreateSn))) { + ++errorNum; + cellNum = cellNum + "Q"; + errorInfo = errorInfo + "第Q列数据无效;"; + } + } + + if (StringUtils.isEmpty(isPSParts)) { + ++errorNum; + cellNum = cellNum + "R;"; + errorInfo = errorInfo + "第R列数据必填;"; + } else { + if (StringUtils.isEmpty(CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isPSParts))) { + ++errorNum; + cellNum = cellNum + "R"; + errorInfo = errorInfo + "第R列数据无效;"; + } + } + + if (!StringUtils.isEmpty(standardWork)) { + try { + if (MathOperation.compareTo(Double.valueOf(standardWork), new Double(0)) < 0) { + errorNum++; + cellNum += "S;"; + errorInfo += "第S列数据不能小于0;"; + } + String[] standardWorkArr = standardWork.split(MesExtConstWords.DECIMAL_POINT); + if (null != standardWorkArr && standardWorkArr.length == 2 && standardWorkArr[1].length() > 2) { + errorNum++; + cellNum += "S;"; + errorInfo += "第S列数据无效,最多2位小数;"; + } + } catch (NumberFormatException e) { + errorNum ++; + cellNum += "S;"; + errorInfo += "第S列数据无效;"; + } + } + + //校验文件原名 + if (!StringUtils.isEmpty(fileOriginName)) { + if (!fileOriginName.contains(".")) { + errorNum ++; + cellNum += "Z;"; + errorInfo += "第Z列数据无效;"; + } else { + String fileType = fileOriginName.substring(fileOriginName.lastIndexOf(".")); + if (StringUtils.isEmpty(fileType) || (!fileType.equals(".jpg") && !fileType.equals(".jpeg") && !fileType.equals(".png"))) { + errorNum ++; + cellNum += "Z;"; + errorInfo += "第Z列数据无效;"; + } + } + } + + if(!StringUtils.isEmpty(packNoPrintTimes)){ + try { + Integer packNoPrintTimesNumber = Integer.valueOf(packNoPrintTimes); + if(packNoPrintTimesNumber <= 0){ + ++errorNum; + cellNum = cellNum + "AA;"; + errorInfo = errorInfo + "第AA列数据无效;"; + } + } catch (NumberFormatException var83) { + ++errorNum; + cellNum = cellNum + "AA;"; + errorInfo = errorInfo + "第AA列数据无效;"; + } + } + + if(!StringUtils.isEmpty(snPrintTimes)){ + try { + Integer snPrintTimesNumber = Integer.valueOf(snPrintTimes); + if(snPrintTimesNumber <= 0){ + ++errorNum; + cellNum = cellNum + "AB;"; + errorInfo = errorInfo + "第AB列数据无效;"; + } + } catch (NumberFormatException var83) { + ++errorNum; + cellNum = cellNum + "AB;"; + errorInfo = errorInfo + "第AB列数据无效;"; + } + } + + if (!StringUtils.isEmpty(printColumnNumber)) { + try { + Integer snPrintTimesNumber = Integer.valueOf(printColumnNumber); + if(snPrintTimesNumber <= 0){ + ++errorNum; + cellNum = cellNum + "AC;"; + errorInfo = errorInfo + "第AC列数据无效;"; + } + } catch (NumberFormatException var83) { + ++errorNum; + cellNum = cellNum + "AC;"; + errorInfo = errorInfo + "第AC列数据无效;"; + } + } + + if (!StringUtils.isEmpty(bigProcessMatchType)) { + if (StringUtils.isEmpty(MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(bigProcessMatchType))) { + ++errorNum; + cellNum = cellNum + "AD;"; + errorInfo = errorInfo + "第AD列数据无效;"; + } + } + + if(StringUtils.isEmpty(isPrintQualityAssureIndia)){ + ++errorNum; + cellNum = cellNum + "AE;"; + errorInfo = errorInfo + "第AE列数据必填;"; + }else if (StringUtils.isEmpty(MesExtEnumUtil.IS_PRINT_QUALITY_ASSURE_INDIA.valueOfDescription(Integer.parseInt(isPrintQualityAssureIndia)))){ + ++errorNum; + cellNum = cellNum + "AE;"; + errorInfo = errorInfo + "第AE列数据无效;"; + } + + if (!StringUtils.isEmpty(snPackagePrintColumnNumber)) { + try { + Integer snPrintTimesNumber = Integer.valueOf(snPackagePrintColumnNumber); + if(snPrintTimesNumber <= 0){ + ++errorNum; + cellNum = cellNum + "AI;"; + errorInfo = errorInfo + "第AI列数据无效;"; + } + } catch (NumberFormatException var83) { + ++errorNum; + cellNum = cellNum + "AI;"; + errorInfo = errorInfo + "第AI列数据无效;"; + } + } + + if (!StringUtils.isEmpty(bigPackageMatchType) && StringUtils.isEmpty(MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(bigPackageMatchType))) { + ++errorNum; + cellNum = cellNum + "AJ;"; + errorInfo = errorInfo + "第AJ列数据无效;"; + } + + if (!StringUtils.isEmpty(isRepairWorkReport) && StringUtils.isEmpty(MesExtEnumUtil.IS_REPAIR_WORK_REPORT.valueOfDescription(Integer.parseInt(isRepairWorkReport)))) { + ++errorNum; + cellNum = cellNum + "AK;"; + errorInfo = errorInfo + "第AK列数据无效;"; + } + + if (!StringUtils.isEmpty(isManualReport) && StringUtils.isEmpty(MesExtEnumUtil.IS_MANUAL_REPORT.valueOfDescription(Integer.parseInt(isManualReport)))) { + ++errorNum; + cellNum = cellNum + "AL;"; + errorInfo = errorInfo + "第AL列数据无效;"; + } + + if (errorNum == 0) { + + MesPartExt mesPart = (MesPartExt) ((List) partNoMap.get(partNo)).get(0); + ConvertBean.serviceModelUpdate(mesPart, userName); + if(!CollectionUtils.isEmpty(travelMenuFieldConfigList)){ + MesPartExt newPartExt = new MesPartExt(); + newPartExt.setPartNo(partNo); + newPartExt.setPartName(partName); + newPartExt.setBriefText(StringUtils.isEmpty(briefText) ? null : briefText); + newPartExt.setUnit(unit); + newPartExt.setCategoryCode1(categoryCode1); + newPartExt.setCategoryCode2(StringUtils.isEmpty(categoryCode2) ? null : categoryCode2); + newPartExt.setCategoryCode3(StringUtils.isEmpty(categoryCode3) ? null : categoryCode3); + newPartExt.setProcessMatchType(StringUtils.isEmpty(processMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(processMatchType)); + newPartExt.setProductMatchType(StringUtils.isEmpty(productMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(productMatchType)); + newPartExt.setPackageMatchType(StringUtils.isEmpty(packageMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(packageMatchType)); + newPartExt.setQty2(StringUtils.isEmpty(qty2) ? null : Double.parseDouble(qty2)); + newPartExt.setPptCode(pptCode); + newPartExt.setColorCode(colorCode); + newPartExt.setColorName(colorName); + newPartExt.setSalesTo(!StringUtils.isEmpty(salesTo) ? String.valueOf(MesExtEnumUtil.SALES_TO.descriptionOfValue(salesTo)) : null); + newPartExt.setIsOqc(!StringUtils.isEmpty(isOqc) ? CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isOqc) : null); + newPartExt.setIsCreateSn(!StringUtils.isEmpty(isCreateSn) ? CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isCreateSn) : null); + newPartExt.setIsPSParts(!StringUtils.isEmpty(isPSParts) ? CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isPSParts) : null); + newPartExt.setStandardWork(StringUtils.isEmpty(standardWork) ? null : Double.parseDouble(standardWork)); + newPartExt.setJapanDesc(japanDesc); + newPartExt.setGoodsCode(goodsCode); + newPartExt.setPrefix(prefix); + newPartExt.setQualityAssureCode(qualityAssureCode); + newPartExt.setIdentifyCode(identifyCode); + newPartExt.setSnLastCode(snLastCode); + newPartExt.setFileOriginName(fileOriginName); + newPartExt.setOrganizeCode(organizeCode); + newPartExt.setSnPrintTimes(StringUtils.isEmpty(snPrintTimes) ? null :Integer.valueOf(snPrintTimes)); + newPartExt.setPackNoPrintTimes(StringUtils.isEmpty(packNoPrintTimes) ? null :Integer.valueOf(packNoPrintTimes)); + newPartExt.setBigProcessMatchType(StringUtils.isEmpty(bigProcessMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(bigProcessMatchType)); + newPartExt.setSnPrintColumnNumber(StringUtils.isEmpty(printColumnNumber) ? null : Integer.valueOf(printColumnNumber)); + newPartExt.setIsPrintQualityAssureIndia(Integer.parseInt(isPrintQualityAssureIndia)); + mesPart.setShiXiangDiCode(shiXiangDiCode); + mesPart.setModel(model); + mesPart.setProductNumber(productNumber); + mesPart.setSnPackagePrintColumnNumber(StringUtils.isEmpty(snPackagePrintColumnNumber) ? 0 : Integer.parseInt(snPackagePrintColumnNumber)); + mesPart.setBigPackageMatchType(StringUtils.isEmpty(bigPackageMatchType) ? MesExtEnumUtil.ENCODE_MATCH_TYPE.PART.getValue() : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(bigPackageMatchType)); + mesPart.setIsRepairWorkReport(StringUtils.isEmpty(isRepairWorkReport) ? MesExtEnumUtil.IS_REPAIR_WORK_REPORT.YES.getValue() : Integer.parseInt(isRepairWorkReport)); + + List fields = travelMenuFieldConfigList.stream().map(MesTravelMenuFieldConfig::getFieldCode).distinct().collect(Collectors.toList()); + partExtDataService.doRecordChangeData(partExtDataService.getModel(mesPart), partExtDataService.getModel(newPartExt), MesPartExtModel.class, fields); + } + + mesPart.setPartNo(partNo); + mesPart.setPartName(partName); + mesPart.setBriefText(StringUtils.isEmpty(briefText) ? null : briefText); + mesPart.setUnit(unit); + mesPart.setCategoryCode1(categoryCode1); + mesPart.setCategoryCode2(StringUtils.isEmpty(categoryCode2) ? null : categoryCode2); + mesPart.setCategoryCode3(StringUtils.isEmpty(categoryCode3) ? null : categoryCode3); + mesPart.setProcessMatchType(StringUtils.isEmpty(processMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(processMatchType)); + mesPart.setProductMatchType(StringUtils.isEmpty(productMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(productMatchType)); + mesPart.setPackageMatchType(StringUtils.isEmpty(packageMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(packageMatchType)); + mesPart.setQty2(StringUtils.isEmpty(qty2) ? null : Double.parseDouble(qty2)); + mesPart.setPptCode(pptCode); + mesPart.setColorCode(colorCode); + mesPart.setColorName(colorName); + mesPart.setSalesTo(!StringUtils.isEmpty(salesTo) ? String.valueOf(MesExtEnumUtil.SALES_TO.descriptionOfValue(salesTo)) : null); + mesPart.setIsOqc(!StringUtils.isEmpty(isOqc) ? CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isOqc) : null); + mesPart.setIsCreateSn(!StringUtils.isEmpty(isCreateSn) ? CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isCreateSn) : null); + mesPart.setIsPSParts(!StringUtils.isEmpty(isPSParts) ? CommonEnumUtil.TRUE_OR_FALSE.descriptionOfValue(isPSParts) : null); + mesPart.setStandardWork(StringUtils.isEmpty(standardWork) ? null : Double.parseDouble(standardWork)); + mesPart.setJapanDesc(japanDesc); + mesPart.setGoodsCode(goodsCode); + mesPart.setPrefix(prefix); + mesPart.setQualityAssureCode(qualityAssureCode); + mesPart.setIdentifyCode(identifyCode); + mesPart.setSnLastCode(snLastCode); + mesPart.setFileOriginName(fileOriginName); + mesPart.setLotNo(lotNo); + mesPart.setOrganizeCode(organizeCode); + mesPart.setPartNoExt(partNo); + mesPart.setSnPrintTimes(StringUtils.isEmpty(snPrintTimes) ? null :Integer.valueOf(snPrintTimes)); + mesPart.setPackNoPrintTimes(StringUtils.isEmpty(packNoPrintTimes) ? null :Integer.valueOf(packNoPrintTimes)); + mesPart.setBigProcessMatchType(StringUtils.isEmpty(bigProcessMatchType) ? null : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(bigProcessMatchType)); + mesPart.setSnPrintColumnNumber(StringUtils.isEmpty(printColumnNumber) ? null : Integer.valueOf(printColumnNumber)); + mesPart.setIsPrintQualityAssureIndia(Integer.parseInt(isPrintQualityAssureIndia)); + mesPart.setShiXiangDiCode(shiXiangDiCode); + mesPart.setModel(model); + mesPart.setProductNumber(productNumber); + mesPart.setSnPackagePrintColumnNumber(StringUtils.isEmpty(snPackagePrintColumnNumber) ? 0 : Integer.parseInt(snPackagePrintColumnNumber)); + mesPart.setBigPackageMatchType(StringUtils.isEmpty(bigPackageMatchType) ? MesExtEnumUtil.ENCODE_MATCH_TYPE.PART.getValue() : MesExtEnumUtil.ENCODE_MATCH_TYPE.descriptionOfValue(bigPackageMatchType)); + mesPart.setIsRepairWorkReport(StringUtils.isEmpty(isRepairWorkReport) ? MesExtEnumUtil.IS_REPAIR_WORK_REPORT.YES.getValue() : Integer.parseInt(isRepairWorkReport)); + mesPart.setIsManualReport(StringUtils.isEmpty(isManualReport) ? MesExtEnumUtil.IS_MANUAL_REPORT.YES.getValue() : Integer.parseInt(isManualReport)); + new ConvertBeanExt(mesPart).convertBean(mesPart); + + partExtList.add(mesPart); + successRowNum = successRowNum + 1; + } else { + //封装错误行信息ExcelImportErrorExtModel + excelImportErrorExtModels = commonExtService.getExcelImportErrorModels(excelImportErrorExtModels, rowNum, errorNum, cellNum, errorInfo); + + errorRows += rowNum + ";"; + failRowNum ++; + } + } + } + + + //校验EXCEL数据 + commonExtService.checkExcelData(failRowNum, successRowNum, errorRows); + + //封装返回结果 + ExcelImportResultExtModel excelImportResultModel = commonExtService.getExcelImportResultModel(failRowNum, successRowNum, excelImportErrorExtModels, errorRows); + excelImportResultModel.setExcelList((failRowNum > 0) ? null : partExtList); + return excelImportResultModel; + } + + private void insertExcelMesPart(ExcelImportResultExtModel excelImportResultExtModel) { + if (null != excelImportResultExtModel) { + List excelList = excelImportResultExtModel.getExcelList(); + if (!CollectionUtils.isEmpty(excelList)) { + for (MesPartExt partExt : excelList) { + if(StringUtils.isEmpty(partExt.getId())){ + partExtRepository.insert(partExt); + }else{ + partExtRepository.save(partExt); + } + } + MesModuleFileImportLot lot = new MesModuleFileImportLot(); + lot.setLotNo(excelList.get(0).getLotNo()); + lot.setModule(MesExtEnumUtil.BATCH_FILE_IMPORT_MODULE.PART.getValue()); + lot.setOrganizeCode(excelList.get(0).getOrganizeCode()); + ConvertBean.serviceModelInitialize(lot, excelList.get(0).getCreateUser()); + moduleFileImportLotRepository.insert(lot); + } + } + } + + /** + * 获取EXCEL的行数据 + * @param sheetAt + * @param i + * @return + */ + private Row getExcelRow(Sheet sheetAt, int i) { + if (i == 0) { + return null; + } + Row row = sheetAt.getRow(sheetAt.getFirstRowNum() + (i - 1)); + if (null == row) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("EXCEL表中第%s行为空", i) + .build(); + } + return row; + } + + /** + * 获取当前行每列的数据 + * @param row + * @param cell + * @param cellLetter + * @param cell + * @param fieldName + * @param checkNullFlag + * @return + */ + private String getCellData(Row row, int cell, String cellLetter, String fieldName, int rowNum, boolean checkNullFlag, String methodStr, Object... obj) { + String data = null; + try { + row.getCell(cell).setCellType(CellType.STRING); + data = row.getCell(cell, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim(); + } catch (Exception e) { + } + + checkDataNull(checkNullFlag, data, rowNum, cellLetter, fieldName); + + if (!StringUtils.isEmpty(methodStr)) { + Method method; + try { + method = this.getClass().getDeclaredMethod(methodStr, String.class, int.class, String.class, String.class, Object[].class); + method.setAccessible(true); + Object result = method.invoke(this, data, rowNum, cellLetter, fieldName, obj); + data = !StringUtils.isEmpty(result) ? result.toString() : data; + } catch (Exception e) { + InvocationTargetException targetEx = (InvocationTargetException) e; + Throwable trowEx = targetEx.getTargetException(); + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail(trowEx.getMessage()) + .build(); + } + } + return data; + } + + /** + * 数据判空 + * @param checkNullFlag + * @param data + * @param rowNum + * @param cellLetter + * @param fieldName + */ + private void checkDataNull(boolean checkNullFlag, String data, int rowNum, String cellLetter, String fieldName) { + if (checkNullFlag && StringUtils.isEmpty(data)) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("EXCEL表中第%s行%s列%s为空", rowNum, cellLetter, fieldName) + .build(); + } + } + + /** + * 批次号 + * @param data + * @param rowNum + * @param cellLetter + * @param fieldName + * @param obj -> organizeCode + * @return + */ + private String checkLotNoMethod(String data, int rowNum, String cellLetter, String fieldName, Object... obj){ + if (!StringUtils.isEmpty(data)) { + if (data.length() > 20) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("EXCEL表中第%s行%s列%长度超过20个字符", rowNum, cellLetter, fieldName) + .build(); + } + MesModuleFileImportLot lot = moduleFileImportLotRepository.getByProperty( + new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID, MesExtConstWords.LOT_NO, MesExtConstWords.MODULE}, + new Object[]{obj[0].toString(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), data, MesExtEnumUtil.BATCH_FILE_IMPORT_MODULE.PART.getValue()}); + if (null != lot) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("EXCEL表中第%s行%s列%s已存在数据库", rowNum, cellLetter, fieldName) + .build(); + } + } + return data; + } + +} diff --git a/modules/i3plus-ext-mes-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pojo/util/MesExtEnumUtil.java b/modules/i3plus-ext-mes-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pojo/util/MesExtEnumUtil.java index e2af113..5c1a87c 100644 --- a/modules/i3plus-ext-mes-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pojo/util/MesExtEnumUtil.java +++ b/modules/i3plus-ext-mes-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pojo/util/MesExtEnumUtil.java @@ -29,6 +29,7 @@ public class MesExtEnumUtil { MES_PRODUCT_ENCODE_CFG(100, "productEncodeCfgExtExcelService", "产品编码配置"), MES_PROCESS_CELL(110, "processCellExcelService", "工序工位关系"), MES_PART_EXT(120, "partExtExcelService", "物料信息"), + UPDATE_MES_PART_EXT(121, "updatePartExtExcelService", "仅修改物料信息"), MES_WEIGHT(130, "sxWeighExcelService", "称重信息"), MES_FOUR_M_MANAGE(140, "sxFourMManageExcelService", "4M管理表"), MES_FOUR_M_CONFIRM(150, "sxFourMConfirmExcelService", "4M确认表"),