package com.ruoyi.indica.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.indica.domain.CIndicationInfo;
import com.ruoyi.indica.service.ICIndicationInfoExcel;
import com.ruoyi.indica.service.ICIndicationInfoService;
import com.ruoyi.indica.vo.CIndicationInfoDTO;
import com.ruoyi.indica.vo.CIndicationInfoVO;

/**
 * 地理标志Controller
 *
 * @author ruoyi
 * @date 2023-04-28
 */
@RestController
@RequestMapping("/indica/cIndicationInfo")
public class CIndicationInfoController extends BaseController {
    private final ICIndicationInfoService cIndicationInfoService;

    @Autowired
    private  ICIndicationInfoExcel cIndicationInfoExcel;
    public CIndicationInfoController(ICIndicationInfoService cIndicationInfoService) {
        this.cIndicationInfoService = cIndicationInfoService;
    }
    
    
	@PreAuthorize("@ss.hasPermi('trade:cTrademark:list')")
	@GetMapping("/listReportGrowth")
	public AjaxResult listReportGrowth(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		String sumType = "province";
		if (StringUtils.isBlank(cIndicationInfo.getProvince())
				|| StringUtils.isBlank(cIndicationInfo.getAppliCity()) 
				||"null".equals(cIndicationInfo.getAppliCity()) ) {
			sumType = "province";
		} else if (StringUtils.isNotBlank(cIndicationInfo.getAppliCity())
				&& "all".equals(cIndicationInfo.getAppliCity())) {
			sumType = "city";
		} else if (StringUtils.isNotBlank(cIndicationInfo.getAppliCity())
				&& !"all".equals(cIndicationInfo.getAppliCity())  
				&& !"null".equals(cIndicationInfo.getAppliCity())  ) {
			sumType = "city";
			if(!"53".equals(cIndicationInfo.getAppliCity().trim())) {
				cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
			}
			if(StringUtils.isNotBlank(cIndicationInfo.getAppliCounty())
					&& "null".equals(cIndicationInfo.getAppliCounty())){
				sumType = "city";
				
			}else if(StringUtils.isNotBlank(cIndicationInfo.getAppliCounty())
					&& "all".equals(cIndicationInfo.getAppliCounty())){
				sumType = "area";
			}
		}
		cIndicationInfo.setSumType(sumType);
		List<CIndicationInfoDTO> list = cIndicationInfoService.listReportGrowth(cIndicationInfo);
		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportGrowth(out, cIndicationInfo, list);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
		
		return AjaxResult.success(list);
		
		
		
	}
	
	

	@PreAuthorize("@ss.hasPermi('trade:cTrademark:list')")
	@PostMapping("/exportReportGrowth")
	public void exportReportGrowth(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		String sumType = "province";
		if (StringUtils.isBlank(cIndicationInfo.getProvince())
				|| StringUtils.isBlank(cIndicationInfo.getAppliCity()) 
				||"null".equals(cIndicationInfo.getAppliCity()) ) {
			sumType = "province";
		} else if (StringUtils.isNotBlank(cIndicationInfo.getAppliCity())
				&& "all".equals(cIndicationInfo.getAppliCity())) {
			sumType = "city";
		} else if (StringUtils.isNotBlank(cIndicationInfo.getAppliCity())
				&& !"all".equals(cIndicationInfo.getAppliCity())  
				&& !"null".equals(cIndicationInfo.getAppliCity())  ) {
			sumType = "city";
			if(!"53".equals(cIndicationInfo.getAppliCity().trim())) {
				cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
			}
			if(StringUtils.isNotBlank(cIndicationInfo.getAppliCounty())
					&& "null".equals(cIndicationInfo.getAppliCounty())){
				sumType = "city";
				
			}else if(StringUtils.isNotBlank(cIndicationInfo.getAppliCounty())
					&& "all".equals(cIndicationInfo.getAppliCounty())){
				sumType = "area";
			}
		}
		cIndicationInfo.setSumType(sumType);
		List<CIndicationInfoDTO> list = cIndicationInfoService.listReportGrowth(cIndicationInfo);
//		return AjaxResult.success(list);
		

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportGrowth(response.getOutputStream(), cIndicationInfo, list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
		
		
		
		
		
	}
	
	
    /**
     * 01-地标商标
     * @param cTrademark
     * @return
     */
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@GetMapping("/listReportMark")
	public AjaxResult listReportMark(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期:"+cIndicationInfo.getEndDate());
		
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		
		String beginDate=beginYear+month+"01";
		endDate=endYear+month+"31";
		
		
		String maxEndDate = DateUtils.getMaxdayInMonth(endYear+month);
		
		List<String>pubYears=new ArrayList<String>();
		for(int y=beginYear;y<=endYear;y++) {
			pubYears.add(y+"");
		}
		cIndicationInfo.setPubYears(pubYears);
		cIndicationInfo.setSumYearDate(maxEndDate);
		
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		CIndicationInfoDTO dto = cIndicationInfoService.listReportMark(cIndicationInfo);
		
		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportMark(out, cIndicationInfo, dto);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
		
		return AjaxResult.success(dto);
	}
	
	

    /**
     * 01-地标商标
     * @param cTrademark
     * @return
     */
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@PostMapping("/exportReportMark")
	public void exportReportMark(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}

		cIndicationInfo.setCountTimeStr("统计时期:"+cIndicationInfo.getEndDate());
		
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
		int beginYear=endYear-5;
		String beginDate=beginYear+month+"01";
		endDate=endYear+month+"31";
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		
		
		
		
		String maxEndDate = DateUtils.getMaxdayInMonth(endYear+month);
		
		List<String>pubYears=new ArrayList<String>();
		for(int y=beginYear;y<=endYear;y++) {
			pubYears.add(y+"");
		}
		cIndicationInfo.setPubYears(pubYears);
		cIndicationInfo.setSumYearDate(maxEndDate);
		
		
		CIndicationInfoDTO dto = cIndicationInfoService.listReportMark(cIndicationInfo);
//		return AjaxResult.success(dto);
		


        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportMark(response.getOutputStream(), cIndicationInfo, dto);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
		
		
	}
	
	
	/**
     * 02-地标产品
     * @param cTrademark
     * @return
     */
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@GetMapping("/listReportHzqy")
	public AjaxResult listReportHzqy(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		String beginDate=beginYear+month+"01";
		endDate=endYear+month+"31";
		
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		CIndicationInfoDTO dto = cIndicationInfoService.listReportHzqy(cIndicationInfo);
		
		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportHzqy(out, cIndicationInfo, dto);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
		return AjaxResult.success(dto);
	}
	
	

	/**
     * 02-地标产品
     * @param cTrademark
     * @return
     */
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@PostMapping("/exportReportHzqy")
	public void exportReportHzqy(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
		int beginYear=endYear-5;
		String beginDate=beginYear+month+"01";
		endDate=endYear+month+"31";
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		CIndicationInfoDTO dto = cIndicationInfoService.listReportHzqy(cIndicationInfo);
//		return AjaxResult.success(dto);
		


        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportHzqy(response.getOutputStream(), cIndicationInfo, dto);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
		
	}
	
	
//	04-地标商标全国排名
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@GetMapping("/listReportMarkRank")
	public AjaxResult listReportMarkRank(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
//		int beginYear=endYear-5;
//		endDate=endYear+month+"15";
//		String beginDate=beginYear+month+"16";
		int beginYear=endYear-70;//换成一个很早的时间 20230927
		String beginDate=beginYear+month+"01";
		endDate=DateUtils.getMaxdayInMonth(endYear+month);
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		List<CIndicationInfoVO>list = cIndicationInfoService.listReportMarkRank(cIndicationInfo);
		
////		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportMarkRank(out, cIndicationInfo, list);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		
//		
		return AjaxResult.success(list);
	}
	
	

//	04-地标商标全国排名
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@PostMapping("/exportReportMarkRank")
	public void exportReportMarkRank(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
//		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		int beginYear=endYear-70;
		String beginDate=beginYear+month+"01";
		endDate=DateUtils.getMaxdayInMonth(endYear+month);
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		List<CIndicationInfoVO>list = cIndicationInfoService.listReportMarkRank(cIndicationInfo);
//		return AjaxResult.success(list);


        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportMarkRank(response.getOutputStream(), cIndicationInfo, list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
	}
	
	
//	05-地标产品全国排名
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@GetMapping("/listReportAddrRank")
	public AjaxResult listReportAddrRank(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
//		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		int beginYear=endYear-70;
		String beginDate=beginYear+month+"01";
		endDate=DateUtils.getMaxdayInMonth(endYear+month);
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		List<CIndicationInfoVO>list = cIndicationInfoService.listReportAddrRank(cIndicationInfo);
		
		
//		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportAddrRank(out, cIndicationInfo, list);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//		
		
		return AjaxResult.success(list);
	}
	
	

	
//	05-地标产品全国排名
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@PostMapping("/exportReportAddrRank")
	public void exportReportAddrRank(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
//		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		
		int beginYear=endYear-70;
		String beginDate=beginYear+month+"01";
		endDate=DateUtils.getMaxdayInMonth(endYear+month);
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		List<CIndicationInfoVO>list = cIndicationInfoService.listReportAddrRank(cIndicationInfo);
//		return AjaxResult.success(list);
		

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportAddrRank(response.getOutputStream(), cIndicationInfo, list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
	}
	
//	06-农产品地标全国排名
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@GetMapping("/listReportFarmRank")
	public AjaxResult listReportFarmRank(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
//		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		
		int beginYear=endYear-70;
		String beginDate=beginYear+month+"01";
		endDate=DateUtils.getMaxdayInMonth(endYear+month);
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		List<CIndicationInfoVO>list = cIndicationInfoService.listReportFarmRank(cIndicationInfo);
		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportFarmRank(out, cIndicationInfo, list);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
		
		return AjaxResult.success(list);
	}

//	06-农产品地标全国排名
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@PostMapping("/exportReportFarmRank")
	public void exportReportFarmRank(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
//		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		
		int beginYear=endYear-70;
		String beginDate=beginYear+month+"01";
		endDate=DateUtils.getMaxdayInMonth(endYear+month);
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		List<CIndicationInfoVO>list = cIndicationInfoService.listReportFarmRank(cIndicationInfo);
//		return AjaxResult.success(list);
		

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportFarmRank(response.getOutputStream(), cIndicationInfo, list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
		
	}
	
	
	  
    /**
     * 03-农产品地理标志
     * @param cTrademark
     * @return
     */
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@GetMapping("/listReportFarm")
	public AjaxResult listReportFarm(CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
		int beginYear=endYear-5;
//		String beginDate=beginYear+month+"16";
//		endDate=endYear+month+"15";
		String beginDate=beginYear+month+"01";
		endDate=endYear+month+"31";
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		CIndicationInfoDTO dto = cIndicationInfoService.listReportFarm(cIndicationInfo);
		
		
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.exportReportFarm(out, cIndicationInfo, dto);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
		
		return AjaxResult.success(dto);
	}
	
	

    /**
     * 03-农产品地理标志
     * @param cTrademark
     * @return
     */
	@PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
	@PostMapping("/exportReportFarm")
	public void exportReportFarm(HttpServletResponse response,CIndicationInfo cIndicationInfo) {
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getYear()) 
				&& StringUtils.isNotBlank(cIndicationInfo.getMonth()) ) {
			cIndicationInfo.setEndDate(cIndicationInfo.getYear()+cIndicationInfo.getMonth());
		}
		if(StringUtils.isBlank(cIndicationInfo.getEndDate()) ) {
			cIndicationInfo.setEndDate(new SimpleDateFormat("yyyy").format(new Date())+"12");
		}
		cIndicationInfo.setCountTimeStr("统计时期"+cIndicationInfo.getEndDate());
		String endDate=cIndicationInfo.getEndDate().replace("-", "");
		String month=endDate.substring(4,6);
		int endYear=Integer.parseInt(cIndicationInfo.getEndDate().substring(0,4));
		int beginYear=endYear-5;
		String beginDate=beginYear+month+"01";
		endDate=endYear+month+"31";
		
		cIndicationInfo.setBeginDate(beginDate);
		cIndicationInfo.setEndDate(endDate);
		
		if(StringUtils.isNotBlank(cIndicationInfo.getAppliCity()) && !"53".equals(cIndicationInfo.getAppliCity().trim())) {
			cIndicationInfo.setCityCode(cIndicationInfo.getAppliCity().trim());
		}
		CIndicationInfoDTO dto = cIndicationInfoService.listReportFarm(cIndicationInfo);
//		return AjaxResult.success(dto);
		

        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
		response.setCharacterEncoding("utf-8");

		try {

			cIndicationInfoExcel.exportReportFarm(response.getOutputStream(), cIndicationInfo, dto);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			logger.error("导出失败," + e.getMessage(), e);
			throw new RuntimeException("导出失败，请联系管理员", e);
		}
	}
	
	
//	hzqy_counts

    /**
     * 查询地理标志列表
     *
     * @param cIndicationInfo 地理标志
     * @return 地理标志集合
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CIndicationInfo cIndicationInfo) {
        startPage();
        
        List<CIndicationInfo> list = cIndicationInfoService.queryList(cIndicationInfo);
        
        
//		OutputStream out = null;
//		try {
//			out = new FileOutputStream(new File("D:\\temp\\exp.xlsx"));
//			cIndicationInfoExcel.export3(out, cIndicationInfo, list);
//
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} finally {
//			try {
//				out.close();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		
        return getDataTable(list);
    }


    /**
     * 导出地理标志列表
     *
     * @param cIndicationInfo 地理标志
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
//    @Log(title = "地理标志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CIndicationInfo cIndicationInfo) {
//    	 startPage();
         List<CIndicationInfo> list = cIndicationInfoService.queryList(cIndicationInfo);
         
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
 		response.setCharacterEncoding("utf-8");

 		try {

 			cIndicationInfoExcel.export(response.getOutputStream(), cIndicationInfo, list);
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 			logger.error("导出失败," + e.getMessage(), e);
 			throw new RuntimeException("导出失败，请联系管理员", e);
 		}
 		
         
    }
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
//    @Log(title = "地理标志", businessType = BusinessType.EXPORT)
    @PostMapping("/export2")
    public void export2(HttpServletResponse response, CIndicationInfo cIndicationInfo) {
//    	 startPage();
         List<CIndicationInfo> list = cIndicationInfoService.queryList(cIndicationInfo);
         
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
 		response.setCharacterEncoding("utf-8");

 		try {

 			cIndicationInfoExcel.export2(response.getOutputStream(), cIndicationInfo, list);
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 			logger.error("导出失败," + e.getMessage(), e);
 			throw new RuntimeException("导出失败，请联系管理员", e);
 		}
 		
         
    }
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
//    @Log(title = "地理标志", businessType = BusinessType.EXPORT)
    @PostMapping("/export3")
    public void export3(HttpServletResponse response, CIndicationInfo cIndicationInfo) {
//    	 startPage();
         List<CIndicationInfo> list = cIndicationInfoService.queryList(cIndicationInfo);
         
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
 		response.setCharacterEncoding("utf-8");

 		try {

 			cIndicationInfoExcel.export3(response.getOutputStream(), cIndicationInfo, list);
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 			logger.error("导出失败," + e.getMessage(), e);
 			throw new RuntimeException("导出失败，请联系管理员", e);
 		}
 		
         
    }
    /**
     * 获取地理标志详细信息
     *
     * @param id 主键id
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cIndicationInfoService.getById(id));
    }


    /**
     * 新增地理标志信息
     *
     * @param cIndicationInfo 地理标志
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:add')")
    @Log(title = "地理标志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CIndicationInfo cIndicationInfo) {
        return toAjax(cIndicationInfoService.save(cIndicationInfo));
    }


    /**
     * 修改地理标志信息
     *
     * @param cIndicationInfo 地理标志
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:edit')")
    @Log(title = "地理标志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CIndicationInfo cIndicationInfo) {
        return toAjax(cIndicationInfoService.updateById(cIndicationInfo));
    }


    /**
     * 删除地理标志信息
     *
     * @param ids 主键ids
     * @return 结果
     * @date 2023-04-28
     */
    @PreAuthorize("@ss.hasPermi('indica:cIndicationInfo:remove')")
    @Log(title = "地理标志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cIndicationInfoService.removeByIds(Arrays.asList(ids)));
    }


}
