Showing
9 changed files
with
292 additions
and
2 deletions
application/src/main/java/org/thingsboard/server/controller/yunteng/YtVideoPlatformController.java
0 → 100644
1 | +package org.thingsboard.server.controller.yunteng; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import io.swagger.annotations.Api; | ||
5 | +import io.swagger.annotations.ApiOperation; | ||
6 | +import lombok.RequiredArgsConstructor; | ||
7 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
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.DeleteGroup; | ||
12 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
13 | +import org.thingsboard.server.common.data.yunteng.dto.YtVideoPlatformDTO; | ||
14 | +import org.thingsboard.server.common.data.yunteng.enums.OrderTypeEnum; | ||
15 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
16 | +import org.thingsboard.server.controller.BaseController; | ||
17 | +import org.thingsboard.server.dao.yunteng.entities.YtVideoPlatformEntity; | ||
18 | +import org.thingsboard.server.dao.yunteng.service.YtVideoPlatformService; | ||
19 | + | ||
20 | +import static org.thingsboard.server.common.data.yunteng.constant.QueryConstant.*; | ||
21 | + | ||
22 | +@RestController | ||
23 | +@RequestMapping("api/yt/video/platform") | ||
24 | +@Api(tags = {"流媒体平台配置"}) | ||
25 | +@RequiredArgsConstructor | ||
26 | +@PreAuthorize("hasAnyAuthority('TENANT_ADMIN','CUSTOMER_USER')") | ||
27 | +public class YtVideoPlatformController extends BaseController { | ||
28 | + | ||
29 | + private final YtVideoPlatformService videoPlatformService; | ||
30 | + | ||
31 | + @GetMapping(params = {PAGE_SIZE, PAGE}) | ||
32 | + @ApiOperation("分页") | ||
33 | + public YtPageData<YtVideoPlatformDTO> pageVideoPlatform( | ||
34 | + @RequestParam(PAGE_SIZE) int pageSize, | ||
35 | + @RequestParam(PAGE) int page, | ||
36 | + @RequestParam(value = "host", required = false) String host, | ||
37 | + @RequestParam(value = ORDER_FILED, required = false) String orderBy, | ||
38 | + @RequestParam(value = ORDER_TYPE, required = false) OrderTypeEnum orderType) | ||
39 | + throws ThingsboardException { | ||
40 | + | ||
41 | + | ||
42 | + IPage<YtVideoPlatformEntity> pageInfo = videoPlatformService.getPage(page, pageSize, orderBy, orderType); | ||
43 | + return videoPlatformService.page(pageInfo, getCurrentUser().isPtTenantAdmin(), | ||
44 | + getCurrentUser().getCurrentTenantId(), | ||
45 | + getCurrentUser().getCurrentUserId(), host); | ||
46 | + } | ||
47 | + | ||
48 | + @PostMapping | ||
49 | + @ApiOperation("新增|编辑") | ||
50 | + public YtVideoPlatformDTO saveOrUpdateVideoPlatform( | ||
51 | + @Validated @RequestBody YtVideoPlatformDTO dto) throws ThingsboardException { | ||
52 | + dto.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
53 | + return videoPlatformService.saveOrUpdate(dto); | ||
54 | + } | ||
55 | + | ||
56 | + @DeleteMapping | ||
57 | + @ApiOperation("删除") | ||
58 | + public boolean deleteVideoPlatform(@Validated(DeleteGroup.class) @RequestBody DeleteDTO deleteDTO) | ||
59 | + throws ThingsboardException { | ||
60 | + deleteDTO.setTenantId(getCurrentUser().getCurrentTenantId()); | ||
61 | + return videoPlatformService.deleteDataByIds(deleteDTO); | ||
62 | + } | ||
63 | +} |
@@ -45,8 +45,6 @@ public final class ModelConstants { | @@ -45,8 +45,6 @@ public final class ModelConstants { | ||
45 | "iotfs_user_organization_mapping"; | 45 | "iotfs_user_organization_mapping"; |
46 | /** 设备表 */ | 46 | /** 设备表 */ |
47 | public static final String IOTFS_DEVICE_TABLE_NAME = "iotfs_device"; | 47 | public static final String IOTFS_DEVICE_TABLE_NAME = "iotfs_device"; |
48 | - /** 设备配置表 */ | ||
49 | - public static final String IOTFS_DEVICE_PROFILE_TABLE_NAME = "iotfs_device_profile"; | ||
50 | /** 设备类型表 */ | 48 | /** 设备类型表 */ |
51 | public static final String IOTFS_DEVICE_TYPE_TABLE_NAME = "iotfs_device_type"; | 49 | public static final String IOTFS_DEVICE_TYPE_TABLE_NAME = "iotfs_device_type"; |
52 | /** 告警配置表 */ | 50 | /** 告警配置表 */ |
@@ -83,6 +81,8 @@ public final class ModelConstants { | @@ -83,6 +81,8 @@ public final class ModelConstants { | ||
83 | public static final String IOTFS_CONFIGURATION_ACT = "iotfs_configuration_act"; | 81 | public static final String IOTFS_CONFIGURATION_ACT = "iotfs_configuration_act"; |
84 | /** 视频流 */ | 82 | /** 视频流 */ |
85 | public static final String IOTFS_VIDEO_STREAM_TABLE_NAME = "iotfs_device_camera"; | 83 | public static final String IOTFS_VIDEO_STREAM_TABLE_NAME = "iotfs_device_camera"; |
84 | + /** 流媒体配置 */ | ||
85 | + public static final String IOTFS_VIDEO_PLATFORM_TABLE_NAME = "iotfs_video_platform"; | ||
86 | /** 意见反馈 */ | 86 | /** 意见反馈 */ |
87 | public static final String IOTFS_OPINION_TABLE_NAME = "iotfs_opinion"; | 87 | public static final String IOTFS_OPINION_TABLE_NAME = "iotfs_opinion"; |
88 | /** 第三方用户表 */ | 88 | /** 第三方用户表 */ |
@@ -63,6 +63,7 @@ public enum ErrorMessage { | @@ -63,6 +63,7 @@ public enum ErrorMessage { | ||
63 | APP_USER_BINDED(400043,"平台用户【%s】已被其它账号绑定"), | 63 | APP_USER_BINDED(400043,"平台用户【%s】已被其它账号绑定"), |
64 | THIRD_PLATFORM_EXCEPTION(400044,"【%s】,第三方异常【%s】"), | 64 | THIRD_PLATFORM_EXCEPTION(400044,"【%s】,第三方异常【%s】"), |
65 | DEVICE_NOT_EXTIED(400045,"设备不存在"), | 65 | DEVICE_NOT_EXTIED(400045,"设备不存在"), |
66 | + VIDEO_PLATFORM_HOST_EXISTED(400046,"流媒体平台地址已存在"), | ||
66 | HAVE_NO_PERMISSION(500002,"没有修改权限"); | 67 | HAVE_NO_PERMISSION(500002,"没有修改权限"); |
67 | private final int code; | 68 | private final int code; |
68 | private String message; | 69 | private String message; |
common/data/src/main/java/org/thingsboard/server/common/data/yunteng/dto/YtVideoPlatformDTO.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.Max; | ||
8 | +import javax.validation.constraints.NotEmpty; | ||
9 | +import javax.validation.constraints.NotNull; | ||
10 | +import javax.validation.constraints.Size; | ||
11 | + | ||
12 | +@Data | ||
13 | +@EqualsAndHashCode(callSuper = true) | ||
14 | +public class YtVideoPlatformDTO extends TenantDTO { | ||
15 | + @ApiModelProperty(value = "平台类型",required = true) | ||
16 | + @NotNull(message = "平台类型不能为空") | ||
17 | + @Max(value = 2,message = "平台类型最大长度2") | ||
18 | + private Integer type; | ||
19 | + | ||
20 | + @ApiModelProperty(value = "平台地址+端口",required = true) | ||
21 | + @NotEmpty(message = "平台地址+端口不能为空") | ||
22 | + @Size(max = 36,message = "平台地址最大长度36") | ||
23 | + private String host; | ||
24 | + | ||
25 | + @ApiModelProperty(value = "秘钥appKey", required = true) | ||
26 | + @NotEmpty(message = "秘钥appKey不能为空") | ||
27 | + @Size(max = 36,message = "appKey最大长度36") | ||
28 | + private String appKey; | ||
29 | + | ||
30 | + @ApiModelProperty(value = "秘钥appSecret", required = true) | ||
31 | + @NotEmpty(message = "秘钥appSecret不能为空") | ||
32 | + @Size(max = 36,message = "appSecret最大长度36") | ||
33 | + private String appSecret; | ||
34 | + | ||
35 | + @ApiModelProperty(value = "流媒体部署环境",required = true) | ||
36 | + @NotNull(message = "流媒体部署环境不能为空") | ||
37 | + @Max(value = 2,message = "平台类型最大长度2") | ||
38 | + private Integer ssl; | ||
39 | + | ||
40 | +} |
1 | +package org.thingsboard.server.dao.yunteng.entities; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
4 | +import lombok.Data; | ||
5 | +import lombok.EqualsAndHashCode; | ||
6 | +import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; | ||
7 | + | ||
8 | +/** | ||
9 | + * @author Administrator | ||
10 | + */ | ||
11 | +@Data | ||
12 | +@EqualsAndHashCode(callSuper = true) | ||
13 | +@TableName(ModelConstants.Table.IOTFS_VIDEO_PLATFORM_TABLE_NAME) | ||
14 | +public class YtVideoPlatformEntity extends TenantBaseEntity { | ||
15 | + | ||
16 | + | ||
17 | + private static final long serialVersionUID = 2003070844243253804L; | ||
18 | + private Integer type; | ||
19 | + private String host; | ||
20 | + private String appKey; | ||
21 | + private String appSecret; | ||
22 | + private Integer ssl; | ||
23 | +} |
dao/src/main/java/org/thingsboard/server/dao/yunteng/impl/YtVideoPlatformServiceImpl.java
0 → 100644
1 | +package org.thingsboard.server.dao.yunteng.impl; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.conditions.Wrapper; | ||
4 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
5 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
6 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
7 | +import lombok.RequiredArgsConstructor; | ||
8 | +import lombok.extern.slf4j.Slf4j; | ||
9 | +import org.springframework.stereotype.Service; | ||
10 | +import org.springframework.transaction.annotation.Transactional; | ||
11 | +import org.thingsboard.server.common.data.StringUtils; | ||
12 | +import org.thingsboard.server.common.data.yunteng.core.exception.YtDataValidationException; | ||
13 | +import org.thingsboard.server.common.data.yunteng.core.message.ErrorMessage; | ||
14 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
15 | +import org.thingsboard.server.common.data.yunteng.dto.YtVideoPlatformDTO; | ||
16 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
17 | +import org.thingsboard.server.dao.yunteng.entities.YtVideoPlatformEntity; | ||
18 | +import org.thingsboard.server.dao.yunteng.mapper.YtVideoPlatformMapper; | ||
19 | +import org.thingsboard.server.dao.yunteng.service.AbstractBaseService; | ||
20 | +import org.thingsboard.server.dao.yunteng.service.YtVideoPlatformService; | ||
21 | + | ||
22 | +@Slf4j | ||
23 | +@Service | ||
24 | +@RequiredArgsConstructor | ||
25 | +public class YtVideoPlatformServiceImpl extends AbstractBaseService<YtVideoPlatformMapper, YtVideoPlatformEntity> | ||
26 | + implements YtVideoPlatformService { | ||
27 | + | ||
28 | + @Override | ||
29 | + public YtPageData<YtVideoPlatformDTO> page(IPage<YtVideoPlatformEntity> pageInfo, | ||
30 | + boolean isPtTenantAdmin, String tenantId, String currentUserId, String host) { | ||
31 | + IPage<YtVideoPlatformDTO> page = | ||
32 | + baseMapper.getVideoPlatformPage(pageInfo, tenantId, host); | ||
33 | + return getPageData(page, YtVideoPlatformDTO.class); | ||
34 | + } | ||
35 | + | ||
36 | + | ||
37 | + @Override | ||
38 | + @Transactional(rollbackFor = Exception.class) | ||
39 | + public YtVideoPlatformDTO saveOrUpdate(YtVideoPlatformDTO videoPlatformDTO) { | ||
40 | + if (StringUtils.isNotEmpty(videoPlatformDTO.getId())) { | ||
41 | + Wrapper filter = new QueryWrapper<YtVideoPlatformEntity>().lambda() | ||
42 | + .eq(YtVideoPlatformEntity::getTenantId, videoPlatformDTO.getTenantId()) | ||
43 | + .eq(YtVideoPlatformEntity::getId, videoPlatformDTO.getId()); | ||
44 | + YtVideoPlatformEntity oldVideo = baseMapper.selectOne(filter); | ||
45 | + if (null == oldVideo) { | ||
46 | + throw new YtDataValidationException(String.format(ErrorMessage.NOT_EXITED_OR_PERMISSION.getMessage(), | ||
47 | + videoPlatformDTO.getId())); | ||
48 | + } | ||
49 | + baseMapper.updateById(videoPlatformDTO.getEntity(YtVideoPlatformEntity.class)); | ||
50 | + } else { | ||
51 | + YtVideoPlatformEntity entity = baseMapper.selectOne(new LambdaQueryWrapper<YtVideoPlatformEntity>(). | ||
52 | + eq(YtVideoPlatformEntity::getHost, videoPlatformDTO.getHost())); | ||
53 | + if (null != entity) { | ||
54 | + throw new YtDataValidationException(ErrorMessage.VIDEO_PLATFORM_HOST_EXISTED.getMessage()); | ||
55 | + } | ||
56 | + baseMapper.insert(videoPlatformDTO.getEntity(YtVideoPlatformEntity.class)); | ||
57 | + } | ||
58 | + return videoPlatformDTO; | ||
59 | + } | ||
60 | + | ||
61 | + | ||
62 | + @Override | ||
63 | + @Transactional(rollbackFor = Exception.class) | ||
64 | + public boolean deleteDataByIds(DeleteDTO deleteDTO) { | ||
65 | + Wrapper<YtVideoPlatformEntity> filter = new QueryWrapper<YtVideoPlatformEntity>().lambda() | ||
66 | + .eq(YtVideoPlatformEntity::getTenantId, deleteDTO.getTenantId()) | ||
67 | + .in(YtVideoPlatformEntity::getId, deleteDTO.getIds()); | ||
68 | + return baseMapper.delete(filter) > 0; | ||
69 | + } | ||
70 | + | ||
71 | +} |
1 | +package org.thingsboard.server.dao.yunteng.mapper; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
4 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
5 | +import org.apache.ibatis.annotations.Mapper; | ||
6 | +import org.apache.ibatis.annotations.Param; | ||
7 | +import org.thingsboard.server.common.data.yunteng.dto.YtVideoPlatformDTO; | ||
8 | +import org.thingsboard.server.dao.yunteng.entities.YtVideoPlatformEntity; | ||
9 | + | ||
10 | + | ||
11 | +/** | ||
12 | + * @author Administrator | ||
13 | + */ | ||
14 | +@Mapper | ||
15 | +public interface YtVideoPlatformMapper extends BaseMapper<YtVideoPlatformEntity> { | ||
16 | + /** | ||
17 | + * @param page | ||
18 | + * @param tenantId | ||
19 | + * @return | ||
20 | + */ | ||
21 | + IPage<YtVideoPlatformDTO> getVideoPlatformPage(IPage<?> page, @Param("tenantId") String tenantId, @Param("host") String host); | ||
22 | +} |
1 | +package org.thingsboard.server.dao.yunteng.service; | ||
2 | + | ||
3 | +import com.baomidou.mybatisplus.core.metadata.IPage; | ||
4 | +import org.thingsboard.server.common.data.yunteng.dto.DeleteDTO; | ||
5 | +import org.thingsboard.server.common.data.yunteng.dto.YtVideoPlatformDTO; | ||
6 | +import org.thingsboard.server.common.data.yunteng.utils.tools.YtPageData; | ||
7 | +import org.thingsboard.server.dao.yunteng.entities.YtVideoPlatformEntity; | ||
8 | + | ||
9 | +public interface YtVideoPlatformService extends BaseService<YtVideoPlatformEntity> { | ||
10 | + | ||
11 | + /** | ||
12 | + * @param pageInfo 分页配置信息 | ||
13 | + * @param isPtTenantAdmin 是否平台管理员 | ||
14 | + * @param tenantId 租户ID | ||
15 | + * @param currentUserId 用户ID | ||
16 | + * @param host 流媒体地址 | ||
17 | + * @return | ||
18 | + */ | ||
19 | + YtPageData<YtVideoPlatformDTO> page(IPage<YtVideoPlatformEntity> pageInfo, | ||
20 | + boolean isPtTenantAdmin, String tenantId, String currentUserId, String host); | ||
21 | + | ||
22 | + /** | ||
23 | + * @param dto | ||
24 | + * @return | ||
25 | + */ | ||
26 | + YtVideoPlatformDTO saveOrUpdate(YtVideoPlatformDTO dto); | ||
27 | + | ||
28 | + /** | ||
29 | + * @param deleteDTO | ||
30 | + * @return | ||
31 | + */ | ||
32 | + boolean deleteDataByIds(DeleteDTO deleteDTO); | ||
33 | + | ||
34 | +} |
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
3 | + | ||
4 | +<mapper namespace="org.thingsboard.server.dao.yunteng.mapper.YtVideoPlatformMapper"> | ||
5 | + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.YtVideoPlatformDTO" id="videoPlatformMap"> | ||
6 | + <result property="id" column="id"/> | ||
7 | + <result property="type" column="type"/> | ||
8 | + <result property="host" column="host"/> | ||
9 | + <result property="appKey" column="app_key"/> | ||
10 | + <result property="appSecret" column="app_secret"/> | ||
11 | + <result property="ssl" column="ssl"/> | ||
12 | + <result property="tenantId" column="tenant_id"/> | ||
13 | + <result property="createTime" column="create_time"/> | ||
14 | + <result property="updateTime" column="update_time"/> | ||
15 | + <result property="creator" column="creator"/> | ||
16 | + <result property="updater" column="updater"/> | ||
17 | + </resultMap> | ||
18 | + | ||
19 | + <sql id="basicColumns"> | ||
20 | + base.id,base.type,base.host,base.app_key,base.app_secret,base.ssl,base.tenant_id,base.create_time, | ||
21 | + base.update_time,base.creator, base.updater | ||
22 | + </sql> | ||
23 | + <select id="getVideoPlatformPage" resultMap="videoPlatformMap"> | ||
24 | + SELECT | ||
25 | + <include refid="basicColumns"/> | ||
26 | + FROM iotfs_video_platform base | ||
27 | + <where> | ||
28 | + <if test="tenantId !=null and tenantId !=''"> | ||
29 | + AND base.tenant_id = #{tenantId} | ||
30 | + </if> | ||
31 | + <if test="host !=null and host !=''"> | ||
32 | + AND base.host LIKE concat('%',#{host}::TEXT,'%') | ||
33 | + </if> | ||
34 | + </where> | ||
35 | + </select> | ||
36 | +</mapper> |