Procházet zdrojové kódy

定时任务更新项目点档案子表月度定额产值预估数据

fyz před 2 měsíci
rodič
revize
308fadebdb

+ 5 - 4
mjava-lanyun/src/main/java/com/malk/lanyun/schedule/ScheduleTask.java

@@ -41,12 +41,13 @@ public class ScheduleTask {
     }
 
     /**
-     * 每月16日凌晨1点自动执行更新项目点档案子表产值预估
+     * 每月16日凌晨6点30自动执行更新项目点档案子表产值预估
      */
-    @Scheduled(cron = "0 0 0 16 * ?")
+    @Scheduled(cron = "0 30 6 16 * ?")
     public void updateOutputPredict() {
-        timerService.updateOutputPredict();
         log.info("定时方法执行时间 :" + new Date());
+        timerService.updateOutputPredict();
+        timerService.updateYearPredict();
     }
 
     /**
@@ -102,7 +103,7 @@ public class ScheduleTask {
     /**
      * 每月最后一天跑批离职人员
      */
-    @Scheduled(cron = "0 30 23 28-31 * ?")
+    @Scheduled(cron = "0 30 22 28-31 * ?")
     void SynDingLeaveOffice(){
         // 获取当前日期
         LocalDate today = LocalDate.now();

+ 2 - 0
mjava-lanyun/src/main/java/com/malk/lanyun/service/TimerService.java

@@ -123,4 +123,6 @@ public interface TimerService {
      * @param processInstanceId
      */
     void terminateDataById(String processInstanceId);
+
+    void updateYearPredict();
 }

+ 4 - 3
mjava-lanyun/src/main/java/com/malk/lanyun/service/impl/FImplService.java

@@ -128,7 +128,7 @@ public class FImplService implements FService {
 //                            .searchCondition(JSON.toJSONString(searchCondition))
                             .formUuid("FORM-EC785A5AB2B9432C892062823EB7C62A9NTL")
 //                            .formDataJson(JSON.toJSONString(dataForm))
-                            .formInstanceId(v.get(i).get("formInstId").toString())
+                            .formInstanceId(v.get(i).get("formInstanceId").toString())
                             .build(), YDConf.FORM_OPERATION.delete);
                 }
             }
@@ -159,8 +159,8 @@ public class FImplService implements FService {
         compId_main.putAll(UtilMap.map("textField_lvdntzul, textField_m25j5gxk, selectField_lvc9x4vq", "textField_m4h15mt7, textField_lvdntzul, selectField_lvc9x4vq"));
         // 账龄表主表: 4 客户名称, 客户编号, 实际开票日期
         compId_main.putAll(UtilMap.map("selectField_lvdojfui, textField_lvdojfuj, dateField_lw5ud9bk", "selectField_lvdojfui, textField_lvdojfuj, dateField_lw5ud9bk"));
-        // 账龄表主表: 5 实例ID, 发票号码, 发票状态
-        compId_main.putAll(UtilMap.map("textField_m25j5gyi, textField_lvd8pp35, selectField_lvituew9", "formInstanceId, textField_lvd8pp35, selectField_lvituew9"));
+        // 账龄表主表: 5 实例ID, 发票号码, 发票状态, 是否往年退票重开
+        compId_main.putAll(UtilMap.map("textField_m25j5gyi, textField_lvd8pp35, selectField_lvituew9, radioField_m883s9n6", "formInstanceId, textField_lvd8pp35, selectField_lvituew9, radioField_m883s9n6"));
 
         // 账龄表子表: 1 开票周期, 开票周期-文本, 开票内容, 含税单价, 数量, 税率
         List<String> compId_detail = UtilList.asList("dateField_m25j5gxu", "textField_m25j5gxv", "textField_lvdnme0u", "numberField_lvdnme0w", "numberField_lvdnme0x", "numberField_lvdnme0y");
@@ -256,6 +256,7 @@ public class FImplService implements FService {
                         .searchCondition(JSON.toJSONString(searchCondition))
                         .formUuid("FORM-EC785A5AB2B9432C892062823EB7C62A9NTL")
                         .formDataJson(JSON.toJSONString(dataForm))
+                        .useLatestVersion(true)
                         .build(), YDConf.FORM_OPERATION.upsert_v2);
             }
         }

+ 112 - 74
mjava-lanyun/src/main/java/com/malk/lanyun/service/impl/TimerServiceImpl.java

@@ -88,64 +88,64 @@ public class TimerServiceImpl implements TimerService {
         dataList.forEach(formData -> {
 //            if("PM00411".equals(UtilMap.getString(formData, "textField_ltxrn8h1"))){
 
-                //获取撤场时间
-                Long withdrawalTime = formData.get("dateField_lzaqu26p")==null?null:DateUtil.beginOfMonth(DateUtil.date(Long.parseLong(formData.get("dateField_lzaqu26p").toString()))).getTime();
-                if (UtilMap.getString(formData, "selectField_lrn2oy4a").equals("进行中") || (ObjectUtil.isNotNull(withdrawalTime) && lastMonth == withdrawalTime)){
-                    List<Map> details = UtilMap.getList(formData, "tableField_lrru2tnq");
+            //获取撤场时间
+            Long withdrawalTime = formData.get("dateField_lzaqu26p")==null?null:DateUtil.beginOfMonth(DateUtil.date(Long.parseLong(formData.get("dateField_lzaqu26p").toString()))).getTime();
+            if (UtilMap.getString(formData, "selectField_lrn2oy4a").equals("进行中") || (ObjectUtil.isNotNull(withdrawalTime) && lastMonth == withdrawalTime)){
+                List<Map> details = UtilMap.getList(formData, "tableField_lrru2tnq");
 //            details = details.stream().filter(item -> UtilMap.isNotBlankString(item, "dateField_lrru2tnr")).collect(Collectors.toList());
-                    // 数据格式化
+                // 数据格式化
 //            details.forEach(row -> {
 //                row.put("textField_luh0k82j", UtilDateTime.format(new Date(UtilMap.getLong(row, "dateField_lrru2tnr")), "yyyy-MM"));
 //            }
 //            });
 //            Collections.sort(details, Comparator.comparingLong(o -> UtilMap.getLong(o, "dateField_lrru2tnr")));
 
-                    // 查找当月数据
-                    LocalDateTime currentDate = UtilDateTime.firstDayOfLastMonth(LocalDateTime.now());
+                // 查找当月数据
+                LocalDateTime currentDate = UtilDateTime.firstDayOfLastMonth(LocalDateTime.now());
 //            LocalDateTime currentDate = UtilDateTime.parseLocalDateTime("2024-07-01 00:00:00");
 
-                    try {
-                        Optional optional = details.stream().filter(item -> UtilDateTime.getLocalDateTimeTimeStamp(currentDate) == UtilMap.getLong(item, "dateField_lrru2tnr") || (currentDate.getYear() +"-"+ String.format("%02d", currentDate.getMonthValue())).equals(UtilMap.getString(item,"textField_luh0k82j"))).findAny();
-                        log.info("上个月数据, {}, {}", currentDate, optional);
-                        if (!optional.isPresent() || UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz") == 0f) {
-                            return;
-                        }
+                try {
+                    Optional optional = details.stream().filter(item -> UtilDateTime.getLocalDateTimeTimeStamp(currentDate) == UtilMap.getLong(item, "dateField_lrru2tnr") || (currentDate.getYear() +"-"+ String.format("%02d", currentDate.getMonthValue())).equals(UtilMap.getString(item,"textField_luh0k82j"))).findAny();
+                    log.info("上个月数据, {}, {}", currentDate, optional);
+                    if (!optional.isPresent() || UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz") == 0f) {
+                        return;
+                    }
 
-                        LocalDateTime lastMonthDate = UtilDateTime.firstDayOfLastMonth(currentDate);
+                    LocalDateTime lastMonthDate = UtilDateTime.firstDayOfLastMonth(currentDate);
 //            LocalDateTime lastMonthDate = UtilDateTime.parseLocalDateTime("2024-06-01 00:00:00");
-                        Map currentRow = (Map) optional.get();
-                        optional = details.stream().filter(item -> UtilDateTime.getLocalDateTimeTimeStamp(lastMonthDate) == UtilMap.getLong(item, "dateField_lrru2tnr") || (currentDate.getYear() +"-"+ String.format("%02d", currentDate.getMonthValue())).equals(UtilMap.getString(item,"textField_luh0k82j"))).findAny();
-                        log.info("上上月数据, {}, {}", lastMonthDate, optional);
-
-                        float price;
-                        if (!optional.isPresent() || UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz") == 0f) {
-                            price = UtilMap.getFloat(currentRow, "numberField_lrru2tns");
-                            currentRow.put("numberField_lrru2tnz", price); // 取本月收入定额
-                        } else {
-                            price = UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz");
-                            currentRow.put("numberField_lrru2tnz", price); // 取上月收入预估
-                        }
-                        //明细合计
-                        currentRow.put("numberField_lryopn7o", UtilMap.getFloat(currentRow, "numberField_lrru2tnz") + UtilMap.getFloat(currentRow, "numberField_lrru2to0") + UtilMap.getFloat(currentRow, "numberField_lrru2to1"));
-                        currentRow.put("numberField_m1hhyqiv", UtilMap.getFloat(currentRow, "numberField_lrru2tnz") + UtilMap.getFloat(currentRow, "numberField_lrru2to0") + UtilMap.getFloat(currentRow, "numberField_lrru2to1"));
+                    Map currentRow = (Map) optional.get();
+                    optional = details.stream().filter(item -> UtilDateTime.getLocalDateTimeTimeStamp(lastMonthDate) == UtilMap.getLong(item, "dateField_lrru2tnr") || (currentDate.getYear() +"-"+ String.format("%02d", currentDate.getMonthValue())).equals(UtilMap.getString(item,"textField_luh0k82j"))).findAny();
+                    log.info("上上月数据, {}, {}", lastMonthDate, optional);
+
+                    float price;
+                    if (!optional.isPresent() || UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz") == 0f) {
+                        price = UtilMap.getFloat(currentRow, "numberField_lrru2tns");
+                        currentRow.put("numberField_lrru2tnz", price); // 取本月收入定额
+                    } else {
+                        price = UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz");
+                        currentRow.put("numberField_lrru2tnz", price); // 取上月收入预估
+                    }
+                    //明细合计
+                    currentRow.put("numberField_lryopn7o", UtilMap.getFloat(currentRow, "numberField_lrru2tnz") + UtilMap.getFloat(currentRow, "numberField_lrru2to0") + UtilMap.getFloat(currentRow, "numberField_lrru2to1"));
+                    currentRow.put("numberField_m1hhyqiv", UtilMap.getFloat(currentRow, "numberField_lrru2tnz") + UtilMap.getFloat(currentRow, "numberField_lrru2to0") + UtilMap.getFloat(currentRow, "numberField_lrru2to1"));
 
-                        price += UtilMap.getFloat(formData, "numberField_lutjev0u");
-                        log.info("price, {}", price);
+                    price += UtilMap.getFloat(formData, "numberField_lutjev0u");
+                    log.info("price, {}", price);
 
-                        System.out.println("更新内容:" + JSON.toJSONString(UtilMap.map("tableField_lrru2tnq, numberField_lutjev0u", details, price)));
-                        // 合计初始化
+                    System.out.println("更新内容:" + JSON.toJSONString(UtilMap.map("tableField_lrru2tnq, numberField_lutjev0u", details, price)));
+                    // 合计初始化
 //            price = details.stream().map(item -> UtilMap.getFloat(item, "numberField_lrru2tnz")).collect(Collectors.toList()).stream().reduce(0f, (acc, cur) -> acc + cur);
-                        ydClient.operateData(YDParam.builder()
-                                .appType("APP_ERBDTFS82HOVBPL3NFH0")
-                                .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
-                                .formInstanceId(UtilMap.getString(formData, "formInstanceId"))
+                    ydClient.operateData(YDParam.builder()
+                            .appType("APP_ERBDTFS82HOVBPL3NFH0")
+                            .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
+                            .formInstanceId(UtilMap.getString(formData, "formInstanceId"))
 //                    .useLatestVersion(true)
-                                .updateFormDataJson(JSON.toJSONString(UtilMap.map("tableField_lrru2tnq, numberField_lutjev0u", details, price)))
-                                .build(), YDConf.FORM_OPERATION.update);
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
+                            .updateFormDataJson(JSON.toJSONString(UtilMap.map("tableField_lrru2tnq, numberField_lutjev0u", details, price)))
+                            .build(), YDConf.FORM_OPERATION.update);
+                } catch (Exception e) {
+                    e.printStackTrace();
                 }
+            }
 //            }
 
         });
@@ -1441,52 +1441,21 @@ public class TimerServiceImpl implements TimerService {
             Long withdrawalTime = formData.get("dateField_lzaqu26p")==null?null:DateUtil.beginOfMonth(DateUtil.date(Long.parseLong(formData.get("dateField_lzaqu26p").toString()))).getTime();
             if (UtilMap.getString(formData, "selectField_lrn2oy4a").equals("进行中") || (ObjectUtil.isNotNull(withdrawalTime) && lastMonth == withdrawalTime)){
                 List<Map> details = UtilMap.getList(formData, "tableField_lrru2tnq");
-//            details = details.stream().filter(item -> UtilMap.isNotBlankString(item, "dateField_lrru2tnr")).collect(Collectors.toList());
-                // 数据格式化
-//            details.forEach(row -> {
-//                row.put("textField_luh0k82j", UtilDateTime.format(new Date(UtilMap.getLong(row, "dateField_lrru2tnr")), "yyyy-MM"));
-//            }
-//            });
-//            Collections.sort(details, Comparator.comparingLong(o -> UtilMap.getLong(o, "dateField_lrru2tnr")));
-
                 // 查找当月数据
                 LocalDateTime currentDate = UtilDateTime.firstDayOfLastMonth(LocalDateTime.now());
-//            LocalDateTime currentDate = UtilDateTime.parseLocalDateTime("2024-07-01 00:00:00");
-
                 try {
                     Optional optional = details.stream().filter(item -> UtilDateTime.getLocalDateTimeTimeStamp(currentDate) == UtilMap.getLong(item, "dateField_lrru2tnr")).findAny();
                     log.info("上个月数据, {}, {}", currentDate, optional);
-                    if (!optional.isPresent() || UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz") != 0f) {
+                    if (!optional.isPresent()) {
                         return;
                     }
-
-//                    LocalDateTime lastMonthDate = UtilDateTime.firstDayOfLastMonth(currentDate);
-////            LocalDateTime lastMonthDate = UtilDateTime.parseLocalDateTime("2024-06-01 00:00:00");
                     Map currentRow = (Map) optional.get();
-//                    optional = details.stream().filter(item -> UtilDateTime.getLocalDateTimeTimeStamp(lastMonthDate) == UtilMap.getLong(item, "dateField_lrru2tnr")).findAny();
-//                    log.info("上上月数据, {}, {}", lastMonthDate, optional);
-//
-//                    float price = 0f;
-//                    if (!optional.isPresent() || UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz") == 0f) {
-//                        price = UtilMap.getFloat(currentRow, "numberField_lrru2tns");
-//                        currentRow.put("numberField_lrru2tnz", price); // 取本月收入定额
-//                    } else {
-//                        price = UtilMap.getFloat((Map) optional.get(), "numberField_lrru2tnz");
-//                        currentRow.put("numberField_lrru2tnz", price); // 取上月收入预估
-//                    }
                     float open = UtilMap.getFloat(currentRow, "numberField_lryopn7o");
                     if (ObjectUtil.isNotNull(currentRow.get("numberField_lrru2to2")) && UtilMap.getFloat(currentRow, "numberField_lrru2to2") > 0){
                         open = UtilMap.getFloat(currentRow, "numberField_lrru2to2");
                     }
                     //明细合计
                     currentRow.put("numberField_m1hhyqiv", open + UtilMap.getFloat(currentRow, "numberField_m5uf580r"));
-
-//                    price += UtilMap.getFloat(formData, "numberField_lutjev0u");
-//                    log.info("price, {}", price);
-
-//                    System.out.println("更新内容:" + JSON.toJSONString(UtilMap.map("tableField_lrru2tnq, numberField_lutjev0u", details, price)));
-                    // 合计初始化
-//            price = details.stream().map(item -> UtilMap.getFloat(item, "numberField_lrru2tnz")).collect(Collectors.toList()).stream().reduce(0f, (acc, cur) -> acc + cur);
                     ydClient.operateData(YDParam.builder()
                             .appType("APP_ERBDTFS82HOVBPL3NFH0")
                             .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
@@ -1525,4 +1494,73 @@ public class TimerServiceImpl implements TimerService {
             }
         }
     }
+
+    @Override
+    public void updateYearPredict() {
+        long lastMonth = DateUtil.beginOfMonth(DateUtil.lastMonth()).getTime();
+
+        List<Map> dataList = ydService.queryFormData_all(YDParam.builder()
+                .appType("APP_ERBDTFS82HOVBPL3NFH0")
+                .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
+                .formUuid("FORM-97BA6C6C8C50416A9E5854F2F4B5C3F3R4WC")
+//                .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_lrr3rg6h", "XM00345")))
+                .build());
+        log.info("项目点数据, {}", dataList.size());
+        System.out.println(dataList.size());
+        dataList.forEach(
+                formData -> {
+                    System.out.println(formData);
+                    // 获取撤场时间
+                    Long withdrawalTime =
+                            formData.get("dateField_lzaqu26p") == null
+                                    ? null
+                                    : DateUtil.beginOfMonth(
+                                            DateUtil.date(
+                                                    Long.parseLong(formData.get("dateField_lzaqu26p").toString())))
+                                    .getTime();
+                    if (UtilMap.getString(formData, "selectField_lrn2oy4a").equals("进行中")
+                            || (ObjectUtil.isNotNull(withdrawalTime) && lastMonth == withdrawalTime)) {
+                        List<Map> details = UtilMap.getList(formData, "tableField_lrru2tnq");
+                        // 查找当月数据
+                        LocalDateTime currentDate = UtilDateTime.firstDayOfLastMonth(LocalDateTime.now());
+                        System.out.println("currentDate"+currentDate);
+                        try {
+                            Optional optional =
+                                    details.stream()
+                                            .filter(
+                                                    item ->
+                                                            UtilDateTime.getLocalDateTimeTimeStamp(currentDate)
+                                                                    == UtilMap.getLong(item, "dateField_lrru2tnr"))
+                                            .findAny();
+                            log.info("上个月数据, {}, {}", currentDate, optional);
+
+                            System.out.println("2222222222222222222");
+                            Map currentRow = (Map) optional.get();
+                            float open = UtilMap.getFloat(currentRow, "numberField_lrru2tns");
+                            if (ObjectUtil.isNotNull(currentRow.get("numberField_m1hhyqiv"))
+                                    && UtilMap.getFloat(currentRow, "numberField_m1hhyqiv") > 0) {
+                                open = UtilMap.getFloat(currentRow, "numberField_m1hhyqiv");
+                            }
+                            System.out.println("formInstanceId:" + UtilMap.getString(formData, "formInstanceId"));
+                            // 明细合计
+                            currentRow.put(
+                                    "numberField_m8gn1uof",
+                                    open + UtilMap.getFloat(currentRow, "numberField_m5uf580r"));
+                            ydClient.operateData(
+                                    YDParam.builder()
+                                            .appType("APP_ERBDTFS82HOVBPL3NFH0")
+                                            .systemToken("RRB66F91T97H1WN89QZYC47PKLZO2ZQOUMOQLP")
+                                            .formInstanceId(UtilMap.getString(formData, "formInstanceId"))
+                                            .useLatestVersion(true)
+                                            .updateFormDataJson(
+                                                    JSON.toJSONString(UtilMap.map("tableField_lrru2tnq", details)))
+                                            .build(),
+                                    YDConf.FORM_OPERATION.update);
+                            System.out.println("更新成功");
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+    }
 }