Showing
8 changed files
with
110 additions
and
34 deletions
1 | 1 | package org.thingsboard.server.controller.yunteng; |
2 | 2 | |
3 | 3 | import io.swagger.annotations.Api; |
4 | +import io.swagger.annotations.ApiOperation; | |
4 | 5 | import io.swagger.annotations.ApiParam; |
5 | 6 | import lombok.RequiredArgsConstructor; |
6 | 7 | import org.springframework.security.access.prepost.PreAuthorize; |
... | ... | @@ -22,6 +23,7 @@ import org.thingsboard.server.dao.yunteng.service.TkDeviceService; |
22 | 23 | import org.thingsboard.server.dao.yunteng.service.media.TkVideoChannelService; |
23 | 24 | |
24 | 25 | import java.util.HashMap; |
26 | +import java.util.List; | |
25 | 27 | |
26 | 28 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; |
27 | 29 | import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.ORDER_TYPE; |
... | ... | @@ -76,4 +78,14 @@ public class TkVideoChannelController extends BaseController { |
76 | 78 | } |
77 | 79 | return tkVideoChannelService.page(tenantId, queryMap); |
78 | 80 | } |
81 | + | |
82 | + @GetMapping("/list") | |
83 | + @ApiOperation("选项列表") | |
84 | + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") | |
85 | + public List<VideoChanelDTO> listDeviceProfile( | |
86 | + @ApiParam(value = "设备Id") @RequestParam(value = "deviceId", required = false) String deviceId) | |
87 | + throws ThingsboardException { | |
88 | + String tenantId = getCurrentUser().getCurrentTenantId(); | |
89 | + return tkVideoChannelService.getListByDeviceId(deviceId,tenantId); | |
90 | + } | |
79 | 91 | } | ... | ... |
... | ... | @@ -11,7 +11,7 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
11 | 11 | import org.thingsboard.server.common.data.yunteng.common.DeleteGroup; |
12 | 12 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
13 | 13 | import org.thingsboard.server.common.data.yunteng.dto.TkVideoDTO; |
14 | -import org.thingsboard.server.common.data.yunteng.dto.TkVideoGptDTO; | |
14 | +import org.thingsboard.server.common.data.yunteng.dto.TkVideoGbtDTO; | |
15 | 15 | import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; |
16 | 16 | import org.thingsboard.server.common.data.yunteng.utils.tools.ProtocolType; |
17 | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.ResponseResult; |
... | ... | @@ -73,10 +73,10 @@ public class TkVideoController extends BaseController { |
73 | 73 | @ApiOperation("新增国标视频") |
74 | 74 | @PreAuthorize( |
75 | 75 | "@check.checkPermissions({'TENANT_ADMIN','CUSTOMER_USER'},{'api:yt:video:post','api:yt:video:update'})") |
76 | - public TkVideoGptDTO saveOrUpdateAlarmProfile(@Validated @RequestBody TkVideoGptDTO dto) | |
76 | + public TkVideoGbtDTO saveOrUpdateAlarmProfile(@Validated @RequestBody TkVideoGbtDTO dto) | |
77 | 77 | throws ThingsboardException { |
78 | 78 | dto.setTenantId(getCurrentUser().getCurrentTenantId()); |
79 | - return videoService.saveGpt(dto); | |
79 | + return videoService.saveGbt(dto); | |
80 | 80 | } |
81 | 81 | |
82 | 82 | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkVideoGbtDTO.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkVideoGptDTO.java
1 | 1 | package org.thingsboard.server.common.data.yunteng.dto; |
2 | 2 | |
3 | -import com.fasterxml.jackson.databind.JsonNode; | |
4 | 3 | import io.swagger.annotations.ApiModelProperty; |
5 | 4 | import lombok.Data; |
6 | 5 | import lombok.EqualsAndHashCode; |
... | ... | @@ -10,7 +9,7 @@ import java.util.List; |
10 | 9 | |
11 | 10 | @Data |
12 | 11 | @EqualsAndHashCode(callSuper = true) |
13 | -public class TkVideoGptDTO extends TenantDTO { | |
12 | +public class TkVideoGbtDTO extends TenantDTO { | |
14 | 13 | |
15 | 14 | @ApiModelProperty(value = "组织ID", required = true) |
16 | 15 | @NotEmpty(message = "组织ID不能为空或空字符串") |
... | ... | @@ -20,6 +19,9 @@ public class TkVideoGptDTO extends TenantDTO { |
20 | 19 | private Integer accessMode; |
21 | 20 | |
22 | 21 | @ApiModelProperty(value = "多个设备id与通道号") |
23 | - private List<TkVideoGptDeviceDTO> gptDeviceDTOS; | |
22 | + private List<TkVideoGbtDeviceDTO> gbtDeviceDTOS; | |
23 | + | |
24 | + @ApiModelProperty(value = "是否全部设备 0否 1是") | |
25 | + private Integer allDevice; | |
24 | 26 | |
25 | 27 | } |
\ No newline at end of file | ... | ... |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkVideoGbtDeviceDTO.java
renamed from
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/TkVideoGptDeviceDTO.java
1 | 1 | package org.thingsboard.server.common.data.yunteng.dto; |
2 | 2 | |
3 | -import com.fasterxml.jackson.databind.JsonNode; | |
4 | 3 | import io.swagger.annotations.ApiModelProperty; |
5 | 4 | import lombok.Data; |
6 | 5 | |
... | ... | @@ -8,7 +7,7 @@ import javax.validation.constraints.NotEmpty; |
8 | 7 | import java.util.List; |
9 | 8 | |
10 | 9 | @Data |
11 | -public class TkVideoGptDeviceDTO { | |
10 | +public class TkVideoGbtDeviceDTO { | |
12 | 11 | |
13 | 12 | @ApiModelProperty(value = "设备id", required = true) |
14 | 13 | @NotEmpty(message = "设备id不能为空") | ... | ... |
... | ... | @@ -11,15 +11,11 @@ import lombok.extern.slf4j.Slf4j; |
11 | 11 | import org.springframework.stereotype.Service; |
12 | 12 | import org.springframework.transaction.annotation.Transactional; |
13 | 13 | import org.thingsboard.server.common.data.StringUtils; |
14 | -import org.thingsboard.server.common.data.alarm.Alarm; | |
15 | -import org.thingsboard.server.common.data.audit.ActionType; | |
16 | -import org.thingsboard.server.common.data.exception.ThingsboardException; | |
17 | -import org.thingsboard.server.common.data.id.AlarmId; | |
18 | -import org.thingsboard.server.common.data.id.EdgeId; | |
19 | 14 | import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants; |
20 | 15 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
21 | 16 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
22 | 17 | import org.thingsboard.server.common.data.yunteng.dto.*; |
18 | +import org.thingsboard.server.common.data.yunteng.dto.sip.VideoChanelDTO; | |
23 | 19 | import org.thingsboard.server.common.data.yunteng.utils.JacksonUtil; |
24 | 20 | import org.thingsboard.server.common.data.yunteng.utils.tools.*; |
25 | 21 | import org.thingsboard.server.dao.yunteng.entities.TkVideoEntity; |
... | ... | @@ -27,6 +23,7 @@ import org.thingsboard.server.dao.yunteng.entities.TkVideoPlatformEntity; |
27 | 23 | import org.thingsboard.server.dao.yunteng.mapper.TkVideoMapper; |
28 | 24 | import org.thingsboard.server.dao.yunteng.mapper.TkVideoPlatformMapper; |
29 | 25 | import org.thingsboard.server.dao.yunteng.service.*; |
26 | +import org.thingsboard.server.dao.yunteng.service.media.TkVideoChannelService; | |
30 | 27 | |
31 | 28 | import java.io.IOException; |
32 | 29 | import java.util.ArrayList; |
... | ... | @@ -43,6 +40,9 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid |
43 | 40 | private final UserOrganizationMappingService userOrganizationMappingService; |
44 | 41 | private final TkOrganizationService organizationService; |
45 | 42 | private final TkVideoPlatformMapper tkVideoPlatformMapper; |
43 | + private final TkDeviceService tkdeviceService; | |
44 | + private final TkVideoChannelService tkVideoChannelService; | |
45 | + | |
46 | 46 | @Override |
47 | 47 | public TkPageData<TkVideoDTO> pageDatas(IPage<TkVideoEntity> pageInfrom, |
48 | 48 | boolean isPtTenantAdmin, String tenantId, String currentUserId, |
... | ... | @@ -92,25 +92,35 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid |
92 | 92 | } |
93 | 93 | |
94 | 94 | @Override |
95 | - public TkVideoGptDTO saveGpt(TkVideoGptDTO dto) { | |
96 | - List<TkVideoGptDeviceDTO> deviceList = dto.getGptDeviceDTOS(); | |
97 | - deviceList.forEach(device -> { | |
98 | - String deviceId = device.getDeviceID(); | |
99 | - String deviceName = device.getDeviceName(); | |
100 | - List<String> channelNos = device.getChannelNos(); | |
101 | - channelNos.forEach(channelNo -> { | |
102 | - TkVideoDTO videoDto = new TkVideoDTO(); | |
103 | - videoDto.setOrganizationId(dto.getOrganizationId()); | |
104 | - videoDto.setName(deviceName+channelNo); | |
105 | - videoDto.setAccessMode(dto.getAccessMode()); | |
106 | - videoDto.setSn(channelNo); | |
107 | - String json = "{\"channelNo\":\""+channelNo+"\",\"deviceId\":\""+deviceId+"\",\"deviceName\":\""+deviceName+"\"}"; | |
108 | - JsonNode params = JacksonUtil.toJsonNode(json); | |
109 | - videoDto.setParams(params); | |
110 | - videoDto.setTenantId(dto.getTenantId()); | |
111 | - baseMapper.insert(videoDto.getEntity(TkVideoEntity.class)); | |
112 | - }); | |
113 | - }); | |
95 | + public TkVideoGbtDTO saveGbt(TkVideoGbtDTO dto) { | |
96 | + if(dto.getAllDevice()==FastIotConstants.MagicNumber.ONE){ | |
97 | + //插入组织下全部设备时后端处理dto对象 查询全部所需要插入的摄像头信息 | |
98 | + String organizationId = dto.getOrganizationId(); | |
99 | + List<TkVideoGbtDeviceDTO> deviceList = new ArrayList<>(); | |
100 | + List<DeviceDTO> deviceDTOS = tkdeviceService.findDevicesByDeviceTypeAndOrganizationId( | |
101 | + null,dto.getTenantId(),organizationId,null,null,null); | |
102 | + for(DeviceDTO device:deviceDTOS){ | |
103 | + List<VideoChanelDTO> chanelDTOS = tkVideoChannelService.getListByDeviceId(device.getTbDeviceId(),dto.getTenantId()); | |
104 | + if(chanelDTOS.isEmpty()){ | |
105 | + continue; | |
106 | + } | |
107 | + //该设备拥有通道号时才插入 | |
108 | + TkVideoGbtDeviceDTO gbt = new TkVideoGbtDeviceDTO(); | |
109 | + gbt.setDeviceID(device.getTbDeviceId()); | |
110 | + gbt.setDeviceName(device.getAlias()==null?device.getName():device.getAlias()); | |
111 | + List<String> channelNos = new ArrayList<>(); | |
112 | + for (VideoChanelDTO chanel :chanelDTOS){ | |
113 | + channelNos.add(chanel.getChannelId()); | |
114 | + } | |
115 | + gbt.setChannelNos(channelNos); | |
116 | + deviceList.add(gbt); | |
117 | + } | |
118 | + dto.setGbtDeviceDTOS(deviceList); | |
119 | + saveGbtS(dto); | |
120 | + } | |
121 | + else{ | |
122 | + saveGbtS(dto); | |
123 | + } | |
114 | 124 | return dto; |
115 | 125 | } |
116 | 126 | |
... | ... | @@ -218,4 +228,34 @@ public class TkVideoServiceImpl extends AbstractBaseService<TkVideoMapper, TkVid |
218 | 228 | return videoDTOList.get(0); |
219 | 229 | } |
220 | 230 | |
231 | + | |
232 | + void saveGbtS(TkVideoGbtDTO dto){ | |
233 | + List<TkVideoGbtDeviceDTO> deviceList = dto.getGbtDeviceDTOS(); | |
234 | + deviceList.forEach(device -> { | |
235 | + String deviceId = device.getDeviceID(); | |
236 | + String deviceName = device.getDeviceName(); | |
237 | + List<String> channelNos = device.getChannelNos(); | |
238 | + channelNos.forEach(channelNo -> { | |
239 | + TkVideoDTO videoDto = new TkVideoDTO(); | |
240 | + videoDto.setOrganizationId(dto.getOrganizationId()); | |
241 | + videoDto.setName(deviceName+channelNo); | |
242 | + videoDto.setAccessMode(dto.getAccessMode()); | |
243 | + videoDto.setSn(channelNo); | |
244 | + String json = "{\"channelNo\":\""+channelNo+"\",\"deviceId\":\""+deviceId+"\",\"deviceName\":\""+deviceName+"\"}"; | |
245 | + JsonNode params = JacksonUtil.toJsonNode(json); | |
246 | + videoDto.setParams(params); | |
247 | + videoDto.setTenantId(dto.getTenantId()); | |
248 | + TkVideoEntity oldVideo = baseMapper.selectOne(new QueryWrapper<TkVideoEntity>().lambda() | |
249 | + .eq(TkVideoEntity::getSn, channelNo) | |
250 | + .like(TkVideoEntity::getParams, deviceId)); | |
251 | + if(oldVideo!=null){ | |
252 | + videoDto.setId(oldVideo.getId()); | |
253 | + baseMapper.updateById(videoDto.getEntity(TkVideoEntity.class)); | |
254 | + }else{ | |
255 | + baseMapper.insert(videoDto.getEntity(TkVideoEntity.class)); | |
256 | + } | |
257 | + }); | |
258 | + }); | |
259 | + } | |
260 | + | |
221 | 261 | } | ... | ... |
... | ... | @@ -3,6 +3,7 @@ package org.thingsboard.server.dao.yunteng.impl.media; |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import com.baomidou.mybatisplus.core.metadata.IPage; |
5 | 5 | import java.time.LocalDateTime; |
6 | +import java.util.List; | |
6 | 7 | import java.util.Map; |
7 | 8 | import java.util.Optional; |
8 | 9 | import lombok.RequiredArgsConstructor; |
... | ... | @@ -12,6 +13,7 @@ import org.thingsboard.server.common.data.StringUtils; |
12 | 13 | import org.thingsboard.server.common.data.yunteng.core.exception.TkDataValidationException; |
13 | 14 | import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; |
14 | 15 | import org.thingsboard.server.common.data.yunteng.dto.sip.VideoChanelDTO; |
16 | +import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; | |
15 | 17 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
16 | 18 | import org.thingsboard.server.dao.yunteng.entities.TkVideoChannelEntity; |
17 | 19 | import org.thingsboard.server.dao.yunteng.mapper.TkVideoChannelMapper; |
... | ... | @@ -113,4 +115,15 @@ public class TkVideoChannelServiceImpl |
113 | 115 | }) |
114 | 116 | .orElse(false); |
115 | 117 | } |
118 | + | |
119 | + | |
120 | + @Override | |
121 | + public List<VideoChanelDTO> getListByDeviceId(String deviceId,String tenantId) { | |
122 | + return ReflectUtils.sourceToTarget( | |
123 | + baseMapper.selectList( | |
124 | + new LambdaQueryWrapper<TkVideoChannelEntity>() | |
125 | + .eq(TkVideoChannelEntity::getDeviceId, deviceId) | |
126 | + .eq(TkVideoChannelEntity::getTenantId, tenantId) | |
127 | + ),VideoChanelDTO.class); | |
128 | + } | |
116 | 129 | } | ... | ... |
... | ... | @@ -3,7 +3,7 @@ package org.thingsboard.server.dao.yunteng.service; |
3 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; |
4 | 4 | import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; |
5 | 5 | import org.thingsboard.server.common.data.yunteng.dto.TkVideoDTO; |
6 | -import org.thingsboard.server.common.data.yunteng.dto.TkVideoGptDTO; | |
6 | +import org.thingsboard.server.common.data.yunteng.dto.TkVideoGbtDTO; | |
7 | 7 | import org.thingsboard.server.common.data.yunteng.utils.tools.ProtocolType; |
8 | 8 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
9 | 9 | import org.thingsboard.server.dao.yunteng.entities.TkVideoEntity; |
... | ... | @@ -49,7 +49,7 @@ public interface TkVideoService extends BaseService<TkVideoEntity> { |
49 | 49 | * @param dto |
50 | 50 | * @return |
51 | 51 | */ |
52 | - TkVideoGptDTO saveGpt(TkVideoGptDTO dto); | |
52 | + TkVideoGbtDTO saveGbt(TkVideoGbtDTO dto); | |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @param deleteDTO | ... | ... |
1 | 1 | package org.thingsboard.server.dao.yunteng.service.media; |
2 | 2 | |
3 | +import java.util.List; | |
3 | 4 | import java.util.Map; |
4 | 5 | import org.thingsboard.server.common.data.yunteng.dto.sip.VideoChanelDTO; |
5 | 6 | import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData; |
... | ... | @@ -55,4 +56,13 @@ public interface TkVideoChannelService extends BaseService<TkVideoChannelEntity> |
55 | 56 | */ |
56 | 57 | boolean updateVideoChannelStreamId( |
57 | 58 | String streamId, String deviceCode, String channelId); |
59 | + | |
60 | + /** | |
61 | + * 根据设备id获取通道号集合 | |
62 | + * | |
63 | + * @param deviceId 流ID | |
64 | + * @return VideoChanelDTOs 摄像头通道信息集合 | |
65 | + */ | |
66 | + List<VideoChanelDTO> getListByDeviceId(String deviceId,String tenantId); | |
67 | + | |
58 | 68 | } | ... | ... |