<?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.cftech.pay.dao.PayRecordMapper">

    <resultMap id="resultMap" type="com.cftech.pay.model.PayRecord">
                                    <id column="id" property="id"/>
                                                <result column="srcid" property="srcid"/>
                                                <result column="srctype" property="srctype"/>
                                                <result column="mch_id" property="mch_id"/>
                                                <result column="err_code" property="err_code"/>
                                                <result column="err_code_des" property="err_code_des"/>
                                                <result column="openid" property="openid"/>
                                                <result column="trade_type" property="trade_type"/>
                                                <result column="is_subscribe" property="is_subscribe"/>
                                                <result column="bank_type" property="bank_type"/>
                                                <result column="total_fee" property="total_fee"/>
                                                <result column="fee_type" property="fee_type"/>
                                                <result column="cash_fee" property="cash_fee"/>
                                                <result column="cash_fee_type" property="cash_fee_type"/>
                                                <result column="transaction_id" property="transaction_id"/>
                                                <result column="out_trade_no" property="out_trade_no"/>
                                                <result column="attach" property="attach"/>
                                                <result column="time_end" property="time_end"/>
                                                <result column="accounts_id" property="accountsId"/>
                                                <result column="del_flag" property="delFlag"/>
                                                <result column="status" property="status"/>
                                                <result column="create_time" property="createTime"/>
                                                <result column="update_time" property="updateTime"/>
                                                <result column="description" property="description"/>
                                                <result column="create_by" property="createBy"/>
                                                <result column="update_by" property="updateBy"/>
                        </resultMap>

    <sql id="sqlWhere">
        <if test="conds!=null">
            <trim prefix="WHERE" prefixOverrides="AND|OR">
                <foreach collection="conds.conds" index="index" item="cond">
                    ${cond.linkType}
                    <if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
                    <if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
                    <if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
                    <if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
                    <if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
                    <if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
                    <if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND
                        #{cond.endValue}
                    </if>
                    <if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
                    <if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
                    <if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
                    <if test="cond.condType == 'IN'">${cond.param} IN
                        <foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
                            #{item}
                        </foreach>
                    </if>
                </foreach>
            </trim>
        </if>
    </sql>

    <sql id="sqlColumns">
                                    id,
                                                srcid,
                                                srctype,
                                                mch_id,
                                                err_code,
                                                err_code_des,
                                                openid,
                                                trade_type,
                                                is_subscribe,
                                                bank_type,
                                                total_fee,
                                                fee_type,
                                                cash_fee,
                                                cash_fee_type,
                                                transaction_id,
                                                out_trade_no,
                                                attach,
                                                time_end,
                                                accounts_id,
                                                del_flag,
                                                status,
                                                create_time,
                                                update_time,
                                                description,
                                                create_by,
                                                update_by
                        </sql>

    
    <insert id="save" parameterType="com.cftech.pay.model.PayRecord" useGeneratedKeys="true"
            keyProperty="id">
        insert into t_pay_record
        (
        <include refid="sqlColumns"/>
        )
        values
        (
                                                        #{id, jdbcType=BIGINT},
                                                                                    #{srcid, jdbcType=VARCHAR},
                                                                                    #{srctype, jdbcType=VARCHAR},
                                                                                    #{mch_id, jdbcType=VARCHAR},
                                                                                    #{err_code, jdbcType=VARCHAR},
                                                                                    #{err_code_des, jdbcType=VARCHAR},
                                                                                    #{openid, jdbcType=VARCHAR},
                                                                                    #{trade_type, jdbcType=VARCHAR},
                                                                                    #{is_subscribe, jdbcType=VARCHAR},
                                                                                    #{bank_type, jdbcType=VARCHAR},
                                                                                    #{total_fee, jdbcType=VARCHAR},
                                                                                    #{fee_type, jdbcType=VARCHAR},
                                                                                    #{cash_fee, jdbcType=VARCHAR},
                                                                                    #{cash_fee_type, jdbcType=VARCHAR},
                                                                                    #{transaction_id, jdbcType=VARCHAR},
                                                                                    #{out_trade_no, jdbcType=VARCHAR},
                                                                                    #{attach, jdbcType=CLOB},
                                                                                    now(),
                                                                                    #{accountsId, jdbcType=BIGINT},
                                                                                    #{delFlag, jdbcType=TINYINT},
                                                                                    #{status, jdbcType=VARCHAR},
                                                                                    now(),
                                                                                    now(),
                                                                                    #{description, jdbcType=VARCHAR},
                                                                                    #{createBy, jdbcType=BIGINT},
                                                                                    #{updateBy, jdbcType=BIGINT}
                                            )
    </insert>

    <select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
        SELECT
        <include refid="sqlColumns"/>
        FROM t_pay_record t
        WHERE t.id=#{id}
    </select>

    <select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
                    SELECT COUNT(1) FROM t_pay_record
            <include refid="sqlWhere"/>
        
    </select>

    <select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
                    SELECT
            <include refid="sqlColumns"/>
            FROM t_pay_record
            <include refid="sqlWhere"/>
                <if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
        <if test="limit>0">limit #{offset},#{limit}</if>
    </select>

    <update id="update" parameterType="com.cftech.pay.model.PayRecord">
        update t_pay_record
        <set>
                                                <if test="id != null">
                        id = #{id, jdbcType=BIGINT},
                    </if>
                                                                <if test="srcid != null">
                        srcid = #{srcid, jdbcType=VARCHAR},
                    </if>
                                                                <if test="srctype != null">
                        srctype = #{srctype, jdbcType=VARCHAR},
                    </if>
                                                                <if test="mch_id != null">
                        mch_id = #{mch_id, jdbcType=VARCHAR},
                    </if>
                                                                <if test="err_code != null">
                        err_code = #{err_code, jdbcType=VARCHAR},
                    </if>
                                                                <if test="err_code_des != null">
                        err_code_des = #{err_code_des, jdbcType=VARCHAR},
                    </if>
                                                                <if test="openid != null">
                        openid = #{openid, jdbcType=VARCHAR},
                    </if>
                                                                <if test="trade_type != null">
                        trade_type = #{trade_type, jdbcType=VARCHAR},
                    </if>
                                                                <if test="is_subscribe != null">
                        is_subscribe = #{is_subscribe, jdbcType=VARCHAR},
                    </if>
                                                                <if test="bank_type != null">
                        bank_type = #{bank_type, jdbcType=VARCHAR},
                    </if>
                                                                <if test="total_fee != null">
                        total_fee = #{total_fee, jdbcType=VARCHAR},
                    </if>
                                                                <if test="fee_type != null">
                        fee_type = #{fee_type, jdbcType=VARCHAR},
                    </if>
                                                                <if test="cash_fee != null">
                        cash_fee = #{cash_fee, jdbcType=VARCHAR},
                    </if>
                                                                <if test="cash_fee_type != null">
                        cash_fee_type = #{cash_fee_type, jdbcType=VARCHAR},
                    </if>
                                                                <if test="transaction_id != null">
                        transaction_id = #{transaction_id, jdbcType=VARCHAR},
                    </if>
                                                                <if test="out_trade_no != null">
                        out_trade_no = #{out_trade_no, jdbcType=VARCHAR},
                    </if>
                                                                <if test="attach != null">
                        attach = #{attach, jdbcType=CLOB},
                    </if>
                                                                <if test="time_end != null">
                        time_end = #{time_end, jdbcType=TIMESTAMP},
                    </if>
                                                                <if test="accountsId != null">
                        accounts_id = #{accountsId, jdbcType=BIGINT},
                    </if>
                                                                <if test="delFlag != null">
                        del_flag = #{delFlag, jdbcType=TINYINT},
                    </if>
                                                                <if test="status != null">
                        status = #{status, jdbcType=VARCHAR},
                    </if>
                                                                <if test="createTime != null">
                        create_time = #{createTime, jdbcType=TIMESTAMP},
                    </if>
                                                                                                            <if test="description != null">
                        description = #{description, jdbcType=VARCHAR},
                    </if>
                                                                <if test="createBy != null">
                        create_by = #{createBy, jdbcType=BIGINT},
                    </if>
                                                                <if test="updateBy != null">
                        update_by = #{updateBy, jdbcType=BIGINT},
                    </if>
                                    </set>
        where id=#{id,jdbcType=BIGINT}
    </update>

    <update id="delete" parameterType="java.lang.Long">
        update t_pay_record set del_flag=1 where id=#{id,jdbcType=BIGINT}
    </update>
</mapper>