完成龙兴发运看板

uat-temp-nht-202502180000-shippingkanban
jason 3 months ago
parent cb50635c6c
commit ff7b11e271

@ -1043,8 +1043,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) { if (CollectionUtils.isEmpty(strShippingGroupList)) {
values.add("0"); return Collections.singletonList("0");
return values;
} }
Date nowTime = DateUtil.now(); Date nowTime = DateUtil.now();
@ -1083,19 +1082,19 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
List<String> values = new ArrayList<>(); List<String> values = new ArrayList<>();
List<MesPartShippingGroup> partShippingGroups = getShippingGroups(cfg); List<MesPartShippingGroup> partShippingGroups = getShippingGroups(cfg);
if (CollectionUtils.isEmpty(partShippingGroups)) { if (CollectionUtils.isEmpty(partShippingGroups)) {
values.add("0"); return Collections.singletonList("0");
return values;
} }
Date nowTime = DateUtil.now(); Date nowTime = DateUtil.now();
Date prevHourTime = DateUtil.addMinutes(nowTime, -60); Date prevHourTime = DateUtil.addMinutes(nowTime, -60);
StringBuilder hql = new StringBuilder(); // Use a single query to fetch counts grouped by work center code
hql.append("select new map(workCenterCode, count(1) as totalCount) from " + MesProductionRecord.class.getName()); List<Map> productionCounts = entityManager.createQuery(
hql.append(" where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid "); "SELECT new map(pr.workCenterCode as workCenterCode, COUNT(pr) as totalCount) " +
hql.append(" and createDatetime BETWEEN :startDateTime AND :endDateTime "); "FROM " + MesProductionRecord.class.getName() + " pr " +
hql.append(" group by workCenterCode"); "WHERE pr.organizeCode = :organizeCode AND pr.isDeleted = :isDeleted AND pr.isValid = :isValid " +
List<Map> ddd = entityManager.createQuery(hql.toString()) "AND pr.createDatetime BETWEEN :startDateTime AND :endDateTime " +
"GROUP BY pr.workCenterCode", Map.class)
.setParameter("organizeCode", cfg.getOrganizeCode()) .setParameter("organizeCode", cfg.getOrganizeCode())
.setParameter("isValid", CommonEnumUtil.VALID) .setParameter("isValid", CommonEnumUtil.VALID)
.setParameter("isDeleted", CommonEnumUtil.FALSE) .setParameter("isDeleted", CommonEnumUtil.FALSE)
@ -1103,21 +1102,23 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
.setParameter("endDateTime", DateUtil.formatDate(prevHourTime)) .setParameter("endDateTime", DateUtil.formatDate(prevHourTime))
.getResultList(); .getResultList();
Map<String, String> shippingGroupCount = new HashMap<>(); // Use a map to store counts for quick access
if (!CollectionUtils.isEmpty(ddd)) { Map<String, String> shippingGroupCount = productionCounts.stream()
for (Map dd : ddd) { .collect(Collectors.toMap(
Object totalCount = dd.get("totalCount"); map -> map.get("workCenterCode").toString(),
if (totalCount != null) { map -> map.get("totalCount").toString(),
shippingGroupCount.put(dd.get("workCenterCode").toString(), totalCount.toString()); (existing, replacement) -> existing // Handle duplicates if any
} ));
}
} // Collect counts for each shipping group
for (MesPartShippingGroup shippingGroup : partShippingGroups) { for (MesPartShippingGroup shippingGroup : partShippingGroups) {
if (StringUtils.isEmpty(shippingGroup.getCarrierCode())) { if (StringUtils.isEmpty(shippingGroup.getCarrierCode())) {
continue; continue;
} }
values.add(shippingGroupCount.getOrDefault(shippingGroup.getCarrierCode(), "0")); values.add(shippingGroupCount.getOrDefault(shippingGroup.getCarrierCode(), "0"));
} }
// Ensure at least one value is returned
if (values.isEmpty()) { if (values.isEmpty()) {
values.add("0"); values.add("0");
} }

Loading…
Cancel
Save