diff --git a/mes/hd/nladmin-system/src/main/java/org/nl/wms/product_manage/service/workorder/impl/IPdmProduceWorkorderServiceImpl.java b/mes/hd/nladmin-system/src/main/java/org/nl/wms/product_manage/service/workorder/impl/IPdmProduceWorkorderServiceImpl.java index 687aaa3b..71f3702f 100644 --- a/mes/hd/nladmin-system/src/main/java/org/nl/wms/product_manage/service/workorder/impl/IPdmProduceWorkorderServiceImpl.java +++ b/mes/hd/nladmin-system/src/main/java/org/nl/wms/product_manage/service/workorder/impl/IPdmProduceWorkorderServiceImpl.java @@ -173,6 +173,12 @@ public class IPdmProduceWorkorderServiceImpl extends ServiceImpl() + .set("workorder_status", WorkerOrderEnum.SEND.getCode()) + .set("down_id", SecurityUtils.getCurrentUserId()) + .set("down_name", SecurityUtils.getCurrentNickName()) + .set("down_time", new Date()) + .in("workorder_id", ids)); this.recordWorkOrder(OptionRecord.OptionEnum.UPDATE, ids.toArray(new String[0])); } @@ -247,120 +253,14 @@ public class IPdmProduceWorkorderServiceImpl extends ServiceImpl> read = excelReader.read(); - // 循环获取的数据 - List data = new ArrayList<>(); - Map errorMap = new HashMap(); - - List workprodures = new ArrayList<>(); - List materialSpecs = new ArrayList<>(); - List persons = new ArrayList<>(); - row: - for (int i = 0; i < read.size(); i++) { - List list = read.get(i); - if (ObjectUtil.isEmpty(list)) { continue; } - PdmProduceWorkorder workorder = new PdmProduceWorkorder(); - packageForm(workorder); - for (int j = 0; j < list.size(); j++) { - String col = String.valueOf(list.get(j)); - 解析cell: - { //如果是第一行 为生产日期 - if (i == 0 && j == 0) { - continue row; - } - //如果第一列包含规格二字 则为表头 结束内循环列 - if (j == 0 && col.contains("班次")) { - continue row; - } - if (j == 0) { - //物料 - workorder.setShift_type_scode(col.equals("晚班") ? "2" : "1"); - } - if (j == 1) { - //物料 - workorder.setPlanproduceend_date(col.substring(0, col.indexOf(" ")) + " 18:30:00"); - workorder.setPlanproducestart_date(col.substring(0, col.indexOf(" ")) + " 07:30:00"); - } - if (j == 2) { - //物料 - materialSpecs.add(col); - workorder.setMaterial_id(col); - } - if (j == 3) { - workprodures.add(col); - workorder.setWorkprocedure_id(col); - } - if (j == 4) { - //设备 A1_TW_ - workorder.setDevice_code("A1_TW_" + col.replaceAll("-", "_")); - } - if (j == 7) { - //单重 - BigDecimal bigDecimal = BigDecimal.valueOf(Double.valueOf(col) * 1000); - workorder.setMaterial_weight(bigDecimal.setScale(3, RoundingMode.HALF_UP)); - } - if (j == 8) { - persons.add(col); - workorder.setCurrent_produce_person_id(col); - } - if (j == 9) { - workorder.setPlan_qty(new BigDecimal(Long.valueOf(col))); - } - if (j == 13) { - workorder.setIs_needmove(col.equals("是") ? true : false); - } - } - } - if (CollectionUtils.isEmpty(errorMap)) { - data.add(workorder); - } + String name = file.getOriginalFilename(); + if (name.contains("推弯")){ + 推弯(inputStream); } - List tmp_material_specs = materialbaseService.list(new QueryWrapper().in("material_spec", materialSpecs)); - List tmp_sysUsers = userService.list(new QueryWrapper().in("person_name", persons)); - List tmp_workprocedure_names = workprocedureService.list(new QueryWrapper().in("workprocedure_name", workprodures)); - - Map collect = tmp_workprocedure_names.stream().collect(HashMap::new, (k, v) -> k.put(v.getWorkprocedure_name(), v), HashMap::putAll); - Map users = tmp_sysUsers.stream().collect(HashMap::new, (k, v) -> k.put(v.getPerson_name(), v), HashMap::putAll); - Map> materialspecs = tmp_material_specs.stream().collect(Collectors.groupingBy(MdMeMaterialbase::getMaterial_spec)); - for (int i = 0; i < data.size(); i++) { - PdmProduceWorkorder workorder = data.get(i); - SysUser sysUser = users.get(workorder.getCurrent_produce_person_id()); - if (sysUser==null){ - errorMap.put("第"+(i+1)+"行:","账号:"+workorder.getCurrent_produce_person_id()+"不存在"); - }else { - workorder.setCurrent_produce_person_id(sysUser.getUser_id()); - } - PdmBiWorkprocedure workprocedure = collect.get(workorder.getWorkprocedure_id()); - if (workprocedure==null){ - errorMap.put("第"+(i+1)+"行:","工序名称:"+workorder.getWorkprocedure_id()+"不存在"); - }else { - workorder.setWorkorder_id(workprocedure.getWorkprocedure_id()); - } - List mdMeMaterialbases = materialspecs.get(workorder.getMaterial_id()); - if (!CollectionUtils.isEmpty(mdMeMaterialbases)){ - if (mdMeMaterialbases.size() == 1){ - workorder.setMaterial_id(mdMeMaterialbases.get(0).getMaterial_id()); - }else { - Optional first = mdMeMaterialbases.stream().filter(mdMeMaterialbase -> mdMeMaterialbase.getMaterial_code().contains("S") - && Pattern.matches("^[0-9]*$", mdMeMaterialbase.getMaterial_name().substring(mdMeMaterialbase.getMaterial_name().length() - 1)) - ).findFirst(); - if (first.isPresent()){ - workorder.setMaterial_id(first.get().getMaterial_id()); - }else { - errorMap.put("第"+(i+1)+"行:","物料规格:"+workorder.getMaterial_id()+"不存在"); - } - } - }else { - errorMap.put("第"+(i+1)+"行:","物料规格:"+workorder.getMaterial_id()+"不存在"); - } - - } - if (!CollectionUtils.isEmpty(errorMap)) { - throw new BadRequestException(JSON.toJSONString(errorMap)); - } else { - this.saveBatch(data); + if (name.contains("综合")){ + 综合(inputStream); } + } catch (Exception e) { e.printStackTrace(); throw new BadRequestException(e.getMessage()); @@ -375,6 +275,279 @@ public class IPdmProduceWorkorderServiceImpl extends ServiceImpl> read = excelReader.read(); + // 循环获取的数据 + List data = new ArrayList<>(); + Map errorMap = new HashMap(); + + List workprodures = new ArrayList<>(); + List materialSpecs = new ArrayList<>(); + List persons = new ArrayList<>(); + row: + for (int i = 0; i < read.size(); i++) { + List list = read.get(i); + if (ObjectUtil.isEmpty(list)) { continue; } + PdmProduceWorkorder workorder = new PdmProduceWorkorder(); + packageForm(workorder); + for (int j = 0; j < list.size(); j++) { + String col = String.valueOf(list.get(j)); + 解析cell: + { //如果是第一行 为生产日期 + if (i == 0 && j == 0) { + continue row; + } + //如果第一列包含规格二字 则为表头 结束内循环列 + if (j == 0 && col.contains("班次")) { + continue row; + } + if (j == 0) { + //物料 + workorder.setShift_type_scode(col.equals("晚班") ? "2" : "1"); + } + if (j == 1) { + //物料 + workorder.setPlanproduceend_date(col.substring(0, col.indexOf(" ")) + " 18:30:00"); + workorder.setPlanproducestart_date(col.substring(0, col.indexOf(" ")) + " 07:30:00"); + } + if (j == 2) { + //物料 + materialSpecs.add(col); + workorder.setMaterial_id(col); + } + if (j == 3) { + workprodures.add(col); + workorder.setWorkprocedure_id(col); + } + if (j == 4) { + //设备 A1_TW_ + workorder.setDevice_code("A1_TW_" + col.replaceAll("-", "_")); + } + if (j == 7) { + //单重 + BigDecimal bigDecimal = BigDecimal.valueOf(Double.valueOf(col) * 1000); + workorder.setMaterial_weight(bigDecimal.setScale(3, RoundingMode.HALF_UP)); + } + if (j == 8) { + persons.add(col); + workorder.setCurrent_produce_person_id(col); + } + if (j == 9) { + workorder.setPlan_qty(new BigDecimal(Long.valueOf(col))); + } + if (j == 13) { + workorder.setIs_needmove(col.equals("是") ? true : false); + } + if (j == 14) { + workorder.setRemark(col); + } + } + } + if (CollectionUtils.isEmpty(errorMap)) { + data.add(workorder); + } + } + List tmp_material_specs = materialbaseService.list(new QueryWrapper().in("material_spec", materialSpecs)); + List tmp_sysUsers = userService.list(new QueryWrapper().in("person_name", persons)); + List tmp_workprocedure_names = workprocedureService.list(new QueryWrapper().in("workprocedure_name", workprodures)); + + Map collect = tmp_workprocedure_names.stream().collect(HashMap::new, (k, v) -> k.put(v.getWorkprocedure_name(), v), HashMap::putAll); + Map users = tmp_sysUsers.stream().collect(HashMap::new, (k, v) -> k.put(v.getPerson_name(), v), HashMap::putAll); + Map> materialspecs = tmp_material_specs.stream().collect(Collectors.groupingBy(MdMeMaterialbase::getMaterial_spec)); + for (int i = 0; i < data.size(); i++) { + PdmProduceWorkorder workorder = data.get(i); + SysUser sysUser = users.get(workorder.getCurrent_produce_person_id()); + if (sysUser==null){ + errorMap.put("第"+(i+1)+"行:","账号:"+workorder.getCurrent_produce_person_id()+"不存在"); + }else { + workorder.setCurrent_produce_person_id(sysUser.getUser_id()); + } + PdmBiWorkprocedure workprocedure = collect.get(workorder.getWorkprocedure_id()); + if (workprocedure==null){ + errorMap.put("第"+(i+1)+"行:","工序名称:"+workorder.getWorkprocedure_id()+"不存在"); + }else { + workorder.setWorkorder_id(workprocedure.getWorkprocedure_id()); + } + List mdMeMaterialbases = materialspecs.get(workorder.getMaterial_id()); + if (!CollectionUtils.isEmpty(mdMeMaterialbases)){ + if (mdMeMaterialbases.size() == 1){ + workorder.setMaterial_id(mdMeMaterialbases.get(0).getMaterial_id()); + }else { + Optional first = mdMeMaterialbases.stream().filter(mdMeMaterialbase -> mdMeMaterialbase.getMaterial_code().contains("S") + && Pattern.matches("^[0-9]*$", mdMeMaterialbase.getMaterial_name().substring(mdMeMaterialbase.getMaterial_name().length() - 1)) + ).findFirst(); + if (first.isPresent()){ + workorder.setMaterial_id(first.get().getMaterial_id()); + }else { + errorMap.put("第"+(i+1)+"行:","物料规格:"+workorder.getMaterial_id()+"不存在"); + } + } + }else { + errorMap.put("第"+(i+1)+"行:","物料规格:"+workorder.getMaterial_id()+"不存在"); + } + + } + if (!CollectionUtils.isEmpty(errorMap)) { + throw new BadRequestException(JSON.toJSONString(errorMap)); + } else { + this.saveBatch(data); + } + } + private void 综合(InputStream inputStream) { + ExcelReader excelReader = ExcelUtil.getReader(inputStream, 0); + List> read = excelReader.read(); + // 循环获取的数据 + List data = new ArrayList<>(); + Map errorMap = new HashMap(); + + List workprodures = new ArrayList<>(); + List materialSpecs = new ArrayList<>(); + List persons = new ArrayList<>(); + row: + for (int i = 0; i < read.size(); i++) { + List list = read.get(i); + if (ObjectUtil.isEmpty(list)) { continue; } + PdmProduceWorkorder workorder = new PdmProduceWorkorder(); + packageForm(workorder); + for (int j = 0; j < list.size(); j++) { + String col = String.valueOf(list.get(j)); + 解析cell: + { //如果是第一行 为生产日期 + if (i == 0 && j == 0) { + continue row; + } + //如果第一列包含规格二字 则为表头 结束内循环列 + if (j == 0 && col.contains("班次")) { + continue row; + } + if (j == 0) { + workorder.setShift_type_scode(col.equals("晚班") ? "2" : "1"); + } + if (j == 1) { + if (workorder.getShift_type_scode().equals("1")){ + workorder.setPlanproduceend_date(col.substring(0, col.indexOf(" ")) + " 18:30:00"); + workorder.setPlanproducestart_date(col.substring(0, col.indexOf(" ")) + " 07:30:00"); + }else { + workorder.setPlanproducestart_date(col.substring(0, col.indexOf(" ")) + " 18:30:00"); + workorder.setPlanproduceend_date(col.substring(0, col.indexOf(" ")) + " 07:30:00"); + } + } + if (j == 2) { + //物料 + materialSpecs.add(col); + workorder.setMaterial_id(col); + } + if (j == 4) { + workprodures.add(col); + workorder.setWorkprocedure_id(col); + } + if (j == 5) { + //设备 A1_TW_ + workorder.setDevice_code(col); + } + if (j == 8) { + //单重 + BigDecimal bigDecimal = BigDecimal.valueOf(Double.valueOf(col) * 1000); + workorder.setMaterial_weight(bigDecimal.setScale(3, RoundingMode.HALF_UP)); + } + if (j == 9) { + persons.add(col); + workorder.setCurrent_produce_person_id(col); + } + if (j == 10) { + workorder.setPlan_qty(new BigDecimal(Long.valueOf(col))); + } + if (j == 14) { + workorder.setIs_needmove(col.equals("是") ? true : false); + } + if (j == 15) { + workorder.setRemark(col); + } + } + } + if (CollectionUtils.isEmpty(errorMap)) { + data.add(workorder); + } + } + List tmp_material_specs = materialbaseService.list(new QueryWrapper().in("material_spec", materialSpecs)); + List tmp_sysUsers = userService.list(new QueryWrapper().in("person_name", persons)); + List tmp_workprocedure_names = workprocedureService.list(new QueryWrapper().in("workprocedure_name", workprodures)); + + Map collect = tmp_workprocedure_names.stream().collect(HashMap::new, (k, v) -> k.put(v.getWorkprocedure_name(), v), HashMap::putAll); + Map users = tmp_sysUsers.stream().collect(HashMap::new, (k, v) -> k.put(v.getPerson_name(), v), HashMap::putAll); + Map> materialspecs = tmp_material_specs.stream().collect(Collectors.groupingBy(MdMeMaterialbase::getMaterial_spec)); + for (int i = 0; i < data.size(); i++) { + PdmProduceWorkorder workorder = data.get(i); + SysUser sysUser = users.get(workorder.getCurrent_produce_person_id()); + if (sysUser==null){ + errorMap.put("第"+(i+1)+"行:","账号:"+workorder.getCurrent_produce_person_id()+"不存在"); + }else { + workorder.setCurrent_produce_person_id(sysUser.getUser_id()); + } + PdmBiWorkprocedure workprocedure = collect.get(workorder.getWorkprocedure_id()); + if (workprocedure==null){ + errorMap.put("第"+(i+1)+"行:","工序名称:"+workorder.getWorkprocedure_id()+"不存在"); + }else { + workorder.setWorkprocedure_id(workprocedure.getWorkprocedure_id()); + } + List mdMeMaterialbases = materialspecs.get(workorder.getMaterial_id()); + if (!CollectionUtils.isEmpty(mdMeMaterialbases)){ + if (mdMeMaterialbases.size() == 1){ + workorder.setMaterial_id(mdMeMaterialbases.get(0).getMaterial_id()); + }else { + Optional first = mdMeMaterialbases.stream().filter(mdMeMaterialbase -> mdMeMaterialbase.getMaterial_code().contains("S") + && Pattern.matches("^[0-9]*$", mdMeMaterialbase.getMaterial_name().substring(mdMeMaterialbase.getMaterial_name().length() - 1)) + ).findFirst(); + if (first.isPresent()){ + workorder.setMaterial_id(first.get().getMaterial_id()); + }else { + errorMap.put("第"+(i+1)+"行:","物料规格:"+workorder.getMaterial_id()+"不存在"); + } + } + }else { + errorMap.put("第"+(i+1)+"行:","物料规格:"+workorder.getMaterial_id()+"不存在"); + } + } + if (!CollectionUtils.isEmpty(errorMap)) { + throw new BadRequestException(JSON.toJSONString(errorMap)); + } else { + List workprocedures = data.stream().map(PdmProduceWorkorder::getWorkprocedure_id).collect(Collectors.toList()); + List list = deviceService.list(new QueryWrapper() + .in("workprocedure_id", workprocedures) + ); + Map> listMap = list.stream().collect(Collectors.groupingBy(PdmBiDevice::getWorkprocedure_id)); + for (int i = 0; i < data.size(); i++) { + PdmProduceWorkorder item = data.get(i); + List devices = listMap.get(item.getWorkprocedure_id()); + if (item.getWorkprocedure_id().equals("1535144356586165920")){ + item.setDevice_code("A1_DC_" + item.getDevice_code().replaceAll("-", "_")); + }else if (item.getWorkprocedure_id().equals("1535143882327724032")){ + item.setDevice_code("A1_XY_" + item.getDevice_code().replaceAll("-", "_")); + } else { + List deviceCollect = devices.stream().filter(pdmBiDevice -> { + String device_code = pdmBiDevice.getDevice_code(); + int indexOf = device_code.lastIndexOf("_"); + String substring = device_code.substring(indexOf+1); + return Integer.valueOf(substring).equals(Integer.valueOf(item.getDevice_code())); + }).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(deviceCollect) || deviceCollect.size()>1){ + errorMap.put("第"+(i+1)+"行:","设备名称:"+item.getDevice_code()+"不存在了!!"); + }else { + item.setDevice_code(deviceCollect.get(0).getDevice_code()); + } + } + } + + if (!CollectionUtils.isEmpty(errorMap)) { + throw new BadRequestException(JSON.toJSONString(errorMap)); + }else { + this.saveBatch(data); + + } + } + } + private void packageForm(PdmProduceWorkorder workorder) { workorder.setWorkorder_id(IdUtil.getStringId()); workorder.setWorkorder_code(CodeUtil.getNewCode("PDM_SHIFTORDER"));