| | |
| | | package com.zy.common.service; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.Cools; |
| | | import com.core.exception.CoolException; |
| | | import com.zy.asrs.domain.param.*; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.NavigateNode; |
| | | import com.zy.common.utils.NavigateUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.model.StationObjModel; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private WrkMastLogService wrkMastLogService; |
| | | @Autowired |
| | | private WrkLastnoService wrkLastnoService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private NavigateUtils navigateUtils; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | /** |
| | | * 生成工作号 |
| | |
| | | return workNo; |
| | | } |
| | | |
| | | public static String zerofill(String msg, Integer count) { |
| | | if (msg.length() == count) { |
| | | return msg; |
| | | } else if (msg.length() > count) { |
| | | return msg.substring(0, 16); |
| | | } else { |
| | | StringBuilder msgBuilder = new StringBuilder(msg); |
| | | for(int i = 0; i < count - msg.length(); ++i) { |
| | | msgBuilder.insert(0, "0"); |
| | | } |
| | | return msgBuilder.toString(); |
| | | } |
| | | } |
| | | |
| | | public boolean completeTask(CompleteTaskParam param) { |
| | | Integer wrkNo = param.getWrkNo(); |
| | | WrkMast wrkMast = wrkMastService.selectByWorkNo(wrkNo); |
| | |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_INBOUND.sts); |
| | | }else if (wrkMast.getIoType() == WrkIoType.OUT.id) { |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts); |
| | | } else if (wrkMast.getIoType() == WrkIoType.SHUTTLE_MOVE.id) { |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_MOVE.sts); |
| | | } else if (wrkMast.getIoType() == WrkIoType.SHUTTLE_CHARGE.id) { |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_CHARGE.sts); |
| | | } else if (wrkMast.getIoType() == WrkIoType.LOC_MOVE.id) { |
| | | wrkMast.setWrkSts(WrkStsType.COMPLETE_LOC_MOVE.sts); |
| | | } |
| | |
| | | throw new CoolException("目标库位不处于空库状态"); |
| | | } |
| | | |
| | | double ioPri = 800D; |
| | | if (param.getTaskPri() != null) { |
| | | ioPri = param.getTaskPri().doubleValue(); |
| | | } |
| | | |
| | | Integer sourceCrnNo = commonService.findCrnNoByLocNo(sourceLocMast.getLocNo()); |
| | | if (sourceCrnNo == null) { |
| | | throw new CoolException("未找到对应堆垛机"); |
| | | } |
| | | |
| | | Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo()); |
| | | if (crnNo == null) { |
| | | throw new CoolException("未找到对应堆垛机"); |
| | | } |
| | | |
| | | if (!sourceCrnNo.equals(crnNo)) { |
| | | throw new CoolException("源库位和目标库位不在同一巷道"); |
| | | } |
| | | |
| | | // 获取工作号 |
| | | int workNo = getWorkNo(WrkIoType.LOC_MOVE.id); |
| | | // 保存工作档 |
| | |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setWrkSts(WrkStsType.NEW_LOC_MOVE.sts); // 工作状态:501.生成移库任务 |
| | | wrkMast.setIoType(WrkIoType.LOC_MOVE.id); // 入出库状态: 201.移库任务 |
| | | wrkMast.setIoPri(800D); |
| | | wrkMast.setIoPri(ioPri); |
| | | wrkMast.setSourceLocNo(param.getSourceLocNo()); |
| | | wrkMast.setLocNo(param.getLocNo()); // 目标库位 |
| | | wrkMast.setCrnNo(crnNo); |
| | | wrkMast.setWmsWrkNo(param.getTaskNo()); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | |
| | | throw new CoolException("目标库位不处于空库状态"); |
| | | } |
| | | |
| | | double ioPri = 100D; |
| | | if (param.getTaskPri() != null) { |
| | | ioPri = param.getTaskPri().doubleValue(); |
| | | } |
| | | |
| | | Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo()); |
| | | if (crnNo == null) { |
| | | throw new CoolException("未找到对应堆垛机"); |
| | | } |
| | | |
| | | // 获取工作号 |
| | | int workNo = getWorkNo(WrkIoType.IN.id); |
| | | // 保存工作档 |
| | |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setWrkSts(WrkStsType.NEW_INBOUND.sts); // 工作状态:1.生成入库任务 |
| | | wrkMast.setIoType(WrkIoType.IN.id); // 入出库状态: 1.入库 |
| | | wrkMast.setIoPri(100D); |
| | | wrkMast.setIoPri(ioPri); |
| | | wrkMast.setLocNo(param.getLocNo()); // 目标库位 |
| | | wrkMast.setSourceStaNo(param.getSourceStaNo());//源站 |
| | | wrkMast.setStaNo(param.getStaNo());//目标站 |
| | | wrkMast.setWmsWrkNo(param.getTaskNo()); |
| | | wrkMast.setBarcode(param.getBarcode()); |
| | | wrkMast.setCrnNo(crnNo); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | | boolean res = wrkMastService.insert(wrkMast); |
| | |
| | | locMast.setModiTime(new Date()); |
| | | locMastService.updateById(locMast); |
| | | |
| | | //缓存记录当前命令堆垛机编号 |
| | | redisUtil.set(RedisKeyType.CURRENT_CIRCLE_TASK_CRN_NO.key, crnNo, 60 * 60 * 24); |
| | | return true; |
| | | } |
| | | |
| | | //出库任务 |
| | | public boolean createOutTask(CreateOutTaskParam param) { |
| | | Date now = new Date(); |
| | | LocMast locMast = locMastService.queryByLoc(param.getSourceLocNo()); |
| | | LocMast locMast = locMastService.queryByLoc(param.getLocNo()); |
| | | if (null == locMast) { |
| | | throw new CoolException("源库位不存在"); |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("F")) { |
| | | throw new CoolException("源库位不处于在库状态"); |
| | | } |
| | | |
| | | double ioPri = 100D; |
| | | if (param.getTaskPri() != null) { |
| | | ioPri = param.getTaskPri().doubleValue(); |
| | | } |
| | | |
| | | Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo()); |
| | | if (crnNo == null) { |
| | | throw new CoolException("未找到对应堆垛机"); |
| | | } |
| | | |
| | | Integer sourceStationId = commonService.findOutStationId(crnNo, param.getStaNo()); |
| | | if (sourceStationId == null) { |
| | | throw new CoolException("未找到输送目标站点可走行路径"); |
| | | } |
| | | |
| | | // 获取工作号 |
| | |
| | | wrkMast.setIoTime(now); |
| | | wrkMast.setWrkSts(WrkStsType.NEW_OUTBOUND.sts); // 工作状态:101.生成出库任务 |
| | | wrkMast.setIoType(WrkIoType.OUT.id); // 入出库状态: 101.出库 |
| | | wrkMast.setIoPri(100D); |
| | | wrkMast.setSourceLocNo(param.getSourceLocNo()); // 源库位 |
| | | wrkMast.setIoPri(ioPri); |
| | | wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位 |
| | | wrkMast.setSourceStaNo(sourceStationId);//源站 |
| | | wrkMast.setStaNo(param.getStaNo());//目标站 |
| | | wrkMast.setWmsWrkNo(param.getTaskNo()); |
| | | wrkMast.setBarcode(locMast.getBarcode()); |
| | | wrkMast.setCrnNo(crnNo); |
| | | wrkMast.setAppeTime(now); |
| | | wrkMast.setModiTime(now); |
| | | boolean res = wrkMastService.insert(wrkMast); |
| | |
| | | return true; |
| | | } |
| | | |
| | | public Integer findCrnNoByLocNo(String locNo) { |
| | | List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>()); |
| | | for (BasCrnp basCrnp : basCrnps) { |
| | | String controlRows = basCrnp.getControlRows(); |
| | | if (Cools.isEmpty(controlRows)) { |
| | | continue; |
| | | } |
| | | |
| | | List<Integer> rowList = JSON.parseArray(controlRows, Integer.class); |
| | | if(rowList.contains(Utils.getRow(locNo))) { |
| | | return basCrnp.getCrnNo(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public Integer findInStationId(Integer crnNo, Integer sourceStationId) { |
| | | BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo)); |
| | | if(basCrnp == null) { |
| | | return null; |
| | | } |
| | | |
| | | Integer targetStationId = null; |
| | | List<StationObjModel> stationList = basCrnp.getInStationList$(); |
| | | for (StationObjModel stationObjModel : stationList) { |
| | | try { |
| | | String startLev = String.valueOf(sourceStationId).substring(0, 1); |
| | | List<NavigateNode> navigateNodes = navigateUtils.calcByStationId(Integer.parseInt(startLev), sourceStationId, stationObjModel.getStationId()); |
| | | if(navigateNodes != null) { |
| | | targetStationId = stationObjModel.getStationId(); |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return targetStationId; |
| | | } |
| | | |
| | | public Integer findOutStationId(Integer crnNo, Integer targetStationId) { |
| | | BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper<BasCrnp>().eq("crn_no", crnNo)); |
| | | if(basCrnp == null) { |
| | | return null; |
| | | } |
| | | |
| | | Integer finalSourceStationId = null; |
| | | List<StationObjModel> stationList = basCrnp.getOutStationList$(); |
| | | for (StationObjModel stationObjModel : stationList) { |
| | | try { |
| | | String startLev = String.valueOf(targetStationId).substring(0, 1); |
| | | List<NavigateNode> navigateNodes = navigateUtils.calcByStationId(Integer.parseInt(startLev), stationObjModel.getStationId(), targetStationId); |
| | | if(navigateNodes != null) { |
| | | finalSourceStationId = stationObjModel.getStationId(); |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return finalSourceStationId; |
| | | } |
| | | |
| | | } |