Commit f8abe650 authored by suhuiguang's avatar suhuiguang

1。视频点增加建筑父级冗余,树形查询用

parent 20abe15f
...@@ -34,4 +34,7 @@ public class VideoSource { ...@@ -34,4 +34,7 @@ public class VideoSource {
@TableField(exist = false) @TableField(exist = false)
private Date createDate; private Date createDate;
@ApiModelProperty(value = "本级及父级建筑ids,冗余树形搜索")
private String parentSourceIds;
} }
...@@ -87,4 +87,6 @@ public interface VideoMapper extends BaseMapper<Video> { ...@@ -87,4 +87,6 @@ public interface VideoMapper extends BaseMapper<Video> {
List<Video>listByCode(@Param("code")String code); List<Video>listByCode(@Param("code")String code);
List<Video> selectListBySourceId(Long floorId); List<Video> selectListBySourceId(Long floorId);
String getParentSourceIds(String childrenId);
} }
...@@ -157,6 +157,8 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i ...@@ -157,6 +157,8 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i
@Value("${firefightingsystem.equip.alarms.url}") @Value("${firefightingsystem.equip.alarms.url}")
private String ffsEquipAlarmsUrl; private String ffsEquipAlarmsUrl;
final String ALL_BUILDING = "allBuilding";
/** /**
* @param groupCode * @param groupCode
* @Description 根据groupCode查询allowOperation对应的操作菜单 * @Description 根据groupCode查询allowOperation对应的操作菜单
...@@ -768,19 +770,17 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i ...@@ -768,19 +770,17 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i
@Override @Override
public Page<BuildingVideoVO> buildingVideoList(Page page, BuildingVideoListVO dto) { public Page<BuildingVideoVO> buildingVideoList(Page page, BuildingVideoListVO dto) {
Page<BuildingVideoVO> pages = videoService.pageBuildingVideo(page, dto); Page<BuildingVideoVO> pages = videoService.pageBuildingVideo(page, dto);
if (0 < pages.getRecords().size()) { pages.getRecords().forEach(x -> {
pages.getRecords().forEach(x -> { if (StringUtil.isNotEmpty(x.getLocation()) && StringUtil.isNotEmpty(x.getAddress())) {
if (StringUtil.isNotEmpty(x.getLocation()) && StringUtil.isNotEmpty(x.getAddress())) { x.setLocation(x.getLocation() + '-' + x.getAddress());
x.setLocation(x.getLocation() + '-' + x.getAddress()); } else {
} else { if (!StringUtil.isNotEmpty(x.getLocation())) {
if (!StringUtil.isNotEmpty(x.getLocation())) { x.setLocation(x.getAddress());
x.setLocation(x.getAddress());
}
} }
x.setVedioFormat(vedioFormat); }
x.setUrl(videoService.getVideoUrl(x.getName(), x.getPresetPosition(), x.getUrl(), x.getCode())); x.setVedioFormat(vedioFormat);
}); x.setUrl(videoService.getVideoUrl(x.getName(), x.getPresetPosition(), x.getUrl(), x.getCode()));
} });
return pages; return pages;
} }
...@@ -1160,6 +1160,14 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i ...@@ -1160,6 +1160,14 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i
List<BuildingTreeVo> companyBuildingList = buildBuildingAndCompanyListVos(buildVideoAuthKey); List<BuildingTreeVo> companyBuildingList = buildBuildingAndCompanyListVos(buildVideoAuthKey);
List<Map<String, Long>> countList = iFormInstanceService.getBuildVideoCount(); List<Map<String, Long>> countList = iFormInstanceService.getBuildVideoCount();
Map<Long, Long> countMap = countList.stream().collect(Collectors.toMap(p -> p.get("buildId"), p -> p.get("total"))); Map<Long, Long> countMap = countList.stream().collect(Collectors.toMap(p -> p.get("buildId"), p -> p.get("total")));
companyBuildingList.forEach(c-> {
if(!ALL_BUILDING.equals(c.getGroupType())){
c.setTotal(countMap.get(c.getInstanceId()) == null ? 0L : countMap.get(c.getInstanceId()));
} else {
// 方法 复用,覆盖掉不需要的数据
c.setTotal(0L);
}
});
//2.list to tree //2.list to tree
return companyBuildingList.stream() return companyBuildingList.stream()
.filter(a -> companyBuildingList.stream().noneMatch(c -> c.getId().toString().equals(a.getParentId()))) .filter(a -> companyBuildingList.stream().noneMatch(c -> c.getId().toString().equals(a.getParentId())))
...@@ -1169,11 +1177,13 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i ...@@ -1169,11 +1177,13 @@ public class BuildingServiceImpl extends ServiceImpl<BuildingMapper, Building> i
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
private List<BuildingTreeVo> getCompanyBuildingChildrenWithCount(String private List<BuildingTreeVo> getCompanyBuildingChildrenWithCount(String parentId, List<BuildingTreeVo> companyBuildingList) {
parentId, List<BuildingTreeVo> companyBuildingList) {
return companyBuildingList.stream().filter(a -> parentId.equals(a.getParentId())).peek(a -> { return companyBuildingList.stream().filter(a -> parentId.equals(a.getParentId())).peek(a -> {
a.setChildren(getCompanyBuildingChildrenWithCount(a.getId().toString(), companyBuildingList)); a.setChildren(getCompanyBuildingChildrenWithCount(a.getId().toString(), companyBuildingList));
a.setTotal(a.getChildren().stream().filter(c -> c.getTotal() != null).mapToLong(BuildingTreeVo::getTotal).sum()); //单位类型节点才需要设置摄像头总数,建筑的下摄像头总数已经在sql计算出来
if(ALL_BUILDING.equals(a.getGroupType())){
a.setTotal(a.getChildren().stream().filter(c -> c.getTotal() != null).mapToLong(BuildingTreeVo::getTotal).sum());
}
}).collect(Collectors.toList()); }).collect(Collectors.toList());
} }
......
...@@ -100,15 +100,16 @@ public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements ...@@ -100,15 +100,16 @@ public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements
List<VideoSource> videoSources = new ArrayList<>(); List<VideoSource> videoSources = new ArrayList<>();
if (videoSave.getIds() != null && videoSave.getIds().size() > 0) { if (videoSave.getIds() != null && videoSave.getIds().size() > 0) {
videoSave.getIds().forEach(x -> { videoSave.getIds().forEach(x -> {
if (x != null && x.indexOf("equip") != -1) { if (x != null && x.contains("equip")) {
VideoEquipmentSpecific videoEquipmentSpecific = new VideoEquipmentSpecific(); VideoEquipmentSpecific videoEquipmentSpecific = new VideoEquipmentSpecific();
videoEquipmentSpecific.setEquipmentSpecificId(Long.valueOf(x.substring(5))); videoEquipmentSpecific.setEquipmentSpecificId(Long.valueOf(x.substring(5)));
videoEquipmentSpecific.setVideoId(videoSave.getVideo().getId()); videoEquipmentSpecific.setVideoId(videoSave.getVideo().getId());
videoEquipmentSpecifics.add(videoEquipmentSpecific); videoEquipmentSpecifics.add(videoEquipmentSpecific);
} else if (x != null && x.indexOf("region") != -1) { } else if (x != null && x.contains("region")) {
VideoSource videoSource = new VideoSource(); VideoSource videoSource = new VideoSource();
videoSource.setVideoId(videoSave.getVideo().getId()); videoSource.setVideoId(videoSave.getVideo().getId());
videoSource.setSourceId(Long.valueOf(x.substring(6))); videoSource.setSourceId(Long.valueOf(x.substring(6)));
videoSource.setParentSourceIds(getParentSourceIds(videoSource.getSourceId().toString()));
videoSources.add(videoSource); videoSources.add(videoSource);
} }
}); });
...@@ -130,6 +131,10 @@ public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements ...@@ -130,6 +131,10 @@ public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements
return videoSave.getVideo(); return videoSave.getVideo();
} }
private String getParentSourceIds(String childrenId){
return this.videoMapper.getParentSourceIds(childrenId);
}
@Transactional @Transactional
@Override @Override
public Boolean delVideo(List<Long> ids) { public Boolean delVideo(List<Long> ids) {
...@@ -173,15 +178,16 @@ public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements ...@@ -173,15 +178,16 @@ public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements
List<VideoSource> videoSources = new ArrayList<>(); List<VideoSource> videoSources = new ArrayList<>();
if (videoSave.getIds() != null && videoSave.getIds().size() > 0) { if (videoSave.getIds() != null && videoSave.getIds().size() > 0) {
videoSave.getIds().forEach(x -> { videoSave.getIds().forEach(x -> {
if (x != null && x.indexOf("equip") != -1) { if (x != null && x.contains("equip")) {
VideoEquipmentSpecific videoEquipmentSpecific = new VideoEquipmentSpecific(); VideoEquipmentSpecific videoEquipmentSpecific = new VideoEquipmentSpecific();
videoEquipmentSpecific.setEquipmentSpecificId(Long.valueOf(x.substring(5))); videoEquipmentSpecific.setEquipmentSpecificId(Long.valueOf(x.substring(5)));
videoEquipmentSpecific.setVideoId(videoSave.getVideo().getId()); videoEquipmentSpecific.setVideoId(videoSave.getVideo().getId());
videoEquipmentSpecifics.add(videoEquipmentSpecific); videoEquipmentSpecifics.add(videoEquipmentSpecific);
} else if (x != null && x.indexOf("region") != -1) { } else if (x != null && x.contains("region")) {
VideoSource videoSource = new VideoSource(); VideoSource videoSource = new VideoSource();
videoSource.setVideoId(videoSave.getVideo().getId()); videoSource.setVideoId(videoSave.getVideo().getId());
videoSource.setSourceId(Long.valueOf(x.substring(6))); videoSource.setSourceId(Long.valueOf(x.substring(6)));
videoSource.setParentSourceIds(getParentSourceIds(videoSource.getSourceId().toString()));
videoSources.add(videoSource); videoSources.add(videoSource);
} }
}); });
......
...@@ -2385,4 +2385,46 @@ ...@@ -2385,4 +2385,46 @@
alter table `wl_equipment_specific` modify column `team_id` varchar(32) DEFAULT NULL COMMENT '所属队伍id(来源于平台)'; alter table `wl_equipment_specific` modify column `team_id` varchar(32) DEFAULT NULL COMMENT '所属队伍id(来源于平台)';
</sql> </sql>
</changeSet> </changeSet>
<changeSet author="shg" id="1644459872903-2">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="wl_video_source" columnName="parent_source_ids"/>
</not>
</preConditions>
<comment>wl_video_source add column parent_source_ids 本级及父级建筑ids,冗余树形搜索</comment>
<sql>
alter table `wl_video_source` add column `parent_source_ids` text COMMENT '本级及父级建筑ids,冗余树形搜索';
</sql>
</changeSet>
<changeSet author="shg" id="1644459872903-1" runAlways="true">
<comment>`getBuildingParentIds` 存在前后顺序依赖关系所以放在这里</comment>
<sql endDelimiter="#">
DROP FUNCTION IF EXISTS `getBuildingParentIds`#
CREATE DEFINER=`root`@`%` FUNCTION `getBuildingParentIds`(`childrenId` VARCHAR(32)) RETURNS varchar(1000) CHARSET utf8
BEGIN
DECLARE ptemp VARCHAR(1000);
DECLARE ctemp VARCHAR(1000);
DECLARE ctempName VARCHAR(1000);
SET ptemp ='';
SET ctemp = childrenId;
WHILE ctemp != '0' DO
SET ptemp = concat(ptemp,',',ctemp);
SELECT IFNULL((SELECT parentId
FROM get_building_tree
WHERE instanceId = ctemp),'0') INTO ctemp;
END WHILE;
SET ptemp = SUBSTR(ptemp,2);
RETURN ptemp;
END#
</sql>
</changeSet>
<changeSet author="shg" id="1644459872903-3">
<preConditions onFail="MARK_RAN">
<columnExists tableName="wl_video_source" columnName="parent_source_ids"/>
</preConditions>
<comment>wl_video_source 存量数据修改parent_source_ids</comment>
<sql>
update wl_video_source s set s.parent_source_ids = (SELECT getBuildingParentIds(s.source_id)) ;
</sql>
</changeSet>
</databaseChangeLog> </databaseChangeLog>
\ No newline at end of file
...@@ -61,14 +61,15 @@ ...@@ -61,14 +61,15 @@
v.token AS token, v.token AS token,
v.url AS url, v.url AS url,
v.code AS code, v.code AS code,
getBuildingNames(vc.source_id) as location, ws.full_name as location,
v.address, v.address,
v.preset_position as presetPosition v.preset_position as presetPosition
FROM wl_video v FROM wl_video v
JOIN wl_video_source vc ON vc.video_id = v.id JOIN wl_video_source vc ON vc.video_id = v.id
left join wl_warehouse_structure ws on ws.id = vc.source_id
<where> <where>
<if test="dto.buildingId!=null and dto.buildingId!=''"> <if test="dto.buildingId!=null and dto.buildingId!=''">
FIND_IN_SET(vc.source_id, getBuildChildIdsByRootId(#{dto.buildingId})) FIND_IN_SET(#{dto.buildingId}, vc.parent_source_ids)
</if> </if>
<if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''"> <if test="dto.bizOrgCode!=null and dto.bizOrgCode!=''">
and v.biz_org_code LIKE CONCAT(#{dto.bizOrgCode}, '%') and v.biz_org_code LIKE CONCAT(#{dto.bizOrgCode}, '%')
...@@ -377,4 +378,7 @@ ...@@ -377,4 +378,7 @@
where vs.source_id = #{floorId} where vs.source_id = #{floorId}
and vs.video_id = v.id and vs.video_id = v.id
</select> </select>
<select id="getParentSourceIds" resultType="java.lang.String">
select getBuildingParentIds(#{childrenId})
</select>
</mapper> </mapper>
...@@ -2770,7 +2770,5 @@ ...@@ -2770,7 +2770,5 @@
END# END#
</sql> </sql>
</changeSet> </changeSet>
</databaseChangeLog> </databaseChangeLog>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment