“lqy 4 months ago
parent
commit
e75f3fcbde

+ 41 - 4
mjava-huagao/src/main/java/com/malk/huagao/controller/HuaGaoController.java

@@ -1,14 +1,19 @@
 package com.malk.huagao.controller;
 
 import com.malk.huagao.service.HuaGaoService;
+import com.malk.server.common.McException;
 import com.malk.server.common.McR;
+import com.malk.utils.UtilServlet;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+@Slf4j
 @RestController
-@RequestMapping("")
+@RequestMapping("/hg")
 public class HuaGaoController {
     @Autowired
     private HuaGaoService huaGaoService;
@@ -17,4 +22,36 @@ public class HuaGaoController {
     public McR test() {
         return McR.success();
     }
+
+    /**
+     * 创建投资人用户
+     */
+    @PostMapping("/user/sync")
+    McR syncUser() {
+
+        log.info("syncUser");
+        huaGaoService.syncDingTalk_exclusive();
+        return McR.success();
+    }
+
+    /**
+     * 重置密码流程
+     */
+    @PostMapping("/reset")
+    McR resetPwd(HttpServletRequest request) {
+
+        Map data = UtilServlet.getParamMap(request);
+        log.info("reset, {}", data);
+        McException.assertParamException_Null(data, "userId", "password");
+        huaGaoService.resetPwd(data);
+        return McR.success();
+    }
+    /**
+     * 获取工作时长详情
+     */
+    @PostMapping("details")
+    McR details(@RequestBody Map<String,Object> data) {
+        huaGaoService.getCheckWorkDateDetails(data);
+        return McR.success();
+    }
 }

+ 13 - 0
mjava-huagao/src/main/java/com/malk/huagao/service/HuaGaoService.java

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

+ 217 - 0
mjava-huagao/src/main/java/com/malk/huagao/service/impl/HuaGaoServiceImpl.java

@@ -1,8 +1,225 @@
 package com.malk.huagao.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.malk.huagao.service.HuaGaoService;
+import com.malk.server.aliwork.YDConf;
+import com.malk.server.aliwork.YDParam;
+import com.malk.server.common.McException;
+import com.malk.server.dingtalk.DDR;
+import com.malk.service.aliwork.YDClient;
+import com.malk.service.aliwork.YDService;
+import com.malk.service.dingtalk.DDClient;
+import com.malk.service.dingtalk.DDClient_Attendance;
+import com.malk.service.dingtalk.DDClient_Contacts;
+import com.malk.service.fxiaoke.FXKClient;
+import com.malk.utils.UtilMap;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Slf4j
 @Service
 public class HuaGaoServiceImpl implements HuaGaoService {
+
+    @Autowired
+    private YDService ydService;
+
+    @Autowired
+    private YDClient ydClient;
+
+    @Value("${dingtalk.appKey}")
+    private String appKey;
+
+    @Value("${dingtalk.appSecret}")
+    private String appSecret;
+
+    @Autowired
+    private DDClient_Contacts ddClient_contacts;
+
+    @Autowired
+    private DDClient_Attendance ddClientAttendance;
+
+    @Autowired
+    private DDClient ddClient;
+    @Autowired
+    private FXKClient fxkClient;
+
+    @Autowired
+    private static final long DEPT_ID = 971482089L; // 合作加盟校区
+
+    /// 创建企业账号: loginI/userId 都为 SHR 工号
+private Map crcreateUser_dingTalk(String name, String randomAccount, String randomPassword) {
+
+    Map param = new HashMap();
+    param.put("access_token", ddClient.getAccessToken());
+    Map body = new HashMap();
+    body.put("exclusive_account", "true");
+    body.put("exclusive_account_type", "dingtalk");
+    body.put("login_id", randomAccount);
+    body.put("init_password", randomPassword);
+    body.put("name", name);
+    body.put("userid", randomAccount);
+    body.put("dept_id_list", DEPT_ID);
+    Object result = DDR.doPost("https://oapi.dingtalk.com/topapi/v2/user/create", (Map) null, param, body).getResult();
+    return (Map) result;
+}
+
+    /**
+     * 同步钉钉企业账号
+     */
+    @Override
+    public void syncDingTalk_exclusive() {
+
+        List<Map> dataList = ydService.queryFormData_all(YDParam.builder()
+                .formUuid("FORM-0086C4597047459BBB37C79E404745C9CK0C")
+                .build());
+        log.info("钉钉企业账号同步开始,共{}条数据", dataList.size());
+        dataList.forEach(data -> {
+            if ("".equals(UtilMap.getString(data, "textField_m1mw64v4"))) {
+                String message = "";
+                String randomAccount = generateRandomAccount();
+                String randomPassword = generateRandomSixDigitPassword();
+                try {
+                    Map textField_m21lkesk = this.crcreateUser_dingTalk(UtilMap.getString(data, "textField_m21lkesk"), randomAccount, randomPassword);
+                    System.out.println("");
+                } 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("textField_m1mw64v4, textField_m1mw64v5", randomAccount, randomPassword)))
+                        .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")));
+    }
+    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    @Override
+    public void getCheckWorkDateDetails(Map data) {
+        List<String> users = new ArrayList<>();
+        users.add("284156461536271475");
+        String[] strings = users.toArray(new String[0]);
+        log.info("users:{}", JSON.toJSONString(strings));
+        List<Map> mapList = ddClientAttendance.getAttColumnVal(ddClient.getAccessToken(appKey, appSecret),"284156461536271475", Arrays.asList("82772106,89349019"),"2025-01-20 08:00:00", "2025-01-21 08:00:00");
+        System.out.println("====="+mapList);
+//        mapList.get(0)
+       String FORMtime = "2025-01-01 00:00:00";
+        String TOtime = "2025-01-31 00:00:00";
+
+//        dateFormat.format(FORMtime);
+//        dateFormat.format(TOtime);
+        //工作时长(实际工时)
+        // Step 1. 提取原始数据到日期-字段ID-值的映射
+        Map<String, Map<Long, Double>> dateData = new HashMap<>();
+
+        for (Map<String, Object> element : mapList) {
+            // 获取字段ID
+            Map<String, Object> columnVo = (Map<String, Object>) element.get("column_vo");
+            Long id = ((Number) columnVo.get("id")).longValue();
+
+            // 遍历该字段的所有日期数据
+            List<Map<String, String>> columnVals = (List<Map<String, String>>) element.get("column_vals");
+            for (Map<String, String> entry : columnVals) {
+                String fullDate = entry.get("date");
+//                System.out.println("fullDate:====="+fullDate);
+                String date = fullDate.split(" ")[0]; // 提取日期部分
+                Double value = Double.parseDouble(entry.get("value"));
+
+                // 存储到日期映射中
+                dateData.computeIfAbsent(date, k -> new HashMap<>())
+                        .put(id, value);
+            }
+        }
+
+        // Step 2. 按日期处理业务逻辑
+        Map<String, Double> finalResult = new LinkedHashMap<>(); // 保持日期顺序
+
+        for (Map.Entry<String, Map<Long, Double>> entry : dateData.entrySet()) {
+            String date = entry.getKey();
+            Map<Long, Double> idValues = entry.getValue();
+
+            // 获取目标字段的值
+            Double targetValue = idValues.get(89349019L); // ID=89349019
+            Double refValue = idValues.get(82772106L);    // ID=82772106
+
+            // 逻辑判断
+            if (targetValue == null || refValue == null) {
+                System.err.println("日期 " + date + " 缺少必要字段数据,跳过计算");
+                continue;
+            }
+
+            double result;
+            if (targetValue >= 8) {
+                result = targetValue; // 直接返回
+            } else {
+                result = targetValue + (refValue / 60); // 组合计算
+            }
+
+            finalResult.put(date, result);
+        }
+
+        // Step 3. 打印最终结果
+        System.out.println("===== 计算结果 =====");
+        finalResult.forEach((date, value) -> {
+            System.out.printf("日期: %s \t 结果值: %.1f%n", date, value);
+        });
+
+
+    }
+
+    /**
+     * 生成一个由大写字母和数字组成的八位随机账号。
+     *
+     * @return 生成的随机账号字符串
+     */
+    public static String generateRandomAccount() {
+        // 可选字符集合:大写字母A-Z和数字0-9
+        final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+        final int LENGTH = 8; // 账号长度
+
+        Random random = new Random();
+        StringBuilder sb = new StringBuilder(LENGTH);
+
+        for (int i = 0; i < LENGTH; i++) {
+            // 随机选择一个字符
+            int index = random.nextInt(CHARS.length());
+            char randomChar = CHARS.charAt(index);
+            sb.append(randomChar);
+        }
+
+        return sb.toString();
+    }
+
+    /**
+     * 生成一个六位数的随机密码。
+     *
+     * @return 生成的随机密码字符串
+     */
+    public static String generateRandomSixDigitPassword() {
+        Random random = new Random();
+        int min = 100000; // 六位数最小值
+        int max = 999999; // 六位数最大值
+
+        // 生成一个介于[min, max]之间的随机数
+        int randomNumber = random.nextInt(max - min + 1) + min;
+
+        // 将生成的随机数转换为字符串
+        return String.valueOf(randomNumber);
+    }
 }

+ 2 - 2
mjava-huagao/src/main/resources/application-dev.yml

@@ -22,7 +22,7 @@ dingtalk:
 
 # aliwork
 aliwork:
-  appType:
-  systemToken:
+  appType: APP_FWH90IADKEXJ1O540RCM
+  systemToken: IDD66DC1H2ITY3HU789SK9IFJXKD2RL8BF28MBF1