70 lines
2.2 KiB
Java
70 lines
2.2 KiB
Java
|
|
package com.celnet.datadump.config;
|
|||
|
|
|
|||
|
|
import com.alibaba.fastjson.JSONArray;
|
|||
|
|
import com.celnet.datadump.mapper.CustomMapper;
|
|||
|
|
import com.google.common.collect.Lists;
|
|||
|
|
import com.sforce.soap.partner.PartnerConnection;
|
|||
|
|
import com.sforce.ws.ConnectionException;
|
|||
|
|
import com.sforce.ws.ConnectorConfig;
|
|||
|
|
import lombok.extern.slf4j.Slf4j;
|
|||
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||
|
|
import org.springframework.stereotype.Component;
|
|||
|
|
|
|||
|
|
import javax.annotation.Resource;
|
|||
|
|
import java.util.HashMap;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.Map;
|
|||
|
|
import java.util.Queue;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @author Red
|
|||
|
|
* @description
|
|||
|
|
* @date 2022/09/23
|
|||
|
|
*/
|
|||
|
|
@Component
|
|||
|
|
@Slf4j
|
|||
|
|
public class SalesforceConnect {
|
|||
|
|
|
|||
|
|
@Resource
|
|||
|
|
private CustomMapper customerMapper;
|
|||
|
|
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 创建连接
|
|||
|
|
* @return
|
|||
|
|
*/
|
|||
|
|
public PartnerConnection createConnect() {
|
|||
|
|
try {
|
|||
|
|
List<Map<String, Object>> poll = customerMapper.list("code,value","org_config",null);
|
|||
|
|
//遍历poll,找出code值为SOURCE_ORG_URL,SOURCE_ORG_USERNAME,SOURCE_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"));
|
|||
|
|
}
|
|||
|
|
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);
|
|||
|
|
return new PartnerConnection(config);
|
|||
|
|
} catch (ConnectionException e) {
|
|||
|
|
e.printStackTrace();
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|