package com.ruoyi.hv.service.impl;

import java.io.OutputStream;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.springframework.stereotype.Service;

import com.ruoyi.hv.domain.DHeightValuePatentDetail;
import com.ruoyi.hv.service.IDHeightValuePatentDetailExcel;
import com.ruoyi.hv.vo.RzgClassifiedStatisticsInfoVo;
import com.ruoyi.report.service.impl.AbstractExcelExp;


@Service
public class DHeightValuePatentDetailExcelImpl extends AbstractExcelExp implements IDHeightValuePatentDetailExcel {

	@Override
	public void doExport(OutputStream out, DHeightValuePatentDetail req, List<DHeightValuePatentDetail> list) {

		// TODO Auto-generated method stub


		// TODO Auto-generated method stub
		SXSSFWorkbook wb = new SXSSFWorkbook(500);

		try {
			// response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
			// response.setCharacterEncoding("utf-8");
			short headHeight = 30 * 20;
			int minWidth = "四个字宽".getBytes().length * 256;
			int maxWidth = minWidth;
			String title = "高价值统计-专利详情";

			int dataHeight = 30;

			SXSSFSheet sheet = wb.createSheet();
			wb.setSheetName(0, title);
			sheet.trackAllColumnsForAutoSizing();

			Map<String, XSSFCellStyle> styles = createStyles(wb);

			Row titleRow0 = sheet.createRow(0);
			titleRow0.setHeightInPoints(dataHeight);
			Cell titleCell = titleRow0.createCell(0);
			titleCell.setCellStyle(styles.get("title"));
			titleCell.setCellValue(title);

			int titleSize = 25;

			// 合并单元格语法： 开始行、结束行、开始列、结束列
			// 对应代码：new CellRangeAddress(startRowIndex, rowIndex - 1, i, i);
			sheet.addMergedRegion(new CellRangeAddress(titleRow0.getRowNum(), titleRow0.getRowNum(),0, titleSize));
			
			
			Row titleRow1 = sheet.createRow(1);
			titleRow1.setHeightInPoints(dataHeight/2*3);
			
			XSSFCellStyle header2=styles.get("header2");
			int column=0;
			createCell(titleRow1, column++, "主建", header2);
			createCell(titleRow1, column++, "数据类型", header2);
			createCell(titleRow1, column++, "申请号", header2);
			createCell(titleRow1, column++, "申请日", header2);
			createCell(titleRow1, column++, "第一申请人(原始专利权人)", header2);
			createCell(titleRow1, column++, "申请人地址", header2);
			createCell(titleRow1, column++, "省份(原始)", header2);
			createCell(titleRow1, column++, "州市(原始)", header2);
			createCell(titleRow1, column++, "区县(原始)", header2);
			createCell(titleRow1, column++, "省份", header2);
			createCell(titleRow1, column++, "州市", header2);
			createCell(titleRow1, column++, "区县", header2);
			createCell(titleRow1, column++, "当前权利状态", header2);
			createCell(titleRow1, column++, "高价值(出版社)", header2);
			createCell(titleRow1, column++, "战略性新兴产业", header2);
			createCell(titleRow1, column++, "在海外有同族专利", header2);
			createCell(titleRow1, column++, "维护年限超十年", header2);
			createCell(titleRow1, column++, "存在质押记录", header2);
			createCell(titleRow1, column++, "获取国家科技奖或者中国专利奖", header2);
			createCell(titleRow1, column++, "战略性新兴产业(局)", header2);
			createCell(titleRow1, column++, "在海外有同族专利(局)", header2);
			createCell(titleRow1, column++, "维护年限超十年(局)", header2);
			createCell(titleRow1, column++, "存在质押记录(局)", header2);
			createCell(titleRow1, column++, "获取国家科技奖或者中国专利奖(局)", header2);
			createCell(titleRow1, column++, "高价值(局)", header2);
			createCell(titleRow1, column++, "高价值(局)数据批次", header2);

			
			autoColumnWidthForChineseChar(sheet, 0,titleSize, minWidth,maxWidth);
			// 冻结
			sheet.createFreezePane(0, 2, 0, 2);
			
			
			for(int i=0;i<list.size();i++) {
				
				DHeightValuePatentDetail vo=list.get(i);
				Row dataRow = sheet.createRow(2+i);
				dataRow.setHeightInPoints(dataHeight);
				
				column=0;
				XSSFCellStyle dataStyle=styles.get("data");
				createCell(dataRow, column++, vo.getId(), dataStyle);
				
				String dataType="";
				if("act".equals(vo.getDataType())) {
					dataType="有效";
				}else if("auth".equals(vo.getDataType())) {
					dataType="授权";
				}else if("pub".equals(vo.getDataType())) {
					dataType="公开";
				}
				createCell(dataRow, column++, dataType, dataStyle);
				
				createCell(dataRow, column++, vo.getAppNumber(), dataStyle);
				
				createCell(dataRow, column++, vo.getAppDate(), dataStyle);
				createCell(dataRow, column++, vo.getAppli(), dataStyle);
				createCell(dataRow, column++, vo.getAppliAddress(), dataStyle);
				createCell(dataRow, column++, vo.getAppliProvince(), dataStyle);
				createCell(dataRow, column++, vo.getAppliCity(), dataStyle);
				createCell(dataRow, column++, vo.getAppliCounty(), dataStyle);
				createCell(dataRow, column++, vo.getModifyAppliProvince(), dataStyle);
				createCell(dataRow, column++, vo.getModifyAppliCity(), dataStyle);
				createCell(dataRow, column++, vo.getModifyAppliCounty(), dataStyle);
				
				String status=vo.getStatus();;
				String statusCode=vo.getStatus();
				if("10".equals(statusCode)) {
					status="有效";
				}else if("20".equals(statusCode)) {
					status="无效";
				}else if("30".equals(statusCode)) {
					status="公开";
				}
				createCell(dataRow, column++, status, dataStyle);
				
				String yes="";
				if("1".equals(vo.getHeightValuePress())) {
					yes="是";
				}else if("2".equals(vo.getHeightValuePress())) {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getHvSeisPress())) {
					yes="是";
				}else if("2".equals(vo.getHvSeisPress())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getHvHaveOverseasPress())) {
					yes="是";
				}else if("2".equals(vo.getHvHaveOverseasPress())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				
				yes="";
				if("1".equals(vo.getHvKeep10Press())) {
					yes="是";
				}else if("2".equals(vo.getHvKeep10Press())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				
				yes="";
				if("1".equals(vo.getHvHighPledgePress())) {
					yes="是";
				}else if("2".equals(vo.getHvHighPledgePress())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getHvTechnologyAwardPress())) {
					yes="是";
				}else if("2".equals(vo.getHvTechnologyAwardPress())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				
				yes="";
				if("1".equals(vo.getHvSeisDept())) {
					yes="是";
				}else if("2".equals(vo.getHvSeisDept())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getHvHaveOverseasDept())) {
					yes="是";
				}else if("2".equals(vo.getHvHaveOverseasDept())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);

				

				yes="";
				if("1".equals(vo.getHvKeep10Dept())) {
					yes="是";
				}else if("2".equals(vo.getHvKeep10Dept())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				
				yes="";
				if("1".equals(vo.getHvHighPledgeDept())) {
					yes="是";
				}else if("2".equals(vo.getHvHighPledgeDept())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getHvTechnologyAwardDept())) {
					yes="是";
				}else if("2".equals(vo.getHvTechnologyAwardDept())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getHeightValueDept())) {
					yes="是";
				}else if("2".equals(vo.getHeightValueDept())) {
					yes="否";
				}else {
					yes="否";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				yes="";
				if("1".equals(vo.getLicCounts())) {
					yes="";
				}else if("2".equals(vo.getLicCounts())) {
					yes="";
				}else {
					yes="";
				}
				createCell(dataRow, column++, yes, dataStyle);
				
				
				
				
			}
			
			
		} finally {
			writeToOut(wb, out);
		}
	
	
	}
	
	

}
