<?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.xhpc.payment.mapper.XhpcSettingConfigMapper">

    <resultMap type="com.xhpc.common.domain.XhpcSettingConfig" id="XhpcSettingConfigResult">
        <result column="setting_config_id" property="settingConfigId"/>
        <result column="wx_app_id" property="wxAppId"/>
        <result column="wx_app_secret" property="wxAppSecret"/>
        <result column="wx_mch_id" property="wxMchId"/>
        <result column="wx_mch_key" property="wxMchKey"/>
        <result column="wx_payment_url" property="wxPaymentUrl"/>
        <result column="wx_callback_url" property="wxCallbackUrl"/>
        <result column="wx_transfers_url" property="wxTransfersUrl"/>
        <result column="wx_apiclient_cert_pem" property="wxApiclientCertPem"/>
        <result column="wx_apiclient_key_pem" property="wxApiclientKeyPem"/>
        <result column="wx_app_cert_public_key" property="wxAppCertPublicKey"/>
        <result column="zfb_app_id" property="zfbAppId"/>
        <result column="zfb_private_key" property="zfbPrivateKey"/>
        <result column="zfb_callback_url" property="zfbCallbackUrl"/>
        <result column="zfb_app_cert_public_key" property="zfbAppCertPublicKey"/>
        <result column="zfb_alipay_cert_public_key_rsa" property="zfbAlipayCertPublicKeyRsa" />
        <result column="zfb_alipay_root_cert" property="zfbAlipayRootCert" />
        <result column="zhb_server_url" property="zhbServerUrl" />
        <result column="status" property="status" />
        <result column="del_flag" property="delFlag" />
        <result column="tenant_id" property="tenantId" />
    </resultMap>

    <insert id="insertXhpcSettingConfig" parameterType="com.xhpc.common.domain.XhpcSettingConfig" useGeneratedKeys="true"
            keyProperty="settingConfigId">
        INSERT INTO xhpc_setting_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="null != wxAppId and '' != wxAppId">
                wx_app_id,
            </if>
            <if test="null != wxAppSecret and '' != wxAppSecret">
                wx_app_secret,
            </if>
            <if test="null != wxMchId and '' != wxMchId">
                wx_mch_id,
            </if>
            <if test="null != wxMchKey and '' != wxMchKey">
                wx_mch_key,
            </if>
            <if test="null != wxPaymentUrl and '' != wxPaymentUrl">
                wx_payment_url,
            </if>
            <if test="null != wxCallbackUrl and '' != wxCallbackUrl">
                wx_callback_url,
            </if>
            <if test="null != wxTransfersUrl and '' != wxTransfersUrl">
                wx_transfers_url,
            </if>
            <if test="null != wxApiclientCertPem and '' != wxApiclientCertPem">
                wx_apiclient_cert_pem,
            </if>
            <if test="null != wxApiclientKeyPem and '' != wxApiclientKeyPem">
                wx_apiclient_key_pem,
            </if>
            <if test="null != wxAppCertPublicKey and ''!=wxAppCertPublicKey">
                wx_app_cert_public_key,
            </if>
            <if test="null != zfbAppId and '' != zfbAppId">
                zfb_app_id,
            </if>
            <if test="null != zfbPrivateKey and '' !=zfbPrivateKey">
                zfb_private_key,
            </if>
            <if test="null != zfbCallbackUrl and '' != zfbCallbackUrl">
                zfb_callback_url,
            </if>
            <if test="null != zfbAppCertPublicKey and '' != zfbAppCertPublicKey">
                zfb_app_cert_public_key,
            </if>
            <if test="null != zfbAlipayCertPublicKeyRsa and ''!=zfbAlipayCertPublicKeyRsa">
                zfb_alipay_cert_public_key_rsa,
            </if>
            <if test="null != zfbAlipayRootCert and ''!=zfbAlipayRootCert">
                zfb_alipay_root_cert,
            </if>
            <if test="null != zhbServerUrl and ''!=zhbServerUrl">
                zhb_server_url,
            </if>
            <if test="null != status">
                status,
            </if>
            <if test="null != tenantId and ''!=tenantId">
                tenant_id,
            </if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="null != wxAppId and '' != wxAppId">
                #{wxAppId},
            </if>
            <if test="null != wxAppSecret and '' != wxAppSecret">
                #{wxAppSecret},
            </if>
            <if test="null != wxMchId and '' != wxMchId">
                #{wxMchId},
            </if>
            <if test="null != wxMchKey and '' != wxMchKey">
                #{wxMchKey},
            </if>
            <if test="null != wxPaymentUrl and '' != wxPaymentUrl">
                #{wxPaymentUrl},
            </if>
            <if test="null != wxCallbackUrl and '' != wxCallbackUrl">
                #{wxCallbackUrl},
            </if>
            <if test="null != wxTransfersUrl and '' != wxTransfersUrl">
                #{wxTransfersUrl},
            </if>
            <if test="null != wxApiclientCertPem and '' != wxApiclientCertPem">
                #{wxApiclientCertPem},
            </if>
            <if test="null != wxApiclientKeyPem and '' != wxApiclientKeyPem">
                #{wxApiclientKeyPem},
            </if>
            <if test="null != wxAppCertPublicKey and ''!=wxAppCertPublicKey">
                #{wxAppCertPublicKey},
            </if>
            <if test="null != zfbAppId and '' != zfbAppId">
                #{zfbAppId},
            </if>
            <if test="null != zfbPrivateKey and '' !=zfbPrivateKey">
                #{zfbPrivateKey},
            </if>
            <if test="null != zfbCallbackUrl and '' != zfbCallbackUrl">
                #{zfbCallbackUrl},
            </if>
            <if test="null != zfbAppCertPublicKey and '' != zfbAppCertPublicKey">
                #{zfbAppCertPublicKey},
            </if>
            <if test="null != zfbAlipayCertPublicKeyRsa and ''!=zfbAlipayCertPublicKeyRsa">
                #{zfbAlipayCertPublicKeyRsa},
            </if>
            <if test="null != zfbAlipayRootCert and ''!=zfbAlipayRootCert">
                #{zfbAlipayRootCert},
            </if>
            <if test="null != zhbServerUrl and ''!=zhbServerUrl">
                #{zhbServerUrl},
            </if>
            <if test="null != status">
                #{status},
            </if>
            <if test="null != tenantId and ''!=tenantId">
                #{tenantId},
            </if>
        </trim>
    </insert>

    <update id="updateXhpcSettingConfig" parameterType="com.xhpc.common.domain.XhpcSettingConfig">
        UPDATE xhpc_setting_config
        <set>
            <if test="null != wxAppId and '' != wxAppId">
                wx_app_id =#{wxAppId},
            </if>
            <if test="null != wxAppSecret and '' != wxAppSecret">
                wx_app_secret =#{wxAppSecret},
            </if>
            <if test="null != wxMchId and '' != wxMchId">
                wx_mch_id =#{wxMchId},
            </if>
            <if test="null != wxMchKey and '' != wxMchKey">
                wx_mch_key =#{wxMchKey},
            </if>
            <if test="null != wxPaymentUrl and '' != wxPaymentUrl">
                wx_payment_url =#{wxPaymentUrl},
            </if>
            <if test="null != wxCallbackUrl and '' != wxCallbackUrl">
                wx_callback_url =#{wxCallbackUrl},
            </if>
            <if test="null != wxTransfersUrl and '' != wxTransfersUrl">
                wx_transfers_url =#{wxTransfersUrl},
            </if>
            <if test="null != wxApiclientCertPem and '' != wxApiclientCertPem">
                wx_apiclient_cert_pem =#{wxApiclientCertPem},
            </if>
            <if test="null != wxApiclientKeyPem and '' != wxApiclientKeyPem">
                wx_apiclient_key_pem = #{wxApiclientKeyPem},
            </if>
            <if test="null != wxAppCertPublicKey and ''!=wxAppCertPublicKey">
                wx_app_cert_public_key =#{wxAppCertPublicKey},
            </if>
            <if test="null != zfbAppId and '' != zfbAppId">
                zfb_app_id =#{zfbAppId},
            </if>
            <if test="null != zfbPrivateKey and '' !=zfbPrivateKey">
                zfb_private_key =#{zfbPrivateKey},
            </if>
            <if test="null != zfbCallbackUrl and '' != zfbCallbackUrl">
                zfb_callback_url =#{zfbCallbackUrl},
            </if>
            <if test="null != zfbAppCertPublicKey and '' != zfbAppCertPublicKey">
                zfb_app_cert_public_key =#{zfbAppCertPublicKey},
            </if>
            <if test="null != zfbAlipayCertPublicKeyRsa and ''!=zfbAlipayCertPublicKeyRsa">
                zfb_alipay_cert_public_key_rsa =#{zfbAlipayCertPublicKeyRsa},
            </if>
            <if test="null != zfbAlipayRootCert and ''!=zfbAlipayRootCert">
                zfb_alipay_root_cert =#{zfbAlipayRootCert},
            </if>
            <if test="null != zhbServerUrl and ''!=zhbServerUrl">
                zhb_server_url =#{zhbServerUrl},
            </if>
            <if test="null != status">
                status =#{status},
            </if>
            <if test="null != tenantId and ''!=tenantId">
                tenant_id =#{tenantId},
            </if>
        </set>
        WHERE setting_config_id = #{settingConfigId}
    </update>

    <select id="getXhpcSettingConfigStatus" resultType="java.util.Map">
       select
           setting_config_id as settingConfigId,
            <if test="status==1">
                wx_app_id as wxAppId,
                wx_app_secret as wxAppSecret,
                wx_mch_id as wxMchId,
                wx_mch_key as wxMchKey,
                wx_payment_url as wxPaymentUrl,
                wx_callback_url as wxCallbackUrl,
                wx_transfers_url as wxTransfersUrl,
                wx_apiclient_cert_pem as wxApiclientCertPem,
                wx_apiclient_key_pem as wxApiclientKeyPem,
                wx_app_cert_public_key as wxAppCertPublicKey,
            </if>
            <if test="status==2">
                zfb_app_id as zfbAppId,
                zfb_private_key as zfbPrivateKey,
                zfb_callback_url as zfbCallbackUrl,
                zfb_app_cert_public_key as zfbAppCertPublicKey,
                zfb_alipay_cert_public_key_rsa as zfbAlipayCertPublicKeyRsa,
                zfb_alipay_root_cert as zfbAlipayRootCert,
                zhb_server_url as zhbServerUrl,
            </if>
           status as status,
           del_flag as delFlag,
           tenant_id as tenantId
        from xhpc_setting_config
        where del_flag = 0 and status = #{status} and tenant_id=#{tenantId}
    </select>


</mapper> 