123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package com.steerinfo.dil.service.impl;
- import com.steerinfo.dil.mapper.QmsQueueResultMapper;
- import com.steerinfo.dil.mapper.QueuingRulesMapper;
- import com.steerinfo.dil.service.IQueuingRulesService;
- import com.steerinfo.dil.util.DataChange;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 排队规则
- * @ author :TXF
- * @ time :2021/10/16 10:04
- */
- @Service
- public class QueuingRulesServiceImpl implements IQueuingRulesService {
- @Resource
- private QueuingRulesMapper queuingRulesMapper;
- /*=========================进厂排队规则=========================*/
- /**
- * 通过物资Id查询网格ID
- * @param materialId
- * @return
- */
- public BigDecimal calculateGridId(BigDecimal materialId){
- Map<String, Object> map = new HashMap<>();
- //通过物资Id 和 进厂类型 查询 门岗ID
- map.put("materialId", materialId);
- map.put("type", 0); //匹配物资可进厂的门岗
- List<Map<String, Object>> gatepostMesList = queuingRulesMapper.queryGatepostByMaterialId(map); //可能会有多个门岗可入
- for (Map<String, Object> mes : gatepostMesList) {
- //从数据库中获取门岗开始时间结束时间 若当前时间满足该门岗进门时间 则下放 暂不考虑门岗优先级
- boolean judgeTime = judgeTime((String)mes.get("startTime"), (String)mes.get("endTime"));
- if(judgeTime){
- mes.put("gridType", 3);
- //通过匹配出来的门岗ID获取网格ID
- return getGridIdByGatepostIdAndGridType(mes);
- }
- }
- return null;
- }
- /**
- * 判断当前时间是否在时间区间范围内
- * @param startTime
- * @param endTime
- * @return
- */
- public boolean judgeTime(String startTime, String endTime){
- SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
- String format = sdf.format(new Date());
- int begin = Integer.parseInt(startTime);
- int end = Integer.parseInt(endTime);
- int now = Integer.parseInt(format);
- if(begin < end){
- return now < end && now >= begin;
- }else {
- return now < end || now >= begin;
- }
- }
- /**
- * 通过门岗ID 和 网格类型 匹配 网格主键
- * @param map
- * @return
- */
- @Override
- public BigDecimal getGridIdByGatepostIdAndGridType(Map<String, Object> map) {
- return queuingRulesMapper.getGridIdByGatepostIdAndGridType(map);
- }
- /*=========================仓库排队规则=========================*/
- /**
- * 查询订单中所需要运输的物资 物资表对订单表 一对多
- * @param map 运输订单号 orderNumber
- * @return
- */
- @Override
- public List<Integer> getAllMaterialId(Map<String, Object> map) {
- return queuingRulesMapper.getAllMaterialId(map);
- }
- /**
- *通过物资Id查询仓库是否有货 或者 是否有多个仓库有货
- * @param materialId 物资ID
- * @return
- */
- @Override
- public List<Integer> getWarehouseIdByMaterialId(Integer materialId) {
- return queuingRulesMapper.getWarehouseIdByMaterialId(materialId);
- }
- /**
- * 通过仓库Id 和 物资Id 查询垛位 层次 月台 仓库
- * @param map MaterialId 物资ID warehouseId 仓库ID
- * @return
- */
- @Override
- public List<Map<String, Object>> getStackGradation(Map<String, Object> map) {
- return queuingRulesMapper.getStackGradation(map);
- }
- /**
- * 通过月台Id 查询月台当前排队车辆数
- * @param platformId 月台ID
- * @return
- */
- @Override
- public BigDecimal queueCountByPlatformId(BigDecimal platformId) {
- return queuingRulesMapper.queueCountByPlatformId(platformId);
- }
- /**
- * 获取月台Id 通过物资ID 根据排队规则 获取车辆该去哪个月台
- * 遗留问题:多种物资会有多个装车实绩 多个月台该如何插入装车实绩 先装哪个物资 查询线路会有多条数据 如何进行筛选
- * @param materialIdList
- * @return
- */
- public List<Map<String, Object>> getPlatId(List<Integer> materialIdList){
- //遍历每一中物资查找月台
- List<Map<String, Object>> platIdList = new ArrayList<>();
- con:for (Integer materialId : materialIdList) {
- Integer platId = null;
- //一种物资可能在多个仓库中
- Map<String, Object> map = new HashMap<>();
- map.put("materialId", materialId);
- List<Integer> warehouseList = getWarehouseIdByMaterialId(materialId);
- int countNum = 1000; //初始化比较值
- for (Integer warehouseId : warehouseList) {
- HashMap<String, Object> hashMap = new HashMap<>();
- hashMap.put("materialId", materialId);
- hashMap.put("warehouseId", warehouseId);
- //通过物资Id和仓库ID对仓储网格表 再次进行查询并筛选出层次号最高的几条数据
- List<Map<String, Object>> mesList = getStackGradation(hashMap);
- //遍历筛选出来的月台 查看当前月台排队车辆数
- for (Map<String, Object> mesMap : mesList) {
- BigDecimal platformId = DataChange.dataToBigDecimal(mesMap.get("platformId"));
- //通过月台ID 和 网格类型 查找当前网格Id
- hashMap.put("queueLocationId", platformId);
- hashMap.put("gridType", 1);
- BigDecimal gridId = queuingRulesMapper.getGridIdByGatepostIdAndGridType(hashMap);
- //取得排队车辆数
- int count = queueCountByPlatformId(gridId).intValue();
- //如果当前月台排队车数为0 则直接选择这个月台
- if(count == 0){
- platId = platformId.intValue();
- map.put("loadingId", platId);
- platIdList.add(map);
- continue con;
- }
- //如果排队车辆数小于上个月台排队车辆数
- if(count < countNum){
- countNum = count; //取代比较数
- platId = platformId.intValue(); //替换月台ID
- map.put("loadingId", platId);
- }
- }
- }
- platIdList.add(map);
- }
- return platIdList;
- }
- }
|