|
@@ -1,17 +1,34 @@
|
|
package cn.iocoder.yudao.module.pms.oa;
|
|
package cn.iocoder.yudao.module.pms.oa;
|
|
|
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.oa.IotOaCompanyDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.oa.IotOaDepartDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.oa.IotOaPersonDO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.oa.IotOaCompanyMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.oa.IotOaDepartMapper;
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.oa.IotOaPersonMapper;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
@Component
|
|
@Component
|
|
public class OaFlow {
|
|
public class OaFlow {
|
|
|
|
+ private final IotOaCompanyMapper iotOaCompanyMapper;
|
|
|
|
+ private final IotOaDepartMapper iotOaDepartMapper;
|
|
|
|
+ private final IotOaPersonMapper iotOaPersonMapper;
|
|
@Value("${oa.appid}")
|
|
@Value("${oa.appid}")
|
|
private String appid;
|
|
private String appid;
|
|
@Value("${oa.cpk}")
|
|
@Value("${oa.cpk}")
|
|
@@ -20,13 +37,23 @@ public class OaFlow {
|
|
private String registerUrl;
|
|
private String registerUrl;
|
|
@Value("${oa.gettoken}")
|
|
@Value("${oa.gettoken}")
|
|
private String tokenUrl;
|
|
private String tokenUrl;
|
|
|
|
+ @Value("${oa.companyUrl}")
|
|
|
|
+ private String companyUrl;
|
|
|
|
+ @Value("${oa.departmentUrl}")
|
|
|
|
+ private String departmentUrl;
|
|
@Value("${oa.userUrl}")
|
|
@Value("${oa.userUrl}")
|
|
private String userUrl;
|
|
private String userUrl;
|
|
private static String spk = "";
|
|
private static String spk = "";
|
|
private static String secret = "";
|
|
private static String secret = "";
|
|
|
|
|
|
|
|
+ public OaFlow(IotOaCompanyMapper iotOaCompanyMapper, IotOaDepartMapper iotOaDepartMapper, IotOaPersonMapper iotOaPersonMapper) {
|
|
|
|
+ this.iotOaCompanyMapper = iotOaCompanyMapper;
|
|
|
|
+ this.iotOaDepartMapper = iotOaDepartMapper;
|
|
|
|
+ this.iotOaPersonMapper = iotOaPersonMapper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
- public void regist() throws Exception{
|
|
|
|
|
|
+ public void register() throws Exception{
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
headers.add("appid", appid);
|
|
headers.add("appid", appid);
|
|
headers.add("cpk", cpk);
|
|
headers.add("cpk", cpk);
|
|
@@ -42,9 +69,9 @@ public class OaFlow {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public void getToken() throws Exception{
|
|
|
|
|
|
+ public String getToken() throws Exception{
|
|
if (StringUtils.isBlank(spk) || StringUtils.isBlank(secret)) {
|
|
if (StringUtils.isBlank(spk) || StringUtils.isBlank(secret)) {
|
|
- regist();
|
|
|
|
|
|
+ register();
|
|
}
|
|
}
|
|
String secretEn = E9ApiTokenUtil.encryptString(spk, secret);
|
|
String secretEn = E9ApiTokenUtil.encryptString(spk, secret);
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -58,13 +85,117 @@ public class OaFlow {
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
String token = String.valueOf(jsonObject.get("token"));
|
|
String token = String.valueOf(jsonObject.get("token"));
|
|
System.out.println("result:" + result);
|
|
System.out.println("result:" + result);
|
|
|
|
+ return token;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void getCompany() throws Exception{
|
|
|
|
+ String token = getToken();
|
|
|
|
+ HttpHeaders headersOut = new HttpHeaders();
|
|
|
|
+ headersOut.add("token", token);
|
|
|
|
+ headersOut.add("appid", appid);
|
|
|
|
+ headersOut.add("userid", "cLPEaFs9moW6b3xZMl1kNNWAAo7bp61ZRRTKmpiJUe56hSxQvrC2vWtY5ogj7g5FAnUOlzYjYg9MRktKXcseh/nsvZCQGa3BAlYixlDJruV19y4Omx5dYnqu/qv2rJAqTzUS71sOwuB1M2nKlLVsphw1GF74UhGP4xsjpZP7mC8=");
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("pagesize",1000000);
|
|
|
|
+ params.put("params", map);
|
|
|
|
+ // 3. 组合请求头和请求体
|
|
|
|
+ HttpEntity<Map<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
|
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
|
+ String company = restTemplate.postForObject(companyUrl, requestEntityOut, String.class);
|
|
|
|
+ JSONObject companyInfo = JSON.parseObject(company);
|
|
|
|
+ //请求成功
|
|
|
|
+ if (Objects.nonNull(companyInfo)&&"1".equals(String.valueOf(companyInfo.get("code")))){
|
|
|
|
+ if (Objects.nonNull(companyInfo.get("data"))) {
|
|
|
|
+ JSONObject resultJson = JSON.parseObject(companyInfo.get("data").toString());
|
|
|
|
+ if (Objects.nonNull(resultJson.get("dataList"))) {
|
|
|
|
+ //先删除
|
|
|
|
+ List<Long> ids = iotOaCompanyMapper.selectList().stream().map(IotOaCompanyDO::getId).collect(Collectors.toList());
|
|
|
|
+ iotOaCompanyMapper.deleteByIds(ids);
|
|
|
|
+ JSON.parseArray(resultJson.get("dataList").toString(),IotOaCompanyDO.class).forEach(item -> {
|
|
|
|
+ IotOaCompanyDO companyDO = new IotOaCompanyDO();
|
|
|
|
+ BeanUtils.copyProperties(item,companyDO);
|
|
|
|
+ companyDO.setOaId(String.valueOf(companyDO.getId()));
|
|
|
|
+ companyDO.setId(null);
|
|
|
|
+ companyDO.setDeleted(false);
|
|
|
|
+ iotOaCompanyMapper.insert(companyDO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ public void getDepart() throws Exception {
|
|
|
|
+ String token = getToken();
|
|
HttpHeaders headersOut = new HttpHeaders();
|
|
HttpHeaders headersOut = new HttpHeaders();
|
|
- headersOut.add("Authorization", token);
|
|
|
|
|
|
+ headersOut.add("token", token);
|
|
|
|
+ headersOut.add("appid", appid);
|
|
|
|
+ headersOut.add("userid", "cLPEaFs9moW6b3xZMl1kNNWAAo7bp61ZRRTKmpiJUe56hSxQvrC2vWtY5ogj7g5FAnUOlzYjYg9MRktKXcseh/nsvZCQGa3BAlYixlDJruV19y4Omx5dYnqu/qv2rJAqTzUS71sOwuB1M2nKlLVsphw1GF74UhGP4xsjpZP7mC8=");
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("pagesize",1000000);
|
|
|
|
+ params.put("params", map);
|
|
|
|
+ // 3. 组合请求头和请求体
|
|
|
|
+ HttpEntity<Map<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
|
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
|
+ String company = restTemplate.postForObject(departmentUrl, requestEntityOut, String.class);
|
|
|
|
+ JSONObject companyInfo = JSON.parseObject(company);
|
|
|
|
+ //请求成功
|
|
|
|
+ if (Objects.nonNull(companyInfo) && "1".equals(String.valueOf(companyInfo.get("code")))) {
|
|
|
|
+ if (Objects.nonNull(companyInfo.get("data"))) {
|
|
|
|
+ JSONObject resultJson = JSON.parseObject(companyInfo.get("data").toString());
|
|
|
|
+ if (Objects.nonNull(resultJson.get("dataList"))) {
|
|
|
|
+ //先删除
|
|
|
|
+ List<Long> ids = iotOaDepartMapper.selectList().stream().map(IotOaDepartDO::getId).collect(Collectors.toList());
|
|
|
|
+ iotOaDepartMapper.deleteByIds(ids);
|
|
|
|
+ JSON.parseArray(resultJson.get("dataList").toString(), IotOaDepartDO.class).forEach(item -> {
|
|
|
|
+ IotOaDepartDO iotOaDepartDO = new IotOaDepartDO();
|
|
|
|
+ BeanUtils.copyProperties(item, iotOaDepartDO);
|
|
|
|
+ iotOaDepartDO.setOaId(String.valueOf(iotOaDepartDO.getId()));
|
|
|
|
+ iotOaDepartDO.setId(null);
|
|
|
|
+ iotOaDepartDO.setDeleted(false);
|
|
|
|
+ iotOaDepartMapper.insert(iotOaDepartDO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- HttpEntity<MultiValueMap<String, String>> requestEntityOut = new HttpEntity<>(headersOut);
|
|
|
|
- String user = restTemplate.postForObject(userUrl, requestEntityOut, String.class);
|
|
|
|
- JSONObject userInfo = JSON.parseObject(result);
|
|
|
|
- System.out.println("user:" + user);
|
|
|
|
|
|
+ public void getPerson() throws Exception {
|
|
|
|
+ String token = getToken();
|
|
|
|
+ HttpHeaders headersOut = new HttpHeaders();
|
|
|
|
+ headersOut.add("token", token);
|
|
|
|
+ headersOut.add("appid", appid);
|
|
|
|
+ headersOut.add("userid", "cLPEaFs9moW6b3xZMl1kNNWAAo7bp61ZRRTKmpiJUe56hSxQvrC2vWtY5ogj7g5FAnUOlzYjYg9MRktKXcseh/nsvZCQGa3BAlYixlDJruV19y4Omx5dYnqu/qv2rJAqTzUS71sOwuB1M2nKlLVsphw1GF74UhGP4xsjpZP7mC8=");
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("pagesize",1000000);
|
|
|
|
+ params.put("params", map);
|
|
|
|
+ // 3. 组合请求头和请求体
|
|
|
|
+ HttpEntity<Map<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
|
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
|
+ String company = restTemplate.postForObject(userUrl, requestEntityOut, String.class);
|
|
|
|
+ JSONObject companyInfo = JSON.parseObject(company);
|
|
|
|
+ //请求成功
|
|
|
|
+ if (Objects.nonNull(companyInfo) && "1".equals(String.valueOf(companyInfo.get("code")))) {
|
|
|
|
+ if (Objects.nonNull(companyInfo.get("data"))) {
|
|
|
|
+ JSONObject resultJson = JSON.parseObject(companyInfo.get("data").toString());
|
|
|
|
+ if (Objects.nonNull(resultJson.get("dataList"))) {
|
|
|
|
+ //先删除
|
|
|
|
+ List<Long> ids = iotOaPersonMapper.selectList().stream().map(IotOaPersonDO::getId).collect(Collectors.toList());
|
|
|
|
+ iotOaPersonMapper.deleteByIds(ids);
|
|
|
|
+ JSON.parseArray(resultJson.get("dataList").toString(), IotOaPersonDO.class).forEach(item -> {
|
|
|
|
+ IotOaPersonDO iotOaPersonDO = new IotOaPersonDO();
|
|
|
|
+ BeanUtils.copyProperties(item, iotOaPersonDO);
|
|
|
|
+ iotOaPersonDO.setOaId(String.valueOf(iotOaPersonDO.getId()));
|
|
|
|
+ iotOaPersonDO.setId(null);
|
|
|
|
+ iotOaPersonDO.setDeleted(false);
|
|
|
|
+ iotOaPersonMapper.insert(iotOaPersonDO);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|