<?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.GuestInfoRecordDAO">
	<resultMap id="GuestInfoRecordMap" type="com.jpsoft.shinestar.modules.business.entity.GuestInfoRecord">
		<id property="id" column="id_" />
			<result property="name" column="name_" />
			<result property="mobilePhone" column="mobile_phone" />
			<result property="unit" column="unit_" />
			<result property="idCard" column="id_card" />
			<result property="visitDate" column="visit_date" />
			<result property="visitReasons" column="visit_reasons" />
			<result property="numberPlate" column="number_plate" />
			<result property="intervieweeId" column="interviewee_id" />
			<result property="intervieweeName" column="interviewee_name" />
			<result property="intervieweePhone" column="interviewee_phone" />
			<result property="openId" column="open_id" />
			<result property="comeInTime" column="come_in_time" />
			<result property="outTime" column="out_time" />
			<result property="status" column="status" />
			<result property="auditTime" column="audit_time" />
			<result property="delFlag" column="del_flag" />
			<result property="createTime" column="create_time" />
			<result property="createBy" column="create_by" />
			<result property="updateTime" column="update_time" />
			<result property="updateBy" column="update_by" />
			<result property="issueDevice" column="issue_device" />
			<result property="expirationTime" column="expiration_time" />
			<result property="isUpPhoto" column="is_up_photo" />
			<result property="photo" column="photo_" />
			<result property="confirmationTime" column="confirmation_time" />
			<result property="temperature" column="temperature_" />
			<result property="temperatureBack" column="temperature_back" />
			<result property="companyId" column="company_id" />
			<result property="personId" column="person_id" />
			</resultMap>
	<insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.GuestInfoRecord">
	<!--
	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
		select sys_guid() from dual
	</selectKey>
	-->
	<![CDATA[
		insert into business_guest_info_record
	    (id_,name_,mobile_phone,unit_,id_card,visit_date,visit_reasons,number_plate,
	    interviewee_id,interviewee_name,interviewee_Phone,open_id,
	    come_in_time,out_time,status,audit_time,del_flag,create_time,create_by,update_time,update_by,issue_device,expiration_time,is_up_photo,photo_,confirmation_time,temperature_,temperature_back,company_id,person_id)
		values
		(
#{id,jdbcType=VARCHAR}
,#{name,jdbcType=VARCHAR}
,#{mobilePhone,jdbcType=VARCHAR}
,#{unit,jdbcType=VARCHAR}
,#{idCard,jdbcType=VARCHAR}
,#{visitDate,jdbcType= TIMESTAMP }
,#{visitReasons,jdbcType=VARCHAR}
,#{numberPlate,jdbcType=VARCHAR}
,#{intervieweeId,jdbcType=VARCHAR}

,#{intervieweeName,jdbcType=VARCHAR}
,#{intervieweePhone,jdbcType=VARCHAR}
,#{openId,jdbcType=VARCHAR}
,#{comeInTime,jdbcType= TIMESTAMP }
,#{outTime,jdbcType= TIMESTAMP }
,#{status,jdbcType= NUMERIC }
,#{auditTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{createTime,jdbcType= TIMESTAMP }
,#{createBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{issueDevice,jdbcType=VARCHAR}
,#{expirationTime,jdbcType= TIMESTAMP }
,#{isUpPhoto,jdbcType= NUMERIC }
,#{photo,jdbcType=VARCHAR}
,#{confirmationTime,jdbcType=TIMESTAMP}
,#{temperature,jdbcType=NUMERIC},#{temperatureBack,jdbcType=NUMERIC}
,#{companyId,jdbcType=VARCHAR}
,#{personId,jdbcType=NUMERIC}
		)
	]]>
	</insert>
	<delete id="delete" parameterType="string">
		delete from business_guest_info_record where id_=#{id,jdbcType=VARCHAR}
	</delete>
	<update id="update" parameterType="com.jpsoft.shinestar.modules.business.entity.GuestInfoRecord">
		update business_guest_info_record
		<set>
				<if test="name!=null">
		name_=#{name,jdbcType=VARCHAR},
		</if>
				<if test="mobilePhone!=null">
		mobile_phone=#{mobilePhone,jdbcType=VARCHAR},
		</if>
				<if test="unit!=null">
		unit_=#{unit,jdbcType=VARCHAR},
		</if>
				<if test="idCard!=null">
		id_card=#{idCard,jdbcType=VARCHAR},
		</if>
				<if test="visitDate!=null">
		visit_date=#{visitDate,jdbcType= TIMESTAMP },
		</if>
				<if test="visitReasons!=null">
		visit_reasons=#{visitReasons,jdbcType=VARCHAR},
		</if>
				<if test="numberPlate!=null">
		number_plate=#{numberPlate,jdbcType=VARCHAR},
		</if>
				<if test="intervieweeId!=null">
		interviewee_id=#{intervieweeId,jdbcType=VARCHAR},
		</if>
			<if test="intervieweeName!=null">
				interviewee_Name=#{intervieweeName,jdbcType=VARCHAR},
			</if>
			<if test="intervieweePhone!=null">
				interviewee_Phone=#{intervieweePhone,jdbcType=VARCHAR},
			</if>
			<if test="openId!=null">
				open_id=#{openId,jdbcType=VARCHAR},
			</if>
				<if test="comeInTime!=null">
		come_in_time=#{comeInTime,jdbcType= TIMESTAMP },
		</if>
				<if test="outTime!=null">
		out_time=#{outTime,jdbcType= TIMESTAMP },
		</if>
				<if test="status!=null">
		status=#{status,jdbcType= NUMERIC },
		</if>
				<if test="auditTime!=null">
		audit_time=#{auditTime,jdbcType= TIMESTAMP },
		</if>
				<if test="delFlag!=null">
		del_flag=#{delFlag,jdbcType= NUMERIC },
		</if>
				<if test="createTime!=null">
		create_time=#{createTime,jdbcType= TIMESTAMP },
		</if>
				<if test="createBy!=null">
		create_by=#{createBy,jdbcType=VARCHAR},
		</if>
				<if test="updateTime!=null">
		update_time=#{updateTime,jdbcType= TIMESTAMP },
		</if>
				<if test="updateBy!=null">
		update_by=#{updateBy,jdbcType=VARCHAR},
		</if>
			<if test="issueDevice!=null">
				issue_device=#{issueDevice,jdbcType=VARCHAR},
			</if>
			<if test="expirationTime!=null">
				expiration_time=#{expirationTime,jdbcType=TIMESTAMP},
			</if>
			<if test="isUpPhoto!=null">
				is_up_photo=#{isUpPhoto,jdbcType=NUMERIC},
			</if>

			<if test="photo!=null">
				photo_=#{photo,jdbcType=VARCHAR},
			</if>
			<if test="confirmationTime!=null">
				confirmation_time=#{confirmationTime,jdbcType=TIMESTAMP},
			</if>
			<if test="temperature!=null">
				temperature_=#{temperature,jdbcType=NUMERIC},
			</if>
			<if test="temperatureBack!=null">
				temperature_back=#{temperatureBack,jdbcType=NUMERIC},
			</if>
			<if test="companyId!=null">
				company_id=#{companyId,jdbcType=NUMERIC},
			</if>
			<if test="personId!=null">
				person_id=#{personId,jdbcType=NUMERIC},
			</if>
		</set>
	where id_=#{id}
	</update>
	<select id="get" parameterType="string" resultMap="GuestInfoRecordMap">
		select  *	from business_guest_info_record where id_=#{0}
	</select>
	<select id="exist" parameterType="string" resultType="int">
		select count(*) from business_guest_info_record where id_=#{0}
	</select>
	<select id="list" resultMap="GuestInfoRecordMap">
		select * from business_guest_info_record
	</select>
	<select id="findByPersonId" resultMap="GuestInfoRecordMap">
		select * from business_guest_info_record where del_flag=false and person_id = #{0} limit 1
	</select>
	<select id="findByOpenId" resultMap="GuestInfoRecordMap">
		select * from business_guest_info_record where del_flag=false and open_id = #{0}  order by create_Time desc limit 1
	</select>
	<select id="search" parameterType="hashmap" resultMap="GuestInfoRecordMap">
		<![CDATA[
			select * from business_guest_info_record
		]]>
		<where>
			<if test="searchParams.startDate != null">
				<![CDATA[
					 and visit_Date >= #{searchParams.startDate}
				]]>
 			</if>

			<if test="searchParams.endDate != null">
				<![CDATA[
					 and visit_Date <= #{searchParams.endDate}
				]]>
 			</if>
			<if test="searchParams.guest != null">
				and status =1
			</if>
			<if test="searchParams.intervieweeId != null">
				and interviewee_id = #{searchParams.intervieweeId}
			</if>
            <if test="searchParams.openId != null">
                and open_id = #{searchParams.openId}
            </if>
			<if test="searchParams.companyIdList != null">
				<foreach collection="searchParams.companyIdList" index="index" item="item" open="and company_id in(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		</where>
		<foreach item="sort" collection="sortList"  open="order by" separator=",">
	        ${sort.name} ${sort.order}
	 	</foreach>
	</select>
	<select id="getScanNum" parameterType="hashmap" resultType="hashmap">
		<![CDATA[
			select

			 count('1') num1,

			count(come_In_Time is not null OR NULL) num2,

			count(out_Time is not null OR NULL ) num3

			 from business_guest_info_record
		]]>
		<where>
			to_days(now())=to_days(visit_Date)
            and status =1
			<if test="intervieweeId != null">
				and interviewee_id = #{searchParams.intervieweeId}
			</if>
			<if test="companyIdList != null">
				<foreach collection="companyIdList" index="index" item="item" open="and company_id in(" separator="," close=")">
					#{item}
				</foreach>
			</if>

		</where>

	</select>
</mapper>