SaPlusStartup.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.pj.current;
  2. import java.net.InetAddress;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import com.pj.api.jh.task.CheckPayStatusTask;
  6. import com.pj.current.config.WxConfig;
  7. import com.pj.current.task.TaskService;
  8. import com.pj.current.task.TokenTask;
  9. import com.pj.project.tb_order.TbOrderService;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.boot.CommandLineRunner;
  13. import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
  14. import org.springframework.stereotype.Component;
  15. import javax.annotation.Resource;
  16. /**
  17. * springboot启动之后
  18. *
  19. * @author kong
  20. */
  21. @Component
  22. @Slf4j
  23. public class SaPlusStartup implements CommandLineRunner {
  24. @Value("${spring.application.name:sa-plus}")
  25. private String applicationName;
  26. @Value("${server.port:8080}")
  27. private String port;
  28. @Value("${server.servlet.context-path:}")
  29. private String path;
  30. @Value("${spring.profiles.active:}")
  31. private String active;
  32. @Resource
  33. private ThreadPoolTaskScheduler threadPoolTaskScheduler;
  34. @Resource
  35. TokenTask tokenTask;
  36. @Resource
  37. WxConfig wxConfig;
  38. @Resource
  39. TaskService taskService;
  40. @Override
  41. public void run(String... args){
  42. tokenTask.run();
  43. threadPoolTaskScheduler.scheduleAtFixedRate(tokenTask, wxConfig.getFlushSecond() * 1000);
  44. taskService.addTask(new CheckPayStatusTask("=========检查正在支付订单状态========",2000L));
  45. }
  46. /**
  47. * 返回系统当前时间的YYYY-MM-dd hh:mm:ss 字符串格式
  48. */
  49. private static String getNow() {
  50. return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
  51. }
  52. }