<?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.CheckinInfoDAO">
    <resultMap id="CheckinInfoMap" type="com.jpsoft.shinestar.modules.base.entity.CheckinInfo">
        <id property="id" column="id_"/>
        <result property="building" column="building_"/>
        <result property="room" column="room_"/>
        <result property="companyId" column="company_id"/>
        <result property="artificialPerson" column="artificial_person"/>
        <result property="artificialPersonPhone" column="artificial_person_phone"/>
        <result property="area" column="area_"/>
        <result property="checkinTime" column="checkin_time"/>
        <result property="feeExpirationTime" column="fee_expiration_time"/>
        <result property="contractExpirationTime" column="contract_expiration_time"/>
        <result property="leaseTerm" column="lease_term"/>
        <result property="rent" column="rent_"/>
        <result property="propertyId" column="property_id"/>
        <result property="delFlag" column="del_flag"/>
        <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="boss" column="boss_"/>
        <result property="wechatPay" column="wechat_pay"/>
        <result property="aliPay" column="ali_pay"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CheckinInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_checkin_info
	    (id_,building_,room_,company_id,artificial_person,artificial_person_phone,area_,checkin_time,fee_expiration_time,contract_expiration_time,lease_term,rent_,property_id,del_flag,create_by,create_time,update_by,update_time,boss_,wechat_pay,ali_pay)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{building,jdbcType=VARCHAR}
            ,#{room,jdbcType=VARCHAR}
            ,#{companyId,jdbcType=VARCHAR}
            ,#{artificialPerson,jdbcType=NUMERIC}
            ,#{artificialPersonPhone,jdbcType=VARCHAR}
            ,#{area,jdbcType= VARCHAR }
            ,#{checkinTime,jdbcType= TIMESTAMP }
            ,#{feeExpirationTime,jdbcType= TIMESTAMP }
            ,#{contractExpirationTime,jdbcType= TIMESTAMP }
            ,#{leaseTerm,jdbcType=VARCHAR}
            ,#{rent,jdbcType=VARCHAR}
            ,#{propertyId,jdbcType=VARCHAR}
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{boss,jdbcType=VARCHAR}
            ,#{wechatPay,jdbcType= NUMERIC }
            ,#{aliPay,jdbcType= NUMERIC }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_checkin_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CheckinInfo">
        update base_checkin_info
        <set>
            <if test="building!=null">
                building_=#{building,jdbcType=VARCHAR},
            </if>
            <if test="room!=null">
                room_=#{room,jdbcType=VARCHAR},
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="artificialPerson!=null">
                artificial_person=#{artificialPerson,jdbcType=NUMERIC},
            </if>
            <if test="artificialPersonPhone!=null">
                artificial_person_phone=#{artificialPersonPhone,jdbcType=VARCHAR},
            </if>
            <if test="area!=null">
                area_=#{area,jdbcType= VARCHAR },
            </if>
            <if test="checkinTime!=null">
                checkin_time=#{checkinTime,jdbcType= TIMESTAMP },
            </if>
            <if test="feeExpirationTime!=null">
                fee_expiration_time=#{feeExpirationTime,jdbcType= TIMESTAMP },
            </if>
            <if test="contractExpirationTime!=null">
                contract_expiration_time=#{contractExpirationTime,jdbcType= TIMESTAMP },
            </if>
            <if test="leaseTerm!=null">
                lease_term=#{leaseTerm,jdbcType=VARCHAR},
            </if>
            <if test="rent!=null">
                rent_=#{rent,jdbcType=VARCHAR},
            </if>
            <if test="propertyId!=null">
                property_id=#{propertyId,jdbcType=VARCHAR},
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </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="boss!=null">
                boss_=#{boss,jdbcType=VARCHAR},
            </if>
            <if test="wechatPay!=null">
                wechat_pay=#{wechatPay,jdbcType= NUMERIC },
            </if>
            <if test="aliPay!=null">
                ali_pay=#{aliPay,jdbcType= NUMERIC },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="CheckinInfoMap">
        select * from base_checkin_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_checkin_info where id_=#{0}
    </select>
    <select id="list" resultMap="CheckinInfoMap">
        select * from base_checkin_info
    </select>
    <select id="findBypropertyId" resultMap="CheckinInfoMap">
        select * from base_checkin_info where del_flag=0 and property_id=#{0}
    </select>
    <select id="findByCompanyId" resultMap="CheckinInfoMap">
        select * from base_checkin_info where del_flag=0 and company_id=#{0} limit 1
    </select>
    <select id="search" parameterType="hashmap" resultMap="CheckinInfoMap">
        <![CDATA[
			select * from base_checkin_info a
			LEFT JOIN base_company_info b ON a.company_Id = b.id_
		]]>
        <where>
            a.del_flag=0
            <if test="searchParams.building != null">
                and a.building_ like #{searchParams.building}
            </if>
            <if test="searchParams.companyId != null">
                and a.company_id like #{searchParams.companyId}
            </if>
            <if test="searchParams.propertyId != null">
                and a.property_id = #{searchParams.propertyId}
            </if>
            <if test="searchParams.feeExpirationTime != null">
                <![CDATA[
				and a.fee_expiration_time <= #{searchParams.feeExpirationTime}
				]]>
            </if>
            <if test="searchParams.contractExpirationTime != null">
                <![CDATA[
				and a.contract_expiration_time <= #{searchParams.contractExpirationTime}
				]]>
            </if>
            <if test="searchParams.name != null">
				and b.name_ like #{searchParams.name}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
</mapper>