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