<?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.ruoyi.ss.apiPrice.mapper.ApiPriceMapper">

    <resultMap type="ApiPriceVO" id="ApiPriceResult" autoMapping="true"/>

    <sql id="selectApiPriceVo">
        select
            sap.id,
            sap.type,
            sap.num,
            sap.name,
            sap.description,
            sap.price,
            sap.create_time,
            sap.create_by,
            sap.update_time,
            sap.update_by,
            sap.deleted
        from ss_api_price sap
    </sql>

    <sql id="searchCondition">
        <if test="query.id != null "> and sap.id = #{query.id}</if>
        <if test="query.type != null  and query.type != ''"> and sap.type = #{query.type}</if>
        <if test="query.name != null  and query.name != ''"> and sap.`name` like concat('%', #{query.name}, '%')</if>
        <if test="query.description != null  and query.description != ''"> and sap.`description` like concat('%', #{query.description}, '%')</if>
        <if test="query.price != null "> and sap.price = #{query.price}</if>
        <if test="query.createBy != null  and query.createBy != ''"> and sap.create_by like concat('%', #{query.createBy}, '%')</if>
        <if test="query.updateBy != null "> and sap.update_by like concat('%', #{query.updateBy}, '%')</if>
        <if test="query.deleted != null "> and sap.deleted = #{query.deleted}</if>
        <if test="query.deleted == null "> and sap.deleted = false</if>
    </sql>

    <select id="selectApiPriceList" parameterType="ApiPriceQuery" resultMap="ApiPriceResult">
        <include refid="selectApiPriceVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
    </select>

    <select id="selectApiPriceById" parameterType="Long" resultMap="ApiPriceResult">
        <include refid="selectApiPriceVo"/>
        where id = #{id}
    </select>

    <select id="selectOne"  resultMap="ApiPriceResult">
        <include refid="selectApiPriceVo"/>
        <where>
            <include refid="searchCondition"/>
        </where>
        limit 1
    </select>

    <insert id="insertApiPrice" parameterType="ApiPrice" useGeneratedKeys="true" keyProperty="id">
        insert into ss_api_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="num != null">num,</if>
            <if test="name != null">`name`,</if>
            <if test="description != null">`description`,</if>
            <if test="price != null">price,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="num != null">#{num},</if>
            <if test="name != null">#{name},</if>
            <if test="description != null">#{description},</if>
            <if test="price != null">#{price},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>

    <update id="updateApiPrice" parameterType="ApiPrice">
        update ss_api_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="data.type != null">type = #{data.type},</if>
            <if test="data.num != null">num = #{data.num},</if>
            <if test="data.name != null">`name` = #{data.name},</if>
            <if test="data.description != null">`description` = #{data.description},</if>
            <if test="data.price != null">price = #{data.price},</if>
            <if test="data.createTime != null">create_time = #{data.createTime},</if>
            <if test="data.createBy != null">create_by = #{data.createBy},</if>
            <if test="data.updateTime != null">update_time = #{data.updateTime},</if>
            <if test="data.updateBy != null">update_by = #{data.updateBy},</if>
            <if test="data.deleted != null">deleted = #{data.deleted},</if>
        </trim>
        where id = #{data.id}
    </update>

    <update id="logicDel">
        update ss_api_price
        set deleted = true
        where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteApiPriceById" parameterType="Long">
        delete from ss_api_price where id = #{id}
    </delete>

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