Showing
30 changed files
with
467 additions
and
450 deletions
application/src/main/java/org/thingsboard/server/config/yunteng/ThingsKitExceptionHandler.java
renamed from
application/src/main/java/org/thingsboard/server/config/yunteng/ControllerExceptionHandler.java
@@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; | @@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; | ||
5 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
6 | import org.apache.http.HttpHeaders; | 6 | import org.apache.http.HttpHeaders; |
7 | import org.springframework.http.HttpStatus; | 7 | import org.springframework.http.HttpStatus; |
8 | -import org.springframework.security.access.AccessDeniedException; | ||
9 | import org.springframework.security.core.Authentication; | 8 | import org.springframework.security.core.Authentication; |
10 | import org.springframework.security.core.context.SecurityContextHolder; | 9 | import org.springframework.security.core.context.SecurityContextHolder; |
11 | import org.springframework.web.bind.MethodArgumentNotValidException; | 10 | import org.springframework.web.bind.MethodArgumentNotValidException; |
@@ -21,7 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.*; | @@ -21,7 +20,7 @@ import org.thingsboard.server.common.data.yunteng.core.exception.*; | ||
21 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 20 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
22 | import org.thingsboard.server.common.data.yunteng.dto.SysLogOperateDTO; | 21 | import org.thingsboard.server.common.data.yunteng.dto.SysLogOperateDTO; |
23 | import org.thingsboard.server.dao.audit.AuditLogService; | 22 | import org.thingsboard.server.dao.audit.AuditLogService; |
24 | -import org.thingsboard.server.exception.yunteng.YunTengErrorResponseHandler; | 23 | +import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; |
25 | import org.thingsboard.server.service.security.model.SecurityUser; | 24 | import org.thingsboard.server.service.security.model.SecurityUser; |
26 | import org.thingsboard.server.utils.yunteng.LogUtils; | 25 | import org.thingsboard.server.utils.yunteng.LogUtils; |
27 | 26 | ||
@@ -33,99 +32,49 @@ import java.util.UUID; | @@ -33,99 +32,49 @@ import java.util.UUID; | ||
33 | @ControllerAdvice(basePackages = "org.thingsboard.server.controller.yunteng") | 32 | @ControllerAdvice(basePackages = "org.thingsboard.server.controller.yunteng") |
34 | @RequiredArgsConstructor | 33 | @RequiredArgsConstructor |
35 | @Slf4j | 34 | @Slf4j |
36 | -public class ControllerExceptionHandler { | ||
37 | - | 35 | +public class ThingsKitExceptionHandler { |
38 | private final AuditLogService auditLogService; | 36 | private final AuditLogService auditLogService; |
39 | - private final YunTengErrorResponseHandler errorResponseHandler; | ||
40 | - | ||
41 | - @ExceptionHandler(YunTengException.class) | ||
42 | - public void handleYunTengException(YunTengException ex,HttpServletRequest request, HttpServletResponse response) { | ||
43 | - produceLog( request, ex); | ||
44 | - errorResponseHandler.handle(ex, response); | ||
45 | - } | 37 | + private final ThingsboardErrorResponseHandler errorResponseHandler; |
46 | 38 | ||
47 | @ExceptionHandler(MethodArgumentNotValidException.class) | 39 | @ExceptionHandler(MethodArgumentNotValidException.class) |
48 | public void handleMethodArgumentNotValidException( | 40 | public void handleMethodArgumentNotValidException( |
49 | - MethodArgumentNotValidException ex,HttpServletRequest request, HttpServletResponse response) { | ||
50 | - produceLog( request, ex); | 41 | + MethodArgumentNotValidException ex, |
42 | + HttpServletRequest request, | ||
43 | + HttpServletResponse response) { | ||
44 | + produceLog(request, ex); | ||
51 | errorResponseHandler.handle( | 45 | errorResponseHandler.handle( |
52 | - new YunTengException( | 46 | + new ThingsKitException( |
53 | ErrorMessage.INVALID_PARAMETER.setMessage( | 47 | ErrorMessage.INVALID_PARAMETER.setMessage( |
54 | Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()), | 48 | Objects.requireNonNull(ex.getBindingResult().getFieldError()).getDefaultMessage()), |
55 | HttpStatus.BAD_REQUEST), | 49 | HttpStatus.BAD_REQUEST), |
56 | response); | 50 | response); |
57 | } | 51 | } |
58 | 52 | ||
59 | - @ExceptionHandler(YtDataValidationException.class) | ||
60 | - public void handleDataValidationException( | ||
61 | - YtDataValidationException ex, HttpServletRequest request, HttpServletResponse response) { | ||
62 | - produceLog( request, ex); | ||
63 | - YunTengException YunTengException = | ||
64 | - new YunTengException( | ||
65 | - ErrorMessage.BAD_PARAMETER.setMessage(ex.getMessage()), HttpStatus.BAD_REQUEST); | ||
66 | - errorResponseHandler.handle(YunTengException, response); | ||
67 | - } | ||
68 | - | ||
69 | - @ExceptionHandler(TooManyRequestException.class) | ||
70 | - public void handleTooManyRequestException(HttpServletResponse response) { | ||
71 | - errorResponseHandler.handle( | ||
72 | - new YunTengException(ErrorMessage.TOO_MANY_REQUEST, HttpStatus.TOO_MANY_REQUESTS), | ||
73 | - response); | ||
74 | - } | ||
75 | - | ||
76 | - @ExceptionHandler(AccessDeniedException.class) | ||
77 | - public void handleAccessDeniedException(AccessDeniedException ex,HttpServletRequest request, HttpServletResponse response) { | ||
78 | - produceLog( request, ex); | ||
79 | - errorResponseHandler.handle( | ||
80 | - new YunTengException( | ||
81 | - ErrorMessage.ACCESS_DENIED.setMessage(ex.getMessage()), HttpStatus.FORBIDDEN), | ||
82 | - response); | ||
83 | - } | ||
84 | - | ||
85 | - @ExceptionHandler(NoneTenantAssetException.class) | ||
86 | - public void handleNoneTenantAssetException( | ||
87 | - NoneTenantAssetException ex, HttpServletRequest request, HttpServletResponse response) { | ||
88 | - produceLog( request, ex); | ||
89 | - errorResponseHandler.handle( | ||
90 | - new YunTengException( | ||
91 | - ErrorMessage.NONE_TENANT_ASSET.setMessage(ex.getMessage()), HttpStatus.NOT_FOUND), | ||
92 | - response); | ||
93 | - } | ||
94 | - | ||
95 | - @ExceptionHandler(EntityCreationException.class) | ||
96 | - public void handleEntityCreationException(HttpServletResponse response) { | ||
97 | - errorResponseHandler.handle( | ||
98 | - new YunTengException( | ||
99 | - ErrorMessage.SEND_DESTINATION_NOT_FOUND, HttpStatus.BAD_REQUEST), | ||
100 | - response); | ||
101 | - } | ||
102 | - | ||
103 | - | ||
104 | - | ||
105 | protected SecurityUser getCurrentUser() throws ThingsboardException { | 53 | protected SecurityUser getCurrentUser() throws ThingsboardException { |
106 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | 54 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
107 | if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) { | 55 | if (authentication != null && authentication.getPrincipal() instanceof SecurityUser) { |
108 | return (SecurityUser) authentication.getPrincipal(); | 56 | return (SecurityUser) authentication.getPrincipal(); |
109 | } else { | 57 | } else { |
110 | - throw new ThingsboardException("You aren't authorized to perform this operation!", ThingsboardErrorCode.AUTHENTICATION); | 58 | + throw new ThingsboardException( |
59 | + "You aren't authorized to perform this operation!", ThingsboardErrorCode.AUTHENTICATION); | ||
111 | } | 60 | } |
112 | } | 61 | } |
113 | 62 | ||
114 | /** | 63 | /** |
115 | * 生产日志并缓存到队列中 | 64 | * 生产日志并缓存到队列中 |
116 | * | 65 | * |
117 | - * @param request 响应头 | 66 | + * @param request 响应头 |
118 | * @param e 异常信息 | 67 | * @param e 异常信息 |
119 | */ | 68 | */ |
120 | - void produceLog(HttpServletRequest request, Exception e) { | 69 | + void produceLog(HttpServletRequest request, Exception e) { |
121 | 70 | ||
122 | try { | 71 | try { |
123 | - SecurityUser currentUser = getCurrentUser(); | 72 | + SecurityUser currentUser = getCurrentUser(); |
124 | 73 | ||
125 | Asset entity = new Asset(); | 74 | Asset entity = new Asset(); |
126 | entity.setName(e.getMessage()); | 75 | entity.setName(e.getMessage()); |
127 | 76 | ||
128 | - //请求相关信息 | 77 | + // 请求相关信息 |
129 | SysLogOperateDTO additionalInfo = new SysLogOperateDTO(); | 78 | SysLogOperateDTO additionalInfo = new SysLogOperateDTO(); |
130 | additionalInfo.setApi(request.getRequestURI()); | 79 | additionalInfo.setApi(request.getRequestURI()); |
131 | additionalInfo.setClientIp(LogUtils.clientIP(request)); | 80 | additionalInfo.setClientIp(LogUtils.clientIP(request)); |
@@ -133,24 +82,31 @@ public class ControllerExceptionHandler { | @@ -133,24 +82,31 @@ public class ControllerExceptionHandler { | ||
133 | additionalInfo.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT)); | 82 | additionalInfo.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT)); |
134 | additionalInfo.setMethod(request.getMethod()); | 83 | additionalInfo.setMethod(request.getMethod()); |
135 | 84 | ||
136 | - | ||
137 | - EntityId operateId = new EntityId() { | ||
138 | - @Override | ||
139 | - public UUID getId() { | ||
140 | - return Uuids.timeBased(); | ||
141 | - } | ||
142 | - | ||
143 | - @Override | ||
144 | - public EntityType getEntityType() { | ||
145 | - return EntityType.RUNNING_EXCEPTION; | ||
146 | - } | ||
147 | - }; | ||
148 | - | ||
149 | - | ||
150 | - auditLogService.logEntityAction(currentUser.getTenantId(),currentUser.getCustomerId(),currentUser.getId(), currentUser.getName(), operateId,entity, ActionType.LOG_EXCEPTION,e,additionalInfo); | 85 | + EntityId operateId = |
86 | + new EntityId() { | ||
87 | + @Override | ||
88 | + public UUID getId() { | ||
89 | + return Uuids.timeBased(); | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public EntityType getEntityType() { | ||
94 | + return EntityType.RUNNING_EXCEPTION; | ||
95 | + } | ||
96 | + }; | ||
97 | + | ||
98 | + auditLogService.logEntityAction( | ||
99 | + currentUser.getTenantId(), | ||
100 | + currentUser.getCustomerId(), | ||
101 | + currentUser.getId(), | ||
102 | + currentUser.getName(), | ||
103 | + operateId, | ||
104 | + entity, | ||
105 | + ActionType.LOG_EXCEPTION, | ||
106 | + e, | ||
107 | + additionalInfo); | ||
151 | } catch (ThingsboardException ex) { | 108 | } catch (ThingsboardException ex) { |
152 | - log.error("异常日志记录异常【{}】",ex); | 109 | + log.error("异常日志记录异常【{}】", ex); |
153 | } | 110 | } |
154 | - | ||
155 | } | 111 | } |
156 | } | 112 | } |
application/src/main/java/org/thingsboard/server/controller/yunteng/AlarmProfileController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import io.swagger.annotations.Api; | ||
4 | +import io.swagger.annotations.ApiOperation; | ||
5 | +import lombok.RequiredArgsConstructor; | ||
6 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
7 | +import org.springframework.validation.annotation.Validated; | ||
8 | +import org.springframework.web.bind.annotation.*; | ||
9 | +import org.thingsboard.server.common.data.StringUtils; | ||
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | ||
11 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | ||
12 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | ||
13 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
14 | +import org.thingsboard.server.common.data.yunteng.dto.MailLogDTO; | ||
15 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
17 | +import org.thingsboard.server.controller.BaseController; | ||
18 | +import org.thingsboard.server.dao.yunteng.service.AlarmProfileService; | ||
19 | + | ||
20 | +import java.util.HashMap; | ||
21 | + | ||
22 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
23 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; | ||
24 | + | ||
25 | +@RestController | ||
26 | +@RequestMapping("api/yt/alarm/profile") | ||
27 | +@Api(tags = {"告警配置"}) | ||
28 | +@RequiredArgsConstructor | ||
29 | +@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
30 | +public class AlarmProfileController extends BaseController { | ||
31 | + | ||
32 | + private final AlarmProfileService alarmProfileService; | ||
33 | + | ||
34 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
35 | + @ApiOperation("分页") | ||
36 | + public YtPageData<AlarmProfileDTO> pageAlarmProfile( | ||
37 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
38 | + @RequestParam(PAGE) int page, | ||
39 | + @RequestParam(value = "status", required = false) Integer status, | ||
40 | + @RequestParam(value = "name", required = false) String name, | ||
41 | + @RequestParam(value = "organizationId", required = false) String organizationId, | ||
42 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
43 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
44 | + throws ThingsboardException { | ||
45 | + | ||
46 | + HashMap<String, Object> queryMap = new HashMap<>(); | ||
47 | + queryMap.put(PAGE_SIZE, pageSize); | ||
48 | + queryMap.put(PAGE, page); | ||
49 | + queryMap.put(ORDER_FILED, orderBy); | ||
50 | + queryMap.put("status", status); | ||
51 | + queryMap.put("name", name); | ||
52 | + queryMap.put("organizationId", organizationId); | ||
53 | + if (orderType != null) { | ||
54 | + queryMap.put(ORDER_TYPE, orderType.name()); | ||
55 | + } | ||
56 | + return alarmProfileService.page( | ||
57 | + getCurrentUser().isPtTenantAdmin(), | ||
58 | + getCurrentUser().getCurrentTenantId(), | ||
59 | + getCurrentUser().getCurrentUserId(), | ||
60 | + queryMap); | ||
61 | + } | ||
62 | + | ||
63 | + @PostMapping | ||
64 | + @ApiOperation("新增|编辑") | ||
65 | + public AlarmProfileDTO saveOrUpdateAlarmProfile(@Validated @RequestBody AlarmProfileDTO alarmProfileDTO) | ||
66 | + throws ThingsboardException { | ||
67 | + alarmProfileDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
68 | + return alarmProfileService.saveOrUpdateAlarmProfile(alarmProfileDTO); | ||
69 | + } | ||
70 | + | ||
71 | + @DeleteMapping | ||
72 | + @ApiOperation("删除") | ||
73 | + public boolean deleteAlarmProfile(@Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) { | ||
74 | + return alarmProfileService.deleteAlarmProFile(deleteDTO); | ||
75 | + } | ||
76 | + | ||
77 | + @GetMapping("{alarmProfileId}/{status}") | ||
78 | + @ApiOperation("更新状态") | ||
79 | + public AlarmProfileDTO saveOrUpdateAlarmProfile( | ||
80 | + @PathVariable("alarmProfileId") String alarmProfileId, @PathVariable("status") Integer status) | ||
81 | + throws ThingsboardException { | ||
82 | + return alarmProfileService.updateAlarmProFileStatus( | ||
83 | + alarmProfileId, getCurrentUser().getCurrentTenantId(), status); | ||
84 | + } | ||
85 | +} |
@@ -4,12 +4,10 @@ import io.swagger.annotations.Api; | @@ -4,12 +4,10 @@ import io.swagger.annotations.Api; | ||
4 | import io.swagger.annotations.ApiOperation; | 4 | import io.swagger.annotations.ApiOperation; |
5 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
6 | import org.apache.commons.lang3.StringUtils; | 6 | import org.apache.commons.lang3.StringUtils; |
7 | -import org.springframework.http.HttpStatus; | ||
8 | import org.springframework.http.ResponseEntity; | 7 | import org.springframework.http.ResponseEntity; |
9 | import org.springframework.security.access.prepost.PreAuthorize; | 8 | import org.springframework.security.access.prepost.PreAuthorize; |
10 | import org.springframework.validation.annotation.Validated; | 9 | import org.springframework.validation.annotation.Validated; |
11 | import org.springframework.web.bind.annotation.*; | 10 | import org.springframework.web.bind.annotation.*; |
12 | -import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | ||
13 | import org.thingsboard.server.common.data.DeviceProfile; | 11 | import org.thingsboard.server.common.data.DeviceProfile; |
14 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; | 12 | import org.thingsboard.server.common.data.DeviceProfileProvisionType; |
15 | import org.thingsboard.server.common.data.DeviceProfileType; | 13 | import org.thingsboard.server.common.data.DeviceProfileType; |
@@ -33,8 +31,6 @@ import org.thingsboard.server.controller.BaseController; | @@ -33,8 +31,6 @@ import org.thingsboard.server.controller.BaseController; | ||
33 | import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService; | 31 | import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService; |
34 | import org.thingsboard.server.service.security.permission.Operation; | 32 | import org.thingsboard.server.service.security.permission.Operation; |
35 | 33 | ||
36 | -import java.net.URI; | ||
37 | -import java.sql.ResultSet; | ||
38 | import java.time.LocalDateTime; | 34 | import java.time.LocalDateTime; |
39 | import java.time.ZoneOffset; | 35 | import java.time.ZoneOffset; |
40 | import java.util.*; | 36 | import java.util.*; |
@@ -65,23 +61,9 @@ public class YtDeviceProfileController extends BaseController { | @@ -65,23 +61,9 @@ public class YtDeviceProfileController extends BaseController { | ||
65 | 61 | ||
66 | deviceProfileDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | 62 | deviceProfileDTO.setTenantId(getCurrentUser().getCurrentTenantId()); |
67 | DeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(deviceProfileDTO); | 63 | DeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(deviceProfileDTO); |
68 | - DeviceProfile savedDeviceProfile = updateTbDeviceProfile(tbDeviceProfile, created); | 64 | + updateTbDeviceProfile(tbDeviceProfile, created); |
69 | 65 | ||
70 | - | ||
71 | - | ||
72 | - | ||
73 | - DeviceProfileDTO newDeviceProfileDTO = ytDeviceProfileService.insertOrUpdate(savedDeviceProfile.getId().getId().toString(), deviceProfileDTO); | ||
74 | - return Optional.ofNullable(newDeviceProfileDTO) | ||
75 | - .map( | ||
76 | - dto -> { | ||
77 | - URI location = | ||
78 | - ServletUriComponentsBuilder.fromCurrentRequest() | ||
79 | - .path("/{id}") | ||
80 | - .buildAndExpand(newDeviceProfileDTO.getId()) | ||
81 | - .toUri(); | ||
82 | - return ResponseEntity.created(location).body(newDeviceProfileDTO); | ||
83 | - }) | ||
84 | - .orElse(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build()); | 66 | + return ResponseEntity.ok(deviceProfileDTO); |
85 | } | 67 | } |
86 | 68 | ||
87 | /** | 69 | /** |
@@ -151,7 +133,7 @@ public class YtDeviceProfileController extends BaseController { | @@ -151,7 +133,7 @@ public class YtDeviceProfileController extends BaseController { | ||
151 | @DeleteMapping | 133 | @DeleteMapping |
152 | @ApiOperation("删除") | 134 | @ApiOperation("删除") |
153 | public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | 135 | public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { |
154 | - ytDeviceProfileService.deleteDeviceProfiles(getCurrentUser().getCurrentTenantId(), deleteDTO.getIds()); | 136 | + ytDeviceProfileService.checkDeviceProfiles(getCurrentUser().getCurrentTenantId(), deleteDTO.getIds()); |
155 | 137 | ||
156 | for (String id : deleteDTO.getIds()) { | 138 | for (String id : deleteDTO.getIds()) { |
157 | deleteTbDeviceProfile(id); | 139 | deleteTbDeviceProfile(id); |
@@ -244,11 +226,6 @@ public class YtDeviceProfileController extends BaseController { | @@ -244,11 +226,6 @@ public class YtDeviceProfileController extends BaseController { | ||
244 | && deviceProfileDTO.getProfileData().getAlarms() !=null){ | 226 | && deviceProfileDTO.getProfileData().getAlarms() !=null){ |
245 | deviceProfileData.setAlarms(deviceProfileDTO.getProfileData().getAlarms()); | 227 | deviceProfileData.setAlarms(deviceProfileDTO.getProfileData().getAlarms()); |
246 | } | 228 | } |
247 | -// if (null != deviceProfileDTO.getAlarms()) { | ||
248 | -// List<DeviceProfileAlarm> list = new ArrayList<>(); | ||
249 | -// DeviceProfileAlarm deviceProfileAlarm = JacksonUtil.convertValue(deviceProfileDTO.getAlarms(),DeviceProfileAlarm.class); | ||
250 | -// list.add(deviceProfileAlarm); | ||
251 | -// } | ||
252 | tbDeviceProfile.setProfileData(deviceProfileData); | 229 | tbDeviceProfile.setProfileData(deviceProfileData); |
253 | 230 | ||
254 | return tbDeviceProfile; | 231 | return tbDeviceProfile; |
@@ -40,6 +40,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep | @@ -40,6 +40,8 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep | ||
40 | import org.springframework.web.util.WebUtils; | 40 | import org.springframework.web.util.WebUtils; |
41 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | 41 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
42 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 42 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
43 | +import org.thingsboard.server.common.data.yunteng.core.Result; | ||
44 | +import org.thingsboard.server.common.data.yunteng.core.exception.ThingsKitException; | ||
43 | import org.thingsboard.server.common.msg.tools.TbRateLimitsException; | 45 | import org.thingsboard.server.common.msg.tools.TbRateLimitsException; |
44 | import org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException; | 46 | import org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException; |
45 | import org.thingsboard.server.service.security.exception.JwtExpiredTokenException; | 47 | import org.thingsboard.server.service.security.exception.JwtExpiredTokenException; |
@@ -130,7 +132,10 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand | @@ -130,7 +132,10 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand | ||
130 | handleAccessDeniedException(response); | 132 | handleAccessDeniedException(response); |
131 | } else if (exception instanceof AuthenticationException) { | 133 | } else if (exception instanceof AuthenticationException) { |
132 | handleAuthenticationException((AuthenticationException) exception, response); | 134 | handleAuthenticationException((AuthenticationException) exception, response); |
133 | - } else { | 135 | + }else if(exception instanceof ThingsKitException){ |
136 | + handleThingsKitException((ThingsKitException)exception, response); | ||
137 | + } | ||
138 | + else { | ||
134 | response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); | 139 | response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); |
135 | mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(exception.getMessage(), | 140 | mapper.writeValue(response.getWriter(), ThingsboardErrorResponse.of(exception.getMessage(), |
136 | ThingsboardErrorCode.GENERAL, HttpStatus.INTERNAL_SERVER_ERROR)); | 141 | ThingsboardErrorCode.GENERAL, HttpStatus.INTERNAL_SERVER_ERROR)); |
@@ -208,4 +213,10 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand | @@ -208,4 +213,10 @@ public class ThingsboardErrorResponseHandler extends ResponseEntityExceptionHand | ||
208 | } | 213 | } |
209 | } | 214 | } |
210 | 215 | ||
216 | + private void handleThingsKitException(ThingsKitException exception ,HttpServletResponse response) throws IOException { | ||
217 | + response.setStatus((exception).getHttpStatus().value()); | ||
218 | + mapper.writeValue( | ||
219 | + response.getWriter(), Result.error(( exception).getError())); | ||
220 | + } | ||
221 | + | ||
211 | } | 222 | } |
application/src/main/java/org/thingsboard/server/exception/yunteng/YunTengErrorResponseHandler.java
deleted
100644 → 0
1 | -package org.thingsboard.server.exception.yunteng; | ||
2 | - | ||
3 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
4 | -import lombok.extern.slf4j.Slf4j; | ||
5 | -import org.springframework.beans.factory.annotation.Autowired; | ||
6 | -import org.springframework.http.HttpStatus; | ||
7 | -import org.springframework.http.MediaType; | ||
8 | -import org.springframework.security.access.AccessDeniedException; | ||
9 | -import org.springframework.security.authentication.BadCredentialsException; | ||
10 | -import org.springframework.security.authentication.DisabledException; | ||
11 | -import org.springframework.security.authentication.LockedException; | ||
12 | -import org.springframework.security.core.AuthenticationException; | ||
13 | -import org.springframework.security.web.access.AccessDeniedHandler; | ||
14 | -import org.springframework.stereotype.Component; | ||
15 | -import org.thingsboard.server.common.data.yunteng.core.Result; | ||
16 | -import org.thingsboard.server.common.data.yunteng.core.exception.YunTengException; | ||
17 | -import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
18 | -import org.thingsboard.server.service.security.exception.AuthMethodNotSupportedException; | ||
19 | -import org.thingsboard.server.service.security.exception.JwtExpiredTokenException; | ||
20 | - | ||
21 | -import javax.servlet.http.HttpServletRequest; | ||
22 | -import javax.servlet.http.HttpServletResponse; | ||
23 | -import java.io.IOException; | ||
24 | - | ||
25 | -@Component | ||
26 | -@Slf4j | ||
27 | -public class YunTengErrorResponseHandler implements AccessDeniedHandler { | ||
28 | - | ||
29 | - private final ObjectMapper mapper; | ||
30 | - | ||
31 | - @Autowired | ||
32 | - public YunTengErrorResponseHandler(ObjectMapper mapper) { | ||
33 | - this.mapper = mapper; | ||
34 | - } | ||
35 | - | ||
36 | - @Override | ||
37 | - public void handle( | ||
38 | - HttpServletRequest request, | ||
39 | - HttpServletResponse response, | ||
40 | - AccessDeniedException accessDeniedException) | ||
41 | - throws IOException { | ||
42 | - if (!response.isCommitted()) { | ||
43 | - response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
44 | - response.setStatus(HttpStatus.FORBIDDEN.value()); | ||
45 | - mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.NO_PERMISSION)); | ||
46 | - } | ||
47 | - } | ||
48 | - | ||
49 | - public void handle(Exception exception, HttpServletResponse response) { | ||
50 | - log.debug("Processing exception {}", exception.getMessage(), exception); | ||
51 | - if (!response.isCommitted()) { | ||
52 | - try { | ||
53 | - response.setCharacterEncoding("utf-8"); | ||
54 | - response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
55 | - | ||
56 | - if (exception instanceof AccessDeniedException) { | ||
57 | - response.setStatus(HttpStatus.FORBIDDEN.value()); | ||
58 | - mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.ACCESS_DENIED)); | ||
59 | - } else if (exception instanceof AuthenticationException) { | ||
60 | - handleAuthenticationException((AuthenticationException) exception, response); | ||
61 | - } else if (exception instanceof YunTengException) { | ||
62 | - response.setStatus(((YunTengException) exception).getHttpStatus().value()); | ||
63 | - mapper.writeValue( | ||
64 | - response.getWriter(), Result.error(((YunTengException) exception).getError())); | ||
65 | - } else { | ||
66 | - response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); | ||
67 | - mapper.writeValue(response.getWriter(), Result.error(exception.getMessage())); | ||
68 | - } | ||
69 | - } catch (IOException e) { | ||
70 | - log.error("Can't handle exception", e); | ||
71 | - } | ||
72 | - } | ||
73 | - } | ||
74 | - | ||
75 | - private void handleAuthenticationException( | ||
76 | - AuthenticationException authenticationException, HttpServletResponse response) | ||
77 | - throws IOException { | ||
78 | - response.setStatus(HttpStatus.UNAUTHORIZED.value()); | ||
79 | - if (authenticationException instanceof BadCredentialsException) { | ||
80 | - mapper.writeValue( | ||
81 | - response.getWriter(), Result.error(ErrorMessage.USERNAME_PASSWORD_INCORRECT)); | ||
82 | - } else if (authenticationException instanceof DisabledException) { | ||
83 | - mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.ACCOUNT_DISABLED)); | ||
84 | - } else if (authenticationException instanceof LockedException) { | ||
85 | - mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.ACCOUNT_DISABLED)); | ||
86 | - } else if (authenticationException instanceof JwtExpiredTokenException) { | ||
87 | - mapper.writeValue(response.getWriter(), Result.error(ErrorMessage.TOKEN_EXPIRED)); | ||
88 | - } else if (authenticationException instanceof AuthMethodNotSupportedException) { | ||
89 | - mapper.writeValue( | ||
90 | - response.getWriter(), Result.error(ErrorMessage.AUTHENTICATION_METHOD_NOT_SUPPORTED)); | ||
91 | - } else { | ||
92 | - mapper.writeValue( | ||
93 | - response.getWriter(), | ||
94 | - Result.error(HttpStatus.UNAUTHORIZED.value(), authenticationException.getMessage())); | ||
95 | - } | ||
96 | - } | ||
97 | -} |
1 | package org.thingsboard.server.common.data.yunteng.core.exception; | 1 | package org.thingsboard.server.common.data.yunteng.core.exception; |
2 | 2 | ||
3 | -public class EntityCreationException extends RuntimeException { | 3 | +import org.springframework.http.HttpStatus; |
4 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
5 | + | ||
6 | +public class EntityCreationException extends ThingsKitException { | ||
4 | 7 | ||
5 | private static final long serialVersionUID = 5255597864949518781L; | 8 | private static final long serialVersionUID = 5255597864949518781L; |
6 | 9 | ||
7 | public EntityCreationException(String message) { | 10 | public EntityCreationException(String message) { |
8 | - super(message); | 11 | + super(ErrorMessage.BAD_PARAMETER.setMessage(message), HttpStatus.BAD_REQUEST); |
9 | } | 12 | } |
10 | } | 13 | } |
1 | package org.thingsboard.server.common.data.yunteng.core.exception; | 1 | package org.thingsboard.server.common.data.yunteng.core.exception; |
2 | 2 | ||
3 | -public class FileNotFoundException extends RuntimeException{ | 3 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
4 | + | ||
5 | +public class FileNotFoundException extends ThingsKitException { | ||
4 | private static final long serialVersionUID = 3466865879043055822L; | 6 | private static final long serialVersionUID = 3466865879043055822L; |
5 | 7 | ||
6 | - public FileNotFoundException(String message) { | 8 | + public FileNotFoundException(ErrorMessage message) { |
7 | super(message); | 9 | super(message); |
8 | } | 10 | } |
9 | } | 11 | } |
1 | package org.thingsboard.server.common.data.yunteng.core.exception; | 1 | package org.thingsboard.server.common.data.yunteng.core.exception; |
2 | 2 | ||
3 | -public class FileStorageException extends RuntimeException{ | 3 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
4 | + | ||
5 | +public class FileStorageException extends ThingsKitException { | ||
4 | private static final long serialVersionUID = -8866081834891143120L; | 6 | private static final long serialVersionUID = -8866081834891143120L; |
5 | 7 | ||
6 | - public FileStorageException(String message) { | 8 | + public FileStorageException(ErrorMessage message) { |
7 | super(message); | 9 | super(message); |
8 | } | 10 | } |
9 | } | 11 | } |
1 | package org.thingsboard.server.common.data.yunteng.core.exception; | 1 | package org.thingsboard.server.common.data.yunteng.core.exception; |
2 | 2 | ||
3 | -public class NoneTenantAssetException extends RuntimeException { | 3 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
4 | + | ||
5 | +public class NoneTenantAssetException extends ThingsKitException { | ||
4 | private static final long serialVersionUID = 9135599998185288967L; | 6 | private static final long serialVersionUID = 9135599998185288967L; |
5 | 7 | ||
6 | - public NoneTenantAssetException(String message) { | 8 | + public NoneTenantAssetException(ErrorMessage message) { |
7 | super(message); | 9 | super(message); |
8 | } | 10 | } |
9 | } | 11 | } |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/core/exception/ThingsKitException.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/core/exception/YunTengException.java
@@ -4,26 +4,27 @@ import lombok.Getter; | @@ -4,26 +4,27 @@ import lombok.Getter; | ||
4 | import org.springframework.http.HttpStatus; | 4 | import org.springframework.http.HttpStatus; |
5 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 5 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
6 | 6 | ||
7 | -public class YunTengException extends RuntimeException { | 7 | +public class ThingsKitException extends RuntimeException { |
8 | private static final long serialVersionUID = 4036257507478854844L; | 8 | private static final long serialVersionUID = 4036257507478854844L; |
9 | 9 | ||
10 | @Getter private final HttpStatus httpStatus; | 10 | @Getter private final HttpStatus httpStatus; |
11 | 11 | ||
12 | @Getter private final ErrorMessage error; | 12 | @Getter private final ErrorMessage error; |
13 | 13 | ||
14 | - public YunTengException(ErrorMessage errorMessage) { | 14 | + |
15 | + public ThingsKitException(ErrorMessage errorMessage) { | ||
15 | super(errorMessage.getMessage()); | 16 | super(errorMessage.getMessage()); |
16 | - this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; | 17 | + this.httpStatus = HttpStatus.BAD_REQUEST; |
17 | this.error = errorMessage; | 18 | this.error = errorMessage; |
18 | } | 19 | } |
19 | 20 | ||
20 | - public YunTengException(ErrorMessage errorMessage, HttpStatus httpStatus) { | 21 | + public ThingsKitException(ErrorMessage errorMessage, HttpStatus httpStatus) { |
21 | super(errorMessage.getMessage()); | 22 | super(errorMessage.getMessage()); |
22 | this.httpStatus = httpStatus; | 23 | this.httpStatus = httpStatus; |
23 | this.error = errorMessage; | 24 | this.error = errorMessage; |
24 | } | 25 | } |
25 | 26 | ||
26 | - public YunTengException() { | 27 | + public ThingsKitException() { |
27 | super(ErrorMessage.INTERNAL_ERROR.getMessage()); | 28 | super(ErrorMessage.INTERNAL_ERROR.getMessage()); |
28 | this.error = ErrorMessage.INTERNAL_ERROR; | 29 | this.error = ErrorMessage.INTERNAL_ERROR; |
29 | this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; | 30 | this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; |
1 | package org.thingsboard.server.common.data.yunteng.core.exception; | 1 | package org.thingsboard.server.common.data.yunteng.core.exception; |
2 | 2 | ||
3 | import lombok.Getter; | 3 | import lombok.Getter; |
4 | +import org.springframework.http.HttpStatus; | ||
5 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
4 | 6 | ||
5 | -public class YtDataValidationException extends RuntimeException { | 7 | +public class YtDataValidationException extends ThingsKitException { |
6 | private static final long serialVersionUID = 3556952261254572635L; | 8 | private static final long serialVersionUID = 3556952261254572635L; |
7 | 9 | ||
8 | @Getter public boolean log = false; | 10 | @Getter public boolean log = false; |
9 | 11 | ||
10 | public YtDataValidationException(String message) { | 12 | public YtDataValidationException(String message) { |
11 | - super(message); | 13 | + super(ErrorMessage.BAD_PARAMETER.setMessage(message)); |
12 | } | 14 | } |
13 | 15 | ||
14 | public YtDataValidationException(String message, boolean log) { | 16 | public YtDataValidationException(String message, boolean log) { |
15 | - super(message); | 17 | + super(ErrorMessage.BAD_PARAMETER.setMessage(message)); |
16 | this.log = log; | 18 | this.log = log; |
17 | } | 19 | } |
18 | } | 20 | } |
@@ -51,7 +51,10 @@ public enum ErrorMessage { | @@ -51,7 +51,10 @@ public enum ErrorMessage { | ||
51 | ORGANIZATION_DEVICE_NOT_MATCHED_IN_ACTION(400032,"动作中存在设备不属于场景联动所在组织"), | 51 | ORGANIZATION_DEVICE_NOT_MATCHED_IN_ACTION(400032,"动作中存在设备不属于场景联动所在组织"), |
52 | ORGANIZATION_EXISTED_SCENE_REACT(400033,"组织被场景联动使用中"), | 52 | ORGANIZATION_EXISTED_SCENE_REACT(400033,"组织被场景联动使用中"), |
53 | ORGANIZATION_EXISTED_ALARM_CONTACT(400034,"组织被告警联系人使用中"), | 53 | ORGANIZATION_EXISTED_ALARM_CONTACT(400034,"组织被告警联系人使用中"), |
54 | - | 54 | + EXIST_LEADER_MEMBER_RELATION(400035,"上下级之间有一种关系"), |
55 | + FILE_NOT_FOUND(400036,"文件未找到"), | ||
56 | + STORE_FILE_FAILED(400037,"文件存储失败"), | ||
57 | + NOT_BELONG_CURRENT_TENANT(400038,"不属于当前租户"), | ||
55 | HAVE_NO_PERMISSION(500002,"没有修改权限"); | 58 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
56 | private final int code; | 59 | private final int code; |
57 | private String message; | 60 | private String message; |
@@ -16,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile; | @@ -16,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile; | ||
16 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | 16 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; |
17 | import org.thingsboard.server.common.data.yunteng.core.exception.FileNotFoundException; | 17 | import org.thingsboard.server.common.data.yunteng.core.exception.FileNotFoundException; |
18 | import org.thingsboard.server.common.data.yunteng.core.exception.FileStorageException; | 18 | import org.thingsboard.server.common.data.yunteng.core.exception.FileStorageException; |
19 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
19 | import org.thingsboard.server.common.data.yunteng.dto.FileUploadResponse; | 20 | import org.thingsboard.server.common.data.yunteng.dto.FileUploadResponse; |
20 | 21 | ||
21 | import javax.servlet.http.HttpServletRequest; | 22 | import javax.servlet.http.HttpServletRequest; |
@@ -69,8 +70,7 @@ public class LocalFileStorageService implements FileStorageService { | @@ -69,8 +70,7 @@ public class LocalFileStorageService implements FileStorageService { | ||
69 | } | 70 | } |
70 | // Check if the file's name contains invalid characters | 71 | // Check if the file's name contains invalid characters |
71 | if (fileName.contains("..")) { | 72 | if (fileName.contains("..")) { |
72 | - throw new FileStorageException( | ||
73 | - "Sorry! Filename contains invalid path sequence " + fileName); | 73 | + throw new FileStorageException(ErrorMessage.STORE_FILE_FAILED); |
74 | } | 74 | } |
75 | 75 | ||
76 | // Copy file to the target location (Replacing existing file with the same name) | 76 | // Copy file to the target location (Replacing existing file with the same name) |
@@ -79,7 +79,7 @@ public class LocalFileStorageService implements FileStorageService { | @@ -79,7 +79,7 @@ public class LocalFileStorageService implements FileStorageService { | ||
79 | 79 | ||
80 | return fileName; | 80 | return fileName; |
81 | } catch (IOException ex) { | 81 | } catch (IOException ex) { |
82 | - throw new FileStorageException("Could not store file " + fileName + ". Please try again!"); | 82 | + throw new FileStorageException(ErrorMessage.STORE_FILE_FAILED); |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
@@ -90,10 +90,10 @@ public class LocalFileStorageService implements FileStorageService { | @@ -90,10 +90,10 @@ public class LocalFileStorageService implements FileStorageService { | ||
90 | if (resource.exists()) { | 90 | if (resource.exists()) { |
91 | return resource; | 91 | return resource; |
92 | } else { | 92 | } else { |
93 | - throw new FileNotFoundException("File not found " + fileName); | 93 | + throw new FileNotFoundException(ErrorMessage.FILE_NOT_FOUND); |
94 | } | 94 | } |
95 | } catch (MalformedURLException ex) { | 95 | } catch (MalformedURLException ex) { |
96 | - throw new FileNotFoundException("File not found " + fileName); | 96 | + throw new FileNotFoundException(ErrorMessage.FILE_NOT_FOUND); |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 |
@@ -15,6 +15,7 @@ import org.springframework.web.context.request.RequestContextHolder; | @@ -15,6 +15,7 @@ import org.springframework.web.context.request.RequestContextHolder; | ||
15 | import org.springframework.web.context.request.ServletRequestAttributes; | 15 | import org.springframework.web.context.request.ServletRequestAttributes; |
16 | import org.springframework.web.multipart.MultipartFile; | 16 | import org.springframework.web.multipart.MultipartFile; |
17 | import org.thingsboard.server.common.data.yunteng.core.exception.FileStorageException; | 17 | import org.thingsboard.server.common.data.yunteng.core.exception.FileStorageException; |
18 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
18 | import org.thingsboard.server.common.data.yunteng.dto.FileUploadResponse; | 19 | import org.thingsboard.server.common.data.yunteng.dto.FileUploadResponse; |
19 | 20 | ||
20 | import javax.servlet.http.HttpServletRequest; | 21 | import javax.servlet.http.HttpServletRequest; |
@@ -59,7 +60,7 @@ public class MinioFileStorageService implements FileStorageService { | @@ -59,7 +60,7 @@ public class MinioFileStorageService implements FileStorageService { | ||
59 | } | 60 | } |
60 | // Check if the file's name contains invalid characters | 61 | // Check if the file's name contains invalid characters |
61 | if (fileName.contains("..")) { | 62 | if (fileName.contains("..")) { |
62 | - throw new FileStorageException("Sorry! Filename contains invalid path sequence " + fileName); | 63 | + throw new FileStorageException(ErrorMessage.STORE_FILE_FAILED); |
63 | } | 64 | } |
64 | 65 | ||
65 | // 储存 | 66 | // 储存 |
@@ -76,7 +77,7 @@ public class MinioFileStorageService implements FileStorageService { | @@ -76,7 +77,7 @@ public class MinioFileStorageService implements FileStorageService { | ||
76 | return fileName; | 77 | return fileName; |
77 | } catch (Exception ex) { | 78 | } catch (Exception ex) { |
78 | ex.printStackTrace(); | 79 | ex.printStackTrace(); |
79 | - throw new FileStorageException("Could not store file " + fileName + ". Please try again!"); | 80 | + throw new FileStorageException(ErrorMessage.STORE_FILE_FAILED); |
80 | } | 81 | } |
81 | } | 82 | } |
82 | 83 |
1 | package org.thingsboard.server.common.data.yunteng.dto; | 1 | package org.thingsboard.server.common.data.yunteng.dto; |
2 | 2 | ||
3 | +import io.swagger.annotations.ApiModelProperty; | ||
3 | import lombok.Data; | 4 | import lombok.Data; |
4 | 5 | ||
6 | +import javax.validation.constraints.NotEmpty; | ||
7 | + | ||
5 | @Data | 8 | @Data |
6 | public class AlarmProfileDTO extends TenantDTO { | 9 | public class AlarmProfileDTO extends TenantDTO { |
7 | - /** 告警联系人 通知多人“,”号分隔 */ | 10 | + @ApiModelProperty(value = "告警联系人 通知多人“,”号分隔",required = true) |
11 | + @NotEmpty(message = "告警联系人不能为空或空字符串") | ||
8 | private String alarmContactId; | 12 | private String alarmContactId; |
9 | - /** 设备配置ID */ | ||
10 | - private String deviceProfileId; | ||
11 | - /** 消息通知方式:多种方式“,”号分隔 MessageTypeEnum */ | 13 | + |
14 | + @ApiModelProperty(value ="消息通知方式:多种方式“,”号分隔 MessageTypeEnum",required = true) | ||
15 | + @NotEmpty(message = "消息通知方式不能为空或空字符串") | ||
12 | private String messageMode; | 16 | private String messageMode; |
17 | + | ||
18 | + @ApiModelProperty(value ="组织ID",required = true) | ||
19 | + @NotEmpty(message = "组织ID不能为空或空字符串") | ||
20 | + private String organizationId; | ||
21 | + | ||
22 | + @ApiModelProperty("状态:0禁用 1启用") | ||
23 | + private Integer status; | ||
24 | + | ||
25 | + @ApiModelProperty(value ="告警配置名称",required = true) | ||
26 | + @NotEmpty(message = "告警配置名称不能为空或空字符串") | ||
27 | + private String name; | ||
28 | + | ||
29 | + @ApiModelProperty("告警配置备注") | ||
30 | + private String remark; | ||
13 | } | 31 | } |
1 | package org.thingsboard.server.common.data.yunteng.dto; | 1 | package org.thingsboard.server.common.data.yunteng.dto; |
2 | 2 | ||
3 | +import io.swagger.annotations.ApiModelProperty; | ||
3 | import lombok.Data; | 4 | import lombok.Data; |
4 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | 5 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
5 | 6 | ||
@@ -18,4 +19,7 @@ public class DeleteDTO { | @@ -18,4 +19,7 @@ public class DeleteDTO { | ||
18 | message = "删除至少需要一个id", | 19 | message = "删除至少需要一个id", |
19 | groups = {DeleteGroup.class}) | 20 | groups = {DeleteGroup.class}) |
20 | private Set<String> ids; | 21 | private Set<String> ids; |
22 | + | ||
23 | + @ApiModelProperty("租户ID") | ||
24 | + private String tenantId; | ||
21 | } | 25 | } |
@@ -8,27 +8,23 @@ import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum; | @@ -8,27 +8,23 @@ import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum; | ||
8 | 8 | ||
9 | import java.util.List; | 9 | import java.util.List; |
10 | 10 | ||
11 | -/** | ||
12 | - * @Description 场景联动执行动作数据传输表 | ||
13 | - * @Author cxy | ||
14 | - * @Date 2021/11/24 17:32 | ||
15 | - */ | 11 | +/** @Description 场景联动执行动作数据传输表 @Author cxy @Date 2021/11/24 17:32 */ |
16 | @Data | 12 | @Data |
17 | @EqualsAndHashCode(callSuper = true) | 13 | @EqualsAndHashCode(callSuper = true) |
18 | -public class DoActionDTO extends TenantDTO{ | 14 | +public class DoActionDTO extends TenantDTO { |
19 | 15 | ||
20 | - @ApiModelProperty(value = "所属设备id") | ||
21 | - private String deviceId; | 16 | + @ApiModelProperty(value = "所属设备id") |
17 | + private String deviceId; | ||
22 | 18 | ||
19 | + @ApiModelProperty(value = "场景联动内容") | ||
20 | + private JsonNode doContext; | ||
23 | 21 | ||
22 | + @ApiModelProperty(value = "输出目标:设备,告警,其他") | ||
23 | + private ActionTypeEnum outTarget; | ||
24 | 24 | ||
25 | - @ApiModelProperty(value = "场景联动内容") | ||
26 | - private JsonNode doContext; | ||
27 | - | ||
28 | - @ApiModelProperty(value = "输出目标:设备,场景,其他") | ||
29 | - private ActionTypeEnum outTarget; | ||
30 | - | ||
31 | - @ApiModelProperty(value = "场景联动id") | ||
32 | - private String sceneLinkageId; | 25 | + @ApiModelProperty(value = "场景联动id") |
26 | + private String sceneLinkageId; | ||
33 | 27 | ||
28 | + @ApiModelProperty(value = "输出目标为告警才进行配置") | ||
29 | + private String alarmProfileId; | ||
34 | } | 30 | } |
@@ -12,6 +12,10 @@ public class AlarmProfile extends TenantBaseEntity { | @@ -12,6 +12,10 @@ public class AlarmProfile extends TenantBaseEntity { | ||
12 | 12 | ||
13 | private static final long serialVersionUID = -4922707705163155569L; | 13 | private static final long serialVersionUID = -4922707705163155569L; |
14 | private String alarmContactId; | 14 | private String alarmContactId; |
15 | - private String deviceProfileId; | 15 | + private String organizationId; |
16 | private String messageMode; | 16 | private String messageMode; |
17 | + private Integer status; | ||
18 | + private String name; | ||
19 | + private String remark; | ||
20 | + | ||
17 | } | 21 | } |
@@ -10,27 +10,24 @@ import org.apache.ibatis.type.EnumTypeHandler; | @@ -10,27 +10,24 @@ import org.apache.ibatis.type.EnumTypeHandler; | ||
10 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | 10 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
11 | import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum; | 11 | import org.thingsboard.server.common.data.yunteng.enums.ActionTypeEnum; |
12 | 12 | ||
13 | -/** | ||
14 | - * @Description 执行动作 @Author cxy @Date 2021/11/24 17:24 | ||
15 | - */ | 13 | +/** @Description 执行动作 @Author cxy @Date 2021/11/24 17:24 */ |
16 | @Data | 14 | @Data |
17 | @TableName(value = ModelConstants.Table.IOTFS_DO_ACTION_TABLE_NAME, autoResultMap = true) | 15 | @TableName(value = ModelConstants.Table.IOTFS_DO_ACTION_TABLE_NAME, autoResultMap = true) |
18 | @EqualsAndHashCode(callSuper = true) | 16 | @EqualsAndHashCode(callSuper = true) |
19 | public class DoAction extends TenantBaseEntity { | 17 | public class DoAction extends TenantBaseEntity { |
20 | 18 | ||
21 | - private static final long serialVersionUID = -5459834451418047957L; | 19 | + private static final long serialVersionUID = -5459834451418047957L; |
22 | 20 | ||
23 | - private String deviceId; | ||
24 | - @TableField(typeHandler = EnumTypeHandler.class) | ||
25 | - private ActionTypeEnum outTarget; | ||
26 | - /** | ||
27 | - * 场景联动内容 | ||
28 | - */ | ||
29 | - @TableField(typeHandler = JacksonTypeHandler.class) | ||
30 | - private JsonNode doContext; | 21 | + private String deviceId; |
31 | 22 | ||
32 | - /** | ||
33 | - * 场景联动id | ||
34 | - */ | ||
35 | - private String sceneLinkageId; | 23 | + @TableField(typeHandler = EnumTypeHandler.class) |
24 | + private ActionTypeEnum outTarget; | ||
25 | + /** 场景联动内容 */ | ||
26 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
27 | + private JsonNode doContext; | ||
28 | + | ||
29 | + /** 场景联动id */ | ||
30 | + private String sceneLinkageId; | ||
31 | + | ||
32 | + private String alarmProfileId; | ||
36 | } | 33 | } |
1 | package org.thingsboard.server.dao.yunteng.impl; | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | 2 | ||
3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
5 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | import lombok.RequiredArgsConstructor; | 6 | import lombok.RequiredArgsConstructor; |
5 | import lombok.extern.slf4j.Slf4j; | 7 | import lombok.extern.slf4j.Slf4j; |
6 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
9 | +import org.springframework.transaction.annotation.Transactional; | ||
10 | +import org.thingsboard.server.common.data.StringUtils; | ||
11 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.NoneTenantAssetException; | ||
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
14 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
7 | import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | 15 | import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; |
16 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
17 | +import org.thingsboard.server.common.data.yunteng.dto.DoActionDTO; | ||
18 | +import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; | ||
19 | +import org.thingsboard.server.common.data.yunteng.enums.RoleEnum; | ||
8 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | 20 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
21 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
9 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; | 22 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; |
23 | +import org.thingsboard.server.dao.yunteng.entities.Role; | ||
10 | import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; | 24 | import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; |
25 | +import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; | ||
11 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 26 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
12 | import org.thingsboard.server.dao.yunteng.service.AlarmProfileService; | 27 | import org.thingsboard.server.dao.yunteng.service.AlarmProfileService; |
28 | +import org.thingsboard.server.dao.yunteng.service.DoActionService; | ||
29 | +import org.thingsboard.server.dao.yunteng.service.YtOrganizationService; | ||
13 | 30 | ||
14 | -import java.util.List; | 31 | +import java.util.*; |
32 | +import java.util.stream.Collectors; | ||
15 | 33 | ||
16 | @Slf4j | 34 | @Slf4j |
17 | @Service | 35 | @Service |
18 | @RequiredArgsConstructor | 36 | @RequiredArgsConstructor |
19 | public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMapper, AlarmProfile> | 37 | public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMapper, AlarmProfile> |
20 | implements AlarmProfileService { | 38 | implements AlarmProfileService { |
39 | + | ||
40 | + private final DoActionService doActionService; | ||
41 | + | ||
42 | + private final UserOrganizationMappingServiceImpl userOrganizationMappingService; | ||
43 | + | ||
44 | + private final OrganizationMapper ytOrganizationMapper; | ||
45 | + | ||
46 | + @Override | ||
47 | + public YtPageData<AlarmProfileDTO> page( | ||
48 | + boolean isPtTenantAdmin, | ||
49 | + String tenantId, | ||
50 | + String currentUserId, | ||
51 | + Map<String, Object> queryMap) { | ||
52 | + List<String> organizationIds = null; | ||
53 | + if (null != queryMap.get("organizationId")) { | ||
54 | + String organizationId = (String) queryMap.get("organizationId"); | ||
55 | + List<OrganizationDTO> organizationList = | ||
56 | + ytOrganizationMapper.findOrganizationTreeList( | ||
57 | + tenantId, new HashSet<>(Arrays.asList(organizationId))); | ||
58 | + Set<String> ids = | ||
59 | + organizationList.stream() | ||
60 | + .map(organizationDTO -> organizationDTO.getId()) | ||
61 | + .collect(Collectors.toSet()); | ||
62 | + organizationIds = new ArrayList<>(ids); | ||
63 | + } else { | ||
64 | + if (!isPtTenantAdmin) { | ||
65 | + organizationIds = userOrganizationMappingService.getOrganizationIdsByUserId(currentUserId); | ||
66 | + } | ||
67 | + } | ||
68 | + IPage<AlarmProfile> alarmProfileIPage = | ||
69 | + baseMapper.selectPage( | ||
70 | + getPage(queryMap, "create_time", false), | ||
71 | + new QueryWrapper<AlarmProfile>() | ||
72 | + .lambda() | ||
73 | + .eq(queryMap.get("status") != null, AlarmProfile::getStatus, queryMap.get("status")) | ||
74 | + .eq(AlarmProfile::getTenantId, tenantId) | ||
75 | + .in(organizationIds != null, AlarmProfile::getOrganizationId, organizationIds) | ||
76 | + .like( | ||
77 | + queryMap.get("name") != null, | ||
78 | + AlarmProfile::getName, | ||
79 | + String.valueOf(queryMap.get("name")))); | ||
80 | + return getPageData(alarmProfileIPage, AlarmProfileDTO.class); | ||
81 | + } | ||
82 | + | ||
21 | @Override | 83 | @Override |
22 | public List<AlarmProfileDTO> findAlarmProfilesByContactId(String contactId, String tenantId) { | 84 | public List<AlarmProfileDTO> findAlarmProfilesByContactId(String contactId, String tenantId) { |
23 | return ReflectUtils.sourceToTarget( | 85 | return ReflectUtils.sourceToTarget( |
@@ -27,4 +89,47 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | @@ -27,4 +89,47 @@ public class AlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMap | ||
27 | .like(AlarmProfile::getAlarmContactId, contactId)), | 89 | .like(AlarmProfile::getAlarmContactId, contactId)), |
28 | AlarmProfileDTO.class); | 90 | AlarmProfileDTO.class); |
29 | } | 91 | } |
92 | + | ||
93 | + @Override | ||
94 | + @Transactional | ||
95 | + public AlarmProfileDTO saveOrUpdateAlarmProfile(AlarmProfileDTO alarmProfileDTO) { | ||
96 | + if (StringUtils.isNotEmpty(alarmProfileDTO.getId())) { | ||
97 | + AlarmProfile alarmProfile = baseMapper.selectById(alarmProfileDTO.getId()); | ||
98 | + if (null == alarmProfile) { | ||
99 | + throw new YtDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage()); | ||
100 | + } | ||
101 | + baseMapper.updateById(alarmProfileDTO.getEntity(AlarmProfile.class)); | ||
102 | + } else { | ||
103 | + baseMapper.insert(alarmProfileDTO.getEntity(AlarmProfile.class)); | ||
104 | + } | ||
105 | + return alarmProfileDTO; | ||
106 | + } | ||
107 | + | ||
108 | + @Override | ||
109 | + @Transactional | ||
110 | + public AlarmProfileDTO updateAlarmProFileStatus( | ||
111 | + String alarmProfileId, String tenantId, Integer status) { | ||
112 | + AlarmProfile alarmProfile = baseMapper.selectById(alarmProfileId); | ||
113 | + if (null == alarmProfile) { | ||
114 | + throw new YtDataValidationException(ErrorMessage.INTERNAL_ERROR.getMessage()); | ||
115 | + } | ||
116 | + if (!alarmProfile.getTenantId().equals(tenantId)) { | ||
117 | + throw new NoneTenantAssetException(ErrorMessage.NOT_BELONG_CURRENT_TENANT); | ||
118 | + } | ||
119 | + alarmProfile.setStatus(status); | ||
120 | + baseMapper.updateById(alarmProfile); | ||
121 | + return alarmProfile.getDTO(AlarmProfileDTO.class); | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + @Transactional | ||
126 | + public boolean deleteAlarmProFile(DeleteDTO deleteDTO) { | ||
127 | + // 如果有场景联动使用告警配置,则不能删除 | ||
128 | + List<DoActionDTO> list = | ||
129 | + doActionService.findDoActionByAlarmProfileIds(deleteDTO.getTenantId(), deleteDTO.getIds()); | ||
130 | + if (list.size() > FastIotConstants.MagicNumber.ZERO) { | ||
131 | + throw new YtDataValidationException(ErrorMessage.EXIST_LEADER_MEMBER_RELATION.getMessage()); | ||
132 | + } | ||
133 | + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | ||
134 | + } | ||
30 | } | 135 | } |
1 | package org.thingsboard.server.dao.yunteng.impl; | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | + | ||
2 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
4 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
6 | +import org.springframework.cglib.core.ReflectUtils; | ||
5 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
8 | +import org.thingsboard.server.common.data.yunteng.dto.DoActionDTO; | ||
6 | import org.thingsboard.server.dao.yunteng.entities.DoAction; | 9 | import org.thingsboard.server.dao.yunteng.entities.DoAction; |
10 | +import org.thingsboard.server.dao.yunteng.entities.TenantBaseEntity; | ||
7 | import org.thingsboard.server.dao.yunteng.mapper.DoActionMapper; | 11 | import org.thingsboard.server.dao.yunteng.mapper.DoActionMapper; |
8 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | 12 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
9 | import org.thingsboard.server.dao.yunteng.service.DoActionService; | 13 | import org.thingsboard.server.dao.yunteng.service.DoActionService; |
10 | 14 | ||
11 | import java.util.List; | 15 | import java.util.List; |
16 | +import java.util.Optional; | ||
17 | +import java.util.Set; | ||
18 | +import java.util.stream.Collectors; | ||
12 | 19 | ||
13 | -/** | ||
14 | - * @Description | ||
15 | - * @Author cxy | ||
16 | - * @Date 2021/12/6 20:23 | ||
17 | - */ | 20 | +/** @Description @Author cxy @Date 2021/12/6 20:23 */ |
18 | @Service | 21 | @Service |
19 | @RequiredArgsConstructor | 22 | @RequiredArgsConstructor |
20 | public class DoActionServiceImpl extends AbstractBaseService<DoActionMapper, DoAction> | 23 | public class DoActionServiceImpl extends AbstractBaseService<DoActionMapper, DoAction> |
21 | - implements DoActionService { | ||
22 | - private final DoActionMapper actionMapper; | ||
23 | - @Override | ||
24 | - public List<DoAction> getActions(String sceneId) { | ||
25 | - LambdaQueryWrapper filter = new QueryWrapper<DoAction>().lambda() | ||
26 | - .eq(DoAction::getSceneLinkageId,sceneId); | ||
27 | - return actionMapper.selectList(filter); | ||
28 | - } | 24 | + implements DoActionService { |
25 | + @Override | ||
26 | + public List<DoAction> getActions(String sceneId) { | ||
27 | + LambdaQueryWrapper filter = | ||
28 | + new QueryWrapper<DoAction>().lambda().eq(DoAction::getSceneLinkageId, sceneId); | ||
29 | + return baseMapper.selectList(filter); | ||
30 | + } | ||
29 | 31 | ||
32 | + @Override | ||
33 | + public List<DoActionDTO> findDoActionByAlarmProfileIds( | ||
34 | + String tenantId, Set<String> alarmProfileIds) { | ||
35 | + List<DoAction> doActions = | ||
36 | + baseMapper.selectList( | ||
37 | + new LambdaQueryWrapper<DoAction>() | ||
38 | + .eq(TenantBaseEntity::getTenantId, tenantId) | ||
39 | + .in(DoAction::getAlarmProfileId, alarmProfileIds)); | ||
40 | + return doActions.stream() | ||
41 | + .map(doAction -> doAction.getDTO(DoActionDTO.class)) | ||
42 | + .collect(Collectors.toList()); | ||
43 | + } | ||
30 | } | 44 | } |
1 | package org.thingsboard.server.dao.yunteng.impl; | 1 | package org.thingsboard.server.dao.yunteng.impl; |
2 | + | ||
2 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 3 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
3 | import com.baomidou.mybatisplus.core.metadata.IPage; | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
4 | import lombok.RequiredArgsConstructor; | 5 | import lombok.RequiredArgsConstructor; |
5 | import lombok.extern.slf4j.Slf4j; | 6 | import lombok.extern.slf4j.Slf4j; |
6 | import org.springframework.stereotype.Service; | 7 | import org.springframework.stereotype.Service; |
7 | import org.springframework.transaction.annotation.Transactional; | 8 | import org.springframework.transaction.annotation.Transactional; |
9 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | ||
8 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | 10 | import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; |
9 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | 11 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
10 | import org.thingsboard.server.common.data.yunteng.dto.SysDictDTO; | 12 | import org.thingsboard.server.common.data.yunteng.dto.SysDictDTO; |
@@ -48,7 +50,7 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi | @@ -48,7 +50,7 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi | ||
48 | 50 | ||
49 | @Override | 51 | @Override |
50 | @Transactional | 52 | @Transactional |
51 | - public SysDictDTO saveSysDict(SysDictDTO sysDictDTO,String tenantId) { | 53 | + public SysDictDTO saveSysDict(SysDictDTO sysDictDTO, String tenantId) { |
52 | // 新增之前先判断该租户是否已添加 | 54 | // 新增之前先判断该租户是否已添加 |
53 | SysDictDTO querySysDict = baseMapper.getDictInfoByCode(tenantId, sysDictDTO.getDictCode()); | 55 | SysDictDTO querySysDict = baseMapper.getDictInfoByCode(tenantId, sysDictDTO.getDictCode()); |
54 | if (querySysDict != null) { | 56 | if (querySysDict != null) { |
@@ -66,11 +68,9 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi | @@ -66,11 +68,9 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi | ||
66 | @Transactional | 68 | @Transactional |
67 | public boolean deleteSysDict(Set<String> sysDictIds) { | 69 | public boolean deleteSysDict(Set<String> sysDictIds) { |
68 | for (String id : sysDictIds) { | 70 | for (String id : sysDictIds) { |
69 | - List<SysDictItemDTO> sysDictItemDTO = | ||
70 | - sysDictItemMapper.getDictItemInfo(id,null); | ||
71 | - if (sysDictItemDTO != null) { | ||
72 | - throw new YtDataValidationException( | ||
73 | - "There is a relationship between superiors and subordinates"); | 71 | + List<SysDictItemDTO> sysDictItemDTO = sysDictItemMapper.getDictItemInfo(id, null); |
72 | + if (sysDictItemDTO != null && sysDictItemDTO.size() > FastIotConstants.MagicNumber.ZERO) { | ||
73 | + throw new YtDataValidationException(ErrorMessage.EXIST_LEADER_MEMBER_RELATION.getMessage()); | ||
74 | } | 74 | } |
75 | } | 75 | } |
76 | return baseMapper.deleteBatchIds(sysDictIds) > 0; | 76 | return baseMapper.deleteBatchIds(sysDictIds) > 0; |
@@ -78,7 +78,7 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi | @@ -78,7 +78,7 @@ public class SysDictServiceImpl extends AbstractBaseService<SysDictMapper, SysDi | ||
78 | 78 | ||
79 | @Override | 79 | @Override |
80 | @Transactional | 80 | @Transactional |
81 | - public SysDictDTO updateSysDict(SysDictDTO sysDictDTO,String tenantId) { | 81 | + public SysDictDTO updateSysDict(SysDictDTO sysDictDTO, String tenantId) { |
82 | SysDict sysDict = baseMapper.selectById(sysDictDTO.getId()); | 82 | SysDict sysDict = baseMapper.selectById(sysDictDTO.getId()); |
83 | sysDictDTO.copyToEntity(sysDict); | 83 | sysDictDTO.copyToEntity(sysDict); |
84 | sysDict.setTenantId(tenantId); | 84 | sysDict.setTenantId(tenantId); |
@@ -21,10 +21,7 @@ import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | @@ -21,10 +21,7 @@ import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
21 | import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; | 21 | import org.thingsboard.server.dao.yunteng.service.UserOrganizationMappingService; |
22 | import org.thingsboard.server.dao.yunteng.service.YtAlarmContactService; | 22 | import org.thingsboard.server.dao.yunteng.service.YtAlarmContactService; |
23 | 23 | ||
24 | -import java.util.ArrayList; | ||
25 | -import java.util.List; | ||
26 | -import java.util.Map; | ||
27 | -import java.util.Set; | 24 | +import java.util.*; |
28 | import java.util.stream.Collectors; | 25 | import java.util.stream.Collectors; |
29 | 26 | ||
30 | /** | 27 | /** |
@@ -165,7 +162,7 @@ public class YtAlarmContactServiceImpl extends AbstractBaseService<AlarmContactM | @@ -165,7 +162,7 @@ public class YtAlarmContactServiceImpl extends AbstractBaseService<AlarmContactM | ||
165 | String organizationId = (String) queryMap.get("organizationId"); | 162 | String organizationId = (String) queryMap.get("organizationId"); |
166 | queryMap.put("tenantId", tenantId); | 163 | queryMap.put("tenantId", tenantId); |
167 | if (StringUtils.isNotEmpty(organizationId)) { | 164 | if (StringUtils.isNotEmpty(organizationId)) { |
168 | - List<String> ids = new ArrayList<>(); | 165 | + Set<String> ids = new HashSet<>(); |
169 | ids.add(organizationId); | 166 | ids.add(organizationId); |
170 | // 查询该组织的所有子类 | 167 | // 查询该组织的所有子类 |
171 | List<OrganizationDTO> organizationDTOS = | 168 | List<OrganizationDTO> organizationDTOS = |
@@ -35,158 +35,76 @@ import java.util.*; | @@ -35,158 +35,76 @@ import java.util.*; | ||
35 | @Service | 35 | @Service |
36 | @RequiredArgsConstructor | 36 | @RequiredArgsConstructor |
37 | @Slf4j | 37 | @Slf4j |
38 | -public class YtDeviceProfileServiceImpl | ||
39 | - implements YtDeviceProfileService { | ||
40 | - | ||
41 | - private final DeviceMapper deviceMapper; | ||
42 | - private final AlarmProfileMapper alarmProfileMapper; | ||
43 | - private final CacheUtils cacheUtils; | ||
44 | - | ||
45 | - private final YtJpaDeviceProfileDao deviceProfileDao; | ||
46 | - | ||
47 | - @Override | ||
48 | - @Transactional | ||
49 | - public DeviceProfileDTO insertOrUpdate(String deviceProfileId, DeviceProfileDTO deviceProfileDTO) { | ||
50 | - if (StringUtils.isBlank(deviceProfileDTO.getId())) { | ||
51 | - return insert(deviceProfileId, deviceProfileDTO); | ||
52 | - } else { | ||
53 | - return update(deviceProfileDTO); | ||
54 | - } | ||
55 | - } | ||
56 | - | ||
57 | - private DeviceProfileDTO update(DeviceProfileDTO deviceProfileDTO) { | ||
58 | - | ||
59 | - // 如果原来不是TCP或者更新也不是TCP 那就需要check | ||
60 | -// if (!deviceProfile.getTransportType().equals(TransportTypeEnum.TCP) | ||
61 | -// || !deviceProfileDTO.getTransportType().equals(TransportTypeEnum.TCP)) { | ||
62 | -// checkDeviceProfile(deviceProfileDTO, deviceProfile); | ||
63 | -// } | ||
64 | - LambdaQueryWrapper<AlarmProfile> filter = new QueryWrapper<AlarmProfile>().lambda() | ||
65 | - .eq(AlarmProfile::getTenantId, deviceProfileDTO.getTenantId()) | ||
66 | - .eq(AlarmProfile::getDeviceProfileId, deviceProfileDTO.getId()); | ||
67 | - List<AlarmProfile> oldAlarms = alarmProfileMapper.selectList(filter); | ||
68 | - List<String> oldIds = new ArrayList<>(); | ||
69 | - for (AlarmProfile item : oldAlarms) { | ||
70 | - oldIds.add(item.getId()); | ||
71 | - } | ||
72 | - | ||
73 | - | ||
74 | - Optional.ofNullable(deviceProfileDTO.getAlarmProfile()) | ||
75 | -// .filter(alarmProfileDTO -> StringUtils.isNotBlank(alarmProfileDTO.getId())) | ||
76 | - .ifPresent(alarmProfileDTO -> { | ||
77 | - AlarmProfile alarmProfile = buildAlarmDto2Entity(deviceProfileDTO.getId(), deviceProfileDTO.getTenantId(), alarmProfileDTO); | ||
78 | - String alarmId = alarmProfileDTO.getId(); | ||
79 | - if (StringUtils.isNotBlank(alarmId)) { | ||
80 | - alarmProfileMapper.updateById(alarmProfile); | ||
81 | - oldIds.remove(alarmId); | ||
82 | - } | ||
83 | - { | ||
84 | - alarmProfileMapper.insert(alarmProfile); | ||
85 | - } | ||
86 | - }); | ||
87 | - if(!oldIds.isEmpty()){ | ||
88 | - alarmProfileMapper.deleteBatchIds(oldIds); | ||
89 | - } | ||
90 | - return deviceProfileDTO; | 38 | +public class YtDeviceProfileServiceImpl implements YtDeviceProfileService { |
39 | + | ||
40 | + private final DeviceMapper deviceMapper; | ||
41 | + | ||
42 | + private final YtJpaDeviceProfileDao deviceProfileDao; | ||
43 | + | ||
44 | + @Override | ||
45 | + public boolean validateFormdata(DeviceProfileDTO ytDeviceProfileDTO) { | ||
46 | + TenantId tenantId = new TenantId(UUID.fromString(ytDeviceProfileDTO.getTenantId())); | ||
47 | + if (StringUtils.isBlank(ytDeviceProfileDTO.getId())) { | ||
48 | + // 判断数据库是否已存在名字相同的设备配置 | ||
49 | + | ||
50 | + DeviceProfile profile = deviceProfileDao.findByName(tenantId, ytDeviceProfileDTO.getName()); | ||
51 | + if (profile != null) { | ||
52 | + throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | ||
53 | + } | ||
54 | + } else { | ||
55 | + UUID profileId = UUID.fromString(ytDeviceProfileDTO.getId()); | ||
56 | + DeviceProfile profile = deviceProfileDao.findById(tenantId, profileId); | ||
57 | + if (profile == null) { | ||
58 | + throw new YtDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | ||
59 | + } | ||
91 | } | 60 | } |
92 | 61 | ||
93 | - private DeviceProfileDTO insert(String deviceProfileId, DeviceProfileDTO deviceProfileDTO) { | ||
94 | - Optional.ofNullable(deviceProfileDTO.getAlarmProfile()) | ||
95 | - .map( | ||
96 | - alarmProfileDTO -> { | ||
97 | - AlarmProfile alarmProfile = buildAlarmDto2Entity(deviceProfileId, deviceProfileDTO.getTenantId(), alarmProfileDTO); | ||
98 | - alarmProfileMapper.insert(alarmProfile); | ||
99 | - alarmProfile.copyToDTO(alarmProfileDTO); | ||
100 | - return alarmProfileDTO; | ||
101 | - }); | ||
102 | - return deviceProfileDTO; | 62 | + return false; |
63 | + } | ||
64 | + | ||
65 | + @Override | ||
66 | + @Transactional | ||
67 | + public void checkDeviceProfiles(String tenantId, Set<String> ids) { | ||
68 | + // check if ids bind to device | ||
69 | + int count = | ||
70 | + deviceMapper.selectCount( | ||
71 | + new QueryWrapper<YtDevice>().lambda().in(YtDevice::getProfileId, ids)); | ||
72 | + if (count > 0) { | ||
73 | + throw new YtDataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置"); | ||
103 | } | 74 | } |
104 | - | ||
105 | - @NotNull | ||
106 | - private AlarmProfile buildAlarmDto2Entity(String deviceProfileId, String tenantId, AlarmProfileDTO alarmProfileDTO) { | ||
107 | - alarmProfileDTO.setDeviceProfileId(deviceProfileId); | ||
108 | - alarmProfileDTO.setTenantId(tenantId); | ||
109 | - AlarmProfile alarmProfile = new AlarmProfile(); | ||
110 | - alarmProfileDTO.copyToEntity(alarmProfile, ModelConstants.TablePropertyMapping.UPDATE_TIME, | ||
111 | - ModelConstants.TablePropertyMapping.UPDATER); | ||
112 | - return alarmProfile; | ||
113 | - } | ||
114 | - | ||
115 | - @Override | ||
116 | - public boolean validateFormdata(DeviceProfileDTO ytDeviceProfileDTO) { | ||
117 | - TenantId tenantId = new TenantId(UUID.fromString(ytDeviceProfileDTO.getTenantId())); | ||
118 | - if (StringUtils.isBlank(ytDeviceProfileDTO.getId())) { | ||
119 | - // 判断数据库是否已存在名字相同的设备配置 | ||
120 | - | ||
121 | - DeviceProfile profile = deviceProfileDao.findByName(tenantId, ytDeviceProfileDTO.getName()); | ||
122 | - if (profile != null) { | ||
123 | - throw new YtDataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | ||
124 | - } | ||
125 | - } else { | ||
126 | - UUID profileId = UUID.fromString(ytDeviceProfileDTO.getId()); | ||
127 | - DeviceProfile profile = deviceProfileDao.findById(tenantId, profileId); | ||
128 | - if (profile == null) { | ||
129 | - throw new YtDataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); | ||
130 | - } | ||
131 | - } | ||
132 | - | ||
133 | - return false; | ||
134 | - } | ||
135 | - | ||
136 | - @Override | ||
137 | - @Transactional | ||
138 | - public void deleteDeviceProfiles(String tenantId, Set<String> ids) { | ||
139 | - // check if ids bind to device | ||
140 | - int count = | ||
141 | - deviceMapper.selectCount(new QueryWrapper<YtDevice>().lambda().in(YtDevice::getProfileId, ids)); | ||
142 | - if (count > 0) { | ||
143 | - throw new YtDataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置"); | ||
144 | - } | ||
145 | - | ||
146 | - for (String id : ids) { | ||
147 | - Validator.validateId(UUID.fromString(id),"Incorrect device profile id to deal."); | ||
148 | - LambdaQueryWrapper filter = new LambdaQueryWrapper<AlarmProfile>() | ||
149 | - .eq(AlarmProfile::getTenantId, tenantId) | ||
150 | - .in(AlarmProfile::getDeviceProfileId, id); | ||
151 | - alarmProfileMapper.delete(filter); | ||
152 | - } | ||
153 | - | ||
154 | - } | ||
155 | - | ||
156 | - @Override | ||
157 | - public Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id) { | ||
158 | - TenantId tenant = new TenantId(UUID.fromString(tenantId)); | ||
159 | - DeviceProfile profile = deviceProfileDao.findById(tenant, UUID.fromString(id)); | ||
160 | - return Optional.ofNullable(profile).map(entity -> { | ||
161 | - DeviceProfileDTO result = ReflectUtils.getDeviceProfileDTO(entity); | ||
162 | - AlarmProfile alarmProfile = alarmProfileMapper.selectOne(new QueryWrapper<AlarmProfile>().lambda().eq(AlarmProfile::getDeviceProfileId, result.getId())); | ||
163 | - Optional.ofNullable(alarmProfile).ifPresent(alarmProfile1 -> { | ||
164 | - AlarmProfileDTO alarmProfileDTO = new AlarmProfileDTO(); | ||
165 | - BeanUtils.copyProperties(alarmProfile, alarmProfileDTO); | ||
166 | - result.setAlarmProfile(alarmProfileDTO); | 75 | + } |
76 | + | ||
77 | + @Override | ||
78 | + public Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id) { | ||
79 | + TenantId tenant = new TenantId(UUID.fromString(tenantId)); | ||
80 | + DeviceProfile profile = deviceProfileDao.findById(tenant, UUID.fromString(id)); | ||
81 | + return Optional.ofNullable(profile) | ||
82 | + .map( | ||
83 | + entity -> { | ||
84 | + DeviceProfileDTO result = ReflectUtils.getDeviceProfileDTO(entity); | ||
85 | + return result; | ||
167 | }); | 86 | }); |
168 | - | ||
169 | - return result; | ||
170 | - }); | ||
171 | - } | ||
172 | - | ||
173 | - @Override | ||
174 | - public YtPageData<DeviceProfileDTO> page(PageLink pageLink, String tenantIdStr, String transportType) { | ||
175 | - | ||
176 | - | ||
177 | - TenantId tenantId = new TenantId(UUID.fromString(tenantIdStr)); | ||
178 | - Validator.validatePageLink(pageLink); | ||
179 | - PageData<DeviceProfileDTO> tbDatas = deviceProfileDao.findDeviceProfileInfos(pageLink, tenantId, transportType); | ||
180 | - YtPageData<DeviceProfileDTO> result = new YtPageData<>(tbDatas.getData(), tbDatas.getTotalElements()); | ||
181 | - | ||
182 | - return result; | ||
183 | - } | ||
184 | - | ||
185 | - | ||
186 | - @Override | ||
187 | - public List<DeviceProfileDTO> findDeviceProfile(String tenantId) { | ||
188 | - UUID profileId = UUID.fromString(tenantId); | ||
189 | - List<DeviceProfileDTO> results = deviceProfileDao.findDeviceProfileByTenantId(new TenantId(profileId)); | ||
190 | - return results; | ||
191 | - } | 87 | + } |
88 | + | ||
89 | + @Override | ||
90 | + public YtPageData<DeviceProfileDTO> page( | ||
91 | + PageLink pageLink, String tenantIdStr, String transportType) { | ||
92 | + | ||
93 | + TenantId tenantId = new TenantId(UUID.fromString(tenantIdStr)); | ||
94 | + Validator.validatePageLink(pageLink); | ||
95 | + PageData<DeviceProfileDTO> tbDatas = | ||
96 | + deviceProfileDao.findDeviceProfileInfos(pageLink, tenantId, transportType); | ||
97 | + YtPageData<DeviceProfileDTO> result = | ||
98 | + new YtPageData<>(tbDatas.getData(), tbDatas.getTotalElements()); | ||
99 | + | ||
100 | + return result; | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public List<DeviceProfileDTO> findDeviceProfile(String tenantId) { | ||
105 | + UUID profileId = UUID.fromString(tenantId); | ||
106 | + List<DeviceProfileDTO> results = | ||
107 | + deviceProfileDao.findDeviceProfileByTenantId(new TenantId(profileId)); | ||
108 | + return results; | ||
109 | + } | ||
192 | } | 110 | } |
@@ -69,8 +69,9 @@ public class YtNoticeServiceImpl implements YtNoticeService { | @@ -69,8 +69,9 @@ public class YtNoticeServiceImpl implements YtNoticeService { | ||
69 | Organization organization = organizationMapper.selectOne(organizationQueryWrapper); | 69 | Organization organization = organizationMapper.selectOne(organizationQueryWrapper); |
70 | 70 | ||
71 | QueryWrapper<AlarmProfile> alarmProfileQueryWrapper = new QueryWrapper<AlarmProfile>(); | 71 | QueryWrapper<AlarmProfile> alarmProfileQueryWrapper = new QueryWrapper<AlarmProfile>(); |
72 | - alarmProfileQueryWrapper.lambda() | ||
73 | - .eq(AlarmProfile::getDeviceProfileId, device.getProfileId()); | 72 | + //TODO junlianglee 修改通知 |
73 | +// alarmProfileQueryWrapper.lambda() | ||
74 | +// .eq(AlarmProfile::getDeviceProfileId, device.getProfileId()); | ||
74 | AlarmProfile alarmProfile = alarmProfileMapper.selectOne(alarmProfileQueryWrapper); | 75 | AlarmProfile alarmProfile = alarmProfileMapper.selectOne(alarmProfileQueryWrapper); |
75 | 76 | ||
76 | 77 |
@@ -282,7 +282,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | @@ -282,7 +282,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> | ||
282 | public UserDTO updateUser(UserDTO userDTO, boolean isPtSysadmin, String tenantId) { | 282 | public UserDTO updateUser(UserDTO userDTO, boolean isPtSysadmin, String tenantId) { |
283 | User user = baseMapper.selectById(userDTO.getId()); | 283 | User user = baseMapper.selectById(userDTO.getId()); |
284 | if (!isPtSysadmin && !user.getTenantId().equals(tenantId)) { | 284 | if (!isPtSysadmin && !user.getTenantId().equals(tenantId)) { |
285 | - throw new NoneTenantAssetException("this user not belong to current tenant"); | 285 | + throw new NoneTenantAssetException(ErrorMessage.NOT_BELONG_CURRENT_TENANT); |
286 | } | 286 | } |
287 | if (!user.getUsername().equals(userDTO.getUsername())) { | 287 | if (!user.getUsername().equals(userDTO.getUsername())) { |
288 | throw new YtDataValidationException(ErrorMessage.USERNAME_IS_IMMUTABLE.getMessage()); | 288 | throw new YtDataValidationException(ErrorMessage.USERNAME_IS_IMMUTABLE.getMessage()); |
1 | package org.thingsboard.server.dao.yunteng.service; | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | ||
3 | import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | 3 | import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; |
4 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
5 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
4 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; | 6 | import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; |
5 | 7 | ||
6 | import java.util.List; | 8 | import java.util.List; |
9 | +import java.util.Map; | ||
7 | 10 | ||
8 | public interface AlarmProfileService extends BaseService<AlarmProfile> { | 11 | public interface AlarmProfileService extends BaseService<AlarmProfile> { |
12 | + | ||
13 | + YtPageData<AlarmProfileDTO> page( | ||
14 | + boolean isPtTenantAdmin, String tenantId, String currentUserId, Map<String, Object> queryMap); | ||
15 | + | ||
9 | List<AlarmProfileDTO> findAlarmProfilesByContactId(String contactId, String tenantId); | 16 | List<AlarmProfileDTO> findAlarmProfilesByContactId(String contactId, String tenantId); |
17 | + | ||
18 | + AlarmProfileDTO saveOrUpdateAlarmProfile(AlarmProfileDTO alarmProfileDTO); | ||
19 | + | ||
20 | + AlarmProfileDTO updateAlarmProFileStatus(String alarmProfileId, String tenantId, Integer status); | ||
21 | + | ||
22 | + boolean deleteAlarmProFile(DeleteDTO deleteDTO); | ||
10 | } | 23 | } |
1 | package org.thingsboard.server.dao.yunteng.service; | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | ||
3 | -import org.thingsboard.server.common.data.id.EntityId; | ||
4 | -import org.thingsboard.server.common.data.yunteng.dto.TriggerDTO; | 3 | +import org.thingsboard.server.common.data.yunteng.dto.DoActionDTO; |
5 | import org.thingsboard.server.dao.yunteng.entities.DoAction; | 4 | import org.thingsboard.server.dao.yunteng.entities.DoAction; |
6 | 5 | ||
7 | import java.util.List; | 6 | import java.util.List; |
7 | +import java.util.Set; | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * @Description | 10 | * @Description |
@@ -14,4 +14,6 @@ import java.util.List; | @@ -14,4 +14,6 @@ import java.util.List; | ||
14 | public interface DoActionService extends BaseService<DoAction>{ | 14 | public interface DoActionService extends BaseService<DoAction>{ |
15 | 15 | ||
16 | List<DoAction> getActions(String sceneId); | 16 | List<DoAction> getActions(String sceneId); |
17 | + | ||
18 | + List<DoActionDTO> findDoActionByAlarmProfileIds(String tenantId, Set<String> alarmProfileIds); | ||
17 | } | 19 | } |
@@ -9,9 +9,8 @@ import java.util.Optional; | @@ -9,9 +9,8 @@ import java.util.Optional; | ||
9 | import java.util.Set; | 9 | import java.util.Set; |
10 | 10 | ||
11 | public interface YtDeviceProfileService { | 11 | public interface YtDeviceProfileService { |
12 | - DeviceProfileDTO insertOrUpdate(String deviceProfileId, DeviceProfileDTO deviceProfileDTO); | ||
13 | 12 | ||
14 | - void deleteDeviceProfiles(String tenantId, Set<String> ids); | 13 | + void checkDeviceProfiles(String tenantId, Set<String> ids); |
15 | 14 | ||
16 | Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id); | 15 | Optional<DeviceProfileDTO> getDeviceProfile(String tenantId, String id); |
17 | 16 |
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | <result property="doContext" column="do_context" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> | 8 | <result property="doContext" column="do_context" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/> |
9 | <result property="outTarget" column="out_target" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> | 9 | <result property="outTarget" column="out_target" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> |
10 | <result property="sceneLinkageId" column="scene_linkage_id"/> | 10 | <result property="sceneLinkageId" column="scene_linkage_id"/> |
11 | + <result property="alarmProfileId" column="alarm_profile_id"/> | ||
11 | <result property="description" column="description"/> | 12 | <result property="description" column="description"/> |
12 | <result property="tenantId" column="tenant_id"/> | 13 | <result property="tenantId" column="tenant_id"/> |
13 | <result property="updater" column="updater"/> | 14 | <result property="updater" column="updater"/> |