Browse Source

清除错误数据

yingp 5 years ago
parent
commit
160ea31d80

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

@@ -25,7 +25,7 @@ public abstract class BaseTest {
         // 日程
         agents.add(new Agent("Schedule", null, "nBfWqPZS8GXNnkBovhtjMl8UCKI5XoaXUuZnz_Oxkao"));
         // 打卡
-        agents.add(new Agent("Checkin", 3010011, "UqGEo3694hopQIfsd3fEDVx0b0rscrl5QzNsOUeZ4lU"));
+        agents.add(new Agent("Checkin", 3010011, "UqGEo3694hopQIfsd3fEDSTJ0tmHAehavWzv082fkp0"));
         // 审批
         agents.add(new Agent("Approval", 3010040, "sSwb62-S-bGftHcCVChnxASz8SnqnvobtIU8Q42kT2w"));
 

+ 40 - 0
uas-office-dingtalk/src/main/java/com/usoftchina/uas/office/dingtalk/task/DingAddrBookTask.java

@@ -0,0 +1,40 @@
+package com.usoftchina.uas.office.dingtalk.task;
+
+import com.usoftchina.uas.office.dingtalk.service.UasEmployeeService;
+import com.usoftchina.uas.office.dingtalk.service.UasOrgService;
+import com.usoftchina.uas.office.entity.DataCenter;
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author yingp
+ * @date 2020/5/14
+ */
+@Component
+public class DingAddrBookTask {
+
+    @Autowired
+    private UasEmployeeService uasEmployeeService;
+
+    @Autowired
+    private UasOrgService uasOrgService;
+
+    /**
+     * 清除在uas有绑定,而在钉钉已删除的部门、人员
+     */
+    @Scheduled(cron = "0 0 23 * * ?  ")
+    public void clearInvalid() {
+        DataCenter dataCenter = DataCenter.INSTANCE;
+        if (null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
+            try {
+                DataSourceHolder.set(dataCenter);
+                uasOrgService.clearInvalidBinding();
+                uasEmployeeService.clearInvalidBinding();
+            } finally {
+                DataSourceHolder.clear();
+            }
+        }
+    }
+}

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

@@ -398,6 +398,7 @@ public class UasEmployeeService extends AbstractService {
                 for (String emp : empList) {
                     if (!idSet.contains(emp)) {
                         jdbcTemplate.update("update employee set em_qywx=null where em_qywx=?", emp);
+                        logger.debug("clear invalid employee {}", emp);
                     }
                 }
             }

+ 1 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/service/UasOrgService.java

@@ -298,6 +298,7 @@ public class UasOrgService extends AbstractService {
             for (Integer org : orgList) {
                 if (!idSet.contains(org)) {
                     jdbcTemplate.update("update HrOrg set or_qywx=null where or_qywx=?", org);
+                    logger.debug("clear invalid org {}", org);
                 }
             }
         }

+ 40 - 0
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/task/QywxAddrBookTask.java

@@ -0,0 +1,40 @@
+package com.usoftchina.uas.office.qywx.task;
+
+import com.usoftchina.uas.office.entity.DataCenter;
+import com.usoftchina.uas.office.jdbc.DataSourceHolder;
+import com.usoftchina.uas.office.qywx.service.UasEmployeeService;
+import com.usoftchina.uas.office.qywx.service.UasOrgService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author yingp
+ * @date 2020/5/14
+ */
+@Component
+public class QywxAddrBookTask {
+
+    @Autowired
+    private UasEmployeeService uasEmployeeService;
+
+    @Autowired
+    private UasOrgService uasOrgService;
+
+    /**
+     * 清除在uas有绑定,而在企业微信已删除的部门、人员
+     */
+    @Scheduled(cron = "0 0 23 * * ?  ")
+    public void clearInvalid() {
+        DataCenter dataCenter = DataCenter.INSTANCE;
+        if (null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
+            try {
+                DataSourceHolder.set(dataCenter);
+                uasOrgService.clearInvalidBinding();
+                uasEmployeeService.clearInvalidBinding();
+            } finally {
+                DataSourceHolder.clear();
+            }
+        }
+    }
+}

+ 1 - 1
uas-office-qywx/src/main/java/com/usoftchina/uas/office/qywx/task/QywxPushMsgTask.java

@@ -39,7 +39,7 @@ public class QywxPushMsgTask {
             return;
         }
         DataCenter dataCenter = DataCenter.INSTANCE;
-        if (null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
+        if (null != dataCenter && null != dataCenter.getUsername() && null != dataCenter.getPassword() && null != dataCenter.getUrl()) {
             try {
                 DataSourceHolder.set(dataCenter);
                 try {