rk
2025-09-28 2304d7b140c5c5b4bf3a83f9ced8bff37d20c42e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.doumee.biz.system.impl;
 
import com.doumee.biz.system.SystemJobBiz;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.dao.system.model.SystemJob;
import com.doumee.service.system.SystemJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
public class SystemJobBizImpl implements SystemJobBiz {
 
    @Autowired
    private SystemJobService systemJobService;
 
    @Override
    public Integer create(SystemJob job) {
        job.setDisabled(Boolean.FALSE);
        SystemJob queryDto = new SystemJob();
        queryDto.setDisabled(Boolean.FALSE);
        queryDto.setDeleted(Boolean.FALSE);
        queryDto.setHandler(job.getHandler());
        job.setStatus(Constants.Job.JobStatus.READY.getCode());
        if (systemJobService.count(queryDto) > 0) {
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "已存在任务处理器'" + job.getHandler() + "',请勿重复绑定");
        }
        return systemJobService.create(job);
    }
 
    @Override
    public void updateById(SystemJob job) {
        SystemJob queryDto = new SystemJob();
        queryDto.setDisabled(Boolean.FALSE);
        queryDto.setDeleted(Boolean.FALSE);
        queryDto.setHandler(job.getHandler());
        List<SystemJob> jobs = systemJobService.findList(queryDto);
        if (jobs.size() > 1) {
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "已存在任务处理器'" + job.getHandler() + "',请勿重复绑定");
        }
        if (jobs.size() == 1 && !jobs.get(0).getId().equals(job.getId())) {
            throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "已存在任务处理器'" + job.getHandler() + "',请勿重复绑定");
        }
        systemJobService.updateById(job);
    }
}