| | |
| | | package com.zy.core.plugin; |
| | | |
| | | 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.domain.param.CreateInTaskParam; |
| | | import com.zy.asrs.entity.BasDevp; |
| | | import com.zy.asrs.entity.WrkMast; |
| | | import com.zy.asrs.service.BasDevpService; |
| | | import com.zy.asrs.service.WrkMastService; |
| | | import com.zy.common.model.StartupDto; |
| | | import com.zy.common.service.CommonService; |
| | | 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.StationCommandType; |
| | | import com.zy.core.enums.WrkIoType; |
| | | 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.plugin.api.MainProcessPluginApi; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.core.utils.CrnOperateProcessUtils; |
| | | import com.zy.core.utils.StationOperateProcessUtils; |
| | | import com.zy.core.utils.WmsOperateUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Component |
| | |
| | | private CrnOperateProcessUtils crnOperateUtils; |
| | | @Autowired |
| | | private StationOperateProcessUtils stationOperateProcessUtils; |
| | | @Autowired |
| | | private CommonService commonService; |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private WmsOperateUtils wmsOperateUtils; |
| | | |
| | | @Override |
| | | public void run() { |
| | | //检测入库站是否有任务生成,并启动入库 |
| | | checkInStationHasTask(); |
| | | //请求生成入库任务 |
| | | generateStoreWrkFile(); |
| | | |
| | | //执行堆垛机任务 |
| | | crnOperateUtils.crnIoExecute(); |
| | | //堆垛机任务执行完成-具备仿真能力 |
| | |
| | | stationOperateProcessUtils.stationOutExecute(); |
| | | //检测输送站点出库任务执行完成 |
| | | stationOperateProcessUtils.stationOutExecuteFinish(); |
| | | |
| | | //检测输送站点是否运行堵塞 |
| | | stationOperateProcessUtils.checkStationRunBlock(); |
| | | } |
| | | |
| | | /** |
| | | * 请求生成入库任务 |
| | | * 入库站,根据条码扫描生成入库工作档 |
| | | */ |
| | | public synchronized void generateStoreWrkFile() { |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if(stationThread == null){ |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> list = basDevp.getBarcodeStationList$(); |
| | | for (StationObjModel entity : list) { |
| | | Integer stationId = entity.getStationId(); |
| | | if(!stationMap.containsKey(stationId)){ |
| | | continue; |
| | | } |
| | | |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (stationProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | //满足自动、有物、有工作号,生成入库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.isInEnable() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | ) { |
| | | if (stationProtocol.getError() > 0) { |
| | | Object backLock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationId); |
| | | if (backLock != null) { |
| | | continue; |
| | | } |
| | | |
| | | //报警回退 |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.STATION_BACK.id), stationId, entity.getBackStation().getStationId(), 0); |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationId, "lock", 15); |
| | | News.info("{}站点报警回退成功,数据包:{}", stationId, JSON.toJSONString(command)); |
| | | continue; |
| | | } |
| | | |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | continue; |
| | | } |
| | | |
| | | //检测任务是否生成 |
| | | List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode())); |
| | | if (!wrkMasts.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId); |
| | | if (lock != null) { |
| | | continue; |
| | | } |
| | | redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2); |
| | | |
| | | String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight()); |
| | | if (response == null) { |
| | | News.error("请求WMS入库接口失败,接口未响应!!!response:{}", response); |
| | | continue; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getInteger("code").equals(200)) { |
| | | StartupDto dto = jsonObject.getObject("data", StartupDto.class); |
| | | |
| | | CreateInTaskParam taskParam = new CreateInTaskParam(); |
| | | taskParam.setTaskNo(dto.getTaskNo()); |
| | | taskParam.setLocNo(dto.getLocNo()); |
| | | taskParam.setTaskPri(dto.getTaskPri()); |
| | | taskParam.setBarcode(stationProtocol.getBarcode()); |
| | | WrkMast wrkMast = commonService.createInTask(taskParam); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //检测入库站是否有任务生成,并启动入库 |
| | | private synchronized void checkInStationHasTask() { |
| | | List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if(stationThread == null){ |
| | | continue; |
| | | } |
| | | |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | |
| | | List<StationObjModel> 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; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId); |
| | | if(lock != null){ |
| | | continue; |
| | | } |
| | | |
| | | //满足自动、无物、工作号0,生成入库数据 |
| | | if (stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.getTaskNo() == 0 |
| | | && stationProtocol.isEnableIn() |
| | | ) { |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.ENABLE_IN.id), stationId, entity.getBarcodeStation().getStationId(), 0); |
| | | MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command)); |
| | | redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15); |
| | | News.info("{}站点启动入库成功,数据包:{}", stationId, JSON.toJSONString(command)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |