| | |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.common.entity.Parameter; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import com.zy.integration.iot.biz.IotInstructionService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | public static final String ERP_REPORT_PENDING_FLAG = "P"; |
| | | public static final String ERP_REPORT_SUCCESS_FLAG = "Y"; |
| | | public static final String ERP_REPORT_FAIL_FLAG = "F"; |
| | | public static final String ERP_REPORT_SKIPPED_FLAG = "S"; |
| | | |
| | | private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; |
| | | |
| | |
| | | private WaitPakinService waitPakinService; |
| | | @Autowired |
| | | private ApiLogService apiLogService; |
| | | @Autowired |
| | | private IotInstructionService iotInstructionService; |
| | | |
| | | @Value("${erp.switch.ErpReportOld}") |
| | | private boolean erpReportOld; |
| | |
| | | public ReturnT<String> start(WrkMast source) { |
| | | WrkMast wrkMast = wrkMastService.selectById(source.getWrkNo()); |
| | | if (wrkMast == null || !Long.valueOf(ERP_REPORT_PENDING_WRK_STS).equals(wrkMast.getWrkSts())) { |
| | | return SUCCESS; |
| | | } |
| | | |
| | | // 历史/运行中数据可能已经在完工时被置为 ERP 待上报。 |
| | | // 调度器执行前再做一次来源判断,确保 MQTT 来源任务即使已进入待上报状态,也会被改回完成态并跳过 ERP HTTP 调用。 |
| | | if (iotInstructionService.isMqttOriginWork(wrkMast)) { |
| | | skipReport(wrkMast); |
| | | return SUCCESS; |
| | | } |
| | | |
| | |
| | | param.setCreateTime(formatDate(resolveCreateTime(wrkMast))); |
| | | param.setBizNo(resolveBizNo(wrkDetls, waitPakin)); |
| | | param.setStartTime(formatDate(resolveStartTime(wrkMast, waitPakin))); |
| | | param.setPhotos(wrkDetls.get(0).getPic()); |
| | | return param; |
| | | } |
| | | |
| | | /** 上报 ERP 重量:称重减固定值,负则按 0 */ |
| | | /** 上报 ERP 重量:≤20 传 0,>20 减 10 */ |
| | | private static BigDecimal adjustErpReportWeight(BigDecimal scWeight) { |
| | | BigDecimal base = scWeight == null ? BigDecimal.ZERO : scWeight; |
| | | BigDecimal v = base.subtract(new BigDecimal("10")); |
| | | return v.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : v; |
| | | if (base.compareTo(new BigDecimal("20")) <= 0) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | return base.subtract(new BigDecimal("20.8")); |
| | | // BigDecimal v = base.subtract(new BigDecimal("10")); |
| | | // return v.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : v; |
| | | } |
| | | private String resolvePalletId(WrkMast wrkMast, List<WrkDetl> wrkDetls) { |
| | | if (!Cools.isEmpty(wrkMast.getBarcode())) { |
| | |
| | | // } |
| | | |
| | | private Date resolveCreateTime(WrkMast wrkMast) { |
| | | if (!Cools.isEmpty(wrkMast.getCrnEndTime())) { |
| | | return wrkMast.getCrnEndTime(); |
| | | } |
| | | if (!Cools.isEmpty(wrkMast.getModiTime())) { |
| | | return wrkMast.getModiTime(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void skipReport(WrkMast wrkMast) { |
| | | Date now = new Date(); |
| | | wrkMast.setWrkSts(ERP_REPORT_FINISHED_WRK_STS); |
| | | wrkMast.setLogMk(ERP_REPORT_SKIPPED_FLAG); |
| | | wrkMast.setExpTime(0D); |
| | | wrkMast.setLogErrMemo(null); |
| | | wrkMast.setLogErrTime(null); |
| | | wrkMast.setModiTime(now); |
| | | if (!wrkMastService.updateById(wrkMast)) { |
| | | throw new IllegalStateException("skip inbound erp report failed, workNo=" + wrkMast.getWrkNo()); |
| | | } |
| | | // 兼容已进入 ERP 待上报的旧任务:跳过 ERP 后补一次 MQTT 完工入队,已有记录时 queueWorkCompletion 会直接返回。 |
| | | iotInstructionService.queueWorkCompletion(wrkMast); |
| | | } |
| | | |
| | | private String truncate(String message, int maxLength) { |
| | | if (message == null || message.length() <= maxLength) { |
| | | return message; |