Commit 9db0b83f71e40be26bfc37dd83ba6f38caea3da8
1 parent
50a2df75
feat: add data reset to app design and platform design
Showing
6 changed files
with
94 additions
and
44 deletions
... | ... | @@ -8,6 +8,7 @@ import org.springframework.security.access.prepost.PreAuthorize; |
8 | 8 | import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.dto.SysAppDesignDTO; |
11 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | |
11 | 12 | import org.thingsboard.server.controller.BaseController; |
12 | 13 | import org.thingsboard.server.dao.yunteng.service.SysAppDesignService; |
13 | 14 | |
... | ... | @@ -32,7 +33,7 @@ public class YtAppDesignController extends BaseController { |
32 | 33 | |
33 | 34 | @PutMapping("update") |
34 | 35 | @ApiOperation("更新") |
35 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','TENANT_ADMIN'},{'api:yt:appDesign:update:update'})") | |
36 | + @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:appDesign:update:update'})") | |
36 | 37 | public ResponseEntity update(@RequestBody SysAppDesignDTO sysAppDesignDTO) |
37 | 38 | throws ThingsboardException { |
38 | 39 | sysAppDesignDTO.setId(null); |
... | ... | @@ -40,4 +41,14 @@ public class YtAppDesignController extends BaseController { |
40 | 41 | ? ResponseEntity.ok().build() |
41 | 42 | : ResponseEntity.badRequest().build(); |
42 | 43 | } |
44 | + | |
45 | + @PostMapping("data_reset") | |
46 | + @PreAuthorize( | |
47 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:appDesign:data_reset:reset'})") | |
48 | + @ApiOperation("恢复出厂设置") | |
49 | + public ResponseResult<Boolean> dataReset() | |
50 | + throws ThingsboardException { | |
51 | + return ResponseResult.success( | |
52 | + sysAppDesignService.factoryDataReset(getCurrentUser().getCurrentTenantId())); | |
53 | + } | |
43 | 54 | } | ... | ... |
... | ... | @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
10 | 10 | import org.thingsboard.server.common.data.id.EntityId; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.dto.SysPlatformDesignDTO; |
12 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | |
12 | 13 | import org.thingsboard.server.controller.BaseController; |
13 | 14 | import org.thingsboard.server.dao.yunteng.service.SysPlatformDesignService; |
14 | 15 | |
... | ... | @@ -27,7 +28,7 @@ public class YtPlatformDesignController extends BaseController { |
27 | 28 | |
28 | 29 | @GetMapping("get") |
29 | 30 | @ApiOperation("查询详情") |
30 | - public ResponseEntity<SysPlatformDesignDTO> get() { | |
31 | + public ResponseEntity<SysPlatformDesignDTO> get() { | |
31 | 32 | String tenantId = EntityId.NULL_UUID.toString(); |
32 | 33 | try { |
33 | 34 | tenantId = getCurrentUser().getCurrentTenantId(); |
... | ... | @@ -37,7 +38,8 @@ public class YtPlatformDesignController extends BaseController { |
37 | 38 | } |
38 | 39 | |
39 | 40 | @PutMapping("update") |
40 | - @PreAuthorize("@check.checkPermissions({'SYS_ADMIN','TENANT_ADMIN'},{'api:yt:platform:update:update'})") | |
41 | + @PreAuthorize( | |
42 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:platform:update:update'})") | |
41 | 43 | @ApiOperation("更新") |
42 | 44 | public ResponseEntity update(@RequestBody SysPlatformDesignDTO sysPlatformDesignDTO) |
43 | 45 | throws ThingsboardException { |
... | ... | @@ -46,4 +48,14 @@ public class YtPlatformDesignController extends BaseController { |
46 | 48 | ? ResponseEntity.ok().build() |
47 | 49 | : ResponseEntity.badRequest().build(); |
48 | 50 | } |
51 | + | |
52 | + @PostMapping("data_reset") | |
53 | + @PreAuthorize( | |
54 | + "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:platform:data_reset:reset'})") | |
55 | + @ApiOperation("恢复出厂设置") | |
56 | + public ResponseResult<Boolean> dataReset(@RequestBody SysPlatformDesignDTO sysPlatformDesignDTO) | |
57 | + throws ThingsboardException { | |
58 | + return ResponseResult.success( | |
59 | + sysPlatformDesignService.factoryDataReset(getCurrentUser().getCurrentTenantId())); | |
60 | + } | |
49 | 61 | } | ... | ... |
... | ... | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import lombok.RequiredArgsConstructor; |
5 | 5 | import lombok.extern.slf4j.Slf4j; |
6 | 6 | import org.springframework.stereotype.Service; |
7 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
7 | 8 | import org.thingsboard.server.common.data.yunteng.dto.SysAppDesignDTO; |
8 | 9 | import org.thingsboard.server.dao.yunteng.entities.SysAppDesign; |
9 | 10 | import org.thingsboard.server.dao.yunteng.mapper.SysAppDesignMapper; |
... | ... | @@ -21,34 +22,39 @@ import org.thingsboard.server.dao.yunteng.service.SysAppDesignService; |
21 | 22 | public class SysAppDesignServiceImpl extends AbstractBaseService<SysAppDesignMapper, SysAppDesign> |
22 | 23 | implements SysAppDesignService { |
23 | 24 | @Override |
24 | - public boolean save(SysAppDesignDTO sysAppDesignDTO,String tenantId) { | |
25 | + public boolean save(SysAppDesignDTO sysAppDesignDTO, String tenantId) { | |
25 | 26 | if (get(tenantId) != null) { |
26 | 27 | return false; |
27 | 28 | } |
28 | 29 | SysAppDesign entity = sysAppDesignDTO.getEntity(SysAppDesign.class); |
29 | 30 | entity.setTenantId(tenantId); |
30 | - return baseMapper.insert(entity) > 0; | |
31 | + return baseMapper.insert(entity) > FastIotConstants.MagicNumber.ZERO; | |
31 | 32 | } |
32 | 33 | |
33 | 34 | @Override |
34 | 35 | public SysAppDesignDTO get(String tenantId) { |
35 | - SysAppDesign sysAppDesign = baseMapper | |
36 | - .selectOne( | |
37 | - new LambdaQueryWrapper<SysAppDesign>() | |
38 | - .eq(SysAppDesign::getTenantId, tenantId)); | |
36 | + SysAppDesign sysAppDesign = | |
37 | + baseMapper.selectOne( | |
38 | + new LambdaQueryWrapper<SysAppDesign>().eq(SysAppDesign::getTenantId, tenantId)); | |
39 | 39 | return sysAppDesign == null ? null : sysAppDesign.getDTO(SysAppDesignDTO.class); |
40 | 40 | } |
41 | 41 | |
42 | 42 | @Override |
43 | - public boolean update(SysAppDesignDTO sysAppDesignDTO,String tenantId) { | |
43 | + public boolean update(SysAppDesignDTO sysAppDesignDTO, String tenantId) { | |
44 | 44 | if (get(tenantId) != null) { |
45 | 45 | return baseMapper.update( |
46 | 46 | sysAppDesignDTO.getEntity(SysAppDesign.class), |
47 | - new LambdaQueryWrapper<SysAppDesign>() | |
48 | - .eq(SysAppDesign::getTenantId, tenantId)) | |
49 | - > 0; | |
50 | - }else { | |
51 | - return save(sysAppDesignDTO,tenantId); | |
47 | + new LambdaQueryWrapper<SysAppDesign>().eq(SysAppDesign::getTenantId, tenantId)) | |
48 | + > FastIotConstants.MagicNumber.ZERO; | |
49 | + } else { | |
50 | + return save(sysAppDesignDTO, tenantId); | |
52 | 51 | } |
53 | 52 | } |
53 | + | |
54 | + @Override | |
55 | + public boolean factoryDataReset(String tenantId) { | |
56 | + return baseMapper.delete( | |
57 | + new LambdaQueryWrapper<SysAppDesign>().eq(SysAppDesign::getTenantId, tenantId)) | |
58 | + > FastIotConstants.MagicNumber.ZERO; | |
59 | + } | |
54 | 60 | } | ... | ... |
... | ... | @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import lombok.RequiredArgsConstructor; |
5 | 5 | import lombok.extern.slf4j.Slf4j; |
6 | 6 | import org.springframework.stereotype.Service; |
7 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
7 | 8 | import org.thingsboard.server.common.data.yunteng.dto.SysPlatformDesignDTO; |
8 | 9 | import org.thingsboard.server.dao.yunteng.entities.SysPlatformDesign; |
9 | 10 | import org.thingsboard.server.dao.yunteng.mapper.SysPlatformDesignMapper; |
... | ... | @@ -21,32 +22,40 @@ import org.thingsboard.server.dao.yunteng.service.SysPlatformDesignService; |
21 | 22 | public class SysPlatformDesignServiceImpl |
22 | 23 | extends AbstractBaseService<SysPlatformDesignMapper, SysPlatformDesign> |
23 | 24 | implements SysPlatformDesignService { |
24 | - @Override | |
25 | - public boolean save(SysPlatformDesignDTO sysAppDesignDTO,String tenantId) { | |
26 | - SysPlatformDesign entity = sysAppDesignDTO.getEntity(SysPlatformDesign.class); | |
27 | - entity.setTenantId(tenantId); | |
28 | - return baseMapper.insert(entity) > 0; | |
29 | - } | |
25 | + @Override | |
26 | + public boolean save(SysPlatformDesignDTO sysAppDesignDTO, String tenantId) { | |
27 | + SysPlatformDesign entity = sysAppDesignDTO.getEntity(SysPlatformDesign.class); | |
28 | + entity.setTenantId(tenantId); | |
29 | + return baseMapper.insert(entity) > 0; | |
30 | + } | |
30 | 31 | |
31 | - @Override | |
32 | - public SysPlatformDesignDTO get(String tenantId) { | |
33 | - SysPlatformDesign sysPlatformDesign = baseMapper | |
34 | - .selectOne( | |
35 | - new LambdaQueryWrapper<SysPlatformDesign>() | |
36 | - .eq(SysPlatformDesign::getTenantId, tenantId)); | |
37 | - return sysPlatformDesign == null ? null : sysPlatformDesign.getDTO(SysPlatformDesignDTO.class); | |
38 | - } | |
32 | + @Override | |
33 | + public SysPlatformDesignDTO get(String tenantId) { | |
34 | + SysPlatformDesign sysPlatformDesign = | |
35 | + baseMapper.selectOne( | |
36 | + new LambdaQueryWrapper<SysPlatformDesign>() | |
37 | + .eq(SysPlatformDesign::getTenantId, tenantId)); | |
38 | + return sysPlatformDesign == null ? null : sysPlatformDesign.getDTO(SysPlatformDesignDTO.class); | |
39 | + } | |
39 | 40 | |
40 | - @Override | |
41 | - public boolean update(SysPlatformDesignDTO sysAppDesignDTO,String tenantId) { | |
42 | - if (get(tenantId) != null) { | |
43 | - return baseMapper.update( | |
44 | - sysAppDesignDTO.getEntity(SysPlatformDesign.class), | |
45 | - new LambdaQueryWrapper<SysPlatformDesign>() | |
46 | - .eq(SysPlatformDesign::getTenantId, tenantId)) | |
47 | - > 0; | |
48 | - }else { | |
49 | - return save(sysAppDesignDTO,tenantId); | |
50 | - } | |
41 | + @Override | |
42 | + public boolean update(SysPlatformDesignDTO sysAppDesignDTO, String tenantId) { | |
43 | + if (get(tenantId) != null) { | |
44 | + return baseMapper.update( | |
45 | + sysAppDesignDTO.getEntity(SysPlatformDesign.class), | |
46 | + new LambdaQueryWrapper<SysPlatformDesign>() | |
47 | + .eq(SysPlatformDesign::getTenantId, tenantId)) | |
48 | + > 0; | |
49 | + } else { | |
50 | + return save(sysAppDesignDTO, tenantId); | |
51 | 51 | } |
52 | + } | |
53 | + | |
54 | + @Override | |
55 | + public boolean factoryDataReset(String tenantId) { | |
56 | + return baseMapper.delete( | |
57 | + new LambdaQueryWrapper<SysPlatformDesign>() | |
58 | + .eq(SysPlatformDesign::getTenantId, tenantId)) | |
59 | + > FastIotConstants.MagicNumber.ZERO; | |
60 | + } | |
52 | 61 | } | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | |
3 | - | |
4 | 3 | import org.thingsboard.server.common.data.yunteng.dto.SysAppDesignDTO; |
5 | 4 | import org.thingsboard.server.dao.yunteng.entities.SysAppDesign; |
6 | 5 | |
... | ... | @@ -9,10 +8,17 @@ import org.thingsboard.server.dao.yunteng.entities.SysAppDesign; |
9 | 8 | * @desc: |
10 | 9 | * @date: 2021/12/3-18:40 |
11 | 10 | */ |
12 | -public interface SysAppDesignService extends BaseService<SysAppDesign>{ | |
13 | - boolean save(SysAppDesignDTO sysAppDesignDTO,String tenantId); | |
11 | +public interface SysAppDesignService extends BaseService<SysAppDesign> { | |
12 | + boolean save(SysAppDesignDTO sysAppDesignDTO, String tenantId); | |
14 | 13 | |
15 | 14 | SysAppDesignDTO get(String tenantId); |
16 | 15 | |
17 | - boolean update(SysAppDesignDTO sysAppDesignDTO,String tenantId); | |
16 | + boolean update(SysAppDesignDTO sysAppDesignDTO, String tenantId); | |
17 | + | |
18 | + /** | |
19 | + * 恢复出厂设置 | |
20 | + * | |
21 | + * @return true 成功 false 失败 | |
22 | + */ | |
23 | + boolean factoryDataReset(String tenantId); | |
18 | 24 | } | ... | ... |
... | ... | @@ -13,4 +13,10 @@ public interface SysPlatformDesignService extends BaseService<SysPlatformDesign> |
13 | 13 | SysPlatformDesignDTO get(String tenantId); |
14 | 14 | |
15 | 15 | boolean update(SysPlatformDesignDTO sysPlatformDesignDTO,String tenantId); |
16 | + | |
17 | + /** | |
18 | + * 恢复出厂设置 | |
19 | + * @return true 成功 false 失败 | |
20 | + */ | |
21 | + boolean factoryDataReset(String tenantId); | |
16 | 22 | } | ... | ... |