|
|
@ -8,30 +8,26 @@ 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.device_driver.standard_conveyor_line.StandardConveyorLineDeviceDriver; |
|
|
|
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.opc.Device; |
|
|
|
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.exception.BadRequestException; |
|
|
|
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.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
@ -40,6 +36,8 @@ import java.util.Map; |
|
|
|
@Slf4j |
|
|
|
public class AcsToWmsZDServiceImpl implements AcsToWmsZDService { |
|
|
|
|
|
|
|
private final DeviceAppService deviceAppService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
RouteLineService routeLineService; |
|
|
|
|
|
|
@ -64,121 +62,117 @@ public class AcsToWmsZDServiceImpl implements AcsToWmsZDService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> taskCreate(JSONObject whereJson) { |
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
log.info("taskCreate--------------:输入参数:" + whereJson.toString()); |
|
|
|
try { |
|
|
|
JSONArray errArr = new JSONArray(); |
|
|
|
|
|
|
|
//获取甲方wcs传过来的参数
|
|
|
|
String houseCode = whereJson.optString("houseCode"); |
|
|
|
String systemCode = whereJson.optString("systemCode"); |
|
|
|
JSONObject parameters = whereJson.optJSONObject("parameters"); |
|
|
|
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("容器编号不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if (start_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = start_point_code.split("-"); |
|
|
|
start_device_code = str[0]; |
|
|
|
} else { |
|
|
|
start_device_code = start_point_code; |
|
|
|
} |
|
|
|
//获取甲方wcs传过来的参数
|
|
|
|
String houseCode = whereJson.optString("houseCode"); |
|
|
|
String systemCode = whereJson.optString("systemCode"); |
|
|
|
JSONObject parameters = whereJson.optJSONObject("parameters"); |
|
|
|
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"); |
|
|
|
|
|
|
|
if (next_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = next_point_code.split("-"); |
|
|
|
next_device_code = str[0]; |
|
|
|
} else { |
|
|
|
next_device_code = next_point_code; |
|
|
|
} |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
//查询wcs传过来的起点终点路由
|
|
|
|
List<RouteLineDto> list = routeLineService.getShortPathLines(start_device_code, next_device_code, "normal"); |
|
|
|
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("已存在该容器号的任务!"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (start_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = start_point_code.split("-"); |
|
|
|
start_device_code = str[0]; |
|
|
|
} else { |
|
|
|
start_device_code = start_point_code; |
|
|
|
} |
|
|
|
|
|
|
|
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.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 (next_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = next_point_code.split("-"); |
|
|
|
next_device_code = str[0]; |
|
|
|
} else { |
|
|
|
next_device_code = next_point_code; |
|
|
|
} |
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(errArr)) { |
|
|
|
resultJson.put("responseCode", 0); |
|
|
|
resultJson.put("responseMessage", "操作成功"); |
|
|
|
} else { |
|
|
|
resultJson.put("responseCode", 400); |
|
|
|
resultJson.put("responseMessage", "操作失败"); |
|
|
|
//查询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; |
|
|
|
} |
|
|
|
resultJson.put("parameters", errArr); |
|
|
|
log.info("taskCreate--------------:输出参数:" + resultJson.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
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.toBean(jo, TaskDto.class); |
|
|
|
try { |
|
|
|
taskService.create(task_dto); |
|
|
|
} catch (Exception e) { |
|
|
|
resultJson.put("responseCode", 400); |
|
|
|
resultJson.put("parameters", e.getMessage()); |
|
|
|
resultJson.put("responseMessage", "操作失败"); |
|
|
|
log.info("taskCreate--------------:输出参数:" + resultJson.toString()); |
|
|
|
e.printStackTrace(); |
|
|
|
map.put("responseCode", 1); |
|
|
|
map.put("responseMessage", e.getMessage()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
return resultJson; |
|
|
|
map.put("responseCode", 0); |
|
|
|
map.put("responseMessage", "创建任务成功!"); |
|
|
|
map.put("parameters", new HashMap<>()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> taskFeedback(Map whereJson){ |
|
|
|
public Map<String, Object> taskFeedback(Map whereJson) { |
|
|
|
log.info("taskFeedback-----请求参数{}", whereJson.toString()); |
|
|
|
String taskCode = (String) whereJson.get("task_code"); |
|
|
|
String vehicle_code = (String) whereJson.get("carId"); |
|
|
|
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); |
|
|
@ -189,47 +183,22 @@ public class AcsToWmsZDServiceImpl implements AcsToWmsZDService { |
|
|
|
.header("Authorization", token).body(String.valueOf(whereJson)) |
|
|
|
.execute(); |
|
|
|
} catch (Exception e) { |
|
|
|
String msg = e.getMessage(); |
|
|
|
//网络不通
|
|
|
|
System.out.println(msg); |
|
|
|
logServer.log(taskCode, "taskFeedback", "error", whereJson.toString(), msg, String.valueOf(result.getStatus()), url, vehicle_code); |
|
|
|
log.info("taskFeedback-----异常输出参数{}", msg); |
|
|
|
} |
|
|
|
String type = ""; |
|
|
|
if(!ObjectUtil.isEmpty(result)){ |
|
|
|
if (result.getStatus() == 0) { |
|
|
|
type = "info"; |
|
|
|
} else { |
|
|
|
type = "error"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
type = "error"; |
|
|
|
logServer.log(taskCode, "taskFeedback", "error", whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, carId); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("responseCode", 1); |
|
|
|
map.put("responseMessage", e.getMessage()); |
|
|
|
map.put("parameters", new HashMap<>()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
logServer.log(taskCode, "taskFeedback", type, whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, vehicle_code); |
|
|
|
logServer.log(taskCode, "taskFeedback", "success", whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, carId); |
|
|
|
JSONObject jo = JSONObject.fromObject(result.body()); |
|
|
|
log.info("taskFeedback-----输出参数{}", jo.toString()); |
|
|
|
return jo; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> taskDeprecate(Map whereJson) throws Exception { |
|
|
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|
|
|
public Map<String, Object> taskDeprecate(Map whereJson) { |
|
|
|
log.info("taskDeprecate--------------:输入参数" + whereJson.toString()); |
|
|
|
String taskCode = MapUtil.getStr(whereJson,"task_code"); |
|
|
|
String houseCode =MapUtil.getStr(whereJson,"taskhouseCode_code"); |
|
|
|
Object parameters = whereJson.get("parameters"); |
|
|
|
String systemCode = MapUtil.getStr(whereJson,"systemCode"); |
|
|
|
String reason = MapUtil.getStr(whereJson,"reason"); |
|
|
|
if(ObjectUtil.isEmpty(taskCode)){ |
|
|
|
throw new BadRequestException("任务编号不能为空"); |
|
|
|
} |
|
|
|
JSONObject map = new JSONObject(); |
|
|
|
map.put("houseCode",houseCode); |
|
|
|
map.put("systemCode",systemCode); |
|
|
|
map.put("parameters",parameters); |
|
|
|
map.put("taskCode",taskCode); |
|
|
|
map.put("reason",reason); |
|
|
|
String taskCode = MapUtil.getStr(whereJson, "task_code"); |
|
|
|
HttpResponse result = null; |
|
|
|
AddressDto addressDto = addressService.findByCode("deprecateTask"); |
|
|
|
String wcsurl = acsConfigService.findConfigFromCache().get(AcsConfig.WCSURL); |
|
|
@ -240,50 +209,57 @@ public class AcsToWmsZDServiceImpl implements AcsToWmsZDService { |
|
|
|
.header("Authorization", token).body(String.valueOf(whereJson)) |
|
|
|
.execute(); |
|
|
|
} catch (Exception e) { |
|
|
|
String msg = e.getMessage(); |
|
|
|
//网络不通
|
|
|
|
System.out.println(msg); |
|
|
|
logServer.log(taskCode, "taskFeedback", "error", whereJson.toString(), msg, String.valueOf(result.getStatus()), url, ""); |
|
|
|
log.info("taskFeedback-----异常输出参数{}", msg); |
|
|
|
} |
|
|
|
String type = ""; |
|
|
|
if(!ObjectUtil.isEmpty(result)){ |
|
|
|
if (result.getStatus() == 0) { |
|
|
|
type = "info"; |
|
|
|
} else { |
|
|
|
type = "error"; |
|
|
|
} |
|
|
|
} else { |
|
|
|
type = "error"; |
|
|
|
e.printStackTrace(); |
|
|
|
logServer.log(taskCode, "taskFeedback", "error", whereJson.toString(), e.getMessage(), String.valueOf(result.getStatus()), url, ""); |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("responseCode", 1); |
|
|
|
map.put("responseMessage", e.getMessage()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
logServer.log(taskCode, "taskDeprecate", type, whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, ""); |
|
|
|
logServer.log(taskCode, "taskDeprecate", "success", whereJson.toString(), result.body(), String.valueOf(result.getStatus()), url, ""); |
|
|
|
JSONObject jo = JSONObject.fromObject(result.body()); |
|
|
|
log.info("taskDeprecate-----输出参数{}", jo.toString()); |
|
|
|
return jo; |
|
|
|
} |
|
|
|
|
|
|
|
@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); |
|
|
|
public Map<String, Object> checkDeviceStatus(Map whereJson) throws Exception { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
String systemCode = MapUtil.getStr(whereJson, "systemCode"); |
|
|
|
String houseCode = MapUtil.getStr(whereJson, "houseCode"); |
|
|
|
String parameters = MapUtil.getStr(whereJson, "parameters"); |
|
|
|
String deviceCode = MapUtil.getStr(whereJson, "deviceCode"); |
|
|
|
if (StrUtil.isEmpty(deviceCode)) { |
|
|
|
map.put("responseCode", 1); |
|
|
|
map.put("responseMessage", "请求设备号不能为空!"); |
|
|
|
map.put("parameters", new HashMap<>()); |
|
|
|
return map; |
|
|
|
} |
|
|
|
Device device = deviceAppService.findDeviceByCode(deviceCode); |
|
|
|
StandardConveyorLineDeviceDriver standardConveyorLineDeviceDriver; |
|
|
|
int status = 0; |
|
|
|
Boolean hasGoods = false; |
|
|
|
String statusDescription = "正常"; |
|
|
|
if (device.getDeviceDriver() instanceof StandardConveyorLineDeviceDriver) { |
|
|
|
standardConveyorLineDeviceDriver = (StandardConveyorLineDeviceDriver) device.getDeviceDriver(); |
|
|
|
status = standardConveyorLineDeviceDriver.getError(); |
|
|
|
int move = standardConveyorLineDeviceDriver.getMove(); |
|
|
|
if (status != 0) { |
|
|
|
statusDescription = "异常"; |
|
|
|
} |
|
|
|
if (move == 1) { |
|
|
|
hasGoods = true; |
|
|
|
} |
|
|
|
} else if (1 == 1) { |
|
|
|
|
|
|
|
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; |
|
|
|
map.put("responseCode", 0); |
|
|
|
map.put("responseMessage", "响应成功!"); |
|
|
|
map.put("parameters", new HashMap<>()); |
|
|
|
map.put("status", status); |
|
|
|
map.put("statusDescription", statusDescription); |
|
|
|
map.put("hasGoods", hasGoods); |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|