Browse Source

优化管控策略修改操作

develop
zhaoxianglong 5 months ago
parent
commit
7d88f64b04
  1. 12
      zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java
  2. 34
      zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobServiceImpl.java

12
zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java

@ -48,6 +48,18 @@ public class DcBatchFunctionsJobGroupServiceImpl extends ServiceImpl<DcBatchFunc
dcBatchFunctionsJobGroup.setUpdateTime(new Date()); dcBatchFunctionsJobGroup.setUpdateTime(new Date());
boolean update = update(dcBatchFunctionsJobGroup, lambdaQueryWrapper); boolean update = update(dcBatchFunctionsJobGroup, lambdaQueryWrapper);
if (update) { if (update) {
LambdaQueryWrapper<DcBatchFunctionsJob> dcBatchFunctionsJobLambdaQueryWrapper = new LambdaQueryWrapper<>();
dcBatchFunctionsJobLambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobGroup,dcBatchFunctionsJobGroup.getId());
List<DcBatchFunctionsJob> list = dcBatchFunctionsJobService.list(dcBatchFunctionsJobLambdaQueryWrapper);
list.forEach(item->{
try {
dcBatchFunctionsJobService.editDcBatchFunctionsJob(item);
} catch (SchedulerException e) {
throw new RuntimeException(e);
} catch (TaskException e) {
throw new RuntimeException(e);
}
});
return dcBatchFunctionsJobGroup; return dcBatchFunctionsJobGroup;
} }
return null; return null;

34
zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobServiceImpl.java

@ -9,6 +9,7 @@ import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.common.utils.spring.SpringUtils;
import com.zc.business.domain.DcBatchFunctionsJob; import com.zc.business.domain.DcBatchFunctionsJob;
import com.zc.business.domain.DcBatchFunctionsJobGroup; import com.zc.business.domain.DcBatchFunctionsJobGroup;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.mapper.DcBatchFunctionsJobMapper; import com.zc.business.mapper.DcBatchFunctionsJobMapper;
import com.zc.business.service.IDcBatchFunctionsJobGroupService; import com.zc.business.service.IDcBatchFunctionsJobGroupService;
import com.zc.business.service.IDcBatchFunctionsJobService; import com.zc.business.service.IDcBatchFunctionsJobService;
@ -55,8 +56,18 @@ public class DcBatchFunctionsJobServiceImpl extends ServiceImpl<DcBatchFunctions
JSONArray jsonArray = JSONObject.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); JSONArray jsonArray = JSONObject.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration());
for (Object o : jsonArray) { for (Object o : jsonArray) {
String time = ((JSONObject) o).getString("time"); String time = ((JSONObject) o).getString("time");
String[] times = time.split(":"); String[] times = time.split(UniversalEnum.IN_THE_COLON.getValue());
String cron = times[2] + " " + times[1] + " " + times[0] + " " + " * * ?"; String cron = times[UniversalEnum.TWO.getNumber()]
+ UniversalEnum.BLANK_SPACE.getValue()
+ times[UniversalEnum.ONE.getNumber()]
+ UniversalEnum.BLANK_SPACE.getValue()
+ times[UniversalEnum.ZERO.getNumber()]
+ UniversalEnum.BLANK_SPACE.getValue()
+ UniversalEnum.ASTERISK_ASTERISK.getValue()
+ UniversalEnum.BLANK_SPACE.getValue()
+ UniversalEnum.ASTERISK_ASTERISK.getValue()
+ UniversalEnum.BLANK_SPACE.getValue()
+ UniversalEnum.QUESTION_MARK.getValue();
JSONArray tasks = ((JSONObject) o).getJSONArray("tasks"); JSONArray tasks = ((JSONObject) o).getJSONArray("tasks");
for (Object task : tasks) { for (Object task : tasks) {
if (Objects.equals(String.valueOf(job.getJobId()), String.valueOf(task))) { if (Objects.equals(String.valueOf(job.getJobId()), String.valueOf(task))) {
@ -79,12 +90,15 @@ public class DcBatchFunctionsJobServiceImpl extends ServiceImpl<DcBatchFunctions
if (time == null) { if (time == null) {
return null; return null;
} }
if (detailedConfigurations==null) {
detailedConfigurations = new JSONArray();
}
List<Object> detaileds = detailedConfigurations.stream().filter(detailed -> List<Object> detaileds = detailedConfigurations.stream().filter(detailed ->
Objects.equals((String) ((JSONObject) detailed).get("time"), time) Objects.equals((String) ((JSONObject) detailed).get("time"), time)
).collect(Collectors.toList()); ).collect(Collectors.toList());
Integer id = ThreadLocalRandom.current().nextInt(0, 999999999); Integer id = ThreadLocalRandom.current().nextInt(UniversalEnum.ZERO.getNumber(), UniversalEnum.NINE_HUNDRED_AND_NINETY_NINE_HUNDRED_AND_NINETY_NINE_HUNDRED_AND_NINETY_NINE.getNumber());
if (detaileds.size() > 0) { if (detaileds.size() > UniversalEnum.ZERO.getNumber()) {
JSONObject detailed = (JSONObject) detaileds.get(0); JSONObject detailed = (JSONObject) detaileds.get(UniversalEnum.ZERO.getNumber());
JSONArray tasks = detailed.getJSONArray("tasks"); JSONArray tasks = detailed.getJSONArray("tasks");
tasks.add(id); tasks.add(id);
detailed.put("tasks", tasks); detailed.put("tasks", tasks);
@ -152,10 +166,10 @@ public class DcBatchFunctionsJobServiceImpl extends ServiceImpl<DcBatchFunctions
DcBatchFunctionsJob job = new DcBatchFunctionsJob(); DcBatchFunctionsJob job = new DcBatchFunctionsJob();
job.setJobId(Long.valueOf(id)); job.setJobId(Long.valueOf(id));
List<DcBatchFunctionsJob> dcBatchFunctionsJobs = listDcBatchFunctionsJob(job); List<DcBatchFunctionsJob> dcBatchFunctionsJobs = listDcBatchFunctionsJob(job);
if (dcBatchFunctionsJobs.size() == 0) { if (dcBatchFunctionsJobs.size() == UniversalEnum.ZERO.getNumber()) {
return false; return false;
} }
DcBatchFunctionsJob dcBatchFunctionsJob = dcBatchFunctionsJobs.get(0); DcBatchFunctionsJob dcBatchFunctionsJob = dcBatchFunctionsJobs.get(UniversalEnum.ZERO.getNumber());
ScheduleUtils.deleteJob(scheduler, dcBatchFunctionsJob); ScheduleUtils.deleteJob(scheduler, dcBatchFunctionsJob);
DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(dcBatchFunctionsJob.getJobGroup()); DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(dcBatchFunctionsJob.getJobGroup());
if (dcBatchFunctionsJobGroup == null) { if (dcBatchFunctionsJobGroup == null) {
@ -177,8 +191,8 @@ public class DcBatchFunctionsJobServiceImpl extends ServiceImpl<DcBatchFunctions
return result; return result;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
System.out.println(detaileds); System.out.println(detaileds);
if (detaileds.size() > 0) { if (detaileds.size() > UniversalEnum.ZERO.getNumber()) {
JSONObject detailed = (JSONObject) detaileds.get(0); JSONObject detailed = (JSONObject) detaileds.get(UniversalEnum.ZERO.getNumber());
JSONArray tasks = detailed.getJSONArray("tasks"); JSONArray tasks = detailed.getJSONArray("tasks");
tasks = tasks.stream() tasks = tasks.stream()
@ -223,7 +237,7 @@ public class DcBatchFunctionsJobServiceImpl extends ServiceImpl<DcBatchFunctions
@Override @Override
public boolean changeStatus(DcBatchFunctionsJob dcBatchFunctionsJob, String status) throws SchedulerException, TaskException { public boolean changeStatus(DcBatchFunctionsJob dcBatchFunctionsJob, String status) throws SchedulerException, TaskException {
if (Objects.equals(status, "0")) { if (Objects.equals(status, UniversalEnum.ZERO.getValue())) {
scheduler.resumeJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup()))); scheduler.resumeJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup())));
} else { } else {
scheduler.pauseJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup()))); scheduler.pauseJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup())));

Loading…
Cancel
Save