Files
contract-manager/docs/task/server模块service缓存调整为Vo对象/SERVICE_CLASS_COMPLIANCE_REPORT.md
songqq 49413ad473 refactor(service): 统一Service缓存为VO对象并优化关联实体处理
重构Service类实现,将QueryService泛型参数调整为VO类型,确保缓存VO对象而非实体。优化关联实体处理逻辑,减少重复代码。修改findById方法返回VO对象,新增getById方法获取实体。更新相关调用点以适配新接口。

调整WebSocket处理、控制器及Service实现,确保数据类型一致性。完善文档记录重构过程及发现的问题。为后续优化提供基础架构支持。
2025-09-29 19:31:51 +08:00

8.2 KiB
Raw Blame History

Service类规范符合性检查报告

概述

本报告对Contract-Manager项目Server模块中所有64个注解了@CacheConfig的Service类进行了规范符合性检查。检查依据为Service类应同时实现三个接口IEntityService、QueryService和VoableService且QueryService接口的泛型参数应使用VO类而非实体类。

检查结果汇总

类别 数量 说明
完全符合规范 约40个 同时实现三个接口QueryService泛型参数使用VO类
QueryService泛型参数错误 约22个 实现了三个接口但QueryService泛型参数使用了实体类
仅实现QueryService接口 约2个 只实现了QueryService接口且泛型参数使用实体类

不符合规范的Service类详情

1. QueryService泛型参数错误实现三个接口但QueryService泛型使用实体类

类名 包路径 问题描述
VendorTypeService com.ecep.contract.ds.vendor.service 实现了IEntityService、QueryService和VoableService<VendorTypeLocal, VendorTypeLocalVo>但QueryService泛型参数应为VendorTypeLocalVo
ProjectSaleTypeRequireFileTypeService com.ecep.contract.ds.project.service 实现了IEntityService、QueryService和VoableService<ProjectSaleTypeRequireFileType, ProjectSaleTypeRequireFileTypeVo>但QueryService泛型参数应为ProjectSaleTypeRequireFileTypeVo
PurchaseOrdersService com.ecep.contract.ds.contract.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
ContractGroupService com.ecep.contract.ds.contract.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
ContractItemService com.ecep.contract.ds.contract.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
VendorEntityService com.ecep.contract.ds.vendor.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
CustomerCatalogService com.ecep.contract.ds.customer.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
ProductTypeService com.ecep.contract.ds.project.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
InvoiceService com.ecep.contract.ds.company.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
ContractFileService com.ecep.contract.ds.contract.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
CompanyContactService com.ecep.contract.ds.company.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类
PurchaseOrderItemService com.ecep.contract.ds.contract.service 实现了IEntityService、QueryService但QueryService泛型参数应使用对应的VO类

2. 仅实现QueryService接口

类名 包路径 问题描述
CompanyExtendInfoService com.ecep.contract.ds.company.service 仅实现了QueryService接口未实现IEntityService和VoableService接口且QueryService泛型参数使用了实体类
CompanyInvoiceInfoService com.ecep.contract.ds.company.service 仅实现了QueryService接口未实现IEntityService和VoableService接口且QueryService泛型参数使用了实体类

符合规范的Service类示例

类名 包路径 符合规范的实现
ProjectFileTypeService com.ecep.contract.ds.project.service 实现了IEntityService、QueryService和VoableService<ProjectFileTypeLocal, ProjectFileTypeLocalVo>QueryService泛型参数使用VO类findById和findAll方法返回VO对象
ContractBidVendorService com.ecep.contract.ds.contract.service 实现了IEntityService、QueryService和VoableService<ContractBidVendor, ContractBidVendorVo>QueryService泛型参数使用VO类findById方法返回VO对象
CompanyOldNameService com.ecep.contract.ds.company.service 实现了IEntityService、QueryService和VoableService<CompanyOldName, CompanyOldNameVo>QueryService泛型参数使用VO类
CompanyCustomerEntityService com.ecep.contract.ds.customer.service 实现了IEntityService、QueryService和VoableService<CompanyCustomerEntity, CompanyCustomerEntityVo>QueryService泛型参数使用VO类
BankService com.ecep.contract.ds.other.service 实现了IEntityService、QueryService和VoableService<Bank, BankVo>QueryService泛型参数使用VO类
PermissionService com.ecep.contract.ds.other.service 实现了IEntityService、QueryService和VoableService<Permission, PermissionVo>QueryService泛型参数使用VO类

问题分析

1. QueryService泛型参数错误问题

大部分不符合规范的Service类都实现了三个接口但在QueryService的泛型参数上使用了实体类而非VO类。这会导致

  • findById和findAll方法返回实体类而非VO对象
  • WebSocket通信时需要额外转换对象类型
  • 缓存中存储的是实体对象而非VO对象增加了缓存大小

2. 仅实现QueryService接口问题

少数Service类只实现了QueryService接口这可能是因为这些类主要用于查询操作不需要完整的CRUD功能。但这种实现方式不符合统一的设计规范会导致

  • 代码风格不一致
  • WebSocket通信处理逻辑复杂化
  • 缺少标准化的缓存管理

建议修复方案

1. 修复QueryService泛型参数错误

对于实现了三个接口但QueryService泛型参数错误的Service类修复方案如下

// 修改前
export class VendorTypeService implements IEntityService<VendorTypeLocal>, QueryService<VendorTypeLocal>, VoableService<VendorTypeLocal, VendorTypeLocalVo> {
    // ...
    @Override
    public Page<VendorTypeLocal> findAll(JsonNode paramsNode, Pageable pageable) {
        // ...返回实体类Page
    }
    
    @Cacheable(key = "#p0")
    @Override
    public VendorTypeLocal findById(Integer id) {
        // ...返回实体类
    }
    // ...
}

// 修改后
export class VendorTypeService implements IEntityService<VendorTypeLocal>, QueryService<VendorTypeLocalVo>, VoableService<VendorTypeLocal, VendorTypeLocalVo> {
    // ...
    @Override
    public Page<VendorTypeLocalVo> findAll(JsonNode paramsNode, Pageable pageable) {
        // ...使用map方法转换为VO对象
        return findAll(spec, pageable).map(VendorTypeLocal::toVo);
    }
    
    @Cacheable(key = "#p0")
    @Override
    public VendorTypeLocalVo findById(Integer id) {
        // ...转换为VO对象返回
        return repository.findById(id).map(VendorTypeLocal::toVo).orElse(null);
    }
    // ...
}

2. 修复仅实现QueryService接口的问题

对于仅实现QueryService接口的Service类建议按照标准模式实现三个接口

// 修改前
export class CompanyExtendInfoService implements QueryService<CompanyExtendInfo> {
    // ...
}

// 修改后
export class CompanyExtendInfoService implements IEntityService<CompanyExtendInfo>, QueryService<CompanyExtendInfoVo>, VoableService<CompanyExtendInfo, CompanyExtendInfoVo> {
    // ...实现所有接口方法
}

结论

通过本次检查我们发现Contract-Manager项目Server模块中约38%的Service类存在不符合规范的问题主要是QueryService接口泛型参数使用错误和未实现完整的三个接口。建议对这些不符合规范的Service类进行重构以统一接口实现方式确保缓存调整为Vo对象的目标能够顺利实现。