Merge branch 'master' into docker_package

This commit is contained in:
wangliwen 2022-07-18 09:47:44 +08:00
commit 8a782ee314
8 changed files with 204 additions and 72 deletions

View File

@ -11,6 +11,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -639,24 +640,22 @@ public class Controller {
list1 = Arrays.asList(labelCodes);
}
//查询当前地区及下级地区的id,组成list,2022-07-14,ytl
List<Map> orgenIds = monitorService.listChildOrgenIds(new ArrayList<Map>(), queryMap.get("parentId").toString());
List<Map> orgenIds = new ArrayList<>();
String path = "";
if(queryMap.get("parentId") != null && StringUtils.isNotBlank(queryMap.get("parentId").toString())){
//根据parentId获取地区表中的path
Map parentId = cameraOrgenMapper.selectOrgenizationById(queryMap.get("parentId").toString());
path = parentId.get("path").toString();
}
List<Map> list = cameraChannelMapper.selectByParentIdNew(queryMap, list1,orgenIds);
List<Map> list = cameraChannelMapper.selectByParentIdNew(queryMap, list1,path);
Result success = Result.success(list);
success.setCount(cameraChannelMapper.selectByParentIdCountNew(queryMap, list1,orgenIds));
success.setCount(cameraChannelMapper.selectByParentIdCountNew(queryMap, list1,path));
return success;
}
//测试获取某个地区 及旗下的所有地区id
@GetMapping("listChildOrgenIds")
public Result listChildOrgenIds(String id){
List<Map> list = new ArrayList<>();
List<Map> maps = monitorService.listChildOrgenIds(list, id);
return Result.success(maps);
}
/**
* 摄像头按照市区进行聚合查询
@ -680,11 +679,13 @@ public class Controller {
cameraOrgenMapper.batchSaveOrgenization(list);
});
maps.forEach(map->{
monitorService.setOrganizationPath(map,map.get("parentId").toString());
//修改path 信息
List<Map> maps2 = cameraOrgenMapper.testAll();
maps2.forEach(map->{
monitorService.setOrganizationPath(map,map.get("parent_id").toString());
});
//修改path
maps.forEach(m->{
maps2.forEach(m->{
cameraOrgenMapper.updateOrganizationPaht(m.get("path").toString(),m.get("id").toString());
});
}
@ -693,12 +694,13 @@ public class Controller {
}
/**
* 保存通道信息
* 保存通道信息多线程版
* @return
*/
@GetMapping("saveChannelInfo")
public Result saveChannelInfo() throws Exception{
return monitorService.saveChannelInfo();
@GetMapping("saveChannelInfoAsync")
public Result saveChannelInfoAsync() throws Exception{
monitorService.saveChannelInfoAsync();
return Result.success("成功收到指令,请耐心等待");
}
/******************************2022/07/13 ytl修改视频资源 end********************************************/

View File

@ -64,9 +64,9 @@ public interface CameraChannelMapper extends BaseDao<CameraChannel> {
Integer selectChannelCounts(@Param("path") String path);
List<Map> selectByParentIdNew(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes,@Param("orgenIds") List<Map> orgenIds);
List<Map> selectByParentIdNew(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes,@Param("path") String path);
Integer selectByParentIdCountNew(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes,@Param("orgenIds") List<Map> orgenIds);
Integer selectByParentIdCountNew(@Param("map") Map queryMap, @Param("labelCodes") List labelCodes,@Param("path") String path);
List<Map> selectChannelNumByRegion();
}

View File

@ -20,12 +20,12 @@ public interface CameraOrgenizationMapper extends BaseDao<CameraOrganization> {
@Select("select * from t_camera_organization02 where parent_id = #{parentId}")
List<Map> selectSubOrganizationMap(@Param("parentId") String parentId);
@Select("select name,parent_id,id from t_camera_organization02 where parent_id = #{parentId}")
List<Map> selectSubOrganizationMapByPid(@Param("parentId") String parentId);
@Select("select name,parent_id,id from t_camera_organization02 where path LIKE CONCAT(#{path},'%') ")
List<Map> selectSubOrganizationMapByPath(@Param("path") String path);
void batchSaveOrgenization(List<Map> list);
@Select("SELECT name,parent_id,id FROM t_camera_organization02 WHERE id = #{id}")
@Select("SELECT name,parent_id,id,path 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}")
@ -41,4 +41,28 @@ public interface CameraOrgenizationMapper extends BaseDao<CameraOrganization> {
void updateOrganizationCount(@Param("id") String id);
void batchSaveCameraChannel(List<Map> list);
@Select("select * from t_camera_organization02")
List<Map> testAll();
@Update("truncate table ${tableName}")
void truncate(@Param("tableName") String tableName) ;
@Select("select orgaid,id,name,path from t_camera_organization02 order by orgaid")
List<Map> selectAllSubOrganizationMap();
@Update("UPDATE t_camera_organization02 SET channelCount = #{channelCount} where orgaid = #{orgaId}")
void editChannelCount(@Param("channelCount") Integer channelCount,@Param("orgaId") Integer orgaId);
@Update(" UPDATE t_region a inner join \n" +
" (SELECT COUNT(idt_camera_channel) AS channel_count,region_code FROM t_camera_channel01 GROUP BY region_code) b\n" +
" ON a.region_code = b.region_code set a.channel_count = b.channel_count")
void updateRegionChannelCount();
@Select(" SELECT id FROM t_camera_organization02 WHERE orgaid >(SELECT a.orgaid FROM t_camera_organization02 a INNER JOIN \n" +
"\t(\n" +
"\t\tSELECT parent_id FROM t_camera_channel01 ORDER BY idt_camera_channel desc LIMIT 1\n" +
"\t) b ON a.id = b.parent_id \n" +
") ORDER BY orgaid ASC ")
List<Map> listOrgenization2();
}

View File

@ -15,6 +15,7 @@ import org.bytedeco.javacv.Java2DFrameConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.Base64Utils;
@ -1244,16 +1245,117 @@ public class MonitorService {
}
}
public List<Map> listChildOrgenIds(List<Map> list,String id){
Map orgenNow = cameraOrgenMapper.selectOrgenizationById(id);
list.add(orgenNow);
List<Map> childs = cameraOrgenMapper.selectSubOrganizationMapByPid(id);
if(childs.size() > 0){
childs.forEach(child->{
listChildOrgenIds(list,child.get("id").toString());
});
//2获取视频通道信息并保存,多线程版
@Async
public void saveChannelInfoAsync() throws Exception {
//1-清空t_camera_channel01
cameraOrgenMapper.truncate("t_camera_channel01");
//2-创建线程池
ExecutorService executorService = Executors.newFixedThreadPool(20);//20个线程足够
//3-查询全部地区
List<Map> maps = cameraOrgenMapper.testAll();
List<List<Map>> lists = Lists.partition(maps, 1000);
List<CompletableFuture> completableFutureLis = new ArrayList<>();
lists.forEach(l->{
completableFutureLis.add(
CompletableFuture.runAsync(()->{
l.forEach(m->{
boolean flag = true;
int tryCount = 0;//每个地区重试10次去获取该地区下视频通道信息
while(flag){
if(tryCount >= 9){
flag = false;
}
tryCount++;
//4-根据地区id去查询视频通道信息
List<Map> cameraChannels = new ArrayList<>();
try {
cameraChannels = getChannelInfo(m.get("id").toString());
}catch (Exception e){
log.info("根据地区id:{}查询视频通道失败,这是第{}次重试",m.get("id").toString(),tryCount);
continue;
}
//5-保存视频通道信息
batchSaveChannelInfos(cameraChannels,m.get("id").toString());
//6-更新地区表的count
cameraOrgenMapper.updateOrganizationCount(m.get("id").toString());
flag = false;
}
});
},executorService)
);
});
CompletableFuture.allOf(completableFutureLis.toArray(new CompletableFuture[completableFutureLis.size()])).join();
//6-更新完通道信息后查询地区下通道的数量并更新到地区表和市区表中
editChannelCount();
}
//单独保存视频通道信息
public void batchSaveChannelInfos(List<Map> list,String parentId){
List<Map> needSave = new ArrayList<>();
if(list.size() > 0){
for(Map j:list){
if(Integer.parseInt(j.get("nodeType").toString()) ==3 && Integer.parseInt(j.get("channelType").toString()) ==1){
if(j.get("sn") == null){
continue;
}
String channelSn = j.get("sn").toString();
String channelOrngin = channelSn.substring(0,6);
String deptName = cameraOrgenMapper.getNameByidPart(channelOrngin);
j.put("regionName",deptName);
j.put("regionCode",channelOrngin);
j.put("parentId",parentId);
j.put("nodeName","");
needSave.add(j);
}
}
}else{//更新count字段
cameraOrgenMapper.updateOrganizationCount(parentId);
}
return list;
//修改nodeName
needSave.forEach(map->setNodeName(map,map.get("parentId").toString()));
//保存并更新count字段
if(needSave.size() > 0){
List<List<Map>> partition = Lists.partition(needSave, 100);
partition.forEach(l->{
cameraOrgenMapper.batchSaveCameraChannel(l);
});
cameraOrgenMapper.updateOrganizationCount(parentId);
}
}
//更新完通道信息后查询地区下通道的数量并更新到地区表中和市区表中
public void editChannelCount() throws Exception{
//1-更新地区表中的每个地区下channelCount
List<Map> maps = cameraOrgenMapper.selectAllSubOrganizationMap();
if(maps.size() > 0){
for(int i=0;i< maps.size();i++){
String path = maps.get(i).get("path").toString();
Integer count = cameraChannelMapper.selectChannelCounts(path);
Integer orgaid = Integer.parseInt(maps.get(i).get("orgaid").toString());
cameraOrgenMapper.editChannelCount(count,orgaid);
};
}
//2-更新市区表t_region表中的channelCount
cameraOrgenMapper.updateRegionChannelCount();
}
public List<Map> listChildOrgenIds(String id){
Map orgenNow = cameraOrgenMapper.selectOrgenizationById(id);
List<Map> childs = new ArrayList<>();
if(!orgenNow.isEmpty()){
String path = orgenNow.get("path").toString();
childs = cameraOrgenMapper.selectSubOrganizationMapByPath(id);
}
return childs;
}
}

View File

@ -46,7 +46,7 @@ public class TsingtaoXHAVideoPreviewService extends AbstractVideoPreviewService
@Override
public String getHls(String key) {
List<String> result = new CopyOnWriteArrayList<>();
String url = String.format(tsingtao_xhaProperties.getCloudhls(), key);
String url = String.format(tsingtao_xhaProperties.getCloudhls(), key.replaceAll("\"", ""));
Request request = new Request.Builder().url(url).build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
@ -58,7 +58,7 @@ public class TsingtaoXHAVideoPreviewService extends AbstractVideoPreviewService
logger.error("西海岸预览地址获取失败:{}", url);
}
} catch (Exception exception) {
logger.error("西海岸预览地址获取失败:", url, exception);
logger.error("西海岸预览地址获取失败:{}", url, exception);
}
return result.stream().filter(index -> StringUtils.isNotEmpty(index)).findAny().orElse(null);
}

View File

@ -7,45 +7,50 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/share_platform?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=false
username: root
password: 123456
password: root
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://15.2.21.238:3310/share_platform?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&useSSL=false
# username: root
# password: Hisense2019
#Hisense2019
#上传的静态资源配置
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 10
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
#Oracle需要打开注释
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
stat-view-servlet:
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 10
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
#Oracle需要打开注释
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
stat-view-servlet:
enabled: true
url-pattern: /druid/*
#login-username: admin
#login-password: admin
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true
flyway:
enabled: true
url-pattern: /druid/*
#login-username: admin
#login-password: admin
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true
validate-on-migrate: false
# 允许乱序执行
out-of-order: true
#上传的静态资源配置
resource:
root_url: 15.2.21.238
path: /home/yth/files/
devModelFilePath: /home/yth/files/devModelFile
pic-host: 127.0.0.1
# 大数据部门相关配置
big_date:
name: 青岛市大数据发展管理局

View File

@ -141,10 +141,9 @@
JOIN t_label tl ON tl.label_code = tcml.label_code
</if>
WHERE 1 = 1
AND tcc.parent_id IN
<foreach collection="orgenIds" item="item" open="(" separator="," close=")">
#{item.id}
</foreach>
<if test = "map.parentId != null and map.parentId != '' and path != null and path != ''">
AND tcc.node_name LIKE CONCAT(#{path},'%')
</if>
AND tcc.check_status IN (${map.checkStatus})
AND tcc.gps_x != ''
@ -190,10 +189,10 @@
JOIN t_label tl ON tl.label_code = tcml.label_code
</if>
WHERE 1 = 1
AND tcc.parent_id IN
<foreach collection="orgenIds" item="item" open="(" separator="," close=")">
#{item.id}
</foreach>
<if test = "map.parentId != null and map.parentId != '' and path != null and path != ''">
AND tcc.node_name LIKE CONCAT(#{path},'%')
</if>
AND tcc.check_status IN (${map.checkStatus})

View File

@ -4,11 +4,11 @@
<insert id="batchSaveOrgenization" parameterType="java.util.List">
INSERT INTO t_camera_organization02 (
id,name,parent_id,sort,subCount,path
id,name,parent_id,sort,subCount,path,is_parent,is_root
) VALUES
<foreach collection="list" item="item" separator="," >
(
#{item.id},#{item.name},#{item.parentId},#{item.sort},#{item.subCount},#{item.name}
#{item.id},#{item.name},#{item.parentId},#{item.sort},#{item.subCount},#{item.name},#{item.isParent},#{item.root}
)
</foreach>
</insert>