123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package com.sooka.api;
- import com.sooka.base.BaseApi;
- import com.sooka.model.ResultModel;
- import com.sooka.service.Guiji_Gjj_Service;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import javax.annotation.Resource;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- @Configuration //1.主要用于标记配置类,兼备Component的效果。
- @EnableScheduling
- public class Guiji_Gjj extends BaseApi {
- @Resource
- Guiji_Gjj_Service guiji_gjj_service;
- final String scheduTime_1 = "0 31 12 ? * *";
- final String scheduTime_2 = "0 31 01 ? * *";
- // final String scheduTime_1 = "0 56 12 ? * *";
- // final String scheduTime_2 = "0 58 12 ? * *";
- @Scheduled(cron = scheduTime_1)
- public ResultModel gjj_0_12() {
- Date t = new Date();
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
- String d =f.format(t);
- //取当天0-12点
- String begin_time = d+" 00:00:00";
- String end_time = d+" 12:00:00";
- System.out.println("am :"+begin_time+" "+end_time);
- guiji_gjj_service.data_schedu(begin_time,end_time);
- return null;
- }
- @Scheduled(cron = scheduTime_2)
- public ResultModel gjj_12_24() {
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.DATE, -1);
- String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
- //取当天0-12点
- String begin_time = yesterday+" 12:00:00";
- String end_time = yesterday+" 24:59:00";
- System.out.println("pm :"+begin_time+" "+end_time);
- guiji_gjj_service.data_schedu(begin_time,end_time);
- return null;
- }
- public static void main(String[] args){
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.DATE, -1);
- String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
- System.out.println(yesterday);
- }
- }
|