package com.zy.core.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.zy.asrs.entity.BasCrnp; import com.zy.asrs.entity.BasDevp; import com.zy.asrs.entity.WrkMast; import com.zy.asrs.service.BasCrnpService; import com.zy.asrs.service.BasDevpService; import com.zy.asrs.service.WrkMastService; import com.zy.common.service.CommonService; import com.zy.core.News; import com.zy.core.cache.MessageQueue; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.SlaveType; import com.zy.core.enums.WrkStsType; import com.zy.core.model.StationObjModel; import com.zy.core.model.Task; import com.zy.core.model.command.StationCommand; import com.zy.core.model.protocol.StationProtocol; import com.zy.core.thread.StationThread; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; import java.util.List; import java.util.Map; @Component public class StationOperateProcessUtils { @Autowired private BasDevpService basDevpService; @Autowired private WrkMastService wrkMastService; @Autowired private CommonService commonService; @Autowired private BasCrnpService basCrnpService; //执行输送站点入库任务 public synchronized void stationInExecute() { List basDevps = basDevpService.selectList(new EntityWrapper<>()); for (BasDevp basDevp : basDevps) { StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); if(stationThread == null){ continue; } Map stationMap = stationThread.getStatusMap(); List list = basDevp.getInStationList$(); for (StationObjModel entity : list) { Integer stationId = entity.getStationId(); if(!stationMap.containsKey(stationId)){ continue; } StationProtocol stationProtocol = stationMap.get(stationId); if (stationProtocol == null) { continue; } //满足自动、有物、工作号9999 if (stationProtocol.isAutoing() && stationProtocol.isLoading() && stationProtocol.getTaskNo() == 9999 ) { //检测任务是否生成 WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper().eq("barcode", stationProtocol.getBarcode())); if (wrkMast == null) { continue; } if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) { continue; } String locNo = wrkMast.getLocNo(); Integer crnNo = commonService.findCrnNoByLocNo(locNo); if (crnNo == null) { News.taskInfo(wrkMast.getWrkNo(), "未匹配到堆垛机"); continue; } Integer targetStationId = commonService.findInStationId(crnNo, stationId); if (targetStationId == null) { News.taskInfo(wrkMast.getWrkNo(), "搜索入库站点失败"); continue; } StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationId, targetStationId, 0); if(command == null){ News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); continue; } wrkMast.setWrkSts(WrkStsType.INBOUND_DEVICE_RUN.sts); wrkMast.setSourceStaNo(stationProtocol.getStationId()); wrkMast.setStaNo(targetStationId); wrkMast.setSystemMsg(""); wrkMast.setIoTime(new Date()); if (wrkMastService.updateById(wrkMast)) { MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); News.info("输送站点入库命令下发成功,站点号={},工作号={},命令数据={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command)); } } } } } //执行输送站点出库任务 public synchronized void stationOutExecute() { List wrkMasts = wrkMastService.selectList(new EntityWrapper().eq("wrk_sts", WrkStsType.OUTBOUND_RUN_COMPLETE.sts)); for (WrkMast wrkMast : wrkMasts) { BasCrnp basCrnp = basCrnpService.selectOne(new EntityWrapper().eq("crn_no", wrkMast.getCrnNo())); if (basCrnp == null) { continue; } List outStationList = basCrnp.getOutStationList$(); if(outStationList.isEmpty()){ News.info("堆垛机:{} 出库站点未设置", basCrnp.getCrnNo()); continue; } for (StationObjModel stationObjModel : outStationList) { StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo()); if(stationThread == null){ continue; } Map stationMap = stationThread.getStatusMap(); StationProtocol stationProtocol = stationMap.get(stationObjModel.getStationId()); if (stationProtocol == null) { continue; } //满足自动、有物、工作号0 if (stationProtocol.isAutoing() && stationProtocol.isLoading() && stationProtocol.getTaskNo() == 0 ) { StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0); if(command == null){ News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); continue; } wrkMast.setWrkSts(WrkStsType.STATION_RUN.sts); wrkMast.setSystemMsg(""); wrkMast.setIoTime(new Date()); if (wrkMastService.updateById(wrkMast)) { MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); News.info("输送站点出库命令下发成功,站点号={},工作号={},命令数据={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command)); } } } } } //检测输送站点出库任务执行完成 public synchronized void stationOutExecuteFinish() { List wrkMasts = wrkMastService.selectList(new EntityWrapper().eq("wrk_sts", WrkStsType.STATION_RUN.sts)); for (WrkMast wrkMast : wrkMasts) { Integer wrkNo = wrkMast.getWrkNo(); boolean complete = true; List basDevps = basDevpService.selectList(new EntityWrapper<>()); for (BasDevp basDevp : basDevps) { StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); if (stationThread == null) { continue; } List list = stationThread.getStatus(); for (StationProtocol stationProtocol : list) { if (stationProtocol.getTaskNo().equals(wrkNo)) { complete = false; } } } if (complete) { wrkMast.setWrkSts(WrkStsType.COMPLETE_OUTBOUND.sts); wrkMast.setIoTime(new Date()); wrkMastService.updateById(wrkMast); } } } }