<?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.QywxCompanyMapper">

    <resultMap type="QywxCompany" id="QywxCompanyResult">
        <result property="id"    column="id"    />
        <result property="corpId"    column="corp_id"    />
        <result property="permanentCode"    column="permanent_code"    />
        <result property="corpName"    column="corp_name"    />
        <result property="corpFullName"    column="corp_full_name"    />
        <result property="subjectType"    column="subject_type"    />
        <result property="verifiedEndTime"    column="verified_end_time"    />
        <result property="companyId"    column="company_id"    />
        <result property="agentId"    column="agent_id"    />
        <result property="accessToken"    column="access_token"    />
        <result property="expiresIn"    column="expires_in"    />
        <result property="status"    column="status"    />
        <result property="docPrivateKey"    column="doc_private_key"    />
        <result property="docPublicKey"    column="doc_public_key"    />
        <result property="docPrivateSecret"    column="doc_private_secret"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQywxCompanyVo">
        select id, corp_id, permanent_code, corp_name, corp_full_name, subject_type, verified_end_time, agent_id,access_token,expires_in,company_id, status,doc_private_key,doc_public_key,doc_private_secret, create_time, update_time from qywx_company
    </sql>

    <select id="selectQywxCompanyList" parameterType="QywxCompany" resultMap="QywxCompanyResult">
        <include refid="selectQywxCompanyVo"/>
        <where>
            <if test="corpId != null  and corpId != ''"> and corp_id = #{corpId}</if>
            <if test="permanentCode != null  and permanentCode != ''"> and permanent_code = #{permanentCode}</if>
            <if test="corpName != null  and corpName != ''"> and corp_name like concat('%', #{corpName}, '%')</if>
            <if test="corpFullName != null  and corpFullName != ''"> and corp_full_name like concat('%', #{corpFullName}, '%')</if>
            <if test="subjectType != null  and subjectType != ''"> and subject_type = #{subjectType}</if>
            <if test="verifiedEndTime != null  and verifiedEndTime != ''"> and verified_end_time = #{verifiedEndTime}</if>
            <if test="agentId != null "> and agent_id = #{agentId}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectQywxCompanyById" parameterType="Integer" resultMap="QywxCompanyResult">
        <include refid="selectQywxCompanyVo"/>
        where id = #{id}
    </select>

    <insert id="insertQywxCompany" parameterType="QywxCompany" useGeneratedKeys="true" keyProperty="id">
        insert into qywx_company
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="corpId != null and corpId != ''">corp_id,</if>
            <if test="permanentCode != null and permanentCode != ''">permanent_code,</if>
            <if test="corpName != null and corpName != ''">corp_name,</if>
            <if test="corpFullName != null and corpFullName != ''">corp_full_name,</if>
            <if test="subjectType != null and subjectType != ''">subject_type,</if>
            <if test="verifiedEndTime != null and verifiedEndTime != ''">verified_end_time,</if>
            <if test="companyId != null">company_id,</if>
            <if test="agentId != null">agent_id,</if>
            <if test="accessToken != null and accessToken != ''">access_token,</if>
            <if test="expiresIn != null">expires_in,</if>
            <if test="status != null">status,</if>

            <if test="docPrivateKey != null and docPrivateKey != ''">doc_private_key,</if>
            <if test="docPublicKey != null and docPublicKey != ''">doc_public_key,</if>
            <if test="docPrivateSecret != null and docPrivateSecret != ''">doc_private_secret,</if>

            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="corpId != null and corpId != ''">#{corpId},</if>
            <if test="permanentCode != null and permanentCode != ''">#{permanentCode},</if>
            <if test="corpName != null and corpName != ''">#{corpName},</if>
            <if test="corpFullName != null and corpFullName != ''">#{corpFullName},</if>
            <if test="subjectType != null and subjectType != ''">#{subjectType},</if>
            <if test="verifiedEndTime != null and verifiedEndTime != ''">#{verifiedEndTime},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="agentId != null">#{agentId},</if>
            <if test="accessToken != null and accessToken != ''">#{accessToken},</if>
            <if test="expiresIn != null">#{expiresIn},</if>
            <if test="status != null">#{status},</if>

            <if test="docPrivateKey != null and docPrivateKey != ''">#{docPrivateKey},</if>
            <if test="docPublicKey != null and docPublicKey != ''">#{docPublicKey},</if>
            <if test="docPrivateSecret != null and docPrivateSecret != ''">#{docPrivateSecret},</if>

            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateQywxCompany" parameterType="QywxCompany">
        update qywx_company
        <trim prefix="SET" suffixOverrides=",">
            <if test="corpId != null and corpId != ''">corp_id = #{corpId},</if>
            <if test="permanentCode != null and permanentCode != ''">permanent_code = #{permanentCode},</if>
            <if test="corpName != null and corpName != ''">corp_name = #{corpName},</if>
            <if test="corpFullName != null and corpFullName != ''">corp_full_name = #{corpFullName},</if>
            <if test="subjectType != null and subjectType != ''">subject_type = #{subjectType},</if>
            <if test="verifiedEndTime != null and verifiedEndTime != ''">verified_end_time = #{verifiedEndTime},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="agentId != null">agent_id = #{agentId},</if>
            <if test="accessToken != null and accessToken != ''">access_token = #{accessToken},</if>
            <if test="expiresIn != null">expires_in = #{expiresIn},</if>
            <if test="status != null">status = #{status},</if>

            <if test="docPrivateKey != null and docPrivateKey != ''">doc_private_key = #{docPrivateKey},</if>
            <if test="docPublicKey != null and docPublicKey != ''">doc_public_key = #{docPublicKey},</if>
            <if test="docPrivateSecret != null and docPrivateSecret != ''">doc_private_secret = #{docPrivateSecret},</if>

            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQywxCompanyById" parameterType="Integer">
        delete from qywx_company where id = #{id}
    </delete>

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