Commit 70df6393ed9a85922030e8875c1ca97f8b1e8546
Merge branch 'ljl' into 'master'
refactor: 迁移代码 See merge request huang/thingsboard3.3.2!1
Showing
59 changed files
with
2887 additions
and
59 deletions
application/src/main/java/org/thingsboard/server/controller/yunteng/YtAlarmContactController.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.http.HttpStatus; | |
7 | +import org.springframework.http.ResponseEntity; | |
8 | +import org.springframework.validation.annotation.Validated; | |
9 | +import org.springframework.web.bind.annotation.*; | |
10 | +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | |
11 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
12 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
16 | +import org.thingsboard.server.controller.BaseController; | |
17 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmContactService; | |
18 | + | |
19 | +import java.net.URI; | |
20 | +import java.util.HashMap; | |
21 | +import java.util.List; | |
22 | +import java.util.Map; | |
23 | +import java.util.Optional; | |
24 | + | |
25 | +import static org.thingsboard.server.common.data.yunteng.constant.FastIotConstants.DefaultOrder.CREATE_TIME; | |
26 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | |
27 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; | |
28 | + | |
29 | +/** @Description 告警联系人 @Author cxy @Date 2021/11/2 14:54 */ | |
30 | +@RestController | |
31 | +@RequestMapping("/api/yt/alarmContact") | |
32 | +@RequiredArgsConstructor | |
33 | +@Api(value = "告警联系人") | |
34 | +public class YtAlarmContactController extends BaseController { | |
35 | + private final YtAlarmContactService alarmService; | |
36 | + | |
37 | + @ApiOperation(value = "新增告警联系人") | |
38 | + @PostMapping | |
39 | + public ResponseEntity<AlarmContactDTO> saveAlarmContact( | |
40 | + @Validated(AddGroup.class) @RequestBody AlarmContactDTO alarmContactDTO) throws ThingsboardException { | |
41 | + AlarmContactDTO newAlarmContactDTO = alarmService.saveAlarmContact(getCurrentUser().getCurrentTenantId(), alarmContactDTO); | |
42 | + return Optional.ofNullable(newAlarmContactDTO) | |
43 | + .map( | |
44 | + dto -> { | |
45 | + URI location = | |
46 | + ServletUriComponentsBuilder.fromCurrentRequest() | |
47 | + .path("/{id}") | |
48 | + .buildAndExpand(newAlarmContactDTO.getId()) | |
49 | + .toUri(); | |
50 | + return ResponseEntity.created(location).body(newAlarmContactDTO); | |
51 | + }) | |
52 | + .orElse(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build()); | |
53 | + } | |
54 | + | |
55 | + @ApiOperation(value = "查询全部告警联系人名单") | |
56 | + @PostMapping("/all") | |
57 | + public ResponseEntity<List<AlarmContactDTO>> findall(@RequestBody Map<String,Object> params) throws ThingsboardException { | |
58 | + | |
59 | + List<AlarmContactDTO> all = alarmService.findAll(getCurrentUser().getCurrentTenantId(), params); | |
60 | + return ResponseEntity.ok(all); | |
61 | + } | |
62 | + | |
63 | + @ApiOperation(value = "分页查询") | |
64 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
65 | + public PageData<AlarmContactDTO> pageAlarm( | |
66 | + @RequestParam(PAGE_SIZE) int pageSize, | |
67 | + @RequestParam(PAGE) int page, | |
68 | + @RequestParam(value = "username", required = false) String username, | |
69 | + @RequestParam(value = "organizationId", required = false) String organizationId, | |
70 | + @RequestParam(value = CREATE_TIME, required = false) String createtime) { | |
71 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
72 | + queryMap.put(PAGE_SIZE, pageSize); | |
73 | + queryMap.put(PAGE, page); | |
74 | + queryMap.put("username",username); | |
75 | + queryMap.put("organizationId",organizationId); | |
76 | + queryMap.put(CREATE_TIME, createtime); | |
77 | + | |
78 | + return alarmService.page(queryMap); | |
79 | + } | |
80 | + | |
81 | + @ApiOperation(value = "通过id来删除联系人") | |
82 | + @DeleteMapping | |
83 | + public void deleteById(@RequestBody String[] ids) { | |
84 | + if (ids.length == 0) { | |
85 | + throw new DataValidationException("please provide alarm ids to delete"); | |
86 | + } | |
87 | + alarmService.delete(ids); | |
88 | + } | |
89 | + | |
90 | + @ApiOperation(value = "修改告警联系人信息") | |
91 | + @PostMapping("/update") | |
92 | + public void update( @RequestBody AlarmContactDTO alarmContactDTO) { | |
93 | + | |
94 | + alarmService.update(alarmContactDTO); | |
95 | + } | |
96 | + | |
97 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtAlarmInfoController.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.web.bind.annotation.GetMapping; | |
7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
8 | +import org.springframework.web.bind.annotation.RequestParam; | |
9 | +import org.springframework.web.bind.annotation.RestController; | |
10 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
11 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
12 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmInfoService; | |
13 | + | |
14 | +import java.util.HashMap; | |
15 | + | |
16 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE; | |
17 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.PAGE_SIZE; | |
18 | + | |
19 | +/** | |
20 | + * @Description 告警中心 | |
21 | + * @Author cxy | |
22 | + * @Date 2021/11/11 9:23 | |
23 | + */ | |
24 | +@RestController | |
25 | +@RequestMapping("/api/yt/alarmInfo") | |
26 | +@RequiredArgsConstructor | |
27 | +@Api(value = "告警中心") | |
28 | +public class YtAlarmInfoController { | |
29 | + | |
30 | + private final YtAlarmInfoService alarmInfoService; | |
31 | + | |
32 | + /*@ApiOperation(value = "增加或修改告警中心") | |
33 | + @PostMapping | |
34 | + @PreAuthorize("hasRole('ROLE_TENANT_ADMIN')") | |
35 | + public ResponseEntity<AlarmInfoDTO> saveAlarmInfo(@RequestBody AlarmInfoDTO alarmInfoDto){ | |
36 | + | |
37 | + AlarmInfoDTO newalarmInfoDto = alarmInfoService.insertOrUpdate(alarmInfoDto); | |
38 | + return Optional.ofNullable(newalarmInfoDto) | |
39 | + .map( | |
40 | + dto -> { | |
41 | + URI location = | |
42 | + ServletUriComponentsBuilder.fromCurrentRequest() | |
43 | + .path("/{id}") | |
44 | + .buildAndExpand(newalarmInfoDto.getId()) | |
45 | + .toUri(); | |
46 | + return ResponseEntity.created(location).body(newalarmInfoDto); | |
47 | + }) | |
48 | + .orElse(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build()); | |
49 | + } | |
50 | + | |
51 | +*/ | |
52 | + //分页测试通过 | |
53 | + @ApiOperation(value="分页查询告警中心数据") | |
54 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
55 | + public PageData<AlarmInfoDTO> pageAlarmInfo( | |
56 | + @RequestParam(PAGE_SIZE) int pageSize, | |
57 | + @RequestParam(PAGE) int page, | |
58 | + @RequestParam(value = "sortProperty", required = false) String sortProperty, | |
59 | + @RequestParam(value = "status", required = false) String status, | |
60 | + @RequestParam(value = "sortOrder", required = false) String sortOrder, | |
61 | + @RequestParam(value = "searchStatus", required = false) String searchStatus, | |
62 | + @RequestParam(value = "textSearch", required = false) String textSearch, | |
63 | + @RequestParam(value = "startTime", required = false) String startTime, | |
64 | + @RequestParam(value = "fetchOriginator", required = false) String fetchOriginator, | |
65 | + @RequestParam(value = "endTime", required = false) String endTime){ | |
66 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
67 | + queryMap.put(PAGE_SIZE, pageSize); | |
68 | + queryMap.put(PAGE, page); | |
69 | + queryMap.put("sortProperty", sortProperty); | |
70 | + queryMap.put("sortOrder", sortOrder); | |
71 | + queryMap.put("searchStatus", searchStatus); | |
72 | + queryMap.put("status", status); | |
73 | + queryMap.put("textSearch", textSearch); | |
74 | + queryMap.put("startTime", startTime); | |
75 | + queryMap.put("endTime", endTime); | |
76 | + queryMap.put("fetchOriginator", fetchOriginator); | |
77 | + return alarmInfoService.page(queryMap); | |
78 | + } | |
79 | + /*@ApiOperation(value = "删除告警中心数据") | |
80 | + @DeleteMapping | |
81 | + public void deleteAlarmInfo(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO){ | |
82 | + | |
83 | + alarmInfoService.deleteAlarm(deleteDTO.getIds()); | |
84 | + }*/ | |
85 | + | |
86 | + | |
87 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtAlarmProfileController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.springframework.http.ResponseEntity; | |
5 | +import org.springframework.web.bind.annotation.*; | |
6 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
7 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | |
8 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
9 | +import org.thingsboard.server.controller.BaseController; | |
10 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmProfileService; | |
11 | + | |
12 | +@RestController | |
13 | +@RequestMapping("/api/yt/alarmProfile") | |
14 | +@RequiredArgsConstructor | |
15 | +public class YtAlarmProfileController extends BaseController { | |
16 | + private final YtAlarmProfileService alarmProfileService; | |
17 | + | |
18 | + @PostMapping | |
19 | + public ResponseEntity<AlarmProfileDTO> saveAlarmProfile( | |
20 | + @RequestBody AlarmProfileDTO alarmProfileDTO) throws ThingsboardException { | |
21 | + return ResponseEntity.ok(alarmProfileService.saveOrUpdateAlarmProfile(getCurrentUser().getCurrentTenantId(), alarmProfileDTO)); | |
22 | + } | |
23 | + | |
24 | + @DeleteMapping | |
25 | + public ResponseEntity<Boolean> deleteAlarmProfile( | |
26 | + @RequestBody DeleteDTO deleteDTO) { | |
27 | + return ResponseEntity.ok(alarmProfileService.deleteAlarmProfile(deleteDTO.getIds())); | |
28 | + } | |
29 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtCommonController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import io.swagger.annotations.ApiOperation; | |
4 | +import lombok.RequiredArgsConstructor; | |
5 | +import org.springframework.http.ResponseEntity; | |
6 | +import org.springframework.web.bind.annotation.GetMapping; | |
7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
8 | +import org.springframework.web.bind.annotation.RestController; | |
9 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
10 | +import org.thingsboard.server.common.data.yunteng.common.YtCommonService; | |
11 | +import org.thingsboard.server.controller.BaseController; | |
12 | + | |
13 | +@RequiredArgsConstructor | |
14 | +@RequestMapping("/api/yt/common") | |
15 | +@RestController | |
16 | +public class YtCommonController extends BaseController { | |
17 | + private final YtCommonService commonService; | |
18 | + | |
19 | + @GetMapping | |
20 | + @ApiOperation(value = "生成随机设备Token") | |
21 | + public ResponseEntity<String> generateDeviceToken() throws ThingsboardException { | |
22 | + return ResponseEntity.ok(commonService.generateDeviceToken(getCurrentUser().getCurrentTenantId())); | |
23 | + } | |
24 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtDeviceController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.apache.commons.lang3.StringUtils; | |
5 | +import org.springframework.http.HttpStatus; | |
6 | +import org.springframework.http.ResponseEntity; | |
7 | +import org.springframework.validation.annotation.Validated; | |
8 | +import org.springframework.web.bind.annotation.*; | |
9 | +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; | |
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
11 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
12 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | |
13 | +import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; | |
16 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceState; | |
17 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
18 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
19 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
20 | +import org.thingsboard.server.controller.BaseController; | |
21 | +import org.thingsboard.server.dao.yunteng.service.YtDeviceService; | |
22 | + | |
23 | +import java.net.URI; | |
24 | +import java.util.HashMap; | |
25 | +import java.util.Optional; | |
26 | + | |
27 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
28 | + | |
29 | +@RestController | |
30 | +@RequiredArgsConstructor | |
31 | +@RequestMapping("api/yt/device") | |
32 | +public class YtDeviceController extends BaseController { | |
33 | + private final YtDeviceService deviceService; | |
34 | + | |
35 | + @PostMapping | |
36 | + public ResponseEntity<DeviceDTO> saveDevice(@Validated(AddGroup.class)@RequestBody DeviceDTO deviceDTO) | |
37 | + throws FastIotException, ThingsboardException { | |
38 | + DeviceDTO newDeviceDTO = deviceService.insertOrUpdate(getCurrentUser().getCurrentTenantId(), deviceDTO); | |
39 | + return Optional.ofNullable(newDeviceDTO) | |
40 | + .map( | |
41 | + dto -> { | |
42 | + URI location = | |
43 | + ServletUriComponentsBuilder.fromCurrentRequest() | |
44 | + .path("/{id}") | |
45 | + .buildAndExpand(newDeviceDTO.getId()) | |
46 | + .toUri(); | |
47 | + return ResponseEntity.created(location).body(newDeviceDTO); | |
48 | + }) | |
49 | + .orElse(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build()); | |
50 | + } | |
51 | + | |
52 | + @GetMapping("{id}") | |
53 | + public ResponseEntity<DeviceDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException { | |
54 | + return ResponseEntity.of(deviceService.getDevice(getCurrentUser().getCurrentTenantId(), id)); | |
55 | + } | |
56 | + | |
57 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
58 | + public PageData<DeviceDTO> pageDevice( | |
59 | + @RequestParam(PAGE_SIZE) int pageSize, | |
60 | + @RequestParam(PAGE) int page, | |
61 | + @RequestParam(value = "name", required = false) String name, | |
62 | + @RequestParam(value = "deviceState", required = false) DeviceState deviceState, | |
63 | + @RequestParam(value = "deviceType", required = false) DeviceTypeEnum deviceType, | |
64 | + @RequestParam(value = "organizationId",required = false) String organizationId, | |
65 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
66 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
67 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
68 | + queryMap.put(PAGE_SIZE, pageSize); | |
69 | + queryMap.put(PAGE, page); | |
70 | + queryMap.put(ORDER_FILED, orderBy); | |
71 | + queryMap.put("name", name); | |
72 | + if (deviceState != null) { | |
73 | + queryMap.put("deviceState", deviceState.name()); | |
74 | + } | |
75 | + if (deviceType != null) { | |
76 | + queryMap.put("deviceType", deviceType.name()); | |
77 | + } | |
78 | + if(!StringUtils.isEmpty(organizationId)){ | |
79 | + queryMap.put("organizationId", organizationId); | |
80 | + } | |
81 | + if (orderType != null) { | |
82 | + queryMap.put(ORDER_TYPE, orderType.name()); | |
83 | + } | |
84 | + return deviceService.page(getCurrentUser().getCurrentTenantId(), queryMap); | |
85 | + } | |
86 | + | |
87 | + @DeleteMapping | |
88 | + public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | |
89 | + deviceService.deleteDevices(getCurrentUser().getCurrentTenantId(), deleteDTO.getIds()); | |
90 | + } | |
91 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtDeviceProfileController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.springframework.http.HttpStatus; | |
5 | +import org.springframework.http.ResponseEntity; | |
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.springframework.web.servlet.support.ServletUriComponentsBuilder; | |
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.core.exception.FastIotException; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
17 | +import org.thingsboard.server.controller.BaseController; | |
18 | +import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService; | |
19 | + | |
20 | +import java.net.URI; | |
21 | +import java.util.HashMap; | |
22 | +import java.util.List; | |
23 | +import java.util.Optional; | |
24 | + | |
25 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
26 | + | |
27 | +@RestController | |
28 | +@RequiredArgsConstructor | |
29 | +@RequestMapping("api/yt/deviceProfile") | |
30 | +public class YtDeviceProfileController extends BaseController { | |
31 | + private final YtDeviceProfileService deviceProfileService; | |
32 | + | |
33 | + @PostMapping | |
34 | + @PreAuthorize("hasRole('ROLE_TENANT_ADMIN')") | |
35 | + public ResponseEntity<DeviceProfileDTO> saveDeviceProfile( | |
36 | + @RequestBody DeviceProfileDTO deviceProfileDTO) throws FastIotException, ThingsboardException { | |
37 | + DeviceProfileDTO newDeviceProfileDTO = deviceProfileService.insertOrUpdate(getCurrentUser().getCurrentTenantId(), deviceProfileDTO); | |
38 | + return Optional.ofNullable(newDeviceProfileDTO) | |
39 | + .map( | |
40 | + dto -> { | |
41 | + URI location = | |
42 | + ServletUriComponentsBuilder.fromCurrentRequest() | |
43 | + .path("/{id}") | |
44 | + .buildAndExpand(newDeviceProfileDTO.getId()) | |
45 | + .toUri(); | |
46 | + return ResponseEntity.created(location).body(newDeviceProfileDTO); | |
47 | + }) | |
48 | + .orElse(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build()); | |
49 | + } | |
50 | + | |
51 | + @GetMapping("{id}") | |
52 | + public ResponseEntity<DeviceProfileDTO> getDevice(@PathVariable("id") String id) throws ThingsboardException { | |
53 | + return ResponseEntity.of(deviceProfileService.getDeviceProfile(getCurrentUser().getCurrentTenantId(), id)); | |
54 | + } | |
55 | + | |
56 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
57 | + public PageData<DeviceProfileDTO> pageDevice( | |
58 | + @RequestParam(PAGE_SIZE) int pageSize, | |
59 | + @RequestParam(PAGE) int page, | |
60 | + @RequestParam(value = "name", required = false) String name, | |
61 | + @RequestParam(value = "transportType", required = false) String transportType, | |
62 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
63 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
64 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
65 | + queryMap.put(PAGE_SIZE, pageSize); | |
66 | + queryMap.put(PAGE, page); | |
67 | + queryMap.put(ORDER_FILED, orderBy); | |
68 | + queryMap.put("transportType", transportType); | |
69 | + queryMap.put("name", name); | |
70 | + if (orderType != null) { | |
71 | + queryMap.put(ORDER_TYPE, orderType.name()); | |
72 | + } | |
73 | + return deviceProfileService.page(getCurrentUser().getCurrentTenantId(), queryMap); | |
74 | + } | |
75 | + | |
76 | + @DeleteMapping | |
77 | + public void deleteDevices(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) throws ThingsboardException { | |
78 | + deviceProfileService.deleteDeviceProfiles(getCurrentUser().getCurrentTenantId(), deleteDTO.getIds()); | |
79 | + } | |
80 | + | |
81 | + @GetMapping("/me") | |
82 | + public ResponseEntity<List<DeviceProfileDTO>> findCurrentTenantDeviceProfiles() throws ThingsboardException { | |
83 | + DeviceProfileDTO deviceProfileDTO = new DeviceProfileDTO(); | |
84 | + deviceProfileDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | |
85 | + return ResponseEntity.ok(deviceProfileService.findDeviceProfile(getCurrentUser().getCurrentTenantId(), deviceProfileDTO)); | |
86 | + } | |
87 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtDeviceTypeController.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 io.swagger.annotations.ApiParam; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import org.springframework.http.ResponseEntity; | |
8 | +import org.springframework.validation.annotation.Validated; | |
9 | +import org.springframework.web.bind.annotation.*; | |
10 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
11 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
12 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | |
13 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceTypeDTO; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | |
17 | +import org.thingsboard.server.controller.BaseController; | |
18 | +import org.thingsboard.server.dao.yunteng.service.YtDeviceTypeService; | |
19 | + | |
20 | +import java.util.List; | |
21 | + | |
22 | +@RestController | |
23 | +@RequestMapping("api/yt/device_type") | |
24 | +@RequiredArgsConstructor | |
25 | +@Api(value = "设备类型") | |
26 | +public class YtDeviceTypeController extends BaseController { | |
27 | + private final YtDeviceTypeService deviceTypeService; | |
28 | + | |
29 | + @GetMapping | |
30 | + @ApiOperation(value = "获取当前用户的设备类型树形") | |
31 | + @ApiParam(name = "tenantCode",value = "租户Code") | |
32 | + public ResponseEntity<List<DeviceTypeDTO>> getDeviceTypeTree(String tenantCode){ | |
33 | + return ResponseEntity.ok(deviceTypeService.getDeviceTypeTree(tenantCode)); | |
34 | + } | |
35 | + | |
36 | + @PostMapping | |
37 | + @ApiOperation(value = "保存设备类型") | |
38 | + public ResponseEntity<DeviceTypeDTO> saveDeviceType( | |
39 | + @Validated({AddGroup.class}) @RequestBody DeviceTypeDTO deviceTypeDTO) throws ThingsboardException { | |
40 | + return ResponseEntity.ok(deviceTypeService.saveDeviceTye(getCurrentUser().getCurrentTenantId(), deviceTypeDTO)); | |
41 | + } | |
42 | + | |
43 | + @PutMapping | |
44 | + @ApiOperation(value = "修改设备类型") | |
45 | + public ResponseEntity<DeviceTypeDTO> updateDeviceType( | |
46 | + @Validated({UpdateGroup.class}) @RequestBody DeviceTypeDTO deviceTypeDTO) { | |
47 | + return ResponseEntity.ok(deviceTypeService.updateDeviceType(deviceTypeDTO)); | |
48 | + } | |
49 | + | |
50 | + @DeleteMapping | |
51 | + @ApiOperation(value = "删除设备类型") | |
52 | + public ResponseResult<Boolean> deleteDeviceType( | |
53 | + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) { | |
54 | + return ResponseResult.success(deviceTypeService.deleteDeviceType(deleteDTO)); | |
55 | + } | |
56 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtMailLogController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.springframework.web.bind.annotation.*; | |
5 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
6 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
7 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
8 | +import org.thingsboard.server.common.data.yunteng.dto.MailLogDTO; | |
9 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
10 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
11 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | |
12 | +import org.thingsboard.server.controller.BaseController; | |
13 | +import org.thingsboard.server.dao.yunteng.service.YtMailLogService; | |
14 | + | |
15 | +import java.util.HashMap; | |
16 | + | |
17 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
18 | + | |
19 | +@RestController | |
20 | +@RequestMapping("api/yt/mailLog") | |
21 | +@RequiredArgsConstructor | |
22 | +public class YtMailLogController extends BaseController { | |
23 | + | |
24 | + private final YtMailLogService mailLogService; | |
25 | + | |
26 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
27 | + public PageData<MailLogDTO> pageMessageConfig( | |
28 | + @RequestParam(PAGE_SIZE) int pageSize, | |
29 | + @RequestParam(PAGE) int page, | |
30 | + @RequestParam(value = "emailSubject", required = false) String emailSubject, | |
31 | + @RequestParam(value = "startTime", required = false) String startTime, | |
32 | + @RequestParam(value = "endTime", required = false) String endTime, | |
33 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
34 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
35 | + | |
36 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
37 | + queryMap.put(PAGE_SIZE, pageSize); | |
38 | + queryMap.put(PAGE, page); | |
39 | + queryMap.put(ORDER_FILED, orderBy); | |
40 | + queryMap.put("emailSubject", emailSubject); | |
41 | + queryMap.put("startTime", startTime); | |
42 | + queryMap.put("endTime", endTime); | |
43 | + if (orderType != null) { | |
44 | + queryMap.put(ORDER_TYPE, orderType.name()); | |
45 | + } | |
46 | + return mailLogService.page(getCurrentUser().getCurrentTenantId(), queryMap); | |
47 | + } | |
48 | + | |
49 | + @DeleteMapping | |
50 | + public ResponseResult<String> deleteMailLog(@RequestBody DeleteDTO deleteDTO) { | |
51 | + return mailLogService.deleteMailLog(deleteDTO.getIds()) | |
52 | + ? ResponseResult.success(FastIotConstants.StateValue.DELETE_SUCCESS) | |
53 | + : ResponseResult.failed(FastIotConstants.StateValue.DELETE_FAILED); | |
54 | + } | |
55 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtMessageConfigController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.springframework.http.ResponseEntity; | |
5 | +import org.springframework.validation.annotation.Validated; | |
6 | +import org.springframework.web.bind.annotation.*; | |
7 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
8 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
9 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | |
10 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | |
11 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
12 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.MessageConfigDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
15 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | |
17 | +import org.thingsboard.server.controller.BaseController; | |
18 | +import org.thingsboard.server.dao.yunteng.service.YtMessageConfigService; | |
19 | + | |
20 | +import java.util.HashMap; | |
21 | +import java.util.List; | |
22 | + | |
23 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
24 | + | |
25 | +@RestController | |
26 | +@RequestMapping("api/yt/message") | |
27 | +@RequiredArgsConstructor | |
28 | +public class YtMessageConfigController extends BaseController { | |
29 | + | |
30 | + private final YtMessageConfigService messageConfigService; | |
31 | + | |
32 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
33 | + public PageData<MessageConfigDTO> pageMessageConfig( | |
34 | + @RequestParam(PAGE_SIZE) int pageSize, | |
35 | + @RequestParam(PAGE) int page, | |
36 | + @RequestParam(value = "platformType", required = false) String platformType, | |
37 | + @RequestParam(value = "messageType", required = false) String messageType, | |
38 | + @RequestParam(value = "status", required = false) Integer status, | |
39 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
40 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
41 | + | |
42 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
43 | + queryMap.put(PAGE_SIZE, pageSize); | |
44 | + queryMap.put(PAGE, page); | |
45 | + queryMap.put(ORDER_FILED, orderBy); | |
46 | + queryMap.put("platformType", platformType); | |
47 | + queryMap.put("messageType", messageType); | |
48 | + queryMap.put("status",status); | |
49 | + if (orderType != null) { | |
50 | + queryMap.put(ORDER_TYPE, orderType.name()); | |
51 | + } | |
52 | + return messageConfigService.page(getCurrentUser().getCurrentTenantId(),queryMap); | |
53 | + } | |
54 | + | |
55 | + @PostMapping | |
56 | + public ResponseResult<MessageConfigDTO> saveMessageConfig( | |
57 | + @Validated({AddGroup.class})@RequestBody MessageConfigDTO configDTO) throws ThingsboardException { | |
58 | + MessageConfigDTO newDTO = messageConfigService.saveMessageConfig(getCurrentUser().getCurrentTenantId(),configDTO); | |
59 | + return ResponseResult.success(newDTO); | |
60 | + } | |
61 | + | |
62 | + @GetMapping("/{id}") | |
63 | + public ResponseResult<MessageConfigDTO> findMessageConfigById(@PathVariable String id){ | |
64 | + return ResponseResult.success(messageConfigService.findMessageConfigById(id)); | |
65 | + } | |
66 | + @DeleteMapping | |
67 | + public ResponseResult<String> deleteMessageConfig(@Validated({DeleteGroup.class})@RequestBody DeleteDTO deleteDTO) { | |
68 | + return messageConfigService.deleteMessageConfig(deleteDTO.getIds()) | |
69 | + ? ResponseResult.success(FastIotConstants.StateValue.DELETE_SUCCESS) | |
70 | + : ResponseResult.failed(FastIotConstants.StateValue.DELETE_FAILED); | |
71 | + } | |
72 | + | |
73 | + @PutMapping | |
74 | + public MessageConfigDTO updateMessageConfig(@Validated({UpdateGroup.class})@RequestBody MessageConfigDTO configDTO) throws ThingsboardException { | |
75 | + return messageConfigService.updateMessageConfig(getCurrentUser().getCurrentTenantId(), configDTO); | |
76 | + } | |
77 | + | |
78 | + @PostMapping("/find") | |
79 | + public ResponseEntity<List<MessageConfigDTO>> findMessageInfo(@RequestBody MessageConfigDTO configDTO){ | |
80 | + return ResponseEntity.ok(messageConfigService.findMessageInfo(configDTO)); | |
81 | + } | |
82 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtMessageTemplateController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.springframework.util.Assert; | |
5 | +import org.springframework.validation.annotation.Validated; | |
6 | +import org.springframework.web.bind.annotation.*; | |
7 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
8 | +import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; | |
9 | +import org.thingsboard.server.common.data.yunteng.common.UpdateGroup; | |
10 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
11 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
12 | +import org.thingsboard.server.common.data.yunteng.dto.MessageTemplateDTO; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
16 | +import org.thingsboard.server.common.data.yunteng.enums.ResponseCodeEnum; | |
17 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
18 | +import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; | |
19 | +import org.thingsboard.server.dao.yunteng.service.YtMailService; | |
20 | +import org.thingsboard.server.dao.yunteng.service.YtMessageTemplateService; | |
21 | +import org.thingsboard.server.dao.yunteng.service.YtSmsService; | |
22 | + | |
23 | +import java.util.HashMap; | |
24 | + | |
25 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
26 | + | |
27 | +@RestController | |
28 | +@RequestMapping("api/yt/template") | |
29 | +@RequiredArgsConstructor | |
30 | +public class YtMessageTemplateController { | |
31 | + | |
32 | + private final YtMessageTemplateService messageTemplateService; | |
33 | + | |
34 | + private final YtSmsService smsService; | |
35 | + | |
36 | + private final YtMailService mailService; | |
37 | + | |
38 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | |
39 | + public PageData<MessageTemplateDTO> pageMessageTemplate( | |
40 | + @RequestParam(PAGE_SIZE) int pageSize, | |
41 | + @RequestParam(PAGE) int page, | |
42 | + @RequestParam(value = "templateCode", required = false) String templateCode, | |
43 | + @RequestParam(value = "templateName", required = false) String templateName, | |
44 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
45 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) { | |
46 | + | |
47 | + HashMap<String, Object> queryMap = new HashMap<>(); | |
48 | + queryMap.put(PAGE_SIZE, pageSize); | |
49 | + queryMap.put(PAGE, page); | |
50 | + queryMap.put(ORDER_FILED, orderBy); | |
51 | + queryMap.put("templateCode", templateCode); | |
52 | + queryMap.put("templateName", templateName); | |
53 | + if (orderType != null) { | |
54 | + queryMap.put(ORDER_TYPE, orderType.name()); | |
55 | + } | |
56 | + return messageTemplateService.page(queryMap); | |
57 | + } | |
58 | + | |
59 | + @PostMapping | |
60 | + public ResponseResult<MessageTemplateDTO> saveMessageTemplate( | |
61 | + @Validated({AddGroup.class}) @RequestBody MessageTemplateDTO templateDTO) { | |
62 | + MessageTemplateDTO newDTO = messageTemplateService.saveMessageTemplate(templateDTO); | |
63 | + return ResponseResult.success(newDTO); | |
64 | + } | |
65 | + | |
66 | + @DeleteMapping | |
67 | + public ResponseResult<String> deleteMessageTemplate( | |
68 | + @Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO) { | |
69 | + return messageTemplateService.deleteMessageTemplate(deleteDTO.getIds()) | |
70 | + ? ResponseResult.success(FastIotConstants.StateValue.DELETE_SUCCESS) | |
71 | + : ResponseResult.failed(FastIotConstants.StateValue.DELETE_FAILED); | |
72 | + } | |
73 | + | |
74 | + @PutMapping | |
75 | + public MessageTemplateDTO updateMessageTemplate( | |
76 | + @Validated({UpdateGroup.class}) @RequestBody MessageTemplateDTO templateDTO) { | |
77 | + Assert.notNull(templateDTO.getId(), "messageTemplate id cannot be null"); | |
78 | + return messageTemplateService.updateMessageTemplate(templateDTO); | |
79 | + } | |
80 | + | |
81 | + @PostMapping("/sendSms") | |
82 | + public ResponseResult<String> sendSms( | |
83 | + @Validated({AddGroup.class}) @RequestBody SmsReqDTO smsReqDTO) { | |
84 | + boolean result = smsService.sendSms(smsReqDTO); | |
85 | + String message = result ? ResponseCodeEnum.SUCCESS.name() : ResponseCodeEnum.FAILED.name(); | |
86 | + return ResponseResult.success(message); | |
87 | + } | |
88 | + | |
89 | + @PostMapping("/sendEmail") | |
90 | + public ResponseResult<String> sendEmail( | |
91 | + @Validated({AddGroup.class}) @RequestBody EmailReqDTO emailReqDTO) { | |
92 | + boolean result = mailService.sendEmail(emailReqDTO); | |
93 | + String message = result ? ResponseCodeEnum.SUCCESS.name() : ResponseCodeEnum.FAILED.name(); | |
94 | + return ResponseResult.success(message); | |
95 | + } | |
96 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtNoAuthController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import org.springframework.util.Assert; | |
5 | +import org.springframework.web.bind.annotation.PathVariable; | |
6 | +import org.springframework.web.bind.annotation.PostMapping; | |
7 | +import org.springframework.web.bind.annotation.RequestMapping; | |
8 | +import org.springframework.web.bind.annotation.RestController; | |
9 | +import org.thingsboard.server.dao.yunteng.service.YtSmsService; | |
10 | + | |
11 | +import static org.thingsboard.server.common.data.yunteng.constant.FastIotConstants.CHINA_MOBILE_PATTERN; | |
12 | + | |
13 | +@RestController | |
14 | +@RequestMapping("api/yt/noauth") | |
15 | +@RequiredArgsConstructor | |
16 | +public class YtNoAuthController { | |
17 | + | |
18 | + private final YtSmsService smsService; | |
19 | + | |
20 | + @PostMapping("/sendLoginSmsCode/{phoneNumber}") | |
21 | + public boolean sendVerificationCode(@PathVariable("phoneNumber") String phoneNumber) { | |
22 | + Assert.isTrue( | |
23 | + CHINA_MOBILE_PATTERN.matcher(phoneNumber).matches(), "please input correct phone number"); | |
24 | + return smsService.sendLoginSmsCode(phoneNumber); | |
25 | + } | |
26 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/controller/yunteng/YtNoticeController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | |
2 | + | |
3 | +import io.jsonwebtoken.*; | |
4 | +import lombok.RequiredArgsConstructor; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.springframework.security.authentication.BadCredentialsException; | |
7 | +import org.springframework.util.Assert; | |
8 | +import org.springframework.web.bind.annotation.*; | |
9 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
10 | +import org.thingsboard.server.dao.yunteng.service.YtNoticeService; | |
11 | +import org.thingsboard.server.service.security.exception.JwtExpiredTokenException; | |
12 | + | |
13 | +import java.net.InetAddress; | |
14 | + | |
15 | +/** | |
16 | + * @version V1.0 | |
17 | + * @Description : | |
18 | + * 1.其它地方抛出异常,交由控制层统一处理 | |
19 | + * 2.服务层注意持久化的事务管理 | |
20 | + * @Dependency: 依赖包 | |
21 | + * @Author: junlianglee | |
22 | + * @Date Created in 2021/11/23$ | |
23 | + * @Copyright 2016-2018 - Powered By 云腾五洲 | |
24 | + */ | |
25 | +@RestController | |
26 | +@RequestMapping("/api/yt/notice") | |
27 | +@RequiredArgsConstructor | |
28 | +@Slf4j | |
29 | +public class YtNoticeController { | |
30 | + | |
31 | + private final YtNoticeService service; | |
32 | + | |
33 | + @PostMapping("/alert") | |
34 | + public void alermNotice(@RequestParam(value = "token", required = true) String token, | |
35 | + @RequestBody AlarmInfoDTO alarmInfo){ | |
36 | + Assert.notNull(token, "token cannot be null"); | |
37 | + Assert.notNull(alarmInfo, "alarm info cannot be null"); | |
38 | + if(parseTokenClaims(token,alarmInfo)){ | |
39 | + service.alert(token,alarmInfo); | |
40 | + } | |
41 | + } | |
42 | + | |
43 | + | |
44 | + | |
45 | + private boolean parseTokenClaims(String token,AlarmInfoDTO alarmInfo) { | |
46 | + try { | |
47 | + Claims claims = Jwts.parser() | |
48 | + .setSigningKey(alarmInfo.getSeverity()) | |
49 | + .parseClaimsJws(token) | |
50 | + .getBody(); | |
51 | + if(claims.get("deviceId").equals(alarmInfo.getDeviceId()) | |
52 | + &&claims.get("tenantId").equals(alarmInfo.getTenantId()) | |
53 | + &&claims.get("ip").equals(InetAddress.getLocalHost().getHostAddress())){ | |
54 | + return true; | |
55 | + } | |
56 | + return false; | |
57 | + } catch (UnsupportedJwtException | MalformedJwtException | IllegalArgumentException | SignatureException ex) { | |
58 | + log.debug("Invalid JWT Token", ex); | |
59 | + throw new BadCredentialsException("Invalid JWT token: ", ex); | |
60 | + } catch (ExpiredJwtException expiredEx) { | |
61 | + log.debug("JWT Token is expired", expiredEx); | |
62 | + throw new JwtExpiredTokenException(expiredEx.getMessage()); | |
63 | + } catch (Exception e) { | |
64 | + log.error("not allowed send notice",e); | |
65 | + } | |
66 | + return false; | |
67 | + } | |
68 | +} | ... | ... |
... | ... | @@ -17,7 +17,6 @@ package org.thingsboard.server.dao.device; |
17 | 17 | |
18 | 18 | import org.thingsboard.server.common.data.DeviceProfile; |
19 | 19 | import org.thingsboard.server.common.data.DeviceProfileInfo; |
20 | -import org.thingsboard.server.common.data.EntityInfo; | |
21 | 20 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
22 | 21 | import org.thingsboard.server.common.data.id.TenantId; |
23 | 22 | import org.thingsboard.server.common.data.page.PageData; | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/common/YtCommonService.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/common/CommonService.java
... | ... | @@ -2,7 +2,7 @@ package org.thingsboard.server.common.data.yunteng.common; |
2 | 2 | |
3 | 3 | import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO; |
4 | 4 | |
5 | -public interface CommonService { | |
5 | +public interface YtCommonService { | |
6 | 6 | /** |
7 | 7 | * 通过dict表的Code和dictItem的codeText查询字典表的值 |
8 | 8 | * | ... | ... |
... | ... | @@ -12,7 +12,7 @@ import org.aspectj.lang.annotation.Aspect; |
12 | 12 | import org.aspectj.lang.annotation.Pointcut; |
13 | 13 | import org.springframework.stereotype.Component; |
14 | 14 | import org.thingsboard.common.util.JacksonUtil; |
15 | -import org.thingsboard.server.common.data.yunteng.common.CommonService; | |
15 | +import org.thingsboard.server.common.data.yunteng.common.YtCommonService; | |
16 | 16 | import org.thingsboard.server.common.data.yunteng.common.aspect.annotation.AutoDict; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO; |
18 | 18 | import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
... | ... | @@ -31,7 +31,7 @@ import java.util.List; |
31 | 31 | @RequiredArgsConstructor |
32 | 32 | public class SysDictAspect { |
33 | 33 | |
34 | - private final CommonService commonService; | |
34 | + private final YtCommonService commonService; | |
35 | 35 | |
36 | 36 | /** 表对应字段加上_dictText即可显示出文本 */ |
37 | 37 | private static final String DICT_TEXT_SUFFIX = "DictText"; | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/AlarmContactDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonInclude; | |
4 | +import io.swagger.annotations.ApiModelProperty; | |
5 | +import lombok.Data; | |
6 | +import lombok.EqualsAndHashCode; | |
7 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
8 | + | |
9 | +import javax.validation.constraints.NotEmpty; | |
10 | + | |
11 | +/** | |
12 | + * @Description 告警联系人实体表返回给前端视图 | |
13 | + * @Author cxy | |
14 | + * @Date 2021/11/2 13:49 | |
15 | + */ | |
16 | +@Data | |
17 | +@EqualsAndHashCode(callSuper = false) | |
18 | +public class AlarmContactDTO extends TenantDTO { | |
19 | + | |
20 | + @ApiModelProperty(value = "用户名", required = true) | |
21 | + @NotEmpty(message = "用户名不能为空或字符串", groups = AddGroup.class) | |
22 | + private String username; | |
23 | + | |
24 | + @ApiModelProperty(value = "组织") | |
25 | + private String organizationId; | |
26 | + | |
27 | + @NotEmpty(message = "电话不能为空或字符串", groups = AddGroup.class) | |
28 | + @ApiModelProperty(value = "电话", required = true) | |
29 | + private String phone; | |
30 | + | |
31 | + @ApiModelProperty(value = "电子邮件") | |
32 | + private String email; | |
33 | + | |
34 | + @ApiModelProperty(value = "微信") | |
35 | + private String wechat; | |
36 | + | |
37 | + @ApiModelProperty(value = "钉钉") | |
38 | + private String dingtalk; | |
39 | + /** | |
40 | + * Include.NON_NULL 属性为NULL 不序列化 ,不显示出字段 | |
41 | + */ | |
42 | + @ApiModelProperty(value = "备注") | |
43 | + @JsonInclude(JsonInclude.Include.NON_NULL) | |
44 | + private String remark; | |
45 | + | |
46 | + @ApiModelProperty(value = "添加人") | |
47 | + private String addPeople; | |
48 | + | |
49 | + | |
50 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/AlarmInfoDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | + | |
7 | +import javax.validation.constraints.NotEmpty; | |
8 | + | |
9 | +/** @Description @Author cxy @Date 2021/11/16 17:49 */ | |
10 | +@Data | |
11 | +@EqualsAndHashCode(callSuper = true) | |
12 | +public class AlarmInfoDTO extends TenantDTO { | |
13 | + @ApiModelProperty(value = "告警时间") | |
14 | + private long createTs; | |
15 | + | |
16 | + @ApiModelProperty(value = "告警类型") | |
17 | + private String type; | |
18 | + | |
19 | + @ApiModelProperty(value = "告警详情") | |
20 | + private String details; | |
21 | + | |
22 | + | |
23 | + @ApiModelProperty(value = "告警开始时间") | |
24 | + private long startTs; | |
25 | + | |
26 | + @ApiModelProperty(value = "告警结束时间") | |
27 | + private long endTs; | |
28 | + | |
29 | + @ApiModelProperty(value = "告警状态") | |
30 | + private String status; | |
31 | + | |
32 | + @ApiModelProperty(value = "告警程度") | |
33 | + private String severity; | |
34 | + | |
35 | + | |
36 | + | |
37 | + @ApiModelProperty(value = "告警设备名称") | |
38 | + private String deviceName; | |
39 | + @ApiModelProperty(value = "告警设备ID") | |
40 | + @NotEmpty(message = "设备ID不能为空") | |
41 | + private String deviceId; | |
42 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/DeviceTypeDTO.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import io.swagger.annotations.ApiModelProperty; | |
4 | +import lombok.Data; | |
5 | +import lombok.EqualsAndHashCode; | |
6 | +import org.thingsboard.server.common.data.yunteng.common.AddGroup; | |
7 | +import org.thingsboard.server.common.data.yunteng.utils.tree.TreeDTO; | |
8 | + | |
9 | +import javax.validation.constraints.NotEmpty; | |
10 | +import java.util.ArrayList; | |
11 | +import java.util.List; | |
12 | + | |
13 | +@EqualsAndHashCode(callSuper = true) | |
14 | +@Data | |
15 | +public class DeviceTypeDTO extends TenantDTO implements TreeDTO<DeviceTypeDTO> { | |
16 | + | |
17 | + @NotEmpty(message = "名称不能不空或者空字符串") | |
18 | + @ApiModelProperty(value = "设备类型名称") | |
19 | + private String name; | |
20 | + | |
21 | + @ApiModelProperty(value = "父ID") | |
22 | + private String parentId; | |
23 | + | |
24 | + @NotEmpty(message = "图片地址不能为空或者空字符串",groups = AddGroup.class) | |
25 | + @ApiModelProperty(value = "图片地址") | |
26 | + private String path; | |
27 | + | |
28 | + @ApiModelProperty(value = "排序") | |
29 | + private Integer sort; | |
30 | + | |
31 | + @ApiModelProperty(value = "描述") | |
32 | + private String description; | |
33 | + | |
34 | + @ApiModelProperty(value = "下级列表") | |
35 | + private List<DeviceTypeDTO> children; | |
36 | + | |
37 | + public DeviceTypeDTO(){ | |
38 | + this.children = new ArrayList<>(); | |
39 | + } | |
40 | + | |
41 | + @Override | |
42 | + public int compareTo(DeviceTypeDTO o) { | |
43 | + return this.getSort()-o.getSort(); | |
44 | + } | |
45 | +} | ... | ... |
1 | +package org.thingsboard.server.common.data.yunteng.dto; | |
2 | + | |
3 | +import com.fasterxml.jackson.annotation.JsonFormat; | |
4 | +import com.fasterxml.jackson.databind.JsonNode; | |
5 | +import lombok.Data; | |
6 | +import org.thingsboard.server.common.data.yunteng.common.aspect.annotation.AutoDict; | |
7 | + | |
8 | +import java.time.LocalDateTime; | |
9 | + | |
10 | +@Data | |
11 | +public class MailLogDTO extends BaseDTO{ | |
12 | + /** 发件人 */ | |
13 | + private String emailFrom; | |
14 | + | |
15 | + /** 收件人 */ | |
16 | + private JsonNode emailTo; | |
17 | + | |
18 | + /** 抄送人 */ | |
19 | + private JsonNode emailCc; | |
20 | + | |
21 | + /** 密送人 */ | |
22 | + private JsonNode emailBcc; | |
23 | + | |
24 | + /** 邮件主题 */ | |
25 | + private String emailSubject; | |
26 | + | |
27 | + /** 邮件内容 */ | |
28 | + private String emailBody; | |
29 | + | |
30 | + /** 状态:ResponseCodeEnum枚举值 */ | |
31 | + private String status; | |
32 | + | |
33 | + /** 发送时间 */ | |
34 | + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | |
35 | + private LocalDateTime sendTime; | |
36 | + | |
37 | + /** 租户Code */ | |
38 | + private String tenantCode; | |
39 | + | |
40 | + /** 模板ID */ | |
41 | + private String messageTemplateId; | |
42 | + | |
43 | + /**备注*/ | |
44 | + private String remark; | |
45 | + | |
46 | + /**用途*/ | |
47 | + @AutoDict(dictCode = "template_purpose") | |
48 | + private String templatePurpose; | |
49 | +} | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/enums/AssetStatusEnum.java
0 → 100644
1 | +package org.thingsboard.server.common.data.yunteng.enums; | |
2 | + | |
3 | +/** | |
4 | + * @version V1.0 | |
5 | + * @Description : 资源状态, | |
6 | + * 例如:消息模板等。 | |
7 | + * 1.其它地方抛出异常,交由控制层统一处理 | |
8 | + * 2.服务层注意持久化的事务管理 | |
9 | + * @Dependency: 依赖包 | |
10 | + * @Author: junlianglee | |
11 | + * @Date Created in 2021/11/24$ | |
12 | + * @Copyright 2016-2018 - Powered By 云腾五洲 | |
13 | + */ | |
14 | +public enum AssetStatusEnum { | |
15 | + DISABLED, | |
16 | + ENABLE | |
17 | +} | ... | ... |
... | ... | @@ -13,7 +13,7 @@ public class TenantBaseEntity extends BaseEntity { |
13 | 13 | |
14 | 14 | private static final long serialVersionUID = -4315734960161684909L; |
15 | 15 | |
16 | - private String tenantCode; | |
16 | + private String tenantId; | |
17 | 17 | |
18 | 18 | @TableField(fill = FieldFill.INSERT) |
19 | 19 | private String creator; | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.entities; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.annotation.FieldStrategy; | |
4 | +import com.baomidou.mybatisplus.annotation.TableField; | |
5 | +import com.baomidou.mybatisplus.annotation.TableName; | |
6 | +import lombok.Data; | |
7 | +import lombok.EqualsAndHashCode; | |
8 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | |
9 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | |
10 | + | |
11 | +@Data | |
12 | +@EqualsAndHashCode(callSuper = true) | |
13 | +@TableName(ModelConstants.Table.IOTFS_DEVICE_PROFILE_TABLE_NAME) | |
14 | +public class YtDeviceProfile extends TenantBaseEntity { | |
15 | + private String name; | |
16 | + private String description; | |
17 | + /** 转换脚本:TCP才会使用 */ | |
18 | + private String convertJs; | |
19 | + | |
20 | + private TransportTypeEnum transportType; | |
21 | + private String tenantCode; | |
22 | + /** TB的设备配置文件 */ | |
23 | + @TableField(updateStrategy = FieldStrategy.IGNORED) | |
24 | + private String tbProfileId; | |
25 | +} | ... | ... |
... | ... | @@ -38,7 +38,7 @@ public class MenuServiceImpl extends AbstractBaseService<MenuMapper, Menu> imple |
38 | 38 | |
39 | 39 | List<Menu> menus = |
40 | 40 | baseMapper.selectList( |
41 | - new QueryWrapper<Menu>().lambda().eq(Menu::getTenantCode, tenantId)); | |
41 | + new QueryWrapper<Menu>().lambda().eq(Menu::getTenantId, tenantId)); | |
42 | 42 | Map<String, MenuDTO> menuDTOMap = new LinkedHashMap<>(menus.size()); |
43 | 43 | menus.forEach(menu -> menuDTOMap.put(menu.getId(), menu.getDTO(MenuDTO.class))); |
44 | 44 | return buildMenuDTOTree(menuDTOMap); |
... | ... | @@ -144,7 +144,7 @@ public class MenuServiceImpl extends AbstractBaseService<MenuMapper, Menu> imple |
144 | 144 | baseMapper.selectCount( |
145 | 145 | new QueryWrapper<Menu>() |
146 | 146 | .lambda() |
147 | - .ne(Menu::getTenantCode, tenantId) | |
147 | + .ne(Menu::getTenantId, tenantId) | |
148 | 148 | .in(Menu::getId, ids)); |
149 | 149 | if (notTenantMenuCount > 0) { |
150 | 150 | throw new AccessDeniedException("cannot delete menu that not create by you"); | ... | ... |
... | ... | @@ -7,7 +7,6 @@ import lombok.RequiredArgsConstructor; |
7 | 7 | import lombok.extern.slf4j.Slf4j; |
8 | 8 | import org.apache.commons.lang3.RandomStringUtils; |
9 | 9 | import org.apache.commons.lang3.StringUtils; |
10 | -import org.springframework.boot.actuate.endpoint.SecurityContext; | |
11 | 10 | import org.springframework.security.access.AccessDeniedException; |
12 | 11 | import org.springframework.stereotype.Service; |
13 | 12 | import org.springframework.transaction.annotation.Transactional; |
... | ... | @@ -63,7 +62,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
63 | 62 | RoleEnum.ROLE_SYS_ADMIN) |
64 | 63 | .eq( |
65 | 64 | !isSysadmin, |
66 | - Role::getTenantCode, | |
65 | + Role::getTenantId, | |
67 | 66 | tenantId) |
68 | 67 | .like( |
69 | 68 | queryMap.get("roleName") != null, |
... | ... | @@ -80,7 +79,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
80 | 79 | baseMapper.selectCount( |
81 | 80 | new QueryWrapper<Role>() |
82 | 81 | .lambda() |
83 | - .ne(Role::getTenantCode, tenantId) | |
82 | + .ne(Role::getTenantId, tenantId) | |
84 | 83 | .in(Role::getId, ids)); |
85 | 84 | if (notTenantMenuCount > 0) { |
86 | 85 | throw new AccessDeniedException("cannot delete role that not create by you"); |
... | ... | @@ -155,7 +154,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
155 | 154 | .eq(Role::getId, roleId) |
156 | 155 | .eq( |
157 | 156 | !isSysadmin, |
158 | - Role::getTenantCode, | |
157 | + Role::getTenantId, | |
159 | 158 | tenantId))) |
160 | 159 | .ifPresent( |
161 | 160 | role -> { |
... | ... | @@ -188,7 +187,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
188 | 187 | .eq(Role::getId, roleReqDTO.getId()) |
189 | 188 | .eq( |
190 | 189 | !isSysadmin, |
191 | - Role::getTenantCode, | |
190 | + Role::getTenantId, | |
192 | 191 | tenantId)); |
193 | 192 | if (role == null) { |
194 | 193 | return null; |
... | ... | @@ -206,7 +205,7 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
206 | 205 | role.setRemark(roleReqDTO.getRemark()); |
207 | 206 | role.setName(roleReqDTO.getName()); |
208 | 207 | role.setEnabled(roleReqDTO.getStatus() == 1); |
209 | - role.setTenantCode(tenantId); | |
208 | + role.setTenantId(tenantId); | |
210 | 209 | baseMapper.insert(role); |
211 | 210 | } |
212 | 211 | // do update or save menu associate with this roleId |
... | ... | @@ -245,8 +244,8 @@ public class RoleServiceImpl extends AbstractBaseService<RoleMapper, Role> imple |
245 | 244 | |
246 | 245 | @Override |
247 | 246 | public List<RoleDTO> findRoleInfo(boolean isTenantAdmin,String tenantId,String userId,RoleDTO roleDTO) { |
248 | - if (StringUtils.isEmpty(roleDTO.getTenantCode())) { | |
249 | - roleDTO.setTenantCode(tenantId); | |
247 | + if (StringUtils.isEmpty(roleDTO.getTenantId())) { | |
248 | + roleDTO.setTenantId(tenantId); | |
250 | 249 | } |
251 | 250 | if (isTenantAdmin) { |
252 | 251 | // 租户管理员既要查询自己拥有的角色,也要查询自己创建的角色 | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
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; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import org.apache.commons.lang3.StringUtils; | |
8 | +import org.springframework.stereotype.Service; | |
9 | +import org.springframework.transaction.annotation.Transactional; | |
10 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
11 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; | |
12 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
13 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
14 | +import org.thingsboard.server.dao.yunteng.entities.AlarmContact; | |
15 | +import org.thingsboard.server.dao.yunteng.mapper.AlarmContactMapper; | |
16 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
17 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmContactService; | |
18 | + | |
19 | +import java.util.List; | |
20 | +import java.util.Map; | |
21 | +import java.util.Set; | |
22 | + | |
23 | +/** @Description 告警联系人业务实现 @Author cxy @Date 2021/11/2 14:47 */ | |
24 | +@Service | |
25 | +@RequiredArgsConstructor | |
26 | +public class YtAlarmContactServiceImpl extends AbstractBaseService<AlarmContactMapper, AlarmContact> | |
27 | + implements YtAlarmContactService { | |
28 | + /** mapper注入 自带方法加入,继承的baseMapper */ | |
29 | + private final AlarmContactMapper alarmContactMapper; | |
30 | + | |
31 | + /** | |
32 | + * 查询全部的告警联系人 | |
33 | + * | |
34 | + * @param params 传参 | |
35 | + * @return List | |
36 | + */ | |
37 | + @Override | |
38 | + public List<AlarmContactDTO> findAll(String tenantId,Map<String, Object> params) { | |
39 | + // 查询当前租户 | |
40 | + List<AlarmContact> list = | |
41 | + alarmContactMapper.selectList( | |
42 | + new QueryWrapper<AlarmContact>() | |
43 | + .lambda() | |
44 | + .eq(AlarmContact::getTenantId, tenantId) | |
45 | + .like( | |
46 | + params.containsKey("username"), | |
47 | + AlarmContact::getUsername, | |
48 | + String.valueOf(params.get("username"))) | |
49 | + .or() | |
50 | + .like( | |
51 | + params.containsKey("department"), | |
52 | + AlarmContact::getOrganizationId, | |
53 | + String.valueOf(params.get("organizationId")))); | |
54 | + System.out.println(list); | |
55 | + return ReflectUtils.sourceToTarget(list, AlarmContactDTO.class); | |
56 | + } | |
57 | + | |
58 | + /** | |
59 | + * 新增租户 | |
60 | + * | |
61 | + * @param tenantCode 租户编码 | |
62 | + * @return alarmContactDTO | |
63 | + */ | |
64 | + private LambdaQueryWrapper<AlarmContact> tenantWapper(String tenantCode) { | |
65 | + return new QueryWrapper<AlarmContact>().lambda().eq(AlarmContact::getTenantId, tenantCode); | |
66 | + } | |
67 | + | |
68 | + @Override | |
69 | + @Transactional | |
70 | + public AlarmContactDTO saveAlarmContact(String tenantId,AlarmContactDTO alarmContactDTO) { | |
71 | + LambdaQueryWrapper<AlarmContact> Wrapper = | |
72 | + tenantWapper(tenantId).eq(AlarmContact::getUsername, alarmContactDTO.getUsername()); | |
73 | + int Count = baseMapper.selectCount(Wrapper); | |
74 | + if (Count > 0) { | |
75 | + throw new DataValidationException("department for this name is exited"); | |
76 | + } | |
77 | + alarmContactDTO.setTenantId(tenantId); | |
78 | + AlarmContact alarmContact = alarmContactDTO.getEntity(AlarmContact.class); | |
79 | + int insertCount = baseMapper.insert(alarmContact); | |
80 | + if (insertCount > 0) { | |
81 | + alarmContact.copyToDTO(alarmContactDTO); | |
82 | + return alarmContactDTO; | |
83 | + } | |
84 | + return null; | |
85 | + } | |
86 | + | |
87 | + /** | |
88 | + * 删除告警联系人,byId | |
89 | + * | |
90 | + * @param alarmIds 通过列表id | |
91 | + * @return Integer | |
92 | + */ | |
93 | + @Override | |
94 | + @Transactional | |
95 | + public boolean delete(String[] alarmIds) { | |
96 | + Set<String> ids = Set.of(alarmIds); | |
97 | + baseMapper.deleteBatchIds(ids); | |
98 | + return true; | |
99 | + } | |
100 | + | |
101 | + /** | |
102 | + * 修改告警联系人数据 | |
103 | + * | |
104 | + * @param alarmContactDTO 对象 | |
105 | + * @return Integer | |
106 | + */ | |
107 | + @Override | |
108 | + @Transactional | |
109 | + public boolean update(AlarmContactDTO alarmContactDTO) { | |
110 | + | |
111 | + // 得到对象 | |
112 | + AlarmContact alarmContact = baseMapper.selectById(alarmContactDTO.getId()); | |
113 | + if (alarmContact == null) { | |
114 | + throw new DataValidationException("此数据不存在"); | |
115 | + } else { | |
116 | + AlarmContact entity = alarmContactDTO.getEntity(AlarmContact.class); | |
117 | + System.out.println(alarmContact); | |
118 | + baseMapper.updateById(entity); | |
119 | + alarmContact.copyToDTO(alarmContactDTO); | |
120 | + return true; | |
121 | + } | |
122 | + } | |
123 | + | |
124 | + | |
125 | + | |
126 | + /** | |
127 | + * @param queryMap 查询集合 | |
128 | + * @return PageData | |
129 | + */ | |
130 | + @Override | |
131 | + @Transactional | |
132 | + public PageData<AlarmContactDTO> page(Map<String, Object> queryMap) { | |
133 | + // 查询分页,加入条模糊条件查询 | |
134 | + IPage<AlarmContact> iPage = | |
135 | + alarmContactMapper.selectPage( | |
136 | + getPage(queryMap, "create_time", false), | |
137 | + new QueryWrapper<AlarmContact>() | |
138 | + .lambda() | |
139 | + .like( | |
140 | + StringUtils.isNoneBlank((String) queryMap.get("username")), | |
141 | + AlarmContact::getUsername, | |
142 | + queryMap.get("username")) | |
143 | + .eq( | |
144 | + StringUtils.isNoneBlank((String) queryMap.get("organizationId")), | |
145 | + AlarmContact::getOrganizationId, | |
146 | + queryMap.get("organizationId"))); | |
147 | + return getPageData(iPage, AlarmContactDTO.class); | |
148 | + } | |
149 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import lombok.RequiredArgsConstructor; | |
4 | +import lombok.extern.slf4j.Slf4j; | |
5 | +import org.springframework.stereotype.Service; | |
6 | +import org.thingsboard.server.common.data.yunteng.core.exception.FastIotException; | |
7 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
8 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
9 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
10 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
11 | +import org.thingsboard.server.common.data.yunteng.utils.tools.TBPageData; | |
12 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmInfoService; | |
13 | + | |
14 | +import java.util.List; | |
15 | +import java.util.Map; | |
16 | + | |
17 | +/** @Description 告警中心业务实现 @Author cxy @Date 2021/11/10 16:56 */ | |
18 | +@Service | |
19 | +@RequiredArgsConstructor | |
20 | +@Slf4j | |
21 | +public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { | |
22 | +// private final TBConfig tbConfig; | |
23 | +// private final TBConnectService tbConnectService; | |
24 | +// | |
25 | +// | |
26 | +// | |
27 | +// private LambdaQueryWrapper<YtAlarmInfo> tenantWapper(String tenantCode) { | |
28 | +// return new QueryWrapper<AlarmInfo>().lambda().eq(AlarmInfo::getTenantCode, tenantCode); | |
29 | +// } | |
30 | + | |
31 | + /** | |
32 | + * 封装修改 | |
33 | + * | |
34 | + * @param alarmInfoDto 告警对象 | |
35 | + * @return return alarmInfo.getDTO(AlarmInfoDto.class); | |
36 | + */ | |
37 | + /* private AlarmInfoDTO update(AlarmInfoDTO alarmInfoDto) { | |
38 | + AlarmInfo alarmInfo = baseMapper.selectById(alarmInfoDto.getId()); | |
39 | + if (!alarmInfo.getTenantCode().equals(SecurityContext.getCurrentUser().getTenantCode())) { | |
40 | + return null; | |
41 | + } | |
42 | + alarmInfoDto.copyToEntity(alarmInfo); | |
43 | + baseMapper.updateById(alarmInfo); | |
44 | + alarmInfo.copyToDTO(alarmInfoDto); | |
45 | + return alarmInfo.getDTO(AlarmInfoDTO.class); | |
46 | + }*/ | |
47 | + /** | |
48 | + * 封装新增 | |
49 | + * | |
50 | + * @param alarmInfoDto 告警对象 | |
51 | + * @return alarmInfoDto | |
52 | + */ | |
53 | + /*private AlarmInfoDTO insert(AlarmInfoDTO alarmInfoDto) { | |
54 | + String tenantCode = SecurityContext.getCurrentUser().getTenantCode(); | |
55 | + LambdaQueryWrapper<AlarmInfo> Wrapper = | |
56 | + tenantWapper(tenantCode) | |
57 | + .eq(AlarmInfo::getStatus, alarmInfoDto.getStatus()) | |
58 | + .eq(AlarmInfo::getSeverity, alarmInfoDto.getSeverity()); | |
59 | + int Count = baseMapper.selectCount(Wrapper); | |
60 | + if (Count > 0) { | |
61 | + throw new DataValidationException("告警中心数据已经存在"); | |
62 | + } | |
63 | + // 保存租户编码 | |
64 | + alarmInfoDto.setTenantCode(tenantCode); | |
65 | + AlarmInfo alarmInfo = alarmInfoDto.getEntity(AlarmInfo.class); | |
66 | + | |
67 | + int insertCount = baseMapper.insert(alarmInfo); | |
68 | + if (insertCount > 0) { | |
69 | + alarmInfo.copyToDTO(alarmInfoDto); | |
70 | + return alarmInfoDto; | |
71 | + } | |
72 | + | |
73 | + return alarmInfoDto; | |
74 | + } | |
75 | +*/ | |
76 | + /** | |
77 | + * 新增或者修改告警中心 | |
78 | + * | |
79 | + * @param alarmInfoDto 告警对象 | |
80 | + * @return alarmInfoDto | |
81 | + */ | |
82 | + /*@Override | |
83 | + @Transactional | |
84 | + public AlarmInfoDTO insertOrUpdate(AlarmInfoDTO alarmInfoDto) { | |
85 | + // 判断为空,则新增告警信息 | |
86 | + if (StringUtils.isBlank(alarmInfoDto.getId())) { | |
87 | + return insert(alarmInfoDto); | |
88 | + } else { | |
89 | + // 不为空则执行修改操作 | |
90 | + return update(alarmInfoDto); | |
91 | + } | |
92 | + }*/ | |
93 | + | |
94 | + /** | |
95 | + * 删除告警中心数据 | |
96 | + * | |
97 | + * @param | |
98 | + * @return boolean | |
99 | + */ | |
100 | + /* @Override | |
101 | + public boolean deleteAlarm(Set<String> alarmIds) { | |
102 | + LambdaQueryWrapper<AlarmInfo> queryWrapper = | |
103 | + new QueryWrapper<AlarmInfo>() | |
104 | + .lambda() | |
105 | + .eq(AlarmInfo::getTenantCode, SecurityContext.getCurrentUser().getTenantCode()) | |
106 | + .in(AlarmInfo::getId, alarmIds); | |
107 | + baseMapper.delete(queryWrapper); | |
108 | + return true; | |
109 | + }*/ | |
110 | + | |
111 | + /** | |
112 | + * 分页查询数据 | |
113 | + * | |
114 | + * @param queryMap 集合 | |
115 | + * @return PageData | |
116 | + */ | |
117 | + @Override | |
118 | + public PageData<AlarmInfoDTO> page(Map<String, Object> queryMap) { | |
119 | + /* queryMap.put("tenantCode", SecurityContext.getCurrentUser().getTenantCode()); | |
120 | + IPage<AlarmInfo> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME,false); | |
121 | + IPage<AlarmInfo> alarmInfoIPage = alarmInfoBaseMapper.selectPage(page,queryMap);*/ | |
122 | + | |
123 | + try { | |
124 | + TBPageData tbPageData = null;//tbConnectService.getAlarmInfos(queryMap).get(); | |
125 | + System.out.println("==================tbPageData:" + tbPageData); | |
126 | + List<AlarmInfoDTO> alarmInfoDTOS = ReflectUtils.sourceToTarget(tbPageData.getData(), AlarmInfoDTO.class); | |
127 | + PageData<AlarmInfoDTO> pageData = new PageData(); | |
128 | + pageData.setItems(alarmInfoDTOS); | |
129 | + | |
130 | + System.out.println("==================alarmInfoDTOS:" + alarmInfoDTOS); | |
131 | + return pageData; | |
132 | + } catch (Exception e) { | |
133 | + log.error("create TBAlarmInfo error {}", e.getMessage()); | |
134 | + throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR); | |
135 | + } | |
136 | + //return getPageData(alarmInfoIPage,AlarmInfoDTO.class); | |
137 | + } | |
138 | + | |
139 | + | |
140 | + | |
141 | + /** | |
142 | + * 查询告警中心集合 | |
143 | + * | |
144 | + * @param alarmInfoDto 过滤参数 | |
145 | + * @return AlarmInfoDto | |
146 | + */ | |
147 | + /*@Override | |
148 | + public List<AlarmInfoDTO> findAlarmInfo(AlarmInfoDTO alarmInfoDto) { | |
149 | + List<AlarmInfo> alarmInfoList = | |
150 | + baseMapper.selectList( | |
151 | + new QueryWrapper<AlarmInfo>() | |
152 | + .lambda() | |
153 | + .eq(AlarmInfo::getTenantCode, SecurityContext.getCurrentUser().getTenantCode()) | |
154 | + .like( | |
155 | + StringUtils.isNotBlank(alarmInfoDto.getStatus()), | |
156 | + AlarmInfo::getStatus, | |
157 | + alarmInfoDto.getStatus())); | |
158 | + return ReflectUtils.sourceToTarget(alarmInfoList, AlarmInfoDTO.class); | |
159 | + }*/ | |
160 | + | |
161 | + /** | |
162 | + * 创建调用TBAlarmInfo需要的参数 | |
163 | + * | |
164 | + * @param alarmInfoDto 页面接收的参数 | |
165 | + * @return 封装的tbAlarmInfo | |
166 | + */ | |
167 | +// private TBAlarmInfo buildTbAlarmInfoFromAlarmInfoDto(AlarmInfoDTO alarmInfoDto) { | |
168 | +// // 新建tbAlarmInfo对象获取数据 | |
169 | +// TBAlarmInfo tbAlarmInfo = new TBAlarmInfo(); | |
170 | +// tbAlarmInfo.setDetails(alarmInfoDto.getDetails()); | |
171 | +// tbAlarmInfo.setEndTs(alarmInfoDto.getEndTs()); | |
172 | +// tbAlarmInfo.setSeverity(alarmInfoDto.getSeverity()); | |
173 | +// tbAlarmInfo.setStatus(alarmInfoDto.getStatus()); | |
174 | +// tbAlarmInfo.setType(alarmInfoDto.getType()); | |
175 | +// tbAlarmInfo.setStartTs(alarmInfoDto.getStartTs()); | |
176 | +// Id alarmInfoId = new Id(); | |
177 | +// alarmInfoId.setEntityType(EntityType.TENANT); | |
178 | +// alarmInfoId.setId(alarmInfoId.getId()); | |
179 | +// Id id = new Id(); | |
180 | +// id.setId(alarmInfoId.getId()); | |
181 | +// tbAlarmInfo.setTenantId(id); | |
182 | +// return tbAlarmInfo; | |
183 | +// } | |
184 | + | |
185 | + /** | |
186 | + * 调用TB来保存 | |
187 | + * | |
188 | + * @param alarmInfoDto 告警对象 | |
189 | + */ | |
190 | + private void saveOrUpdateTblarmInfo(AlarmInfoDTO alarmInfoDto) throws InterruptedException { | |
191 | + // 启用则创建连接对象 | |
192 | +// if (tbConfig.isEnabled()) { | |
193 | +// TBAlarmInfo tbAlarmInfo = buildTbAlarmInfoFromAlarmInfoDto(alarmInfoDto); | |
194 | +// try { | |
195 | +// // 得到连接对象 | |
196 | +// TBAlarmInfo newtbAlarmInfo = tbConnectService.saveOrUpdateAlarmInfo(tbAlarmInfo).get(); | |
197 | +// // 为空 | |
198 | +// if (null == newtbAlarmInfo) { | |
199 | +// throw new FastIotException( | |
200 | +// ErrorMessage.CONNECT_TO_TB_ERROR.setMessage("update tb alarmInfo error")); | |
201 | +// } | |
202 | +// } catch (ExecutionException e) { | |
203 | +// log.error("create TBAlarmInfo error {}", e.getMessage()); | |
204 | +// throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR); | |
205 | +// } | |
206 | +// } | |
207 | + } | |
208 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import lombok.RequiredArgsConstructor; | |
5 | +import lombok.extern.slf4j.Slf4j; | |
6 | +import org.apache.commons.lang3.StringUtils; | |
7 | +import org.springframework.stereotype.Service; | |
8 | +import org.springframework.transaction.annotation.Transactional; | |
9 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
10 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
11 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | |
12 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
13 | +import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; | |
14 | +import org.thingsboard.server.dao.yunteng.mapper.AlarmProfileMapper; | |
15 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
16 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmProfileService; | |
17 | + | |
18 | +import java.util.List; | |
19 | +import java.util.Optional; | |
20 | +import java.util.Set; | |
21 | + | |
22 | +@Service | |
23 | +@RequiredArgsConstructor | |
24 | +@Slf4j | |
25 | +public class YtAlarmProfileServiceImpl extends AbstractBaseService<AlarmProfileMapper, AlarmProfile> | |
26 | + implements YtAlarmProfileService { | |
27 | + | |
28 | + @Override | |
29 | + @Transactional | |
30 | + public AlarmProfileDTO saveOrUpdateAlarmProfile(String tenantId,AlarmProfileDTO alarmProfileDTO) { | |
31 | + AlarmProfile alarmProfile = new AlarmProfile(); | |
32 | + alarmProfileDTO.copyToEntity(alarmProfile); | |
33 | + if (StringUtils.isEmpty(alarmProfileDTO.getId())) { | |
34 | + alarmProfile.setTenantId(tenantId); | |
35 | + baseMapper.insert(alarmProfile); | |
36 | + } else { | |
37 | + baseMapper.updateById(alarmProfile); | |
38 | + } | |
39 | + alarmProfile.copyToDTO(alarmProfileDTO); | |
40 | + return alarmProfileDTO; | |
41 | + } | |
42 | + | |
43 | + @Override | |
44 | + @Transactional | |
45 | + public boolean deleteAlarmProfile(Set<String> ids) { | |
46 | + return baseMapper.deleteBatchIds(ids) > 0; | |
47 | + } | |
48 | + | |
49 | + @Override | |
50 | + public AlarmProfileDTO findAlarmProfileByDeviceProfileId(String tenantId,String deviceProfileId) { | |
51 | + if (StringUtils.isEmpty(deviceProfileId)) { | |
52 | + throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
53 | + } | |
54 | + List<AlarmProfile> alarmProfileList = | |
55 | + baseMapper.selectList( | |
56 | + new QueryWrapper<AlarmProfile>() | |
57 | + .lambda() | |
58 | + .eq(AlarmProfile::getDeviceProfileId, deviceProfileId) | |
59 | + .eq(AlarmProfile::getTenantId, tenantId)); | |
60 | + return Optional.ofNullable(alarmProfileList) | |
61 | + .filter(alarmProfiles -> alarmProfiles.size() > 0) | |
62 | + .map( | |
63 | + alarmProfiles -> | |
64 | + ReflectUtils.sourceToTarget(alarmProfileList, AlarmProfileDTO.class).get(0)) | |
65 | + .orElse(null); | |
66 | + } | |
67 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
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; | |
6 | +import lombok.RequiredArgsConstructor; | |
7 | +import org.apache.commons.lang3.StringUtils; | |
8 | +import org.springframework.security.access.AccessDeniedException; | |
9 | +import org.springframework.stereotype.Service; | |
10 | +import org.springframework.transaction.annotation.Transactional; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
15 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
16 | +import org.thingsboard.server.dao.yunteng.entities.AlarmContact; | |
17 | +import org.thingsboard.server.dao.yunteng.mapper.AlarmContactMapper; | |
18 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
19 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmService; | |
20 | + | |
21 | +import java.util.List; | |
22 | +import java.util.Map; | |
23 | +import java.util.Set; | |
24 | + | |
25 | + | |
26 | +/** | |
27 | + * @Description 告警联系人业务实现 | |
28 | + * @Author cxy | |
29 | + * @Date 2021/11/2 14:47 | |
30 | + */ | |
31 | +@Service | |
32 | +@RequiredArgsConstructor | |
33 | +public class YtAlarmServiceImpl extends AbstractBaseService<AlarmContactMapper, AlarmContact> implements YtAlarmService { | |
34 | + /** | |
35 | + * mapper注入 自带方法加入,继承的baseMapper | |
36 | + */ | |
37 | + | |
38 | + | |
39 | + private final AlarmContactMapper alarmContactMapper; | |
40 | + | |
41 | + /** | |
42 | + * 查询全部的告警联系人 | |
43 | + * | |
44 | + * @param alarmContactDTO 对象 | |
45 | + * @return List | |
46 | + */ | |
47 | + @Override | |
48 | + public List<AlarmContactDTO> findAll(String tenantId,AlarmContactDTO alarmContactDTO) { | |
49 | + //查询当前租户 | |
50 | + List<AlarmContact> list = alarmContactMapper.selectList( | |
51 | + | |
52 | + new QueryWrapper<AlarmContact>() | |
53 | + .lambda().eq(AlarmContact::getTenantId,tenantId)); | |
54 | + System.out.println(list); | |
55 | + return ReflectUtils.sourceToTarget(list, AlarmContactDTO.class); | |
56 | + } | |
57 | + | |
58 | + /** | |
59 | + * 新增租户 | |
60 | + * @param tenantCode | |
61 | + * @return alarmContactDTO | |
62 | + */ | |
63 | + private LambdaQueryWrapper<AlarmContact> tenantWapper(String tenantCode) { | |
64 | + return new QueryWrapper<AlarmContact>().lambda() | |
65 | + .eq(AlarmContact::getTenantId, tenantCode); | |
66 | + } | |
67 | + @Override | |
68 | + @Transactional | |
69 | + public AlarmContactDTO saveAlarmContact(String tenantId,AlarmContactDTO alarmContactDTO) { | |
70 | + LambdaQueryWrapper<AlarmContact> Wrapper = tenantWapper(tenantId) | |
71 | + .eq( AlarmContact::getUsername, alarmContactDTO.getUsername()); | |
72 | + int Count = baseMapper.selectCount(Wrapper); | |
73 | + if (Count > 0) { | |
74 | + throw new DataValidationException("department for this name is exited"); | |
75 | + } | |
76 | + alarmContactDTO.setTenantId(tenantId); | |
77 | + AlarmContact alarmContact = alarmContactDTO.getEntity(AlarmContact.class); | |
78 | + int insertCount = baseMapper.insert(alarmContact); | |
79 | + if (insertCount > 0) { | |
80 | + alarmContact.copyToDTO(alarmContactDTO); | |
81 | + return alarmContactDTO; | |
82 | + } | |
83 | + return null; | |
84 | + } | |
85 | + | |
86 | + /** | |
87 | + * 删除告警联系人,byId | |
88 | + * | |
89 | + * @param Alarmids 通过列表id | |
90 | + * @return Integer | |
91 | + */ | |
92 | + @Override | |
93 | + | |
94 | + public boolean delete(String[] Alarmids) { | |
95 | + | |
96 | + Set<String> ids = Set.of(Alarmids); | |
97 | + baseMapper.deleteBatchIds(ids); | |
98 | + | |
99 | + return true; | |
100 | + } | |
101 | + | |
102 | + /** | |
103 | + * 修改告警联系人数据 | |
104 | + * | |
105 | + * @param alarmContactDTO 对象 | |
106 | + * @return Integer | |
107 | + */ | |
108 | + @Override | |
109 | + @Transactional | |
110 | + public AlarmContactDTO update(boolean istenantAdmin,String tenantId,AlarmContactDTO alarmContactDTO) { | |
111 | + //先获取id | |
112 | + AlarmContact alarmContact = alarmContactMapper.selectById(alarmContactDTO.getId()); | |
113 | + if (alarmContact == null) { | |
114 | + //为空则抛出无效参数的异常 | |
115 | + throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
116 | + } else { | |
117 | + if (!istenantAdmin) { | |
118 | + if (!tenantId.equals(alarmContactDTO.getTenantId())) { | |
119 | + throw new AccessDeniedException(ErrorMessage.HAVE_NO_PERMISSION.getMessage()); | |
120 | + } | |
121 | + } | |
122 | + //复制到alarmContact | |
123 | + alarmContactDTO.copyToEntity(alarmContact); | |
124 | + baseMapper.updateById(alarmContact); | |
125 | + alarmContact.copyToDTO(alarmContactDTO); | |
126 | + } | |
127 | + return alarmContactDTO; | |
128 | + } | |
129 | + | |
130 | + /** | |
131 | + * @param queryMap 查询集合 | |
132 | + * @return PageData | |
133 | + */ | |
134 | + @Override | |
135 | + @Transactional | |
136 | + public PageData<AlarmContactDTO> page(Map<String, Object> queryMap) { | |
137 | +//查询分页,加入条模糊条件查询 | |
138 | + IPage<AlarmContact> iPage = alarmContactMapper.selectPage(getPage(queryMap, "create_time", false), | |
139 | + new QueryWrapper<AlarmContact>().lambda(). | |
140 | + like(StringUtils.isNoneBlank((CharSequence) queryMap.get("username")) | |
141 | + , AlarmContact::getUsername, queryMap.get("username"))); | |
142 | + | |
143 | + return getPageData(iPage, AlarmContactDTO.class); | |
144 | + } | |
145 | + | |
146 | + | |
147 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtCommonServiceImpl.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/CommonServiceImpl.java
... | ... | @@ -4,7 +4,7 @@ import lombok.RequiredArgsConstructor; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
5 | 5 | import org.apache.commons.lang3.RandomStringUtils; |
6 | 6 | import org.springframework.stereotype.Service; |
7 | -import org.thingsboard.server.common.data.yunteng.common.CommonService; | |
7 | +import org.thingsboard.server.common.data.yunteng.common.YtCommonService; | |
8 | 8 | import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO; |
9 | 9 | import org.thingsboard.server.common.data.yunteng.dto.SysDictItemDTO; |
10 | 10 | import org.thingsboard.server.dao.yunteng.mapper.SysDictItemMapper; |
... | ... | @@ -13,7 +13,7 @@ import org.thingsboard.server.dao.yunteng.service.YtDeviceService; |
13 | 13 | @Slf4j |
14 | 14 | @Service |
15 | 15 | @RequiredArgsConstructor |
16 | -public class CommonServiceImpl implements CommonService { | |
16 | +public class YtCommonServiceImpl implements YtCommonService { | |
17 | 17 | |
18 | 18 | private final SysDictItemMapper sysDictItemMapper; |
19 | 19 | private final YtDeviceService deviceService; | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtDeviceProfileServiceImpl.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | +import lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.commons.lang3.StringUtils; | |
8 | +import org.springframework.stereotype.Service; | |
9 | +import org.springframework.transaction.annotation.Transactional; | |
10 | +import org.thingsboard.server.common.data.yunteng.core.cache.CacheUtils; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
12 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
13 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.TransportTypeEnum; | |
16 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
17 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
18 | +import org.thingsboard.server.dao.yunteng.entities.YtDevice; | |
19 | +import org.thingsboard.server.dao.yunteng.entities.YtDeviceProfile; | |
20 | +import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; | |
21 | +import org.thingsboard.server.dao.yunteng.mapper.DeviceProfileMapper; | |
22 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
23 | +import org.thingsboard.server.dao.yunteng.service.YtAlarmProfileService; | |
24 | +import org.thingsboard.server.dao.yunteng.service.YtDeviceProfileService; | |
25 | + | |
26 | +import java.util.*; | |
27 | + | |
28 | +@Service | |
29 | +@RequiredArgsConstructor | |
30 | +@Slf4j | |
31 | +public class YtDeviceProfileServiceImpl | |
32 | + extends AbstractBaseService<DeviceProfileMapper, org.thingsboard.server.dao.yunteng.entities.YtDeviceProfile> | |
33 | + implements YtDeviceProfileService { | |
34 | + | |
35 | + private final DeviceMapper deviceMapper; | |
36 | + private final YtAlarmProfileService alarmProfileService; | |
37 | + private final CacheUtils cacheUtils; | |
38 | + | |
39 | + @Override | |
40 | + @Transactional | |
41 | + public DeviceProfileDTO insertOrUpdate(String tenantId,DeviceProfileDTO deviceProfileDTO) { | |
42 | + if (StringUtils.isBlank(deviceProfileDTO.getId())) { | |
43 | + return insert(tenantId,deviceProfileDTO); | |
44 | + } else { | |
45 | + return update(tenantId,deviceProfileDTO); | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + private DeviceProfileDTO update(String tenantId,DeviceProfileDTO deviceProfileDTO) { | |
50 | + YtDeviceProfile deviceProfile = baseMapper.selectById(deviceProfileDTO.getId()); | |
51 | + if (!deviceProfile.getTenantId().equals(tenantId)) { | |
52 | + return null; | |
53 | + } | |
54 | + deviceProfileDTO.copyToEntity(deviceProfile); | |
55 | + // 如果原来不是TCP或者更新也不是TCP 那就需要check | |
56 | + if (!deviceProfile.getTransportType().equals(TransportTypeEnum.TCP) | |
57 | + || !deviceProfileDTO.getTransportType().equals(TransportTypeEnum.TCP)) { | |
58 | + checkDeviceProfile(deviceProfileDTO, deviceProfile); | |
59 | + } | |
60 | + baseMapper.updateById(deviceProfile); | |
61 | + Optional.ofNullable(deviceProfileDTO.getAlarmProfile()) | |
62 | + .filter(alarmProfileDTO -> StringUtils.isNotBlank(alarmProfileDTO.getId())) | |
63 | + .map(alarmProfileDTO -> alarmProfileService.saveOrUpdateAlarmProfile(tenantId,alarmProfileDTO)); | |
64 | + return deviceProfile.getDTO(DeviceProfileDTO.class); | |
65 | + } | |
66 | + | |
67 | + private DeviceProfileDTO insert(String tenantId,DeviceProfileDTO deviceProfileDTO) { | |
68 | + YtDeviceProfile deviceProfile = new YtDeviceProfile(); | |
69 | + // 判断数据库是否已存在名字相同的设备配置 | |
70 | + if (findDeviceProfile(tenantId,deviceProfileDTO).size() > 0) { | |
71 | + throw new DataValidationException(ErrorMessage.NAME_ALREADY_EXISTS.getMessage()); | |
72 | + } | |
73 | + deviceProfileDTO.copyToEntity(deviceProfile); | |
74 | + deviceProfile.setTenantId(tenantId); | |
75 | + saveOrUpdateTBDeviceProfile(deviceProfileDTO, deviceProfile); | |
76 | + baseMapper.insert(deviceProfile); | |
77 | + Optional.ofNullable(deviceProfileDTO.getAlarmProfile()) | |
78 | + .map( | |
79 | + alarmProfileDTO -> { | |
80 | + alarmProfileDTO.setDeviceProfileId(deviceProfile.getId()); | |
81 | + return alarmProfileService.saveOrUpdateAlarmProfile(tenantId,alarmProfileDTO); | |
82 | + }); | |
83 | + return deviceProfile.getDTO(DeviceProfileDTO.class); | |
84 | + } | |
85 | + | |
86 | + @Override | |
87 | + @Transactional | |
88 | + public void deleteDeviceProfiles(String tenantId,Set<String> ids) { | |
89 | + // check if ids bind to device | |
90 | + int count = | |
91 | + deviceMapper.selectCount(new QueryWrapper<YtDevice>().lambda().in(YtDevice::getProfileId, ids)); | |
92 | + if (count > 0) { | |
93 | + throw new DataValidationException("有设备使用待删除配置,请先删除设备或者修改设备配置"); | |
94 | + } | |
95 | + // TODO check if ids bind to iotfs_key_value_mapping | |
96 | + // 删除本地时,先删除TB的DeviceProfile | |
97 | + for (String id : ids) { | |
98 | + YtDeviceProfile deviceProfile = baseMapper.selectById(id); | |
99 | +// if (!tbConnectService.deleteDeviceProfile(deviceProfile.getTbProfileId()).get()) { | |
100 | +// log.error("delete TBProfile error {}", deviceProfile.getTbProfileId()); | |
101 | +// throw new FastIotException(ErrorMessage.INVALID_PARAMETER); | |
102 | +// } | |
103 | + // 删除设备配置同时需要删除对应的告警配置 | |
104 | + AlarmProfileDTO alarmProfileDTO = alarmProfileService.findAlarmProfileByDeviceProfileId(tenantId,id); | |
105 | + Optional.ofNullable(alarmProfileDTO) | |
106 | + .filter(alarm -> StringUtils.isNotBlank(alarm.getId())) | |
107 | + .map( | |
108 | + alarm -> { | |
109 | + Set<String> alarmList = new HashSet<>(); | |
110 | + alarmList.add(alarm.getId()); | |
111 | + return alarmProfileService.deleteAlarmProfile(alarmList); | |
112 | + }); | |
113 | + } | |
114 | + baseMapper.delete( | |
115 | + new QueryWrapper<YtDeviceProfile>() | |
116 | + .lambda() | |
117 | + .eq(YtDeviceProfile::getTenantId, tenantId) | |
118 | + .in(YtDeviceProfile::getId, ids)); | |
119 | + } | |
120 | + | |
121 | + @Override | |
122 | + public Optional<DeviceProfileDTO> getDeviceProfile(String tenantId,String id) { | |
123 | + return Optional.ofNullable( | |
124 | + baseMapper.selectOne( | |
125 | + new QueryWrapper<YtDeviceProfile>() | |
126 | + .lambda() | |
127 | + .eq( | |
128 | + YtDeviceProfile::getTenantId, | |
129 | + tenantId) | |
130 | + .eq(YtDeviceProfile::getId, id))) | |
131 | + .map(deviceProfile -> deviceProfile.getDTO(DeviceProfileDTO.class)); | |
132 | + } | |
133 | + | |
134 | + @Override | |
135 | + public PageData<DeviceProfileDTO> page(String tenantId,Map<String, Object> queryMap) { | |
136 | + String transportType = (String) queryMap.get("transportType"); | |
137 | + TransportTypeEnum type = null; | |
138 | + if (StringUtils.isNotBlank(transportType)) { | |
139 | + type = | |
140 | + Arrays.stream(TransportTypeEnum.values()) | |
141 | + .filter(s -> s.name().equalsIgnoreCase(transportType)) | |
142 | + .findAny() | |
143 | + .orElse(null); | |
144 | + } | |
145 | + IPage<YtDeviceProfile> deviceIPage = | |
146 | + baseMapper.selectPage( | |
147 | + getPage(queryMap, "create_time", false), | |
148 | + new QueryWrapper<YtDeviceProfile>() | |
149 | + .lambda() | |
150 | + .eq(YtDeviceProfile::getTenantId, tenantId) | |
151 | + .eq(type != null, YtDeviceProfile::getTransportType, type) | |
152 | + .like( | |
153 | + StringUtils.isNotBlank((String) queryMap.get("name")), | |
154 | + YtDeviceProfile::getName, | |
155 | + String.valueOf(queryMap.get("name")))); | |
156 | + return getPageData(deviceIPage, DeviceProfileDTO.class); | |
157 | + } | |
158 | + | |
159 | + @Override | |
160 | + public List<DeviceProfileDTO> findDeviceProfile(String tenantId,DeviceProfileDTO deviceProfileDTO) { | |
161 | + List<YtDeviceProfile> deviceProfileList = | |
162 | + baseMapper.selectList( | |
163 | + new QueryWrapper<YtDeviceProfile>() | |
164 | + .lambda() | |
165 | + .eq(YtDeviceProfile::getTenantId, tenantId) | |
166 | + .like( | |
167 | + StringUtils.isNotBlank(deviceProfileDTO.getName()), | |
168 | + YtDeviceProfile::getName, | |
169 | + deviceProfileDTO.getName())); | |
170 | + return ReflectUtils.sourceToTarget(deviceProfileList, DeviceProfileDTO.class); | |
171 | + } | |
172 | + | |
173 | + /** | |
174 | + * 构造调用TBDeviceProfile需要的参数 | |
175 | + * | |
176 | + * @param deviceProfileDTO 页面接收的参数 | |
177 | + * @return 封装好的TBDeviceProfile | |
178 | + | |
179 | + private TBDeviceProfile buildTbDeviceProfileFromDeviceProfileDTO( | |
180 | + DeviceProfileDTO deviceProfileDTO) { | |
181 | + TBDeviceProfile tbDeviceProfile = new TBDeviceProfile(); | |
182 | + if (StringUtils.isNotBlank(deviceProfileDTO.getId())) { | |
183 | + List<DeviceProfileDTO> deviceProfile = baseMapper.getDeviceProfileInfo(deviceProfileDTO); | |
184 | + tbDeviceProfile.setId( | |
185 | + new Id(EntityType.DEVICE_PROFILE, deviceProfile.get(0).getTbProfileId())); | |
186 | + } | |
187 | + tbDeviceProfile.setName(deviceProfileDTO.getName()); | |
188 | + // 传输类型默认都是Default | |
189 | + tbDeviceProfile.setTransportType(TransportTypeEnum.DEFAULT.name()); | |
190 | + // 获取当前租户的默认规则链 | |
191 | + tbDeviceProfile.setDefaultRuleChainId( | |
192 | + new Id(EntityType.RULE_CHAIN, getCurrentUserDefaultRuleChains())); | |
193 | + tbDeviceProfile.setDefaultQueueName(TbConnectConstant.RuleEngine.MAIN); | |
194 | + tbDeviceProfile.setProvisionType(ProvisionTypeEnum.DISABLED.name()); | |
195 | + tbDeviceProfile.setCreatedTime( | |
196 | + LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()); | |
197 | + TBDeviceProfile.DeviceProfileData deviceProfileData = new TBDeviceProfile.DeviceProfileData(); | |
198 | + deviceProfileData.setConfiguration(new TBDeviceProfile.DeviceProfileConfiguration()); | |
199 | + deviceProfileData.setProvisionConfiguration( | |
200 | + new TBDeviceProfile.DeviceProfileProvisionConfiguration()); | |
201 | + deviceProfileData.setTransportConfiguration( | |
202 | + new TBDeviceProfile.DeviceProfileTransportConfiguration()); | |
203 | + if (null != deviceProfileDTO.getAlarms()) { | |
204 | + List<TBDeviceProfile.DeviceProfileAlarm> list = new ArrayList<>(); | |
205 | + TBDeviceProfile.DeviceProfileAlarm deviceProfileAlarm = JacksonUtil.convertValue(deviceProfileDTO.getAlarms(),TBDeviceProfile.DeviceProfileAlarm.class); | |
206 | + list.add(deviceProfileAlarm); | |
207 | + deviceProfileData.setAlarms(list); | |
208 | + } | |
209 | + tbDeviceProfile.setProfileData(deviceProfileData); | |
210 | + return tbDeviceProfile; | |
211 | + } */ | |
212 | + | |
213 | + /** | |
214 | + * 检查设备配置然后进行相应的操作 | |
215 | + * | |
216 | + * @param target 用户新选择的配置 | |
217 | + * @param source 用户以前选择的配置 | |
218 | + */ | |
219 | + private void checkDeviceProfile(DeviceProfileDTO target, YtDeviceProfile source) { | |
220 | + // 原来是TCP => Default、MQTT或其他 需要新增TB设备配置文件 | |
221 | + if (source.getTransportType().equals(TransportTypeEnum.TCP) | |
222 | + && !target.getTransportType().equals(TransportTypeEnum.TCP)) { | |
223 | + saveOrUpdateTBDeviceProfile(target, source); | |
224 | + } | |
225 | + if (!source.getTransportType().equals(TransportTypeEnum.TCP)) { | |
226 | + // 原来不是TCP => 更新值或者更换TB设备配置文件 | |
227 | + if (!target.getTransportType().equals(TransportTypeEnum.TCP)) { | |
228 | + // 目标不是TCP则进行修改名称 | |
229 | + saveOrUpdateTBDeviceProfile(target, source); | |
230 | + } else { | |
231 | + // 目标是TCP则删除原来的TBDeviceProfile | |
232 | +// tbConnectService.deleteDeviceProfile(source.getTbProfileId()); | |
233 | + source.setTbProfileId(null); | |
234 | + } | |
235 | + } | |
236 | + } | |
237 | + | |
238 | + /** | |
239 | + * 调用TB保存设备配置 | |
240 | + * | |
241 | + * @param target 用户新选择的配置 | |
242 | + * @param source 用户以前选择的配置 | |
243 | + */ | |
244 | + private void saveOrUpdateTBDeviceProfile(DeviceProfileDTO target, YtDeviceProfile source) { | |
245 | +// if (tbConfig.isEnabled()) { | |
246 | +// try { | |
247 | +// TBDeviceProfile tbDeviceProfile = buildTbDeviceProfileFromDeviceProfileDTO(target); | |
248 | +// tbDeviceProfile = tbConnectService.saveOrUpdateDeviceProfile(tbDeviceProfile).get(); | |
249 | +// if (null == tbDeviceProfile) { | |
250 | +// throw new FastIotException(ErrorMessage.INVALID_PARAMETER); | |
251 | +// } | |
252 | +// source.setTbProfileId(tbDeviceProfile.getId().getId()); | |
253 | +// } catch (ExecutionException | InterruptedException e) { | |
254 | +// log.error("create TBDeviceProfile error {}", e.getMessage()); | |
255 | +// throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR); | |
256 | +// } | |
257 | +// } | |
258 | + } | |
259 | + | |
260 | + private String getCurrentUserDefaultRuleChains() { | |
261 | + String defaultId; | |
262 | +// Optional<String> result = | |
263 | +// cacheUtils | |
264 | +// .get( | |
265 | +// FastIotConstants.CacheConfigKey.DEFAULT_RULE_CHAIN, | |
266 | +// SecurityContext.getCurrentUser().getTenantCode()); | |
267 | +// if (null != result && result.isPresent()) { | |
268 | +// return result.get(); | |
269 | +// } | |
270 | +// try { | |
271 | +// if (tbConfig.isEnabled()) { | |
272 | +// TBPageData tbPageData = tbConnectService.getRuleChains(10, 0).get(); | |
273 | +// if (null == tbPageData || null == tbPageData.getData()) { | |
274 | +// throw new FastIotException(ErrorMessage.NONE_DEFAULT_RULE_CHAIN); | |
275 | +// } | |
276 | +// TBPageData convert = new TBPageData().getPageData(tbPageData,TBRuleChain.class); | |
277 | +// List<TBRuleChain> data = (List<TBRuleChain>) convert.getData(); | |
278 | +// for (TBRuleChain tbRuleChain : data) { | |
279 | +// if (tbRuleChain.isRoot()) { | |
280 | +// defaultId = tbRuleChain.getId().getId(); | |
281 | +// cacheUtils.put( | |
282 | +// FastIotConstants.CacheConfigKey.DEFAULT_RULE_CHAIN, | |
283 | +// SecurityContext.getCurrentUser().getTenantCode(), | |
284 | +// defaultId); | |
285 | +// return defaultId; | |
286 | +// } | |
287 | +// } | |
288 | +// } | |
289 | +// } catch (ExecutionException | InterruptedException e) { | |
290 | +// throw new FastIotException(ErrorMessage.CONNECT_TO_TB_ERROR); | |
291 | +// } | |
292 | + return null; | |
293 | + } | |
294 | +} | ... | ... |
... | ... | @@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j; |
9 | 9 | import org.apache.commons.lang3.StringUtils; |
10 | 10 | import org.springframework.stereotype.Service; |
11 | 11 | import org.springframework.transaction.annotation.Transactional; |
12 | -import org.thingsboard.server.common.data.DeviceProfile; | |
13 | 12 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
14 | 13 | import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
15 | 14 | import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; |
... | ... | @@ -22,6 +21,7 @@ import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; |
22 | 21 | import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
23 | 22 | import org.thingsboard.server.dao.yunteng.entities.Organization; |
24 | 23 | import org.thingsboard.server.dao.yunteng.entities.YtDevice; |
24 | +import org.thingsboard.server.dao.yunteng.entities.YtDeviceProfile; | |
25 | 25 | import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper; |
26 | 26 | import org.thingsboard.server.dao.yunteng.mapper.DeviceProfileMapper; |
27 | 27 | import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; |
... | ... | @@ -56,7 +56,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
56 | 56 | |
57 | 57 | private DeviceDTO update(String tenantId,DeviceDTO deviceDTO) { |
58 | 58 | YtDevice device = baseMapper.selectById(deviceDTO.getId()); |
59 | - if (!device.getTenantCode().equals(tenantId)) { | |
59 | + if (!device.getTenantId().equals(tenantId)) { | |
60 | 60 | return null; |
61 | 61 | } |
62 | 62 | validateDeviceDTO(tenantId,deviceDTO, false); |
... | ... | @@ -208,7 +208,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
208 | 208 | } |
209 | 209 | } |
210 | 210 | // 验证数据profileId的正确性 |
211 | - DeviceProfile deviceProfile = deviceProfileMapper.selectById(deviceDTO.getProfileId()); | |
211 | + YtDeviceProfile deviceProfile = deviceProfileMapper.selectById(deviceDTO.getProfileId()); | |
212 | 212 | Organization organization = organizationMapper.selectById(deviceDTO.getOrganizationId()); |
213 | 213 | if (null == deviceProfile || null == organization) { |
214 | 214 | throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); |
... | ... | @@ -217,7 +217,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
217 | 217 | } else if (!deviceProfile |
218 | 218 | .getTenantId() |
219 | 219 | .equals(tenantId) |
220 | - || !organization.getTenantCode().equals(tenantId)) { | |
220 | + || !organization.getTenantId().equals(tenantId)) { | |
221 | 221 | throw new DataValidationException(ErrorMessage.TENANT_MISMATCHING.getMessage()); |
222 | 222 | } |
223 | 223 | } |
... | ... | @@ -246,7 +246,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
246 | 246 | ModelConstants.TablePropertyMapping.CREATE_TIME, |
247 | 247 | ModelConstants.TablePropertyMapping.UPDATE, |
248 | 248 | ModelConstants.TablePropertyMapping.UPDATE_TIME); |
249 | - device.setTenantCode(tenantId); | |
249 | + device.setTenantId(tenantId); | |
250 | 250 | // First insert into TB |
251 | 251 | // if (tbConfig.isEnabled()) { |
252 | 252 | // Device tbDevice = buildTbDeviceFromDeviceDTO(deviceDTO); |
... | ... | @@ -316,7 +316,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
316 | 316 | LambdaQueryWrapper<YtDevice> queryWrapper = |
317 | 317 | new QueryWrapper<YtDevice>() |
318 | 318 | .lambda() |
319 | - .eq(YtDevice::getTenantCode, tenantId) | |
319 | + .eq(YtDevice::getTenantId, tenantId) | |
320 | 320 | .in(YtDevice::getId, ids); |
321 | 321 | |
322 | 322 | List<String> tbDeviceIds = |
... | ... | @@ -336,7 +336,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
336 | 336 | baseMapper.selectOne( |
337 | 337 | new QueryWrapper<YtDevice>() |
338 | 338 | .lambda() |
339 | - .eq(YtDevice::getTenantCode, tenantId) | |
339 | + .eq(YtDevice::getTenantId, tenantId) | |
340 | 340 | .eq(YtDevice::getId, id))) |
341 | 341 | .map(device -> device.getDTO(DeviceDTO.class)); |
342 | 342 | } |
... | ... | @@ -374,7 +374,7 @@ public class YtDeviceServiceImpl extends AbstractBaseService<DeviceMapper, YtDev |
374 | 374 | StringUtils.isNotBlank(deviceDTO.getDeviceToken()), |
375 | 375 | YtDevice::getDeviceToken, |
376 | 376 | deviceDTO.getDeviceToken()) |
377 | - .eq(true, YtDevice::getTenantCode, tenantId) | |
377 | + .eq(true, YtDevice::getTenantId, tenantId) | |
378 | 378 | .like( |
379 | 379 | StringUtils.isNotBlank(deviceDTO.getName()), |
380 | 380 | YtDevice::getName, | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import org.apache.commons.lang3.StringUtils; | |
5 | +import org.springframework.stereotype.Service; | |
6 | +import org.springframework.transaction.annotation.Transactional; | |
7 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
8 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | |
9 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
10 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceTypeDTO; | |
11 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
12 | +import org.thingsboard.server.common.data.yunteng.utils.tree.TreeUtils; | |
13 | +import org.thingsboard.server.dao.yunteng.entities.DeviceType; | |
14 | +import org.thingsboard.server.dao.yunteng.mapper.DeviceTypeMapper; | |
15 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
16 | +import org.thingsboard.server.dao.yunteng.service.YtDeviceTypeService; | |
17 | + | |
18 | +import java.util.List; | |
19 | + | |
20 | +@Service | |
21 | +public class YtDeviceTypeServiceImpl extends AbstractBaseService<DeviceTypeMapper, DeviceType> | |
22 | + implements YtDeviceTypeService { | |
23 | + @Override | |
24 | + public List<DeviceTypeDTO> getDeviceTypeTree(String tenantId) { | |
25 | + if (StringUtils.isEmpty(tenantId)) { | |
26 | + if (StringUtils.isEmpty(tenantId)) { | |
27 | + throw new DataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
28 | + } | |
29 | + } | |
30 | + List<DeviceType> typeList = baseMapper.selectList( | |
31 | + new QueryWrapper<DeviceType>() | |
32 | + .lambda() | |
33 | + .eq(StringUtils.isNoneEmpty(tenantId), DeviceType::getTenantId, tenantId)); | |
34 | + return TreeUtils.buildTree(ReflectUtils.sourceToTarget(typeList,DeviceTypeDTO.class)); | |
35 | + } | |
36 | + | |
37 | + @Override | |
38 | + @Transactional | |
39 | + public DeviceTypeDTO saveDeviceTye(String tenantId,DeviceTypeDTO deviceTypeDTO) { | |
40 | + deviceTypeDTO.setTenantId(tenantId); | |
41 | + DeviceType deviceType = deviceTypeDTO.getEntity(DeviceType.class); | |
42 | + int insertCount = baseMapper.insert(deviceType); | |
43 | + if (insertCount > 0) { | |
44 | + deviceType.copyToDTO(deviceTypeDTO); | |
45 | + return deviceTypeDTO; | |
46 | + } | |
47 | + return null; | |
48 | + } | |
49 | + | |
50 | + @Override | |
51 | + public DeviceTypeDTO updateDeviceType(DeviceTypeDTO deviceTypeDTO) { | |
52 | + DeviceType deviceType = deviceTypeDTO.getEntity(DeviceType.class); | |
53 | + int insertCount = baseMapper.updateById(deviceType); | |
54 | + if (insertCount > 0) { | |
55 | + deviceType.copyToDTO(deviceTypeDTO); | |
56 | + return deviceTypeDTO; | |
57 | + } | |
58 | + return null; | |
59 | + } | |
60 | + | |
61 | + @Override | |
62 | + public boolean deleteDeviceType(DeleteDTO deleteDTO) { | |
63 | + return baseMapper.deleteBatchIds(deleteDTO.getIds()) > 0; | |
64 | + } | |
65 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | +import lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.springframework.stereotype.Service; | |
8 | +import org.springframework.transaction.annotation.Transactional; | |
9 | +import org.thingsboard.server.common.data.yunteng.dto.MailLogDTO; | |
10 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
11 | +import org.thingsboard.server.dao.yunteng.entities.MailLog; | |
12 | +import org.thingsboard.server.dao.yunteng.mapper.MaiLogMapper; | |
13 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
14 | +import org.thingsboard.server.dao.yunteng.service.YtMailLogService; | |
15 | + | |
16 | +import java.util.Map; | |
17 | +import java.util.Set; | |
18 | + | |
19 | +@Slf4j | |
20 | +@Service | |
21 | +@RequiredArgsConstructor | |
22 | +public class YtMailLogServiceImpl extends AbstractBaseService<MaiLogMapper, MailLog> | |
23 | + implements YtMailLogService { | |
24 | + @Override | |
25 | + public PageData<MailLogDTO> page(String tenantId,Map<String, Object> queryMap) { | |
26 | + IPage<MailLog> configIPage = | |
27 | + baseMapper.selectPage( | |
28 | + getPage(queryMap, "send_time", false), | |
29 | + new QueryWrapper<MailLog>() | |
30 | + .lambda() | |
31 | + .eq(MailLog::getTenantId, tenantId) | |
32 | + .like( | |
33 | + queryMap.get("emailSubject") != null, | |
34 | + MailLog::getEmailSubject, | |
35 | + String.valueOf(queryMap.get("emailSubject"))) | |
36 | + .between( | |
37 | + queryMap.get("startTime") != null && queryMap.get("endTime") != null, | |
38 | + MailLog::getSendTime, | |
39 | + queryMap.get("startTime"), | |
40 | + queryMap.get("endTime"))); | |
41 | + return getPageData(configIPage, MailLogDTO.class); | |
42 | + } | |
43 | + | |
44 | + @Override | |
45 | + @Transactional | |
46 | + public boolean deleteMailLog(Set<String> ids) { | |
47 | + return baseMapper.deleteBatchIds(ids) > 0; | |
48 | + } | |
49 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.JsonNode; | |
4 | +import jakarta.mail.*; | |
5 | +import jakarta.mail.internet.InternetAddress; | |
6 | +import jakarta.mail.internet.MimeBodyPart; | |
7 | +import jakarta.mail.internet.MimeMessage; | |
8 | +import jakarta.mail.internet.MimeMultipart; | |
9 | +import lombok.RequiredArgsConstructor; | |
10 | +import lombok.extern.slf4j.Slf4j; | |
11 | +import org.springframework.stereotype.Service; | |
12 | +import org.thingsboard.server.common.data.yunteng.config.email.EmailConfiguration; | |
13 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
14 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
15 | +import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; | |
16 | +import org.thingsboard.server.common.data.yunteng.enums.EmailFormatEnum; | |
17 | +import org.thingsboard.server.common.data.yunteng.enums.ResponseCodeEnum; | |
18 | +import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; | |
19 | +import org.thingsboard.server.dao.yunteng.entities.MailLog; | |
20 | +import org.thingsboard.server.dao.yunteng.entities.MessageConfig; | |
21 | +import org.thingsboard.server.dao.yunteng.entities.MessageTemplate; | |
22 | +import org.thingsboard.server.dao.yunteng.mapper.MaiLogMapper; | |
23 | +import org.thingsboard.server.dao.yunteng.mapper.MessageConfigMapper; | |
24 | +import org.thingsboard.server.dao.yunteng.mapper.MessageTemplateMapper; | |
25 | +import org.thingsboard.server.dao.yunteng.service.YtMailService; | |
26 | + | |
27 | +import java.io.File; | |
28 | +import java.io.IOException; | |
29 | +import java.time.LocalDateTime; | |
30 | +import java.util.Date; | |
31 | +import java.util.Properties; | |
32 | + | |
33 | +@Slf4j | |
34 | +@Service | |
35 | +@RequiredArgsConstructor | |
36 | +public class YtMailServiceImpl implements YtMailService { | |
37 | + | |
38 | + private final MessageTemplateMapper messageTemplateMapper; | |
39 | + | |
40 | + private final MessageConfigMapper messageConfigMapper; | |
41 | + | |
42 | + private final MaiLogMapper maiLogMapper; | |
43 | + | |
44 | + @Override | |
45 | + public boolean sendEmail(EmailReqDTO emailReqDTO) { | |
46 | + boolean result =false; | |
47 | + //查询模板信息 | |
48 | + MessageTemplate messageTemplate = messageTemplateMapper.selectById(emailReqDTO.getId()); | |
49 | + if(null == messageTemplate){ | |
50 | + throw new DataValidationException("invalid parameters"); | |
51 | + } | |
52 | + MessageConfig messageConfig =messageConfigMapper.selectById(messageTemplate.getMessageConfigId()); | |
53 | + if (messageConfig.getStatus() != FastIotConstants.StateValue.ENABLE) { | |
54 | + throw new DataValidationException("messageConfig is disable"); | |
55 | + } | |
56 | + JsonNode configNode = messageConfig.getConfig(); | |
57 | + EmailConfiguration emailConfiguration = JacksonUtil.convertValue(configNode, EmailConfiguration.class); | |
58 | + if(emailConfiguration !=null){ | |
59 | + Properties props = new Properties(); | |
60 | + // 要连接的SMTP服务器 | |
61 | + props.put("mail.smtp.host", emailConfiguration.getHost()); | |
62 | + // 如果 connect()方法未明确指定一个,则要连接的SMTP服务器端口。默认为25 | |
63 | + props.put("mail.smtp.port", emailConfiguration.getPort()); | |
64 | + props.put("mail.smtp.user", emailConfiguration.getUsername()); | |
65 | + props.put("mail.smtp.pass", emailConfiguration.getPassword()); | |
66 | + props.put("mail.smtp.ssl.enable", "true"); | |
67 | + // 如果为true,请尝试使用AUTH命令对用户进行身份验证。默认为false。 | |
68 | + props.put("mail.smtp.auth", "true"); | |
69 | + // 使用ssl | |
70 | + props.put("mail.smtp.ssl.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); | |
71 | + props.put("mail.smtp.socketFactory.port",emailConfiguration.getPort()); | |
72 | + | |
73 | + try { | |
74 | + Session session = | |
75 | + Session.getInstance( | |
76 | + props, | |
77 | + new Authenticator() { | |
78 | + @Override | |
79 | + protected PasswordAuthentication getPasswordAuthentication() { | |
80 | + if (Boolean.parseBoolean(props.getProperty("mail.smtp.auth"))) { | |
81 | + // 需要认证 | |
82 | + return new PasswordAuthentication( | |
83 | + props.getProperty("mail.smtp.user"), | |
84 | + props.getProperty("mail.smtp.pass")); | |
85 | + } | |
86 | + return super.getPasswordAuthentication(); | |
87 | + } | |
88 | + }); | |
89 | + | |
90 | + MimeMessage mimeMessage = new MimeMessage(session); | |
91 | + // 邮件发送人 | |
92 | + mimeMessage.setFrom(new InternetAddress(emailConfiguration.getUsername())); | |
93 | + setRecipients(emailReqDTO,mimeMessage); | |
94 | + // 邮件主题 | |
95 | + mimeMessage.setSubject(emailReqDTO.getSubject()); | |
96 | + // 邮件内容部分 | |
97 | + MimeBodyPart mimeBodyPart = new MimeBodyPart(); | |
98 | + String chartSet = "text/html;charset=utf-8"; | |
99 | + if (emailReqDTO.getEmailFormatEnum().equals(EmailFormatEnum.TEXT.name())) { | |
100 | + mimeBodyPart.setText(emailReqDTO.getBody()); | |
101 | + } else { | |
102 | + mimeBodyPart.setContent(emailReqDTO.getBody(), chartSet); | |
103 | + } | |
104 | + Multipart multipart = new MimeMultipart(); | |
105 | + multipart.addBodyPart(mimeBodyPart); | |
106 | + | |
107 | + //如果有附件就添加附件 | |
108 | + if(null != emailReqDTO.getFiles() && emailReqDTO.getFiles().length>0){ | |
109 | + addFiles(multipart,emailReqDTO.getFiles()); | |
110 | + } | |
111 | + mimeMessage.setContent(multipart); | |
112 | + mimeMessage.setSentDate(new Date()); | |
113 | + Transport.send(mimeMessage); | |
114 | + result = true; | |
115 | + } catch (Exception exception){ | |
116 | + log.error("send email failed",exception); | |
117 | + } | |
118 | + MailLog mailLog = new MailLog(); | |
119 | + mailLog.setEmailFrom(emailConfiguration.getUsername()); | |
120 | + mailLog.setEmailTo(JacksonUtil.toJsonNode(JacksonUtil.toString(emailReqDTO.getTo()))); | |
121 | + mailLog.setEmailCc(JacksonUtil.toJsonNode(JacksonUtil.toString(emailReqDTO.getCc()))); | |
122 | + mailLog.setEmailBcc(JacksonUtil.toJsonNode(JacksonUtil.toString(emailReqDTO.getBcc()))); | |
123 | + mailLog.setEmailSubject(emailReqDTO.getSubject()); | |
124 | + mailLog.setEmailBody(emailReqDTO.getBody()); | |
125 | + mailLog.setTenantId(messageTemplate.getTenantId()); | |
126 | + mailLog.setSendTime(LocalDateTime.now()); | |
127 | + mailLog.setMessageTemplateId(messageTemplate.getId()); | |
128 | + mailLog.setStatus(result ? ResponseCodeEnum.SUCCESS.name() : ResponseCodeEnum.FAILED.name()); | |
129 | + mailLog.setRemark(emailReqDTO.getRemark()); | |
130 | + mailLog.setTemplatePurpose(emailReqDTO.getTemplatePurpose()); | |
131 | + maiLogMapper.insert(mailLog); | |
132 | + return result; | |
133 | + } | |
134 | + return false; | |
135 | + } | |
136 | + | |
137 | + /** | |
138 | + * 添加接收人、抄送人、密送人 | |
139 | + * @param emailReqDTO 邮件参数 | |
140 | + * @param mimeMessage 邮件消息体 | |
141 | + * @throws MessagingException 消息发送失败异常 | |
142 | + */ | |
143 | + private void setRecipients(EmailReqDTO emailReqDTO, MimeMessage mimeMessage) | |
144 | + throws MessagingException { | |
145 | + // 邮件接收人多个 | |
146 | + InternetAddress[] toAddress = addInternetAddress(emailReqDTO.getTo()); | |
147 | + mimeMessage.setRecipients(Message.RecipientType.TO, toAddress); | |
148 | + | |
149 | + if(null != emailReqDTO.getCc() && emailReqDTO.getCc().length>0){ | |
150 | + // 邮件抄送人多个 | |
151 | + InternetAddress[] ccAddress = addInternetAddress(emailReqDTO.getCc()); | |
152 | + mimeMessage.setRecipients(Message.RecipientType.CC, ccAddress); | |
153 | + } | |
154 | + if(null != emailReqDTO.getBcc() &&emailReqDTO.getBcc().length>0){ | |
155 | + // 邮件密送人多个 | |
156 | + InternetAddress[] bccAddress = addInternetAddress(emailReqDTO.getBcc()); | |
157 | + mimeMessage.setRecipients(Message.RecipientType.BCC, bccAddress); | |
158 | + } | |
159 | + } | |
160 | + | |
161 | + /** | |
162 | + * 添加收件人地址 | |
163 | + * @param content 接收人、抄送人、密送人数组 | |
164 | + * @return 添加收件人地址 | |
165 | + * @throws MessagingException 地址异常 | |
166 | + */ | |
167 | + private InternetAddress[] addInternetAddress(String[] content) | |
168 | + throws MessagingException { | |
169 | + InternetAddress[] address = new InternetAddress[content.length]; | |
170 | + for (int i = 0,j = content.length;i<j; i++) { | |
171 | + address[i] = new InternetAddress(content[i]); | |
172 | + } | |
173 | + return address; | |
174 | + } | |
175 | + | |
176 | + /** | |
177 | + * 添加附件 | |
178 | + * @param multipart Multipart | |
179 | + * @param files 附件 | |
180 | + * @throws MessagingException 消息发送失败异常 | |
181 | + * @throws IOException IO流异常 | |
182 | + */ | |
183 | + private void addFiles(Multipart multipart,File[] files) throws MessagingException, IOException { | |
184 | + for (File file : files) { | |
185 | + MimeBodyPart attachment = new MimeBodyPart(); | |
186 | + attachment.attachFile(file); | |
187 | + multipart.addBodyPart(attachment); | |
188 | + } | |
189 | + } | |
190 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtMessageConfigServiceImpl.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | |
5 | +import lombok.RequiredArgsConstructor; | |
6 | +import lombok.extern.slf4j.Slf4j; | |
7 | +import org.apache.commons.lang3.StringUtils; | |
8 | +import org.springframework.stereotype.Service; | |
9 | +import org.springframework.transaction.annotation.Transactional; | |
10 | +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; | |
11 | +import org.thingsboard.server.common.data.yunteng.core.exception.DataValidationException; | |
12 | +import org.thingsboard.server.common.data.yunteng.dto.MessageConfigDTO; | |
13 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
14 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
15 | +import org.thingsboard.server.dao.yunteng.entities.MessageConfig; | |
16 | +import org.thingsboard.server.dao.yunteng.mapper.MessageConfigMapper; | |
17 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | |
18 | +import org.thingsboard.server.dao.yunteng.service.YtMessageConfigService; | |
19 | + | |
20 | +import java.util.List; | |
21 | +import java.util.Map; | |
22 | +import java.util.Set; | |
23 | + | |
24 | +@Service | |
25 | +@Slf4j | |
26 | +@RequiredArgsConstructor | |
27 | +public class YtMessageConfigServiceImpl | |
28 | + extends AbstractBaseService<MessageConfigMapper, MessageConfig> | |
29 | + implements YtMessageConfigService { | |
30 | + | |
31 | + @Override | |
32 | + public PageData<MessageConfigDTO> page(String tenantId,Map<String, Object> queryMap) { | |
33 | + IPage<MessageConfig> configIPage = | |
34 | + baseMapper.selectPage( | |
35 | + getPage(queryMap, "create_time", false), | |
36 | + new QueryWrapper<MessageConfig>() | |
37 | + .lambda() | |
38 | + .eq( | |
39 | + queryMap.get("platformType") != null, | |
40 | + MessageConfig::getPlatformType, | |
41 | + String.valueOf(queryMap.get("platformType"))) | |
42 | + .eq( | |
43 | + queryMap.get("messageType") != null, | |
44 | + MessageConfig::getMessageType, | |
45 | + String.valueOf(queryMap.get("messageType"))) | |
46 | + .eq( | |
47 | + queryMap.get("status") != null, | |
48 | + MessageConfig::getStatus, | |
49 | + String.valueOf(queryMap.get("status"))) | |
50 | + .eq( | |
51 | + true, | |
52 | + MessageConfig::getTenantId,tenantId)); | |
53 | + return getPageData(configIPage, MessageConfigDTO.class); | |
54 | + } | |
55 | + | |
56 | + @Override | |
57 | + @Transactional | |
58 | + public MessageConfigDTO saveMessageConfig(String tenantId,MessageConfigDTO configDTO) { | |
59 | + checkMessageConfig(configDTO, tenantId); | |
60 | + MessageConfig config = new MessageConfig(); | |
61 | + configDTO.copyToEntity(config); | |
62 | + config.setTenantId(tenantId); | |
63 | + baseMapper.insert(config); | |
64 | + config.copyToDTO(configDTO); | |
65 | + return configDTO; | |
66 | + } | |
67 | + | |
68 | + @Override | |
69 | + @Transactional | |
70 | + public boolean deleteMessageConfig(Set<String> ids) { | |
71 | + return baseMapper.deleteBatchIds(ids) > 0; | |
72 | + } | |
73 | + | |
74 | + @Override | |
75 | + @Transactional | |
76 | + public MessageConfigDTO updateMessageConfig(String tenantId,MessageConfigDTO configDTO) { | |
77 | + MessageConfig config = baseMapper.selectById(configDTO.getId()); | |
78 | + if (configDTO.getStatus() == FastIotConstants.StateValue.ENABLE) { | |
79 | + if (StringUtils.isEmpty(config.getId())) { | |
80 | + throw new DataValidationException("invalid parameters"); | |
81 | + } | |
82 | + checkMessageConfig(configDTO, tenantId); | |
83 | + } | |
84 | + configDTO.copyToEntity(config); | |
85 | + config.setTenantId(tenantId); | |
86 | + | |
87 | + baseMapper.updateById(config); | |
88 | + config.copyToDTO(configDTO); | |
89 | + return configDTO; | |
90 | + } | |
91 | + | |
92 | + /** | |
93 | + * 通过租户Code、消息类型和平台类型获取启用的配置 | |
94 | + * | |
95 | + * @param messageType 消息类型 | |
96 | + * @param platform 平台类型 | |
97 | + * @param tenantCode 租户Code | |
98 | + * @return 启用的配置信息 | |
99 | + */ | |
100 | + @Override | |
101 | + public MessageConfigDTO getEnableConfigByMessageAndPlatform( | |
102 | + String messageType, String platform, String tenantCode) { | |
103 | + return baseMapper.getEnableConfigByMessageAndPlatform(messageType, platform, tenantCode); | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * 通过ID查询MessageConfig信息 | |
108 | + * | |
109 | + * @param id 主键ID | |
110 | + * @return 返回类型:MessageConfigDTO | |
111 | + */ | |
112 | + @Override | |
113 | + public MessageConfigDTO findMessageConfigById(String id) { | |
114 | + MessageConfigDTO messageConfigDTO = new MessageConfigDTO(); | |
115 | + MessageConfig messageConfig = baseMapper.selectById(id); | |
116 | + if (null == messageConfig) { | |
117 | + return null; | |
118 | + } | |
119 | + messageConfig.copyToDTO(messageConfigDTO); | |
120 | + return messageConfigDTO; | |
121 | + } | |
122 | + | |
123 | + @Override | |
124 | + public List<MessageConfigDTO> findMessageInfo(MessageConfigDTO configDTO) { | |
125 | + return ReflectUtils.sourceToTarget( | |
126 | + baseMapper.selectList( | |
127 | + new QueryWrapper<MessageConfig>() | |
128 | + .lambda() | |
129 | + .eq( | |
130 | + configDTO.getMessageType() != null, | |
131 | + MessageConfig::getMessageType, | |
132 | + configDTO.getMessageType())), | |
133 | + MessageConfigDTO.class); | |
134 | + } | |
135 | + | |
136 | + /** | |
137 | + * 检查MessageConfig状态 | |
138 | + * | |
139 | + * @param configDTO MessageConfig配置 | |
140 | + * @param tenantCode 租户Code | |
141 | + */ | |
142 | + private void checkMessageConfig(MessageConfigDTO configDTO, String tenantCode) { | |
143 | + // 查询该租户下是否有相同消息类型和平台的配置已经启用 | |
144 | + MessageConfigDTO enableConfig = | |
145 | + getEnableConfigByMessageAndPlatform( | |
146 | + configDTO.getMessageType(), configDTO.getPlatformType(), tenantCode); | |
147 | + if (null != enableConfig && !enableConfig.getId().equalsIgnoreCase(configDTO.getId())) { | |
148 | + throw new DataValidationException("enabled config is existed"); | |
149 | + } | |
150 | + } | |
151 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtMessageTemplateServiceImpl.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/MessageTemplateServiceImpl.java
... | ... | @@ -13,7 +13,7 @@ import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; |
13 | 13 | import org.thingsboard.server.dao.yunteng.entities.MessageTemplate; |
14 | 14 | import org.thingsboard.server.dao.yunteng.mapper.MessageTemplateMapper; |
15 | 15 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
16 | -import org.thingsboard.server.dao.yunteng.service.MessageTemplateService; | |
16 | +import org.thingsboard.server.dao.yunteng.service.YtMessageTemplateService; | |
17 | 17 | |
18 | 18 | import java.util.List; |
19 | 19 | import java.util.Map; |
... | ... | @@ -22,9 +22,9 @@ import java.util.Set; |
22 | 22 | @Service |
23 | 23 | @Slf4j |
24 | 24 | @RequiredArgsConstructor |
25 | -public class MessageTemplateServiceImpl | |
25 | +public class YtMessageTemplateServiceImpl | |
26 | 26 | extends AbstractBaseService<MessageTemplateMapper, MessageTemplate> |
27 | - implements MessageTemplateService { | |
27 | + implements YtMessageTemplateService { | |
28 | 28 | @Override |
29 | 29 | public PageData<MessageTemplateDTO> page(Map<String, Object> queryMap) { |
30 | 30 | // queryMap.put("tenantCode",SecurityContext.getCurrentUser().getTenantCode()); | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.impl; | |
2 | + | |
3 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |
4 | +import lombok.RequiredArgsConstructor; | |
5 | +import org.springframework.stereotype.Service; | |
6 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
7 | +import org.thingsboard.server.common.data.yunteng.dto.request.EmailReqDTO; | |
8 | +import org.thingsboard.server.common.data.yunteng.dto.request.SmsReqDTO; | |
9 | +import org.thingsboard.server.common.data.yunteng.enums.AssetStatusEnum; | |
10 | +import org.thingsboard.server.common.data.yunteng.enums.MessageTypeEnum; | |
11 | +import org.thingsboard.server.common.data.yunteng.enums.MsgTemplatePurposeEnum; | |
12 | +import org.thingsboard.server.dao.yunteng.entities.*; | |
13 | +import org.thingsboard.server.dao.yunteng.mapper.*; | |
14 | +import org.thingsboard.server.dao.yunteng.service.YtNoticeService; | |
15 | +import org.thingsboard.server.dao.yunteng.service.YtMailService; | |
16 | +import org.thingsboard.server.dao.yunteng.service.YtSmsService; | |
17 | + | |
18 | +import java.time.LocalDateTime; | |
19 | +import java.time.OffsetDateTime; | |
20 | +import java.time.format.DateTimeFormatter; | |
21 | +import java.util.*; | |
22 | +import java.util.stream.Collectors; | |
23 | + | |
24 | +/** | |
25 | + * @version V1.0 | |
26 | + * @Description : | |
27 | + * 1.其它地方抛出异常,交由控制层统一处理 | |
28 | + * 2.服务层注意持久化的事务管理 | |
29 | + * @Dependency: 依赖包 | |
30 | + * @Author: junlianglee | |
31 | + * @Date Created in 2021/11/23$ | |
32 | + * @Copyright 2016-2018 - Powered By 云腾五洲 | |
33 | + */ | |
34 | +@Service | |
35 | +@RequiredArgsConstructor | |
36 | +public class YtNoticeServiceImpl implements YtNoticeService { | |
37 | + | |
38 | + private final DeviceMapper deviceMapper; | |
39 | + private final OrganizationMapper organizationMapper; | |
40 | + private final AlarmProfileMapper alarmProfileMapper; | |
41 | + private final AlarmContactMapper alarmContactMapper; | |
42 | + private final MessageTemplateMapper messageTemplateMapper; | |
43 | + | |
44 | + private final YtSmsService smsService; | |
45 | + private final YtMailService mailService; | |
46 | + | |
47 | + @Override | |
48 | + public void alert(String token, AlarmInfoDTO alarmInfo) { | |
49 | + | |
50 | + //TODO 查找设备和设备所属组织 | |
51 | + QueryWrapper<YtDevice> queryWrapper=new QueryWrapper<YtDevice>(); | |
52 | + queryWrapper.lambda() | |
53 | + .eq(YtDevice::getTbDeviceId, alarmInfo.getDeviceId()); | |
54 | + YtDevice device = deviceMapper.selectOne(queryWrapper); | |
55 | + | |
56 | + | |
57 | + //TODO 查找告警配置 ,与设备配置一一对应。 | |
58 | + if(device == null){ | |
59 | + return; | |
60 | + } | |
61 | + QueryWrapper<Organization> organizationQueryWrapper=new QueryWrapper<Organization>(); | |
62 | + organizationQueryWrapper.lambda() | |
63 | + .eq(Organization::getId, device.getOrganizationId()); | |
64 | + Organization organization = organizationMapper.selectOne(organizationQueryWrapper); | |
65 | + | |
66 | + QueryWrapper<AlarmProfile> alarmProfileQueryWrapper=new QueryWrapper<AlarmProfile>(); | |
67 | + alarmProfileQueryWrapper.lambda() | |
68 | + .eq(AlarmProfile::getDeviceProfileId, device.getProfileId()); | |
69 | + AlarmProfile alarmProfile = alarmProfileMapper.selectOne(alarmProfileQueryWrapper); | |
70 | + | |
71 | + | |
72 | + //TODO 查找告警通知联系人 | |
73 | + if(alarmProfile == null || alarmProfile.getAlarmContactId().isEmpty() || alarmProfile.getMessageMode().isEmpty()){ | |
74 | + return; | |
75 | + } | |
76 | + String messageCode = alarmProfile.getMessageMode(); | |
77 | + List<AlarmContact> alarmContactList = alarmContactMapper.selectBatchIds(Arrays.stream(alarmProfile.getAlarmContactId().split(",")).distinct().collect(Collectors.toList())); | |
78 | + noticeAll(messageCode, alarmContactList,alarmInfo,organization); | |
79 | + | |
80 | + | |
81 | + } | |
82 | + | |
83 | + /** | |
84 | + * 通知所有联系人 | |
85 | + * @param messageCode 通知类型 | |
86 | + * @param alarmContactList 通知联系人 | |
87 | + * @param alarmInfo 通知内容 | |
88 | + * @param organization 设备所属组织 | |
89 | + */ | |
90 | + private void noticeAll(String messageCode, List<AlarmContact> alarmContactList, AlarmInfoDTO alarmInfo, Organization organization) { | |
91 | + Optional.ofNullable(alarmContactList).ifPresent(contacts ->{ | |
92 | + QueryWrapper<MessageTemplate> messageTemplateQueryWrapper=new QueryWrapper<MessageTemplate>(); | |
93 | + messageTemplateQueryWrapper.lambda() | |
94 | +// .eq(MessageTemplate::getTenantCode, SecurityContext.getCurrentUser().getTenantCode()) | |
95 | + .eq(MessageTemplate::getTemplatePurpose, MsgTemplatePurposeEnum.FOR_ALARM_NOTICE.name()) | |
96 | + .eq(MessageTemplate::getStatus, AssetStatusEnum.ENABLE.ordinal()); | |
97 | + List<MessageTemplate>templateList = messageTemplateMapper.selectList(messageTemplateQueryWrapper); | |
98 | + Map<String,String> templatesMap = new HashMap<>(); | |
99 | + Optional.ofNullable(templateList).ifPresent(all ->{ | |
100 | + for(MessageTemplate item: all){ | |
101 | + templatesMap.put(item.getMessageType(),item.getId()); | |
102 | + } | |
103 | + }); | |
104 | + contacts.stream().parallel().forEach(item ->{ | |
105 | + if(messageCode.contains(MessageTypeEnum.PHONE_MESSAGE.name()) | |
106 | + &&templatesMap.containsKey(MessageTypeEnum.PHONE_MESSAGE.name()) | |
107 | + && !item.getPhone().isEmpty()){ | |
108 | + | |
109 | + | |
110 | + | |
111 | + | |
112 | + SmsReqDTO info = new SmsReqDTO(); | |
113 | + info.setId(templatesMap.get(MessageTypeEnum.PHONE_MESSAGE.name())); | |
114 | + info.setPhoneNumbers(item.getPhone()); | |
115 | + LinkedHashMap<String, String> params = new LinkedHashMap<>(); | |
116 | + //name-其他;device_name-其他;level-其他;location-其他;alarm_value-其他; | |
117 | + params.put("type", alarmInfo.getType()); | |
118 | + params.put("device_name", alarmInfo.getDeviceName()); | |
119 | + params.put("severity", alarmInfo.getSeverity()); | |
120 | + params.put("organization", organization!=null?organization.getName():""); | |
121 | + LocalDateTime createTime = LocalDateTime.ofEpochSecond(alarmInfo.getCreateTs()/1000,0, OffsetDateTime.now().getOffset()); | |
122 | + params.put("createtime", createTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); | |
123 | + info.setParams(params); | |
124 | + smsService.sendSms(info); | |
125 | + } | |
126 | + | |
127 | + if(messageCode.contains(MessageTypeEnum.EMAIL_MESSAGE.name()) | |
128 | + &&templatesMap.containsKey(MessageTypeEnum.EMAIL_MESSAGE.name()) | |
129 | + && !item.getEmail().isEmpty()){ | |
130 | + EmailReqDTO info = new EmailReqDTO(); | |
131 | + mailService.sendEmail(info); | |
132 | + } | |
133 | + | |
134 | + | |
135 | + if(messageCode.contains(MessageTypeEnum.DING_TALK_MESSAGE.name()) | |
136 | + &&templatesMap.containsKey(MessageTypeEnum.DING_TALK_MESSAGE.name()) | |
137 | + && !item.getDingtalk().isEmpty()){ | |
138 | + | |
139 | + } | |
140 | + | |
141 | + if(messageCode.contains(MessageTypeEnum.WECHAT_MESSAGE.name()) | |
142 | + &&templatesMap.containsKey(MessageTypeEnum.WECHAT_MESSAGE.name()) | |
143 | + && !item.getWechat().isEmpty()){ | |
144 | + | |
145 | + } | |
146 | + }); | |
147 | + }); | |
148 | + } | |
149 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtOrganizationServiceImpl.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/OrganizationServiceImpl.java
... | ... | @@ -20,15 +20,15 @@ import org.thingsboard.server.dao.yunteng.mapper.OrganizationMapper; |
20 | 20 | import org.thingsboard.server.dao.yunteng.mapper.UserMapper; |
21 | 21 | import org.thingsboard.server.dao.yunteng.mapper.UserOrganizationMappingMapper; |
22 | 22 | import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; |
23 | -import org.thingsboard.server.dao.yunteng.service.OrganizationService; | |
23 | +import org.thingsboard.server.dao.yunteng.service.YtOrganizationService; | |
24 | 24 | |
25 | 25 | import java.util.*; |
26 | 26 | import java.util.stream.Collectors; |
27 | 27 | |
28 | 28 | @Service |
29 | 29 | @RequiredArgsConstructor |
30 | -public class OrganizationServiceImpl extends AbstractBaseService<OrganizationMapper, Organization> | |
31 | - implements OrganizationService { | |
30 | +public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationMapper, Organization> | |
31 | + implements YtOrganizationService { | |
32 | 32 | |
33 | 33 | private final UserOrganizationMappingMapper userOrganizationMappingMapper; |
34 | 34 | private final UserMapper userMapper; |
... | ... | @@ -44,7 +44,7 @@ public class OrganizationServiceImpl extends AbstractBaseService<OrganizationMap |
44 | 44 | throw new DataValidationException("parent organization not exist!"); |
45 | 45 | } else { |
46 | 46 | if (!organization |
47 | - .getTenantCode() | |
47 | + .getTenantId() | |
48 | 48 | .equals(null)) {//TODO getCurrentUser().getTenantCode() |
49 | 49 | throw new DataValidationException("parent organization not exist."); |
50 | 50 | } | ... | ... |
... | ... | @@ -8,7 +8,6 @@ import lombok.RequiredArgsConstructor; |
8 | 8 | import lombok.extern.slf4j.Slf4j; |
9 | 9 | import org.apache.commons.lang3.RandomStringUtils; |
10 | 10 | import org.apache.commons.lang3.StringUtils; |
11 | -import org.springframework.beans.factory.annotation.Autowired; | |
12 | 11 | import org.springframework.stereotype.Service; |
13 | 12 | import org.springframework.transaction.annotation.Transactional; |
14 | 13 | import org.thingsboard.common.util.JacksonUtil; |
... | ... | @@ -98,7 +97,7 @@ public class YtSmsServiceImpl implements YtSmsService { |
98 | 97 | smsLog.setMessageTemplateId(messageTemplate.getId()); |
99 | 98 | smsLog.setTemplateParam(JacksonUtil.toJsonNode(JacksonUtil.toString(templateParam))); |
100 | 99 | smsLog.setSendTime(LocalDateTime.now()); |
101 | - smsLog.setTenantCode(messageTemplate.getTenantCode()); | |
100 | + smsLog.setTenantCode(messageTemplate.getTenantId()); | |
102 | 101 | smsLog.setTemplatePurpose(smsReqDTO.getTemplatePurpose()); |
103 | 102 | smsLogMapper.insert(smsLog); |
104 | 103 | return ResponseCodeEnum.SUCCESS.name().equals(result); | ... | ... |
... | ... | @@ -46,7 +46,7 @@ public class YtTenantServiceImpl extends AbstractBaseService<TenantMapper, Tenan |
46 | 46 | baseMapper.insert(tenant); |
47 | 47 | // 调用TB API |
48 | 48 | tenant.copyToDTO(tenantDTO); |
49 | - saveTenantMapping(tenantDTO.getTenantCode(), tenantReqDTO.getRoleIds()); | |
49 | + saveTenantMapping(tenantDTO.getTenantId(), tenantReqDTO.getRoleIds()); | |
50 | 50 | return tenantDTO; |
51 | 51 | } |
52 | 52 | |
... | ... | @@ -76,20 +76,20 @@ public class YtTenantServiceImpl extends AbstractBaseService<TenantMapper, Tenan |
76 | 76 | } |
77 | 77 | |
78 | 78 | private void processTenantCode(TenantDTO tenantDTO) { |
79 | - if (tenantDTO.getTenantCode() != null) { | |
80 | - if (tenantDTO.getTenantCode().length() > 30) { | |
79 | + if (tenantDTO.getTenantId() != null) { | |
80 | + if (tenantDTO.getTenantId().length() > 30) { | |
81 | 81 | throw new DataValidationException("tenant code too long"); |
82 | 82 | } |
83 | 83 | int count = |
84 | 84 | baseMapper.selectCount( |
85 | 85 | new QueryWrapper<Tenant>() |
86 | 86 | .lambda() |
87 | - .eq(Tenant::getTenantCode, tenantDTO.getTenantCode())); | |
87 | + .eq(Tenant::getTenantCode, tenantDTO.getTenantId())); | |
88 | 88 | if (count > 0) { |
89 | 89 | throw new DataValidationException("tenant code already exist"); |
90 | 90 | } |
91 | 91 | } else { |
92 | - tenantDTO.setTenantCode(RandomStringUtils.randomAlphabetic(20)); | |
92 | + tenantDTO.setTenantId(RandomStringUtils.randomAlphabetic(20)); | |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
... | ... | @@ -130,7 +130,7 @@ public class YtTenantServiceImpl extends AbstractBaseService<TenantMapper, Tenan |
130 | 130 | menuMapper.deleteTenantMenuMappingByMenuIds(allMenuIds); |
131 | 131 | } |
132 | 132 | // 4. DELETE USER |
133 | - userMapper.delete(new QueryWrapper<User>().lambda().in(User::getTenantCode, tenantCodes)); | |
133 | + userMapper.delete(new QueryWrapper<User>().lambda().in(User::getTenantId, tenantCodes)); | |
134 | 134 | // 5. TELL RULE ENGINE TO STOP TENANT |
135 | 135 | // 6. DELETE OTHER RESOURCES IF ANY |
136 | 136 | // 7. DELETE TENANT | ... | ... |
... | ... | @@ -59,8 +59,8 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
59 | 59 | private final TenantRoleMapper tenantRoleMapper; |
60 | 60 | |
61 | 61 | private final YtSmsService ytSmsService; |
62 | - private final MessageTemplateService messageTemplateService; | |
63 | - private final OrganizationService groupService; | |
62 | + private final YtMessageTemplateService messageTemplateService; | |
63 | + private final YtOrganizationService groupService; | |
64 | 64 | |
65 | 65 | public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s"; |
66 | 66 | private final PasswordEncoder passwordEncoder; |
... | ... | @@ -98,7 +98,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
98 | 98 | if (isAdminOperate) { |
99 | 99 | // 添加的租户管理员 |
100 | 100 | if (StringUtils.isNotBlank(userDTO.getTenantCode())) { |
101 | - user.setTenantCode(userDTO.getTenantCode()); | |
101 | + user.setTenantId(userDTO.getTenantCode()); | |
102 | 102 | user.setPassword(passwordEncoder.encode(DEFAULT_PWD)); |
103 | 103 | int tenantExist = |
104 | 104 | tenantMapper.selectCount( |
... | ... | @@ -111,24 +111,24 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
111 | 111 | } else { |
112 | 112 | // 添加的平台系统其他用户 |
113 | 113 | user.setLevel(FastIotConstants.LevelValue.IS_OTHER_ADMIN); |
114 | - user.setTenantCode(tenantId); | |
114 | + user.setTenantId(tenantId); | |
115 | 115 | } |
116 | 116 | userExist = |
117 | 117 | baseMapper.selectCount( |
118 | 118 | new QueryWrapper<User>() |
119 | 119 | .lambda() |
120 | 120 | .eq(User::getUsername, userDTO.getUsername()) |
121 | - .eq(User::getTenantCode, userDTO.getTenantCode())) | |
121 | + .eq(User::getTenantId, userDTO.getTenantCode())) | |
122 | 122 | > 0; |
123 | 123 | } else { |
124 | 124 | user.setLevel(FastIotConstants.LevelValue.IS_NORMAL); |
125 | - user.setTenantCode(tenantId); | |
125 | + user.setTenantId(tenantId); | |
126 | 126 | userExist = |
127 | 127 | baseMapper.selectCount( |
128 | 128 | new QueryWrapper<User>() |
129 | 129 | .lambda() |
130 | 130 | .eq(User::getUsername, userDTO.getUsername()) |
131 | - .eq(User::getTenantCode, tenantId)) | |
131 | + .eq(User::getTenantId, tenantId)) | |
132 | 132 | > 0; |
133 | 133 | } |
134 | 134 | if (userExist) { |
... | ... | @@ -170,7 +170,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
170 | 170 | public String getActivationLink(String userId,boolean isSysadmin,String tenantId) { |
171 | 171 | User user = baseMapper.selectById(userId); |
172 | 172 | if (!isSysadmin |
173 | - && tenantId.equals(user.getTenantCode())) { | |
173 | + && tenantId.equals(user.getTenantId())) { | |
174 | 174 | throw new AccessDeniedException( |
175 | 175 | "you don't have permission to get activation link for this user"); |
176 | 176 | } |
... | ... | @@ -224,7 +224,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
224 | 224 | UserDTO userDTO = new UserDTO(); |
225 | 225 | user.copyToDTO(userDTO, PASSWORD, ACTIVATE_TOKEN); |
226 | 226 | if (!isSysadmin |
227 | - && !tenantId.equals(user.getTenantCode())) { | |
227 | + && !tenantId.equals(user.getTenantId())) { | |
228 | 228 | return Optional.empty(); |
229 | 229 | } |
230 | 230 | return Optional.of(userDTO); |
... | ... | @@ -239,7 +239,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
239 | 239 | Assert.notNull(userDTO.getId(), "user is must be specified"); |
240 | 240 | User user = baseMapper.selectById(userDTO.getId()); |
241 | 241 | if (!isSysadmin |
242 | - && !user.getTenantCode().equals(tenantId)) { | |
242 | + && !user.getTenantId().equals(tenantId)) { | |
243 | 243 | throw new NoneTenantAssetException("this user not belong to current tenant"); |
244 | 244 | } |
245 | 245 | if (!user.getUsername().equals(userDTO.getUsername())) { |
... | ... | @@ -325,7 +325,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
325 | 325 | baseMapper.selectCount( |
326 | 326 | new QueryWrapper<User>() |
327 | 327 | .lambda() |
328 | - .ne(User::getTenantCode, tenantId) | |
328 | + .ne(User::getTenantId, tenantId) | |
329 | 329 | .in(User::getId, userIds)); |
330 | 330 | if (notTenantUserCount > 0) { |
331 | 331 | throw new AccessDeniedException("cannot delete user that not belong to your tenant"); |
... | ... | @@ -388,7 +388,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
388 | 388 | if (user == null) { |
389 | 389 | return; |
390 | 390 | } |
391 | - if (tenantId.equals(user.getTenantCode())) { | |
391 | + if (tenantId.equals(user.getTenantId())) { | |
392 | 392 | baseMapper.setPassword2NullAndInsertActiveToken( |
393 | 393 | userId, RandomStringUtils.randomAlphabetic(10)); |
394 | 394 | } |
... | ... | @@ -434,7 +434,7 @@ public class YtUserServiceImpl extends AbstractBaseService<UserMapper, User> imp |
434 | 434 | public Optional<List<UserDTO>> getOrganizationUserByOrganizationId(String groupId,String tenantId) { |
435 | 435 | Organization group = organizationMapper.selectById(groupId); |
436 | 436 | if (group == null |
437 | - || !group.getTenantCode().equals(tenantId)) { | |
437 | + || !group.getTenantId().equals(tenantId)) { | |
438 | 438 | return Optional.empty(); |
439 | 439 | } |
440 | 440 | Set<String> userIds = | ... | ... |
... | ... | @@ -3,13 +3,13 @@ package org.thingsboard.server.dao.yunteng.mapper; |
3 | 3 | |
4 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
5 | 5 | import org.apache.ibatis.annotations.Mapper; |
6 | -import org.thingsboard.server.common.data.DeviceProfile; | |
7 | 6 | import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; |
7 | +import org.thingsboard.server.dao.yunteng.entities.YtDeviceProfile; | |
8 | 8 | |
9 | 9 | import java.util.List; |
10 | 10 | |
11 | 11 | @Mapper |
12 | -public interface DeviceProfileMapper extends BaseMapper<DeviceProfile> { | |
12 | +public interface DeviceProfileMapper extends BaseMapper<YtDeviceProfile> { | |
13 | 13 | |
14 | 14 | List<DeviceProfileDTO> getDeviceProfileInfo(DeviceProfileDTO deviceProfileDTO); |
15 | 15 | } | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; | |
4 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
5 | + | |
6 | +import java.util.List; | |
7 | +import java.util.Map; | |
8 | + | |
9 | + | |
10 | +/** | |
11 | + * @Description 告警联系人的操作方法 | |
12 | + * @Author cxy | |
13 | + * @Date 2021/11/2 14:46 | |
14 | + */ | |
15 | + | |
16 | +public interface YtAlarmContactService { | |
17 | + /** | |
18 | + * 查询全部的告警联系人 | |
19 | + * | |
20 | + * @param | |
21 | + * @return List | |
22 | + */ | |
23 | + List<AlarmContactDTO> findAll(String tenantId,Map<String,Object> params); | |
24 | + | |
25 | + /** | |
26 | + * 添加告警联系人 | |
27 | + * | |
28 | + * @param alarmContactDTO 对象 | |
29 | + * @return AlarmContactDTO | |
30 | + */ | |
31 | + AlarmContactDTO saveAlarmContact(String tenantId,AlarmContactDTO alarmContactDTO); | |
32 | + | |
33 | + /** | |
34 | + * 删除告警联系人 | |
35 | + * | |
36 | + * @param ids 通过列表id | |
37 | + * @return i | |
38 | + */ | |
39 | + boolean delete(String[]ids); | |
40 | + | |
41 | + | |
42 | + /** | |
43 | + * 修改告警联系人数据 | |
44 | + * | |
45 | + * @param alarmContactDTO 对象 | |
46 | + * @return Integer | |
47 | + */ | |
48 | + boolean update(AlarmContactDTO alarmContactDTO); | |
49 | + | |
50 | + /** | |
51 | + * 分页查询 | |
52 | + * | |
53 | + * @param queryMap 查询集合 | |
54 | + * @return PageData | |
55 | + */ | |
56 | + PageData<AlarmContactDTO> page(Map<String, Object> queryMap); | |
57 | + | |
58 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
4 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
5 | + | |
6 | +import java.util.Map; | |
7 | + | |
8 | +/** @Description 告警中心数据业务层 @Author cxy @Date 2021/11/10 16:51 */ | |
9 | +public interface YtAlarmInfoService { | |
10 | + | |
11 | + /** | |
12 | + * 新增或修改告警中心数据 | |
13 | + * | |
14 | + * @param alarmInfoDto 对象 | |
15 | + * @return alarmInfoDto | |
16 | + */ | |
17 | +/* AlarmInfoDTO insertOrUpdate(AlarmInfoDTO alarmInfoDto);*/ | |
18 | + | |
19 | + /** | |
20 | + * 删除告警中心数据 | |
21 | + * | |
22 | + * @param ids id | |
23 | + * @return true和false | |
24 | + */ | |
25 | + /*boolean deleteAlarm(Set<String> ids);*/ | |
26 | + | |
27 | + /** | |
28 | + * 分页数据 | |
29 | + * | |
30 | + * @param queryMap 集合对象 | |
31 | + * @return AlarmInfoDto | |
32 | + */ | |
33 | + PageData<AlarmInfoDTO> page(Map<String, Object> queryMap); | |
34 | + /** | |
35 | + * 查询告警中心所有数据 | |
36 | + * | |
37 | + * @param alarmInfoDto 过滤参数 | |
38 | + * @return List<AlarmCenterDto> | |
39 | + */ | |
40 | + /*List<AlarmInfoDTO> findAlarmInfo(AlarmInfoDTO alarmInfoDto);*/ | |
41 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; | |
4 | + | |
5 | +import java.util.Set; | |
6 | + | |
7 | +public interface YtAlarmProfileService { | |
8 | + /** | |
9 | + * 保存告警设置 | |
10 | + * @param alarmProfileDTO 告警设置相关信息 | |
11 | + * @return AlarmProfileDTO | |
12 | + */ | |
13 | + AlarmProfileDTO saveOrUpdateAlarmProfile(String tenantId,AlarmProfileDTO alarmProfileDTO); | |
14 | + | |
15 | + /** | |
16 | + * 删除告警配置 | |
17 | + * @param ids 删除的ids | |
18 | + * @return 删除结果:true 成功 false 失败 | |
19 | + */ | |
20 | + boolean deleteAlarmProfile(Set<String> ids); | |
21 | + | |
22 | + /** | |
23 | + * 根据设备配置ID查询告警配置信息 | |
24 | + * @param deviceProfileId 设备配置ID | |
25 | + * @return 告警配置信息 | |
26 | + */ | |
27 | + AlarmProfileDTO findAlarmProfileByDeviceProfileId(String tenantId,String deviceProfileId); | |
28 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmContactDTO; | |
4 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
5 | + | |
6 | +import java.util.List; | |
7 | +import java.util.Map; | |
8 | + | |
9 | + | |
10 | +/** | |
11 | + * @Description 告警联系人的操作方法 | |
12 | + * @Author cxy | |
13 | + * @Date 2021/11/2 14:46 | |
14 | + */ | |
15 | + | |
16 | +public interface YtAlarmService { | |
17 | + /** | |
18 | + * 查询全部的告警联系人 | |
19 | + * | |
20 | + * @param alarmContactDTO 对象 | |
21 | + * @return List | |
22 | + */ | |
23 | + List<AlarmContactDTO> findAll(String tenantId,AlarmContactDTO alarmContactDTO); | |
24 | + | |
25 | + /** | |
26 | + * 添加告警联系人 | |
27 | + * | |
28 | + * @param alarmContactDTO 对象 | |
29 | + * @return AlarmContactDTO | |
30 | + */ | |
31 | + AlarmContactDTO saveAlarmContact(String tenantId,AlarmContactDTO alarmContactDTO); | |
32 | + | |
33 | + /** | |
34 | + * 删除告警联系人 | |
35 | + * | |
36 | + * @param ids 通过列表id | |
37 | + * @return i | |
38 | + */ | |
39 | + boolean delete(String[] ids); | |
40 | + | |
41 | + | |
42 | + /** | |
43 | + * 修改告警联系人数据 | |
44 | + * | |
45 | + * @param alarmContactDTO 对象 | |
46 | + * @return Integer | |
47 | + */ | |
48 | + AlarmContactDTO update(boolean istenantAdmin,String tenantId,AlarmContactDTO alarmContactDTO); | |
49 | + | |
50 | + /** | |
51 | + * 分页查询 | |
52 | + * | |
53 | + * @param queryMap 查询集合 | |
54 | + * @return PageData | |
55 | + */ | |
56 | + PageData<AlarmContactDTO> page(Map<String, Object> queryMap); | |
57 | + | |
58 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceProfileDTO; | |
4 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
5 | + | |
6 | +import java.util.List; | |
7 | +import java.util.Map; | |
8 | +import java.util.Optional; | |
9 | +import java.util.Set; | |
10 | + | |
11 | +public interface YtDeviceProfileService { | |
12 | + DeviceProfileDTO insertOrUpdate(String tenantId,DeviceProfileDTO deviceProfileDTO); | |
13 | + | |
14 | + void deleteDeviceProfiles(String tenantId,Set<String> ids); | |
15 | + | |
16 | + Optional<DeviceProfileDTO> getDeviceProfile(String tenantId,String id); | |
17 | + | |
18 | + PageData<DeviceProfileDTO> page(String tenantId, Map<String, Object> queryMap); | |
19 | + | |
20 | + List<DeviceProfileDTO> findDeviceProfile(String tenantId,DeviceProfileDTO deviceProfileDTO); | |
21 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | + | |
4 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | |
5 | +import org.thingsboard.server.common.data.yunteng.dto.DeviceTypeDTO; | |
6 | + | |
7 | +import java.util.List; | |
8 | + | |
9 | +public interface YtDeviceTypeService { | |
10 | + /** | |
11 | + * 获取当前租户设备类型的树形结构 | |
12 | + * @param tenantId 租户Code | |
13 | + * @return 树形结构 | |
14 | + */ | |
15 | + List<DeviceTypeDTO> getDeviceTypeTree(String tenantId); | |
16 | + | |
17 | + /** | |
18 | + * 保存设备类型 | |
19 | + * @param deviceTypeDTO 设备类型参数 | |
20 | + * @return 设备类型 | |
21 | + */ | |
22 | + DeviceTypeDTO saveDeviceTye(String tenantId,DeviceTypeDTO deviceTypeDTO); | |
23 | + | |
24 | + /** | |
25 | + * 修改设备类型 | |
26 | + * @param deviceTypeDTO 设备参数类型 | |
27 | + * @return 设备类型 | |
28 | + */ | |
29 | + DeviceTypeDTO updateDeviceType(DeviceTypeDTO deviceTypeDTO); | |
30 | + | |
31 | + /** | |
32 | + * 删除设备类型 | |
33 | + * @param deleteDTO 删除设备IDS | |
34 | + * @return true or false 删除成功或失败 | |
35 | + */ | |
36 | + boolean deleteDeviceType(DeleteDTO deleteDTO); | |
37 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.MailLogDTO; | |
4 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
5 | + | |
6 | +import java.util.Map; | |
7 | +import java.util.Set; | |
8 | + | |
9 | +public interface YtMailLogService { | |
10 | + PageData<MailLogDTO> page(String tenantId,Map<String, Object> queryMap); | |
11 | + | |
12 | + boolean deleteMailLog(Set<String> ids); | |
13 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.MessageConfigDTO; | |
4 | +import org.thingsboard.server.common.data.yunteng.utils.tools.PageData; | |
5 | + | |
6 | +import java.util.List; | |
7 | +import java.util.Map; | |
8 | +import java.util.Set; | |
9 | + | |
10 | +public interface YtMessageConfigService { | |
11 | + | |
12 | + PageData<MessageConfigDTO> page(String tenantId,Map<String, Object> queryMap); | |
13 | + | |
14 | + MessageConfigDTO saveMessageConfig(String tenantId,MessageConfigDTO configDTO); | |
15 | + | |
16 | + boolean deleteMessageConfig(Set<String> ids); | |
17 | + | |
18 | + MessageConfigDTO updateMessageConfig(String tenantId,MessageConfigDTO configDTO); | |
19 | + | |
20 | + MessageConfigDTO getEnableConfigByMessageAndPlatform( | |
21 | + String messageType, String platform, String tenantCode); | |
22 | + | |
23 | + MessageConfigDTO findMessageConfigById(String id); | |
24 | + | |
25 | + List<MessageConfigDTO> findMessageInfo(MessageConfigDTO configDTO); | |
26 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/YtMessageTemplateService.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/MessageTemplateService.java
1 | +package org.thingsboard.server.dao.yunteng.service; | |
2 | + | |
3 | +import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
4 | + | |
5 | +/** | |
6 | + * @version V1.0 | |
7 | + * @Description : | |
8 | + * 1.其它地方抛出异常,交由控制层统一处理 | |
9 | + * 2.服务层注意持久化的事务管理 | |
10 | + * @Dependency: 依赖包 | |
11 | + * @Author: junlianglee | |
12 | + * @Date Created in 2021/11/23$ | |
13 | + * @Copyright 2016-2018 - Powered By 云腾五洲 | |
14 | + */ | |
15 | +public interface YtNoticeService { | |
16 | + | |
17 | + /** | |
18 | + * 设备告警通知负责人 | |
19 | + * * @param alarmInfo | |
20 | + * @param token 告警通知鉴权信息 | |
21 | + * @param alarmInfo 告警数据 | |
22 | + */ | |
23 | + public void alert(String token, AlarmInfoDTO alarmInfo); | |
24 | + | |
25 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/YtOrganizationService.java
renamed from
dao/src/main/java/org/thingsboard/server/dao/yunteng/service/OrganizationService.java
... | ... | @@ -8,7 +8,7 @@ import org.thingsboard.server.common.data.yunteng.dto.OrganizationDTO; |
8 | 8 | import java.util.List; |
9 | 9 | import java.util.Set; |
10 | 10 | |
11 | -public interface OrganizationService { | |
11 | +public interface YtOrganizationService { | |
12 | 12 | OrganizationDTO saveOrganization(OrganizationDTO organizationDTO); |
13 | 13 | |
14 | 14 | boolean deleteOrganizations(DeleteDTO deleteDTO); | ... | ... |