package com.ruoyi.hv.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
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.utils.SecurityUtils;
import com.ruoyi.hv.domain.RzgHighValueIewStatisticsInfo;
import com.ruoyi.hv.mapper.RzgHighValueIewStatisticsInfoMapper;
import com.ruoyi.hv.service.IRzgHighValueIewStatisticsInfoService;
import com.ruoyi.hv.vo.RzgHighValueIewStatisticsInfoRep;
import com.ruoyi.hv.vo.RzgHighValueIewStatisticsInfoVo;
import com.ruoyi.hv.vo.RzgHighValueIewStatisticsInfoVo.Item;
import com.ruoyi.system.domain.BladeRegion;
import com.ruoyi.utils.BladeRegionUtils;

/**
 * 高价值专利-概况统计Service业务层处理
 *
 * @author ruoyi
 * @date 2023-04-02
 */
@Service
public class RzgHighValueIewStatisticsInfoServiceImpl extends ServiceImpl<RzgHighValueIewStatisticsInfoMapper, RzgHighValueIewStatisticsInfo>
		implements IRzgHighValueIewStatisticsInfoService {

	@Autowired
	private RzgHighValueIewStatisticsInfoMapper rzgHighValueIewStatisticsInfoMapper;

	private void margeNotThisArea(List<Map> notThisAreaList, Map dataMap, Map<String, Map> alreadyNotThisArea, String areaCodeKey, String areaNameKey,
			String[] keys, String[] dataKeys) {
		StringBuffer keysb = new StringBuffer();
//		String areaCode = "000000";
		String areaCode = "非本区划";
		String areaName = "非本区划";
		keysb.append(areaCode).append("_").append(areaName);
		for (String key : keys) {
			String val = getStr(dataMap, key);
			if (StringUtils.isBlank(val)) {
				val = "null";
			}
			keysb.append("_").append(val);
		}
		if (!alreadyNotThisArea.containsKey(keysb.toString())) {
			Map newMap = new HashMap();
			newMap.putAll(dataMap);
			newMap.put(areaCodeKey, areaCode);
			newMap.put(areaNameKey, areaName);
			notThisAreaList.add(newMap);
			alreadyNotThisArea.put(keysb.toString(), newMap);
		} else {
			Map oldMap = alreadyNotThisArea.get(keysb.toString());
			for (String key : dataKeys) {
				long oldVal = getLong(oldMap, key);
				long newVal = getLong(dataMap, key);
				oldMap.put(key, oldVal + newVal);
			}
		}

	}

	private boolean isNotThisArea(Map map) {
		Object obj = map.get("not_this_area");
		if (obj != null) {
			return Boolean.parseBoolean(obj + "");
		}
		return false;
	}

	public RzgHighValueIewStatisticsInfoRep listByReport(RzgHighValueIewStatisticsInfo rzgHighValueIewStatisticsInfo) {
		RzgHighValueIewStatisticsInfoRep rep = new RzgHighValueIewStatisticsInfoRep();
//		List<RzlViewStatisticsInfoVo> typeTotalList = new ArrayList<RzlViewStatisticsInfoVo>();

		boolean retEmpty = false;
		if (StringUtils.isNotBlank(rzgHighValueIewStatisticsInfo.getCityCode()) && !"53".equals(rzgHighValueIewStatisticsInfo.getCityCode())) {
			String cityCode = rzgHighValueIewStatisticsInfo.getCityCode().trim();
			if (SecurityUtils.isNeedFilterByCityCode()) {
				String cc = SecurityUtils.needFilterByCityCode();
				if (!cc.equals(cityCode)) {
					retEmpty = true;
				}
			}
		} else {
			if (SecurityUtils.isNeedFilterByCityCode()) {
				String cityCode = SecurityUtils.needFilterByCityCode();
				rzgHighValueIewStatisticsInfo.setCityCode(cityCode);
			}
		}

		String cityCode = null;
		if (StringUtils.isNotBlank(rzgHighValueIewStatisticsInfo.getCityCode()) && !"53".equals(rzgHighValueIewStatisticsInfo.getCityCode())) {
			cityCode = rzgHighValueIewStatisticsInfo.getCityCode().trim();
		}
		rzgHighValueIewStatisticsInfo.setCityCode(cityCode);
		String qyear = rzgHighValueIewStatisticsInfo.getYear();

		if (StringUtils.isBlank(rzgHighValueIewStatisticsInfo.getYear()) || StringUtils.isBlank(rzgHighValueIewStatisticsInfo.getMonth())) {
			throw new RuntimeException("请指定查询的数据月份");
		}

		if (StringUtils.isBlank(qyear)) {
			qyear = new SimpleDateFormat("yyyy").format(new Date());
		}
		if (StringUtils.isNotBlank(qyear)) {
			String minYear = (Integer.parseInt(qyear) - 10) + "";
			rzgHighValueIewStatisticsInfo.setMinYear(minYear);
			rzgHighValueIewStatisticsInfo.setMaxYear(qyear);

			rzgHighValueIewStatisticsInfo.setYear(null);

//			String minDay=minYear+rzgHighValueIewStatisticsInfo.getMonth()+"01";
//			String maxDay=qyear+rzgHighValueIewStatisticsInfo.getMonth()+"31";
//			rzgHighValueIewStatisticsInfo.setMinDay(minDay);
//			rzgHighValueIewStatisticsInfo.setMaxDay(maxDay);
		}
		rzgHighValueIewStatisticsInfo.setStatus(10L);// 10有效，20无效
//		List<Map> mapList = rzlViewStatisticsInfoMapper.listByReport(rzgHighValueIewStatisticsInfo);
//		List<Map> mapList = rzgHighValueIewStatisticsInfoMapper.listByReport(rzgHighValueIewStatisticsInfo);
		
		List<Map> mapList =new ArrayList<Map>();
		if(!retEmpty) {
			mapList = rzgHighValueIewStatisticsInfoMapper.listByReport(rzgHighValueIewStatisticsInfo);
		}
		
//		   year_batch,count(*) total_cnt
//	        ,sum(case when hv_seis_press='1' then 1 else 0 end ) seis
//	        ,sum(case when hv_have_overseas_press='1' then 1 else 0 end ) have_overseas
//	        ,sum(case when hv_keep10_press='1' then 1 else 0 end ) keep_10_years
//	        ,sum(case when hv_high_pledge_press='1' then 1 else 0 end ) high_pledge
//	        ,sum(case when hv_technology_award_press='1' then 1 else 0 end ) technology_award

		// 处理非本区划
		boolean needSumNotThisArea = false;
		if (StringUtils.isNotBlank(cityCode)) {
			needSumNotThisArea = true;
		}
		List<Map> notThisAreaList = new ArrayList<Map>();
		Map<String, Map> alreadyNotThisArea = new HashMap<String, Map>();
		if (needSumNotThisArea && mapList != null && !mapList.isEmpty()) {
			List<Map> newList = new ArrayList<Map>();
			BladeRegionUtils.setNotThisArea(mapList, cityCode);
//			List<String> allCodes=bladeRegionService.getAllAreaCode();
//			Map<String,Boolean>alreadyMap=new HashMap<String,Boolean>();
			for (Map map : mapList) {
				String area_code = getStr(map, "area_code");
//				if (StringUtils.isBlank(area_code) || !area_code.startsWith(cityCode)) {
				if (isNotThisArea(map)) {
					// 合并到非本区化
					margeNotThisArea(notThisAreaList, map, alreadyNotThisArea, "area_code", "area_name", new String[] { "year_batch" },
							new String[] { "total_cnt", "seis", "have_overseas", "keep_10_years", "high_pledge", "technology_award" });
				} else {
					newList.add(map);// 不是非本区划
				}
			}
			mapList = newList;
			mapList.addAll(notThisAreaList);
		}

		// key: areaName //20231013改为areaCode
		Map<String, RzgHighValueIewStatisticsInfoVo> areaMap = new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo>();

//		// key:areaName_type
//		Map<String, RzgHighValueIewStatisticsInfoVo> areaTypeMap = new HashMap<String, RzgHighValueIewStatisticsInfoVo>();

		// key: type
//		Map<String, RzgHighValueIewStatisticsInfoVo> typeTotalMap = new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo>();

		Set<String> yearSet = new HashSet<String>();
		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);

			String alreadyKey = sb.toString();

			RzgHighValueIewStatisticsInfoVo vo = null;
			if (areaMap.containsKey(alreadyKey)) {
				vo = areaMap.get(alreadyKey);
			} else {
				vo = new RzgHighValueIewStatisticsInfoVo();
				vo.setAreaName(areaName);
				vo.setYearData(new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo.Item>());
				areaMap.put(alreadyKey, vo);
			}

			String year = getStr(itemMap, "year_batch");

			yearSet.add(year);

			RzgHighValueIewStatisticsInfoVo.Item item = new RzgHighValueIewStatisticsInfoVo.Item();
			item.setYear(year);
//			item.setTotalCnt(getInt(itemMap, "total_cnt"));
			item.setTotalCnt(0L);

			item.setSeis(getLong(itemMap, "seis"));
			item.setKeep10Years(getLong(itemMap, "keep_10_years"));
			item.setHaveOverseas(getLong(itemMap, "have_overseas"));
			item.setHighPledge(getLong(itemMap, "high_pledge"));
			item.setTechnologyAward(getLong(itemMap, "technology_award"));

			long total = 0;

			if ("1".equals(rzgHighValueIewStatisticsInfo.getIndustryEmergIndustryQ())) {
				total = total + item.getSeis();
			}
//
//		    /**
//		     * 在海外有同族专利
//		     */
//		@TableField(exist =false)
//		    private String overseasCongenerPatentQ;
			if ("1".equals(rzgHighValueIewStatisticsInfo.getOverseasCongenerPatentQ())) {
				total = total + item.getHaveOverseas();
			}
//
//		    /**
//		     * 维持年限超十年
//		     */
//		@TableField(exist =false)
//		    private String maintenanceTenYearQ;
			if ("1".equals(rzgHighValueIewStatisticsInfo.getMaintenanceTenYearQ())) {
				total = total + item.getKeep10Years();
			}
//
//		    /**
//		     * 存在质押记录
//		     */
//		@TableField(exist =false)
//		    private String pledgeRecordQ;
			if ("1".equals(rzgHighValueIewStatisticsInfo.getPledgeRecordQ())) {
				total = total + item.getHighPledge();
			}
//
//		    /**
//		     * 获得国家科技奖或者中国专利奖
//		     */
//		@TableField(exist =false)
//		    private String nationalScienceAwardQ;
			if ("1".equals(rzgHighValueIewStatisticsInfo.getNationalScienceAwardQ())) {
				total = total + item.getTechnologyAward();
			}
			item.setTotalCnt(total);

			vo.getYearData().put(year, item);

		}

		// 结果列表
		List<RzgHighValueIewStatisticsInfoVo> list = new ArrayList<RzgHighValueIewStatisticsInfoVo>();

		// 总的统计
		RzgHighValueIewStatisticsInfoVo allTypeList = new RzgHighValueIewStatisticsInfoVo();
		allTypeList.setYearData(new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo.Item>());
		if (rzgHighValueIewStatisticsInfo.getCityCode() == null || "null".equals(rzgHighValueIewStatisticsInfo.getCityCode().trim())
				|| "".equals(rzgHighValueIewStatisticsInfo.getCityCode().trim()) || "53".equals(rzgHighValueIewStatisticsInfo.getCityCode().trim())) {
			allTypeList.setAreaName("云南省");
		} else {
//			allTypeList.setAreaName(rzgHighValueIewStatisticsInfo.getCityName());

			BladeRegion bladeRegion = BladeRegionUtils.selectByCode(rzgHighValueIewStatisticsInfo.getCityCode().trim());
			if (bladeRegion != null) {
//				allTypeList.setAreaName(bladeRegion.getName());
				allTypeList.setAreaName(bladeRegion.getDistrictShortName());
			}

		}
//		allTypeList.setPatentType("总计");
		// 处理统计
		for (Map.Entry<String, RzgHighValueIewStatisticsInfoVo> ent : areaMap.entrySet()) {
			RzgHighValueIewStatisticsInfoVo vo = ent.getValue();

			Map<String, Item> yearData = vo.getYearData();

			for (Map.Entry<String, Item> itemEnt : yearData.entrySet()) {
				String year = itemEnt.getKey();
				if (allTypeList.getYearData().containsKey(itemEnt.getKey())) {
					// 累加
					Item item = allTypeList.getYearData().get(itemEnt.getKey());
					Item curr = itemEnt.getValue();

					item.setTotalCnt(item.getTotalCnt() + curr.getTotalCnt());

					item.setSeis(item.getSeis() + curr.getSeis());
					item.setKeep10Years(item.getKeep10Years() + curr.getKeep10Years());
					item.setHaveOverseas(item.getHaveOverseas() + curr.getHaveOverseas());
					item.setHighPledge(item.getHighPledge() + curr.getHighPledge());
					item.setTechnologyAward(item.getTechnologyAward() + curr.getTechnologyAward());

					allTypeList.getYearData().put(year, item);

				} else {

					Item item = new Item();

					item.setYear(year);
					Item curr = itemEnt.getValue();

					item.setTotalCnt(curr.getTotalCnt());
					item.setSeis(curr.getSeis());
					item.setKeep10Years(curr.getKeep10Years());
					item.setHaveOverseas(curr.getHaveOverseas());
					item.setHighPledge(curr.getHighPledge());
					item.setTechnologyAward(curr.getTechnologyAward());

					allTypeList.getYearData().put(year, item);

				}
			}

		}

		List<RzgHighValueIewStatisticsInfoVo> list1 = new ArrayList<RzgHighValueIewStatisticsInfoVo>();
//		list1.addAll(areaMap.values());
		List<RzgHighValueIewStatisticsInfoVo> notThis = new ArrayList<RzgHighValueIewStatisticsInfoVo>();

		List<String> keys = BladeRegionUtils.sortedKey(areaMap.keySet());
		for (String area : keys) {
			if ("非本区划".equals(area)) {
				notThis.add(areaMap.get(area));
			} else {
				String areaName = BladeRegionUtils.getDistrictShortName(area);
				if (areaName != null) {
					areaMap.get(area).setAreaName(areaName);
				}
				list1.add(areaMap.get(area));
			}
		}

//		if (areaMap.containsKey("非本区划")) {
//			for (Map.Entry<String, RzgHighValueIewStatisticsInfoVo> ent : areaMap.entrySet()) {
//				if ("非本区划".equals(ent.getKey())) {
//					notThis.add(ent.getValue());
//				} else {
//					list1.add(ent.getValue());
//				}
//			}
//		} else {
//			list1.addAll(areaMap.values());
//		}

//		Collections.sort(list1, new Comparator<RzgHighValueIewStatisticsInfoVo>() {
//			@Override
//			public int compare(RzgHighValueIewStatisticsInfoVo o1, RzgHighValueIewStatisticsInfoVo o2) {
//				long t1 = getTotal(o1);
//				long t2 = getTotal(o2);
//				return (int)(t2 - t1);
//			}
//		});

		if (notThis != null && !notThis.isEmpty()) {
			list1.addAll(notThis);
		}

		for (RzgHighValueIewStatisticsInfoVo ent : list1) {
			list.add(ent);
		}
//		Collections.sort(list ,new RzgHighValueIewStatisticsInfoVo());

		if (!list.isEmpty()) {
			list.add(0, allTypeList);
		}

		List<String> yearList = new ArrayList<String>();
		// 确保返回列表中所有年份都有数据
		for (String year : yearSet) {
			for (RzgHighValueIewStatisticsInfoVo vo : list) {
				if (!vo.getYearData().containsKey(year)) {
					Item item = new Item();
					item.setYear(year);
					vo.getYearData().put(year, item);
				}
			}
			yearList.add(year);
		}

		Collections.sort(yearList, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				// TODO Auto-generated method stub
				if (o1 == null && o2 == null) {
					return 0;
				} else {
					if (o1 == null) {
						return -1;
					} else if (o2 == null) {
						return 1;
					} else {
						return o1.compareTo(o2);
					}
				}
			}
		});
		rep.setDataList(list);
		rep.setYearList(yearList);

		return rep;

	}

	private long getTotal(RzgHighValueIewStatisticsInfoVo vo) {
		long total = 0l;
		if (vo == null || vo.getYearData() == null || vo.getYearData().isEmpty()) {
			total = 0;
		} else {
			for (Item item : vo.getYearData().values()) {
				if (item.getTotalCnt() == null) {
					continue;
				}
				total = total + item.getTotalCnt();
			}
		}
		return total;
	}

//	public List<RzgHighValueIewStatisticsInfoVo> listByReport_bak(
//			RzgHighValueIewStatisticsInfo rzgHighValueIewStatisticsInfo) {
//		// TODO Auto-generated method stub
//
////		List<RzlViewStatisticsInfoVo> typeTotalList = new ArrayList<RzlViewStatisticsInfoVo>();
//		String cityCode = null;
//		if (StringUtils.isNotBlank(rzgHighValueIewStatisticsInfo.getCityCode())
//				&& !"53".equals(rzgHighValueIewStatisticsInfo.getCityCode())) {
//			cityCode = rzgHighValueIewStatisticsInfo.getCityCode().trim();
//		}
//
////		List<Map> mapList = rzlViewStatisticsInfoMapper.listByReport(rzlViewStatisticsInfo.getCityName());
//		List<Map> mapList = rzgHighValueIewStatisticsInfoMapper.listByReport(cityCode);
//
//		// key: areaName
//		Map<String, RzgHighValueIewStatisticsInfoVo> areaMap = new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo>();
//
////		// key:areaName_type
////		Map<String, RzgHighValueIewStatisticsInfoVo> areaTypeMap = new HashMap<String, RzgHighValueIewStatisticsInfoVo>();
//
//		// key: type
////		Map<String, RzgHighValueIewStatisticsInfoVo> typeTotalMap = new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo>();
//
//		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);
//
//			String alreadyKey = sb.toString();
//
//			RzgHighValueIewStatisticsInfoVo vo = null;
//			if (areaMap.containsKey(alreadyKey)) {
//				vo = areaMap.get(alreadyKey);
//			} else {
//				vo = new RzgHighValueIewStatisticsInfoVo();
//				vo.setAreaName(areaName);
//				vo.setYearData(new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo.Item>());
//				areaMap.put(alreadyKey, vo);
//			}
//
//			String year = getStr(itemMap, "year_batch");
//			RzgHighValueIewStatisticsInfoVo.Item item = new RzgHighValueIewStatisticsInfoVo.Item();
//			item.setYear(year);
//			item.setTotalCnt(getInt(itemMap, "total_cnt"));
//
//			item.setSeis(getInt(itemMap, "seis"));
//			item.setKeep10Years(getInt(itemMap, "keep10_years"));
//			item.setHaveOverseas(getInt(itemMap, "have_overseas"));
//			item.setHighPledge(getInt(itemMap, "high_pledge"));
//			item.setTechnologyAward(getInt(itemMap, "technology_award"));
//
//			vo.getYearData().put(year, item);
////			// 总计
////			RzlViewStatisticsInfoVo typeTotal = null;
////			if (typeTotalMap.containsKey(patentType)) {
////				typeTotal = typeTotalMap.get(patentType);
////			} else {
////				typeTotal = new RzlViewStatisticsInfoVo();
////				
//////				if(areaName==null || "null".equals(areaName.trim())  || "".equals(areaName.trim()) ) {
////				typeTotal.setPatentType(patentType);
////				typeTotal.setYearData(new LinkedHashMap<String, RzlViewStatisticsInfoVo.Item>());
//////				}
////
////				typeTotalMap.put(patentType, typeTotal);
////			}
////			Item totItem = null;
////			Item curr = item;
////			if (typeTotal.getYearData().containsKey(year)) {
////				totItem = typeTotal.getYearData().get(year);
////
////				totItem.setTotalCnt(totItem.getTotalCnt() + curr.getTotalCnt());
////				totItem.setHigherSchool(totItem.getHigherSchool() + curr.getHigherSchool());
////				totItem.setResearchInstitute(totItem.getResearchInstitute() + curr.getResearchInstitute());
////				totItem.setEnterprise(totItem.getEnterprise() + curr.getEnterprise());
////				totItem.setInstitutions(totItem.getInstitutions() + curr.getInstitutions());
////				totItem.setIndividual(totItem.getIndividual() + curr.getIndividual());
////
////			} else {
////				totItem = new Item();
////				totItem.setYear(year);
////				typeTotal.getYearData().put(year, totItem);
////				
////				totItem.setTotalCnt(curr.getTotalCnt());
////				totItem.setHigherSchool(curr.getHigherSchool());
////				totItem.setResearchInstitute(curr.getResearchInstitute());
////				totItem.setEnterprise(curr.getEnterprise());
////				totItem.setInstitutions(curr.getInstitutions());
////				totItem.setIndividual(curr.getIndividual());
////			}
//
//		}
//
//		// 处理小计
////		for (Map.Entry<String, RzgHighValueIewStatisticsInfoVo> ent : areaMap.entrySet()) {
////			RzgHighValueIewStatisticsInfoVo areaList = ent.getValue();
////
////			RzgHighValueIewStatisticsInfoVo total = new RzgHighValueIewStatisticsInfoVo();
////			total.setAreaName(ent.getKey());
////			total.setPatentType("总计");
////
////			total.setYearData(new LinkedHashMap<String, Item>());
////			for (RzlViewStatisticsInfoVo vo : areaList) {
////				Map<String, Item> yearData = vo.getYearData();
////
////				for (Map.Entry<String, Item> itemEnt : yearData.entrySet()) {
////					String year = itemEnt.getKey();
////					if (total.getYearData().containsKey(itemEnt.getKey())) {
////						// 累加
////						Item item = total.getYearData().get(itemEnt.getKey());
////						Item curr = itemEnt.getValue();
////
////						item.setTotalCnt(item.getTotalCnt() + curr.getTotalCnt());
////						item.setHigherSchool(item.getHigherSchool() + curr.getHigherSchool());
////						item.setResearchInstitute(item.getResearchInstitute() + curr.getResearchInstitute());
////						item.setEnterprise(item.getEnterprise() + curr.getEnterprise());
////						item.setInstitutions(item.getInstitutions() + curr.getInstitutions());
////						item.setIndividual(item.getIndividual() + curr.getIndividual());
////
////						total.getYearData().put(year, item);
////
////					} else {
////
////						Item item = new Item();
////
////						item.setYear(year);
////						Item curr = itemEnt.getValue();
////
////						item.setTotalCnt(curr.getTotalCnt());
////						item.setHigherSchool(curr.getHigherSchool());
////						item.setResearchInstitute(curr.getResearchInstitute());
////						item.setEnterprise(curr.getEnterprise());
////						item.setInstitutions(curr.getInstitutions());
////						item.setIndividual(curr.getIndividual());
////
////						total.getYearData().put(year, item);
////
////					}
////				}
////
////			}
////
////			areaList.add(0, total);
////		}
//
//		// 结果列表
//		List<RzgHighValueIewStatisticsInfoVo> list = new ArrayList<RzgHighValueIewStatisticsInfoVo>();
//
//		// 总的统计
//		RzgHighValueIewStatisticsInfoVo allTypeList = new RzgHighValueIewStatisticsInfoVo();
//		list.add(allTypeList);
//		allTypeList.setYearData(new LinkedHashMap<String, RzgHighValueIewStatisticsInfoVo.Item>());
//		if (rzgHighValueIewStatisticsInfo.getCityName() == null
//				|| "null".equals(rzgHighValueIewStatisticsInfo.getCityName().trim())
//				|| "".equals(rzgHighValueIewStatisticsInfo.getCityName().trim())) {
//			allTypeList.setAreaName("云南省");
//		} else {
//			allTypeList.setAreaName(rzgHighValueIewStatisticsInfo.getCityName());
//		}
////		allTypeList.setPatentType("总计");
//
//		// 处理统计
//		for (Map.Entry<String, RzgHighValueIewStatisticsInfoVo> ent : areaMap.entrySet()) {
//			RzgHighValueIewStatisticsInfoVo vo = ent.getValue();
//
//			list.add(vo);
//
//			Map<String, Item> yearData = vo.getYearData();
//
//			for (Map.Entry<String, Item> itemEnt : yearData.entrySet()) {
//				String year = itemEnt.getKey();
//				if (allTypeList.getYearData().containsKey(itemEnt.getKey())) {
//					// 累加
//					Item item = allTypeList.getYearData().get(itemEnt.getKey());
//					Item curr = itemEnt.getValue();
//
//					item.setTotalCnt(item.getTotalCnt() + curr.getTotalCnt());
//
//					item.setSeis(item.getSeis() + curr.getSeis());
//					item.setKeep10Years(item.getKeep10Years() + curr.getKeep10Years());
//					item.setHaveOverseas(item.getHaveOverseas() + curr.getHaveOverseas());
//					item.setHighPledge(item.getHighPledge() + curr.getHighPledge());
//					item.setTechnologyAward(item.getTechnologyAward() + curr.getTechnologyAward());
//
//					allTypeList.getYearData().put(year, item);
//
//				} else {
//
//					Item item = new Item();
//
//					item.setYear(year);
//					Item curr = itemEnt.getValue();
//
//					item.setTotalCnt(curr.getTotalCnt());
//					item.setSeis(curr.getSeis());
//					item.setKeep10Years(curr.getKeep10Years());
//					item.setHaveOverseas(curr.getHaveOverseas());
//					item.setHighPledge(curr.getHighPledge());
//					item.setTechnologyAward(curr.getTechnologyAward());
//
//					allTypeList.getYearData().put(year, item);
//
//				}
//			}
//
//		}
//
//		for (Map.Entry<String, RzgHighValueIewStatisticsInfoVo> ent : areaMap.entrySet()) {
//			list.add(ent.getValue());
//		}
//
//		return list;
//	}

	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());
//	}
	private long getLong(Map map, String key) {
		if (map == null || key == null || !map.containsKey(key)) {
			return 0L;
		}
		return Long.parseLong(map.get(key).toString());
	}

	/**
	 * 查询高价值专利-概况统计列表
	 *
	 * @param rzgHighValueIewStatisticsInfo 高价值专利-概况统计
	 * @return 高价值专利-概况统计集合
	 * @date 2023-04-02
	 */
	@Override
	public List<RzgHighValueIewStatisticsInfo> queryList(RzgHighValueIewStatisticsInfo rzgHighValueIewStatisticsInfo) {
		QueryWrapper<RzgHighValueIewStatisticsInfo> queryWrapper = Wrappers.query();
		if (StringUtils.isNotBlank(rzgHighValueIewStatisticsInfo.getCityCode())) {
			queryWrapper.eq("city_code", rzgHighValueIewStatisticsInfo.getCityCode());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getCityName())) {
			queryWrapper.like("city_name", rzgHighValueIewStatisticsInfo.getCityName());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getYear())) {
			queryWrapper.eq("year", rzgHighValueIewStatisticsInfo.getYear());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getMonth())) {
			queryWrapper.eq("month", rzgHighValueIewStatisticsInfo.getMonth());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getPatentType())) {
			queryWrapper.eq("patent_type", rzgHighValueIewStatisticsInfo.getPatentType());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getIsAddPopulation())) {
			queryWrapper.eq("is_add_population", rzgHighValueIewStatisticsInfo.getIsAddPopulation());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getHighValueType())) {
			queryWrapper.eq("high_value_type", rzgHighValueIewStatisticsInfo.getHighValueType());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getIndustryEmergIndustry())) {
			queryWrapper.eq("industry_emerg_industry", rzgHighValueIewStatisticsInfo.getIndustryEmergIndustry());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getOverseasCongenerPatent())) {
			queryWrapper.eq("overseas_congener_patent", rzgHighValueIewStatisticsInfo.getOverseasCongenerPatent());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getMaintenanceTenYear())) {
			queryWrapper.eq("maintenance_ten_year", rzgHighValueIewStatisticsInfo.getMaintenanceTenYear());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getPledgeRecord())) {
			queryWrapper.eq("pledge_record", rzgHighValueIewStatisticsInfo.getPledgeRecord());
		}
		if (StringUtils.isNotEmpty(rzgHighValueIewStatisticsInfo.getNationalScienceAward())) {
			queryWrapper.eq("national_science_award", rzgHighValueIewStatisticsInfo.getNationalScienceAward());
		}
		if (rzgHighValueIewStatisticsInfo.getStatus() != null) {
			queryWrapper.eq("status", rzgHighValueIewStatisticsInfo.getStatus());
		}
		queryWrapper.orderByDesc("id");
		return this.list(queryWrapper);
	}
}
