diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesShippingKanbanCfgServiceImpl.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesShippingKanbanCfgServiceImpl.java index ea202d7..ecd7612 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesShippingKanbanCfgServiceImpl.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesShippingKanbanCfgServiceImpl.java @@ -1,11 +1,7 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi; import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesShippingKanbanCfgService; -import cn.estsh.i3plus.ext.mes.pcn.pojo.model.CustQtyByTimeChartDataModel; -import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesShippingKanbanCfgModel; -import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesShippingKanbanModel; -import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesShippingKanbanViewModel; -import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; +import cn.estsh.i3plus.ext.mes.pcn.pojo.model.*; import cn.estsh.i3plus.mes.pcn.util.DateUtil; import cn.estsh.i3plus.platform.common.convert.ConvertBean; import cn.estsh.i3plus.platform.common.tool.TimeTool; @@ -25,6 +21,7 @@ import cn.estsh.i3plus.pojo.mes.repository.MesShippingKanbanCfgRepository; import cn.estsh.i3plus.pojo.mes.repository.seres.IMesCimSeresJisVinOverPointRepository; import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; import cn.hutool.core.util.NumberUtil; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -38,6 +35,7 @@ import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; +@Slf4j @Service public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgService { @Autowired @@ -169,6 +167,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer cfgDetailMap = cfgModel.getDetails().stream().collect(Collectors.toMap(MesShippingKanbanCfgDetail::getDetailCode, v -> v)); } + ShippingKanbanCacheModel cacheModel = new ShippingKanbanCacheModel(); for (MesExtEnumUtil.SHIPPING_KANBAN_DETAIL_INDEX index : MesExtEnumUtil.SHIPPING_KANBAN_DETAIL_INDEX.values()) { MesShippingKanbanCfgDetail cfgDetail = cfgDetailMap != null ? cfgDetailMap.get(index.getValue()) : null; if (cfgDetail == null || cfgDetail.getIsShow() == null || cfgDetail.getIsShow() != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() || cfgDetail.getOrderNumber() == null) { @@ -192,49 +191,49 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer List values = null; switch (index) { case CLIENT_STOCK_QTY: - values = getClientStockQty(cfg); + values = getClientStockQty(cfg, cacheModel); break; case WAIT_SHIPPING_QTY: - values = getWaitShippingQty(cfg, cfgDetail); + values = getWaitShippingQty(cfg); break; case CP_WAIT_SHIPPING_QTY: - values = getCPWaitShippingQty(cfg, cfgDetail); + values = getCPWaitShippingQty(cfg); break; case WAIT_PRODUCT_QTY: - values = getWaitProductQty(cfg, cfgDetail); + values = getWaitProductQty(cfg); break; case LAST_SHIPPING_TIME: - values = getLastShippingTime(cfg, cfgDetail); + values = getLastShippingTime(cfg); break; case CP_LAST_SHIPPING_TIME: - values = getCPLastShippingTime(cfg, cfgDetail); + values = getCPLastShippingTime(cfg); break; case NEXT_SHIPPING_TIME: - values = getNextShippingTime(cfg, cfgDetail); + values = getNextShippingTime(cfg, cacheModel); break; case TREE_STOP_WARNING: - values = getTreeStopWarning(cfg, cfgDetail); + values = getTreeStopWarning(cfg, cacheModel); break; case SHIPPING_VIN: - values = getShippingVin(cfg, cfgDetail); + values = getShippingVin(cfg); break; case CP_SHIPPING_VIN: - values = getCPShippingVin(cfg, cfgDetail); + values = getCPShippingVin(cfg); break; case TODAY_ONLINE: - values = getTodayOnline(cfg, cfgDetail); + values = getTodayOnline(cfg); break; case TODAY_SHIPPING: - values = getTodayShipping(cfg, cfgDetail); + values = getTodayShipping(cfg); break; case TODAY_CAR: - values = getTodayCar(cfg, cfgDetail); + values = getTodayCar(cfg); break; case CLIENT_JPH: - values = getClientJPH(cfg, cfgDetail); + values = getClientJph(cfg); break; case PRODUCT_JPH: - values = getProductJPH(cfg, cfgDetail); + values = getProductJph(cfg); break; } if (values == null) { @@ -437,9 +436,6 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 最新下线的排序发运单客户流水号 - * @param organizeCode - * @param shippingGroupCodes - * @return */ private String getMaxOffNumber(String organizeCode, List shippingGroupCodes) { String vinCode = getMesShippingVin(organizeCode, shippingGroupCodes, Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); @@ -465,10 +461,12 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 客户端库存 * 最新下线的排序发运单客户流水号(SERIAL_NUMBER)- 赛力斯上线的最新流水号+调整值。 - * @param cfg - * @return + * @param cfg 看板配置 */ - private List getClientStockQty(MesShippingKanbanCfg cfg) { + private List getClientStockQty(MesShippingKanbanCfg cfg, ShippingKanbanCacheModel cacheModel) { + if (cacheModel.getClientStockQty() != null) { + return cacheModel.getClientStockQty(); + } List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -505,17 +503,16 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer int adjustValue = cfg.getAdjustValue() != null ? cfg.getAdjustValue() : 0; int result = Integer.parseInt(offNumber) - Integer.parseInt(onNumber) + adjustValue; values.add(String.valueOf(result)); + cacheModel.setClientStockQty(values); return values; } /** * 待发运数量 * 排序单装箱扫描流水号-发运扫描流水号,精排最新流水号-辊道线下件流水号(cockpit) - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getWaitShippingQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getWaitShippingQty(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -557,15 +554,23 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select new Map(s.shippingGroupCode as shippingGroupCode, COUNT(sd.id) as COUNT)"); hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status = :status "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" group by s.shippingGroupCode"); - List ddd = entityManager.createQuery(hql.toString()) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue()) - .setParameter("shippingGroupCode", strShippingGroupList) - .getResultList(); + Query query = entityManager.createQuery(hql.toString()); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue()); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + List ddd = query.getResultList(); Map shippingGroupCount = new HashMap<>(); if (!CollectionUtils.isEmpty(ddd)) { for (Map dd : ddd) { @@ -582,7 +587,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer return values; } - private List getCPWaitShippingQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getCPWaitShippingQty(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -629,11 +634,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 待生产/装箱数量 * 精排最新流水号-排序单装箱扫描流水号 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getWaitProductQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getWaitProductQty(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -669,15 +672,23 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select new Map(s.shippingGroupCode as shippingGroupCode, max(sd.custInfoSeq) as custInfoSeq)"); hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" group by s.shippingGroupCode"); - List ddd = entityManager.createQuery(hql.toString()) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .getResultList(); + Query query = entityManager.createQuery(hql.toString()); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + List ddd = query.getResultList(); Map shippingGroupCount = new HashMap<>(); if (!CollectionUtils.isEmpty(ddd)) { for (Map dd : ddd) { @@ -701,11 +712,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 距离上一次发运时间(Min) * 当前时间-最近一次发运扫描时间 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getLastShippingTime(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getLastShippingTime(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -717,16 +726,24 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select max(s.endScanTime)"); hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } String strScanEndTime = ""; try { - strScanEndTime = entityManager.createQuery(hql.toString(), String.class) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .getSingleResult(); + Query query = entityManager.createQuery(hql.toString(), String.class); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + strScanEndTime = query.getSingleResult().toString(); } catch (NoResultException ignored) { } @@ -739,15 +756,23 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select new Map(s.shippingGroupCode as shippingGroupCode, max(l.endScanTime) as endScanTime)"); hql.append(" from MesLoadingList l inner join MesLoadingListDetail ld on l.id = ld.pid inner join MesShippingOrderManagement s on s.id = ld.shippingId and l.organizeCode = :organizeCode and l.isDeleted=:isDeleted and l.isValid=:isValid "); hql.append(" and l.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" group by s.shippingGroupCode"); - List ddd = entityManager.createQuery(hql.toString()) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.MES_LOADING_STATUS.PUBLISH.getValue(), MesExtEnumUtil.MES_LOADING_STATUS.SCANNED.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .getResultList(); + Query query = entityManager.createQuery(hql.toString()); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.MES_LOADING_STATUS.PUBLISH.getValue(), MesExtEnumUtil.MES_LOADING_STATUS.SCANNED.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + List ddd = query.getResultList(); Map shippingGroupCount = new HashMap<>(); if (!CollectionUtils.isEmpty(ddd)) { for (Map dd : ddd) { @@ -772,7 +797,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer return values; } - private List getCPLastShippingTime(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getCPLastShippingTime(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); DdlPackBean packBean = DdlPackBean.getDdlPackBean(cfg.getOrganizeCode()); List shippingGroups = partShippingGroupRDao.findByHqlWhere(packBean); @@ -787,16 +812,24 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select max(s.endScanTime)"); hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } String strScanEndTime = ""; try { - strScanEndTime = entityManager.createQuery(hql.toString(), String.class) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .getSingleResult(); + Query query = entityManager.createQuery(hql.toString(), String.class); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + strScanEndTime = query.getSingleResult().toString(); } catch (NoResultException ignored) { } if (!StringUtils.isEmpty(strScanEndTime)) { @@ -812,21 +845,24 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 下一车最晚发运时间 * 当前时间+客户端库存/客户JPH-在途时间 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getNextShippingTime(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getNextShippingTime(MesShippingKanbanCfg cfg, ShippingKanbanCacheModel cacheModel) { + if (cacheModel.getCacheNextShipping() != null) { + return cacheModel.getCacheNextShipping(); + } List values = new ArrayList<>(); Date nowTime = DateUtil.now(); //获取客户端库存 - List clientStockValue = getClientStockQty(cfg); + List clientStockValue = getClientStockQty(cfg, cacheModel); if (StringUtils.isEmpty(clientStockValue)) { + cacheModel.setCacheNextShipping(values); return values; } //获取客户JPH - List customerJPHValue = getClientJPH(cfg, cfgDetail); + List customerJPHValue = getClientJph(cfg); if (CollectionUtils.isEmpty(customerJPHValue)) { + cacheModel.setCacheNextShipping(values); return values; } double clientStock = Double.parseDouble(clientStockValue.get(0)); @@ -842,20 +878,19 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer int minutes = (int)(customerJPHInt * 60); Date newDate = DateUtil.addMinutes(nowTime, minutes - onTheWayDate); values.add(DateUtil.formatDate(DateUtil.BASE_FORMAT3, newDate)); + cacheModel.setCacheNextShipping(values); return values; } /** * 三级停线预警(Min) * 当前时间+客户端库存/客户JPH-在途时间 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getTreeStopWarning(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getTreeStopWarning(MesShippingKanbanCfg cfg, ShippingKanbanCacheModel cacheModel) { List values = new ArrayList<>(); //获取下一车最晚发运时间 - List nextShippingTimeValue = getNextShippingTime(cfg, cfgDetail); + List nextShippingTimeValue = getNextShippingTime(cfg, cacheModel); if (StringUtils.isEmpty(nextShippingTimeValue)) { values.add("0"); return values; @@ -869,11 +904,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 最近发运VIN/流水号,客户排序信息序号,截取后6位 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getShippingVin(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getShippingVin(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -886,19 +919,28 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select sd.custInfoSeq"); hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" ORDER BY sd.id DESC"); Long custInfoSeq = null; try { - custInfoSeq = entityManager.createQuery(hql.toString(), Long.class) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .setMaxResults(1) - .getSingleResult(); + Query query = entityManager.createQuery(hql.toString(), Long.class); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + query.setMaxResults(1); + custInfoSeq = (Long) query.getSingleResult(); } catch (NoResultException e) { + log.error("", e); } String strCustInfoSeq = custInfoSeq != null ? Long.toString(custInfoSeq) : ""; if (strCustInfoSeq.length() >= 5) { @@ -911,16 +953,23 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select new Map(s.shippingGroupCode as shippingGroupCode, max(sd.custInfoSeq) as custInfoSeq)"); hql.append(" from MesLoadingList l inner join MesLoadingListDetail ld on l.id = ld.pid inner join MesShippingOrderManagement s on s.id = ld.shippingId inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and l.organizeCode = :organizeCode and l.isDeleted=:isDeleted and l.isValid=:isValid "); hql.append(" and l.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" group by s.shippingGroupCode"); - List ddd = entityManager.createQuery(hql.toString()) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.MES_LOADING_STATUS.PUBLISH.getValue(), MesExtEnumUtil.MES_LOADING_STATUS.SCANNED.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .getResultList(); - + Query query = entityManager.createQuery(hql.toString()); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.MES_LOADING_STATUS.PUBLISH.getValue(), MesExtEnumUtil.MES_LOADING_STATUS.SCANNED.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + List ddd = query.getResultList(); Map shippingGroupCount = new HashMap<>(); if (!CollectionUtils.isEmpty(ddd)) { for (Map dd : ddd) { @@ -951,11 +1000,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 最近发运VIN/流水号,客户排序信息序号,截取后6位 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getCPShippingVin(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getCPShippingVin(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); DdlPackBean packBean = DdlPackBean.getDdlPackBean(cfg.getOrganizeCode()); List shippingGroups = partShippingGroupRDao.findByHqlWhere(packBean); @@ -971,19 +1018,27 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append("select sd.custInfoSeq"); hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status in (:status) "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" ORDER BY sd.id DESC"); Long custInfoSeq = null; try { - custInfoSeq = entityManager.createQuery(hql.toString(), Long.class) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())) - .setParameter("shippingGroupCode", strShippingGroupList) - .setMaxResults(1) - .getSingleResult(); - } catch (NoResultException e) { + Query query = entityManager.createQuery(hql.toString(), Long.class); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + query.setMaxResults(1); + custInfoSeq = (Long) query.getSingleResult(); + } catch (NoResultException ignored) { } String strCustInfoSeq = custInfoSeq != null ? Long.toString(custInfoSeq) : ""; @@ -1002,11 +1057,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer * 当天上线数,要设置客户开班时间、信息点 * 基于信息点到当前时间过点数量。按天显示。 * 当天上线数/当班上线数 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getTodayOnline(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getTodayOnline(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); if (StringUtils.isEmpty(cfg.getCustStartShift()) || StringUtils.isEmpty(cfg.getOnlinePoint())) { values.add("0"); @@ -1048,11 +1101,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 当天发运数 * 设置内部开班时间,显示已发运数、已装车数,发运单状态为已发运及已装车。 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getTodayShipping(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getTodayShipping(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList) || StringUtils.isEmpty(cfg.getInterStartShift())) { @@ -1080,17 +1131,25 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append(" from MesShippingOrderManagement s inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and sd.organizeCode = :organizeCode and sd.isDeleted=:isDeleted and sd.isValid=:isValid "); hql.append(" and s.status in (:status) "); hql.append(" and s.modifyDatetime BETWEEN :startDateTime AND :endDateTime "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" group by s.shippingGroupCode"); - List ddd = entityManager.createQuery(hql.toString()) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())) - .setParameter("startDateTime", startDateTime) - .setParameter("endDateTime", endDateTime) - .setParameter("shippingGroupCode", strShippingGroupList) - .getResultList(); + Query query = entityManager.createQuery(hql.toString()); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue())); + query.setParameter("startDateTime", startDateTime); + query.setParameter("endDateTime", endDateTime); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + List ddd = query.getResultList(); Map shippingGroupCount = new HashMap<>(); if (!CollectionUtils.isEmpty(ddd)) { for (Map dd : ddd) { @@ -1109,11 +1168,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 当天装车数 * 设置内部开班时间,显示已装车数,装车单状态为已扫描。 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getTodayCar(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getTodayCar(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList) || StringUtils.isEmpty(cfg.getInterStartShift())) { @@ -1141,18 +1198,25 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer hql.append(" from MesLoadingList l inner join MesLoadingListDetail ld on l.id = ld.pid inner join MesShippingOrderManagement s on s.id = ld.shippingId inner join MesShippingOrderManagementDetail sd on s.id = sd.pid and l.organizeCode = :organizeCode and l.isDeleted=:isDeleted and l.isValid=:isValid "); hql.append(" and l.status = :status "); hql.append(" and l.modifyDatetime BETWEEN :startDateTime AND :endDateTime "); - hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + if (strShippingGroupList.size() == 1) { + hql.append(" and s.shippingGroupCode = :shippingGroupCode "); + } else { + hql.append(" and s.shippingGroupCode in (:shippingGroupCode) "); + } hql.append(" group by s.shippingGroupCode "); - List dataList = entityManager.createQuery(hql.toString()) - .setParameter("organizeCode", cfg.getOrganizeCode()) - .setParameter("isValid", CommonEnumUtil.VALID) - .setParameter("isDeleted", CommonEnumUtil.FALSE) - .setParameter("status", MesExtEnumUtil.MES_LOADING_STATUS.SCANNED.getValue()) - .setParameter("startDateTime", startDateTime) - .setParameter("endDateTime", endDateTime) - .setParameter("shippingGroupCode", strShippingGroupList) - .getResultList(); - + Query query = entityManager.createQuery(hql.toString()); + query.setParameter("organizeCode", cfg.getOrganizeCode()); + query.setParameter("isValid", CommonEnumUtil.VALID); + query.setParameter("isDeleted", CommonEnumUtil.FALSE); + query.setParameter("status", MesExtEnumUtil.MES_LOADING_STATUS.SCANNED.getValue()); + query.setParameter("startDateTime", startDateTime); + query.setParameter("endDateTime", endDateTime); + if (strShippingGroupList.size() == 1) { + query.setParameter("shippingGroupCode", strShippingGroupList.get(0)); + } else { + query.setParameter("shippingGroupCode", strShippingGroupList); + } + List dataList = query.getResultList(); Map shippingGroupCount = new HashMap<>(); if (!CollectionUtils.isEmpty(dataList)) { for (Map data : dataList) { @@ -1171,11 +1235,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 客户端JPH * 上线点,当前时间往前一小时的过点总数维护默认值,当数值为0时,显示为默认值 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getClientJPH(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getClientJph(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(",")); if (CollectionUtils.isEmpty(strShippingGroupList)) { @@ -1186,7 +1248,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer Date prevHourTime = DateUtil.addMinutes(nowTime, -60); StringBuilder offNumberHql = new StringBuilder(); - offNumberHql.append("select count(1) from " + MesCimSeresJisVinOverPoint.class.getName()); + offNumberHql.append("select count(1) from ").append(MesCimSeresJisVinOverPoint.class.getName()); offNumberHql.append(" where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid "); offNumberHql.append(" and createDatetime BETWEEN :startDateTime AND :endDateTime "); offNumberHql.append(" and overPoint = :overPoint "); @@ -1217,11 +1279,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer /** * 生产JPH * 当前时间往前一小时的完成数/下线数 - * @param cfg - * @param cfgDetail - * @return + * @param cfg 看板配置 */ - private List getProductJPH(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) { + private List getProductJph(MesShippingKanbanCfg cfg) { List values = new ArrayList<>(); List partShippingGroups = getShippingGroups(cfg); if (CollectionUtils.isEmpty(partShippingGroups)) { @@ -1233,11 +1293,11 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer // Use a single query to fetch counts grouped by work center code List productionCounts = entityManager.createQuery( - "SELECT new map(pr.workCenterCode as workCenterCode, COUNT(DISTINCT pr.productSn) as totalCount) " + - "FROM " + MesProductionRecord.class.getName() + " pr " + - "WHERE pr.organizeCode = :organizeCode AND pr.isDeleted = :isDeleted AND pr.isValid = :isValid " + - "AND pr.reportType = :reportType AND pr.createDatetime BETWEEN :startDateTime AND :endDateTime " + - "GROUP BY pr.workCenterCode", Map.class) + "SELECT new map(pr.workCenterCode as workCenterCode, COUNT(DISTINCT pr.productSn) as totalCount) " + + "FROM " + MesProductionRecord.class.getName() + " pr " + + "WHERE pr.organizeCode = :organizeCode AND pr.isDeleted = :isDeleted AND pr.isValid = :isValid " + + "AND pr.reportType = :reportType AND pr.createDatetime BETWEEN :startDateTime AND :endDateTime " + + "GROUP BY pr.workCenterCode", Map.class) .setParameter("organizeCode", cfg.getOrganizeCode()) .setParameter("isValid", CommonEnumUtil.VALID) .setParameter("isDeleted", CommonEnumUtil.FALSE) diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/ShippingKanbanCacheModel.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/ShippingKanbanCacheModel.java new file mode 100644 index 0000000..982427a --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/model/ShippingKanbanCacheModel.java @@ -0,0 +1,12 @@ +package cn.estsh.i3plus.ext.mes.pcn.pojo.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class ShippingKanbanCacheModel { + private List clientStockQty; + private List cacheNextShipping; + +}