<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.MeetingPersonDAO">
    <resultMap id="MeetingPersonMap" type="com.jpsoft.shinestar.modules.base.entity.MeetingPerson">
        <id property="id" column="id_"/>
        <result property="personId" column="person_id"/>
        <result property="meetingInfoId" column="meetingInfo_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="signTime" column="sign_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="signType" column="sign_type"/>
        <result property="personName" column="person_name"/>
        <result property="companyName" column="company_name"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.MeetingPerson">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_meeting_person
	    (id_,person_id,meetingInfo_id,create_by,create_time,update_by,update_time,del_flag,sign_time,sign_type)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{personId,jdbcType= NUMERIC }
            ,#{meetingInfoId,jdbcType=VARCHAR}
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{signTime,jdbcType= TIMESTAMP }
            ,#{signType,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_meeting_person where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="deleteByMeetingId">
        update base_meeting_person set del_flag=1
        where
        meetingInfo_id=#{meetingId,jdbcType=VARCHAR}
    </update>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.MeetingPerson">
        update base_meeting_person
        <set>
            <if test="personId!=null">
                person_id=#{personId,jdbcType= NUMERIC },
            </if>
            <if test="meetingInfoId!=null">
                meetingInfo_id=#{meetingInfoId,jdbcType=VARCHAR},
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="signTime!=null">
                sign_time=#{signTime,jdbcType= TIMESTAMP },
            </if>
            <if test="signType!=null">
                sign_type=#{signType,jdbcType= VARCHAR },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="MeetingPersonMap">
        select * from base_meeting_person where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_meeting_person where id_=#{0}
    </select>
    <select id="list" resultMap="MeetingPersonMap">
        select * from base_meeting_person
    </select>
    <select id="findByMeetingId" resultMap="MeetingPersonMap">
        select a.*,
        b.name_ as person_name,
        c.name_ as company_name
        from base_meeting_person a
        inner join base_person_info b on a.person_id = b.id_
        inner join base_company_info c on b.company_id = c.id_
        where a.del_flag=false
        and a.meetingInfo_id=#{0}
    </select>
    <select id="findByMeetingIdAndPersonId" resultMap="MeetingPersonMap">
        select * from base_meeting_person where del_flag=false and meetingInfo_id = #{meetingId} and person_id =
        #{personId} limit 1
    </select>
    <select id="search" parameterType="hashmap" resultMap="MeetingPersonMap">
        <![CDATA[
			select a.* from base_meeting_person a inner join base_person_info b on a.person_id = b.id_
		]]>
        <where>
            a.del_flag = false and b.del_flag = false
            <if test="searchParams.meetingId != null">
                and a.meetingInfo_id = #{searchParams.meetingId}
            </if>
            <if test="searchParams.name != null">
                and b.name_ like #{searchParams.name}
            </if>
            <if test="searchParams.jobNumber != null">
                and b.job_number like #{searchParams.jobNumber}
            </if>
            <if test="searchParams.personIdList!=null">
                <foreach collection="searchParams.personIdList" index="index" item="item" open=" and a.person_id not in ("
                         separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="absentSearch" parameterType="hashmap" resultMap="MeetingPersonMap">
        <![CDATA[
			select a.*
			FROM base_meeting_person a
			inner join base_person_info b on a.person_id = b.id_
		]]>
        <where>
            a.del_flag=0 and b.del_flag = 0 and a.sign_time is null
            <if test="searchParams.meetingId != null">
                and a.meetingInfo_id = #{searchParams.meetingId}
            </if>
            <if test="searchParams.name != null">
                and b.name_ like #{searchParams.name}
            </if>
            <if test="searchParams.jobNumber != null">
                and b.job_number like #{searchParams.jobNumber}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
        <!--and (SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='1') is not null-->
    </select>
    <select id="realToSearch" parameterType="hashmap" resultType="java.util.HashMap">
        <![CDATA[
			select a.person_id,a.sign_time
			FROM base_meeting_person a
			inner join base_person_info b on a.person_id = b.id_
		]]>
        <where>
            a.del_flag = 0 and b.del_flag = 0 and a.sign_time is not null
            <if test="searchParams.meetingId != null">
                and a.meetingInfo_id = #{searchParams.meetingId}
            </if>
            <if test="searchParams.name != null">
                and b.name_ like #{searchParams.name}
            </if>
            <if test="searchParams.jobNumber != null">
                and b.job_number like #{searchParams.jobNumber}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
        <!--and (SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='1') is not null-->
    </select>
    <select id="lateSearch" parameterType="hashmap" resultType="java.util.HashMap">
        <![CDATA[
			select a.person_id,a.sign_time
			from base_meeting_person a
			inner join base_person_info b on a.person_id = b.id_
		]]>
        <where>
            a.del_flag=0 and b.del_flag = 0 and a.sign_type='2'
            <if test="searchParams.meetingId != null">
                and a.meetingInfo_id = #{searchParams.meetingId}
            </if>
            <if test="searchParams.name != null">
                and b.name_ like #{searchParams.name}
            </if>
            <if test="searchParams.jobNumber != null">
                and b.job_number like #{searchParams.jobNumber}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
</mapper>