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 implements OrgConfigService { @Resource private CustomMapper customerMapper; @Override public void verifyOrgConfig() { boolean flag = true; String sourceOrgUrl = null; String targetOrgUrl = null; try { List> poll = customerMapper.list("code,value","org_config",null); //遍历poll,找出code值为SOURCE_ORG_URL,SOURCE_ORG_USERNAME,SOURCE_ORG_PASSWORD的value值 Map map = new HashMap<>(); for (Map 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> poll = customerMapper.list("code,value","org_config",null); //遍历poll,找出code值为TARGET_ORG_URL,TARGET_ORG_USERNAME,TARGET_ORG_PASSWORD的value值 Map map = new HashMap<>(); for (Map 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); } } }