Commit c848b7d5a8369fab04babe2a44e47ad96b5585a3
1 parent
2ef7cd76
fix: [DEFECT-917] add update script status api
Showing
3 changed files
with
31 additions
and
2 deletions
... | ... | @@ -89,6 +89,17 @@ public class TkDeviceScriptController extends BaseController { |
89 | 89 | return ResponseEntity.ok(scriptService.insertOrUpdate(scriptDTO)); |
90 | 90 | } |
91 | 91 | |
92 | + @PostMapping("/{id}/{status}") | |
93 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{'api:yt:js:post','api:yt:js:update:status'})") | |
94 | + @ApiOperation("修改脚本状态") | |
95 | + public ResponseEntity<Boolean> updateScriptStatus( | |
96 | + @PathVariable("id") String id, @PathVariable("status") Integer status) | |
97 | + throws ThingsboardException { | |
98 | + | |
99 | + return ResponseEntity.ok( | |
100 | + scriptService.updateScriptStatus(getCurrentUser().getCurrentTenantId(), id, status)); | |
101 | + } | |
102 | + | |
92 | 103 | /** |
93 | 104 | * 更新thingsboard的设备配置信息 |
94 | 105 | * |
... | ... | @@ -131,8 +142,7 @@ public class TkDeviceScriptController extends BaseController { |
131 | 142 | |
132 | 143 | @GetMapping("{id}") |
133 | 144 | @ApiOperation("详情") |
134 | - @PreAuthorize( | |
135 | - "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:js:get'})") | |
145 | + @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:js:get'})") | |
136 | 146 | public ResponseEntity<TkDeviceScriptDTO> getDevice(@PathVariable("id") String id) |
137 | 147 | throws ThingsboardException { |
138 | 148 | return ResponseEntity.of( | ... | ... |
... | ... | @@ -80,6 +80,23 @@ public class TkDeviceScriptServiceImpl |
80 | 80 | } |
81 | 81 | |
82 | 82 | @Override |
83 | + @Transactional | |
84 | + public boolean updateScriptStatus(String tenantId, String id, Integer status) { | |
85 | + if (StringUtils.isEmpty(tenantId) || StringUtils.isEmpty(id) || null != status) { | |
86 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
87 | + } | |
88 | + TkDeviceScriptEntity entity = baseMapper.selectById(id); | |
89 | + if (null == entity) { | |
90 | + throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
91 | + } | |
92 | + if (!entity.getTenantId().equals(tenantId)) { | |
93 | + throw new YtDataValidationException(ErrorMessage.NOT_BELONG_CURRENT_TENANT.getMessage()); | |
94 | + } | |
95 | + entity.setStatus(status); | |
96 | + return baseMapper.updateById(entity) > FastIotConstants.MagicNumber.ZERO; | |
97 | + } | |
98 | + | |
99 | + @Override | |
83 | 100 | public String getScriptText(String tenantId, String scriptId) { |
84 | 101 | LambdaQueryWrapper<TkDeviceScriptEntity> queryWrapper = |
85 | 102 | new QueryWrapper<TkDeviceScriptEntity>() | ... | ... |
... | ... | @@ -40,4 +40,6 @@ public interface TkDeviceScriptService extends BaseService<TkDeviceScriptEntity> |
40 | 40 | * @return |
41 | 41 | */ |
42 | 42 | boolean validateFormdata(TkDeviceScriptDTO scriptDTO, boolean created); |
43 | + | |
44 | + boolean updateScriptStatus(String tenantId,String id,Integer status); | |
43 | 45 | } | ... | ... |