Browse Source

任务取消/故障反馈/位置反馈接口实现

master
psh 1 year ago
parent
commit
a33fe65de1
  1. 2
      acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
  2. 42
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
  3. 47
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/DeviceMotion.java
  4. 51
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDCancelTaskRequest.java
  5. 30
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDCancelTaskResponse.java
  6. 57
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDChangeTaskRequest.java
  7. 30
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDChangeTaskResponse.java
  8. 57
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDFaultRequest.java
  9. 30
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDFaultResponse.java
  10. 25
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDFeedbackRequest.java
  11. 94
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/Payload.java
  12. 48
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/TaskList.java
  13. 18
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/JDToAcsController.java
  14. 67
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/JDToAcsService.java
  15. 676
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/JDToAcsServiceImpl.java
  16. 10
      acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceAppServiceImpl.java
  17. 36
      acs/nladmin-system/src/main/java/org/nl/modules/common/utils/enums/DeviceStatusEnum.java
  18. 106
      acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java
  19. 5
      acs/nladmin-system/src/main/resources/config/application-dev.yml

2
acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java

@ -216,7 +216,7 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
} else {
//上报异常信息
//(不需要WCS反馈)
if (phase == 0x67) {
if (phase == 0x67 || phase == 0x74) {
device = deviceAppService.findDeviceByCode(Integer.toString(arr[27]));
} else {
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));

42
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java

@ -18,7 +18,9 @@ import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDevic
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver;
import org.nl.acs.device_driver.driver.AbstractDeviceDriver;
import org.nl.acs.ext.wms.data.JDFaultRequest;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.ext.wms.service.JDToAcsService;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
@ -30,6 +32,7 @@ import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.impl.TaskServiceImpl;
import org.nl.modules.common.utils.enums.DeviceStatusEnum;
import org.nl.modules.system.service.ParamService;
import org.nl.modules.system.service.impl.ParamServiceImpl;
import org.nl.modules.wql.util.SpringContextHolder;
@ -55,6 +58,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
JDToAcsService jdToAcsService=SpringContextHolder.getBean(JDToAcsService.class);
int agvaddr = 0;
int agvaddr_copy = 0;
int weight = 0;
@ -75,6 +79,13 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
int last_status = 0;
int last_error = 0;
int goods =0;
//0-初始;1-取货中;2-取货完成;3-放货中;4-放货完成
int inst_status = 0;
Instruction global_inst = null;
@LokiLog(type = LokiLogType.ACS_TO_LMS)
public synchronized void processSocket(int[] arr) throws Exception {
device_code = this.getDeviceCode();
@ -98,6 +109,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
}
if (ikey != 0) {
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
global_inst=inst;
// if (ObjectUtil.isEmpty(inst)) {
// inst = instructionService.findByCode(String.valueOf(ikey));
// }
@ -112,6 +124,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
String device_code = null;
if (phase == 0x67) {
error= ikey;
//故障信息
if (arr[18] * 256 + arr[19] == 0) {
@ -141,6 +154,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
map.put("deviceNo",inst.getCarno());
// req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(map);
inst_status=0;
//到达取货点
//(需要WCS反馈)
} else if (phase == 0x03) {
@ -179,6 +193,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
return;
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
inst_status=1;
//取货完毕
//(需要WCS反馈)
} else if (phase == 0x05) {
@ -242,6 +257,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
log.warn("指令号:{},acs反馈wms取货完成离开失败,连接被拒绝,未反馈agv取货完成离开", inst.getInstruction_code());
}
}
goods=1;
inst_status=2;
//到达放货点
//(需要WCS反馈)
} else if (phase == 0x07) {
@ -277,7 +294,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
inst_status=3;
//放货完毕
//(需要WCS反馈)
} else if (phase == 0x09) {
@ -338,7 +355,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
log.warn("指令号:{},acs请求wms放货完成离开失败,连接被拒绝,未反馈agv放货完成离开", inst.getInstruction_code());
}
}
goods=0;
inst_status=4;
}
//到达位置点
//(需要WCS反馈)
@ -354,6 +372,26 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
} else if (phase == 0x51) {//离开交通灯区域
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
} else if (phase == 0x70) {
//x坐标
x = ikey;
} else if (phase == 0x71) {
//y坐标
y = ikey;
} else if (phase == 0x72) {
//车辆角度
angle = ikey;
} else if (phase == 0x73) {
//agv电量
electric_qty = ikey;
} else if (phase == 0x74) {
status = ikey;
JDFaultRequest jdFaultRequest=new JDFaultRequest();
jdFaultRequest.setUuid(IdUtil.simpleUUID());
jdFaultRequest.setStatus(ikey==2?"0":"2");
jdFaultRequest.setFaultType(DeviceStatusEnum.getEnumValue(ikey).getDesc());
jdFaultRequest.setDesc(DeviceStatusEnum.getEnumValue(ikey).getDesc());
jdToAcsService.feedbackDeviceFault(jdFaultRequest);
}
if (!ObjectUtil.isEmpty(data)) {
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);

47
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/DeviceMotion.java

@ -0,0 +1,47 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class DeviceMotion{
/**
* 车头方向
*/
private String direction;
/**
* 逻辑位置 Z
*/
private String logicalZ;
/**
* 逻辑位置 X
*/
private String logicalX;
/**
* 逻辑位置 Y
*/
private String logicalY;
/**
* 水平速度
*/
private Double speedH;
/**
* 垂直速度
*/
private Double speedV;
/**
* 当前行程点
*/
private String planPath;
}

51
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDCancelTaskRequest.java

@ -0,0 +1,51 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class JDCancelTaskRequest extends BaseRequest {
/**
* 场景编号
*/
private String scenarioNo;
/**
* 防重码
*/
String uuid;
/**
* 当前时间
*/
Long currentTime;
/**
* 任务号
*/
String taskNo;
/**
* 容器号
*/
String containerNo;
/**
* 备注
*/
String remark;
@Override
public String toString() {
return "JDCancelTaskRequest{" +
"scenarioNo='" + scenarioNo + '\'' +
", uuid='" + uuid + '\'' +
", currentTime=" + currentTime +
", taskNo='" + taskNo + '\'' +
", containerNo='" + containerNo + '\'' +
", remark='" + remark + '\'' +
'}';
}
}

30
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDCancelTaskResponse.java

@ -0,0 +1,30 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class JDCancelTaskResponse extends BaseRequest {
/**
* 是否成功
*/
private Boolean result=true;
/**
* 异常码
*/
Integer code=200;
/**
* 异常消息
*/
String message="取消任务成功";
/**
* 数据对象
*/
Object data;
}

57
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDChangeTaskRequest.java

@ -0,0 +1,57 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class JDChangeTaskRequest extends BaseRequest {
/**
* 场景编号
*/
private String scenarioNo;
/**
* 防重码
*/
String uuid;
/**
* 当前时间
*/
Long currentTime;
/**
* 任务号
*/
String taskNo;
/**
* 容器号
*/
String containerNo;
/**
* 优先级
*/
Integer priority;
/**
* 备注
*/
String remark;
@Override
public String toString() {
return "JDChangeTaskRequest{" +
"scenarioNo='" + scenarioNo + '\'' +
", uuid='" + uuid + '\'' +
", currentTime=" + currentTime +
", taskNo='" + taskNo + '\'' +
", containerNo='" + containerNo + '\'' +
", priority=" + priority +
", remark='" + remark + '\'' +
'}';
}
}

30
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDChangeTaskResponse.java

@ -0,0 +1,30 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class JDChangeTaskResponse extends BaseRequest {
/**
* 是否成功
*/
private Boolean result=true;
/**
* 异常码
*/
Integer code=200;
/**
* 异常消息
*/
String message="取消任务成功";
/**
* 数据对象
*/
Object data;
}

57
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDFaultRequest.java

@ -0,0 +1,57 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class JDFaultRequest extends BaseRequest {
/**
* 场景编号
*/
private String scenarioNo;
/**
* 防重码
*/
String uuid;
/**
* 故障类型
*/
String faultType;
/**
* 故障对象
*/
String faultNo;
/**
* 故障状态
*/
String status;
/**
* 故障描述
*/
String desc;
/**
* 当前位置
*/
String location;
@Override
public String toString() {
return "JDFaultRequest{" +
"scenarioNo='" + scenarioNo + '\'' +
", uuid='" + uuid + '\'' +
", faultType=" + faultType +
", faultNo='" + faultNo + '\'' +
", status='" + status + '\'' +
", desc='" + desc + '\'' +
", location='" + location + '\'' +
'}';
}
}

30
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDFaultResponse.java

@ -0,0 +1,30 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class JDFaultResponse extends BaseRequest {
/**
* 是否成功
*/
private Boolean result=true;
/**
* 异常码
*/
Integer code=200;
/**
* 异常消息
*/
String message="操作成功";
/**
* 数据对象
*/
Object data;
}

25
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JDFeedbackRequest.java

@ -0,0 +1,25 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
import java.util.List;
@Data
public class JDFeedbackRequest{
/**
* 调用码
*/
private String callCode;
private List<Payload> payload;
@Override
public String toString() {
return "JDFeedbackRequest{" +
"callCode='" + callCode + '\'' +
", payload=" + payload +
'}';
}
}

94
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/Payload.java

@ -0,0 +1,94 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
import java.util.List;
@Data
public class Payload{
/**
* 设备类型
*/
private String deviceType;
/**
* 设备代码
*/
private String deviceNo;
/**
* 当前时间
*/
private Long currentTime;
/**
* 工作模式
*/
private String workMode;
/**
* 工作状态
*/
private String workStatus;
/**
* 故障状态
*/
private String faultStatus;
/**
* 故障码
*/
private String faultCodes;
/**
* 通讯状态
*/
private String connectStatus;
/**
* 是否载货
*/
private String existGoods;
/**
* 充电状态
*/
private String charging;
/**
* 电池电量
*/
private String battery;
/**
* 运动信息
*/
private DeviceMotion deviceMotion;
/**
* 任务信息
*/
private List<TaskList> taskList;
@Override
public String toString() {
return "Payload{" +
"deviceType='" + deviceType + '\'' +
", deviceNo='" + deviceNo + '\'' +
", currentTime=" + currentTime +
", workMode='" + workMode + '\'' +
", workStatus='" + workStatus + '\'' +
", faultStatus='" + faultStatus + '\'' +
", faultCodes='" + faultCodes + '\'' +
", connectStatus='" + connectStatus + '\'' +
", existGoods='" + existGoods + '\'' +
", charging='" + charging + '\'' +
", battery='" + battery + '\'' +
", deviceMotion=" + deviceMotion +
", taskList=" + taskList +
'}';
}
}

48
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/TaskList.java

@ -0,0 +1,48 @@
package org.nl.acs.ext.wms.data;
import lombok.Data;
@Data
public class TaskList {
/**
* 容器编号
*/
private String containerNo;
/**
* 是否载货
*/
private String existGoods;
/**
* 位置序号
*/
private String sequence;
/**
* 地图号
*/
private String mapNo;
/**
* 起始位
*/
private String fromPoint;
/**
* 目标位
*/
private String toPoint;
/**
* 任务状态
*/
private String taskStatus;
}

18
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/JDToAcsController.java

@ -10,6 +10,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.ext.wms.data.CancelTaskRequest;
import org.nl.acs.ext.wms.data.CreateTaskRequest;
import org.nl.acs.ext.wms.data.JDCancelTaskRequest;
import org.nl.acs.ext.wms.data.JDChangeTaskRequest;
import org.nl.acs.ext.wms.data.JDCreateTaskRequest;
import org.nl.acs.ext.wms.service.JDToAcsService;
import org.nl.acs.ext.wms.service.WmsToAcsService;
@ -44,5 +46,21 @@ public class JDToAcsController {
return new ResponseEntity<>(jDtoacsService.crateTask(reqs), HttpStatus.OK);
}
@PostMapping("/task_cancel")
@Log(value = "ACS接收WMS任务取消",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS)
@ApiOperation("接收WMS任务取消")
@SaIgnore
public ResponseEntity<Object> cancelFromWms(@RequestBody JDCancelTaskRequest reqs) {
return new ResponseEntity<>(jDtoacsService.cancelFromWms(reqs), HttpStatus.OK);
}
@PostMapping("/task_priority_change")
@Log(value = "任务优先级变更",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS)
@ApiOperation("任务优先级变更")
@SaIgnore
public ResponseEntity<Object> changeFromWms(@RequestBody JDChangeTaskRequest reqs) {
return new ResponseEntity<>(jDtoacsService.changeFromWms(reqs), HttpStatus.OK);
}
}

67
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/JDToAcsService.java

@ -1,13 +1,22 @@
package org.nl.acs.ext.wms.service;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.PutActionResponse;
import java.util.List;
@ -28,64 +37,22 @@ public interface JDToAcsService {
*
* @param reqs 条件
*/
CancelTaskResponse cancelFromWms(List<CancelTaskRequest> reqs) throws Exception;
JDCancelTaskResponse cancelFromWms(JDCancelTaskRequest reqs);
/**
* 修改设置有无货属性
* 更改优先级
*
* @param jsonObject 条件
* @return Map<String, Object>
*/
Map<String, Object> updateDeviceGoodsFromWms(String jsonObject);
/**
* 区域控制
*
* @param jsonObject 条件
* @return Map<String, Object>
* @param reqs 条件
*/
Map<String, Object> areaControl(JSONObject jsonObject);
JDChangeTaskResponse changeFromWms(JDChangeTaskRequest reqs);
/**
* 下发动作
*
* @param jsonObject 条件
* @return Map<String, Object>
*/
PutActionResponse putAction(String jsonObject) throws Exception;
void feedbackDeviceFault(JDFaultRequest reqs);
/**
* 查询设备状态
* 反馈AGV设备信息
*
* @param jsonObject 条件
* @return Map<String, Object>
*/
Map<String, Object> queryDevice(String jsonObject) throws Exception;
/**
* 查询设备DB值
* @param whereJson
* @return
*/
Map<String, Object> queryDeviceDBValue(String whereJson);
/**
* ACS系统在获取空的托盘号
* @param whereJson
* @param from
* @return
*/
Map<String, Object> querydevice(String whereJson);
/**
* 下发插拔轴动作
*
* @param whereJson 条件
* @return Map<String, Object>
*/
Map<String, Object> putPlusPullAction(String whereJson);
HttpResponse feedbackAgv(JDFeedbackRequest jdFeedbackRequest);
}

676
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/JDToAcsServiceImpl.java

@ -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;
}

10
acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceAppServiceImpl.java

@ -263,15 +263,7 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
@Override
public List<Device> findDeviceByType(DeviceType deviceType) {
List<Device> list = this.findDevice(deviceType);
Map<String, String> map = new HashMap();
Iterator var4 = list.iterator();
while (var4.hasNext()) {
Device device = (Device) var4.next();
list.add(device);
}
return list;
return this.findDevice(deviceType);
}

36
acs/nladmin-system/src/main/java/org/nl/modules/common/utils/enums/DeviceStatusEnum.java

@ -0,0 +1,36 @@
package org.nl.modules.common.utils.enums;
import lombok.Getter;
import java.util.Arrays;
@Getter
public enum DeviceStatusEnum {
T1("关机", 1),
T2("运行中", 2),
T3("交通管制", 3),
T4("任务等待", 4),
T5("充电中", 5),
T6("故障中", 6),
T7("低电量", 7);
DeviceStatusEnum(String desc, Integer value) {
this.desc = desc;
this.value = value;
}
private String desc;
private Integer value;
/**
* 根据key得到枚举value
* Lambda表达式
*/
public static DeviceStatusEnum getEnumValue(Integer value) {
return Arrays.asList(DeviceStatusEnum.values()).stream()
.filter(obj -> obj.value.equals(value))
.findFirst().orElse(null);
}
}

106
acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java

@ -1,18 +1,26 @@
package org.nl.modules.quartz.task;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.agv.server.AgvService;
import org.nl.acs.agv.server.dto.AgvDto;
import org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver;
import org.nl.acs.ext.wms.data.DeviceMotion;
import org.nl.acs.ext.wms.data.JDFeedbackRequest;
import org.nl.acs.ext.wms.data.Payload;
import org.nl.acs.ext.wms.data.TaskList;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.modules.mnt.websocket.MsgType;
import org.nl.modules.mnt.websocket.SocketMsg;
import org.nl.modules.mnt.websocket.WebSocketServer;
import org.nl.acs.ext.wms.service.JDToAcsService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.opc.DeviceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
/**
* 查询AGV设备状态
@ -22,55 +30,57 @@ import java.util.Map;
public class ToAgvDevice {
@Autowired
AcsToWmsService acsToWmsService;
JDToAcsService jdToAcsService;
@Autowired
AgvService agvService;
@Autowired
DeviceAppService deviceAppService;
public void run() throws Exception {
JSONObject json = new JSONObject();
Map<String, AgvDto> agv_map = agvService.findAllAgvFromCache();
JSONArray agv_rows = new JSONArray();
JSONObject row = new JSONObject();
for (AgvDto agvDto : agv_map.values()) {
row.put("device_code", agvDto.getName());
row.put("energyLevel", agvDto.getEnergyLevel());
if (agvDto.getState().equals("UNKNOWN")) {
row.put("status_name", "有任务");
row.put("flag", "1");
}
if (agvDto.getState().equals("UNAVAILABLE")) {
row.put("status_name", "网络异常");
row.put("flag", "1");
}
if (agvDto.getState().equals("ERROR")) {
row.put("status_name", "机器错误");
row.put("flag", "1");
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
JDFeedbackRequest jdFeedbackRequest=new JDFeedbackRequest();
jdFeedbackRequest.setCallCode("");
try {
List<Device> deviceList = deviceAppService.findDeviceByType(DeviceType.agv);
List<Payload> payloadList=new ArrayList<>();
for(Device device:deviceList) {
if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
Payload payload=new Payload();
payload.setDeviceType("30");
payload.setDeviceNo(agvNdcOneDeviceDriver.getDevice_code());
payload.setCurrentTime(DateUtil.current());
payload.setWorkMode("1");
payload.setWorkStatus("1");
payload.setFaultStatus(agvNdcOneDeviceDriver.getStatus()!=2?"1":"0");
payload.setFaultStatus(String.valueOf(agvNdcOneDeviceDriver.getError()));
payload.setConnectStatus(agvNdcOneDeviceDriver.isStop()==false?"0":"1");
payload.setExistGoods(String.valueOf(agvNdcOneDeviceDriver.getGoods()));
payload.setCharging(agvNdcOneDeviceDriver.getError()==64?"1":"0");
payload.setBattery(String.valueOf(agvNdcOneDeviceDriver.getElectric_qty()));
DeviceMotion deviceMotion=new DeviceMotion();
deviceMotion.setDirection(String.valueOf(agvNdcOneDeviceDriver.getAngle()));
deviceMotion.setLogicalY(String.valueOf(agvNdcOneDeviceDriver.getX()));
deviceMotion.setLogicalY(String.valueOf(agvNdcOneDeviceDriver.getY()));
payload.setDeviceMotion(deviceMotion);
List<TaskList> taskLists=new ArrayList<>();
TaskList taskList=new TaskList();
Instruction inst=agvNdcOneDeviceDriver.getGlobal_inst();
taskList.setContainerNo(inst!=null?inst.getTask_code():"");
taskList.setMapNo("0");
taskList.setFromPoint(inst!=null?inst.getStart_point_code():"");
taskList.setToPoint(inst!=null?inst.getNext_point_code():"");
taskList.setTaskStatus(String.valueOf(agvNdcOneDeviceDriver.getInst_status()));
taskLists.add(taskList);
payload.setTaskList(taskLists);
payloadList.add(payload);
}
}
if (agvDto.getState().equals("IDLE")) {
row.put("status_name", "空闲");
row.put("flag", "0");
}
if (agvDto.getState().equals("EXECUTING")) {
row.put("status_name", "运行中");
row.put("flag", "0");
}
if (agvDto.getState().equals("CHARGING")) {
row.put("status_name", "充电中");
row.put("flag", "0");
}
row.put("transportOrder", agvDto.getTransportOrder());
row.put("positionX", agvDto.getPositionX());
row.put("positionY", agvDto.getPositionY());
row.put("positionAngle", agvDto.getPositionAngle());
agv_rows.add(row);
jdFeedbackRequest.setPayload(payloadList);
}catch (Exception e){
System.out.println(e.getMessage());
}
json.put("agv_rows", agv_rows);
SocketMsg deviceInfo = new SocketMsg(json, MsgType.INFO);
WebSocketServer.sendInfo(deviceInfo, "toAgvDevice_data");
// acsToWmsService.feedbackAgv(row);
jdToAcsService.feedbackAgv(jdFeedbackRequest);
}
}

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

@ -12,11 +12,12 @@ spring:
db-type: com.alibaba.druid.pool.DruidDataSource
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:shiyaozhongchen_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:shiyaozhongchen_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&allowPublicKeyRetrieval=true
username: ${DB_USER:root}
# password: ${DB_PWD:P@ssw0rd}
password: ${DB_PWD:Root.123456}
# password: ${DB_PWD:Root.123456}
password: ${DB_PWD:123456}
# password: ${DB_PWD:password}
# 初始连接数

Loading…
Cancel
Save