package com.ruoyi.report.vo;

import java.util.Comparator;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.constant.PatentType;

import lombok.Data;


@Data
public class ViewStatisticsInfoVo implements Comparator<ViewStatisticsInfoVo>{
	
	private String areaName;
	private String areaCode;
	private String patentType;
	
	private Map<String,Item>yearData;
	
	
	public long getTotal() {
		long total=0;
		if(yearData==null || yearData.isEmpty()) {
			return 0;
		}
		for(Item item:yearData.values()) {
			total=total+item.getTotalCnt();
		}
		return total;
	}
	
	public static long getTotal(List<ViewStatisticsInfoVo>list) {
		long total=0;
		if(list==null||list.isEmpty()) {
			return 0;
		}
		for(ViewStatisticsInfoVo vo:list) {
			total=total+vo.getTotal();
		}
		
		return total;
	}
	@Override
	public int compare(ViewStatisticsInfoVo o1, ViewStatisticsInfoVo o2) {
		if (o1 == null && o2 == null) {
			return 0;
		} else {
			if (o1 == null) {
				return -1;
			} else if (o2 == null) {
				return 1;
			} else {
				PatentType tp1 = PatentType.valueOfByName(o1.getPatentType());
				PatentType tp2 = PatentType.valueOfByName(o2.getPatentType());
				if (tp1 == null && tp2 == null) {
					return 0;
				} else if (tp1 == null) {
					return -1;
				} else if (tp2 == null) {
					return 1;
				} else {
					return Integer.parseInt(tp1.getTypeId()) - Integer.parseInt(tp2.getTypeId());
				}
			}
		}
	}
	@Data
	public static class Item{
		
		public Item() {
			this.totalCnt=0L;
			this.higherSchool=0L;
			this.researchInstitute=0L;
			this.enterprise=0L;
			this.institutions=0L;
			this.individual=0L;
		}

		private String areaCode;
		private String year;
		private Long totalCnt;
		
		/** 大专院校 */
		private Long higherSchool;

		/** 科研机构 */
		private Long researchInstitute;

		private Long enterprise;

		/** 事业单位 */
		private Long institutions;

		/** 个人 */
		private Long individual;

		
	}



}
