| | |
| | | package com.zy.core.utils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zy.asrs.entity.BasCrnp; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.common.service.CommonService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.dispatch.StationCommandDispatcher; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.enums.StationCommandType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | 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.task.MainProcessLane; |
| | | import com.zy.core.task.MainProcessTaskSubmitter; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | @Component |
| | | public class StationOperateProcessUtils { |
| | | private static final String STATION_COMMAND_SOURCE = "station-operate-process"; |
| | | |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | |
| | | private StationOutboundDecisionSupport stationOutboundDecisionSupport; |
| | | @Autowired |
| | | private BasCrnpService basCrnpService; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private StationCommandDispatcher stationCommandDispatcher; |
| | | |
| | | public void submitStationEnableInTasks(long minIntervalMs) { |
| | | submitStationEnableInTasks(MainProcessLane.STATION_ENABLE_IN, minIntervalMs); |
| | | } |
| | | |
| | | public void submitStationEnableInTasks(MainProcessLane lane, |
| | | long minIntervalMs) { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | if (stationMap == null || stationMap.isEmpty()) { |
| | | continue; |
| | | } |
| | | for (StationObjModel stationObjModel : basDevp.getInStationList$()) { |
| | | Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId(); |
| | | if (stationId == null || !stationMap.containsKey(stationId)) { |
| | | continue; |
| | | } |
| | | mainProcessTaskSubmitter.submitKeyedSerialTask( |
| | | lane, |
| | | stationId, |
| | | "stationEnableInExecute", |
| | | minIntervalMs, |
| | | () -> stationEnableInExecute(basDevp, stationObjModel) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 执行单个站点的入库任务下发 |
| | | public void stationInExecute(BasDevp basDevp, StationObjModel stationObjModel) { |
| | | stationRegularDispatchProcessor.stationInExecute(basDevp, stationObjModel); |
| | | } |
| | | |
| | | // 执行单个站点的启动入库下发 |
| | | public void stationEnableInExecute(BasDevp basDevp, StationObjModel stationObjModel) { |
| | | if (basDevp == null || stationObjModel == null || stationObjModel.getStationId() == null) { |
| | | return; |
| | | } |
| | | |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | return; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | if (stationMap == null || stationMap.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | Integer stationId = stationObjModel.getStationId(); |
| | | if (!stationMap.containsKey(stationId)) { |
| | | return; |
| | | } |
| | | |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (stationProtocol == null) { |
| | | return; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId); |
| | | if (lock != null) { |
| | | return; |
| | | } |
| | | |
| | | if (!stationProtocol.isAutoing() |
| | | || !stationProtocol.isLoading() |
| | | || stationProtocol.getTaskNo() != 0 |
| | | || !stationProtocol.isEnableIn()) { |
| | | return; |
| | | } |
| | | |
| | | Integer backStationId = stationObjModel.getBarcodeStation() == null ? null : stationObjModel.getBarcodeStation().getStationId(); |
| | | if (backStationId == null) { |
| | | return; |
| | | } |
| | | |
| | | StationCommand command = stationThread.getCommand( |
| | | StationCommandType.MOVE, |
| | | commonService.getWorkNo(WrkIoType.ENABLE_IN.id), |
| | | stationId, |
| | | backStationId, |
| | | 0 |
| | | ); |
| | | stationCommandDispatcher.dispatch(basDevp.getDevpNo(), command, STATION_COMMAND_SOURCE, "enable-in"); |
| | | Utils.precomputeInTaskEnableRow(backStationId); |
| | | redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15); |
| | | News.info("{}站点启动入库成功,数据包:{}", stationId, JSON.toJSONString(command)); |
| | | } |
| | | |
| | | // 执行单个出库任务对应的输送站点下发 |
| | | public void crnStationOutExecute(WrkMast wrkMast) { |
| | | stationOutboundDispatchProcessor.crnStationOutExecute(wrkMast); |