package com.ruoyi.reportpub.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.ApplicantType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.report.vo.ClassStatisticsInfoVo;
import com.ruoyi.reportpub.domain.RzgClassStatisticsInfo;
import com.ruoyi.reportpub.mapper.RzgClassStatisticsInfoMapper;
import com.ruoyi.reportpub.service.IRzgClassStatisticsInfoService;
import com.ruoyi.system.domain.BladeRegion;
import com.ruoyi.system.service.IBladeRegionService;
import com.ruoyi.utils.BladeRegionUtils;

/**
 * 专利公开-分类统计Service业务层处理
 *
 * @author ruoyi
 * @date 2023-03-27
 */
@Service
public class RzgClassStatisticsInfoServiceImpl extends ServiceImpl<RzgClassStatisticsInfoMapper, RzgClassStatisticsInfo>
		implements IRzgClassStatisticsInfoService {
	@Autowired
	private IBladeRegionService bladeRegionService;
	@Autowired
	private RzgClassStatisticsInfoMapper rzgClassStatisticsInfoMapper;

	private static final Logger logger = LoggerFactory.getLogger(RzgClassStatisticsInfoServiceImpl.class);

	public Long sumByRank(RzgClassStatisticsInfo rzgClassStatisticsInfo) {
		return rzgClassStatisticsInfoMapper.sumByRank(rzgClassStatisticsInfo);
	}
	public List<ClassStatisticsInfoVo> listByReport(RzgClassStatisticsInfo rzgClassStatisticsInfo) {

		// TODO Auto-generated method stub
		String year = rzgClassStatisticsInfo.getYear();
		if (StringUtils.isBlank(year)) {
			year = "2022";
		}

		String cityCode = null;
		List<String> applicantTypesList = rzgClassStatisticsInfo.getApplicantTypesList();

		if (StringUtils.isNotBlank(rzgClassStatisticsInfo.getCityCode())
				&& !"53".equals(rzgClassStatisticsInfo.getCityCode())) {
			cityCode = rzgClassStatisticsInfo.getCityCode().trim();
		}
		rzgClassStatisticsInfo.setCityCode(cityCode);
		
		boolean retEmpty=false;
		if (StringUtils.isNotBlank(rzgClassStatisticsInfo.getCityCode()) && !"53".equals(rzgClassStatisticsInfo.getCityCode())) {
			cityCode = rzgClassStatisticsInfo.getCityCode().trim();
			if(SecurityUtils.isNeedFilterByCityCode()) {
				String cc=SecurityUtils.needFilterByCityCode();
				if(!cc.equals(cityCode) ) {
					retEmpty=true;
				}
			}
		}else {
			if(SecurityUtils.isNeedFilterByCityCode()) {
				cityCode=SecurityUtils.needFilterByCityCode();
				rzgClassStatisticsInfo.setCityCode(cityCode);
			}
		}
		
		
		List<Map> mapList = new ArrayList<Map>();
		if(!retEmpty) {
			mapList = rzgClassStatisticsInfoMapper.listByReport(rzgClassStatisticsInfo);
		}


//		List<RzlClassStatisticsInfoVo> list = new ArrayList<RzlClassStatisticsInfoVo>();

		ClassStatisticsInfoVo total = new ClassStatisticsInfoVo();
		total.setYear(year);
		total.setTotalCnt(0L);
		total.setHigherSchool(0L);
		total.setResearchInstitute(0L);
		total.setEnterprise(0L);
		total.setInstitutions(0L);
		total.setIndividual(0L);
		total.setPatentType("总计");
		if (rzgClassStatisticsInfo.getCityCode() == null || "null".equals(rzgClassStatisticsInfo.getCityCode().trim())
				|| "".equals(rzgClassStatisticsInfo.getCityCode().trim())) {
			total.setAreaName("云南省");
		} else {
			BladeRegion bladeRegion = BladeRegionUtils.selectByCode(rzgClassStatisticsInfo.getCityCode());
			if (bladeRegion != null) {
				total.setAreaName(bladeRegion.getName());
			}
		}
//		list.add(total);

		// key:area  ,20231013 改成用 area_code
		Map<String, List<ClassStatisticsInfoVo>> areaMap = new LinkedHashMap<String, List<ClassStatisticsInfoVo>>();

		// key:areaName_type
		Map<String, ClassStatisticsInfoVo> areaTypeMap = new HashMap<String, ClassStatisticsInfoVo>();
		// key:type
		Map<String, ClassStatisticsInfoVo> typeTotalMap = new LinkedHashMap<String, ClassStatisticsInfoVo>();
		
		logger.debug("mapList总数:"+mapList.size());
		

		for (Map itemMap : mapList) {
			
			String areaName = null;

			StringBuffer sb = new StringBuffer();
//			if (itemMap.containsKey("area_name")) {
//				areaName = itemMap.get("area_name").toString();
//			} else {
//				areaName = "null";
//			}
			
			if (itemMap.containsKey("area_code")) {
				areaName = itemMap.get("area_code").toString();
			} else {
				areaName = "null";
			}

			sb.append(areaName);
			sb.append("_");

			String patentType = null;
			if (itemMap.containsKey("patent_type")) {
				patentType = itemMap.get("patent_type").toString();
			} else {
				patentType = "null";
			}
			sb.append(patentType);

			String alreadyKey = sb.toString();

			ClassStatisticsInfoVo vo = null;
			if (areaTypeMap.containsKey(alreadyKey)) {
				vo = areaTypeMap.get(alreadyKey);
			} else {
				vo = new ClassStatisticsInfoVo();
				// list.add(vo);
				vo.setPatentType(patentType);
				areaTypeMap.put(alreadyKey, vo);

				if (!areaMap.containsKey(areaName)) {
					List<ClassStatisticsInfoVo> areaList = new ArrayList<ClassStatisticsInfoVo>();
					areaMap.put(areaName, areaList);
					areaList.add(vo);
				} else {
					areaMap.get(areaName).add(vo);
				}

			}
			
			
			// 总计
			ClassStatisticsInfoVo typeTotal = null;
			if (typeTotalMap.containsKey(patentType)) {
				typeTotal = typeTotalMap.get(patentType);
			} else {
				typeTotal = new ClassStatisticsInfoVo();

//							if(areaName==null || "null".equals(areaName.trim())  || "".equals(areaName.trim()) ) {
				typeTotal.setPatentType(patentType);
				total.setYear(year);
//							}

				typeTotalMap.put(patentType, typeTotal);
			}

//			vo.setHigherSchool(vo.getHigherSchool() + getInt(itemMap, "higher_school"));
//			vo.setResearchInstitute(vo.getResearchInstitute() + getInt(itemMap, "research_institute"));
//			vo.setEnterprise(vo.getEnterprise() + getInt(itemMap, "enterprise"));
//			vo.setInstitutions(vo.getInstitutions() + getInt(itemMap, "institutions"));
//			vo.setIndividual(vo.getIndividual() + getInt(itemMap, "individual"));

			if (applicantTypesList.contains(ApplicantType.UNIVERSITIES.getTypeCode())) {
				int cnt=getInt(itemMap, "higher_school");
				
				vo.setHigherSchool(vo.getHigherSchool()+cnt);
				vo.setTotalCnt(vo.getTotalCnt() +cnt);
				total.setHigherSchool(total.getHigherSchool()+cnt);
				
				typeTotal.setTotalCnt(typeTotal.getTotalCnt() + cnt);
				typeTotal.setHigherSchool(typeTotal.getHigherSchool() + cnt);
			}
			if (applicantTypesList.contains(ApplicantType.SCIENTIFIC.getTypeCode())) {
				int cnt=getInt(itemMap, "research_institute");
				vo.setResearchInstitute(vo.getResearchInstitute()+cnt);
				vo.setTotalCnt(vo.getTotalCnt() + cnt);
				total.setResearchInstitute(total.getResearchInstitute() + cnt);
				
				typeTotal.setTotalCnt(typeTotal.getTotalCnt() + cnt);
				typeTotal.setResearchInstitute(typeTotal.getResearchInstitute() + cnt);
			}
			if (applicantTypesList.contains(ApplicantType.ENTERPRISE.getTypeCode())) {
				int cnt=+getInt(itemMap, "enterprise");
				vo.setEnterprise(vo.getEnterprise()+cnt);
				vo.setTotalCnt(vo.getTotalCnt() +cnt);
				total.setEnterprise(total.getEnterprise() +cnt);
				
				typeTotal.setTotalCnt(typeTotal.getTotalCnt() + cnt);
				typeTotal.setEnterprise(typeTotal.getEnterprise() + cnt);
			}

			if (applicantTypesList.contains(ApplicantType.GOVERNMENT.getTypeCode())) {
				int cnt=getInt(itemMap, "institutions");
				vo.setInstitutions(vo.getInstitutions()+cnt);
				vo.setTotalCnt(vo.getTotalCnt() + cnt);
				total.setInstitutions(total.getInstitutions() +cnt);
				
				typeTotal.setTotalCnt(typeTotal.getTotalCnt() + cnt);
				typeTotal.setInstitutions(typeTotal.getInstitutions() + cnt);
			}

			if (applicantTypesList.contains(ApplicantType.PERSONAL.getTypeCode())) {
				int cnt=getInt(itemMap, "individual");
				vo.setIndividual(vo.getIndividual()+cnt);
				vo.setTotalCnt(vo.getTotalCnt() +cnt);
				total.setIndividual(total.getIndividual() +cnt);
				
				typeTotal.setTotalCnt(typeTotal.getTotalCnt() + cnt);
				typeTotal.setIndividual(typeTotal.getIndividual() + cnt);
			}
//			logger.debug("循环第"+c+"条计录,vo:"+new Gson().toJson(vo));
			vo.setAreaName(getStr(itemMap, "area_name"));

//			total.setTotalCnt(total.getTotalCnt() + vo.getTotalCnt());
			
//			logger.debug("计算总数前：" + total.getHigherSchool() + "," + vo.getHigherSchool()+","+vo.getYear()+","+vo.getMonth()+","+vo.getAreaName());
			
//			logger.debug("计算总数后：" + total.getHigherSchool() + "," + vo.getHigherSchool());

//			list.add(vo);
			
			
//			typeTotal.setTotalCnt(typeTotal.getTotalCnt() + vo.getTotalCnt());
//
//			typeTotal.setHigherSchool(typeTotal.getHigherSchool() + vo.getHigherSchool());
//			typeTotal.setResearchInstitute(typeTotal.getResearchInstitute() + vo.getResearchInstitute());
//			typeTotal.setEnterprise(typeTotal.getEnterprise() + vo.getEnterprise());
//			typeTotal.setInstitutions(typeTotal.getInstitutions() + vo.getInstitutions());
//			typeTotal.setIndividual(typeTotal.getIndividual() + vo.getIndividual());

		}
		
//		Map<String, ClassStatisticsInfoVo> areaTypeMap
		long cc=0;
		for(ClassStatisticsInfoVo vo:areaTypeMap.values()) {
			cc=cc+vo.getHigherSchool();
		}
		logger.debug("allHigherSchool:"+cc);
		
//		Collections.sort(list,new VoComparator());

		// 处理小计
		for (Map.Entry<String, List<ClassStatisticsInfoVo>> ent : areaMap.entrySet()) {
			List<ClassStatisticsInfoVo> areaList = ent.getValue();

			ClassStatisticsInfoVo tot = new ClassStatisticsInfoVo();
			tot.setAreaName(ent.getKey());
			tot.setPatentType("总计");
			for (ClassStatisticsInfoVo vo : areaList) {

				tot.setTotalCnt(tot.getTotalCnt() + vo.getTotalCnt());
				tot.setHigherSchool(tot.getHigherSchool() + vo.getHigherSchool());
				tot.setResearchInstitute(tot.getResearchInstitute() + vo.getResearchInstitute());
				tot.setEnterprise(tot.getEnterprise() + vo.getEnterprise());
				tot.setInstitutions(tot.getInstitutions() + vo.getInstitutions());
				tot.setIndividual(tot.getIndividual() + vo.getIndividual());
			}

			areaList.add(0, tot);

		}

		// 结果列表
		List<ClassStatisticsInfoVo> list = new ArrayList<ClassStatisticsInfoVo>();
		
		if(!typeTotalMap.isEmpty()) {
			list.add(total);
		}
		
		list.addAll(typeTotalMap.values());
		Collections.sort(list, new ClassStatisticsInfoVo());

//		for (Map.Entry<String, List<ClassStatisticsInfoVo>> ent : areaMap.entrySet()) {
		 List<String>codes= BladeRegionUtils.sortedKey(areaMap.keySet());
		for (String code:codes) {
			List<ClassStatisticsInfoVo> list1 = areaMap.get(code);
//			List<ClassStatisticsInfoVo> list1 = ent.getValue();
			List<ClassStatisticsInfoVo> shorted = getShortEd(list1);

			for (ClassStatisticsInfoVo vo : shorted) {
				if (!"总计".equals(vo.getPatentType())) {
					vo.setAreaName("");
				}else {
					String areaName=BladeRegionUtils.getDistrictShortName(code);
					if(StringUtils.isNotBlank(areaName)) {
						vo.setAreaName(areaName);
					}
					
				}
				list.add(vo);
			}

		}

		// 处理总计
		for (ClassStatisticsInfoVo vo : list) {
			vo.setTotalCnt(0L);
			if (applicantTypesList.contains(ApplicantType.UNIVERSITIES.getTypeCode())) {
				vo.setTotalCnt(vo.getTotalCnt() + vo.getHigherSchool());
			}
			if (applicantTypesList.contains(ApplicantType.SCIENTIFIC.getTypeCode())) {
				vo.setTotalCnt(vo.getTotalCnt() + vo.getResearchInstitute());
			}
			if (applicantTypesList.contains(ApplicantType.ENTERPRISE.getTypeCode())) {
				vo.setTotalCnt(vo.getTotalCnt() + vo.getEnterprise());
			}

			if (applicantTypesList.contains(ApplicantType.GOVERNMENT.getTypeCode())) {
				vo.setTotalCnt(vo.getTotalCnt() + vo.getInstitutions());
			}

			if (applicantTypesList.contains(ApplicantType.PERSONAL.getTypeCode())) {
				vo.setTotalCnt(vo.getTotalCnt() + vo.getIndividual());
			}
		}

		return list;

	}

	private List<ClassStatisticsInfoVo> getShortEd(Collection<ClassStatisticsInfoVo> voList) {
		List<ClassStatisticsInfoVo> list = new ArrayList<ClassStatisticsInfoVo>();
		if (voList != null) {
			list.addAll(voList);
		}
		Collections.sort(list, new ClassStatisticsInfoVo());
		return list;
	}

//	public List<ClassStatisticsInfoVo> listByReport(RzgClassStatisticsInfo rzgClassStatisticsInfo) {
//		// TODO Auto-generated method stub
//		String year = rzgClassStatisticsInfo.getYear();
//
//		String cityCode = null;
//
//		if (StringUtils.isNotBlank(rzgClassStatisticsInfo.getCityCode())
//				&& !"53".equals(rzgClassStatisticsInfo.getCityCode())) {
//			cityCode = rzgClassStatisticsInfo.getCityCode().trim();
//		}
//		rzgClassStatisticsInfo.setCityCode(cityCode);
//		
//		List<Map> mapList = rzgClassStatisticsInfoMapper.listByReport(rzgClassStatisticsInfo);
//
////		List<RzlClassStatisticsInfoVo> list = new ArrayList<RzlClassStatisticsInfoVo>();
//
//		ClassStatisticsInfoVo total = new ClassStatisticsInfoVo();
//		total.setYear(year);
//		total.setTotalCnt(0);
//		total.setHigherSchool(0);
//		total.setResearchInstitute(0);
//		total.setEnterprise(0);
//		total.setInstitutions(0);
//		total.setIndividual(0);
//		total.setPatentType("总计");
//		if (rzgClassStatisticsInfo.getCityCode() == null || "null".equals(rzgClassStatisticsInfo.getCityCode().trim())
//				|| "".equals(rzgClassStatisticsInfo.getCityCode().trim())) {
//			total.setAreaName("云南省");
//		} else {
//			BladeRegion bladeRegion = BladeRegionUtils.selectByCode(rzgClassStatisticsInfo.getCityCode());
//			if (bladeRegion != null) {
//				total.setAreaName(bladeRegion.getName());
//			}
//		}
////		list.add(total);
//
//		// key:area
//		Map<String, List<ClassStatisticsInfoVo>> areaMap = new LinkedHashMap<String, List<ClassStatisticsInfoVo>>();
//
//		// key:areaName_type
//		Map<String, ClassStatisticsInfoVo> areaTypeMap = new HashMap<String, ClassStatisticsInfoVo>();
//		// key:type
//		Map<String, ClassStatisticsInfoVo> typeTotalMap = new LinkedHashMap<String, ClassStatisticsInfoVo>();
//
//		for (Map itemMap : mapList) {
//
//			String areaName = null;
//
//			StringBuffer sb = new StringBuffer();
//			if (itemMap.containsKey("area_name")) {
//				areaName = itemMap.get("area_name").toString();
//			} else {
//				areaName = "null";
//			}
//
//			sb.append(areaName);
//			sb.append("_");
//
//			String patentType = null;
//			if (itemMap.containsKey("patent_type")) {
//				patentType = itemMap.get("patent_type").toString();
//			} else {
//				patentType = "null";
//			}
//			sb.append(patentType);
//
//			String alreadyKey = sb.toString();
//
//			ClassStatisticsInfoVo vo = null;
//			if (areaTypeMap.containsKey(alreadyKey)) {
//				vo = areaTypeMap.get(alreadyKey);
//			} else {
//				vo = new ClassStatisticsInfoVo();
//				// list.add(vo);
//				vo.setPatentType(patentType);
//				areaTypeMap.put(alreadyKey, vo);
//
//				if (!areaMap.containsKey(areaName)) {
//					List<ClassStatisticsInfoVo> areaList = new ArrayList<ClassStatisticsInfoVo>();
//					areaMap.put(areaName, areaList);
//					areaList.add(vo);
//				} else {
//					areaMap.get(areaName).add(vo);
//				}
//
//			}
//
//			vo.setYear(year);
//			vo.setPatentType(getStr(itemMap, "patent_type"));
//			vo.setTotalCnt(vo.getTotalCnt() + getInt(itemMap, "total_cnt"));
//			vo.setHigherSchool(vo.getHigherSchool() + getInt(itemMap, "higher_school"));
//			vo.setResearchInstitute(vo.getResearchInstitute() + getInt(itemMap, "research_institute"));
//			vo.setEnterprise(vo.getEnterprise() + getInt(itemMap, "enterprise"));
//			vo.setInstitutions(vo.getInstitutions() + getInt(itemMap, "institutions"));
//			vo.setIndividual(vo.getIndividual() + getInt(itemMap, "individual"));
//			vo.setAreaName(getStr(itemMap, "area_name"));
//
//			total.setTotalCnt(total.getTotalCnt() + vo.getTotalCnt());
//			total.setHigherSchool(total.getHigherSchool() + vo.getHigherSchool());
//			total.setResearchInstitute(total.getResearchInstitute() + vo.getResearchInstitute());
//			total.setEnterprise(total.getEnterprise() + vo.getEnterprise());
//			total.setInstitutions(total.getInstitutions() + vo.getInstitutions());
//			total.setIndividual(total.getIndividual() + vo.getIndividual());
//
////			list.add(vo);
//
//		}
//
////		Collections.sort(list,new VoComparator());
//
//		// 处理小计
//		for (Map.Entry<String, List<ClassStatisticsInfoVo>> ent : areaMap.entrySet()) {
//			List<ClassStatisticsInfoVo> areaList = ent.getValue();
//
//			ClassStatisticsInfoVo tot = new ClassStatisticsInfoVo();
//			tot.setAreaName(ent.getKey());
//			tot.setPatentType("总计");
//			for (ClassStatisticsInfoVo vo : areaList) {
//				tot.setTotalCnt(total.getTotalCnt() + vo.getTotalCnt());
//				tot.setHigherSchool(total.getHigherSchool() + vo.getHigherSchool());
//				tot.setResearchInstitute(total.getResearchInstitute() + vo.getResearchInstitute());
//				tot.setEnterprise(total.getEnterprise() + vo.getEnterprise());
//				tot.setInstitutions(total.getInstitutions() + vo.getInstitutions());
//				tot.setIndividual(total.getIndividual() + vo.getIndividual());
//			}
//
//			areaList.add(0, tot);
//
//		}
//
//		// 结果列表
//		List<ClassStatisticsInfoVo> list = new ArrayList<ClassStatisticsInfoVo>();
//
//		list.add(total);
//		
//		for (Map.Entry<String, List<ClassStatisticsInfoVo>> ent : areaMap.entrySet()) {
//			for(ClassStatisticsInfoVo vo:ent.getValue()) {
//				if(!"总计".equals(vo.getPatentType())) {
//					vo.setAreaName("");
//				}
//				list.add(vo);
//			}
//			
//		}
//		
//		return list;
//	}

	private static class VoComparator implements Comparator<ClassStatisticsInfoVo> {

		@Override
		public int compare(ClassStatisticsInfoVo o1, ClassStatisticsInfoVo o2) {
			// TODO Auto-generated method stub
			int c = 0;
			if (o1.getAreaName() == null) {
				if (o2.getAreaName() == null) {
					c = 0;
				} else {
					return -1;
				}
			} else if (o2.getAreaName() != null) {
				c = o1.getAreaName().compareTo(o2.getAreaName());
			} else {
				c = 1;
			}

			if (c == 0) {
				if (o1.getPatentType() == null) {
					if (o2.getPatentType() == null) {
						c = 0;
					} else {
						return -1;
					}
				} else if (o2.getPatentType() != null) {
					c = o1.getPatentType().compareTo(o2.getPatentType());
				} else {
					c = 1;
				}
			}
			return 0;
		}

	}

	private String getStr(Map map, String key) {
		if (map == null || key == null || !map.containsKey(key)) {
			return "";
		}
		return map.get(key).toString();
	}

	private int getInt(Map map, String key) {
		if (map == null || key == null || !map.containsKey(key)) {
			return 0;
		}
		return Integer.parseInt(map.get(key).toString());
	}

	/**
	 * 查询专利公开-分类统计列表
	 *
	 * @param rzgClassStatisticsInfo 专利公开-分类统计
	 * @return 专利公开-分类统计集合
	 * @date 2023-03-27
	 */
	@Override
	public List<RzgClassStatisticsInfo> queryList(RzgClassStatisticsInfo rzgClassStatisticsInfo) {
		QueryWrapper<RzgClassStatisticsInfo> queryWrapper = Wrappers.query();
		if (StringUtils.isNotNull(rzgClassStatisticsInfo.getCityCode())) {
			queryWrapper.eq("city_code", rzgClassStatisticsInfo.getCityCode());
		}
		if (StringUtils.isNotEmpty(rzgClassStatisticsInfo.getCityName())) {
			queryWrapper.like("city_name", rzgClassStatisticsInfo.getCityName());
		}
		if (StringUtils.isNotEmpty(rzgClassStatisticsInfo.getYear())) {
			queryWrapper.eq("year", rzgClassStatisticsInfo.getYear());
		}
		if (StringUtils.isNotEmpty(rzgClassStatisticsInfo.getMonth())) {
			queryWrapper.eq("month", rzgClassStatisticsInfo.getMonth());
		}
//                if ( StringUtils.isNotEmpty(rzgClassStatisticsInfo.getHigherSchool())  ){
//                    queryWrapper.eq("higher_school", rzgClassStatisticsInfo.getHigherSchool());
//                }
//                if ( StringUtils.isNotEmpty(rzgClassStatisticsInfo.getResearchInstitute())  ){
//                    queryWrapper.eq("research_institute", rzgClassStatisticsInfo.getResearchInstitute());
//                }
//                if ( StringUtils.isNotEmpty(rzgClassStatisticsInfo.getEnterprise())  ){
//                    queryWrapper.eq("enterprise", rzgClassStatisticsInfo.getEnterprise());
//                }
//                if ( StringUtils.isNotEmpty(rzgClassStatisticsInfo.getInstitutions())  ){
//                    queryWrapper.eq("institutions", rzgClassStatisticsInfo.getInstitutions());
//                }
//                if ( StringUtils.isNotEmpty(rzgClassStatisticsInfo.getIndividual())  ){
//                    queryWrapper.eq("individual", rzgClassStatisticsInfo.getIndividual());
//                }
//                if ( StringUtils.isNotEmpty(rzgClassStatisticsInfo.getTotal())  ){
//                    queryWrapper.eq("total", rzgClassStatisticsInfo.getTotal());
//                }
		if (StringUtils.isNotEmpty(rzgClassStatisticsInfo.getPatentType())) {
			queryWrapper.eq("patent_type", rzgClassStatisticsInfo.getPatentType());
		}
		if (StringUtils.isNotEmpty(rzgClassStatisticsInfo.getApplicantType())) {
			queryWrapper.eq("applicant_type", rzgClassStatisticsInfo.getApplicantType());
		}
		if (StringUtils.isNotNull(rzgClassStatisticsInfo.getStatus())) {
			queryWrapper.eq("status", rzgClassStatisticsInfo.getStatus());
		}
		queryWrapper.orderByDesc("id");
		return this.list(queryWrapper);
	}
}
