Browse Source

更新中鼎wcs接口

master
汪菘 2 years ago
parent
commit
70df419217
  1. 49
      hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java
  2. 40
      hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java
  3. 305
      hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java

49
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<Object> taskCreate(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(acsToWmsZDService.taskCreate(whereJson), HttpStatus.OK);
}
@PostMapping("/feedbackTask")
@Log("任务反馈")
@ApiOperation("任务反馈")
public ResponseEntity<Object> taskFeedback(@RequestBody Map whereJson) throws Exception {
return new ResponseEntity<>(acsToWmsZDService.taskFeedback(whereJson), HttpStatus.OK);
}
@PostMapping("/deprecateTask")
@Log("任务取消")
@ApiOperation("任务取消")
public ResponseEntity<Object> taskDeprecate(@RequestBody Map whereJson) throws Exception {
return new ResponseEntity<>(acsToWmsZDService.taskDeprecate(whereJson), HttpStatus.OK);
}
}

40
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<String, Object>
*/
Map<String, Object> taskCreate(JSONObject whereJson);
/**
* 任务反馈
*
*
* @return Map<String, Object>
*/
Map<String, Object> taskFeedback(Map whereJson) throws Exception;
/**
* 任务取消
*
*
* @return Map<String, Object>
*/
Map<String, Object> taskDeprecate(Map whereJson) throws Exception;
/**
* 设备查询
*
*
* @return Map<String, Object>
*/
HttpResponse deviceStatusQuery(JSONObject whereJson) throws Exception;
}

305
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<String, Object> 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<RouteLineDto> 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<String, Object> 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<String, Object> 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;
}
}
Loading…
Cancel
Save