<?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.cool.store.mapper.HyPartnerLabelGroupMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyPartnerLabelGroupDO">
    <id column="id" property="id" />
    <result column="label_group_name" property="labelGroupName" />
    <result column="deleted" property="deleted" />
    <result column="edit_user_id" property="editUserId" />
    <result column="edit_date" property="editDate" />
    <result column="create_time" property="createTime" />
    <result column="update_time" property="updateTime" />
    <result column="create_user_id" property="createUserId" />
    <result column="update_user_id" property="updateUserId" />
    <result column="remark" property="remark" />
  </resultMap>
  <sql id="Base_Column_List">
    id, label_group_name, deleted, edit_user_id, edit_date, create_time, update_time, 
    create_user_id, update_user_id, remark
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from xfsg_partner_label_group
    where id = #{id}
    order by create_time
  </select>

  <select id="selectSelective" resultType="com.cool.store.entity.HyPartnerLabelGroupDO">
    select <include refid="Base_Column_List"></include>
    from xfsg_partner_label_group
    where deleted = 0
    <if test="labelGroupName != null and labelGroupName != ''">
      and label_group_name = #{labelGroupName}
    </if>
    <if test="editUserId != null">
      and edit_user_id = #{editUserId}
    </if>
    <if test="editDate != null">
      and edit_date = #{editDate}
    </if>
    <if test="createTime != null">
      and create_time = #{createTime}
    </if>
    <if test="updateTime != null">
      and update_time =#{updateTime}
    </if>
    <if test="createUserId != null">
      and create_user_id = #{createUserId}
    </if>
    <if test="updateUserId != null">
      and update_user_id = #{updateUserId}
    </if>
    <if test="remark != null and remark != ''">
      and remark like concat('%', #{remark}, '%')
    </if>
    order by create_time
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from xfsg_partner_label_group
    where id = #{id}
    <if test="id != null">
      and id = #{id}
    </if>
    <if test="labelGroupName != null and labelGroupName != ''">
      and label_group_name like concat('%', #{labelGroupName}, '%')
    </if>
    <if test="editUserId != null">
      and edit_user_id = #{editUserId}
    </if>
    <if test="editDate != null">
      and edit_date = #{editDate}
    </if>
    <if test="createTime != null">
      and create_time = #{createTime}
    </if>
    <if test="updateTime != null">
      and update_time =#{updateTime}
    </if>
    <if test="createUserId != null">
      and create_user_id = #{createUserId}
    </if>
    <if test="updateUserId != null">
      and update_user_id = #{updateUserId}
    </if>
    <if test="remark != null and remark != ''">
      and remark like concat('%', #{remark}, '%')
    </if>
  </delete>
  <insert id="insert" parameterType="com.cool.store.entity.HyPartnerLabelGroupDO">
    insert into xfsg_partner_label_group (id, label_group_name, deleted, 
      edit_user_id, edit_date, create_time, 
      update_time, create_user_id, update_user_id, 
      remark)
    values (#{id}, #{labelGroupName}, #{deleted}, 
      #{editUserId}, #{editDate}, #{createTime}, 
      #{updateTime}, #{createUserId}, #{updateUserId}, 
      #{remark})
  </insert>
  <insert id="insertSelective" parameterType="com.cool.store.entity.HyPartnerLabelGroupDO">
    insert into xfsg_partner_label_group
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="labelGroupName != null and labelGroupName != ''">
        label_group_name,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
      <if test="editUserId != null">
        edit_user_id,
      </if>
      <if test="editDate != null">
        edit_date,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="createUserId != null">
        create_user_id,
      </if>
      <if test="updateUserId != null">
        update_user_id,
      </if>
      <if test="remark != null">
        remark,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id},
      </if>
      <if test="labelGroupName != null">
        #{labelGroupName},
      </if>
      <if test="deleted != null">
        #{deleted},
      </if>
      <if test="editUserId != null">
        #{editUserId},
      </if>
      <if test="editDate != null">
        #{editDate},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
      <if test="createUserId != null">
        #{createUserId},
      </if>
      <if test="updateUserId != null">
        #{updateUserId},
      </if>
      <if test="remark != null">
        #{remark},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.cool.store.entity.HyPartnerLabelGroupDO">
    update xfsg_partner_label_group
    <set>
      <if test="labelGroupName != null">
        label_group_name = #{labelGroupName},
      </if>
      <if test="deleted != null">
        deleted = #{deleted},
      </if>
      <if test="editUserId != null">
        edit_user_id = #{editUserId},
      </if>
      <if test="editDate != null">
        edit_date = #{editDate},
      </if>
      <if test="createTime != null">
        create_time = #{createTime},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime},
      </if>
      <if test="createUserId != null">
        create_user_id = #{createUserId},
      </if>
      <if test="updateUserId != null">
        update_user_id = #{updateUserId},
      </if>
      <if test="remark != null">
        remark = #{remark},
      </if>
    </set>
    where id = #{id}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.cool.store.entity.HyPartnerLabelGroupDO">
    update xfsg_partner_label_group
    set label_group_name = #{labelGroupName},
      deleted = #{deleted},
      edit_user_id = #{editUserId},
      edit_date = #{editDate},
      create_time = #{createTime},
      update_time = #{updateTime},
      create_user_id = #{createUserId},
      update_user_id = #{updateUserId},
      remark = #{remark}
    where id = #{id}
  </update>

  <!-- 获取标签分组信息列表 -->
  <select id="getLabelGroupList" resultType="com.cool.store.vo.LabelGroupListVo">
    SELECT  t1.id, t1.label_group_name, t2.`name` AS editName, t2.mobile AS editMobile, t1.edit_date
    FROM xfsg_partner_label_group t1
    LEFT JOIN enterprise_user_${enterpriseId} t2 ON t1.edit_user_id = t2.user_id
    WHERE t1.deleted = 0
    <if test="labelGroupName != null and labelGroupName != ''">
      AND t1.label_group_name LIKE CONCAT('%', #{labelGroupName}, '%')
    </if>
    ORDER BY t1.create_time DESC
  </select>

  <select id="getLabelGroupListOrder" resultType="com.cool.store.vo.LabelGroupListVo">
    SELECT  t1.id, t1.label_group_name, t2.`name` AS editName, t2.mobile AS editMobile, t1.edit_date
    FROM xfsg_partner_label_group t1
    LEFT JOIN enterprise_user_${enterpriseId} t2 ON t1.edit_user_id = t2.user_id
    WHERE t1.deleted = 0
    <if test="labelGroupName != null and labelGroupName != ''">
      AND t1.label_group_name LIKE CONCAT('%', #{labelGroupName}, '%')
    </if>
    ORDER BY t1.create_time,t1.id
  </select>

</mapper>