|  |  |  | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.domain.dto.NotifyCustomDataDto; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.NotifyMsgType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.TaskStatusType; | 
|---|
|  |  |  | import com.zy.asrs.domain.enums.WorkNoType; | 
|---|
|  |  |  | import com.zy.asrs.entity.*; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.*; | 
|---|
|  |  |  | import com.zy.asrs.service.*; | 
|---|
|  |  |  | import com.zy.asrs.utils.NotifyUtils; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.service.CommonService; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import com.zy.core.cache.MessageQueue; | 
|---|
|  |  |  | import com.zy.core.enums.SlaveType; | 
|---|
|  |  |  | import com.zy.core.model.Task; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping("/open") | 
|---|
|  |  |  | public class OpenController extends BaseController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wms.url}") | 
|---|
|  |  |  | private String wmsUrl; | 
|---|
|  |  |  | @Value("${wms.inboundTaskApplyPath}") | 
|---|
|  |  |  | private String inboundTaskApplyPath; | 
|---|
|  |  |  | @Value("${wms.taskStatusFeedbackPath}") | 
|---|
|  |  |  | private String taskStatusFeedbackPath; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private OpenService openService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | private CommandInfoService commandInfoService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TaskWrkController taskWrkController; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasDevpService basDevpService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiLogService apiLogService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | private LocMastService locMastService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasCrnErrorService basCrnErrorService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private NotifyUtils notifyUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final boolean auth = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(crnStatusParams); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //模拟输送线入库 | 
|---|
|  |  |  | @PostMapping("/simulationDevpIn") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R simulationDevpIn(@RequestBody SimulationDevpInParam param) { | 
|---|
|  |  |  | String barcode = param.getBarcode(); | 
|---|
|  |  |  | Integer staNo = param.getStaNo(); | 
|---|
|  |  |  | Boolean back = param.getBack(); | 
|---|
|  |  |  | String errMsg = param.getErrMsg(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | TaskWrk taskWrk1 = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode)); | 
|---|
|  |  |  | if (taskWrk1 != null) { | 
|---|
|  |  |  | log.info("托盘码:" + barcode + "任务档存在"); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | HashMap<String, Object> requestParam = new HashMap<>(); | 
|---|
|  |  |  | requestParam.put("BoxNo", barcode);//托盘码 | 
|---|
|  |  |  | requestParam.put("TerminalNo", staNo);//入库口 | 
|---|
|  |  |  | if (back) { | 
|---|
|  |  |  | requestParam.put("WCSStatus", 1);//失败 | 
|---|
|  |  |  | requestParam.put("WCSErrorMessage", errMsg);//失败原因 | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | requestParam.put("WCSStatus", 0);//成功 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String response = ""; | 
|---|
|  |  |  | Boolean success = false; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wmsUrl) | 
|---|
|  |  |  | .setPath(inboundTaskApplyPath) | 
|---|
|  |  |  | .setJson(JSON.toJSONString(requestParam)) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | int returnStatus = Integer.parseInt(jsonObject.get("ReturnStatus").toString()); | 
|---|
|  |  |  | if (returnStatus == 0) { | 
|---|
|  |  |  | Result result = JSON.parseObject(jsonObject.get("Result").toString(), Result.class); | 
|---|
|  |  |  | // 创新一个入库工作档 | 
|---|
|  |  |  | TaskWrk taskWrk = taskWrkService.selectByTaskNo(result.getTaskNo()); | 
|---|
|  |  |  | if(taskWrk != null) { | 
|---|
|  |  |  | log.info("任务:" + result.getTaskNo() + "已经存在"); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String locNo = Utils.getLocNo(result.getRow(), result.getFloor(), result.getColumn()); | 
|---|
|  |  |  | LocMast locMast = locMastService.selectByLocNo(locNo); | 
|---|
|  |  |  | if (locMast == null) { | 
|---|
|  |  |  | log.info(locNo + "库位不存在"); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!locMast.getLocSts().equals("O")) { | 
|---|
|  |  |  | log.info(locNo + "库位不处于空库位"); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date now = new Date(); | 
|---|
|  |  |  | taskWrk = new TaskWrk(); | 
|---|
|  |  |  | taskWrk.setTaskNo(result.getTaskNo());//任务号 | 
|---|
|  |  |  | taskWrk.setWrkNo(commonService.getWorkNo(WorkNoType.PAKIN.type));//获取入库工作号 | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.RECEIVE.id);//任务状态:接收 | 
|---|
|  |  |  | taskWrk.setWrkSts(2);//2.设备上走 | 
|---|
|  |  |  | taskWrk.setCreateTime(now); | 
|---|
|  |  |  | taskWrk.setIoType(1);//任务类型 | 
|---|
|  |  |  | taskWrk.setIoPri(13);//优先级 | 
|---|
|  |  |  | taskWrk.setBarcode(barcode);//条码 | 
|---|
|  |  |  | taskWrk.setCrnNo(locMast.getCrnNo()); | 
|---|
|  |  |  | taskWrk.setTargetPoint(locNo); | 
|---|
|  |  |  | taskWrk.setStartPoint(String.valueOf(staNo)); | 
|---|
|  |  |  | if (!Cools.isEmpty(taskWrk.getTargetPoint())) { | 
|---|
|  |  |  | taskWrk.setOriginTargetPoint(taskWrk.getTargetPoint()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!taskWrkService.insert(taskWrk)) { | 
|---|
|  |  |  | log.info("任务:" + result.getTaskNo() + "任务创建失败"); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | locMast.setLocSts("S"); | 
|---|
|  |  |  | locMast.setModiTime(new Date()); | 
|---|
|  |  |  | locMastService.updateById(locMast); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //上报 | 
|---|
|  |  |  | HashMap<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("TaskNo", taskWrk.getTaskNo()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | NotifyCustomDataDto customDataDto = new NotifyCustomDataDto(); | 
|---|
|  |  |  | customDataDto.setUri(wmsUrl); | 
|---|
|  |  |  | customDataDto.setPath(taskStatusFeedbackPath); | 
|---|
|  |  |  | customDataDto.setData(JSON.toJSONString(hashMap)); | 
|---|
|  |  |  | boolean notifyResult = notifyUtils.notify("task", 1, String.valueOf(taskWrk.getWrkNo()), taskWrk.getTaskNo(), NotifyMsgType.TASK_START, JSON.toJSONString(taskWrk), true, customDataDto); | 
|---|
|  |  |  | if(notifyResult) { | 
|---|
|  |  |  | taskWrk.setStatus(TaskStatusType.DISTRIBUTE.id);//任务派发 | 
|---|
|  |  |  | taskWrkService.updateById(taskWrk); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("请求入库调用接口失败"); | 
|---|
|  |  |  | log.error("异常信息打印:" + e); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | apiLogService.save("wms请求入库货位接口" | 
|---|
|  |  |  | , wmsUrl + inboundTaskApplyPath | 
|---|
|  |  |  | , null | 
|---|
|  |  |  | , "127.0.0.1" | 
|---|
|  |  |  | , JSON.toJSONString(requestParam) | 
|---|
|  |  |  | , response | 
|---|
|  |  |  | , success | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("入库请求参数=" + JSON.toJSONString(barcode)); | 
|---|
|  |  |  | log.info("入库请求返回参数=" + JSON.toJSONString(response)); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|