|
@@ -1,9 +1,11 @@
|
|
|
package org.dromara.server.sync.service;
|
|
package org.dromara.server.sync.service;
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
import org.dromara.server.base.service.dept.strategy.SyncDeptStrategyContent;
|
|
import org.dromara.server.base.service.dept.strategy.SyncDeptStrategyContent;
|
|
|
import org.dromara.server.base.service.user.strategy.SyncUserStrategyContent;
|
|
import org.dromara.server.base.service.user.strategy.SyncUserStrategyContent;
|
|
|
import org.dromara.server.common.constant.DefaultConstants;
|
|
import org.dromara.server.common.constant.DefaultConstants;
|
|
@@ -11,6 +13,7 @@ import org.dromara.server.common.constant.SyncResourceConstants;
|
|
|
import org.dromara.server.common.domain.bo.ResourceDept;
|
|
import org.dromara.server.common.domain.bo.ResourceDept;
|
|
|
import org.dromara.server.common.domain.bo.ResourcePerson;
|
|
import org.dromara.server.common.domain.bo.ResourcePerson;
|
|
|
import org.dromara.server.common.domain.bo.SyncFullDataBo;
|
|
import org.dromara.server.common.domain.bo.SyncFullDataBo;
|
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -35,32 +38,89 @@ public class SyncHrService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 同步教职工部门数据,该方法将提供给定时任务调用
|
|
* 同步教职工部门数据,该方法将提供给定时任务调用
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return boolean
|
|
|
*/
|
|
*/
|
|
|
- public void syncDept() {
|
|
|
|
|
|
|
+ public Boolean syncDept() {
|
|
|
HttpRequest req = CreateHttpRequest.createRequest();
|
|
HttpRequest req = CreateHttpRequest.createRequest();
|
|
|
req.body(getQueryBodyForDept());
|
|
req.body(getQueryBodyForDept());
|
|
|
|
|
|
|
|
- SyncFullDataBo dataBo = JSONUtil.toBean(req.execute().body(), SyncFullDataBo.class);
|
|
|
|
|
|
|
+ try (HttpResponse res = req.execute()) {
|
|
|
|
|
+ SyncFullDataBo dataBo = JSONUtil.toBean(res.body(), SyncFullDataBo.class);
|
|
|
|
|
+ List<ResourceDept> resourceDeptlist = getResourceDeptList(dataBo);
|
|
|
|
|
+ log.info("[全量获取到的部门数据]-共[{}]条-[{}]", resourceDeptlist.size(), JSONUtil.toJsonStr(dataBo));
|
|
|
|
|
+ syncDeptStrategyContent.syncDept(resourceDeptlist, SyncResourceConstants.HR_DEPT);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 同步教职工数据
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return boolean
|
|
|
|
|
+ */
|
|
|
|
|
+ public Boolean syncTeacher() {
|
|
|
|
|
+ HttpRequest req = CreateHttpRequest.createRequest();
|
|
|
|
|
+ req.body(getQueryBodyForTeacher());
|
|
|
|
|
+ try (HttpResponse res = req.execute()) {
|
|
|
|
|
+ SyncFullDataBo dataBo = JSONUtil.toBean(res.body(), SyncFullDataBo.class);
|
|
|
|
|
+ List<ResourcePerson> resourcePersonList = getResourcePeopleList(dataBo);
|
|
|
|
|
+ log.info("[全量获取到的教职工数据]-[共{}条]-[{}]", resourcePersonList.size(), JSONUtil.toJsonStr(dataBo));
|
|
|
|
|
+ syncUserStrategyContent.syncUser(resourcePersonList, SyncResourceConstants.TEACHER);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ // region 模拟测试数据
|
|
|
|
|
+ // List<ResourcePerson> resourcePersonList = new ArrayList<>();
|
|
|
|
|
+ // ResourcePerson person = new ResourcePerson();
|
|
|
|
|
+ // person.setUserId("00314200");
|
|
|
|
|
+ // person.setDeptId("001001001000");
|
|
|
|
|
+ // person.setPostCode(DefaultConstants.TEACHER_CODE);
|
|
|
|
|
+ // person.setRealName("康重文");
|
|
|
|
|
+ // person.setSex("1");
|
|
|
|
|
+ // person.setPhone("13875850616");
|
|
|
|
|
+ // person.setCategory("1");
|
|
|
|
|
+ // person.setRemark("");
|
|
|
|
|
+ // person.setUserState("on");
|
|
|
|
|
+ // resourcePersonList.add(person);
|
|
|
|
|
+ // syncUserStrategyContent.syncUser(resourcePersonList, SyncResourceConstants.TEACHER);
|
|
|
|
|
+ // endregion
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 全量部门数据转换
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param dataBo 全量数据
|
|
|
|
|
+ * @return 部门数据
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ @NotNull
|
|
|
|
|
+ private static List<ResourceDept> getResourceDeptList(SyncFullDataBo dataBo) {
|
|
|
List<ResourceDept> resourceDeptlist = new ArrayList<>();
|
|
List<ResourceDept> resourceDeptlist = new ArrayList<>();
|
|
|
for (List<String> list : dataBo.getResponseParam().getResourceInfos().get(0).getDataInfo()) {
|
|
for (List<String> list : dataBo.getResponseParam().getResourceInfos().get(0).getDataInfo()) {
|
|
|
ResourceDept dept = new ResourceDept();
|
|
ResourceDept dept = new ResourceDept();
|
|
|
dept.setParent_id(list.get(0));
|
|
dept.setParent_id(list.get(0));
|
|
|
dept.setDept_id(list.get(1));
|
|
dept.setDept_id(list.get(1));
|
|
|
dept.setDept_name(list.get(2));
|
|
dept.setDept_name(list.get(2));
|
|
|
|
|
+ dept.setOperatorId(DefaultConstants.FULL_SYNC_ADMIN);
|
|
|
|
|
+ dept.setTenantId(DefaultConstants.TENANT_ID);
|
|
|
resourceDeptlist.add(dept);
|
|
resourceDeptlist.add(dept);
|
|
|
}
|
|
}
|
|
|
- log.info("[全量获取到的部门数据]-共[{}]条-[{}]", resourceDeptlist.size(), JSONUtil.toJsonStr(dataBo));
|
|
|
|
|
- syncDeptStrategyContent.syncDept(resourceDeptlist, SyncResourceConstants.HR_DEPT);
|
|
|
|
|
|
|
+ return resourceDeptlist;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 同步教职工数据
|
|
|
|
|
|
|
+ * 全量人员数据转换
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param dataBo 全量数据
|
|
|
|
|
+ * @return 转换结果
|
|
|
*/
|
|
*/
|
|
|
- public void syncTeacher() {
|
|
|
|
|
- HttpRequest req = CreateHttpRequest.createRequest();
|
|
|
|
|
- req.body(getQueryBodyForTeacher());
|
|
|
|
|
-
|
|
|
|
|
- SyncFullDataBo dataBo = JSONUtil.toBean(req.execute().body(), SyncFullDataBo.class);
|
|
|
|
|
|
|
+ @NotNull
|
|
|
|
|
+ private static List<ResourcePerson> getResourcePeopleList(SyncFullDataBo dataBo) {
|
|
|
List<ResourcePerson> resourcePersonList = new ArrayList<>();
|
|
List<ResourcePerson> resourcePersonList = new ArrayList<>();
|
|
|
for (List<String> list : dataBo.getResponseParam().getResourceInfos().get(0).getDataInfo()) {
|
|
for (List<String> list : dataBo.getResponseParam().getResourceInfos().get(0).getDataInfo()) {
|
|
|
ResourcePerson person = new ResourcePerson();
|
|
ResourcePerson person = new ResourcePerson();
|
|
@@ -74,32 +134,16 @@ public class SyncHrService {
|
|
|
person.setCategory("1");
|
|
person.setCategory("1");
|
|
|
person.setRemark("");
|
|
person.setRemark("");
|
|
|
person.setUserState(list.get(16));
|
|
person.setUserState(list.get(16));
|
|
|
|
|
+ person.setOperatorId(DefaultConstants.FULL_SYNC_ADMIN);
|
|
|
|
|
+ person.setTenantId(DefaultConstants.TENANT_ID);
|
|
|
resourcePersonList.add(person);
|
|
resourcePersonList.add(person);
|
|
|
}
|
|
}
|
|
|
- log.info("[全量获取到的教职工数据]-[共{}条]-[{}]", resourcePersonList.size(), JSONUtil.toJsonStr(dataBo));
|
|
|
|
|
-
|
|
|
|
|
- //region 模拟测试数据
|
|
|
|
|
- //List<ResourcePerson> resourcePersonList = new ArrayList<>();
|
|
|
|
|
- //ResourcePerson person = new ResourcePerson();
|
|
|
|
|
- //person.setUserId("00314200");
|
|
|
|
|
- //person.setDeptId("001001001000");
|
|
|
|
|
- //person.setPostCode(DefaultConstants.TEACHER_CODE);
|
|
|
|
|
- //person.setRealName("康重文");
|
|
|
|
|
- //person.setSex("1");
|
|
|
|
|
- //person.setPhone("13875850616");
|
|
|
|
|
- //person.setCategory("1");
|
|
|
|
|
- //person.setRemark("");
|
|
|
|
|
- //person.setUserState("on");
|
|
|
|
|
- //resourcePersonList.add(person);
|
|
|
|
|
- //endregion
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- syncUserStrategyContent.syncUser(resourcePersonList, SyncResourceConstants.TEACHER);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return resourcePersonList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成部门查询body参数
|
|
* 生成部门查询body参数
|
|
|
|
|
+ *
|
|
|
* @return body数据
|
|
* @return body数据
|
|
|
*/
|
|
*/
|
|
|
private String getQueryBodyForDept() {
|
|
private String getQueryBodyForDept() {
|
|
@@ -141,6 +185,7 @@ public class SyncHrService {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成教职工查询的body参数
|
|
* 生成教职工查询的body参数
|
|
|
|
|
+ *
|
|
|
* @return body 数据
|
|
* @return body 数据
|
|
|
*/
|
|
*/
|
|
|
private String getQueryBodyForTeacher() {
|
|
private String getQueryBodyForTeacher() {
|