diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java index 399594ea5..1ccdd7d7e 100644 --- a/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/pdm/subpackagerelation/service/impl/PdmBiSubpackagerelationServiceImpl.java @@ -17,7 +17,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.PageHelper; import lombok.SneakyThrows; import lombok.extern.log4j.Log4j; -import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.nl.b_lms.pdm.bi.slittingproductionplan.service.IPdmBiSlittingproductionplanService; import org.nl.b_lms.pdm.bi.slittingproductionplan.service.dao.PdmBiSlittingproductionplan; @@ -94,9 +94,6 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl ivtList = packageinfoivtService.list(new QueryWrapper().eq("container_name", whereJson.get("container_name").toString()).eq("ivt_status", PackageInfoIvtEnum.IVT_STATUS.code("合格品"))); - if (CollectionUtils.isEmpty(ivtList)) { + if (ObjectUtils.isEmpty(ivtList)) { throw new BadRequestException("该子卷未质检或品质不符合要求,请扫码质检!"); } if (ivtList.stream().noneMatch(r -> r.getPoint_status().equals(PackageInfoIvtEnum.POINT_STATUS.code("待检区")))) { @@ -247,12 +244,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl 10) { - throw new BadRequestException("子卷搬运任务数已达上限!"); - } + String deviceCode = getPointCode(packagerelationList.size()); try { List workIdList = JSONObject.parseArray(whereJson.getJSONArray("tableMater").toJSONString(), PdmBiSubpackagerelation.class).stream() .map(PdmBiSubpackagerelation::getWorkorder_id) @@ -267,7 +259,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl bstIvtPackageinfoivtList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper().eq(BstIvtPackageinfoivt::getPoint_status, "5").eq(BstIvtPackageinfoivt::getIs_used, "1").orderByAsc(BstIvtPackageinfoivt::getPoint_code)); - if (CollectionUtils.isEmpty(bstIvtPackageinfoivtList)) { + private String getPointCode(Integer entitySize) { + //装箱区对接位 + List bstIvtPackageinfoivtList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper().eq(BstIvtPackageinfoivt::getPoint_status, PackageInfoIvtEnum.POINT_STATUS.code("装箱位")).eq(BstIvtPackageinfoivt::getIs_used, IOSEnum.IS_NOTANDYES.code("是")).orderByAsc(BstIvtPackageinfoivt::getPoint_code)); + if (ObjectUtils.isEmpty(bstIvtPackageinfoivtList)) { throw new BadRequestException("没有可用的装箱区对接位"); } Map resultMap = new LinkedHashMap<>(); - //获取装箱位任务数量 - List> taskCount = bstIvtPackageinfoivtMapper.getPointTaskCount(); - if (taskCount != null) { - for (Map map : taskCount) { - Object pointCode2Obj = map.get("point_code2"); + Set zxIvtSet = bstIvtPackageinfoivtList.stream().map(BstIvtPackageinfoivt::getBlock).collect(Collectors.toSet()); + //装箱区任务数 + List> zxTaskCount = bstIvtPackageinfoivtMapper.getZxqTaskCount(zxIvtSet); + if (ObjectUtils.isNotEmpty(zxTaskCount)) { + for (Map map : zxTaskCount) { + String pointCode = map.get("point_code2").toString(); Object countObj = map.get("count"); - if (pointCode2Obj != null && countObj != null) { - String pointCode2 = pointCode2Obj.toString(); + if (pointCode != null && countObj != null) { Long countLong = (Long) countObj; - Integer count = countLong.intValue(); - resultMap.merge(pointCode2, count, Integer::sum); + List pointList = bstIvtPackageinfoivtList.stream().filter(r -> r.getBlock().equals(pointCode) || r.getPoint_code().equals(pointCode)).collect(Collectors.toList()); + if (ObjectUtils.isNotEmpty(pointList)) { + pointList.forEach(r -> { + if (r.getPoint_code().equals(pointCode) || r.getBlock().equals(pointCode)) { + resultMap.merge(pointList.get(0).getPoint_code(), countLong.intValue(), Integer::sum); + } + }); + } } } } + //装箱位有木箱也计算任务数 bstIvtPackageinfoivtList.stream() .sorted(Comparator.comparing(BstIvtPackageinfoivt::getSort_seq)) .forEach(p -> { - String key = p.getPoint_code(); int value = StringUtils.isNotBlank(p.getContainer_name()) ? 1 : 0; - resultMap.merge(key, value, Integer::sum); + resultMap.merge(p.getPoint_code(), value, Integer::sum); }); List> result = resultMap.entrySet().stream() .map(entry -> Collections.singletonMap(entry.getKey(), entry.getValue())) .collect(Collectors.toList()); + //任务数量超过10个不满足装箱任务创建 + result.removeIf(map -> { + Map.Entry entry = map.entrySet().iterator().next(); + return entry.getValue() + entitySize > 10; + }); //获取数量最少的点位 Optional minPointCode = result.stream() .min(Comparator.comparingInt(map -> map.entrySet().iterator().next().getValue())) .map(map -> map.keySet().iterator().next()); - return minPointCode.orElseGet(() -> bstIvtPackageinfoivtList.get(0).getPoint_code()); + return minPointCode.orElseThrow(() -> new BadRequestException("装箱区任务已满,请等待装箱任务完成再操作")); } @@ -512,9 +514,9 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl subList = this.list(new LambdaQueryWrapper().eq(PdmBiSubpackagerelation::getContainer_name, jo.getString("container_name"))); - if (CollectionUtils.isEmpty(subList)) { - List planList = iPdmBiSlittingproductionplanService.list(new LambdaQueryWrapper().eq(PdmBiSlittingproductionplan::getContainer_name, containerName).eq(PdmBiSlittingproductionplan::getIs_delete, IOSEnum.IS_NOTANDYES.code("否"))); - if (CollectionUtils.isEmpty(planList)) { + if (ObjectUtils.isEmpty(subList)) { + List planList = iPdmBiSlittingproductionplanService.list(new LambdaQueryWrapper().eq(PdmBiSlittingproductionplan::getContainer_name, containerName).eq(PdmBiSlittingproductionplan::getIs_delete, IOSEnum.IS_NOTANDYES.code("否"))); + if (ObjectUtils.isEmpty(planList)) { throw new BadRequestException("未查询到可用的分切计划!"); } PdmBiSlittingproductionplan plan = planList.get(0); @@ -564,7 +566,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl containerNameList.contains(r.getContainer_name())) .collect(Collectors.toList()); //任务组id - String groupId = deviceCode.substring(deviceCode.lastIndexOf("_") + 1); + String groupId = deviceCode.substring(deviceCode.indexOf("_") + 1, deviceCode.indexOf("_", deviceCode.indexOf("_") + 1)); RLock lock = redissonClient.getLock(groupId); boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS); try { @@ -575,7 +577,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl taskList = taskService.list(new LambdaQueryWrapper().eq(SchBaseTask::getVehicle_code, r.getContainer_name()).eq(SchBaseTask::getTask_type, PackageInfoIvtEnum.TASK_TYPE.code("待检区->装箱区")) .eq(SchBaseTask::getIs_delete, IOSEnum.IS_NOTANDYES.code("否")).lt(SchBaseTask::getTask_status, TaskStatusEnum.FINISHED.getCode())); - if (CollectionUtils.isEmpty(taskList)) { + if (ObjectUtils.isEmpty(taskList)) { JSONObject jo = new JSONObject(); //确定搬运任务不执行 jo.put("task_type", PackageInfoIvtEnum.TASK_TYPE.code("待检区->装箱区")); @@ -595,7 +597,7 @@ public class PdmBiSubpackagerelationServiceImpl extends ServiceImpl> getZxqTaskCount(Set groupIds); /** diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/point/dao/mapper/BstIvtPackageinfoivtMapper.xml b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/point/dao/mapper/BstIvtPackageinfoivtMapper.xml index bce455291..b42c76402 100644 --- a/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/point/dao/mapper/BstIvtPackageinfoivtMapper.xml +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/sch/point/dao/mapper/BstIvtPackageinfoivtMapper.xml @@ -10,16 +10,29 @@ AND t.task_status '07' GROUP BY t.point_code2 - + SELECT + CASE + WHEN t.task_type = '010704' THEN t.point_code2 + WHEN t.task_type = '010908' THEN t.vehicle_code2 + END AS point_code2, + COUNT(*) AS count FROM sch_base_task t - WHERE t.task_type = '010908' - AND t.vehicle_code2 = #{groupId} - AND t.task_status '07' - AND t.create_time >= DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%s') + WHERE + t.task_type IN ('010704', '010908') + AND t.create_time >= DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d %H:%i:%s') + AND t.task_status '07' + + AND (t.task_type != '010908' OR t.vehicle_code2 IN + #{code} + ) + + GROUP BY + CASE + WHEN t.task_type = '010704' THEN t.point_code2 + WHEN t.task_type = '010908' THEN t.vehicle_code2 + END - - -