Browse Source

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

master
gengby 2 years ago
parent
commit
eaf08c6e17
  1. 2
      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. 46
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
  4. 22
      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. 123
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java
  7. 8
      acs/nladmin-system/src/main/java/org/nl/modules/common/utils/RedisUtils.java

2
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));
}

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,19 +154,19 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
inst.setAgv_jobno(String.valueOf(index));
inst.setSend_status("1");
instructionService.update(inst);
}
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
//任务完毕
//(无车id及状态)
else if (phase == 0x0A) {
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反馈)

46
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,7 +169,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey);
return;
}
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();
@ -185,7 +188,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
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());
log.warn("指令号:{},acs请求wms取货申请失败,wms不允许agv取货,未反馈agv允许取货", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms取货申请失败,连接被拒绝,未反馈agv允许取货", inst.getInstruction_code());
@ -193,6 +196,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
//取货完毕
//(需要WCS反馈)
} else if (phase == 0x05) {
@ -230,6 +234,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
return;
}
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();
@ -244,16 +251,17 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
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());
log.info("指令号:{},acs反馈wms取货完成离开成功,wms允许agv取货完成离开,已反馈agv取货完成离开", inst.getInstruction_code());
} else {
log.warn("指令号:{},acs反馈wms取货完成成功,wms不允许agv取货完成,未反馈agv取货完成", inst.getInstruction_code());
log.warn("指令号:{},acs反馈wms取货完成离开失败,wms不允许agv取货完成离开,未反馈agv取货完成离开", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs反馈wms取货完成失败,连接被拒绝,未反馈agv取货完成", inst.getInstruction_code());
log.warn("指令号:{},acs反馈wms取货完成离开失败,连接被拒绝,未反馈agv取货完成离开", inst.getInstruction_code());
}
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
//到达放货点
//(需要WCS反馈)
} else if (phase == 0x07) {
@ -287,6 +295,10 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
log.info("未找到关联编号{}对应的指令", ikey);
return;
}
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();
@ -303,7 +315,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
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());
log.warn("指令号:{},acs请求wms放货申请失败,wms不允许agv放货,未反馈agv允许放货", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
@ -311,6 +323,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
//放货完毕
//(需要WCS反馈)
} else if (phase == 0x09) {
@ -345,6 +359,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
log.info("未找到编号{}对应的指令", ikey);
return;
}
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();
@ -356,15 +373,22 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
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());
log.info("指令号:{},acs请求wms放货完成申请成功,wms允许agv放货完成,已反馈agv放货完成", inst.getInstruction_code());
} else {
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
log.warn("指令号:{},acs请求wms放货完成离开失败,wms不允许agv放货完成离开,未反馈agv放货完成离开", inst.getInstruction_code());
}
} else {
log.warn("指令号:{},acs请求wms放货完成离开失败,连接被拒绝,未反馈agv放货完成离开", inst.getInstruction_code());
}
} else {
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
}
}
}
//到达位置点
//(需要WCS反馈)
else if (phase == 0x64) {//param,agv货位id待定

22
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;
@ -112,4 +110,20 @@ public class AcsToWmsController {
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);
}

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

@ -19,29 +19,29 @@ 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;
@ -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();
}
TaskDto taskDto = taskService.findByCode(task_code);
String vehicle_code = taskDto.getVehicle_code();
HttpResponse result2 = null;
log.info("feedbackTaskStatusToWms-----请求参数{}", data.toString());
String wmsurl = paramService.findByCode(AcsConfig.WMSURL).getValue();
HttpResponse result = null;
AddressDto addressDto = addressService.findByCode("feedbackTaskStatusToWms");
String methods_url = addressDto.getMethods_url();
try {
result2 = HttpRequest.post(wmsurl + methods_url)
.header("Authorization", token).body(String.valueOf(data))
result = HttpRequest
.post(wmsurl + methods_url)
.header("Authorization", String.valueOf(redisUtils.get("wms_token")))
.body(JSON.toJSONString(data))
.execute();
// //System.out.println(result2);
log.info("反馈wms任务状态成功,请求路径:{},请求参数:{}", wmsurl + methods_url, JSON.toJSONString(data));
} catch (Exception e) {
String msg = e.getMessage();
//网络不通
// //System.out.println(msg);
log.info("feedbackTaskStatusToWms-----输出参数{}", msg);
log.info("反馈wms任务状态失败,请求路径:{},失败原因:{}", wmsurl + methods_url, e.getMessage());
}
String type = "";
if (result2.getStatus() == 200) {
type = "info";
} else {
type = "error";
return result;
}
JSONObject jo = JSONObject.parseObject(result2.body());
log.info("feedbackTaskStatusToWms-----输出参数{}", jo.toString());
return result2;
return null;
} finally {
MDC.remove(log_file_type);
}
}
@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 {
result = HttpRequest.post(url)
.body(url + methods_url)
.execute();
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) {
log.error("acs向wms获取token失败,失败原因:{}", e.getMessage());
}
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) {
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;
log.info("feedAgvTaskStatus----请求参数{}", from);
try {
result = HttpRequest.post(url)
.body(String.valueOf(from))
.header("Authorization", String.valueOf(redisUtils.get("wms_token")))
.body(JSON.toJSONString(from))
.execute();
System.out.println(result);
log.info("feedAgvTaskStatus----返回参数{}", result);
log.info("反馈WMS AGV取放货状态成功,请求路径:{},请求结果:{}", url, result.body());
} catch (Exception e) {
String msg = e.getMessage();
//网络不通
//System.out.println(msg);
log.info("反馈WMS AGV取放货状态失败,请求路径:{},请求结果:{}", url, e.getMessage());
}
return result;
}
return null;
}
@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;
}
}

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

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