| | |
| | | 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 org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class StoreInTaskGenerationService { |
| | | private static final int APPLY_IN_TASK_TIMEOUT_SECONDS = 5; |
| | | |
| | | @Autowired |
| | | private BasDevpService basDevpService; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | |
| | | * 保留当前按站点 lane 并发的能力,同时用一个简单计数避免并发生成把站点任务数顶穿上限。 |
| | | */ |
| | | private int inFlightGenerateCount = 0; |
| | | |
| | | public void generate(StoreInTaskPolicy policy) { |
| | | try { |
| | | if (!policy.isEnabled()) { |
| | | return; |
| | | } |
| | | |
| | | HashMap<String, String> systemConfigMap = getSystemConfigMap(); |
| | | if (systemConfigMap == null) { |
| | | return; |
| | | } |
| | | if (!hasAvailableStationTaskCapacity(systemConfigMap)) { |
| | | return; |
| | | } |
| | | |
| | | List<BasDevp> basDevps = basDevpService.list(new QueryWrapper<>()); |
| | | for (BasDevp basDevp : basDevps) { |
| | | List<StationObjModel> barcodeStations = policy.getBarcodeStations(basDevp); |
| | | for (StationObjModel stationObjModel : barcodeStations) { |
| | | generateByStation(policy, basDevp, stationObjModel, systemConfigMap); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | News.error("生成入库任务异常,policy={}", policy.getPolicyName(), e); |
| | | } |
| | | } |
| | | |
| | | public void generate(StoreInTaskPolicy policy, BasDevp basDevp, StationObjModel stationObjModel) { |
| | | try { |
| | |
| | | if (context == null) { |
| | | return; |
| | | } |
| | | if (!policy.matchCandidate(context)) { |
| | | |
| | | StationProtocol stationProtocol = context.getStationProtocol(); |
| | | if (stationProtocol == null) { |
| | | return; |
| | | } |
| | | if (!policy.beforeApply(context)) { |
| | | |
| | | if (!stationProtocol.isAutoing()) { |
| | | return; |
| | | } |
| | | |
| | | if (!stationProtocol.isLoading()) { |
| | | return; |
| | | } |
| | | |
| | | if (!stationProtocol.isInEnable()) { |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.getTaskNo() == 0) { |
| | | return; |
| | | } |
| | | |
| | | if (Cools.isEmpty(stationProtocol.getBarcode())) { |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.getError() > 0) { |
| | | return; |
| | | } |
| | | |
| | | if (stationProtocol.isInBarcodeError()) { |
| | | return; |
| | | } |
| | | |
| | |
| | | result.setResponse(response); |
| | | result.setMessage(message); |
| | | |
| | | News.error("WMS入库请求失败,barcode={},stationId={},response={}", |
| | | request.getBarcode(), request.getSourceStaNo(), policy.buildFailureMessage(result)); |
| | | News.error("WMS入库请求失败,barcode={},stationId={},response={},WCS响应={}", |
| | | request.getBarcode(), request.getSourceStaNo(), result.getResponse(), result.getMessage()); |
| | | redisUtil.set(policy.getGenerateLockKey(context), "lock", policy.getRetryLockSeconds(context)); |
| | | policy.onApplyFailed(context, result); |
| | | } |