package cn.com.countrygarden.bi.main.controller.project.imports;

import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;

import com.mysql.fabric.xmlrpc.base.Data;

import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.dup.SiteResources;
import cn.com.countrygarden.bi.main.model.project.BiEmergency;
import cn.com.countrygarden.bi.main.model.project.ProjectSignInfo;
	/**
	 * 
	*突发事件导出功能 创建表头表体以及表格样式
	* @author wangyanlei
	* @Time 2018年8月15日 16:22:07
	* @version1.0
	 */
public class ProjectEmergencyImports {
	public static final String PATH = "/excel/sing.xlsx";
	
	 /**
	  * 
	 *突发事件导出功能 表头
	 * @author wangyanlei
	 * @Time 2018年8月15日 16:22:07
	 * @version1.0
	  */
	 public void createHeader(Workbook workbook, Sheet sheet) {
		  
		 
	     CellRangeAddress cra=new CellRangeAddress(0,0,0,10);
	     sheet.addMergedRegion(cra);//起始行号，终止行号， 起始列号，终止列号			
    	 int rowIndex = 1;
         CellStyle headerStyle = createHeaderStyle(workbook);
         CellStyle firstStyle = createFirstStyle(workbook);
         Row row = sheet.createRow(rowIndex);
         Row row0 = sheet.createRow(0);
         //Row row1 = sheet.createRow(rowIndex);
         row0.setHeight((short) (450 * 2));
         row.setHeight((short) (350 * 2));
        // row1.setHeight((short) (450 * 2));
         createCell("突发事件上报统计", firstStyle, row0, 0);
         sheet.setColumnWidth(0, 22 * 256);
         sheet.setColumnWidth(1, 22 * 256);
         sheet.setColumnWidth(2, 22 * 256);
         sheet.setColumnWidth(3, 22 * 256);
         sheet.setColumnWidth(8, 22 * 256);
         sheet.setColumnWidth(9, 22 * 256);
         sheet.setColumnWidth(10, 22 * 256);
     
         createCell("区域", headerStyle, row, 0);
         createCell("项目", headerStyle, row, 1);
         createCell("突发事件一级类别", headerStyle, row, 2);
         createCell("突发事件二级分类", headerStyle, row, 3);
         createCell("主题", headerStyle, row, 4);
         createCell("事发日期", headerStyle, row, 5);
         createCell("是否伤亡", headerStyle, row, 6);
         createCell("是否损失", headerStyle, row, 7);
         createCell("事件简述", headerStyle, row, 8);
         createCell("应急措施", headerStyle, row, 9);
         createCell("风险提示", headerStyle, row, 10);
    }
	 //第一行样式
//	  public CellStyle createFirstStyle(Workbook workbook) {
//		  CellStyle firstStyle = workbook.createCellStyle();
//		  firstStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//		  firstStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
//	  }
	 
	   public CellStyle createHeaderStyle(Workbook workbook) {
	        CellStyle headerStyle = workbook.createCellStyle();
	        headerStyle.setAlignment(HorizontalAlignment.CENTER);
	        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	        //headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
	        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	        headerStyle.setWrapText(true);
	        headerStyle.setBorderBottom(BorderStyle.THIN); //下边框
	        headerStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderLeft(BorderStyle.THIN);//左边框
	        headerStyle.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderTop(BorderStyle.THIN);//上边框
	        headerStyle.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderRight(BorderStyle.THIN);//右边框
	        headerStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());

	        return headerStyle;
	    }
	   public CellStyle createFirstStyle(Workbook workbook) {
	        CellStyle headerStyle = workbook.createCellStyle();
	        headerStyle.setAlignment(HorizontalAlignment.CENTER);
	        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
	        //headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
   /*       headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
	        headerStyle.setWrapText(true);//自动换行
//	        headerStyle.setBorderBottom(BorderStyle.THIN); //下边框
//	        headerStyle.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        headerStyle.setBorderLeft(BorderStyle.THIN);//左边框
	        headerStyle.setLeftBorderColor(IndexedColors.AUTOMATIC.getIndex());
	        headerStyle.setBorderTop(BorderStyle.THIN);//上边框
	        headerStyle.setTopBorderColor(IndexedColors.AUTOMATIC.getIndex());
//	        headerStyle.setBorderRight(BorderStyle.THIN);//右边框
//	        headerStyle.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
*/	        Font fontStyle = workbook.createFont(); // 字体样式
			fontStyle.setBold(true); // 加粗
			fontStyle.setFontName("黑体"); // 字体
			fontStyle.setFontHeightInPoints((short) 22);		
			headerStyle.setFont(fontStyle);
	        return headerStyle;
	    }
	   public void createCell(String value, CellStyle style, Row row, int col) {
	        Cell cell = row.createCell(col);
	        cell.setCellStyle(style);
	        if (value != null) {
	            cell.setCellValue(value);
	        }
	    }

	    public CellStyle createBodyStyle(Workbook workbook) {
	        CellStyle style = workbook.createCellStyle();
	        style.setAlignment(HorizontalAlignment.CENTER);
	        style.setVerticalAlignment(VerticalAlignment.CENTER);
	        style.setWrapText(true);
	        style.setBorderBottom(BorderStyle.THIN); //下边框
	        style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        style.setBorderLeft(BorderStyle.THIN);//左边框
	        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        style.setBorderTop(BorderStyle.THIN);//上边框
	        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        style.setBorderRight(BorderStyle.THIN);//右边框
	        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
	        return style;
	    }
	    /**
		 * 表体
		 * @param pList
		 * @param workbook
		 * @param sheet
		 */
		public void createBody(PageData p, Workbook workbook, Sheet sheet) {
			  CellStyle style = createBodyStyle(workbook);
		        int rowIndex = 2;
			List<BiEmergency> list=(List) p.getData();
			 for (BiEmergency data : list ){
//				 sheet.addMergedRegion(new CellRangeAddress(rowIndex,rowIndex,4,5));//起始行号，终止行号， 起始列号，终止列号
//				 sheet.addMergedRegion(new CellRangeAddress(rowIndex,rowIndex,8,10));
				 Row row = sheet.createRow(rowIndex);
				 row.setHeight((short) (700 * 2));
	        	  createCell(data.getOrgName(), style, row, 0);
	        	  createCell(data.getCommName(), style, row, 1);
	        	  createCell(data.getLevelOne(), style, row, 2);
	        	  createCell(data.getLevelTwo(), style, row, 3);
	        	  createCell(data.getTheme(), style, row, 4);
	        	  createCell(data.getHappenTime(), style, row, 5);
	        	  createCell(data.getIsCasualties(), style, row, 6);
	        	  createCell(data.getIsProperty(), style, row, 7);	        	  
	        	  createCell(data.getSketch(), style, row, 8);
	        	  createCell(data.getRisk(), style, row, 9);
	        	  createCell(data.getMeasure(), style, row, 10);

	        	  rowIndex++;
			 }
		}
}
