package cn.yw.video.videostate.action;

 import cn.base.aspect.OperateType;
import cn.base.bean.BaseAction;
import cn.base.bean.BeanHelper;
import cn.base.excel.ExcelCol;
import cn.base.excel.ExportEngine;
import cn.base.excel.ExportExcel;
import cn.base.pdf.ExportPDF;
import cn.base.util.*;
import cn.bsystem.ptuserrole.model.PtyhBean;
 import cn.yw.nhyw.nhywjtxhdgl.service.NhywjtxhdglService;
 import cn.yw.video.videostate.service.YwvideocurrentstateService;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@SuppressWarnings({"all"})
@Component("ywvideocurrentstateAction")
public class YwvideocurrentstateAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private static Logger iLog = Logger.getLogger(YwvideocurrentstateAction.class);
	
	@Autowired
	private YwvideocurrentstateService service;

	@Autowired
	private NhywjtxhdglService xhdservice;
	/**
	 * 监控设备在线率统计
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="statisticsVideoOnlineRate")
	public void statisticsVideoOnlineRate(){
		try {
			Map param = new HashMap();
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				param.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			Struts2Utils.renderJson(this.service.statisticsVideoOnlineRate(param));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-statisticsVideoOnlineRate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	// 首页   监控完好率统计
	@OperateType(value = LogConstants.LOG_GET ,info ="count_HomepageJkwhl")
	public void count_HomepageJkwhl(){
		try {
			Map param = new HashMap();
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				param.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			Struts2Utils.renderJson(this.service.statisticsVideoOnlineRate(param));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_HomepageJkwhl-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 视频完好率统计
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="statisticsVideoIntactRate")
	public void statisticsVideoIntactRate(){
		try {
			Struts2Utils.renderJson(this.service.statisticsVideoIntactRate());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-statisticsVideoIntactRate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 录像完好率统计
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="statisticsRecordIntactRate")
	public void statisticsRecordIntactRate(){
		try {
			Struts2Utils.renderJson(this.service.statisticsRecordIntactRate());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-statisticsRecordIntactRate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 分页
	 */
	//@OperateType(value = LogConstants.LOG_QUERY ,info ="listYwvideocurrentstateByPage")
	public void listYwvideocurrentstateByPage(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				map.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			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.listYwvideocurrentstateByPage(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-listYwvideocurrentstateByPage-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 查询总数
	 */
	//@OperateType(value = LogConstants.LOG_QUERY ,info ="count_Ywvideocurrentstate")
	public void count_Ywvideocurrentstate(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.count_Ywvideocurrentstate(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_Ywvideocurrentstate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 统计
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="videoCurrentStateStatistics")
	public void videoCurrentStateStatistics(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				map.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			Struts2Utils.renderJson(this.service.videoCurrentStateStatistics(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_Ywvideocurrentstate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	// 区域在线率统计        ================== start
	@OperateType(value = LogConstants.LOG_QUERY ,info ="countAreaOnlineByPage")
	public void countAreaOnlineByPage(){
		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 );
			List list = service.query_areaOnline(map);
			int totalCount = service.count_areaOnline(map);
			map.clear();
			map.put("total", totalCount);
			map.put("rows", list);

			Struts2Utils.renderJson(map);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-countAreaOnlineByPage-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	@OperateType(value = LogConstants.LOG_QUERY ,info ="areaNotOnlineByPageDetail")
	public void areaNotOnlineByPageDetail(){
		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 );
			List list=new ArrayList();
			int totalCount=0;
			if(map.get("alarmdevicetype")!=null  && map.get("alarmdevicetype").equals("1")) {
				 list = service.query_AreaNotonlineDetail(map);
				 totalCount = service.count_AreaNotonlineDetail(map);
			}
			else{
				 list = service.query_AreaNotonlineDeviceDetail(map);
				 totalCount = service.count_AreaNotonlineDeviceDetail(map);
			}
			map.clear();
			map.put("total", totalCount);
			map.put("rows", list);
			Struts2Utils.renderJson(map);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-areaNotOnlineByPageDetail-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	@OperateType(value = LogConstants.LOG_QUERY ,info ="count_showBar")
	public void count_showBar(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			List list = service.query_areaOnline(map);
			
			Struts2Utils.renderJson(list);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_showBar-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	@OperateType(value = LogConstants.LOG_GET ,info ="count_areaOnline")
	public void count_areaOnline(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Struts2Utils.renderJson(this.service.count_areaOnline(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_areaOnline-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	// 导出excel 在线率
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="exp_AreaOnline")
	public void exp_AreaOnline(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			map.put("start",0 );
			map.put("limit",5000);
			List<Map> sList = service.query_areaOnline(map);
			if(RHUtil.isNotEmpty(sList)) {
				Integer zs = 0;
				Integer zzxs = 0;
				Integer zlxs = 0;
				Integer zwxjs = 0;
				String  zlxl = "0";
				for(Map smap : sList) {
					String zcount = (String) smap.get("mcount");
					String zxs = (String) smap.get("onlinecount");
					String lxs = (String) smap.get("notonlinecount");
					String wxj = (String) smap.get("wxj");
					String lxl = "0";
					Integer mcount = Integer.parseInt(zxs) + Integer.parseInt(lxs);
					if(mcount != 0) {
						lxl = division(Integer.parseInt(zxs), mcount);
					}
					smap.put("lxl", lxl);
					
					zs = zs + Integer.parseInt(zcount);
					zzxs = zzxs + Integer.parseInt(zxs);
					zlxs = zlxs + Integer.parseInt(lxs);
					zwxjs = zwxjs + Integer.parseInt(wxj);
				}	
				// 总计
				Integer zx = zzxs + zlxs;
				if(zx != 0) {
					zlxl = division(zzxs, zx);
				}
				Map footMap = new HashMap();
				footMap.put("xzmc", "总计");
				footMap.put("mcount", zs);
				footMap.put("wxj", zwxjs);
				footMap.put("onlinecount", zzxs);
				footMap.put("notonlinecount", zlxs);
				footMap.put("lxl", zlxl);
				sList.add(footMap);
			}
			
			
			String[] zdbm = {"xzmc", "mcount","wxj","onlinecount","notonlinecount","lxl"};
			String[] zdmc = {"行政区划", "点位总数", "未巡检数","在线数","离线数","在线率"};
			int excelNum = zdmc.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]);
			}		
			SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");   
        	String dateTime=formart.format(new Date()); 
			Map params = new HashMap();
			params.put("fileName", "区域在线率统计-"+dateTime);
			params.put("sheetName", "区域在线率统计");
			params.put("header", "区域在线率统计");	
			new ExportEngine().exportCommData(params, cells, (ArrayList)sList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountuserrepairjobAction-exp_AreaOnline-error:" +e);
			
		}
	}
	// 导出pdf 在线率
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="expPDF_AreaOnline")
	public void expPDF_AreaOnline(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			map.put("start",0 );
			map.put("limit",5000);
			List<Map> sList = service.query_areaOnline(map);
			//表头
			String[] header = {"行政区划", "点位总数", "未巡检数","在线数","离线数","在线率"};
			//内容
			String[][] expArr = null;
			if(RHUtil.isNotEmpty(sList)) {
				Integer zs = 0,zzxs = 0,zlxs = 0,zwxjs = 0;
				String  zlxl = "0";
				expArr = new String[sList.size()+1][header.length];
				int index = 0;
				for(Map smap : sList) {
					String zcount = (String) smap.get("mcount");
					String zxs = (String) smap.get("onlinecount");
					String lxs = (String) smap.get("notonlinecount");
					String wxj = (String) smap.get("wxj");
					String lxl = "0";
					Integer mcount = Integer.parseInt(zxs) + Integer.parseInt(lxs);
					if(mcount != 0) {
						lxl = division(Integer.parseInt(zxs), mcount);
					}
					smap.put("lxl", lxl);
					expArr[index][0] = StringUtil.transEmpty(smap.get("xzmc")+"");
					expArr[index][1] = zcount;
					expArr[index][2] = wxj;
					expArr[index][3] = zxs;
					expArr[index][4] = lxs;
					expArr[index][5] = lxl;
					index++;
					zs = zs + Integer.parseInt(zcount);
					zzxs = zzxs + Integer.parseInt(zxs);
					zlxs = zlxs + Integer.parseInt(lxs);
					zwxjs = zwxjs + Integer.parseInt(wxj);
				}	
				// 总计
				Integer zx = zzxs + zlxs;
				if(zx != 0) {
					zlxl = division(zzxs, zx);
				}
				expArr[index][0] = "总计";
				expArr[index][1] = String.valueOf(zs);
				expArr[index][2] = String.valueOf(zwxjs);
				expArr[index][3] = String.valueOf(zzxs);
				expArr[index][4] = String.valueOf(zlxs);
				expArr[index][5] = zlxl;
			}
			SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");   
			String dateTime=formart.format(new Date()); 
			Map params = new HashMap();
			params.put("fileName", "区域在线率统计-"+dateTime);
			params.put("sheetName", "区域在线率统计");
			params.put("header", "区域在线率统计(制表时间："+DateUtil.currentDateTime()+")");
			new ExportPDF().exportCommPDF(params,header,new ArrayList(),0, expArr, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountuserrepairjobAction-expPDF_AreaOnline-error:" +e);
			
		}
	}
	// 区域在线率统计        ================== end

	
	/**
	 * 分页
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="listVideoDetailByPage")
	public void listVideoDetailByPage(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				map.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			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.listVideoDetailByPage(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-listVideoDetailByPage-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 视频质量诊断统计
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="vdqStatisticsRegionList")
	public void vdqStatisticsRegionList(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				map.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			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.vdqStatisticsRegion(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-vdqStatisticsRegionList-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	@OperateType(value = LogConstants.LOG_QUERY ,info="count_vdqStatisticsRegionList")
	public void count_vdqStatisticsRegionList() {
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				map.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			Struts2Utils.renderJson(this.service.count_vdqStatisticsRegion(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_vdqStatisticsRegionList-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 导出Excel
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="exp_Ywvideocurrentstatecount")
	public void exp_Ywvideocurrentstatecount(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Map queryMap = JSONObject.fromObject(map.get("downParam"));
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				queryMap.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			queryMap.put("start",0 );
			queryMap.put("limit",5000);
			Map result = service.vdqStatisticsRegion(queryMap);	
			List<Map> sList = null;
			if(result!=null && result.get("rows")!=null){
				sList = (List<Map>) result.get("rows");
			}
			List<Map> expList = new ArrayList<Map>();
			String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
			List<String> headerList = new ArrayList<String>();
			headerList.add("序号");
			headerList.add("行政区划");
			headerList.add("点位总数");
			headerList.add("未巡检数");
			headerList.add("在线数");
			headerList.add("离线数");
			headerList.add("在线率");
			headerList.add("视频正常数");
			headerList.add("视频异常数");
			headerList.add("视频完好率");
			headerList.add("视频丢失");
			headerList.add("视频遮挡");
			headerList.add("场景变更");
			headerList.add("亮度过低");
			headerList.add("亮度过高");
			headerList.add("图像模糊");
			headerList.add("图像偏色");
			
			for(int i  =0;i<sList.size()-1;i++ ){
				Map exportMap = new HashMap();
				exportMap.put("序号", i+1);
				exportMap.put("行政区划", sList.get(i).get("videocatalogname")==null?"":sList.get(i).get("videocatalogname"));
				exportMap.put("点位总数", sList.get(i).get("totalnum"));
				exportMap.put("未巡检数", sList.get(i).get("noinspectionnum"));
				exportMap.put("在线数", sList.get(i).get("zxnum"));
				exportMap.put("离线数", sList.get(i).get("lxnum"));
				exportMap.put("在线率", sList.get(i).get("zxrate"));
				exportMap.put("视频正常数", sList.get(i).get("videonormalnum"));
				exportMap.put("视频异常数", sList.get(i).get("videoabnormalnum"));
				exportMap.put("视频完好率", sList.get(i).get("videorate"));
				exportMap.put("视频丢失", sList.get(i).get("nosignalstatusnum"));
				exportMap.put("视频遮挡", sList.get(i).get("videoocclusionstatusnum"));
				exportMap.put("场景变更", sList.get(i).get("scenechangestatusnum"));
				exportMap.put("亮度过低", sList.get(i).get("imgtoodarkstatusnum"));
				exportMap.put("亮度过高", sList.get(i).get("imgoverbrightstatusnum"));
				exportMap.put("图像模糊", sList.get(i).get("imgclearstatusnum"));
				exportMap.put("图像偏色", sList.get(i).get("imgcolorstatusnum"));
				expList.add(exportMap);
			}
			List footerList = new ArrayList();
			if(sList.size()>0){
				Map json = JSONObject.fromObject(sList.get(sList.size()-1));
				footerList.add( "总计");
				footerList.add("总计");
				footerList.add( json.get("monitorSum"));
				footerList.add( json.get("noinspectionSum"));
				footerList.add( json.get("zxSum"));
				footerList.add( json.get("lxSum"));
				footerList.add( json.get("zxrate"));
				footerList.add( json.get("videonormalSum"));
				footerList.add( json.get("videoabnormalSum"));
				footerList.add( json.get("videorate"));
				footerList.add( json.get("nosignalstatusSum"));
				footerList.add( json.get("videoocclusionstatusSum"));
				footerList.add( json.get("scenechangestatusSum"));
				footerList.add( json.get("imgtoodarkstatusSum"));
				footerList.add(json.get("imgoverbrightstatusSum"));
				footerList.add(json.get("imgclearstatusSum"));
				footerList.add(json.get("imgcolorstatusSum"));
			}
			SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");   
			String dateTime=formart.format(new Date()); 
			Map params = new HashMap();
			params.put("fileName", "视频质量诊断统计-"+dateTime);
			params.put("sheetName", "视频质量诊断统计");
			params.put("header", "视频质量诊断统计");	
			new ExportExcel().exportCommExcel(params,headerList,footerList, expList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-exp_Ywvideocurrentstatecount-error:" +e);
			
		}
	}
	/**
	 * 导出pdf
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="expPDF_Ywvideocurrentstatecount")
	public void expPDF_Ywvideocurrentstatecount(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Map queryMap = JSONObject.fromObject(map.get("downParam"));
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				queryMap.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			queryMap.put("start",0 );
			queryMap.put("limit",5000);
			Map result = service.vdqStatisticsRegion(queryMap);	
			List<Map> sList = null;
			if(result!=null && result.get("rows")!=null){
				sList = (List<Map>) result.get("rows");
			}
			List<Map> expList = new ArrayList<Map>();
			String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
			List<String> headerList = new ArrayList<String>();
			headerList.add("序号");
			headerList.add("行政区划");
			headerList.add("点位总数");
			headerList.add("未巡检数");
			headerList.add("在线数");
			headerList.add("离线数");
			headerList.add("在线率");
			headerList.add("视频正常数");
			headerList.add("视频异常数");
			headerList.add("视频完好率");
			headerList.add("视频丢失");
			headerList.add("视频遮挡");
			headerList.add("场景变更");
			headerList.add("亮度过低");
			headerList.add("亮度过高");
			headerList.add("图像模糊");
			headerList.add("图像偏色");
			
			for(int i  =0;i<sList.size()-1;i++ ){
				Map exportMap = new HashMap();
				exportMap.put("序号", i+1);
				exportMap.put("行政区划", sList.get(i).get("videocatalogname")==null?"":sList.get(i).get("videocatalogname"));
				exportMap.put("点位总数", sList.get(i).get("totalnum"));
				exportMap.put("未巡检数", sList.get(i).get("noinspectionnum"));
				exportMap.put("在线数", sList.get(i).get("zxnum"));
				exportMap.put("离线数", sList.get(i).get("lxnum"));
				exportMap.put("在线率", sList.get(i).get("zxrate"));
				exportMap.put("视频正常数", sList.get(i).get("videonormalnum"));
				exportMap.put("视频异常数", sList.get(i).get("videoabnormalnum"));
				exportMap.put("视频完好率", sList.get(i).get("videorate"));
				exportMap.put("视频丢失", sList.get(i).get("nosignalstatusnum"));
				exportMap.put("视频遮挡", sList.get(i).get("videoocclusionstatusnum"));
				exportMap.put("场景变更", sList.get(i).get("scenechangestatusnum"));
				exportMap.put("亮度过低", sList.get(i).get("imgtoodarkstatusnum"));
				exportMap.put("亮度过高", sList.get(i).get("imgoverbrightstatusnum"));
				exportMap.put("图像模糊", sList.get(i).get("imgclearstatusnum"));
				exportMap.put("图像偏色", sList.get(i).get("imgcolorstatusnum"));
				expList.add(exportMap);
			}
			List footerList = new ArrayList();
			if(sList.size()>0){
				Map json = JSONObject.fromObject(sList.get(sList.size()-1));
				footerList.add( "总计");
				footerList.add("总计");
				footerList.add( json.get("monitorSum"));
				footerList.add( json.get("noinspectionSum"));
				footerList.add( json.get("zxSum"));
				footerList.add( json.get("lxSum"));
				footerList.add( json.get("zxrate"));
				footerList.add( json.get("videonormalSum"));
				footerList.add( json.get("videoabnormalSum"));
				footerList.add( json.get("videorate"));
				footerList.add( json.get("nosignalstatusSum"));
				footerList.add( json.get("videoocclusionstatusSum"));
				footerList.add( json.get("scenechangestatusSum"));
				footerList.add( json.get("imgtoodarkstatusSum"));
				footerList.add(json.get("imgoverbrightstatusSum"));
				footerList.add(json.get("imgclearstatusSum"));
				footerList.add(json.get("imgcolorstatusSum"));
			}
			SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");   
			String dateTime=formart.format(new Date()); 
			Map params = new HashMap();
			params.put("fileName", "视频质量诊断统计-"+dateTime);
			params.put("sheetName", "视频质量诊断统计");
			params.put("header", "视频质量诊断统计(制表时间："+DateUtil.currentDateTime()+")");	
			new ExportPDF().exportCommPDF(params,headerList,footerList, expList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-expPDF_Ywvideocurrentstatecount-error:" +e);
			
		}finally{
//			try {
//				Struts2Utils.getResponse().getOutputStream().close();
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
		}
	}
	/**
	 * 查询 Ywvideocurrentstate
	 */
	/*
	@OperateType(value = LogConstants.LOG_GET ,info ="query_Ywvideocurrentstate")
	public void query_Ywvideocurrentstate(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.query_Ywvideocurrentstate(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-query_Ywvideocurrentstate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	*/
	
	/**
	 * 查询 一条Ywvideocurrentstate
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="get_Ywvideocurrentstate")
	public void get_Ywvideocurrentstate(){
		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.get_Ywvideocurrentstate(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateActionquery_Ywvideocurrentstate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 删除
	 */
	/*
	@OperateType(value = LogConstants.LOG_DELETE ,info ="deleteYwvideocurrentstate")
	public void delete_Ywvideocurrentstate(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(!CommUtils.isEmpty(map)){
				int result = service.delete_Ywvideocurrentstate(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}else{
				 throw new Exception("请正确的选择删除记录!!!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-delete_Ywvideocurrentstate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	*/

	/**
	 * 插入
	 */
	/*
	@OperateType(value = LogConstants.LOG_ADD ,info ="insert_Ywvideocurrentstate")
	public void insert_Ywvideocurrentstate(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(StringUtil.checkEmpty(map.get("currentstateid"))){
				map.put("currentstateid",StringUtil.getUUID());
			}
			if(!StringUtil.checkEmpty(map.get("checkparam"))){
				Map sMap = new HashMap();
				sMap.put("tableparam", map.get("checkparam"));
				List ls = service.query_Ywvideocurrentstate(sMap);
				if(!StringUtil.checkEmpty(ls)||ls.size()>0){
					Struts2Utils.renderJson(Constants.SAME);
				}else{
					service.insert_Ywvideocurrentstate(map);
					Struts2Utils.renderJson(Constants.SUCCESS);
				}
			}else{
				service.insert_Ywvideocurrentstate(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}			
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-insert_Ywvideocurrentstate()-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	*/
	
	/**
	 * 修改
	 */
	/*
	@OperateType(value = LogConstants.LOG_UPDATE ,info ="update_Ywvideocurrentstate")
	public void update_Ywvideocurrentstate(){
		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_Ywvideocurrentstate(sMap);
				if(!StringUtil.checkEmpty(ls)||ls.size()>0){
					Struts2Utils.renderJson(Constants.SAME);
				}else{
					int result = service.update_Ywvideocurrentstate(map);
					Struts2Utils.renderJson(Constants.SUCCESS);
				}
			}else{
				int result = service.update_Ywvideocurrentstate(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-update_Ywvideocurrentstate-error: " +e);
			Struts2Utils.renderJson(null);
		}
	}
	*/
	
	/**
	 * 批量删除
	 */
	/*
	@OperateType(value = LogConstants.LOG_DELETE ,info ="batch_delete_Ywvideocurrentstate")
	public void batch_delete_Ywvideocurrentstate(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Map m = new HashMap();
			m.put("keyword", map.get("keyword").toString());
			int result = service.batch_delete_Ywvideocurrentstate(m);
			Struts2Utils.renderJson(Constants.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-batch_delete_Ywvideocurrentstate-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	*/
	
	/**
	 * 导出Excel
	 */
	/*
	//@OperateType(value = LogConstants.LOG_EXPORT ,info ="exp_Ywvideocurrentstate")
	public void exp_Ywvideocurrentstate(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			map.put("start",0 );
			map.put("limit",5000);
			List<Map> sList = service.query_Ywvideocurrentstate(map);		
			List<HashMap> expList = new ArrayList<HashMap>();
			for(Map m : sList){
				Map exportMap = new HashMap();
				exportMap.put("yhzh", m.get("yhzh"));
				expList.add((HashMap) exportMap);
			}
			int excelNum = 2;
			ExcelCol[] cells = new ExcelCol[excelNum];
			String[] zdbm = {"yhzh", "yhmc",};
			String[] zdmc = {"用户账号", "用户名称"};
			for(int i=0;i<excelNum;i++){
				cells[i] = new ExcelCol();
				cells[i].setColKey(zdbm[i]);
				cells[i].setColName(zdmc[i]);
			}		
			SimpleDateFormat formart = new SimpleDateFormat("yyyy-MM-dd");   
        	String dateTime=formart.format(new Date()); 
			Map params = new HashMap();
			params.put("fileName", "运维监控当前状态表-"+dateTime);
			params.put("sheetName", "运维监控当前状态表");
			params.put("header", "运维监控当前状态表");	
			new ExportEngine().exportCommData(params, cells, (ArrayList)map.get("rows"), Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-exoprtExcel-error:" +e);
			
		}
	}
	*/
	
	/**
	 * 导入Excel
	 */
	/*
	//@OperateType(value = LogConstants.LOG_IMPORT ,info ="imp_Ywvideocurrentstate")
	public String imp_Ywvideocurrentstate(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("YwvideocurrentstateAction-imp_Ywvideocurrentstate-error:" +e);
			e.printStackTrace();
		}		
		return rs;
	}
	*/
	
	
	// 首页统计
	public void count_HomepageFalultType(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {			
			Struts2Utils.renderJson(this.service.count_HomepageFalultType(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-count_HomepageFalultType-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	// 中间查询设备
	public void query_videoState(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			// 获取用户信息
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Integer sfgly = ptyh.getSfgly();
			if(sfgly != 1) {
				map.put("bmbh", ptyh.getBmbh()); // 获取部门编号
			}
			// 分页
			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.query_videoState(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-query_videoState-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 运维大屏设备行政树及其设备查询
	 */
	@OperateType(value = LogConstants.LOG_IMPORT ,info ="getVideoTree")
	public void getVideoTree(){
		try {
			//请求参数
			Map map = Struts2Utils.getRequestParameterMap();
			//获取私有行政树配置节点
			String rootNode = BeanHelper.getModuleConfFactory().getYwDp().getYwXzTree();
			// 分页
			/*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 );*/
			map.put("sjxzbh",rootNode );
			Struts2Utils.renderJson(this.service.queryVideoTree(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-queryVideoTree-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	
	/**
     * 转成百分数
     * 当前数除以总数
     * @param  num1 ,num2  num1/num2
     * @return  rate  保留2位小数的
     */
    public static String  division(int num1,int num2){
        String rate="0.00%";
        //定义格式化起始位数
        String format="0.00";
        if(num2 != 0 && num1 != 0){
            DecimalFormat dec = new DecimalFormat(format);
            rate =  dec.format((double) num1 / num2*100)+"%";
            while(true){
                if(rate.equals(format+"%")){
                    format=format+"0";
                    DecimalFormat dec1 = new DecimalFormat(format);
                    rate =  dec1.format((double) num1 / num2*100)+"%";
                }else {
                    break;
                }
            }
        }else if(num1 != 0 && num2 == 0){
            rate = "100%";
        }
        return rate;
    }
    public static void main(String[] args) {
		String str = "-1$fe5217b3d27bf1db8d3067eae68dd832$04e24338cd296596f34c8d5cd5c8ff5d$";
		String[] strs = str.split("\\$");
		System.out.println(strs.length);
		for(int i=0;i<strs.length;i++){
			System.out.println(i+":"+strs[i]);
		}
		System.out.println("-----------------------------------------------");
		str = str.substring(str.indexOf("fe5217b3d27bf1db8d3067eae68dd832")+"fe5217b3d27bf1db8d3067eae68dd832".length());
		System.out.println(str);
		strs = str.split("\\$");
		System.out.println(strs.length);
		for(int i=0;i<strs.length;i++){
			System.out.println(i+":"+strs[i]);
		}
	}
	/**
	 * 获得计算方式
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="getjsgs")
	public void getjsgs(){
		try {
			//请求参数
			Map map = Struts2Utils.getRequestParameterMap();
			Struts2Utils.renderJson(this.service.queryjsgs(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-getjsfs-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 修改计算方式
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="updatejsgs")
	public void updatejsgs(){
		try {
			//请求参数
			Map map = Struts2Utils.getRequestParameterMap();
			Struts2Utils.renderJson(this.service.updatejsgs(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwvideocurrentstateAction-updatejsfs-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
}
