<?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">
<mapper namespace="com.jianshui.income.mapper.CollectRecordMapper">
    
    <resultMap type="CollectRecord" id="CollectRecordResult">
        <result property="pch"    column="pch"    />
        <result property="gmfsbh"    column="gmfsbh"    />
        <result property="fplxdm"    column="fplxdm"    />
        <result property="cjksrq"    column="cjksrq"    />
        <result property="cjjsrq"    column="cjjsrq"    />
        <result property="zhs"    column="zhs"    />
        <result property="dqskssq"    column="dqskssq"    />
        <result property="cjlx"    column="cjlx"    />
        <result property="createtime"    column="createtime"    />
    </resultMap>

    <sql id="selectCollectRecordVo">
        select pch, gmfsbh, fplxdm, cjksrq, cjjsrq, zhs, dqskssq, cjlx, createtime from cjjlb
    </sql>

    <select id="selectCollectRecordList" parameterType="CollectRecord" resultMap="CollectRecordResult">
        <include refid="selectCollectRecordVo"/>
        <where>  
            <if test="gmfsbh != null  and gmfsbh != ''"> and gmfsbh = #{gmfsbh}</if>
            <if test="fplxdm != null  and fplxdm != ''"> and fplxdm = #{fplxdm}</if>
            <if test="cjksrq != null  and cjksrq != ''"> and cjksrq = #{cjksrq}</if>
            <if test="cjjsrq != null  and cjjsrq != ''"> and cjjsrq = #{cjjsrq}</if>
            <if test="zhs != null "> and zhs = #{zhs}</if>
            <if test="dqskssq != null  and dqskssq != ''"> and dqskssq = #{dqskssq}</if>
            <if test="cjlx != null  and cjlx != ''"> and cjlx = #{cjlx}</if>
            <if test="createtime != null "> and createtime = #{createtime}</if>
        </where>
        order by createtime desc
    </select>


    <select id="selectCollectRecord" parameterType="CollectRecord" resultMap="CollectRecordResult">
        select pch,gmfsbh,fplxdm,cjjsrq
        from cjjlb
        <where>
            <if test="gmfsbh != null  and gmfsbh != ''"> and gmfsbh = #{gmfsbh}</if>
            <if test="fplxdm != null  and fplxdm != ''"> and fplxdm = #{fplxdm}</if>
            <if test="cjlx != null  and cjlx != ''"> and cjlx = #{cjlx}</if>
            and zhs &gt; 0
        </where>
        order by createtime desc
        limit 1
    </select>
    <select id="selectCollectRecordById" parameterType="int" resultMap="CollectRecordResult">
        <include refid="selectCollectRecordVo"/>
        where pch = #{pch}
    </select>
        
    <insert id="insertCollectRecord" parameterType="CollectRecord">
        insert into cjjlb
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pch != null">pch,</if>
            <if test="gmfsbh != null">gmfsbh,</if>
            <if test="fplxdm != null">fplxdm,</if>
            <if test="cjksrq != null">cjksrq,</if>
            <if test="cjjsrq != null">cjjsrq,</if>
            <if test="zhs != null">zhs,</if>
            <if test="dqskssq != null">dqskssq,</if>
            <if test="cjlx != null">cjlx,</if>
            <if test="createtime != null">createtime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pch != null">#{pch},</if>
            <if test="gmfsbh != null">#{gmfsbh},</if>
            <if test="fplxdm != null">#{fplxdm},</if>
            <if test="cjksrq != null">#{cjksrq},</if>
            <if test="cjjsrq != null">#{cjjsrq},</if>
            <if test="zhs != null">#{zhs},</if>
            <if test="dqskssq != null">#{dqskssq},</if>
            <if test="cjlx != null">#{cjlx},</if>
            <if test="createtime != null">#{createtime},</if>
         </trim>
    </insert>

    <update id="updateCollectRecord" parameterType="CollectRecord">
        update cjjlb
        <trim prefix="SET" suffixOverrides=",">
            <if test="gmfsbh != null">gmfsbh = #{gmfsbh},</if>
            <if test="fplxdm != null">fplxdm = #{fplxdm},</if>
            <if test="cjksrq != null">cjksrq = #{cjksrq},</if>
            <if test="cjjsrq != null">cjjsrq = #{cjjsrq},</if>
            <if test="zhs != null">zhs = #{zhs},</if>
            <if test="dqskssq != null">dqskssq = #{dqskssq},</if>
            <if test="cjlx != null">cjlx = #{cjlx},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
        </trim>
        where pch = #{pch}
    </update>

    <delete id="deleteCollectRecordById" parameterType="int">
        delete from cjjlb where pch = #{pch}
    </delete>

    <delete id="deleteCollectRecordByIds" parameterType="String">
        delete from cjjlb where pch in 
        <foreach item="pch" collection="array" open="(" separator="," close=")">
            #{pch}
        </foreach>
    </delete>
    
</mapper>