Showing
6 changed files
with
50 additions
and
19 deletions
... | ... | @@ -7,6 +7,7 @@ import org.springframework.security.access.prepost.PreAuthorize; |
7 | 7 | import org.springframework.validation.annotation.Validated; |
8 | 8 | import org.springframework.web.bind.annotation.*; |
9 | 9 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
10 | +import org.thingsboard.server.common.data.id.EntityId; | |
10 | 11 | import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
11 | 12 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
... | ... | @@ -21,6 +22,7 @@ import org.thingsboard.server.controller.BaseController; |
21 | 22 | import org.thingsboard.server.dao.yunteng.service.OpenApiService; |
22 | 23 | import org.thingsboard.server.queue.util.TbCoreComponent; |
23 | 24 | |
25 | +import java.util.ArrayList; | |
24 | 26 | import java.util.HashMap; |
25 | 27 | import java.util.List; |
26 | 28 | |
... | ... | @@ -42,14 +44,17 @@ public class TkOpenApiController extends BaseController { |
42 | 44 | @RequestParam(value = "name", required = false) String name, |
43 | 45 | @RequestParam(value = "classify", required = false) String classify, |
44 | 46 | @RequestParam(value = ORDER_FILED, required = false) String orderBy, |
45 | - @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) { | |
46 | - | |
47 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
47 | 48 | HashMap<String, Object> queryMap = new HashMap<>(); |
48 | 49 | queryMap.put(PAGE_SIZE, pageSize); |
49 | 50 | queryMap.put(PAGE, page); |
50 | 51 | queryMap.put(ORDER_FILED, orderBy); |
51 | 52 | queryMap.put("name", name); |
52 | 53 | queryMap.put("classify", classify); |
54 | + List<String> tenantIds = new ArrayList<>(); | |
55 | + tenantIds.add(EntityId.NULL_UUID.toString()); | |
56 | + tenantIds.add(getCurrentUser().getTenantId().toString()); | |
57 | + queryMap.put("tenantIds",tenantIds); | |
53 | 58 | if (orderType != null) { |
54 | 59 | queryMap.put(ORDER_TYPE, orderType.name()); |
55 | 60 | } |
... | ... | @@ -69,8 +74,8 @@ public class TkOpenApiController extends BaseController { |
69 | 74 | @DeleteMapping |
70 | 75 | @PreAuthorize("@check.checkPermissions({'TENANT_ADMIN'},{})") |
71 | 76 | public ResponseResult<String> delete( |
72 | - @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) { | |
73 | - return apiService.delete(deleteDTO.getIds()) | |
77 | + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | |
78 | + return apiService.delete(deleteDTO.getIds(), getCurrentUser().getCurrentTenantId()) | |
74 | 79 | ? ResponseResult.success(FastIotConstants.StateValue.DELETE_SUCCESS) |
75 | 80 | : ResponseResult.failed(FastIotConstants.StateValue.DELETE_FAILED); |
76 | 81 | } | ... | ... |
... | ... | @@ -13,6 +13,7 @@ import org.thingsboard.server.dao.yunteng.entities.TkApplicationApiEntity; |
13 | 13 | import org.thingsboard.server.dao.yunteng.entities.TkApplicationEntity; |
14 | 14 | import org.thingsboard.server.dao.yunteng.mapper.ApplicationApiMapper; |
15 | 15 | import org.thingsboard.server.dao.yunteng.mapper.ApplicationMapper; |
16 | +import org.thingsboard.server.dao.yunteng.mapper.OpenApiRecordMapper; | |
16 | 17 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
17 | 18 | import org.thingsboard.server.dao.yunteng.service.ApplicationService; |
18 | 19 | |
... | ... | @@ -30,7 +31,7 @@ public class ApplicationServiceImpl extends AbstractBaseService<ApplicationMappe |
30 | 31 | private static final int KEY_LENGTH = 32; // 32位字符 |
31 | 32 | private static final SecureRandom secureRandom = new SecureRandom(); |
32 | 33 | private static final Base64.Encoder base64Encoder = Base64.getUrlEncoder().withoutPadding(); |
33 | - | |
34 | + private final OpenApiRecordMapper openApiRecordMapper; | |
34 | 35 | |
35 | 36 | @Override |
36 | 37 | public ApplicationDTO getDto(String id) { |
... | ... | @@ -90,6 +91,7 @@ public class ApplicationServiceImpl extends AbstractBaseService<ApplicationMappe |
90 | 91 | @Transactional |
91 | 92 | public boolean delete(Set<String> applicationIds) { |
92 | 93 | applicationApiMapper.deleteByAppIds(applicationIds); |
94 | + openApiRecordMapper.deleteByAppIds(applicationIds); | |
93 | 95 | return baseMapper.deleteBatchIds(applicationIds) > 0; |
94 | 96 | } |
95 | 97 | ... | ... |
... | ... | @@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor; |
7 | 7 | import lombok.extern.slf4j.Slf4j; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.transaction.annotation.Transactional; |
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
10 | 11 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
11 | 12 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiContrlooerDTO; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiDTO; |
... | ... | @@ -42,18 +43,22 @@ public class OpenApiImpl extends AbstractBaseService<OpenApiMapper, TkOpenApiEnt |
42 | 43 | @Override |
43 | 44 | public TkPageData<OpenApiDTO> page(Map<String, Object> queryMap) { |
44 | 45 | IPage<TkOpenApiEntity> iPage = |
45 | - baseMapper.selectPage( | |
46 | - getPage(queryMap, "create_time", false), | |
47 | - new QueryWrapper<TkOpenApiEntity>() | |
48 | - .lambda() | |
49 | - .like( | |
50 | - queryMap.get("name") != null, | |
51 | - TkOpenApiEntity::getName, | |
52 | - String.valueOf(queryMap.get("name"))) | |
53 | - .like( | |
54 | - queryMap.get("classify") != null, | |
55 | - TkOpenApiEntity::getClassify, | |
56 | - String.valueOf(queryMap.get("classify")))); | |
46 | + baseMapper.selectPage( | |
47 | + getPage(queryMap, "create_time", false), | |
48 | + new QueryWrapper<TkOpenApiEntity>() | |
49 | + .lambda() | |
50 | + .like( | |
51 | + queryMap.get("name") != null, | |
52 | + TkOpenApiEntity::getName, | |
53 | + String.valueOf(queryMap.get("name"))) | |
54 | + .like( | |
55 | + queryMap.get("classify") != null, | |
56 | + TkOpenApiEntity::getClassify, | |
57 | + String.valueOf(queryMap.get("classify"))) | |
58 | + .in( | |
59 | + queryMap.get("tenantIds") != null, | |
60 | + TkOpenApiEntity::getTenantId, | |
61 | + (List<String>)queryMap.get("tenantIds"))); | |
57 | 62 | return getPageData(iPage, OpenApiDTO.class); |
58 | 63 | } |
59 | 64 | |
... | ... | @@ -69,7 +74,14 @@ public class OpenApiImpl extends AbstractBaseService<OpenApiMapper, TkOpenApiEnt |
69 | 74 | |
70 | 75 | @Override |
71 | 76 | @Transactional |
72 | - public boolean delete(Set<String> apiIds) { | |
77 | + public boolean delete(Set<String> apiIds ,String tenantId) { | |
78 | + List<TkOpenApiEntity> list = baseMapper.selectList(new LambdaQueryWrapper<TkOpenApiEntity>() | |
79 | + .in(TkOpenApiEntity::getId,apiIds)); | |
80 | + list.stream().forEach(entity ->{ | |
81 | + if(!entity.getTenantId().equals(tenantId)){ | |
82 | + throw new TkDataValidationException("没有权限删除"); | |
83 | + } | |
84 | + }); | |
73 | 85 | return baseMapper.deleteBatchIds(apiIds) > 0; |
74 | 86 | } |
75 | 87 | |
... | ... | @@ -77,6 +89,9 @@ public class OpenApiImpl extends AbstractBaseService<OpenApiMapper, TkOpenApiEnt |
77 | 89 | @Transactional |
78 | 90 | public OpenApiDTO update(OpenApiDTO dto, String tenantId) { |
79 | 91 | TkOpenApiEntity openApi = baseMapper.selectById(dto.getId()); |
92 | + if(!openApi.getTenantId().equals(tenantId)){ | |
93 | + throw new TkDataValidationException("没有权限删除"); | |
94 | + } | |
80 | 95 | dto.copyToEntity(openApi); |
81 | 96 | baseMapper.updateById(openApi); |
82 | 97 | return dto; | ... | ... |
... | ... | @@ -7,6 +7,7 @@ import org.thingsboard.server.common.data.yunteng.dto.OpenApiRecordClassifyDTO; |
7 | 7 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiRecordTopDTO; |
8 | 8 | import org.thingsboard.server.dao.yunteng.entities.TkOpenApiRecordEntity; |
9 | 9 | |
10 | +import java.util.Collection; | |
10 | 11 | import java.util.List; |
11 | 12 | |
12 | 13 | @Mapper |
... | ... | @@ -16,4 +17,6 @@ public interface OpenApiRecordMapper extends BaseMapper<TkOpenApiRecordEntity> { |
16 | 17 | |
17 | 18 | List<OpenApiRecordClassifyDTO> getClassify(@Param("tenantId") String tenantId, |
18 | 19 | @Param("type") String type); |
20 | + | |
21 | + int deleteByAppIds(@Param("applicationIds") Collection<String> applicationId); | |
19 | 22 | } | ... | ... |
... | ... | @@ -18,7 +18,7 @@ public interface OpenApiService extends BaseService<TkOpenApiEntity>{ |
18 | 18 | |
19 | 19 | OpenApiDTO save(OpenApiDTO dto, String tenantId); |
20 | 20 | |
21 | - boolean delete(Set<String> applicationIds); | |
21 | + boolean delete(Set<String> applicationIds, String tenantId); | |
22 | 22 | |
23 | 23 | OpenApiDTO update(OpenApiDTO dto, String tenantId); |
24 | 24 | ... | ... |
... | ... | @@ -64,5 +64,11 @@ |
64 | 64 | time_period |
65 | 65 | </select> |
66 | 66 | |
67 | + <delete id="deleteByAppIds"> | |
68 | + DELETE FROM tk_open_api_record WHERE application_id IN | |
69 | + <foreach collection="applicationIds" item="applicationId" open="(" separator="," close=")"> | |
70 | + #{applicationId} | |
71 | + </foreach> | |
72 | + </delete> | |
67 | 73 | |
68 | 74 | </mapper> | ... | ... |