data-dump/src/main/java/com/celnet/datadump/service/impl/OrgConfigServiceImpl.java

124 lines
5.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.celnet.datadump.service.impl;
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.SystemConfig;
import com.celnet.datadump.mapper.CustomMapper;
import com.celnet.datadump.mapper.OrgConfigMapper;
import com.celnet.datadump.mapper.SystemConfigMapper;
import com.celnet.datadump.service.OrgConfigService;
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 javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* org配置表 服务实现类
*/
@Service
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();
} catch (ConnectionException e) {
String message = "源ORG连接配置错误,\n地址" + sourceOrgUrl;
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();
} catch (ConnectionException e) {
String message = "目标ORG连接配置错误,\n地址" + targetOrgUrl;
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);
}
}
}