diff --git a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java index 98c14a2..bfc4278 100644 --- a/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java +++ b/server/src/main/java/com/ecep/contract/ds/company/service/CompanyBasicService.java @@ -18,6 +18,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.util.StringUtils; import com.ecep.contract.CustomerFileType; +import com.ecep.contract.EntityService; import com.ecep.contract.VendorFileType; import com.ecep.contract.SpringApp; import com.ecep.contract.ds.company.CompanyFileUtils; @@ -26,8 +27,9 @@ import com.ecep.contract.model.CompanyBasicFile; import com.ecep.contract.ds.customer.model.CompanyCustomerFile; import com.ecep.contract.ds.vendor.model.VendorFile; import com.ecep.contract.model.HolidayTable; +import com.ecep.contract.model.Voable; -public abstract class CompanyBasicService { +public abstract class CompanyBasicService, VO> extends EntityService { private static final Logger logger = LoggerFactory.getLogger(CompanyBasicService.class); /** @@ -458,4 +460,6 @@ public abstract class CompanyBasicService { */ protected abstract boolean isEvaluationFile(String fileName); + public abstract File getBasePath(); + } diff --git a/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileService.java b/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileService.java index ec627d2..63ab4e9 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileService.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileService.java @@ -8,12 +8,9 @@ import java.util.Optional; import com.ecep.contract.constant.ParamConstant; import com.ecep.contract.ds.company.service.HolidayService; -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; @@ -23,6 +20,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import com.ecep.contract.CustomerFileType; +import com.ecep.contract.EntityService; import com.ecep.contract.IEntityService; import com.ecep.contract.MessageHolder; import com.ecep.contract.QueryService; @@ -47,10 +45,9 @@ import jakarta.persistence.criteria.Path; @Lazy @Service @CacheConfig(cacheNames = "company-customer-file") -public class CompanyCustomerFileService - implements IEntityService, QueryService, +public class CompanyCustomerFileService extends EntityService + implements IEntityService, QueryService, VoableService { - private static final Logger logger = LoggerFactory.getLogger(CompanyCustomerFileService.class); @Lazy @Autowired private SysConfService confService; @@ -61,18 +58,32 @@ public class CompanyCustomerFileService @Autowired private CompanyCustomerEvaluationFormFileRepository companyCustomerEvaluationFormFileRepository; - @Cacheable(key = "#p0") - public CompanyCustomerFile findById(Integer id) { - return getById(id); + @Override + protected CompanyCustomerFileRepository getRepository() { + return companyCustomerFileRepository; } @Override - public CompanyCustomerFile getById(Integer id) { - return companyCustomerFileRepository.findById(id).orElse(null); + public CustomerFileVo findById(Integer id) { + return getRepository().findById(id).map(CompanyCustomerFile::toVo).orElse(null); } @Override - public Specification getSearchSpecification(String searchText) { + public CompanyCustomerFile createNewEntity() { + return new CompanyCustomerFile(); + } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + // field + spec = SpecificationUtils.andParam(spec, paramsNode, "customer"); + // spec = SpecificationUtils.andParam(spec, paramsNode, "company"); + return spec; + } + + @Override + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or(builder.like(root.get("filePath"), "%" + searchText + "%")); }; @@ -99,23 +110,6 @@ public class CompanyCustomerFileService return companyCustomerEvaluationFormFileRepository.save(formFile); } - @Override - public Page findAll(Specification spec, Pageable pageable) { - return companyCustomerFileRepository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "customer"); - // spec = SpecificationUtils.andParam(spec, paramsNode, "company"); - return findAll(spec, pageable); - } - public List findAllByCustomer(CompanyCustomer customer) { return companyCustomerFileRepository.findAllByCustomer(customer); } @@ -183,7 +177,8 @@ public class CompanyCustomerFileService LocalDate miniContractDate = LocalDate.of(2022, 1, 1); // 检索全部合同 ContractService contractService = SpringApp.getBean(ContractService.class); - List contractList = contractService.findAllByCompanyCustomer(companyCustomer, miniContractDate, LocalDate.now()); + List contractList = contractService.findAllByCompanyCustomer(companyCustomer, miniContractDate, + LocalDate.now()); if (contractList.isEmpty()) { holder.error("未发现已登记的合同"); return null; @@ -299,6 +294,4 @@ public class CompanyCustomerFileService } } - - } diff --git a/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileTypeService.java b/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileTypeService.java index 6ba7b3e..9a66d87 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileTypeService.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/service/CompanyCustomerFileTypeService.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import com.ecep.contract.CustomerFileType; +import com.ecep.contract.EntityService; import com.ecep.contract.IEntityService; import com.ecep.contract.QueryService; import com.ecep.contract.ds.customer.repository.CompanyCustomerFileTypeLocalRepository; @@ -31,33 +32,37 @@ import jakarta.annotation.Resource; @Lazy @Service @CacheConfig(cacheNames = "customer-file-type") -public class CompanyCustomerFileTypeService implements IEntityService, QueryService, +public class CompanyCustomerFileTypeService + extends EntityService + implements IEntityService, QueryService, VoableService { @Resource private CompanyCustomerFileTypeLocalRepository repository; + @Override + protected CompanyCustomerFileTypeLocalRepository getRepository() { + return repository; + } + + @Override + public CompanyCustomerFileTypeLocal createNewEntity() { + return new CompanyCustomerFileTypeLocal(); + } + @Cacheable(key = "#p0") @Override public CompanyCustomerFileTypeLocalVo findById(Integer id) { return repository.findById(id).map(CompanyCustomerFileTypeLocal::toVo).orElse(null); } - public CompanyCustomerFileTypeLocal getById(Integer id) { - return repository.findById(id).orElse(null); - } - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { + protected Specification buildParameterSpecification(JsonNode paramsNode) { Specification 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"), CustomerFileType.valueOf(paramsNode.get("type").asText()))); + spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), + CustomerFileType.valueOf(paramsNode.get("type").asText()))); } - // field - return findAll(spec, pageable).map(CompanyCustomerFileTypeLocal::toVo); + return spec; } @Cacheable(key = "'all-'+#p0.toLanguageTag()") @@ -65,26 +70,13 @@ public class CompanyCustomerFileTypeService implements IEntityService entry.getValue().toVo() - )); + entry -> entry.getValue().toVo())); } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { - return - // builder.or( - builder.like(root.get("type"), "%" + searchText + "%") - // ) - ; + return builder.like(root.get("type"), "%" + searchText + "%"); }; } diff --git a/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerCatalogService.java b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerCatalogService.java index 757a077..255bb10 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerCatalogService.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerCatalogService.java @@ -1,9 +1,20 @@ package com.ecep.contract.ds.customer.service; +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.context.annotation.Lazy; +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.constant.ParamConstant; import com.ecep.contract.ds.customer.repository.CustomerCatalogRepository; import com.ecep.contract.model.CustomerCatalog; import com.ecep.contract.service.ServiceException; @@ -11,20 +22,6 @@ import com.ecep.contract.service.VoableService; import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.CustomerCatalogVo; import com.fasterxml.jackson.databind.JsonNode; -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 org.springframework.util.StringUtils; - -import java.util.List; /** * 客户分类服务 @@ -32,7 +29,8 @@ import java.util.List; @Lazy @Service @CacheConfig(cacheNames = "customer-catalog") -public class CustomerCatalogService extends EntityService implements IEntityService, QueryService, +public class CustomerCatalogService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired @@ -49,23 +47,22 @@ public class CustomerCatalogService extends EntityService buildParameterSpecification(JsonNode paramsNode) { + protected org.springframework.data.jpa.domain.Specification buildParameterSpecification( + JsonNode paramsNode) { org.springframework.data.jpa.domain.Specification spec = null; spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code", "name", "description"); return spec; } @Override - protected org.springframework.data.jpa.domain.Specification buildSearchSpecification(String searchText) { - return getSearchSpecification(searchText); - } - - /** - * 根据 id 查找 CustomerCatalog - */ - @Override - public CustomerCatalog getById(Integer id) { - return repository.findById(id).orElse(null); + protected Specification buildSearchSpecification(String searchText) { + String likeText = "%" + searchText + "%"; + return (root, query, builder) -> { + return builder.or( + builder.like(root.get("code"), likeText), + builder.like(root.get("name"), likeText), + builder.like(root.get("description"), likeText)); + }; } @Cacheable(key = "#p0") @@ -132,49 +129,6 @@ public class CustomerCatalogService extends EntityService findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - - // 字段等值查询 - spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code", "name", "description"); - return repository.findAll(spec, pageable).map(CustomerCatalog::toVo); - } - - /** - * 根据搜索文本创建查询条件 - */ - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - String likeText = "%" + searchText + "%"; - return (root, query, builder) -> { - return builder.or( - builder.like(root.get("code"), likeText), - builder.like(root.get("name"), likeText), - builder.like(root.get("description"), likeText)); - }; - } - - /** - * 搜索 CustomerCatalog - */ - public List search(String searchText) { - return repository.findAll(getSearchSpecification(searchText), Pageable.ofSize(10)).getContent(); - } - - @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - @Override public void updateByVo(CustomerCatalog model, CustomerCatalogVo vo) { // 参数校验 diff --git a/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerFileTypeService.java b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerFileTypeService.java index cb14786..99c7619 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerFileTypeService.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerFileTypeService.java @@ -17,6 +17,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import com.ecep.contract.CustomerFileType; +import com.ecep.contract.EntityService; import com.ecep.contract.IEntityService; import com.ecep.contract.QueryService; import com.ecep.contract.ds.customer.repository.CustomerFileTypeLocalRepository; @@ -31,26 +32,30 @@ import com.ecep.contract.vo.CustomerFileTypeLocalVo; @Lazy @Service @CacheConfig(cacheNames = "customer-file-type") -public class CustomerFileTypeService implements IEntityService, QueryService, +public class CustomerFileTypeService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private CustomerFileTypeLocalRepository repository; @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { + protected Specification buildSearchSpecification(String searchText) { + return (root, query, builder) -> { + return builder.like(root.get("type"), "%" + searchText + "%"); + }; + } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { Specification 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"), CustomerFileType.valueOf(paramsNode.get("type").asText()))); + spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), + CustomerFileType.valueOf(paramsNode.get("type").asText()))); } - // field spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value"); - return findAll(spec, pageable).map(CustomerFileTypeLocal::toVo); + return spec; } @Cacheable(key = "#p0") @@ -59,36 +64,22 @@ public class CustomerFileTypeService implements IEntityService findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - @Cacheable(key = "'all-'+#p0.toLanguageTag()") public Map findAll(Locale locale) { return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream() .collect(java.util.stream.Collectors.toMap( java.util.Map.Entry::getKey, - entry -> entry.getValue().toVo() - )); + entry -> entry.getValue().toVo())); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - return (root, query, builder) -> { - return - // builder.or( - builder.like(root.get("type"), "%" + searchText + "%") - // ) - ; - }; + protected CustomerFileTypeLocalRepository getRepository() { + return repository; + } + + @Override + public CustomerFileTypeLocal createNewEntity() { + return new CustomerFileTypeLocal(); } @Caching(evict = { diff --git a/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java index 98743fb..8ea7ab8 100644 --- a/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java +++ b/server/src/main/java/com/ecep/contract/ds/customer/service/CustomerService.java @@ -28,6 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import com.ecep.contract.CustomerFileType; +import com.ecep.contract.EntityService; import com.ecep.contract.IEntityService; import com.ecep.contract.MessageHolder; import com.ecep.contract.QueryService; @@ -59,7 +60,8 @@ import jakarta.persistence.criteria.Path; @Lazy @Service @CacheConfig(cacheNames = "company-customer") -public class CustomerService extends CompanyBasicService +public class CustomerService extends CompanyBasicService // EntityService implements IEntityService, QueryService, VoableService { private static final Logger logger = LoggerFactory.getLogger(CustomerService.class); @@ -77,49 +79,21 @@ public class CustomerService extends CompanyBasicService @Autowired private CompanyCustomerEntityService companyCustomerEntityService; - public CompanyCustomer findByCompany(Company company) { - return repository.findByCompany(company).orElse(null); - } - - public CustomerVo findByCompany(CompanyVo company) { - return repository.findByCompanyId(company.getId()).map(CompanyCustomer::toVo).orElse(null); - } - - @Override - public CompanyCustomer getById(Integer id) { - return repository.findById(id).orElse(null); - } - - @Cacheable(key = "#p0") - public CustomerVo findById(Integer id) { - return repository.findById(id).map(CompanyCustomer::toVo).orElse(null); - } - - @Caching(evict = { - @CacheEvict(key = "#p0.id") - }) - public CompanyCustomer save(CompanyCustomer companyCustomer) { - return repository.save(companyCustomer); - } - - @Caching(evict = { - @CacheEvict(key = "#p0") - }) - @Override - public void delete(CompanyCustomer entity) { - repository.delete(entity); + protected CompanyCustomerRepository getRepository() { + return repository; } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + public CompanyCustomer createNewEntity() { + return new CompanyCustomer(); + } + @Override + protected Specification buildSearchSpecification(String searchText) { Specification nameSpec = (root, query, builder) -> { Path company = root.get("company"); - return companyService.buildSearchPredicate(searchText, company, query, builder); + return SpringApp.getBean(CompanyService.class).buildSearchPredicate(searchText, company, query, builder); }; // 判断是否全是数字 if (MyStringUtils.isAllDigit(searchText)) { @@ -147,9 +121,40 @@ public class CustomerService extends CompanyBasicService } @Override - public List search(String searchText) { - Specification spec = getSearchSpecification(searchText); - return repository.findAll(spec, Pageable.ofSize(10)).getContent(); + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + // field + spec = SpecificationUtils.andParam(spec, paramsNode, "company"); + return spec; + } + + public CompanyCustomer findByCompany(Company company) { + return repository.findByCompany(company).orElse(null); + } + + public CustomerVo findByCompany(CompanyVo company) { + return repository.findByCompanyId(company.getId()).map(CompanyCustomer::toVo).orElse(null); + } + + @Cacheable(key = "#p0") + public CustomerVo findById(Integer id) { + return repository.findById(id).map(CompanyCustomer::toVo).orElse(null); + } + + @Caching(evict = { + @CacheEvict(key = "#p0.id") + }) + @Override + public CompanyCustomer save(CompanyCustomer companyCustomer) { + return repository.save(companyCustomer); + } + + @Caching(evict = { + @CacheEvict(key = "#p0") + }) + @Override + public void delete(CompanyCustomer entity) { + repository.delete(entity); } @Override @@ -158,6 +163,7 @@ public class CustomerService extends CompanyBasicService companyCustomerFileService.delete(customerFile); } + @Override public File getBasePath() { return new File(confService.getString(CompanyCustomerConstant.KEY_BASE_PATH)); } @@ -199,7 +205,7 @@ public class CustomerService extends CompanyBasicService @SuppressWarnings("unchecked") @Override protected > boolean fillFileAsDefaultType(F dbFile, File file, - Consumer status) { + Consumer status) { dbFile.setType((T) CustomerFileType.General); fillFile(dbFile, file, null, status); companyCustomerFileService.save((CompanyCustomerFile) dbFile); @@ -208,7 +214,7 @@ public class CustomerService extends CompanyBasicService @Override protected > boolean fillFileAsEvaluationFile(F customerFile, File file, - List fileList, Consumer status) { + List fileList, Consumer status) { boolean modified = super.fillFileAsEvaluationFile(customerFile, file, fileList, status); if (fileList != null) { @@ -242,7 +248,7 @@ public class CustomerService extends CompanyBasicService } private > void updateEvaluationFileByJsonFile(F customerFile, File jsonFile, - Consumer status) throws IOException { + Consumer status) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); JsonNode root = objectMapper.readTree(jsonFile); if (!root.isObject()) { @@ -268,7 +274,7 @@ public class CustomerService extends CompanyBasicService @SuppressWarnings("unchecked") @Override protected > F fillFileType(File file, List fileList, - Consumer status) { + Consumer status) { CompanyCustomerFile customerFile = new CompanyCustomerFile(); customerFile.setType(CustomerFileType.General); if (fillFile(customerFile, file, fileList, status)) { @@ -292,7 +298,7 @@ public class CustomerService extends CompanyBasicService return (fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME1) || fileName.contains(CompanyCustomerConstant.EVALUATION_FORM_NAME2)) && (FileUtils.withExtensions(fileName, FileUtils.JPG, FileUtils.JPEG, - FileUtils.PDF)); + FileUtils.PDF)); } public boolean makePathAbsent(CompanyCustomer companyCustomer) { @@ -335,21 +341,6 @@ public class CustomerService extends CompanyBasicService return dir; } - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "company"); - return findAll(spec, pageable).map(CompanyCustomer::toVo); - } - /** * 将一个公司的客户信息转移到另一个公司,并保存在数据库中 * diff --git a/server/src/main/java/com/ecep/contract/ds/other/repository/InventoryCatalogRepository.java b/server/src/main/java/com/ecep/contract/ds/other/repository/InventoryCatalogRepository.java index ea3078b..723c5dc 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/repository/InventoryCatalogRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/other/repository/InventoryCatalogRepository.java @@ -2,14 +2,13 @@ package com.ecep.contract.ds.other.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.InventoryCatalog; @Repository -public interface InventoryCatalogRepository extends JpaRepository, JpaSpecificationExecutor { +public interface InventoryCatalogRepository extends MyRepository { Optional findByCode(String code); Optional findByName(String name); diff --git a/server/src/main/java/com/ecep/contract/ds/other/repository/PermissionRepository.java b/server/src/main/java/com/ecep/contract/ds/other/repository/PermissionRepository.java index 9fdf39a..61dc77b 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/repository/PermissionRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/other/repository/PermissionRepository.java @@ -3,24 +3,15 @@ package com.ecep.contract.ds.other.repository; import java.util.List; import org.springframework.context.annotation.Lazy; -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.model.Permission; @Lazy @Repository -public interface PermissionRepository extends - // JDBC interfaces - CrudRepository, PagingAndSortingRepository, - // JPA interfaces - JpaRepository, JpaSpecificationExecutor { - +public interface PermissionRepository extends MyRepository { List findAllByFunctionId(Integer functionId); - } diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/BankService.java b/server/src/main/java/com/ecep/contract/ds/other/service/BankService.java index 2239628..fca4dc2 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/BankService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/BankService.java @@ -1,19 +1,12 @@ package com.ecep.contract.ds.other.service; -import java.util.List; -import java.util.Optional; - 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.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.jpa.domain.Specification; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; import com.ecep.contract.EntityService; import com.ecep.contract.IEntityService; @@ -21,14 +14,15 @@ import com.ecep.contract.QueryService; import com.ecep.contract.ds.other.repository.BankRepository; import com.ecep.contract.model.Bank; import com.ecep.contract.service.VoableService; +import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.BankVo; import com.fasterxml.jackson.databind.JsonNode; -import com.ecep.contract.util.SpecificationUtils; @Lazy @Service @CacheConfig(cacheNames = "bank") -public class BankService extends EntityService implements IEntityService, QueryService, VoableService { +public class BankService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private BankRepository bankRepository; @@ -52,44 +46,6 @@ public class BankService extends EntityService implements @Override protected org.springframework.data.jpa.domain.Specification buildSearchSpecification(String searchText) { - return getSearchSpecification(searchText); - } - - @Cacheable(key = "#id") - public BankVo findById(Integer id) { - return bankRepository.findById(id).map(Bank::toVo).orElse(null); - } - - public Bank getById(Integer id) { - return bankRepository.findById(id).orElse(null); - } - - public Page findAll(Specification spec, Pageable pageable) { - return bankRepository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - return findAll(spec, pageable).map(Bank::toVo); - } - - - - @Override - public long count(JsonNode paramsNode) { - return bankRepository.count(); - } - - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } return (root, query, builder) -> { return builder.or( builder.like(root.get("code"), "%" + searchText + "%"), @@ -97,9 +53,9 @@ public class BankService extends EntityService implements }; } - public List search(String searchText) { - Specification spec = getSearchSpecification(searchText); - return bankRepository.findAll(spec, Pageable.ofSize(10)).getContent(); + @Cacheable(key = "#id") + public BankVo findById(Integer id) { + return bankRepository.findById(id).map(Bank::toVo).orElse(null); } public Bank findByName(String name) { diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/DepartmentService.java b/server/src/main/java/com/ecep/contract/ds/other/service/DepartmentService.java index 614bf3a..ef1796d 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/DepartmentService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/DepartmentService.java @@ -73,25 +73,11 @@ public class DepartmentService extends EntityService findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - public List search(String searchText) { - Specification spec = getSearchSpecification(searchText); - return repository.findAll(spec, Pageable.ofSize(10)).getContent(); - } - @Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'code-'+#p0.code") diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeAuthBindService.java b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeAuthBindService.java index f0bb2c2..99038d4 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeAuthBindService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeAuthBindService.java @@ -13,6 +13,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; @@ -28,26 +29,25 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "employee-auth-bind") -public class EmployeeAuthBindService implements IEntityService, QueryService, +public class EmployeeAuthBindService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private EmployeeAuthBindRepository repository; @Override - public EmployeeAuthBindVo findById(Integer id) { - return repository.findById(id).map(EmployeeAuthBind::toVo).orElse(null); - } - - public EmployeeAuthBind getById(Integer id) { - return repository.findById(id).orElse(null); + protected EmployeeAuthBindRepository getRepository() { + return repository; } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + public EmployeeAuthBind createNewEntity() { + return new EmployeeAuthBind(); + } + + @Override + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("ip"), "%" + searchText + "%"), @@ -57,19 +57,16 @@ public class EmployeeAuthBindService implements IEntityService } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + // 可以根据需要添加更多参数处理 + spec = SpecificationUtils.andParam(spec, paramsNode, "employee"); + return null; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - spec = SpecificationUtils.andParam(spec, paramsNode, "employee"); - return findAll(spec, pageable).map(EmployeeAuthBind::toVo); + public EmployeeAuthBindVo findById(Integer id) { + return repository.findById(id).map(EmployeeAuthBind::toVo).orElse(null); } @Override diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeLoginHistoryService.java b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeLoginHistoryService.java index 9440883..3a9d572 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeLoginHistoryService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeLoginHistoryService.java @@ -1,16 +1,15 @@ package com.ecep.contract.ds.other.service; -import java.util.Optional; - 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.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 +24,7 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "employee-login-history") -public class EmployeeLoginHistoryService +public class EmployeeLoginHistoryService extends EntityService implements IEntityService, QueryService, VoableService { @Lazy @@ -33,19 +32,17 @@ public class EmployeeLoginHistoryService private EmployeeLoginHistoryRepository repository; @Override - public EmployeeLoginHistoryVo findById(Integer id) { - return repository.findById(id).map(EmployeeLoginHistory::toVo).orElse(null); - } - - public EmployeeLoginHistory getById(Integer id) { - return repository.findById(id).orElse(null); + protected EmployeeLoginHistoryRepository getRepository() { + return repository; } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + public EmployeeLoginHistory createNewEntity() { + return new EmployeeLoginHistory(); + } + + @Override + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("ip"), "%" + searchText + "%"), @@ -54,8 +51,17 @@ public class EmployeeLoginHistoryService } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + // 可以根据需要添加更多参数处理 + spec = SpecificationUtils.andParam(spec, paramsNode, "employee"); + spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "ip", "mac"); + return spec; + } + + @Override + public EmployeeLoginHistoryVo findById(Integer id) { + return repository.findById(id).map(EmployeeLoginHistory::toVo).orElse(null); } @Override @@ -71,11 +77,7 @@ public class EmployeeLoginHistoryService } @Override - public void delete(EmployeeLoginHistory entity) { - repository.delete(entity); - } - - @Override + @CacheEvict(key = "#p0.id") public EmployeeLoginHistory save(EmployeeLoginHistory entity) { return repository.save(entity); } diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeRoleService.java b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeRoleService.java index 0a2e668..f7f17aa 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeRoleService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeRoleService.java @@ -3,27 +3,25 @@ package com.ecep.contract.ds.other.service; import java.util.List; import java.util.Optional; -import com.ecep.contract.vo.FunctionVo; 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.service.VoableService; -import com.fasterxml.jackson.databind.JsonNode; import com.ecep.contract.ds.other.repository.EmployeeRoleRepository; import com.ecep.contract.model.EmployeeRole; import com.ecep.contract.model.Function; +import com.ecep.contract.service.VoableService; import com.ecep.contract.vo.EmployeeRoleVo; +import com.ecep.contract.vo.FunctionVo; +import com.fasterxml.jackson.databind.JsonNode; import jakarta.transaction.Transactional; @@ -32,7 +30,8 @@ import jakarta.transaction.Transactional; */ @Service @CacheConfig(cacheNames = "employee-role") -public class EmployeeRoleService implements IEntityService, QueryService, +public class EmployeeRoleService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired @@ -41,20 +40,18 @@ public class EmployeeRoleService implements IEntityService, QueryS @Autowired private FunctionService functionService; - @Cacheable(key = "#p0") - public EmployeeRoleVo findById(Integer id) { - return roleRepository.findById(id).map(EmployeeRole::toVo).orElse(null); - } - - public EmployeeRole getById(Integer id) { - return roleRepository.findById(id).orElse(null); + @Override + protected EmployeeRoleRepository getRepository() { + return roleRepository; } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + public EmployeeRole createNewEntity() { + return new EmployeeRole(); + } + + @Override + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("code"), "%" + searchText + "%"), @@ -62,6 +59,11 @@ public class EmployeeRoleService implements IEntityService, QueryS }; } + @Cacheable(key = "#p0") + public EmployeeRoleVo findById(Integer id) { + return roleRepository.findById(id).map(EmployeeRole::toVo).orElse(null); + } + @Cacheable(key = "'code-'+#p0") public EmployeeRoleVo findByCode(String code) { return roleRepository.findByCode(code).map(EmployeeRole::toVo).orElse(null); @@ -84,18 +86,8 @@ public class EmployeeRoleService implements IEntityService, QueryS } @Override - public Page findAll(Specification spec, Pageable pageable) { - return roleRepository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - return findAll(spec, pageable).map(EmployeeRole::toVo); + protected Specification buildParameterSpecification(JsonNode paramsNode) { + return null; } @Transactional diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeService.java b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeService.java index 16a9db1..d4148f5 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/EmployeeService.java @@ -29,7 +29,6 @@ import com.ecep.contract.service.VoableService; import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.EmployeeVo; import com.fasterxml.jackson.databind.JsonNode; -import com.ecep.contract.util.SpecificationUtils; import jakarta.transaction.Transactional; @@ -58,7 +57,8 @@ public class EmployeeService extends EntityService buildParameterSpecification(JsonNode paramsNode) { + protected org.springframework.data.jpa.domain.Specification buildParameterSpecification( + JsonNode paramsNode) { org.springframework.data.jpa.domain.Specification spec = null; spec = SpecificationUtils.andParam(spec, paramsNode, "department"); spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "isActive"); @@ -85,10 +85,6 @@ public class EmployeeService extends EntityService findAll(Specification spec, Pageable pageable) { - return employeeRepository.findAll(spec, pageable); - } - @Override public Page findAll(JsonNode paramsNode, Pageable pageable) { Specification spec = null; @@ -185,11 +176,6 @@ public class EmployeeService extends EntityService search(String searchText) { - // 创建一个Specification对象,用于定义复杂的查询条件 - Specification spec = getSearchSpecification(searchText); - return employeeRepository.findAll(spec, Pageable.ofSize(10)).getContent(); - } @Transactional public List getRolesByEmployeeId(Integer employeeId) { @@ -209,7 +195,7 @@ public class EmployeeService extends EntityService, QueryService, VoableService { +public class FunctionService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private FunctionRepository repository; @@ -34,14 +33,11 @@ public class FunctionService implements IEntityService, QueryService, QueryService findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + protected FunctionRepository getRepository() { + return repository; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - return findAll(spec, pageable).map(Function::toVo); + public Function createNewEntity() { + return new Function(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("key"), "%" + searchText + "%"), builder.like(root.get("name"), "%" + searchText + "%"), builder.like(root.get("controller"), "%" + searchText + "%"), - builder.like(root.get("icon"), "%" + searchText + "%") - ); + builder.like(root.get("icon"), "%" + searchText + "%")); }; } @@ -93,4 +81,9 @@ public class FunctionService implements IEntityService, QueryService buildParameterSpecification(JsonNode paramsNode) { + throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'"); + } +} \ No newline at end of file diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/InventoryCatalogService.java b/server/src/main/java/com/ecep/contract/ds/other/service/InventoryCatalogService.java index f468c3b..b67f664 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/InventoryCatalogService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/InventoryCatalogService.java @@ -1,7 +1,6 @@ package com.ecep.contract.ds.other.service; import java.util.List; -import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; @@ -17,6 +16,7 @@ import org.springframework.util.StringUtils; import com.ecep.contract.IEntityService; import com.ecep.contract.QueryService; +import com.ecep.contract.EntityService; import com.ecep.contract.ds.other.repository.InventoryCatalogRepository; import com.ecep.contract.model.InventoryCatalog; import com.ecep.contract.service.VoableService; @@ -26,7 +26,8 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "inventory-catalog") -public class InventoryCatalogService implements IEntityService, QueryService, +public class InventoryCatalogService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired @@ -36,10 +37,6 @@ public class InventoryCatalogService implements IEntityService public InventoryCatalogVo findById(Integer id) { return repository.findById(id).map(InventoryCatalog::toVo).orElse(null); } - - public InventoryCatalog getById(Integer id) { - return repository.findById(id).orElse(null); - } @Cacheable(key = "'code-'+#p0") public InventoryCatalogVo findByCode(String code) { @@ -51,50 +48,35 @@ public class InventoryCatalogService implements IEntityService return repository.findByName(name).map(InventoryCatalog::toVo).orElse(null); } - @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - return findAll(spec, pageable).map(InventoryCatalog::toVo); - } - - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - return (root, query, builder) -> { - return builder.or( - builder.like(root.get("code"), "%" + searchText + "%"), - builder.like(root.get("name"), "%" + searchText + "%")); - }; - } - - public List search(String searchText) { - Specification spec = (root, query, builder) -> { - return builder.or(builder.like(root.get("code"), "%" + searchText + "%"), - builder.like(root.get("name"), "%" + searchText + "%")); - }; - return repository.findAll(spec, Pageable.ofSize(10)).getContent(); - } - @Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'code-'+#p0.code"), @CacheEvict(key = "'name-'+#p0.code") }) + @Override public InventoryCatalog save(InventoryCatalog entity) { return repository.save(entity); } + @Override + protected InventoryCatalogRepository getRepository() { + return repository; + } + + @Override + public InventoryCatalog createNewEntity() { + return new InventoryCatalog(); + } + + @Override + protected Specification buildSearchSpecification(String searchText) { + return (root, query, builder) -> { + return builder.or( + builder.like(root.get("code"), "%" + searchText + "%"), + builder.like(root.get("name"), "%" + searchText + "%")); + }; + } + @Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'code-'+#p0.code"), @@ -111,4 +93,9 @@ public class InventoryCatalogService implements IEntityService model.setName(vo.getName()); // 其他属性根据实际需要添加 } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'"); + } } diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/InventoryHistoryPriceService.java b/server/src/main/java/com/ecep/contract/ds/other/service/InventoryHistoryPriceService.java index 71fc31b..20a307b 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/InventoryHistoryPriceService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/InventoryHistoryPriceService.java @@ -5,6 +5,8 @@ import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import com.ecep.contract.EntityService; import org.springframework.context.annotation.Lazy; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -26,7 +28,7 @@ import jakarta.persistence.criteria.Path; @Lazy @Service @CacheConfig(cacheNames = "inventory-history-price") -public class InventoryHistoryPriceService +public class InventoryHistoryPriceService extends EntityService implements IEntityService, QueryService, VoableService { @Lazy @@ -41,16 +43,35 @@ public class InventoryHistoryPriceService public InventoryHistoryPriceVo findById(Integer id) { return repository.findById(id).map(InventoryHistoryPrice::toVo).orElse(null); } - - public InventoryHistoryPrice getById(Integer id) { - return repository.findById(id).orElse(null); + + public List findAllByInventory(Inventory inventory) { + return repository.findAllByInventory(inventory); + } + + @CacheEvict(key = "#p0.id") + @Override + public void delete(InventoryHistoryPrice entity) { + repository.delete(entity); + } + + @CacheEvict(key = "#p0.id") + @Override + public InventoryHistoryPrice save(InventoryHistoryPrice entity) { + return repository.save(entity); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected InventoryHistoryPriceRepository getRepository() { + return repository; + } + + @Override + public InventoryHistoryPrice createNewEntity() { + return new InventoryHistoryPrice(); + } + + @Override + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { Path inventory = root.get("inventory"); return builder.or( @@ -59,35 +80,6 @@ public class InventoryHistoryPriceService }; } - @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - return findAll(spec, pageable).map(InventoryHistoryPrice::toVo); - } - - public List findAllByInventory(Inventory inventory) { - return repository.findAllByInventory(inventory); - } - - @Override - public void delete(InventoryHistoryPrice entity) { - repository.delete(entity); - } - - @Override - public InventoryHistoryPrice save(InventoryHistoryPrice entity) { - return repository.save(entity); - } - @Override public void updateByVo(InventoryHistoryPrice entity, InventoryHistoryPriceVo vo) { if (entity == null || vo == null) { @@ -151,4 +143,9 @@ public class InventoryHistoryPriceService } } + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'"); + } + } diff --git a/server/src/main/java/com/ecep/contract/ds/other/service/PermissionService.java b/server/src/main/java/com/ecep/contract/ds/other/service/PermissionService.java index 53c0c83..52e87f0 100644 --- a/server/src/main/java/com/ecep/contract/ds/other/service/PermissionService.java +++ b/server/src/main/java/com/ecep/contract/ds/other/service/PermissionService.java @@ -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.SpringApp; @@ -28,7 +26,7 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "permission") -public class PermissionService +public class PermissionService extends EntityService implements IEntityService, QueryService, VoableService { @Lazy @@ -42,21 +40,6 @@ public class PermissionService return permissionRepository.findById(id).map(Permission::toVo).orElse(null); } - public Permission getById(Integer id) { - return permissionRepository.findById(id).orElse(null); - } - - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - return (root, query, builder) -> { - return builder.or( - builder.like(root.get("name"), "%" + searchText + "%")); - }; - } - @Cacheable(key = "'permission-code-'+#p0") public Permission findByCode(String code) { // return permissionRepository.findByCode(code).orElse(null); @@ -67,25 +50,12 @@ public class PermissionService @CacheEvict(key = "'permission-'+#p0.id"), // @CacheEvict(key = "'permission-code-'+#p0.code") }) + @Override public Permission save(Permission role) { return permissionRepository.save(role); } - @Override - public Page findAll(Specification spec, Pageable pageable) { - return permissionRepository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // 可以根据需要添加更多参数处理 - return findAll(spec, pageable).map(Permission::toVo); - } - + @CacheEvict(key = "'permission-'+#p0.id") @Override public void delete(Permission entity) { permissionRepository.delete(entity); @@ -95,6 +65,24 @@ public class PermissionService return permissionRepository.findAllByFunctionId(functionId); } + @Override + protected PermissionRepository getRepository() { + return permissionRepository; + } + + @Override + public Permission createNewEntity() { + return new Permission(); + } + + @Override + protected Specification buildSearchSpecification(String searchText) { + return (root, query, builder) -> { + return builder.or( + builder.like(root.get("name"), "%" + searchText + "%")); + }; + } + @Override public void updateByVo(Permission permission, PermissionVo vo) { // 映射基本属性 @@ -121,4 +109,9 @@ public class PermissionService // 如果需要处理,可以添加日志记录或者其他逻辑 } + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'"); + } + } diff --git a/server/src/main/java/com/ecep/contract/ds/project/repository/CustomerSatisfactionSurveyRepository.java b/server/src/main/java/com/ecep/contract/ds/project/repository/CustomerSatisfactionSurveyRepository.java index b92ffaf..f00fae8 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/repository/CustomerSatisfactionSurveyRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/project/repository/CustomerSatisfactionSurveyRepository.java @@ -1,18 +1,16 @@ package com.ecep.contract.ds.project.repository; -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.customer.model.CustomerSatisfactionSurvey; /** * 项目客户满意度调查数据访问层 */ @Repository -public interface CustomerSatisfactionSurveyRepository - extends JpaRepository, - JpaSpecificationExecutor { - - // 可以在这里添加自定义查询方法 +public interface CustomerSatisfactionSurveyRepository + extends MyRepository { + + // 可以在这里添加自定义查询方法 } diff --git a/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostItemRepository.java b/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostItemRepository.java index 65c1d1a..8ccfeca 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostItemRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostItemRepository.java @@ -2,15 +2,14 @@ package com.ecep.contract.ds.project.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.ds.project.model.ProjectCost; import com.ecep.contract.ds.project.model.ProjectCostItem; @Repository -public interface ProjectCostItemRepository extends JpaRepository, JpaSpecificationExecutor { +public interface ProjectCostItemRepository extends MyRepository { /** * 根据项目成本查询项目成本条目 */ diff --git a/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostRepository.java b/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostRepository.java index 4c9daf0..855ac6b 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostRepository.java +++ b/server/src/main/java/com/ecep/contract/ds/project/repository/ProjectCostRepository.java @@ -3,16 +3,15 @@ package com.ecep.contract.ds.project.repository; import java.util.List; 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.contract.model.Contract; import com.ecep.contract.ds.project.model.Project; import com.ecep.contract.ds.project.model.ProjectCost; @Repository -public interface ProjectCostRepository extends JpaRepository, JpaSpecificationExecutor { +public interface ProjectCostRepository extends MyRepository { /** * 根据合同查询 * diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/CustomerSatisfactionSurveyService.java b/server/src/main/java/com/ecep/contract/ds/project/service/CustomerSatisfactionSurveyService.java index 9c824b6..b2aae05 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/CustomerSatisfactionSurveyService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/CustomerSatisfactionSurveyService.java @@ -2,9 +2,9 @@ package com.ecep.contract.ds.project.service; import java.util.List; -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.context.annotation.Lazy; import org.springframework.data.domain.Page; @@ -13,14 +13,17 @@ 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.other.service.EmployeeService; -import com.ecep.contract.ds.project.repository.CustomerSatisfactionSurveyRepository; +import com.ecep.contract.constant.ParamConstant; +import com.ecep.contract.ds.MyRepository; import com.ecep.contract.ds.customer.model.CustomerSatisfactionSurvey; -import com.ecep.contract.model.Employee; +import com.ecep.contract.ds.other.service.EmployeeService; import com.ecep.contract.ds.project.model.Project; +import com.ecep.contract.ds.project.repository.CustomerSatisfactionSurveyRepository; +import com.ecep.contract.model.Employee; import com.ecep.contract.service.VoableService; import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.CustomerSatisfactionSurveyVo; @@ -33,6 +36,7 @@ import com.fasterxml.jackson.databind.JsonNode; @Service @CacheConfig(cacheNames = "customer-satisfaction-survey") public class CustomerSatisfactionSurveyService + extends EntityService implements IEntityService, QueryService, VoableService { @Lazy @@ -40,8 +44,13 @@ public class CustomerSatisfactionSurveyService private CustomerSatisfactionSurveyRepository repository; @Override - public CustomerSatisfactionSurvey getById(Integer id) { - return repository.findById(id).orElse(null); + protected MyRepository getRepository() { + return repository; + } + + @Override + public CustomerSatisfactionSurvey createNewEntity() { + return new CustomerSatisfactionSurvey(); } /** @@ -61,16 +70,25 @@ public class CustomerSatisfactionSurveyService } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.like(root.get("code"), "%" + searchText + "%"); }; } - ; + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + if (paramsNode.has("project.customer")) { + int customerId = paramsNode.get("project.customer").asInt(); + spec = SpecificationUtils.and(spec, (root, query, builder) -> { + return builder.equal(root.get("project").get("customer").get("id"), customerId); + }); + } + // field + spec = SpecificationUtils.andParam(spec, paramsNode, "project", "applicant"); + return spec; + } /** * 保存客户满意度调查 @@ -78,6 +96,8 @@ public class CustomerSatisfactionSurveyService * @param survey 客户满意度调查实体 * @return 保存后的实体 */ + @CacheEvict(key = "#p0.id") + @Override public CustomerSatisfactionSurvey save(CustomerSatisfactionSurvey survey) { return repository.save(survey); } @@ -87,6 +107,8 @@ public class CustomerSatisfactionSurveyService * * @param survey 客户满意度调查实体 */ + @CacheEvict(key = "#p0.id") + @Override public void delete(CustomerSatisfactionSurvey survey) { repository.delete(survey); } @@ -98,9 +120,6 @@ public class CustomerSatisfactionSurveyService * @param pageable 分页参数 * @return 客户满意度调查分页列表 */ - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } /** * 根据条件查找所有客户满意度调查 @@ -113,25 +132,6 @@ public class CustomerSatisfactionSurveyService return entities.stream().map(CustomerSatisfactionSurvey::toVo).toList(); } - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - - if (paramsNode.has("project.customer")) { - int customerId = paramsNode.get("project.customer").asInt(); - spec = SpecificationUtils.and(spec, (root, query, builder) -> { - return builder.equal(root.get("project").get("customer").get("id"), customerId); - }); - } - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "project", "applicant"); - Page page = findAll(spec, pageable); - return page.map(CustomerSatisfactionSurvey::toVo); - } - @Override public void updateByVo(CustomerSatisfactionSurvey model, CustomerSatisfactionSurveyVo vo) { model.setCode(vo.getCode()); diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/DeliverySignMethodService.java b/server/src/main/java/com/ecep/contract/ds/project/service/DeliverySignMethodService.java index 94526af..79aae60 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/DeliverySignMethodService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/DeliverySignMethodService.java @@ -15,9 +15,11 @@ import org.springframework.data.domain.Sort; 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; +import com.ecep.contract.ds.MyRepository; import com.ecep.contract.ds.project.repository.ProductDeliverySignMethodRepository; import com.ecep.contract.model.DeliverySignMethod; import com.ecep.contract.model.ProjectSaleType; @@ -30,18 +32,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-sign-method") -public class DeliverySignMethodService +public class DeliverySignMethodService extends EntityService implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProductDeliverySignMethodRepository deliverySignMethodRepository; - @Override - public DeliverySignMethod getById(Integer id) { - return deliverySignMethodRepository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public DeliverySignMethodVo findById(Integer id) { @@ -52,39 +49,20 @@ public class DeliverySignMethodService return null; } - @Override - public Page findAll(Specification spec, Pageable pageable) { - return deliverySignMethodRepository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "saleType"); - Page page = findAll(spec, pageable); - return page.map(DeliverySignMethod::toVo); - } - public DeliverySignMethod findBySaleTypeAndName(ProjectSaleType saleType, String name) { return deliverySignMethodRepository.findBySaleTypeAndName(saleType, name).orElse(null); } @Cacheable(key = "'type-'+#p0.id+'_code-'+#p1") public DeliverySignMethodVo findBySaleTypeAndCode(ProjectSaleType saleType, String code) { - return deliverySignMethodRepository.findBySaleTypeAndCode(saleType, code).map(DeliverySignMethod::toVo).orElse(null); + return deliverySignMethodRepository.findBySaleTypeAndCode(saleType, code).map(DeliverySignMethod::toVo) + .orElse(null); } @Cacheable(key = "'type-'+#p0.id+'_code-'+#p1") public DeliverySignMethodVo findBySaleTypeAndCode(ProjectSaleTypeVo saleType, String code) { - return deliverySignMethodRepository.findBySaleTypeIdAndCode(saleType.getId(), code).map(DeliverySignMethod::toVo).orElse(null); - } - - public List findAll(Specification spec, Sort sort) { - return deliverySignMethodRepository.findAll(spec, sort); + return deliverySignMethodRepository.findBySaleTypeIdAndCode(saleType.getId(), code) + .map(DeliverySignMethod::toVo).orElse(null); } @Cacheable(key = "'all'") @@ -116,9 +94,29 @@ public class DeliverySignMethodService deliverySignMethodRepository.delete(method); } + @Override + protected MyRepository getRepository() { + return deliverySignMethodRepository; + } + + @Override + public DeliverySignMethod createNewEntity() { + return new DeliverySignMethod(); + } + + @Override + protected Specification 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 + "%")); + }; + } + @Override public Specification getSearchSpecification(String searchText) { - return null; + return super.getSearchSpecification(searchText); } @Override @@ -142,4 +140,11 @@ public class DeliverySignMethodService } } + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + spec = SpecificationUtils.andParam(spec, paramsNode, "saleType"); + return spec; + } + } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProductTypeService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProductTypeService.java index 821710f..a351ac0 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProductTypeService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProductTypeService.java @@ -8,16 +8,15 @@ 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.project.repository.ProductTypeRepository; +import com.ecep.contract.ds.MyRepository; import com.ecep.contract.ds.project.model.ProductType; +import com.ecep.contract.ds.project.repository.ProductTypeRepository; import com.ecep.contract.service.VoableService; import com.ecep.contract.vo.ProductTypeVo; import com.fasterxml.jackson.databind.JsonNode; @@ -25,17 +24,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "product-type") -public class ProductTypeService implements IEntityService, QueryService, +public class ProductTypeService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProductTypeRepository productTypeRepository; - @Override - public ProductType getById(Integer id) { - return productTypeRepository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProductTypeVo findById(Integer id) { @@ -58,26 +53,17 @@ public class ProductTypeService implements IEntityService, QuerySer } @Override - public Page findAll(Specification spec, Pageable pageable) { - return productTypeRepository.findAll(spec, pageable); + protected MyRepository getRepository() { + return productTypeRepository; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // field - // spec = SpecificationUtils.andParam(spec, paramsNode, "company"); - return findAll(spec, pageable).map(ProductType::toVo); + public ProductType createNewEntity() { + return new ProductType(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("code"), "%" + searchText + "%"), @@ -115,4 +101,9 @@ public class ProductTypeService implements IEntityService, QuerySer model.setName(vo.getName()); model.setCode(vo.getCode()); } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'"); + } } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProductUsageService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProductUsageService.java index b2cf2a0..af0e20a 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProductUsageService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProductUsageService.java @@ -14,8 +14,10 @@ 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.MyRepository; import com.ecep.contract.ds.project.repository.ProductUsageRepository; import com.ecep.contract.ds.project.model.ProductUsage; import com.ecep.contract.service.VoableService; @@ -25,17 +27,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "product-usage") -public class ProductUsageService implements IEntityService, QueryService, +public class ProductUsageService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProductUsageRepository productUsageRepository; - @Override - public ProductUsage getById(Integer id) { - return productUsageRepository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProductUsageVo findById(Integer id) { @@ -70,27 +68,17 @@ public class ProductUsageService implements IEntityService, QueryS } @Override - public Page findAll(Specification spec, Pageable pageable) { - return productUsageRepository.findAll(spec, pageable); + protected MyRepository getRepository() { + return productUsageRepository; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); - } - // field - // spec = SpecificationUtils.andParam(spec, paramsNode, "company"); - Page page = findAll(spec, pageable); - return page.map(ProductUsage::toVo); + public ProductUsage createNewEntity() { + return new ProductUsage(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.like(root.get("name"), "%" + searchText + "%"); }; @@ -124,4 +112,9 @@ public class ProductUsageService implements IEntityService, QueryS } + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + throw new UnsupportedOperationException("Unimplemented method 'buildParameterSpecification'"); + } + } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectBidService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectBidService.java index 2bd848f..9274a7a 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectBidService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectBidService.java @@ -15,9 +15,11 @@ 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.MyRepository; import com.ecep.contract.ds.customer.service.CompanyCustomerEvaluationFormFileService; import com.ecep.contract.ds.other.service.EmployeeService; import com.ecep.contract.ds.project.repository.ProjectBidRepository; @@ -31,17 +33,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-bid") -public class ProjectBidService implements IEntityService, QueryService, +public class ProjectBidService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProjectBidRepository repository; - @Override - public ProjectBid getById(Integer id) { - return repository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProjectBidVo findById(Integer id) { @@ -53,35 +51,17 @@ public class ProjectBidService implements IEntityService, QueryServi } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + protected MyRepository getRepository() { + return repository; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "project"); - - if (paramsNode.has("project.customer")) { - Integer customerId = paramsNode.get("project.customer").asInt(); - spec = SpecificationUtils.and(spec, (root, query, builder) -> { - return builder.equal(root.get("project").get("customer").get("id"), customerId); - }); - } - Page page = findAll(spec, pageable); - return page.map(ProjectBid::toVo); + public ProjectBid createNewEntity() { + return new ProjectBid(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("code"), "%" + searchText + "%"), @@ -164,4 +144,23 @@ public class ProjectBidService implements IEntityService, QueryServi public List findAllByProject(Project project) { return repository.findAllByProject(project); } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { + spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); + } + + // field + spec = SpecificationUtils.andParam(spec, paramsNode, "project"); + + if (paramsNode.has("project.customer")) { + Integer customerId = paramsNode.get("project.customer").asInt(); + spec = SpecificationUtils.and(spec, (root, query, builder) -> { + return builder.equal(root.get("project").get("customer").get("id"), customerId); + }); + } + return spec; + } } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostItemService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostItemService.java index ebfda38..8e95198 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostItemService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostItemService.java @@ -15,9 +15,11 @@ 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.MyRepository; import com.ecep.contract.ds.other.service.InventoryService; import com.ecep.contract.ds.project.repository.ProjectCostItemRepository; import com.ecep.contract.ds.project.model.ProjectCost; @@ -30,17 +32,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-cost-item") -public class ProjectCostItemService implements IEntityService, QueryService, +public class ProjectCostItemService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProjectCostItemRepository repository; - @Override - public ProjectCostItem getById(Integer id) { - return repository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProjectCostItemVo findById(Integer id) { @@ -52,49 +50,38 @@ public class ProjectCostItemService implements IEntityService, } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + protected MyRepository getRepository() { + return repository; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "cost"); - - Page page = findAll(spec, pageable); - return page.map(ProjectCostItem::toVo); + public ProjectCostItem createNewEntity() { + return new ProjectCostItem(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification 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("name"), "%" + searchText + "%")); }; } @Caching(evict = { @CacheEvict(key = "#p0.id"), }) + @Override public ProjectCostItem save(ProjectCostItem item) { - return repository.save(item); + return super.save(item); } @Caching(evict = { @CacheEvict(key = "#p0.id"), }) + @Override public void delete(ProjectCostItem item) { - repository.delete(item); + super.delete(item); } public List findByCostId(Integer costId) { @@ -131,4 +118,12 @@ public class ProjectCostItemService implements IEntityService, model.setInventory(null); } } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + // field + spec = SpecificationUtils.andParam(spec, paramsNode, "cost"); + return spec; + } } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostService.java index 7a502eb..22d88e6 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectCostService.java @@ -17,9 +17,11 @@ 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.MyRepository; import com.ecep.contract.ds.project.repository.ProjectCostRepository; import com.ecep.contract.ds.project.model.Project; import com.ecep.contract.ds.project.model.ProjectCost; @@ -32,17 +34,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-cost") -public class ProjectCostService implements IEntityService, QueryService, +public class ProjectCostService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProjectCostRepository repository; - @Override - public ProjectCost getById(Integer id) { - return repository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProjectCostVo findById(Integer id) { @@ -54,35 +52,17 @@ public class ProjectCostService implements IEntityService, QuerySer } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + protected MyRepository getRepository() { + return repository; } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - - // field - spec = SpecificationUtils.andParam(spec, paramsNode, "project"); - - if (paramsNode.has("project.customer")) { - Integer customerId = paramsNode.get("project.customer").asInt(); - spec = SpecificationUtils.and(spec, (root, query, builder) -> { - return builder.equal(root.get("project").get("customer").get("id"), customerId); - }); - } - Page page = findAll(spec, pageable); - return page.map(ProjectCost::toVo); + public ProjectCost createNewEntity() { + return new ProjectCost(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.or( builder.like(root.get("code"), "%" + searchText + "%"), @@ -93,15 +73,17 @@ public class ProjectCostService implements IEntityService, QuerySer @Caching(evict = { @CacheEvict(key = "#p0.id"), }) + @Override public ProjectCost save(ProjectCost cost) { - return repository.save(cost); + return super.save(cost); } @Caching(evict = { @CacheEvict(key = "#p0.id"), }) + @Override public void delete(ProjectCost cost) { - repository.delete(cost); + super.delete(cost); } public List findByProject(Project project) { @@ -151,7 +133,6 @@ public class ProjectCostService implements IEntityService, QuerySer model.setOutExclusiveTaxAmount(vo.getOutExclusiveTaxAmount()); model.setGrossProfitMargin(vo.getGrossProfitMargin()); - if (vo.getProject() == null) { model.setProject(null); } else { @@ -181,4 +162,23 @@ public class ProjectCostService implements IEntityService, QuerySer model.setAuthorizationTime(vo.getAuthorizationTime()); } + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { + spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); + } + + // field + spec = SpecificationUtils.andParam(spec, paramsNode, "project"); + + if (paramsNode.has("project.customer")) { + Integer customerId = paramsNode.get("project.customer").asInt(); + spec = SpecificationUtils.and(spec, (root, query, builder) -> { + return builder.equal(root.get("project").get("customer").get("id"), customerId); + }); + } + return spec; + } + } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileService.java index 110016f..f4450a6 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileService.java @@ -9,18 +9,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.EntityService; import com.ecep.contract.IEntityService; import com.ecep.contract.ProjectFileType; import com.ecep.contract.QueryService; -import com.ecep.contract.ds.project.repository.ProjectFileRepository; +import com.ecep.contract.ds.MyRepository; import com.ecep.contract.ds.project.model.Project; import com.ecep.contract.ds.project.model.ProjectFile; +import com.ecep.contract.ds.project.repository.ProjectFileRepository; import com.ecep.contract.service.VoableService; import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.ProjectFileVo; @@ -29,20 +28,16 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-file") -public class ProjectFileService implements IEntityService, QueryService, VoableService { +public class ProjectFileService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProjectFileRepository repository; - + @Lazy @Autowired private ProjectService projectService; - @Override - public ProjectFile getById(Integer id) { - return repository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProjectFileVo findById(Integer id) { @@ -54,58 +49,36 @@ public class ProjectFileService implements IEntityService, QuerySer } @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - // 构建查询规范 - Specification spec = getSpecification(paramsNode); - // 查询实体列表 - Page entityPage = findAll(spec, pageable); - // 转换为VO列表 - return entityPage.map(ProjectFile::toVo); + protected MyRepository getRepository() { + return repository; } @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); + public ProjectFile createNewEntity() { + return new ProjectFile(); } @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } + protected Specification buildSearchSpecification(String searchText) { return (root, query, builder) -> { return builder.like(root.get("filePath"), "%" + searchText + "%"); }; } - @Override - public List search(String searchText) { - Specification spec = getSearchSpecification(searchText); - return repository.findAll(spec); - } - - @Override - public void delete(ProjectFile entity) { - repository.delete(entity); - } - + @Caching(evict = { + @CacheEvict(key = "#p0.id"), + }) @Override public ProjectFile save(ProjectFile entity) { - return repository.save(entity); + return super.save(entity); } @Caching(evict = { @CacheEvict(key = "#p0.id"), }) - public ProjectFile saveFile(ProjectFile file) { - return repository.save(file); - } - - @Caching(evict = { - @CacheEvict(key = "#p0.id"), - }) - public void deleteFile(ProjectFile file) { - repository.delete(file); + @Override + public void delete(ProjectFile entity) { + super.delete(entity); } // 根据项目查询文件列表 @@ -121,27 +94,18 @@ public class ProjectFileService implements IEntityService, QuerySer } // 构建查询规范 - private Specification getSpecification(JsonNode paramsNode) { + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { Specification spec = null; // 根据参数构建查询条件 spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "id"); spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "projectId"); spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "type"); - + return spec; } - // 计数方法实现 - @Override - public long count(JsonNode paramsNode) { - Specification spec = getSpecification(paramsNode); - if (spec != null) { - return repository.count(spec); - } - return repository.count(); - } - @Override public void updateByVo(ProjectFile model, ProjectFileVo vo) { // 更新文件类型 @@ -150,7 +114,7 @@ public class ProjectFileService implements IEntityService, QuerySer model.setFilePath(vo.getFilePath()); // 更新项目关联 if (vo.getProjectId() != null) { - + model.setProject(projectService.getById(vo.getProjectId())); } else { model.setProject(null); diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileTypeService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileTypeService.java index 0f17316..fe4f8b5 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileTypeService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFileTypeService.java @@ -3,22 +3,20 @@ package com.ecep.contract.ds.project.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.ProjectFileType; import com.ecep.contract.QueryService; +import com.ecep.contract.ds.MyRepository; import com.ecep.contract.ds.project.repository.ProjectFileTypeLocalRepository; import com.ecep.contract.model.ProjectFileTypeLocal; import com.ecep.contract.service.ServiceException; @@ -30,7 +28,7 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-file-type") -public class ProjectFileTypeService +public class ProjectFileTypeService extends EntityService implements IEntityService, QueryService, VoableService { @@ -38,37 +36,11 @@ public class ProjectFileTypeService @Autowired private ProjectFileTypeLocalRepository repository; - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification 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"), - ProjectFileType.valueOf(paramsNode.get("type").asText()))); - } - - // field - spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value"); - return findAll(spec, pageable).map(ProjectFileTypeLocal::toVo); - } - @Override public ProjectFileTypeLocalVo findById(Integer id) { return repository.findById(id).map(ProjectFileTypeLocal::toVo).orElse(null); } - public ProjectFileTypeLocal getById(Integer id) { - return repository.findById(id).orElse(null); - } - - @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - @Cacheable(key = "'all-'+#p0.toLanguageTag()") public Map findAll(Locale locale) { return repository.getCompleteMapByLocal(locale.toLanguageTag()).entrySet().stream() @@ -77,20 +49,6 @@ public class ProjectFileTypeService entry -> entry.getValue().toVo())); } - @Override - public Specification 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()") @@ -122,4 +80,37 @@ public class ProjectFileTypeService entity.setLang(vo.getLang()); entity.setValue(vo.getValue()); } + + @Override + protected MyRepository getRepository() { + return repository; + } + + @Override + public ProjectFileTypeLocal createNewEntity() { + return new ProjectFileTypeLocal(); + } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + if (paramsNode.has("type")) { + spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), + ProjectFileType.valueOf(paramsNode.get("type").asText()))); + } + // field + spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "lang", "value"); + return spec; + } + + @Override + protected Specification buildSearchSpecification(String searchText) { + return (root, query, builder) -> { + return + // builder.or( + builder.like(root.get("type"), "%" + searchText + "%") + // ) + ; + }; + } } \ No newline at end of file diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFundPlanService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFundPlanService.java index 782bf31..86eef0d 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFundPlanService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectFundPlanService.java @@ -13,16 +13,16 @@ 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.SpringApp; -import com.ecep.contract.ds.contract.service.ContractPayPlanService; -import com.ecep.contract.ds.project.repository.ProjectFundPlanRepository; import com.ecep.contract.ds.contract.model.ContractPayPlan; +import com.ecep.contract.ds.contract.service.ContractPayPlanService; import com.ecep.contract.ds.project.model.Project; import com.ecep.contract.ds.project.model.ProjectFundPlan; +import com.ecep.contract.ds.project.repository.ProjectFundPlanRepository; import com.ecep.contract.service.VoableService; import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.ProjectFundPlanVo; @@ -31,17 +31,13 @@ import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-fund-plan") -public class ProjectFundPlanService implements IEntityService, QueryService, +public class ProjectFundPlanService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProjectFundPlanRepository repository; - @Override - public ProjectFundPlan getById(Integer id) { - return repository.findById(id).orElse(null); - } - @Cacheable(key = "#p0") @Override public ProjectFundPlanVo findById(Integer id) { @@ -52,36 +48,21 @@ public class ProjectFundPlanService implements IEntityService, return null; } - @Override - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - @Override public Page findAll(JsonNode paramsNode, Pageable pageable) { Specification spec = null; if (paramsNode.has("searchText")) { - spec = getSearchSpecification(paramsNode.get("searchText").asText()); + spec = buildSearchSpecification(paramsNode.get("searchText").asText()); } // field spec = SpecificationUtils.andParam(spec, paramsNode, "project"); - Page page = findAll(spec, pageable); - return page.map(ProjectFundPlan::toVo); - } - - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - return (root, query, builder) -> { - return builder.like(root.get("description"), "%" + searchText + "%"); - }; + return findAll(spec, pageable).map(ProjectFundPlan::toVo); } @Caching(evict = { @CacheEvict(key = "#p0.id"), }) + @Override public ProjectFundPlan save(ProjectFundPlan fundPlan) { return repository.save(fundPlan); } @@ -89,10 +70,35 @@ public class ProjectFundPlanService implements IEntityService, @Caching(evict = { @CacheEvict(key = "#p0.id"), }) + @Override public void delete(ProjectFundPlan fundPlan) { repository.delete(fundPlan); } + @Override + protected ProjectFundPlanRepository getRepository() { + return repository; + } + + @Override + public ProjectFundPlan createNewEntity() { + return new ProjectFundPlan(); + } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + spec = SpecificationUtils.andParam(spec, paramsNode, "project"); + return spec; + } + + @Override + protected Specification buildSearchSpecification(String searchText) { + return (root, query, builder) -> { + return builder.like(root.get("description"), "%" + searchText + "%"); + }; + } + public List findByProject(Project project) { return repository.findAllByProject(project); } @@ -105,10 +111,10 @@ public class ProjectFundPlanService implements IEntityService, // 转换为BigDecimal return BigDecimal.valueOf(plans.stream().mapToDouble(ProjectFundPlan::getPayCurrency).sum()); // return plans.stream() - // .map(ProjectFundPlan::getAmount) - // .filter(Optional::isPresent) - // .map(Optional::get) - // .reduce(BigDecimal.ZERO, BigDecimal::add); + // .map(ProjectFundPlan::getAmount) + // .filter(Optional::isPresent) + // .map(Optional::get) + // .reduce(BigDecimal.ZERO, BigDecimal::add); } @Override @@ -124,15 +130,16 @@ public class ProjectFundPlanService implements IEntityService, // 处理关联实体 if (vo.getContractPayPlanId() != null) { - ContractPayPlan contractPayPlan = SpringApp.getBean(ContractPayPlanService.class).getById(vo.getContractPayPlanId()); + ContractPayPlan contractPayPlan = SpringApp.getBean(ContractPayPlanService.class) + .getById(vo.getContractPayPlanId()); model.setContractPayPlan(contractPayPlan); - }else{ + } else { model.setContractPayPlan(null); } if (vo.getProjectId() != null) { Project project = SpringApp.getBean(ProjectService.class).getById(vo.getProjectId()); model.setProject(project); - }else{ + } else { model.setProject(null); } } diff --git a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectIndustryService.java b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectIndustryService.java index 6139f05..bd8c360 100644 --- a/server/src/main/java/com/ecep/contract/ds/project/service/ProjectIndustryService.java +++ b/server/src/main/java/com/ecep/contract/ds/project/service/ProjectIndustryService.java @@ -2,40 +2,38 @@ package com.ecep.contract.ds.project.service; import java.util.List; -import com.ecep.contract.QueryService; -import com.ecep.contract.constant.ParamConstant; -import com.ecep.contract.util.SpecificationUtils; -import com.fasterxml.jackson.databind.JsonNode; 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.ds.project.repository.ProjectIndustryRepository; +import com.ecep.contract.QueryService; import com.ecep.contract.ds.project.model.ProjectIndustry; +import com.ecep.contract.ds.project.repository.ProjectIndustryRepository; import com.ecep.contract.service.VoableService; +import com.ecep.contract.util.SpecificationUtils; import com.ecep.contract.vo.ProjectIndustryVo; +import com.fasterxml.jackson.databind.JsonNode; @Lazy @Service @CacheConfig(cacheNames = "project-industry") -public class ProjectIndustryService implements IEntityService, QueryService, +public class ProjectIndustryService extends EntityService + implements IEntityService, QueryService, VoableService { @Lazy @Autowired private ProjectIndustryRepository repository; @Override - public ProjectIndustry getById(Integer id) { - return repository.findById(id).orElse(null); + protected ProjectIndustryRepository getRepository() { + return repository; } @Cacheable(key = "#p0") @@ -72,34 +70,6 @@ public class ProjectIndustryService implements IEntityService, return industries.stream().map(ProjectIndustry::toVo).toList(); } - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - // field - spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code", "name"); - Page page = findAll(spec, pageable); - return page.map(ProjectIndustry::toVo); - } - - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - return (root, query, builder) -> { - return builder.or( - builder.like(root.get("code"), "%" + searchText + "%"), - builder.like(root.get("name"), "%" + searchText + "%")); - }; - } - @Caching(evict = { @CacheEvict(key = "#p0.id"), @CacheEvict(key = "'code-'+#p0.code"), @@ -126,4 +96,25 @@ public class ProjectIndustryService implements IEntityService, model.setCode(vo.getCode()); model.setDescription(vo.getDescription()); } + + @Override + public ProjectIndustry createNewEntity() { + return new ProjectIndustry(); + } + + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + spec = SpecificationUtils.andFieldEqualParam(spec, paramsNode, "code", "name"); + return spec; + } + + @Override + protected Specification buildSearchSpecification(String searchText) { + return (root, query, builder) -> { + return builder.or( + builder.like(root.get("code"), "%" + searchText + "%"), + builder.like(root.get("name"), "%" + searchText + "%")); + }; + } } diff --git a/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java b/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java index 2a6cd18..e801c85 100644 --- a/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java +++ b/server/src/main/java/com/ecep/contract/ds/vendor/service/VendorService.java @@ -42,6 +42,7 @@ import com.ecep.contract.ds.other.service.SysConfService; import com.ecep.contract.ds.vendor.repository.VendorClassRepository; import com.ecep.contract.ds.vendor.repository.VendorRepository; import com.ecep.contract.ds.vendor.repository.VendorTypeLocalRepository; +import com.ecep.contract.ds.MyRepository; import com.ecep.contract.ds.company.model.Company; import com.ecep.contract.model.CompanyBasicFile; import com.ecep.contract.ds.contract.model.Contract; @@ -65,7 +66,7 @@ import jakarta.persistence.criteria.Path; @Lazy @Service @CacheConfig(cacheNames = CompanyVendorConstant.CACHE_NAME) -public class VendorService extends CompanyBasicService +public class VendorService extends CompanyBasicService implements IEntityService, QueryService, VoableService { @Autowired private VendorCatalogService vendorCatalogService; @@ -92,6 +93,16 @@ public class VendorService extends CompanyBasicService @Autowired private VendorClassRepository vendorClassRepository; + @Override + protected VendorRepository getRepository() { + return repository; + } + + @Override + public Vendor createNewEntity() { + return new Vendor(); + } + @PostConstruct public void init() { SpringApp.getBean(org.springframework.core.convert.converter.ConverterRegistry.class) @@ -103,30 +114,6 @@ public class VendorService extends CompanyBasicService return repository.findById(id).map(Vendor::toVo).orElse(null); } - @Override - public Vendor getById(Integer id) { - return repository.findById(id).orElse(null); - } - - public Page findAll(Specification spec, Pageable pageable) { - return repository.findAll(spec, pageable); - } - - @Override - public Page findAll(JsonNode paramsNode, Pageable pageable) { - Specification spec = null; - if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) { - spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText()); - } - // 添加额外的参数过滤 - if (paramsNode.has("type")) { - VendorType type = VendorType.valueOf(paramsNode.get("type").asText()); - spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), type)); - } - spec = SpecificationUtils.andParam(spec, paramsNode, "company", "catalog"); - return findAll(spec, pageable).map(Vendor::toVo); - } - public Vendor findByCompany(Company company) { return repository.findByCompany(company).orElse(null); } @@ -150,45 +137,6 @@ public class VendorService extends CompanyBasicService repository.delete(entity); } - @Override - public Specification getSearchSpecification(String searchText) { - if (!StringUtils.hasText(searchText)) { - return null; - } - Specification nameSpec = (root, query, builder) -> { - Path company = root.get("company"); - return companyService.buildSearchPredicate(searchText, company, query, builder); - }; - // 判断是否全是数字 - if (MyStringUtils.isAllDigit(searchText)) { - // 全数字就按 Id 查询 - try { - int id = Integer.parseInt(searchText); - nameSpec = SpecificationUtils.or(nameSpec, (root, query, builder) -> { - return builder.equal(root.get("id"), id); - }); - } catch (Exception ignored) { - } - } - List searched = vendorEntityService.search(searchText); - if (!searched.isEmpty()) { - nameSpec = SpecificationUtils.or(nameSpec, (root, query, builder) -> { - return builder.in(root.get("id")).value(searched.stream() - .map(VendorEntity::getVendor) - .filter(Objects::nonNull) - .map(Vendor::getId) - .collect(Collectors.toSet())); - }); - } - return nameSpec; - } - - @Override - public List search(String searchText) { - Specification spec = getSearchSpecification(searchText); - return repository.findAll(spec, Pageable.ofSize(10)).getContent(); - } - @Override public , ID> void deleteFile(F file) { vendorFileService.delete((VendorFile) file); @@ -521,4 +469,46 @@ public class VendorService extends CompanyBasicService } } + @Override + protected Specification buildParameterSpecification(JsonNode paramsNode) { + Specification spec = null; + // 添加额外的参数过滤 + if (paramsNode.has("type")) { + VendorType type = VendorType.valueOf(paramsNode.get("type").asText()); + spec = SpecificationUtils.and(spec, (root, query, builder) -> builder.equal(root.get("type"), type)); + } + spec = SpecificationUtils.andParam(spec, paramsNode, "company", "catalog"); + return spec; + } + + @Override + protected Specification buildSearchSpecification(String searchText) { + Specification nameSpec = (root, query, builder) -> { + Path company = root.get("company"); + return companyService.buildSearchPredicate(searchText, company, query, builder); + }; + // 判断是否全是数字 + if (MyStringUtils.isAllDigit(searchText)) { + // 全数字就按 Id 查询 + try { + int id = Integer.parseInt(searchText); + nameSpec = SpecificationUtils.or(nameSpec, (root, query, builder) -> { + return builder.equal(root.get("id"), id); + }); + } catch (Exception ignored) { + } + } + List searched = vendorEntityService.search(searchText); + if (!searched.isEmpty()) { + nameSpec = SpecificationUtils.or(nameSpec, (root, query, builder) -> { + return builder.in(root.get("id")).value(searched.stream() + .map(VendorEntity::getVendor) + .filter(Objects::nonNull) + .map(Vendor::getId) + .collect(Collectors.toSet())); + }); + } + return nameSpec; + } + } diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java index 10bbd3b..f15a511 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CompanyCustomerEvaluationFormUpdateTask.java @@ -272,7 +272,7 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker impl baseRow++; CompanyCustomerFile customerFile = form.getCustomerFile(); if (!Hibernate.isInitialized(customerFile)) { - customerFile = getCompanyCustomerFileService().findById(customerFile.getId()); + customerFile = getCompanyCustomerFileService().getById(customerFile.getId()); holder.debug("延迟加载评价表文件信息,文件ID:" + customerFile.getId()); } setCellValue(sheet, baseRow, 2, String.valueOf(customerFile.getSignDate())); diff --git a/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java b/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java index 9e309e9..b36fa6e 100644 --- a/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java +++ b/server/src/main/java/com/ecep/contract/service/tasker/CustomerFileMoveTasker.java @@ -25,7 +25,7 @@ public class CustomerFileMoveTasker extends Tasker implements WebSocketS @Override public void init(JsonNode argsNode) { if (argsNode != null && argsNode.size() > 0) { - this.file = getCompanyCustomerFileService().findById(argsNode.get(0).asInt()); + this.file = getCompanyCustomerFileService().getById(argsNode.get(0).asInt()); } } diff --git a/server_entity_services.md b/server_entity_services.md index 137b618..5422bf7 100644 --- a/server_entity_services.md +++ b/server_entity_services.md @@ -39,32 +39,32 @@ | 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 | 否 | +| 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 | 否 |