Showing
7 changed files
with
50 additions
and
41 deletions
... | ... | @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiOperation; |
5 | 5 | import lombok.RequiredArgsConstructor; |
6 | 6 | import org.apache.commons.lang3.StringUtils; |
7 | 7 | import org.quartz.SchedulerException; |
8 | +import org.springframework.security.access.prepost.PreAuthorize; | |
8 | 9 | import org.springframework.validation.annotation.Validated; |
9 | 10 | import org.springframework.web.bind.annotation.*; |
10 | 11 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
... | ... | @@ -60,9 +61,8 @@ public class TkTaskCenterController extends BaseController { |
60 | 61 | |
61 | 62 | @PostMapping("/add") |
62 | 63 | @ApiOperation(value = "新增任务中心") |
63 | - // @PreAuthorize( | |
64 | - // | |
65 | - // "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:add:post'})") | |
64 | + @PreAuthorize( | |
65 | + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:add:post'})") | |
66 | 66 | public ResponseResult<TkTaskCenterDTO> save( |
67 | 67 | @RequestBody @Validated(AddGroup.class) TkTaskCenterDTO taskCenter) |
68 | 68 | throws ThingsboardException, SchedulerException { |
... | ... | @@ -73,9 +73,8 @@ public class TkTaskCenterController extends BaseController { |
73 | 73 | } |
74 | 74 | |
75 | 75 | @PutMapping("/update") |
76 | - // @PreAuthorize( | |
77 | - // | |
78 | - // "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:update:update'})") | |
76 | + @PreAuthorize( | |
77 | + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:update:update'})") | |
79 | 78 | @ApiOperation(value = "编辑任务中心") |
80 | 79 | public ResponseResult<TkTaskCenterDTO> update( |
81 | 80 | @RequestBody @Validated(UpdateGroup.class) TkTaskCenterDTO taskCenter) |
... | ... | @@ -87,9 +86,8 @@ public class TkTaskCenterController extends BaseController { |
87 | 86 | } |
88 | 87 | |
89 | 88 | @PutMapping("/{id}/update/{state}") |
90 | - // @PreAuthorize( | |
91 | - // | |
92 | - // "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:update:update'})") | |
89 | + @PreAuthorize( | |
90 | + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:update:state'})") | |
93 | 91 | @ApiOperation(value = "更新状态") |
94 | 92 | public ResponseResult<Boolean> updateState( |
95 | 93 | @PathVariable("id") String id, @PathVariable("state") Integer state) |
... | ... | @@ -102,8 +100,8 @@ public class TkTaskCenterController extends BaseController { |
102 | 100 | } |
103 | 101 | |
104 | 102 | @DeleteMapping |
105 | - // @PreAuthorize( | |
106 | - // "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:delete'})") | |
103 | + @PreAuthorize( | |
104 | + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:delete'})") | |
107 | 105 | @ApiOperation(value = "删除任务中心") |
108 | 106 | public ResponseResult<Boolean> deleteTaskCenter(@RequestBody DeleteDTO deleteDTO) |
109 | 107 | throws ThingsboardException, SchedulerException { |
... | ... | @@ -112,9 +110,8 @@ public class TkTaskCenterController extends BaseController { |
112 | 110 | } |
113 | 111 | |
114 | 112 | @PutMapping("/{id}/update/{tbDeviceId}/{allow}") |
115 | - // @PreAuthorize( | |
116 | - // | |
117 | - // "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:cancel'})") | |
113 | + @PreAuthorize( | |
114 | + "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:task_center:cancel:allow'})") | |
118 | 115 | @ApiOperation(value = "设备更新任务执行") |
119 | 116 | public ResponseResult<Boolean> cancelOrAllowExecute( |
120 | 117 | @PathVariable("id") String taskId, | ... | ... |
... | ... | @@ -13,7 +13,7 @@ public class TkDeviceTaskCenterDTO extends BaseDTO { |
13 | 13 | private String taskCenterId; |
14 | 14 | |
15 | 15 | @ApiModelProperty(value = "是否允许执行:0不执行 1允许执行") |
16 | - private Integer state; | |
16 | + private Integer allowState; | |
17 | 17 | |
18 | 18 | @ApiModelProperty(value = "租户ID") |
19 | 19 | private String tenantId; | ... | ... |
... | ... | @@ -48,7 +48,7 @@ public class TkDeviceTaskCenterServiceImpl |
48 | 48 | .eq(TkDeviceTaskCenterEntity::getTaskCenterId, taskCenterId) |
49 | 49 | .eq(TkDeviceTaskCenterEntity::getTenantId, tenantId)); |
50 | 50 | if (null != entity) { |
51 | - entity.setState(state); | |
51 | + entity.setAllowState(state); | |
52 | 52 | baseMapper.updateById(entity); |
53 | 53 | } |
54 | 54 | return false; | ... | ... |
... | ... | @@ -81,8 +81,7 @@ public class TkReportFromConfigServiceImpl |
81 | 81 | || null == report.getExecuteAttributes()) { |
82 | 82 | throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
83 | 83 | } |
84 | - if (null != report.getExecuteAttributes() | |
85 | - && report.getExecuteAttributes().size() > FastIotConstants.MagicNumber.ZERO) { | |
84 | + if (report.getExecuteAttributes().size() > FastIotConstants.MagicNumber.ZERO) { | |
86 | 85 | report |
87 | 86 | .getExecuteAttributes() |
88 | 87 | .forEach( |
... | ... | @@ -171,10 +170,7 @@ public class TkReportFromConfigServiceImpl |
171 | 170 | public ReportFormConfigDTO findReportFormConfigById(String id) { |
172 | 171 | return Optional.ofNullable(baseMapper.selectById(id)) |
173 | 172 | .map(this::getReportFormConfigDTOByEntity) |
174 | - .orElseThrow( | |
175 | - () -> { | |
176 | - throw new TkDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage()); | |
177 | - }); | |
173 | + .orElseThrow(() -> new TkDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage())); | |
178 | 174 | } |
179 | 175 | |
180 | 176 | private void addCheckSysJob(TkReportFormConfigEntity reportFormConfig) throws SchedulerException { |
... | ... | @@ -212,6 +208,7 @@ public class TkReportFromConfigServiceImpl |
212 | 208 | } else { |
213 | 209 | // 修改cron表达式 |
214 | 210 | sysJobDTO.setCronExpression(cronExpression); |
211 | + sysJobDTO.setJobName(reportFormConfig.getName()); | |
215 | 212 | sysJobDTO.setStatus( |
216 | 213 | reportFormConfig.getStatus() == null |
217 | 214 | ? StatusEnum.DISABLE.getIndex() | ... | ... |
... | ... | @@ -30,6 +30,7 @@ import org.thingsboard.server.dao.yunteng.service.*; |
30 | 30 | |
31 | 31 | import javax.transaction.Transactional; |
32 | 32 | import java.util.*; |
33 | +import java.util.stream.Collectors; | |
33 | 34 | |
34 | 35 | @Service |
35 | 36 | @RequiredArgsConstructor |
... | ... | @@ -49,15 +50,17 @@ public class TkTaskCenterServiceImpl |
49 | 50 | getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME, false); |
50 | 51 | IPage<TkTaskCenterDTO> iPage = baseMapper.getPageData(page, queryMap); |
51 | 52 | if (!iPage.getRecords().isEmpty()) { |
52 | - iPage.getRecords().stream() | |
53 | - .peek( | |
53 | + iPage.setRecords(iPage.getRecords().stream() | |
54 | + .map( | |
54 | 55 | obj -> { |
55 | 56 | String cacheName = FastIotConstants.CacheConfigKey.TASK_CENTER_INFOS; |
56 | 57 | String key = |
57 | 58 | FastIotConstants.CacheConfigKey.TASK_CENTER_EXECUTE_TIME + "_" + obj.getId(); |
58 | 59 | Optional<Long> lastExecuteTime = cacheUtils.get(cacheName, key); |
59 | 60 | lastExecuteTime.ifPresent(obj::setLastExecuteTime); |
60 | - }); | |
61 | + return obj; | |
62 | + }) | |
63 | + .collect(Collectors.toList())); | |
61 | 64 | } |
62 | 65 | return new TkPageData<>(iPage.getRecords(), iPage.getTotal()); |
63 | 66 | } |
... | ... | @@ -207,20 +210,20 @@ public class TkTaskCenterServiceImpl |
207 | 210 | if (baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO) { |
208 | 211 | String sourceId = entity.getId(); |
209 | 212 | SysJobDTO queryJob = tkSysJobService.findSysJobBySourceId(sourceId); |
213 | + TaskExecuteTimeDTO executeTime = | |
214 | + JacksonUtil.convertValue(entity.getExecuteTime(), TaskExecuteTimeDTO.class); | |
215 | + if (null == executeTime || StringUtils.isEmpty(executeTime.getCron())) { | |
216 | + throw new TkDataValidationException(ErrorMessage.CRON_INVALID.getMessage()); | |
217 | + } | |
210 | 218 | if (null == queryJob) { |
211 | - TaskExecuteTimeDTO executeTime = | |
212 | - JacksonUtil.convertValue(entity.getExecuteTime(), TaskExecuteTimeDTO.class); | |
213 | - if (null == executeTime || StringUtils.isEmpty(executeTime.getCron())) { | |
214 | - throw new TkDataValidationException(ErrorMessage.CRON_INVALID.getMessage()); | |
215 | - } | |
216 | 219 | queryJob = new SysJobDTO(); |
217 | 220 | queryJob.setSourceId(sourceId); |
218 | - queryJob.setJobName(entity.getName()); | |
219 | 221 | queryJob.setInvokeTarget("rpcCommandTask.process('" + sourceId + "')"); |
220 | 222 | queryJob.setJobGroup(JobGroupEnum.TASK_CENTER.name()); |
221 | - queryJob.setCronExpression(executeTime.getCron()); | |
222 | 223 | queryJob.setTenantId(entity.getTenantId()); |
223 | 224 | } |
225 | + queryJob.setCronExpression(executeTime.getCron()); | |
226 | + queryJob.setJobName(entity.getName()); | |
224 | 227 | queryJob.setStatus(state); |
225 | 228 | tkSysJobService.saveOrUpdateJob(queryJob); |
226 | 229 | result = true; |
... | ... | @@ -244,11 +247,22 @@ public class TkTaskCenterServiceImpl |
244 | 247 | // 查询设备信息 |
245 | 248 | DeviceDTO dto = tkDeviceService.findDeviceInfoByTbDeviceId(tenantId, tbDeviceId); |
246 | 249 | Map<String, List<String>> map = targetContent.getCancelExecuteDevices(); |
247 | - if (isAllow) { | |
248 | - map.get(dto.getDeviceProfileId()).remove(tbDeviceId); | |
249 | - } else { | |
250 | - map.get(dto.getDeviceProfileId()).add(tbDeviceId); | |
250 | + if (null == map) { | |
251 | + map = new HashMap<>(); | |
252 | + } | |
253 | + List<String> cancelExecuteList = map.get(dto.getDeviceProfileId()); | |
254 | + if (null != cancelExecuteList && !cancelExecuteList.isEmpty()) { | |
255 | + if (isAllow) { | |
256 | + cancelExecuteList.remove(tbDeviceId); | |
257 | + } else { | |
258 | + cancelExecuteList.add(tbDeviceId); | |
259 | + } | |
260 | + } else if (null == cancelExecuteList && !isAllow) { | |
261 | + cancelExecuteList = new ArrayList<>(); | |
262 | + cancelExecuteList.add(tbDeviceId); | |
263 | + map.put(dto.getDeviceProfileId(), cancelExecuteList); | |
251 | 264 | } |
265 | + targetContent.setCancelExecuteDevices(map); | |
252 | 266 | entity.setExecuteTarget(JacksonUtil.convertValue(targetContent, JsonNode.class)); |
253 | 267 | baseMapper.updateById(entity); |
254 | 268 | tkDeviceTaskCenterService.updateStateByTbDeviceIdAndTaskCenterId( |
... | ... | @@ -304,7 +318,7 @@ public class TkTaskCenterServiceImpl |
304 | 318 | entity.setTbDeviceId(key); |
305 | 319 | entity.setTaskCenterId(taskCenterId); |
306 | 320 | entity.setTenantId(tenantId); |
307 | - entity.setState(StatusEnum.ENABLE.getIndex()); | |
321 | + entity.setAllowState(StatusEnum.ENABLE.getIndex()); | |
308 | 322 | saveList.add(entity); |
309 | 323 | } |
310 | 324 | tkDeviceTaskCenterService.insertBatch(saveList); | ... | ... |
... | ... | @@ -13,12 +13,13 @@ |
13 | 13 | <result property="executeTime" column="execute_time" |
14 | 14 | typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> |
15 | 15 | <result property="createTime" column="create_time"/> |
16 | + <result property="state" column="state"/> | |
16 | 17 | <result property="creator" column="creator"/> |
17 | 18 | <result property="updater" column="updater"/> |
18 | 19 | <result property="updateTime" column="update_time"/> |
19 | 20 | <result property="tenantId" column="tenant_id" /> |
20 | 21 | <association property="tkDeviceTaskCenter" javaType="org.thingsboard.server.common.data.yunteng.dto.task.TkDeviceTaskCenterDTO"> |
21 | - <result property="state" column="state"/> | |
22 | + <result property="allowState" column="allow_state"/> | |
22 | 23 | <result property="taskCenterId" column="task_center_id"/> |
23 | 24 | <result property="tbDeviceId" column="tb_device_id"/> |
24 | 25 | </association> |
... | ... | @@ -28,12 +29,12 @@ |
28 | 29 | |
29 | 30 | <sql id="basicColumns"> |
30 | 31 | tc.id,tc.name,tc.target_type,tc.execute_target,tc.execute_content,tc.execute_time,tc.create_time,tc.creator, |
31 | - tc.updater,tc.update_time,tc.tenant_id | |
32 | + tc.updater,tc.update_time,tc.tenant_id,tc.state | |
32 | 33 | </sql> |
33 | 34 | |
34 | 35 | <sql id="detailColumns"> |
35 | 36 | <include refid="basicColumns"/> |
36 | - ,tdc.state,tdc.task_center_id,tb_device_id | |
37 | + ,tdc.allow_state,tdc.task_center_id,tb_device_id | |
37 | 38 | </sql> |
38 | 39 | <select id="getPageData" resultMap="dataMap"> |
39 | 40 | SELECT | ... | ... |