Browse Source

清除错误数据

yingp 5 years ago
parent
commit
92052e5138

+ 19 - 1
qywx-sdk/src/test/java/com/usoftchina/qywx/sdk/test/AddrBookSdkTest.java

@@ -6,6 +6,7 @@ import com.usoftchina.qywx.sdk.dto.*;
 import org.junit.Test;
 import org.springframework.util.CollectionUtils;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -57,7 +58,15 @@ public class AddrBookSdkTest extends BaseTest {
 
     @Test
     public void deleteUser() {
-        sdk.deleteUser("qy01d3ffd8cd39d7002a66ffc62c");
+        String[] userIds = new String[]{"T03547","QIULZ","XUGH","T02573","T00012","T02599","T02676","T02659","RD14102","T02608","T02582","U0718","T00227","ZHENGJ","ZHANGMR","qy0155ff9ccd32d7012a4b21ee7d","qy018cff21cd15d7012a945a2cb3","LB","T02629","T02633","WANGDY","SHIYL","T02637","qy0125ff9ccd32d7012a57faa7dc","T02652","WXR","LINDA_WANG","XHD","T02679","T02680","WUJM","CHENJJ","ZHB","T03566","T03552","T03557","T03622","T03553","T03918","T04010","T03677","T03900","T03901","T03740","T03782","T03839","T03821","T03843","T04013","T03953","T03962","T03736","qy0171ffa2cd9dd7002a7d00e8eb","T03649","T03851","T03778","T03788","T03697","T03780","T03936","T04026","T03702","T04014","T03777","qy0108ff8ccde5d7012a6eb40046","T03646","qy012dffbfcdb8d7012a83563b91","T03684","T04028","T03942","T04247","qy015fff03cd83d7072a024ca3a7","qy01d5ffbdcd47d7012a7c766201","T04289","qy015bff7acd44d7002abc7e608d","qy014fffa1cd00d7072ae26316bb","T04223","qy014bff65cd9fd7012aa2706550","qy0100ff42cdf3d7062ae603c7a2","qy0193ff38cd5fd7012aba55c61a","T04117","qy01baff0fcda8d7012aa79faff3","T04267","qy01afff8acdbad7062a141068db","qy01ffffa9cdead7062a577ae9fb","T04224","T04263","qy0164ffffcd65d7042ae805caba"};
+        for (String userId : userIds) {
+            try {
+                sdk.deleteUser(userId);
+                System.out.println("delete " + userId);
+            } catch (Exception e) {
+
+            }
+        }
     }
 
     @Test
@@ -88,4 +97,13 @@ public class AddrBookSdkTest extends BaseTest {
         sdk.updateDepartment(new UpdateDepartmentReq().id(1).name("优软科技事业部"));
     }
 
+    @Test
+    public void createDepartment() {
+        CreateDepartmentReq req = new CreateDepartmentReq()
+                .name("华商龙香港仓管科")
+                .parent(1543022789);
+        Integer departmentId = sdk.createDepartment(req);
+        System.out.println(departmentId);
+    }
+
 }

+ 19 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/service/UasEmployeeService.java

@@ -353,4 +353,23 @@ public class UasEmployeeService extends AbstractService {
             }
         }
     }
+
+    /**
+     * 清除在uas有绑定em_ding,而在钉钉已删除的人员
+     */
+    public void clearInvalidBinding() {
+        List<String> empList = queryForList("select distinct em_ding from employee where em_ding is not null", String.class);
+        if (!CollectionUtils.isEmpty(empList)) {
+            HrOrg root = getRootOrg();
+            if (null != root && null != root.getOr_ding()) {
+                List<OapiUserListbypageResponse.Userlist> userList = addrBookSdk.getUserList("Uas", root.getOr_ding(), true);
+                Set<String> idSet = userList.stream().map(OapiUserListbypageResponse.Userlist::getUserid).collect(Collectors.toSet());
+                for (String emp : empList) {
+                    if (!idSet.contains(emp)) {
+                        jdbcTemplate.update("update employee set em_ding=null where em_ding=?", emp);
+                    }
+                }
+            }
+        }
+    }
 }

+ 17 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/service/UasOrgService.java

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author yingp
@@ -260,4 +261,20 @@ public class UasOrgService extends AbstractService {
             }
         }
     }
+
+    /**
+     * 清除在uas有绑定or_ding,而在钉钉已删除的部门
+     */
+    public void clearInvalidBinding() {
+        List<Long> orgList = queryForList("select distinct or_ding from HrOrg where or_ding is not null and or_ding<>1", Long.class);
+        if (!CollectionUtils.isEmpty(orgList)) {
+            List<OapiDepartmentListResponse.Department> departmentList = addrBookSdk.getDepartmentList("Uas", 1);
+            Set<Long> idSet = departmentList.stream().map(OapiDepartmentListResponse.Department::getId).collect(Collectors.toSet());
+            for (Long org : orgList) {
+                if (!idSet.contains(org)) {
+                    jdbcTemplate.update("update HrOrg set or_ding=null where or_ding=?", org);
+                }
+            }
+        }
+    }
 }

+ 23 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/service/UasEmployeeService.java

@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author yingp
@@ -380,4 +381,26 @@ public class UasEmployeeService extends AbstractService {
         QywxUserFactory qywxUserFactory = new QywxUserFactory(getRootOrg().getOr_qywx());
         sync(employee, qywxUserFactory);
     }
+
+    /**
+     * 清除在uas有绑定em_qywx,而在企业微信已删除的人员
+     */
+    public void clearInvalidBinding() {
+        if (addrBookSdk.isReadonly()) {
+            return;
+        }
+        List<String> empList = queryForList("select distinct em_qywx from employee where em_qywx is not null", String.class);
+        if (!CollectionUtils.isEmpty(empList)) {
+            HrOrg root = getRootOrg();
+            if (null != root && null != root.getOr_qywx()) {
+                List<GetUserListResp.User> userList = addrBookSdk.getUserList(root.getOr_qywx(), true);
+                Set<String> idSet = userList.stream().map(GetUserListResp.User::getUserid).collect(Collectors.toSet());
+                for (String emp : empList) {
+                    if (!idSet.contains(emp)) {
+                        jdbcTemplate.update("update employee set em_qywx=null where em_qywx=?", emp);
+                    }
+                }
+            }
+        }
+    }
 }

+ 23 - 3
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/service/UasOrgService.java

@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author yingp
@@ -56,10 +57,10 @@ public class UasOrgService extends AbstractService {
      * 同步全部 uas组织资料 -> 企业微信部门资料
      */
     public void sync() {
-        List<HrOrg> HrOrgList = queryForBeanList("select * from HrOrg where or_statuscode<>'DISABLE'", HrOrg.class);
-        if (!CollectionUtils.isEmpty(HrOrgList)) {
+        List<HrOrg> orgList = queryForBeanList("select * from HrOrg where or_statuscode<>'DISABLE'", HrOrg.class);
+        if (!CollectionUtils.isEmpty(orgList)) {
             List<GetDepartmentListResp.Department> departmentList = addrBookSdk.getDepartmentList();
-            checkOrg(groupOrgList(HrOrgList), 0, groupDepartmentList(departmentList), 0);
+            checkOrg(groupOrgList(orgList), 0, groupDepartmentList(departmentList), 0);
         }
     }
 
@@ -282,4 +283,23 @@ public class UasOrgService extends AbstractService {
             }
         }
     }
+
+    /**
+     * 清除在uas有绑定or_qywx,而在企业微信已删除的部门
+     */
+    public void clearInvalidBinding() {
+        if (addrBookSdk.isReadonly()) {
+            return;
+        }
+        List<Integer> orgList = queryForList("select distinct or_qywx from HrOrg where or_qywx is not null", Integer.class);
+        if (!CollectionUtils.isEmpty(orgList)) {
+            List<GetDepartmentListResp.Department> departmentList = addrBookSdk.getDepartmentList();
+            Set<Integer> idSet = departmentList.stream().map(GetDepartmentListResp.Department::getId).collect(Collectors.toSet());
+            for (Integer org : orgList) {
+                if (!idSet.contains(org)) {
+                    jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=?", org);
+                }
+            }
+        }
+    }
 }