<?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.CustomerDiningRecordDAO">
    <resultMap id="CustomerDiningRecordMap" type="com.jpsoft.shinestar.modules.base.entity.CustomerDiningRecord">
        <id property="id" column="id_" />
        <result property="personPopedomId" column="person_popedom_id" />
        <result property="companyId" column="company_id"/>
        <result property="customerCompany" column="customer_company" />
        <result property="reason" column="reason_" />
        <result property="customerNum" column="customer_num" />
        <result property="accompanyNum" column="accompany_num" />
        <result property="diningTime" column="dining_time" />
        <result property="diningName" column="dining_name" />
        <result property="diningFee" column="dining_fee" />
        <result property="status" column="status_"/>
        <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="procinstId" column="procinst_id" />
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.CustomerDiningRecord">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_customer_dining_record
	    (id_,person_popedom_id,company_id,customer_company,reason_,customer_num,accompany_num,dining_time,dining_name,dining_fee,status_,create_by,create_time,update_by,update_time,del_flag,procinst_id)
		values
		(
#{id,jdbcType=VARCHAR}
,#{personPopedomId,jdbcType=VARCHAR}
,#{companyId,jdbcType=VARCHAR}
,#{customerCompany,jdbcType= VARCHAR }
,#{reason,jdbcType= VARCHAR }
,#{customerNum,jdbcType=INTEGER}
,#{accompanyNum,jdbcType=INTEGER }
,#{diningTime,jdbcType=TIMESTAMP}
,#{diningName,jdbcType=VARCHAR}
,#{diningFee,jdbcType=DECIMAL }
,#{status,jdbcType=VARCHAR}
,#{createBy,jdbcType=VARCHAR}
,#{createTime,jdbcType= TIMESTAMP }
,#{updateBy,jdbcType=VARCHAR}
,#{updateTime,jdbcType= TIMESTAMP }
,#{delFlag,jdbcType= NUMERIC }
,#{procinstId,jdbcType=VARCHAR }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_customer_dining_record where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.CustomerDiningRecord">
        update base_customer_dining_record
        <set>
            <if test="personPopedomId!=null">
                person_popedom_id=#{personPopedomId,jdbcType=VARCHAR},
            </if>
            <if test="companyId != null">
                company_id = #{companyId,jdbcType=VARCHAR},
            </if>
            <if test="customerCompany!=null">
                customer_company=#{customerCompany,jdbcType= VARCHAR },
            </if>
            <if test="reason!=null">
                reason_=#{reason,jdbcType= VARCHAR },
            </if>
            <if test="customerNum!=null">
                customer_num=#{customerNum,jdbcType=INTEGER },
            </if>
            <if test="accompanyNum!=null">
                accompany_num=#{accompanyNum,jdbcType=INTEGER },
            </if>
            <if test="diningTime!=null">
                dining_time=#{diningTime,jdbcType=TIMESTAMP},
            </if>
            <if test="diningName!=null">
                dining_name=#{diningName,jdbcType=VARCHAR},
            </if>
            <if test="diningFee!=null">
                dining_fee=#{diningFee,jdbcType=DECIMAL },
            </if>
            <if test="status != null">
                status_ = #{status,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="procinstId!=null">
                procinst_id=#{procinstId,jdbcType=VARCHAR }
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="CustomerDiningRecordMap">
        select * from base_customer_dining_record where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_customer_dining_record where id_=#{0}
    </select>
    <select id="list" resultMap="CustomerDiningRecordMap">
		select * from base_customer_dining_record where del_flag = 0
	</select>
    <select id="search" parameterType="hashmap" resultMap="CustomerDiningRecordMap">
        <![CDATA[
			select a.* from base_customer_dining_record a
            left JOIN base_person_popedom b on a.person_popedom_id=b.id_
            left join base_person_info c on b.person_id=c.id_
            left join base_company_info d on a.company_id=d.id_
		]]>
        <where>
            a.del_flag=FALSE and b.del_flag=FALSE and c.del_flag=FALSE
            <if test="searchParams.personName != null">
                and c.name_ like #{searchParams.personName}
            </if>
            <if test="searchParams.companyId != null">
                and d.code_ like #{searchParams.companyId}
            </if>
            <if test="searchParams.auditStatus != null">
                and a.status_ = #{searchParams.auditStatus}
            </if>
            <if test="searchParams.diningType != null">
                and a.dining_name = #{searchParams.diningType}
            </if>
            <if test="searchParams.beginTime != null">
                <![CDATA[
					and a.create_time >=#{searchParams.beginTime}
				]]>
            </if>
            <if test="searchParams.endTime != null">
                <![CDATA[
					and a.create_time <=#{searchParams.endTime}
				]]>
            </if>
            <if test="searchParams.beginDiningTime != null">
                <![CDATA[
					and a.dining_time >=#{searchParams.beginDiningTime}
				]]>
            </if>
            <if test="searchParams.beginDiningTime != null">
                <![CDATA[
					and a.dining_time <=#{searchParams.endDiningTime}
				]]>
            </if>
            <if test="searchParams.beginAuditTime != null">
                <![CDATA[
					and a.update_time >=#{searchParams.beginAuditTime}
				]]>
            </if>
            <if test="searchParams.endAuditTime != null">
                <![CDATA[
					and a.update_time <=#{searchParams.endAuditTime}
				]]>
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
</mapper>