| | |
| | | package com.zy.core.plugin; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.core.common.Cools; |
| | | import com.zy.asrs.domain.param.CreateInTaskParam; |
| | | import com.zy.asrs.utils.Utils; |
| | | 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.model.command.StationCommand; |
| | | import com.zy.core.model.protocol.StationProtocol; |
| | | import com.zy.core.plugin.api.MainProcessPluginApi; |
| | | import com.zy.core.plugin.store.StoreInTaskContext; |
| | | import com.zy.core.plugin.store.StoreInTaskGenerationService; |
| | | import com.zy.core.plugin.store.StoreInTaskPolicy; |
| | | import com.zy.core.thread.StationThread; |
| | | import com.zy.core.utils.CrnOperateProcessUtils; |
| | | import com.zy.core.utils.DualCrnOperateProcessUtils; |
| | | 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.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private WmsOperateUtils wmsOperateUtils; |
| | | @Autowired |
| | | private DualCrnOperateProcessUtils dualCrnOperateProcessUtils; |
| | | @Autowired |
| | |
| | | * 入库站,根据条码扫描生成入库工作档 |
| | | */ |
| | | public synchronized void generateStoreWrkFile() { |
| | | storeInTaskGenerationService.generate(this); |
| | | submitGenerateStoreTasks(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean matchCandidate(StoreInTaskContext context) { |
| | | StationProtocol stationProtocol = context.getStationProtocol(); |
| | | return stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.isInEnable() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | && !Cools.isEmpty(stationProtocol.getBarcode()); |
| | | } |
| | | private void submitGenerateStoreTasks() { |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo()); |
| | | if (stationThread == null) { |
| | | continue; |
| | | } |
| | | |
| | | @Override |
| | | public boolean beforeApply(StoreInTaskContext context) { |
| | | StationProtocol stationProtocol = context.getStationProtocol(); |
| | | if (stationProtocol.getError() <= 0) { |
| | | return true; |
| | | } |
| | | Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap(); |
| | | if (stationMap == null || stationMap.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo()); |
| | | if (lock != null) { |
| | | return false; |
| | | List<StationObjModel> barcodeStations = getBarcodeStations(basDevp); |
| | | for (StationObjModel stationObjModel : barcodeStations) { |
| | | Integer stationId = stationObjModel == null ? null : stationObjModel.getStationId(); |
| | | if (stationId == null || !stationMap.containsKey(stationId)) { |
| | | continue; |
| | | } |
| | | |
| | | StationProtocol stationProtocol = stationMap.get(stationId); |
| | | if (!canSubmitGenerateStoreTask(basDevp, stationThread, stationObjModel, stationProtocol)) { |
| | | continue; |
| | | } |
| | | |
| | | storeInTaskGenerationService.submitGenerateStoreTask(this, basDevp, stationObjModel, 0L, |
| | | () -> storeInTaskGenerationService.generate(this, basDevp, stationObjModel)); |
| | | } |
| | | } |
| | | StationObjModel backStation = context.getStationObjModel().getBackStation(); |
| | | StationCommand command = context.getStationThread().getCommand(StationCommandType.MOVE, |
| | | commonService.getWorkNo(WrkIoType.STATION_BACK.id), |
| | | context.getStationObjModel().getStationId(), |
| | | backStation.getStationId(), 0); |
| | | if (command == null) { |
| | | News.taskInfo(stationProtocol.getTaskNo(), "{}工作,获取输送线命令失败", stationProtocol.getTaskNo()); |
| | | return false; |
| | | } |
| | | stationCommandDispatcher.dispatch(context.getBasDevp().getDevpNo(), command, "xiaosong-process", "station-back"); |
| | | News.taskInfo(stationProtocol.getTaskNo(), "{}扫码异常,已退回至{}", backStation.getStationId()); |
| | | redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo(), "lock", 10); |
| | | return true; |
| | | } |
| | | |
| | | //检测入库站是否有任务生成,并启动入库 |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean canSubmitGenerateStoreTask(BasDevp basDevp, |
| | | StationThread stationThread, |
| | | StationObjModel stationObjModel, |
| | | StationProtocol stationProtocol) { |
| | | if (!handleErrorStationBack(basDevp, stationThread, stationObjModel, stationProtocol)) { |
| | | return false; |
| | | } |
| | | return canRequestStoreIn(stationProtocol); |
| | | } |
| | | |
| | | private boolean canRequestStoreIn(StationProtocol stationProtocol) { |
| | | return stationProtocol != null |
| | | && stationProtocol.getError() <= 0 |
| | | && stationProtocol.isAutoing() |
| | | && stationProtocol.isLoading() |
| | | && stationProtocol.isInEnable() |
| | | && stationProtocol.getTaskNo() > 0 |
| | | && !Cools.isEmpty(stationProtocol.getBarcode()); |
| | | } |
| | | |
| | | private boolean handleErrorStationBack(BasDevp basDevp, |
| | | StationThread stationThread, |
| | | StationObjModel stationObjModel, |
| | | StationProtocol stationProtocol) { |
| | | if (stationProtocol.getError() <= 0) { |
| | | return true; |
| | | } |
| | | |
| | | Object lock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo()); |
| | | if (lock != null) { |
| | | return false; |
| | | } |
| | | StationObjModel backStation = stationObjModel.getBackStation(); |
| | | StationCommand command = stationThread.getCommand(StationCommandType.MOVE, |
| | | commonService.getWorkNo(WrkIoType.STATION_BACK.id), |
| | | stationObjModel.getStationId(), |
| | | backStation.getStationId(), 0); |
| | | if (command == null) { |
| | | News.taskInfo(stationProtocol.getTaskNo(), "{}工作,获取输送线命令失败", stationProtocol.getTaskNo()); |
| | | return false; |
| | | } |
| | | stationCommandDispatcher.dispatch(basDevp.getDevpNo(), command, "xiaosong-process", "station-back"); |
| | | News.taskInfo(stationProtocol.getTaskNo(), "{}扫码异常,已退回至{}", backStation.getStationId()); |
| | | redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getTaskNo(), "lock", 10); |
| | | return false; |
| | | } |
| | | |
| | | } |