<?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.kexue.skills.mapper.ModelPriceMapper">

    <resultMap type="com.kexue.skills.entity.ModelPrice" id="ModelPriceMap">
        <result property="id" column="id" jdbcType="BIGINT"/>
        <result property="vendor" column="vendor" jdbcType="VARCHAR"/>
        <result property="modelName" column="model_name" jdbcType="VARCHAR"/>
        <result property="inputPrice" column="input_price" jdbcType="DECIMAL"/>
        <result property="outputPrice" column="output_price" jdbcType="DECIMAL"/>
        <result property="inputPerCent" column="input_per_cent" jdbcType="BIGINT"/>
        <result property="outputPerCent" column="output_per_cent" jdbcType="BIGINT"/>
        <result property="unit" column="unit" jdbcType="VARCHAR"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
        <result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
        <result property="updatedTime" column="updated_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="ModelPriceMap">
        select 
          id, vendor, model_name, input_price, output_price, input_per_cent, output_per_cent, unit, remark, created_time, updated_time
        from model_price
        where id = #{id}
    </select>

    <!--通过模型名称查询-->
    <select id="queryByModelName" resultMap="ModelPriceMap">
        select 
          id, vendor, model_name, input_price, output_price, input_per_cent, output_per_cent, unit, remark, created_time, updated_time
        from model_price
        where model_name = #{modelName}
    </select>

    <!--分页查询-->
    <select id="getPageList" resultMap="ModelPriceMap">
        select 
          id, vendor, model_name, input_price, output_price, input_per_cent, output_per_cent, unit, remark, created_time, updated_time
        from model_price
        <where>
            <if test="vendor != null and vendor != ''">
                and vendor = #{vendor}
            </if>
            <if test="modelName != null and modelName != ''">
                and model_name like concat('%', #{modelName}, '%')
            </if>
        </where>
        <if test="sortBy != null and sortBy != ''">
            order by ${sortBy} ${sortDesc ? 'desc' : 'asc'}
        </if>
    </select>

    <!--查询列表-->
    <select id="getList" resultMap="ModelPriceMap">
        select 
          id, vendor, model_name, input_price, output_price, input_per_cent, output_per_cent, unit, remark, created_time, updated_time
        from model_price
        <where>
            <if test="vendor != null and vendor != ''">
                and vendor = #{vendor}
            </if>
            <if test="modelName != null and modelName != ''">
                and model_name like concat('%', #{modelName}, '%')
            </if>
        </where>
    </select>

    <!--新增数据-->
    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
        insert into model_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="vendor != null">vendor,</if>
            <if test="modelName != null">model_name,</if>
            <if test="inputPrice != null">input_price,</if>
            <if test="outputPrice != null">output_price,</if>
            <if test="inputPerCent != null">input_per_cent,</if>
            <if test="outputPerCent != null">output_per_cent,</if>
            <if test="unit != null">unit,</if>
            <if test="remark != null">remark,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedTime != null">updated_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="vendor != null">#{vendor},</if>
            <if test="modelName != null">#{modelName},</if>
            <if test="inputPrice != null">#{inputPrice},</if>
            <if test="outputPrice != null">#{outputPrice},</if>
            <if test="inputPerCent != null">#{inputPerCent},</if>
            <if test="outputPerCent != null">#{outputPerCent},</if>
            <if test="unit != null">#{unit},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <!--更新数据-->
    <update id="update">
        update model_price
        <set>
            <if test="vendor != null">vendor = #{vendor},</if>
            <if test="modelName != null">model_name = #{modelName},</if>
            <if test="inputPrice != null">input_price = #{inputPrice},</if>
            <if test="outputPrice != null">output_price = #{outputPrice},</if>
            <if test="inputPerCent != null">input_per_cent = #{inputPerCent},</if>
            <if test="outputPerCent != null">output_per_cent = #{outputPerCent},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </set>
        where id = #{id}
    </update>

    <!--删除数据-->
    <delete id="deleteById">
        delete from model_price
        where id = #{id}
    </delete>

</mapper>
