ParseVideoJson.java 3.1 KB
/**
 * 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 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,depart_id) values ('"+videoRootId+"','"+regionName+"','1151041342');");
			System.out.println("insert into t_video_diy_root(video_diy_id,video_diy_name,depart_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,depart_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,depart_id)"
						+ " values ('"+videoRootId+"','"+videoId+"','1151041342');");
				System.out.println("insert into t_video_diy_relate_diy_root(video_diy_id,video_id,depart_id)"
						+ " values ('"+videoDiyId+"','"+videoId+"','1151041342');");
				videoId++;
			}
			videoRootId++;
			videoDiyId++;
		}
		System.out.println("sql打印结束---------------------------");
	}

}