Commit 2dfe716f7269c7635743034a6fc0656986396366

Authored by xp.Huang
2 parents fedbeba1 84c7ffcf

Merge branch '20230914' into 'master_dev'

fix(DEFECT-1523): 非业务异常日志问题修复

See merge request yunteng/thingskit!232
@@ -36,18 +36,22 @@ public class ThingsKitExceptionHandler { @@ -36,18 +36,22 @@ public class ThingsKitExceptionHandler {
36 private final AuditLogService auditLogService; 36 private final AuditLogService auditLogService;
37 private final ThingsboardErrorResponseHandler errorResponseHandler; 37 private final ThingsboardErrorResponseHandler errorResponseHandler;
38 38
39 - @ExceptionHandler(MethodArgumentNotValidException.class) 39 + @ExceptionHandler(RuntimeException.class)
40 public void handleMethodArgumentNotValidException( 40 public void handleMethodArgumentNotValidException(
41 - MethodArgumentNotValidException ex, 41 + RuntimeException ex,
42 HttpServletRequest request, 42 HttpServletRequest request,
43 HttpServletResponse response) { 43 HttpServletResponse response) {
44 - produceLog(request, ex);  
45 - errorResponseHandler.handle(  
46 - new ThingsKitException(  
47 - ErrorMessage.INVALID_PARAMETER.setMessage(  
48 - Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()),  
49 - HttpStatus.BAD_REQUEST),  
50 - 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{
  52 + produceLog(request, ex);
  53 + errorResponseHandler.handle(ex,response);
  54 + }
51 } 55 }
52 56
53 protected SecurityUser getCurrentUser() throws ThingsboardException { 57 protected SecurityUser getCurrentUser() throws ThingsboardException {
@@ -94,7 +94,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -94,7 +94,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
94 } 94 }
95 95
96 @Override 96 @Override
97 - public void validateFormData(String currentTenantId, DeviceDTO deviceDTO) { 97 + public void validateFormData(String currentTenantId, DeviceDTO deviceDTO) throws RuntimeException{
98 boolean insert = StringUtils.isBlank(deviceDTO.getId()); 98 boolean insert = StringUtils.isBlank(deviceDTO.getId());
99 String deviceTenantId; 99 String deviceTenantId;
100 if (StringUtils.isBlank(deviceDTO.getName())) { 100 if (StringUtils.isBlank(deviceDTO.getName())) {
@@ -132,7 +132,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev @@ -132,7 +132,7 @@ public class TkDeviceServiceImpl extends AbstractBaseService<DeviceMapper, TkDev
132 DeviceProfile deviceProfile = 132 DeviceProfile deviceProfile =
133 deviceProfileDao.findById(id, UUID.fromString(deviceDTO.getProfileId())); 133 deviceProfileDao.findById(id, UUID.fromString(deviceDTO.getProfileId()));
134 OrganizationDTO organization = 134 OrganizationDTO organization =
135 - organizationService.findOrganizationById(deviceTenantId,deviceDTO.getOrganizationId()); 135 + organizationService.findOrganizationById(deviceDTO.getOrganizationId(),deviceTenantId);
136 if (null == deviceProfile || null == organization) { 136 if (null == deviceProfile || null == organization) {
137 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); 137 throw new TkDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage());
138 } else if (!organization.getTenantId().equals(deviceTenantId)) { 138 } else if (!organization.getTenantId().equals(deviceTenantId)) {
@@ -44,9 +44,6 @@ @@ -44,9 +44,6 @@
44 LEFT JOIN tk_organization org ON org.id = d.organization_id 44 LEFT JOIN tk_organization org ON org.id = d.organization_id
45 <where> 45 <where>
46 m.tenant_id = #{tenantId} 46 m.tenant_id = #{tenantId}
47 - <if test="customerId!=null">  
48 - AND m.customer_id = #{customerId}  
49 - </if>  
50 <if test="severity!=null"> 47 <if test="severity!=null">
51 AND severity = #{severity} 48 AND severity = #{severity}
52 </if> 49 </if>
@@ -62,6 +62,7 @@ class ReactState { @@ -62,6 +62,7 @@ class ReactState {
62 private final TkNoticeService noticeService; 62 private final TkNoticeService noticeService;
63 private TkDeviceService ytDeviceService; 63 private TkDeviceService ytDeviceService;
64 64
  65 + private String actionData;
65 ReactState(String reactId, TbContext ctx, TbSceneReactNodeConfig config) { 66 ReactState(String reactId, TbContext ctx, TbSceneReactNodeConfig config) {
66 this.reactId = reactId; 67 this.reactId = reactId;
67 this.reactName = config.getNames().get(reactId); 68 this.reactName = config.getNames().get(reactId);
@@ -82,6 +83,7 @@ class ReactState { @@ -82,6 +83,7 @@ class ReactState {
82 } 83 }
83 this.noticeService = SpringBeanUtils.getBean(TkNoticeService.class); 84 this.noticeService = SpringBeanUtils.getBean(TkNoticeService.class);
84 this.ytDeviceService = SpringBeanUtils.getBean(TkDeviceService.class); 85 this.ytDeviceService = SpringBeanUtils.getBean(TkDeviceService.class);
  86 + actionData ="";
85 } 87 }
86 88
87 /** 89 /**
@@ -219,8 +221,10 @@ class ReactState { @@ -219,8 +221,10 @@ class ReactState {
219 })); 221 }));
220 }); 222 });
221 223
222 - if (triggerMatched.get() && conditionMatched.get()) {  
223 - log.debug(String.format("设备【%s】的消息内容【%s】触发动作", deviceId, msg.getData())); 224 + String msgData = msg.getData();
  225 + if (triggerMatched.get() && conditionMatched.get() && !actionData.equals(msgData)) {
  226 + actionData = msgData;
  227 + log.debug(String.format("设备【%s】的消息内容【%s】触发动作", deviceId, msgData));
224 for (TkDoActionEntity item : actions) { 228 for (TkDoActionEntity item : actions) {
225 if (ActionTypeEnum.MSG_NOTIFY.equals(item.getOutTarget())) { 229 if (ActionTypeEnum.MSG_NOTIFY.equals(item.getOutTarget())) {
226 noticeMsg(ctx, msg, item, deviceId, detail, msg.getTs()); 230 noticeMsg(ctx, msg, item, deviceId, detail, msg.getTs());