Commit 3231a48a31e1128d83ffe5bc2b26aa4e18dfe33e
Merge branch '20220922' into 'master'
20220922 See merge request huang/thingsboard3.3.2!135
Showing
7 changed files
with
132 additions
and
62 deletions
... | ... | @@ -2,14 +2,12 @@ package org.thingsboard.server.controller.yunteng; |
2 | 2 | |
3 | 3 | import io.swagger.annotations.Api; |
4 | 4 | import io.swagger.annotations.ApiOperation; |
5 | +import io.swagger.annotations.ApiParam; | |
5 | 6 | import lombok.RequiredArgsConstructor; |
6 | 7 | import org.springframework.http.HttpStatus; |
7 | 8 | import org.springframework.http.ResponseEntity; |
8 | 9 | import org.springframework.security.access.prepost.PreAuthorize; |
9 | -import org.springframework.web.bind.annotation.GetMapping; | |
10 | -import org.springframework.web.bind.annotation.RequestMapping; | |
11 | -import org.springframework.web.bind.annotation.RequestParam; | |
12 | -import org.springframework.web.bind.annotation.RestController; | |
10 | +import org.springframework.web.bind.annotation.*; | |
13 | 11 | import org.springframework.web.context.request.async.DeferredResult; |
14 | 12 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
15 | 13 | import org.thingsboard.server.common.data.query.TsValue; |
... | ... | @@ -18,6 +16,7 @@ import org.thingsboard.server.common.data.yunteng.dto.HomePageLeftTopDTO; |
18 | 16 | import org.thingsboard.server.common.data.yunteng.dto.TenantDTO; |
19 | 17 | import org.thingsboard.server.common.data.yunteng.dto.TenantTransportMessageDTO; |
20 | 18 | import org.thingsboard.server.common.data.yunteng.dto.statistics.HomePageAppDTO; |
19 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
21 | 20 | import org.thingsboard.server.common.data.yunteng.enums.TrendType; |
22 | 21 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
23 | 22 | import org.thingsboard.server.controller.BaseController; |
... | ... | @@ -103,13 +102,13 @@ public class HomePageController extends BaseController { |
103 | 102 | |
104 | 103 | @GetMapping("app") |
105 | 104 | @ApiOperation(value = "小程序首页统计信息") |
106 | - public ResponseEntity<HomePageAppDTO> appStatistics() | |
105 | + public ResponseEntity<HomePageAppDTO> appStatistics(@ApiParam(value = "只取告警数据") @RequestParam("login") Boolean login) | |
107 | 106 | throws ThingsboardException, ExecutionException, InterruptedException { |
108 | 107 | SecurityUser user = getCurrentUser(); |
109 | 108 | if(user == null){ |
110 | 109 | return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); |
111 | 110 | } |
112 | - HomePageAppDTO app = homePageService.app(user.isPtSysadmin(),user.isPtAdmin(),user.isPtTenantAdmin(),user.getTenantId(),user.getCustomerId()); | |
111 | + HomePageAppDTO app = homePageService.app(login,user.isPtSysadmin(),user.isPtAdmin(),user.isPtTenantAdmin(),user.getTenantId(),user.getCustomerId()); | |
113 | 112 | return ResponseEntity.ok(app); |
114 | 113 | } |
115 | 114 | } | ... | ... |
... | ... | @@ -37,9 +37,9 @@ public enum ErrorMessage { |
37 | 37 | USER_NOT_EXISTS(400015,"用户不存在"), |
38 | 38 | ENABLED_CONFIG_IS_EXISTED(400016,"已启用同类型配置"), |
39 | 39 | USERNAME_IS_IMMUTABLE(400017,"用户账号不可变"), |
40 | - CONFIG_IS_DISABLE(400018,"配置未启用"), | |
40 | + MESSAGE_CONFIG_NOT_EXISTS(400018,"消息配置不存在或未启用"), | |
41 | 41 | IT_CANT_EQUAL_ITSELF(400019,"父级组织不可以为本身"), |
42 | - TARGET_TEMPLATE_NOT_EXISTS(400020,"不存在可用的消息模板"), | |
42 | + MESSAGE_TEMPLATE_NOT_EXISTS(400020,"消息模板不存在或未启用!"), | |
43 | 43 | DEVICE_NOT_EXISTENCE_IN_TENANT(400021,"当前租户下不存在该设备"), |
44 | 44 | DEVICE_RELATION_IS_ABSENT(400022,"设备关联关系已不存在"), |
45 | 45 | DATA_IS_DELETED(400023,"数据已经删除"), | ... | ... |
... | ... | @@ -115,7 +115,7 @@ public class HomePageServiceImpl implements HomePageService { |
115 | 115 | } |
116 | 116 | |
117 | 117 | @Override |
118 | - public HomePageAppDTO app(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId) { | |
118 | + public HomePageAppDTO app(Boolean login,boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId) { | |
119 | 119 | /** |
120 | 120 | * 如果当前用户是超级管理员或平台管理员,查询所有的租户数量、客户、设备 |
121 | 121 | * 如果当前用户是租户管理员,查询租户下的所有 客户、设备、告警、消息量 |
... | ... | @@ -135,6 +135,15 @@ public class HomePageServiceImpl implements HomePageService { |
135 | 135 | Map<String, Object> todayFilter = buildCountFilter(entityId,startTime,endTime); |
136 | 136 | |
137 | 137 | HomePageAppDTO app = new HomePageAppDTO(); |
138 | + | |
139 | + if (!isPtSysAdmin && !isPtAdmin ) { | |
140 | + app.setTotalAlarm(getAlarmInfo(totalFilter)); | |
141 | + app.setTodayAlarm(getAlarmInfo(todayFilter)); | |
142 | + } | |
143 | + if(login){ | |
144 | + return app; | |
145 | + } | |
146 | + | |
138 | 147 | if (isPtSysAdmin || isPtAdmin) { |
139 | 148 | List<TenantDTO> tenants = getTenantInfo(); |
140 | 149 | AtomicInteger totalExpired = new AtomicInteger(); |
... | ... | @@ -192,10 +201,7 @@ public class HomePageServiceImpl implements HomePageService { |
192 | 201 | app.setTodayCustomer(today); |
193 | 202 | } |
194 | 203 | |
195 | - if (!isPtSysAdmin && !isPtAdmin ) { | |
196 | - app.setTotalAlarm(getAlarmInfo(totalFilter)); | |
197 | - app.setTodayAlarm(getAlarmInfo(todayFilter)); | |
198 | - } | |
204 | + | |
199 | 205 | |
200 | 206 | if (!isPtSysAdmin && !isPtAdmin ) { |
201 | 207 | app.setTotalMsg(getFlowStatistics(totalFilter)); | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
3 | 4 | import com.fasterxml.jackson.databind.JsonNode; |
4 | 5 | import jakarta.mail.*; |
5 | 6 | import jakarta.mail.internet.InternetAddress; |
... | ... | @@ -14,6 +15,7 @@ import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
14 | 15 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
15 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
16 | 17 | import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; |
18 | +import org.thingsboard.server.common.data.yunteng.enums.AssetStatusEnum; | |
17 | 19 | import org.thingsboard.server.common.data.yunteng.enums.EmailFormatEnum; |
18 | 20 | import org.thingsboard.server.common.data.yunteng.enums.ResponseCodeEnum; |
19 | 21 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; |
... | ... | @@ -45,15 +47,38 @@ public class YtMailServiceImpl implements YtMailService { |
45 | 47 | @Override |
46 | 48 | public boolean sendEmail(EmailReqDTO emailReqDTO) { |
47 | 49 | boolean result =false; |
48 | - //查询模板信息 | |
49 | - MessageTemplate messageTemplate = messageTemplateMapper.selectById(emailReqDTO.getId()); | |
50 | - if(null == messageTemplate){ | |
51 | - throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
52 | - } | |
53 | - MessageConfig messageConfig =messageConfigMapper.selectById(messageTemplate.getMessageConfigId()); | |
54 | - if (messageConfig.getStatus() != FastIotConstants.StateValue.ENABLE) { | |
55 | - throw new YtDataValidationException(ErrorMessage.CONFIG_IS_DISABLE.getMessage()); | |
56 | - } | |
50 | + | |
51 | + | |
52 | + | |
53 | + /**消息模板是否可用*/ | |
54 | + QueryWrapper<MessageTemplate> messageTemplateQueryWrapper = new QueryWrapper<MessageTemplate>(); | |
55 | + messageTemplateQueryWrapper.lambda() | |
56 | + .eq(MessageTemplate::getId, emailReqDTO.getId()) | |
57 | + .eq(MessageTemplate::getStatus, AssetStatusEnum.ENABLE.ordinal()); | |
58 | + MessageTemplate messageTemplate = messageTemplateMapper.selectOne(messageTemplateQueryWrapper); | |
59 | + if (null == messageTemplate) { | |
60 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_TEMPLATE_NOT_EXISTS.getMessage()); | |
61 | + } | |
62 | + | |
63 | + /**消息配置是否可用*/ | |
64 | + QueryWrapper<MessageConfig> configQueryWrapper = new QueryWrapper<>(); | |
65 | + configQueryWrapper.lambda() | |
66 | + .eq(MessageConfig::getId, messageTemplate.getMessageConfigId()) | |
67 | + .eq(MessageConfig::getStatus, AssetStatusEnum.ENABLE.ordinal()); | |
68 | + MessageConfig messageConfig = | |
69 | + messageConfigMapper.selectOne(configQueryWrapper); | |
70 | + if (null == messageConfig) { | |
71 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_CONFIG_NOT_EXISTS.getMessage()); | |
72 | + } | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
77 | + | |
78 | + | |
79 | + | |
80 | + | |
81 | + | |
57 | 82 | JsonNode configNode = messageConfig.getConfig(); |
58 | 83 | EmailConfiguration emailConfiguration = JacksonUtil.convertValue(configNode, EmailConfiguration.class); |
59 | 84 | if(emailConfiguration !=null){ | ... | ... |
... | ... | @@ -19,6 +19,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidatio |
19 | 19 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
20 | 20 | import org.thingsboard.server.common.data.yunteng.dto.request.CodeTTL; |
21 | 21 | import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO; |
22 | +import org.thingsboard.server.common.data.yunteng.enums.AssetStatusEnum; | |
22 | 23 | import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum; |
23 | 24 | import org.thingsboard.server.common.data.yunteng.enums.MsgTemplatePurposeEnum; |
24 | 25 | import org.thingsboard.server.common.data.yunteng.enums.ResponseCodeEnum; |
... | ... | @@ -65,43 +66,59 @@ public class YtSmsServiceImpl implements YtSmsService { |
65 | 66 | if (StringUtils.isEmpty(phoneNumbers) || StringUtils.isEmpty(templateId)) { |
66 | 67 | throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
67 | 68 | } |
68 | - MessageTemplate messageTemplate = messageTemplateMapper.selectById(templateId); | |
69 | - if (null != messageTemplate) { | |
70 | - MessageConfig messageConfig = | |
71 | - messageConfigMapper.selectById(messageTemplate.getMessageConfigId()); | |
72 | - JsonNode configJsonNode = messageConfig.getConfig(); | |
73 | - ObjectNode configObjectNode = (ObjectNode) configJsonNode; | |
74 | - configObjectNode.put("type", messageConfig.getPlatformType()); | |
75 | - SmsProviderConfiguration smsProviderConfiguration = | |
76 | - JacksonUtil.convertValue(configObjectNode, SmsProviderConfiguration.class); | |
77 | - if (null != smsProviderConfiguration) { | |
78 | - SmsSender smsSender = ytDefaultSmsSenderFactory.createSmsSender(smsProviderConfiguration); | |
79 | - String result = | |
80 | - smsSender.sendSms( | |
81 | - phoneNumbers, | |
82 | - messageTemplate.getTemplateCode(), | |
83 | - templateParam, | |
84 | - messageTemplate.getSignName()); | |
85 | - // 记录短信日志 | |
86 | - String status = ResponseCodeEnum.SUCCESS.name(); | |
87 | - String remark = smsReqDTO.getRemark()==null?"":smsReqDTO.getRemark(); | |
88 | - if(!ResponseCodeEnum.SUCCESS.name().equals(result)){ | |
89 | - status = ResponseCodeEnum.FAILED.name(); | |
90 | - remark += result; | |
91 | - } | |
92 | - SmsLog smsLog = new SmsLog(); | |
93 | - smsLog.setToPhone(phoneNumbers); | |
94 | - smsLog.setType(messageConfig.getPlatformType()); | |
95 | - smsLog.setStatus(status); | |
96 | - smsLog.setRemark(remark); | |
97 | - smsLog.setMessageTemplateId(messageTemplate.getId()); | |
98 | - smsLog.setTemplateParam(JacksonUtil.toJsonNode(JacksonUtil.toString(templateParam))); | |
99 | - smsLog.setSendTime(LocalDateTime.now()); | |
100 | - smsLog.setTenantId(messageTemplate.getTenantId()); | |
101 | - smsLog.setTemplatePurpose(smsReqDTO.getTemplatePurpose()); | |
102 | - smsLogMapper.insert(smsLog); | |
103 | - return ResponseCodeEnum.SUCCESS.name().equals(result); | |
69 | + /**消息模板是否可用*/ | |
70 | + QueryWrapper<MessageTemplate> messageTemplateQueryWrapper = new QueryWrapper<MessageTemplate>(); | |
71 | + messageTemplateQueryWrapper.lambda() | |
72 | + .eq(MessageTemplate::getId, templateId) | |
73 | + .eq(MessageTemplate::getStatus, AssetStatusEnum.ENABLE.ordinal()); | |
74 | + MessageTemplate messageTemplate = messageTemplateMapper.selectOne(messageTemplateQueryWrapper); | |
75 | + if (null == messageTemplate) { | |
76 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_TEMPLATE_NOT_EXISTS.getMessage()); | |
77 | + } | |
78 | + | |
79 | + /**消息配置是否可用*/ | |
80 | + QueryWrapper<MessageConfig> configQueryWrapper = new QueryWrapper<>(); | |
81 | + configQueryWrapper.lambda() | |
82 | + .eq(MessageConfig::getId, messageTemplate.getMessageConfigId()) | |
83 | + .eq(MessageConfig::getStatus, AssetStatusEnum.ENABLE.ordinal()); | |
84 | + MessageConfig messageConfig = | |
85 | + messageConfigMapper.selectOne(configQueryWrapper); | |
86 | + if (null == messageConfig) { | |
87 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_CONFIG_NOT_EXISTS.getMessage()); | |
88 | + } | |
89 | + | |
90 | + JsonNode configJsonNode = messageConfig.getConfig(); | |
91 | + ObjectNode configObjectNode = (ObjectNode) configJsonNode; | |
92 | + configObjectNode.put("type", messageConfig.getPlatformType()); | |
93 | + SmsProviderConfiguration smsProviderConfiguration = | |
94 | + JacksonUtil.convertValue(configObjectNode, SmsProviderConfiguration.class); | |
95 | + if (null != smsProviderConfiguration) { | |
96 | + SmsSender smsSender = ytDefaultSmsSenderFactory.createSmsSender(smsProviderConfiguration); | |
97 | + String result = | |
98 | + smsSender.sendSms( | |
99 | + phoneNumbers, | |
100 | + messageTemplate.getTemplateCode(), | |
101 | + templateParam, | |
102 | + messageTemplate.getSignName()); | |
103 | + // 记录短信日志 | |
104 | + String status = ResponseCodeEnum.SUCCESS.name(); | |
105 | + String remark = smsReqDTO.getRemark()==null?"":smsReqDTO.getRemark(); | |
106 | + if(!ResponseCodeEnum.SUCCESS.name().equals(result)){ | |
107 | + status = ResponseCodeEnum.FAILED.name(); | |
108 | + remark += result; | |
104 | 109 | } |
110 | + SmsLog smsLog = new SmsLog(); | |
111 | + smsLog.setToPhone(phoneNumbers); | |
112 | + smsLog.setType(messageConfig.getPlatformType()); | |
113 | + smsLog.setStatus(status); | |
114 | + smsLog.setRemark(remark); | |
115 | + smsLog.setMessageTemplateId(messageTemplate.getId()); | |
116 | + smsLog.setTemplateParam(JacksonUtil.toJsonNode(JacksonUtil.toString(templateParam))); | |
117 | + smsLog.setSendTime(LocalDateTime.now()); | |
118 | + smsLog.setTenantId(messageTemplate.getTenantId()); | |
119 | + smsLog.setTemplatePurpose(smsReqDTO.getTemplatePurpose()); | |
120 | + smsLogMapper.insert(smsLog); | |
121 | + return ResponseCodeEnum.SUCCESS.name().equals(result); | |
105 | 122 | } |
106 | 123 | return false; |
107 | 124 | } |
... | ... | @@ -136,6 +153,8 @@ public class YtSmsServiceImpl implements YtSmsService { |
136 | 153 | if (!canSend) { |
137 | 154 | throw new YtDataValidationException(ErrorMessage.MESSAGE_SEND_TOO_FAST.getMessage()); |
138 | 155 | } |
156 | + | |
157 | + /**消息模板是否可用*/ | |
139 | 158 | List<MessageTemplate> messageTemplates = |
140 | 159 | messageTemplateMapper.selectList( |
141 | 160 | new QueryWrapper<MessageTemplate>() |
... | ... | @@ -145,12 +164,25 @@ public class YtSmsServiceImpl implements YtSmsService { |
145 | 164 | .eq(MessageTemplate::getTemplatePurpose, purpose.name()) |
146 | 165 | .eq(MessageTemplate::getMessageType, MessageTypeEnum.PHONE_MESSAGE.name())); |
147 | 166 | if (messageTemplates.isEmpty()) { |
148 | - throw new YtDataValidationException(ErrorMessage.TARGET_TEMPLATE_NOT_EXISTS.getMessage()); | |
167 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_TEMPLATE_NOT_EXISTS.getMessage()); | |
149 | 168 | } |
169 | + | |
170 | + /**消息配置是否可用*/ | |
171 | + | |
172 | + MessageTemplate messageTemplate = messageTemplates.get(0); | |
173 | + QueryWrapper<MessageConfig> configQueryWrapper = new QueryWrapper<>(); | |
174 | + configQueryWrapper.lambda() | |
175 | + .eq(MessageConfig::getId, messageTemplate.getMessageConfigId()) | |
176 | + .eq(MessageConfig::getStatus, AssetStatusEnum.ENABLE.ordinal()); | |
177 | + MessageConfig messageConfig = | |
178 | + messageConfigMapper.selectOne(configQueryWrapper); | |
179 | + if (null == messageConfig) { | |
180 | + throw new YtDataValidationException(ErrorMessage.MESSAGE_CONFIG_NOT_EXISTS.getMessage()); | |
181 | + } | |
182 | + | |
150 | 183 | String code = RandomStringUtils.randomNumeric(6); |
151 | 184 | LinkedHashMap<String, String> params = new LinkedHashMap<>(); |
152 | 185 | params.put("code", code); |
153 | - MessageTemplate messageTemplate = messageTemplates.get(0); | |
154 | 186 | SmsReqDTO smsReqDTO = new SmsReqDTO(); |
155 | 187 | smsReqDTO.setParams(params); |
156 | 188 | smsReqDTO.setPhoneNumbers(phoneNumber); | ... | ... |
... | ... | @@ -297,6 +297,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
297 | 297 | user.setEmail(userDTO.getEmail()); |
298 | 298 | user.setAccountExpireTime(userDTO.getAccountExpireTime()); |
299 | 299 | user.setRemark(userDTO.getRemark()); |
300 | + user.setUpdateTime(LocalDateTime.now()); | |
300 | 301 | if (userDTO.getPassword() != null && !userDTO.getPassword().equals("******")) { |
301 | 302 | user.setPassword(passwordEncoder.encode(userDTO.getPassword())); |
302 | 303 | } |
... | ... | @@ -572,7 +573,14 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> |
572 | 573 | .stream() |
573 | 574 | .map(UserRole::getRoleId) |
574 | 575 | .collect(Collectors.toList()); |
575 | - return roleIds.toArray(new String[roleIds.size()]); | |
576 | + List<String> enableRoles = roleMapper.selectList(new QueryWrapper<Role>().lambda() | |
577 | + .eq(Role::isEnabled, true).in(Role::getId,roleIds)) | |
578 | + .stream().map(m -> m.getId()) | |
579 | + .collect(Collectors.toList()); | |
580 | + if(enableRoles.size() == 0){ | |
581 | + return null; | |
582 | + } | |
583 | + return roleIds.toArray(new String[enableRoles.size()]); | |
576 | 584 | } |
577 | 585 | if (roleOrGroupReqDTO.isQueryOrganization()) { |
578 | 586 | List<String> organizationIds = | ... | ... |
... | ... | @@ -81,7 +81,7 @@ public interface HomePageService { |
81 | 81 | * @param customerId |
82 | 82 | * @return |
83 | 83 | */ |
84 | - HomePageAppDTO app(boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId); | |
84 | + HomePageAppDTO app(Boolean login,boolean isPtSysAdmin, boolean isPtAdmin, boolean isTenantAdmin, EntityId tenantId, EntityId customerId); | |
85 | 85 | } |
86 | 86 | |
87 | 87 | ... | ... |