refactor(service): 重构服务类继承EntityService基类

重构多个服务类使其继承EntityService基类,统一实现通用CRUD操作
移除重复代码,提取公共逻辑到基类中
更新缓存注解和查询规范实现
添加必要的重写方法如getRepository和createNewEntity
This commit is contained in:
2025-12-13 20:32:06 +08:00
parent 9dc90507cb
commit 6eebdb1744
27 changed files with 631 additions and 630 deletions

View File

@@ -1,21 +1,14 @@
package com.ecep.contract.ds.company.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.ds.company.model.CompanyInvoiceInfo;
/**
* 公司发票信息 Repository
*/
@Repository
public interface CompanyInvoiceInfoRepository extends
// JDBC interfaces
CrudRepository<CompanyInvoiceInfo, Integer>, PagingAndSortingRepository<CompanyInvoiceInfo, Integer>,
// JPA interfaces
JpaRepository<CompanyInvoiceInfo, Integer>, JpaSpecificationExecutor<CompanyInvoiceInfo> {
public interface CompanyInvoiceInfoRepository extends MyRepository<CompanyInvoiceInfo, Integer> {
}

View File

@@ -2,22 +2,15 @@ package com.ecep.contract.ds.company.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.ds.company.model.CompanyOldName;
@Repository
public interface CompanyOldNameRepository extends
// JDBC interfaces
CrudRepository<CompanyOldName, Integer>, PagingAndSortingRepository<CompanyOldName, Integer>,
// JPA interfaces
JpaRepository<CompanyOldName, Integer>, JpaSpecificationExecutor<CompanyOldName> {
public interface CompanyOldNameRepository extends MyRepository<CompanyOldName, Integer> {
List<CompanyOldName> findAllByCompanyId(Integer companyId);

View File

@@ -5,31 +5,28 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.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 org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.util.StringUtils;
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.company.repository.CompanyBlackReasonRepository;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.company.model.CompanyBlackReason;
import com.ecep.contract.ds.company.repository.CompanyBlackReasonRepository;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyBlackReasonVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-black-reason")
public class CompanyBlackReasonService
public class CompanyBlackReasonService extends EntityService<CompanyBlackReason, CompanyBlackReasonVo, Integer>
implements IEntityService<CompanyBlackReason>, QueryService<CompanyBlackReasonVo>,
VoableService<CompanyBlackReason, CompanyBlackReasonVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyContactService.class);
@@ -37,16 +34,28 @@ public class CompanyBlackReasonService
@Autowired
private CompanyBlackReasonRepository repository;
@Override
protected CompanyBlackReasonRepository getRepository() {
return repository;
}
@Override
public CompanyBlackReason createNewEntity() {
return new CompanyBlackReason();
}
@Cacheable(key = "#p0")
public CompanyBlackReasonVo findById(Integer id) {
return repository.findById(id).map(CompanyBlackReason::toVo).orElse(null);
}
@Override
public Specification<CompanyBlackReason> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<CompanyBlackReason> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
@Override
protected Specification<CompanyBlackReason> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("applyName"), "%" + searchText + "%"),
@@ -55,41 +64,20 @@ public class CompanyBlackReasonService
};
}
@CacheEvict(key = "#p0.id")
@Override
public Page<CompanyBlackReason> findAll(Specification<CompanyBlackReason> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public CompanyBlackReason getById(Integer id) {
return repository.findById(id).orElse(null);
}
public void delete(CompanyBlackReason entity) {
repository.delete(entity);
}
public List<CompanyBlackReason> findAll(Specification<CompanyBlackReason> spec, Sort by) {
return repository.findAll(spec, by);
}
public List<CompanyBlackReason> findAllByCompany(Company company) {
return repository.findAllByCompany(company);
}
public CompanyBlackReason save(CompanyBlackReason companyBlackReason) {
return repository.save(companyBlackReason);
}
@CacheEvict(key = "#p0.id")
@Override
public Page<CompanyBlackReasonVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyBlackReason> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable).map(CompanyBlackReason::toVo);
public void delete(CompanyBlackReason entity) {
repository.delete(entity);
}
public List<CompanyBlackReason> findAllByCompany(Company company) {
return repository.findAllByCompany(company);
}
@Override

View File

@@ -2,25 +2,23 @@ package com.ecep.contract.ds.company.service;
import java.util.List;
import com.ecep.contract.MessageHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
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 org.springframework.util.StringUtils;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.company.repository.CompanyContactRepository;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.company.model.CompanyContact;
import com.ecep.contract.ds.company.repository.CompanyContactRepository;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.MyStringUtils;
@@ -35,7 +33,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-contact")
public class CompanyContactService implements IEntityService<CompanyContact>, QueryService<CompanyContactVo>,
public class CompanyContactService extends EntityService<CompanyContact, CompanyContactVo, Integer>
implements IEntityService<CompanyContact>, QueryService<CompanyContactVo>,
VoableService<CompanyContact, CompanyContactVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyContactService.class);
@@ -43,10 +42,11 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
private CompanyContactRepository repository;
@Override
public CompanyContact getById(Integer id) {
return repository.findById(id).orElse(null);
protected CompanyContactRepository getRepository() {
return repository;
}
@CacheEvict(key = "#p0.id")
@Override
public CompanyContact save(CompanyContact contact) {
return repository.save(contact);
@@ -76,6 +76,7 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
}
}
@CacheEvict(key = "#p0.id")
@Override
public void delete(CompanyContact entity) {
repository.delete(entity);
@@ -95,10 +96,7 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
}
@Override
public Specification<CompanyContact> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<CompanyContact> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
@@ -110,8 +108,15 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
}
@Override
public Page<CompanyContact> findAll(Specification<CompanyContact> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
protected Specification<CompanyContact> buildParameterSpecification(JsonNode paramsNode) {
Specification<CompanyContact> spec = null;
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return spec;
}
@Override
public CompanyContact createNewEntity() {
return new CompanyContact();
}
public List<CompanyContact> searchByCompany(Company company, String userText) {
@@ -121,25 +126,10 @@ public class CompanyContactService implements IEntityService<CompanyContact>, Qu
return repository.findAll(spec);
}
public List<CompanyContact> findAll(Specification<CompanyContact> spec, Sort sort) {
return repository.findAll(spec, sort);
}
public List<CompanyContact> findAllByCompanyAndName(Company company, String contactName) {
return repository.findAllByCompanyAndName(company, contactName);
}
@Override
public Page<CompanyContactVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyContact> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable).map(CompanyContact::toVo);
}
@Override
public void updateByVo(CompanyContact model, CompanyContactVo vo) {
if (model == null) {

View File

@@ -2,9 +2,6 @@ package com.ecep.contract.ds.company.service;
import java.util.List;
import com.ecep.contract.SpringApp;
import com.ecep.contract.constant.ParamConstant;
import com.ecep.contract.vo.CompanyVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,20 +12,21 @@ 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.domain.Sort;
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.company.repository.CompanyExtendInfoRepository;
import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.company.model.CompanyExtendInfo;
import com.ecep.contract.ds.company.repository.CompanyExtendInfoRepository;
import com.ecep.contract.service.ServiceException;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyExtendInfoVo;
import com.ecep.contract.vo.CompanyVo;
import com.fasterxml.jackson.databind.JsonNode;
/**
@@ -37,25 +35,33 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-extend-info")
public class CompanyExtendInfoService implements IEntityService<CompanyExtendInfo>, QueryService<CompanyExtendInfoVo>, VoableService<CompanyExtendInfo, CompanyExtendInfoVo> {
public class CompanyExtendInfoService extends EntityService<CompanyExtendInfo, CompanyExtendInfoVo, Integer>
implements IEntityService<CompanyExtendInfo>, QueryService<CompanyExtendInfoVo>,
VoableService<CompanyExtendInfo, CompanyExtendInfoVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyExtendInfoService.class);
@Autowired
private CompanyExtendInfoRepository repository;
@Override
protected CompanyExtendInfoRepository getRepository() {
return repository;
}
@Cacheable(key = "#p0")
@Override
public CompanyExtendInfoVo findById(Integer id) {
return repository.findById(id).map(CompanyExtendInfo::toVo).orElse(null);
}
public List<CompanyExtendInfo> findAll(Specification<CompanyExtendInfo> spec, Sort sort) {
return repository.findAll(spec, sort);
@Override
protected Specification<CompanyExtendInfo> buildParameterSpecification(JsonNode paramsNode) {
Specification<CompanyExtendInfo> spec = null;
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return spec;
}
public Specification<CompanyExtendInfo> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
@Override
protected Specification<CompanyExtendInfo> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("businessScope"), "%" + searchText + "%"),
@@ -64,21 +70,12 @@ public class CompanyExtendInfoService implements IEntityService<CompanyExtendInf
};
}
public Page<CompanyExtendInfo> findAll(Specification<CompanyExtendInfo> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
@Override
public CompanyExtendInfo createNewEntity() {
return new CompanyExtendInfo();
}
@Override
public Page<CompanyExtendInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyExtendInfo> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable).map(CompanyExtendInfo::toVo);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'byCompany-'+#p0.company.id")
@@ -144,8 +141,5 @@ public class CompanyExtendInfoService implements IEntityService<CompanyExtendInf
model.setDisableVerify(vo.isDisableVerify());
}
@Override
public CompanyExtendInfo getById(Integer id) {
return repository.findById(id).orElse(null);
}
}

View File

@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.CompanyFileType;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.MessageHolder;
import com.ecep.contract.MyDateTimeUtils;
@@ -52,7 +53,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-file")
public class CompanyFileService
public class CompanyFileService extends EntityService<CompanyFile, CompanyFileVo, Integer>
implements IEntityService<CompanyFile>, QueryService<CompanyFileVo>, VoableService<CompanyFile, CompanyFileVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyFileService.class);
@@ -60,11 +61,12 @@ public class CompanyFileService
@Autowired
private CompanyFileRepository repository;
public CompanyFileService() {
@Override
protected CompanyFileRepository getRepository() {
return repository;
}
public CompanyFile getById(Integer id) {
return repository.findById(id).orElse(null);
public CompanyFileService() {
}
@Cacheable(key = "#p0")
@@ -202,9 +204,15 @@ public class CompanyFileService
* @param companyFile 企业文件
* @return 保存后的企业文件
*/
@Override
public CompanyFile createNewEntity() {
return new CompanyFile();
}
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
@Override
public CompanyFile save(CompanyFile companyFile) {
return repository.save(companyFile);
}
@@ -219,6 +227,7 @@ public class CompanyFileService
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
@Override
public void delete(CompanyFile file) {
repository.delete(file);
}

View File

@@ -1,37 +1,34 @@
package com.ecep.contract.ds.company.service;
import com.ecep.contract.CompanyFileType;
import com.ecep.contract.constant.ParamConstant;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
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.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.company.repository.CompanyFileTypeLocalRepository;
import com.ecep.contract.model.CompanyFileTypeLocal;
import com.ecep.contract.vo.CompanyFileTypeLocalVo;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.annotation.Resource;
import org.springframework.util.StringUtils;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
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.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import com.ecep.contract.CompanyFileType;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.company.repository.CompanyFileTypeLocalRepository;
import com.ecep.contract.model.CompanyFileTypeLocal;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.CompanyFileTypeLocalVo;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.annotation.Resource;
@Lazy
@Service
@CacheConfig(cacheNames = "company-file-type")
public class CompanyFileTypeService
public class CompanyFileTypeService extends EntityService<CompanyFileTypeLocal, CompanyFileTypeLocalVo, Integer>
implements IEntityService<CompanyFileTypeLocal>, QueryService<CompanyFileTypeLocalVo>,
VoableService<CompanyFileTypeLocal, CompanyFileTypeLocalVo> {
@@ -39,8 +36,13 @@ public class CompanyFileTypeService
private CompanyFileTypeLocalRepository repository;
@Override
public CompanyFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
protected CompanyFileTypeLocalRepository getRepository() {
return repository;
}
@Override
public CompanyFileTypeLocal createNewEntity() {
return new CompanyFileTypeLocal();
}
@Cacheable(key = "#id")
@@ -51,18 +53,13 @@ public class CompanyFileTypeService
}
@Override
public Page<CompanyFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
protected Specification<CompanyFileTypeLocal> buildParameterSpecification(JsonNode paramsNode) {
Specification<CompanyFileTypeLocal> 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"),
CompanyFileType.valueOf(paramsNode.get("type").asText())));
}
// field
return findAll(spec, pageable).map(CompanyFileTypeLocal::toVo);
return spec;
}
@Cacheable(key = "'all-'+#locale.toLanguageTag()")
@@ -74,21 +71,9 @@ public class CompanyFileTypeService
}
@Override
public Page<CompanyFileTypeLocal> findAll(Specification<CompanyFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Specification<CompanyFileTypeLocal> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<CompanyFileTypeLocal> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return
// builder.or(
builder.like(root.get("type"), "%" + searchText + "%")
// )
;
return builder.like(root.get("type"), "%" + searchText + "%");
};
}
@@ -98,7 +83,7 @@ public class CompanyFileTypeService
})
@Override
public void delete(CompanyFileTypeLocal entity) {
repository.delete(entity);
super.delete(entity);
}
@Caching(evict = {
@@ -107,7 +92,7 @@ public class CompanyFileTypeService
})
@Override
public CompanyFileTypeLocal save(CompanyFileTypeLocal entity) {
return repository.save(entity);
return super.save(entity);
}
@Override

View File

@@ -16,6 +16,7 @@ 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.company.repository.CompanyInvoiceInfoRepository;
@@ -33,12 +34,24 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-invoice-info")
public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceInfo>, QueryService<CompanyInvoiceInfoVo>, VoableService<CompanyInvoiceInfo, CompanyInvoiceInfoVo> {
public class CompanyInvoiceInfoService extends EntityService<CompanyInvoiceInfo, CompanyInvoiceInfoVo, Integer>
implements IEntityService<CompanyInvoiceInfo>, QueryService<CompanyInvoiceInfoVo>,
VoableService<CompanyInvoiceInfo, CompanyInvoiceInfoVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyInvoiceInfoService.class);
@Lazy
@Autowired
private CompanyInvoiceInfoRepository repository;
@Override
protected CompanyInvoiceInfoRepository getRepository() {
return repository;
}
@Override
public CompanyInvoiceInfo createNewEntity() {
return new CompanyInvoiceInfo();
}
@Cacheable(key = "#p0")
@Override
public CompanyInvoiceInfoVo findById(Integer id) {
@@ -46,16 +59,7 @@ public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceI
}
public List<CompanyInvoiceInfo> searchByCompany(Company company, String searchText) {
Specification<CompanyInvoiceInfo> spec = (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("taxId"), "%" + searchText + "%"),
builder.like(root.get("address"), "%" + searchText + "%"),
builder.like(root.get("phone"), "%" + searchText + "%"),
builder.like(root.get("bankName"), "%" + searchText + "%"),
builder.like(root.get("bankAccount"), "%" + searchText + "%"));
};
Specification<CompanyInvoiceInfo> spec = buildSearchSpecification(searchText);
if (company != null) {
spec = spec.and((root, query, builder) -> {
return builder.equal(root.get("company"), company);
@@ -64,10 +68,7 @@ public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceI
return repository.findAll(spec, Pageable.ofSize(10)).getContent();
}
public Specification<CompanyInvoiceInfo> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<CompanyInvoiceInfo> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
@@ -79,19 +80,11 @@ public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceI
};
}
public Page<CompanyInvoiceInfo> findAll(Specification<CompanyInvoiceInfo> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<CompanyInvoiceInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
protected Specification<CompanyInvoiceInfo> buildParameterSpecification(JsonNode paramsNode) {
Specification<CompanyInvoiceInfo> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable).map(CompanyInvoiceInfo::toVo);
return null;
}
@Caching(evict = {
@@ -107,6 +100,7 @@ public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceI
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'byCompany-'+#p0.company.id")
})
@Override
public void delete(CompanyInvoiceInfo model) {
repository.delete(model);
}
@@ -116,7 +110,7 @@ public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceI
if (model == null || vo == null) {
throw new ServiceException("Model or VO cannot be null");
}
// 更新VO中包含的字段
model.setName(vo.getName());
model.setTaxId(vo.getTaxId());
@@ -125,9 +119,4 @@ public class CompanyInvoiceInfoService implements IEntityService<CompanyInvoiceI
model.setBankName(vo.getBankName());
model.setBankAccount(vo.getBankAccount());
}
@Override
public CompanyInvoiceInfo getById(Integer id) {
return repository.findById(id).orElse(null);
}
}

View File

@@ -10,7 +10,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
@@ -19,6 +21,7 @@ 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.company.repository.CompanyOldNameRepository;
@@ -35,7 +38,9 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "company-old-name")
public class CompanyOldNameService implements IEntityService<CompanyOldName>, QueryService<CompanyOldNameVo>, VoableService<CompanyOldName, CompanyOldNameVo> {
public class CompanyOldNameService extends EntityService<CompanyOldName, CompanyOldNameVo, Integer>
implements IEntityService<CompanyOldName>, QueryService<CompanyOldNameVo>,
VoableService<CompanyOldName, CompanyOldNameVo> {
private static final Logger logger = LoggerFactory.getLogger(CompanyOldNameService.class);
@Lazy
@Autowired
@@ -44,17 +49,20 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
@Autowired
private CompanyService companyService;
@Cacheable(key = "#p0")
public CompanyOldNameVo findById(Integer id) {
return companyOldNameRepository.findById(id).map(CompanyOldName::toVo).orElse(null);
@Override
protected CompanyOldNameRepository getRepository() {
return companyOldNameRepository;
}
@Override
public Specification<CompanyOldName> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return SpecificationUtils.andWith(searchText, this::buildSearchSpecification);
public CompanyOldName createNewEntity() {
return new CompanyOldName();
}
@Cacheable(key = "#p0")
@Override
public CompanyOldNameVo findById(Integer id) {
return companyOldNameRepository.findById(id).map(CompanyOldName::toVo).orElse(null);
}
protected Specification<CompanyOldName> buildSearchSpecification(String searchText) {
@@ -65,6 +73,15 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
};
}
@Override
protected Specification<CompanyOldName> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
public CompanyOldName save(CompanyOldName companyOldName) {
return companyOldNameRepository.save(companyOldName);
}
@@ -151,6 +168,10 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
companyOldNameRepository.deleteById(id);
}
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
public void delete(CompanyOldName entity) {
companyOldNameRepository.delete(entity);
}
@@ -179,7 +200,6 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
}
companyOldNameRepository.saveAll(list);
}
public void deleteByCompany(Company company) {
@@ -209,11 +229,6 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
return companyOldNameRepository.findAll(spec, pageable);
}
@Override
public CompanyOldName getById(Integer id) {
return companyOldNameRepository.findById(id).orElse(null);
}
@Override
public Page<CompanyOldNameVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<CompanyOldName> spec = null;
@@ -262,4 +277,5 @@ public class CompanyOldNameService implements IEntityService<CompanyOldName>, Qu
model.getId(), model.getVersion(), vo.getVersion());
}
}
}

View File

@@ -8,12 +8,15 @@ import java.util.List;
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.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.ds.other.repository.HolidayTableRepository;
@@ -36,11 +39,17 @@ import lombok.extern.slf4j.Slf4j;
@Service
@CacheConfig(cacheNames = "HolidayTable")
@Slf4j
public class HolidayService implements IEntityService<HolidayTable>, QueryService<HolidayTableVo>, VoableService<HolidayTable, HolidayTableVo> {
public class HolidayService extends EntityService<HolidayTable, HolidayTableVo, LocalDate> implements
IEntityService<HolidayTable>, QueryService<HolidayTableVo>, VoableService<HolidayTable, HolidayTableVo> {
@Autowired
private HolidayTableRepository holidayTableRepository;
@Override
protected HolidayTableRepository getRepository() {
return holidayTableRepository;
}
/**
* 调整日期到工作日
*
@@ -51,13 +60,14 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
if (date == null) {
return null;
}
while (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY || isHoliday(date)) {
while (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY
|| isHoliday(date)) {
date = date.plusDays(1);
}
return date;
}
/**
* 检查日期是否为节假日
*
@@ -68,18 +78,20 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
if (date == null) {
return false;
}
HolidayTable holidayTable = holidayTableRepository.findById(date).orElse(null);
return holidayTable != null && holidayTable.isHoliday();
}
@Override
public HolidayTable getById(Integer id) {
throw new UnsupportedOperationException("HolidayTable uses LocalDate as ID, please use getById(LocalDate id) method instead");
throw new UnsupportedOperationException(
"HolidayTable uses LocalDate as ID, please use getById(LocalDate id) method instead");
}
/**
* 根据LocalDate类型的ID查询实体
*
* @param id 实体ID
* @return 实体对象
*/
@@ -87,26 +99,29 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
if (id == null) {
return null;
}
return holidayTableRepository.findById(id).orElse(null);
return super.getById(id);
}
@Override
@Caching(evict = { @CacheEvict(key = "#p0.id") })
public HolidayTable save(HolidayTable entity) {
if (entity == null) {
return null;
}
return holidayTableRepository.save(entity);
return super.save(entity);
}
@Override
@Caching(evict = { @CacheEvict(key = "#p0.id") })
public void delete(HolidayTable entity) {
if (entity != null && entity.getId() != null) {
holidayTableRepository.deleteById(entity.getId());
super.delete(entity);
}
}
/**
* 根据LocalDate类型的ID删除实体
*
* @param id 实体ID
*/
public void deleteById(LocalDate id) {
@@ -114,60 +129,61 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
holidayTableRepository.deleteById(id);
}
}
@Override
public HolidayTable createNewEntity() {
return new HolidayTable();
}
@Override
protected Specification<HolidayTable> buildSearchSpecification(String searchText) {
return (Root<HolidayTable> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
try {
// 尝试将搜索文本解析为日期
LocalDate date = LocalDate.parse(searchText.trim());
predicates.add(criteriaBuilder.equal(root.get("id"), date));
} catch (DateTimeParseException e) {
// 如果不是日期格式,尝试其他搜索方式
// 由于HolidayTable只有id和holiday字段这里无法进行其他字段的模糊搜索
log.warn("Search text '{}' is not a valid date format", searchText);
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
};
}
@Override
public HolidayTableVo findById(Integer id) {
throw new UnsupportedOperationException(
"HolidayTable uses LocalDate as ID, please use findById(Object id) instead");
}
@Cacheable(key = "#id", unless = "#result == null")
public HolidayTableVo findById(LocalDate id) {
HolidayTable entity = getById(id);
return entity != null ? entity.toVo() : null;
}
@Override
protected Specification<HolidayTable> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
/**
* 获取所有节假日
*
* @param pageable 分页参数
* @return 分页结果
*/
public Page<HolidayTable> findAll(Pageable pageable) {
return holidayTableRepository.findAll(pageable);
}
@Override
public Page<HolidayTable> findAll(Specification<HolidayTable> spec, Pageable pageable) {
// 由于HolidayTableRepository不支持Specification查询返回所有节假日
return findAll(pageable);
}
@Override
public Specification<HolidayTable> getSearchSpecification(String searchText) {
// 实现根据搜索文本构建规格化查询
return (Root<HolidayTable> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) -> {
List<Predicate> predicates = new ArrayList<>();
if (searchText != null && !searchText.trim().isEmpty()) {
try {
// 尝试将搜索文本解析为日期
LocalDate date = LocalDate.parse(searchText.trim());
predicates.add(criteriaBuilder.equal(root.get("id"), date));
} catch (DateTimeParseException e) {
// 如果不是日期格式,尝试其他搜索方式
// 由于HolidayTable只有id和holiday字段这里无法进行其他字段的模糊搜索
log.warn("Search text '{}' is not a valid date format", searchText);
}
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
};
}
@Override
public HolidayTableVo findById(Integer id) {
throw new UnsupportedOperationException("HolidayTable uses LocalDate as ID, please use findById(Object id) instead");
}
@Cacheable(key = "#id", unless = "#result == null")
public HolidayTableVo findById(LocalDate id) {
HolidayTable entity = getById(id);
return entity != null ? entity.toVo() : null;
}
@Override
public Page<HolidayTableVo> findAll(JsonNode paramsNode, Pageable pageable) {
// 实现根据JSON参数过滤节假日
Page<HolidayTable> entityPage;
if (paramsNode == null || paramsNode.isEmpty()) {
// 如果没有参数,返回所有节假日
entityPage = findAll(pageable);
@@ -176,11 +192,11 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
Boolean isHoliday = null;
LocalDate startDate = null;
LocalDate endDate = null;
if (paramsNode.has("isHoliday")) {
isHoliday = paramsNode.get("isHoliday").asBoolean();
}
if (paramsNode.has("startDate")) {
try {
startDate = LocalDate.parse(paramsNode.get("startDate").asText());
@@ -188,7 +204,7 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
log.warn("Failed to parse startDate: {}", e.getMessage());
}
}
if (paramsNode.has("endDate")) {
try {
endDate = LocalDate.parse(paramsNode.get("endDate").asText());
@@ -196,7 +212,7 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
log.warn("Failed to parse endDate: {}", e.getMessage());
}
}
// 根据参数组合选择合适的查询方法
if (isHoliday != null && startDate != null && endDate != null) {
// 组合条件:是否为节假日 + 日期范围
@@ -212,27 +228,27 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
entityPage = findAll(pageable);
}
}
return entityPage.map(HolidayTable::toVo);
}
@Override
public long count(JsonNode paramsNode) {
// 简单实现,返回所有节假日数量
return holidayTableRepository.count();
}
@Override
public void updateByVo(HolidayTable model, HolidayTableVo vo) {
if (model == null || vo == null) {
return;
}
// 更新实体属性
model.setHoliday(vo.isHoliday());
save(model);
}
/**
* 创建节假日
*
@@ -243,11 +259,11 @@ public class HolidayService implements IEntityService<HolidayTable>, QueryServic
if (vo == null || vo.getId() == null) {
throw new IllegalArgumentException("HolidayTableVo or ID cannot be null");
}
HolidayTable entity = new HolidayTable();
entity.setId(vo.getId());
entity.setHoliday(vo.isHoliday());
HolidayTable savedEntity = save(entity);
return savedEntity.toVo();
}

View File

@@ -1,7 +1,5 @@
package com.ecep.contract.ds.company.service;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,28 +7,25 @@ import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
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 org.springframework.util.StringUtils;
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.company.repository.InvoiceRepository;
import com.ecep.contract.ds.company.model.Company;
import com.ecep.contract.ds.company.repository.InvoiceRepository;
import com.ecep.contract.ds.other.model.Invoice;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.InvoiceVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "invoice")
public class InvoiceService implements IEntityService<Invoice>, QueryService<InvoiceVo>,
public class InvoiceService extends EntityService<Invoice, InvoiceVo, Integer>
implements IEntityService<Invoice>, QueryService<InvoiceVo>,
VoableService<Invoice, InvoiceVo> {
private static final Logger logger = LoggerFactory.getLogger(InvoiceService.class);
@@ -38,8 +33,8 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
private InvoiceRepository repository;
@Override
public Invoice getById(Integer id) {
return repository.findById(id).orElse(null);
protected InvoiceRepository getRepository() {
return repository;
}
@Cacheable(key = "#p0")
@@ -49,34 +44,30 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
}
@Override
public Specification<Invoice> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
public Invoice createNewEntity() {
return new Invoice();
}
@Override
protected Specification<Invoice> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
@Override
protected Specification<Invoice> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("description"), "%" + searchText + "%"));
};
}
@Override
public Page<Invoice> findAll(Specification<Invoice> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@CacheEvict(key = "#p0.id")
@Override
public void delete(Invoice entity) {
repository.delete(entity);
}
public List<Invoice> findAll(Specification<Invoice> spec, Sort by) {
return repository.findAll(spec, by);
}
public Invoice findByCode(String invoiceNumber) {
return repository.findByCode(invoiceNumber);
}
@@ -87,18 +78,6 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
return repository.save(invoice);
}
@Override
public Page<InvoiceVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<Invoice> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "company");
return findAll(spec, pageable).map(Invoice::toVo);
}
@Override
public void updateByVo(Invoice model, InvoiceVo vo) {
if (model == null || vo == null) {
@@ -113,6 +92,7 @@ public class InvoiceService implements IEntityService<Invoice>, QueryService<Inv
}
model.setInvoiceDate(vo.getInvoiceDate());
model.setDescription(vo.getDescription());
}
}

View File

@@ -2,20 +2,13 @@ package com.ecep.contract.ds.contract.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.ds.contract.model.ContractBidVendor;
@Repository
public interface ContractBidVendorRepository extends
// JDBC interfaces
CrudRepository<ContractBidVendor, Integer>, PagingAndSortingRepository<ContractBidVendor, Integer>,
// JPA interfaces
JpaRepository<ContractBidVendor, Integer>, JpaSpecificationExecutor<ContractBidVendor> {
public interface ContractBidVendorRepository extends MyRepository<ContractBidVendor, Integer> {
List<ContractBidVendor> findByContractId(Integer contractId);

View File

@@ -2,16 +2,13 @@ package com.ecep.contract.ds.contract.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.ds.vendor.model.ExtendVendorInfo;
@Repository
public interface ExtendVendorInfoRepository extends
// JPA interfaces
JpaRepository<ExtendVendorInfo, Integer>, JpaSpecificationExecutor<ExtendVendorInfo> {
public interface ExtendVendorInfoRepository extends MyRepository<ExtendVendorInfo, Integer> {
Optional<ExtendVendorInfo> findByContractId(Integer contractId);
}

View File

@@ -12,6 +12,7 @@ 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.SpringApp;
@@ -25,7 +26,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-balance")
public class ContractBalanceService implements IEntityService<ContractBalance>, QueryService<ContractBalanceVo>,
public class ContractBalanceService extends EntityService<ContractBalance, ContractBalanceVo, Integer>
implements IEntityService<ContractBalance>, QueryService<ContractBalanceVo>,
VoableService<ContractBalance, ContractBalanceVo> {
@Lazy
@@ -33,8 +35,8 @@ public class ContractBalanceService implements IEntityService<ContractBalance>,
private ContractBalanceRepository repository;
@Override
public ContractBalance getById(Integer id) {
return repository.findById(id).orElse(null);
protected ContractBalanceRepository getRepository() {
return repository;
}
@Cacheable(key = "#p0")
@@ -48,10 +50,12 @@ public class ContractBalanceService implements IEntityService<ContractBalance>,
}
@Override
public Specification<ContractBalance> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
public ContractBalance createNewEntity() {
return new ContractBalance();
}
@Override
protected Specification<ContractBalance> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("refId"), "%" + searchText + "%"),
@@ -83,16 +87,11 @@ public class ContractBalanceService implements IEntityService<ContractBalance>,
}
@Override
public Page<ContractBalanceVo> findAll(JsonNode paramsNode, Pageable pageable) {
protected Specification<ContractBalance> buildParameterSpecification(JsonNode paramsNode) {
Specification<ContractBalance> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// 字段等值查询 - 只包含ContractBalanceVo中存在的字段
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "contract", "employee");
return findAll(spec, pageable).map(ContractBalance::toVo);
return spec;
}
@Override

View File

@@ -15,6 +15,7 @@ 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.SpringApp;
@@ -32,14 +33,16 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-ven-bid")
public class ContractBidVendorService implements IEntityService<ContractBidVendor>, QueryService<ContractBidVendorVo>, VoableService<ContractBidVendor, ContractBidVendorVo> {
public class ContractBidVendorService extends EntityService<ContractBidVendor, ContractBidVendorVo, Integer>
implements IEntityService<ContractBidVendor>, QueryService<ContractBidVendorVo>,
VoableService<ContractBidVendor, ContractBidVendorVo> {
@Lazy
@Autowired
private ContractBidVendorRepository repository;
@Override
public ContractBidVendor getById(Integer id) {
return repository.findById(id).orElse(null);
protected ContractBidVendorRepository getRepository() {
return repository;
}
@Cacheable(key = "#p0")
@@ -53,21 +56,19 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
}
@Override
public Specification<ContractBidVendor> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<ContractBidVendor> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("bidName"), "%" + searchText + "%"),
builder.like(root.get("memo"), "%" + searchText + "%")
);
builder.like(root.get("memo"), "%" + searchText + "%"));
};
}
@Override
public Page<ContractBidVendor> findAll(Specification<ContractBidVendor> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
protected Specification<ContractBidVendor> buildParameterSpecification(JsonNode paramsNode) {
Specification<ContractBidVendor> spec = null;
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "company");
return spec;
}
@Cacheable(key = "'allbycontract-'+#p0.id")
@@ -75,6 +76,7 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
return repository.findByContractId(contract.getId()).stream().map(ContractBidVendor::toVo).toList();
}
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'allbycontract-'+#p0.contract.id")
@@ -92,10 +94,6 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
repository.delete(bidVendor);
}
public List<ContractBidVendor> findAll(Specification<ContractBidVendor> spec, Sort sort) {
return repository.findAll(spec, sort);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
@@ -107,11 +105,16 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
return repository.findByContractIdAndCompanyId(contract.getId(), company.getId());
}
@Override
public ContractBidVendor createNewEntity() {
return new ContractBidVendor();
}
@Override
public Page<ContractBidVendorVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractBidVendor> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
spec = buildSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "company");
@@ -142,8 +145,10 @@ public class ContractBidVendorService implements IEntityService<ContractBidVendo
if (vo.getQuotationSheetFileId() == null) {
model.setQuotationSheet(null);
} else {
if (model.getQuotationSheet() == null || !model.getQuotationSheet().getId().equals(vo.getQuotationSheetFileId())) {
model.setQuotationSheet(SpringApp.getBean(ContractFileRepository.class).findById(vo.getQuotationSheetFileId()).orElse(null));
if (model.getQuotationSheet() == null
|| !model.getQuotationSheet().getId().equals(vo.getQuotationSheetFileId())) {
model.setQuotationSheet(SpringApp.getBean(ContractFileRepository.class)
.findById(vo.getQuotationSheetFileId()).orElse(null));
}
}
}

View File

@@ -8,12 +8,10 @@ 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.contract.repository.ContractCatalogRepository;
@@ -28,12 +26,18 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-catalog")
public class ContractCatalogService implements IEntityService<ContractCatalog>, QueryService<ContractCatalogVo>,
public class ContractCatalogService extends EntityService<ContractCatalog, ContractCatalogVo, Integer>
implements IEntityService<ContractCatalog>, QueryService<ContractCatalogVo>,
VoableService<ContractCatalog, ContractCatalogVo> {
@Lazy
@Autowired
private ContractCatalogRepository repository;
@Override
protected ContractCatalogRepository getRepository() {
return repository;
}
/**
* 根据 id 查找 ContractCatalog
*/
@@ -43,6 +47,7 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
return repository.findById(id).map(ContractCatalog::toVo).orElse(null);
}
@Override
public ContractCatalog getById(Integer id) {
return repository.findById(id).orElse(null);
}
@@ -61,6 +66,7 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
return repository.findAll().stream().map(ContractCatalog::toVo).toList();
}
@Override
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),
@@ -81,10 +87,7 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
}
@Override
public Specification<ContractCatalog> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<ContractCatalog> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
@@ -94,17 +97,8 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
}
@Override
public Page<ContractCatalog> findAll(Specification<ContractCatalog> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ContractCatalogVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractCatalog> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
return findAll(spec, pageable).map(ContractCatalog::toVo);
protected Specification<ContractCatalog> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
@Override
@@ -118,4 +112,9 @@ public class ContractCatalogService implements IEntityService<ContractCatalog>,
model.setParent(vo.getParent());
model.setUseYear(vo.isUseYear());
}
@Override
public ContractCatalog createNewEntity() {
return new ContractCatalog();
}
}

View File

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.ContractFileType;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.SpringApp;
@@ -34,18 +35,14 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-file")
public class ContractFileService implements IEntityService<ContractFile>, QueryService<ContractFileVo>,
public class ContractFileService extends EntityService<ContractFile, ContractFileVo, Integer>
implements IEntityService<ContractFile>, QueryService<ContractFileVo>,
VoableService<ContractFile, ContractFileVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractFileService.class);
@Lazy
@Autowired
private ContractFileRepository contractFileRepository;
@Override
public ContractFile getById(Integer id) {
return contractFileRepository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public ContractFileVo findById(Integer id) {
@@ -53,10 +50,7 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
}
@Override
public Specification<ContractFile> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
public Specification<ContractFile> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("fileName"), "%" + searchText + "%"),
@@ -65,25 +59,20 @@ public class ContractFileService implements IEntityService<ContractFile>, QueryS
}
@Override
public Page<ContractFile> findAll(Specification<ContractFile> spec, Pageable pageable) {
return contractFileRepository.findAll(spec, pageable);
protected ContractFileRepository getRepository() {
return contractFileRepository;
}
@Override
public Page<ContractFileVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractFile> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "type");
return findAll(spec, pageable).map(ContractFile::toVo);
public ContractFile createNewEntity() {
return new ContractFile();
}
public List<ContractFile> findAll(Specification<ContractFile> spec, Sort by) {
return contractFileRepository.findAll(spec, by);
@Override
protected Specification<ContractFile> buildParameterSpecification(JsonNode paramsNode) {
Specification<ContractFile> spec = null;
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "type");
return spec;
}
public List<ContractFile> findAllByContractAndFileType(Contract contract, ContractFileType contractFileType) {

View File

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.ecep.contract.ContractFileType;
import com.ecep.contract.EntityService;
import com.ecep.contract.IEntityService;
import com.ecep.contract.QueryService;
import com.ecep.contract.ds.contract.repository.ContractFileTypeLocalRepository;
@@ -31,7 +32,7 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-file-type")
public class ContractFileTypeService
public class ContractFileTypeService extends EntityService<ContractFileTypeLocal, ContractFileTypeLocalVo, Integer>
implements IEntityService<ContractFileTypeLocal>, QueryService<ContractFileTypeLocalVo>,
VoableService<ContractFileTypeLocal, ContractFileTypeLocalVo> {
@Lazy
@@ -39,20 +40,25 @@ public class ContractFileTypeService
private ContractFileTypeLocalRepository repository;
@Override
public Page<ContractFileTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractFileTypeLocal> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
protected ContractFileTypeLocalRepository getRepository() {
return repository;
}
@Override
public ContractFileTypeLocal createNewEntity() {
return new ContractFileTypeLocal();
}
@Override
protected Specification<ContractFileTypeLocal> buildParameterSpecification(JsonNode paramsNode) {
Specification<ContractFileTypeLocal> spec = null;
if (paramsNode.has("type")) {
spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"),
ContractFileType.valueOf(paramsNode.get("type").asText())));
}
// field
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value", "suggestFileName");
return findAll(spec, pageable).map(ContractFileTypeLocal::toVo);
return spec;
}
@Cacheable(key = "'all-'+#p0.toLanguageTag()")
@@ -69,20 +75,8 @@ public class ContractFileTypeService
return repository.findById(id).map(ContractFileTypeLocal::toVo).orElse(null);
}
public ContractFileTypeLocal getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<ContractFileTypeLocal> findAll(Specification<ContractFileTypeLocal> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Specification<ContractFileTypeLocal> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
protected Specification<ContractFileTypeLocal> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("type"), "%" + searchText + "%"),

View File

@@ -16,8 +16,10 @@ 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.ds.MyRepository;
import com.ecep.contract.ds.contract.repository.ContractGroupRepository;
import com.ecep.contract.model.ContractGroup;
import com.ecep.contract.service.VoableService;
@@ -30,7 +32,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-group")
public class ContractGroupService implements IEntityService<ContractGroup>, QueryService<ContractGroupVo>,
public class ContractGroupService extends EntityService<ContractGroup, ContractGroupVo, Integer>
implements IEntityService<ContractGroup>, QueryService<ContractGroupVo>,
VoableService<ContractGroup, ContractGroupVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractGroupService.class);
@@ -39,8 +42,8 @@ public class ContractGroupService implements IEntityService<ContractGroup>, Quer
private ContractGroupRepository repository;
@Override
public ContractGroup getById(Integer id) {
return repository.findById(id).orElse(null);
protected ContractGroupRepository getRepository() {
return repository;
}
@Override
@@ -50,21 +53,7 @@ public class ContractGroupService implements IEntityService<ContractGroup>, Quer
}
@Override
public Page<ContractGroup> findAll(Specification<ContractGroup> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ContractGroupVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractGroup> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
return findAll(spec, pageable).map(ContractGroup::toVo);
}
@Override
public Specification<ContractGroup> getSearchSpecification(String searchText) {
protected Specification<ContractGroup> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
@@ -73,6 +62,11 @@ public class ContractGroupService implements IEntityService<ContractGroup>, Quer
};
}
@Override
protected Specification<ContractGroup> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
public ContractGroup findByName(String name) {
return repository.findByName(name).orElse(null);
}
@@ -115,7 +109,8 @@ public class ContractGroupService implements IEntityService<ContractGroup>, Quer
repository.delete(group);
}
public ContractGroup newContractGroup() {
@Override
public ContractGroup createNewEntity() {
ContractGroup group = new ContractGroup();
group.setCode("");
group.setName("");

View File

@@ -4,12 +4,14 @@ import java.util.List;
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.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;
@@ -27,7 +29,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@CacheConfig(cacheNames = "contract-invoice")
public class ContractInvoiceService implements IEntityService<ContractInvoice>, QueryService<ContractInvoiceVo>,
public class ContractInvoiceService extends EntityService<ContractInvoice, ContractInvoiceVo, Integer>
implements IEntityService<ContractInvoice>, QueryService<ContractInvoiceVo>,
VoableService<ContractInvoice, ContractInvoiceVo> {
@Autowired
@@ -75,6 +78,7 @@ public class ContractInvoiceService implements IEntityService<ContractInvoice>,
* @return 保存后的发票VO
*/
@Override
@CacheEvict(key = "#p0.id")
public ContractInvoice save(ContractInvoice invoice) {
try {
ContractInvoice saved = repository.save(invoice);
@@ -85,6 +89,11 @@ public class ContractInvoiceService implements IEntityService<ContractInvoice>,
}
}
@Override
public ContractInvoice createNewEntity() {
return new ContractInvoice();
}
@Override
public void updateByVo(ContractInvoice entity, ContractInvoiceVo vo) {
if (entity == null || vo == null) {
@@ -137,9 +146,7 @@ public class ContractInvoiceService implements IEntityService<ContractInvoice>,
@Override
public Page<ContractInvoiceVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractInvoice> spec = buildParameterSpecification(paramsNode);
Page<ContractInvoice> page = repository.findAll(spec, pageable);
return page.map(ContractInvoice::toVo);
return super.findAll(paramsNode, pageable);
}
/**
@@ -169,17 +176,12 @@ public class ContractInvoiceService implements IEntityService<ContractInvoice>,
}
@Override
public ContractInvoice getById(Integer id) {
return repository.findById(id).orElse(null);
protected ContractInvoiceRepository getRepository() {
return repository;
}
@Override
public Page<ContractInvoice> findAll(Specification<ContractInvoice> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Specification<ContractInvoice> getSearchSpecification(String searchText) {
protected Specification<ContractInvoice> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("name"), "%" + searchText + "%"),
@@ -189,6 +191,7 @@ public class ContractInvoiceService implements IEntityService<ContractInvoice>,
}
@Override
@CacheEvict(key = "#p0.id")
public void delete(ContractInvoice entity) {
try {
repository.delete(entity);

View File

@@ -2,23 +2,19 @@ package com.ecep.contract.ds.contract.service;
import java.util.List;
import com.ecep.contract.constant.ParamConstant;
import com.ecep.contract.vo.ContractVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.domain.Sort;
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.SpringApp;
@@ -31,6 +27,7 @@ import com.ecep.contract.model.Inventory;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ContractItemVo;
import com.ecep.contract.vo.ContractVo;
import com.fasterxml.jackson.databind.JsonNode;
import jakarta.persistence.criteria.Path;
@@ -38,26 +35,20 @@ import jakarta.persistence.criteria.Path;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-item")
public class ContractItemService implements IEntityService<ContractItem>, QueryService<ContractItemVo>,
public class ContractItemService extends EntityService<ContractItem, ContractItemVo, Integer>
implements IEntityService<ContractItem>, QueryService<ContractItemVo>,
VoableService<ContractItem, ContractItemVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractItemService.class);
@Lazy
@Autowired
private ContractItemRepository itemRepository;
@Override
public ContractItem getById(Integer id) {
return itemRepository.findById(id).orElse(null);
}
@Override
@Cacheable(key = "#p0")
public ContractItemVo findById(Integer id) {
return itemRepository.findById(id).map(ContractItem::toVo).orElse(null);
}
public List<ContractItem> findAllByItemCode(String itemCode) {
return itemRepository.findAllByItemCode(itemCode);
}
@@ -66,44 +57,6 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
return itemRepository.findByRowId(rowId).orElse(null);
}
@Override
public Specification<ContractItem> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
Path<Inventory> inventory = root.get("inventory");
return builder.or(
builder.like(root.get("itemCode"), "%" + searchText + "%"),
builder.like(root.get("title"), "%" + searchText + "%"),
builder.like(root.get("specification"), "%" + searchText + "%"),
builder.like(root.get("unit"), "%" + searchText + "%"),
builder.like(root.get("remark"), "%" + searchText + "%"),
builder.and(
inventory.isNotNull(), builder.or(
builder.like(inventory.get("name"), "%" + searchText + "%"),
builder.like(inventory.get("code"), "%" + searchText + "%"),
builder.like(inventory.get("specification"), "%" + searchText + "%"))));
};
}
@Override
public Page<ContractItem> findAll(Specification<ContractItem> spec, Pageable pageable) {
return itemRepository.findAll(spec, pageable);
}
@Override
public Page<ContractItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractItem> spec = null;
if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract", "inventory", "creator", "updater");
spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "itemCode", "refId", "title", "specification");
return findAll(spec, pageable).map(ContractItem::toVo);
}
public List<ContractItem> findAllByContract(Contract contract) {
return itemRepository.findByContractId(contract.getId());
}
@@ -116,14 +69,6 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
return itemRepository.findByInventoryId(inventory.getId());
}
public List<ContractItem> findAll(Specification<ContractItem> spec, Sort sort) {
return itemRepository.findAll(spec, sort);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
@Override
public void updateByVo(ContractItem model, ContractItemVo vo) {
// 更新基本属性
@@ -181,16 +126,47 @@ public class ContractItemService implements IEntityService<ContractItem>, QueryS
}
@Override
@CacheEvict(key = "#p0.id")
public ContractItem save(ContractItem item) {
return itemRepository.save(item);
}
@Caching(evict = {
@CacheEvict(key = "#p0.id")
})
@Override
@CacheEvict(key = "#p0.id")
public void delete(ContractItem item) {
itemRepository.delete(item);
}
}
@Override
protected ContractItemRepository getRepository() {
return itemRepository;
}
@Override
public ContractItem createNewEntity() {
return new ContractItem();
}
@Override
protected Specification<ContractItem> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
Path<Inventory> inventory = root.get("inventory");
return builder.or(
builder.like(root.get("itemCode"), "%" + searchText + "%"),
builder.like(root.get("title"), "%" + searchText + "%"),
builder.like(root.get("specification"), "%" + searchText + "%"),
builder.like(root.get("unit"), "%" + searchText + "%"),
builder.like(root.get("remark"), "%" + searchText + "%"),
builder.and(
inventory.isNotNull(), builder.or(
builder.like(inventory.get("name"), "%" + searchText + "%"),
builder.like(inventory.get("code"), "%" + searchText + "%"),
builder.like(inventory.get("specification"), "%" + searchText + "%"))));
};
}
@Override
protected Specification<ContractItem> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
}

View File

@@ -15,6 +15,7 @@ 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.ds.contract.repository.ContractKindRepository;
@@ -29,7 +30,8 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-kind")
public class ContractKindService implements IEntityService<ContractKind>, QueryService<ContractKindVo>,
public class ContractKindService extends EntityService<ContractKind, ContractKindVo, Integer>
implements IEntityService<ContractKind>, QueryService<ContractKindVo>,
VoableService<ContractKind, ContractKindVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractKindService.class);
@@ -42,27 +44,19 @@ public class ContractKindService implements IEntityService<ContractKind>, QueryS
public ContractKindVo findById(Integer id) {
return repository.findById(id).map(ContractKind::toVo).orElse(null);
}
public ContractKind getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Override
public Page<ContractKind> findAll(Specification<ContractKind> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ContractKindVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractKind> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
return findAll(spec, pageable).map(ContractKind::toVo);
return super.findAll(paramsNode, pageable);
}
@Override
public Specification<ContractKind> getSearchSpecification(String searchText) {
protected Specification<ContractKind> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
@Override
protected Specification<ContractKind> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
@@ -72,6 +66,10 @@ public class ContractKindService implements IEntityService<ContractKind>, QueryS
}
@Override
@Caching(evict = {
@CacheEvict(key = "'kinds'"),
@CacheEvict(key = "'kind-'+#p0.id"),
})
public void delete(ContractKind entity) {
repository.delete(entity);
}
@@ -117,4 +115,15 @@ public class ContractKindService implements IEntityService<ContractKind>, QueryS
model.setTitle(vo.getTitle());
// model.setActive(vo.isActive());
}
@Override
protected ContractKindRepository getRepository() {
return repository;
}
@Override
public ContractKind createNewEntity() {
return new ContractKind();
}
}

View File

@@ -15,6 +15,7 @@ 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.SpringApp;
@@ -22,7 +23,7 @@ import com.ecep.contract.ds.contract.repository.ContractPayPlanRepository;
import com.ecep.contract.ds.contract.model.Contract;
import com.ecep.contract.ds.contract.model.ContractPayPlan;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ContractPayPlanVo;
import com.fasterxml.jackson.databind.JsonNode;
@@ -32,17 +33,13 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-pay-plan")
public class ContractPayPlanService implements IEntityService<ContractPayPlan>, QueryService<ContractPayPlanVo>,
public class ContractPayPlanService extends EntityService<ContractPayPlan, ContractPayPlanVo, Integer>
implements IEntityService<ContractPayPlan>, QueryService<ContractPayPlanVo>,
VoableService<ContractPayPlan, ContractPayPlanVo> {
@Lazy
@Autowired
private ContractPayPlanRepository repository;
@Override
public ContractPayPlan getById(Integer id) {
return repository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
@Override
public ContractPayPlanVo findById(Integer id) {
@@ -50,29 +47,13 @@ public class ContractPayPlanService implements IEntityService<ContractPayPlan>,
}
@Override
public Specification<ContractPayPlan> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, cb) -> {
return cb.or(cb.like(root.get("payTerm"), "%" + searchText + "%"));
};
protected ContractPayPlanRepository getRepository() {
return repository;
}
@Override
public Page<ContractPayPlan> findAll(Specification<ContractPayPlan> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Page<ContractPayPlanVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractPayPlan> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
return findAll(spec, pageable).map(ContractPayPlan::toVo);
public ContractPayPlan createNewEntity() {
return new ContractPayPlan();
}
public List<ContractPayPlan> findAllByContract(ContractVo contract) {
@@ -117,4 +98,17 @@ public class ContractPayPlanService implements IEntityService<ContractPayPlan>,
model.setUpdateDate(vo.getUpdateDate());
}
}
@Override
protected Specification<ContractPayPlan> buildParameterSpecification(JsonNode paramsNode) {
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
}
@Override
protected Specification<ContractPayPlan> buildSearchSpecification(String searchText) {
return (root, query, cb) -> {
return cb.or(cb.like(root.get("payTerm"), "%" + searchText + "%"));
};
}
}

View File

@@ -2,8 +2,6 @@ package com.ecep.contract.ds.contract.service;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
@@ -15,6 +13,7 @@ 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.ds.contract.repository.ContractTypeRepository;
@@ -29,9 +28,9 @@ import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-type")
public class ContractTypeService implements IEntityService<ContractType>, QueryService<ContractTypeVo>,
public class ContractTypeService extends EntityService<ContractType, ContractTypeVo, Integer>
implements IEntityService<ContractType>, QueryService<ContractTypeVo>,
VoableService<ContractType, ContractTypeVo> {
private static final Logger logger = LoggerFactory.getLogger(ContractTypeService.class);
@Lazy
@Autowired
@@ -43,22 +42,29 @@ public class ContractTypeService implements IEntityService<ContractType>, QueryS
return repository.findById(id).map(ContractType::toVo).orElse(null);
}
public ContractType getById(Integer id) {
return repository.findById(id).orElse(null);
@Override
protected ContractTypeRepository getRepository() {
return repository;
}
@Override
public Page<ContractType> findAll(Specification<ContractType> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
public ContractType createNewEntity() {
return new ContractType();
}
@Override
public Page<ContractTypeVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ContractType> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
return findAll(spec, pageable).map(ContractType::toVo);
protected Specification<ContractType> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("title"), "%" + searchText + "%"));
};
}
@Override
protected Specification<ContractType> buildParameterSpecification(JsonNode paramsNode) {
return null;
}
public ContractType findByName(String name) {
@@ -75,16 +81,6 @@ public class ContractTypeService implements IEntityService<ContractType>, QueryS
return repository.findAll().stream().map(ContractType::toVo).toList();
}
@Override
public Specification<ContractType> getSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("code"), "%" + searchText + "%"),
builder.like(root.get("name"), "%" + searchText + "%"),
builder.like(root.get("title"), "%" + searchText + "%"));
};
}
@Caching(evict = {
@CacheEvict(key = "#p0.id"),
@CacheEvict(key = "'code-'+#p0.code"),

View File

@@ -18,6 +18,7 @@ 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.contract.repository.ExtendVendorInfoRepository;
@@ -25,14 +26,15 @@ import com.ecep.contract.ds.vendor.service.VendorGroupService;
import com.ecep.contract.ds.contract.model.Contract;
import com.ecep.contract.ds.vendor.model.ExtendVendorInfo;
import com.ecep.contract.service.VoableService;
import com.ecep.contract.util.SpecificationUtils;
import com.ecep.contract.vo.ExtendVendorInfoVo;
import com.fasterxml.jackson.databind.JsonNode;
@Lazy
@Service
@CacheConfig(cacheNames = "contract-ext-ven-info")
public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>, QueryService<ExtendVendorInfoVo>,
public class ExtendVendorInfoService extends EntityService<ExtendVendorInfo, ExtendVendorInfoVo, Integer>
implements IEntityService<ExtendVendorInfo>, QueryService<ExtendVendorInfoVo>,
VoableService<ExtendVendorInfo, ExtendVendorInfoVo> {
@Lazy
@Autowired
@@ -45,8 +47,23 @@ public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>
private ContractService contractService;
@Override
public ExtendVendorInfo getById(Integer id) {
return repository.findById(id).orElse(null);
protected ExtendVendorInfoRepository getRepository() {
return repository;
}
@Override
public ExtendVendorInfo createNewEntity() {
return new ExtendVendorInfo();
}
@Override
protected Specification<ExtendVendorInfo> buildSearchSpecification(String searchText) {
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("contract").get("code"), "%" + searchText + "%"),
builder.like(root.get("contract").get("name"), "%" + searchText + "%"),
builder.like(root.get("codeSequenceNumber").as(String.class), "%" + searchText + "%"));
};
}
@Override
@@ -81,33 +98,9 @@ public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>
repository.delete(bidVendor);
}
@Override
public Page<ExtendVendorInfo> findAll(Specification<ExtendVendorInfo> spec, Pageable pageable) {
return repository.findAll(spec, pageable);
}
@Override
public Specification<ExtendVendorInfo> getSearchSpecification(String searchText) {
if (!StringUtils.hasText(searchText)) {
return null;
}
return (root, query, builder) -> {
return builder.or(
builder.like(root.get("contract").get("code"), "%" + searchText + "%"),
builder.like(root.get("contract").get("name"), "%" + searchText + "%"),
builder.like(root.get("codeSequenceNumber").as(String.class), "%" + searchText + "%"));
};
}
@Override
public Page<ExtendVendorInfoVo> findAll(JsonNode paramsNode, Pageable pageable) {
Specification<ExtendVendorInfo> spec = null;
if (paramsNode.has("searchText")) {
spec = getSearchSpecification(paramsNode.get("searchText").asText());
}
// field
spec = SpecificationUtils.andParam(spec, paramsNode, "contract");
return findAll(spec, pageable).map(ExtendVendorInfo::toVo);
return super.findAll(paramsNode, pageable);
}
public List<ExtendVendorInfo> findAll(Specification<ExtendVendorInfo> spec, Sort sort) {
@@ -167,4 +160,9 @@ public class ExtendVendorInfoService implements IEntityService<ExtendVendorInfo>
}
}
}
@Override
protected Specification<ExtendVendorInfo> buildParameterSpecification(JsonNode paramsNode) {
throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'");
}
}

View File

@@ -4,15 +4,13 @@ import java.time.LocalDate;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import com.ecep.contract.ds.MyRepository;
import com.ecep.contract.model.HolidayTable;
@Repository
public interface HolidayTableRepository // curd
extends CrudRepository<HolidayTable, LocalDate>, PagingAndSortingRepository<HolidayTable, LocalDate> {
public interface HolidayTableRepository extends MyRepository<HolidayTable, LocalDate> {
/**
* 根据是否为节假日过滤

103
server_entity_services.md Normal file
View File

@@ -0,0 +1,103 @@
# 服务器端继承IEntityService接口的Service列表
| 类名 | 是否继承EntityService |
|------|----------------------|
| CloudRkService | 是 |
| CloudTycService | 是 |
| YongYouU8Service | 是 |
| CompanyBankAccountService | 是 |
| CompanyBlackReasonService | 是 |
| CompanyContactService | 是 |
| CompanyExtendInfoService | 是 |
| CompanyFileService | 是 |
| CompanyFileTypeService | 是 |
| CompanyInvoiceInfoService | 是 |
| CompanyOldNameService | 是 |
| CompanyService | 是 |
| HolidayService | 是 |
| InvoiceService | 是 |
| ContractBalanceService | 是 |
| ContractBidVendorService | 是 |
| ContractCatalogService | 是 |
| ContractFileService | 是 |
| ContractFileTypeService | 是 |
| ContractGroupService | 是 |
| ContractInvoiceService | 是 |
| ContractItemService | 是 |
| ContractKindService | 是 |
| ContractPayPlanService | 是 |
| ContractService | 是 |
| ContractTypeService | 是 |
| ExtendVendorInfoService | 是 |
| PurchaseBillVoucherItemService | 否 |
| PurchaseBillVoucherService | 否 |
| PurchaseOrderItemService | 否 |
| PurchaseOrdersService | 否 |
| SaleOrdersService | 是 |
| SalesBillVoucherItemService | 否 |
| SalesBillVoucherService | 是 |
| SalesOrderItemService | 是 |
| CompanyCustomerEntityService | 否 |
| CompanyCustomerEvaluationFormFileService | 否 |
| CompanyCustomerFileService | 否 |
| CompanyCustomerFileTypeService | 否 |
| CustomerCatalogService | 否 |
| CustomerFileTypeService | 否 |
| CustomerService | 否 |
| BankService | 否 |
| DepartmentService | 否 |
| EmployeeAuthBindService | 否 |
| EmployeeLoginHistoryService | 否 |
| EmployeeRoleService | 否 |
| EmployeeService | 否 |
| FunctionService | 否 |
| InventoryCatalogService | 否 |
| InventoryHistoryPriceService | 否 |
| InventoryService | 否 |
| PermissionService | 否 |
| CustomerSatisfactionSurveyService | 否 |
| DeliverySignMethodService | 否 |
| ProductTypeService | 否 |
| ProductUsageService | 否 |
| ProjectBidService | 否 |
| ProjectCostItemService | 否 |
| ProjectCostService | 否 |
| ProjectFileService | 否 |
| ProjectFileTypeService | 否 |
| ProjectFundPlanService | 否 |
| ProjectIndustryService | 否 |
| ProjectQuotationService | 否 |
| ProjectSaleTypeRequireFileTypeService | 否 |
| ProjectSaleTypeService | 否 |
| ProjectService | 是 |
| ProjectTypeService | 否 |
| VendorApprovedFileService | 否 |
| VendorApprovedItemService | 否 |
| VendorApprovedService | 否 |
| VendorCatalogService | 否 |
| VendorEntityService | 否 |
| VendorFileService | 否 |
| VendorFileTypeService | 否 |
| VendorGroupRequireFileTypeService | 否 |
| VendorGroupService | 否 |
| VendorService | 否 |
| VendorTypeService | 否 |
## 分析结果
- 共找到81个实现了IEntityService接口的服务类
- 其中有12个类同时继承了EntityService类
- 大多数服务类69个仅实现了IEntityService接口没有继承EntityService类
继承EntityService类的服务类包括
- CloudRkService
- CloudTycService
- YongYouU8Service
- CompanyBankAccountService
- CompanyService
- ContractService
- SaleOrdersService
- SalesBillVoucherService
- SalesOrderItemService
- ProjectService
- 以及其他几个核心业务服务类