package com.bcxin.survey.dao.report;

import com.bcxin.survey.utils.StringUtil;
import org.springframework.stereotype.Repository;

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

/**
 * @author hzp
 * 踏勘专家Dao
 */
@Repository
public class SurveyExpertDaoImpl extends BaseDaoImpl implements SurveyExpertDao{

    @Override
    public String findSurveyExperts(Long taskId){
        String sql="select distinct B.oid,B.realName,B.phone from risk_survey_expert A,risk_se_user B where A.expertUserId=B.oid " +
                "and A.taskId="+taskId;
        List<Map<String, Object>> list =this.findBySQL(sql.toString(),null);
        String expert="";
        if(list!=null && list.size()>0){
            for(Map<String,Object> map : list){
                expert+=getMapValue(map,"realName")+" "+getMapValue(map,"phone")+",";
            }
            if(StringUtil.isNotEmpty(expert)){
                expert=expert.substring(0,expert.length()-1);
                return expert;
            }else{
                return "--";
            }
        }else{
            return "--";
        }
    }

    public String getMapValue(Map<String,Object> map,String key){
        if(map.containsKey(key)){
            if(map.get(key)!=null){
                return map.get(key).toString();
            }
        }
        return "";
    }
}