<?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.company.mapper.CompanyVoiceApiMapper">
    
    <resultMap type="CompanyVoiceApi" id="CompanyVoiceApiResult">
        <result property="apiId"    column="api_id"    />
        <result property="apiName"    column="api_name"    />
        <result property="apiType"    column="api_type"    />
        <result property="apiJson"    column="api_json"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyVoiceApiVo">
        select api_id, api_name, api_type, api_json, status, remark from company_voice_api
    </sql>

    <select id="selectCompanyVoiceApiList" parameterType="CompanyVoiceApi" resultMap="CompanyVoiceApiResult">
        <include refid="selectCompanyVoiceApiVo"/>
        <where>  
            <if test="apiName != null  and apiName != ''"> and api_name like concat('%', #{apiName}, '%')</if>
            <if test="apiType != null  and apiType != ''"> and api_type = #{apiType}</if>
            <if test="apiJson != null  and apiJson != ''"> and api_json = #{apiJson}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
        order by api_id desc
    </select>
    
    <select id="selectCompanyVoiceApiById" parameterType="Long" resultMap="CompanyVoiceApiResult">
        <include refid="selectCompanyVoiceApiVo"/>
        where api_id = #{apiId}
    </select>
        
    <insert id="insertCompanyVoiceApi" parameterType="CompanyVoiceApi" useGeneratedKeys="true" keyProperty="apiId">
        insert into company_voice_api
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="apiName != null">api_name,</if>
            <if test="apiType != null">api_type,</if>
            <if test="apiJson != null">api_json,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="apiName != null">#{apiName},</if>
            <if test="apiType != null">#{apiType},</if>
            <if test="apiJson != null">#{apiJson},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanyVoiceApi" parameterType="CompanyVoiceApi">
        update company_voice_api
        <trim prefix="SET" suffixOverrides=",">
            <if test="apiName != null">api_name = #{apiName},</if>
            <if test="apiType != null">api_type = #{apiType},</if>
            <if test="apiJson != null">api_json = #{apiJson},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where api_id = #{apiId}
    </update>

    <delete id="deleteCompanyVoiceApiById" parameterType="Long">
        delete from company_voice_api where api_id = #{apiId}
    </delete>

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