46881 PCN:发运看板开启多个导致CPU很高,优化查询SQL

uat-temp-nht-202505150000-46881
jason 2 months ago
parent 7576219ed8
commit beee1d6277

@ -4,29 +4,24 @@ import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesShippingKanbanCfgService;
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.ShippingKanbanCacheModel;
import cn.estsh.i3plus.mes.pcn.util.DateUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesPartShippingGroup;
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
import cn.estsh.i3plus.pojo.mes.bean.seres.MesCimSeresJisVinOverPoint;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesLoadingListDetail;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingKanbanCfg;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingKanbanCfgDetail;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingOrderManagement;
import cn.estsh.i3plus.pojo.mes.repository.MesPartShippingGroupRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesShippingKanbanCfgDetailRepository;
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.date.DateTime;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@ -40,6 +35,7 @@ import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgService {
@Autowired
@ -165,6 +161,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) {
@ -188,49 +185,49 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
List<String> values = null;
switch (index) {
case CLIENT_STOCK_QTY:
values = getClientStockQty(cfg, cfgDetail);
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) {
@ -306,17 +303,25 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
hql.append("select sd.vin");
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 (shippingGroupCodes.size() == 1) {
hql.append(" and s.shippingGroupCode = :shippingGroupCode ");
} else {
hql.append(" and s.shippingGroupCode in (:shippingGroupCode) ");
}
hql.append(" ORDER BY sd.id desc");
try {
return entityManager.createQuery(hql.toString(), String.class)
.setParameter("organizeCode", organizeCode)
.setParameter("isValid", CommonEnumUtil.VALID)
.setParameter("isDeleted", CommonEnumUtil.FALSE)
.setParameter("status", status)
.setParameter("shippingGroupCode", shippingGroupCodes)
.setMaxResults(1)
.getSingleResult();
Query query = entityManager.createQuery(hql.toString(), String.class);
query.setParameter("organizeCode", organizeCode);
query.setParameter("isValid", CommonEnumUtil.VALID);
query.setParameter("isDeleted", CommonEnumUtil.FALSE);
query.setParameter("status", status);
if (shippingGroupCodes.size() == 1) {
query.setParameter("shippingGroupCode", shippingGroupCodes.get(0));
} else {
query.setParameter("shippingGroupCode", shippingGroupCodes);
}
query.setMaxResults(1);
return query.getSingleResult().toString();
} catch (NoResultException e) {
return "";
}
@ -324,9 +329,6 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* 线
* @param organizeCode
* @param shippingGroupCodes
* @return
*/
private String getMaxOffNumber(String organizeCode, List<String> shippingGroupCodes) {
String vinCode = getMesShippingVin(organizeCode, shippingGroupCodes, Arrays.asList(MesExtEnumUtil.SHIPPING_ORDER_STATUS.SHIPPED.getValue(), MesExtEnumUtil.SHIPPING_ORDER_STATUS.LOADING.getValue()));
@ -334,7 +336,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
return "";
}
StringBuilder offNumberHql = new StringBuilder();
offNumberHql.append("select max(serialNumber) from " + MesCimSeresJisVinOverPoint.class.getName());
offNumberHql.append("select max(serialNumber) from ").append(MesCimSeresJisVinOverPoint.class.getName());
offNumberHql.append(" where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid ");
offNumberHql.append(" and vin = :vin ");
try {
@ -352,11 +354,12 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
*
* 线SERIAL_NUMBER- 线+
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getClientStockQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getClientStockQty(MesShippingKanbanCfg cfg, ShippingKanbanCacheModel cacheModel) {
if (cacheModel.getClientStockQty() != null) {
return cacheModel.getClientStockQty();
}
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -368,7 +371,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
String onNumber = "";
if (!StringUtils.isEmpty(cfg.getOnlinePoint())) {
StringBuilder onNumberHql = new StringBuilder();
onNumberHql.append("select max(serialNumber) from " + MesCimSeresJisVinOverPoint.class.getName());
onNumberHql.append("select max(serialNumber) from ").append(MesCimSeresJisVinOverPoint.class.getName());
onNumberHql.append(" where organizeCode = :organizeCode and isDeleted = :isDeleted and isValid = :isValid ");
onNumberHql.append(" and overPoint = :overPoint ");
try {
@ -393,17 +396,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<String> getWaitShippingQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getWaitShippingQty(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -445,15 +447,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<Map> 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<Map> ddd = query.getResultList();
Map<String, String> shippingGroupCount = new HashMap<>();
if (!CollectionUtils.isEmpty(ddd)) {
for (Map dd : ddd) {
@ -470,7 +480,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
return values;
}
private List<String> getCPWaitShippingQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getCPWaitShippingQty(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -517,11 +527,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* /
* -
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getWaitProductQty(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getWaitProductQty(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -557,15 +565,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<Map> 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<Map> ddd = query.getResultList();
Map<String, String> shippingGroupCount = new HashMap<>();
if (!CollectionUtils.isEmpty(ddd)) {
for (Map dd : ddd) {
@ -589,11 +605,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* (Min)
* -
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getLastShippingTime(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getLastShippingTime(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -605,16 +619,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) {
}
@ -627,15 +649,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<Map> 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<Map> ddd = query.getResultList();
Map<String, String> shippingGroupCount = new HashMap<>();
if (!CollectionUtils.isEmpty(ddd)) {
for (Map dd : ddd) {
@ -660,7 +690,7 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
return values;
}
private List<String> getCPLastShippingTime(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getCPLastShippingTime(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
DdlPackBean packBean = DdlPackBean.getDdlPackBean(cfg.getOrganizeCode());
List<MesPartShippingGroup> shippingGroups = partShippingGroupRDao.findByHqlWhere(packBean);
@ -675,16 +705,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)) {
@ -700,21 +738,24 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
*
* +/JPH-
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getNextShippingTime(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getNextShippingTime(MesShippingKanbanCfg cfg, ShippingKanbanCacheModel cacheModel) {
if (cacheModel.getCacheNextShipping() != null) {
return cacheModel.getCacheNextShipping();
}
List<String> values = new ArrayList<>();
Date nowTime = DateUtil.now();
//获取客户端库存
List<String> clientStockValue = getClientStockQty(cfg, cfgDetail);
List<String> clientStockValue = getClientStockQty(cfg, cacheModel);
if (StringUtils.isEmpty(clientStockValue)) {
cacheModel.setCacheNextShipping(values);
return values;
}
//获取客户JPH
List<String> customerJPHValue = getClientJPH(cfg, cfgDetail);
List<String> customerJPHValue = getClientJph(cfg);
if (CollectionUtils.isEmpty(customerJPHValue)) {
cacheModel.setCacheNextShipping(values);
return values;
}
double clientStock = Double.parseDouble(clientStockValue.get(0));
@ -730,20 +771,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<String> getTreeStopWarning(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getTreeStopWarning(MesShippingKanbanCfg cfg, ShippingKanbanCacheModel cacheModel) {
List<String> values = new ArrayList<>();
//获取下一车最晚发运时间
List<String> nextShippingTimeValue = getNextShippingTime(cfg, cfgDetail);
List<String> nextShippingTimeValue = getNextShippingTime(cfg, cacheModel);
if (StringUtils.isEmpty(nextShippingTimeValue)) {
values.add("0");
return values;
@ -757,11 +797,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* VIN/6
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getShippingVin(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getShippingVin(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -774,19 +812,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) {
@ -799,16 +846,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<Map> 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<Map> ddd = query.getResultList();
Map<String, String> shippingGroupCount = new HashMap<>();
if (!CollectionUtils.isEmpty(ddd)) {
for (Map dd : ddd) {
@ -839,11 +893,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* VIN/6
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getCPShippingVin(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getCPShippingVin(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
DdlPackBean packBean = DdlPackBean.getDdlPackBean(cfg.getOrganizeCode());
List<MesPartShippingGroup> shippingGroups = partShippingGroupRDao.findByHqlWhere(packBean);
@ -859,19 +911,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) : "";
@ -890,11 +950,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
* 线
*
* 线/线
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getTodayOnline(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getTodayOnline(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
if (StringUtils.isEmpty(cfg.getCustStartShift()) || StringUtils.isEmpty(cfg.getOnlinePoint())) {
values.add("0");
@ -936,11 +994,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
*
*
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getTodayShipping(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getTodayShipping(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList) || StringUtils.isEmpty(cfg.getInterStartShift())) {
@ -968,17 +1024,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<Map> 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<Map> ddd = query.getResultList();
Map<String, String> shippingGroupCount = new HashMap<>();
if (!CollectionUtils.isEmpty(ddd)) {
for (Map dd : ddd) {
@ -997,11 +1061,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
*
*
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getTodayCar(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getTodayCar(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList) || StringUtils.isEmpty(cfg.getInterStartShift())) {
@ -1029,18 +1091,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<Map> 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<Map> dataList = query.getResultList();
Map<String, String> shippingGroupCount = new HashMap<>();
if (!CollectionUtils.isEmpty(dataList)) {
for (Map data : dataList) {
@ -1059,11 +1128,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* JPH
* 线0
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getClientJPH(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getClientJph(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<String> strShippingGroupList = Arrays.asList(cfg.getShippingGroupCode().split(","));
if (CollectionUtils.isEmpty(strShippingGroupList)) {
@ -1074,7 +1141,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 ");
@ -1105,11 +1172,9 @@ public class MesShippingKanbanCfgServiceImpl implements IMesShippingKanbanCfgSer
/**
* JPH
* /线
* @param cfg
* @param cfgDetail
* @return
* @param cfg
*/
private List<String> getProductJPH(MesShippingKanbanCfg cfg, MesShippingKanbanCfgDetail cfgDetail) {
private List<String> getProductJph(MesShippingKanbanCfg cfg) {
List<String> values = new ArrayList<>();
List<MesPartShippingGroup> partShippingGroups = getShippingGroups(cfg);
if (CollectionUtils.isEmpty(partShippingGroups)) {

@ -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<String> clientStockQty;
private List<String> cacheNextShipping;
}
Loading…
Cancel
Save