package com.sys.bus.excel.controller;

import com.jfinal.aop.Enhancer;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.jfinal.upload.UploadFile;
import com.sys.bus.excel.tool.ExcelImportTool;
import com.sys.bus.excel.tool.ExcelRender;
import com.sys.bus.hr.model.Person;
import com.sys.bus.jx.service.*;
import com.sys.bus.model.*;
import com.sys.core.model.DataBean;
import com.sys.core.utils.Tool;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletContext;
import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

public class ExcelController extends Controller {
	Log log = LogFactory.getLog(this.getClass());
	static String basePath = "upload"+File.separator+"temp"+File.separator;
	static String pathHead = PropKit.get("file.uploadPath");
	static JxCycleService jxCycleService = Enhancer.enhance(JxCycleService.class);
	static OrgService orgService = Enhancer.enhance(OrgService.class);
	//static JxManagerService jxManagerService = Enhancer.enhance(JxManagerService.class);
	//static ExpService expService = Enhancer.enhance(ExpService.class);
	static KpilibService kpilibService = Enhancer.enhance(KpilibService.class);
	// HrService hrService = Enhancer.enhance(HrService.class);
	static JxCommonService jxCommonService = Enhancer.enhance(JxCommonService.class);
	static PerformanceService performanceService = Enhancer.enhance(PerformanceService.class);//需要事务处理的service，必须使用增强方法
	//static RatingService ratingService = Enhancer.enhance(RatingService.class);
	/**
	 * 导出模板
	 *
	 */
	public void exportModel(){
		String type = this.getPara("type");
		ServletContext servletContext = this.getRequest().getSession().getServletContext();
		String realpath = servletContext.getRealPath(File.separator+"WEB-INF"+File.separator+"template");
		if(type.equals("1")){//导出KPI模板
			this.renderFile(new File(realpath  +File.separator +"kpitemplate.xlsx"));
		}else if(type.equals("2")){//导出评级模板
			this.renderFile(new File(realpath  +File.separator +"ratingtemplate.xlsx"));
		}else if(type.equals("3")){//导出线下数据模板
			this.renderFile(new File(realpath  +File.separator +"offlineDatamplate.xlsx"));
		}
	}

	public void exportJxData(){
		String type = this.getPara("type");
		if(type.equals("1")){
			exportKpiAndExp();
		} else if(type.equals("2")){
			exportEntrys();
		}else if(type.equals("3")){
			exportKpis();
		}else if(type.equals("4")){
			exportKpiAppInfo();
		}
	}



	/**
	 * 考核人评分信息
	 */
	public void exportKpiAppInfo(){
//		String entryNo = this.getPara("entryno");
//		List<Kpi> kpiList = jxCommonService.getKpiList(entryNo,null);
//		List<Object[]> list = new ArrayList<Object[]>();
//		Kpi lastHeadKpi = null;
//		int lastHeadIndex = 0;
//		String lastHeadPersonId = null;
//		String typeValue = "客观分";
//		for(int i=0;i<kpiList.size();i++){
//			Kpi kpi = kpiList.get(i);
//			if(i==0){
//				lastHeadKpi = kpi;
//				lastHeadIndex =0;
//				lastHeadPersonId = kpi.get("entry_khpersonid");
//				continue;
//			}
//			String khPersonId = kpi.get("entry_khpersonid");
//            typeValue = getKpiTypeStr(lastHeadKpi.getKpiType());
//			list.add(new Object[]{
//					lastHeadIndex+1,
//					lastHeadKpi.get("entry_khpersonname"),
//					lastHeadKpi.getKpiName(),
//					lastHeadKpi.getKpiTarget(),
//					lastHeadKpi.getKpiWeight()==null?null:lastHeadKpi.getKpiWeight().divide(new BigDecimal(100)),
//					lastHeadKpi.getKpiDefine(),
//					typeValue,
//					//lastHeadKpi.getKpiGradername(),
//					lastHeadKpi.get("sweight")==null?"--":lastHeadKpi.get("sweight"),
//					lastHeadKpi.getKpiCaption(),
//					lastHeadKpi.getKpiZp(),
//					lastHeadKpi.get("kpi_value")==null?"--":lastHeadKpi.get("kpi_value")+"("+lastHeadKpi.getKpiUnit()+")",
//					lastHeadKpi.get("kpi_score")==null?"":lastHeadKpi.get("kpi_score"),
//					lastHeadKpi.getKpiInfo()});
//			if(kpi.getKpiSweight()!=null){
//				kpi.put("sweight",""+kpi.getKpiSweight()+"%");
//			}
//			lastHeadKpi = kpi;
//			lastHeadIndex ++;
//			if(!khPersonId.equals(lastHeadPersonId)){
//				lastHeadIndex = 0;
//			}
//			lastHeadPersonId = khPersonId;
//		}
//        typeValue = getKpiTypeStr(lastHeadKpi.getKpiType());
//		list.add(new Object[]{
//				lastHeadIndex+1,
//				lastHeadKpi.get("entry_khpersonname"),
//				lastHeadKpi.getKpiName(),
//				lastHeadKpi.getKpiTarget(),
//				lastHeadKpi.getKpiWeight()==null?null:lastHeadKpi.getKpiWeight().divide(new BigDecimal(100)),
//				lastHeadKpi.getKpiDefine(),
//				typeValue,
//				//lastHeadKpi.getKpiGradername(),
//				lastHeadKpi.get("sweight")==null?"--":lastHeadKpi.get("sweight"),
//				lastHeadKpi.getKpiCaption(),
//				lastHeadKpi.getKpiZp(),
//				lastHeadKpi.get("kpi_value")==null?"--":lastHeadKpi.get("kpi_value")+"("+lastHeadKpi.getKpiUnit()+")",
//				lastHeadKpi.get("kpi_score")==null?"":lastHeadKpi.get("kpi_score"),
//				lastHeadKpi.getKpiInfo()});
//		String[] columns = {"序号","被考核人","关键绩效指标","目标值","指标权重","指标定义","评分类型",
//				"评分人","考核人权重","考评办法/计算公式","自评","客观值","得分","评分说明"};//,
//		int[] columnType = {2,1,1,1,3,1,1,1,1,1,1,1,1,1};
//		ExcelRender render = ExcelRender.me(list,columns,columnType);
//		render.fileName(kpiList.get(0).get("entry_cyclename")+"评分明细");
//		render.setContext(this.getRequest(),this.getResponse());
//		this.render(render);
	}

	/**
	 * 导出kpi得分明细
	 */
	public void exportKpis(){
		String entryNo = this.getPara("entryno");
		List<Kpi> kpiList = jxCommonService.getKpiListByNo(entryNo);
		if(kpiList.size()==0){
//			DataBean dBean = new DataBean();
//			dBean.setCode(-1);
//			dBean.setMsg("没有指标明细，无法导出！");
			this.renderJson("没有指标明细，无法导出！");
			return;
		}
		List<Object[]> list = new ArrayList<Object[]>();
        String lastEntryId = "";
        int i=0;
		for(;i<kpiList.size();i++){
			Kpi kpi = kpiList.get(i);
			String entryId = kpi.getKpiEntryid();
			boolean newEntry = !entryId.equals(lastEntryId);
			Entry entry = null;
			if(newEntry){
				entry = jxCommonService.getJxentryById(entryId);
			}
			String typeName = null;
			String kpiType = kpi.getKpiType();
			if(kpiType.equals("0")){
				typeName = "个人专业业务指标";
			}else if(kpiType.equals("1")){
				typeName ="行为指标（价值观）";
			}else if(kpiType.equals("2")){
				typeName ="团队任务指标";
			}
			String[] names = kpi.get("entry_khpersonname").toString().split("_");
            list.add(new Object[]{i+1,kpi.get("entry_cyclename"),names[0],names[1],kpi.get("entry_orgname"),kpi.get("entry_khdeptname"),
					typeName,kpi.getKpiName(),kpi.getKpiCaption(),kpi.getKpiWeight()==null?"": Tool.getStripZeros(kpi.getKpiWeight()).toString()+"%",
                    kpi.getKpiZpscore(),kpi.getKpiZp(),kpi.getKpiScorelv1(),kpi.getKpiInfolv1(),kpi.getKpiScorelv2(),kpi.getKpiInfolv2(),kpi.getKpiScorelv3(),kpi.getKpiInfolv3()
					,newEntry?entry.getEntryZpscore():null,newEntry?entry.getEntryScore():null,newEntry?entry.getEntryRating():null});
			lastEntryId = entryId;
		}
		Entry entryWhere = new Entry();
		entryWhere.setEntryOffline("1");
		entryWhere.setEntryNo(entryNo);
		List<Entry> offLienList = jxCommonService.getJxEntryByWhere(entryWhere);
		if(offLienList.size()>0){
			for (Entry offEntry : offLienList) {
				i++;
				String[] names = offEntry.getEntryKhpersonname().split("_");
				list.add(new Object[]{i+1,offEntry.getEntryCyclename(),names[0],names[1],offEntry.getEntryOrgname(),offEntry.getEntryKhdeptname(),null,null,null,null,
						null,null,null,null
						,offEntry.getEntryZpscore(),offEntry.getEntryScore(),offEntry.getEntryRating()});
			}
		}

		String[] columns = {"序号","考核周期","被考核人姓名","被考核人工号","考核组织","被考核人部门",
				"指标类别","指标","衡量标准","权重%","自评分","自评说明",
				"组长评分","组长评分说明","总监评分","总监评分说明","总经理评分","总经理评分说明","自评总分","综合评分","评级"};
		int[] columnType = {2,1,1,1,1,1,
				1,1,1,1,2,1,
				2,1,2,1,2,1,2,1,1};
		ExcelRender render = ExcelRender.me(list,columns,columnType);
		render.fileName(kpiList.get(0).get("entry_cyclename")+"指标明细");
		render.setContext(this.getRequest(),this.getResponse());
		this.render(render);

		//this.render
	}

	/**
	 * 导出最终得分
	 */
	public void exportEntrys(){
		String entryNo = this.getPara("entryno");
		List<Entry> jxEntryList = jxCommonService.getJxEntryList(entryNo);
		//List<RatingEntry> ratingEntryList = jxCommonService.getRatingEntryList(entryNo);
//		Map<String,RatingEntry> ratingEntryMap = new HashMap<>();
//		for (RatingEntry ratingEntry : ratingEntryList) {
//			ratingEntryMap.put(ratingEntry.getRatingentryId(),ratingEntry);
//		}
		List<Object[]> list = new ArrayList<>();
		for(int i=0;i<jxEntryList.size();i++) {
			Entry entry = jxEntryList.get(i);
			String[] names = entry.getEntryKhpersonname().split("_");
			//RatingEntry ratingEntry = ratingEntryMap.get(entry.getEntryId());
			list.add(new Object[]{i + 1, entry.getEntryCyclename(), names[0],names[1], entry.getEntryOrgname(), entry.getEntryKhdeptname(),entry.getEntryZpscore()
					,entry.getEntryScorelv1() ,entry.getEntryRatinglv1(),entry.getEntryInfolv1()
					,entry.getEntryScorelv2() ,entry.getEntryRatinglv2(),entry.getEntryInfolv2()
					,entry.getEntryScorelv3() ,entry.getEntryRatinglv3(),entry.getEntryInfolv3()
					,entry.getEntryScore() ,entry.getEntryRating()
					//ratingEntry==null?"":ratingEntry.getRatingentryValue(),ratingEntry==null?"":ratingEntry.getRatingentryDeptValueInfo(),ratingEntry==null?"":ratingEntry.getRatingentryCenterValueInfo()
			});
		}
		String[] columns = new String[]{"序号","考核周期","被考核人姓名","被考核人工号","考核组织","被考核人部门","自评总分",
				"组长评分","组长评级","组长综合评价","总监评分","总监评级","总监综合评价","总经理评分","总经理评级","总经理综合评价","最终得分","最终评级"
		 };
		int[] columnType = {2,1,1,1,1,1,2,
				2,1,1,2,1,1,2,1,1,2,1};
		ExcelRender render = ExcelRender.me(list,columns,columnType);
		render.fileName(jxEntryList.get(0).get("entry_cyclename")+"被考核人明细");
		render.setContext(this.getRequest(),this.getResponse());
		this.render(render);
	}
	/**
	 * 导出KPI和公式
	 *
	 */
	public void exportKpiAndExp(){
//		String entryNo = this.getPara("entryno");
//		List<Kpi> kpiList = jxCommonService.getKpiList(entryNo,null);
//		//Map<String, Exp> expMap = expService.getExpMap(entryNo);
//		List<Object[]> list = new ArrayList<>();
//		Kpi lastHeadKpi = null;
//		int lastHeadIndex = 0;
//		String lastHeadPersonId = null;
//		String typeValue = "客观分";
//		BigDecimal kpiWeight = null;
//		Map<String, Kpilib> allKpilibMap = this.getAllKpilib();
//		boolean last = false;
//		for(int i=0;i<=kpiList.size();i++){
//			if(i==kpiList.size())last =true;
//			Kpi kpi = null;
//			if(!last){
//				kpi = kpiList.get(i);
//			}else{
//				kpi = new Kpi();
//			}
//			if(i==0){
//				lastHeadKpi = kpi;
//				lastHeadIndex =0;
//				lastHeadPersonId = kpi.get("entry_khpersonid");
//				if(kpi.getKpiSweight()!=null){
//					kpi.put("sweight",""+kpi.getKpiSweight()+"%");
//				}
//				continue;
//			}
//			String head = kpi.getKpiHead();
//			if(last || head.equals("1")||head.equals("3")){
//
//                typeValue = getKpiTypeStr(lastHeadKpi.getKpiType());
//				String kpilibId = lastHeadKpi.getKpiBaseid();
//				if("2".equals(lastHeadKpi.getKpiIsSel())){//只导出下发的
//					if (StringUtils.isNotBlank(kpilibId)) {
//						Kpilib kpilib = allKpilibMap.get(kpilibId);
//						String unit = kpilib.getKpilibUnit();
//						String paramVaueStr = lastHeadKpi.getKpiFielddata();
//						String[] paramValue = getParamValue(paramVaueStr);
//						list.add(new Object[]{lastHeadIndex + 1, lastHeadKpi.get("entry_khpersonname"), "是",
//								kpilib.getKpilibName(), kpilib.getKpilibTarget(), kpilib.getKpilibDefine(), unit, kpilib.getKpilibCaption(),
//								typeValue, //lastHeadKpi.getKpiGradername(),
//								lastHeadKpi.getKpiWeight() == null ? null : lastHeadKpi.getKpiWeight().divide(new BigDecimal(100)), lastHeadKpi.get("sweight"),
//								paramValue[0], paramValue[1] != null ? paramValue[1] + unit : null, paramValue[2], paramValue[3] != null ? paramValue[3] + unit : null, paramValue[4], paramValue[5] != null ? paramValue[5] + unit : null, paramValue[6], paramValue[7] != null ? paramValue[7] + unit : null,});
//					} else {
//						list.add(new Object[]{lastHeadIndex + 1, lastHeadKpi.get("entry_khpersonname"), "否",
//								lastHeadKpi.getKpiName(), lastHeadKpi.getKpiTarget(), lastHeadKpi.getKpiDefine(), lastHeadKpi.getKpiUnit(), lastHeadKpi.getKpiCaption(),
//								typeValue, //lastHeadKpi.getKpiGradername(),
//								lastHeadKpi.getKpiWeight() == null ? null : lastHeadKpi.getKpiWeight().divide(new BigDecimal(100)), lastHeadKpi.get("sweight"),
//								"", "", "", "", "", "", "", "",});
//					}
//					lastHeadIndex ++;
//				}
//				if(kpi.getKpiSweight()!=null){
//					kpi.put("sweight",""+kpi.getKpiSweight()+"%");
//				}
//
//				String khPersonId = kpi.get("entry_khpersonid");
//				if(last || !lastHeadPersonId.equals(khPersonId) ){
//					BigDecimal selfkpiweight = (BigDecimal)lastHeadKpi.get("entry_selfkpiweight");
//					if(selfkpiweight!=null && selfkpiweight.compareTo(new BigDecimal("0"))!=0){
//						list.add(new Object[]{lastHeadIndex+1,lastHeadKpi.get("entry_khpersonname"),"否",
//								"个人录入指标","","","","",
//								"","",selfkpiweight.divide(new BigDecimal(100)),"",
//								"","","","","","","","",});
//
//					}
//				}
//
//				if(!lastHeadPersonId.equals(khPersonId)){
//					lastHeadIndex = 0;
//				}
//				if(last)break;
//				lastHeadKpi = kpi;
//				lastHeadPersonId = khPersonId;
//			}else{
//				//数据提供人+考核人权重 处理
//				if(kpi.getKpiSweight()!=null){
//					lastHeadKpi.put("sweight",""+lastHeadKpi.get("sweight")+"/"+kpi.getKpiSweight()+"%");
//					//lastHeadKpi.setKpiGradername(lastHeadKpi.getKpiGradername()+"/"+kpi.getKpiGradername());
//				}
//
//			}
//		}
//
//		String[] columns = {"序号","被考核人","是否指标库","关键绩效指标","目标值","指标定义","客观指标单位","考评办法/计算公式"
//				,"评分类型","数据提供人员","指标权重", "考核人权重","自定义参数名称1","自定义参数值1","自定义参数名称2","自定义参数值2","自定义参数名称3","自定义参数值3","自定义参数名称4","自定义参数值4"};
//		//columns = new String[]{"序号","被考核人","关键绩效指标","目标值","指标权重","指标定义","客观指标单位","评分类型","数据提供人员",
//		//	  "考核人权重","考评办法/计算公式"};
//		int[] columnType = {2,1,1,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
//		ExcelRender render = ExcelRender.me(list,columns,columnType);
//		render.fileName(kpiList.get(0).get("entry_cyclename")+"KPI明细-导入格式");
//		render.setContext(this.getRequest(),this.getResponse());
//		this.render(render);
//		//this.render
	}
	private String[] getParamValue(String str){
		String[] ss = new String[8];
		if(StringUtils.isBlank(str)) return ss;
		String[] sstr = str.split(",");
		int i = 0;
		for (String s : sstr) {
			if(StringUtils.isBlank(s))continue;
			String[] sm = s.split(":");
			if(sm.length!=2)continue;
			ss[i]=sm[0];
			ss[i+1]=sm[1];
			i=i+2;
		}
		return ss;
	}

	/**
	 * key - kpilibId
	 * @return
	 */
	private Map<String,Kpilib> getAllKpilib(){
		Map<String, Kpilib> map = new HashMap<>();
		List<Kpilib> kpilibList = kpilibService.getKpilib(new Kpilib());
		for (Kpilib kpilib : kpilibList) {
			map.put(kpilib.getKpilibId(),kpilib);
		}
		return map;
	}
	/**
	 * key - kpilibName
	 * @return
	 */
	private Map<String,Kpilib> getEnableKpilib(String orgId){
		Map<String, Kpilib> map = new HashMap<>();
		List<Kpilib> kpilibList = kpilibService.getKpilibList(orgId);
		for (Kpilib kpilib : kpilibList) {
			map.put(kpilib.getKpilibName(),kpilib);
		}
		return map;
	}
	/**
	 * key - kpilibName
	 * @return
	 */
	private Map<String,Kpilib> getAllKpilibName(){
		Map<String, Kpilib> map = new HashMap<>();
		List<Kpilib> kpilibList = kpilibService.getKpilib(new Kpilib());
		for (Kpilib kpilib : kpilibList) {
			map.put(kpilib.getKpilibName(),kpilib);
		}
		return map;
	}
	/**
	 * 导出KPI和公式
	 *
	 */
	public void exportKpiAndExpOld(){
//		String entryNo = this.getPara("entryno");
//		List<Kpi> kpiList = jxCommonService.getKpiList(entryNo,null);
//		Map<String, Exp> expMap = expService.getExpMap(entryNo);
//		List<Object[]> list = new ArrayList<>();
//		Kpi lastHeadKpi = null;
//		int lastHeadIndex = 0;
//		String lastHeadPersonId = null;
//		String typeValue = "客观分";
//		BigDecimal kpiWeight = null;
//		for(int i=0;i<kpiList.size();i++){
//			Kpi kpi = kpiList.get(i);
//			if(i==0){
//				lastHeadKpi = kpi;
//				lastHeadIndex =0;
//				lastHeadPersonId = kpi.get("entry_khpersonid");
//				continue;
//			}
//			String head = kpi.getKpiHead();
//			if(head.equals("1")||head.equals("3")){
//				String khPersonId = kpi.get("entry_khpersonid");
//
//                typeValue = getKpiTypeStr(lastHeadKpi.getKpiType());
//				list.add(new Object[]{lastHeadIndex+1,lastHeadKpi.get("entry_khpersonname"),lastHeadKpi.getKpiName(),lastHeadKpi.getKpiTarget(),lastHeadKpi.getKpiWeight()==null?null:lastHeadKpi.getKpiWeight().divide(new BigDecimal(100)),
//						lastHeadKpi.getKpiDefine(),lastHeadKpi.getKpiUnit(),typeValue,//lastHeadKpi.getKpiGradername(),
//						// lastHeadKpi.get("sweight"),lastHeadKpi.getKpiCaption(),
//						expMap.get(lastHeadKpi.getKpiId()+"01"),expMap.get(lastHeadKpi.getKpiId()+"02"),expMap.get(lastHeadKpi.getKpiId()+"03"),expMap.get(lastHeadKpi.getKpiId()+"04"),
//						expMap.get(lastHeadKpi.getKpiId()+"05"),expMap.get(lastHeadKpi.getKpiId()+"06"),expMap.get(lastHeadKpi.getKpiId()+"07"),expMap.get(lastHeadKpi.getKpiId()+"08"),
//						expMap.get(lastHeadKpi.getKpiId()+"09"),expMap.get(lastHeadKpi.getKpiId()+"10"),expMap.get(lastHeadKpi.getKpiId()+"11"),expMap.get(lastHeadKpi.getKpiId()+"12"),
//						expMap.get(lastHeadKpi.getKpiId()+"13"),expMap.get(lastHeadKpi.getKpiId()+"14"),expMap.get(lastHeadKpi.getKpiId()+"15"),});
//				if(kpi.getKpiSweight()!=null){
//					kpi.put("sweight",""+kpi.getKpiSweight()+"%");
//				}
//				lastHeadKpi = kpi;
//				lastHeadIndex ++;
//				if(!khPersonId.equals(lastHeadPersonId)){
//					lastHeadIndex = 0;
//				}
//				lastHeadPersonId = khPersonId;
//			}else{
//				//数据提供人+考核人权重 处理
//				if(kpi.getKpiSweight()!=null){
//					lastHeadKpi.put("sweight",""+lastHeadKpi.get("sweight")+"/"+kpi.getKpiSweight()+"%");
//					//lastHeadKpi.setKpiGradername(lastHeadKpi.getKpiGradername()+"/"+kpi.getKpiGradername());
//				}
//
//			}
//		}
//        typeValue = getKpiTypeStr(lastHeadKpi.getKpiType());
//
//		list.add(new Object[]{lastHeadIndex+1,lastHeadKpi.get("entry_khpersonname"),lastHeadKpi.getKpiName(),lastHeadKpi.getKpiTarget(),lastHeadKpi.getKpiWeight()==null?null:lastHeadKpi.getKpiWeight().divide(new BigDecimal(100)),
//				lastHeadKpi.getKpiDefine(),lastHeadKpi.getKpiUnit(),typeValue,//lastHeadKpi.getKpiGradername(),
//				 lastHeadKpi.get("sweight"),lastHeadKpi.getKpiCaption(),
//				expMap.get(lastHeadKpi.getKpiId()+"01"),expMap.get(lastHeadKpi.getKpiId()+"02"),expMap.get(lastHeadKpi.getKpiId()+"03"),expMap.get(lastHeadKpi.getKpiId()+"04"),
//				expMap.get(lastHeadKpi.getKpiId()+"05"),expMap.get(lastHeadKpi.getKpiId()+"06"),expMap.get(lastHeadKpi.getKpiId()+"07"),expMap.get(lastHeadKpi.getKpiId()+"08"),
//				expMap.get(lastHeadKpi.getKpiId()+"09"),expMap.get(lastHeadKpi.getKpiId()+"10"),expMap.get(lastHeadKpi.getKpiId()+"11"),expMap.get(lastHeadKpi.getKpiId()+"12"),
//				expMap.get(lastHeadKpi.getKpiId()+"13"),expMap.get(lastHeadKpi.getKpiId()+"14"),expMap.get(lastHeadKpi.getKpiId()+"15"),});
//		String[] columns = {"序号","被考核人","关键绩效指标","目标值","指标权重","指标定义","客观指标单位","评分类型","数据提供人员",
//				"考核人权重","考评办法/计算公式","公式1","公式2","公式3","公式4","公式5",
//				"公式6","公式7","公式8","公式9","公式10","公式11","公式12","公式13","公式14","公式15"};
//		//columns = new String[]{"序号","被考核人","关键绩效指标","目标值","指标权重","指标定义","客观指标单位","评分类型","数据提供人员",
//		//	  "考核人权重","考评办法/计算公式"};
//		int[] columnType = {2,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
//		ExcelRender render = ExcelRender.me(list,columns,columnType);
//		render.fileName(kpiList.get(0).get("entry_cyclename")+"KPI明细-导入格式");
//		render.setContext(this.getRequest(),this.getResponse());
//		this.render(render);
//		//this.render
	}

	private String getKpiTypeStr(String KpiType){
        if("1".equals(KpiType)){
            return  "主观分";
        }else if("3".equals(KpiType)){
            return "附加项";
        }else{
            return  "客观分";
        }
    }
	/**
	 * 跳转到导入页面
	 */
	public void importUi(){
		String type = this.getPara("type");//1 导入考核人员  2导入评级 3导入线下
		String entryno = this.getPara("entryno");
		this.setAttr("type", type);
		this.setAttr("entryno", entryno);
		Person person = (Person)this.getSession().getAttribute("person");
		boolean isAdmin = (boolean)this.getSession().getAttribute("admin");
		//获取所有状态为生效的考核周期
		List<Cycle> jxCycleList = jxCycleService.getJxCycleList();
		this.setAttr("jxCycleList", jxCycleList);

		if(isAdmin){
			List<Org> enableOrgList = orgService.getOrgList();
			this.setAttr("enableOrgList",enableOrgList);
		}else{
			//获取员工有效的考核组织
			List<Org> enableOrgList = orgService.getOrgList(person.getId());
			this.setAttr("enableOrgList",enableOrgList);
		}
		this.render("import.html");
	}
	/**
	 * 跳转到导出页面
	 */
	public void exportUi(){
		String entryno = this.getPara("entryno");
		this.setAttr("entryno", entryno);

		this.render("export.html");
	}
	/**
	 * 导入数据
	 */
	public void importData()throws Exception{
		String type = this.getPara("type");
		String entryNo = this.getPara("entryno");


		//this.getAttr()

		Person operator = (Person) this.getSession().getAttribute("person");
		boolean isJxjl = (boolean) this.getSession().getAttribute("jxjl");
		//获取文件
		UploadFile file = this.getFile("file");

		boolean isAdmin = (boolean)this.getSession().getAttribute("admin");


		String fileName =  new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+".xlsx";
		//上传文件
		File upFile = new File(pathHead + basePath+fileName);
		if (!upFile.getParentFile().exists()) {
			upFile.getParentFile().mkdirs();
		}
		file.getFile().renameTo(upFile);

        List<Map<String, Object>> dataList = ExcelImportTool.readData(pathHead + basePath, fileName, 0, 0, 0);
        //删除文件
        ExcelImportTool.deleteFile(pathHead + basePath, fileName);

        if ("1".equals(type)){
			String khcycle = this.getPara("khcycle");
			String khorg = this.getPara("khorg");
			this.renderJson(jxCommonService.importJxKpiData(dataList,entryNo,operator,khcycle,khorg,isJxjl,isAdmin));
		}else if("2".equals(type)){
			this.renderJson(jxCommonService.importRatingData(dataList,entryNo,operator,isJxjl,isAdmin));
		}else if("3".equals(type)){//导入线下数据
			String khcycle = this.getPara("khcycle");
			String khorg = this.getPara("khorg");
			String startDate = this.getPara("startDate");
			this.renderJson(jxCommonService.importOfflineData(dataList,entryNo,operator,khcycle,khorg,startDate,isJxjl,isAdmin));
		}else{
			exceptionReturn("获取数据失败");
			return;
		}
	}
   /**
	private void importRatingData(List<Map<String, Object>> dataList,String entryNo,Person operator,boolean isJxjl,boolean isAdmin) {
    // //序号	被考核人	部门	部门领导	部门评级要求	中心	中心领导	中心评级要求
		if(dataList == null ||dataList.size()<2){
			exceptionReturn("缺少数据！");
			return;
		}
		if(StringUtils.isBlank(entryNo)){
			exceptionReturn("数据异常，请重新点开！");
			return;
		}
		String[] titles = {"序号","被考核人","部门","部门领导","部门评级要求","中心","中心领导","中心评级要求"};
		Map<String, Object> titleMap = dataList.get(0);
		Map<String,String> tmap = new HashMap<String,String>();//表头-FX 映射
		for (String s : titleMap.keySet()) {
			tmap.put(titleMap.get(s).toString().trim(),s);
		}
		for (String title : titles) {
			if(!tmap.containsKey(title)){
				exceptionReturn("缺少列<"+title+">,请核对数据！");
				return;
			}
		}
		int i = 0;
		List<RatingEntry> existRatingList = ratingService.getRatingList(entryNo);
		List<RatingDept> ratingDeptList = ratingService.getRatingDept(entryNo);
		List<RatingDept> ratingCenterList = ratingService.getRatingCenter(entryNo);
		List<Entry> jxEntryList = jxCommonService.getJxEntryList(entryNo);
		Map<String,Entry> existEntryMap = new HashMap<String,Entry>();
		Map<String,RatingEntry> existRatingEntryMap = new HashMap<String,RatingEntry>();
		Map<String,String> existDeptMap = new HashMap<String,String>();//长name-id
		Map<String,String> existCenterMap = new HashMap<String,String>();//name-id
		for (Entry entry : jxEntryList) {
			existEntryMap.put(entry.getEntryKhpersonname(),entry);
		}
		for (RatingDept ratingDept : ratingDeptList) {
			existDeptMap.put(ratingDept.getRatingdeptCname(),ratingDept.getRatingdeptId());
		}
		for (RatingDept ratingCenter : ratingCenterList) {
			existCenterMap.put(ratingCenter.getRatingdeptName(),ratingCenter.getRatingdeptId());
		}
		for (RatingEntry ratingEntry : existRatingList) {
			existRatingEntryMap.put(ratingEntry.getRatingentryPersonname(),ratingEntry);
		}
		List<String> excelPersons = new ArrayList<String>();
		//List<String> center = new ArrayList<String>();
		List<RatingEntry> newRatingList = new ArrayList<>();
		List<RatingDept> newRatingDeptList = new ArrayList<>();
		List<RatingDept> newRatingCenterList = new ArrayList<>();
		String currTime = Tool.getCurrTime();
		String pid = operator.getId();
		String pname = operator.getName();
		try {

			for (Map<String, Object> map : dataList) {
				i++;
				if(i==1)continue;//列名
				Object personDate = map.get(tmap.get(titles[1]));
				Object indexData = map.get(tmap.get(titles[0]));
				if((personDate==null||personDate.toString().trim().equals(""))&&(indexData==null||indexData.toString().trim().equals(""))){
					i--;
					break;//识为excel编辑动到空格了。。
				}
				String personName = map.get(tmap.get(titles[1])).toString().trim();
				if(!existEntryMap.containsKey(personName)){
					exceptionReturn("Excel第" + i + "行<" + personName + ">不在原考核名单里！");
					return;
				}
				if(excelPersons.contains(personName)){
					exceptionReturn("Excel第" + i + "行<" + personName + ">存在两条数据！");
					return;
				}
				excelPersons.add(personName);
				String dept = (String) map.get(tmap.get(titles[2]));
				String deptManager = (String) map.get(tmap.get(titles[3]));
				String deptDesc = (String) map.get(tmap.get(titles[4]));
				String center = (String) map.get(tmap.get(titles[5]));
				String centerManager = (String) map.get(tmap.get(titles[6]));
				String centerDesc = (String) map.get(tmap.get(titles[7]));
				if(StringUtils.isBlank(dept)){
					exceptionReturn("Excel第"+i+"行<"+titles[2]+">不能为空！");
					return;
				}
				if(StringUtils.isBlank(deptManager)){
					exceptionReturn("Excel第"+i+"行<"+titles[3]+">不能为空！");
					return;
				}
				if(StringUtils.isBlank(deptDesc)){
					exceptionReturn("Excel第"+i+"行<"+titles[4]+">不能为空！");
					return;
				}
				if(StringUtils.isBlank(center)){
					exceptionReturn("Excel第"+i+"行<"+titles[5]+">不能为空！");
					return;
				}
				if(StringUtils.isBlank(centerManager)){
					exceptionReturn("Excel第"+i+"行<"+titles[6]+">不能为空！");
					return;
				}
				if(StringUtils.isBlank(centerDesc)){
					exceptionReturn("Excel第"+i+"行<"+titles[7]+">不能为空！");
					return;
				}
				RatingEntry ratingEntry = new RatingEntry();
				newRatingList.add(ratingEntry);
				if(existRatingEntryMap.containsKey(personName)){
					ratingEntry.setRatingentryId(existRatingEntryMap.get(personName).getRatingentryId());
				}else{
					ratingEntry.setRatingentryId(UUID.randomUUID().toString().replace("-",""));
				}
				String centerId ="";
				String deptId ="";
				if(!existCenterMap.containsKey(center)){
					centerId = UUID.randomUUID().toString().replace("-","");
					existCenterMap.put(center,centerId);
					RatingDept newCenter = new RatingDept();
					newCenter.setRatingdeptId(centerId);
					newCenter.setRatingdeptName(center);
					newCenter.setRatingdeptType("2");
					newCenter.setRatingdeptEntryno(entryNo);
					newCenter.setRatingdeptDesc(centerDesc);
					newRatingCenterList.add(newCenter);
				}else{
					centerId = existCenterMap.get(center);
				}
				String cname = center+"_"+dept;
				if(!existDeptMap.containsKey(cname)){
					deptId = UUID.randomUUID().toString().replace("-","");
					existDeptMap.put(cname,deptId);
					RatingDept newDept = new RatingDept();
					newDept.setRatingdeptId(deptId);
					newDept.setRatingdeptName(dept);
					newDept.setRatingdeptCname(cname);
					newDept.setRatingdeptPid(centerId);
					newDept.setRatingdeptType("1");
					newDept.setRatingdeptEntryno(entryNo);
					newDept.setRatingdeptDesc(deptDesc);
					newRatingDeptList.add(newDept);
				}else{
					deptId = existDeptMap.get(center);
				}
				ratingEntry.setRatingentryAppnode("0");
				ratingEntry.setRatingentryCenterid(centerId);
				ratingEntry.setRatingentryDeptid(deptId);
				ratingEntry.setRatingentryEntryno(entryNo);
				ratingEntry.setRatingentryPersonid(existEntryMap.get(personName).getEntryId());
				ratingEntry.setRatingentryPersonname(personName);
				ratingEntry.setRatingentryCreatetime(currTime);
				ratingEntry.setRatingentryCreatorid(pid);
				ratingEntry.setRatingentryCreatorname(pname);
			}

			for (RatingDept ratingDept : newRatingCenterList) {
				ratingDept.save();
			}
			for (RatingDept ratingDept : newRatingDeptList) {
				ratingDept.save();
			}
			for (RatingEntry ratingEntry : newRatingList) {
				ratingEntry.save();
			}
            Set useDeptList = new HashSet();
			Set useCenterList = new HashSet();
			existRatingList = ratingService.getRatingList(entryNo);
			ratingDeptList = ratingService.getRatingDept(entryNo);
			ratingCenterList = ratingService.getRatingCenter(entryNo);
			for (RatingEntry ratingEntry : existRatingList) {
				useDeptList.add(ratingEntry.getRatingentryDeptid());
				useCenterList.add(ratingEntry.getRatingentryCenterid());
			}
			for (RatingDept ratingDept : ratingDeptList) {
				if(!useDeptList.contains(ratingDept.getRatingdeptId())){
					ratingDept.delete();
				}
			}
			for (RatingDept ratingDept : ratingCenterList) {
				if(!useCenterList.contains(ratingDept.getRatingdeptId())){
					ratingDept.delete();
				}
			}
		}catch (Exception e){
			log.error("excel导入定级失败",e);
			exceptionReturn("Excel读取到"+(i-1)+"行时出现错误！"+e.getMessage());
			return;
		}
		DataBean dBean = new DataBean();
		dBean.setMsg("成功录入"+(i-1)+"条数据！");

		this.renderJson(dBean);
    }

	private void importJxKpiData(List<Map<String, Object>> dataList,String entryNo,Person operator,boolean isJxjl,boolean isAdmin){

		String khcycle = this.getPara("khcycle");
		String khorg = this.getPara("khorg");
		String pid = operator.getId();

		if(dataList == null ||dataList.size()<2){
			exceptionReturn("缺少数据！");
			return;
		}
		Org org = null;
		Cycle cycle = null;
		String orgName = null;
        if (StringUtils.isNotBlank(entryNo)) {
            List<Entry> jxEntryList = jxCommonService.getJxEntryList(entryNo);
            org = Org.dao.findById(jxEntryList.get(0).getEntryOrgid());
            cycle = Cycle.dao.findById(jxEntryList.get(0).getEntryCycleid());
            orgName = jxEntryList.get(0).getEntryOrgname();

        } else {
            if(StringUtils.isBlank(khcycle)){
                exceptionReturn("请选择考核周期！");
                return;
            }
            if(StringUtils.isBlank(khorg)){
                exceptionReturn("请选择考核组织！");
                return;
            }
            cycle = Cycle.dao.findById(khcycle);

            List<Org> enableOrgList = orgService.getEnableOrgList(pid);

            for (Org o : enableOrgList) {
                if(o.getOrgId().equals(khorg)){
                    org = o;
                    orgName = o.get("fname_l2");
                    break;
                }
            }
        }


        if(cycle==null){
			exceptionReturn("考核周期数据异常，请重试！");
			return;
		}

		if(org==null){
			exceptionReturn("考核组织数据异常，请重试！");
			return;
		}
		String[] titles = {"序号","被考核人","关键绩效指标","目标值","指标权重","指标定义","是否指标库","客观指标单位","评分类型","数据提供人员",
				"数据提供部门","考核人权重","考核组织", "考核周期","考评办法/计算公式","自定义参数名称1","自定义参数值1","自定义参数名称2","自定义参数值2"
				,"自定义参数名称3","自定义参数值3","自定义参数名称4","自定义参数值4"};

		Map<String, Object> titleMap = dataList.get(0);
		Map<String,String> tmap = new HashMap<String,String>();//表头-FX 映射
		for (String s : titleMap.keySet()) {
			tmap.put(titleMap.get(s).toString().trim(),s);
		}
		for (String title : titles) {
			if(title.equals("公式名称")||title.equals("考核组织")||title.equals("考核周期")||title.equals("数据提供部门")){
				continue;
			}
			if(!tmap.containsKey(title)){
				exceptionReturn("缺少列<"+title+">,请核对数据！");
				return;
			}
		}
		List<Person> list= new ArrayList<Person>();
		List<Kpi > kpiList= new ArrayList<Kpi>();

		Person creator= null;
		int lastIndex = 0;
		String entryId = null;
		String lastPerson = "";
		BigDecimal sumWeight = new BigDecimal(0);
		int num =0 ;
		int i = 0;
		List<String> personList = new ArrayList<String>();
		boolean newPerson = true;
		Map<String, Kpilib> kpilibMap = getEnableKpilib(khorg);
		Map<String, Kpilib> allKpilibMap = getAllKpilibName();
		Map<String,BigDecimal> selfKpiMap = new HashMap<>();
		try {

			for(Map<String, Object> map : dataList){
				String person =  map.get(tmap.get(titles[1])).toString().trim();
				String kpiname = (String) map.get(tmap.get(titles[2]));
				kpiname = kpiname.trim();
				boolean isSelfKpi = "个人录入指标".equals(kpiname);
				if(!isSelfKpi)continue;
				String weight = (String) map.get(tmap.get(titles[4]));
				if(StringUtils.isBlank(weight)){
					exceptionReturn("Excel第"+i+"行<"+titles[4]+">不能为空！");
					return;
				}
				BigDecimal weightNum = null;
				try {
					weightNum = new BigDecimal(weight).multiply(new BigDecimal(100));
					selfKpiMap.put(person,weightNum);
				}catch (Exception e){
					exceptionReturn("Excel第"+i+"行<"+titles[4]+">设置有误！");
					return;
				}


			}
			for (Map<String, Object> map : dataList) {
				i++;
				if(i==1)continue;//列名
				//System.out.println("-----------------"+map.get(tmap.get(titles[1])));
				Object personDate = map.get(tmap.get(titles[1]));
				Object indexData = map.get(tmap.get(titles[0]));
				if((personDate==null||personDate.toString().trim().equals(""))&&(indexData==null||indexData.toString().trim().equals(""))){
					i--;
					break;//识为excel编辑动到空格了。。
				}
				//System.out.println(personDate+"----"+indexData);
				String person =  map.get(tmap.get(titles[1])).toString().trim();

				int index = 0;

				try{
					index = Integer.valueOf(map.get(tmap.get(titles[0])).toString().trim());
				}catch (Exception e){
					exceptionReturn("Excel第"+i+"行序号录入有误！");
					return;
				}
				if(index==1){//新被考核人
					if(personList.contains(person)){
						exceptionReturn("Excel第"+i+"行被考核人<"+person+">录入有误！在前面行已经有此人KPI数据！");
						return;
					}
					newPerson = true;
				}else if(index==lastIndex+1){//被考核人非第一条
					if(!person.equals(lastPerson)){
						exceptionReturn("Excel第"+i+"行被考核人<"+person+">或<序号："+index+">录入有误！");
						return;
					}
					newPerson = false;
				}else{
					exceptionReturn("Excel第"+i+"行序号有误！");
					return;
				}
				//entryId
				if(newPerson){
					String[]parr = person.split("_");
					if(parr.length!=2){
						exceptionReturn("Excel第"+i+"行被考核人<"+person+">设置有误！请按（姓名_工号）填写！");
						return;
					}
					Person p = hrService.getPersonByNumberAndName(parr[1],parr[0]);
					if(p==null){
						exceptionReturn("Excel第"+i+"行被考核人<"+person+">设置有误！未查到此人！");
						return;
					}
					if(!(sumWeight.compareTo(new BigDecimal(100))==0 || sumWeight.compareTo(new BigDecimal(0))==0)){
						exceptionReturn("Excel第"+(i-1)+"行被考核人KPI累计<"+titles[4]+">合计不等于100%！");
						return;
					}
					entryId = Tool.uuid();
					num  =1;
					sumWeight = new BigDecimal(0);
					p.put("entryId",entryId);
					p.put("selfKpi",selfKpiMap.get(person));
					list.add(p);
				}

				String kpiname = (String) map.get(tmap.get(titles[2]));
				kpiname = kpiname.trim();
				if(StringUtils.isBlank(kpiname)){
					exceptionReturn("Excel第"+i+"行<"+titles[2]+">不能为空！");
					return;
				}
				boolean isKpilib = "是".equals(map.get(tmap.get(titles[6])));
				boolean isSelfKpi = "个人录入指标".equals(kpiname);
				if(isSelfKpi){
					BigDecimal weightNum = selfKpiMap.get(person);
					sumWeight = sumWeight.add(weightNum);
					if(sumWeight.compareTo(new BigDecimal(100))==1){
						exceptionReturn("Excel第"+i+"行<"+titles[4]+">设置有误,该被考核人KPI累计<"+titles[4]+">超过了100%！");
						return;
					}
					continue;
				}
				Kpilib kl = null;
				if(isKpilib){
					kl = kpilibMap.get(kpiname);

					if(kl == null && !allKpilibMap.containsKey(kpiname)){
						exceptionReturn("Excel第"+i+"行在指标库没查到对应信息！<"+kpiname+">");
						return;
					}
					if(kl == null && allKpilibMap.containsKey(kpiname)){
						Kpilib ek = allKpilibMap.get(kpiname);
						if("2".equals(ek.getKpilibStatus())){
							exceptionReturn("Excel第"+i+"行在指标<"+kpiname+">已禁用！");return;
						}
						if(!khorg.equals(ek.getKpilibOrgid())){
							exceptionReturn("Excel第"+i+"行指标<"+kpiname+">对应考核组织为："+ek.get("fname_l2"));return;
						}

					}

				}

				String kpitype = (String) map.get(tmap.get(titles[8]));
				if(!isKpilib && StringUtils.isBlank(kpitype)){
					exceptionReturn("Excel第"+i+"行<"+titles[8]+">不能为空！");
					return;
				}
				String kpiType = null;//1主观 2客观 3附加项
				if(kpitype.indexOf("主观")>=0)kpiType="1";
				if(kpitype.indexOf("客观")>=0)kpiType="2";
				if(kpitype.indexOf("附加")>=0)kpiType="3";
				if(isKpilib){
					kpiType = kl.getKpilibType();
				}
				if(StringUtils.isBlank(kpiType)){
					exceptionReturn("Excel第"+i+"行<"+titles[8]+">设置有误，请正确填写！");
					return;
				}
				String target = (String) map.get(tmap.get(titles[3]));
				String define = (String) map.get(tmap.get(titles[5]));
				//String expname = (String) map.get(tmap.get(titles[6]));
				String unit = (String) map.get(tmap.get(titles[7]));
				String caption = (String) map.get(tmap.get(titles[14]));
				if(isKpilib){
					target = kl.getKpilibTarget();
					define = kl.getKpilibDefine();
					unit = kl.getKpilibUnit();
					caption = kl.getKpilibCaption();
				}
				String weight = (String) map.get(tmap.get(titles[4]));
				if(StringUtils.isBlank(weight)&&!kpiType.equals("3")){
					exceptionReturn("Excel第"+i+"行<"+titles[4]+">不能为空！");
					return;
				}
				BigDecimal weightNum = null;
				if(StringUtils.isNotBlank(weight)){
					try {
						weightNum = new BigDecimal(weight).multiply(new BigDecimal(100));
					}catch (Exception e){
						exceptionReturn("Excel第"+i+"行<"+titles[4]+">设置有误！");
						return;
					}
					sumWeight = sumWeight.add(weightNum);
					if(sumWeight.compareTo(new BigDecimal(100))==1){
						exceptionReturn("Excel第"+i+"行<"+titles[4]+">设置有误,该被考核人KPI累计<"+titles[4]+">超过了100%！");
						return;
					}
				}

				String grader = (String) map.get(tmap.get(titles[9]));
				if(StringUtils.isBlank(grader)&&!kpiType.equals("3")){
					exceptionReturn("Excel第"+i+"行<"+titles[9]+">不能为空！");
					return;
				}
				//String dept = (String) map.get(tmap.get(titles[10]));


				String sweight = (String) map.get(tmap.get(titles[11]));

				Person gra = null;//单个评分人
				Person[] gras = null;//多个评分人
				BigDecimal[] sweights = null;
				int grasCount = 0;//是否有评分人
				if(StringUtils.isNotBlank(grader)){//有评分人的情况
					String[] graders = grader.split("/");
					grasCount = graders.length;
					if(graders.length>1){//多个评分人
						if(StringUtils.isBlank(sweight)){
							exceptionReturn("Excel第"+i+"行<"+titles[11]+">不能为空！");
							return;
						}
						String[] ss = sweight.split("/");
						if(graders.length!=ss.length){
							exceptionReturn("Excel第"+i+"行<"+titles[9]+">与<"+titles[11]+">个数不匹配！");
							return;
						}
						sweights = new BigDecimal[graders.length];
						gras = new Person[graders.length];
						BigDecimal sumNum = new BigDecimal(0);//累计考核人权重
						for (int j =0;j<ss.length;j++) {
							String s=ss[j];
							if(!s.endsWith("%")){
								exceptionReturn("Excel第"+i+"行<"+titles[11]+">设置有误！请按格式如：（40%/60%）设置");
								return;
							}
							BigDecimal b = null;
							try {
								b = new BigDecimal(s.substring(0,s.length()-1));
							}catch (Exception e){
								exceptionReturn("Excel第"+i+"行<"+titles[11]+">设置有误！");
								return;
							}

							sweights[j] = b;
							sumNum = sumNum.add(b);
						}
						if(!(sumNum.compareTo(new BigDecimal(100))==0)){
							exceptionReturn("Excel第"+(i)+"行"+titles[11]+"合计不等于100%！");
							return;
						}
						for (int j =0;j<graders.length;j++) {
							String s = graders[j];
							String[]parr = s.split("_");
							if(parr.length!=2){
								exceptionReturn("Excel第"+i+"行评分人<"+s+">设置有误！请按（姓名_工号）填写！");
								return;
							}
							Person pp = hrService.getPersonByNumberAndName(parr[1],parr[0]);
							if(pp==null){
								exceptionReturn("Excel第"+i+"行评分人<"+s+">设置有误！未查到此人！");
								return;
							}
							gras[j] = pp;
						}

					}else{//一个评分人
						String[]parr = grader.split("_");
						if(parr.length!=2){
							exceptionReturn("Excel第"+i+"行评分人<"+grader+">设置有误！请按（姓名_工号）填写！");
							return;
						}
						gra = hrService.getPersonByNumberAndName(parr[1],parr[0]);
						if(gra==null){
							exceptionReturn("Excel第"+i+"行评分人<"+grader+">设置有误！未查到此人！");
							return;
						}
					}
				}


				String expkey1 = (String) map.get(tmap.get(titles[15]));
				String expval1 = (String) map.get(tmap.get(titles[16]));
				String expkey2 = (String) map.get(tmap.get(titles[17]));
				String expval2 = (String) map.get(tmap.get(titles[18]));
				String expkey3 = (String) map.get(tmap.get(titles[19]));
				String expval3 = (String) map.get(tmap.get(titles[20]));
				String expkey4 = (String) map.get(tmap.get(titles[21]));
				String expval4 = (String) map.get(tmap.get(titles[22]));
				if(kpiType.equals("2") && !isKpilib){
					exceptionReturn("Excel第"+i+"行客观评分时，<是否指标库>需为<是>！");
					return;
				}
				Map<String,BigDecimal> paramValue = null;
				if(kpiType.equals("2")){
					if(StringUtils.isBlank(expkey1)!=StringUtils.isBlank(expval1)||StringUtils.isBlank(expkey3)!=StringUtils.isBlank(expval3)
							||StringUtils.isBlank(expkey2)!=StringUtils.isBlank(expval2)||StringUtils.isBlank(expkey4)!=StringUtils.isBlank(expval4)){
						exceptionReturn("Excel第"+i+"行自定义参数请对应填写！");return;
					}
					if((StringUtils.isNotBlank(expkey1) && !expval1.endsWith(unit))||(StringUtils.isNotBlank(expkey2) && !expval2.endsWith(unit))||(StringUtils.isNotBlank(expkey3) && !expval3.endsWith(unit))||(StringUtils.isNotBlank(expkey4) && !expval4.endsWith(unit))){
						exceptionReturn("Excel第"+i+"行自定义参数值请以客观单位结尾！如："+20+unit);return;
					}

				}else{
					if(StringUtils.isNotBlank(expkey1)||StringUtils.isNotBlank(expkey2)||StringUtils.isNotBlank(expkey3)||StringUtils.isNotBlank(expkey4)
							||StringUtils.isNotBlank(expval1)||StringUtils.isNotBlank(expval2)||StringUtils.isNotBlank(expval3)||StringUtils.isNotBlank(expval4)){
						exceptionReturn("Excel第"+i+"行非客观评分时请不要设置自定义参数！");return;
					}
				}
				List<Exp> expList = null;
				if(isKpilib){
					paramValue = new LinkedHashMap<String,BigDecimal>();
					try{
						int unitLen = unit.length();
						if(StringUtils.isNotBlank(expkey1))paramValue.put(expkey1,new BigDecimal(expval1.substring(0,expval1.length()-unitLen)));
						if(StringUtils.isNotBlank(expkey2))paramValue.put(expkey2,new BigDecimal(expval2.substring(0,expval2.length()-unitLen)));
						if(StringUtils.isNotBlank(expkey3))paramValue.put(expkey3,new BigDecimal(expval3.substring(0,expval3.length()-unitLen)));
						if(StringUtils.isNotBlank(expkey4))paramValue.put(expkey4,new BigDecimal(expval4.substring(0,expval4.length()-unitLen)));
					}catch (Exception e){
						exceptionReturn("Excel第"+i+"行自定义参数取数异常！不能转化为数字");return;
					}
					try {
						expList = kpilibService.getExp(kl.getKpilibId(), paramValue);
					}catch (Exception e){
						exceptionReturn("Excel第"+i+"行获取公式错误！"+e.getMessage());return;
					}

				}

				Kpi kpi = new Kpi();
				kpi.setKpiIndex(index);
				kpi.setKpiEntryid(entryId);
				kpi.setKpiName(kpiname);
				kpi.setKpiType(kpiType);
				if(isKpilib){
					kpi.setKpiTarget(StringUtils.isNotBlank(target.trim())?target.trim():kl.getKpilibTarget());
					kpi.setKpiUnit(kl.getKpilibUnit());
					kpi.setKpiDefine(kl.getKpilibDefine());
					kpi.setKpiCaption(kl.getKpilibCaption());
					kpi.setKpiBaseid(kl.getKpilibId());
				}else{
					kpi.setKpiTarget(target.trim());
					//kpi.setKpiExpname(expname);
					kpi.setKpiUnit(unit);
					kpi.setKpiDefine(define);
					kpi.setKpiCaption(caption);
				}
				if(paramValue!=null&& paramValue.size()>0){
					String pv = "";
					for (String param:paramValue.keySet()){
						pv += ","+param+":"+paramValue.get(param).toString();
					}
					kpi.setKpiFielddata(pv.substring(1));
				}

				kpi.setKpiWeight(weightNum);
				kpi.setKpiNum(num<10?"0"+num:""+num);
				kpi.put("expList",expList);
				//kpi.setKpiSweight(json.getBigDecimal("kpisweight"));
				// kpi.setKpiGraderid(json.getString("kpigraderid"));
				// kpi.setKpiGradername(json.getString("kpigradername"));
				if(grasCount ==0 ||grasCount==1){
					if(gra!=null){
						kpi.setKpiGraderid(gra.getId());
						kpi.setKpiGradername(gra.getName());
					}
					kpiList.add(kpi);
				}else{
					for(int ii=0;ii<grasCount;ii++){
						num++;
						Person p = gras[ii];
						Kpi k = this.copyExp(kpi);
						k.setKpiGraderid(p.getId());
						k.setKpiGradername(p.getName());
						k.setKpiSweight(sweights[ii]);
						k.setKpiNum(num<10?"0"+num:""+num);
						kpiList.add(k);
					}
				}
				lastPerson = person;
				lastIndex = index;
				num++;
				if(!personList.contains(person)){
					personList.add(person);
				}
			}
		}catch (Exception e){
			log.error("excel导入考核失败",e);
			exceptionReturn("Excel读取到"+(i-1)+"行时出现错误！"+e.getMessage());
			return;
		}
		if(!(sumWeight.compareTo(new BigDecimal(100))==0 || sumWeight.compareTo(new BigDecimal(0))==0)){
			exceptionReturn("Excel第"+(i-1)+"行被考核人KPI累计<"+titles[4]+">合计不等于100%！");
			return;
		}
		try {
			jxCommonService.saveEntrys( list, kpiList, org.getOrgId(), orgName, cycle, entryNo,operator);
		}catch (Exception e){
			String m = e.getMessage();
			if(m==null||m.indexOf("Exception")>0){
				e.printStackTrace();
			}
			exceptionReturn(e.getMessage());
			return;
		}

		DataBean dBean = new DataBean();
		dBean.setMsg("成功录入"+(i-1)+"条数据！");

		this.renderJson(dBean);
	}
 */
	public void importData_Old()throws Exception{
//		String type = this.getPara("type");
//		String entryNo = this.getPara("entryNo");
//
//
//		//this.getAttr()
//		String msg = "";
//		Person operator = (Person) this.getSession().getAttribute("person");
//		String pid = operator.getId();
//		boolean isJxjl = (boolean) this.getSession().getAttribute("jxjl");
//		//获取文件
//		UploadFile file = this.getFile("file");
//		String khcycle = this.getPara("khcycle");
//		String khorg = this.getPara("khorg");
//		boolean isAdmin = (boolean)this.getSession().getAttribute("admin");
//		String fileName =  new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+".xlsx";
//		//上传文件
//		File upFile = new File(pathHead + basePath+fileName);
//		if (!upFile.getParentFile().exists()) {
//			upFile.getParentFile().mkdirs();
//		}
//		file.getFile().renameTo(upFile);
////		//获取jxcycle
////		Cycle jxCycle = Cycle.dao.findById(cycleid);
////		if(jxCycle == null){
////			exceptionReturn("参数异常");
////			return;
////		}
//
//
//		int i = 0;
//		if (type.equals("1")){ //
//			List<Map<String, Object>> list1 = ExcelImportTool.readData(pathHead + basePath, fileName, 0, 0, 0);
//			if(list1 == null ||list1.size()<2){
//				exceptionReturn("缺少数据！");
//				return;
//			}
//			Org org = null;
//			Cycle cycle = null;
//			String orgName = null;
//			if(StringUtils.isBlank(entryNo)){
//				if(StringUtils.isBlank(khcycle)){
//					exceptionReturn("请选择考核周期！");
//					return;
//				}
//				if(StringUtils.isBlank(khorg)){
//					exceptionReturn("请选择考核组织！");
//					return;
//				}
//				cycle = Cycle.dao.findById(khcycle);
//
//				List<Org> enableOrgList = orgService.getEnableOrgList(pid);
//
//				for (Org o : enableOrgList) {
//					if(o.getOrgId().equals(khorg)){
//						org = o;
//						orgName = o.get("fname_l2");
//						break;
//					}
//				}
//			}else{
//				List<Entry> jxEntryList = jxCommonService.getJxEntryList(entryNo);
//				org = Org.dao.findById(jxEntryList.get(0).getEntryOrgid());
//				cycle = Cycle.dao.findById(jxEntryList.get(0).getEntryCycleid());
//				orgName = jxEntryList.get(0).getEntryOrgname();
//
//			}
//
//
//
//			if(cycle==null){
//				exceptionReturn("考核周期数据异常，请重试！");
//				return;
//			}
//
//			if(org==null){
//				exceptionReturn("考核组织数据异常，请重试！");
//				return;
//			}
//			String[] titles = {"序号","被考核人","关键绩效指标","目标值","指标权重","指标定义","公式名称","客观指标单位","评分类型","数据提供人员",
//					"数据提供部门","考核人权重","考核组织", "考核周期","考评办法/计算公式","公式1","公式2","公式3","公式4","公式5",
//					"公式6","公式7","公式8","公式9","公式10","公式11","公式12","公式13","公式14","公式15"};
//
//			Map<String, Object> titleMap = list1.get(0);
//			Map<String,String> tmap = new HashMap<String,String>();//表头-FX 映射
//			for (String s : titleMap.keySet()) {
//				tmap.put(titleMap.get(s).toString().trim(),s);
//			}
//			for (String title : titles) {
//				if(title.equals("公式名称")||title.equals("考核组织")||title.equals("考核周期")||title.equals("数据提供部门")){
//					continue;
//				}
//				if(!tmap.containsKey(title)){
//					exceptionReturn("缺少列<"+title+">,请核对数据！");
//					return;
//				}
//			}
//
//
//
//			List<Person> list= new ArrayList<Person>();
//			List<Kpi > kpiList= new ArrayList<Kpi>();
//
//			Person creator= null;
//			int lastIndex = 0;
//			String entryId = null;
//			String lastPerson = "";
//			BigDecimal sumWeight = new BigDecimal(0);
//			int num =0 ;
//			List<String> personList = new ArrayList<String>();
//			boolean newPerson = true;
//			try {
//
//
//				for (Map<String, Object> map : list1) {
//					i++;
//					if(i==1)continue;//列名
//					//System.out.println("-----------------"+map.get(tmap.get(titles[1])));
//					Object personDate = map.get(tmap.get(titles[1]));
//					Object indexData = map.get(tmap.get(titles[0]));
//					if((personDate==null||personDate.toString().trim().equals(""))&&(indexData==null||indexData.toString().trim().equals(""))){
//						i--;
//						break;//识为excel编辑动到空格了。。
//					}
//					System.out.println(personDate+"----"+indexData);
//					String person =  map.get(tmap.get(titles[1])).toString().trim();
//
//					int index = 0;
//
//					try{
//						index = Integer.valueOf(map.get(tmap.get(titles[0])).toString().trim());
//					}catch (Exception e){
//						exceptionReturn("Excel第"+i+"行序号录入有误！");
//						return;
//					}
//					if(index==1){//新被考核人
//						if(personList.contains(person)){
//							exceptionReturn("Excel第"+i+"行被考核人<"+person+">录入有误！在前面行已经有此人KPI数据！");
//							return;
//						}
//						newPerson = true;
//					}else if(index==lastIndex+1){//被考核人非第一条
//						if(!person.equals(lastPerson)){
//							exceptionReturn("Excel第"+i+"行被考核人<"+person+">或<序号："+index+">录入有误！");
//							return;
//						}
//						newPerson = false;
//					}else{
//						exceptionReturn("Excel第"+i+"行序号有误！");
//						return;
//					}
//					//entryId
//					if(newPerson){
//						String[]parr = person.split("_");
//						if(parr.length!=2){
//							exceptionReturn("Excel第"+i+"行被考核人<"+person+">设置有误！请按（姓名_工号）填写！");
//							return;
//						}
//						Person p = hrService.getPersonByNumberAndName(parr[1],parr[0]);
//						if(p==null){
//							exceptionReturn("Excel第"+i+"行被考核人<"+person+">设置有误！未查到此人！");
//							return;
//						}
//						if(!(sumWeight.compareTo(new BigDecimal(100))==0 || sumWeight.compareTo(new BigDecimal(0))==0)){
//							exceptionReturn("Excel第"+(i-1)+"行被考核人KPI累计<"+titles[4]+">合计不等于100%！");
//							return;
//						}
//						entryId = Tool.uuid();
//						num  =1;
//						sumWeight = new BigDecimal(0);
//						p.put("entryId",entryId);
//						list.add(p);
//					}
//
//					String kpiname = (String) map.get(tmap.get(titles[2]));
//					if(StringUtils.isBlank(kpiname)){
//						exceptionReturn("Excel第"+i+"行<"+titles[2]+">不能为空！");
//						return;
//					}
//					String kpitype = (String) map.get(tmap.get(titles[8]));
//					if(StringUtils.isBlank(kpitype)){
//						exceptionReturn("Excel第"+i+"行<"+titles[8]+">不能为空！");
//						return;
//					}
//					String kpiType = null;//1主观 2客观 3附加项
//					if(kpitype.indexOf("主观")>=0)kpiType="1";
//					if(kpitype.indexOf("客观")>=0)kpiType="2";
//					if(kpitype.indexOf("附加")>=0)kpiType="3";
//					if(StringUtils.isBlank(kpiType)){
//						exceptionReturn("Excel第"+i+"行<"+titles[8]+">设置有误，请正确填写！");
//						return;
//					}
//					String target = (String) map.get(tmap.get(titles[3]));
//					String define = (String) map.get(tmap.get(titles[5]));
//					//String expname = (String) map.get(tmap.get(titles[6]));
//					String unit = (String) map.get(tmap.get(titles[7]));
//
//					String weight = (String) map.get(tmap.get(titles[4]));
//					if(StringUtils.isBlank(weight)&&!kpiType.equals("3")){
//						exceptionReturn("Excel第"+i+"行<"+titles[4]+">不能为空！");
//						return;
//					}
//					BigDecimal weightNum = null;
//					if(StringUtils.isNotBlank(weight)){
//						try {
//							weightNum = new BigDecimal(weight).multiply(new BigDecimal(100));
//						}catch (Exception e){
//							exceptionReturn("Excel第"+i+"行<"+titles[4]+">设置有误！");
//							return;
//						}
//						sumWeight = sumWeight.add(weightNum);
//						if(sumWeight.compareTo(new BigDecimal(100))==1){
//							exceptionReturn("Excel第"+i+"行<"+titles[4]+">设置有误,该被考核人KPI累计<"+titles[4]+">超过了100%！");
//							return;
//						}
//					}
//
//					String grader = (String) map.get(tmap.get(titles[9]));
//					if(StringUtils.isBlank(grader)&&!kpiType.equals("3")){
//						exceptionReturn("Excel第"+i+"行<"+titles[9]+">不能为空！");
//						return;
//					}
//					String dept = (String) map.get(tmap.get(titles[10]));
//
//					String caption = (String) map.get(tmap.get(titles[14]));
//					String sweight = (String) map.get(tmap.get(titles[11]));
//
//					Person gra = null;//单个评分人
//					Person[] gras = null;//多个评分人
//					BigDecimal[] sweights = null;
//					int grasCount = 0;//是否有评分人
//					if(StringUtils.isNotBlank(grader)){//有评分人的情况
//						String[] graders = grader.split("/");
//						grasCount = graders.length;
//						if(graders.length>1){//多个评分人
//							if(StringUtils.isBlank(sweight)){
//								exceptionReturn("Excel第"+i+"行<"+titles[11]+">不能为空！");
//								return;
//							}
//							String[] ss = sweight.split("/");
//							if(graders.length!=ss.length){
//								exceptionReturn("Excel第"+i+"行<"+titles[9]+">与<"+titles[11]+">个数不匹配！");
//								return;
//							}
//							sweights = new BigDecimal[graders.length];
//							gras = new Person[graders.length];
//							BigDecimal sumNum = new BigDecimal(0);//累计考核人权重
//							for (int j =0;j<ss.length;j++) {
//								String s=ss[j];
//								if(!s.endsWith("%")){
//									exceptionReturn("Excel第"+i+"行<"+titles[11]+">设置有误！请按格式如：（40%/60%）设置");
//									return;
//								}
//								BigDecimal b = null;
//								try {
//									b = new BigDecimal(s.substring(0,s.length()-1));
//								}catch (Exception e){
//									exceptionReturn("Excel第"+i+"行<"+titles[11]+">设置有误！");
//									return;
//								}
//
//								sweights[j] = b;
//								sumNum = sumNum.add(b);
//							}
//							if(!(sumNum.compareTo(new BigDecimal(100))==0)){
//								exceptionReturn("Excel第"+(i)+"行"+titles[11]+"合计不等于100%！");
//								return;
//							}
//							for (int j =0;j<graders.length;j++) {
//								String s = graders[j];
//								String[]parr = s.split("_");
//								if(parr.length!=2){
//									exceptionReturn("Excel第"+i+"行评分人<"+s+">设置有误！请按（姓名_工号）填写！");
//									return;
//								}
//								Person pp = hrService.getPersonByNumberAndName(parr[1],parr[0]);
//								if(pp==null){
//									exceptionReturn("Excel第"+i+"行评分人<"+s+">设置有误！未查到此人！");
//									return;
//								}
//								gras[j] = pp;
//							}
//
//						}else{//一个评分人
//							String[]parr = grader.split("_");
//							if(parr.length!=2){
//								exceptionReturn("Excel第"+i+"行评分人<"+grader+">设置有误！请按（姓名_工号）填写！");
//								return;
//							}
//							gra = hrService.getPersonByNumberAndName(parr[1],parr[0]);
//							if(gra==null){
//								exceptionReturn("Excel第"+i+"行评分人<"+grader+">设置有误！未查到此人！");
//								return;
//							}
//						}
//					}
//
//					String exp1 = (String) map.get(tmap.get(titles[15]));
//					String exp2 = (String) map.get(tmap.get(titles[16]));
//					String exp3 = (String) map.get(tmap.get(titles[17]));
//					String exp4 = (String) map.get(tmap.get(titles[18]));
//					String exp5 = (String) map.get(tmap.get(titles[19]));
//					String exp6 = (String) map.get(tmap.get(titles[20]));
//					String exp7 = (String) map.get(tmap.get(titles[21]));
//					String exp8 = (String) map.get(tmap.get(titles[22]));
//					String exp9 = (String) map.get(tmap.get(titles[23]));
//					String exp10 = (String) map.get(tmap.get(titles[24]));
//					String exp11 = (String) map.get(tmap.get(titles[25]));
//					String exp12 = (String) map.get(tmap.get(titles[26]));
//					String exp13 = (String) map.get(tmap.get(titles[27]));
//					String exp14 = (String) map.get(tmap.get(titles[28]));
//					String exp15 = (String) map.get(tmap.get(titles[29]));
//					List<String> elist = new ArrayList<>();
//					if(StringUtils.isNotBlank(exp1))elist.add(exp1);
//					if(StringUtils.isNotBlank(exp2))elist.add(exp2);
//					if(StringUtils.isNotBlank(exp3))elist.add(exp3);
//					if(StringUtils.isNotBlank(exp4))elist.add(exp4);
//					if(StringUtils.isNotBlank(exp5))elist.add(exp5);
//					if(StringUtils.isNotBlank(exp6))elist.add(exp6);
//					if(StringUtils.isNotBlank(exp7))elist.add(exp7);
//					if(StringUtils.isNotBlank(exp8))elist.add(exp8);
//					if(StringUtils.isNotBlank(exp9))elist.add(exp9);
//					if(StringUtils.isNotBlank(exp10))elist.add(exp10);
//					if(StringUtils.isNotBlank(exp11))elist.add(exp11);
//					if(StringUtils.isNotBlank(exp12))elist.add(exp12);
//					if(StringUtils.isNotBlank(exp13))elist.add(exp13);
//					if(StringUtils.isNotBlank(exp14))elist.add(exp14);
//					if(StringUtils.isNotBlank(exp15))elist.add(exp15);
//					List<Exp> expList = null;
//					try{
//						expList = this.getExpList(elist);
//					}catch (Exception e){
//						exceptionReturn("Excel第"+i+"行错误！"+e.getMessage());
//						return;
//					}
//
//					Kpi kpi = new Kpi();
//					kpi.setKpiIndex(index);
//					kpi.setKpiEntryid(entryId);
//					kpi.setKpiName(kpiname.trim());
//					kpi.setKpiTarget(target.trim());
//					kpi.setKpiType(kpiType);
//					//kpi.setKpiExpname(expname);
//					kpi.setKpiUnit(unit);
//					kpi.setKpiDefine(define);
//					kpi.setKpiCaption(caption);
//					kpi.setKpiWeight(weightNum);
//					kpi.setKpiNum(num<10?"0"+num:""+num);
//					kpi.put("expList",expList);
//					//kpi.setKpiSweight(json.getBigDecimal("kpisweight"));
//					// kpi.setKpiGraderid(json.getString("kpigraderid"));
//					// kpi.setKpiGradername(json.getString("kpigradername"));
//					if(grasCount ==0 ||grasCount==1){
//						if(gra!=null){
//							kpi.setKpiGraderid(gra.getId());
//							kpi.setKpiGradername(gra.getName());
//						}
//						kpiList.add(kpi);
//					}else{
//						for(int ii=0;ii<grasCount;ii++){
//							num++;
//							Person p = gras[ii];
//							Kpi k = this.copyExp(kpi);
//							k.setKpiGraderid(p.getId());
//							k.setKpiGradername(p.getName());
//							k.setKpiSweight(sweights[ii]);
//							k.setKpiNum(num<10?"0"+num:""+num);
//							kpiList.add(k);
//						}
//					}
//					lastPerson = person;
//					lastIndex = index;
//					num++;
//					if(!personList.contains(person)){
//						personList.add(person);
//					}
//				}
//			}catch (Exception e){
//				exceptionReturn("Excel读取到"+(i-1)+"行时出现错误！");
//				return;
//			}
//			if(!(sumWeight.compareTo(new BigDecimal(100))==0 || sumWeight.compareTo(new BigDecimal(0))==0)){
//				exceptionReturn("Excel第"+(i-1)+"行被考核人KPI累计<"+titles[4]+">合计不等于100%！");
//				return;
//			}
//			try {
//				jxCommonService.saveEntrys( list, kpiList, org.getOrgId(), orgName, cycle, entryNo,operator);
//			}catch (Exception e){
//				String m = e.getMessage();
//				if(m==null||m.indexOf("Exception")>0){
//					e.printStackTrace();
//				}
//				exceptionReturn(e.getMessage());
//				return;
//			}
//
//
//
//		}else{
//			exceptionReturn("获取数据失败");
//			return;
//		}
//
//
//		//删除文件
//		ExcelImportTool.deleteFile(pathHead + basePath, fileName);
//
//
//
//		DataBean dBean = new DataBean();
//		if(msg.equals("")){
//			dBean.setCode(1);
//			dBean.setMsg("成功录入"+(i-1)+"条数据！");
//		}else{
//			dBean.setCode(-1);
//			dBean.setMsg(msg);
//		}
//		this.renderJson(dBean);

	}


	private void exceptionReturn(String msg){
		DataBean dBean = new DataBean();
		dBean.setCode(-1);
		dBean.setMsg("导入失败!"+msg);
		this.renderJson(dBean);
	}

//	private List<Exp> getExpList(List<String> list){
//		if(list==null||list.size()==0){
//			return null;
//		}
//		List<Exp> expList= new ArrayList<Exp>();
//		for (int i=0;i<list.size();i++) {
//			String s = list.get(i);
//			s = s.trim();
//			s = s.replace("：",":");
//			String[] ss = s.split(":");
//			if(ss.length!=2){
//				throw new RuntimeException("公式"+(i+1)+"缺少符号<:>！");
//			}
//			if(s.indexOf(":")<3||s.indexOf(":")>s.length()-2){
//				throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//			}
//			String d = ss[0].trim();
//			String score = ss[1].trim();
//			String[] scores = score.split("-");
//
//			BigDecimal firdata = null;
//			BigDecimal secdata = null;
//			String firsign = "";
//			String secsign = "";
//			BigDecimal firscore = null;
//			BigDecimal secscore = null;
//			Exp exp = new Exp();
//			int dateIndex = d.indexOf("值");//1≤ 2< 3>  4≥  5=
//			if(dateIndex==d.length()-1){// 5<值
//				if(scores.length!=1||dateIndex<2){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//
//				firsign = d.substring(dateIndex-1,dateIndex);
//				firsign = this.getSignIndex(firsign);
//				if(StringUtils.isBlank(firsign)){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//				String fdata = d.substring(0,dateIndex-1);
//				try{
//					firscore = new BigDecimal(score);
//					firdata = new BigDecimal(fdata);
//				}catch (Exception e){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//
//
//			}else if(dateIndex==0){//值>15
//				if(scores.length!=1){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//				secsign = d.substring(dateIndex+1,dateIndex+2);
//				secsign = this.getSignIndex(secsign);
//				if(StringUtils.isBlank(secsign)){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//				String sdata = d.substring(dateIndex+2);
//				try{
//					secscore = new BigDecimal(score);
//					secdata = new BigDecimal(sdata);
//				}catch (Exception e){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//			}else{//30>值>22    :0-80
//				if(scores.length!=2){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//				firsign = d.substring(dateIndex-1,dateIndex);
//				secsign = d.substring(dateIndex+1,dateIndex+2);
//				firsign = this.getSignIndex(firsign);
//				if(StringUtils.isBlank(firsign)){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//				secsign = this.getSignIndex(secsign);
//				if(StringUtils.isBlank(secsign)){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//				String sdata = d.substring(dateIndex+2);
//				String fdata = d.substring(0,dateIndex-1);
//				try{
//					firscore = new BigDecimal(scores[0]);
//					secscore = new BigDecimal(scores[1]);
//					firdata = new BigDecimal(fdata);
//					secdata = new BigDecimal(sdata);
//				}catch (Exception e){
//					throw new RuntimeException("公式"+(i+1)+"设置有误，请核对格式！");
//				}
//			}
//			exp.setExpFirsign(firsign);
//			exp.setExpFirscore(firscore);
//			exp.setExpFirdata(firdata);
//			exp.setExpSecsign(secsign);
//			exp.setExpSecscore(secscore);
//			exp.setExpSecdata(secdata);
//			expList.add(exp);
//
//		}
//		return expList;
//	}

	private String getSignIndex(String sign){//1≤ 2< 3>  4≥  5=
		if(sign.equals("≤"))return "1";
		if(sign.equals("<"))return "2";
		if(sign.equals(">"))return "3";
		if(sign.equals("≥"))return "4";
		if(sign.equals("="))return "5";
		return null;
	}
}
