<?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.web.modules.template.mapper.BizGoodsAttrTemplateMapper">

    <resultMap id="BizGoodsAttrTemplateResult" type="com.ruoyi.web.modules.template.domain.BizGoodsAttrTemplate">
        <id property="templateId" column="template_id"/>
        <result property="shopId" column="shop_id"/>
        <result property="templateName" column="template_name"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="selectList" resultMap="BizGoodsAttrTemplateResult">
        select template_id, shop_id, template_name, del_flag, create_by, create_time, update_by, update_time
        from biz_goods_attr_template
        where shop_id = #{shopId} and del_flag = '0'
        <if test="keyword != null and keyword != ''">
            and template_name like concat('%', #{keyword}, '%')
        </if>
        order by create_time desc
    </select>

    <select id="selectById" resultMap="BizGoodsAttrTemplateResult">
        select template_id, shop_id, template_name, del_flag, create_by, create_time, update_by, update_time
        from biz_goods_attr_template
        where template_id = #{templateId} and shop_id = #{shopId} and del_flag = '0'
    </select>

    <select id="countByName" resultType="int">
        select count(1) from biz_goods_attr_template
        where shop_id = #{shopId} and template_name = #{templateName} and del_flag = '0'
        <if test="excludeTemplateId != null">
            and template_id != #{excludeTemplateId}
        </if>
    </select>

    <insert id="insert" useGeneratedKeys="true" keyProperty="templateId">
        insert into biz_goods_attr_template (shop_id, template_name, del_flag, create_by, create_time)
        values (#{shopId}, #{templateName}, #{delFlag}, #{createBy}, sysdate())
    </insert>

    <update id="update">
        update biz_goods_attr_template
        set template_name = #{templateName},
            update_by = #{updateBy},
            update_time = sysdate()
        where template_id = #{templateId} and shop_id = #{shopId} and del_flag = '0'
    </update>

    <update id="logicDeleteByIds">
        update biz_goods_attr_template
        set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
        where shop_id = #{shopId} and del_flag = '0'
          and template_id in
        <foreach collection="templateIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
