<?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.qw.mapper.QwCompanyMapper">
    
    <resultMap type="QwCompany" id="QwCompanyResult">
        <result property="id"    column="id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="corpName"    column="corp_name"    />
        <result property="openSecret"    column="open_secret"    />
        <result property="openCorpId"    column="open_corp_id"    />
        <result property="serverAgentId"    column="server_agent_id"    />
        <result property="serverBookCorpId"    column="server_book_corp_id"    />
        <result property="serverBookSecret"    column="server_book_secret"    />
        <result property="token"    column="token"    />
        <result property="encodingAesKey"    column="encoding_aes_key"    />
        <result property="providerSecret"    column="provider_secret"    />
        <result property="realmNameUrl"    column="realm_name_url"    />
        <result property="notifyUrl"    column="notify_url"    />
        <result property="chatToolbar"    column="chat_toolbar"    />
        <result property="chatToolbarOauth"    column="chat_toolbar_oauth"    />
        <result property="companyIds"    column="company_ids"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="isBuy"    column="is_buy"    />
    </resultMap>

    <sql id="selectQwCompanyVo">
        select id, corp_id, corp_name, open_secret, open_corp_id, server_agent_id, server_book_corp_id, server_book_secret, token, encoding_aes_key, provider_secret, realm_name_url, notify_url, chat_toolbar, chat_toolbar_oauth, company_ids, status, create_time, update_time, create_by,is_buy from qw_company
    </sql>

    <select id="selectQwCompanyList" parameterType="QwCompany" resultMap="QwCompanyResult">
        <include refid="selectQwCompanyVo"/>
        <where>  
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="corpName != null  and corpName != ''"> and corp_name like concat('%', #{corpName}, '%')</if>
            <if test="openSecret != null  and openSecret != ''"> and open_secret = #{openSecret}</if>
            <if test="openCorpId != null  and openCorpId != ''"> and open_corp_id = #{openCorpId}</if>
            <if test="serverAgentId != null  and serverAgentId != ''"> and server_agent_id = #{serverAgentId}</if>
            <if test="serverBookCorpId != null  and serverBookCorpId != ''"> and server_book_corp_id = #{serverBookCorpId}</if>
            <if test="serverBookSecret != null  and serverBookSecret != ''"> and server_book_secret = #{serverBookSecret}</if>
            <if test="token != null  and token != ''"> and token = #{token}</if>
            <if test="encodingAesKey != null  and encodingAesKey != ''"> and encoding_aes_key = #{encodingAesKey}</if>
            <if test="providerSecret != null  and providerSecret != ''"> and provider_secret = #{providerSecret}</if>
            <if test="realmNameUrl != null  and realmNameUrl != ''"> and realm_name_url = #{realmNameUrl}</if>
            <if test="notifyUrl != null  and notifyUrl != ''"> and notify_url = #{notifyUrl}</if>
            <if test="chatToolbar != null  and chatToolbar != ''"> and chat_toolbar = #{chatToolbar}</if>
            <if test="chatToolbarOauth != null  and chatToolbarOauth != ''"> and chat_toolbar_oauth = #{chatToolbarOauth}</if>
            <if test="companyIds != null  and companyIds != ''"> and company_ids = #{companyIds}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isBuy != null "> and isBuy = #{isBuy}</if>
        </where>
    </select>
    
    <select id="selectQwCompanyById" parameterType="Long" resultMap="QwCompanyResult">
        <include refid="selectQwCompanyVo"/>
        where id = #{id}
    </select>

    <select id="selectQwCompanyByCropID" parameterType="String" resultMap="QwCompanyResult">
        <include refid="selectQwCompanyVo"/>
        where corp_id = #{corpId}
    </select>


    <insert id="insertQwCompany" parameterType="QwCompany" useGeneratedKeys="true" keyProperty="id">
        insert into qw_company
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="corpId != null">corp_id,</if>
            <if test="corpName != null">corp_name,</if>
            <if test="openSecret != null">open_secret,</if>
            <if test="openCorpId != null">open_corp_id,</if>
            <if test="serverAgentId != null">server_agent_id,</if>
            <if test="serverBookCorpId != null">server_book_corp_id,</if>
            <if test="serverBookSecret != null">server_book_secret,</if>
            <if test="token != null">token,</if>
            <if test="encodingAesKey != null">encoding_aes_key,</if>
            <if test="providerSecret != null">provider_secret,</if>
            <if test="realmNameUrl != null">realm_name_url,</if>
            <if test="notifyUrl != null">notify_url,</if>
            <if test="chatToolbar != null">chat_toolbar,</if>
            <if test="chatToolbarOauth != null">chat_toolbar_oauth,</if>
            <if test="companyIds != null">company_ids,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="isBuy != null">is_buy,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="corpId != null">#{corpId},</if>
            <if test="corpName != null">#{corpName},</if>
            <if test="openSecret != null">#{openSecret},</if>
            <if test="openCorpId != null">#{openCorpId},</if>
            <if test="serverAgentId != null">#{serverAgentId},</if>
            <if test="serverBookCorpId != null">#{serverBookCorpId},</if>
            <if test="serverBookSecret != null">#{serverBookSecret},</if>
            <if test="token != null">#{token},</if>
            <if test="encodingAesKey != null">#{encodingAesKey},</if>
            <if test="providerSecret != null">#{providerSecret},</if>
            <if test="realmNameUrl != null">#{realmNameUrl},</if>
            <if test="notifyUrl != null">#{notifyUrl},</if>
            <if test="chatToolbar != null">#{chatToolbar},</if>
            <if test="chatToolbarOauth != null">#{chatToolbarOauth},</if>
            <if test="companyIds != null">#{companyIds},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="isBuy != null">#{isBuy},</if>
         </trim>
    </insert>

    <update id="updateQwCompany" parameterType="QwCompany">
        update qw_company
        <trim prefix="SET" suffixOverrides=",">
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="corpName != null">corp_name = #{corpName},</if>
            <if test="openSecret != null">open_secret = #{openSecret},</if>
            <if test="openCorpId != null">open_corp_id = #{openCorpId},</if>
            <if test="serverAgentId != null">server_agent_id = #{serverAgentId},</if>
            <if test="serverBookCorpId != null">server_book_corp_id = #{serverBookCorpId},</if>
            <if test="serverBookSecret != null">server_book_secret = #{serverBookSecret},</if>
            <if test="token != null">token = #{token},</if>
            <if test="encodingAesKey != null">encoding_aes_key = #{encodingAesKey},</if>
            <if test="providerSecret != null">provider_secret = #{providerSecret},</if>
            <if test="realmNameUrl != null">realm_name_url = #{realmNameUrl},</if>
            <if test="notifyUrl != null">notify_url = #{notifyUrl},</if>
            <if test="chatToolbar != null">chat_toolbar = #{chatToolbar},</if>
            <if test="chatToolbarOauth != null">chat_toolbar_oauth = #{chatToolbarOauth},</if>
            <if test="companyIds != null">company_ids = #{companyIds},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="isBuy != null">is_buy = #{isBuy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwCompanyById" parameterType="Long">
        delete from qw_company where id = #{id}
    </delete>

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