Commit ec8d1bd3d152b407d6793b6e1284f173cd69c157

Authored by xp.Huang
2 parents f4460d3b df57da34

Merge branch 'master' into 'master_dev'

Merge branch 'master' into 'master_dev'

See merge request yunteng/thingskit!240
... ... @@ -177,3 +177,4 @@ ThingsKit像楊銝挽憭皞PaaS
177 177
178 178
179 179
  180 +版本:v1.1.2_release
... ...
... ... @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.*;
20 20 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
21 21 import org.thingsboard.server.common.data.yunteng.dto.SysLogOperateDTO;
22 22 import org.thingsboard.server.dao.audit.AuditLogService;
  23 +import org.thingsboard.server.dao.exception.DataValidationException;
23 24 import org.thingsboard.server.exception.ThingsboardErrorResponseHandler;
24 25 import org.thingsboard.server.service.security.model.SecurityUser;
25 26 import org.thingsboard.server.utils.yunteng.LogUtils;
... ... @@ -36,22 +37,27 @@ public class ThingsKitExceptionHandler {
36 37 private final AuditLogService auditLogService;
37 38 private final ThingsboardErrorResponseHandler errorResponseHandler;
38 39
39   - @ExceptionHandler(RuntimeException.class)
  40 + @ExceptionHandler(MethodArgumentNotValidException.class)
40 41 public void handleMethodArgumentNotValidException(
41   - RuntimeException ex,
42   - HttpServletRequest request,
43   - HttpServletResponse response) {
44   - if(ex instanceof ThingsKitException){
45   - errorResponseHandler.handle(
46   - new ThingsKitException(
47   - ErrorMessage.INVALID_PARAMETER.setMessage(
48   - ex.getMessage()),
49   - HttpStatus.BAD_REQUEST),
50   - response);
51   - }else{
  42 + MethodArgumentNotValidException ex,
  43 + HttpServletRequest request,
  44 + HttpServletResponse response) {
  45 + produceLog(request, ex);
  46 + errorResponseHandler.handle(
  47 + new ThingsKitException(
  48 + ErrorMessage.VALIDATE_PARAM_FAILED.setMessage(
  49 + Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()),
  50 + HttpStatus.BAD_REQUEST),
  51 + response);
  52 + }
  53 +
  54 + @ExceptionHandler(RuntimeException.class)
  55 + public void handleRuntimeException(
  56 + RuntimeException ex, HttpServletRequest request, HttpServletResponse response) {
  57 + if(!(ex instanceof ThingsKitException) && !(ex instanceof DataValidationException)){
52 58 produceLog(request, ex);
53   - errorResponseHandler.handle(ex,response);
54 59 }
  60 + errorResponseHandler.handle(ex,response);
55 61 }
56 62
57 63 protected SecurityUser getCurrentUser() throws ThingsboardException {
... ...
... ... @@ -6,7 +6,6 @@ import lombok.RequiredArgsConstructor;
6 6 import org.apache.commons.lang3.StringUtils;
7 7 import org.springframework.http.ResponseEntity;
8 8 import org.springframework.security.access.prepost.PreAuthorize;
9   -import org.springframework.transaction.annotation.Transactional;
10 9 import org.springframework.util.Assert;
11 10 import org.springframework.validation.annotation.Validated;
12 11 import org.springframework.web.bind.annotation.*;
... ... @@ -22,7 +21,6 @@ import org.thingsboard.server.common.data.id.UserId;
22 21 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
23 22 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
24 23 import org.thingsboard.server.common.data.yunteng.common.UpdateGroup;
25   -import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
26 24 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
27 25 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
28 26 import org.thingsboard.server.common.data.yunteng.dto.MenuDTO;
... ... @@ -162,7 +160,6 @@ public class TkAdminController extends BaseController {
162 160 }
163 161
164 162 @PostMapping("/tenant/adminUser")
165   - @Transactional
166 163 @PreAuthorize(
167 164 "@check.checkPermissions({'SYS_ADMIN','PLATFORM_ADMIN'},{'api:yt:admin:tenant:adminUser:post'})")
168 165 public ResponseEntity<UserDTO> createTenantAdmin(
... ...
... ... @@ -11,7 +11,6 @@ import org.springframework.validation.annotation.Validated;
11 11 import org.springframework.web.bind.annotation.*;
12 12 import org.thingsboard.server.common.data.*;
13 13 import org.thingsboard.server.common.data.audit.ActionType;
14   -import org.thingsboard.server.common.data.device.profile.*;
15 14 import org.thingsboard.server.common.data.edge.EdgeEventActionType;
16 15 import org.thingsboard.server.common.data.exception.ThingsboardException;
17 16 import org.thingsboard.server.common.data.id.DeviceProfileId;
... ... @@ -20,7 +19,6 @@ import org.thingsboard.server.common.data.id.TenantId;
20 19 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
21 20 import org.thingsboard.server.common.data.rule.RuleChain;
22 21 import org.thingsboard.server.common.data.yunteng.common.DeleteGroup;
23   -import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
24 22 import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException;
25 23 import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage;
26 24 import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO;
... ...
... ... @@ -38,7 +38,6 @@ import org.thingsboard.server.common.data.yunteng.enums.TkScriptFunctionType;
38 38 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
39 39 import org.thingsboard.server.common.msg.queue.ServiceQueue;
40 40 import org.thingsboard.server.controller.BaseController;
41   -import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService;
42 41 import org.thingsboard.server.dao.yunteng.service.TkDeviceScriptService;
43 42 import org.thingsboard.server.transport.tcp.script.TkScriptInvokeService;
44 43
... ... @@ -60,7 +59,6 @@ public class TkDeviceScriptController extends BaseController {
60 59 private static final JsonParser parser = new JsonParser();
61 60 private static final ObjectMapper objectMapper = new ObjectMapper();
62 61 private final TkDeviceScriptService scriptService;
63   - private final TkDeviceProfileService ytDeviceProfileService;
64 62 private final TkScriptInvokeService jsEngine;
65 63
66 64 @PostMapping()
... ... @@ -218,10 +216,18 @@ public class TkDeviceScriptController extends BaseController {
218 216 throw new TkDataValidationException(String.format(ErrorMessage.NEED_MAIN_PARAMETER.getMessage(),"设备地址码"));
219 217 }
220 218 if(StringUtils.isEmpty(inputParams.getMethod()) || null == inputParams.getCrc() ||
221   - null ==inputParams.getRegisterNumber() || null ==inputParams.getRegisterAddress() ||
222   - null ==inputParams.getRegisterValues() || inputParams.getRegisterValues().isEmpty()){
  219 + null ==inputParams.getRegisterAddress()){
223 220 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
224 221 }
  222 + if(null !=inputParams.getRegisterNumber() && null !=inputParams.getRegisterValues() &&
  223 + !inputParams.getRegisterValues().isEmpty()){
  224 + List<Integer> registerValues = inputParams.getRegisterValues();
  225 + for (Integer value : registerValues){
  226 + if(null == value){
  227 + throw new TkDataValidationException(ErrorMessage.REGISTER_VALUE_IS_NONE.getMessage());
  228 + }
  229 + }
  230 + }
225 231 return ResponseEntity.ok(scriptService.modbus(inputParams));
226 232 }
227 233
... ...
... ... @@ -7,6 +7,7 @@ public enum ErrorMessage {
7 7 // ERROR STARTS FROM HERE
8 8 INTERNAL_ERROR(500000, "网络异常"),
9 9 OPERATION_FAILED(500001, "操作失败"),
  10 + VALIDATE_PARAM_FAILED(440000, "参数验证失败"),
10 11 NO_PERMISSION(403001, "没有操作权限"),
11 12 ACCOUNT_DISABLED(403002, "账号已禁用"),
12 13 ACCESS_DENIED(403003, "拒绝访问"),
... ... @@ -109,7 +110,8 @@ public enum ErrorMessage {
109 110 RESET_PASSWORD_SUCCESS(400085,"重置成功,请使用默认密码登录"),
110 111 HAVE_NO_PERMISSION(500002,"没有修改权限"),
111 112 MESSAGE_TEMPLATE_DELETED(400020,"消息模板不存在!"),
112   - NEED_MAIN_PARAMETER(400001, "缺少必要参数【%s】"),
  113 + NEED_MAIN_PARAMETER(400021, "缺少必要参数【%s】"),
  114 + REGISTER_VALUE_IS_NONE(400022, "寄存器值不能为空"),
113 115 NOT_ALLOED_ISOLATED_IN_MONOLITH(500003,"【monolith】模式下,不能选择【isolated】类型的租户配置"),
114 116 MESSAGE_TEMPLATE_USING_CONFIG(500004,"删除消息配置前,需要禁用使用消息配置的消息模板%s。");
115 117 private final int code;
... ...
... ... @@ -23,9 +23,9 @@ public class TkDeviceRpcDTO implements Serializable {
23 23 @ApiModelProperty(value = "寄存器地址", required = true)
24 24 private Integer registerAddress;
25 25
26   - @ApiModelProperty(value = "寄存器数量", required = true)
  26 + @ApiModelProperty(value = "寄存器数量")
27 27 private Integer registerNumber;
28 28
29   - @ApiModelProperty(value = "寄存器值", required = true)
  29 + @ApiModelProperty(value = "寄存器值")
30 30 private List<Integer> registerValues;
31 31 }
... ...