refactor(service): 统一Service缓存为VO对象并优化关联实体处理
重构Service类实现,将QueryService泛型参数调整为VO类型,确保缓存VO对象而非实体。优化关联实体处理逻辑,减少重复代码。修改findById方法返回VO对象,新增getById方法获取实体。更新相关调用点以适配新接口。 调整WebSocket处理、控制器及Service实现,确保数据类型一致性。完善文档记录重构过程及发现的问题。为后续优化提供基础架构支持。
This commit is contained in:
@@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
|
||||
import com.ecep.contract.IEntityService;
|
||||
import com.ecep.contract.PageArgument;
|
||||
@@ -158,7 +157,7 @@ public class WebSocketServerCallbackManager {
|
||||
}
|
||||
int id = paramsNode.get("id").asInt();
|
||||
IEntityService<Object> entityService = (IEntityService<Object>) service;
|
||||
Object entity = entityService.findById(id);
|
||||
Object entity = entityService.getById(id);
|
||||
if (entity == null) {
|
||||
throw new NoSuchElementException("未找到实体: #" + id);
|
||||
}
|
||||
@@ -172,7 +171,7 @@ public class WebSocketServerCallbackManager {
|
||||
Object entity = null;
|
||||
if (paramsNode.has("id") && !paramsNode.get("id").isNull()) {
|
||||
int id = paramsNode.get("id").asInt();
|
||||
entity = entityService.findById(id);
|
||||
entity = entityService.getById(id);
|
||||
if (entity == null) {
|
||||
throw new NoSuchElementException("未找到实体: #" + id);
|
||||
}
|
||||
@@ -346,7 +345,7 @@ public class WebSocketServerCallbackManager {
|
||||
JsonNode paramsNode = argumentsNode.get(0);
|
||||
if (service instanceof IEntityService<?> entityService) {
|
||||
Integer id = paramsNode.asInt();
|
||||
return entityService.findById(id);
|
||||
return entityService.getById(id);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CompanyCompositeUpdateTasker extends Tasker<Object> implements WebS
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int companyId = argsNode.get(0).asInt();
|
||||
company = getCachedBean(com.ecep.contract.ds.company.service.CompanyService.class).findById(companyId);
|
||||
company = getCachedBean(com.ecep.contract.ds.company.service.CompanyService.class).getById(companyId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,7 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> impl
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int customerId = argsNode.get(0).asInt();
|
||||
customer = getCachedBean(CompanyCustomerService.class).findById(customerId);
|
||||
customer = getCachedBean(CompanyCustomerService.class).getById(customerId);
|
||||
}
|
||||
|
||||
CompanyCustomerFileService getCompanyCustomerFileService() {
|
||||
@@ -116,7 +116,7 @@ public class CompanyCustomerEvaluationFormUpdateTask extends Tasker<Object> impl
|
||||
updateProgress(2, 10);
|
||||
Company company = customer.getCompany();
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
company = getCompanyService().getById(company.getId());
|
||||
customer.setCompany(company);
|
||||
}
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CompanyCustomerNextSignDateTask extends Tasker<Object> implements W
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int customerId = argsNode.get(0).asInt();
|
||||
customer = getCachedBean(CompanyCustomerService.class).findById(customerId);
|
||||
customer = getCachedBean(CompanyCustomerService.class).getById(customerId);
|
||||
}
|
||||
|
||||
CompanyCustomerFileService getCompanyCustomerFileService() {
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CompanyCustomerRebuildFilesTasker extends Tasker<Object> implements
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int customerId = argsNode.get(0).asInt();
|
||||
customer = getCompanyCustomerService().findById(customerId);
|
||||
customer = getCompanyCustomerService().getById(customerId);
|
||||
}
|
||||
|
||||
void setFilesUpdated(boolean filesUpdated) {
|
||||
@@ -51,7 +51,7 @@ public class CompanyCustomerRebuildFilesTasker extends Tasker<Object> implements
|
||||
|
||||
Company company = customer.getCompany();
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCachedBean(CompanyService.class).findById(company.getId());
|
||||
company = getCachedBean(CompanyService.class).getById(company.getId());
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class CompanyVerifyTasker extends Tasker<Object> implements WebSocketServ
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int companyId = argsNode.get(0).asInt();
|
||||
company = getCompanyService().findById(companyId);
|
||||
company = getCompanyService().getById(companyId);
|
||||
comm.setVerifyCompanyPath(false);
|
||||
comm.setVerifyCompanyStatus(false);
|
||||
comm.setVerifyCompanyCredit(false);
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ContractRepairTasker extends AbstContractRepairTasker implements We
|
||||
|
||||
public void init(JsonNode argsNode) {
|
||||
int contractId = argsNode.get(0).asInt();
|
||||
contract = getCachedBean(ContractService.class).findById(contractId);
|
||||
contract = getCachedBean(ContractService.class).getById(contractId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ContractVerifyTasker extends Tasker<Object> implements WebSocketSer
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int contractId = argsNode.get(0).asInt();
|
||||
contract = getCachedBean(ContractService.class).findById(contractId);
|
||||
contract = getCachedBean(ContractService.class).getById(contractId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CustomerFileMoveTasker extends Tasker<Object> implements WebSocketS
|
||||
throw new IllegalArgumentException("客户不存在");
|
||||
}
|
||||
if (!Hibernate.isInitialized(customer)) {
|
||||
customer = getCompanyCustomerService().findById(customer.getId());
|
||||
customer = getCompanyCustomerService().getById(customer.getId());
|
||||
}
|
||||
|
||||
// 获取公司信息
|
||||
@@ -54,7 +54,7 @@ public class CustomerFileMoveTasker extends Tasker<Object> implements WebSocketS
|
||||
throw new IllegalArgumentException("公司不存在: " + customer.getCompany());
|
||||
}
|
||||
if (!Hibernate.isInitialized(company)) {
|
||||
company = getCompanyService().findById(company.getId());
|
||||
company = getCompanyService().getById(company.getId());
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(company.getPath())) {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ProjectCostImportItemsFromContractsTasker extends Tasker<Object> im
|
||||
@Override
|
||||
public void setSession(SessionInfo session) {
|
||||
currentUser = () -> {
|
||||
return getEmployeeService().findById(session.getEmployeeId());
|
||||
return getEmployeeService().getById(session.getEmployeeId());
|
||||
};
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ public class ProjectCostImportItemsFromContractsTasker extends Tasker<Object> im
|
||||
@Override
|
||||
public void init(JsonNode argsNode) {
|
||||
int contractId = argsNode.get(0).asInt();
|
||||
cost = getCachedBean(ProjectCostService.class).findById(contractId);
|
||||
cost = getCachedBean(ProjectCostService.class).getById(contractId);
|
||||
}
|
||||
|
||||
public void importFromContracts(ProjectCost projectCost, MessageHolder holder) {
|
||||
Project project = projectCost.getProject();
|
||||
List<ProjectCostItem> projectCostItems = getItemService().findByCost(projectCost);
|
||||
List<ProjectCostItem> projectCostItems = getItemService().findByCostId(projectCost.getId());
|
||||
List<Contract> salesContracts = getContractService().findAllSalesByProject(project);
|
||||
holder.debug("检索到 " + salesContracts.size() + " 个销售合同, 导入合同数据...");
|
||||
|
||||
@@ -182,7 +182,7 @@ public class ProjectCostImportItemsFromContractsTasker extends Tasker<Object> im
|
||||
// 根据存货匹配,可对多个相同的存货进行合并
|
||||
for (Map.Entry<Inventory, List<ContractItem>> entry : map.entrySet()) {
|
||||
Inventory inventory = Hibernate.isInitialized(entry.getKey()) ? entry.getKey()
|
||||
: getInventoryService().findById(entry.getKey().getId());
|
||||
: getInventoryService().getById(entry.getKey().getId());
|
||||
if (inventory == null) {
|
||||
// 存货编号没有,则使用 项目名称+规格 来判断是否有数据
|
||||
entry.getValue().stream().filter(item -> item.getInventory() == null)
|
||||
|
||||
Reference in New Issue
Block a user