refactor(service): 统一Service缓存为VO对象并优化关联实体处理
重构Service类实现,将QueryService泛型参数调整为VO类型,确保缓存VO对象而非实体。优化关联实体处理逻辑,减少重复代码。修改findById方法返回VO对象,新增getById方法获取实体。更新相关调用点以适配新接口。 调整WebSocket处理、控制器及Service实现,确保数据类型一致性。完善文档记录重构过程及发现的问题。为后续优化提供基础架构支持。
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
# 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<VendorTypeLocal>、QueryService<VendorTypeLocal>和VoableService<VendorTypeLocal, VendorTypeLocalVo>,但QueryService泛型参数应为VendorTypeLocalVo |
|
||||
| ProjectSaleTypeRequireFileTypeService | com.ecep.contract.ds.project.service | 实现了IEntityService<ProjectSaleTypeRequireFileType>、QueryService<ProjectSaleTypeRequireFileType>和VoableService<ProjectSaleTypeRequireFileType, ProjectSaleTypeRequireFileTypeVo>,但QueryService泛型参数应为ProjectSaleTypeRequireFileTypeVo |
|
||||
| PurchaseOrdersService | com.ecep.contract.ds.contract.service | 实现了IEntityService<PurchaseOrder>、QueryService<PurchaseOrder>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| ContractGroupService | com.ecep.contract.ds.contract.service | 实现了IEntityService<ContractGroup>、QueryService<ContractGroup>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| ContractItemService | com.ecep.contract.ds.contract.service | 实现了IEntityService<ContractItem>、QueryService<ContractItem>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| VendorEntityService | com.ecep.contract.ds.vendor.service | 实现了IEntityService<VendorEntity>、QueryService<VendorEntity>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| CustomerCatalogService | com.ecep.contract.ds.customer.service | 实现了IEntityService<CustomerCatalog>、QueryService<CustomerCatalog>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| ProductTypeService | com.ecep.contract.ds.project.service | 实现了IEntityService<ProductType>、QueryService<ProductType>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| InvoiceService | com.ecep.contract.ds.company.service | 实现了IEntityService<Invoice>、QueryService<Invoice>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| ContractFileService | com.ecep.contract.ds.contract.service | 实现了IEntityService<ContractFile>、QueryService<ContractFile>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| CompanyContactService | com.ecep.contract.ds.company.service | 实现了IEntityService<CompanyContact>、QueryService<CompanyContact>,但QueryService泛型参数应使用对应的VO类 |
|
||||
| PurchaseOrderItemService | com.ecep.contract.ds.contract.service | 实现了IEntityService<PurchaseOrderItem>、QueryService<PurchaseOrderItem>,但QueryService泛型参数应使用对应的VO类 |
|
||||
|
||||
### 2. 仅实现QueryService接口
|
||||
|
||||
| 类名 | 包路径 | 问题描述 |
|
||||
|------|--------|----------|
|
||||
| CompanyExtendInfoService | com.ecep.contract.ds.company.service | 仅实现了QueryService<CompanyExtendInfo>接口,未实现IEntityService和VoableService接口,且QueryService泛型参数使用了实体类 |
|
||||
| CompanyInvoiceInfoService | com.ecep.contract.ds.company.service | 仅实现了QueryService<CompanyInvoiceInfo>接口,未实现IEntityService和VoableService接口,且QueryService泛型参数使用了实体类 |
|
||||
|
||||
## 符合规范的Service类示例
|
||||
|
||||
| 类名 | 包路径 | 符合规范的实现 |
|
||||
|------|--------|----------------|
|
||||
| ProjectFileTypeService | com.ecep.contract.ds.project.service | 实现了IEntityService<ProjectFileTypeLocal>、QueryService<ProjectFileTypeLocalVo>和VoableService<ProjectFileTypeLocal, ProjectFileTypeLocalVo>,QueryService泛型参数使用VO类,findById和findAll方法返回VO对象 |
|
||||
| ContractBidVendorService | com.ecep.contract.ds.contract.service | 实现了IEntityService<ContractBidVendor>、QueryService<ContractBidVendorVo>和VoableService<ContractBidVendor, ContractBidVendorVo>,QueryService泛型参数使用VO类,findById方法返回VO对象 |
|
||||
| CompanyOldNameService | com.ecep.contract.ds.company.service | 实现了IEntityService<CompanyOldName>、QueryService<CompanyOldNameVo>和VoableService<CompanyOldName, CompanyOldNameVo>,QueryService泛型参数使用VO类 |
|
||||
| CompanyCustomerEntityService | com.ecep.contract.ds.customer.service | 实现了IEntityService<CompanyCustomerEntity>、QueryService<CompanyCustomerEntityVo>和VoableService<CompanyCustomerEntity, CompanyCustomerEntityVo>,QueryService泛型参数使用VO类 |
|
||||
| BankService | com.ecep.contract.ds.other.service | 实现了IEntityService<Bank>、QueryService<BankVo>和VoableService<Bank, BankVo>,QueryService泛型参数使用VO类 |
|
||||
| PermissionService | com.ecep.contract.ds.other.service | 实现了IEntityService<Permission>、QueryService<PermissionVo>和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类,修复方案如下:
|
||||
|
||||
```java
|
||||
// 修改前
|
||||
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类,建议按照标准模式实现三个接口:
|
||||
|
||||
```java
|
||||
// 修改前
|
||||
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对象的目标能够顺利实现。
|
||||
Reference in New Issue
Block a user