ScheduleTask.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.scbfkj.uni.system;
  2. import com.scbfkj.uni.library.UniReturnUtil;
  3. import com.scbfkj.uni.service.DataProcessService;
  4. import java.util.HashMap;
  5. import java.util.Objects;
  6. public class ScheduleTask implements Runnable {
  7. private final String id; // 服务ID
  8. private final Integer loopCount;
  9. int count = 0;
  10. public ScheduleTask(String id, Integer loopCount) {
  11. this.id = id;
  12. this.loopCount = Objects.isNull(loopCount) || loopCount < 0 ? 0 : loopCount;
  13. }
  14. public String getId() {
  15. return id;
  16. }
  17. @Override
  18. public void run() {
  19. if (loopCount > 0) {
  20. count++;
  21. }
  22. try {
  23. DataProcessService.process(new HashMap<>() {{
  24. put("serviceid", id);
  25. }});
  26. } catch (Exception e) {
  27. throw new RuntimeException(e);
  28. }
  29. if (loopCount < count) {
  30. try {
  31. ScheduleUtil.cancel(id);
  32. } catch (Exception e) {
  33. if (Config.isDebug()) {
  34. e.printStackTrace();
  35. } else {
  36. System.out.println(UniReturnUtil.getMessage(e));
  37. }
  38. }
  39. }
  40. }
  41. }