refactor(vendor): 移除冗余方法并统一继承EntityService

重构供应商相关服务类,移除重复的getById等方法,统一继承EntityService基类
更新文档中的服务类检查状态
This commit is contained in:
2025-12-14 16:36:11 +08:00
parent be63ff62a4
commit e8c8305f40
11 changed files with 174 additions and 293 deletions

View File

@@ -2,15 +2,14 @@ package com.ecep.contract.ds.vendor.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.model.VendorGroup;
@Repository
public interface VendorGroupRepository extends
JpaRepository<VendorGroup, Integer>, JpaSpecificationExecutor<VendorGroup> {
MyRepository<VendorGroup, Integer> {
Optional<VendorGroup> findByName(String name);

View File

@@ -2,16 +2,14 @@ package com.ecep.contract.ds.vendor.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.model.VendorGroupRequireFileType;
@Repository
public interface VendorGroupRequireFileTypeRepository extends
JpaRepository<VendorGroupRequireFileType, Integer>, JpaSpecificationExecutor<VendorGroupRequireFileType> {
MyRepository<VendorGroupRequireFileType, Integer> {
List<VendorGroupRequireFileType> findByGroupId(int groupId);
}

View File

@@ -8,36 +8,32 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import com.ecep.contract.SpringApp;
import com.ecep.contract.constant.ParamConstant;
import com.ecep.contract.service.SmbFileService;
import com.hierynomus.smbj.common.SmbPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
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.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.MyDateTimeUtils;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.constant.CompanyVendorConstant;
import com.ecep.contract.ds.other.service.SysConfService;
import com.ecep.contract.ds.vendor.repository.VendorApprovedRepository;
import com.ecep.contract.model.VendorApproved;
import com.ecep.contract.model.VendorApprovedFile;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.SmbFileService;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.FileUtils;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.VendorApprovedVo;
import com.fasterxml.jackson.databind.JsonNode;
import com.hierynomus.smbj.common.SmbPath;
@Lazy
@Service
@@ -78,11 +74,6 @@ public class VendorApprovedService extends EntityService<VendorApproved, VendorA
return repository.findById(id).map(VendorApproved::toVo).orElse(null);
}
@Override
public VendorApproved getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
protected org.springframework.data.jpa.domain.Specification<VendorApproved> buildParameterSpecification(
JsonNode paramsNode) {
@@ -108,10 +99,6 @@ public class VendorApprovedService extends EntityService<VendorApproved, VendorA
repository.delete(entity);
}
public Page<VendorApproved> findAll(Specification<VendorApproved> spec, PageRequest pageRequest) {
return repository.findAll(spec, pageRequest);
}
public boolean makePathAbsent(VendorApproved list) {
String path = list.getPath();
if (StringUtils.hasText(path)) {

View File

@@ -1,20 +1,16 @@
package com.ecep.contract.ds.vendor.service;
import com.ecep.contract.constant.ParamConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.vendor.repository.VendorClassRepository;
import com.ecep.contract.model.VendorCatalog;
@@ -48,34 +44,12 @@ public class VendorCatalogService extends EntityService<VendorCatalog, VendorCat
return new VendorCatalog();
}
@Override
public Page<VendorCatalogVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<VendorCatalog> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "name", "code", "parentId");
return findAll(spec, pageable).map(VendorCatalog::toVo);
}
@Override
public VendorCatalog getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public VendorCatalogVo findById(Integer id) {
return repository.findById(id).map(VendorCatalog::toVo).orElse(null);
}
@Override
public Page<VendorCatalog> findAll(Specification<VendorCatalog> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
protected org.springframework.data.jpa.domain.Specification<VendorCatalog> buildParameterSpecification(
JsonNode paramsNode) {

View File

@@ -8,20 +8,17 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
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.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.vendor.repository.VendorEntityRepository;
import com.ecep.contract.ds.vendor.model.Vendor;
import com.ecep.contract.ds.vendor.model.VendorEntity;
import com.ecep.contract.ds.vendor.repository.VendorEntityRepository;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.VendorEntityVo;
@@ -30,7 +27,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-vendor-entity")
public class VendorEntityService extends EntityService<VendorEntity, VendorEntityVo, Integer> implements IEntityService<VendorEntity>, QueryService<VendorEntityVo>,
public class VendorEntityService extends EntityService<VendorEntity, VendorEntityVo, Integer>
implements IEntityService<VendorEntity>, QueryService<VendorEntityVo>,
VoableService<VendorEntity, VendorEntityVo> {
@Lazy
@Autowired
@@ -46,11 +44,6 @@ public class VendorEntityService extends EntityService<VendorEntity, VendorEntit
return new VendorEntity();
}
@Override
public VendorEntity getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public VendorEntityVo findById(Integer id) {
@@ -69,13 +62,6 @@ public class VendorEntityService extends EntityService<VendorEntity, VendorEntit
}
@Override
public Specification<VendorEntity> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
}
protected Specification<VendorEntity> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
@@ -86,35 +72,14 @@ public class VendorEntityService extends EntityService<VendorEntity, VendorEntit
}
@Override
protected org.springframework.data.jpa.domain.Specification<VendorEntity> buildParameterSpecification(JsonNode paramsNode) {
protected org.springframework.data.jpa.domain.Specification<VendorEntity> buildParameterSpecification(
JsonNode paramsNode) {
org.springframework.data.jpa.domain.Specification<VendorEntity> spec = null;
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "name", "abbName", "code");
return spec;
}
@Override
public List<VendorEntity> search(String searchText) {
Specification<VendorEntity> spec = getSearchSpecification(searchText);
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
}
@Override
public Page<VendorEntity> findAll(Specification<VendorEntity> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<VendorEntityVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<VendorEntity> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// 添加额外的参数过滤s
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor");
return findAll(spec, pageable).map(VendorEntity::toVo);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code")

View File

@@ -12,11 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
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.stereotype.Service;
import com.ecep.contract.ContractPayWay;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.MyDateTimeUtils;
@@ -42,8 +41,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
public class VendorFileService
implements IEntityService<VendorFile>, QueryService<VendorFile>, VoableService<VendorFile, VendorFileVo> {
public class VendorFileService extends EntityService<VendorFile, VendorFileVo, Integer>
implements IEntityService<VendorFile>, QueryService<VendorFileVo>, VoableService<VendorFile, VendorFileVo> {
private static final Logger logger = LoggerFactory.getLogger(VendorFileService.class);
@@ -59,42 +58,8 @@ public class VendorFileService
@Autowired
private VendorFileRepository repository;
@Override
public VendorFile getById(Integer id) {
return repository.findById(id).orElse(null);
}
public VendorFile findById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Specification<VendorFile> getSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(builder.like(root.get("filePath"), "%" + searchText + "%"));
};
}
@Override
public Page<VendorFile> findAll(Specification<VendorFile> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<VendorFile> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<VendorFile> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
// 添加额外的参数过滤
if (paramsNode.has("type")) {
VendorFileType type = VendorFileType.valueOf(paramsNode.get("type").asText());
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), type));
}
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "valid");
spec = SpecificationUtils.andFieldBetweenParam(spec, paramsNode, "signDate", LocalDate.class);
spec = SpecificationUtils.andParam(spec, paramsNode, "vendor");
return findAll(spec, pageable);
public VendorFileVo findById(Integer id) {
return repository.findById(id).map(VendorFile::toVo).orElse(null);
}
public List<VendorFile> findAllByVendor(Vendor vendor) {
@@ -105,10 +70,6 @@ public class VendorFileService
return repository.findAllByVendorId(vendor.getId()).stream().map(VendorFile::toVo).toList();
}
public void delete(VendorFile file) {
repository.delete(file);
}
public void deleteById(int id) {
repository.deleteById(id);
}
@@ -117,14 +78,6 @@ public class VendorFileService
repository.saveAll(files);
}
public VendorFile save(VendorFile file) {
return repository.save(file);
}
public List<VendorFile> findAll(Specification<VendorFile> spec, Sort sort) {
return repository.findAll(spec, sort);
}
public List<VendorFile> findAllByVendorAndType(Vendor vendor, VendorFileType type) {
return repository.findAllByVendorAndType(vendor, type);
}
@@ -133,6 +86,40 @@ public class VendorFileService
return repository.findAllByVendorIdAndType(vendor.getId(), type);
}
@Override
protected VendorFileRepository getRepository() {
return repository;
}
@Override
public VendorFile createNewEntity() {
return new VendorFile();
}
@Override
protected Specification<VendorFile> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(builder.like(root.get("filePath"), "%" + searchText + "%"));
};
}
@Override
protected Specification<VendorFile> buildParameterSpecification(JsonNode node) {
Specification<VendorFile> spec = null;
if (node.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(node.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
// 添加额外的参数过滤
if (node.has("type")) {
VendorFileType type = VendorFileType.valueOf(node.get("type").asText());
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), type));
}
spec = SpecificationUtils.andFieldEqualParam(spec, node, "valid");
spec = SpecificationUtils.andFieldBetweenParam(spec, node, "signDate", LocalDate.class);
spec = SpecificationUtils.andParam(spec, node, "vendor");
return spec;
}
/**
* 验证供应商文件
*

View File

@@ -3,23 +3,21 @@ package com.ecep.contract.ds.vendor.service;
import java.util.Locale;
import java.util.Map;
import com.ecep.contract.constant.ParamConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.VendorFileType;
import com.ecep.contract.VendorType;
import com.ecep.contract.constant.ParamConstant;
import com.ecep.contract.ds.vendor.repository.VendorFileTypeLocalRepository;
import com.ecep.contract.model.VendorFileTypeLocal;
import com.ecep.contract.service.ServiceException;
@@ -35,44 +33,19 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "vendor-file-type")
public class VendorFileTypeService implements IEntityService<VendorFileTypeLocal>, QueryService<VendorFileTypeLocalVo>,
public class VendorFileTypeService extends EntityService<VendorFileTypeLocal, VendorFileTypeLocalVo, Integer>
implements IEntityService<VendorFileTypeLocal>, QueryService<VendorFileTypeLocalVo>,
VoableService<VendorFileTypeLocal, VendorFileTypeLocalVo> {
@Lazy
@Autowired
private VendorFileTypeLocalRepository repository;
@Override
public Page<VendorFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<VendorFileTypeLocal> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
if (paramsNode.has("type")) {
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"),
VendorType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value");
return findAll(spec, pageable).map(VendorFileTypeLocal::toVo);
}
@Cacheable(key = "#p0")
@Override
public VendorFileTypeLocalVo findById(Integer id) {
return repository.findById(id).map(VendorFileTypeLocal::toVo).orElse(null);
}
public VendorFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<VendorFileTypeLocal> findAll(Specification<VendorFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<VendorFileType, VendorFileTypeLocalVo> findAll(Locale locale) {
return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream()
@@ -81,20 +54,6 @@ public class VendorFileTypeService implements IEntityService<VendorFileTypeLocal
entry -> entry.getValue().toVo()));
}
@Override
public Specification<VendorFileTypeLocal> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
return
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'all-'+#p0.getLang()")
@@ -113,6 +72,40 @@ public class VendorFileTypeService implements IEntityService<VendorFileTypeLocal
return repository.save(entity);
}
@Override
protected VendorFileTypeLocalRepository getRepository() {
return repository;
}
@Override
public VendorFileTypeLocal createNewEntity() {
return new VendorFileTypeLocal();
}
@Override
protected Specification<VendorFileTypeLocal> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.like(root.get("type"), "%" + searchText + "%");
};
}
@Override
protected Specification<VendorFileTypeLocal> buildParameterSpecification(JsonNode node) {
Specification<VendorFileTypeLocal> spec = null;
if (node.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(node.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
if (node.has("type")) {
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"),
VendorType.valueOf(node.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, node, "lang", "value");
return spec;
}
@Override
public void updateByVo(VendorFileTypeLocal entity, VendorFileTypeLocalVo vo) throws ServiceException {
if (entity == null) {

View File

@@ -2,18 +2,16 @@ package com.ecep.contract.ds.vendor.service;
import java.util.List;
import com.ecep.contract.util.SpecificationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
@@ -22,6 +20,7 @@ import com.ecep.contract.model.VendorGroup;
import com.ecep.contract.model.VendorGroupRequireFileType;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.VendorGroupRequireFileTypeVo;
import com.fasterxml.jackson.databind.JsonNode;
@@ -29,55 +28,47 @@ import com.fasterxml.jackson.databind.JsonNode;
@Service
@CacheConfig(cacheNames = "vendor-group-require-file-type")
public class VendorGroupRequireFileTypeService
implements IEntityService<VendorGroupRequireFileType>, QueryService<VendorGroupRequireFileType>,
extends EntityService<VendorGroupRequireFileType, VendorGroupRequireFileTypeVo, Integer>
implements IEntityService<VendorGroupRequireFileType>, QueryService<VendorGroupRequireFileTypeVo>,
VoableService<VendorGroupRequireFileType, VendorGroupRequireFileTypeVo> {
@Lazy
@Autowired
private VendorGroupRequireFileTypeRepository repository;
@Override
public VendorGroupRequireFileType getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public VendorGroupRequireFileType findById(Integer id) {
return getById(id);
protected VendorGroupRequireFileTypeRepository getRepository() {
return repository;
}
@Override
public Page<VendorGroupRequireFileType> findAll(Specification<VendorGroupRequireFileType> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
public VendorGroupRequireFileType createNewEntity() {
return new VendorGroupRequireFileType();
}
@Override
public Page<VendorGroupRequireFileType> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<VendorGroupRequireFileType> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
spec = SpecificationUtils.andParam(spec, paramsNode, "group");
// 添加额外的参数过滤
return findAll(spec, pageable);
public VendorGroupRequireFileTypeVo findById(Integer id) {
return repository.findById(id).map(VendorGroupRequireFileType::toVo).orElse(null);
}
@Override
public Specification<VendorGroupRequireFileType> getSearchSpecification(String searchText) {
protected Specification<VendorGroupRequireFileType> buildSearchSpecification(String searchText) {
return null;
}
@Override
protected Specification<VendorGroupRequireFileType> buildParameterSpecification(JsonNode paramsNode) {
Specification<VendorGroupRequireFileType> spec = null;
spec = SpecificationUtils.andParam(spec, paramsNode, "group");
return spec;
}
@Cacheable(key = "'byGroup-'+#p0")
public List<VendorGroupRequireFileTypeVo> findByGroupId(int groupId) {
return repository.findByGroupId(groupId).stream().map(VendorGroupRequireFileType::toVo).toList();
}
// findAll
@Cacheable(key = "'all'")
public List<VendorGroupRequireFileType> findAll() {
return repository.findAll();
}
// save
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'byGroup-'+#p0.group.id"),
@@ -90,6 +81,7 @@ public class VendorGroupRequireFileTypeService
/**
* delete and evict cache
*/
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id"), @CacheEvict(key = "'byGroup-'+#p0.group.id"),
@CacheEvict(key = "'all'")
@@ -121,4 +113,5 @@ public class VendorGroupRequireFileTypeService
}
}
}
}

View File

@@ -8,12 +8,11 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.vendor.repository.VendorGroupRepository;
@@ -27,22 +26,36 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "vendor-group")
public class VendorGroupService
public class VendorGroupService extends EntityService<VendorGroup, VendorGroupVo, Integer>
implements IEntityService<VendorGroup>, QueryService<VendorGroupVo>, VoableService<VendorGroup, VendorGroupVo> {
@Lazy
@Autowired
private VendorGroupRepository vendorGroupRepository;
@Override
protected VendorGroupRepository getRepository() {
return vendorGroupRepository;
}
@Override
public VendorGroup createNewEntity() {
VendorGroup group = new VendorGroup();
group.setCode("");
group.setName("");
group.setDescription("");
group.setActive(true);
group.setPriceComparison(true);
group.setRequireQuotationSheetForBid(true);
group.setCanPrePurchase(false);
return group;
}
@Cacheable(key = "#p0")
@Override
public VendorGroupVo findById(Integer id) {
return vendorGroupRepository.findById(id).map(VendorGroup::toVo).orElse(null);
}
public VendorGroup getById(Integer id) {
return vendorGroupRepository.findById(id).orElse(null);
}
public VendorGroup findByName(String name) {
return vendorGroupRepository.findByName(name).orElse(null);
}
@@ -57,63 +70,21 @@ public class VendorGroupService
return vendorGroupRepository.findAll();
}
public Page<VendorGroup> findAll(Specification<VendorGroup> spec, Pageable pageable) {
return vendorGroupRepository.findAll(spec, pageable);
}
@Override
public Page<VendorGroupVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<VendorGroup> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// 添加额外的参数过滤
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "active", "name", "code");
return findAll(spec, pageable).map(entity -> entity.toVo());
}
@Override
public Specification<VendorGroup> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<VendorGroup> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("description"), "%" + searchText + "%")
);
builder.like(root.get("description"), "%" + searchText + "%"));
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.name"),
@CacheEvict(key = "'all'"),
})
public VendorGroup saveEntity(VendorGroup group) {
return vendorGroupRepository.save(group);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.name"),
@CacheEvict(key = "'all'"),
})
public void deleteEntity(VendorGroup entity) {
vendorGroupRepository.delete(entity);
}
public VendorGroup newInstance() {
VendorGroup group = new VendorGroup();
group.setCode("");
group.setName("");
group.setDescription("");
group.setActive(true);
group.setPriceComparison(true);
group.setRequireQuotationSheetForBid(true);
group.setCanPrePurchase(false);
return group;
@Override
protected Specification<VendorGroup> buildParameterSpecification(JsonNode paramsNode) {
Specification<VendorGroup> spec = null;
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "active", "name", "code");
return spec;
}
@Override
@@ -134,14 +105,23 @@ public class VendorGroupService
model.setCanPrePurchase(vo.isCanPrePurchase());
}
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.name"),
@CacheEvict(key = "'all'"),
})
public VendorGroup save(VendorGroup entity) {
return saveEntity(entity);
return vendorGroupRepository.save(entity);
}
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.name"),
@CacheEvict(key = "'all'"),
})
public void delete(VendorGroup entity) {
deleteEntity(entity);
vendorGroupRepository.delete(entity);
}
}

View File

@@ -77,10 +77,7 @@ public class VendorTypeService extends EntityService<VendorTypeLocal, VendorType
return repository.findById(id).map(VendorTypeLocal::toVo).orElse(null);
}
@Override
public VendorTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
public Map<VendorType, VendorTypeLocal> findAll(Locale locale) {

View File

@@ -69,6 +69,14 @@
1.5 检查`count`方法的功能实现是否与父类相同,相同则移除
1.6 检查`findAll`方法的功能实现是否与父类相同,相同则移除
1.7 检查`getById`方法的功能实现是否与父类相同,相同则移除
1.8 检查`findById`f方法的返回值类型须 Vo 类型,如未实现,则添加如下代码
```java
@Override
public VendorGroupRequireFileTypeVo findById(Integer id) {
return repository.findById(id).map(VendorGroupRequireFileType::toVo).orElse(null);
}
```
2. 缓存相关任务
2.1 确认Service类是否有 @CacheConfig 注解,没有注解,则没有应用缓存功能,跳过后续缓存检查
@@ -154,14 +162,14 @@
| ProjectService | 是 |
| ProjectTypeService | 是 |
| VendorApprovedFileService | 是 |
| VendorApprovedItemService | |
| VendorApprovedService | |
| VendorCatalogService | |
| VendorEntityService | |
| VendorFileService | |
| VendorFileTypeService | |
| VendorGroupRequireFileTypeService | |
| VendorGroupService | |
| VendorService | |
| VendorTypeService | |
| VendorApprovedItemService | |
| VendorApprovedService | |
| VendorCatalogService | |
| VendorEntityService | |
| VendorFileService | |
| VendorFileTypeService | |
| VendorGroupRequireFileTypeService | |
| VendorGroupService | |
| VendorService | |
| VendorTypeService | |