package cn.yw.archive.videoarchive.action;


import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.base.aspect.OperateType;
import cn.base.bean.BaseAction;
import cn.base.bean.BeanHelper;
import cn.base.conf.ModuleConfFactory;
import cn.base.excel.ExcelCol;
import cn.base.excel.ExcelImport;
import cn.base.excel.ExportEngine;
import cn.base.util.CommUtils;
import cn.base.util.Constants;
import cn.base.util.DateUtil;
import cn.base.util.FileCopyUtil;
import cn.base.util.LogConstants;
import cn.base.util.RHUtil;
import cn.base.util.StringUtil;
import cn.base.util.Struts2Utils;
import cn.bsystem.ptuserrole.model.PtyhBean;
import cn.yw.archive.videoarchive.service.YwarchivevideoinfoService;

@SuppressWarnings({"all"})
@Component("ywarchivevideoinfoAction")
public class YwarchivevideoinfoAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private static Logger iLog = Logger.getLogger(YwarchivevideoinfoAction.class);
	
	private File file;
	private String fileContentType;
	private String fileFileName;
	
	public void setFile(File file) {
		this.file = file;
	}
	public File getFile() {
		return file;
	}
	public String getFileContentType() {
		return fileContentType;
	}

	public String getFileFileName() {
		return fileFileName;
	}
	
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}


	@Autowired
	private YwarchivevideoinfoService service;
	
	/**
	 * 分页
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="listYwarchivevideoinfoByPage")
	public void listYwarchivevideoinfoByPage(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			int page = Integer.parseInt(Struts2Utils.getParameter("page"));
			int rows = Integer.parseInt(Struts2Utils.getParameter("rows"));
			int start = ( (page == 0 ?  1 : page ) - 1) * rows ;
			map.put("start",start );
			map.put("limit",rows );
			Struts2Utils.renderJson(this.service.listYwarchivevideoinfoByPage(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-listYwarchivevideoinfoByPage-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
	 * 查询总数
	 */	
	@OperateType(value = LogConstants.LOG_QUERY ,info ="count_Ywarchivevideoinfo")
	public void count_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.count_Ywarchivevideoinfo(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-count_Ywarchivevideoinfo-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
	 * 查询 Ywarchivevideoinfo
	 */
	
	@OperateType(value = LogConstants.LOG_GET ,info ="query_Ywarchivevideoinfo")
	public void query_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.query_Ywarchivevideoinfo(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-query_Ywarchivevideoinfo-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
	 * 查询 一条Ywarchivevideoinfo
	 */
	
	@OperateType(value = LogConstants.LOG_GET ,info ="get_Ywarchivevideoinfo")
	public void get_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.get_Ywarchivevideoinfo(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoActionquery_Ywarchivevideoinfo-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
	 * 删除
	 */
	@OperateType(value = LogConstants.LOG_DELETE ,info ="deleteYwarchivevideoinfo")
	public void delete_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(!CommUtils.isEmpty(map)){
				int result = service.delete_Ywarchivevideoinfo(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}else{
				 throw new Exception("请正确的选择删除记录!!!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-delete_Ywarchivevideoinfo-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	

	/**
	 * 插入
	 */
	@OperateType(value = LogConstants.LOG_ADD ,info ="insert_Ywarchivevideoinfo")
	public void insert_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhbh();
			String time = DateUtil.getDateTimeStr(new Date());
			map.put("createaccount", username);
			map.put("createtime", time);
			map.put("modifyaccount", username);
			map.put("modifytime", time);
			if(StringUtil.checkEmpty(map.get("archivevideoid"))){
				map.put("archivevideoid",StringUtil.getUUID());
			}
			if(!StringUtil.checkEmpty(map.get("checkparam"))){
				Map sMap = new HashMap();
				sMap.put("tableparam", map.get("checkparam"));
				List ls = service.query_Ywarchivevideoinfo(sMap);
				if(!StringUtil.checkEmpty(ls)||ls.size()>0){
					Struts2Utils.renderJson(Constants.SAME);
				}else{
					service.insert_Ywarchivevideoinfo(map);
					Struts2Utils.renderJson(Constants.SUCCESS);
				}
			}else{
				service.insert_Ywarchivevideoinfo(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}			
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-insert_Ywarchivevideoinfo()-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
	 * 修改
	 */
	@OperateType(value = LogConstants.LOG_UPDATE ,info ="update_Ywarchivevideoinfo")
	public void update_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(!StringUtil.checkEmpty(map.get("checkparam"))){
				Map sMap = new HashMap();
				sMap.put("tableparam", map.get("checkparam"));
				List ls = service.query_Ywarchivevideoinfo(sMap);
				if(!StringUtil.checkEmpty(ls)||ls.size()>0){
					Struts2Utils.renderJson(Constants.SAME);
				}else{
					int result = service.update_Ywarchivevideoinfo(map);
					Struts2Utils.renderJson(Constants.SUCCESS);
				}
			}else{
				int result = service.update_Ywarchivevideoinfo(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-update_Ywarchivevideoinfo-error: " +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
	 * 批量删除
	 */
	
	@OperateType(value = LogConstants.LOG_DELETE ,info ="batch_delete_Ywarchivevideoinfo")
	public void batch_delete_Ywarchivevideoinfo(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			String keywords = map.get("keyword").toString();
			if(RHUtil.isNotEmpty(keywords)) {
				String[] ids = keywords.split(",");
				map.clear();
				map.put("ids", ids);
			}
			int result = service.batch_delete_Ywarchivevideoinfo(map);
			Struts2Utils.renderJson(Constants.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-batch_delete_Ywarchivevideoinfo-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	// 代码转换   根据columnname查询  代码及中文
	public void queryByColumnname(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.queryByColumnname(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoActionquery_queryByColumnname-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 导出Excel
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="exp_Ywarchivevideoinfo")
	public void exp_Ywarchivevideoinfo(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			map.put("start",0 );
			map.put("limit",5000);
			List<Map> sList = service.query_Ywarchivevideoinfo(map);
			if(RHUtil.isNotEmpty(sList)) {


			}
			
			String[] zdbm = {"channelname", "videofactorymc","cameratypemc","videoresolutionmc","videoinstalladdress","videopointname","installpositiontypemc","builddepartmentmc"};                          
			String[] zdmc = {"设备名称", "设备厂商","摄像机类型","摄像机分辨率","安装地址","点位俗称","室外、内","相机建设部门"};
			int excelNum = zdbm.length;
			ExcelCol[] cells = new ExcelCol[excelNum];
			for(int i=0;i<excelNum;i++){
				cells[i] = new ExcelCol();
				cells[i].setColKey(zdbm[i]);
				cells[i].setColName(zdmc[i]);
			}			
			new ExportEngine().exportData("一机一档", cells, sList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwarchivevideoinfoAction-exoprtExcel-error:" +e);
			
		}
	}
	
	/**
	 * 导入Excel
	 * @throws Exception 
	 */
	/*@OperateType(value = LogConstants.LOG_IMPORT ,info ="imp_Ywarchivevideoinfo")
	public void imp_Ywarchivevideoinfo() throws Exception {
		
		String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhbh();
		String time = DateUtil.getDateTimeStr(new Date());

		// 相机建设部门     必填项
		Map<String,String> xjjsbmMap = new HashMap<String,String>();
		xjjsbmMap.put("公安自建", "0");
		xjjsbmMap.put("社会单位出资建设公安租赁", "1");
		xjjsbmMap.put("街镇出资建设公安使用", "2");
		xjjsbmMap.put("复接公安其他图像", "3");
		xjjsbmMap.put("社会单位复接", "4");
		xjjsbmMap.put("社会单位联网", "5");
		xjjsbmMap.put("移动监控", "6");
		xjjsbmMap.put("指挥室会议室监控室内部", "7");
		xjjsbmMap.put("试验用", "8");
		xjjsbmMap.put("其他", "9");
		
		// 保密属性	非必填
		Map<String,String> bmsxMap = new HashMap<String,String>();
		bmsxMap.put("不涉密", "0");
		bmsxMap.put("涉密", "1");
		
		// 摄像机功能类型     非必填
		Map<String,String> xjglMap = new HashMap<String,String>();
		xjglMap.put("车辆卡口", "1");
		xjglMap.put("人员卡口", "2");
		xjglMap.put("微卡口", "3");
		xjglMap.put("特征摄像机", "4");
		xjglMap.put("普通监控", "5");
		
		// 摄像机所属警种           必填
		Map<String,String> xjjzMap = new HashMap<String,String>();
		xjjzMap.put("警务督察", "1");
		xjjzMap.put("治安监控", "2");
		xjjzMap.put("交通管理", "3");
		xjjzMap.put("信访", "4");
		xjjzMap.put("出入境", "5");
		xjjzMap.put("监管", "6");
		xjjzMap.put("检查站", "7");
		xjjzMap.put("其他", "8");
		
		// 监控点类型		必填
		Map<String,String> jklxMap = new HashMap<String,String>();
		jklxMap.put("一类视频", "1");
		jklxMap.put("二类视频", "2");
		jklxMap.put("三类视频", "3");
		jklxMap.put("公安内部", "4");

		// 使用属性 		必填
		Map<String,String> syMap = new HashMap<String,String>();
		syMap.put("公安机关", "1");
		syMap.put("环保部门", "2");
		syMap.put("文博部门", "3");
		syMap.put("医疗部门", "4");
		syMap.put("旅游管理", "5");
		syMap.put("新闻广电", "6");
		syMap.put("食品医药监督管理部门", "7");
		syMap.put("教育管理部门", "8");
		syMap.put("检察院", "9");
		syMap.put("法院", "10");
		syMap.put("金融部门", "11");
		syMap.put("交通部门", "12");
		syMap.put("住房和城乡建设部门", "13");
		syMap.put("水利部门", "14");
		syMap.put("林业部门", "15");
		syMap.put("安全生产监督部门", "16");
		syMap.put("市政市容委", "17");
		syMap.put("国土局", "18");
		
		// 摄像机位置类型          必填
		Map<String,String> xjwzMap = new HashMap<String,String>();
		xjwzMap.put("省际检查站", "1");
		xjwzMap.put("党政机关", "2");
		xjwzMap.put("车站码头", "3");
		xjwzMap.put("中心广场", "4");
		xjwzMap.put("体育场馆", "5");
		xjwzMap.put("商业中心", "6");
		xjwzMap.put("宗教场所", "7");
		xjwzMap.put("校园周边", "8");
		xjwzMap.put("治安复杂区域", "9");
		xjwzMap.put("交通干线", "10");
		xjwzMap.put("市际公安检查站", "96");
		xjwzMap.put("涉外场所", "97");
		xjwzMap.put("边境沿线", "98");
		xjwzMap.put("旅游景区", "99");

		//摄像机安装位置 室内/外属性         非必填
		Map<String,String> nwMap = new HashMap<String,String>();
		nwMap.put("室内", "1");
		nwMap.put("室外", "2");
		
		//摄像机监视方位			非必填
		Map<String,String> fwMap = new HashMap<String,String>();
		fwMap.put("东", "1");
		fwMap.put("西", "2");
		fwMap.put("南", "3");
		fwMap.put("北", "4");
		fwMap.put("东南", "5");
		fwMap.put("东北", "6");
		fwMap.put("西南", "7");
		fwMap.put("西北", "8");
		fwMap.put("全向", "9");
		
		//联网属性			必填
		Map<String,String> lwMap = new HashMap<String,String>();
		lwMap.put("已联网", "0");
		lwMap.put("未联网", "1");
		
		// 设备厂商   		必填
		Map<String,String> sbcsMap = new HashMap<String,String>();
		sbcsMap.put("海康威视", "1");
		sbcsMap.put("大华", "2");
		sbcsMap.put("天地伟业", "3");
		sbcsMap.put("科达", "4");
		sbcsMap.put("安讯士", "5");
		sbcsMap.put("博世", "6");
		sbcsMap.put("亚安", "7");
		sbcsMap.put("英飞拓", "8");
		sbcsMap.put("宇视", "9");
		sbcsMap.put("海信", "10");
		sbcsMap.put("中星电子", "11");
		sbcsMap.put("明景", "12");
		sbcsMap.put("联想", "13");
		sbcsMap.put("中兴", "14");
		sbcsMap.put("其他", "99");
		
		//摄像机类型 		非必填
		Map<String,String> xjlxMap = new HashMap<String,String>();
		xjlxMap.put("可控球机", "1");
		xjlxMap.put("固定球机", "2");
		xjlxMap.put("固定枪机", "3");
		xjlxMap.put("云台枪机", "4");
		xjlxMap.put("卡口枪机", "5");
		xjlxMap.put("未知", "99");
		
		//摄像机补光属性		非必填
		Map<String,String> bgMap = new HashMap<String,String>();
		bgMap.put("无补光", "1");
		bgMap.put("红外补光", "2");
		bgMap.put("白光补光", "3");
		
		// 摄像机分辨率		非必填
		Map<String,String> xjfblMap = new HashMap<String,String>();
		xjfblMap.put("QCIF", "1");
		xjfblMap.put("CIF", "2");
		xjfblMap.put("4CIF", "3");
		xjfblMap.put("DI", "4");
		xjfblMap.put("720P", "5");
		xjfblMap.put("1080P", "6");
		xjfblMap.put("其他", "7");
		
		// 编码格式
		Map<String,String> bmgsMap = new HashMap<String,String>();
		bmgsMap.put("MPEG-4", "1");
		bmgsMap.put("H.264", "2");
		bmgsMap.put("SVAC可扩展", "3");
		bmgsMap.put("H.265", "4");
		
		// 视频分辨率
		Map<String,String> spfblMap = new HashMap<String,String>();
		spfblMap.put("标清", "1");
		spfblMap.put("高清", "2");
		spfblMap.put("超清", "3");
		
		// 视频信号类型
		Map<String,String> spxhlxMap = new HashMap<String,String>();
		spxhlxMap.put("数字", "1");
		spxhlxMap.put("模拟", "2");
		
		// 设备状态
		Map<String,String> sbztMap = new HashMap<String,String>();
		sbztMap.put("在用", "1");
		sbztMap.put("维修", "2");
		sbztMap.put("拆除", "3");
		
		// 是否 共享 / 接入三级平台
		Map<String,String> ynMap = new HashMap<String,String>();
		ynMap.put("是", "1");
		ynMap.put("否", "2");
		
		
		String rs = "导入格式有误!";
		int rowNum = 0;
		int dataCount = 0;
		int successNum = 0;
		int repeatNum = 0;
		int failNum = 0;
		
		int rkNum = 0;
		int reprkNum = 0;
		
		Map params = Struts2Utils.getRequestParameterMap();
		String sbbh = (String) params.get("sbbh");				// 是否覆盖
		
		InputStream inputStream = null;
		String uuid = StringUtil.getUUID();
		try {
	        String rootpath = ModuleConfFactory.getInstance().getScatter().getDownPath(); // private.xml中读取文件存放路径
	        String path = rootpath+uuid+"\\";
	        File tempPathFile = new File(path);
			if (!tempPathFile.exists()) {
				tempPathFile.mkdirs();
			}
			int isSuccess = 0;
			try{
				inputStream = new FileInputStream(file);
				isSuccess  = FileCopyUtil.copy(inputStream, new BufferedOutputStream(new FileOutputStream(path+fileFileName)));
			}catch(Exception e){
			}finally{
				if(inputStream!=null){
					try {
						inputStream.close();
					} catch (IOException ex) {
					}
				}
			}
			
			
			List<Map> list = new ArrayList();		
			List xhList = new ArrayList();					// 检查xh是否重复
			List failList = new ArrayList();				// 存放有问题的数据信息
			Map<String,Map> repeatMap = new HashMap();		// 存放最后一条重复数据
			List<Map> repeatList = new ArrayList();			// 存放所有重复数据
			List repeatMsgList = new ArrayList();			// 存放重复数据的返回信息
			String failMsg = "";
			String repeatMsg = "";
			String nullMsg = "数据不能为空";
			String transMsg = "代码转换错误";
			
	        String[] headArr = {"第0列","序号","设备编码","设备名称","设备厂商","行政区划","监控点类型","设备型号","点位俗称","IPV4地址",
	        					"IPV6地址","MAC地址","摄像机类型","摄像机功能类型","补光属性","摄像机编码格式","对应存储设备IP",
	        					"对应设备通道","安装地址","经度","纬度","摄像机位置类型","监视方向","摄像机场景预设URL","联网属性",
	        					"所属辖区公安机关","安装时间","管理单位","管理单位联系方式","录像保存天数","设备状态","所属部门/行业",
	        					"视频分辨率","视频型号类型","是否对外共享","是否接入三级平台","键盘编号","建设应用类别","安装高度",
	        					"可视距离","摄像机用户名","摄像机密码","硬盘录像机用户名","硬盘录像机密码"};
			int count = 0;
			ExcelImport readExcel = new ExcelImport();
			readExcel.openFile(path+fileFileName);
			readExcel.setSheetNum(0);
			int cellNum = 0;
			count = readExcel.getRowCount();
			 for (int i = 2; i < count; i++) { 
	            String[] rows = readExcel.readExcelLine(i,0);
	            cellNum = rows.length;
	            for(int j=0; j < cellNum; j++) {
	            	String str = readExcel.readStringExcelCell(i,j);		// 读取每个单元格的内容	
	            	System.out.print("第"+i+"行，第"+j+"列："+str + "  ");
	            }
	            System.out.print("\n");
				 Map map = new HashMap();				// 存放 excel 单元格中数据
				 boolean repeatflag = false;		//是否重复数据
				 boolean flag = true;				//数据是否为空   或   数据是否正确
				 
				 int j = 0;                    // 从第0列开始读
				 String xh = readExcel.readStringExcelCell(i,j++);				
				 
				 String outsidecode = readExcel.readStringExcelCell(i, j++);		// 设备编码				 
				 if(RHUtil.isEmpty(outsidecode)) {
					 flag = false;					 
				//	 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1, colStr, nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 if(xhList.contains(outsidecode)) {
						 repeatflag = true;
						 repeatNum++;
				//		 Map repMsg = getErrorMsg(i+1, j, "数据重复(设备编码重复)", outsidecode, xh);
						 repeatMsg = "序号："+xh+",第"+(i+1)+"行,第"+j+"列("+headArr[j]+"),设备编码："+outsidecode+", 重复";
						 repeatMsgList.add(repeatMsg);
					 }else {
						 xhList.add(xh);
					 }
				 }
				 map.put("outsidecode", outsidecode);
				 
				 String channelname = readExcel.readStringExcelCell(i, j++);		//设备名称
				 if(RHUtil.isEmpty(channelname)) {
					 flag = false;
		//			 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("channelname", channelname);
				 
				 String videofactoryMc = readExcel.readStringExcelCell(i, j++);		//设备厂商         需转化为代码
				 if(RHUtil.isEmpty(videofactoryMc)) {
					 flag = false;
		//			 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String videofactory = sbcsMap.get(videofactoryMc);
					 if(RHUtil.isEmpty(videofactory)) {
						 flag = false;
			//			 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("videofactory", videofactory);
					 }
				 }
				 
				 
				 String areacode = readExcel.readStringExcelCell(i, j++);				// 行政区划
				 if(RHUtil.isEmpty(areacode)) {
					 flag = false;
				//	 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("areacode", areacode);
				 
				 String videopointtypeMc = readExcel.readStringExcelCell(i, j++);		// 监控点类型
				 if(RHUtil.isEmpty(videopointtypeMc)) {
					 flag = false;
				//	 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String videopointtype = jklxMap.get(videopointtypeMc);
					 if(RHUtil.isEmpty(videopointtype)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else{
						 map.put("videopointtype", videopointtype);
					 }
				 }
				 
				 
				 String videomodel = readExcel.readStringExcelCell(i, j++);				// 设备型号
				 map.put("videomodel", videomodel);
				 
				 String videopointname = readExcel.readStringExcelCell(i, j++);			// 点位俗称
				 map.put("videopointname", videopointname);
				 
				 String videoip = readExcel.readStringExcelCell(i, j++);				// ipv4地址
				 map.put("videoip", videoip);
				 
				 String videoipv6 = readExcel.readStringExcelCell(i, j++);				// ipv6地址
				 map.put("videoipv6", videoipv6);
				 
				 String videomacaddress = readExcel.readStringExcelCell(i, j++);				// MAC地址
				 map.put("videomacaddress", videomacaddress);
				 
				 String cameratypeMc = readExcel.readStringExcelCell(i, j++);				// 摄像机类型     非必填
				 if(RHUtil.isEmpty(cameratypeMc)) {
				//	 map.put("cameratype", cameratypeMc);
				 }else {
					 String cameratype = xjlxMap.get(cameratypeMc);
					 if(RHUtil.isEmpty(cameratype)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("cameratype", cameratype);
					 }
				 }
				 
				 
				 String videofunctiontypeMc = readExcel.readStringExcelCell(i, j++);		// 摄像机功能类型     非必填
				 if(RHUtil.isEmpty(videofunctiontypeMc)) {
				//	 map.put("videofunctiontype", videofunctiontypeMc);
				 }else {
					 String videofunctiontype = xjglMap.get(videofunctiontypeMc);
					 if(RHUtil.isEmpty(videofunctiontype)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("videofunctiontype", videofunctiontype);
					 }
				 }
				 
				 
				 String cameralightpropertyMc = readExcel.readStringExcelCell(i, j++);				// 补光属性    非必填
				 if(RHUtil.isNotEmpty(cameralightpropertyMc)) {
				//	 map.put("cameralightproperty", cameralightpropertyMc);
				 }else {
					 String cameralightproperty = bgMap.get(cameralightpropertyMc);
					 if(RHUtil.isEmpty(cameralightproperty)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("cameralightproperty", cameralightproperty);
					 } 
				 }
				 
				 
				 String videocodeformatMc = readExcel.readStringExcelCell(i, j++);				// 相机编码格式      非必填
				 if(RHUtil.isEmpty(videocodeformatMc)) {
				//	 map.put("videocodeformat", videocodeformatMc);
				 }else {
					 String videocodeformat = bmgsMap.get(videocodeformatMc);
					 if(RHUtil.isEmpty(videocodeformat)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else{
						 map.put("videocodeformat", videocodeformat);
					 } 
				 }
				 
				 
				 String storageip = readExcel.readStringExcelCell(i, j++);				// 对应存储设备ip
				 map.put("storageip", storageip);
				 
				 String storagechannel = readExcel.readStringExcelCell(i, j++);				// 对应存储设备通道
				 map.put("storagechannel", storagechannel);

				 String videoinstalladdress = readExcel.readStringExcelCell(i, j++);				// 安装地址
				 if(RHUtil.isEmpty(videoinstalladdress)) {
					 flag = false;
		//			 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("videoinstalladdress", videoinstalladdress);
				 
				 String longitude = readExcel.readStringExcelCell(i, j++);				// 经度
				 if(RHUtil.isEmpty(longitude)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("longitude", longitude);
				 
				 String dimension = readExcel.readStringExcelCell(i, j++);				// 纬度
				 if(RHUtil.isEmpty(dimension)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("dimension", dimension);
				 
				 String camerapositiontypeMc = readExcel.readStringExcelCell(i, j++);				// 摄像机位置类型
				 if(RHUtil.isEmpty(camerapositiontypeMc)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String camerapositiontype = xjwzMap.get(camerapositiontypeMc);
					 if(RHUtil.isEmpty(camerapositiontype)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("camerapositiontype", camerapositiontype);
					 } 
				 }
				 
				 
				 String monitorposition = readExcel.readStringExcelCell(i, j++);				// 监视方向(角度)
				 map.put("monitorposition", monitorposition);
				 
				 String monitorscenepicurl = readExcel.readStringExcelCell(i, j++);				// 摄像机场景预设照片URL
				 map.put("monitorscenepicurl", monitorscenepicurl);
				 
				 String networkpropertyMc = readExcel.readStringExcelCell(i, j++);				// 联网属性
				 if(RHUtil.isEmpty(networkpropertyMc)) {
					 flag = false;
		//			 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String networkproperty = lwMap.get(networkpropertyMc);
					 if(RHUtil.isEmpty(networkproperty)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("networkproperty", networkproperty);
					 }
				 }
				 
				
				 String areapolicecode = readExcel.readStringExcelCell(i, j++);				// 所属辖区公安机关
				 if(RHUtil.isEmpty(areapolicecode)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("areapolicecode", areapolicecode);
				 
				 String monitorinstalltime = readExcel.readStringExcelCell(i, j++);				// 安装时间
				 map.put("monitorinstalltime", monitorinstalltime);
				 
				 String manageunitname = readExcel.readStringExcelCell(i, j++);				// 管理单位
				 if(RHUtil.isEmpty(manageunitname)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("manageunitname", manageunitname);
				 
				 String manageunitphone = readExcel.readStringExcelCell(i, j++);				// 管理单位联系方式
				 if(RHUtil.isEmpty(manageunitphone)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空"; 
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }
				 map.put("manageunitphone", manageunitphone);
				 
				 String recordkeepdays = readExcel.readStringExcelCell(i, j++);				// 录像保存天数
				 map.put("recordkeepdays", recordkeepdays);
				 
				 String videostateMc = readExcel.readStringExcelCell(i, j++);				// 设备状态
				 if(RHUtil.isEmpty(videostateMc)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 map.put("videostate", videostateMc);
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String videostate = sbztMap.get(videostateMc);
					 if(RHUtil.isEmpty(videostate)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("videostate", videostate);
					 } 
				 }
				 
				 
				 String useattributeMc = readExcel.readStringExcelCell(i, j++);				// 所属部门/行业     使用属性
				 if(RHUtil.isEmpty(useattributeMc)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String useattribute = syMap.get(useattributeMc);
					 if(RHUtil.isEmpty(useattribute)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1,colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("useattribute", useattribute);
					 } 
				 }
				 
				
				 String videoresolutionMc = readExcel.readStringExcelCell(i, j++);				// 视频分辨率    非必填
				 if(RHUtil.isEmpty(videoresolutionMc)) {
				//	 map.put("videoresolution", videoresolutionMc);
				 }else {
					 String videoresolution = spfblMap.get(videoresolutionMc);
					 if(RHUtil.isEmpty(videoresolution)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("videoresolution", videoresolution);
					 }
				 }
				 
				 
				 String videosignaltypeMc = readExcel.readStringExcelCell(i, j++);				// 视频信号类型     非必填
				 if(RHUtil.isEmpty(videosignaltypeMc)) {
				//	 map.put("videosignaltype", videosignaltypeMc);
				 }else {
					 String videosignaltype = spxhlxMap.get(videosignaltypeMc);
					 if(RHUtil.isEmpty(videosignaltype)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("videosignaltype", videosignaltype);
					 } 
				 }
				 
				 
				 String isshareMc = readExcel.readStringExcelCell(i, j++);				// 是否对外共享     非必填
				 if(RHUtil.isEmpty(isshareMc)) {
				//	 String isshare = ynMap.get(isshareMc);
				 }else {
					 String isshare = ynMap.get(isshareMc);
					 if(RHUtil.isEmpty(isshare)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("isshare", isshare);
					 } 
				 }
				 
				 
				 String isjointhreesystemMc = readExcel.readStringExcelCell(i, j++);				// 是否接入三级平台     非必填
				 if(RHUtil.isEmpty(isjointhreesystemMc)) {
				//	 map.put("isjointhreesystem", isjointhreesystemMc);
				 }else {
					 String isjointhreesystem = ynMap.get(isjointhreesystemMc);
					 if(RHUtil.isEmpty(isjointhreesystem)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("isjointhreesystem", isjointhreesystem);
					 } 
				 }
				 
				 
				 String keyboardnum = readExcel.readStringExcelCell(i, j++);				//  键盘编号
				 map.put("keyboardnum", keyboardnum);
				 
				 String builddepartmentMc = readExcel.readStringExcelCell(i, j++);				//  建设应用类别
				 if(RHUtil.isEmpty(builddepartmentMc)) {
					 flag = false;
			//		 failMsg = "第"+(i+1)+"行,第"+j+"列,数据不能为空";
					 String colStr = "第"+j+"列,("+headArr[j]+")";
					 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
					 failList.add(errMap);
				 }else {
					 String builddepartment = xjjsbmMap.get(builddepartmentMc);
					 if(RHUtil.isEmpty(builddepartment)) {
						 flag = false;
//						 failMsg = "第"+(i+1)+"行,第"+j+"列,代码转换错误";
						 String colStr = "第"+j+"列,("+headArr[j]+")";
						 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
						 failList.add(errMap);
					 }else {
						 map.put("builddepartment", builddepartment);
					 }
				 }
				 
				 
				 String monitorininstallhight = readExcel.readStringExcelCell(i, j++);				//  安装高度
				 map.put("monitorininstallhight", monitorininstallhight);
				 
				 String monitorlookrange = readExcel.readStringExcelCell(i, j++);				//  可视距离
				 map.put("monitorlookrange", monitorlookrange);
				 
				 String videousername = readExcel.readStringExcelCell(i, j++);				//  摄像机用户名
				 map.put("videousername", videousername);
				 
				 String videopassword = readExcel.readStringExcelCell(i, j++);				//  摄像机  密码
				 map.put("videopassword", videopassword);
				 
				 String dvrusername = readExcel.readStringExcelCell(i, j++);				//  硬盘录像机用户名
				 map.put("dvrusername", dvrusername);
				 
				 String dvrpassword = readExcel.readStringExcelCell(i, j++);				//  硬盘录像机密码
				 map.put("dvrpassword", dvrpassword);
				 
				 
				 String archivevideoid = StringUtil.getUUID();
				 map.put("archivevideoid",archivevideoid);
				 map.put("createaccount", username);
				 map.put("createtime", time);
				 map.put("modifyaccount", username);
				 map.put("modifytime", time);
		//		 判断数据是否重复  即 设备编码 是否重复
				 if(repeatflag && flag) {
					 repeatMap.put(outsidecode, map);			// excel中的重复 设备编码数据	
					 repeatList.add(map);
				 }else {	
					 if(flag) {
						 list.add(map);				// 经数据校验后的正确数据且无重复
					 }else {
						 failNum++;
					 }
				 }	
				 
	        }

			File file = new File(path+fileFileName);
			if(file.exists()){
				file.delete();
				File dir = new File(rootpath+uuid);
				dir.delete();
			}
						
			// 数据入库
			if("1".equals(sbbh)) {				// 覆盖  设备编码相同的数据  入库
				for(Map rkMap : list) {
					String outsidecode = (String) rkMap.get("outsidecode");
					Map repMap = repeatMap.get(outsidecode);
					if(RHUtil.isEmpty(repMap)) {    // 是否有重复
						
					}else {
						list.remove(rkMap);
						list.add(repMap);
					}
				}
				// 批量插入
				if(list.size() > 0) {
					for(Map insertMap : list) {
						service.insert_Ywarchivevideoinfo(insertMap);
					}
					service.batch_insert_Ywarchivevideoinfo(list);
				}
				rkNum = list.size();               // 入库数据
			}else {
				// 批量插入
				if(list !=null && list.size() > 0) {
					for(Map insertMap : list) {
						service.insert_Ywarchivevideoinfo(insertMap);
					}
					service.batch_insert_Ywarchivevideoinfo(list);
					rkNum = list.size(); 
				}
				if(RHUtil.isNotEmpty(repeatList)) {
					// 批量插入 设备编号重复的数据
					if(repeatList.size() > 0) {
						for(Map insertMap : repeatList) {
							service.insert_Ywarchivevideoinfo(insertMap);
						}
						service.batch_insert_Ywarchivevideoinfo(repeatList);
					}	
					rkNum = rkNum + repeatList.size();
				}
				
			}
			
			iLog.info("总行数count--->" + count);
			rs = " 导入数据成功！总共"+ (count-2) +"条数据,重复"+repeatNum+"条数据！失败"+failNum+"条数据!";
//			System.out.println("总行数count--->" + count);
//			System.out.println(rs);
			// 入库数据  rkNum
			// 重复数据入库的  reprkNum
			// 问题数据   failNum
			reprkNum = repeatList.size();
			Map resMap = new HashMap();       // 返回前端展示数据
			resMap.put("repeatData", repeatMsgList);		// 重复的
			resMap.put("failData", failList);				// 失败信息
			resMap.put("sucNum", rkNum);					// 入库数据量
			resMap.put("reprkNum", reprkNum);				// 覆盖的数据量
			resMap.put("failNum", failNum);					// 失败的数据量
			Struts2Utils.renderJson(resMap);
		} catch (Exception e) {			
			iLog.error("YwarchivevideoinfoAction-imp_Ywarchivevideoinfo-error:" +e);
			e.printStackTrace();
			Struts2Utils.renderJson(null);
		}		
	}
	*/
	
	@OperateType(value = LogConstants.LOG_IMPORT ,info ="imp_Ywarchivevideoinfo")
	public void imp_Ywarchivevideoinfo() throws Exception {
		
		String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
		String time = DateUtil.getDateTimeStr(new Date());

		String rs = "导入格式有误!";
		int rowNum = 0;
		int dataCount = 0;
		int successNum = 0;
		int repeatNum = 0;
		int failNum = 0;
		
		int rkNum = 0;
		int reprkNum = 0;
		
		Map params = Struts2Utils.getRequestParameterMap();
		String sbbh = (String) params.get("sbbh");				// 是否覆盖
		
		InputStream inputStream = null;
		String uuid = StringUtil.getUUID();
		try {
	        String rootpath = ModuleConfFactory.getInstance().getScatter().getDownPath(); // private.xml中读取文件存放路径
	        String path = rootpath+uuid+"\\";
	        File tempPathFile = new File(path);
			if (!tempPathFile.exists()) {
				tempPathFile.mkdirs();
			}
			int isSuccess = 0;
			try{
				inputStream = new FileInputStream(file);
				isSuccess  = FileCopyUtil.copy(inputStream, new BufferedOutputStream(new FileOutputStream(path+fileFileName)));
			}catch(Exception e){
			}finally{
				if(inputStream!=null){
					try {
						inputStream.close();
					} catch (IOException ex) {
					}
				}
			}
			
			
			List<Map> list = new ArrayList();		
			List xhList = new ArrayList();					// 检查xh是否重复
			List failList = new ArrayList();				// 存放有问题的数据信息
			Map<String,Map> repeatMap = new HashMap();		// 存放最后一条重复数据
			List<Map> repeatList = new ArrayList();			// 存放所有重复数据
			List repeatMsgList = new ArrayList();			// 存放重复数据的返回信息
			
			List<String> outsidecodeList = service.queryOutsidecode(null);
			List<Map> editList = new ArrayList();          // 存放与数据库中 外部编码重复的数据
			
			String failMsg = "";
			String repeatMsg = "";
			String nullMsg = "数据不能为空";
			String transMsg = "代码转换错误";
			
	       
			int count = 0;
			ExcelImport readExcel = new ExcelImport();
			readExcel.openFile(path+fileFileName);
			readExcel.setSheetNum(0);
			int cellNum = 0;
			count = readExcel.getRowCount();
			
			if(count > 2) {
				// 查询 excel 相关信息
				List<Map> colList = service.getExeclColname(null);
				Map<String,String> colnum_keyMap = new HashMap();
				Map<String,String> colnum_headMap = new HashMap();
				Map<String,String> colnum_checkMap = new HashMap();
				if(RHUtil.isNotEmpty(colList)) {
					for(Map map : colList) {
						String columnnum = (String) map.get("columnnum");
						String columnname = (String) map.get("columnname");
						String checktype = (String) map.get("checktype");
						String remarks = (String) map.get("remarks");
						colnum_keyMap.put(columnnum, columnname);
						colnum_headMap.put(columnnum, remarks);
						colnum_checkMap.put(columnnum, checktype);
					}
				}else {
					// 说明没有在ywarchivevideoimportcheck表中配置对应的excel信息
					
				}
				
				// 要转换为代码的
				List<Map> transList = service.getExeclCodeName(null);
				// 相机建设部门     必填项
				Map<String,String> xjjsbmMap = new HashMap<String,String>();								
				// 保密属性	非必填
				Map<String,String> bmsxMap = new HashMap<String,String>();				
				// 摄像机功能类型     非必填
				Map<String,String> xjglMap = new HashMap<String,String>();														
				// 监控点类型		必填
				Map<String,String> jklxMap = new HashMap<String,String>();				
				// 使用属性 		必填
				Map<String,String> syMap = new HashMap<String,String>();								
				// 摄像机位置类型          必填
				Map<String,String> xjwzMap = new HashMap<String,String>();				
				//摄像机安装位置 室内/外属性         非必填
				Map<String,String> nwMap = new HashMap<String,String>();				
				//摄像机监视方位			非必填
				Map<String,String> fwMap = new HashMap<String,String>();								
				//联网属性			必填
				Map<String,String> lwMap = new HashMap<String,String>();								
				// 设备厂商   		必填
				Map<String,String> sbcsMap = new HashMap<String,String>();								
				//摄像机类型 		非必填
				Map<String,String> xjlxMap = new HashMap<String,String>();								
				//摄像机补光属性		非必填
				Map<String,String> bgMap = new HashMap<String,String>();								
				// 摄像机分辨率		非必填
				Map<String,String> xjfblMap = new HashMap<String,String>();								
				// 编码格式
				Map<String,String> bmgsMap = new HashMap<String,String>();				
				// 视频分辨率
				Map<String,String> spfblMap = new HashMap<String,String>();				
				// 视频信号类型
				Map<String,String> spxhlxMap = new HashMap<String,String>();								
				// 设备状态
				Map<String,String> sbztMap = new HashMap<String,String>();								
				// 是否 共享 
				Map<String,String> gxMap = new HashMap<String,String>();
				// 接入三级平台
				Map<String,String> sjptMap = new HashMap<String,String>();
				
				if(RHUtil.isNotEmpty(transList)) {
					for(Map transMap : transList) {
						String columnname = (String) transMap.get("columnname");
						String code = (String) transMap.get("code");
						String codename = (String) transMap.get("codename");
						if("cameratype".equals(columnname)) {				// 摄像机类型
							xjlxMap.put(codename, code);
						}else if("videofunctiontype".equals(columnname)) {	// 摄像机功能类型
							xjglMap.put(codename, code);
						}else if("cameralightproperty".equals(columnname)) {      // 补光属性
							bgMap.put(codename, code);
						}else if("videocodeformat".equals(columnname)) {   // 摄像机编码格式
							bmgsMap.put(codename, code);
						}else if("camerapositiontype".equals(columnname)) {  // 摄像机位置类型
							xjwzMap.put(codename, code);
						}else if("monitorposition".equals(columnname)) {		//摄像机监视方位	
							fwMap.put(codename, code);
						}else if("networkproperty".equals(columnname)) {  // 联网属性
							lwMap.put(codename, code);
						}else if("videostate".equals(columnname)) {  // 设备状态
							sbztMap.put(codename, code);
						}else if("videofactory".equals(columnname)) {  // 设备厂商
							sbcsMap.put(codename, code);
						}else if("useattribute".equals(columnname)) {  // 所属部门/行业
							syMap.put(codename, code);
						}else if("videoresolution".equals(columnname)) {  // 视频分辨率
							spfblMap.put(codename, code);
						}else if("videosignaltype".equals(columnname)) {  // 视频信号类型
							spxhlxMap.put(codename, code);
						}else if("isshare".equals(columnname)) {  // 是否对外共享
							gxMap.put(codename, code);
						}else if("isjointhreesystem".equals(columnname)) {  // 是否接入三级平台
							sjptMap.put(codename, code);
						}else if("builddepartment".equals(columnname)) {  // 建设应用类别
							xjjsbmMap.put(codename, code);
						}else if("videopointtype".equals(columnname)) {  // 监控点类型
							jklxMap.put(codename, code);
						}
					}
				}
								
				 
				for (int i = 3; i < count; i++) {						// 循环 excel 行
					
					 Map map = new HashMap();				// 存放 excel 单元格中数据
					 boolean repeatflag = false;		//是否重复数据
					 boolean flag = true;				//数据是否为空   或   数据是否正确
					 
					 String xh = "";
					 String outsidecode = "";
					 
					for(int j=0; j<colnum_keyMap.size(); j++ ) {
						String str = readExcel.readStringExcelCell(i,j);		// 读取对应单元格的内容
						String colnum = String.valueOf(j);
						String key = colnum_keyMap.get(colnum);
						String isCheck = colnum_checkMap.get(colnum);
						String colName = colnum_headMap.get(colnum);
						
						if("outsidecode".equals(key)) {						//设备编码
							outsidecode = str;
							if(RHUtil.isEmpty(str)) {
								 flag = false;					 
								 String colStr = "第"+(j+1)+"列,("+colName+")";
								 Map errMap = getErrorMsg(i+1, colStr, nullMsg, outsidecode, xh);
								 failList.add(errMap);
							}else {
								if(xhList.contains(str)) {
									 repeatflag = true;
									 repeatNum++;
									 repeatMsg = "序号："+xh+",第"+(i+1)+"行,第"+(j+1)+"列("+colName+"),设备编码："+outsidecode+", 重复";
									 repeatMsgList.add(repeatMsg);
								 }else {
									 xhList.add(outsidecode);
								 }
							}
							map.put(key, str);
						}else if("xh".equals(key)){					//序号
							xh = str;
						}else {
							
							if("0".equals(isCheck)) {			// 不校验
								map.put(key, str);
							}else if("1".equals(isCheck)) {		// 非空校验
								if(RHUtil.isEmpty(str)) {
									flag = false;
								    String colStr = "第"+(j+1)+"列,("+colName+")";
								    Map errMap = getErrorMsg(i+1, colStr, nullMsg, outsidecode, xh);
								    failList.add(errMap);
								} 
								map.put(key, str);
							}else if("2".equals(isCheck)) {		// 代码转换
								if(RHUtil.isEmpty(str)) {
									 flag = false;
									 String colStr = "第"+(j+1)+"列,("+colName+")";
									 Map errMap = getErrorMsg(i+1,colStr,nullMsg, outsidecode, xh);
									 failList.add(errMap);
								}else {
									if("videofactory".equals(key)) {				// 设备厂商
										str = sbcsMap.get(str);
									}else if("videopointtype".equals(key)) {			// 监控点类型
										str = jklxMap.get(str);
									}else if("cameratype".equals(key)) {				// 摄像机类型
										str = xjlxMap.get(str);
									}else if("videofunctiontype".equals(key)) {				// 摄像机功能类型
										str = xjglMap.get(str);
									}else if("cameralightproperty".equals(key)) {				// 补光属性
										str = bgMap.get(str);
									}else if("videocodeformat".equals(key)) {				// 摄像机编码格式
										str = bmgsMap.get(str);
									}else if("monitorposition".equals(key)) {			//摄像机监视方位
										str = fwMap.get(str);
									}else if("camerapositiontype".equals(key)) {				// 摄像机位置类型
										str = xjwzMap.get(str);
									}else if("networkproperty".equals(key)) {				// 联网属性
										str = lwMap.get(str);
									}else if("videostate".equals(key)) {				// 设备状态
										str = sbztMap.get(str);
									}else if("useattribute".equals(key)) {				// 所属部门/行业
										if(str.contains("/")) {
											String[] arr = str.split("/");
											for(String s : arr) {
												str += syMap.get(s)+"/";
											}
										}else {
											str = syMap.get(str);
										}									
									}else if("videoresolution".equals(key)) {				// 视频分辨率
										str = spfblMap.get(str);
									}else if("videosignaltype".equals(key)) {				// 视频信号类型 
										str = spxhlxMap.get(str);
									}else if("isshare".equals(key)) {				// 是否对外共享
										str = gxMap.get(str);
									}else if("isjointhreesystem".equals(key)) {				// 是否接入三级平台
										str = sjptMap.get(str);
									}else if("builddepartment".equals(key)) {				// 建设应用类别
										str = xjjsbmMap.get(str);
									}
									
									if(RHUtil.isEmpty(str)) {
										 flag = false;
										 String colStr = "第"+j+"列,("+colName+")";
										 Map errMap = getErrorMsg(i+1, colStr, transMsg, outsidecode, xh);
										 failList.add(errMap);
									 }else {
										 map.put(key, str);
									 }
								}
								
							}else if("3".equals(isCheck)) {		// 数字校验    暂时不用
								map.put(key, str);
							}
						}								
					} 
					
					String archivevideoid = StringUtil.getUUID();
					 map.put("archivevideoid",archivevideoid);
					 map.put("createaccount", username);
					 map.put("createtime", time);
					 map.put("modifyaccount", username);
					 map.put("modifytime", time);
			//		 判断数据是否重复  即 设备编码 是否重复
					 if(RHUtil.isEmpty(outsidecodeList)) {				// 与数据库中设备外部编码是否重复
						 if(repeatflag && flag) {
							 repeatMap.put(outsidecode, map);			// excel中的重复 设备编码数据	
							 repeatList.add(map);
						 }else {	
							 if(flag) {
								 list.add(map);				// 经数据校验后的正确数据且无重复
							 }else {
								 failNum++;
							 }
						 }	
					 }else {
						 if(outsidecodeList.contains(outsidecode)) {
							 editList.add(map);
						 }else {
							 if(repeatflag && flag) {
								 repeatMap.put(outsidecode, map);			// excel中的重复 设备编码数据	
								 repeatList.add(map);
							 }else {	
								 if(flag) {
									 list.add(map);				// 经数据校验后的正确数据且无重复
								 }else {
									 failNum++;
								 }
							 }
						 }
					 }		 
				}
	
			}
			
			

			File file = new File(path+fileFileName);
			if(file.exists()){
				file.delete();
				File dir = new File(rootpath+uuid);
				dir.delete();
			}
						
			// 数据入库
			if("1".equals(sbbh)) {				// 覆盖  设备编码相同的数据  入库
			
				Iterator<Map> it = list.iterator();
				while(it.hasNext()){
					Map rkMap = it.next();
					String outsidecode = (String) rkMap.get("outsidecode");
					Map repMap = repeatMap.get(outsidecode);
					if(RHUtil.isNotEmpty(repMap)) {    // 是否有重复
						it.remove();
					}
				}
				// 重复数据处理
				int editNum = editList.size();
				if(RHUtil.isNotEmpty(editList)) {			// 与数据库中相同的 outsidecode 数据更新
					for(Map editMap : editList ) {
						editMap.put("XGTJoutsidecode", editMap.get("outsidecode"));
						service.update_Ywarchivevideoinfo(editMap);
					}
				}
				if(RHUtil.isNotEmpty(repeatMap)) {
					for(String key : repeatMap.keySet()) {
						list.add(repeatMap.get(key));						
					}
				}
				// 批量插入
				if(list.size() > 0) {
					/*for(Map insertMap : list) {
						service.insert_Ywarchivevideoinfo(insertMap);
					}*/
					service.batch_insert_Ywarchivevideoinfo(list);
				}
				rkNum = list.size() + editNum;               // 入库数据
			}else {
				// 批量插入
				if(list !=null && list.size() > 0) {
					/*for(Map insertMap : list) {
						service.insert_Ywarchivevideoinfo(insertMap);
					}*/
					service.batch_insert_Ywarchivevideoinfo(list);
					rkNum = list.size(); 
				}
				if(RHUtil.isNotEmpty(repeatList)) {
					// 批量插入 设备编号重复的数据
					if(repeatList.size() > 0) {
						/*for(Map insertMap : repeatList) {
							service.insert_Ywarchivevideoinfo(insertMap);
						}*/
						service.batch_insert_Ywarchivevideoinfo(repeatList);
					}	
					rkNum = rkNum + repeatList.size();
				}
				
			}
			
			iLog.info("总行数count--->" + count);
			rs = " 导入数据成功！总共"+ (count-2) +"条数据,重复"+repeatNum+"条数据！失败"+failNum+"条数据!";
//			System.out.println("总行数count--->" + count);
//			System.out.println(rs);
			// 入库数据  rkNum
			// 重复数据入库的  reprkNum
			// 问题数据   failNum
			reprkNum = repeatMsgList.size();
			Map resMap = new HashMap();       // 返回前端展示数据
			resMap.put("repeatData", repeatMsgList);		// 重复的
			resMap.put("failData", failList);				// 失败信息
			resMap.put("sucNum", rkNum);					// 入库数据量
			resMap.put("reprkNum", reprkNum);				// 覆盖的数据量
			resMap.put("failNum", failNum);					// 失败的数据量
			Struts2Utils.renderJson(resMap);
		} catch (Exception e) {			
			iLog.error("YwarchivevideoinfoAction-imp_Ywarchivevideoinfo-error:" +e);
			e.printStackTrace();
			Struts2Utils.renderJson(null);
		}		
	}
	
	public Map getErrorMsg(int row, String column, String errMsg, String sbbm, String xh) {
		Map map = new HashMap();
		map.put("row", row);
		map.put("colu", column);
		map.put("errMsg", errMsg);
		map.put("sbbm", sbbm);
		map.put("xh", xh);
		return map;
	}
	
	
	public void isDownload() {
		ServletRequest req = getRequest();
		String fileName = req.getParameter("fileName");
		String pacPath = BeanHelper.getModuleConfFactory().getScatter().getDownPath(); //siyou.xml中读取文件存放路径
		String fullPath = pacPath + fileName;
		File file = new File(fullPath);
		if(file.exists()) {
			Struts2Utils.renderJson(Constants.SUCCESS);
		}else {
			Struts2Utils.renderJson(null);
		}
		
	}
	
	/*@OperateType(value = LogConstants.LOG_IMPORT ,info ="imp_Ywarchivevideoinfo")
	public String imp_Ywarchivevideoinfo(String excelFile,Object user) {
		String rs = "导入格式有误!";
		int rowNum = 0;
		int dataCount = 0;
		int successNum = 0;
		int repeatNum = 0;
		int failNum = 0;
		try {
		
			ExcelReader readExcel = new ExcelReader();
			readExcel.openFile(excelFile);
			readExcel.setSheetNum(0);
			int count = readExcel.getRowCount();
			iLog.info("总行数count--->" + count);
			rs = " 导入数据成功！总共"+ dataCount +"条数据,重复"+repeatNum+"条数据！失败"+failNum+"条数据!";
			File file = new File(excelFile);
			if(file.exists()){
				file.delete();
			}
		} catch (Exception e) {
			if (rowNum > 3) {
				rs = "资源部分导入(更新)失败！Excel第" + rowNum + "行起未导入(更新)成功！";
			} else {
				rs = "资源导入(更新)失败！";
			}
			iLog.error("YwarchivevideoinfoAction-imp_Ywarchivevideoinfo-error:" +e);
			e.printStackTrace();
		}		
		return rs;
	}*/

	
}
