fix:框架
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
package cn.code.nl.framework.execute.biz;
|
package cn.code.nl.framework.execute.biz;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @Author: liyongde
|
* @Author: liyongde
|
||||||
* @Date: 2026/7/15 14:54
|
* @Date: 2026/7/15 14:54
|
||||||
*/
|
*/
|
||||||
public interface TaskCommonApi {
|
public interface TaskCommonApi {
|
||||||
|
|
||||||
|
@PostMapping("/do-handle-picked")
|
||||||
void doHandlePicked();
|
void doHandlePicked();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.code.nl.framework.common.enums.RpcConstants;
|
|||||||
import cn.code.nl.framework.execute.biz.TaskCommonApi;
|
import cn.code.nl.framework.execute.biz.TaskCommonApi;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lms通用API
|
* lms通用API
|
||||||
@@ -11,6 +12,7 @@ import org.springframework.cloud.openfeign.FeignClient;
|
|||||||
* @Date: 2026/7/15 14:39
|
* @Date: 2026/7/15 14:39
|
||||||
*/
|
*/
|
||||||
@FeignClient(name = RpcConstants.LMS_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
@FeignClient(name = RpcConstants.LMS_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
||||||
|
@RequestMapping("/lms")
|
||||||
@Tag(name = "RPC 服务 - lms任务")
|
@Tag(name = "RPC 服务 - lms任务")
|
||||||
public interface LmsTaskCommonApi extends TaskCommonApi {
|
public interface LmsTaskCommonApi extends TaskCommonApi {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.code.nl.framework.common.enums.RpcConstants;
|
|||||||
import cn.code.nl.framework.execute.biz.TaskCommonApi;
|
import cn.code.nl.framework.execute.biz.TaskCommonApi;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -11,6 +12,7 @@ import org.springframework.cloud.openfeign.FeignClient;
|
|||||||
* @Date: 2026/7/15 14:48
|
* @Date: 2026/7/15 14:48
|
||||||
*/
|
*/
|
||||||
@FeignClient(name = RpcConstants.WMS_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
@FeignClient(name = RpcConstants.WMS_NAME, primary = false) // TODO 芋艿:fallbackFactory =
|
||||||
|
@RequestMapping("/wms")
|
||||||
@Tag(name = "RPC 服务 - wms任务")
|
@Tag(name = "RPC 服务 - wms任务")
|
||||||
public interface WmsTaskCommonApi extends TaskCommonApi {
|
public interface WmsTaskCommonApi extends TaskCommonApi {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package cn.code.nl.framework.execute.core;
|
||||||
|
|
||||||
|
import cn.code.nl.framework.common.enums.RpcConstants;
|
||||||
|
import cn.code.nl.framework.common.exception.ServiceException;
|
||||||
|
import cn.code.nl.framework.execute.biz.TaskCommonApi;
|
||||||
|
import cn.code.nl.framework.execute.biz.lms.LmsTaskCommonApi;
|
||||||
|
import cn.code.nl.framework.execute.biz.wms.WmsTaskCommonApi;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo: (临时使用)
|
||||||
|
* 任务通用 API 工厂
|
||||||
|
* 根据 RPC 服务名获取对应的 {@link TaskCommonApi} 实现
|
||||||
|
* 如果还有其他创建任务的服务,就添加,例如MES
|
||||||
|
* @Author: liyongde
|
||||||
|
* @Date: 2026/7/15
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TaskCommonApiFactory {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LmsTaskCommonApi lmsTaskCommonApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private WmsTaskCommonApi wmsTaskCommonApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务名 → API 实现映射
|
||||||
|
*/
|
||||||
|
private final Map<String, TaskCommonApi> apiMap = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化映射关系
|
||||||
|
*/
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
apiMap.put(RpcConstants.LMS_NAME, lmsTaskCommonApi);
|
||||||
|
apiMap.put(RpcConstants.WMS_NAME, wmsTaskCommonApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据 RPC 服务名获取对应的 TaskCommonApi
|
||||||
|
*
|
||||||
|
* @param serverName RPC 服务名,如 "lms-server"、"wms-server"
|
||||||
|
* @return 对应的 TaskCommonApi 实现
|
||||||
|
*/
|
||||||
|
public TaskCommonApi getByServerName(String serverName) {
|
||||||
|
TaskCommonApi api = apiMap.get(serverName);
|
||||||
|
if (api == null) {
|
||||||
|
throw new ServiceException(500, "未找到对应的任务 API:" + serverName);
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package cn.code.nl.framework.execute.core;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @Author: liyongde
|
||||||
|
* @Date: 2026/7/15 15:32
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class TaskFactory implements BeanPostProcessor {
|
||||||
|
private final Map<String, AbstractTask> taskMap;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public TaskFactory() {
|
||||||
|
taskMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||||
|
if (bean instanceof AbstractTask) {
|
||||||
|
taskMap.put(beanName, (AbstractTask) bean);
|
||||||
|
}
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractTask getTask(String taskType) {
|
||||||
|
if (taskType == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return taskMap.get(taskType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package cn.code.nl.module.lms;
|
||||||
|
|
||||||
|
import cn.code.nl.framework.execute.biz.lms.LmsTaskCommonApi;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @Author: liyongde
|
||||||
|
* @Date: 2026/7/15 15:25
|
||||||
|
*/
|
||||||
|
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||||
|
@Validated
|
||||||
|
public class DemoApi implements LmsTaskCommonApi {
|
||||||
|
@Override
|
||||||
|
public void doHandlePicked() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package cn.code.nl.module.task.framework.rpc.config;
|
package cn.code.nl.module.task.framework.rpc.config;
|
||||||
|
|
||||||
|
import cn.code.nl.framework.execute.biz.lms.LmsTaskCommonApi;
|
||||||
|
import cn.code.nl.framework.execute.biz.wms.WmsTaskCommonApi;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -7,6 +9,6 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
* Task 服务 RPC 配置
|
* Task 服务 RPC 配置
|
||||||
*/
|
*/
|
||||||
@Configuration(value = "taskRpcConfiguration", proxyBeanMethods = false)
|
@Configuration(value = "taskRpcConfiguration", proxyBeanMethods = false)
|
||||||
@EnableFeignClients()
|
@EnableFeignClients(clients = {LmsTaskCommonApi.class, WmsTaskCommonApi.class})
|
||||||
public class RpcConfiguration {
|
public class RpcConfiguration {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package cn.code.nl.module.task.service.transporttask;
|
package cn.code.nl.module.task.service.transporttask;
|
||||||
|
|
||||||
|
import cn.code.nl.framework.execute.biz.TaskCommonApi;
|
||||||
|
import cn.code.nl.framework.execute.core.TaskCommonApiFactory;
|
||||||
import cn.code.nl.module.task.client.TransportTaskStatusClient;
|
import cn.code.nl.module.task.client.TransportTaskStatusClient;
|
||||||
import cn.code.nl.module.task.dal.dataobject.transporttask.TransportTaskDO;
|
import cn.code.nl.module.task.dal.dataobject.transporttask.TransportTaskDO;
|
||||||
import cn.code.nl.module.task.dal.mysql.transporttask.TransportTaskMapper;
|
import cn.code.nl.module.task.dal.mysql.transporttask.TransportTaskMapper;
|
||||||
import cn.code.nl.module.task.dto.AcsFeedbackReqDTO;
|
import cn.code.nl.module.task.dto.AcsFeedbackReqDTO;
|
||||||
import cn.code.nl.module.task.mq.message.TaskEventMessage;
|
import cn.code.nl.module.task.mq.message.TaskEventMessage;
|
||||||
import cn.code.nl.module.task.dto.TaskStatusCallbackReqDTO;
|
import cn.code.nl.module.task.dto.TaskStatusCallbackReqDTO;
|
||||||
import cn.code.nl.module.task.dto.TaskStatusCallbackRespDTO;
|
|
||||||
import cn.code.nl.module.task.enums.CallbackStatusEnum;
|
import cn.code.nl.module.task.enums.CallbackStatusEnum;
|
||||||
import cn.code.nl.module.task.enums.TaskEventTypeEnum;
|
import cn.code.nl.module.task.enums.TaskEventTypeEnum;
|
||||||
import cn.code.nl.module.task.enums.TransportTaskStatusEnum;
|
import cn.code.nl.module.task.enums.TransportTaskStatusEnum;
|
||||||
@@ -42,6 +43,9 @@ public class TransportTaskFeedbackServiceImpl implements TransportTaskFeedbackSe
|
|||||||
@Resource
|
@Resource
|
||||||
private TaskEventProducer taskEventProducer;
|
private TaskEventProducer taskEventProducer;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TaskCommonApiFactory taskCommonApiFactory;
|
||||||
|
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -118,21 +122,26 @@ public class TransportTaskFeedbackServiceImpl implements TransportTaskFeedbackSe
|
|||||||
transportTaskMapper.updateById(task);
|
transportTaskMapper.updateById(task);
|
||||||
log.info("任务已取货, taskId={}", task.getTaskId());
|
log.info("任务已取货, taskId={}", task.getTaskId());
|
||||||
|
|
||||||
|
// 考虑可行性
|
||||||
|
TaskCommonApi byServerName = taskCommonApiFactory.getByServerName("lms-server");
|
||||||
|
byServerName.doHandlePicked();
|
||||||
|
|
||||||
|
|
||||||
// todo: 改成 feign 的 rpc 调用
|
// todo: 改成 feign 的 rpc 调用
|
||||||
// 同步 HTTP 回调 LMS/WMS
|
// 同步 HTTP 回调 LMS/WMS
|
||||||
TaskStatusCallbackReqDTO callbackReq = buildCallbackReq(task, reqDTO);
|
// TaskStatusCallbackReqDTO callbackReq = buildCallbackReq(task, reqDTO);
|
||||||
TaskStatusCallbackRespDTO resp = transportTaskStatusClient.notifyStatus(callbackReq);
|
// TaskStatusCallbackRespDTO resp = transportTaskStatusClient.notifyStatus(callbackReq);
|
||||||
|
//
|
||||||
if (resp != null && Boolean.TRUE.equals(resp.getSuccess())) {
|
// if (resp != null && Boolean.TRUE.equals(resp.getSuccess())) {
|
||||||
log.info("取货完成同步回调成功, taskId={}", task.getTaskId());
|
// log.info("取货完成同步回调成功, taskId={}", task.getTaskId());
|
||||||
} else {
|
// } else {
|
||||||
// 回调失败:记录但不阻塞 ACS 返回
|
// // 回调失败:记录但不阻塞 ACS 返回
|
||||||
task.setCallbackStatus(CallbackStatusEnum.FAILED.getCode());
|
// task.setCallbackStatus(CallbackStatusEnum.FAILED.getCode());
|
||||||
task.setCallbackErrorMsg(resp != null ? resp.getMessage() : "回调无响应");
|
// task.setCallbackErrorMsg(resp != null ? resp.getMessage() : "回调无响应");
|
||||||
transportTaskMapper.updateById(task);
|
// transportTaskMapper.updateById(task);
|
||||||
log.warn("取货完成同步回调失败, taskId={}, msg={}",
|
// log.warn("取货完成同步回调失败, taskId={}, msg={}",
|
||||||
task.getTaskId(), task.getCallbackErrorMsg());
|
// task.getTaskId(), task.getCallbackErrorMsg());
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user