refactor(service): 统一Service缓存为VO对象并优化关联实体处理

重构Service类实现,将QueryService泛型参数调整为VO类型,确保缓存VO对象而非实体。优化关联实体处理逻辑,减少重复代码。修改findById方法返回VO对象,新增getById方法获取实体。更新相关调用点以适配新接口。

调整WebSocket处理、控制器及Service实现,确保数据类型一致性。完善文档记录重构过程及发现的问题。为后续优化提供基础架构支持。
This commit is contained in:
2025-09-29 19:31:51 +08:00
parent 64471b46f8
commit 49413ad473
167 changed files with 6840 additions and 1811 deletions

View File

@@ -107,6 +107,11 @@ public class CloudRkService implements IEntityService<CloudRk>, VoableService<Cl
@Autowired
private CompanyBlackReasonRepository companyBlackReasonRepository;
@Override
public CloudRk getById(Integer id) {
return cloudRKRepository.findById(id).orElse(null);
}
@Cacheable(key = "#p0")
public CloudRk findById(Integer id) {
return cloudRKRepository.findById(id).orElse(null);
@@ -384,15 +389,15 @@ public class CloudRkService implements IEntityService<CloudRk>, VoableService<Cl
if (cloudRk == null || vo == null) {
throw new IllegalArgumentException("CloudRk and CloudRkVo cannot be null");
}
// 更新基本属性
if (vo.getCloudId() != null) {
cloudRk.setCloudId(vo.getCloudId());
}
cloudRk.setAutoUpdate(vo.isAutoUpdate());
cloudRk.setUpdateDays(vo.getUpdateDays());
if (vo.getCustomerGrade() != null) {
cloudRk.setCustomerGrade(vo.getCustomerGrade());
}
@@ -432,11 +437,11 @@ public class CloudRkService implements IEntityService<CloudRk>, VoableService<Cl
if (vo.getLatestUpdate() != null) {
cloudRk.setLatestUpdate(vo.getLatestUpdate());
}
// 更新关联的公司
if (vo.getCompanyId() != null) {
CompanyService companyService = SpringApp.getBean(CompanyService.class);
Company company = companyService.findById(vo.getCompanyId());
Company company = companyService.getById(vo.getCompanyId());
if (company != null) {
cloudRk.setCompany(company);
}

View File

@@ -53,6 +53,7 @@ public class CloudRkSyncTask extends Tasker<Object> {
AtomicInteger counter = new AtomicInteger(0);
holder.info("统计需要更新的 " + total + "");
var companyService = getCompanyService();
try {
// 每次获取100条记录
while (!isCancelled()) {
@@ -73,7 +74,7 @@ public class CloudRkSyncTask extends Tasker<Object> {
break;
}
if (!Hibernate.isInitialized(company)) {
company = getCompanyService().findById(company.getId());
company = companyService.getById(company.getId());
cloudRk.setCompany(company);
}
if (cloudRk.isAutoUpdate()) {