EDZ 3 年之前
父節點
當前提交
e728aefba3

+ 15 - 0
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/DateUtils.java

@@ -32,6 +32,12 @@ public class DateUtils extends PropertyEditorSupport {
             return new SimpleDateFormat("yyyyMMdd");
         }
     };
+    public static ThreadLocal<SimpleDateFormat> yyyy_MM = new ThreadLocal<SimpleDateFormat>() {
+        @Override
+        protected SimpleDateFormat initialValue() {
+            return new SimpleDateFormat("yyyy-MM");
+        }
+    };
     public static ThreadLocal<SimpleDateFormat> date_sdf_wz = new ThreadLocal<SimpleDateFormat>() {
         @Override
         protected SimpleDateFormat initialValue() {
@@ -481,6 +487,15 @@ public class DateUtils extends PropertyEditorSupport {
     // 将日期按照一定的格式转化为字符串
     // ////////////////////////////////////////////////////////////////////////////
 
+    /**
+     * 默认方式表示的系统当前日期,具体格式:年-月
+     *
+     * @return 默认日期按“年-月“格式显示
+     */
+    public static String getNYTime() {
+        return yyyy_MM.get().format(getCalendar().getTime());
+    }
+
     /**
      * 默认方式表示的系统当前日期,具体格式:时:分
      *

+ 53 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/ReportIntoU8Job.java

@@ -1,25 +1,73 @@
 package org.jeecg.modules.quartz.job;
 
-import org.jeecg.modules.viewClockIn.entity.bdClockinMonth;
+import org.apache.commons.lang3.StringUtils;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.system.util.DateUtils2;
 import org.jeecg.modules.viewClockIn.service.IbdClockinMonthService;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.List;
+import java.text.ParseException;
+import java.util.Date;
+
 
 public class ReportIntoU8Job implements Job {
     @Autowired
     private IbdClockinMonthService bdClockinMonthService;
 
+    private static String[] parsePatterns = {"yyyy-MM-dd","yyyy年MM月dd日",
+            "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd",
+            "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyyMMdd"};
+
+
+    /**
+     * 若参数变量名修改 QuartzJobController中也需对应修改
+     */
+    private String parameter;
+
+    public void setParameter(String parameter) {
+        this.parameter = parameter;
+    }
+
+
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
 
-        bdClockinMonthService.reportIntoU8Job("2021-12");
+        if(StringUtils.isEmpty(this.parameter)){
+//            bdClockinMonthService.reportIntoU8Job(DateUtils.getNYTime());
+            System.out.println("==========获取当前月份============"+DateUtils.getNYTime());
+        }else{
+            if(getStrError(this.parameter)){
+//                bdClockinMonthService.reportIntoU8Job(this.parameter);
+                System.out.println("==========获取参数月份============"+this.parameter);
+            }else{
+                System.out.println("==========参数填写有误 例:2021-12 ============"+this.parameter);
+            }
+        }
+
+    }
+
+    public static boolean getStrError(String str){
+
+        try {
+
+            String[] stList = str.split("-");
+            if(stList.length != 2){
+                return false;
+            }
+            if(Integer.valueOf(stList[0]) > 2030 || Integer.valueOf(stList[0]) < 2000){
+                return false;
+            }
+            if(Integer.valueOf(stList[1]) > 12 || Integer.valueOf(stList[1]) < 1){
+                return false;
+            }
 
-        System.out.println("======================");
-        System.out.println("======================");
+        } catch (Exception e) {
+            return false;
+        }
+        return true;
     }
 
 }