package cn.yw.operationcount.videoappraisecount.action;


import java.io.File;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.cxf.common.util.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
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.excel.ExcelCol;
import cn.base.excel.ExportEngine;
import cn.base.excel.ExportExcel;
import cn.base.pdf.ExportPDF;
import cn.base.util.CommUtils;
import cn.base.util.Constants;
import cn.base.util.DateUtil;
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.operationcount.videoappraisecount.service.YwcountvideoappraiseService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@SuppressWarnings({"all"})
@Component("ywcountvideoappraiseAction")
public class YwcountvideoappraiseAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private static Logger iLog = Logger.getLogger(YwcountvideoappraiseAction.class);
	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	@Autowired
	private YwcountvideoappraiseService service;
	
	/**
	 * 分页
	 */
	@OperateType(value = LogConstants.LOG_QUERY ,info ="listYwcountvideoappraiseByPage")
	public void listYwcountvideoappraiseByPage(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			map.put("bmbh",bmbh);
			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 );
			if(null!=map.get("xzbh"))
			{
				String  xzbh=map.get("xzbh").toString();
				map.put("xzbh",xzbh.split(","));
			}
			Struts2Utils.renderJson(this.service.listYwcountvideoappraiseByPage(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-listYwcountvideoappraiseByPage-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 区域运维考核统计
	 */
	public void regionAssessmentCountList(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			if(ptyh.getSfgly()!=1){
				map.put("bmbh",bmbh);
			}
			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 );
			if(null!=map.get("xzbh"))
			{
				String  xzbh=map.get("xzbh").toString();
				map.put("xzbh",xzbh.split(","));
			}
			Struts2Utils.renderJson(this.service.regionAssessmentCountList(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-regionAssessmentCountList-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	// 首页    区域运维考核统计 
	public void count_HomepateAreaExam(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			
			String nowTime = DateUtil.getDateTimeStr(new Date());
//			String zStartTime = sdf.format(DateUtil.day(new Date(),-7));    // 最近一周
//			String yStartTime = sdf.format(DateUtil.month(-1));			 	// 最近一个月
//			String nStartTime = sdf.format(DateUtil.year(-1));				// 最近一年
			
			String type = map.get("type")+"";
			String startTime = sdf.format(DateUtil.day(new Date(),-7));
			if("1".equals(type)){// 最近一个月
				startTime = sdf.format(DateUtil.month(-1));		
			}else if("2".equals(type)){// 最近一年
				startTime = sdf.format(DateUtil.year(-1));
			}
			
			String tableParam=null;
			String jobtableparam = null;
			
			tableParam = " and countDate >= " + "\'" +startTime+ "\'" +" and countDate <= " + "\'" +nowTime+ "\'";
			jobtableparam = " and jobreporttime >= " + "\'" +startTime+ "\'" +" and jobreporttime <= " + "\'" +nowTime+ "\'";
			map.put("tableparam", tableParam);
			map.put("jobtableparam", jobtableparam);
			Map zMap = service.regionAssessmentCountList(map);
			
			/*tableParam = " and countDate >= " + "\'" +yStartTime+ "\'" +" and countDate <= " + "\'" +nowTime+ "\'";
			jobtableparam = " and jobreporttime >= " + "\'" +yStartTime+ "\'" +" and jobreporttime <= " + "\'" +nowTime+ "\'";
			map.put("tableparam", tableParam);
			map.put("jobtableparam", jobtableparam);
			Map yMap = service.regionAssessmentCountList(map);
			
			tableParam = " and countDate >= " + "\'" +nStartTime+ "\'" +" and countDate <= " + "\'" +nowTime+ "\'";
			jobtableparam = " and jobreporttime >= " + "\'" +nStartTime+ "\'" +" and jobreporttime <= " + "\'" +nowTime+ "\'";
			map.put("tableparam", tableParam);
			map.put("jobtableparam", jobtableparam);
			Map nMap = service.regionAssessmentCountList(map);
						
			Object[] zList = (Object[]) zMap.get("rows");
			Object[] yList = (Object[]) yMap.get("rows");
			Object[] nList = (Object[]) nMap.get("rows");*/
			
//			map.clear();
//			Object[] zList = (Object[]) zMap.get("rows");
//			map.put("zList", zMap.get("rows"));
//			map.put("yList", yList);
//			map.put("nList", nList);
			
			Struts2Utils.renderJson(zMap.get("rows"));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-count_HomepateAreaExam-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 区域运维考核统计-钻取某个区域
	 */
	public void regionAssessmentCountListByRegion(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			if(ptyh.getSfgly()!=1){
				map.put("bmbh",bmbh);
			}
			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.regionAssessmentCountListByRegion(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-regionAssessmentCountList-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 查询总数
	 */
	//@OperateType(value = LogConstants.LOG_QUERY ,info ="count_Ywcountvideoappraise")
	public void count_Ywcountvideoappraise(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			map.put("bmbh",bmbh);
			Struts2Utils.renderJson(this.service.count_Ywcountvideoappraise(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-count_Ywcountvideoappraise-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 查询 Ywcountvideoappraise
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="query_Ywcountvideoappraise")
	public void query_Ywcountvideoappraise(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(null!=map.get("xzbh"))
			{
				String  xzbh=map.get("xzbh").toString();
				map.put("xzbh",xzbh.split(","));
			}
			Struts2Utils.renderJson(this.service.query_Ywcountvideoappraise(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-query_Ywcountvideoappraise-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 查询 一条Ywcountvideoappraise
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="get_Ywcountvideoappraise")
	public void get_Ywcountvideoappraise(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.get_Ywcountvideoappraise(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction query_Ywcountvideoappraise-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 获取权重
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="getWeight")
	public void getWeight(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Struts2Utils.renderJson(this.service.getWeight(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("getWeight-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	/**
	 * 设置权重
	 */
	@OperateType(value = LogConstants.LOG_GET ,info ="setWeight")
	public void setWeight(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			Map m = service.getWeight(map);
			if(m!=null && m.size()>0){
				map.put("modifyaccount", ptyh.getYhzh());
				map.put("modifytime", DateUtil.currentDateTime());
				Struts2Utils.renderJson(this.service.updateWeight(map));
			}else{
				map.put("weightId", StringUtil.getUUID());
				map.put("createaccount", ptyh.getYhzh());
				map.put("createtime", DateUtil.currentDateTime());
				map.put("modifyaccount", ptyh.getYhzh());
				map.put("modifytime", DateUtil.currentDateTime());
				this.service.insertWeight(map);
				Struts2Utils.renderJson("success");
				
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("setWeight-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 删除
	 */
	@OperateType(value = LogConstants.LOG_DELETE ,info ="deleteYwcountvideoappraise")
	public void delete_Ywcountvideoappraise(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(!CommUtils.isEmpty(map)){
				int result = service.delete_Ywcountvideoappraise(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}else{
				 throw new Exception("请正确的选择删除记录!!!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-delete_Ywcountvideoappraise-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}

	/**
	 * 插入
	 */
	@OperateType(value = LogConstants.LOG_ADD ,info ="insert_Ywcountvideoappraise")
	public void insert_Ywcountvideoappraise(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			if(StringUtil.checkEmpty(map.get("countId"))){
				map.put("countId",StringUtil.getUUID());
			}
			if(!StringUtil.checkEmpty(map.get("checkparam"))){
				Map sMap = new HashMap();
				sMap.put("tableparam", map.get("checkparam"));
				List ls = service.query_Ywcountvideoappraise(sMap);
				if(!StringUtil.checkEmpty(ls)||ls.size()>0){
					Struts2Utils.renderJson(Constants.SAME);
				}else{
					service.insert_Ywcountvideoappraise(map);
					Struts2Utils.renderJson(Constants.SUCCESS);
				}
			}else{
				service.insert_Ywcountvideoappraise(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}			
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-insert_Ywcountvideoappraise()-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 修改
	 */
	@OperateType(value = LogConstants.LOG_UPDATE ,info ="update_Ywcountvideoappraise")
	public void update_Ywcountvideoappraise(){
		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_Ywcountvideoappraise(sMap);
				if(!StringUtil.checkEmpty(ls)||ls.size()>0){
					Struts2Utils.renderJson(Constants.SAME);
				}else{
					int result = service.update_Ywcountvideoappraise(map);
					Struts2Utils.renderJson(Constants.SUCCESS);
				}
			}else{
				int result = service.update_Ywcountvideoappraise(map);
				Struts2Utils.renderJson(Constants.SUCCESS);
			}
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-update_Ywcountvideoappraise-error: " +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 批量删除
	 */
	@OperateType(value = LogConstants.LOG_DELETE ,info ="batch_delete_Ywcountvideoappraise")
	public void batch_delete_Ywcountvideoappraise(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {
			Map m = new HashMap();
			m.put("keyword", map.get("keyword").toString());
			int result = service.batch_delete_Ywcountvideoappraise(m);
			Struts2Utils.renderJson(Constants.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-batch_delete_Ywcountvideoappraise-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	/**
	 * 导出Excel 区域运维考核
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="exp_Ywcountvideoappraise")
	public void exp_Ywcountvideoappraise(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Map queryMap = JSONObject.fromObject(map.get("downParam"));
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			if(ptyh.getSfgly()!=1){
				queryMap.put("bmbh",bmbh);
			}
			queryMap.put("start",0 );
			queryMap.put("limit",5000);
			JSONArray jsonArr = JSONArray.fromObject( service.regionAssessmentCountList(queryMap).get("rows"));	
//			List<Object> sList = Arrays.asList(objs);
			List<Map> expList = new ArrayList<Map>();
			
			String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
			List<String> headerList = new ArrayList<String>();
			Map weightMap = service.getWeight(new HashMap());
			if(weightMap!=null){
				headerList.add("序号");
				headerList.add("行政区划");
				headerList.add("监控点总数");
				headerList.add("在线时间（小时）");
				headerList.add("在线率（"+weightMap.get("onlineweight")+"）");
				headerList.add("视频完好率（"+weightMap.get("videoweight")+"）");
				headerList.add("录像完好率（"+weightMap.get("recordweight")+"）");
				headerList.add("经纬度采集率（"+weightMap.get("lalweight")+"）");
				headerList.add("修复率（"+weightMap.get("repairweight")+"）");
				headerList.add("总分");
				headerList.add("排名");
			}else{
				
				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<jsonArr.size()-1;i++ ){
				JSONObject json = JSONObject.fromObject(jsonArr.get(i));
				Map exportMap = new HashMap();
				exportMap.put("序号", i+1);
				exportMap.put("行政区划", json.get("areaname")==null?"":json.get("areaname"));
				exportMap.put("监控点总数", json.get("jksum"));
				exportMap.put("在线时间（小时）", json.get("zxsc"));
				exportMap.put("在线率（"+weightMap.get("onlineweight")+"）", json.get("zxRate"));
				exportMap.put("视频完好率（"+weightMap.get("videoweight")+"）", json.get("videoIntactRate"));
				exportMap.put("录像完好率（"+weightMap.get("recordweight")+"）", json.get("recordIntactRate"));
				exportMap.put("经纬度采集率（"+weightMap.get("lalweight")+"）", json.get("lalIntactRate"));
				exportMap.put("修复率（"+weightMap.get("repairweight")+"）", json.get("jobIntactRate"));
				
				exportMap.put("总分", json.get("score"));
				exportMap.put("排名", i+1);
				expList.add(exportMap);
			}
			List footerList = new ArrayList();
			if(jsonArr.size()>0){
				
				JSONObject json = JSONObject.fromObject(jsonArr.get(jsonArr.size()-1));
				footerList.add( "总计");
				footerList.add("总计");
				footerList.add( json.get("jksum"));
				footerList.add( json.get("zxscSum"));
				footerList.add( json.get("zxscRate"));
				footerList.add( json.get("videoRate"));
				footerList.add( json.get("recordRate"));
				footerList.add( json.get("lalRate"));
				footerList.add( json.get("jobRate"));
				footerList.add( json.get("scoreSum"));
				footerList.add("");
			}
			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 ExportExcel().exportCommExcel(params,headerList,footerList, expList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-exoprtExcel-error:" +e);
			
		}
	}
	/**
	 * 导出pdf 区域运维考核
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="expPDF_Ywcountvideoappraise")
	public void expPDF_Ywcountvideoappraise(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Map queryMap = JSONObject.fromObject(map.get("downParam"));
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			if(ptyh.getSfgly()!=1){
				queryMap.put("bmbh",bmbh);
			}
			queryMap.put("start",0 );
			queryMap.put("limit",5000);
			JSONArray jsonArr = JSONArray.fromObject( service.regionAssessmentCountList(queryMap).get("rows"));	
//			List<Object> sList = Arrays.asList(objs);
			List<Map> expList = new ArrayList<Map>();
			
			String username = ((PtyhBean)Struts2Utils.getSession().getAttribute("userInfo")).getYhzh();
			List<String> headerList = new ArrayList<String>();
			Map weightMap = service.getWeight(new HashMap());
			if(weightMap!=null){
				headerList.add("序号");
				headerList.add("行政区划");
				headerList.add("监控点总数");
				headerList.add("在线时间（小时）");
				headerList.add("在线率（"+weightMap.get("onlineweight")+"）");
				headerList.add("视频完好率（"+weightMap.get("videoweight")+"）");
				headerList.add("录像完好率（"+weightMap.get("recordweight")+"）");
				headerList.add("经纬度采集率（"+weightMap.get("lalweight")+"）");
				headerList.add("修复率（"+weightMap.get("repairweight")+"）");
				headerList.add("总分");
				headerList.add("排名");
			}else{
				
				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<jsonArr.size()-1;i++ ){
				JSONObject json = JSONObject.fromObject(jsonArr.get(i));
				Map exportMap = new HashMap();
				exportMap.put("序号", i+1);
				exportMap.put("行政区划", json.get("areaname")==null?"":json.get("areaname"));
				exportMap.put("监控点总数", json.get("jksum"));
				exportMap.put("在线时间（小时）", json.get("zxsc"));
				exportMap.put("在线率（"+weightMap.get("onlineweight")+"）", json.get("zxRate"));
				exportMap.put("视频完好率（"+weightMap.get("videoweight")+"）", json.get("videoIntactRate"));
				exportMap.put("录像完好率（"+weightMap.get("recordweight")+"）", json.get("recordIntactRate"));
				exportMap.put("经纬度采集率（"+weightMap.get("lalweight")+"）", json.get("lalIntactRate"));
				exportMap.put("修复率（"+weightMap.get("repairweight")+"）", json.get("jobIntactRate"));
				
				exportMap.put("总分", json.get("score"));
				exportMap.put("排名", i+1);
				expList.add(exportMap);
			}
			List footerList = new ArrayList();
			if(jsonArr.size()>0){
				
				JSONObject json = JSONObject.fromObject(jsonArr.get(jsonArr.size()-1));
				footerList.add( "总计");
				footerList.add("总计");
				footerList.add( json.get("jksum"));
				footerList.add( json.get("zxscSum"));
				footerList.add( json.get("zxscRate"));
				footerList.add( json.get("videoRate"));
				footerList.add( json.get("recordRate"));
				footerList.add( json.get("lalRate"));
				footerList.add( json.get("jobRate"));
				footerList.add( json.get("scoreSum"));
				footerList.add("");
			}
			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 ExportPDF().exportCommPDF(params,headerList,footerList, expList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-expPDF_Ywcountvideoappraise-error:" +e);
			
		}
	}
	/**
	 * 导出Excel 离线时长
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="exp_Ywcountvideoappraise_online")
	public void exp_Ywcountvideoappraise_online(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Map queryMap = JSONObject.fromObject(map.get("downParam"));
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			if(ptyh.getSfgly()!=1){
				queryMap.put("bmbh",bmbh);
			}
			queryMap.put("start",0 );
			queryMap.put("limit",5000);
			List<Map> jsonArr =  service.query_Ywcountvideoappraise(queryMap);	
			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("IP地址");
			headerList.add("离线时长（小时）");
			headerList.add("离线开始时间");
			
			for(int i  =0;i<jsonArr.size();i++ ){
				Map json = jsonArr.get(i);
				Map exportMap = new HashMap();
				exportMap.put("序号", i+1);
				exportMap.put("监控点名称", json.get("videoname"));
				exportMap.put("行政区划", json.get("areaname")==null?"-":json.get("areaname"));
				exportMap.put("IP地址", json.get("ipaddress"));
				exportMap.put("离线时间（小时）", json.get("lxsc"));
				exportMap.put("离线开始时间", json.get("lxstarttime"));
				
				expList.add(exportMap);
			}
			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,new ArrayList(), expList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-exp_Ywcountvideoappraise_online-error:" +e);
			
		}
	}
	/**
	 * 导出pdf 离线时长
	 */
	@OperateType(value = LogConstants.LOG_EXPORT ,info ="expPDF_Ywcountvideoappraise_online")
	public void expPDF_Ywcountvideoappraise_online(){
		try {
			Map map = Struts2Utils.getRequestParameterMap();
			Map queryMap = JSONObject.fromObject(map.get("downParam"));
			PtyhBean ptyh = (PtyhBean)Struts2Utils.getSession().getAttribute("userInfo");
			String bmbh = ptyh.getBmbh();
			if(ptyh.getSfgly()!=1){
				queryMap.put("bmbh",bmbh);
			}
			queryMap.put("start",0 );
			queryMap.put("limit",5000);
			List<Map> jsonArr =  service.query_Ywcountvideoappraise(queryMap);	
			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("IP地址");
			headerList.add("离线时长（小时）");
			headerList.add("离线开始时间");
			
			for(int i  =0;i<jsonArr.size();i++ ){
				Map json = jsonArr.get(i);
				Map exportMap = new HashMap();
				exportMap.put("序号", i+1);
				exportMap.put("监控点名称", json.get("videoname"));
				exportMap.put("行政区划", json.get("areaname")==null?"-":json.get("areaname"));
				exportMap.put("IP地址", json.get("ipaddress"));
				exportMap.put("离线时间（小时）", json.get("lxsc"));
				exportMap.put("离线开始时间", json.get("lxstarttime"));
				
				expList.add(exportMap);
			}
			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,new ArrayList(), expList, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-expPDF_Ywcountvideoappraise_online-error:" +e);
			
		}
	}
	
	// 点位录像情况统计                           /start 
	@OperateType(value = LogConstants.LOG_DELETE ,info ="batch_delete_Ywcountvideoappraise")
	public void query_dwlxByPage(){
		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 );

			if(null!=map.get("xzbh"))
			{
				String  xzbh=map.get("xzbh").toString();
				map.put("xzbh",xzbh.split(","));
			}

			List list = service.query_dwlx(map);
			int totalCount = service.count_dwlx(map);
			map.clear();
			map.put("total", totalCount);
			map.put("rows", list);
			Struts2Utils.renderJson(map);
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-batch_delete_Ywcountvideoappraise-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	@OperateType(value = LogConstants.LOG_DELETE ,info ="count_dwlx")
	public void count_dwlx(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {		
			Struts2Utils.renderJson(service.count_dwlx(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-count_dwlx-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	
	// 统计  柱状图
	@OperateType(value = LogConstants.LOG_DELETE ,info ="show_bar")
	public void show_bar(){
		Map map = Struts2Utils.getRequestParameterMap();
		try {		
			Struts2Utils.renderJson(service.show_bar(map));
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountvideoappraiseAction-show_bar-error:" +e);
			Struts2Utils.renderJson(null);
		}
	}
	// 导出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_dwlx(map);
			//表头
			String[] header = {"行政区划", "监控点名称", "设备IP","录像正常数","录像异常数","录像完好率"};
			//内容
			String[][] expArr = null;
			List<String> footerList = null;
			if(RHUtil.isNotEmpty(sList)) {
				Integer zs = 0,zzcs = 0,zycs = 0;
				String  zwhl = "0";
				expArr = new String[sList.size()][header.length];
				int index = 0;
				for(Map smap : sList) {
					String zcs = (String) smap.get("recordduration");
					String ycs = (String) smap.get("norecordduration");
					String whl = "0";
					if (StringUtils.isEmpty(zcs)) {
						zcs = "0";
					}
					if (StringUtils.isEmpty(ycs)) {
						ycs = "0";
					}
					Integer mcount = Integer.parseInt(zcs) + Integer.parseInt(ycs);
					if(mcount != 0) {
						whl = division(Integer.parseInt(zcs), mcount);
					}
					smap.put("whl", whl);
					String[] zdbm = {"areaname", "videoname","ipaddress","recordduration","norecordduration","whl"};

					expArr[index][0] = StringUtil.transEmpty(smap.get("areaname")+"");
					expArr[index][1] = StringUtil.transEmpty(smap.get("videoname")+"");
					expArr[index][2] = StringUtil.transEmpty(smap.get("ipaddress")+"");
					expArr[index][3] = zcs;
					expArr[index][4] = ycs;
					expArr[index][5] = whl;
					index++;
					zs = zs + mcount;
					zzcs = zzcs + Integer.parseInt(zcs);
					zycs = zycs + Integer.parseInt(ycs);				
				}	
				// 总计
				if(zs != 0) {
					zwhl = division(zzcs, zs);
				}
				footerList = new ArrayList<String>();
				footerList.add("总计");
				footerList.add("总计");
				footerList.add("总计");
				footerList.add(String.valueOf(zzcs));
				footerList.add(String.valueOf(zycs));
				footerList.add(String.valueOf(zwhl));
			}
			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,footerList,3, expArr, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountuserrepairjobAction-expPDF_AreaOnline-error:" +e);
			
		}
	}
	// 导出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_dwlx(map);
			Map footMap = new HashMap();
			if(RHUtil.isNotEmpty(sList)) {
				Integer zs = 0;
				Integer zzcs = 0;
				Integer zycs = 0;
				String  zwhl = "0";
				for(Map smap : sList) {
					String zcs = (String) smap.get("recordduration");
					String ycs = (String) smap.get("norecordduration");
					String whl = "0";
					if (StringUtils.isEmpty(zcs)) {
						zcs = "0";
					}
					if (StringUtils.isEmpty(ycs)) {
						ycs = "0";
					}
					Integer mcount = Integer.parseInt(zcs) + Integer.parseInt(ycs);
					if(mcount != 0) {
						whl = division(Integer.parseInt(zcs), mcount);
					}
					smap.put("whl", whl);
					
					zs = zs + mcount;
					zzcs = zzcs + Integer.parseInt(zcs);
					zycs = zycs + Integer.parseInt(ycs);				
				}	
				// 总计
				if(zs != 0) {
					zwhl = division(zzcs, zs);
				}
				
				footMap.put("0", "总计");
				footMap.put("1", "总计");
				footMap.put("2", "总计");
				footMap.put("3", String.valueOf(zzcs));
				footMap.put("4", String.valueOf(zycs));
				footMap.put("5", String.valueOf(zwhl));
			}
			
			
			String[] zdbm = {"areaname", "videoname","ipaddress","recordduration","norecordduration","whl"};
			String[] zdmc = {"行政区划", "监控点名称", "设备IP","录像正常数","录像异常数","录像完好率"};
			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());
			exportCommData(params, cells, (ArrayList)sList, footMap, Struts2Utils.getResponse());
		} catch (Exception e) {
			e.printStackTrace();
			iLog.error("YwcountuserrepairjobAction-exp_AreaOnline-error:" +e);
			
		}
	}
	
	public void exportCommData(Map map, ExcelCol[] headertxt, List<HashMap> list,Map footMap, HttpServletResponse responses) {
		OutputStream os = null;
		try {
			ExportEngine exportEngine = new ExportEngine();
			os = responses.getOutputStream();
			responses.reset();// 清空输出流
			String fileName = map.get("fileName").toString();
			fileName = ExportEngine.toUtf8String(fileName);
			responses.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xls");// 设定输出文件头
			responses.setContentType("application/msexcel");// 定义输出类型
			HSSFWorkbook workbook = new HSSFWorkbook();
			HSSFFont font = workbook.createFont();// 创建字体对象
			font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
			font.setFontName("黑体 ");// 设置字体
			// Sheet名称
			HSSFSheet sheet = workbook.createSheet(map.get("sheetName").toString());
			sheet.setDefaultColumnWidth((short) 14);// 默认列宽
			// 合并单元格,表头说明信息
			sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headertxt.length - 1));
			HSSFCellStyle cellStyle2 = exportEngine.setHeadRegionStyle(workbook);// 设置合并头部单元格样式
			// 创建第一行
			HSSFRow row2 = sheet.createRow(0);
			row2.setHeight((short) 400);
			HSSFCell cell2 = row2.createCell(0);
			cell2.setCellValue(map.get("header").toString());
			cell2.setCellStyle(cellStyle2);
			for (int k = 1; k < headertxt.length; k++) {
				row2.createCell(k).setCellStyle(cellStyle2);
			}
			HSSFCellStyle cellStyle = exportEngine.setRowsRegionStyle(workbook);// 设置合并行单元格样式
			// 创建第二行，生成表头
			HSSFRow row = sheet.createRow(1);
			if (headertxt != null && headertxt.length > 0) {
				short j = 0;
				for (ExcelCol s : headertxt) {
					HSSFCell cell1 = row.createCell(j);
					cell1.setCellValue(headertxt[j].getColName());
					cell1.setCellStyle(cellStyle);
					j = (short) (j + 1);
				}
			}
			HSSFCellStyle cs = exportEngine.setCommonStyle(workbook);// 设置普通单元格样式
			// 生成数据
			for (int i = 0; i < list.size(); i++) {
				HSSFRow datarow = sheet.createRow((short) i + 2);
				Map mp = list.get(i);
				for (short k = 0; k < headertxt.length; k++) {
					HSSFCell datacell = datarow.createCell(k);
					datacell.setCellStyle(cs);
					datacell.setCellValue(mp.get(headertxt[k].getColKey()) == null ? "" : mp.get(headertxt[k].getColKey()) + "");
				}
			}
			int lastrowNum = list.size() + 2;
			if(RHUtil.isNotEmpty(footMap)) {
				sheet.addMergedRegion(new CellRangeAddress(lastrowNum, lastrowNum, 0, 2));
				HSSFRow datarow = sheet.createRow(lastrowNum);
				/*HSSFCell lastcell = datarow.createCell(0);
				lastcell.setCellValue("总计");
				lastcell.setCellStyle(cs);*/
				for(int m=0; m<footMap.size(); m++) {
					HSSFCell datacell = datarow.createCell(m);
					datacell.setCellStyle(cs);
					datacell.setCellValue((String)footMap.get(String.valueOf(m)));
				}
			}
			workbook.write(os);
			os.flush();    
			iLog.info("成功导出Excel!");
			// 写入文件
		} catch (Exception ex) {
			iLog.error("导出Excel出错了", ex);
		} finally {
			try {
				os.close();
			} catch (Exception ex) {
				iLog.error("关闭os失败", ex);
			}
		}
	}

	
	// 点位录像情况统计                           /end 
	/**
     * 转成百分数
     * 当前数除以总数
     * @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;
    }
	/**
	 * 导入Excel
	 */
	/*
	//@OperateType(value = LogConstants.LOG_IMPORT ,info ="imp_Ywcountvideoappraise")
	public String imp_Ywcountvideoappraise(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("YwcountvideoappraiseAction-imp_Ywcountvideoappraise-error:" +e);
			e.printStackTrace();
		}		
		return rs;
	}
	*/
}
