Browse Source

add:增加token访问上位系统,acs定点任务无需请求上位系统

master
gengby 2 years ago
parent
commit
eaf08c6e17
  1. 6
      acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java
  2. 12
      acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java
  3. 178
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
  4. 44
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java
  5. 4
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java
  6. 153
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java
  7. 10
      acs/nladmin-system/src/main/java/org/nl/modules/common/utils/RedisUtils.java

6
acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java

@ -67,7 +67,7 @@ public class NDCAgvServiceImpl implements NDCAgvService {
};
log.info("下发删除AGV指令--{}", Bytes2HexString(b));
// NDCSocketConnectionAutoRun.write(b);
OneNDCSocketConnectionAutoRun.write(b);
System.out.println("下发删除agv指令数据:" + Bytes2HexString(b));
}
@ -218,9 +218,9 @@ public class NDCAgvServiceImpl implements NDCAgvService {
};
log.info("下发AGV充电任务--{}", str1);
try{
try {
OneNDCSocketConnectionAutoRun.write(b);
} catch (Exception e){
} catch (Exception e) {
e.getMessage();
return false;
}

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

@ -131,9 +131,9 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
}
if (ikey != 0) {
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
if (ObjectUtil.isEmpty(inst)) {
inst = instructionService.findByCode(String.valueOf(ikey));
}
// if (ObjectUtil.isEmpty(inst)) {
// inst = instructionService.findByCode(String.valueOf(ikey));
// }
}
if (!ObjectUtil.isEmpty(link_inst)) {
link_flag = true;
@ -154,8 +154,8 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
inst.setAgv_jobno(String.valueOf(index));
inst.setSend_status("1");
instructionService.update(inst);
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
//任务完毕
//(无车id及状态)
@ -163,10 +163,10 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
if (!ObjectUtil.isEmpty(inst)) {
instructionService.finish(inst.getInstruction_id());
} else {
log.warn("指令号:{},未反馈wms任务完成,因为agv上报指令号查询指令为空!");
log.warn("指令号:{},未反馈wms任务完成,因为agv上报指令号查询指令为空!",inst.getInstruction_code());
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},已反馈agv任务完成!");
log.info("指令号:{},已反馈agv任务完成!",inst.getInstruction_code());
}
//请求删除任务
//(需要WCS反馈)

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

@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.AcsConfig;
import org.nl.acs.agv.server.NDCAgvService;
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
import org.nl.acs.device.service.DeviceService;
@ -96,9 +97,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
}
if (ikey != 0) {
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
if (ObjectUtil.isEmpty(inst)) {
inst = instructionService.findByCode(String.valueOf(ikey));
}
// if (ObjectUtil.isEmpty(inst)) {
// inst = instructionService.findByCode(String.valueOf(ikey));
// }
}
if (!ObjectUtil.isEmpty(link_inst)) {
link_flag = true;
@ -168,30 +169,33 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey);
return;
}
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "1");
map.put("device_code", inst.getStart_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs请求wms取货申请成功,wms允许agv申请取货,已反馈agv允许取货", inst.getInstruction_code());
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "0")) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
} else {
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "1");
map.put("device_code", inst.getStart_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs请求wms取货申请成功,wms允许agv申请取货,已反馈agv允许取货", inst.getInstruction_code());
} else {
log.warn("指令号:{},acs请求wms取货申请失败,wms不允许agv取货,未反馈agv允许取货", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms取货申请成功,wms不允许agv申请取货,未反馈agv允许取货", inst.getInstruction_code());
log.warn("指令号:{},acs请求wms取货申请失败,连接被拒绝,未反馈agv允许取货", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms取货申请失败,连接被拒绝,未反馈agv允许取货", inst.getInstruction_code());
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
//取货完毕
//(需要WCS反馈)
@ -230,29 +234,33 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
return;
}
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "2");
map.put("device_code", inst.getStart_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs反馈wms取货完成成功,wms允许agv取货完成,已反馈agv取货完成", inst.getInstruction_code());
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "0")) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
} else {
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "2");
map.put("device_code", inst.getStart_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs反馈wms取货完成离开成功,wms允许agv取货完成离开,已反馈agv取货完成离开", inst.getInstruction_code());
} else {
log.warn("指令号:{},acs反馈wms取货完成离开失败,wms不允许agv取货完成离开,未反馈agv取货完成离开", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs反馈wms取货完成成功,wms不允许agv取货完成,未反馈agv取货完成", inst.getInstruction_code());
log.warn("指令号:{},acs反馈wms取货完成离开失败,连接被拒绝,未反馈agv取货完成离开", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs反馈wms取货完成失败,连接被拒绝,未反馈agv取货完成", inst.getInstruction_code());
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
//到达放货点
//(需要WCS反馈)
@ -287,30 +295,36 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
log.info("未找到关联编号{}对应的指令", ikey);
return;
}
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "3");
map.put("device_code", inst.getNext_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs请求wms放货申请成功,wms允许agv申请放货,已反馈agv允许放货", inst.getInstruction_code());
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "0")) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
} else {
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "3");
map.put("device_code", inst.getNext_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs请求wms放货申请成功,wms允许agv申请放货,已反馈agv允许放货", inst.getInstruction_code());
} else {
log.warn("指令号:{},acs请求wms放货申请失败,wms不允许agv放货,未反馈agv允许放货", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms放货申请成功,wms不允许agv申请放货,未反馈agv允许放货", inst.getInstruction_code());
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
//放货完毕
//(需要WCS反馈)
} else if (phase == 0x09) {
@ -345,25 +359,35 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
log.info("未找到编号{}对应的指令", ikey);
return;
}
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "4");
map.put("device_code", inst.getNext_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs请求wms放货申请成功,wms允许agv申请放货,已反馈agv允许放货", inst.getInstruction_code());
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "0")) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
} else {
Object reqWms = device.getExtraValue().get("reqWms");
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
JSONArray req = new JSONArray();
JSONObject map = new JSONObject();
map.put("vehicle_code", inst.getVehicle_code());
map.put("status", "4");
map.put("device_code", inst.getNext_point_code());
map.put("task_code", inst.getTask_code());
req.add(map);
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
JSONObject resp = JSONObject.parseObject(httpResponse.body());
if (resp.getInteger("status") == 200) {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
log.info("指令号:{},acs请求wms放货完成申请成功,wms允许agv放货完成,已反馈agv放货完成", inst.getInstruction_code());
} else {
log.warn("指令号:{},acs请求wms放货完成离开失败,wms不允许agv放货完成离开,未反馈agv放货完成离开", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms放货完成离开失败,连接被拒绝,未反馈agv放货完成离开", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
//到达位置点
//(需要WCS反馈)

44
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java

@ -2,6 +2,7 @@
package org.nl.acs.ext.wms.rest;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
@ -15,10 +16,7 @@ import org.nl.modules.logging.InterfaceLogType;
import org.nl.modules.logging.annotation.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@ -35,14 +33,14 @@ public class AcsToWmsController {
private final AcsToWmsService acstowmsService;
@PostMapping("/applyTask")
@Log(value = "ACS向WMS申请任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "ACS向WMS申请任务", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("ACS向WMS申请任务")
public ResponseEntity<Object> applyTaskToWms(@RequestBody JSONObject jo) {
return new ResponseEntity<>(acstowmsService.applyTaskToWms(jo), HttpStatus.OK);
}
@PostMapping("/taskStatusFeedback")
@Log(value = "ACS向WMS反馈任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "ACS向WMS反馈任务状态", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("ACS向WMS反馈任务状态")
public ResponseEntity<Object> feedbackTaskStatusToWms(@RequestBody Map whereJson) {
JSONArray data = JSONArray.parseArray(String.valueOf(whereJson));
@ -50,28 +48,28 @@ public class AcsToWmsController {
}
@PostMapping("/feedbackAgvStatus")
@Log(value = "反馈AGV设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "反馈AGV设备状态", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("反馈AGV设备状态")
public ResponseEntity<Object> feedbackAgvStatus(@RequestBody String device_code, String error, String error_message) {
return new ResponseEntity<>(acstowmsService.feedbackAgvStatus(device_code, error, error_message), HttpStatus.OK);
}
@PostMapping("/feedbackAgv")
@Log(value = "反馈AGV设备信息",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "反馈AGV设备信息", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("反馈AGV设备信息")
public ResponseEntity<Object> feedbackAgv(@RequestBody JSONArray from) {
return new ResponseEntity<>(acstowmsService.feedbackAgv(from), HttpStatus.OK);
}
@PostMapping("/feedbackDeviceStatus")
@Log(value = "反馈设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "反馈设备状态", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("反馈设备状态")
public ResponseEntity<Object> feedbackDeviceStatus(@RequestBody String device_code, String code, String value) {
return new ResponseEntity<>(acstowmsService.feedbackDeviceStatus(device_code, code, value), HttpStatus.OK);
}
@PostMapping("/feedbackOrderStatus")
@Log(value = "ACS强制完成向WMS反馈",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "ACS强制完成向WMS反馈", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("acs强制完成向wms反馈")
public ResponseEntity<Object> feedbackOrderStatus(@RequestBody JSONObject param) {
return new ResponseEntity<>(acstowmsService.feedbackOrderStatus(param), HttpStatus.OK);
@ -79,37 +77,53 @@ public class AcsToWmsController {
@PostMapping("/applyInCacheLineTask")
@Log(value = "ACS申请缓存线入库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "ACS申请缓存线入库任务", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("ACS申请缓存线入库任务")
public ResponseEntity<Object> applyInCacheLineTask(@RequestBody JSONObject param) {
return new ResponseEntity<>(acstowmsService.applyInCacheLineTask(param), HttpStatus.OK);
}
@PostMapping("/applyOutCacheLineTask")
@Log(value = "ACS系统申请出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "ACS系统申请出库任务", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("ACS系统申请出库任务")
public ResponseEntity<Object> applyOutCacheLineTask(@RequestBody JSONObject param) {
return new ResponseEntity<>(acstowmsService.applyOutCacheLineTask(param), HttpStatus.OK);
}
@PostMapping("/applyLabelingAndBindingRequest")
@Log(value = "ACS系统申请贴标、捆扎",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "ACS系统申请贴标、捆扎", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("ACS系统申请贴标、捆扎")
public ResponseEntity<Object> applyLabelingAndBindingRequest(@RequestBody ApplyLabelingAndBindingRequest param) {
return new ResponseEntity<>(acstowmsService.applyLabelingAndBindingRequest(param), HttpStatus.OK);
}
@PostMapping("/liKuApplyTaskRequest")
@Log(value = "立库申请任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "立库申请任务", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("立库申请任务")
public ResponseEntity<Object> liKuApplyTaskRequest(@RequestBody LiKuApplyTaskRequest param) {
return new ResponseEntity<>(acstowmsService.liKuApplyTaskRequest(param), HttpStatus.OK);
}
@PostMapping("/feedAgvTaskStatus")
@Log(value = "反馈AGV取放货状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS)
@Log(value = "反馈AGV取放货状态", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("反馈AGV取放货状态")
public ResponseEntity<Object> feedAgvTaskStatus(@RequestBody JSONArray from) {
return new ResponseEntity<>(acstowmsService.feedAgvTaskStatus(from), HttpStatus.OK);
}
@GetMapping("/getTokenFromWms")
@Log(value = "向wms获取token", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("向wms获取token")
@SaIgnore
public ResponseEntity<Object> getTokenFromWms() {
return new ResponseEntity<>(acstowmsService.getTokenFromWms(), HttpStatus.OK);
}
@PostMapping("/test")
@Log(value = "test携带Token访问", isInterfaceLog = true, interfaceLogType = InterfaceLogType.ACS_TO_LMS)
@ApiOperation("test携带Token访问")
@SaIgnore
public ResponseEntity<Object> test(@RequestBody JSONObject from) {
return new ResponseEntity<>(acstowmsService.test(from), HttpStatus.OK);
}
}

4
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java

@ -19,6 +19,8 @@ public interface AcsToWmsService {
*/
public HttpResponse feedbackTaskStatusToWms(JSONArray arr);
public HttpResponse getTokenFromWms();
public String requestTaskAgain(String address, String task_id, String vehicle_code);
@ -112,4 +114,6 @@ public interface AcsToWmsService {
* @return
*/
HttpResponse feedAgvTaskStatus(JSONArray from);
public HttpResponse test(JSONObject form);
}

153
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java

@ -19,36 +19,36 @@ import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.system.service.ParamService;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@Service
@RequiredArgsConstructor
@Slf4j
public class AcsToWmsServiceImpl implements AcsToWmsService {
@Autowired
ParamService paramService;
@Autowired
DeviceService deviceService;
private ParamService paramService;
@Autowired
AddressService addressService;
private DeviceService deviceService;
@Autowired
TaskService taskService;
private AddressService addressService;
@Autowired
DeviceExecuteLogService logServer;
private RedisUtils redisUtils;
/*@Value("${acsTowms.token}")*/
public String token;
private String log_file_type="log_file_type";
private String log_type="ACS请求LMS";
private String log_file_type = "log_file_type";
private String log_type = "ACS请求LMS";
@Override
public String applyTaskToWms(JSONObject jo) {
@ -71,7 +71,7 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
//网络不通
// //System.out.println(msg);
}
if(ObjectUtil.isEmpty(result2)){
if (ObjectUtil.isEmpty(result2)) {
log.info("applyTaskToWms-----输出参数{}", "返回结果为空");
return null;
}
@ -95,49 +95,64 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
try {
MDC.put(log_file_type, log_type);
String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue();
String task_code = "";
for (int i = 0; i < data.size(); i++) {
JSONObject json = (JSONObject) data.get(i);
task_code = json.getString("task_code");
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) {
log.info("开始反馈wms任务状态,请求参数:{}", JSON.toJSONString(data));
if (!redisUtils.hasKey("wms_token")) {
this.getTokenFromWms();
}
String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue();
HttpResponse result = null;
AddressDto addressDto = addressService.findByCode("feedbackTaskStatusToWms");
String methods_url = addressDto.getMethods_url();
try {
result = HttpRequest
.post(wmsurl + methods_url)
.header("Authorization", String.valueOf(redisUtils.get("wms_token")))
.body(JSON.toJSONString(data))
.execute();
log.info("反馈wms任务状态成功,请求路径:{},请求参数:{}", wmsurl + methods_url, JSON.toJSONString(data));
} catch (Exception e) {
log.info("反馈wms任务状态失败,请求路径:{},失败原因:{}", wmsurl + methods_url, e.getMessage());
}
return result;
}
TaskDto taskDto = taskService.findByCode(task_code);
String vehicle_code = taskDto.getVehicle_code();
HttpResponse result2 = null;
log.info("feedbackTaskStatusToWms-----请求参数{}", data.toString());
return null;
} finally {
MDC.remove(log_file_type);
}
}
AddressDto addressDto = addressService.findByCode("feedbackTaskStatusToWms");
@Override
public HttpResponse getTokenFromWms() {
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) {
log.info("acs开始向wms获取token......");
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue();
AddressDto addressDto = addressService.findByCode("getTokenFromWms");
String methods_url = addressDto.getMethods_url();
String url = wmsUrl + methods_url;
HttpResponse result = null;
try {
result2 = HttpRequest.post(wmsurl + methods_url)
.header("Authorization", token).body(String.valueOf(data))
result = HttpRequest.post(url)
.body(url + methods_url)
.execute();
// //System.out.println(result2);
if (ObjectUtil.isNotEmpty(result) && result.getStatus() == 200) {
String body = result.body();
if (StrUtil.isNotEmpty(body)) {
JSONObject jsonObject = JSONObject.parseObject(body);
String access_token = jsonObject.getString("access_token");
String token_type = jsonObject.getString("token_type");
String expires_in = jsonObject.getString("expires_in");
String scope = jsonObject.getString("scope");
redisUtils.setExpire("wms_token", token_type + " " + access_token, Long.valueOf(expires_in), TimeUnit.SECONDS);
log.info("acs向wms获取token成功,响应参数:{},已向redis中设置wms_token值", jsonObject);
}
}
} catch (Exception e) {
String msg = e.getMessage();
//网络不通
// //System.out.println(msg);
log.info("feedbackTaskStatusToWms-----输出参数{}", msg);
}
String type = "";
if (result2.getStatus() == 200) {
type = "info";
} else {
type = "error";
log.error("acs向wms获取token失败,失败原因:{}", e.getMessage());
}
JSONObject jo = JSONObject.parseObject(result2.body());
log.info("feedbackTaskStatusToWms-----输出参数{}", jo.toString());
return result2;
} finally {
MDC.remove(log_file_type);
return result;
}
return null;
}
@ -472,7 +487,6 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
}
@Override
public UpdateLKTaskResponse updateLKTaskRequest(UpdateLKTaskRequest param) {
try {
@ -532,25 +546,38 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
@Override
public HttpResponse feedAgvTaskStatus(JSONArray from) {
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue();
AddressDto addressDto = addressService.findByCode("feedAgvTaskStatus");
String methods_url = addressDto.getMethods_url();
String url = wmsUrl + methods_url;
HttpResponse result = null;
log.info("feedAgvTaskStatus----请求参数{}", from);
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) {
log.info("开始反馈WMS AGV取放货状态,请求参数:{}", from);
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue();
AddressDto addressDto = addressService.findByCode("feedAgvTaskStatus");
String methods_url = addressDto.getMethods_url();
String url = wmsUrl + methods_url;
HttpResponse result = null;
try {
result = HttpRequest.post(url)
.header("Authorization", String.valueOf(redisUtils.get("wms_token")))
.body(JSON.toJSONString(from))
.execute();
log.info("反馈WMS AGV取放货状态成功,请求路径:{},请求结果:{}", url, result.body());
} catch (Exception e) {
log.info("反馈WMS AGV取放货状态失败,请求路径:{},请求结果:{}", url, e.getMessage());
}
return result;
}
return null;
}
try {
result = HttpRequest.post(url)
.body(String.valueOf(from))
.execute();
System.out.println(result);
log.info("feedAgvTaskStatus----返回参数{}", result);
} catch (Exception e) {
String msg = e.getMessage();
//网络不通
//System.out.println(msg);
@Override
public HttpResponse test(JSONObject form) {
if (!redisUtils.hasKey("wms_token")) {
this.getTokenFromWms();
}
String url = "https://zoneda.onestep-cloud.com/lwmss/v1/41/chsv-unqualified-products/execute-inspection-ng";
HttpResponse result = HttpRequest
.post(url)
.header("Authorization", String.valueOf(redisUtils.get("wms_token")))
.body(JSON.toJSONString(form))
.execute();
return result;
}
}

10
acs/nladmin-system/src/main/java/org/nl/modules/common/utils/RedisUtils.java

@ -216,7 +216,7 @@ public class RedisUtils {
public List<Object> multiGet(List<String> keys) {
List list = redisTemplate.opsForValue().multiGet(Sets.newHashSet(keys));
List resultList = Lists.newArrayList();
Optional.ofNullable(list).ifPresent(e-> list.forEach(ele-> Optional.ofNullable(ele).ifPresent(resultList::add)));
Optional.ofNullable(list).ifPresent(e -> list.forEach(ele -> Optional.ofNullable(ele).ifPresent(resultList::add)));
return resultList;
}
@ -282,6 +282,14 @@ public class RedisUtils {
}
}
public void setExpire(String key, Object value, long time, TimeUnit timeUnit) {
try {
redisTemplate.opsForValue().set(key, value, time, timeUnit);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
// ================================Map=================================
/**

Loading…
Cancel
Save