|
@@ -0,0 +1,136 @@
|
|
|
|
+package com.malk.huagao.schedule;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.malk.huagao.service.HuaGaoService;
|
|
|
|
+import com.malk.server.aliwork.YDConf;
|
|
|
|
+import com.malk.server.aliwork.YDParam;
|
|
|
|
+import com.malk.service.aliwork.YDClient;
|
|
|
|
+import com.malk.utils.UtilDateTime;
|
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
|
+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;
|
|
|
|
+
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.LocalTime;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Configuration
|
|
|
|
+@EnableScheduling
|
|
|
|
+@ConditionalOnProperty(name = {"enable.scheduling"})
|
|
|
|
+public class ScheduleTask {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private YDClient ydClient;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private HuaGaoService huaGaoService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 5 2 1 * ?")
|
|
|
|
+ public void syncMonths() {
|
|
|
|
+ log.info("考勤同步-月度");
|
|
|
|
+ LocalDateTime startTime= LocalDate.now().minusMonths(1).atTime(LocalTime.MIN);
|
|
|
|
+ LocalDateTime endTime= LocalDate.now().atTime(LocalTime.MIN);
|
|
|
|
+ List<String> time= Arrays.asList(String.valueOf(UtilDateTime.getLocalDateTimeTimeStamp(startTime)),String.valueOf(UtilDateTime.getLocalDateTimeTimeStamp(endTime)));
|
|
|
|
+ try {
|
|
|
|
+ huaGaoService.syncKqData(startTime,endTime);
|
|
|
|
+ compSave(time,"同步成功","");
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ compSave(time,"异常",e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 0 1 * * 1")
|
|
|
|
+ public void syncWeek() {
|
|
|
|
+ log.info("考勤同步-周度");
|
|
|
|
+ LocalDateTime startTime= LocalDate.now().minusWeeks(1).atTime(LocalTime.MIN);
|
|
|
|
+ LocalDateTime endTime= LocalDate.now().atTime(LocalTime.MIN);
|
|
|
|
+ List<String> time= Arrays.asList(String.valueOf(UtilDateTime.getLocalDateTimeTimeStamp(startTime)),String.valueOf(UtilDateTime.getLocalDateTimeTimeStamp(endTime)));
|
|
|
|
+ try {
|
|
|
|
+ huaGaoService.syncKqData(startTime,endTime);
|
|
|
|
+ compSave(time,"同步成功","");
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ compSave(time,"异常",e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 35 0 * * ?")
|
|
|
|
+ public void syncDay() {
|
|
|
|
+ log.info("考勤同步-昨天");
|
|
|
|
+ LocalDateTime startTime= LocalDate.now().minusDays(1).atTime(LocalTime.MIN);
|
|
|
|
+ LocalDateTime endTime= LocalDate.now().atTime(LocalTime.MIN);
|
|
|
|
+ List<String> time= Arrays.asList(String.valueOf(UtilDateTime.getLocalDateTimeTimeStamp(startTime)),String.valueOf(UtilDateTime.getLocalDateTimeTimeStamp(endTime)));
|
|
|
|
+ try {
|
|
|
|
+ huaGaoService.syncKqData(startTime,endTime);
|
|
|
|
+ compSave(time,"同步成功","");
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ compSave(time,"异常",e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
|
+ public void sync() {
|
|
|
|
+ List<Map> list=(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-0D560B9D8B64464C8C885FE20B7C7C95T4IA").pageSize(1)
|
|
|
|
+ .searchFieldJson(JSONObject.toJSONString(UtilMap.map("selectField_m8nud6t3","待处理"))).build(), YDConf.FORM_QUERY.retrieve_list).getData();
|
|
|
|
+ log.info("手动同步查询-结果,{}",list.size());
|
|
|
|
+ if(list==null||list.size()<1){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Map data=list.get(0);
|
|
|
|
+ log.info("{}",data);
|
|
|
|
+ String formInstanceId=String.valueOf(data.get("formInstanceId"));
|
|
|
|
+ processing(formInstanceId);
|
|
|
|
+ Map formData=UtilMap.getMap(data,"formData");
|
|
|
|
+ try {
|
|
|
|
+ List<String> timeList=UtilMap.getList(formData,"cascadeDateField_m8nud6sy");
|
|
|
|
+ LocalDateTime startTime= UtilDateTime.getLocalDateTimeFromTimestamp(Long.parseLong(timeList.get(0)));
|
|
|
|
+ LocalDateTime endTime=UtilDateTime.getLocalDateTimeFromTimestamp(Long.parseLong(timeList.get(1)));
|
|
|
|
+ huaGaoService.syncKqData(startTime,endTime);
|
|
|
|
+ comp(formInstanceId,"同步成功!","");
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ comp(formInstanceId,"异常",e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void processing(String id){
|
|
|
|
+ ydClient.operateData(YDParam.builder().formInstanceId(id)
|
|
|
|
+ .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_m8nud6t3", "处理中")))
|
|
|
|
+ .build(), YDConf.FORM_OPERATION.update);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void comp(String id,String result,String msg){
|
|
|
|
+ ydClient.operateData(YDParam.builder().formInstanceId(id)
|
|
|
|
+ .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_m8nud6t3, textField_m8nud6t9, textareaField_m8nud6tb", "已完成",result,msg)))
|
|
|
|
+ .build(), YDConf.FORM_OPERATION.update);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void compSave(List<String> time,String result,String msg){
|
|
|
|
+ ydClient.operateData(YDParam.builder().formUuid("FORM-0D560B9D8B64464C8C885FE20B7C7C95T4IA")
|
|
|
|
+ .formDataJson(JSON.toJSONString(UtilMap.map("cascadeDateField_m8nud6sy, selectField_m8nud6t3, textField_m8nud6t9, textareaField_m8nud6tb", time,"已完成",result,msg)))
|
|
|
|
+ .build(), YDConf.FORM_OPERATION.create);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|