|
@@ -2,10 +2,7 @@ package com.usoftchina.uas.office.qywx.service;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.usoftchina.qywx.sdk.AddrBookSdk;
|
|
import com.usoftchina.qywx.sdk.AddrBookSdk;
|
|
|
-import com.usoftchina.qywx.sdk.dto.CreateDepartmentReq;
|
|
|
|
|
-import com.usoftchina.qywx.sdk.dto.GetDepartmentListResp;
|
|
|
|
|
-import com.usoftchina.qywx.sdk.dto.GetSimpleUserListResp;
|
|
|
|
|
-import com.usoftchina.qywx.sdk.dto.UpdateDepartmentReq;
|
|
|
|
|
|
|
+import com.usoftchina.qywx.sdk.dto.*;
|
|
|
import com.usoftchina.uas.office.qywx.entity.HrOrg;
|
|
import com.usoftchina.uas.office.qywx.entity.HrOrg;
|
|
|
import com.usoftchina.uas.office.service.AbstractService;
|
|
import com.usoftchina.uas.office.service.AbstractService;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -90,10 +87,10 @@ public class UasOrgService extends AbstractService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- List<GetDepartmentListResp.Department> departmentList = addrBookSdk.getDepartmentList();
|
|
|
|
|
|
|
+ List<GetDepartmentSimpleListResp.Department> departmentList = addrBookSdk.getSimpleDepartmentList();
|
|
|
if (null == org.getOr_subof() || 0 == org.getOr_subof()) {
|
|
if (null == org.getOr_subof() || 0 == org.getOr_subof()) {
|
|
|
- GetDepartmentListResp.Department rootDept = null;
|
|
|
|
|
- for (GetDepartmentListResp.Department department : departmentList) {
|
|
|
|
|
|
|
+ GetDepartmentSimpleListResp.Department rootDept = null;
|
|
|
|
|
+ for (GetDepartmentSimpleListResp.Department department : departmentList) {
|
|
|
if (department.getParentid() == 0) {
|
|
if (department.getParentid() == 0) {
|
|
|
rootDept = department;
|
|
rootDept = department;
|
|
|
break;
|
|
break;
|
|
@@ -113,14 +110,16 @@ public class UasOrgService extends AbstractService {
|
|
|
try {
|
|
try {
|
|
|
// 只需考虑父级组织已同步的情况
|
|
// 只需考虑父级组织已同步的情况
|
|
|
HrOrg parentOrg = getBindById(org.getOr_subof());
|
|
HrOrg parentOrg = getBindById(org.getOr_subof());
|
|
|
- GetDepartmentListResp.Department dept = null;
|
|
|
|
|
- for (GetDepartmentListResp.Department department : departmentList) {
|
|
|
|
|
- if (department.getParentid().equals(parentOrg.getOr_qywx()) && department.getName().equals(org.getOr_name())) {
|
|
|
|
|
- dept = department;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (null != dept) {
|
|
|
|
|
|
|
+// GetDepartmentListResp.Department dept = null;
|
|
|
|
|
+// for (GetDepartmentListResp.Department department : departmentList) {
|
|
|
|
|
+// if (department.getParentid().equals(parentOrg.getOr_qywx())
|
|
|
|
|
+// && department.getName().equals(org.getOr_name())
|
|
|
|
|
+// ) {
|
|
|
|
|
+// dept = department;
|
|
|
|
|
+// break;
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+ /* if (null != dept) {
|
|
|
if (!addrBookSdk.isReadonly()) {
|
|
if (!addrBookSdk.isReadonly()) {
|
|
|
UpdateDepartmentReq req = new UpdateDepartmentReq()
|
|
UpdateDepartmentReq req = new UpdateDepartmentReq()
|
|
|
.id(dept.getId())
|
|
.id(dept.getId())
|
|
@@ -132,19 +131,22 @@ public class UasOrgService extends AbstractService {
|
|
|
jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=? and or_statuscode='DISABLE'", dept.getId());
|
|
jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=? and or_statuscode='DISABLE'", dept.getId());
|
|
|
}
|
|
}
|
|
|
updateOrgQywxId(org, dept.getId());
|
|
updateOrgQywxId(org, dept.getId());
|
|
|
- } else {
|
|
|
|
|
- if (!addrBookSdk.isReadonly()) {
|
|
|
|
|
- CreateDepartmentReq req = new CreateDepartmentReq()
|
|
|
|
|
- .name(org.getOr_name())
|
|
|
|
|
- .parent(parentOrg.getOr_qywx());
|
|
|
|
|
- logger.debug("create qywx department " + JSON.toJSONString(req.build()));
|
|
|
|
|
- Integer departmentId = addrBookSdk.createDepartment(req);
|
|
|
|
|
- updateOrgQywxId(org, departmentId);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ } else {*/
|
|
|
|
|
+ //如果上级没有对接不触发对接操作
|
|
|
|
|
+ if (!addrBookSdk.isReadonly()
|
|
|
|
|
+ && parentOrg.getOr_qywx() != null && !parentOrg.getOr_qywx().equals(0)) {
|
|
|
|
|
+ CreateDepartmentReq req = new CreateDepartmentReq()
|
|
|
|
|
+ .name(org.getOr_name())
|
|
|
|
|
+ .parent(parentOrg.getOr_qywx());
|
|
|
|
|
+ logger.debug("create qywx department " + JSON.toJSONString(req.build()));
|
|
|
|
|
+ Integer departmentId = addrBookSdk.createDepartment(req);
|
|
|
|
|
+ updateOrgQywxId(org, departmentId);
|
|
|
}
|
|
}
|
|
|
|
|
+// }
|
|
|
} catch (EmptyResultDataAccessException e) {
|
|
} catch (EmptyResultDataAccessException e) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -189,7 +191,8 @@ public class UasOrgService extends AbstractService {
|
|
|
List<GetDepartmentListResp.Department> departmentList = deptMap.get(parentDeptId);
|
|
List<GetDepartmentListResp.Department> departmentList = deptMap.get(parentDeptId);
|
|
|
if (null != orgList) {
|
|
if (null != orgList) {
|
|
|
for (HrOrg HrOrg : orgList) {
|
|
for (HrOrg HrOrg : orgList) {
|
|
|
- GetDepartmentListResp.Department department = findDeptByName(departmentList, HrOrg.getOr_name());
|
|
|
|
|
|
|
+ GetDepartmentListResp.Department department = null;
|
|
|
|
|
+// findDeptByName(departmentList, HrOrg.getOr_name());
|
|
|
if (null == department) {
|
|
if (null == department) {
|
|
|
if (null != HrOrg.getOr_qywx() && HrOrg.getOr_qywx() > 0) {
|
|
if (null != HrOrg.getOr_qywx() && HrOrg.getOr_qywx() > 0) {
|
|
|
department = findDeptById(departmentList, HrOrg.getOr_qywx());
|
|
department = findDeptById(departmentList, HrOrg.getOr_qywx());
|
|
@@ -235,7 +238,7 @@ public class UasOrgService extends AbstractService {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private GetDepartmentListResp.Department findDeptByName(List<GetDepartmentListResp.Department> departmentList, String name) {
|
|
|
|
|
|
|
+ /*private GetDepartmentListResp.Department findDeptByName(List<GetDepartmentListResp.Department> departmentList, String name) {
|
|
|
if (null != departmentList) {
|
|
if (null != departmentList) {
|
|
|
for (GetDepartmentListResp.Department department : departmentList) {
|
|
for (GetDepartmentListResp.Department department : departmentList) {
|
|
|
if (department.getName().equals(name)) {
|
|
if (department.getName().equals(name)) {
|
|
@@ -244,7 +247,7 @@ public class UasOrgService extends AbstractService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 清除下面没有人员的部门
|
|
* 清除下面没有人员的部门
|
|
@@ -293,8 +296,8 @@ public class UasOrgService extends AbstractService {
|
|
|
}
|
|
}
|
|
|
List<Integer> orgList = queryForList("select distinct or_qywx from HrOrg where or_qywx is not null", Integer.class);
|
|
List<Integer> orgList = queryForList("select distinct or_qywx from HrOrg where or_qywx is not null", Integer.class);
|
|
|
if (!CollectionUtils.isEmpty(orgList)) {
|
|
if (!CollectionUtils.isEmpty(orgList)) {
|
|
|
- List<GetDepartmentListResp.Department> departmentList = addrBookSdk.getDepartmentList();
|
|
|
|
|
- Set<Integer> idSet = departmentList.stream().map(GetDepartmentListResp.Department::getId).collect(Collectors.toSet());
|
|
|
|
|
|
|
+ List<GetDepartmentSimpleListResp.Department> departmentList = addrBookSdk.getSimpleDepartmentList();
|
|
|
|
|
+ Set<Integer> idSet = departmentList.stream().map(GetDepartmentSimpleListResp.Department::getId).collect(Collectors.toSet());
|
|
|
for (Integer org : orgList) {
|
|
for (Integer org : orgList) {
|
|
|
if (!idSet.contains(org)) {
|
|
if (!idSet.contains(org)) {
|
|
|
jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=?", org);
|
|
jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=?", org);
|