From 70df41921742998a714cef34cd7d619348900824 Mon Sep 17 00:00:00 2001 From: "USER-20220102CG\\noblelift" <546428999@qq.com> Date: Tue, 19 Jul 2022 16:40:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=AD=E9=BC=8Ewcs?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ext/wms/rest/AcsToWmsZDController.java | 49 +++ .../ext/wms/service/AcsToWmsZDService.java | 40 +++ .../service/impl/AcsToWmsZDServiceImpl.java | 305 ++++++++++++++++++ 3 files changed, 394 insertions(+) create mode 100644 hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java create mode 100644 hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java create mode 100644 hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java new file mode 100644 index 0000000..52420dd --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java @@ -0,0 +1,49 @@ +package org.nl.acs.ext.wms.rest; + + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONObject; +import org.nl.acs.ext.wms.service.AcsToWmsZDService; +import org.nl.annotation.Log; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequiredArgsConstructor +@Api(tags = "wms接口") +@RequestMapping("/restful/api/v3") +@Slf4j +public class AcsToWmsZDController { + + private final AcsToWmsZDService acsToWmsZDService; + + @PostMapping("/createTask") + @Log("任务接收") + @ApiOperation("任务接收") + public ResponseEntity taskCreate(@RequestBody JSONObject whereJson) { + return new ResponseEntity<>(acsToWmsZDService.taskCreate(whereJson), HttpStatus.OK); + } + + @PostMapping("/feedbackTask") + @Log("任务反馈") + @ApiOperation("任务反馈") + public ResponseEntity taskFeedback(@RequestBody Map whereJson) throws Exception { + return new ResponseEntity<>(acsToWmsZDService.taskFeedback(whereJson), HttpStatus.OK); + } + + @PostMapping("/deprecateTask") + @Log("任务取消") + @ApiOperation("任务取消") + public ResponseEntity taskDeprecate(@RequestBody Map whereJson) throws Exception { + return new ResponseEntity<>(acsToWmsZDService.taskDeprecate(whereJson), HttpStatus.OK); + } +} diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java new file mode 100644 index 0000000..c1b8083 --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java @@ -0,0 +1,40 @@ +package org.nl.acs.ext.wms.service; + +import cn.hutool.http.HttpResponse; +import net.sf.json.JSONObject; + +import java.util.Map; + +public interface AcsToWmsZDService { + + /** + * 任务接收 + * + * @return Map + */ + Map taskCreate(JSONObject whereJson); + + /** + * 任务反馈 + * + * + * @return Map + */ + Map taskFeedback(Map whereJson) throws Exception; + + /** + * 任务取消 + * + * + * @return Map + */ + Map taskDeprecate(Map whereJson) throws Exception; + + /** + * 设备查询 + * + * + * @return Map + */ + HttpResponse deviceStatusQuery(JSONObject whereJson) throws Exception; +} diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java new file mode 100644 index 0000000..3d98128 --- /dev/null +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java @@ -0,0 +1,305 @@ +package org.nl.acs.ext.wms.service.impl; + + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +import org.nl.acs.config.AcsConfig; +import org.nl.acs.config.server.AcsConfigService; +import org.nl.acs.device.address.service.AddressService; +import org.nl.acs.device.address.service.dto.AddressDto; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.ext.wms.service.AcsToWmsZDService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.LogServer; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.exception.WDKException; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +@Service +@RequiredArgsConstructor +@Slf4j +public class AcsToWmsZDServiceImpl implements AcsToWmsZDService { + + @Autowired + RouteLineService routeLineService; + + @Autowired + TaskService taskService; + + @Autowired + DeviceService deviceService; + + @Autowired + AcsConfigService acsConfigService; + + @Autowired + AddressService addressService; + + @Autowired + AcsToWmsService acsToWmsService; + + @Autowired + LogServer logServer; + + @Override + public Map taskCreate(JSONObject whereJson) { + + JSONObject resultJson = new JSONObject(); + log.info("taskCreate--------------:输入参数:" + whereJson.toString()); + try { + JSONArray errArr = new JSONArray(); + String taskCode = whereJson.optString("taskCode"); + String taskType = whereJson.optString("taskType"); + String taskCreateDatetime = whereJson.optString("taskCreateDatetime"); + String containerCode = whereJson.optString("containerCode"); + String containerType = whereJson.optString("containerType"); + String start_point_code = whereJson.optString("locationFrom"); + String next_point_code = whereJson.optString("locationTo"); + String priority = whereJson.optString("priority"); + + String start_device_code = ""; + String next_device_code = ""; + if (StrUtil.isEmpty(taskCode)) { + throw new WDKException("任务号不能为空"); + } + if (StrUtil.isEmpty(start_point_code)) { + throw new WDKException("起点不能为空"); + } + if (StrUtil.isEmpty(next_point_code)) { + throw new WDKException("终点不能为空"); + } + if (StrUtil.isEmpty(containerCode)) { + throw new WDKException("容器编号不能为空"); + } + + JSONObject start_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_point_code + "'").uniqueResult(0); + if (!ObjectUtil.isEmpty(start_device_json)) { + start_point_code = (String) start_device_json.get("parent_storage_code") == null ? start_point_code : (String) start_device_json.get("storage_code"); + } + JSONObject next_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_point_code + "'").uniqueResult(0); + if (!ObjectUtil.isEmpty(next_device_json)) { + next_point_code = (String) next_device_json.get("parent_storage_code") == null ? next_point_code : (String) next_device_json.get("storage_code"); + } + + String route_plan_code = whereJson.optString("route_plan_code"); + String remark = whereJson.optString("remark"); + String params = whereJson.optString("params"); + + if (start_point_code.indexOf("-") > 0) { + String str[] = start_point_code.split("-"); + start_device_code = str[0]; + } else { + start_device_code = start_point_code; + } + + if (next_point_code.indexOf("-") > 0) { + String str[] = next_point_code.split("-"); + next_device_code = str[0]; + } else { + next_device_code = next_point_code; + } + if (StrUtil.isEmpty(route_plan_code)) { + route_plan_code = "normal"; + } + + List list = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + + if (ObjectUtil.isEmpty(list)) { + throw new WDKException("路由不通!"); + } + TaskDto taskDto = taskService.findByCodeFromCache(taskCode); + if (taskDto != null) { + throw new WDKException("不能存在相同的任务号!"); + } + if (!StrUtil.isEmpty(containerCode)) { + TaskDto vehicle_dto = taskService.findByContainer(containerCode); + if (vehicle_dto != null) { + throw new WDKException("已存在该容器号的任务!"); + } + } + + JSONObject jo = new JSONObject(); + jo.put("task_code", taskCode); + jo.put("start_point_code", start_point_code); + jo.put("next_point_code", next_point_code); + jo.put("start_parent_code", start_point_code); + jo.put("next_parent_code", next_point_code); + jo.put("start_device_code", start_device_code); + jo.put("next_device_code", next_device_code); + jo.put("priority", priority); + jo.put("vehicle_code", containerCode); + jo.put("vehicle_type", containerType); + jo.put("remark", remark); + jo.put("params", params); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject startjo = new JSONObject(); + startjo.put("device_code", start_device_code); + startjo.put("hasGoodStatus", "2"); + startjo.put("material_type", ""); + startjo.put("batch", ""); + startjo.put("islock", "false"); + deviceService.changeDeviceStatus(startjo); + + JSONObject nextjo = new JSONObject(); + nextjo.put("device_code", next_device_code); + nextjo.put("hasGoodStatus", "0"); + nextjo.put("material_type", ""); + nextjo.put("batch", ""); + nextjo.put("islock", "false"); + deviceService.changeDeviceStatus(nextjo); + + TaskDto task_dto = (TaskDto) JSONObject.toBean(jo, TaskDto.class); + try { + taskService.create(task_dto); + } catch (Exception e) { + e.printStackTrace(); + JSONObject json = new JSONObject(); + json.put("task_code", taskCode); + json.put("message", e.getMessage()); + errArr.add(json); + } + + if (ObjectUtil.isEmpty(errArr)) { + resultJson.put("responseCode", 200); + } else { + resultJson.put("responseCode", 400); + } + + resultJson.put("errArr", errArr); + resultJson.put("responseMessage", "操作成功"); + resultJson.put("data", new JSONObject()); + log.info("taskCreate--------------:输出参数:" + resultJson.toString()); + + } catch (Exception e) { + resultJson.put("responseCode", 400); + resultJson.put("errArr", e.getMessage()); + resultJson.put("responseMessage", e.getMessage()); + resultJson.put("data", new JSONObject()); + log.info("taskCreate--------------:输出参数:" + resultJson.toString()); + } + return resultJson; + } + + @Override + public Map taskFeedback(Map whereJson){ + JSONObject resultJson = new JSONObject(); + log.info("taskFeedback--------------:输入参数" + whereJson.toString()); + String carId = whereJson.get("carId").toString(); + String task_code = whereJson.get("taskCode").toString(); + String task_type = whereJson.get("taskType").toString(); + String feedbackStatus = whereJson.get("feedbackStatus").toString(); + + if (StrUtil.isEmpty(task_code)) { + throw new WDKException("任务号不能为空"); + } + + if (StrUtil.isEmpty(carId)) { + throw new WDKException("车号不能为空"); + } + + if (StrUtil.isEmpty(task_type)) { + throw new WDKException("任务类型不能为空"); + } + + if (StrUtil.isEmpty(feedbackStatus)) { + throw new WDKException("任务反馈状态不能为空"); + } + + JSONObject feedjo = new JSONObject(); + feedjo.put("carId",carId); + feedjo.put("task_code",task_code); + feedjo.put("task_type",task_type); + feedjo.put("feedbackStatus",feedbackStatus); + JSONArray feedja = JSONArray.fromObject(feedjo); + + try { + acsToWmsService.feedbackTaskStatusToWms(feedja); + resultJson.put("responseCode", 200); + resultJson.put("responseMessage", "操作成功"); + resultJson.put("data", new JSONObject()); + log.info("taskFeedback--------------:输出参数" + resultJson.toString()); + } catch (Exception e) { + e.printStackTrace(); + String msg = e.getMessage(); + log.info("taskFeedback--------------:异常输出参数" + msg); + resultJson.put("responseCode", 400); + resultJson.put("responseMessage", msg); + resultJson.put("data", new JSONObject()); + } + return resultJson; + } + + @Override + public Map taskDeprecate(Map whereJson) throws Exception { + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + log.info("taskDeprecate--------------:输入参数" + whereJson.toString()); + String reason = whereJson.get("reason").toString(); + String task_code = whereJson.get("taskCode").toString(); + + if (StrUtil.isEmpty(task_code)) { + throw new WDKException("任务号不能为空"); + } + TaskDto taskDto = taskService.findByCode(task_code); + String task_id = taskDto.getTask_id(); + String cancelTaskCheck = acsConfigService.findConfigFromCache().get(AcsConfig.CANCELTASKCHECK); + if (StrUtil.equals(cancelTaskCheck, "1")) { + taskService.cancel(task_id); + } else if (StrUtil.equals(cancelTaskCheck, "0")) { + Instruction inst = instructionService.findByTaskcode(task_code); + if (inst == null) { + taskService.cancel(task_id); + } else { + throw new RuntimeException("指令正在执行中,操作失败!"); + } + } + + JSONObject resultJson = new JSONObject(); + resultJson.put("responseCode", 200); + resultJson.put("responseMessage", "操作成功"); + resultJson.put("data", new JSONObject()); + log.info("taskDeprecate--------------:输出参数" + resultJson.toString()); + return resultJson; + } + + @Override + public HttpResponse deviceStatusQuery(JSONObject whereJson) throws Exception { + String wmsUrl = acsConfigService.findConfigFromCache().get(AcsConfig.WMSURL); + + AddressDto addressDto = addressService.findByCode("deviceStatusQuery"); + String methods_url = addressDto.getMethods_url(); + String url = wmsUrl + methods_url; + HttpResponse result = null; + log.info("feedWeighing----请求参数{}", whereJson); + + try { + result = HttpRequest.post(url) + .body(String.valueOf(whereJson)) + .execute(); + System.out.println(result); + log.info("feedWeighing----返回参数{}", result); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + System.out.println(msg); + } + return result; + } +}