ソースを参照

NC定时任务测试及结构调整

fyz 2 週間 前
コミット
95fbae8843

+ 10 - 2
mjava-lanyun/src/main/java/com/malk/lanyun/schedule/NCTask.java

@@ -48,12 +48,20 @@ public class NCTask {
     void departmentCost() {
         log.info("开始跑批更新NC-部门费用达成明细");
         ncService.getNcCollection();
+    }
+
+    /**
+     * 每月1日凌晨5点30跑批NC-部门费用达成明细
+     */
+    @Scheduled(cron = "0 0 6 18 * ?")
+    void getNcCollectionOld() {
+        log.info("开始跑批更新NC-部门费用达成明细");
         ncService.getNcCollectionOld();
     }
     /**
      * 每月1日凌晨6点跑批NC供应商付款
      */
-    @Scheduled(cron = "0 0 6 * * ?")
+    @Scheduled(cron = "0 30 6 * * ?")
     void supplierPay() {
         log.info("开始跑批更新NC供应商付款");
         ncService.getSupplierPay();
@@ -61,7 +69,7 @@ public class NCTask {
     /**
      * 每日凌晨6点30跑批NC供应商付款
      */
-    @Scheduled(cron = "0 30 6 * * ?")
+    @Scheduled(cron = "0 0 7 * * ?")
     void NcTax() {
         log.info("开始跑批更新NC供应商付款");
         ncService.getNcTax();

+ 11 - 3
mjava-lanyun/src/main/java/com/malk/lanyun/service/impl/NCServiceImpl.java

@@ -378,6 +378,7 @@ public class NCServiceImpl implements NCService {
         String month = String.format("%02d",lastMonth.getMonthValue()) ;
         deleteMonthDate("FORM-0A7979E168AF494F9AA190F043DCBBC7CW9Z","textField_m0dkzhwo", String.valueOf(year),month);
 
+        log.info("执行NC部门-管理费用"+year+"-"+month);
         System.out.println(month);
         Connection connection = null;
         Statement statement = null;
@@ -634,8 +635,15 @@ public class NCServiceImpl implements NCService {
     public void getSupplierPay() {
         // 获取当前年
         int year = lastMonth.getYear();
-        String month = String.format("%02d",lastMonth.getMonthValue()) ;
-        deleteMonthDate("FORM-09CDC75CDC6048379567EC87ED6CE7B6T8PP","textField_m0g4itw4", String.valueOf(year),null);
+        for (int i = 1; i <= lastMonth.getMonthValue(); i++) {
+            String month = String.format("%02d",i) ;
+            deleteMonthDate("FORM-09CDC75CDC6048379567EC87ED6CE7B6T8PP","textField_m0g4itw4", String.valueOf(year),month);
+            try {
+                Thread.sleep(5000);
+            } catch (InterruptedException e) {
+                throw new RuntimeException(e);
+            }
+        }
 
         LocalDate firstDayOfYear = LocalDate.of(year, 1, 1);
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@@ -1488,7 +1496,7 @@ public class NCServiceImpl implements NCService {
                 .appType("APP_ERBDTFS82HOVBPL3NFH0")
                 .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
                 .formUuid(formUuid)
-                .searchFieldJson(JSON.toJSONString(UtilMap.map(key, yearAndMonth)))
+                .searchFieldJson(JSON.toJSONString(UtilMap.map(key + ", selectField_mjl4i6dx", yearAndMonth + ", 否")))
                 .build());
         allProjectList.forEach(e->{
             ydClient.operateData(YDParam.builder()

+ 1 - 1
mjava/src/main/java/com/malk/service/aliwork/impl/YDClientImpl.java

@@ -150,7 +150,7 @@ public class YDClientImpl implements YDClient {
                 ddr_new = DDR_New.doPost(getRequestUrl("/forms/operationsLogs/query"), ddClient.initTokenHeader(), null, param);
                 break;
             case retrieve_approval_record:
-                ddr_new = DDR_New.doGet(this.getRequestUrl("/processes/operationRecords"), this.ddClient.initTokenHeader(), param);
+                ddr_new = DDR_New.doGet(getRequestUrl("/processes/operationRecords"), this.ddClient.initTokenHeader(), param);
                 break;
         }
         return ddr_new;

+ 10 - 0
mjava/src/main/java/com/malk/service/dingtalk/DDClient_Attendance.java

@@ -95,4 +95,14 @@ public interface DDClient_Attendance {
      * 搜索考勤组摘要
      */
     List<Map> getAttendanceGroupSearch(String access_token, String op_user_id, String group_name);
+
+
+    /**
+     * 获取用户考勤数据
+     * @param access_token
+     * @param userid
+     * @param work_date
+     * @return
+     */
+    Map getUpdateData(String access_token, String userid, String work_date);
 }

+ 12 - 0
mjava/src/main/java/com/malk/service/dingtalk/impl/DDImplClient_Attendance.java

@@ -191,4 +191,16 @@ public class DDImplClient_Attendance implements DDClient_Attendance {
         Map boyds = UtilMap.map("op_user_id, group_name", op_user_id, group_name);
         return (List<Map>) DDR.doPost("https://oapi.dingtalk.com/topapi/attendance/group/search", null, DDConf.initTokenParams(access_token), boyds).getResult();
     }
+
+    /**
+     * 获取用户考勤数据
+     *
+     * @apiNote https://open.dingtalk.com/document/development/obtain-the-attendance-update-data
+     */
+    @Override
+    public Map getUpdateData(String access_token, String userid, String work_date) {
+        Map boyds = UtilMap.map("userid, work_date", userid, work_date);
+        return (Map) DDR.doPost("https://oapi.dingtalk.com/topapi/attendance/getupdatedata", null, DDConf.initTokenParams(access_token), boyds).getResult();
+
+    }
 }

+ 143 - 0
mjava/src/main/java/com/malk/utils/UtilHoliday.java

@@ -0,0 +1,143 @@
+package com.malk.utils;
+
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
+
+import java.time.LocalDate;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+@Slf4j
+public abstract class UtilHoliday {
+
+    public static void loadHolidayData(int year, Map<Integer, Set<LocalDate>> holidayCache) {
+        if (holidayCache.containsKey(year)) {
+            return;
+        }
+
+        try {
+            log.info("开始从 API 加载 {} 年的节假日数据...", year);
+            String url = "https://timor.tech/api/holiday/year/" + year;
+            String response = HttpUtil.get(url);
+
+            JSONObject jsonObject = JSONObject.parseObject(response);
+            if (jsonObject.getInteger("code") == 0) {
+                JSONObject holidayObj = jsonObject.getJSONObject("holiday");
+                Set<LocalDate> holidayDates = new HashSet<>();
+
+                // 解析 API 返回的数据
+                for (String key : holidayObj.keySet()) {
+                    JSONObject item = holidayObj.getJSONObject(key);
+                    String dateStr = item.getString("date"); // 格式通常为 "MM-dd"
+                    LocalDate localDate = LocalDate.of(year,
+                            Integer.parseInt(dateStr.split("-")[1]),
+                            Integer.parseInt(dateStr.split("-")[2]));
+                    Boolean isHoliday = item.getBoolean("holiday");
+                    if (isHoliday){
+                        holidayDates.add(localDate);
+                    }
+                }
+
+                holidayCache.put(year, holidayDates);
+                System.out.println(holidayCache);
+                log.info("成功加载 {} 年节假日数据,共计 {} 天", year, holidayDates.size());
+            } else {
+                log.error("节假日 API 返回异常: {}", response);
+                System.out.println("c错误1");
+            }
+        } catch (Exception e) {
+            System.out.println("c错误2");
+            log.error("加载节假日数据失败: {}", e.getMessage(), e);
+        }
+    }
+
+    public static void loadWorkdayData(int year, Map<Integer, Set<LocalDate>> workdayCache) {
+        if (workdayCache.containsKey(year)) {
+            return;
+        }
+
+        try {
+            log.info("开始从 API 加载 {} 年的节假日数据...", year);
+            String url = "https://timor.tech/api/holiday/year/" + year;
+            String response = HttpUtil.get(url);
+
+            JSONObject jsonObject = JSONObject.parseObject(response);
+            if (jsonObject.getInteger("code") == 0) {
+                JSONObject holidayObj = jsonObject.getJSONObject("holiday");
+                Set<LocalDate> workdayDates = new HashSet<>();
+
+                // 解析 API 返回的数据
+                for (String key : holidayObj.keySet()) {
+                    JSONObject item = holidayObj.getJSONObject(key);
+                    String dateStr = item.getString("date"); // 格式通常为 "MM-dd"
+                    LocalDate localDate = LocalDate.of(year,
+                            Integer.parseInt(dateStr.split("-")[1]),
+                            Integer.parseInt(dateStr.split("-")[2]));
+                    Boolean isHoliday = item.getBoolean("holiday");
+                    if (!isHoliday){
+                        workdayDates.add(localDate);
+                    }
+                }
+
+                workdayCache.put(year, workdayDates);
+                System.out.println(workdayDates);
+                log.info("成功加载 {} 年调休日数据,共计 {} 天", year, workdayCache.size());
+            } else {
+                log.error("节假日 API 返回异常: {}", response);
+                System.out.println("c错误1");
+            }
+        } catch (Exception e) {
+            System.out.println("c错误2");
+            log.error("加载节假日数据失败: {}", e.getMessage(), e);
+        }
+    }
+
+    /**
+     * 判断指定日期是否为节假日
+     */
+    public static boolean isHoliday(LocalDate date, Map<Integer, Set<LocalDate>> holidayCache) {
+        Set<LocalDate> dates = holidayCache.get(date.getYear());
+        if (dates == null) {
+            loadHolidayData(date.getYear(),holidayCache);
+            dates = holidayCache.getOrDefault(date.getYear(), Collections.emptySet());
+        }
+        return dates.contains(date);
+    }
+
+    /**
+     * 判断指定日期是否为工作日
+     * 逻辑:如果是调休补班日 -> 是工作日;如果是法定节假日 -> 不是工作日;否则按周一到周五判断
+     */
+    public static boolean isWorkday(LocalDate date, Map<Integer, Set<LocalDate>> holidayCache, Map<Integer, Set<LocalDate>> workdayCache) {
+        int year = date.getYear();
+        Set<LocalDate> workdays = workdayCache.getOrDefault(year, Collections.emptySet());
+        Set<LocalDate> holidays = holidayCache.getOrDefault(year, Collections.emptySet());
+
+        // 缓存未命中时触发加载
+        if (workdayCache.get(year) == null ) {
+            loadWorkdayData(year, workdayCache);
+            workdays = workdayCache.getOrDefault(year, Collections.emptySet());
+        }
+        // 缓存未命中时触发加载
+        if (holidayCache.get(year) == null) {
+            loadHolidayData(year, holidayCache);
+            holidays = holidayCache.getOrDefault(year, Collections.emptySet());
+        }
+        // 优先判断调休补班日(周末变工作日)
+        if (workdays.contains(date)) {
+            return true;
+        }
+        // 其次判断法定节假日
+        if (holidays.contains(date)) {
+            return false;
+        }
+        // 最后按常规周末判断(1=周一 ... 7=周日)
+        int dayOfWeek = date.getDayOfWeek().getValue();
+        return dayOfWeek >= 1 && dayOfWeek <= 5;
+    }
+
+}