Files
contract-manager/server_entity_services.md
songqq e8c8305f40 refactor(vendor): 移除冗余方法并统一继承EntityService
重构供应商相关服务类,移除重复的getById等方法,统一继承EntityService基类
更新文档中的服务类检查状态
2025-12-14 16:36:11 +08:00

6.6 KiB
Raw Blame History

服务器端 Service 继承IEntityService接口任务

IEntityService 接口定义了若干基本 CRUD 操作相对项目路径src/main/java/com/contract/service/IEntityService.java包括保存、删除、查询等方法。

Service 继承 EntityService 类的任务

参考 server\src\main\java\com\ecep\contract\cloud\rk\CloudRkService.java

  1. 实现 server\src\main\java\com\ecep\contract\EntityService.java 类的方法 1.1 实现 getRepository 方法用于获取实体的Repository 1.1.1 确认的Repository是否为server\src\main\java\com\ecep\contract\ds\MyRepository.java的子接口 1.2 实现 createNewEntity 方法,用于创建新实体 1.3 实现 buildSearchSpecification 方法,根据搜索参数构建查询规范 1.3.1 方法内容如下
    @Override
    protected org.springframework.data.jpa.domain.Specification<VendorApprovedFile> buildSearchSpecification(String searchText) {
      return (root, query, builder) -> {
            return builder.or(
                    builder.like(root.get("fileName"), "%" + searchText + "%"),
                    builder.like(root.get("description"), "%" + searchText + "%"));
        };
    }

1.4 实现 buildParameterSpecification 方法,根据参数构建查询规范 1.4.1 方法内容从 findAll(JsonNode paramsNode, Pageable pageable) 中提取,然后删除 findAll 方法 比如 findAll 方法中定义如下

    @Override
    public Page<VendorApprovedItemVo> findAll(JsonNode paramsNode, Pageable pageable) {
        Specification<VendorApprovedItem> spec = null;
        if (paramsNode.has(ParamConstant.KEY_SEARCH_TEXT)) {
            spec = getSearchSpecification(paramsNode.get(ParamConstant.KEY_SEARCH_TEXT).asText());
        }
        // 添加额外的参数过滤
        if (paramsNode.has("type")) {
            String typeText = paramsNode.get("type").asText();
            VendorType type = VendorType.valueOf(typeText);
            spec = SpecificationUtils.and(spec, (root, query, builder) -> {
                return builder.equal(root.get("type"), type);
            });
        }
        spec = SpecificationUtils.andParam(spec, paramsNode, "vendor", "list");
        return findAll(spec, pageable).map(VendorApprovedItem::toVo);
    }

buildParameterSpecification 方法的实现如下(删除 searchText 部分以及直接返回spec不调用findAll方法


    @Override
    protected Specification<VendorApprovedItem> buildParameterSpecification(JsonNode paramsNode) {
        Specification<VendorApprovedItem> spec = null;
        // 添加额外的参数过滤
        if (paramsNode.has("type")) {
            String typeText = paramsNode.get("type").asText();
            VendorType type = VendorType.valueOf(typeText);
            spec = SpecificationUtils.and(spec, (root, query, builder) -> {
                return builder.equal(root.get("type"), type);
            });
        }
        spec = SpecificationUtils.andParam(spec, paramsNode, "vendor", "list");
        return spec;
    }

1.5 检查count方法的功能实现是否与父类相同,相同则移除 1.6 检查findAll方法的功能实现是否与父类相同,相同则移除 1.7 检查getById方法的功能实现是否与父类相同,相同则移除 1.8 检查findByIdf方法的返回值类型须 Vo 类型,如未实现,则添加如下代码

    @Override
    public VendorGroupRequireFileTypeVo findById(Integer id) {
        return repository.findById(id).map(VendorGroupRequireFileType::toVo).orElse(null);
    }
  1. 缓存相关任务 2.1 确认Service类是否有 @CacheConfig 注解,没有注解,则没有应用缓存功能,跳过后续缓存检查 2.2 检查 findById 方法,注解 @Cacheable(key = "#p0") 2.3 检查 save 方法,注解 @CacheEvict(key = "#p0.id") 或者 @Caching(evict = @CacheEvict(key = "#p0.id")) 2.4 检查 delete 方法,注解 @CacheEvict(key = "#p0.id") 或者 @Caching(evict = @CacheEvict(key = "#p0.id"))

  2. 处理异常情况

Service 继承 IEntityService 接口的列表

类名 是否继承EntityService
CloudRkService
CloudTycService
YongYouU8Service
CompanyBankAccountService
CompanyBlackReasonService
CompanyContactService
CompanyExtendInfoService
CompanyFileService
CompanyFileTypeService
CompanyInvoiceInfoService
CompanyOldNameService
CompanyService
HolidayService
InvoiceService
ContractBalanceService
ContractBidVendorService
ContractCatalogService
ContractFileService
ContractFileTypeService
ContractGroupService
ContractInvoiceService
ContractItemService
ContractKindService
ContractPayPlanService
ContractService
ContractTypeService
ExtendVendorInfoService
PurchaseBillVoucherItemService
PurchaseBillVoucherService
PurchaseOrderItemService
PurchaseOrdersService
SaleOrdersService
SalesBillVoucherItemService
SalesBillVoucherService
SalesOrderItemService
CompanyCustomerEntityService
CompanyCustomerEvaluationFormFileService
CompanyCustomerFileService
CompanyCustomerFileTypeService
CustomerCatalogService
CustomerFileTypeService
CustomerService
BankService
DepartmentService
EmployeeAuthBindService
EmployeeLoginHistoryService
EmployeeRoleService
EmployeeService
FunctionService
InventoryCatalogService
InventoryHistoryPriceService
InventoryService
PermissionService
CustomerSatisfactionSurveyService
DeliverySignMethodService
ProductTypeService
ProductUsageService
ProjectBidService
ProjectCostItemService
ProjectCostService
ProjectFileService
ProjectFileTypeService
ProjectFundPlanService
ProjectIndustryService
ProjectQuotationService
ProjectSaleTypeRequireFileTypeService
ProjectSaleTypeService
ProjectService
ProjectTypeService
VendorApprovedFileService
VendorApprovedItemService
VendorApprovedService
VendorCatalogService
VendorEntityService
VendorFileService
VendorFileTypeService
VendorGroupRequireFileTypeService
VendorGroupService
VendorService
VendorTypeService