fix:框架

This commit is contained in:
2026-07-15 15:45:32 +08:00
parent 90c4a9e8e9
commit 2b7ddc2313
8 changed files with 151 additions and 15 deletions

View File

@@ -1,10 +1,14 @@
package cn.code.nl.framework.execute.biz;
import org.springframework.web.bind.annotation.PostMapping;
/**
*
* @Author: liyongde
* @Date: 2026/7/15 14:54
*/
public interface TaskCommonApi {
@PostMapping("/do-handle-picked")
void doHandlePicked();
}

View File

@@ -4,6 +4,7 @@ import cn.code.nl.framework.common.enums.RpcConstants;
import cn.code.nl.framework.execute.biz.TaskCommonApi;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* lms通用API
@@ -11,6 +12,7 @@ import org.springframework.cloud.openfeign.FeignClient;
* @Date: 2026/7/15 14:39
*/
@FeignClient(name = RpcConstants.LMS_NAME, primary = false) // TODO 芋艿fallbackFactory =
@RequestMapping("/lms")
@Tag(name = "RPC 服务 - lms任务")
public interface LmsTaskCommonApi extends TaskCommonApi {
}

View File

@@ -4,6 +4,7 @@ import cn.code.nl.framework.common.enums.RpcConstants;
import cn.code.nl.framework.execute.biz.TaskCommonApi;
import io.swagger.v3.oas.annotations.tags.Tag;
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
*/
@FeignClient(name = RpcConstants.WMS_NAME, primary = false) // TODO 芋艿fallbackFactory =
@RequestMapping("/wms")
@Tag(name = "RPC 服务 - wms任务")
public interface WmsTaskCommonApi extends TaskCommonApi {
}

View File

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

View File

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