【feat】增加org配置连接检测

This commit is contained in:
Kris 2025-07-02 15:51:44 +08:00
parent 8ab83d71e5
commit 006ceba211
3 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package com.celnet.datadump.job;
import com.celnet.datadump.service.OrgConfigService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class OrgConfigJob {
@Autowired
private OrgConfigService orgConfigService;
@XxlJob("getOrgConfigJob")
public ReturnT<String> getOrgConfigJob(String paramStr) throws Exception {
log.info("getOrgConfigJob execute start ..................");
orgConfigService.verifyOrgConfig();
return null;
}
}

View File

@ -9,4 +9,6 @@ import com.celnet.datadump.entity.SystemConfig;
*/ */
public interface OrgConfigService extends IService<OrgConfig> { public interface OrgConfigService extends IService<OrgConfig> {
void verifyOrgConfig();
} }

View File

@ -1,18 +1,135 @@
package com.celnet.datadump.service.impl; package com.celnet.datadump.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.celnet.datadump.config.SalesforceConnect;
import com.celnet.datadump.config.SalesforceTargetConnect;
import com.celnet.datadump.entity.OrgConfig; import com.celnet.datadump.entity.OrgConfig;
import com.celnet.datadump.entity.SystemConfig; import com.celnet.datadump.entity.SystemConfig;
import com.celnet.datadump.mapper.CustomMapper;
import com.celnet.datadump.mapper.OrgConfigMapper; import com.celnet.datadump.mapper.OrgConfigMapper;
import com.celnet.datadump.mapper.SystemConfigMapper; import com.celnet.datadump.mapper.SystemConfigMapper;
import com.celnet.datadump.service.OrgConfigService; import com.celnet.datadump.service.OrgConfigService;
import com.celnet.datadump.service.SystemConfigService; import com.celnet.datadump.service.SystemConfigService;
import com.celnet.datadump.util.EmailUtil;
import com.sforce.soap.partner.PartnerConnection;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* org配置表 服务实现类 * org配置表 服务实现类
*/ */
@Service @Service
public class OrgConfigServiceImpl extends ServiceImpl<OrgConfigMapper, OrgConfig> implements OrgConfigService { public class OrgConfigServiceImpl extends ServiceImpl<OrgConfigMapper, OrgConfig> implements OrgConfigService {
@Resource
private CustomMapper customerMapper;
@Override
public void verifyOrgConfig() {
boolean flag = true;
String sourceOrgUrl = null;
String targetOrgUrl = null;
try {
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
//遍历poll,找出code值为SOURCE_ORG_URLSOURCE_ORG_USERNAMESOURCE_ORG_PASSWORD的value值
Map<String, String> map = new HashMap<>();
for (Map<String, Object> map1 : poll) {
if ("SOURCE_ORG_URL".equals(map1.get("code"))) {
map.put("url", (String) map1.get("value"));
sourceOrgUrl = map1.get("value").toString();
}
if ("SOURCE_ORG_USERNAME".equals(map1.get("code"))) {
map.put("username", (String) map1.get("value"));
}
if ("SOURCE_ORG_PASSWORD".equals(map1.get("code"))) {
map.put("password", String.valueOf(map1.get("value")));
}
}
String username = map.get("username");
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(map.get("password"));
String url = map.get("url");
config.setAuthEndpoint(url);
config.setServiceEndpoint(url);
config.setConnectionTimeout(60 * 60 * 1000);
config.setReadTimeout(60 * 60 * 1000);
PartnerConnection connection = new PartnerConnection(config);
String orgId = connection.getUserInfo().getOrganizationId();
if (StringUtils.isEmpty(orgId)){
String message = "源ORG连接配置错误";
String format = String.format("ORG连接异常, \ncause:\n%s", message);
EmailUtil.send("DataDump ERROR", format);
flag = false;
}
} catch (ConnectionException e) {
String message = "源ORG连接配置错误";
String format = String.format("ORG连接异常, \ncause:\n%s", message);
EmailUtil.send("DataDump ERROR", format);
log.error("exception message", e);
flag = false;
}
try {
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
//遍历poll,找出code值为TARGET_ORG_URLTARGET_ORG_USERNAMETARGET_ORG_PASSWORD的value值
Map<String, String> map = new HashMap<>();
for (Map<String, Object> map1 : poll) {
if ("TARGET_ORG_URL".equals(map1.get("code"))) {
map.put("url", (String) map1.get("value"));
targetOrgUrl = map1.get("value").toString();
}
if ("TARGET_ORG_USERNAME".equals(map1.get("code"))) {
map.put("username", (String) map1.get("value"));
}
if ("TARGET_ORG_PASSWORD".equals(map1.get("code"))) {
map.put("password", (String) map1.get("value"));
}
}
String username = map.get("username");
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(map.get("password"));
String url = map.get("url");
config.setAuthEndpoint(url);
config.setServiceEndpoint(url);
config.setConnectionTimeout(60 * 60 * 1000);
config.setReadTimeout(60 * 60 * 1000);
PartnerConnection connection = new PartnerConnection(config);
String orgId = connection.getUserInfo().getOrganizationId();
if (StringUtils.isEmpty(orgId)){
String message = "目标ORG连接配置错误";
String format = String.format("ORG连接异常, \ncause:\n%s", message);
EmailUtil.send("DataDump ERROR", format);
flag = false;
}
} catch (ConnectionException e) {
String message = "目标ORG连接配置错误";
String format = String.format("ORG连接异常, \ncause:\n%s", message);
EmailUtil.send("DataDump ERROR", format);
log.error("exception message", e);
flag = false;
}
if (flag){
String message = "源ORG与目标ORG连接配置成功";
String format = String.format("ORG连接成功, \ncause:\n%s , \n源ORG地址:\n%s , \n目标ORG地址:\n%s", message,sourceOrgUrl,targetOrgUrl);
EmailUtil.send("DataDump ERROR", format);
}
}
} }