refactor(service): 统一Service缓存为VO对象并优化关联实体处理

重构Service类实现,将QueryService泛型参数调整为VO类型,确保缓存VO对象而非实体。优化关联实体处理逻辑,减少重复代码。修改findById方法返回VO对象,新增getById方法获取实体。更新相关调用点以适配新接口。

调整WebSocket处理、控制器及Service实现,确保数据类型一致性。完善文档记录重构过程及发现的问题。为后续优化提供基础架构支持。
This commit is contained in:
2025-09-29 19:31:51 +08:00
parent 64471b46f8
commit 49413ad473
167 changed files with 6840 additions and 1811 deletions

View File

@@ -2,6 +2,7 @@ package com.ecep.contract;
import java.util.List;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -10,13 +11,25 @@ import org.springframework.util.StringUtils;
import com.ecep.contract.constant.ServiceConstant;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.model.Voable;
import com.ecep.contract.util.SpecificationUtils;
import com.fasterxml.jackson.databind.JsonNode;
public abstract class EntityService<T, ID> {
/**
* 实体服务基类
*
* @param <T> 实体类型
* @param <VO> VO类型
* @param <ID> 主键类型
*/
public abstract class EntityService<T extends Voable<VO>, VO, ID> {
protected abstract MyRepository<T, ID> getRepository();
public T getById(ID id) {
return getRepository().findById(id).orElse(null);
}
public abstract T createNewEntity();
public long count() {
@@ -33,13 +46,13 @@ public abstract class EntityService<T, ID> {
protected abstract Specification<T> buildParameterSpecification(JsonNode paramsNode);
public Page<T> findAll(JsonNode paramsNode, Pageable pageable) {
public Page<VO> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<T> spec = null;
if (paramsNode.has(ServiceConstant.KEY_SEARCH_TEXT)) {
spec = getSpecification(paramsNode.get(ServiceConstant.KEY_SEARCH_TEXT).asText());
}
spec = SpecificationUtils.and(spec, buildParameterSpecification(paramsNode));
return findAll(spec, pageable);
return findAll(spec, pageable).map(T::toVo);
}
public Page<T> findAll(Specification<T> spec, Pageable pageable) {