Browse Source

调度接口

master
周俊杰 2 years ago
parent
commit
79d5772590
  1. 48
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java
  2. 34
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsZDToAcsController.java
  3. 33
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java
  4. 18
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsZDToAcsService.java
  5. 145
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java
  6. 144
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsZDToAcsServiceImpl.java
  7. 29
      acs/nladmin-system/src/main/java/org/nl/config/rest/AcsConfigController.java
  8. 7
      acs/nladmin-system/src/main/java/org/nl/config/server/AcsConfigService.java
  9. 26
      acs/nladmin-system/src/main/java/org/nl/config/server/impl/AcsConfigServiceImpl.java
  10. 12
      acs/nladmin-system/src/main/java/org/nl/modules/logging/service/LogService.java
  11. 5
      acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java
  12. 4
      acs/nladmin-system/src/main/resources/config/application-dev.yml
  13. 2
      acs/nladmin-system/src/main/resources/config/application.yml

48
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsZDController.java

@ -0,0 +1,48 @@
package org.nl.acs.ext.wms.rest;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.annotation.Log;
import org.springframework.context.annotation.Lazy;
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/system_car")
@Slf4j
@Lazy
public class AcsToWmsZDController {
private final AcsToWmsZDController acsToWmsZDService;
@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);
}
@PostMapping("/deviceStatusUpdate")
@Log("设备状态上传")
@ApiOperation("设备状态上传")
public ResponseEntity<Object> deviceStatusUpdate(@RequestBody Map whereJson) throws Exception {
return new ResponseEntity<>(acsToWmsZDService.deviceStatusUpdate(whereJson), HttpStatus.OK);
}
}

34
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsZDToAcsController.java

@ -0,0 +1,34 @@
package org.nl.acs.ext.wms.rest;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.ext.wms.service.WmsZDToAcsService;
import org.nl.modules.logging.annotation.Log;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
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;
@RestController
@RequiredArgsConstructor
@Api(tags = "wms接口")
@RequestMapping("/restful/api/v3")
@Slf4j
@Service
@Lazy
public class WmsZDToAcsController {
private final WmsZDToAcsService wmsZDToAcsService;
@PostMapping("/createTask")
@Log("任务接收")
@ApiOperation("任务接收")
public ResponseEntity<Object> taskCreate(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(wmsZDToAcsService.taskCreate(whereJson), HttpStatus.OK);
}
}

33
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsZDService.java

@ -0,0 +1,33 @@
package org.nl.acs.ext.wms.service;
import com.alibaba.fastjson.JSONObject;
import java.util.Map;
public interface AcsToWmsZDService {
/**
* 任务反馈
*
*
* @return Map<String, Object>
*/
Map<String, Object> taskFeedback(Map whereJson);
/**
* 任务取消
*
*
* @return Map<String, Object>
*/
Map<String, Object> taskDeprecate(Map whereJson);
/**
* 设备状态上传
*
*
* @return Map<String, Object>
*/
Map<String, Object> deviceStatusUpdate(Map whereJson);
}

18
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsZDToAcsService.java

@ -0,0 +1,18 @@
package org.nl.acs.ext.wms.service;
import com.alibaba.fastjson.JSONObject;
import org.nl.acs.ext.wms.data.CreateTaskRequest;
import org.nl.acs.ext.wms.data.CreateTaskResponse;
import java.util.List;
import java.util.Map;
public interface WmsZDToAcsService {
/**
* 任务接收
*
* @return Map<String, Object>
*/
Map<String, Object> taskCreate(JSONObject whereJson);
}

145
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsZDServiceImpl.java

@ -0,0 +1,145 @@
package org.nl.acs.ext.wms.service.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.AcsConfig;
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.AcsToWmsZDService;
import org.nl.acs.opc.DeviceAppService;
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.config.server.AcsConfigService;
import org.nl.modules.logging.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@RequiredArgsConstructor
@Slf4j
public class AcsToWmsZDServiceImpl implements AcsToWmsZDService {
private final DeviceAppService deviceAppService;
@Autowired
AcsConfigService acsConfigService;
@Autowired
AddressService addressService;
@Autowired
LogService logServer;
@Value("${acsTowms.token}")
public String token;
@Override
public Map<String, Object> taskFeedback(Map whereJson) {
log.info("taskFeedback-----请求参数{}", whereJson.toString());
String taskCode = MapUtil.getStr(whereJson, "taskCode");
String carId = MapUtil.getStr(whereJson, "carId");
HttpResponse result = null;
AddressDto addressDto = addressService.findByCode("taskFeedback");
String wcsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WCSURL);
String methods_url = addressDto.getMethods_url();
String url = wcsurl + methods_url;
try {
result = HttpRequest.post(url)
.header("Authorization", token).body(JSON.toJSONString(whereJson))
.execute();
logServer.log(taskCode, "taskFeedback", "success", whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, carId);
JSONObject jo = JSONObject.parseObject(result.body());
return jo;
} catch (Exception e) {
int status = 400;
if (!ObjectUtil.isEmpty(result)) {
status = result.getStatus();
}
logServer.log(taskCode, "taskFeedback", "error", whereJson.toString(), e.getMessage(), String.valueOf(status), url, carId);
Map<String, Object> map = new HashMap<>();
map.put("responseCode", 1);
map.put("responseMessage", e.getMessage());
map.put("parameters", new HashMap<>());
return map;
}
}
@Override
public Map<String, Object> taskDeprecate(Map whereJson) {
log.info("taskDeprecate--------------:输入参数" + whereJson.toString());
String taskCode = MapUtil.getStr(whereJson, "task_code");
HttpResponse result = null;
AddressDto addressDto = addressService.findByCode("deprecateTask");
String wcsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WCSURL);
String methods_url = addressDto.getMethods_url();
String url = wcsurl + methods_url;
try {
result = HttpRequest.post(url)
.header("Authorization", token)
.body(JSON.toJSONString(whereJson))
.execute();
logServer.log(taskCode, "taskDeprecate", "success", whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, "");
JSONObject jo = JSONObject.parseObject(result.body());
return jo;
} catch (Exception e) {
int status = 400;
if (!ObjectUtil.isEmpty(result)) {
status = result.getStatus();
}
logServer.log(taskCode, "taskFeedback", "error", whereJson.toString(), e.getMessage(), String.valueOf(status), url, "");
Map<String, Object> map = new HashMap<>();
map.put("responseCode", 1);
map.put("responseMessage", e.getMessage());
return map;
}
}
@Override
public Map<String, Object> deviceStatusUpdate(Map whereJson) {
Map<String, Object> map = new HashMap<>();
HttpResponse result = null;
AddressDto addressDto = addressService.findByCode("deviceStatusUpdate");
String wcsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WCSURL);
String methods_url = addressDto.getMethods_url();
String url = wcsurl + methods_url;
String deviceCode = MapUtil.getStr(whereJson, "deviceCode");
if (StrUtil.isEmpty(deviceCode)) {
map.put("responseCode", 1);
map.put("responseMessage", "请求设备号不能为空!");
map.put("parameters", new HashMap<>());
return map;
}
try {
result = HttpRequest.post(url)
.header("Authorization", token).body(JSON.toJSONString(whereJson))
.execute();
JSONObject jo = JSONObject.parseObject(result.body());
log.info("checkDeviceStatus-----输出参数{}", jo.toString());
return jo;
} catch (Exception e) {
int status = 400;
if (!ObjectUtil.isEmpty(result)) {
status = result.getStatus();
}
logServer.log(deviceCode, "deviceStatusUpdate", "error", whereJson.toString(), e.getMessage(), String.valueOf(status), url, "");
map.put("responseCode", 1);
map.put("responseMessage", e.getMessage());
return map;
}
}
}

144
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsZDToAcsServiceImpl.java

@ -0,0 +1,144 @@
package org.nl.acs.ext.wms.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.ext.wms.service.WmsZDToAcsService;
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.modules.logging.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@RequiredArgsConstructor
@Slf4j
public class WmsZDToAcsServiceImpl implements WmsZDToAcsService {
@Autowired
RouteLineService routeLineService;
@Autowired
TaskService taskService;
@Autowired
LogService logServer;
@Override
public Map<String, Object> taskCreate(JSONObject whereJson) {
Map<String, Object> map = new HashMap<>();
log.info("taskCreate--------------:输入参数:" + whereJson.toString());
//获取甲方wcs传过来的参数
String houseCode = whereJson.getString("houseCode");
String systemCode = whereJson.getString("systemCode");
JSONObject parameters = whereJson.getJSONObject("parameters");
String taskCode = whereJson.getString("taskCode");
String taskType = whereJson.getString("taskType");
String taskCreateDatetime = whereJson.getString("taskCreateDatetime");
String containerCode = whereJson.getString("containerCode");
String containerType = whereJson.getString("containerType");
String start_point_code = whereJson.getString("locationFrom");
String next_point_code = whereJson.getString("locationTo");
String priority = whereJson.getString("priority");
String start_device_code = "";
String next_device_code = "";
//判断必填项是否为空
if (StrUtil.isEmpty(taskCode)) {
map.put("responseCode", 1);
map.put("responseMessage", "任务号不能为空");
return map;
}
if (StrUtil.isEmpty(start_point_code)) {
map.put("responseCode", 1);
map.put("responseMessage", "起点不能为空");
return map;
}
if (StrUtil.isEmpty(next_point_code)) {
map.put("responseCode", 1);
map.put("responseMessage", "终点不能为空");
return map;
}
if (StrUtil.isEmpty(containerCode)) {
map.put("responseCode", 1);
map.put("responseMessage", "容器编号不能为空");
return map;
}
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;
}
//查询wcs传过来的起点终点路由
List<RouteLineDto> list = routeLineService.getShortPathLines(start_device_code, next_device_code, "normal");
if (ObjectUtil.isEmpty(list)) {
map.put("responseCode", 1);
map.put("responseMessage", "路由不通!");
return map;
}
//查询任务编码是否重复
TaskDto taskDto = taskService.findByCodeFromCache(taskCode);
if (taskDto != null) {
map.put("responseCode", 1);
map.put("responseMessage", "不能存在相同的任务号!");
return map;
}
//判断载具编码是否相同
if (!StrUtil.isEmpty(containerCode)) {
TaskDto vehicle_dto = taskService.findByContainer(containerCode);
if (vehicle_dto != null) {
map.put("responseCode", 1);
map.put("responseMessage", "已存在该容器号的任务!");
return map;
}
}
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("create_time", taskCreateDatetime);
jo.put("task_type", taskType);
TaskDto task_dto = (TaskDto) JSONObject.parseObject(String.valueOf(jo), TaskDto.class);
try {
taskService.create(task_dto);
logServer.log(taskCode, "taskCreate", "success", whereJson.toString(), "创建成功", String.valueOf(200), "/createTask", "");
} catch (Exception e) {
logServer.log(taskCode, "taskCreate", "error", whereJson.toString(), e.getMessage(), String.valueOf(400), "/createTask", "");
e.printStackTrace();
map.put("responseCode", 1);
map.put("responseMessage", e.getMessage());
return map;
}
map.put("responseCode", 0);
map.put("responseMessage", "创建任务成功!");
map.put("parameters", new HashMap<>());
return map;
}
}

29
acs/nladmin-system/src/main/java/org/nl/config/rest/AcsConfigController.java

@ -0,0 +1,29 @@
package org.nl.config.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.config.server.AcsConfigService;
import org.nl.modules.logging.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@Api(tags = "系统参数管理")
@RequestMapping("/api/param")
@Slf4j
public class AcsConfigController {
private final AcsConfigService acsConfigService;
@Log("缓存查询系统参数")
@ApiOperation("缓存查询系统参数")
@PostMapping(value = "/findByCodeFromCache")
public ResponseEntity<Object> findConfigFromCache() {
return new ResponseEntity<>(acsConfigService.findConfigFromCache(), HttpStatus.OK);
}
}

7
acs/nladmin-system/src/main/java/org/nl/config/server/AcsConfigService.java

@ -0,0 +1,7 @@
package org.nl.config.server;
import java.util.Map;
public interface AcsConfigService {
Map<String, String> findConfigFromCache();
}

26
acs/nladmin-system/src/main/java/org/nl/config/server/impl/AcsConfigServiceImpl.java

@ -0,0 +1,26 @@
package org.nl.config.server.impl;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.config.server.AcsConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
@Service
@RequiredArgsConstructor
@Slf4j
public class AcsConfigServiceImpl implements AcsConfigService {
Map<String, String> acsconfigs = new HashMap<>();
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, String> findConfigFromCache() {
Map<String, String> demo = (Map) ObjectUtil.clone(this.acsconfigs);
return demo;
}
}

12
acs/nladmin-system/src/main/java/org/nl/modules/logging/service/LogService.java

@ -79,4 +79,16 @@ public interface LogService {
* 删除所有INFO日志
*/
void delAllByInfo();
/**
* @param task_code 任务编码
* @param method 接口方法名
* @param type 日志类别error / info
* @param requestParam 请求参数
* @param responseParam 返回参数
* @param status_code 接口状态码
* @param requestUrl 请求地址
* @param vehicle_code 载具号
*/
void log(String task_code, String method, String type, String requestParam, String responseParam, String status_code, String requestUrl, String vehicle_code);
}

5
acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java

@ -155,4 +155,9 @@ public class LogServiceImpl implements LogService {
public void delAllByInfo() {
logRepository.deleteByLogType("INFO");
}
@Override
public void log(String task_code, String method, String type, String requestParam, String responseParam, String status_code, String requestUrl, String vehicle_code) {
}
}

4
acs/nladmin-system/src/main/resources/config/application-dev.yml

@ -13,11 +13,11 @@ spring:
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
# url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:wzgj_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
username: ${DB_USER:root}
# password: ${DB_PWD:P@ssw0rd}
# password: ${DB_PWD:Root.123456}
password: ${DB_PWD:password}
password: ${DB_PWD:123456}
# 初始连接数
initial-size: 5

2
acs/nladmin-system/src/main/resources/config/application.yml

@ -78,3 +78,5 @@ security:
- /api/localStorage/pictures
# 参数
- /api/param/getValueByCode
acsTowms:
token: Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiJiZTVmOGZiZDcyMWU0NGFiODRlOGI4NTE4ODE5OWM0ZiIsImF1dGgiOiJ1c2VyOmxpc3QsbW9uaXRvcjpsaXN0Iiwic3ViIjoiYWNzIn0.JGga-TcIHTt76KT_m_7bt-fxdBUdwdRfRjXzwLyPLVLLPoOSXbVPbf2q6vcV-fh33r2wyrBEleWYVPOEvjrZMw

Loading…
Cancel
Save