|  |  |  | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.WorkNoType; | 
|---|
|  |  |  | import com.zy.asrs.entity.LocMast; | 
|---|
|  |  |  | import com.zy.asrs.entity.TaskWrk; | 
|---|
|  |  |  | import com.zy.asrs.entity.TaskWrkReport; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.wms.StorageEscalationParam; | 
|---|
|  |  |  | import com.zy.asrs.entity.wms.WmsResult; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service("toWmsService") | 
|---|
|  |  |  | 
|---|
|  |  |  | @Value("${wms.taskStatusFeedbackPath}") | 
|---|
|  |  |  | private String taskStatusFeedbackPath; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wms.executionStatusReport}") | 
|---|
|  |  |  | private String executionStatusReport; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wms.code}") | 
|---|
|  |  |  | private String code; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addReportLog(TaskWrkLog taskWrk) { | 
|---|
|  |  |  | TaskWrkReport taskWrkReport = new TaskWrkReport(); | 
|---|
|  |  |  | Synchro.Copy(taskWrk, taskWrkReport); | 
|---|
|  |  |  | taskWrkReport.setCreateTime(new Date()); | 
|---|
|  |  |  | taskWrkReportService.insert(taskWrkReport); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addReportLog(WrkMast taskWrk) { | 
|---|
|  |  |  | TaskWrkReport taskWrkReport = new TaskWrkReport(); | 
|---|
|  |  |  | Synchro.Copy(taskWrk, taskWrkReport); | 
|---|
|  |  |  | taskWrkReport.setCreateTime(new Date()); | 
|---|
|  |  |  | taskWrkReportService.insert(taskWrkReport); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public TaskWrk getLocNoFromWms(StorageEscalationParam wmsParam) { | 
|---|
|  |  |  | String response = ""; | 
|---|
|  |  |  | Boolean success = false; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setTimeout(30, TimeUnit.SECONDS) | 
|---|
|  |  |  | .setPath(inboundTaskApplyPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(wmsParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | if (!Cools.isEmpty(response)) { | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | if (!Cools.isEmpty(jsonObject.get(code)) && jsonObject.get(code).equals(successCode)) { | 
|---|
|  |  |  | //有些三方wms系统不能及时返回库位号,这时候就需要 | 
|---|
|  |  |  | //ZWmsResult result = JSON.parseObject(jsonObject.get(data).toString(), WmsResult.class); | 
|---|
|  |  |  | TaskWrk taskWrk = null; | 
|---|
|  |  |  | int i = 1; | 
|---|
|  |  |  | while (i < 10) { | 
|---|
|  |  |  | taskWrk = taskWrkService.selectByBarcode(wmsParam.getBarcode()); | 
|---|
|  |  |  | if (taskWrk != null) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | Thread.sleep(500L); | 
|---|
|  |  |  | } catch (InterruptedException e) { | 
|---|
|  |  |  | throw new RuntimeException(e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if ("700".equals(jsonObject.get(code).toString())) { | 
|---|
|  |  |  | TaskWrk taskWrk=new TaskWrk(); | 
|---|
|  |  |  | taskWrk.setWrkNo(-1); | 
|---|
|  |  |  | return taskWrk; | 
|---|
|  |  |  | } else if (successCode.equals(jsonObject.get(code).toString())) { | 
|---|
|  |  |  | WmsResult result = JSON.parseObject(jsonObject.get(data).toString(), WmsResult.class); | 
|---|
|  |  |  | success = true; | 
|---|
|  |  |  | return createInTask(result, wmsParam.getBarcode(), wmsParam.getStationCode()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | log.info("请求wms报错,{}", e.getMessage()); | 
|---|
|  |  |  | log.info("请求wms报错,入参:{},异常:{}", JSON.toJSONString(wmsParam), e.getMessage()); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | addApiLog("入库任务请求获取库位", wmsUrl + inboundTaskApplyPath, JSON.toJSONString(wmsParam), response, success); | 
|---|
|  |  |  | addApiLog("入库请求WMS", wmsUrl + inboundTaskApplyPath, JSON.toJSONString(wmsParam), response, success); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void executionStatusReport(String taskNo, Integer wrkSts) { | 
|---|
|  |  |  | String response = ""; | 
|---|
|  |  |  | boolean bool = false; | 
|---|
|  |  |  | JSONObject param = new JSONObject(); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | log.info("任务执行状态上报,任务号:{},执行状态:{}", taskNo, wrkSts); | 
|---|
|  |  |  | param.put("taskNo", taskNo); | 
|---|
|  |  |  | param.put("wrkSts", wrkSts); | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | // .setHeaders(headParam) | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(executionStatusReport) | 
|---|
|  |  |  | .setJson(param.toJSONString()) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | if (!Cools.isEmpty(response)) { | 
|---|
|  |  |  | bool = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("任务执行状态上报异常" + e); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | apiLogService.save("任务状态上报" | 
|---|
|  |  |  | , wmsUrl + executionStatusReport | 
|---|
|  |  |  | , null | 
|---|
|  |  |  | , "127.0.0.1" | 
|---|
|  |  |  | , param.toJSONString() | 
|---|
|  |  |  | , response | 
|---|
|  |  |  | , bool | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private TaskWrk createInTask(WmsResult result, String barcode, Integer startPoint) { | 
|---|
|  |  |  | //String locNo = Utils.Fusion(result.getRow(), result.getFloor(), result.getColumn()); | 
|---|
|  |  |  | String locNo = result.getLocNo(); | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | TaskWrk taskWrk = new TaskWrk(); | 
|---|
|  |  |  | 
|---|
|  |  |  | taskWrk.setWrkNo(workNo1); | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//任务状态:派发 | 
|---|
|  |  |  | taskWrk.setCreateTime(now); | 
|---|
|  |  |  | taskWrk.setAssignTime(now); | 
|---|
|  |  |  | taskWrk.setIoType(1);//任务类型 | 
|---|
|  |  |  | taskWrk.setIoPri(13);//优先级 | 
|---|
|  |  |  | taskWrk.setBarcode(barcode);//条码 | 
|---|
|  |  |  | 
|---|
|  |  |  | taskWrk.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | taskWrk.setTargetPoint(locNo); | 
|---|
|  |  |  | taskWrk.setStartPoint(startPoint + ""); | 
|---|
|  |  |  | taskWrk.setCrnNo(result.getCrnNo()); | 
|---|
|  |  |  | if (taskWrk.getIoType() == 1) { | 
|---|
|  |  |  | taskWrk.setWrkSts(2); | 
|---|
|  |  |  | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { | 
|---|
|  |  |  | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | taskWrkService.insert(taskWrk); | 
|---|
|  |  |  | return taskWrk; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|