<?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.fs.qywx.mapper.QywxAppMapper">

    <resultMap type="QywxApp" id="QywxAppResult">
        <result property="id"    column="id"    />
        <result property="agentId"    column="agent_id"    />
        <result property="name"    column="name"    />
        <result property="shortName"    column="short_name"    />
        <result property="suiteId"    column="suite_id"    />
        <result property="suiteSecret"    column="suite_secret"    />
        <result property="suiteTicket"    column="suite_ticket"    />
        <result property="suiteAccessToken"    column="suite_access_token"    />
        <result property="expiresIn"    column="expires_in"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQywxAppVo">
        select id, agent_id, name, short_name, suite_id, suite_secret, suite_ticket, suite_access_token, expires_in, create_time, update_time from qywx_app
    </sql>

    <select id="selectQywxAppList" parameterType="QywxApp" resultMap="QywxAppResult">
        <include refid="selectQywxAppVo"/>
        <where>
            <if test="agentId != null "> and agent_id = #{agentId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="shortName != null  and shortName != ''"> and short_name = #{shortName}</if>
            <if test="suiteId != null  and suiteId != ''"> and suite_id = #{suiteId}</if>
            <if test="suiteSecret != null  and suiteSecret != ''"> and suite_secret = #{suiteSecret}</if>
            <if test="suiteTicket != null  and suiteTicket != ''"> and suite_ticket = #{suiteTicket}</if>
            <if test="suiteAccessToken != null  and suiteAccessToken != ''"> and suite_access_token = #{suiteAccessToken}</if>
            <if test="expiresIn != null "> and expires_in = #{expiresIn}</if>
        </where>
    </select>

    <select id="selectQywxAppById" parameterType="Long" resultMap="QywxAppResult">
        <include refid="selectQywxAppVo"/>
        where id = #{id}
    </select>

    <insert id="insertQywxApp" parameterType="QywxApp" useGeneratedKeys="true" keyProperty="id">
        insert into qywx_app
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="agentId != null">agent_id,</if>
            <if test="name != null">name,</if>
            <if test="shortName != null">short_name,</if>
            <if test="suiteId != null">suite_id,</if>
            <if test="suiteSecret != null">suite_secret,</if>
            <if test="suiteTicket != null">suite_ticket,</if>
            <if test="suiteAccessToken != null">suite_access_token,</if>
            <if test="expiresIn != null">expires_in,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="agentId != null">#{agentId},</if>
            <if test="name != null">#{name},</if>
            <if test="shortName != null">#{shortName},</if>
            <if test="suiteId != null">#{suiteId},</if>
            <if test="suiteSecret != null">#{suiteSecret},</if>
            <if test="suiteTicket != null">#{suiteTicket},</if>
            <if test="suiteAccessToken != null">#{suiteAccessToken},</if>
            <if test="expiresIn != null">#{expiresIn},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateQywxApp" parameterType="QywxApp">
        update qywx_app
        <trim prefix="SET" suffixOverrides=",">
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="shortName != null">short_name = #{shortName},</if>
            <if test="suiteId != null">suite_id = #{suiteId},</if>
            <if test="suiteSecret != null">suite_secret = #{suiteSecret},</if>
            <if test="suiteTicket != null">suite_ticket = #{suiteTicket},</if>
            <if test="suiteAccessToken != null">suite_access_token = #{suiteAccessToken},</if>
            <if test="expiresIn != null">expires_in = #{expiresIn},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQywxAppById" parameterType="Long">
        delete from qywx_app where id = #{id}
    </delete>

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