Showing
8 changed files
with
289 additions
and
271 deletions
... | ... | @@ -379,7 +379,7 @@ public abstract class BaseController { |
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | - TimePageLink createTimePageLink(int pageSize, int page, String textSearch, | |
382 | + protected TimePageLink createTimePageLink(int pageSize, int page, String textSearch, | |
383 | 383 | String sortProperty, String sortOrder, Long startTime, Long endTime) throws ThingsboardException { |
384 | 384 | PageLink pageLink = this.createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); |
385 | 385 | return new TimePageLink(pageLink, startTime, endTime); | ... | ... |
... | ... | @@ -7,14 +7,17 @@ import org.springframework.web.bind.annotation.GetMapping; |
7 | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
8 | 8 | import org.springframework.web.bind.annotation.RequestParam; |
9 | 9 | import org.springframework.web.bind.annotation.RestController; |
10 | -import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; | |
10 | +import org.thingsboard.server.common.data.alarm.Alarm; | |
11 | +import org.thingsboard.server.common.data.alarm.AlarmInfo; | |
12 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | |
13 | +import org.thingsboard.server.common.data.exception.ThingsboardException; | |
14 | +import org.thingsboard.server.common.data.page.TimePageLink; | |
15 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | |
11 | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
17 | +import org.thingsboard.server.controller.BaseController; | |
12 | 18 | import org.thingsboard.server.dao.yunteng.service.YtAlarmInfoService; |
13 | 19 | |
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; | |
20 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | |
18 | 21 | |
19 | 22 | /** |
20 | 23 | * @Description 告警中心 |
... | ... | @@ -22,66 +25,34 @@ import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant. |
22 | 25 | * @Date 2021/11/11 9:23 |
23 | 26 | */ |
24 | 27 | @RestController |
25 | -@RequestMapping("/api/yt/alarmInfo") | |
28 | +@RequestMapping("/api/yt/alarm") | |
26 | 29 | @RequiredArgsConstructor |
27 | -@Api(value = "告警中心") | |
28 | -public class YtAlarmInfoController { | |
30 | +@Api(tags = "告警中心") | |
31 | +public class YtAlarmInfoController extends BaseController { | |
29 | 32 | |
30 | 33 | private final YtAlarmInfoService alarmInfoService; |
31 | 34 | |
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 | 35 | |
51 | -*/ | |
52 | 36 | //分页测试通过 |
53 | - @ApiOperation(value="分页查询告警中心数据") | |
37 | + @ApiOperation(value="设备告警信息") | |
54 | 38 | @GetMapping(params = {PAGE_SIZE, PAGE}) |
55 | - public YtPageData<AlarmInfoDTO> pageAlarmInfo( | |
39 | + public YtPageData<AlarmInfo> pageAlarmInfo( | |
56 | 40 | @RequestParam(PAGE_SIZE) int pageSize, |
57 | 41 | @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, | |
42 | + @RequestParam(value = "status", required = false) AlarmStatus status, | |
62 | 43 | @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); | |
44 | + @RequestParam(value = "alarmType", required = false) String alarmType, | |
45 | + @RequestParam(value = "organizationId", required = false) String organizationId, | |
46 | + @RequestParam(value = "deviceId", required = false) String deviceId, | |
47 | + @RequestParam(value = "startTime", required = false) Long startTime, | |
48 | + @RequestParam(value = "endTime", required = false) Long endTime, | |
49 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | |
50 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) throws ThingsboardException { | |
51 | + TimePageLink pageLink = createTimePageLink(pageSize, page > 1 ? page - 1 : 0, textSearch, orderBy, orderType == null ? "" : orderType.name(), startTime, endTime); | |
52 | + | |
53 | + return alarmInfoService.page(pageLink,getCurrentUser().getTenantId(),alarmType,status,organizationId,deviceId); | |
78 | 54 | } |
79 | - /*@ApiOperation(value = "删除告警中心数据") | |
80 | - @DeleteMapping | |
81 | - public void deleteAlarmInfo(@Validated({DeleteGroup.class}) @RequestBody DeleteDTO deleteDTO){ | |
82 | 55 | |
83 | - alarmInfoService.deleteAlarm(deleteDTO.getIds()); | |
84 | - }*/ | |
85 | 56 | |
86 | 57 | |
87 | 58 | } | ... | ... |
... | ... | @@ -28,8 +28,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; |
28 | 28 | @Configuration |
29 | 29 | @EnableAutoConfiguration |
30 | 30 | @ComponentScan("org.thingsboard.server.dao.sql") |
31 | -@EnableJpaRepositories({"org.thingsboard.server.dao.sql", "org.thingsboard.server.dao.yunteng.repository"}) | |
32 | -@EntityScan("org.thingsboard.server.dao.model.sql") | |
31 | +@EnableJpaRepositories({"org.thingsboard.server.dao.sql", "org.thingsboard.server.dao.yunteng.jpa.repository"}) | |
32 | +@EntityScan({"org.thingsboard.server.dao.model.sql","org.thingsboard.server.dao.yunteng.jpa.entity"}) | |
33 | 33 | @EnableTransactionManagement |
34 | 34 | public class JpaDaoConfig { |
35 | 35 | ... | ... |
... | ... | @@ -3,206 +3,30 @@ package org.thingsboard.server.dao.yunteng.impl; |
3 | 3 | import lombok.RequiredArgsConstructor; |
4 | 4 | import lombok.extern.slf4j.Slf4j; |
5 | 5 | import org.springframework.stereotype.Service; |
6 | -import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | |
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; | |
6 | +import org.thingsboard.server.common.data.alarm.AlarmInfo; | |
7 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | |
8 | +import org.thingsboard.server.common.data.id.TenantId; | |
9 | +import org.thingsboard.server.common.data.page.PageData; | |
10 | +import org.thingsboard.server.common.data.page.TimePageLink; | |
10 | 11 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
12 | +import org.thingsboard.server.dao.service.Validator; | |
13 | +import org.thingsboard.server.dao.yunteng.jpa.dao.YtJpaAarmDao; | |
11 | 14 | import org.thingsboard.server.dao.yunteng.service.YtAlarmInfoService; |
12 | 15 | |
13 | -import java.util.List; | |
14 | -import java.util.Map; | |
15 | - | |
16 | 16 | /** @Description 告警中心业务实现 @Author cxy @Date 2021/11/10 16:56 */ |
17 | 17 | @Service |
18 | 18 | @RequiredArgsConstructor |
19 | 19 | @Slf4j |
20 | 20 | public class YtAlarmInfoServiceImpl implements YtAlarmInfoService { |
21 | -// private final TBConfig tbConfig; | |
22 | -// private final TBConnectService tbConnectService; | |
23 | -// | |
24 | -// | |
25 | -// | |
26 | -// private LambdaQueryWrapper<YtAlarmInfo> tenantWapper(String tenantCode) { | |
27 | -// return new QueryWrapper<AlarmInfo>().lambda().eq(AlarmInfo::getTenantId, tenantCode); | |
28 | -// } | |
29 | - | |
30 | - /** | |
31 | - * 封装修改 | |
32 | - * | |
33 | - * @param alarmInfoDto 告警对象 | |
34 | - * @return return alarmInfo.getDTO(AlarmInfoDto.class); | |
35 | - */ | |
36 | - /* private AlarmInfoDTO update(AlarmInfoDTO alarmInfoDto) { | |
37 | - AlarmInfo alarmInfo = baseMapper.selectById(alarmInfoDto.getId()); | |
38 | - if (!alarmInfo.getTenantId().equals(SecurityContext.getCurrentUser().getTenantId())) { | |
39 | - return null; | |
40 | - } | |
41 | - alarmInfoDto.copyToEntity(alarmInfo); | |
42 | - baseMapper.updateById(alarmInfo); | |
43 | - alarmInfo.copyToDTO(alarmInfoDto); | |
44 | - return alarmInfo.getDTO(AlarmInfoDTO.class); | |
45 | - }*/ | |
46 | - /** | |
47 | - * 封装新增 | |
48 | - * | |
49 | - * @param alarmInfoDto 告警对象 | |
50 | - * @return alarmInfoDto | |
51 | - */ | |
52 | - /*private AlarmInfoDTO insert(AlarmInfoDTO alarmInfoDto) { | |
53 | - String tenantCode = SecurityContext.getCurrentUser().getTenantId(); | |
54 | - LambdaQueryWrapper<AlarmInfo> Wrapper = | |
55 | - tenantWapper(tenantCode) | |
56 | - .eq(AlarmInfo::getStatus, alarmInfoDto.getStatus()) | |
57 | - .eq(AlarmInfo::getSeverity, alarmInfoDto.getSeverity()); | |
58 | - int Count = baseMapper.selectCount(Wrapper); | |
59 | - if (Count > 0) { | |
60 | - throw new DataValidationException("告警中心数据已经存在"); | |
61 | - } | |
62 | - // 保存租户编码 | |
63 | - alarmInfoDto.setTenantId(tenantCode); | |
64 | - AlarmInfo alarmInfo = alarmInfoDto.getEntity(AlarmInfo.class); | |
65 | - | |
66 | - int insertCount = baseMapper.insert(alarmInfo); | |
67 | - if (insertCount > 0) { | |
68 | - alarmInfo.copyToDTO(alarmInfoDto); | |
69 | - return alarmInfoDto; | |
70 | - } | |
71 | - | |
72 | - return alarmInfoDto; | |
73 | - } | |
74 | -*/ | |
75 | - /** | |
76 | - * 新增或者修改告警中心 | |
77 | - * | |
78 | - * @param alarmInfoDto 告警对象 | |
79 | - * @return alarmInfoDto | |
80 | - */ | |
81 | - /*@Override | |
82 | - @Transactional | |
83 | - public AlarmInfoDTO insertOrUpdate(AlarmInfoDTO alarmInfoDto) { | |
84 | - // 判断为空,则新增告警信息 | |
85 | - if (StringUtils.isBlank(alarmInfoDto.getId())) { | |
86 | - return insert(alarmInfoDto); | |
87 | - } else { | |
88 | - // 不为空则执行修改操作 | |
89 | - return update(alarmInfoDto); | |
90 | - } | |
91 | - }*/ | |
92 | - | |
93 | - /** | |
94 | - * 删除告警中心数据 | |
95 | - * | |
96 | - * @param | |
97 | - * @return boolean | |
98 | - */ | |
99 | - /* @Override | |
100 | - public boolean deleteAlarm(Set<String> alarmIds) { | |
101 | - LambdaQueryWrapper<AlarmInfo> queryWrapper = | |
102 | - new QueryWrapper<AlarmInfo>() | |
103 | - .lambda() | |
104 | - .eq(AlarmInfo::getTenantId, SecurityContext.getCurrentUser().getTenantId()) | |
105 | - .in(AlarmInfo::getId, alarmIds); | |
106 | - baseMapper.delete(queryWrapper); | |
107 | - return true; | |
108 | - }*/ | |
109 | 21 | |
110 | - /** | |
111 | - * 分页查询数据 | |
112 | - * | |
113 | - * @param queryMap 集合 | |
114 | - * @return PageData | |
115 | - */ | |
22 | +private final YtJpaAarmDao ytJpaAarmDao; | |
116 | 23 | @Override |
117 | - public YtPageData<AlarmInfoDTO> page(Map<String, Object> queryMap) { | |
118 | - /* queryMap.put("tenantCode", SecurityContext.getCurrentUser().getTenantId()); | |
119 | - IPage<AlarmInfo> page = getPage(queryMap, FastIotConstants.DefaultOrder.CREATE_TIME,false); | |
120 | - IPage<AlarmInfo> alarmInfoIPage = alarmInfoBaseMapper.selectPage(page,queryMap);*/ | |
121 | - | |
122 | -// try { | |
123 | -// TBPageData tbPageData = null;//tbConnectService.getAlarmInfos(queryMap).get(); | |
124 | -// System.out.println("==================tbPageData:" + tbPageData); | |
125 | -// List<AlarmInfoDTO> alarmInfoDTOS = ReflectUtils.sourceToTarget(tbPageData.getData(), AlarmInfoDTO.class); | |
126 | -// YtPageData<AlarmInfoDTO> ytPageData = new YtPageData(); | |
127 | -// ytPageData.setItems(alarmInfoDTOS); | |
128 | -// | |
129 | -// System.out.println("==================alarmInfoDTOS:" + alarmInfoDTOS); | |
130 | -// return ytPageData; | |
131 | -// } catch (Exception e) { | |
132 | -// log.error("create TBAlarmInfo error {}", e.getMessage()); | |
133 | -// throw new YtDataValidationException(ErrorMessage.INVALID_PARAMETER.getMessage()); | |
134 | -// } | |
135 | - //return getPageData(alarmInfoIPage,AlarmInfoDTO.class); | |
136 | - return null; | |
24 | + public YtPageData<AlarmInfo> page(TimePageLink pageLink, TenantId tenantId, String alarmType, AlarmStatus status, String organizationId,String deviceId) { | |
25 | + Validator.validatePageLink(pageLink); | |
26 | + PageData<AlarmInfo> tbDatas = ytJpaAarmDao.pageAlarms(pageLink,tenantId,alarmType,status,null,deviceId); | |
27 | + YtPageData<AlarmInfo> result = new YtPageData<>(tbDatas.getData(), tbDatas.getTotalPages()); | |
28 | + return result; | |
137 | 29 | } |
138 | 30 | |
139 | 31 | |
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::getTenantId, SecurityContext.getCurrentUser().getTenantId()) | |
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 | 32 | } | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * <p> | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * <p> | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * <p> | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.dao.yunteng.jpa.dao; | |
17 | + | |
18 | +import lombok.AllArgsConstructor; | |
19 | +import org.springframework.context.annotation.Primary; | |
20 | +import org.springframework.data.domain.Page; | |
21 | +import org.springframework.stereotype.Component; | |
22 | +import org.thingsboard.server.common.data.EntityType; | |
23 | +import org.thingsboard.server.common.data.StringUtils; | |
24 | +import org.thingsboard.server.common.data.alarm.AlarmInfo; | |
25 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | |
26 | +import org.thingsboard.server.common.data.id.TenantId; | |
27 | +import org.thingsboard.server.common.data.page.PageData; | |
28 | +import org.thingsboard.server.common.data.page.TimePageLink; | |
29 | +import org.thingsboard.server.dao.DaoUtil; | |
30 | +import org.thingsboard.server.dao.model.sql.AlarmInfoEntity; | |
31 | +import org.thingsboard.server.dao.sql.alarm.JpaAlarmDao; | |
32 | +import org.thingsboard.server.dao.yunteng.jpa.repository.YtAlarmRepository; | |
33 | + | |
34 | +import java.util.*; | |
35 | + | |
36 | +@Component | |
37 | +@Primary | |
38 | +@AllArgsConstructor | |
39 | +public class YtJpaAarmDao extends JpaAlarmDao { | |
40 | + | |
41 | + private final YtAlarmRepository ytAlarmRepository; | |
42 | + | |
43 | + public PageData<AlarmInfo> pageAlarms(TimePageLink pageLink, TenantId tenantId, String alarmType, AlarmStatus statu, List<String> organizationId, String entityId){ | |
44 | + | |
45 | + Set<AlarmStatus> status = new HashSet<>(); | |
46 | + if(statu != null){ | |
47 | + status.add(statu); | |
48 | + } | |
49 | + Page<AlarmInfoEntity> datas =null; | |
50 | + try{ | |
51 | + datas = ytAlarmRepository.alarmsByOrganization(tenantId.getId() | |
52 | + , Optional.ofNullable(entityId).map(id ->{ | |
53 | + return UUID.fromString(entityId); | |
54 | + }).orElse(null) | |
55 | + , EntityType.DEVICE.name() | |
56 | + ,Optional.ofNullable(organizationId).map(ids ->{ | |
57 | + Set<String> result = new HashSet<>(); | |
58 | + for(String item:ids){ | |
59 | + if(StringUtils.isNotEmpty(item)){ | |
60 | + result.add(item); | |
61 | + } | |
62 | + } | |
63 | + return result; | |
64 | + }).orElse(null) | |
65 | +// , org.apache.commons.lang3.StringUtils.isEmpty(alarmType)?null:alarmType | |
66 | + ,pageLink.getStartTime(),pageLink.getEndTime(), | |
67 | + status | |
68 | + ,DaoUtil.toPageable(pageLink)); | |
69 | + | |
70 | + }catch (Exception e){ | |
71 | + e.printStackTrace(); | |
72 | + } | |
73 | + return DaoUtil.toPageData(datas); | |
74 | + } | |
75 | + | |
76 | + | |
77 | + | |
78 | + | |
79 | +} | ... | ... |
1 | +package org.thingsboard.server.dao.yunteng.jpa.entity; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.JsonNode; | |
4 | +import lombok.Data; | |
5 | +import org.hibernate.annotations.Type; | |
6 | +import org.hibernate.annotations.TypeDef; | |
7 | +import org.hibernate.annotations.TypeDefs; | |
8 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | |
9 | +import org.thingsboard.server.common.data.yunteng.enums.DeviceTypeEnum; | |
10 | +import org.thingsboard.server.dao.util.mapping.JsonBinaryType; | |
11 | +import org.thingsboard.server.dao.util.mapping.JsonStringType; | |
12 | + | |
13 | +import javax.persistence.*; | |
14 | +import java.util.UUID; | |
15 | + | |
16 | +@Data | |
17 | +@Entity | |
18 | +@Table(name = ModelConstants.Table.IOTFS_DEVICE_TABLE_NAME) | |
19 | +@TypeDefs({ | |
20 | + @TypeDef(name = "json", typeClass = JsonStringType.class), | |
21 | + @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) | |
22 | +}) | |
23 | +public class YtJpaDeviceEntity { | |
24 | + | |
25 | + @Id | |
26 | + @Column(name = org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY) | |
27 | + private String id; | |
28 | + | |
29 | + @Column(name="tenant_id") | |
30 | + private String tenantId; | |
31 | + | |
32 | + private String name; | |
33 | + | |
34 | + @Column(name="organization_id") | |
35 | + private String organizationId; | |
36 | + | |
37 | + @Column(name="tb_device_id") | |
38 | + private String tbDeviceId; | |
39 | + | |
40 | + @Column | |
41 | + @Type(type="json") | |
42 | + private JsonNode deviceInfo; | |
43 | + | |
44 | + @Column(name="device_type_id") | |
45 | + @Enumerated | |
46 | + private DeviceTypeEnum deviceType; | |
47 | + | |
48 | +} | ... | ... |
dao/src/main/java/org/thingsboard/server/dao/yunteng/jpa/repository/YtAlarmRepository.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.dao.yunteng.jpa.repository; | |
17 | + | |
18 | +import org.springframework.data.domain.Page; | |
19 | +import org.springframework.data.domain.Pageable; | |
20 | +import org.springframework.data.jpa.repository.Query; | |
21 | +import org.springframework.data.repository.CrudRepository; | |
22 | +import org.springframework.data.repository.query.Param; | |
23 | +import org.thingsboard.server.common.data.alarm.AlarmSeverity; | |
24 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | |
25 | +import org.thingsboard.server.dao.model.sql.AlarmEntity; | |
26 | +import org.thingsboard.server.dao.model.sql.AlarmInfoEntity; | |
27 | + | |
28 | +import java.util.List; | |
29 | +import java.util.Set; | |
30 | +import java.util.UUID; | |
31 | + | |
32 | +/** | |
33 | + * Created by Valerii Sosliuk on 5/21/2017. | |
34 | + */ | |
35 | +public interface YtAlarmRepository extends CrudRepository<AlarmEntity, UUID> { | |
36 | + | |
37 | + | |
38 | + | |
39 | + @Query(value = "SELECT new org.thingsboard.server.dao.model.sql.AlarmInfoEntity(a) FROM AlarmEntity a " + | |
40 | + "LEFT JOIN YtJpaDeviceEntity yd ON a.originatorId = uuid(yd.tbDeviceId) " + | |
41 | + "LEFT JOIN RelationEntity re ON a.id = re.toId " + | |
42 | + "AND re.relationTypeGroup = 'ALARM' " + | |
43 | + "AND re.toType = 'ALARM' " + | |
44 | + "AND re.fromId = :affectedEntityId " + | |
45 | + "AND re.fromType = :affectedEntityType " + | |
46 | + "WHERE a.tenantId = :tenantId " + | |
47 | + "AND (a.originatorId = :affectedEntityId or re.fromId IS NOT NULL) " + | |
48 | + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " + | |
49 | + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " | |
50 | + + "AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " | |
51 | +// + " AND (:affectedEntityType IS NULL OR a.originatorType = :affectedEntityType) " | |
52 | + + " AND (:organizationId IS NULL OR yd.organizationId in (:organizationId)) " | |
53 | +// + " AND (:alarmType IS NULL OR a.type = :alarmType) " | |
54 | +// "AND (LOWER(a.type) LIKE LOWER(CONCAT('%', :alarmType, '%')) " | |
55 | +// + " OR LOWER(a.severity) LIKE LOWER(CONCAT('%', :searchText, '%'))) " | |
56 | + , | |
57 | + countQuery = "" + | |
58 | + "SELECT count(a) + " + //alarms with relations only | |
59 | + " (SELECT count(a) FROM AlarmEntity a " + //alarms WITHOUT any relations | |
60 | + "LEFT JOIN YtJpaDeviceEntity yd ON a.originatorId = uuid(yd.tbDeviceId) " + | |
61 | + " LEFT JOIN RelationEntity re ON a.id = re.toId " + | |
62 | + " AND re.relationTypeGroup = 'ALARM' " + | |
63 | + " AND re.toType = 'ALARM' " + | |
64 | + " AND re.fromId = :affectedEntityId " + | |
65 | + " AND re.fromType = :affectedEntityType " + | |
66 | + " WHERE a.tenantId = :tenantId " + | |
67 | + " AND (a.originatorId = :affectedEntityId) " + | |
68 | + " AND (re.fromId IS NULL) " + //anti join | |
69 | + " AND (:startTime IS NULL OR a.createdTime >= :startTime) " + | |
70 | + " AND (:endTime IS NULL OR a.createdTime <= :endTime) " | |
71 | + +" AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " | |
72 | +// + " AND (:affectedEntityType IS NULL OR a.originatorType = :affectedEntityType) " | |
73 | + + " AND (:organizationId IS NULL OR yd.organizationId in (:organizationId)) " | |
74 | +// + " AND (:alarmType IS NULL OR a.type = :alarmType) " | |
75 | + +" )" + | |
76 | + "FROM AlarmEntity a " + | |
77 | + "LEFT JOIN YtJpaDeviceEntity yd ON a.originatorId = uuid(yd.tbDeviceId) " + | |
78 | + "INNER JOIN RelationEntity re ON a.id = re.toId " + | |
79 | + "AND re.relationTypeGroup = 'ALARM' " + | |
80 | + "AND re.toType = 'ALARM' " + | |
81 | + "AND re.fromId = :affectedEntityId " + | |
82 | + "AND re.fromType = :affectedEntityType " + | |
83 | + "WHERE a.tenantId = :tenantId " + | |
84 | + "AND (:startTime IS NULL OR a.createdTime >= :startTime) " + | |
85 | + "AND (:endTime IS NULL OR a.createdTime <= :endTime) " | |
86 | + +"AND ((:alarmStatuses) IS NULL OR a.status in (:alarmStatuses)) " | |
87 | +// + " AND (:affectedEntityType IS NULL OR a.originatorType = :affectedEntityType) " | |
88 | + + " AND (:organizationId IS NULL OR yd.organizationId in (:organizationId)) " | |
89 | +// + " AND (:alarmType IS NULL OR a.type = :alarmType) " | |
90 | + ) | |
91 | + Page<AlarmInfoEntity> alarmsByOrganization(@Param("tenantId") UUID tenantId, | |
92 | + @Param("affectedEntityId") UUID affectedEntityId, | |
93 | + @Param("affectedEntityType") String affectedEntityType, | |
94 | + @Param("organizationId") Set<String> organizationId, | |
95 | +// @Param("alarmType") String alarmType, | |
96 | + @Param("startTime") Long startTime, | |
97 | + @Param("endTime") Long endTime, | |
98 | + @Param("alarmStatuses") Set<AlarmStatus> alarmStatuses, | |
99 | + Pageable pageable); | |
100 | + | |
101 | + | |
102 | + | |
103 | + | |
104 | + | |
105 | + | |
106 | + | |
107 | + | |
108 | + | |
109 | +} | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.service; |
2 | 2 | |
3 | +import org.thingsboard.server.common.data.alarm.Alarm; | |
4 | +import org.thingsboard.server.common.data.alarm.AlarmInfo; | |
5 | +import org.thingsboard.server.common.data.alarm.AlarmStatus; | |
6 | +import org.thingsboard.server.common.data.id.TenantId; | |
7 | +import org.thingsboard.server.common.data.page.TimePageLink; | |
3 | 8 | import org.thingsboard.server.common.data.yunteng.dto.AlarmInfoDTO; |
4 | 9 | import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; |
5 | 10 | |
... | ... | @@ -8,34 +13,16 @@ import java.util.Map; |
8 | 13 | /** @Description 告警中心数据业务层 @Author cxy @Date 2021/11/10 16:51 */ |
9 | 14 | public interface YtAlarmInfoService { |
10 | 15 | |
11 | - /** | |
12 | - * 新增或修改告警中心数据 | |
13 | - * | |
14 | - * @param alarmInfoDto 对象 | |
15 | - * @return alarmInfoDto | |
16 | - */ | |
17 | -/* AlarmInfoDTO insertOrUpdate(AlarmInfoDTO alarmInfoDto);*/ | |
18 | 16 | |
19 | 17 | /** |
20 | - * 删除告警中心数据 | |
21 | - * | |
22 | - * @param ids id | |
23 | - * @return true和false | |
18 | + * 告警信息分页数据 | |
19 | + * @param pageLink 分页信息 | |
20 | + * @param tenantId 租户ID | |
21 | + * @param alarmType 告警类型 | |
22 | + * @param status 告警状态 | |
23 | + * @param organizationId 组织ID | |
24 | + * @return | |
24 | 25 | */ |
25 | - /*boolean deleteAlarm(Set<String> ids);*/ | |
26 | + YtPageData<AlarmInfo> page(TimePageLink pageLink,TenantId tenantId, String alarmType, AlarmStatus status, String organizationId,String deviceId); | |
26 | 27 | |
27 | - /** | |
28 | - * 分页数据 | |
29 | - * | |
30 | - * @param queryMap 集合对象 | |
31 | - * @return AlarmInfoDto | |
32 | - */ | |
33 | - YtPageData<AlarmInfoDTO> page(Map<String, Object> queryMap); | |
34 | - /** | |
35 | - * 查询告警中心所有数据 | |
36 | - * | |
37 | - * @param alarmInfoDto 过滤参数 | |
38 | - * @return List<AlarmCenterDto> | |
39 | - */ | |
40 | - /*List<AlarmInfoDTO> findAlarmInfo(AlarmInfoDTO alarmInfoDto);*/ | |
41 | 28 | } | ... | ... |