Commit 4e48e81093d5fde05a4f042509a54dec886273fb
Merge branch '20220923' into 'master'
fix(DEFECT-762): 调整邮件推送频率 See merge request huang/thingsboard3.3.2!137
Showing
5 changed files
with
24 additions
and
5 deletions
application/src/main/java/org/thingsboard/server/controller/yunteng/YtMessageTemplateController.java
... | ... | @@ -10,6 +10,8 @@ import org.thingsboard.server.common.data.yunteng.common.AddGroup; |
10 | 10 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
13 | 15 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
14 | 16 | import org.thingsboard.server.common.data.yunteng.dto.MessageTemplateDTO; |
15 | 17 | import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; |
... | ... | @@ -92,15 +94,19 @@ public class YtMessageTemplateController extends BaseController { |
92 | 94 | public ResponseResult<String> sendSms( |
93 | 95 | @Validated({AddGroup.class}) @RequestBody SmsReqDTO smsReqDTO) { |
94 | 96 | boolean result = smsService.sendSms(smsReqDTO); |
95 | - String message = result ? ResponseCodeEnum.SUCCESS.name() : ResponseCodeEnum.FAILED.name(); | |
96 | - return ResponseResult.success(message); | |
97 | + if(!result){ | |
98 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_SEND_FAILED.getMessage()); | |
99 | + } | |
100 | + return ResponseResult.success(ResponseCodeEnum.SUCCESS.name() ); | |
97 | 101 | } |
98 | 102 | |
99 | 103 | @PostMapping("/send_email") |
100 | 104 | public ResponseResult<String> sendEmail( |
101 | 105 | @Validated({AddGroup.class}) @RequestBody EmailReqDTO emailReqDTO) { |
102 | 106 | boolean result = mailService.sendEmail(emailReqDTO); |
103 | - String message = result ? ResponseCodeEnum.SUCCESS.name() : ResponseCodeEnum.FAILED.name(); | |
104 | - return ResponseResult.success(message); | |
107 | + if(!result){ | |
108 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_SEND_FAILED.getMessage()); | |
109 | + } | |
110 | + return ResponseResult.success(ResponseCodeEnum.SUCCESS.name() ); | |
105 | 111 | } |
106 | 112 | } | ... | ... |
... | ... | @@ -340,6 +340,9 @@ public class RestAuthenticationProvider implements AuthenticationProvider { |
340 | 340 | User user = new User(); |
341 | 341 | String tbEmail = optionalUser.get().getUsername() + "@" + accountProperties.getEmailSuffix(); |
342 | 342 | UserDetailsDTO ytDetailDTO = optionalUser.get(); |
343 | + if(ytDetailDTO.getAccountExpireTime() != null && ytDetailDTO.getAccountExpireTime().isBefore(LocalDateTime.now())){ | |
344 | + throw new AccountExpiredException(ErrorMessage.ACCOUNT_HAS_EXPIRED.getMessage()); | |
345 | + } | |
343 | 346 | //如果是平台管理员 |
344 | 347 | if(isPlatFormUser(ytDetailDTO)){ |
345 | 348 | user.setAuthority(Authority.PLATFORM_USER); | ... | ... |
... | ... | @@ -17,7 +17,6 @@ public enum ErrorMessage { |
17 | 17 | USERNAME_PASSWORD_INCORRECT(401001, "用户名或密码错误"), |
18 | 18 | TOKEN_EXPIRED(401002, "token已过期,请重新登录"), |
19 | 19 | NONE_TENANT_ASSET(401003, "非当前租户资产"), |
20 | - AUTHENTICATION_FAILED_ACCOUNT_EXPIRED(401003, "账号已过期,请联系你的管理员"), | |
21 | 20 | BAD_PARAMETER(400000, "查询参数无效"), |
22 | 21 | INVALID_PARAMETER(400001, "无效参数"), |
23 | 22 | TOO_MANY_REQUEST(429001, "请求过多"), |
... | ... | @@ -81,6 +80,7 @@ public enum ErrorMessage { |
81 | 80 | DATA_BOARD_IS_PRIVATE(400057,"该数据看板不是公有视图"), |
82 | 81 | MESSAGE_SEND_TOO_FAST(400058,"1分钟内请求次数过多,请休息一下!"), |
83 | 82 | PASSWORD_INCORRECT(4010059, "密码错误!"), |
83 | + MESSAGE_SEND_FAILED(4010059, "消息发送失败!"), | |
84 | 84 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
85 | 85 | private final int code; |
86 | 86 | private String message; | ... | ... |
... | ... | @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; |
8 | 8 | import lombok.extern.slf4j.Slf4j; |
9 | 9 | import org.apache.commons.lang3.RandomStringUtils; |
10 | 10 | import org.apache.commons.lang3.StringUtils; |
11 | +import org.springframework.security.authentication.BadCredentialsException; | |
11 | 12 | import org.springframework.stereotype.Service; |
12 | 13 | import org.springframework.transaction.annotation.Transactional; |
13 | 14 | import org.thingsboard.common.util.JacksonUtil; |
... | ... | @@ -133,6 +134,9 @@ public class YtSmsServiceImpl implements YtSmsService { |
133 | 134 | if (users.isEmpty()) { |
134 | 135 | throw new YtDataValidationException("电话号码未在系统注册,请联系你的管理员"); |
135 | 136 | } |
137 | + if(users.get(0).getAccountExpireTime() != null && users.get(0).getAccountExpireTime().isBefore(LocalDateTime.now())){ | |
138 | + throw new YtDataValidationException(ErrorMessage.ACCOUNT_HAS_EXPIRED.getMessage()); | |
139 | + } | |
136 | 140 | // 获取是否有验证码存在,防止发送数量过多 |
137 | 141 | String key = |
138 | 142 | purpose.name() | ... | ... |
... | ... | @@ -327,6 +327,12 @@ class ReactState { |
327 | 327 | currentAlarm.setPropagate(false); |
328 | 328 | |
329 | 329 | currentAlarm = ctx.getAlarmService().createOrUpdateAlarm(currentAlarm); |
330 | + Alarm oldAlarm = currentAlarms.get(deviceId); | |
331 | + if(oldAlarm != null | |
332 | + && currentAlarm.getId().equals(oldAlarm.getId()) | |
333 | + && currentAlarm.getSeverity().equals(oldAlarm.getSeverity())){ | |
334 | + return; | |
335 | + } | |
330 | 336 | ytDeviceService.freshAlarmStatus(entityId, 1); |
331 | 337 | currentAlarms.put(deviceId, currentAlarm); |
332 | 338 | alarmMsg(ctx, msg, currentAlarm, "Alarm Cleared"); | ... | ... |