提交 | 用户 | 时间
|
516ef4
|
1 |
package com.iailab.module.shasteel.job.service.impl; |
L |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
5 |
import com.iailab.framework.common.constant.Constant; |
|
6 |
import com.iailab.framework.common.pojo.PageResult; |
|
7 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
|
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
9 |
import com.iailab.framework.security.core.util.SecurityFrameworkUtils; |
|
10 |
import com.iailab.framework.tenant.core.context.TenantContextHolder; |
|
11 |
import com.iailab.module.shasteel.job.dao.ScheduleJobDao; |
|
12 |
import com.iailab.module.shasteel.job.dto.ScheduleJobDTO; |
|
13 |
import com.iailab.module.shasteel.job.entity.ScheduleJobEntity; |
|
14 |
import com.iailab.module.shasteel.job.service.ScheduleJobService; |
|
15 |
import com.iailab.module.shasteel.job.utils.ScheduleUtils; |
|
16 |
import com.iailab.module.shasteel.job.vo.ScheduleJobReqVO; |
|
17 |
import org.apache.commons.lang3.StringUtils; |
|
18 |
import org.quartz.Scheduler; |
|
19 |
import org.springframework.stereotype.Service; |
|
20 |
import org.springframework.transaction.annotation.Transactional; |
|
21 |
|
|
22 |
import javax.annotation.Resource; |
|
23 |
import java.util.Date; |
|
24 |
import java.util.HashMap; |
|
25 |
import java.util.Map; |
|
26 |
|
|
27 |
@Service |
|
28 |
public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService { |
|
29 |
@Resource |
|
30 |
private Scheduler scheduler; |
|
31 |
|
|
32 |
@Resource |
|
33 |
private ScheduleJobDao scheduleJobDao; |
|
34 |
|
|
35 |
@Override |
|
36 |
public PageResult<ScheduleJobEntity> page(ScheduleJobReqVO reqVO) { |
|
37 |
return scheduleJobDao.selectPage(reqVO); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public ScheduleJobDTO get(Long id) { |
|
42 |
ScheduleJobEntity entity = scheduleJobDao.selectById(id); |
|
43 |
|
|
44 |
return ConvertUtils.sourceToTarget(entity, ScheduleJobDTO.class); |
|
45 |
} |
|
46 |
|
|
47 |
private QueryWrapper<ScheduleJobEntity> getWrapper(Map<String, Object> params){ |
|
48 |
String beanName = (String)params.get("beanName"); |
|
49 |
|
|
50 |
QueryWrapper<ScheduleJobEntity> wrapper = new QueryWrapper<>(); |
|
51 |
wrapper.like(StringUtils.isNotBlank(beanName), "bean_name", beanName); |
|
52 |
|
|
53 |
return wrapper; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
@Transactional(rollbackFor = Exception.class) |
|
58 |
public void save(ScheduleJobDTO dto) { |
|
59 |
Long tenantId = TenantContextHolder.getRequiredTenantId(); |
|
60 |
ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class); |
|
61 |
entity.setId(System.currentTimeMillis()); |
|
62 |
entity.setStatus(Constant.ScheduleStatus.NORMAL.getValue()); |
|
63 |
entity.setTenantId(tenantId); |
|
64 |
entity.setCreator(SecurityFrameworkUtils.getLoginUser().getId()); |
|
65 |
entity.setCreateDate(new Date()); |
|
66 |
scheduleJobDao.insert(entity); |
|
67 |
|
|
68 |
ScheduleUtils.createScheduleJob(scheduler, entity); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
@Transactional(rollbackFor = Exception.class) |
|
73 |
public void update(ScheduleJobDTO dto) { |
|
74 |
Long tenantId = TenantContextHolder.getRequiredTenantId(); |
|
75 |
ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class); |
|
76 |
entity.setUpdateDate(new Date()); |
|
77 |
entity.setUpdater(SecurityFrameworkUtils.getLoginUser().getId()); |
|
78 |
entity.setTenantId(tenantId); |
|
79 |
ScheduleUtils.updateScheduleJob(scheduler, entity); |
|
80 |
|
|
81 |
this.updateById(entity); |
|
82 |
} |
|
83 |
|
|
84 |
@Override |
|
85 |
@Transactional(rollbackFor = Exception.class) |
|
86 |
public void deleteBatch(Long id) { |
|
87 |
ScheduleUtils.deleteScheduleJob(scheduler, id); |
|
88 |
|
|
89 |
scheduleJobDao.deleteById(id); |
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public int updateBatch(Long[] ids, int status){ |
|
94 |
Map<String, Object> map = new HashMap<>(2); |
|
95 |
map.put("ids", ids); |
|
96 |
map.put("status", status); |
|
97 |
return scheduleJobDao.updateBatch(map); |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
@Transactional(rollbackFor = Exception.class) |
|
102 |
public void run(Long[] ids) { |
|
103 |
for(Long id : ids){ |
|
104 |
ScheduleUtils.run(scheduler, scheduleJobDao.selectById(id)); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
@Transactional(rollbackFor = Exception.class) |
|
110 |
public void pause(Long[] ids) { |
|
111 |
for(Long id : ids){ |
|
112 |
ScheduleUtils.pauseJob(scheduler, id); |
|
113 |
} |
|
114 |
|
|
115 |
updateBatch(ids, Constant.ScheduleStatus.PAUSE.getValue()); |
|
116 |
} |
|
117 |
|
|
118 |
@Override |
|
119 |
@Transactional(rollbackFor = Exception.class) |
|
120 |
public void resume(Long[] ids) { |
|
121 |
for(Long id : ids){ |
|
122 |
ScheduleUtils.resumeJob(scheduler, id); |
|
123 |
} |
|
124 |
|
|
125 |
updateBatch(ids, Constant.ScheduleStatus.NORMAL.getValue()); |
|
126 |
} |
|
127 |
|
|
128 |
} |