提交 | 用户 | 时间
|
516ef4
|
1 |
package com.iailab.module.shasteel.job.service.impl; |
L |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
94c44e
|
4 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
516ef4
|
5 |
import com.iailab.framework.common.constant.Constant; |
94c44e
|
6 |
import com.iailab.framework.common.page.PageData; |
516ef4
|
7 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
L |
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
9 |
import com.iailab.framework.security.core.util.SecurityFrameworkUtils; |
|
10 |
import com.iailab.module.shasteel.job.dao.ScheduleJobDao; |
|
11 |
import com.iailab.module.shasteel.job.dto.ScheduleJobDTO; |
|
12 |
import com.iailab.module.shasteel.job.entity.ScheduleJobEntity; |
|
13 |
import com.iailab.module.shasteel.job.service.ScheduleJobService; |
|
14 |
import com.iailab.module.shasteel.job.utils.ScheduleUtils; |
|
15 |
import org.apache.commons.lang3.StringUtils; |
|
16 |
import org.quartz.Scheduler; |
94c44e
|
17 |
import org.springframework.beans.factory.annotation.Autowired; |
516ef4
|
18 |
import org.springframework.stereotype.Service; |
L |
19 |
import org.springframework.transaction.annotation.Transactional; |
|
20 |
|
94c44e
|
21 |
import java.util.Arrays; |
516ef4
|
22 |
import java.util.Date; |
L |
23 |
import java.util.HashMap; |
|
24 |
import java.util.Map; |
|
25 |
|
|
26 |
@Service |
94c44e
|
27 |
public class ScheduleJobServiceImpl extends BaseServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService { |
D |
28 |
@Autowired |
516ef4
|
29 |
private Scheduler scheduler; |
L |
30 |
|
|
31 |
@Override |
94c44e
|
32 |
public PageData<ScheduleJobDTO> page(Map<String, Object> params) { |
D |
33 |
IPage<ScheduleJobEntity> page = baseDao.selectPage( |
|
34 |
getPage(params, "create_date", false), |
|
35 |
getWrapper(params) |
|
36 |
); |
|
37 |
return getPageData(page, ScheduleJobDTO.class); |
516ef4
|
38 |
} |
L |
39 |
|
|
40 |
@Override |
|
41 |
public ScheduleJobDTO get(Long id) { |
94c44e
|
42 |
ScheduleJobEntity entity = baseDao.selectById(id); |
516ef4
|
43 |
|
L |
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 |
ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class); |
|
60 |
entity.setId(System.currentTimeMillis()); |
|
61 |
entity.setCreateDate(new Date()); |
94c44e
|
62 |
entity.setCreator(SecurityFrameworkUtils.getLoginUser().getId()); |
D |
63 |
entity.setStatus(Constant.ScheduleStatus.NORMAL.getValue()); |
|
64 |
this.insert(entity); |
516ef4
|
65 |
|
L |
66 |
ScheduleUtils.createScheduleJob(scheduler, entity); |
|
67 |
} |
|
68 |
|
|
69 |
@Override |
|
70 |
@Transactional(rollbackFor = Exception.class) |
|
71 |
public void update(ScheduleJobDTO dto) { |
|
72 |
ScheduleJobEntity entity = ConvertUtils.sourceToTarget(dto, ScheduleJobEntity.class); |
|
73 |
entity.setUpdateDate(new Date()); |
|
74 |
entity.setUpdater(SecurityFrameworkUtils.getLoginUser().getId()); |
|
75 |
ScheduleUtils.updateScheduleJob(scheduler, entity); |
|
76 |
|
|
77 |
this.updateById(entity); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
@Transactional(rollbackFor = Exception.class) |
94c44e
|
82 |
public void deleteBatch(Long[] ids) { |
D |
83 |
for(Long id : ids){ |
|
84 |
ScheduleUtils.deleteScheduleJob(scheduler, id); |
|
85 |
} |
516ef4
|
86 |
|
94c44e
|
87 |
//删除数据 |
D |
88 |
this.deleteBatchIds(Arrays.asList(ids)); |
516ef4
|
89 |
} |
L |
90 |
|
|
91 |
@Override |
|
92 |
public int updateBatch(Long[] ids, int status){ |
|
93 |
Map<String, Object> map = new HashMap<>(2); |
|
94 |
map.put("ids", ids); |
|
95 |
map.put("status", status); |
94c44e
|
96 |
return baseDao.updateBatch(map); |
516ef4
|
97 |
} |
L |
98 |
|
|
99 |
@Override |
|
100 |
@Transactional(rollbackFor = Exception.class) |
94c44e
|
101 |
public void run(Long id) { |
D |
102 |
ScheduleUtils.run(scheduler, this.selectById(id)); |
516ef4
|
103 |
} |
L |
104 |
|
|
105 |
@Override |
|
106 |
@Transactional(rollbackFor = Exception.class) |
|
107 |
public void pause(Long[] ids) { |
|
108 |
for(Long id : ids){ |
|
109 |
ScheduleUtils.pauseJob(scheduler, id); |
|
110 |
} |
|
111 |
|
|
112 |
updateBatch(ids, Constant.ScheduleStatus.PAUSE.getValue()); |
|
113 |
} |
|
114 |
|
|
115 |
@Override |
|
116 |
@Transactional(rollbackFor = Exception.class) |
|
117 |
public void resume(Long[] ids) { |
|
118 |
for(Long id : ids){ |
|
119 |
ScheduleUtils.resumeJob(scheduler, id); |
|
120 |
} |
|
121 |
|
|
122 |
updateBatch(ids, Constant.ScheduleStatus.NORMAL.getValue()); |
|
123 |
} |
|
124 |
|
|
125 |
} |