pruple_boy месяцев назад: 9
Родитель
Сommit
c0335822bb

+ 11 - 42
mjava-ruisi/src/main/java/com/malk/ruisi/controller/CosController.java

@@ -4,13 +4,9 @@ package com.malk.ruisi.controller;
  * 错误抛出与拦截详见 CatchException
  */
 
-import com.malk.server.aliwork.YDConf;
+import com.malk.ruisi.service.RSService;
+import com.malk.server.common.McException;
 import com.malk.server.common.McR;
-import com.malk.service.aliwork.YDClient;
-import com.malk.service.aliwork.YDService;
-import com.malk.service.dingtalk.DDClient;
-import com.malk.service.dingtalk.DDClient_Contacts;
-import com.malk.utils.UtilMap;
 import com.malk.utils.UtilServlet;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Arrays;
 import java.util.Map;
 
 @Slf4j
@@ -28,42 +23,16 @@ import java.util.Map;
 public class CosController {
 
     @Autowired
-    private YDService ydService;
-
-    @Autowired
-    private YDClient ydClient;
-
-    @Autowired
-    private YDConf ydConf;
-
-    @Autowired
-    private DDClient_Contacts ddClient_contacts;
-
-    @Autowired
-    private DDClient ddClient;
-
-
-    /**
-     * 创建企业账号: loginI/userId 都为 SHR 工号
-     */
-    private void createExclusiveUser(String loginId, String name) {
-
-        final long DEPT_ID = 965111354L;
-        final String PASS_WORD = "tzr@111111";
-
-        Map info = UtilMap.map("userid, email", loginId, "pruple_boy@163.com");
-        ddClient_contacts.createUser_dingTalk(ddClient.getAccessToken(), loginId, PASS_WORD, name, Arrays.asList(DEPT_ID), info);
-    }
+    private RSService rsService;
 
     /**
      * 创建投资人用户
      */
-    @PostMapping("user")
-    McR user(HttpServletRequest request) {
-        Map data = UtilServlet.getParamMap(request);
-        log.info("user, {}", data);
-
-        createExclusiveUser(UtilMap.getString(data, "jobNo"), UtilMap.getString(data, "name"));
+    @PostMapping("user/sync")
+    McR syncUser() {
+        
+        log.info("syncUser");
+        rsService.syncDingTalk_exclusive();
         return McR.success();
     }
 
@@ -71,13 +40,13 @@ public class CosController {
      * 重置密码流程
      */
     @PostMapping("reset")
-    McR dept(HttpServletRequest request) {
+    McR resetPwd(HttpServletRequest request) {
 
         Map data = UtilServlet.getParamMap(request);
         log.info("reset, {}", data);
 
-//        ddClient_contacts.updateUser_dingTalk(ddClient.getAccessToken(), userId, deptIds, UtilMap.map("dept_title_list", titles));
-
+        McException.assertParamException_Null(data, "userId", "password");
+        rsService.resetPwd(data);
         return McR.success();
     }
 

+ 35 - 0
mjava-ruisi/src/main/java/com/malk/ruisi/schedule/RSScheduleTask.java

@@ -0,0 +1,35 @@
+package com.malk.ruisi.schedule;
+
+import com.malk.ruisi.service.RSService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+/**
+ * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
+ */
+@Slf4j
+@Configuration
+@EnableScheduling
+@ConditionalOnProperty(name = {"spel.scheduling"})
+public class RSScheduleTask {
+
+    @Autowired
+    private RSService rsService;
+
+    /**
+     * 每天凌晨5点同步
+     */
+    @Scheduled(cron = "0 0 5 * * ? ")
+    public void syncDingTalkFailedList() {
+        try {
+            rsService.syncDingTalk_exclusive();
+        } catch (Exception e) {
+            // 记录错误信息
+            e.printStackTrace();
+        }
+    }
+}

+ 16 - 0
mjava-ruisi/src/main/java/com/malk/ruisi/service/RSService.java

@@ -0,0 +1,16 @@
+package com.malk.ruisi.service;
+
+import java.util.Map;
+
+public interface RSService {
+
+    /**
+     * 同步钉钉企业账号
+     */
+    void syncDingTalk_exclusive();
+
+    /**
+     * 重置企业账号密码
+     */
+    void resetPwd(Map data);
+}

+ 85 - 0
mjava-ruisi/src/main/java/com/malk/ruisi/service/impl/RSImplService.java

@@ -0,0 +1,85 @@
+package com.malk.ruisi.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.malk.ruisi.service.RSService;
+import com.malk.server.aliwork.YDConf;
+import com.malk.server.aliwork.YDParam;
+import com.malk.server.common.McException;
+import com.malk.service.aliwork.YDClient;
+import com.malk.service.aliwork.YDService;
+import com.malk.service.dingtalk.DDClient;
+import com.malk.service.dingtalk.DDClient_Contacts;
+import com.malk.utils.UtilMap;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class RSImplService implements RSService {
+
+    @Autowired
+    private YDService ydService;
+
+    @Autowired
+    private YDClient ydClient;
+
+    @Autowired
+    private DDClient_Contacts ddClient_contacts;
+
+    @Autowired
+    private DDClient ddClient;
+
+    @Autowired
+    private static final long DEPT_ID = 933074211L; // 合作加盟校区
+
+
+    /// 创建企业账号: loginI/userId 都为 SHR 工号
+    private void createExclusiveUser(String loginId, String name) {
+
+        final String PASS_WORD = "tzr@111111";
+
+        Map info = UtilMap.map("userid", loginId);
+        ddClient_contacts.createUser_dingTalk(ddClient.getAccessToken(), loginId, PASS_WORD, name, Arrays.asList(DEPT_ID), info);
+    }
+
+    /**
+     * 同步钉钉企业账号
+     */
+    @Override
+    public void syncDingTalk_exclusive() {
+
+        List<Map> dataList = ydService.queryFormData_all(YDParam.builder()
+                .formUuid("FORM-11B80FC621CA4DB9A35364CFBFF7287538KR")
+                .build());
+        dataList.forEach(data -> {
+            if (!"是".equals(UtilMap.getString(data, "radioField_m0hlup9w"))) {
+                String userId = UtilMap.getString(data, "textField_lztc6k3k");
+                String message = "";
+                try {
+                    this.createExclusiveUser(userId, UtilMap.getString(data, "textField_lxsm8xow"));
+                } catch (McException e) {
+                    message = e.getMessage();
+                    log.error(e.getMessage(), e);
+                }
+                ydClient.operateData(YDParam.builder()
+                        .formInstanceId(UtilMap.getString(data, "instanceId"))
+                        .useLatestVersion(true)
+                        .updateFormDataJson(JSON.toJSONString(UtilMap.map("radioField_m0hlup9w, employeeField_m0hlup9v, textareaField_m0hs4k90", "是", Arrays.asList(userId), message)))
+                        .build(), YDConf.FORM_OPERATION.update);
+            }
+        });
+    }
+    
+    /**
+     * 重置企业账号密码
+     */
+    @Override
+    public void resetPwd(Map data) {
+        ddClient_contacts.updateUser_dingTalk(ddClient.getAccessToken(), UtilMap.getString(data, "userId"), Arrays.asList(DEPT_ID), UtilMap.map("init_password", UtilMap.getString(data, "password")));
+    }
+}

+ 6 - 6
mjava-ruisi/src/main/resources/application-dev.yml

@@ -49,16 +49,16 @@ logging:
 
 # dingtalk
 dingtalk:
-  agentId: "3079562924"
-  appKey: "dingprswtas7kluqst2c"
-  appSecret: "ukquGx_DjznsTQtKQtFFNutn1NFhSgL9ZbTfCtl_9mJYWacFYu--vj_zThTxjsYN"
-  corpId: "dingccd7fff754e440cf24f2f5cc6abecb85"
+  agentId: 3079562924
+  appKey: dingprswtas7kluqst2c
+  appSecret: ukquGx_DjznsTQtKQtFFNutn1NFhSgL9ZbTfCtl_9mJYWacFYu--vj_zThTxjsYN
+  corpId: dingccd7fff754e440cf24f2f5cc6abecb85
   aesKey:
   token:
   operator:           # OA管理员账号 [首字符若为0需要转一下字符串]
 
 # aliwork
 aliwork:
-  appType: "APP_VCTRP6227CC8368NDOID"
-  systemToken: "5H9662C1X8XJLFFCE841M5VBEBQ73DM5IBPULPI3"
+  appType: APP_VCTRP6227CC8368NDOID
+  systemToken: 5H9662C1X8XJLFFCE841M5VBEBQ73DM5IBPULPI3
 

+ 6 - 6
mjava-ruisi/src/main/resources/application-prod.yml

@@ -24,15 +24,15 @@ spring:
 
 # dingtalk
 dingtalk:
-  agentId: "3079562924"
-  appKey: "dingprswtas7kluqst2c"
-  appSecret: "ukquGx_DjznsTQtKQtFFNutn1NFhSgL9ZbTfCtl_9mJYWacFYu--vj_zThTxjsYN"
-  corpId: "dingccd7fff754e440cf24f2f5cc6abecb85"
+  agentId: 3079562924
+  appKey: dingprswtas7kluqst2c
+  appSecret: ukquGx_DjznsTQtKQtFFNutn1NFhSgL9ZbTfCtl_9mJYWacFYu--vj_zThTxjsYN
+  corpId: dingccd7fff754e440cf24f2f5cc6abecb85
   aesKey:
   token:
   operator:           # OA管理员账号 [首字符若为0需要转一下字符串]
 
 # aliwork
 aliwork:
-  appType: "APP_VCTRP6227CC8368NDOID"
-  systemToken: "5H9662C1X8XJLFFCE841M5VBEBQ73DM5IBPULPI3"
+  appType: APP_VCTRP6227CC8368NDOID
+  systemToken: 5H9662C1X8XJLFFCE841M5VBEBQ73DM5IBPULPI3

+ 3 - 0
mjava/src/main/java/com/malk/schedule/McScheduleTask.java

@@ -29,6 +29,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
  * @ConditionalOnProperty,可多个参数,支持与,若获取值为空识别为false,若有值则将该值与havingValue指定的值进行比较,匹配结果为bool。不支持或
  */
 
+
+// todo L 不识别, 启动报错
+
 @Slf4j
 @Configuration
 @EnableScheduling