diff --git a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/roundness/MesTimeRoundnessService.java b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/roundness/MesTimeRoundnessService.java index 42ba47c..8e58d08 100644 --- a/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/roundness/MesTimeRoundnessService.java +++ b/modules/i3plus-ext-mes-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/apiservice/serviceimpl/base/roundness/MesTimeRoundnessService.java @@ -24,6 +24,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -74,18 +75,24 @@ public class MesTimeRoundnessService implements IRoundnessStrategy { return; } DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - Long createSeq = Long.parseLong(dateFormat.format(new Date())); - + long createSeq = Long.parseLong(dateFormat.format(new Date())); + Map> sortInfoMap = sortInfoList.stream().collect(Collectors.groupingBy(MesCustSortInfo::getCustPartNo)); + Map prodGroupDetailMap = details.stream().collect(Collectors.toMap(MesPartProdGroupDetail::getCustPartNo, Function.identity())); + Set softInfoKeySet = sortInfoMap.keySet(); //遍历零件生产组零件,过滤出 - for (MesPartProdGroupDetail detail : details) { + for (String softInfoKey : softInfoKeySet) { + MesPartProdGroupDetail detail = prodGroupDetailMap.get(softInfoKey); + if (detail == null){ + continue; + } //根据detail.id 获取 MesProdGroupPartBtoCount btoCountInfo = getByGroupPartId(detail.getId(), detail.getOrganizeCode()); //历史累计差异 double btoCount = btoCountInfo.getCurrentQty(); //获取圆整数量 double roundQty = detail.getRoundQty(); - List sortInfos = sortInfoList.stream().filter(info -> info.getCustPartNo().equals(detail.getCustPartNo())).collect(Collectors.toList()); - if (sortInfos.isEmpty()) { + List sortInfos = sortInfoMap.get(detail.getCustPartNo()); + if (sortInfos == null ||sortInfos.isEmpty()) { continue; } //本次排序需要的数量 @@ -116,7 +123,7 @@ public class MesTimeRoundnessService implements IRoundnessStrategy { mesWorkOrder.setFid(UUID.randomUUID().toString()); mesWorkOrder.setWorkOrderNo(resultList.get(0)); mesWorkOrder.setWorkOrderType(MesExtEnumUtil.ORDER_TYPE.BTO.getValue()); - mesWorkOrder.setWorkOrderSeq(createSeq.toString()); + mesWorkOrder.setWorkOrderSeq(Long.toString(createSeq)); //生产顺序号 【前缀(WOPS)+工厂号+产线+特殊符号#+10位流水 步长10】({prefix}{org}{prodLocation}{dynamicRule}{serialNo}) GenSerialNoModel proSeqGenSerialNoModel = new GenSerialNoModel(MesCommonConstant.MES_WORK_ORDER_PRODUCT_SEQ); proSeqGenSerialNoModel.setOrganizeCode(detail.getOrganizeCode()); @@ -171,9 +178,10 @@ public class MesTimeRoundnessService implements IRoundnessStrategy { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int hours = calendar.get(Calendar.HOUR_OF_DAY); + int minutes = calendar.get(Calendar.MINUTE); String shiftTime = String.format("%02d:%02d", hours, minutes); - if (shiftList == null || shiftList.isEmpty()) { + if (!shiftList.isEmpty()) { for (MesShift shift : shiftList) { String startTime = shift.getStartTime().replace(":", ""); String endTime = shift.getEndTime().replace(":", ""); @@ -254,9 +262,10 @@ public class MesTimeRoundnessService implements IRoundnessStrategy { String nowTime = String.format("%02d:%02d", hour, minute); //遍历窗口时间获取最新的窗口时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - List sortedTime = windowTimeList.stream().sorted(Comparator.comparing(MesPartProdGroupWindowTime::getWindowTime)).collect(Collectors.toList()); + //使用降序 + List sortedTime = windowTimeList.stream().sorted(Comparator.comparing(MesPartProdGroupWindowTime::getWindowTime,Comparator.reverseOrder())).collect(Collectors.toList()); for (MesPartProdGroupWindowTime time : sortedTime) { - if (nowTime.compareTo(time.getWindowTime()) < 0) { + if(Integer.parseInt(time.getWindowTime().replace(":","")) > Integer.parseInt(nowTime.replace(":",""))){ continue; } calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.getWindowTime().substring(0, 2))); @@ -266,7 +275,7 @@ public class MesTimeRoundnessService implements IRoundnessStrategy { return time; } Date lastRunTime = sdf.parse(time.getLastRunTime()); - if (dateCreateOrder.compareTo(lastRunTime) < 0) { + if (dateCreateOrder.before(lastRunTime)) { continue; } return time;