refactor(service): 修改IEntityService泛型为VO类型并优化缓存策略
重构所有注解@CacheConfig的Service类,将IEntityService泛型从实体类改为VO类 实现实体与VO之间的转换逻辑,使用VO替代实体进行缓存以避免序列化问题 更新相关依赖组件和测试用例,确保功能完整性和系统兼容性 优化Redis缓存配置,清理旧缓存数据并验证新缓存策略有效性
This commit is contained in:
@@ -39,9 +39,8 @@ public class CloudRkSyncTask extends Tasker<Object> {
|
||||
try {
|
||||
cloudRkCtx = new CloudRkCtx();
|
||||
service = SpringApp.getBean(CloudRkService.class);
|
||||
cloudRkCtx.setCloudRkService(service);
|
||||
} catch (BeansException e) {
|
||||
holder.error("没有找到 " + CloudServiceConstant.RK_NAME + " 服务");
|
||||
holder.error(CloudServiceConstant.RK_NAME + " 服务未启用");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
package com.ecep.contract.cloud.rk.ctx;
|
||||
|
||||
import com.ecep.contract.cloud.rk.CloudRkService;
|
||||
import org.springframework.beans.BeansException;
|
||||
|
||||
public interface CloudRkContext {
|
||||
<T> T getBean(Class<T> requiredType) throws BeansException;
|
||||
|
||||
default CloudRkService getCloudRkService() {
|
||||
return getBean(CloudRkService.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.ecep.contract.cloud.rk.ctx;
|
||||
|
||||
import static com.ecep.contract.SpringApp.getBean;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -31,13 +29,11 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import com.ecep.contract.BlackReasonType;
|
||||
import com.ecep.contract.MessageHolder;
|
||||
import com.ecep.contract.SpringApp;
|
||||
import com.ecep.contract.cloud.AbstractCtx;
|
||||
import com.ecep.contract.cloud.rk.CloudRkService;
|
||||
import com.ecep.contract.ds.company.service.CompanyBlackReasonService;
|
||||
import com.ecep.contract.ds.company.service.CompanyContactService;
|
||||
import com.ecep.contract.ds.company.service.CompanyOldNameService;
|
||||
import com.ecep.contract.ds.company.service.CompanyService;
|
||||
import com.ecep.contract.model.CloudRk;
|
||||
import com.ecep.contract.model.Company;
|
||||
import com.ecep.contract.model.CompanyBlackReason;
|
||||
@@ -50,46 +46,16 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
public class CloudRkCtx extends AbstractCtx {
|
||||
public class CloudRkCtx extends AbstractCtx implements CloudRkContext {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CloudRkCtx.class);
|
||||
@Setter
|
||||
private CloudRkService cloudRkService;
|
||||
@Setter
|
||||
private CompanyService companyService;
|
||||
@Setter
|
||||
private CompanyBlackReasonService companyBlackReasonService;
|
||||
@Setter
|
||||
private ObjectMapper objectMapper;
|
||||
private Proxy socksProxy;
|
||||
|
||||
public CloudRkService getCloudRkService() {
|
||||
if (cloudRkService == null) {
|
||||
cloudRkService = getBean(CloudRkService.class);
|
||||
}
|
||||
return cloudRkService;
|
||||
}
|
||||
|
||||
public CompanyService getCompanyService() {
|
||||
if (companyService == null) {
|
||||
companyService = getBean(CompanyService.class);
|
||||
}
|
||||
return companyService;
|
||||
}
|
||||
|
||||
CompanyBlackReasonService getCompanyBlackReasonService() {
|
||||
if (companyBlackReasonService == null) {
|
||||
companyBlackReasonService = getBean(CompanyBlackReasonService.class);
|
||||
}
|
||||
return companyBlackReasonService;
|
||||
return getCachedBean(CompanyBlackReasonService.class);
|
||||
}
|
||||
|
||||
ObjectMapper getObjectMapper() {
|
||||
if (objectMapper == null) {
|
||||
objectMapper = getBean(ObjectMapper.class);
|
||||
}
|
||||
return objectMapper;
|
||||
return getCachedBean(ObjectMapper.class);
|
||||
}
|
||||
|
||||
Proxy getSocksProxy() {
|
||||
@@ -150,7 +116,11 @@ public class CloudRkCtx extends AbstractCtx {
|
||||
} catch (Exception e) {
|
||||
// 异常
|
||||
logger.error("使用评分接口更新企业资信评价等级时发生错误", e);
|
||||
cloudRk.setDescription("评分接口错误:" + e.getMessage());
|
||||
String message = "评分接口错误:" + e.getMessage();
|
||||
if (message.length() > 50) {
|
||||
message = message.substring(0, 50);
|
||||
}
|
||||
cloudRk.setDescription(message);
|
||||
}
|
||||
return updated;
|
||||
}
|
||||
@@ -172,11 +142,12 @@ public class CloudRkCtx extends AbstractCtx {
|
||||
}
|
||||
}
|
||||
|
||||
CompanyBlackReasonService companyBlackReasonService = getCompanyBlackReasonService();
|
||||
String api = getConfService().getString(CloudRkService.KEY_BLACK_LIST_URL);
|
||||
List<String> companyNames = getCompanyService().getAllNames(company);
|
||||
|
||||
List<CompanyBlackReason> reasonList = new ArrayList<>();
|
||||
List<CompanyBlackReason> dbReasons = getCompanyBlackReasonService().findAllByCompany(company);
|
||||
List<CompanyBlackReason> dbReasons = companyBlackReasonService.findAllByCompany(company);
|
||||
for (String name : companyNames) {
|
||||
String url = api + URLEncoder.encode(name, StandardCharsets.UTF_8);
|
||||
try {
|
||||
@@ -195,7 +166,7 @@ public class CloudRkCtx extends AbstractCtx {
|
||||
|
||||
}
|
||||
for (CompanyBlackReason companyBlackReason : reasonList) {
|
||||
getCompanyBlackReasonService().save(companyBlackReason);
|
||||
companyBlackReasonService.save(companyBlackReason);
|
||||
}
|
||||
cloudRk.setCloudBlackListUpdated(LocalDateTime.now());
|
||||
return true;
|
||||
@@ -634,14 +605,15 @@ public class CloudRkCtx extends AbstractCtx {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public boolean updateLocalDateTime(Supplier<LocalDateTime> getter, Consumer<LocalDateTime> setter, JsonNode data,String field,
|
||||
public boolean updateLocalDateTime(Supplier<LocalDateTime> getter, Consumer<LocalDateTime> setter, JsonNode data,
|
||||
String field,
|
||||
MessageHolder holder, String topic) {
|
||||
JsonNode node = data.get(field);
|
||||
JsonNode node = data.get(field);
|
||||
if (node == null || node.isNull()) {
|
||||
return false;
|
||||
}
|
||||
LocalDateTime updated = getObjectMapper().convertValue(node, LocalDateTime.class);
|
||||
updateLocalDateTime(getter, setter, updated, holder, topic);
|
||||
LocalDateTime updated = getObjectMapper().convertValue(node, LocalDateTime.class);
|
||||
updateLocalDateTime(getter, setter, updated, holder, topic);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -654,7 +626,7 @@ public class CloudRkCtx extends AbstractCtx {
|
||||
return;
|
||||
}
|
||||
|
||||
CompanyContactService contactService = SpringApp.getBean(CompanyContactService.class);
|
||||
CompanyContactService contactService = getCachedBean(CompanyContactService.class);
|
||||
List<CompanyContact> contactList = contactService.findAllByCompanyAndName(company, legalRepresentative);
|
||||
if (contactList == null) {
|
||||
// db error
|
||||
@@ -746,7 +718,7 @@ public class CloudRkCtx extends AbstractCtx {
|
||||
historyNames.add(trimmed);
|
||||
}
|
||||
}
|
||||
CompanyOldNameService service = SpringApp.getBean(CompanyOldNameService.class);
|
||||
CompanyOldNameService service = getCachedBean(CompanyOldNameService.class);
|
||||
List<CompanyOldName> oldNames = service.findAllByCompany(company);
|
||||
for (CompanyOldName oldName : oldNames) {
|
||||
// 已经存在的移除
|
||||
|
||||
Reference in New Issue
Block a user