package com.yonyou.hrcloud.pm.ps.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.hrcloud.adder.exception.AdderBusinessException;
import com.yonyou.hrcloud.adder.model.param.Sorter;
import com.yonyou.hrcloud.adder.model.query.Condition;
import com.yonyou.hrcloud.adder.model.query.Operator;
import com.yonyou.hrcloud.pm.base.model.Dimensionality;
import com.yonyou.hrcloud.pm.common.model.CommonValue;
import com.yonyou.hrcloud.pm.common.model.PmStaff;
import com.yonyou.hrcloud.pm.helper.ListHelper;
import com.yonyou.hrcloud.pm.helper.LoggerDecorator;
import com.yonyou.hrcloud.pm.helper.StaffHelper;
import com.yonyou.hrcloud.pm.ps.dao.ISheetIndicatorDao;
import com.yonyou.hrcloud.pm.ps.model.Approver;
import com.yonyou.hrcloud.pm.ps.model.EvaAppraiser;
import com.yonyou.hrcloud.pm.ps.model.EvaObject;
import com.yonyou.hrcloud.pm.ps.model.EvaSetting;
import com.yonyou.hrcloud.pm.ps.model.Gauge;
import com.yonyou.hrcloud.pm.ps.model.GaugeIndicator;
import com.yonyou.hrcloud.pm.ps.model.Scheme;
import com.yonyou.hrcloud.pm.ps.model.Sheet;
import com.yonyou.hrcloud.pm.ps.service.IEvaGroupService;
import com.yonyou.hrcloud.pm.ps.service.IEvaSettingService;
import com.yonyou.hrcloud.pm.ps.service.IGaugeService;
import com.yonyou.hrcloud.pm.ps.service.ISchemeGaugeService;
import com.yonyou.hrcloud.pm.ps.service.ISheetIndicatorService;

/**
 * @author NIJB
 * @version 1.0
 * @ClassName SchemeGaugeServiceImpl
 * @description 方案量表实现层
 * @date 2019/5/6
 **/
@Service
@Transactional
public class SchemeGaugeServiceImpl implements ISchemeGaugeService {

    @Resource
    public com.yonyou.hrcloud.adder.service.IGenericService daoex;
    
    @Resource
    public IEvaGroupService groupSrv;
    
    @Resource
    IGaugeService gaugeService;
    
    @Resource
    public ISheetIndicatorDao sheetIndicatorDao;
    
    @Resource
    public ISheetIndicatorService sheetIndicatorService;
    
    @Resource
    public IEvaSettingService evaSettingService;

    protected static final Logger logger = new LoggerDecorator(SchemeGaugeServiceImpl.class);
    
	@Override
	public void createIndiOnStartScheme(Scheme scheme) throws AdderBusinessException {
		// 查询出方案下所有的考核对象
		List<EvaObject> evaobject_list = groupSrv.queryEvaObjectBySchemeid(scheme.getId());
		submitSchemeProcess(scheme, evaobject_list);
	}
	
	@Override
	public void submitSchemeProcess(Scheme scheme, List<EvaObject> evaobject_list) {
		if (evaobject_list.size() <= 0) {
			throw new AdderBusinessException("方案设置不完整", "pm.i18n_pbc.ps.001");
		}
    	logger.debug("pm:createIndiOnStartScheme1 " + JSONObject.toJSONString(evaobject_list));
    	if(!scheme.isIsimportresult()) {
			if (!scheme.isIsallowfillup() && scheme.getIndisource() == CommonValue.EnumIndiSource.hrfill.getIndex()) {
	    	// 1.校验公共量表不能为空
				// List<String> emptygauge_staffid =
				// evaobject_list.stream().filter(evaObject->StringUtils.isEmpty(evaObject.getGaugeid()))
				// .map(EvaObject::getStaffid).distinct().collect(Collectors.toList());
				List<String> emptygauge_staffid = ListHelper.filterAndcollect(evaobject_list, "getGaugeid", true,
						"getStaffid");
	    		if(emptygauge_staffid.size() > 0){
	    			Map<String, PmStaff> staffMap = StaffHelper.queryStaffByIds(emptygauge_staffid);
					// String names =
					// staffMap.values().stream().map(staff->staff.name).reduce((name1,name2)->name1+","+name2).get();
					String names = ListHelper.reduce(new ArrayList<>(staffMap.values()), "name", ",");
					throw new AdderBusinessException("方案不允许员工填报！下列考核对象的公共量表不能为空;" + names, "pm.i18n_core.ps.067", names); 
	    		}
	    	}
    	}
    	// 获取公共量表实体及其下的指标    	
		// List<String> gauge_ids = evaobject_list.stream().map(EvaObject::getGaugeid)
		// .filter(gaugeid ->
		// StringUtils.isNotEmpty(gaugeid)).distinct().collect(Collectors.toList());
		List<String> gauge_ids = ListHelper.collect(
				ListHelper.filter(evaobject_list, "getGaugeid", ListHelper.Operator.ISNOTEmpty, null), "getGaugeid");
    	List<Gauge> gauge_list = gaugeService.queryGaugeWithIndiByGaugeids(gauge_ids);
		// Map<Boolean, List<String>> collect = gauge_list.stream()
		// .collect(Collectors.groupingBy(Gauge::isIsdoubleweight,
		// Collectors.mapping(Gauge::getId, Collectors.toList())));
    	logger.debug("pm:createIndiOnStartScheme2 " + JSONObject.toJSONString(evaobject_list));
		Map<Boolean, List<String>> collect = ListHelper.groupingBy(gauge_list, "isIsdoubleweight", "getId");
    	if(collect.get(!scheme.isIsdoubleweight()) != null && collect.get(!scheme.isIsdoubleweight()).size() >0 ){
    		List<String> nosamegauge = collect.get(!scheme.isIsdoubleweight());
			// List<String> nosamestaff =
			// evaobject_list.stream().filter(evaobject->nosamegauge.contains(evaobject.getGaugeid())).map(EvaObject::getStaffid).collect(Collectors.toList());
			List<String> nosamestaff = new ArrayList<>();
			for (EvaObject item : evaobject_list) {
				if (nosamegauge.contains(item.getGaugeid()))
					nosamestaff.add(item.getStaffid());
			}
			// String names =
			// StaffHelper.queryStaffByIds(nosamestaff).values().stream().map(staff->staff.name).reduce((name1,name2)->name1+","+name2).get();
			String names = ListHelper.reduce(StaffHelper.queryStaffByIds3(nosamestaff), "name", ",");
    		String weightname = (scheme.isIsdoubleweight() ? "双权重" :"单权重");
			throw new AdderBusinessException("下列考核对象的公共量表类型不是"+weightname+";"+names, "pm.i18n_core.ps.068", weightname, names); 
		}
		if (!scheme.isIsallowfillup()) {
			if (scheme.getIndisource() == CommonValue.EnumIndiSource.hrfill.getIndex()) {
				// 验证公共量表指标权重必须为100%
				validGaugeWeight(scheme, gauge_list);
			}
			// 校验考核对象上的考核人和审核人,或者方案上的审核人.
			validAppraiserOnEvaObject(scheme.getId(), evaobject_list);
		}

		// 查询方案下的已有的考核量表
		Condition condObj = new Condition();
		condObj.addExpression("schemeid", scheme.getId());
		// Map<String, Sheet> sheetOldMap = daoex.find(Sheet.class, condObj,
		// null).stream().collect( Collectors.toMap(Sheet::getStaffid, Sheet->Sheet));
		// 获取原始公共量表
		Map<String, Sheet> sheetOldMap = ListHelper.toMap(daoex.find(Sheet.class, condObj, null), "getStaffid");
		// 获取副本公共量表集合
		logger.debug("pm:createIndiOnStartScheme3 " + JSONObject.toJSONString(evaobject_list));
		// Map<String, Gauge> origin_list =
		// gauge_list.stream().collect(Collectors.toMap(Gauge::getId, Gauge->Gauge));
        // 原始公共量表
		Map<String, Gauge> origin_list = ListHelper.toMap(gauge_list, "getId");
		// 获取考核对象中副本公共量表
		Map<String, Gauge> copy_gauge_list = queryCopyGaugeByEvaObject(evaobject_list);
		Map<String, String> evaList = new HashMap<>();
		if (scheme.getIndisource() == CommonValue.EnumIndiSource.issued.getIndex()) {
			// 2019-10-18将指标下达人和考核对象id关联
			Condition objapr_cond = new Condition();
			objapr_cond.addExpression("schemeid", scheme.getId());
			objapr_cond.addExpression("workstep", CommonValue.EnumWorkStep.step1.getIndex());
			List<EvaSetting> objlist_all = daoex.find(EvaSetting.class, objapr_cond, null);
			if (objlist_all.isEmpty())
				throw new AdderBusinessException("请设置指标下达人", "pm.i18n_pbc.ia.022");
			evaList = ListHelper.toMap(objlist_all, "getEvaobjectid", "getStaffid");
			logger.debug("pm:submitSchemeProcess " + JSONObject.toJSONString(evaList));
		}
		for (EvaObject evaobject : evaobject_list) {
			Sheet sheet = null;
			if (sheetOldMap.containsKey(evaobject.getStaffid())) {
				sheet = sheetOldMap.get(evaobject.getStaffid());
			} else {
				sheet = new Sheet();
				sheet.setStaffid(evaobject.getStaffid());
				sheet.setSchemeid(scheme.getId());
				sheet.setEnablestate(true);
				sheet.setPeriodcode(scheme.getPeriodcode());
				sheet.setDeptid(evaobject.getStaff().deptid);
				daoex.insert(sheet);
			}
			// 根据公共量表生成量表指标
			if (StringUtils.isNotEmpty(evaobject.getGaugeid())) {
				Gauge origin_gauge = origin_list.get(evaobject.getGaugeid());
        		Gauge copy_gauge_old = copy_gauge_list.get( (evaobject.getGaugecopyid()== null ? "": evaobject.getGaugecopyid()));
        		if (!scheme.isIsallowfillup()) {
        			Gauge new_copy_gauge = gaugeService.queryLastesCopyGauge(origin_gauge);
					sheetIndicatorDao.clearSheetBySheetid(sheet.getId());
					addSheetIndiByGauge(scheme, sheet, new_copy_gauge);
					evaobject.setGaugecopyid(new_copy_gauge.getId());
					daoex.update(evaobject);
        		}
				// 如果没有副本 || 副本的reftime不是最新的 || 更改公共量表的引用.
        		else if (copy_gauge_old == null
						|| copy_gauge_old.getReftime().getTime() != origin_gauge.getModifiedtime().getTime()
						|| !origin_gauge.getId().equals(copy_gauge_old.getOriginalid())) {
					Gauge new_copy_gauge = gaugeService.queryLastesCopyGauge(origin_gauge);
					sheetIndicatorDao.clearSheetBySheetid(sheet.getId());
					addSheetIndiByGauge(scheme, sheet, new_copy_gauge);
					evaobject.setGaugecopyid(new_copy_gauge.getId());
					daoex.update(evaobject);
				}
			}
			// 指标下达生成下达人数据
			if (scheme.getIndisource() == CommonValue.EnumIndiSource.issued.getIndex()) {
				Approver appr = new Approver();
				appr.setSheetid(sheet.getId());
				appr.setAprLevel(1);
				appr.setStaffid(evaList.get(evaobject.getId()));
				appr.setSchemeid(scheme.getId());
				condObj = new Condition();
				condObj.addExpression("sheetid", sheet.getId());
				List<Approver> apprList = daoex.find(Approver.class, condObj, null);
				if (apprList.isEmpty())
					daoex.insert(appr);
				else if (!apprList.get(0).getStaffid().equals(appr.getStaffid())) {
					// edit by nijb-20210620  支持问题项目SUPPORT-187385
					apprList.get(0).setStaffid(appr.getStaffid());
					daoex.update(apprList.get(0));
				}
			}
		}
		// all_copy_id用于清理副本
        //List<String> all_copy_id = copy_gauge_list.values().stream().map(Gauge::getId).distinct().collect(Collectors.toList());
        gaugeService.cleanDuplicateById(new ArrayList<String>(copy_gauge_list.keySet()));
    }
	/**
	 * 获取考核对象中公共量表得副本
	 * @param evaobject_list
	 * @return
	 */
	private Map<String, Gauge> queryCopyGaugeByEvaObject(List<EvaObject>  evaobject_list){
		List<EvaObject> filter1 = ListHelper.filter(evaobject_list, "getGaugeid", ListHelper.Operator.ISNOTEmpty, null);
		List<EvaObject> filter2 = ListHelper.filter(filter1, "getGaugecopyid", ListHelper.Operator.ISNOTEmpty, null);
		List<String> copy_origin_ids = ListHelper.collect(filter2, "getGaugecopyid");
		List<Gauge> queryGaugeWithIndiByGaugeids = gaugeService.queryGaugeWithIndiByGaugeids(copy_origin_ids);
		Map<String, Gauge> copy_gauge_list = ListHelper.toMap(queryGaugeWithIndiByGaugeids, "getId");
		return copy_gauge_list;
	}
	/**
	 * 验证公共量表权重是否正确
	 * @param scheme
	 * @param gauge_list
	 */
	private void validGaugeWeight(Scheme scheme, List<Gauge> gauge_list){
		ArrayList<String> gaugename_list = new ArrayList<String>();
		for(Gauge gauge : gauge_list){
			//验证公共量表 权重
			List<GaugeIndicator> gaugeIndilist = gauge.getGaugeIndilist();
			if(gauge.isIsdoubleweight()){
				//按指标分类分组
				// Map<String, List<GaugeIndicator>> indi_group = gaugeIndilist.stream()
				// .collect(Collectors.groupingBy(GaugeIndicator::getIndiParent,
				// Collectors.mapping(GaugeIndicator -> GaugeIndicator, Collectors.toList())));
				Map<String, List<GaugeIndicator>> indi_group = ListHelper.groupingBy(gaugeIndilist, "getIndiParent");
				Iterator<String> row_iter = indi_group.keySet().iterator();
				BigDecimal parentWeight = new BigDecimal(0);
				while (row_iter.hasNext()) {
					String parentid = row_iter.next();
					List<GaugeIndicator> list = indi_group.get(parentid);
					parentWeight = parentWeight.add(list.get(0).getIndiclassWeight());
					// BigDecimal indiweight_total =
					// list.stream().map(GaugeIndicator::getIndiWeight).reduce((weight_1,weight_2)->weight_1.add(weight_2)).get();
					BigDecimal indiweight_total = BigDecimal.ZERO;
					for (GaugeIndicator item : list) {
						indiweight_total = item.getIndiWeight().add(indiweight_total);
					}
					if(indiweight_total.compareTo(new BigDecimal(1)) != 0){
						gaugename_list.add(gauge.getName());
						break;
					}
				}
				if(parentWeight.compareTo(new BigDecimal(1)) != 0 && !gaugename_list.contains(gauge.getName())){
					gaugename_list.add(gauge.getName());
				}
			} else {
				// BigDecimal indiweight_total =
				// gaugeIndilist.stream().map(GaugeIndicator::getIndiWeight).reduce((weight_1,weight_2)->weight_1.add(weight_2)).get();
				BigDecimal indiweight_total = BigDecimal.ZERO;
				for (GaugeIndicator item : gaugeIndilist) {
					indiweight_total = indiweight_total.add(item.getIndiWeight());
				}
				if (indiweight_total.compareTo(new BigDecimal(1)) != 0) {
					gaugename_list.add(gauge.getName());
		        }
			}
		}
		if(gaugename_list.size() > 0){
			// String gauge_name = gaugename_list.stream().reduce((name1,name2)->
			// name1+","+name2).get();
			String gauge_name = ListHelper.reduce(gaugename_list, null, ",");
			throw new AdderBusinessException("下列公共量表'"+gauge_name+"'权重设置不正确;","pm.i18n_core.ps.069", gauge_name);
		}
	}   

	/**
	 * 通过公关量表为量表添加指标
	 * 
	 * @param scheme
	 * @param sheet
	 * @param gauge
	 */
    private void addSheetIndiByGauge(Scheme scheme , Sheet sheet , Gauge gauge){
		// List<GaugeIndicator> gaugeIndilist = gauge.getGaugeIndilist().stream()
		// .sorted(Comparator.comparing(GaugeIndicator::getDispSeq)).collect(Collectors.toList());
		List<GaugeIndicator> gaugeIndilist = gauge.getGaugeIndilist();
		//ListHelper.sorted(gaugeIndilist, "getDispSeq");
		Collections.sort(gaugeIndilist, new Comparator<GaugeIndicator>() {
			@Override
			public int compare(GaugeIndicator o1, GaugeIndicator o2) {
				return o1.getDispSeq()-o2.getDispSeq();
			}
		});
    	for(GaugeIndicator indi: gaugeIndilist){
    		HashMap<String, Object> indiMap = new HashMap<String,Object>();
    		indiMap.put("sheetid", sheet.getId());
    		indiMap.put("indiname", indi.getIndiname()); // indiname
    		indiMap.put("act_weight", indi.getIndiWeight());
    		indiMap.put("indi_parent", indi.getIndiParent());
    		indiMap.put("indiclass_weight", indi.getIndiclassWeight());
    		// 2019-10-18对于PBC方案要去除评分标准的html格式
			if (scheme.getSchememode() != CommonValue.EnumSchemeMode.pm_values.getIndex()) {
				indi.setEvalstandard(delHtmlTag(indi.getEvalstandard()));
			}
    		indiMap.put("evalstandard", indi.getEvalstandard());
    		indiMap.put("targetvalue", indi.getPlannedgoal());
    		sheetIndicatorService.addSheetIndi(indiMap);//创建量表指标
    	}
    }
    
    /**
     * 方案级深层查询考核人信息,验证考核对象上的考核人和审核人
     * @param schemeid
     * @param evaobjlist
     * @return
     */
	private void validAppraiserOnEvaObject(String schemeid, List<EvaObject> evaobjlist) {
    	// 记录验证不通过的考核对象id
    	List<String> error_evastaffid_list = new ArrayList<String>();
		// List<String> evastaffid_all =
		// evaobjlist.stream().map(EvaObject::getStaffid).collect(Collectors.toList());
		//List<String> evastaffid_all = ListHelper.collect(evaobjlist, "getStaffid");
    	//考核对象id和staffid字典对照
		Map<String, String> evaobj_all = ListHelper.toMap(evaobjlist, "getId", "getStaffid");
    	// 查询方案下 考核人对象上的考核人设置
        Condition objapr_cond = new Condition();
        objapr_cond.addExpression("schemeid", schemeid);
        objapr_cond.addExpression("workstep",CommonValue.EnumWorkStep.step2.getIndex()); 
        List<EvaSetting> objlist_all = daoex.find(EvaSetting.class,objapr_cond, new Sorter(Direction.ASC, Arrays.asList("turn","ts")));
		// Map<String, List<EvaSetting>> eva_list_group = objlist_all.stream()
		// .collect(Collectors.groupingBy(EvaSetting::getEvaobjectid,
		// Collectors.mapping(EvaSetting->EvaSetting, Collectors.toList())));
		Map<String, List<EvaSetting>> eva_list_group = ListHelper.groupingBy(objlist_all, "getEvaobjectid");
        
        for(Entry<String, List<EvaSetting>> eva_settings : eva_list_group.entrySet()){
        	String evaobjid = eva_settings.getKey();
        	String staffid = evaobj_all.remove(evaobjid); // 移除
        	List<EvaSetting> settings = eva_settings.getValue();
        	if(settings == null || settings.size() <= 0){
        		error_evastaffid_list.add(staffid);
        		continue;
        	}
			// Map<Integer, BigDecimal> weightmap =
			// settings.stream().collect(Collectors.groupingBy(
			// EvaSetting::getTurn,
			// Collectors.collectingAndThen(Collectors.toList(),values->values.get(0).getWeight())));
        	Map<Integer, BigDecimal> weightmap = new Hashtable<>();
        	for (EvaSetting item :settings) {
        		weightmap.put(item.getTurn(), item.getWeight());
        	}
			// BigDecimal weightsum = weightmap.values().stream().reduce((dec1,dec2) ->
			// dec1.add(dec2)).get();
			BigDecimal weightsum = BigDecimal.ZERO;
			for (BigDecimal item : weightmap.values()) {
				weightsum = weightsum.add(item);
			}
    		if(weightsum.compareTo(new BigDecimal(1)) != 0){
    			logger.debug("pm:validAppraiserOnEvaObject 1");
    			error_evastaffid_list.add(staffid);
    			continue;
    		}
			// List<String> apprstaffids =
			// settings.stream().map(EvaSetting::getStaffid).collect(Collectors.toList());
			List<String> apprstaffids = ListHelper.collect(settings, "getStaffid");
    		if(apprstaffids.contains(null) || apprstaffids.contains("")){
    			logger.debug("pm:validAppraiserOnEvaObject 2");
    			error_evastaffid_list.add(staffid);
    			continue;
    		}
    		if(apprstaffids.size() != settings.size()){
    			logger.debug("pm:validAppraiserOnEvaObject 3");
    			error_evastaffid_list.add(staffid);
    			continue;
    		}
        }
        if(evaobj_all.size() > 0){
        	// 获取方案上的考核人。
    	    Condition evaapr_cond = new Condition();
    	    evaapr_cond.addExpression("schemeid", schemeid);
    	    evaapr_cond.addExpression("workstep",CommonValue.EnumWorkStep.step2.getIndex()); 
    	    List<EvaAppraiser> evaapprlist = daoex.find(EvaAppraiser.class,evaapr_cond, new Sorter(Direction.ASC, "turn"));
    	    // 先验轮次考核人权重是否为100%
			// BigDecimal weightsum =
			// evaapprlist.stream().map(EvaAppraiser::getWeight).reduce((weight1,
			// weight2)->weight1.add(weight2)).get();
			BigDecimal weightsum = ListHelper.reduceAdd(evaapprlist, "getWeight");
    		if(evaapprlist.size() <= 0 || weightsum.compareTo(new BigDecimal(1)) != 0){
    			logger.debug("pm:validAppraiserOnEvaObject 3");
    			error_evastaffid_list.addAll(evaobj_all.values());
    		} else {
    			for(String apprstaffid : evaobj_all.values()){
    				HashSet<String> inspection = new HashSet<String>(); //自动去重操作
    				for(EvaAppraiser appraiser : evaapprlist){
    					if(StringUtils.isNotEmpty(appraiser.getStaffid())){
    						inspection.add(appraiser.getStaffid());
    					} else {
    						List<String> appraiserByDim = evaSettingService.getAppraiserByDim(appraiser.getDimid(),apprstaffid);
    						inspection.add(appraiserByDim.get(0));
    					}
    				}
    				if(inspection.contains("") || inspection.contains(null) || inspection.size() != evaapprlist.size()){ //包含空，或者长度不同代表有重复
    					error_evastaffid_list.add(apprstaffid);
    				}
    			}
    			
    			// 2019-8-6 nijb@yonyou.com  验证方案上的考核人为空时，若存在非本人和非上级的考核人类别时，则验证失败，上级考核人也为空同样验证失败。 
    			// 				    	该验证方式比较麻烦，顾注释掉。
    			/*List<EvaAppraiser> filter = ListHelper.filter(evaapprlist, "getStaffid", ListHelper.Operator.ISEmpty, null);
    			List<String> dimids = ListHelper.collect(filter, "getDimid");
				List<Dimensionality> dimenlist = getDimenByIds(dimids);
				if(dimenlist.size() > 0){
	            	// 获取除本人和上级之外的其他考核人类型:
					List<Integer> dimtypelist = ListHelper.collect(dimenlist, "getDimtype");
					dimtypelist.remove(new Integer(3)); // 去除本人
					Boolean hasshangji = false; //是否有上级
					if(dimtypelist.contains(new Integer(1))){
						dimtypelist.remove(new Integer(1)); // 去除上级
						hasshangji = true;
					}
					if(dimtypelist.size() > 0){ //去除本人和上级后得考核人类别
						logger.debug("pm:validAppraiserOnEvaObject 4");
		            	error_evastaffid_list.addAll(evaobj_all.values());
		            } else if(hasshangji){ //
		            	for(String apprstaffid : evaobj_all.values()){
            				PmStaff principal = StaffHelper.queryPrincipal(apprstaffid);
            				if(principal == null || StringUtils.isEmpty(principal.id)){
            					logger.debug("pm:validAppraiserOnEvaObject 5");
            					error_evastaffid_list.add(apprstaffid);
            				}
            			}
		            }
	            }*/
    		}
        }
        if (!error_evastaffid_list.isEmpty()) {	
			//add by zengcl 建工项目 方案中直接导入结果，取消考核信息不完整校验  begin
			Condition cond1 = new Condition();
			cond1.addExpression("id", schemeid);
			List<Scheme> schemeList = daoex.find(Scheme.class, cond1, null);
			if(schemeList.get(0).isIsimportresult()) {

			}else {
				//add by zengcl 建工项目 方案中直接导入结果，取消考核信息不完整校验  end
	        	logger.debug("pm:validAppraiserOnEvaObject " + JSONObject.toJSONString(error_evastaffid_list));
	        	Map<String, PmStaff> queryStaffByIds = StaffHelper.queryStaffByIds(error_evastaffid_list);
	        	String names = ListHelper.reduce(new ArrayList<>(queryStaffByIds.values()), "name", ",");
	    		//String names = new StaffHelper(staffService).queryStaffByIds(error_evastaffid_list).values().stream().map(staff->staff.name).reduce((name1,name2)->name1+","+name2).get();
				throw new AdderBusinessException("下列考核对象的考核人信息不完整：" + names, "pm.i18n_core.ps.070", names);
			}
		}
	}

	/**
	 * 转换html标签为普通文本
	 * 
	 * @param content
	 * @return
	 */
	private String delHtmlTag(String content) {
		// 去掉尾部
		content = content.replaceAll("<p><br></p>", "");
		// 去掉<p>段落
		content = content.replaceAll("<p .*?>", "");
		// <br><br/>替换为换行
		content = content.replaceAll("<br\\s*/?>", "\r\n");
		// 去掉其它的<>之间的东西
		content = content.replaceAll("\\<.*?>", "");
		// 去掉空格
		content = content.replaceAll("&nbsp;", " ");
		return content;
	}

    private List<Dimensionality> getDimenByIds(List<String> dim_ids){
    	List<Dimensionality> list = new ArrayList<Dimensionality>();
    	if(dim_ids.size() >0){
    		Condition dim_cond = new Condition();
        	dim_cond.addExpression("id", dim_ids, Operator.IN);
        	list = daoex.find(Dimensionality.class,dim_cond, null);	
    	}
    	return list;
    }
}
