refactor(service): 调整接口泛型参数并优化缓存策略
docs(task): 更新接口泛型修改相关文档 - 重构QueryService接口,移除未使用的Specification相关方法 - InventoryCatalogService实现IEntityService和QueryService接口 - 新增delete方法实现并调整缓存配置 - 删除过时的任务文档并重新组织文档结构 - 更新ALIGNMENT、CONSENSUS等文档,添加WebSocket服务兼容性说明
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package com.ecep.contract;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
/**
|
||||
* 查询服务接口,提供通用的分页查询能力
|
||||
@@ -20,9 +19,9 @@ public interface QueryService<T> {
|
||||
*/
|
||||
Page<T> findAll(JsonNode paramsNode, Pageable pageable);
|
||||
|
||||
Specification<T> getSpecification(String searchText);
|
||||
// Specification<T> getSpecification(String searchText);
|
||||
|
||||
Page<T> findAll(Specification<T> spec, Pageable pageable);
|
||||
// Page<T> findAll(Specification<T> spec, Pageable pageable);
|
||||
|
||||
default long count(JsonNode paramsNode) {
|
||||
return 0;
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.QueryService;
|
||||
import com.ecep.contract.ds.other.repository.InventoryCatalogRepository;
|
||||
import com.ecep.contract.model.InventoryCatalog;
|
||||
@@ -22,7 +23,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
@Lazy
|
||||
@Service
|
||||
@CacheConfig(cacheNames = "inventory-catalog")
|
||||
public class InventoryCatalogService implements QueryService<InventoryCatalog> {
|
||||
public class InventoryCatalogService implements IEntityService<InventoryCatalog>, QueryService<InventoryCatalog> {
|
||||
@Lazy
|
||||
@Autowired
|
||||
private InventoryCatalogRepository repository;
|
||||
@@ -69,6 +70,14 @@ public class InventoryCatalogService implements QueryService<InventoryCatalog> {
|
||||
};
|
||||
}
|
||||
|
||||
public List<InventoryCatalog> search(String searchText) {
|
||||
Specification<InventoryCatalog> spec = (root, query, builder) -> {
|
||||
return builder.or(builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
@@ -78,11 +87,13 @@ public class InventoryCatalogService implements QueryService<InventoryCatalog> {
|
||||
return repository.save(entity);
|
||||
}
|
||||
|
||||
public List<InventoryCatalog> search(String searchText) {
|
||||
Specification<InventoryCatalog> spec = (root, query, builder) -> {
|
||||
return builder.or(builder.like(root.get("code"), "%" + searchText + "%"),
|
||||
builder.like(root.get("name"), "%" + searchText + "%"));
|
||||
};
|
||||
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
@Caching(evict = {
|
||||
@CacheEvict(key = "#p0.id"),
|
||||
@CacheEvict(key = "'code-'+#p0.code"),
|
||||
@CacheEvict(key = "'name-'+#p0.code")
|
||||
})
|
||||
@Override
|
||||
public void delete(InventoryCatalog entity) {
|
||||
repository.delete(entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user