<?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.business.dao.MeetingPersonRecodeDAO">
	<resultMap id="MeetingPersonRecodeMap" type="com.jpsoft.shinestar.modules.business.entity.MeetingPersonRecode">
		<id property="id" column="id_" />
			<result property="personId" column="person_id" />
			<result property="signTime" column="sign_time" />
			<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="delFlag" column="del_flag" />
			<result property="signType" column="sign_type" />

			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.MeetingPersonRecode">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into business_meeting_person_recode
	    (id_,person_id,sign_time,meetingInfo_id,create_by,create_time,update_by,update_time,del_flag,sign_type)
		values
		(
			#{id,jdbcType=VARCHAR}
			,#{personId,jdbcType= NUMERIC }
			,#{signTime,jdbcType= TIMESTAMP }
			,#{meetingInfoId,jdbcType=VARCHAR}
			,#{createBy,jdbcType=VARCHAR}
			,#{createTime,jdbcType= TIMESTAMP }
			,#{updateBy,jdbcType=VARCHAR}
			,#{updateTime,jdbcType= TIMESTAMP }
			,#{delFlag,jdbcType= NUMERIC }
			,#{signType,jdbcType=VARCHAR}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from business_meeting_person_recode where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.MeetingPersonRecode">
		update business_meeting_person_recode
		<set>
				<if test="personId!=null">
		person_id=#{personId,jdbcType= NUMERIC },
		</if>
				<if test="signTime!=null">
		sign_time=#{signTime,jdbcType= TIMESTAMP },
		</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="signType!=null">
				sign_type=#{signType,jdbcType= VARCHAR },
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="MeetingPersonRecodeMap">
		select * from business_meeting_person_recode where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from business_meeting_person_recode where id_=#{0}
	</select>
	<select id="list" resultMap="MeetingPersonRecodeMap">
		select * from business_meeting_person_recode
	</select>
	<select id="findByMeetingIdAndSignTime" resultMap="MeetingPersonRecodeMap">
		select * from business_meeting_person_recode
		where del_flag = false and person_id=#{personId} and meetingInfo_id=#{meetingId} and sign_type = #{signType}
		<![CDATA[
			and sign_time >= #{startTime} and sign_time <= #{endTime} limit 1
		]]>
	</select>
	<select id="search" parameterType="hashmap" resultMap="MeetingPersonRecodeMap">
		<![CDATA[
			select * from business_meeting_person_recode
		]]>
		<where>
			<if test="searchParams.meetingId != null">
				and meetingInfo_id = #{searchParams.meetingId}
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
<!--	<select id="noAbsentSearch" parameterType="hashmap" resultType="java.util.HashMap">
		<![CDATA[
			select a.person_id,
			(SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='0' and meetingInfo_id = #{searchParams.meetingId} limit 1) as startTime,
			(SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='1' and meetingInfo_id = #{searchParams.meetingId} limit 1) as endTime
			FROM business_meeting_person_recode a
		]]>
		<where>
			<if test="searchParams.meetingId != null">
				and meetingInfo_id = #{searchParams.meetingId}
			</if>
		</where>
		GROUP BY a.person_id
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>-->
<!--	<select id="leaveEarlySearch" parameterType="hashmap" resultType="java.util.HashMap">
		<![CDATA[
			select a.person_id,
			(SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='0' and meetingInfo_id = #{searchParams.meetingId} limit 1) as startTime,
			(SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='1' and meetingInfo_id = #{searchParams.meetingId} limit 1) as endTime
			FROM business_meeting_person_recode a
		]]>
		<where>
			<if test="searchParams.meetingId != null">
				and meetingInfo_id = #{searchParams.meetingId}
			</if>
			<![CDATA[
			and (SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='0' and meetingInfo_id = #{searchParams.meetingId} limit 1) is not null
			and (SELECT b.sign_time FROM business_meeting_person_recode b  WHERE b.person_id = a.person_id and b.sign_type='1' and meetingInfo_id = #{searchParams.meetingId} limit 1) is null
			]]>
		</where>
		GROUP BY a.person_id
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>-->
	<select id="meetingRecordPageList" parameterType="hashmap" resultType="java.util.HashMap">
		<![CDATA[
			SELECT a.name_ as name,a.id_ as id,a.status_ as status,
			(SELECT count(person_id) from base_meeting_person z where z.meetingInfo_id = a.id_ and z.del_flag=FALSE ) as 'needNum'
			FROM base_meeting_info a left join base_meeting_time b on a.id_ = b.meeting_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.beginTime != null">
				<![CDATA[
                  and b.meeting_date >= #{searchParams.beginTime}
                ]]>
			</if>
			<if test="searchParams.endTime != null">
				<![CDATA[
                  and b.meeting_date <= #{searchParams.endTime}
                ]]>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
			${sort.name} ${sort.order}
		</foreach>
	</select>
    <select id="findByPersonIdAndSignTime" resultMap="MeetingPersonRecodeMap">
		<![CDATA[
			select * from business_meeting_person_recode
			where
			person_id=#{personId}
			and
			sign_time>=#{startDate}
			and
			sign_time<#{endDate}
			and
			del_flag=0
		]]>
	</select>
</mapper>