Commit 48ee2a99e86232911e1e48a9fe9b6e46156f7d81

Authored by xp.Huang
2 parents 38662e46 e373a9cb

Merge branch '20220419' into 'master'

20220419

See merge request huang/thingsboard3.3.2!81
@@ -432,6 +432,9 @@ caffeine: @@ -432,6 +432,9 @@ caffeine:
432 mobileLoginSmsCode: 432 mobileLoginSmsCode:
433 timeToLiveInMinutes: 2 433 timeToLiveInMinutes: 2
434 maxSize: 10000 434 maxSize: 10000
  435 + thingsArea:
  436 + timeToLiveInMinutes: 1440
  437 + maxSize: 500
435 438
436 redis: 439 redis:
437 # standalone or cluster 440 # standalone or cluster
@@ -82,4 +82,9 @@ public interface FastIotConstants { @@ -82,4 +82,9 @@ public interface FastIotConstants {
82 int PUBLISHED = 1; 82 int PUBLISHED = 1;
83 int DRAFT = 0; 83 int DRAFT = 0;
84 } 84 }
  85 +
  86 + interface CacheKey {
  87 + String area = "thingsArea";
  88 + int DRAFT = 0;
  89 + }
85 } 90 }
@@ -10,7 +10,7 @@ import javax.validation.constraints.NotEmpty; @@ -10,7 +10,7 @@ import javax.validation.constraints.NotEmpty;
10 @EqualsAndHashCode(callSuper = true) 10 @EqualsAndHashCode(callSuper = true)
11 public class YtVideoDTO extends TenantDTO { 11 public class YtVideoDTO extends TenantDTO {
12 @ApiModelProperty(value = "摄像头附加信息,json格式", required = false) 12 @ApiModelProperty(value = "摄像头附加信息,json格式", required = false)
13 - private String deviceInfo; 13 + private String additionalJson;
14 14
15 @ApiModelProperty(value = "封面图", required = false) 15 @ApiModelProperty(value = "封面图", required = false)
16 private String avatar; 16 private String avatar;
@@ -19,7 +19,7 @@ public class YtVideoEntity extends TenantBaseEntity { @@ -19,7 +19,7 @@ public class YtVideoEntity extends TenantBaseEntity {
19 19
20 private static final long serialVersionUID = 1498859811403607497L; 20 private static final long serialVersionUID = 1498859811403607497L;
21 private String name; 21 private String name;
22 - private String deviceInfo; 22 + private String additionalJson;
23 private String avatar; 23 private String avatar;
24 private String videoUrl; 24 private String videoUrl;
25 private String brand; 25 private String brand;
@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 import lombok.RequiredArgsConstructor; 4 import lombok.RequiredArgsConstructor;
5 import org.apache.commons.lang3.StringUtils; 5 import org.apache.commons.lang3.StringUtils;
6 import org.springframework.beans.BeanUtils; 6 import org.springframework.beans.BeanUtils;
  7 +import org.springframework.cache.CacheManager;
7 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
  9 +import org.thingsboard.server.common.data.yunteng.constant.FastIotConstants;
8 import org.thingsboard.server.common.data.yunteng.dto.SysAreaDTO; 10 import org.thingsboard.server.common.data.yunteng.dto.SysAreaDTO;
9 import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils; 11 import org.thingsboard.server.common.data.yunteng.utils.ReflectUtils;
10 import org.thingsboard.server.dao.yunteng.entities.SysArea; 12 import org.thingsboard.server.dao.yunteng.entities.SysArea;
@@ -23,23 +25,32 @@ import java.util.List; @@ -23,23 +25,32 @@ import java.util.List;
23 public class SysAreaServiceImpl implements SysAreaService { 25 public class SysAreaServiceImpl implements SysAreaService {
24 26
25 private final SysAreaMapper sysAreaMapper; 27 private final SysAreaMapper sysAreaMapper;
  28 + private final CacheManager cacheManager;
26 29
27 @Override 30 @Override
28 public List<SysAreaDTO> list(SysAreaDTO sysAreaDTO) { 31 public List<SysAreaDTO> list(SysAreaDTO sysAreaDTO) {
29 - return ReflectUtils.sourceToTarget(  
30 - sysAreaMapper.selectList(  
31 - new LambdaQueryWrapper<SysArea>()  
32 - .eq(sysAreaDTO.getLevel() != null, SysArea::getLevel, sysAreaDTO.getLevel())  
33 - .eq(  
34 - sysAreaDTO.getParentId() != null,  
35 - SysArea::getParentId,  
36 - sysAreaDTO.getParentId())  
37 - .eq(sysAreaDTO.getCode() != null, SysArea::getCode, sysAreaDTO.getCode())  
38 - .like(  
39 - StringUtils.isNotEmpty(sysAreaDTO.getName()),  
40 - SysArea::getName,  
41 - sysAreaDTO.getName())),  
42 - SysAreaDTO.class); 32 + cacheManager.getCache(FastIotConstants.CacheKey.area).get(sysAreaDTO.getParentId());
  33 + List<SysAreaDTO> result = cacheManager.getCache(FastIotConstants.CacheKey.area).get(sysAreaDTO.getParentId(),List.class);
  34 + if(result == null || result.isEmpty()){
  35 + result = ReflectUtils.sourceToTarget(
  36 + sysAreaMapper.selectList(
  37 + new LambdaQueryWrapper<SysArea>()
  38 + .eq(sysAreaDTO.getLevel() != null, SysArea::getLevel, sysAreaDTO.getLevel())
  39 + .eq(
  40 + sysAreaDTO.getParentId() != null,
  41 + SysArea::getParentId,
  42 + sysAreaDTO.getParentId())
  43 + .eq(sysAreaDTO.getCode() != null, SysArea::getCode, sysAreaDTO.getCode())
  44 + .like(
  45 + StringUtils.isNotEmpty(sysAreaDTO.getName()),
  46 + SysArea::getName,
  47 + sysAreaDTO.getName())),
  48 + SysAreaDTO.class);
  49 + cacheManager.getCache(FastIotConstants.CacheKey.area).put(sysAreaDTO.getParentId(),result);
  50 + }
  51 +
  52 +
  53 + return result;
43 } 54 }
44 55
45 @Override 56 @Override
@@ -49,8 +49,8 @@ public class YtVideoServiceImpl extends AbstractBaseService<YtVideoMapper, YtVid @@ -49,8 +49,8 @@ public class YtVideoServiceImpl extends AbstractBaseService<YtVideoMapper, YtVid
49 .in(organizationIds!=null&& !organizationIds.isEmpty(),YtVideoEntity::getOrganizationId,organizationIds) 49 .in(organizationIds!=null&& !organizationIds.isEmpty(),YtVideoEntity::getOrganizationId,organizationIds)
50 .eq(status!=null,YtVideoEntity::getStatus,status) 50 .eq(status!=null,YtVideoEntity::getStatus,status)
51 .like(StringUtils.isNotEmpty(name),YtVideoEntity::getName,name); 51 .like(StringUtils.isNotEmpty(name),YtVideoEntity::getName,name);
52 - IPage<YtVideoEntity> page =  
53 - baseMapper.selectPage(pageInfrom, pageFilter); 52 + IPage<YtVideoDTO> page =
  53 + baseMapper.getVideoPage(pageInfrom, tenantId,name,status,organizationIds);
54 return getPageData(page, YtVideoDTO.class); 54 return getPageData(page, YtVideoDTO.class);
55 } 55 }
56 56
@@ -5,9 +5,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage; @@ -5,9 +5,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
5 import org.apache.ibatis.annotations.Mapper; 5 import org.apache.ibatis.annotations.Mapper;
6 import org.apache.ibatis.annotations.Param; 6 import org.apache.ibatis.annotations.Param;
7 import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO; 7 import org.thingsboard.server.common.data.yunteng.dto.AlarmProfileDTO;
  8 +import org.thingsboard.server.common.data.yunteng.dto.DeviceDTO;
  9 +import org.thingsboard.server.common.data.yunteng.dto.YtVideoDTO;
8 import org.thingsboard.server.dao.yunteng.entities.AlarmProfile; 10 import org.thingsboard.server.dao.yunteng.entities.AlarmProfile;
9 import org.thingsboard.server.dao.yunteng.entities.YtVideoEntity; 11 import org.thingsboard.server.dao.yunteng.entities.YtVideoEntity;
10 12
  13 +import java.util.List;
11 import java.util.Map; 14 import java.util.Map;
12 15
13 /** 16 /**
@@ -15,4 +18,14 @@ import java.util.Map; @@ -15,4 +18,14 @@ import java.util.Map;
15 */ 18 */
16 @Mapper 19 @Mapper
17 public interface YtVideoMapper extends BaseMapper<YtVideoEntity> { 20 public interface YtVideoMapper extends BaseMapper<YtVideoEntity> {
  21 + /**
  22 + *
  23 + * @param page
  24 + * @param tenantId
  25 + * @param name
  26 + * @param status
  27 + * @param organizationId
  28 + * @return
  29 + */
  30 + IPage<YtVideoDTO> getVideoPage(IPage<?> page, @Param("tenantId") String tenantId, @Param("name") String name, @Param("status") Boolean status, @Param("organization") List<String> organizationId);
18 } 31 }
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 <result property="endTs" column="end_ts"/> 18 <result property="endTs" column="end_ts"/>
19 <result property="ackTs" column="ack_ts"/> 19 <result property="ackTs" column="ack_ts"/>
20 <result property="clearTs" column="clear_ts"/> 20 <result property="clearTs" column="clear_ts"/>
21 - <result property="details" column="details" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/> 21 + <result property="details" column="additional_info" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
22 <result property="propagate" column="propagate"/> 22 <result property="propagate" column="propagate"/>
23 </resultMap> 23 </resultMap>
24 24
  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.YtVideoMapper">
  5 + <resultMap type="org.thingsboard.server.common.data.yunteng.dto.YtVideoDTO" id="videoMap">
  6 + <result property="id" column="id"/>
  7 + <result property="name" column="name"/>
  8 + <result property="avatar" column="avatar"/>
  9 + <result property="videoUrl" column="video_url"/>
  10 + <result property="brand" column="brand"/>
  11 + <result property="deviceType" column="device_type" />
  12 + <result property="sn" column="sn"/>
  13 + <result property="tenantId" column="tenant_id"/>
  14 + <result property="createTime" column="create_time"/>
  15 + <result property="updateTime" column="update_time"/>
  16 + <result property="creator" column="creator"/>
  17 + <result property="updater" column="updater"/>
  18 + <result property="description" column="description"/>
  19 + <result property="status" column="status"/>
  20 + <result property="additionalJson" column="additional_json"/>
  21 + <result property="organizationId" column="organization_id"/>
  22 + <result property="organizationName" column="organization_name"/>
  23 + </resultMap>
  24 +
  25 +
  26 +
  27 + <sql id="basicColumns">
  28 + base.id,base.sn,base.name,base.avatar,base.video_url,base.description,base.status,base.additional_json,base.device_type,base.organization_id
  29 + ,base.tenant_id,base.create_time,base.update_time,base.creator, base.updater
  30 + </sql>
  31 +
  32 + <sql id="detailColumns">
  33 + <include refid="basicColumns"/>
  34 + ,org.name AS organization_name
  35 + </sql>
  36 + <select id="getVideoPage" resultMap="videoMap">
  37 + SELECT
  38 + <include refid="detailColumns"/>
  39 + FROM iotfs_device_camera base
  40 + LEFT JOIN iotfs_organization org ON org.id = base.organization_id
  41 + <where>
  42 + <if test="tenantId !=null and tenantId !=''">
  43 + AND base.tenant_id = #{tenantId}
  44 + </if>
  45 + <if test="name !=null and name !=''">
  46 + AND base.name LIKE concat('%',#{name}::TEXT,'%')
  47 + </if>
  48 + <if test="status !=null">
  49 + AND base.status = #{status}
  50 + </if>
  51 + <if test="organization !=null">
  52 + AND base.organization_id IN
  53 + <foreach collection="organization" item="organizationId" open="(" separator="," close=")">
  54 + #{organizationId}
  55 + </foreach>
  56 + </if>
  57 + </where>
  58 + </select>
  59 +
  60 +
  61 + <select id="selectDetail" resultMap="videoMap">
  62 + SELECT
  63 + <include refid="detailColumns"/>,d.customer_id::TEXT AS customer_id
  64 + FROM iotfs_device_camera base
  65 + LEFT JOIN iotfs_organization org ON org.id = base.organization_id
  66 + <where>
  67 + <if test="tenantId !=null and tenantId !=''">
  68 + AND base.tenant_id = #{tenantId}
  69 + </if>
  70 + <if test="id !=null and id !=''">
  71 + AND base.id = #{id}
  72 + </if>
  73 +
  74 + </where>
  75 + </select>
  76 +
  77 +
  78 +
  79 +
  80 +</mapper>
@@ -284,7 +284,7 @@ class ReactState { @@ -284,7 +284,7 @@ class ReactState {
284 for (String id : devices) { 284 for (String id : devices) {
285 TbMsg newMsg = ctx.newMsg(lastMsgQueueName != null ? lastMsgQueueName : ServiceQueue.MAIN 285 TbMsg newMsg = ctx.newMsg(lastMsgQueueName != null ? lastMsgQueueName : ServiceQueue.MAIN
286 , msg.getType() 286 , msg.getType()
287 - , msg.getOriginator() 287 + , new DeviceId(UUID.fromString(id))
288 , msg != null ? msg.getCustomerId() : null 288 , msg != null ? msg.getCustomerId() : null
289 , metaData 289 , metaData
290 , JacksonUtil.toString(context)); 290 , JacksonUtil.toString(context));