ScheduleTaskUtil.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. package com.sooka.sponest.event.utils;
  3. import com.ruoyi.common.core.utils.SpringUtils;
  4. import com.ruoyi.common.core.utils.StringUtils;
  5. import com.ruoyi.common.redis.service.RedisService;
  6. import com.sooka.sponest.event.centereventteventcatalogue.service.ICentereventTEventcatalogueService;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.context.annotation.Configuration;
  11. import org.springframework.scheduling.annotation.EnableScheduling;
  12. import org.springframework.scheduling.annotation.Scheduled;
  13. import java.util.HashMap;
  14. import java.util.Map;
  15. import java.util.concurrent.TimeUnit;
  16. */
  17. /**
  18. * @Auther: mjq
  19. * @Date: 2023/9/12 - 09 - 12 - 10:08
  20. * @Description: com.sooka.sponest.event.utils
  21. * @version: 1.0
  22. *//*
  23. @Configuration
  24. @EnableScheduling
  25. //@RestController
  26. //@RequestMapping("/testload")
  27. public class ScheduleTaskUtil {
  28. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  29. @Autowired
  30. private ICentereventTEventcatalogueService centereventTEventcatalogueService;
  31. static final String DOWN_LOCK = "downlod:lock";
  32. static final String VALUE_LOCK = "valueLock";
  33. @Scheduled(cron = "0 10 0 * * ?")
  34. //@GetMapping("/down")
  35. public void runTask() {
  36. long startMill = System.currentTimeMillis();
  37. // 读取缓存
  38. RedisService redis = SpringUtils.getBean(RedisService.class);
  39. String lock = redis.getCacheObject(DOWN_LOCK);
  40. if (StringUtils.isBlank(lock)) {
  41. redis.setCacheObject(DOWN_LOCK, VALUE_LOCK);
  42. Map<String, Object> params = new HashMap<>();
  43. params.put("taskValue", "1");
  44. centereventTEventcatalogueService.downloadsCommon(params);
  45. }
  46. redis.setCacheObject(DOWN_LOCK, (System.currentTimeMillis() - startMill), (long) 3600 * 12, TimeUnit.SECONDS);
  47. }
  48. }
  49. */