<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.countrygarden.bi.main.dao.personnel.PersonnelAdvisorMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.personnel.PersonnelAdvisor">
                                    <id column="id" property="id" />
                                                <result column="personnel_id" property="personnelId" />
                                                <result column="personnel_type_id" property="personnelTypeId" />
                                                <result column="advisor_user_id" property="advisorUserId" />
                                                <result column="advisor_user_name" property="advisorUserName" />
                                                <result column="positivevaluation" property="positivevaluation" />
                                                <result column="fixedpostevaluation" property="fixedpostevaluation" />                                             
                                                 <result column="filesame" property="filesame" />
                                                <result column="files" property="files" />
                                                <result column="flag" property="flag" />
                                                <result column="start_time" property="startTime" />
                                                <result column="terminal_time" property="terminalTime" />
                                                <result column="addition_time" property="additionTime" />
                                                <result column="created_date" property="createdDate" />
                                                <result column="created_name" property="createdName" />  
                                                <result column="created_by" property="createdBy" />                                              
                                                <result column="updated_date" property="updatedDate" />
                                                <result column="updated_by" property="updatedBy" />
                        </resultMap>
                        
                   <sql id="sqlcoue">      
          <if test="userquyu!=null">
		    <foreach collection="userquyu" item="userquyu"
						index="index" separator="or">
						
						 (t.Four_tissue like concat('%',#{userquyu},'%') or doc.PK_ORG  like concat('%',#{userquyu},'%'))
					</foreach> 
		         <!-- <if test="rolesMap.identitys!=null">
		                   or pg.identity in
					<foreach collection="rolesMap.identitys" item="identitys"
						index="index" open="(" close=")" separator=",">
						#{identitys}
					</foreach>
		          </if> -->
						
		</if> 
		
		 <if test="rolesMap.identitys!=null">
					and pg.identity in
					<foreach collection="rolesMap.identitys" item="identitys"
						index="index" open="(" close=")" separator=",">
						#{identitys}
					</foreach>
			</if>   
     
     
     </sql>     
          <select id="peradvisorlist" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="cn.com.countrygarden.bi.main.model.personnel.PersonnelAdvisor">
                    select pa.id as id,pa.personnel_id as personnelId,pa.personnel_type_id as personnelTypeId,bdps.name as advisorUserName,pa.mentorpost as mentorpost,pa.positivevaluation as positivevaluation,pa.fixedpostevaluation as fixedpostevaluation from biapp.personnel p,biapp.personnel_advisor pa,biapp.personnel_advisor_type paty,performance_app.bd_psndoc bdps
                    where p.id=pa.personnel_id and pa.personnel_type_id=paty.id and bdps.code=pa.advisor_user_id
                    and pa.personnel_id=#{personnelId}    
           
           </select> 
           
           <insert id="insertadd" parameterType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
                 insert into personnel_advisor(personnel_id,personnel_type_id,advisor_user_id,mentorpost, 
                   positivevaluation,fixedpostevaluation,filesame,files,flag,created_date,created_by,personneltag_id,created_name,advisor_user_name
                   ,addition_time,start_time,terminal_time,normal_time,fixed_time,positivescore,fixedscore)values
                 (#{personnelId},#{personnelTypeId},#{advisorUserId},#{mentorpost},#{positivevaluation},#{fixedpostevaluation},#{filesame},#{files}, 
                 #{flag},#{createdDate},#{createdBy},#{personneltagId},#{createdName},#{advisorUserName},#{additionTime},#{startTime},#{terminalTime},#{normalTime},#{fixedTime},#{positivescore},#{fixedscore});
           </insert>
           
           <delete id="deletepead" parameterType="java.lang.Integer">
               <!--  delete from personnel_advisor where personnel_id=#{personnelId} and personneltag_id=#{personneltagId}; -->
            update personnel_advisor set flag=1 where personnel_id=#{personnelId} and personneltag_id=#{personneltagId};
           </delete>
           
           <delete id="deletepeadpead" parameterType="java.lang.Integer">
               delete from personnel_advisor where personnel_id=#{personnelId} and personnel_type_id=#{personnelTypeId} and personneltag_id=#{personneltagId};                            
           </delete>
           
           <select id="findExistWrittenexamination" resultType="cn.com.countrygarden.bi.main.dto.PersonnelTgDTO">
                     
		               select distinct p.id as personnelId ,p.user_id as userId ,p.name as `name`,pg.id as personneltagId,pg.identity as identity,(select max(padv.created_date) from personnel_advisor padv where 
                       padv.personnel_id=pes.personnel_id and padv.personneltag_id=pes.personneltag_id) as createdDate,
                       case when (t.Four_tissue is null) then doc.PK_ORG else t.Four_tissue end regionName                           
                       from biapp.personnel_advisor pes
                       left join biapp.personnel p on pes.personnel_id=p.id 
                       left join biapp.personnel_tag pg on p.user_id=pg.user_id and pg.id=pes.personneltag_id                      
                       left join performance_app.bd_psndoc doc on doc.`CODE`=p.user_id
                       left join (select distinct Four_tissue,pk_org from performance_app.bd_type) t on t.pk_org=doc.PK_ORG                                              
                       <where>
                        <include refid="sqlcoue"/> 
		                <if test="personnelAdvisor.userId!=null and personnelAdvisor.userId!=''">
                            and p.user_id like concat('%',#{personnelAdvisor.userId},'%')
                       </if>
                 
                          <if test="personnelAdvisor.name!=null and personnelAdvisor.name!=''">
                              and p.name like concat('%',#{personnelAdvisor.name},'%')
                         </if>
                         
                         <if test="personnelAdvisor.personneltagId!=null and personnelAdvisor.personneltagId!=''">
                             and pg.id=#{personnelAdvisor.personneltagId}
                         </if>
                         <if test="personnelAdvisor.regionName!=null and personnelAdvisor.regionName!=''">
			                  and (t.Four_tissue like concat('%',#{personnelAdvisor.regionName},'%') or doc.PK_ORG like concat('%',#{personnelAdvisor.regionName},'%'))
		                 </if>
                           <!-- rolesMap.role!=null没有相应的角色 -->
		             <if test=" rolesMap.role!=null">
			             and pes.flag=-1
		             </if>
		           
		            
		            and  pes.flag=0 
		<!-- rolesMap.gj_admin！=null管理员，有所有权限 -->
		<!-- <if test="rolesMap.gj_admin==null and rolesMap.role==null">
			rolesMap.gj_Area！=null区域管理员，只能查看登录账号区域的下的数据
			<if test="rolesMap.gj_Area!=null">
				and doc.code = #{rolesMap.gj_Area}
				 <if test="rolesMap.identitys!=null">
					or pg.identity in
					<foreach collection="rolesMap.identitys" item="identitys"
						index="index" open="(" close=")" separator=",">
						#{identitys}
					</foreach>
			</if>

			 <if test="rolesMap.gj_Area==null">
				<if test="rolesMap.identitys!=null">
					and pg.identity in
					<foreach collection="rolesMap.identitys" item="identitys"
						index="index" open="(" close=")" separator=",">
						#{identitys}
					</foreach>
				</if>
			</if> 

		</if>
		
		</if>
 -->
                    </where>      
                  order by createdDate desc    
           </select>
           
           
           <select id="queryPageList" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
                 select distinct pe.id as id,p.id as personnelId,p.user_id as userId,p.name as name,pe.personneltag_id as personneltagId,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,pe.advisor_user_id as advisorUserId,pe.advisor_user_name as advisorUserName,pe.positivevaluation as positivevaluation,
                 pe.fixedpostevaluation as fixedpostevaluation,pe.filesame as filesame,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate,pe.created_name as createdName,pe.addition_time as additionTime,pe.start_time as startTime,pe.terminal_time as terminalTime,pe.normal_time as normalTime,pe.fixed_time as fixedTime
                 ,pe.positivescore as positivescore,pe.fixedscore as fixedscore
                 from biapp.personnel p,biapp.personnel_advisor pe,biapp.personnel_advisor_type pty                
                 where p.id=pe.personnel_id and pe.personnel_type_id=pty.id and pe.flag=0
                              
                  <!-- <if test="personnelTypeId!=null and personnelTypeId!=''"> -->
                        and pe.personnel_type_id=1
                 <!-- </if>   --> 
                 
                 <if test="personneltagId!=null">
                     and pe.personneltag_id=#{personneltagId}
                 </if>
                 
                 <if test="personnelId!=null">
                        and pe.personnel_id=#{personnelId}
                 </if>
                 <if test="userId!=null and userId!=''">
                       and p.user_id like concat('%',#{userId},'%')
                 </if>
                 
                 <if test="name!=null and name!=''">
                      and p.name like concat('%',#{name},'%')
                 </if>
                  order by pe.addition_time desc
           </select> 
           
           <select id="queryPageListadnamelist" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
                 select distinct pe.id as id,p.id as personnelId,p.user_id as userId,p.name as name,pe.personneltag_id as personneltagId,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,pe.advisor_user_id as advisorUserId,pe.advisor_user_name as advisorUserName,pe.positivevaluation as positivevaluation,
                 pe.fixedpostevaluation as fixedpostevaluation,pe.filesame as filesame,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate,pe.created_name as createdName,pe.addition_time as additionTime,pe.start_time as startTime,pe.terminal_time as terminalTime,pe.normal_time as normalTime,pe.fixed_time as fixedTime,
                 pe.positivescore as positivescore,pe.fixedscore as fixedscore 
                 from biapp.personnel p,biapp.personnel_advisor pe,biapp.personnel_advisor_type pty
                 
                 where p.id=pe.personnel_id and pe.personnel_type_id=pty.id and pe.flag=0
                              
                  <!-- <if test="personnelTypeId!=null and personnelTypeId!=''"> -->
                        and pe.personnel_type_id=2
                 <!-- </if>   --> 
                 
                  <if test="personneltagId!=null">
                     and pe.personneltag_id=#{personneltagId}
                 </if>
                 
                 <if test="personnelId!=null">
                        and pe.personnel_id=#{personnelId}
                 </if>  
                 <if test="userId!=null and userId!=''">
                       and p.user_id like concat('%',#{userId},'%')
                 </if>
                 
                 <if test="name!=null and name!=''">
                      and p.name like concat('%',#{name},'%')
                 </if>
                  order by pe.addition_time desc
           </select> 
           
           <select id="queryById" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="java.lang.Integer">
                   select pe.personnel_id as personnelId,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,bdp.name as advisorUserName,pe.positivevaluation as positivevaluation,
                 pe.fixedpostevaluation as fixedpostevaluation,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate
                 from biapp.personnel p,biapp.personnel_advisor pe,biapp.personnel_advisor_type pty,
                 performance_app.bd_psndoc bdp,performance_app.hi_psnjob hips
                 where p.id=pe.personnel_id and pe.personnel_type_id=pty.id and bdp.PK_PSNDOC = hips.PK_PSNDOC and hips.poststat='Y' and bdp.`CODE`=pe.advisor_user_id
                  and p.id=#{id}
           </select>
           
           <update id="edit" parameterType="cn.com.countrygarden.bi.main.model.personnel.PersonnelAdvisor">
                   update personnel_advisor 
                   <set>
                       <if test="personnelTypeId!=null and personnelTypeId!=''">personnel_type_id=#{personnelTypeId},</if>
                        <if test="mentorpost!=null and mentorpost!=''">mentorpost=#{mentorpost},</if>
                        <if test="positivevaluation!=null and positivevaluation!=''">positivevaluation=#{positivevaluation},</if>
                        <if test="fixedpostevaluation!=null and fixedpostevaluation!=''">fixedpostevaluation=#{fixedpostevaluation},</if>
                        <if test="files!=null and files!=''">files=#{files},</if>
                        <if test="startTime!=null">start_time=#{startTime},</if>
                         <if test="terminalTime!=null">terminal_time=#{terminalTime},</if>
                        <if test="createdBy!=null and createdBy!=''">updated_by=#{createdBy},</if>
                        <if test="createdDate!=null">updated_date=#{createdDate},</if>
                   </set>
                   where id=#{id};
           
           </update> 
            <select id="selectByPersonInfoByCodeOrName1" resultType="cn.com.countrygarden.bi.main.dto.PersonInfoVO">
        select distinct d.BID,d.`CODE`,d.`NAME`,w.pk_dept WORKDEPT,
        case when (t.Four_tissue is null) then d.PK_ORG else t.Four_tissue end regionName 
        from performance_app.bd_psndoc d 
        left join  performance_app.hi_psnjob w  on d.PK_PSNDOC = w.PK_PSNDOC
        left join (select distinct Four_tissue,pk_org from performance_app.bd_type) t on t.pk_org=d.PK_ORG 
        where w.endflag='N' and w.lastflag='Y' and w.ismainjob='Y'
        <if test="userquyu!=null">
		    <foreach collection="userquyu" item="userquyu"
						index="index">
						
						or (t.Four_tissue like concat('%',#{userquyu},'%') or doc.PK_ORG  like concat('%',#{userquyu},'%'))
					</foreach> 
					</if>
        <if test="search != null and search != ''">
            and ( d.`NAME` like concat('%', #{search}, '%') or d.`CODE`  =  #{search} )
        </if>
        
          <if test="userIds!=null">
		and  d.`CODE` in
		<foreach collection="userIds" item="userIds" index="index" open="("
				 close=")" separator=",">
			#{userIds}
		</foreach>
		</if>
        limit 0,20
    </select>  
            <select id="selectByPersonInfoByCodeOrName" resultType="cn.com.countrygarden.bi.main.dto.PersonInfoVO">
       select distinct d.BID,d.`CODE`,d.`NAME`,w.pk_dept WORKDEPT,
        case when (t.Four_tissue is null) then d.PK_ORG else t.Four_tissue end regionName 
        from performance_app.bd_psndoc d 
        left join  performance_app.hi_psnjob w  on d.PK_PSNDOC = w.PK_PSNDOC
        left join (select distinct Four_tissue,pk_org from performance_app.bd_type) t on t.pk_org=d.PK_ORG 
        <where> 
        and w.endflag='N' and w.lastflag='Y' and w.ismainjob='Y'
		<if test="userquyu!=null">
		and
		    (<foreach collection="userquyu" item="userquyu"
						index="index" separator="or">
						
						 (t.Four_tissue like concat('%',#{userquyu},'%') or d.PK_ORG  like concat('%',#{userquyu},'%'))
					</foreach>) 
					</if>
					
        <if test="search != null and search != ''">
            and ( d.`NAME` like concat('%',#{search},'%') or d.`CODE`  =  #{search} )
        </if>
        
           <if test="userIds!=null">
		and  d.`CODE` in
		<foreach collection="userIds" item="userIds" index="index" open="("
				 close=")" separator=",">
			#{userIds}
		</foreach>
		</if> 
		</where>
       limit 0,100
    </select>  
        
    <select id="exxlspersonnelAdvisor" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
          select distinct pe.user_id as userId,pad.personnel_id as personnelId,pad.personnel_type_id as personnelTypeId,doc.name as name,pg.identity as identity,pat.advisor_type as advisortype,pad.advisor_user_id as advisorUserId,bd.name as advisorUserName,w.pk_dept as dept,w.pk_post as mentorpost,
          pad.positivevaluation as positivevaluation,pad.fixedpostevaluation as fixedpostevaluation,w.BEGINDATE as begindate,w.ENDDATE as enddate,pad.addition_time as additionTime,pad.start_time as startTime,pad.terminal_time as terminalTime,
          pad.positivescore as positivescore,pad.fixedscore as fixedscore,pad.created_date as createdDate,
           case when (t.Four_tissue is null) then doc.PK_ORG else t.Four_tissue end regionName   
          from biapp.personnel_advisor pad          
          left join biapp.personnel pe on pe.id=pad.personnel_id 
          left join biapp.personnel_tag pg on pg.user_id=pe.user_id and pad.personneltag_id=pg.id
          left join performance_app.bd_psndoc doc on doc.CODE=pe.user_id 
          left join performance_app.hi_psnjob w on doc.PK_PSNDOC = w.PK_PSNDOC and w.poststat='Y'          
          left join biapp.personnel_advisor_type pat on pad.personnel_type_id=pat.id
          left join performance_app.bd_psndoc bd on bd.CODE=pad.advisor_user_id             
          left join (select distinct Four_tissue,pk_org from performance_app.bd_type) t on t.pk_org=doc.PK_ORG   
          <where>
           <include refid="sqlcoue"/> 
                <if test="personnelAdvisor.personnelTypeId!=null">
                        and pad.personnel_type_id=#{personnelAdvisor.personnelTypeId}
                 </if>
                 <if test="personnelAdvisor.userId!=null and personnelAdvisor.userId!=''">
                       and pe.user_id like concat('%',#{personnelAdvisor.userId},'%')
                 </if>
                 
                 <if test="personnelAdvisor.name!=null and personnelAdvisor.name!=''">
                      and pe.name like concat('%',#{personnelAdvisor.name},'%')
                 </if>
                 	 <if test="personnelAdvisor.regionName!=null and personnelAdvisor.regionName!=''">
			                    and (t.Four_tissue like concat('%',#{personnelAdvisor.regionName},'%') or doc.PK_ORG like concat('%',#{personnelAdvisor.regionName},'%'))
		                 </if>
                 
                 <if test="personnelId!=null">
                         and pad.personnel_id in 
                         <foreach collection="personnelId" item="personnelId" index="index" open="("
				 close=")" separator=",">
			           #{personnelId}
		        </foreach>
                 </if>
                 
       
               <!-- rolesMap.role!=null没有相应的角色 -->
		       <if test=" rolesMap.role!=null">
			       and pad.flag=-1
		       </if>
		      
		       and pad.flag=0
		<!-- rolesMap.gj_admin！=null管理员，有所有权限 -->
		<!-- <if test="rolesMap.gj_admin==null and rolesMap.role==null">
			rolesMap.gj_Area！=null区域管理员，只能查看登录账号区域的下的数据
			<if test="rolesMap.gj_Area!=null">
				and bdps.code = #{rolesMap.gj_Area}
				 <if test="rolesMap.identitys!=null">
					or pag.identity in
					<foreach collection="rolesMap.identitys" item="identitys"
						index="index" open="(" close=")" separator=",">
						#{identitys}
					</foreach>
			</if> 

			  <if test="rolesMap.gj_Area==null">
				<if test="rolesMap.identitys!=null">
					and pag.identity in
					<foreach collection="rolesMap.identitys" item="identitys"
						index="index" open="(" close=")" separator=",">
						#{identitys}
					</foreach>
				</if>
			</if>  
			
		</if>
         </if> -->
          </where>
                
    </select>  
    
     <select id="exxlspersonnelAdvisorall" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
          select distinct pe.user_id as userId,bdps.name as name,pg.identity as identity,pat.advisor_type as advisortype,pad.advisor_user_id as advisorUserId,bd.name as advisorUserName,wp.pk_dept as dept,wp.pk_post as mentorpost,
          pad.positivevaluation as positivevaluation,pad.fixedpostevaluation as fixedpostevaluation,wp.BEGINDATE as begindate,wp.ENDDATE as enddate,pad.addition_time as additionTime,pad.start_time as startTime,pad.terminal_time as terminalTime,max(pad.addition_time) 
          ,pad.normal_time as normalTime,pad.fixed_time as fixedTime,pad.positivescore as positivescore,pad.fixedscore as fixedscore
          from biapp.personnel_advisor pad          
          left join biapp.personnel pe ON pe.id=pad.personnel_id and pad.flag=0
          left join biapp.personnel_tag pg on pg.user_id=pe.user_id and pad.personneltag_id=pg.id
          left join performance_app.bd_psndoc bdps on bdps.CODE=pe.user_id 
          left join performance_app.hi_psnjob w on bdps.PK_PSNDOC = w.PK_PSNDOC and w.poststat='Y'          
          left join biapp.personnel_advisor_type pat on pad.personnel_type_id=pat.id
          left join performance_app.bd_psndoc bd on bd.CODE=pad.advisor_user_id 
          left join performance_app.hi_psnjob wp on bd.PK_PSNDOC = wp.PK_PSNDOC and wp.poststat='Y'
          <where>
                <if test="personnelAdvisor.personnelTypeId!=null">
                        and pad.personnel_type_id=#{personnelAdvisor.personnelTypeId}
                 </if>
                 <if test="personnelAdvisor.userId!=null and personnelAdvisor.userId!=''">
                       and pe.user_id like concat('%',#{personnelAdvisor.userId},'%')
                 </if>
                 
                 <if test="personnelAdvisor.name!=null and personnelAdvisor.name!=''">
                      and pe.name like concat('%',#{personnelAdvisor.name},'%')
                 </if>
                 
                 <if test="personnelId!=null">
                         and pad.personnel_id in 
                         <foreach collection="personnelId" item="personnelId" index="index" open="("
				 close=")" separator=",">
			           #{personnelId}
		        </foreach>
                 </if>
                 
         <if test="userIds!=null">
		and  pe.user_id in
		<foreach collection="userIds" item="userIds" index="index" open="("
				 close=")" separator=",">
			#{userIds}
		</foreach>
		</if>
          
          </where>
    group by bdps.name,pat.advisor_type,pe.user_id,pag.identity,pad.advisor_user_id,bd.name,
   wp.pk_dept,wp.pk_post,pad.positivevaluation,pad.fixedpostevaluation,wp.BEGINDATE,wp.ENDDATE,pad.start_time,pad.terminal_time
    </select>  
    
    
    <select id="exxlspersonneall" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
       <!--   select personnel_id as personnelId,max(created_date) as 
		createdDate,personnel_type_id as personnelTypeId
		from
		personnel_advisor where flag=0
		group by personnel_id,personnel_type_id -->
		
		  select pad.personnel_id as personnelId,max(pad.created_date) as createdDate,pad.personnel_type_id as personnelTypeId,
          case when (t.Four_tissue is null) then doc.PK_ORG else t.Four_tissue end regionName  
          from biapp.personnel_advisor pad
          left join biapp.personnel pe on pe.id=pad.personnel_id 
          left join personnel_tag pg on pg.id=pad.personneltag_id
          left join performance_app.bd_psndoc doc on doc.CODE=pe.user_id 
          left join (select distinct Four_tissue,pk_org from performance_app.bd_type) t on t.pk_org=doc.PK_ORG
          <where>
            
          
          <!-- rolesMap.role!=null没有相应的角色 -->
		       <if test=" rolesMap.role!=null">
			       and pad.flag=-1
		       </if>
		       <include refid="sqlcoue"/> 
		       and pad.flag=0
		</where> 
          group by pad.personnel_id,pad.personnel_type_id,regionName  
    
    
    </select>
    
    
    
    <select id="perone" resultType="cn.com.countrygarden.bi.main.model.personnel.Personnel">
             select p.id as id,p.user_id as userId,p.name as name from personnel p
             where p.user_id=#{userId}
    </select>
    
    <select id="peaduserid" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="java.lang.String">
                select distinct pe.id as id,p.id as personnelId,p.user_id as userId,p.name as name,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,bdp.name as advisorUserName,pe.positivevaluation as positivevaluation,
                 pe.fixedpostevaluation as fixedpostevaluation,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate
                 from biapp.personnel p,biapp.personnel_advisor pe,
                 performance_app.bd_psndoc bdp,performance_app.hi_psnjob hips
                 where p.id=pe.personnel_id and bdp.PK_PSNDOC = hips.PK_PSNDOC and hips.poststat='Y' and bdp.`CODE`=pe.advisor_user_id and pe.flag=0
                 and p.user_id=#{userId} and pe.advisor_user_id=#{advisorUserId} and pe.positivevaluation=#{positivevaluation} and pe.fixedpostevaluation=#{fixedpostevaluation}
    </select>
    
        <select id="peaduseridlist" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="java.lang.String">
                select pe.id as id,p.id as personnelId,p.user_id as userId,p.name as name,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,bdp.name as advisorUserName,pe.positivevaluation as positivevaluation,
                 pe.fixedpostevaluation as fixedpostevaluation,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate
                 from biapp.personnel p,biapp.personnel_advisor pe,
                 performance_app.bd_psndoc bdp,performance_app.hi_psnjob hips
                 where p.id=pe.personnel_id and bdp.PK_PSNDOC = hips.PK_PSNDOC and hips.poststat='Y' and bdp.`CODE`=pe.advisor_user_id
                 and p.user_id=#{userId}
    </select>
    
    <select id="peadone" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="java.lang.Integer">
           select distinct pe.id as id,p.id as personnelId,p.user_id as userId,p.name as name,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,pe.advisor_user_id as advisorUserId,bdp.name as advisorUserName,pe.positivevaluation as positivevaluation,
                 pe.fixedpostevaluation as fixedpostevaluation,pe.filesame as filesame,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate,pe.addition_time as additionTime,pe.normal_time as normalTime,pe.fixed_time as fixedTime,pe.positivescore as positivescore,pe.fixedscore as fixedscore
                 ,pe.positivescore as positivescore,pe.fixedscore as fixedscore
                 from biapp.personnel p,biapp.personnel_advisor pe,
                 performance_app.bd_psndoc bdp,performance_app.hi_psnjob hips
                 where p.id=pe.personnel_id and bdp.PK_PSNDOC = hips.PK_PSNDOC and hips.poststat='Y' and bdp.`CODE`=pe.advisor_user_id and pe.flag=0
                 and p.id=#{personnelId}
    
    </select>
    
    <select id="findProblemClassificationIds" parameterType="int"
		resultType="int">
		select distinct(p.questionnaire_problem_classification_id) from
		review_questionnaire_problem
		p,review_questionnaire_problem_classification c where p.flag=1
		and p.questionnaire_problem_classification_id=c.id and c.flag !=2 and
		p.questionnaire_id=#{questionnaireId}

	</select>
	<select id="queryPageListadd" resultType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO" parameterType="cn.com.countrygarden.bi.main.dto.PersonnelAdvisorDTO">
                 select DISTINCT pe.id as id,p.id as personnelId,pg.id as personneltagId,pg.identity as identity,p.user_id as userId,p.name as `name`,pe.personnel_type_id as personnelTypeId,pe.mentorpost as mentorpost,pe.advisor_user_id as advisorUserId,pe.advisor_user_name as advisorUserName,pe.positivevaluation as positivevaluation,
                  pe.fixedpostevaluation as fixedpostevaluation,pe.filesame as filesame,pe.files as files,pe.created_by as createdBy,pe.created_date as createdDate,pe.created_name as createdName,pg.identity as identity,pg.id as personneltagId,pe.addition_time as additionTime,pe.start_time as startTime,pe.terminal_time as terminalTime,
                  pe.positivescore as positivescore,pe.fixedscore as fixedscore,pe.normal_time as normalTime,pe.fixed_time as fixedTime
                 from biapp.personnel_advisor pe
                 left join biapp.personnel p on p.id=pe.personnel_id
                 left join biapp.personnel_tag pg ON p.user_id=pg.user_id and pg.id=pe.personneltag_id
                left join biapp.personnel_advisor_type pty on pe.personnel_type_id=pty.id
             
                 where pe.flag=0
                  <if test="personnelTypeId!=null and personnelTypeId!=''">
                        and pe.personnel_type_id=#{personnelTypeId}
                 </if>
                 <if test="userId!=null and userId!=''">
                       and p.user_id like concat('%',#{userId},'%')
                 </if>
                 
                 <if test="personnelId!=null and personnelId!=''">
                     and p.id=#{personnelId}
                 </if>
                 
                 <if test="personneltagId!=null and personneltagId!=''">
                      and pe.personneltag_id=#{personneltagId}
                 </if>
                 
    </select>
    
    <update id="delpiliang">
    
       update biapp.personnel_advisor set flag=1 
       <where>
           <if test="persId!=null">
              and personnel_id in 
               <foreach collection="persId" item="persId" index="index" open="(" close=")" separator=",">
    
                    #{persId}
                 </foreach>
           </if>
           <if test="pertagId!=null">
               and personneltag_id in
                 <foreach collection="pertagId" item="pertagId" index="index" open="(" close=")" separator=",">
    
                    #{pertagId}
                 </foreach>
           </if>
       
       </where>
              
    </update>
</mapper>