<?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.microservices.pms.product.mapper.PmsProductPriorityMapper">
    
    <resultMap type="PmsProductPriority" id="PmsProductPriorityResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="color"    column="color"    />
        <result property="isDefault"    column="is_default"    />
    </resultMap>

    <sql id="selectPmsProductPriorityVo">
        select id, name, type, update_time, update_by, create_time, create_by, del_flag, color, is_default from pms_product_priority
    </sql>

    <select id="selectPmsProductPriorityList" parameterType="PmsProductPriority" resultMap="PmsProductPriorityResult">
        <include refid="selectPmsProductPriorityVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="color != null  and color != ''"> and color = #{color}</if>
            <if test="isDefault != null  and isDefault != ''"> and is_default = #{isDefault}</if>
        </where>
    </select>
    
    <select id="selectPmsProductPriorityById" parameterType="Long" resultMap="PmsProductPriorityResult">
        <include refid="selectPmsProductPriorityVo"/>
        where id = #{id}
    </select>
    <select id="selectPmsProductPriorityByNameAndType" resultMap="PmsProductPriorityResult">
        <include refid="selectPmsProductPriorityVo"/>
        where `name` = #{name}
        and type=#{type}
    </select>
    <select id="selectPmsProductDefaultPriorityByType" resultMap="PmsProductPriorityResult">
        <include refid="selectPmsProductPriorityVo"/>
        where type=#{type}
        and is_default=1
    </select>

    <insert id="insertPmsProductPriority" parameterType="PmsProductPriority" useGeneratedKeys="true" keyProperty="id">
        insert into pms_product_priority
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="type != null">type,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="color != null">color,</if>
            <if test="isDefault != null">is_default,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="color != null">#{color},</if>
            <if test="isDefault != null">#{isDefault},</if>
         </trim>
    </insert>

    <update id="updatePmsProductPriority" parameterType="PmsProductPriority">
        update pms_product_priority
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="color != null">color = #{color},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePmsProductPriorityById" parameterType="Long">
        delete from pms_product_priority where id = #{id}
    </delete>

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