refactor: 重构WebSocket服务及相关实体类
重构WebSocket服务名称从WebSocketService改为WebSocketClientService,并实现Serializable接口 添加WebSocket常量定义和消息处理实现 优化实体类equals和hashCode方法 修复控制器路径和日志配置 添加查询服务和任务接口方法
This commit is contained in:
@@ -1,4 +1,68 @@
|
||||
package com.ecep.contract;
|
||||
|
||||
public class EntityService {
|
||||
import com.ecep.contract.ds.MyRepository;
|
||||
import com.ecep.contract.model.Contract;
|
||||
import com.ecep.contract.util.SpecificationUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class EntityService<T, ID> {
|
||||
|
||||
protected abstract MyRepository<T, ID> getRepository();
|
||||
|
||||
public abstract T createNewEntity();
|
||||
|
||||
|
||||
public long count() {
|
||||
return getRepository().count();
|
||||
}
|
||||
|
||||
public long count(Specification<T> spec) {
|
||||
return getRepository().count(spec);
|
||||
}
|
||||
|
||||
public long count(JsonNode paramsNode) {
|
||||
return getRepository().count(buildParameterSpecification(paramsNode));
|
||||
}
|
||||
|
||||
protected abstract Specification<T> buildParameterSpecification(JsonNode paramsNode);
|
||||
|
||||
public Page<T> findAll(JsonNode paramsNode, Pageable pageable) {
|
||||
Specification<T> spec = null;
|
||||
if (paramsNode.has("searchText")) {
|
||||
spec = getSpecification(paramsNode.get("searchText").asText());
|
||||
}
|
||||
spec = SpecificationUtils.and(spec, buildParameterSpecification(paramsNode));
|
||||
return findAll(spec, pageable);
|
||||
}
|
||||
|
||||
|
||||
public Page<T> findAll(Specification<T> spec, Pageable pageable) {
|
||||
return getRepository().findAll(spec, pageable);
|
||||
}
|
||||
|
||||
public List<T> findAll(Specification<T> spec, Sort sort) {
|
||||
return getRepository().findAll(spec, sort);
|
||||
}
|
||||
|
||||
protected abstract Specification<T> buildSearchSpecification(String searchText);
|
||||
|
||||
public Specification<T> getSpecification(String searchText) {
|
||||
if (!StringUtils.hasText(searchText)) {
|
||||
return null;
|
||||
}
|
||||
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
|
||||
}
|
||||
|
||||
public List<T> search(String searchText) {
|
||||
Specification<T> spec = getSpecification(searchText);
|
||||
return getRepository().findAll(spec, Pageable.ofSize(10)).getContent();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user