|
|
@@ -1,5 +1,6 @@
|
|
|
package com.usoftchina.uas.office.qywx.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.usoftchina.qywx.sdk.AddrBookSdk;
|
|
|
import com.usoftchina.qywx.sdk.dto.CreateDepartmentReq;
|
|
|
import com.usoftchina.qywx.sdk.dto.GetDepartmentListResp;
|
|
|
@@ -7,6 +8,8 @@ import com.usoftchina.qywx.sdk.dto.GetSimpleUserListResp;
|
|
|
import com.usoftchina.qywx.sdk.dto.UpdateDepartmentReq;
|
|
|
import com.usoftchina.uas.office.qywx.entity.HrOrg;
|
|
|
import com.usoftchina.uas.office.service.AbstractService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -23,7 +26,20 @@ public class UasOrgService extends AbstractService {
|
|
|
@Autowired
|
|
|
private AddrBookSdk addrBookSdk;
|
|
|
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(UasOrgService.class);
|
|
|
+
|
|
|
public HrOrg getById(Integer id) {
|
|
|
+ return queryForBean("select * from HrOrg where or_statuscode<>'DISABLE' and or_id=?", HrOrg.class,
|
|
|
+ id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组织(已绑定企业微信)
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HrOrg getBindById(Integer id) {
|
|
|
return queryForBean("select * from HrOrg where or_statuscode<>'DISABLE' and or_qywx is not null and or_id=?", HrOrg.class,
|
|
|
id);
|
|
|
}
|
|
|
@@ -53,19 +69,23 @@ public class UasOrgService extends AbstractService {
|
|
|
public void sync(HrOrg org) {
|
|
|
if (null != org.getOr_qywx() && !addrBookSdk.isReadonly()) {
|
|
|
if (null == org.getOr_subof() || 0 == org.getOr_subof()) {
|
|
|
- // 修改部门
|
|
|
- addrBookSdk.updateDepartment(new UpdateDepartmentReq()
|
|
|
+ UpdateDepartmentReq req = new UpdateDepartmentReq()
|
|
|
.id(org.getOr_qywx())
|
|
|
.name(org.getOr_name())
|
|
|
- .parent(0));
|
|
|
+ .parent(0);
|
|
|
+ logger.debug("update qywx department " + JSON.toJSONString(req.build()));
|
|
|
+ // 修改部门
|
|
|
+ addrBookSdk.updateDepartment(req);
|
|
|
} else {
|
|
|
- HrOrg parentOrg = getById(org.getOr_subof());
|
|
|
+ HrOrg parentOrg = getBindById(org.getOr_subof());
|
|
|
if (null != parentOrg) {
|
|
|
- // 修改部门
|
|
|
- addrBookSdk.updateDepartment(new UpdateDepartmentReq()
|
|
|
+ UpdateDepartmentReq req = new UpdateDepartmentReq()
|
|
|
.id(org.getOr_qywx())
|
|
|
.name(org.getOr_name())
|
|
|
- .parent(parentOrg.getOr_qywx()));
|
|
|
+ .parent(parentOrg.getOr_qywx());
|
|
|
+ logger.debug("update qywx department " + JSON.toJSONString(req.build()));
|
|
|
+ // 修改部门
|
|
|
+ addrBookSdk.updateDepartment(req);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
@@ -79,17 +99,19 @@ public class UasOrgService extends AbstractService {
|
|
|
}
|
|
|
}
|
|
|
if (!addrBookSdk.isReadonly()) {
|
|
|
- // 修改部门名称
|
|
|
- addrBookSdk.updateDepartment(new UpdateDepartmentReq()
|
|
|
+ UpdateDepartmentReq req = new UpdateDepartmentReq()
|
|
|
.id(rootDept.getId())
|
|
|
.name(org.getOr_name())
|
|
|
- .parent(0));
|
|
|
+ .parent(0);
|
|
|
+ logger.debug("update qywx department " + JSON.toJSONString(req.build()));
|
|
|
+ // 修改部门名称
|
|
|
+ addrBookSdk.updateDepartment(req);
|
|
|
}
|
|
|
updateOrgQywxId(org, rootDept.getId());
|
|
|
} else {
|
|
|
try {
|
|
|
// 只需考虑父级组织已同步的情况
|
|
|
- HrOrg parentOrg = getById(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())) {
|
|
|
@@ -99,17 +121,23 @@ public class UasOrgService extends AbstractService {
|
|
|
}
|
|
|
if (null != dept) {
|
|
|
if (!addrBookSdk.isReadonly()) {
|
|
|
- // 修改部门名称
|
|
|
- addrBookSdk.updateDepartment(new UpdateDepartmentReq()
|
|
|
+ UpdateDepartmentReq req = new UpdateDepartmentReq()
|
|
|
.id(dept.getId())
|
|
|
- .name(org.getOr_name()));
|
|
|
+ .name(org.getOr_name());
|
|
|
+ logger.debug("update qywx department " + JSON.toJSONString(req.build()));
|
|
|
+ // 修改部门名称
|
|
|
+ addrBookSdk.updateDepartment(req);
|
|
|
+ // 存在旧的已禁用的同名组织
|
|
|
+ jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=? and or_statuscode='DISABLE'", dept.getId());
|
|
|
}
|
|
|
updateOrgQywxId(org, dept.getId());
|
|
|
} else {
|
|
|
if (!addrBookSdk.isReadonly()) {
|
|
|
- Integer departmentId = addrBookSdk.createDepartment(new CreateDepartmentReq()
|
|
|
+ CreateDepartmentReq req = new CreateDepartmentReq()
|
|
|
.name(org.getOr_name())
|
|
|
- .parent(parentOrg.getOr_qywx()));
|
|
|
+ .parent(parentOrg.getOr_qywx());
|
|
|
+ logger.debug("create qywx department " + JSON.toJSONString(req.build()));
|
|
|
+ Integer departmentId = addrBookSdk.createDepartment(req);
|
|
|
updateOrgQywxId(org, departmentId);
|
|
|
}
|
|
|
}
|