<?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.fastbee.rechargecard.mapper.NgMerchantsMapper">

    <resultMap type="NgMerchants" id="NgMerchantsResult">
        <result property="id"    column="id"    />
        <result property="mchId"    column="mch_id"    />
        <result property="privateKeyPath"    column="private_key_path"    />
        <result property="serialNo"    column="serial_no"    />
        <result property="apiV3Key"    column="api_v3_key"    />
        <result property="publicKeyPath"    column="public_key_path"    />
        <result property="deptId"    column="dept_id"    />
        <result property="platformCertificates"    column="platform_certificates"    />
        <result property="wechatPublicKeyId"    column="wechat_public_key_id"    />
        <result property="platformCertificateSerialNumber"    column="platform_certificate_serial_number"    />
    </resultMap>

    <sql id="selectNgMerchantsVo">
        select id, mch_id, private_key_path, serial_no, api_v3_key, public_key_path, dept_id, platform_certificates, wechat_public_key_id, platform_certificate_serial_number from ng_merchants
    </sql>

    <select id="selectNgMerchantsList" parameterType="NgMerchants" resultMap="NgMerchantsResult">
        <include refid="selectNgMerchantsVo"/>
        <where>
            <if test="mchId != null  and mchId != ''"> and mch_id = #{mchId}</if>
            <if test="privateKeyPath != null  and privateKeyPath != ''"> and private_key_path = #{privateKeyPath}</if>
            <if test="serialNo != null  and serialNo != ''"> and serial_no = #{serialNo}</if>
            <if test="apiV3Key != null  and apiV3Key != ''"> and api_v3_key = #{apiV3Key}</if>
            <if test="publicKeyPath != null  and publicKeyPath != ''"> and public_key_path = #{publicKeyPath}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="platformCertificates != null  and platformCertificates != ''"> and platform_certificates = #{platformCertificates}</if>
            <if test="wechatPublicKeyId != null "> and wechat_public_key_id = #{wechatPublicKeyId}</if>
            <if test="platformCertificateSerialNumber != null  and platformCertificateSerialNumber != ''"> and platform_certificate_serial_number = #{platformCertificateSerialNumber}</if>
        </where>
    </select>

    <select id="selectNgMerchantsById" parameterType="Long" resultMap="NgMerchantsResult">
        <include refid="selectNgMerchantsVo"/>
        where id = #{id}
    </select>

    <insert id="insertNgMerchants" parameterType="NgMerchants" useGeneratedKeys="true" keyProperty="id">
        insert into ng_merchants
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mchId != null">mch_id,</if>
            <if test="privateKeyPath != null">private_key_path,</if>
            <if test="serialNo != null">serial_no,</if>
            <if test="apiV3Key != null">api_v3_key,</if>
            <if test="publicKeyPath != null">public_key_path,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="platformCertificates != null">platform_certificates,</if>
            <if test="wechatPublicKeyId != null">wechat_public_key_id,</if>
            <if test="platformCertificateSerialNumber != null">platform_certificate_serial_number,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mchId != null">#{mchId},</if>
            <if test="privateKeyPath != null">#{privateKeyPath},</if>
            <if test="serialNo != null">#{serialNo},</if>
            <if test="apiV3Key != null">#{apiV3Key},</if>
            <if test="publicKeyPath != null">#{publicKeyPath},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="platformCertificates != null">#{platformCertificates},</if>
            <if test="wechatPublicKeyId != null">#{wechatPublicKeyId},</if>
            <if test="platformCertificateSerialNumber != null">#{platformCertificateSerialNumber},</if>
        </trim>
    </insert>

    <update id="updateNgMerchants" parameterType="NgMerchants">
        update ng_merchants
        <trim prefix="SET" suffixOverrides=",">
            <if test="mchId != null">mch_id = #{mchId},</if>
            <if test="privateKeyPath != null">private_key_path = #{privateKeyPath},</if>
            <if test="serialNo != null">serial_no = #{serialNo},</if>
            <if test="apiV3Key != null">api_v3_key = #{apiV3Key},</if>
            <if test="publicKeyPath != null">public_key_path = #{publicKeyPath},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="platformCertificates != null">platform_certificates = #{platformCertificates},</if>
            <if test="wechatPublicKeyId != null">wechat_public_key_id = #{wechatPublicKeyId},</if>
            <if test="platformCertificateSerialNumber != null">platform_certificate_serial_number = #{platformCertificateSerialNumber},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNgMerchantsById" parameterType="Long">
        delete from ng_merchants where id = #{id}
    </delete>

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