add:新增ndc接口

This commit is contained in:
2026-02-05 10:58:58 +08:00
parent d337ed888a
commit ed9a42b086
27 changed files with 1023 additions and 37 deletions

View File

@@ -62,4 +62,8 @@ public interface AcsConfig {
String MAXSENDTASKTIME = "maxSendTaskTime";
//指令下发立库
String INSTSENDLK = "instSendLk";
String HAS_NDC = "has_ndc";
String NDC_URL = "ndc_url";
}

View File

@@ -106,6 +106,14 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
//触摸屏手动触发任务
private Boolean is_has_task = false;
//1取货请求 2取货完成完成 3放货请求 4放货完成 -1进入请求 -2请求离开
private volatile int agvphase = 0;
/**
* agv请求标志和任务号
*/
private volatile String reqTakeInstCode = null;
private volatile Boolean reqTakeRequireSuccess = false;
//申请搬运任务
private Boolean apply_handling = false;
//申请物料

View File

@@ -109,7 +109,13 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
// 1 上位系统允许进入 2 上位系统允许离开
int status = 0;
int agvphase = 0;
//1取货请求 2取货完成完成 3放货请求 4放货完成 -1进入请求 -2请求离开
private volatile int agvphase = 0;
/**
* agv请求标志和任务号
*/
private volatile String reqTakeInstCode = null;
private volatile Boolean reqTakeRequireSuccess = false;
int index = 0;
int mode = 2;

View File

@@ -0,0 +1,29 @@
package org.nl.acs.ext.wms;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class IpUtil {
public static final String LOCAL_IP = localIP();
public static String localIP() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof java.net.Inet4Address) {
return inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "";
}
}

View File

@@ -0,0 +1,124 @@
package org.nl.acs.ext.wms;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import org.nl.acs.AcsConfig;
import org.nl.acs.ext.wms.log.ToOthersInterfaceLog;
import org.nl.modules.quartz.CommonFinalParam;
import org.nl.modules.system.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class NdcHttpUtil {
private static final RequestAdapter REQUEST_ADAPTER = new NdcRequestAdapter();
private static final ResponseAdapter RESPONSE_ADAPTER = new NdcResponseAdapter();
@Autowired
private ParamService paramService;
@ToOthersInterfaceLog("ACS->NDC")
public <T, W> UnifiedResponse<T> sendPostRequest(String path, W requestParam, Class<T> type) {
if (!StrUtil.equals(paramService.findByCode(AcsConfig.HAS_NDC).getValue(), CommonFinalParam.ONE)) {
return new UnifiedResponse<>(false, "未开启连接该系统!");
}
try {
String body = HttpRequest
.post(REQUEST_ADAPTER.getUrl() + path)
.setConnectionTimeout(5000)
.body(JSON.toJSONString(requestParam))
.execute()
.body();
return RESPONSE_ADAPTER.adapt(body, type);
} catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage());
}
}
@ToOthersInterfaceLog("ACS->NDC")
public <T, W> UnifiedResponse<T> sendPostRequest(String path, W requestParam) {
if (!StrUtil.equals(paramService.findByCode(AcsConfig.HAS_NDC).getValue(), CommonFinalParam.ONE)) {
return new UnifiedResponse<>(false, "未开启连接该系统!");
}
try {
String body = HttpRequest
.post(REQUEST_ADAPTER.getUrl() + path)
.setConnectionTimeout(5000)
.body(JSON.toJSONString(requestParam))
.execute()
.body();
return RESPONSE_ADAPTER.adapt(body, null);
} catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage());
}
}
@ToOthersInterfaceLog("ACS->NDC")
public <T> UnifiedResponse<T> sendPostRequest(String path, Class<T> type) {
if (!StrUtil.equals(paramService.findByCode(AcsConfig.HAS_NDC).getValue(), CommonFinalParam.ONE)) {
return new UnifiedResponse<>(false, "未开启连接该系统!");
}
try {
String body = HttpRequest
.post(REQUEST_ADAPTER.getUrl() + path)
.setConnectionTimeout(5000)
.execute()
.body();
return RESPONSE_ADAPTER.adapt(body, type);
} catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage());
}
}
@ToOthersInterfaceLog("ACS->NDC")
public <T> UnifiedResponse<T> sendPostRequest(String path) {
if (!StrUtil.equals(paramService.findByCode(AcsConfig.HAS_NDC).getValue(), CommonFinalParam.ONE)) {
return new UnifiedResponse<>(false, "未开启连接该系统!");
}
try {
String body = HttpRequest
.post(REQUEST_ADAPTER.getUrl() + path)
.setConnectionTimeout(5000)
.execute()
.body();
return RESPONSE_ADAPTER.adapt(body, null);
} catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage());
}
}
@ToOthersInterfaceLog("ACS->NDC")
public <T> UnifiedResponse<T> sendGetRequest(String path, Class<T> type) {
if (!StrUtil.equals(paramService.findByCode(AcsConfig.HAS_NDC).getValue(), CommonFinalParam.ONE)) {
return new UnifiedResponse<>(false, "未开启连接该系统!");
}
try {
String body = HttpRequest
.get(REQUEST_ADAPTER.getUrl() + path)
.setConnectionTimeout(5000)
.execute()
.body();
return RESPONSE_ADAPTER.adapt(body, type);
} catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage());
}
}
@ToOthersInterfaceLog("ACS->NDC")
public <T> UnifiedResponse<T> sendGetRequest(String path) {
if (!StrUtil.equals(paramService.findByCode(AcsConfig.HAS_NDC).getValue(), CommonFinalParam.ONE)) {
return new UnifiedResponse<>(false, "未开启连接该系统!");
}
try {
String body = HttpRequest
.get(REQUEST_ADAPTER.getUrl() + path)
.setConnectionTimeout(5000)
.execute()
.body();
return RESPONSE_ADAPTER.adapt(body, null);
} catch (Exception e) {
return new UnifiedResponse<>(false, e.getMessage());
}
}
}

View File

@@ -0,0 +1,13 @@
package org.nl.acs.ext.wms;
import org.nl.acs.AcsConfig;
import org.nl.modules.system.service.ParamService;
import org.nl.modules.wql.util.SpringContextHolder;
public class NdcRequestAdapter implements RequestAdapter{
@Override
public String getUrl() {
ParamService paramService = SpringContextHolder.getBean(ParamService.class);
return paramService.findByCode(AcsConfig.NDC_URL).getValue();
}
}

View File

@@ -0,0 +1,31 @@
package org.nl.acs.ext.wms;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.Collection;
public class NdcResponseAdapter implements ResponseAdapter{
@Override
public <T> UnifiedResponse<T> adapt(String responseBody, Class<T> type) {
JSONObject resp = JSON.parseObject(responseBody);
boolean isSuccess = resp.getInteger("code") == 0;
String message = resp.getString("message");
String reqCode = resp.getString("reqCode");
if (type != null) {
Object dataObject = resp.get("data");
T data;
if (type == String.class) {
data = type.cast(dataObject.toString());
} else if (type == Object.class) {
data = type.cast(dataObject);
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
data = JSON.parseObject(dataObject.toString(), type);
} else {
data = JSON.parseObject(resp.getString("data"), type);
}
return new UnifiedResponse<>(isSuccess, message, reqCode, data);
}
return new UnifiedResponse<>(isSuccess, message, reqCode);
}
}

View File

@@ -0,0 +1,5 @@
package org.nl.acs.ext.wms;
public interface RequestAdapter {
String getUrl();
}

View File

@@ -0,0 +1,5 @@
package org.nl.acs.ext.wms;
public interface ResponseAdapter {
public <T> UnifiedResponse<T> adapt(String responseBody, Class<T> type);
}

View File

@@ -0,0 +1,53 @@
package org.nl.acs.ext.wms;
public class UnifiedResponse<T> {
private boolean success;
private String message;
private String reqCode;
private T data;
public UnifiedResponse(boolean success, String message, T data) {
this.success = success;
this.message = message;
this.data = data;
}
public UnifiedResponse(boolean success, String message, String reqCode, T data) {
this.success = success;
this.message = message;
this.reqCode = reqCode;
this.data = data;
}
public UnifiedResponse(boolean success, String message) {
this.success = success;
this.message = message;
}
public UnifiedResponse(boolean success, String message, String reqCode) {
this.success = success;
this.message = message;
this.reqCode = reqCode;
}
public boolean isSuccess() {
return this.success;
}
public String getMessage() {
return this.message;
}
public String getReqCode() {
return this.reqCode;
}
public T getData() {
return this.data;
}
public void setData(T data) {
this.data = data;
}
}

View File

@@ -0,0 +1,42 @@
package org.nl.acs.ext.wms.enums;
public enum MsgTypeEnum {
CREATE_TASK_REQ("3", "创建任务"),
CANCEL_TASK_REQ("9", "取消任务"),
TASK_PICKUP_REQ("10", "取请求应答"),
TASK_RELEASE_REQ("11", "放请求应答"),
TASK_STATE_RPT("7", "任务状态上报"),
AGV_POWER_RPT("101", "AGV电量上报"),
AGV_ID_RPT("103", "任务分配车辆上报"),
TASK_INDEX_RPT("8", "车辆任务生成上报"),
AGV_ERROR_RPT("102", "AGV故障上报"),
AGV_STATE_RPT("100", "AGV状态上报");
private final String value;
private final String description;
MsgTypeEnum(String value, String description) {
this.value = value;
this.description = description;
}
public String getValue() {
return value;
}
public String getDescription() {
return description;
}
/**
* 根据值获取对应的枚举
*/
public static MsgTypeEnum fromValue(String value) {
for (MsgTypeEnum type : values()) {
if (type.getValue() == value) {
return type;
}
}
throw new IllegalArgumentException("无效的 MSG_TYPE 值: " + value);
}
}

View File

@@ -0,0 +1,38 @@
package org.nl.acs.ext.wms.enums;
public enum TaskPhaseEnum {
PICKUP_REQUEST_OR_RESPONSE("1", "取货请求或者取请求应答(允许取货)"),
PICKUP_COMPLETE("2", "取货完成"),
RELEASE_REQUEST_OR_RESPONSE("3", "放货请求或者放请求应答(允许放货)"),
RELEASE_COMPLETE("4", "放货完成"),
ENTER_REQUEST_OR_ALLOWED("-1", "进入请求或者允许进入"),
LEAVE_NOTICE_OR_ALLOWED("-2", "离开通知或者允许离开");
private final String value;
private final String description;
TaskPhaseEnum(String value, String description) {
this.value = value;
this.description = description;
}
public String getValue() {
return value;
}
public String getDescription() {
return description;
}
/**
* 根据值获取对应的枚举
*/
public static TaskPhaseEnum fromValue(String value) {
for (TaskPhaseEnum phase : values()) {
if (phase.getValue() == value) {
return phase;
}
}
throw new IllegalArgumentException("无效的 TaskPhase 值: " + value);
}
}

View File

@@ -0,0 +1,36 @@
package org.nl.acs.ext.wms.enums;
public enum TaskStateEnum {
NOT_STARTED("0", "任务未启动"),
EXECUTING("1", "执行中"),
COMPLETED("2", "完成"),
CANCELED("3", "取消"),;
private final String value;
private final String description;
TaskStateEnum(String value, String description) {
this.value = value;
this.description = description;
}
public String getValue() {
return value;
}
public String getDescription() {
return description;
}
/**
* 根据值获取对应的枚举
*/
public static TaskStateEnum fromValue(String value) {
for (TaskStateEnum state : values()) {
if (state.getValue() == value) {
return state;
}
}
throw new IllegalArgumentException("无效的 TASK_STATE 值: " + value);
}
}

View File

@@ -0,0 +1,103 @@
package org.nl.acs.ext.wms.log;
import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.nl.acs.ext.wms.IpUtil;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Method;
@Aspect
@Component
public class OtherToInterfaceLogAspect {
@Autowired
private LuceneExecuteLogService logService;
@Around("@annotation(org.nl.acs.ext.wms.log.OthersToInterfaceLog)")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Class<?> targetClass = joinPoint.getTarget().getClass();
RequestMapping classRequestMapping = targetClass.getAnnotation(RequestMapping.class);
String classUrlValue = classRequestMapping != null ? String.join(",", classRequestMapping.value()) : "No Class Annotation";
String methodUrlValue = "";
if (method.isAnnotationPresent(GetMapping.class)) {
GetMapping getMapping = method.getAnnotation(GetMapping.class);
methodUrlValue = String.join(",", getMapping.value());
} else if (method.isAnnotationPresent(PostMapping.class)) {
PostMapping postMapping = method.getAnnotation(PostMapping.class);
methodUrlValue = String.join(",", postMapping.value());
} else if (method.isAnnotationPresent(PutMapping.class)) {
PutMapping putMapping = method.getAnnotation(PutMapping.class);
methodUrlValue = String.join(",", putMapping.value());
} else if (method.isAnnotationPresent(DeleteMapping.class)) {
DeleteMapping deleteMapping = method.getAnnotation(DeleteMapping.class);
methodUrlValue = String.join(",", deleteMapping.value());
} else if (method.isAnnotationPresent(RequestMapping.class)) {
RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
methodUrlValue = String.join(",", methodRequestMapping.value());
}
String request_direction = "";
if (method.isAnnotationPresent(OthersToInterfaceLog.class)) {
OthersToInterfaceLog interfaceLog = method.getAnnotation(OthersToInterfaceLog.class);
request_direction = interfaceLog.value();
}
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
LuceneLogDto logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(IpUtil.localIP() + classUrlValue + methodUrlValue)
.request_direction(request_direction)
.request_param(JSON.toJSONString(args))
.method(methodName)
.content("开始请求")
.build();
logService.interfaceExecuteLog(logDto);
Object result = null;
try {
result = joinPoint.proceed();
} catch (Exception e) {
logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(IpUtil.localIP() + classUrlValue + methodUrlValue)
.request_direction(request_direction)
.request_param(JSON.toJSONString(args))
.method(methodName)
.response_param(e.getMessage())
.executeTime(System.currentTimeMillis() - startTime)
.content("响应请求")
.build();
logService.interfaceExecuteLog(logDto);
throw new BadRequestException(e.getMessage());
}
logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(IpUtil.localIP() + classUrlValue + methodUrlValue)
.request_direction(request_direction)
.request_param(JSON.toJSONString(args))
.method(methodName)
.response_param(JSON.toJSONString(result))
.executeTime(System.currentTimeMillis() - startTime)
.content("响应请求")
.build();
logService.interfaceExecuteLog(logDto);
return result;
}
}

View File

@@ -0,0 +1,12 @@
package org.nl.acs.ext.wms.log;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OthersToInterfaceLog {
String value() default "";
}

View File

@@ -0,0 +1,133 @@
package org.nl.acs.ext.wms.log;
import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@Aspect
@Component
public class ToOtherInterfaceLogAspect {
private static final ConcurrentMap<Class<?>, Field> fieldCache = new ConcurrentHashMap<>();
private static final ConcurrentMap<Class<?>, Method> methodCache = new ConcurrentHashMap<>();
@Autowired
private LuceneExecuteLogService logService;
@Around("@annotation(org.nl.acs.ext.wms.log.ToOthersInterfaceLog)")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
long startTime = System.currentTimeMillis();
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
String request_direction = "";
if (method.isAnnotationPresent(ToOthersInterfaceLog.class)) {
ToOthersInterfaceLog interfaceLog = method.getAnnotation(ToOthersInterfaceLog.class);
request_direction = interfaceLog.value();
}
String methodName = joinPoint.getSignature().getName();
Object[] args = joinPoint.getArgs();
Object url = "";
Object requesr_param = "";
if (args.length > 1) {
url = args[0];
requesr_param = args[1];
}
Class<?> targetClass = joinPoint.getTarget().getClass();
Object ipPort = "";
try {
Field requestAdapterField = fieldCache.computeIfAbsent(targetClass, clazz -> {
try {
Field field = clazz.getDeclaredField("REQUEST_ADAPTER");
ReflectionUtils.makeAccessible(field);
return field;
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
});
Object requestAdapterObject = requestAdapterField.get(null);
Method getUrlMethod = methodCache.computeIfAbsent(requestAdapterObject.getClass(), clazz -> {
try {
Method m = clazz.getDeclaredMethod("getUrl");
ReflectionUtils.makeAccessible(m);
return m;
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
});
ipPort = getUrlMethod.invoke(requestAdapterObject);
} catch (Exception e) {
LuceneLogDto logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(ipPort + String.valueOf(url))
.request_direction(request_direction)
.request_param(JSON.toJSONString(requesr_param))
.method(methodName)
.content("开始请求,获取url失败," + e.getMessage())
.build();
logService.interfaceExecuteLog(logDto);
}
LuceneLogDto logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(ipPort + String.valueOf(url))
.request_direction(request_direction)
.request_param(JSON.toJSONString(requesr_param))
.method(methodName)
.content("开始请求")
.build();
logService.interfaceExecuteLog(logDto);
Object result = null;
try {
result = joinPoint.proceed();
} catch (Exception e) {
logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(ipPort + String.valueOf(url))
.request_direction(request_direction)
.request_param(JSON.toJSONString(requesr_param))
.method(methodName)
.response_param(e.getMessage())
.executeTime(System.currentTimeMillis() - startTime)
.content("响应请求")
.build();
logService.interfaceExecuteLog(logDto);
throw new BadRequestException(e.getMessage());
}
logDto =
LuceneLogDto.builder()
.logType("接口日志")
.request_url(ipPort + String.valueOf(url))
.request_direction(request_direction)
.request_param(JSON.toJSONString(requesr_param))
.method(methodName)
.response_param(JSON.toJSONString(result))
.executeTime(System.currentTimeMillis() - startTime)
.content("响应请求")
.build();
logService.interfaceExecuteLog(logDto);
return result;
}
}

View File

@@ -0,0 +1,12 @@
package org.nl.acs.ext.wms.log;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ToOthersInterfaceLog {
String value() default "";
}

View File

@@ -0,0 +1,15 @@
package org.nl.acs.ext.wms.rest;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
@Api(tags = "ndc接口")
@RequestMapping("/acsToNdc")
@Slf4j
public class AcsToNDCController {
}

View File

@@ -0,0 +1,34 @@
package org.nl.acs.ext.wms.rest;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.ext.wms.log.OthersToInterfaceLog;
import org.nl.acs.ext.wms.service.AcsToNDCService;
import org.nl.acs.ext.wms.service.NDCToAcsService;
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;
@RestController
@RequiredArgsConstructor
@Api(tags = "ndc接口")
@RequestMapping("/ndcToAcs")
@Slf4j
public class NDCToAcsController {
private final NDCToAcsService ndcToAcsService;
@SaIgnore
@PostMapping("/agv/agvCallbackService/agvCallback")
@OthersToInterfaceLog("NDC->ACS")
public ResponseEntity<Object> agvCallback(@RequestBody JSONObject requestParam) throws Exception{
return new ResponseEntity<>(ndcToAcsService.agvCallback(requestParam), HttpStatus.OK);
}
}

View File

@@ -0,0 +1,7 @@
package org.nl.acs.ext.wms.service;
import com.alibaba.fastjson.JSONObject;
public interface AcsToNDCService {
}

View File

@@ -0,0 +1,13 @@
package org.nl.acs.ext.wms.service;
import com.alibaba.fastjson.JSONObject;
public interface NDCToAcsService {
/**
* NDC反馈状态
* @param requestParam
* @return
*/
JSONObject agvCallback(JSONObject requestParam) throws Exception;
}

View File

@@ -0,0 +1,12 @@
package org.nl.acs.ext.wms.service.impl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.ext.wms.service.AcsToNDCService;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@Slf4j
public class AcsToNDCServiceImpl implements AcsToNDCService {
}

View File

@@ -0,0 +1,237 @@
package org.nl.acs.ext.wms.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.acs.device.service.StorageCellService;
import org.nl.acs.device.service.dto.StorageCellDto;
import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver;
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
import org.nl.acs.ext.wms.enums.MsgTypeEnum;
import org.nl.acs.ext.wms.enums.TaskPhaseEnum;
import org.nl.acs.ext.wms.enums.TaskStateEnum;
import org.nl.acs.ext.wms.service.NDCToAcsService;
import org.nl.acs.instruction.enums.InstStatusEnum;
import org.nl.acs.instruction.enums.InstTypeEnum;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.modules.common.exception.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
@RequiredArgsConstructor
@Slf4j
public class NDCToAcsServiceImpl implements NDCToAcsService {
@Autowired
private InstructionService instructionService;
@Autowired
private StorageCellService storageCellService;
@Autowired
private DeviceAppService deviceAppService;
@Override
public JSONObject agvCallback(JSONObject requestParam) throws Exception{
JSONObject resp = new JSONObject();
String type = requestParam.getString("type");
JSONObject params = requestParam.getJSONObject("params");
if (MsgTypeEnum.TASK_STATE_RPT.getValue().equals(type)) {
String taskId = params.getString("taskId");
String taskPhase = params.getString("taskPhase");
String taskState = params.getString("taskState");
String taskPoint = params.getString("taskPoint");
if (StrUtil.isNotEmpty(taskPhase)&&(TaskPhaseEnum.ENTER_REQUEST_OR_ALLOWED.getValue().equals(taskPhase)||TaskPhaseEnum.LEAVE_NOTICE_OR_ALLOWED.getValue().equals(taskPhase))){
}else if (StrUtil.isNotEmpty(taskPhase)&&(TaskPhaseEnum.PICKUP_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)||TaskPhaseEnum.PICKUP_COMPLETE.getValue().equals(taskPhase)||TaskPhaseEnum.RELEASE_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)||TaskPhaseEnum.RELEASE_COMPLETE.getValue().equals(taskPhase)||TaskStateEnum.NOT_STARTED.getValue().equals(taskPhase)||TaskStateEnum.EXECUTING.getValue().equals(taskPhase)||TaskStateEnum.COMPLETED.getValue().equals(taskPhase))){
Instruction instruction = instructionService.findByCodeFromCache(taskId);
if (ObjectUtil.isEmpty(instruction)) {
resp.put("code", "400");
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
return resp;
}
StorageCellDto storageCellDto = storageCellService.findByAddress(taskPoint);
if (ObjectUtil.isEmpty(storageCellDto)) {
resp.put("code", "400");
resp.put("message", "请求失败,点位信息不存在,点位站点号:" + taskPoint);
return resp;
}
Device device = deviceAppService.findDeviceByCode(storageCellDto.getStorage_code());
if (ObjectUtil.isEmpty(device)) {
resp.put("code", "400");
resp.put("message", "请求失败,请求位置编号不存在!");
return resp;
}
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver;
//taskPhase 任务完成
if (TaskStateEnum.COMPLETED.getValue().equals(taskPhase)){
//修改指令状态完成
instruction.setInstruction_status(InstStatusEnum.FINISHED.getCode());
instruction.setUpdate_time(DateUtil.now());
instructionService.finish(instruction);
resp.put("code", "200");
resp.put("message", "完成任务成功");
return resp;
}
if (TaskStateEnum.CANCELED.getValue().equals(taskPhase)){
instruction.setInstruction_status(InstStatusEnum.CANCELED.getCode());
instruction.setUpdate_time(DateUtil.now());
instructionService.cancel(instruction.getInstruction_id());
resp.put("code", "200");
resp.put("message", "取消任务成功");
return resp;
}
if (TaskPhaseEnum.PICKUP_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)){
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver){
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setAgvphase(1);
standardOrdinarySiteDeviceDriver.setReqTakeInstCode(taskId);
standardOrdinarySiteDeviceDriver.setReqTakeRequireSuccess(true);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
standardInspectSiteDeviceDriver.setAgvphase(1);
standardInspectSiteDeviceDriver.setReqTakeInstCode(taskId);
standardInspectSiteDeviceDriver.setReqTakeRequireSuccess(true);
}
resp.put("code", "200");
resp.put("message", "反馈请求取货成功");
return resp;
}
if (TaskPhaseEnum.PICKUP_COMPLETE.getValue().equals(taskPhase)){
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver){
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setAgvphase(2);
standardOrdinarySiteDeviceDriver.setReqTakeInstCode(taskId);
standardOrdinarySiteDeviceDriver.setReqTakeRequireSuccess(true);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
standardInspectSiteDeviceDriver.setAgvphase(2);
standardInspectSiteDeviceDriver.setReqTakeInstCode(taskId);
standardInspectSiteDeviceDriver.setReqTakeRequireSuccess(true);
}
resp.put("code", "200");
resp.put("message", "反馈取货完成成功");
return resp;
}
if (TaskPhaseEnum.RELEASE_REQUEST_OR_RESPONSE.getValue().equals(taskPhase)){
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver){
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setAgvphase(3);
standardOrdinarySiteDeviceDriver.setReqTakeInstCode(taskId);
standardOrdinarySiteDeviceDriver.setReqTakeRequireSuccess(true);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
standardInspectSiteDeviceDriver.setAgvphase(3);
standardInspectSiteDeviceDriver.setReqTakeInstCode(taskId);
standardInspectSiteDeviceDriver.setReqTakeRequireSuccess(true);
}
resp.put("code", "200");
resp.put("message", "反馈请求放货成功");
return resp;
}
if (TaskPhaseEnum.RELEASE_COMPLETE.getValue().equals(taskPhase)){
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver){
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setAgvphase(4);
standardOrdinarySiteDeviceDriver.setReqTakeInstCode(taskId);
standardOrdinarySiteDeviceDriver.setReqTakeRequireSuccess(true);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
standardInspectSiteDeviceDriver.setAgvphase(4);
standardInspectSiteDeviceDriver.setReqTakeInstCode(taskId);
standardInspectSiteDeviceDriver.setReqTakeRequireSuccess(true);
}
resp.put("code", "200");
resp.put("message", "反馈放货完成成功");
return resp;
}
if (TaskPhaseEnum.ENTER_REQUEST_OR_ALLOWED.getValue().equals(taskPhase)){
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver){
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setAgvphase(-1);
standardOrdinarySiteDeviceDriver.setReqTakeInstCode(taskId);
standardOrdinarySiteDeviceDriver.setReqTakeRequireSuccess(true);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
standardInspectSiteDeviceDriver.setAgvphase(-1);
standardInspectSiteDeviceDriver.setReqTakeInstCode(taskId);
standardInspectSiteDeviceDriver.setReqTakeRequireSuccess(true);
}
resp.put("code", "200");
resp.put("message", "反馈请求进入成功");
return resp;
}
if (TaskPhaseEnum.LEAVE_NOTICE_OR_ALLOWED.getValue().equals(taskPhase)){
if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver){
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setAgvphase(-2);
standardOrdinarySiteDeviceDriver.setReqTakeInstCode(taskId);
standardOrdinarySiteDeviceDriver.setReqTakeRequireSuccess(true);
}
if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver){
standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
standardInspectSiteDeviceDriver.setAgvphase(-2);
standardInspectSiteDeviceDriver.setReqTakeInstCode(taskId);
standardInspectSiteDeviceDriver.setReqTakeRequireSuccess(true);
}
resp.put("code", "200");
resp.put("message", "反馈请求离开成功");
return resp;
}
}else {
throw new BadRequestException("上报的阶段值有误!");
}
}else if (MsgTypeEnum.AGV_ID_RPT.getValue().equals(type)){
String taskId = params.getString("taskId");
String agvId = params.getString("agvId");
Instruction instruction = instructionService.findByCodeFromCache(taskId);
if (ObjectUtil.isEmpty(instruction)) {
resp.put("code", "400");
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
return resp;
}
//更新车号
instruction.setCarno(agvId);
instruction.setInstruction_status(InstStatusEnum.BUSY.getCode());
instruction.setUpdate_time(DateUtil.now());
instructionService.update(instruction);
resp.put("code", "200");
resp.put("message", "更新车号成功");
return resp;
}else if (MsgTypeEnum.TASK_INDEX_RPT.getValue().equals(type)){
String taskId = params.getString("taskId");
Instruction instruction = instructionService.findByCodeFromCache(taskId);
if (ObjectUtil.isEmpty(instruction)) {
resp.put("code", "400");
resp.put("message", "请求失败,任务信息不存在,指令号:" + taskId);
return resp;
}
//修改指令状态执行中
instruction.setInstruction_status(InstStatusEnum.BUSY.getCode());
instruction.setUpdate_time(DateUtil.now());
instructionService.update(instruction);
resp.put("code", "200");
resp.put("message", "更新指令执行中成功");
return resp;
}else if (MsgTypeEnum.AGV_POWER_RPT.getValue().equals(type)){
}
return null;
}
}

View File

@@ -8,14 +8,12 @@ import com.alibaba.fastjson.JSONObject;
* 任务状态
*/
public enum InstStatusEnum {
READY(1, "READY", "就绪"),
ISSUE(2, "ISSUE", "已下发"),
BUSY(3, "BUSY", "执行中"),
FINISHED(4, "FINISHED", "完成");
READY( "0", "就绪"),
BUSY( "1", "执行中"),
FINISHED( "2", "完成"),
CANCELED( "3", "取消"),;
//索引
private int index;
//编码
private String code;
//名字
@@ -24,8 +22,7 @@ public enum InstStatusEnum {
private String desc;
// 构造方法
InstStatusEnum(int index, String code, String name) {
this.index = index;
InstStatusEnum(String code, String name) {
this.code = code;
this.name = name;
@@ -74,12 +71,4 @@ public enum InstStatusEnum {
}
return null;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
}

View File

@@ -8,18 +8,18 @@ import com.alibaba.fastjson.JSONObject;
* 任务完成方式
*/
public enum TaskFinishEnum {
AUTO_FINISH(1, "AUTO_FINISH", "自动完成"),
ACS_MANDATORY_FINISH(2, "ACS_MANDATORY_FINISH", "ACS强制完成"),
WMS_MANDATORY_FINISH(3, "WMS_MANDATORY_FINISH", "WMS强制完成"),
MES_MANDATORY_FINISH(4, "MES_MANDATORY_FINISH", "MES强制完成"),
AUTO_DELETE(5, "AUTO_DELETE", "自动删除"),
ACS_MANDATORY_DELETE(6, "ACS_MANDATORY_DELETE", "ACS强制删除"),
WMS_MANDATORY_DELETE(7, "WMS_MANDATORY_DELETE", "WMS强制删除"),
MES_MANDATORY_DELETE(8, "MES_MANDATORY_DELETE", "MES强制删除"),
DEVICE_DELETE(9, "DEVICE_DELETE", "设备删除");
AUTO_FINISH("1", "AUTO_FINISH", "自动完成"),
ACS_MANDATORY_FINISH("2", "ACS_MANDATORY_FINISH", "ACS强制完成"),
WMS_MANDATORY_FINISH("3", "WMS_MANDATORY_FINISH", "WMS强制完成"),
MES_MANDATORY_FINISH("4", "MES_MANDATORY_FINISH", "MES强制完成"),
AUTO_DELETE("5", "AUTO_DELETE", "自动删除"),
ACS_MANDATORY_DELETE("6", "ACS_MANDATORY_DELETE", "ACS强制删除"),
WMS_MANDATORY_DELETE("7", "WMS_MANDATORY_DELETE", "WMS强制删除"),
MES_MANDATORY_DELETE("8", "MES_MANDATORY_DELETE", "MES强制删除"),
DEVICE_DELETE("9", "DEVICE_DELETE", "设备删除");
//索引
private int index;
private String index;
//编码
private String code;
//名字
@@ -28,7 +28,7 @@ public enum TaskFinishEnum {
private String desc;
// 构造方法
TaskFinishEnum(int index, String code, String name) {
TaskFinishEnum(String index, String code, String name) {
this.index = index;
this.code = code;
this.name = name;
@@ -79,11 +79,11 @@ public enum TaskFinishEnum {
return null;
}
public int getIndex() {
public String getIndex() {
return index;
}
public void setIndex(int index) {
public void setIndex(String index) {
this.index = index;
}
}

View File

@@ -8,13 +8,13 @@ import com.alibaba.fastjson.JSONObject;
* 任务状态
*/
public enum TaskStatusEnum {
READY(1, "READY", "就绪"),
BUSY(2, "BUSY", "执行中"),
FINISHED(3, "FINISHED", "完成");
READY("1", "READY", "就绪"),
BUSY("2", "BUSY", "执行中"),
FINISHED("3", "FINISHED", "完成");
//索引
private int index;
private String index;
//编码
private String code;
//名字
@@ -23,7 +23,7 @@ public enum TaskStatusEnum {
private String desc;
// 构造方法
TaskStatusEnum(int index, String code, String name) {
TaskStatusEnum(String index, String code, String name) {
this.index = index;
this.code = code;
this.name = name;
@@ -74,11 +74,11 @@ public enum TaskStatusEnum {
return null;
}
public int getIndex() {
public String getIndex() {
return index;
}
public void setIndex(int index) {
public void setIndex(String index) {
this.index = index;
}
}

View File

@@ -55,6 +55,21 @@ public class LuceneLogDto {
/* 请求地址 */
private String requesturl;
/**
* 请求参数
*/
private String request_param;
/**
* 响应参数
*/
private String response_param;
/**
* 请求路径
*/
private String request_url;
/* 状态码 */
private String status_code;
@@ -73,6 +88,16 @@ public class LuceneLogDto {
/* 修改时间 */
private String update_time;
/**
* 请求方向
*/
private String request_direction;
/**
* 执行时间
*/
private long executeTime;
public LuceneLogDto(final String opc_server_code, final String opc_plc_code,
final String device_code, final String to_home, final String last_home,