<?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.lz.modules.third.dao.ThirdAppConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.third.entity.ThirdAppConfig">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="app_id" property="appId"/>
        <result column="app_key" property="appKey"/>
        <result column="app_secret" property="appSecret"/>
        <result column="app_name" property="appName"/>
        <result column="app_type" property="appType"/>
        <result column="third_app_name" property="thirdAppName"/>
        <result column="app_url" property="appUrl"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, app_id AS appId, app_key AS appKey, app_secret AS appSecret, app_name AS appName, app_type AS appType, third_app_name AS thirdAppName, app_url AS appUrl
    </sql>




    <select id="selectThirdAppConfigById" resultType="com.lz.modules.third.entity.ThirdAppConfig" >
        select * from third_app_config  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertThirdAppConfig" parameterType="com.lz.modules.third.entity.ThirdAppConfig" useGeneratedKeys="true" keyProperty="id" >
        insert into third_app_config(
            <if test="appId != null">app_id, </if>
            <if test="appKey != null">app_key, </if>
            <if test="appSecret != null">app_secret, </if>
            <if test="appName != null">app_name, </if>
            <if test="appType != null">app_type, </if>
            <if test="thirdAppName != null">third_app_name, </if>
            <if test="appUrl != null">app_url, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="appId != null">#{ appId}, </if>
            <if test="appKey != null">#{ appKey}, </if>
            <if test="appSecret != null">#{ appSecret}, </if>
            <if test="appName != null">#{ appName}, </if>
            <if test="appType != null">#{ appType}, </if>
            <if test="thirdAppName != null">#{ thirdAppName}, </if>
            <if test="appUrl != null">#{ appUrl}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateThirdAppConfigById" parameterType="com.lz.modules.third.entity.ThirdAppConfig" >
        update
            third_app_config
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="appId != null">app_id = #{appId},</if>
            <if test="appKey != null">app_key = #{appKey},</if>
            <if test="appSecret != null">app_secret = #{appSecret},</if>
            <if test="appName != null">app_name = #{appName},</if>
            <if test="appType != null">app_type = #{appType},</if>
            <if test="thirdAppName != null">third_app_name = #{thirdAppName},</if>
            <if test="appUrl != null">app_url = #{appUrl}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverThirdAppConfigById" parameterType="com.lz.modules.third.entity.ThirdAppConfig" >
        update
            third_app_config    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            app_id = #{appId},
            app_key = #{appKey},
            app_secret = #{appSecret},
            app_name = #{appName},
            app_type = #{appType},
            third_app_name = #{thirdAppName},
            app_url = #{appUrl}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteThirdAppConfigById" parameterType="java.lang.Long">
        update third_app_config set is_delete = 1 where id=#{id} limit 1  
    </update>

    <select id="getByAppId" resultType="com.lz.modules.third.entity.ThirdAppConfig" >
        select * from third_app_config  where app_id=#{appid} and is_delete = 0 limit 1
    </select>

</mapper>

