Showing
6 changed files
with
27 additions
and
7 deletions
... | ... | @@ -12,10 +12,13 @@ import org.springframework.web.bind.annotation.*; |
12 | 12 | import org.springframework.web.client.RestTemplate; |
13 | 13 | import org.thingsboard.server.common.data.StringUtils; |
14 | 14 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
15 | +import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; | |
16 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
15 | 17 | import org.thingsboard.server.common.data.yunteng.dto.ApplicationDTO; |
16 | 18 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiContrlooerDTO; |
17 | 19 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiDTO; |
18 | 20 | import org.thingsboard.server.common.data.yunteng.dto.UserDTO; |
21 | +import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; | |
19 | 22 | import org.thingsboard.server.controller.BaseController; |
20 | 23 | import org.thingsboard.server.controller.yunteng.TkThirdPlatformController; |
21 | 24 | import org.thingsboard.server.controller.yunteng.TkUserController; |
... | ... | @@ -82,7 +85,8 @@ public class OpenApiController extends BaseController { |
82 | 85 | //记录日志 |
83 | 86 | setRecord(api,appDto,record); |
84 | 87 | if (!appDto.getApiList().contains(api.getId())) { |
85 | - throw new RuntimeException("没有权限"); | |
88 | + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage. | |
89 | + NOT_HAVE_PERMISSION.getI18nCode()))); | |
86 | 90 | } |
87 | 91 | // 构建URL |
88 | 92 | String url = MiscUtils.constructBaseUrl(request) + api.getUri(); | ... | ... |
... | ... | @@ -191,6 +191,8 @@ rule.chain.used.by.device.profile = This rule chain is being used by the [% s] p |
191 | 191 | same.type.node.name.already.exists = Node names of the same type have already been used. |
192 | 192 | choice.device.profile.rule.chain.is.used.for.convert = The selected product [% s] is currently being used by the data flow [% s] and cannot change the rule chain!! |
193 | 193 | choice.device.profile.rule.chain.is.used.for.scene = The selected product [% s] is currently being used by the scene linkage [% s] and cannot change the rule chain!! |
194 | +openapi.app.isnull= The application does not exist | |
195 | +openapi.api.isnull= API does not exist | |
194 | 196 | |
195 | 197 | |
196 | 198 | ... | ... |
... | ... | @@ -190,4 +190,6 @@ scene.react.is.edge = 场景联动来自于边端请勿操作 |
190 | 190 | rule.chain.used.by.device.profile = 该规则链正在被【%s】产品使用,不能被删除!! |
191 | 191 | same.type.node.name.already.exists = 同类型的节点名称已被使用 |
192 | 192 | choice.device.profile.rule.chain.is.used.for.convert = 选中的产品【%s】正在被数据流转【%s】使用,不能更换规则链!! |
193 | -choice.device.profile.rule.chain.is.used.for.scene = 选中的产品【%s】正在被场景联动【%s】使用,不能更换规则链!! | |
\ No newline at end of file | ||
193 | +choice.device.profile.rule.chain.is.used.for.scene = 选中的产品【%s】正在被场景联动【%s】使用,不能更换规则链!! | |
194 | +openapi.app.isnull= 应用不存在 | |
195 | +openapi.api.isnull= api不存在 | |
\ No newline at end of file | ... | ... |
... | ... | @@ -194,6 +194,8 @@ public enum ErrorMessage { |
194 | 194 | SAME_TYPE_NODE_NAME_ALREADY_EXISTS(400159,"同类型的节点名称已被使用","same.type.node.name.already.exists"), |
195 | 195 | CHOICE_DEVICE_PROFILE_RULE_CHAIN_IS_USED_FOR_CONVERT(400160,"选中的产品【%s】正在被数据流转【%s】使用,不能更换规则链!!","choice.device.profile.rule.chain.is.used.for.convert"), |
196 | 196 | CHOICE_DEVICE_PROFILE_RULE_CHAIN_IS_USED_FOR_SCENE(400161,"选中的产品【%s】正在被场景联动【%s】使用,不能更换规则链!!","choice.device.profile.rule.chain.is.used.for.scene"), |
197 | + OPENAPI_APP_ISNULL(400162,"应用不存在","openapi.app.isnull"), | |
198 | + OPENAPI_API_ISNULL(400163,"api不存在","openapi.api.isnull"), | |
197 | 199 | |
198 | 200 | HAVE_NO_PERMISSION(500002, "没有修改权限", "have.no.permission"), |
199 | 201 | NOT_ALLOWED_ISOLATED_IN_MONOLITH(500003, "【monolith】模式下,不能选择【isolated】类型的租户配置", "not.allowed.isolated.in.monolith"), | ... | ... |
... | ... | @@ -7,7 +7,10 @@ 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; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
10 | 12 | import org.thingsboard.server.common.data.yunteng.dto.ApplicationDTO; |
13 | +import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; | |
11 | 14 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
12 | 15 | import org.thingsboard.server.dao.yunteng.entities.TkApplicationApiEntity; |
13 | 16 | import org.thingsboard.server.dao.yunteng.entities.TkApplicationEntity; |
... | ... | @@ -118,7 +121,8 @@ public class ApplicationServiceImpl extends AbstractBaseService<ApplicationMappe |
118 | 121 | .eq(TkApplicationEntity::getKey, key) |
119 | 122 | .eq(TkApplicationEntity::getSecret,secret)); |
120 | 123 | if(null == entity){ |
121 | - throw new RuntimeException("应用不存在"); | |
124 | + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage. | |
125 | + OPENAPI_APP_ISNULL.getI18nCode()))); | |
122 | 126 | } |
123 | 127 | ApplicationDTO dto = new ApplicationDTO(); |
124 | 128 | entity.copyToDTO(dto); |
... | ... | @@ -131,7 +135,8 @@ public class ApplicationServiceImpl extends AbstractBaseService<ApplicationMappe |
131 | 135 | new LambdaQueryWrapper<TkApplicationEntity>() |
132 | 136 | .eq(TkApplicationEntity::getUserId, userId)); |
133 | 137 | if(null == entity){ |
134 | - throw new RuntimeException("应用不存在"); | |
138 | + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage. | |
139 | + OPENAPI_APP_ISNULL.getI18nCode()))); | |
135 | 140 | } |
136 | 141 | ApplicationDTO dto = new ApplicationDTO(); |
137 | 142 | entity.copyToDTO(dto); | ... | ... |
... | ... | @@ -8,11 +8,13 @@ import lombok.extern.slf4j.Slf4j; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | 9 | import org.springframework.transaction.annotation.Transactional; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
11 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
11 | 12 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiContrlooerDTO; |
13 | 14 | import org.thingsboard.server.common.data.yunteng.dto.OpenApiDTO; |
14 | 15 | import org.thingsboard.server.common.data.yunteng.dto.ApiMenuDTO; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.utils.CopyUtils; |
17 | +import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils; | |
16 | 18 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
17 | 19 | import org.thingsboard.server.dao.yunteng.entities.TkOpenApiEntity; |
18 | 20 | import org.thingsboard.server.dao.yunteng.mapper.OpenApiMapper; |
... | ... | @@ -33,7 +35,8 @@ public class OpenApiImpl extends AbstractBaseService<OpenApiMapper, TkOpenApiEnt |
33 | 35 | public OpenApiDTO getDto(String id) { |
34 | 36 | TkOpenApiEntity entity = baseMapper.selectById(id); |
35 | 37 | if(null == entity){ |
36 | - throw new RuntimeException("Api不存在"); | |
38 | + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage. | |
39 | + OPENAPI_API_ISNULL.getI18nCode()))); | |
37 | 40 | } |
38 | 41 | OpenApiDTO dto = new OpenApiDTO(); |
39 | 42 | entity.copyToDTO(dto); |
... | ... | @@ -79,7 +82,8 @@ public class OpenApiImpl extends AbstractBaseService<OpenApiMapper, TkOpenApiEnt |
79 | 82 | .in(TkOpenApiEntity::getId,apiIds)); |
80 | 83 | list.stream().forEach(entity ->{ |
81 | 84 | if(!entity.getTenantId().equals(tenantId)){ |
82 | - throw new TkDataValidationException("没有权限删除"); | |
85 | + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage. | |
86 | + NOT_HAVE_PERMISSION.getI18nCode()))); | |
83 | 87 | } |
84 | 88 | }); |
85 | 89 | return baseMapper.deleteBatchIds(apiIds) > 0; |
... | ... | @@ -90,7 +94,8 @@ public class OpenApiImpl extends AbstractBaseService<OpenApiMapper, TkOpenApiEnt |
90 | 94 | public OpenApiDTO update(OpenApiDTO dto, String tenantId) { |
91 | 95 | TkOpenApiEntity openApi = baseMapper.selectById(dto.getId()); |
92 | 96 | if(!openApi.getTenantId().equals(tenantId)){ |
93 | - throw new TkDataValidationException("没有权限删除"); | |
97 | + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage. | |
98 | + NOT_HAVE_PERMISSION.getI18nCode()))); | |
94 | 99 | } |
95 | 100 | dto.copyToEntity(openApi); |
96 | 101 | baseMapper.updateById(openApi); | ... | ... |