refactor(util): 重构BeanContext接口及相关实现

将ContextUtils重命名为BeanContext,并统一客户端和服务端的实现
添加DefaultBeanContext作为默认实现
优化Inventory同步任务逻辑,支持WebSocket远程调用
更新tasker_mapper.json添加新的任务映射
移除未使用的syncInventory方法
This commit is contained in:
2025-10-12 22:39:32 +08:00
parent 59d78619da
commit 5b3ab3ed00
17 changed files with 360 additions and 129 deletions

View File

@@ -16,11 +16,13 @@ import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.other.service.SysConfService;
import com.ecep.contract.model.Employee;
import com.ecep.contract.util.BeanContext;
import com.ecep.contract.util.DefaultBeanContext;
import lombok.Getter;
import lombok.Setter;
public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
public abstract class Tasker<T> implements java.util.concurrent.Callable<T>, BeanContext {
private static final Logger logger = LoggerFactory.getLogger(Tasker.class);
@Setter
protected java.util.function.Predicate<Message> messageHandler;
@@ -33,13 +35,16 @@ public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
@Getter
@Setter
private Locale locale = Locale.getDefault();
private HashMap<Class<?>, Object> cachedMap = new HashMap<>();
private BeanContext beanContext;
@Setter
private Employee currentUser;
@Setter
@Getter
private boolean cancelled = false;
public Tasker() {
beanContext = new DefaultBeanContext();
}
public SysConfService getConfService() {
return getCachedBean(SysConfService.class);
@@ -53,18 +58,12 @@ public abstract class Tasker<T> implements java.util.concurrent.Callable<T> {
return getCachedBean(EmployeeService.class);
}
protected <K> K getBean(Class<K> requiredType) throws BeansException {
return SpringApp.getBean(requiredType);
public <K> K getBean(Class<K> requiredType) throws BeansException {
return beanContext.getBean(requiredType);
}
protected <K> K getCachedBean(Class<K> requiredType) {
@SuppressWarnings("unchecked")
K bean = (K) cachedMap.get(requiredType);
if (bean == null) {
bean = getBean(requiredType);
cachedMap.put(requiredType, bean);
}
return bean;
public <K> K getCachedBean(Class<K> requiredType) {
return beanContext.getCachedBean(requiredType);
}
public Employee getCurrentUser() {