<?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.jsowell.thirdparty.mapper.ThirdpartySecretInfoMapper">

    <resultMap type="com.jsowell.thirdparty.domain.ThirdpartySecretInfo" id="ThirdpartySecretInfoResult">
        <result property="id"    column="id"    />
        <result property="platformName"    column="platform_name"    />
        <result property="platformType"    column="platform_type"    />
        <result property="urlPrefix"    column="url_prefix"    />
        <result property="theirOperatorId"    column="their_operator_id"    />
        <result property="theirOperatorSecret"    column="their_operator_secret"    />
        <result property="theirDataSecret"    column="their_data_secret"    />
        <result property="theirDataSecretIv"    column="their_data_secret_iv"    />
        <result property="theirSigSecret"    column="their_sig_secret"    />
        <result property="theirPublicSecret"    column="their_public_secret"    />
        <result property="theirPrivateSecret"    column="their_private_secret"    />
        <result property="ourOperatorSecret"    column="our_operator_secret"    />
        <result property="ourDataSecret"    column="our_data_secret"    />
        <result property="ourDataSecretIv"    column="our_data_secret_iv"    />
        <result property="ourSigSecret"    column="our_sig_secret"    />
        <result property="ourPublicSecret"    column="our_public_secret"    />
        <result property="ourPrivateSecret"    column="our_private_secret"    />
        <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"    />
    </resultMap>

    <sql id="Base_Column_List">
        id, platform_name, platform_type, url_prefix, their_operator_id, their_operator_secret, their_data_secret,
        their_data_secret_iv, their_sig_secret, their_public_secret, their_private_secret, our_operator_secret, our_data_secret, our_data_secret_iv,
        our_sig_secret, our_public_secret, our_private_secret, create_by, create_time, update_by, update_time, del_flag
    </sql>

    <sql id="selectThirdpartySecretInfoVo">
        select <include refid="Base_Column_List"/>
        from thirdparty_secret_info
    </sql>

    <select id="selectThirdpartySecretInfoList" parameterType="com.jsowell.thirdparty.domain.ThirdpartySecretInfo" resultMap="ThirdpartySecretInfoResult">
        <include refid="selectThirdpartySecretInfoVo"/>
        <where>
            <if test="platformName != null  and platformName != ''"> and platform_name like concat('%', #{platformName}, '%')</if>
            <if test="platformType != null  and platformType != ''"> and platform_type = #{platformType}</if>
            <if test="urlPrefix != null  and urlPrefix != ''"> and url_prefix = #{urlPrefix}</if>
            <if test="theirOperatorId != null  and theirOperatorId != ''"> and their_operator_id = #{theirOperatorId}</if>
            <if test="theirOperatorSecret != null  and theirOperatorSecret != ''"> and their_operator_secret = #{theirOperatorSecret}</if>
            <if test="theirDataSecret != null  and theirDataSecret != ''"> and their_data_secret = #{theirDataSecret}</if>
            <if test="theirDataSecretIv != null  and theirDataSecretIv != ''"> and their_data_secret_iv = #{theirDataSecretIv}</if>
            <if test="theirSigSecret != null  and theirSigSecret != ''"> and their_sig_secret = #{theirSigSecret}</if>
            <if test="theirPublicSecret != null  and theirPublicSecret != ''"> and their_public_secret = #{theirPublicSecret}</if>
            <if test="theirPrivateSecret != null  and theirPrivateSecret != ''"> and their_private_secret = #{theirPrivateSecret}</if>
            <if test="ourOperatorSecret != null  and ourOperatorSecret != ''"> and our_operator_secret = #{ourOperatorSecret}</if>
            <if test="ourDataSecret != null  and ourDataSecret != ''"> and our_data_secret = #{ourDataSecret}</if>
            <if test="ourDataSecretIv != null  and ourDataSecretIv != ''"> and our_data_secret_iv = #{ourDataSecretIv}</if>
            <if test="ourSigSecret != null  and ourSigSecret != ''"> and our_sig_secret = #{ourSigSecret}</if>
            <if test="ourPublicSecret != null  and ourPublicSecret != ''"> and our_public_secret = #{ourPublicSecret}</if>
            <if test="ourPrivateSecret != null  and ourPrivateSecret != ''"> and our_private_secret = #{ourPrivateSecret}</if>
        </where>
    </select>

    <select id="selectThirdpartySecretInfoById" parameterType="Long" resultMap="ThirdpartySecretInfoResult">
        <include refid="selectThirdpartySecretInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertThirdpartySecretInfo" parameterType="com.jsowell.thirdparty.domain.ThirdpartySecretInfo" useGeneratedKeys="true" keyProperty="id">
        insert into thirdparty_secret_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="platformName != null">platform_name,</if>
            <if test="platformType != null">platform_type,</if>
            <if test="urlPrefix != null">url_prefix,</if>
            <if test="theirOperatorId != null">their_operator_id,</if>
            <if test="theirOperatorSecret != null">their_operator_secret,</if>
            <if test="theirDataSecret != null">their_data_secret,</if>
            <if test="theirDataSecretIv != null">their_data_secret_iv,</if>
            <if test="theirSigSecret != null">their_sig_secret,</if>
            <if test="theirPublicSecret != null">their_public_secret,</if>
            <if test="theirPrivateSecret != null">their_private_secret,</if>
            <if test="ourOperatorSecret != null">our_operator_secret,</if>
            <if test="ourDataSecret != null">our_data_secret,</if>
            <if test="ourDataSecretIv != null">our_data_secret_iv,</if>
            <if test="ourSigSecret != null">our_sig_secret,</if>
            <if test="ourPublicSecret != null">our_public_secret,</if>
            <if test="ourPrivateSecret != null">our_private_secret,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="platformName != null">#{platformName},</if>
            <if test="platformType != null">#{platformType},</if>
            <if test="urlPrefix != null">#{urlPrefix},</if>
            <if test="theirOperatorId != null">#{theirOperatorId},</if>
            <if test="theirOperatorSecret != null">#{theirOperatorSecret},</if>
            <if test="theirDataSecret != null">#{theirDataSecret},</if>
            <if test="theirDataSecretIv != null">#{theirDataSecretIv},</if>
            <if test="theirSigSecret != null">#{theirSigSecret},</if>
            <if test="theirPublicSecret != null">#{theirPublicSecret},</if>
            <if test="theirPrivateSecret != null">#{theirPrivateSecret},</if>
            <if test="ourOperatorSecret != null">#{ourOperatorSecret},</if>
            <if test="ourDataSecret != null">#{ourDataSecret},</if>
            <if test="ourDataSecretIv != null">#{ourDataSecretIv},</if>
            <if test="ourSigSecret != null">#{ourSigSecret},</if>
            <if test="ourPublicSecret != null">#{ourPublicSecret},</if>
            <if test="ourPrivateSecret != null">#{ourPrivateSecret},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateThirdpartySecretInfo" parameterType="com.jsowell.thirdparty.domain.ThirdpartySecretInfo">
        update thirdparty_secret_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="platformName != null">platform_name = #{platformName},</if>
            <if test="platformType != null">platform_type = #{platformType},</if>
            <if test="urlPrefix != null">url_prefix = #{urlPrefix},</if>
            <if test="theirOperatorId != null">their_operator_id = #{theirOperatorId},</if>
            <if test="theirOperatorSecret != null">their_operator_secret = #{theirOperatorSecret},</if>
            <if test="theirDataSecret != null">their_data_secret = #{theirDataSecret},</if>
            <if test="theirDataSecretIv != null">their_data_secret_iv = #{theirDataSecretIv},</if>
            <if test="theirSigSecret != null">their_sig_secret = #{theirSigSecret},</if>
            <if test="theirPublicSecret != null">their_public_secret = #{theirPublicSecret},</if>
            <if test="theirPrivateSecret != null">their_private_secret = #{theirPrivateSecret},</if>
            <if test="ourOperatorSecret != null">our_operator_secret = #{ourOperatorSecret},</if>
            <if test="ourDataSecret != null">our_data_secret = #{ourDataSecret},</if>
            <if test="ourDataSecretIv != null">our_data_secret_iv = #{ourDataSecretIv},</if>
            <if test="ourSigSecret != null">our_sig_secret = #{ourSigSecret},</if>
            <if test="ourPublicSecret != null">our_public_secret = #{ourPublicSecret},</if>
            <if test="ourPrivateSecret != null">our_private_secret = #{ourPrivateSecret},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteThirdpartySecretInfoById" parameterType="Long">
        delete from thirdparty_secret_info where id = #{id}
    </delete>

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

    <select id="queryByOperatorId" resultType="com.jsowell.pile.vo.ThirdPartySecretInfoVO">
        select
            t1.platform_name as platformName,
            t1.platform_type as platformType,
            t1.their_operator_id as theirOperatorId,
            t1.their_operator_secret as theirOperatorSecret,
            t1.their_data_secret as theirDataSecret,
            t1.their_data_secret_iv as theirDataSecretIv,
            t1.their_sig_secret as theirSigSecret,
            t1.url_prefix as theirUrlPrefix,
            t1.their_public_secret as theirPublicSecret,
            t1.their_private_secret as theirPrivateSecret,
            t1.our_operator_secret as ourOperatorSecret,
            t1.our_data_secret as ourDataSecret,
            t1.our_data_secret_iv as ourDataSecretIv,
            t1.our_public_secret as ourPublicSecret,
            t1.our_private_secret as ourPrivateSecret,
            t1.our_sig_secret as ourSigSecret
        from thirdparty_secret_info t1
        where t1.del_flag = '0'
        and t1.their_operator_id = #{theirOperatorId,jdbcType=VARCHAR}
    </select>

    <select id="queryByThirdPlatformType" resultType="com.jsowell.pile.vo.ThirdPartySecretInfoVO">
        select
            t1.platform_name as platformName,
            t1.platform_type as platformType,
            t1.their_operator_id as theirOperatorId,
            t1.their_operator_secret as theirOperatorSecret,
            t1.their_data_secret as theirDataSecret,
            t1.their_data_secret_iv as theirDataSecretIv,
            t1.their_sig_secret as theirSigSecret,
            t1.url_prefix as theirUrlPrefix,
            t1.their_public_secret as theirPublicSecret,
            t1.their_private_secret as theirPrivateSecret,
            t1.our_operator_secret as ourOperatorSecret,
            t1.our_data_secret as ourDataSecret,
            t1.our_data_secret_iv as ourDataSecretIv,
            t1.our_public_secret as ourPublicSecret,
            t1.our_private_secret as ourPrivateSecret,
            t1.our_sig_secret as ourSigSecret
        from thirdparty_secret_info t1
        where t1.del_flag = '0'
        and t1.platform_type = #{thirdPlatformType,jdbcType=VARCHAR}
    </select>

    <select id="queryStationToPlatformList" resultType="com.jsowell.pile.vo.ThirdPartySecretInfoVO">
        select
            t1.platform_name as platformName,
            t1.platform_type as platformType,
            t1.their_operator_id as theirOperatorId,
            t1.their_operator_secret as theirOperatorSecret,
            t1.their_data_secret as theirDataSecret,
            t1.their_data_secret_iv as theirDataSecretIv,
            t1.their_sig_secret as theirSigSecret,
            t1.url_prefix as theirUrlPrefix,
            t1.their_public_secret as theirPublicSecret,
            t1.their_private_secret as theirPrivateSecret,
            t1.our_operator_secret as ourOperatorSecret,
            t1.our_data_secret as ourDataSecret,
            t1.our_data_secret_iv as ourDataSecretIv,
            t1.our_public_secret as ourPublicSecret,
            t1.our_private_secret as ourPrivateSecret,
            t1.our_sig_secret as ourSigSecret
        from thirdparty_secret_info t1
        left join thirdparty_station_relation t2 on t2.third_party_type = t1.platform_type and t2.del_flag = '0'
        where t1.del_flag = '0'
        and t2.station_id = #{stationId,jdbcType=VARCHAR}
    </select>
</mapper>