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

    <resultMap type="com.microservices.pms.product.domain.PmsProductRequirementTag" id="PmsProductRequirementTagResult">
        <result property="id"    column="id"    />
        <result property="tagName"    column="tag_name"    />
        <result property="pmsEnterpriseId" column="pms_enterprise_id"/>
        <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="type" column="type"/>
        <result property="description" column="description"/>
    </resultMap>

    <sql id="selectPmsProductRequirementTagVo">
        select id,
               tag_name,
               pms_enterprise_id,
               update_time,
               update_by,
               create_time,
               create_by,
               del_flag,
               color,
               type,
               description
        from pms_product_requirement_tag
    </sql>

    <select id="selectPmsProductRequirementTagList" parameterType="PmsProductRequirementTag" resultMap="PmsProductRequirementTagResult">
        <include refid="selectPmsProductRequirementTagVo"/>
        <where>  
            <if test="tagName != null  and tagName != ''"> and tag_name like concat('%', #{tagName}, '%')</if>
            <if test="pmsEnterpriseId != null ">and pms_enterprise_id = #{pmsEnterpriseId}</if>
            <if test="color != null  and color != ''">and color = #{color}</if>
            <if test="type != null">and type = #{type}</if>
            <if test="description != null">and description = #{description}</if>
        </where>
    </select>
    
    <select id="selectPmsProductRequirementTagById" parameterType="Long" resultMap="PmsProductRequirementTagResult">
        <include refid="selectPmsProductRequirementTagVo"/>
        where id = #{id}
    </select>
    <select id="selectPmsProductRequirementTagByNameAndEnterpriseId" resultMap="PmsProductRequirementTagResult">
        <include refid="selectPmsProductRequirementTagVo"/>
        where tag_name = #{name}
        and pms_enterprise_id = #{pmsEnterpriseId}
        and type= #{type}
    </select>
    <select id="selectPmsProductRequirementTagByNameAndProjectId" resultMap="PmsProductRequirementTagResult">
        <include refid="selectPmsProductRequirementTagVo"/>
        where tag_name = #{name}
        and description = #{description}
        and type=2
    </select>
    <select id="selectPmsProductRequirementTagListByTagIds" resultMap="PmsProductRequirementTagResult">
        <include refid="selectPmsProductRequirementTagVo"/>
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertPmsProductRequirementTag" parameterType="PmsProductRequirementTag" useGeneratedKeys="true" keyProperty="id">
        insert into pms_product_requirement_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tagName != null and tagName != ''">tag_name,</if>
            <if test="pmsEnterpriseId != null">pms_enterprise_id,</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="type != null">type,</if>
            <if test="description != null">description,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tagName != null and tagName != ''">#{tagName},</if>
            <if test="pmsEnterpriseId != null">#{pmsEnterpriseId},</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="type != null">#{type},</if>
            <if test="description != null">#{description},</if>
         </trim>
    </insert>

    <update id="updatePmsProductRequirementTag" parameterType="PmsProductRequirementTag">
        update pms_product_requirement_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="tagName != null and tagName != ''">tag_name = #{tagName},</if>
            <if test="pmsEnterpriseId != null">pms_enterprise_id = #{pmsEnterpriseId},</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="type != null">type = #{type},</if>
            <if test="description != null">description = #{description},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePmsProductRequirementTagById" parameterType="Long">
        delete from pms_product_requirement_tag where id = #{id}
    </delete>

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