ParseVideoJson.java
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Copyright (c) 2020 Use is subject to license terms.
*/
package com.skua.common.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.alibaba.fastjson.JSONObject;
import com.skua.core.util.ConvertUtils;
/**
* <pre>
* 积水点二期视频解析类
* </pre>
* @author Li Yuanyuan
* @version V0.1, 2020年6月9日 下午3:13:38
*/
public class ParseVideoJson {
public static void main(String[] args) throws Exception {
//parseXml();
//读取配置文件
File fileDir=new File("D:\\test");
File[] files = fileDir.listFiles();
for(File file : files) {
BufferedReader reader = null;
StringBuffer sbf = new StringBuffer();
try {
reader = new BufferedReader(new FileReader(file));
String tempStr;
while ((tempStr = reader.readLine()) != null) {
sbf.append(tempStr);
}
reader.close();
parseJson(sbf.toString(),file.getName());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}
public static void parseJson(String value,String fileName) {
Map reprot = JSONObject.parseObject(value, Map.class);
List<Map<String,Object>> list = (List)reprot.get("child");
int videoRootId=40;
int videoDiyId=50;
int videoId=540;
System.out.println("sql打印开始---------------------------");
for(Map<String,Object> map:list) {
//区域信息
String regionName = ConvertUtils.getString(map.get("name"));
//厂区摄像头
System.out.println("insert into t_video_root(video_root_id,video_root_name,factory_id) values ('"+videoRootId+"','"+regionName+"','1151041342');");
System.out.println("insert into t_video_diy_root(video_diy_id,video_diy_name,factory_id) values ('"+videoDiyId+"','"+regionName+"','1151041342');");
List<Object> cameraList = (List<Object>)map.get("cameras");
for(Object camera : cameraList) {
Map<String,Object> cameraMap = (Map<String,Object>)camera;
String cameraIndexCode = ConvertUtils.getString(cameraMap.get("indexCode"));
String cameraName = ConvertUtils.getString(cameraMap.get("name"));
System.out.println("insert into t_video(video_id,video_name,video_camerauuid,video_ip,video_dk,video_http,factory_id,video_streammode,video_transmode,video_gpumode)"
+ " values ('"+videoId+"','"+cameraName+"','"+cameraIndexCode+"','222.222.168.90','1004','0','1151041342','0','1','0');");
System.out.println("insert into t_video_relate_root(video_root_id,video_id,factory_id)"
+ " values ('"+videoRootId+"','"+videoId+"','1151041342');");
System.out.println("insert into t_video_diy_relate_diy_root(video_diy_id,video_id,factory_id)"
+ " values ('"+videoDiyId+"','"+videoId+"','1151041342');");
videoId++;
}
videoRootId++;
videoDiyId++;
}
System.out.println("sql打印结束---------------------------");
}
}