Guiji_Gjj.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.sooka.api;
  2. import com.sooka.base.BaseApi;
  3. import com.sooka.model.ResultModel;
  4. import com.sooka.service.Guiji_Gjj_Service;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.scheduling.annotation.EnableScheduling;
  7. import org.springframework.scheduling.annotation.Scheduled;
  8. import javax.annotation.Resource;
  9. import java.text.SimpleDateFormat;
  10. import java.util.Calendar;
  11. import java.util.Date;
  12. @Configuration //1.主要用于标记配置类,兼备Component的效果。
  13. @EnableScheduling
  14. public class Guiji_Gjj extends BaseApi {
  15. @Resource
  16. Guiji_Gjj_Service guiji_gjj_service;
  17. final String scheduTime_1 = "0 31 12 ? * *";
  18. final String scheduTime_2 = "0 31 01 ? * *";
  19. // final String scheduTime_1 = "0 56 12 ? * *";
  20. // final String scheduTime_2 = "0 58 12 ? * *";
  21. @Scheduled(cron = scheduTime_1)
  22. public ResultModel gjj_0_12() {
  23. Date t = new Date();
  24. SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
  25. String d =f.format(t);
  26. //取当天0-12点
  27. String begin_time = d+" 00:00:00";
  28. String end_time = d+" 12:00:00";
  29. System.out.println("am :"+begin_time+" "+end_time);
  30. guiji_gjj_service.data_schedu(begin_time,end_time);
  31. return null;
  32. }
  33. @Scheduled(cron = scheduTime_2)
  34. public ResultModel gjj_12_24() {
  35. Calendar cal = Calendar.getInstance();
  36. cal.add(Calendar.DATE, -1);
  37. String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
  38. //取当天0-12点
  39. String begin_time = yesterday+" 12:00:00";
  40. String end_time = yesterday+" 24:59:00";
  41. System.out.println("pm :"+begin_time+" "+end_time);
  42. guiji_gjj_service.data_schedu(begin_time,end_time);
  43. return null;
  44. }
  45. public static void main(String[] args){
  46. Calendar cal = Calendar.getInstance();
  47. cal.add(Calendar.DATE, -1);
  48. String yesterday = new SimpleDateFormat( "yyyy-MM-dd ").format(cal.getTime());
  49. System.out.println(yesterday);
  50. }
  51. }