12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package com.scbfkj.uni.system;
- import com.scbfkj.uni.library.UniReturnUtil;
- import com.scbfkj.uni.service.DataProcessService;
- import java.util.HashMap;
- import java.util.Objects;
- public class ScheduleTask implements Runnable {
- private final String id; // 服务ID
- private final Integer loopCount;
- int count = 0;
- public ScheduleTask(String id, Integer loopCount) {
- this.id = id;
- this.loopCount = Objects.isNull(loopCount) || loopCount < 0 ? 0 : loopCount;
- }
- public String getId() {
- return id;
- }
- @Override
- public void run() {
- if (loopCount > 0) {
- count++;
- }
- try {
- DataProcessService.process(new HashMap<>() {{
- put("serviceid", id);
- }});
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- if (loopCount < count) {
- try {
- ScheduleUtil.cancel(id);
- } catch (Exception e) {
- if (Config.isDebug()) {
- e.printStackTrace();
- } else {
- System.out.println(UniReturnUtil.getMessage(e));
- }
- }
- }
- }
- }
|