|
|
@@ -1,27 +1,37 @@
|
|
|
package cn.iocoder.yudao.module.system.oa;
|
|
|
|
|
|
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oa.IotOaCompanyDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oa.IotOaDepartDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.oa.IotOaPersonDO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oa.IotOaCompanyMapper;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oa.IotOaDepartMapper;
|
|
|
import cn.iocoder.yudao.module.system.dal.mysql.oa.IotOaPersonMapper;
|
|
|
+import cn.iocoder.yudao.module.system.service.user.AdminUserServiceImpl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Builder;
|
|
|
import lombok.Data;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
+import lombok.extern.java.Log;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
+import software.amazon.awssdk.core.traits.ListTrait;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -31,6 +41,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
@Component
|
|
|
public class OaFlow {
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
private final IotOaCompanyMapper iotOaCompanyMapper;
|
|
|
private final IotOaDepartMapper iotOaDepartMapper;
|
|
|
private final IotOaPersonMapper iotOaPersonMapper;
|
|
|
@@ -61,6 +73,12 @@ public class OaFlow {
|
|
|
|
|
|
private static String spk = "";
|
|
|
private static String secret = "";
|
|
|
+ @Autowired
|
|
|
+ private PasswordEncoder passwordEncoder;
|
|
|
+ @Autowired
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+ @Autowired
|
|
|
+ private AdminUserServiceImpl adminUserService;
|
|
|
|
|
|
public OaFlow(IotOaCompanyMapper iotOaCompanyMapper, IotOaDepartMapper iotOaDepartMapper, IotOaPersonMapper iotOaPersonMapper) {
|
|
|
this.iotOaCompanyMapper = iotOaCompanyMapper;
|
|
|
@@ -195,8 +213,8 @@ public class OaFlow {
|
|
|
public void getPerson() throws Exception {
|
|
|
String token = getToken();
|
|
|
HttpHeaders headersOut = new HttpHeaders();
|
|
|
- headersOut.add("token", token);
|
|
|
- headersOut.add("appid", appid);
|
|
|
+// headersOut.add("token", token);
|
|
|
+// headersOut.add("appid", appid);
|
|
|
// headersOut.add("userid", userid);
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
@@ -206,7 +224,7 @@ public class OaFlow {
|
|
|
params.put("params", map);
|
|
|
// 3. 组合请求头和请求体
|
|
|
HttpEntity<Map<String, Object>> requestEntityOut = new HttpEntity<>(params, headersOut);
|
|
|
- RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+// RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
String company = restTemplate.postForObject(userUrl, requestEntityOut, String.class);
|
|
|
JSONObject companyInfo = JSON.parseObject(company);
|
|
|
//请求成功
|
|
|
@@ -232,8 +250,71 @@ public class OaFlow {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private RestTemplate restTemplate;
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void getOaPerson() throws Exception {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ // 3. 组合请求头和请求体
|
|
|
+ HttpEntity<Map<String, Object>> requestEntityOut = new HttpEntity<>(params);
|
|
|
+// RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+ String company = restTemplate.postForObject(userUrl, requestEntityOut, String.class);
|
|
|
+ JSONObject companyInfo = JSON.parseObject(company);
|
|
|
+ //请求成功
|
|
|
+ if (Objects.nonNull(companyInfo) && "true".equals(String.valueOf(companyInfo.get("success")))) {
|
|
|
+ if (Objects.nonNull(companyInfo.get("data"))) {
|
|
|
+ List<OaPersonVO> data = JSON.parseArray(companyInfo.get("data").toString(), OaPersonVO.class);
|
|
|
+ List<IotOaPersonDO> iotOaPersonDOS = iotOaPersonMapper.selectList();
|
|
|
+ List<String> workcodes = iotOaPersonDOS.stream().map(IotOaPersonDO::getWorkcode).collect(Collectors.toList());
|
|
|
+ TenantUtils.execute(1L, () -> {
|
|
|
+ data.forEach(item -> {
|
|
|
+ //更新
|
|
|
+ if (Objects.nonNull(item.getLoginid())&&StringUtils.isNotBlank(item.getLoginid())) {
|
|
|
+ if (workcodes.contains(item.getLoginid())) {
|
|
|
+ iotOaPersonDOS.stream().filter(f -> Objects.nonNull(f.getWorkcode())&&f.getWorkcode().equals(item.getLoginid())).findAny().ifPresent(workcode -> {
|
|
|
+ workcode.setDepartmentid(String.valueOf(item.getDepartmentid()));
|
|
|
+ workcode.setStatus(String.valueOf(item.getStatus()));
|
|
|
+ iotOaPersonMapper.updateById(workcode);
|
|
|
+ });
|
|
|
+ } else {//新增
|
|
|
+ IotOaPersonDO iotOaPersonDO = new IotOaPersonDO();
|
|
|
+ iotOaPersonDO.setOaId(String.valueOf(item.getId()));
|
|
|
+ iotOaPersonDO.setDeleted(false);
|
|
|
+ iotOaPersonDO.setWorkcode(item.getLoginid());
|
|
|
+ iotOaPersonDO.setMobile(String.valueOf(item.getMobile()));
|
|
|
+ iotOaPersonDO.setLastname(String.valueOf(item.getLastname()));
|
|
|
+ iotOaPersonDO.setStatus(String.valueOf(item.getStatus()));
|
|
|
+ iotOaPersonMapper.insert(iotOaPersonDO);
|
|
|
+ AdminUserRespDTO userByUsername = adminUserApi.getUserByUsername(item.getLoginid());
|
|
|
+ if (Objects.isNull(userByUsername)) {
|
|
|
+ AdminUserDO adminUserDO = new AdminUserDO();
|
|
|
+ adminUserDO.setNickname(item.getLastname());
|
|
|
+ adminUserDO.setDeleted(false);
|
|
|
+ adminUserDO.setUsername(item.getLoginid());
|
|
|
+ if (StringUtils.isNotBlank(item.getMobile())&&item.getMobile().length()<12)
|
|
|
+ adminUserDO.setMobile(item.getMobile());
|
|
|
+ adminUserDO.setPassword(passwordEncoder.encode("rqny2026*"));
|
|
|
+ UserSaveReqVO userSaveReqVO = new UserSaveReqVO();
|
|
|
+ BeanUtils.copyProperties(adminUserDO, userSaveReqVO);
|
|
|
+ adminUserService.createUser(userSaveReqVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class OaPersonVO{
|
|
|
+ private String loginid;
|
|
|
+ private String departmentid;
|
|
|
+ private String mobile;
|
|
|
+ private String id;
|
|
|
+ private String subcompanyid1;
|
|
|
+ private String lastname;
|
|
|
+ private String status;
|
|
|
+ }
|
|
|
|
|
|
/* public void createOutRepairFlow(IotMaintainDO iotMaintainDO) throws Exception {
|
|
|
String token = getToken();
|