1、新增摄像头聚合展示
This commit is contained in:
parent
6e328843a8
commit
1290072076
|
@ -1,5 +1,7 @@
|
|||
package io.renren.modules.monitor.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.renren.modules.monitor.dto.*;
|
||||
import io.renren.modules.monitor.entity.*;
|
||||
import io.renren.modules.monitor.mapper.*;
|
||||
|
@ -581,5 +583,111 @@ public class Controller {
|
|||
return success;
|
||||
}
|
||||
|
||||
/******************************2022/07/13 ytl修改视频资源 start********************************************/
|
||||
|
||||
/**
|
||||
* 根据parentId查询组织新,带摄像头通道数量
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("selectSubOrganNew")
|
||||
@ApiOperation("根据上级组织id查询组织,带摄像头通道数量")
|
||||
@ApiImplicitParam(name = "parentId",value = "上级组织id",required = true,dataType = "String")
|
||||
public Result selectSubOrganizationNew(String parentId){
|
||||
if (parentId == null){
|
||||
parentId = "";
|
||||
}
|
||||
|
||||
//List<CameraOrganization> organs = cameraOrgenMapper.selectSubOrganization(parentId);
|
||||
List<Map> maps = monitorService.selectSubOrganizationNew(parentId);
|
||||
|
||||
Result success = Result.success(maps);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据parentId和checkStatus查询摄像头
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("selectByParentIdNew")
|
||||
@ApiOperation("根据摄像头的组织Id和异常状态查询摄像头")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "parentId",value = "摄像头的组织Id",required = true,dataType = "String"),
|
||||
@ApiImplicitParam(name = "checkStatus",value = "异常状态 1正常,0异常",required = false,dataType = "String"),
|
||||
@ApiImplicitParam(name = "cameraName",value = "摄像头名称",dataType = "String"),
|
||||
@ApiImplicitParam(name = "gpsX",value = "经度坐标",dataType = "Double"),
|
||||
@ApiImplicitParam(name = "gpsY",value = "纬度坐标",dataType = "Double"),
|
||||
@ApiImplicitParam(name = "pageNum",value = "页码",dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize",value = "页数大小",dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "radius",value = "半径",dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "labelCodes",value = "标签",dataType = "List")
|
||||
})
|
||||
public Result selectByParentIdNew(@RequestParam Map queryMap, String[] labelCodes){
|
||||
if (!queryMap.containsKey("pageNum")) {
|
||||
queryMap.put("pageNum", null);
|
||||
queryMap.put("pageSize", null);
|
||||
} else {
|
||||
Integer pageNum = Integer.parseInt(queryMap.get("pageNum").toString());
|
||||
Integer pageSize = Integer.parseInt(queryMap.get("pageSize").toString());
|
||||
queryMap.replace("pageNum", (pageNum - 1) * pageSize);
|
||||
queryMap.replace("pageSize", pageSize);
|
||||
}
|
||||
List<String> list1 = null;
|
||||
if (null != labelCodes && labelCodes.length > 0) {
|
||||
list1 = Arrays.asList(labelCodes);
|
||||
}
|
||||
List<Map> list = cameraChannelMapper.selectByParentIdNew(queryMap, list1);
|
||||
|
||||
Result success = Result.success(list);
|
||||
success.setCount(cameraChannelMapper.selectByParentIdCountNew(queryMap, list1));
|
||||
return success;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 摄像头按照市区进行聚合查询
|
||||
*/
|
||||
@GetMapping("selectChannelNumByRegion")
|
||||
@ApiOperation("根据摄像头的组织Id和异常状态查询摄像头")
|
||||
public Result selectChannelNumByRegion() throws Exception{
|
||||
return monitorService.selectChannelNumByRegion();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存区域信息
|
||||
*/
|
||||
@GetMapping("/saveOrgenization")
|
||||
public Result saveOrgenization() throws Exception{
|
||||
List<JSONObject> orgenizationByPage = monitorService.getOrgenization(new ArrayList<JSONObject>());
|
||||
List<Map> maps = JSONObject.parseArray(JSONObject.toJSONString(orgenizationByPage), Map.class);
|
||||
if(maps.size() > 0){
|
||||
List<List<Map>> lists = Lists.partition(maps,100);
|
||||
lists.forEach(list->{
|
||||
cameraOrgenMapper.batchSaveOrgenization(list);
|
||||
});
|
||||
|
||||
maps.forEach(map->{
|
||||
monitorService.setOrganizationPath(map,map.get("parentId").toString());
|
||||
});
|
||||
//修改path
|
||||
maps.forEach(m->{
|
||||
cameraOrgenMapper.updateOrganizationPaht(m.get("path").toString(),m.get("id").toString());
|
||||
});
|
||||
}
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存通道信息
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("saveChannelInfo")
|
||||
public Result saveChannelInfo() throws Exception{
|
||||
return monitorService.saveChannelInfo();
|
||||
}
|
||||
/******************************2022/07/13 ytl修改视频资源 end********************************************/
|
||||
|
||||
}
|
||||
|
|
|
@ -61,4 +61,12 @@ public interface CameraChannelMapper extends BaseDao<CameraChannel> {
|
|||
List<CameraChannelNLDto> selectByLabel(@Param("page") Integer page,@Param("pageSize") Integer pageSize);
|
||||
|
||||
Integer selectByParentIdCount(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes);
|
||||
|
||||
Integer selectChannelCounts(@Param("path") String path);
|
||||
|
||||
List<Map> selectByParentIdNew(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes);
|
||||
|
||||
Integer selectByParentIdCountNew(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes);
|
||||
|
||||
List<Map> selectChannelNumByRegion();
|
||||
}
|
||||
|
|
|
@ -6,12 +6,36 @@ import io.renren.modules.monitor.entity.CameraOrganization;
|
|||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface CameraOrgenizationMapper extends BaseDao<CameraOrganization> {
|
||||
|
||||
@Select("select * from t_camera_organization where parent_id = #{parentId}")
|
||||
List<CameraOrganization> selectSubOrganization(@Param("parentId") String parentId);
|
||||
|
||||
@Select("select *,0 AS channelCount from t_camera_organization02 where parent_id = #{parentId}")
|
||||
List<Map> selectSubOrganizationMap(@Param("parentId") String parentId);
|
||||
|
||||
void batchSaveOrgenization(List<Map> list);
|
||||
|
||||
@Select("SELECT name,parent_id FROM t_camera_organization02 WHERE id = #{id}")
|
||||
Map selectOrgenizationById(@Param("id") String id);
|
||||
|
||||
@Update("UPDATE t_camera_organization02 SET path = TRIM( TRAILING '->' FROM #{path}) where id = #{id}")
|
||||
void updateOrganizationPaht(@Param("path") String path,@Param("id") String id);
|
||||
|
||||
@Select(" SELECT id FROM t_camera_organization02")
|
||||
List<Map> listOrgenization();
|
||||
|
||||
@Select(" SELECT name FROM t_camera_organization02 where substring(id,5) = #{idPart} and left(id,3) = '006'")
|
||||
String getNameByidPart(@Param("idPart")String idPart);
|
||||
|
||||
@Update("UPDATE t_camera_organization02 SET COUNT = COUNT + 1 WHERE id = #{id}")
|
||||
void updateOrganizationCount(@Param("id") String id);
|
||||
|
||||
void batchSaveCameraChannel(List<Map> list);
|
||||
}
|
||||
|
|
|
@ -1091,6 +1091,166 @@ public class MonitorService {
|
|||
|
||||
return yestDay.format(formatter);
|
||||
}
|
||||
|
||||
//根据父id查询查询通道的数量
|
||||
public List<Map> selectSubOrganizationNew(String parentId) {
|
||||
if (parentId == null){
|
||||
parentId = "";
|
||||
}
|
||||
List<Map> organs = cameraOrgenMapper.selectSubOrganizationMap(parentId);//查询某个区域下的所有地区
|
||||
if(organs.size() > 0){
|
||||
for(int i=0;i< organs.size();i++){
|
||||
String path = organs.get(i).get("path").toString();
|
||||
|
||||
Integer count = cameraChannelMapper.selectChannelCounts(path);
|
||||
organs.get(i).put("channelCount",count);
|
||||
|
||||
};
|
||||
}
|
||||
return organs;
|
||||
}
|
||||
|
||||
|
||||
public Result selectChannelNumByRegion() throws Exception{
|
||||
List<Map> maps = cameraChannelMapper.selectChannelNumByRegion();
|
||||
return Result.success(maps);
|
||||
}
|
||||
|
||||
public List<JSONObject> getOrgenization(List<JSONObject> list){
|
||||
try {
|
||||
List<JSONObject> list1 = this.getOrgenizationRoot();
|
||||
list.addAll(list1);
|
||||
list1.forEach(a->{
|
||||
if(a.getBooleanValue("isParent")){
|
||||
getOrgenizationByParent(list,a.getString("id"));
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}catch (Exception e){
|
||||
log.info(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//获取根组织
|
||||
public List<JSONObject> getOrgenizationRoot() throws Exception{
|
||||
List<JSONObject> list = new ArrayList<>();
|
||||
String url = monitorDomain + "/videoService/devicesManager/deviceTree?id=&nodeType=1&typeCode=01&page=1&pageSize=3000";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("X-Subject-Token",token);
|
||||
ResponseEntity<JSONObject> responseEntity = null;
|
||||
|
||||
HttpEntity<Map> httpEntity = new HttpEntity<>(null, headers);
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET,httpEntity,JSONObject.class);
|
||||
JSONObject re = responseEntity.getBody();
|
||||
List<JSONObject> results = re.getJSONArray("results").toJavaList(JSONObject.class);
|
||||
return results;
|
||||
}
|
||||
|
||||
//组织递归根据父ID查,简化了分页
|
||||
public List<JSONObject> getOrgenizationByParent(List<JSONObject> list,String id){
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("X-Subject-Token",token);
|
||||
String url;
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
HttpEntity<Map> httpEntity;
|
||||
ResponseEntity<JSONObject> responseEntity = null;
|
||||
|
||||
url = monitorDomain + "/videoService/devicesManager/deviceTree?id="+id+"&nodeType=1&typeCode=01&page=1&pageSize=3000";
|
||||
|
||||
httpEntity = new HttpEntity<>(null, headers);
|
||||
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET,httpEntity,JSONObject.class);
|
||||
JSONObject re = responseEntity.getBody();
|
||||
if(re.getIntValue("totalCount")>0){
|
||||
JSONArray results = re.getJSONArray("results");
|
||||
List<JSONObject> jsonObjects = results.toJavaList(JSONObject.class);
|
||||
list.addAll(jsonObjects);
|
||||
jsonObjects.forEach(js->{
|
||||
if(js.getBooleanValue("isParent")){
|
||||
getOrgenizationByParent(list,js.getString("id"));
|
||||
}
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
//更新组织的path
|
||||
public void setOrganizationPath(Map map ,String parentId){
|
||||
Map map2 = cameraOrgenMapper.selectOrgenizationById(parentId);
|
||||
if(map2 != null){
|
||||
String path = map2.get("name").toString();
|
||||
String newNodeName = path + "->" + (map.get("path")==null?"":map.get("path").toString());
|
||||
map.put("path",newNodeName);
|
||||
setOrganizationPath(map,map2.get("parent_id").toString());
|
||||
}
|
||||
}
|
||||
|
||||
//保存通道信息
|
||||
public Result saveChannelInfo() throws Exception {
|
||||
List<Map> orgenList = cameraOrgenMapper.listOrgenization();
|
||||
for(Map m:orgenList){
|
||||
List<Map> cameChannels = getChannelInfo(m.get("id").toString());
|
||||
List<Map> needSave = new ArrayList<>();
|
||||
if(cameChannels.size() > 0){
|
||||
boolean flag = false;
|
||||
for(Map j:cameChannels){
|
||||
if(Integer.parseInt(j.get("nodeType").toString()) ==3){
|
||||
flag = true;
|
||||
String channelSn = j.get("channelSn").toString();
|
||||
String channelOrngin = channelSn.substring(0,6);
|
||||
String deptName = cameraOrgenMapper.getNameByidPart(channelOrngin);
|
||||
j.put("regionName",deptName);
|
||||
j.put("regionCode",channelOrngin);
|
||||
j.put("parentId",m.get("id").toString());
|
||||
j.put("nodeName","");
|
||||
needSave.add(j);
|
||||
}
|
||||
}
|
||||
if(!flag){//更新count字段
|
||||
cameraOrgenMapper.updateOrganizationCount(m.get("id").toString());
|
||||
}
|
||||
}else{//更新count字段
|
||||
cameraOrgenMapper.updateOrganizationCount(m.get("id").toString());
|
||||
}
|
||||
|
||||
needSave.forEach(map->setNodeName(map,map.get("parentId").toString()));
|
||||
//保存并更新count字段
|
||||
if(needSave.size() > 0){
|
||||
List<List<Map>> partition = Lists.partition(needSave, 100);
|
||||
partition.forEach(list->{
|
||||
cameraOrgenMapper.batchSaveCameraChannel(list);
|
||||
});
|
||||
cameraOrgenMapper.updateOrganizationCount(m.get("id").toString());
|
||||
}
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
//根据组织id获取通道信息
|
||||
public List<Map> getChannelInfo(String orgenId) throws Exception{
|
||||
String url = monitorDomain +"/videoService/devicesManager/deviceTree?nodeType=1&typeCode=01;0;ALL;ALL&page=1&pageSize=3000&id="+orgenId;
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("X-Subject-Token",token);
|
||||
ResponseEntity<JSONObject> responseEntity = null;
|
||||
|
||||
HttpEntity<Map> httpEntity = new HttpEntity<>(null, headers);
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET,httpEntity,JSONObject.class);
|
||||
JSONObject re = responseEntity.getBody();
|
||||
List<Map> results = re.getJSONArray("results").toJavaList(Map.class);
|
||||
return results;
|
||||
}
|
||||
|
||||
//查询nodename
|
||||
public void setNodeName(Map map,String id){
|
||||
Map map2 = cameraOrgenMapper.selectOrgenizationById(id);
|
||||
if(map2 != null){
|
||||
String nodeName = map2.get("name").toString();
|
||||
String newNodeName = nodeName + "->" + (map.get("nodeName")==null?"":map.get("nodeName").toString());
|
||||
map.put("nodeName",newNodeName);
|
||||
setNodeName(map,map2.get("parent_id").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,4 +116,103 @@
|
|||
</if> ) temp
|
||||
</select>
|
||||
|
||||
<select id="selectChannelCounts" parameterType="java.lang.String" resultType="integer">
|
||||
SELECT COUNT(a.idt_camera_channel) FROM t_camera_channel01 a inner join t_camera_organization02 b on a.parent_id = b.id
|
||||
WHERE b.path like concat(#{path},'%')
|
||||
</select>
|
||||
|
||||
<select id="selectByParentIdNew" resultType="java.util.Map">
|
||||
SELECT
|
||||
tcc.*
|
||||
<if test = "(map.gpsX != null and map.gpsX != '') and (map.gpsY != null and map.gpsY != '')">
|
||||
, 6371 * 1000 * acos(cos(radians( ${map.gpsY} ))
|
||||
* cos(radians( tcc.gps_y ))
|
||||
* cos(radians( tcc.gps_x ) - radians( ${map.gpsX} ))
|
||||
+ sin(radians( ${map.gpsY} ))
|
||||
* sin(radians( tcc.gps_y ))) AS `distance`
|
||||
</if>
|
||||
FROM
|
||||
t_camera_channel01 tcc
|
||||
<if test = "labelCodes != null and labelCodes.size > 0">
|
||||
JOIN t_channel_mtm_label tcml ON tcml.channel_code = tcc.channel_code
|
||||
JOIN t_label tl ON tl.label_code = tcml.label_code
|
||||
</if>
|
||||
WHERE 1 = 1
|
||||
<if test = "map.parentId != null and map.parentId != ''">
|
||||
AND tcc.parent_id = #{map.parentId}
|
||||
</if>
|
||||
AND tcc.check_status IN (${map.checkStatus})
|
||||
AND tcc.gps_x != ''
|
||||
AND tcc.gps_y != ''
|
||||
AND tcc.gps_x IS NOT NULL
|
||||
AND tcc.gps_y IS NOT NULL
|
||||
<if test = "map.cameraName != null and map.cameraName != ''">
|
||||
AND tcc.channel_name LIKE CONCAT('%',#{map.cameraName},'%')
|
||||
</if>
|
||||
<if test = "labelCodes != null and labelCodes.size > 0">
|
||||
AND tl.label_code IN
|
||||
<foreach collection="labelCodes" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test = "map.radius != null and map.radius != ''">
|
||||
HAVING
|
||||
distance < ${map.radius}
|
||||
ORDER BY
|
||||
distance
|
||||
</if>
|
||||
<if test = "map.pageNum != null and map.pageSize != null">
|
||||
LIMIT ${map.pageNum}, ${map.pageSize}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectByParentIdNew" resultType="java.util.Map">
|
||||
SELECT
|
||||
tcc.*
|
||||
<if test = "(map.gpsX != null and map.gpsX != '') and (map.gpsY != null and map.gpsY != '')">
|
||||
, 6371 * 1000 * acos(cos(radians( ${map.gpsY} ))
|
||||
* cos(radians( tcc.gps_y ))
|
||||
* cos(radians( tcc.gps_x ) - radians( ${map.gpsX} ))
|
||||
+ sin(radians( ${map.gpsY} ))
|
||||
* sin(radians( tcc.gps_y ))) AS `distance`
|
||||
</if>
|
||||
FROM
|
||||
t_camera_channel01 tcc
|
||||
<if test = "labelCodes != null and labelCodes.size > 0">
|
||||
JOIN t_channel_mtm_label tcml ON tcml.channel_code = tcc.channel_code
|
||||
JOIN t_label tl ON tl.label_code = tcml.label_code
|
||||
</if>
|
||||
WHERE 1 = 1
|
||||
<if test = "map.parentId != null and map.parentId != ''">
|
||||
AND tcc.parent_id = #{map.parentId}
|
||||
</if>
|
||||
AND tcc.check_status IN (${map.checkStatus})
|
||||
AND tcc.gps_x != ''
|
||||
AND tcc.gps_y != ''
|
||||
AND tcc.gps_x IS NOT NULL
|
||||
AND tcc.gps_y IS NOT NULL
|
||||
<if test = "map.cameraName != null and map.cameraName != ''">
|
||||
AND tcc.channel_name LIKE CONCAT('%',#{map.cameraName},'%')
|
||||
</if>
|
||||
<if test = "labelCodes != null and labelCodes.size > 0">
|
||||
AND tl.label_code IN
|
||||
<foreach collection="labelCodes" item="item" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test = "map.radius != null and map.radius != ''">
|
||||
HAVING
|
||||
distance < ${map.radius}
|
||||
ORDER BY
|
||||
distance
|
||||
</if>
|
||||
<if test = "map.pageNum != null and map.pageSize != null">
|
||||
LIMIT ${map.pageNum}, ${map.pageSize}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectChannelNumByRegion" resultType="java.util.Map">
|
||||
SELECT COUNT(idt_camera_channel) AS channelNum,region_code,region_name FROM t_camera_channel01 GROUP BY region_code,region_name
|
||||
</select>
|
||||
</mapper>
|
|
@ -1,5 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.renren.modules.monitor.mapper.CameraOrgenizationMapper">
|
||||
<insert id="batchSaveOrgenization" parameterType="java.util.List">
|
||||
|
||||
INSERT INTO t_camera_organization02 (
|
||||
id,name,parent_id,sort,subCount,is_parent,path
|
||||
) VALUES
|
||||
<foreach collection="list" item="item" separator="," >
|
||||
(
|
||||
#{item.id},#{item.name},#{item.parentId},#{item.sort},#{item.subCount},case when #{item.isParent} = true then 1 else 0 end,#{item.name}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
||||
<insert id="batchSaveCameraChannel" parameterType="java.util.List">
|
||||
INSERT INTO t_camera_channel01
|
||||
(
|
||||
channel_code,channel_id,channel_name,gps_x,gps_y,status,
|
||||
parent_id,region_code,region_name,node_name
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator="," >
|
||||
(
|
||||
#{item.channelCode},#{item.channelId},#{item.channelName},#{item.gpsX},#{item.gpsY},#{item.status},
|
||||
#{item.parentId},#{item.regionCode},#{item.regionName},TRIM(TRAILING '->' FROM #{item.nodeName})
|
||||
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue