| | |
| | | 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.asrs.domain.param.CreateInTaskParam; |
| | | import com.zy.asrs.entity.*; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.MessageQueue; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.WrkStsType; |
| | | import com.zy.core.model.StationObjModel; |
| | |
| | | import com.zy.core.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | @Component |
| | | public class StationOperateProcessUtils { |
| | |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private HttpRequestLogService httpRequestLogService; |
| | | @Autowired |
| | | private LocMastService locMastService; |
| | | |
| | | //执行输送站点入库任务 |
| | | public synchronized void stationInExecute() { |
| | |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getInStationList$(); |
| | | List<StationObjModel> list = basDevp.getBarcodeStationList$(); |
| | | for (StationObjModel entity : list) { |
| | | Integer stationId = entity.getStationId(); |
| | | if(!stationMap.containsKey(stationId)){ |
| | |
| | | continue; |
| | | } |
| | | |
| | | //满足自动、有物、工作号9999 |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | | |
| | | //满足自动、有物、有工作号 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 9999 |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | //检测任务是否生成 |
| | | WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | |
| | | } |
| | | |
| | | if (wrkMast.getWrkSts() == WrkStsType.INBOUND_DEVICE_RUN.sts) { |
| | | continue; |
| | | } |
| | | |
| | | if (!wrkMast.getWrkNo().equals(stationProtocol.getTaskNo())) { |
| | | News.taskInfo(stationProtocol.getStationId(), "输送站点工作号:{}与条码搜索到的任务工作号:{}不一致", stationProtocol.getTaskNo(), wrkMast.getWrkNo()); |
| | | continue; |
| | | } |
| | | |
| | |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | News.info("输送站点入库命令下发成功,站点号={},工作号={},命令数据={}", stationId, wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.STATION_IN_EXECUTE_LIMIT.key + stationId, "lock", 5); |
| | | } |
| | | } |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId()); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | |
| | | //满足自动、有物、工作号0 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command)); |
| | | News.info("输送站点出库命令下发成功,站点号={},工作号={},命令数据={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | redisUtil.set(RedisKeyType.STATION_OUT_EXECUTE_LIMIT.key + stationProtocol.getStationId(), "lock", 5); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | //检测输送站点是否运行堵塞 |
| | | public synchronized void checkStationRunBlock() { |
| | | String wmsUrl = null; |
| | | Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri")); |
| | | if (wmsSystemUriConfig != null) { |
| | | wmsUrl = wmsSystemUriConfig.getValue(); |
| | | } |
| | | |
| | | if(wmsUrl == null){ |
| | | News.error("未配置WMS系统URI,配置文件Code编码:wmsSystemUri"); |
| | | return; |
| | | } |
| | | |
| | | String wmsSystemReassignInTaskUrl = null; |
| | | Config wmsSystemReassignInTaskUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl")); |
| | | if (wmsSystemReassignInTaskUrlConfig != null) { |
| | | wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue(); |
| | | } |
| | | |
| | | if(wmsSystemReassignInTaskUrl == null){ |
| | | News.error("未配置WMS任务重新分配入库库位接口地址,配置文件Code编码:wmsSystemReassignInTaskUrl"); |
| | | return; |
| | | } |
| | | |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if(stationThread == null){ |
| | | continue; |
| | | } |
| | | |
| | | List<Integer> runBlockReassignLocStationList = new ArrayList<>(); |
| | | for (StationObjModel stationObjModel : basDevp.getRunBlockReassignLocStationList$()) { |
| | | runBlockReassignLocStationList.add(stationObjModel.getStationId()); |
| | | } |
| | | |
| | | List<StationProtocol> list = stationThread.getStatus(); |
| | | for (StationProtocol stationProtocol : list) { |
| | | if(stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | && stationProtocol.isRunBlock() |
| | | ) { |
| | | WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo()); |
| | | if (wrkMast == null) { |
| | | News.info("输送站点号={} 运行阻塞,但无法找到对应任务,工作号={}", stationProtocol.getStationId(), stationProtocol.getTaskNo()); |
| | | continue; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo()); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | redisUtil.set(RedisKeyType.CHECK_STATION_RUN_BLOCK_LIMIT_.key + stationProtocol.getTaskNo(), "lock", 15); |
| | | |
| | | if (runBlockReassignLocStationList.contains(stationProtocol.getStationId())) { |
| | | //站点处于重新分配库位区域 |
| | | //运行堵塞,重新申请任务 |
| | | |
| | | HashMap<String, Object> requestParam = new HashMap<>(); |
| | | String response = null; |
| | | try { |
| | | requestParam.put("taskNo", wrkMast.getWmsWrkNo()); |
| | | requestParam.put("row", Utils.getInTaskEnableRow(new ArrayList<>(basDevp.getDevpNo()))); |
| | | |
| | | response = new HttpHandler.Builder() |
| | | .setUri(wmsUrl) |
| | | .setPath(wmsSystemReassignInTaskUrl) |
| | | .setJson(JSON.toJSONString(requestParam)) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | |
| | | String sourceLocNo = wrkMast.getLocNo(); |
| | | String locNo = dto.getLocNo(); |
| | | |
| | | LocMast sourceLocMast = locMastService.queryByLoc(sourceLocNo); |
| | | if (sourceLocMast == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 源库位信息不存在", sourceLocNo); |
| | | continue; |
| | | } |
| | | |
| | | if (!sourceLocMast.getLocSts().equals("S")) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 源库位状态不处于入库预约", sourceLocNo); |
| | | continue; |
| | | } |
| | | |
| | | LocMast locMast = locMastService.queryByLoc(locNo); |
| | | if (locMast == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 目标库位信息不存在", locNo); |
| | | continue; |
| | | } |
| | | |
| | | if (!locMast.getLocSts().equals("O")) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "库位号:{} 目标库位状态不处于空库位", locNo); |
| | | continue; |
| | | } |
| | | |
| | | Integer crnNo = commonService.findCrnNoByLocNo(locNo); |
| | | if (crnNo == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "未匹配到堆垛机"); |
| | | continue; |
| | | } |
| | | |
| | | Integer targetStationId = commonService.findInStationId(crnNo, stationProtocol.getStationId()); |
| | | if (targetStationId == null) { |
| | | News.taskInfo(wrkMast.getWrkNo(), "搜索入库站点失败"); |
| | | continue; |
| | | } |
| | | |
| | | StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), targetStationId, 0); |
| | | if(command == null){ |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | |
| | | //更新源库位 |
| | | sourceLocMast.setLocSts("O"); |
| | | sourceLocMast.setModiTime(new Date()); |
| | | locMastService.updateById(sourceLocMast); |
| | | |
| | | //更新目标库位 |
| | | locMast.setLocSts("S"); |
| | | locMast.setModiTime(new Date()); |
| | | locMastService.updateById(locMast); |
| | | |
| | | //更新工作档数据 |
| | | wrkMast.setLocNo(locNo); |
| | | wrkMast.setCrnNo(crnNo); |
| | | wrkMast.setStaNo(targetStationId); |
| | | if (wrkMastService.updateById(wrkMast)) { |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | } |
| | | News.info("请求WMS接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response); |
| | | } else { |
| | | News.error("请求WMS接口失败!!!url:{};request:{};response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response); |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("请求WMS接口异常!!!url:{};request:{}; response:{}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response, e); |
| | | } finally { |
| | | HttpRequestLog httpRequestLog = new HttpRequestLog(); |
| | | httpRequestLog.setName(wmsUrl + wmsSystemReassignInTaskUrl); |
| | | httpRequestLog.setRequest(JSON.toJSONString(requestParam)); |
| | | httpRequestLog.setResponse(response); |
| | | httpRequestLog.setCreateTime(new Date()); |
| | | httpRequestLogService.insert(httpRequestLog); |
| | | } |
| | | }else { |
| | | //运行堵塞,重新计算路线 |
| | | StationCommand command = stationThread.getMoveCommand(wrkMast.getWrkNo(), stationProtocol.getStationId(), wrkMast.getStaNo(), 0); |
| | | if(command == null){ |
| | | News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败"); |
| | | continue; |
| | | } |
| | | |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | News.info("输送站点堵塞后重新计算路径命令下发成功,站点号={},工作号={},命令数据={}", stationProtocol.getStationId(), wrkMast.getWrkNo(), JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |