|
|
@ -3,6 +3,8 @@ package org.nl.acs.ext.wms.service.impl; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
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.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
@ -10,20 +12,32 @@ import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.acs.AcsConfig; |
|
|
|
import org.nl.acs.common.IDriverService; |
|
|
|
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.device_driver.basedriver.hongxiang_conveyor.HongXiangStationDeviceDriver; |
|
|
|
import org.nl.acs.device_driver.basedriver.hongxiang_device.HongXiangConveyorDeviceDriver; |
|
|
|
import org.nl.acs.device_driver.basedriver.plug_pull_device_site.PlugPullDeviceSiteDeviceDriver; |
|
|
|
import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; |
|
|
|
import org.nl.acs.ext.wms.AcsUtil; |
|
|
|
import org.nl.acs.ext.wms.RespUtil; |
|
|
|
import org.nl.acs.ext.wms.data.CancelTaskRequest; |
|
|
|
import org.nl.acs.ext.wms.data.CancelTaskResponse; |
|
|
|
import org.nl.acs.ext.wms.data.CreateTaskRequest; |
|
|
|
import org.nl.acs.ext.wms.data.CreateTaskResponse; |
|
|
|
import org.nl.acs.ext.wms.data.JDCancelTaskRequest; |
|
|
|
import org.nl.acs.ext.wms.data.JDCancelTaskResponse; |
|
|
|
import org.nl.acs.ext.wms.data.JDChangeTaskRequest; |
|
|
|
import org.nl.acs.ext.wms.data.JDChangeTaskResponse; |
|
|
|
import org.nl.acs.ext.wms.data.JDCreateTaskRequest; |
|
|
|
import org.nl.acs.ext.wms.data.JDCreateTaskResponse; |
|
|
|
import org.nl.acs.ext.wms.data.JDFaultRequest; |
|
|
|
import org.nl.acs.ext.wms.data.JDFaultResponse; |
|
|
|
import org.nl.acs.ext.wms.data.JDFeedbackRequest; |
|
|
|
import org.nl.acs.ext.wms.data.JsonUtl; |
|
|
|
import org.nl.acs.ext.wms.data.PutActionRequest; |
|
|
|
import org.nl.acs.ext.wms.data.PutActionResponse; |
|
|
|
import org.nl.acs.ext.wms.liKuData.OutStoreResponse; |
|
|
|
import org.nl.acs.ext.wms.service.AcsToLiKuService; |
|
|
|
import org.nl.acs.ext.wms.service.JDToAcsService; |
|
|
|
import org.nl.acs.ext.wms.service.WmsToAcsService; |
|
|
@ -41,10 +55,12 @@ import org.nl.modules.wql.core.bean.WQLObject; |
|
|
|
import org.nl.modules.wql.exception.WDKException; |
|
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
|
import org.slf4j.MDC; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
@ -55,526 +71,242 @@ import java.util.Map; |
|
|
|
@Slf4j |
|
|
|
public class JDToAcsServiceImpl implements JDToAcsService { |
|
|
|
|
|
|
|
private final ApplicationContext applicationContext; |
|
|
|
@Resource |
|
|
|
private TaskService taskService; |
|
|
|
|
|
|
|
private final InstructionService InstructionService; |
|
|
|
private final TaskService taskService; |
|
|
|
private final DeviceService deviceService; |
|
|
|
private final DeviceAppService deviceAppService; |
|
|
|
private final RouteLineService routeLineService; |
|
|
|
private final AcsToLiKuService acsToLiKuService; |
|
|
|
@Resource |
|
|
|
private InstructionService instructionService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ParamService paramService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private AddressService addressService; |
|
|
|
|
|
|
|
|
|
|
|
private String log_file_type = "log_file_type"; |
|
|
|
private String log_type = "LMS请求ACS"; |
|
|
|
|
|
|
|
@Override |
|
|
|
public CancelTaskResponse cancelFromWms(List<CancelTaskRequest> reqs) throws Exception { |
|
|
|
ParamService paramService = SpringContextHolder.getBean(ParamService.class); |
|
|
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|
|
|
CancelTaskResponse response = new CancelTaskResponse(); |
|
|
|
JSONArray errArr = new JSONArray(); |
|
|
|
for (int i = 0; i < reqs.size(); i++) { |
|
|
|
CancelTaskRequest request = reqs.get(i); |
|
|
|
String task_code = request.getTask_code(); |
|
|
|
String vehicle_code = request.getVehicle_code(); |
|
|
|
Map<String, String> params = request.getParams(); |
|
|
|
public JDCreateTaskResponse crateTask(JDCreateTaskRequest reqs) { |
|
|
|
try { |
|
|
|
MDC.put(log_file_type, log_type); |
|
|
|
log.info("crateTask-----输入参数{}", reqs); |
|
|
|
JDCreateTaskResponse response = new JDCreateTaskResponse(); |
|
|
|
JSONArray errArr = new JSONArray(); |
|
|
|
String task_code = reqs.getTaskNo(); |
|
|
|
String start_device_code = reqs.getCarryTask().getFromPoint(); |
|
|
|
String next_device_code = reqs.getCarryTask().getToPoint(); |
|
|
|
String priority = reqs.getPriority(); |
|
|
|
String vehicle_code = reqs.getCarryTask().getContainerNo(); |
|
|
|
// String vehicle_type = req.getVehicle_type();
|
|
|
|
String task_type = "1"; |
|
|
|
// String remark = req.getRemark();
|
|
|
|
// Map<String, String> params = req.getParams();
|
|
|
|
|
|
|
|
String start_point_code = ""; |
|
|
|
String next_point_code = ""; |
|
|
|
if (StrUtil.isEmpty(task_code)) { |
|
|
|
throw new WDKException("任务号不能为空"); |
|
|
|
response.setMessage("任务号不能为空"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
TaskDto taskDto = taskService.findByCodeFromCache(task_code); |
|
|
|
String cancelTaskCheck = paramService.findByCode(AcsConfig.CANCELTASKCHECK).getValue(); |
|
|
|
if (StrUtil.equals(cancelTaskCheck, "1")) { |
|
|
|
taskService.cancelNoSendWms(taskDto.getTask_id()); |
|
|
|
} else if (StrUtil.equals(cancelTaskCheck, "0")) { |
|
|
|
Instruction inst = instructionService.findByTaskcode(task_code); |
|
|
|
if (inst == null) { |
|
|
|
taskService.cancelNoSendWms(taskDto.getTask_id()); |
|
|
|
} else { |
|
|
|
throw new RuntimeException("指令正在执行中,操作失败!"); |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(start_device_code)) { |
|
|
|
response.setMessage("起点不能为空"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(next_device_code)) { |
|
|
|
response.setMessage("终点不能为空"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
JSONObject start_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_device_code + "'").uniqueResult(0); |
|
|
|
if (!ObjectUtil.isEmpty(start_device_json)) { |
|
|
|
start_point_code = (String) start_device_json.get("parent_storage_code") == null ? start_device_code : (String) start_device_json.get("storage_code"); |
|
|
|
} |
|
|
|
JSONObject next_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_device_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"); |
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(start_point_code) && start_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = start_point_code.split("-"); |
|
|
|
start_device_code = str[0]; |
|
|
|
} else { |
|
|
|
start_device_code = start_point_code; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(next_point_code) && 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)) { |
|
|
|
response.setStatus(200); |
|
|
|
} else { |
|
|
|
response.setStatus(400); |
|
|
|
} |
|
|
|
response.setMessage("success"); |
|
|
|
response.setErrArr(errArr); |
|
|
|
log.info("cancelFromWms--------------:输出参数:" + response); |
|
|
|
String route_plan_code = ""; |
|
|
|
|
|
|
|
return response; |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(route_plan_code)) { |
|
|
|
route_plan_code = "normal"; |
|
|
|
} |
|
|
|
TaskDto taskDto = taskService.findByCodeFromCache(task_code); |
|
|
|
if (taskDto != null) { |
|
|
|
response.setMessage("不能存在相同的任务号"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (!StrUtil.isEmpty(vehicle_code)) { |
|
|
|
TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); |
|
|
|
if (vehicle_dto != null) { |
|
|
|
response.setMessage("不能存在相同的托盘号"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> updateDeviceGoodsFromWms(String param) { |
|
|
|
JSONArray datas = JSONArray.parseArray(param); |
|
|
|
log.info("updateDeviceGoodsFromWms--------------:输入参数" + datas.toString()); |
|
|
|
for (int i = 0; i < datas.size(); i++) { |
|
|
|
JSONObject data = datas.getJSONObject(i); |
|
|
|
String device_code = data.getString("point_code"); |
|
|
|
String has_goods = data.getString("has_goods"); |
|
|
|
if (StrUtil.isEmpty(start_point_code)) { |
|
|
|
response.setMessage(reqs.getCarryTask().getFromPoint() + " 该设备号未找到对应点位"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(next_point_code)) { |
|
|
|
response.setMessage(reqs.getCarryTask().getToPoint() + " 该设备号未找到对应点位"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("device_code", device_code); |
|
|
|
jo.put("hasGoodStatus", has_goods); |
|
|
|
deviceService.changeDeviceStatus(jo); |
|
|
|
|
|
|
|
} |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.OK); |
|
|
|
resultJson.put("message", "操作成功"); |
|
|
|
resultJson.put("data", new JSONObject()); |
|
|
|
log.info("updateDeviceGoodsFromWms--------------:输出参数" + resultJson.toString()); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> areaControl(JSONObject form) { |
|
|
|
String device_code = form.getString("device_code"); |
|
|
|
String type = form.getString("type"); |
|
|
|
|
|
|
|
Device device = deviceAppService.findDeviceByCode(device_code); |
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.OK); |
|
|
|
resultJson.put("message", "操作成功"); |
|
|
|
resultJson.put("data", new JSONObject()); |
|
|
|
log.info("updateDeviceGoodsFromWms--------------:输出参数" + resultJson.toString()); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PutActionResponse putAction(String jsonObject) throws Exception { |
|
|
|
try { |
|
|
|
MDC.put(log_file_type, log_type); |
|
|
|
log.info("putAction--------------:输出参数" + jsonObject); |
|
|
|
JSONArray datas = JSONArray.parseArray(jsonObject); |
|
|
|
PutActionResponse response = new PutActionResponse(); |
|
|
|
JSONArray errArr = new JSONArray(); |
|
|
|
for (int i = 0; i < datas.size(); i++) { |
|
|
|
String data = datas.get(i).toString(); |
|
|
|
PutActionRequest request = JsonUtl.format(data, PutActionRequest.class); |
|
|
|
String device_code = request.getDevice_code(); |
|
|
|
String code = request.getCode(); |
|
|
|
String value = request.getValue(); |
|
|
|
Device device = deviceAppService.findDeviceByCode(device_code); |
|
|
|
if (ObjectUtil.isEmpty(device)) { |
|
|
|
throw new Exception("未找到对应设备:" + device_code); |
|
|
|
} |
|
|
|
HongXiangStationDeviceDriver hongXiangStationDeviceDriver; |
|
|
|
PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; |
|
|
|
if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { |
|
|
|
hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); |
|
|
|
hongXiangStationDeviceDriver.writing(code, value); |
|
|
|
} |
|
|
|
|
|
|
|
jo.put("task_code", task_code); |
|
|
|
jo.put("task_id", IdUtil.simpleUUID()); |
|
|
|
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", vehicle_code); |
|
|
|
// jo.put("vehicle_type", vehicle_type);
|
|
|
|
jo.put("agv_system_type", "1"); |
|
|
|
// jo.put("remark", remark);
|
|
|
|
// jo.put("params", params);
|
|
|
|
jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type)); |
|
|
|
|
|
|
|
TaskDto task_dto = jo.toJavaObject(TaskDto.class); |
|
|
|
try { |
|
|
|
taskService.create(task_dto); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("操作失败{}", e, e.getMessage()); |
|
|
|
response.setMessage("操作失败"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (ObjectUtil.isEmpty(errArr)) { |
|
|
|
response.setCode(200); |
|
|
|
response.setResult("true"); |
|
|
|
response.setMessage("操作成功"); |
|
|
|
} else { |
|
|
|
response.setMessage("操作失败"); |
|
|
|
} |
|
|
|
response.setStatus(200); |
|
|
|
response.setMessage("success"); |
|
|
|
log.info("putAction--------------:输出参数:" + response); |
|
|
|
log.info("createFromWms--------------:输出参数:" + JSON.toJSONString(response)); |
|
|
|
return response; |
|
|
|
} finally { |
|
|
|
MDC.remove(log_file_type); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> queryDevice(String jsonObject) throws Exception { |
|
|
|
public JDCancelTaskResponse cancelFromWms(JDCancelTaskRequest reqs) { |
|
|
|
JDCancelTaskResponse response = new JDCancelTaskResponse(); |
|
|
|
log.info("cancelFromWms--------------:输入参数:" + reqs); |
|
|
|
String task_code = reqs.getTaskNo(); |
|
|
|
if (StrUtil.isEmpty(task_code)) { |
|
|
|
throw new WDKException("任务号不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
MDC.put(log_file_type, log_type); |
|
|
|
// log.info("queryDevice--------------:输入参数" + jsonObject.toString());
|
|
|
|
JSONArray backja = new JSONArray(); |
|
|
|
JSONArray datas = JSONArray.parseArray(jsonObject); |
|
|
|
|
|
|
|
//AGV烘箱对接位
|
|
|
|
HongXiangStationDeviceDriver hongXiangStationDeviceDriver; |
|
|
|
//烘箱工位
|
|
|
|
HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; |
|
|
|
//货梯对接线-带扫码器
|
|
|
|
StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; |
|
|
|
|
|
|
|
if (datas.size() == 0) { |
|
|
|
throw new BadRequestException("缺少输入参数!"); |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < datas.size(); i++) { |
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
JSONObject data = datas.getJSONObject(i); |
|
|
|
String parent_device_code = data.getString("device_code"); |
|
|
|
String device_code = ""; |
|
|
|
JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + parent_device_code + "'").uniqueResult(0); |
|
|
|
if (!ObjectUtil.isEmpty(device_json)) { |
|
|
|
device_code = (String) device_json.get("parent_storage_code") == null ? parent_device_code : (String) device_json.get("storage_code"); |
|
|
|
} |
|
|
|
Device device = deviceAppService.findDeviceByCode(device_code); |
|
|
|
if (ObjectUtil.isEmpty(device)) { |
|
|
|
throw new Exception("未找到对应设备:" + parent_device_code); |
|
|
|
} |
|
|
|
|
|
|
|
if (device.getDeviceDriver() instanceof HongXiangStationDeviceDriver) { |
|
|
|
hongXiangStationDeviceDriver = (HongXiangStationDeviceDriver) device.getDeviceDriver(); |
|
|
|
jo.put("device_code", parent_device_code); |
|
|
|
jo.put("mode", hongXiangStationDeviceDriver.getMode()); |
|
|
|
jo.put("move", hongXiangStationDeviceDriver.getMove()); |
|
|
|
|
|
|
|
} else if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { |
|
|
|
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver(); |
|
|
|
jo.put("device_code", parent_device_code); |
|
|
|
jo.put("mode", hongXiangConveyorDeviceDriver.getMode()); |
|
|
|
jo.put("move", hongXiangConveyorDeviceDriver.getMove()); |
|
|
|
jo.put("countdown_house", hongXiangConveyorDeviceDriver.getCountdown_house()); |
|
|
|
jo.put("countdown_min", hongXiangConveyorDeviceDriver.getCountdown_min()); |
|
|
|
jo.put("countdown_sec", hongXiangConveyorDeviceDriver.getCountdown_sec()); |
|
|
|
//温度需要除以10
|
|
|
|
jo.put("temperature", hongXiangConveyorDeviceDriver.getTemperature() / 10); |
|
|
|
jo.put("door", hongXiangConveyorDeviceDriver.getDoor()); |
|
|
|
jo.put("finish", hongXiangConveyorDeviceDriver.getFinish()); |
|
|
|
jo.put("task", hongXiangConveyorDeviceDriver.getTask()); |
|
|
|
jo.put("error", hongXiangConveyorDeviceDriver.getError()); |
|
|
|
} else if (device.getDeviceDriver() instanceof StandardCoveyorControlWithScannerDeviceDriver) { |
|
|
|
standardCoveyorControlWithScannerDeviceDriver = (StandardCoveyorControlWithScannerDeviceDriver) device.getDeviceDriver(); |
|
|
|
jo.put("device_code", parent_device_code); |
|
|
|
jo.put("move", standardCoveyorControlWithScannerDeviceDriver.getMove()); |
|
|
|
jo.put("action", standardCoveyorControlWithScannerDeviceDriver.getAction()); |
|
|
|
jo.put("error", standardCoveyorControlWithScannerDeviceDriver.getError()); |
|
|
|
} else { |
|
|
|
jo.put("device_code", parent_device_code); |
|
|
|
TaskDto taskDto = taskService.findByCodeFromCache(task_code); |
|
|
|
if (taskDto == null) { |
|
|
|
log.info("任务已完成或取消"); |
|
|
|
} else { |
|
|
|
Instruction inst = instructionService.findByTaskcode(task_code); |
|
|
|
if (inst != null) { |
|
|
|
instructionService.cancel(inst.getInstruction_id()); |
|
|
|
} |
|
|
|
backja.add(jo); |
|
|
|
taskService.cancelNoSendWms(taskDto.getTask_id()); |
|
|
|
} |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.OK.value()); |
|
|
|
resultJson.put("message", "操作成功"); |
|
|
|
resultJson.put("data", backja); |
|
|
|
// log.info("queryDevice--------------:输出参数" + resultJson.toString());
|
|
|
|
return resultJson; |
|
|
|
|
|
|
|
} finally { |
|
|
|
MDC.remove(log_file_type); |
|
|
|
}catch (Exception e){ |
|
|
|
log.error("取消任务失败{}",e,e.getMessage()); |
|
|
|
response.setResult(false); |
|
|
|
response.setCode(400); |
|
|
|
response.setMessage("`取消任务失败"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.info("cancelFromWms--------------:输出参数:" + response); |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//todo 暂不做
|
|
|
|
@Override |
|
|
|
public Map<String, Object> queryDeviceDBValue(String whereJson) { |
|
|
|
JSONArray datas = JSONArray.parseArray(whereJson); |
|
|
|
log.info("orderStatusUpdate--------------:输入参数" + datas.toString()); |
|
|
|
JSONObject map = new JSONObject(); |
|
|
|
if (datas.size() > 0) { |
|
|
|
for (int i = 0; i < datas.size(); i++) { |
|
|
|
JSONObject jsonObject = datas.getJSONObject(i); |
|
|
|
String device_code = jsonObject.getString("device_code"); |
|
|
|
String dbName = jsonObject.getString("DB"); |
|
|
|
Device device = deviceAppService.findDeviceByCode(device_code); |
|
|
|
List<DeviceExtraManageDto> extra = device.getExtra(); |
|
|
|
for (int j = 0; j < extra.size(); j++) { |
|
|
|
DeviceExtraManageDto deviceExtraManageDto = extra.get(j); |
|
|
|
String deviceCode = deviceExtraManageDto.getDevice_code(); |
|
|
|
String extra_name = deviceExtraManageDto.getExtra_name(); |
|
|
|
if (deviceCode.equals(device_code) && extra_name.equals(dbName)) { |
|
|
|
String extra_code = deviceExtraManageDto.getExtra_code(); |
|
|
|
String[] split = extra_code.split("\\."); |
|
|
|
extra_code = split[split.length - 1]; |
|
|
|
extra_code = extra_code.substring(0, 1).toUpperCase() + extra_code.substring(1); |
|
|
|
IDriverService driverService = applicationContext.getBean(device.getDeviceDriverDefination().getDriverCode(), IDriverService.class); |
|
|
|
Integer dbValue = driverService.getDbValue(device, extra_code); |
|
|
|
map.put(dbName, dbValue); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
public JDChangeTaskResponse changeFromWms(JDChangeTaskRequest reqs) { |
|
|
|
JDChangeTaskResponse response = new JDChangeTaskResponse(); |
|
|
|
log.info("changeFromWms--------------:输入参数:" + reqs); |
|
|
|
String task_code = reqs.getTaskNo(); |
|
|
|
if (StrUtil.isEmpty(task_code)) { |
|
|
|
throw new WDKException("任务号不能为空"); |
|
|
|
} |
|
|
|
try { |
|
|
|
// TaskDto taskDto = taskService.findByCodeFromCache(task_code);
|
|
|
|
// taskDto.setPriority(String.valueOf(reqs.getPriority()));
|
|
|
|
// taskService.update(taskDto);
|
|
|
|
// //todo 更改优先级到NDC
|
|
|
|
}catch (Exception e){ |
|
|
|
log.error("取消任务失败{}",e,e.getMessage()); |
|
|
|
response.setResult(false); |
|
|
|
response.setCode(400); |
|
|
|
response.setMessage("`取消任务失败"); |
|
|
|
} |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.OK); |
|
|
|
resultJson.put("message", "操作成功"); |
|
|
|
resultJson.put("data", map); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> querydevice(String whereJson) { |
|
|
|
return null; |
|
|
|
log.info("changeFromWms--------------:输出参数:" + response); |
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> putPlusPullAction(String param) { |
|
|
|
try { |
|
|
|
MDC.put(log_file_type, log_type); |
|
|
|
log.info("putPlusPullAction-----输入参数{}", param); |
|
|
|
JSONObject jo = JSON.parseObject(param); |
|
|
|
String device_code = jo.getString("device_code"); |
|
|
|
String size = jo.getString("size"); |
|
|
|
String type = jo.getString("type"); |
|
|
|
Device device = deviceAppService.findDeviceByCode(device_code); |
|
|
|
if (ObjectUtil.isEmpty(device)) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "未找到对应的设备:" + device_code); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; |
|
|
|
if (device.getDeviceDriver() instanceof PlugPullDeviceSiteDeviceDriver) { |
|
|
|
plugPullDeviceSiteDeviceDriver = (PlugPullDeviceSiteDeviceDriver) device.getDeviceDriver(); |
|
|
|
// 0 穿轴 1拔轴
|
|
|
|
if (StrUtil.equals(type, "1")) { |
|
|
|
|
|
|
|
if (plugPullDeviceSiteDeviceDriver.getMode() == 1) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求拔轴,当前设备工作模式未自动"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getAction() == 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求拔轴,当前设备未全自动"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getStatus() != 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求拔轴,当前设备未待机"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getControl() != 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求拔轴,当前设备未远程控制"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getMove() != 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求拔轴,当前设备有轴"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() == 1 |
|
|
|
&& plugPullDeviceSiteDeviceDriver.getStatus() == 0 && plugPullDeviceSiteDeviceDriver.getMove() == 0 |
|
|
|
&& plugPullDeviceSiteDeviceDriver.getControl() == 0) { |
|
|
|
|
|
|
|
List list = new ArrayList(); |
|
|
|
Map map = new HashMap(); |
|
|
|
map.put("code", "to_size"); |
|
|
|
map.put("value", size); |
|
|
|
list.add(map); |
|
|
|
Map map2 = new HashMap(); |
|
|
|
map2.put("code", "to_type"); |
|
|
|
map2.put("value", type); |
|
|
|
list.add(map2); |
|
|
|
Map map3 = new HashMap(); |
|
|
|
map3.put("code", "to_command"); |
|
|
|
map3.put("value", "1"); |
|
|
|
list.add(map3); |
|
|
|
plugPullDeviceSiteDeviceDriver.writing(list); |
|
|
|
|
|
|
|
} else { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "当前设备状态不满足下发条件"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
|
|
|
|
} else if (StrUtil.equals(type, "0")) { |
|
|
|
public void feedbackDeviceFault(JDFaultRequest reqs) { |
|
|
|
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); |
|
|
|
|
|
|
|
if (plugPullDeviceSiteDeviceDriver.getMode() == 1) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求插轴,当前设备工作模式未自动"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getAction() == 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求插轴,当前设备未全自动"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getStatus() != 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求插轴,当前设备未待机"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getControl() != 0) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求插轴,当前设备未远程控制"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
if (plugPullDeviceSiteDeviceDriver.getMove() != 1) { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "请求插轴,当前设备没有轴"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
|
|
|
|
if (plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() == 1 |
|
|
|
&& plugPullDeviceSiteDeviceDriver.getStatus() == 0 && plugPullDeviceSiteDeviceDriver.getMove() == 1 |
|
|
|
&& plugPullDeviceSiteDeviceDriver.getControl() == 0) { |
|
|
|
AddressDto addressDto = addressService.findByCode("feedbackDeviceFault"); |
|
|
|
String methods_url = addressDto.getMethods_url(); |
|
|
|
String url = wmsUrl + methods_url; |
|
|
|
HttpResponse result = null; |
|
|
|
log.info("feedbackDeviceFault----请求参数{}", reqs); |
|
|
|
|
|
|
|
List list = new ArrayList(); |
|
|
|
Map map = new HashMap(); |
|
|
|
map.put("code", "to_size"); |
|
|
|
map.put("value", size); |
|
|
|
list.add(map); |
|
|
|
Map map2 = new HashMap(); |
|
|
|
map2.put("code", "to_type"); |
|
|
|
map2.put("value", type); |
|
|
|
list.add(map2); |
|
|
|
Map map3 = new HashMap(); |
|
|
|
map3.put("code", "to_command"); |
|
|
|
map3.put("value", "1"); |
|
|
|
list.add(map3); |
|
|
|
plugPullDeviceSiteDeviceDriver.writing(list); |
|
|
|
|
|
|
|
} else { |
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.BAD_REQUEST.value()); |
|
|
|
resultJson.put("message", "当前设备状态不满足下发条件"); |
|
|
|
return resultJson; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject(); |
|
|
|
resultJson.put("status", HttpStatus.OK.value()); |
|
|
|
resultJson.put("message", "操作成功"); |
|
|
|
log.info("putPlusPullAction--------------:输出参数" + resultJson.toString()); |
|
|
|
return resultJson; |
|
|
|
|
|
|
|
} finally { |
|
|
|
MDC.remove(log_file_type); |
|
|
|
try { |
|
|
|
result = HttpRequest.post(url) |
|
|
|
.body(JSONObject.toJSONString(reqs)) |
|
|
|
.execute(); |
|
|
|
System.out.println(result); |
|
|
|
log.info("feedbackDeviceFault----返回参数{}", result); |
|
|
|
} catch (Exception e) { |
|
|
|
String msg = e.getMessage(); |
|
|
|
//网络不通
|
|
|
|
//System.out.println(msg);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public JDCreateTaskResponse crateTask(JDCreateTaskRequest reqs) { |
|
|
|
try { |
|
|
|
MDC.put(log_file_type, log_type); |
|
|
|
log.info("crateTask-----输入参数{}", reqs); |
|
|
|
JDCreateTaskResponse response = new JDCreateTaskResponse(); |
|
|
|
JSONArray errArr = new JSONArray(); |
|
|
|
String task_code = reqs.getTaskNo(); |
|
|
|
String start_device_code = reqs.getCarryTask().getFromPoint(); |
|
|
|
String next_device_code = reqs.getCarryTask().getToPoint(); |
|
|
|
String priority = reqs.getPriority(); |
|
|
|
String vehicle_code = reqs.getCarryTask().getContainerNo(); |
|
|
|
// String vehicle_type = req.getVehicle_type();
|
|
|
|
String task_type = "1"; |
|
|
|
// String remark = req.getRemark();
|
|
|
|
// Map<String, String> params = req.getParams();
|
|
|
|
public HttpResponse feedbackAgv(JDFeedbackRequest jdFeedbackRequest) { |
|
|
|
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); |
|
|
|
|
|
|
|
String start_point_code = ""; |
|
|
|
String next_point_code = ""; |
|
|
|
if (StrUtil.isEmpty(task_code)) { |
|
|
|
response.setMessage("任务号不能为空"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(start_device_code)) { |
|
|
|
response.setMessage("起点不能为空"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(next_device_code)) { |
|
|
|
response.setMessage("终点不能为空"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
JSONObject start_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_device_code + "'").uniqueResult(0); |
|
|
|
if (!ObjectUtil.isEmpty(start_device_json)) { |
|
|
|
start_point_code = (String) start_device_json.get("parent_storage_code") == null ? start_device_code : (String) start_device_json.get("storage_code"); |
|
|
|
} |
|
|
|
JSONObject next_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + next_device_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"); |
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(start_point_code) && start_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = start_point_code.split("-"); |
|
|
|
start_device_code = str[0]; |
|
|
|
} else { |
|
|
|
start_device_code = start_point_code; |
|
|
|
} |
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(next_point_code) && next_point_code.indexOf("-") > 0) { |
|
|
|
String str[] = next_point_code.split("-"); |
|
|
|
next_device_code = str[0]; |
|
|
|
} else { |
|
|
|
next_device_code = next_point_code; |
|
|
|
} |
|
|
|
|
|
|
|
String route_plan_code = ""; |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(route_plan_code)) { |
|
|
|
route_plan_code = "normal"; |
|
|
|
} |
|
|
|
TaskDto taskDto = taskService.findByCodeFromCache(task_code); |
|
|
|
if (taskDto != null) { |
|
|
|
response.setMessage("不能存在相同的任务号"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (!StrUtil.isEmpty(vehicle_code)) { |
|
|
|
TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); |
|
|
|
if (vehicle_dto != null) { |
|
|
|
response.setMessage("不能存在相同的托盘号"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(start_point_code)) { |
|
|
|
response.setMessage(reqs.getCarryTask().getFromPoint() + " 该设备号未找到对应点位"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (StrUtil.isEmpty(next_point_code)) { |
|
|
|
response.setMessage(reqs.getCarryTask().getToPoint() + " 该设备号未找到对应点位"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
AddressDto addressDto = addressService.findByCode("feedbackAgv"); |
|
|
|
String methods_url = addressDto.getMethods_url(); |
|
|
|
String url = wmsUrl + methods_url; |
|
|
|
HttpResponse result = null; |
|
|
|
log.info("feedbackAgv----请求参数{}", jdFeedbackRequest); |
|
|
|
|
|
|
|
JSONObject jo = new JSONObject(); |
|
|
|
jo.put("task_code", task_code); |
|
|
|
jo.put("task_id", IdUtil.simpleUUID()); |
|
|
|
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", vehicle_code); |
|
|
|
// jo.put("vehicle_type", vehicle_type);
|
|
|
|
jo.put("agv_system_type", "1"); |
|
|
|
// jo.put("remark", remark);
|
|
|
|
// jo.put("params", params);
|
|
|
|
jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type)); |
|
|
|
|
|
|
|
TaskDto task_dto = jo.toJavaObject(TaskDto.class); |
|
|
|
try { |
|
|
|
taskService.create(task_dto); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("操作失败{}",e,e.getMessage()); |
|
|
|
response.setMessage("操作失败"); |
|
|
|
return response; |
|
|
|
} |
|
|
|
if (ObjectUtil.isEmpty(errArr)) { |
|
|
|
response.setCode(200); |
|
|
|
response.setResult("true"); |
|
|
|
response.setMessage("操作成功"); |
|
|
|
} else { |
|
|
|
response.setMessage("操作失败"); |
|
|
|
} |
|
|
|
log.info("createFromWms--------------:输出参数:" + JSON.toJSONString(response)); |
|
|
|
return response; |
|
|
|
} finally { |
|
|
|
MDC.remove(log_file_type); |
|
|
|
try { |
|
|
|
result = HttpRequest.post(url) |
|
|
|
.body(JSONObject.toJSONString(jdFeedbackRequest)) |
|
|
|
.execute(); |
|
|
|
System.out.println(result); |
|
|
|
log.info("feedbackAgv----返回参数{}", result); |
|
|
|
} catch (Exception e) { |
|
|
|
String msg = e.getMessage(); |
|
|
|
//网络不通
|
|
|
|
//System.out.println(msg);
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|