<?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.HyPartnerLabelMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.HyPartnerLabelDO">
    <id column="id" property="id" />
    <result column="label_group_id" property="labelGroupId" />
    <result column="label_name" property="labelName" />
    <result column="edit_user_id" property="editUserId" />
    <result column="edit_date" property="editDate" />
    <result column="deleted" property="deleted" />
    <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_id, label_name, edit_user_id, edit_date, deleted, 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
    where deleted = 0
    and id = #{id}
    order by create_time desc
  </select>

  <select id="selectSelective" resultType="com.cool.store.entity.HyPartnerLabelDO">
    select <include refid="Base_Column_List"></include>
    from xfsg_partner_label
    where deleted = 0
    <if test="labelGroupId != null">
      and label_group_id = #{labelGroupId}
    </if>
    <if test="labelName != null and labelName != ''">
      and label_name = #{labelName}
    </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 = #{remark}
    </if>
    order by create_time desc
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from xfsg_partner_label
    where id = #{id}
  </delete>
  <insert id="insert" parameterType="com.cool.store.entity.HyPartnerLabelDO">
    insert into xfsg_partner_label (id, label_group_id, label_name, 
      edit_user_id, edit_date, deleted, 
      create_time, update_time, create_user_id, 
      update_user_id, remark)
    values (#{id}, #{labelGroupId}, #{labelName}, 
      #{editUserId}, #{editDate}, #{deleted}, 
      #{createTime}, #{updateTime}, #{createUserId}, 
      #{updateUserId}, #{remark})
  </insert>
  <insert id="insertSelective" parameterType="com.cool.store.entity.HyPartnerLabelDO">
    insert into xfsg_partner_label
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="labelGroupId != null">
        label_group_id,
      </if>
      <if test="labelName != null">
        label_name,
      </if>
      <if test="editUserId != null">
        edit_user_id,
      </if>
      <if test="editDate != null">
        edit_date,
      </if>
      <if test="deleted != null">
        deleted,
      </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="labelGroupId != null">
        #{labelGroupId},
      </if>
      <if test="labelName != null">
        #{labelName},
      </if>
      <if test="editUserId != null">
        #{editUserId},
      </if>
      <if test="editDate != null">
        #{editDate},
      </if>
      <if test="deleted != null">
        #{deleted},
      </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.HyPartnerLabelDO">
    update xfsg_partner_label
    <set>
      <if test="labelGroupId != null">
        label_group_id = #{labelGroupId},
      </if>
      <if test="labelName != null and labelName != ''">
        label_name = #{labelName},
      </if>
      <if test="editUserId != null">
        edit_user_id = #{editUserId},
      </if>
      <if test="editDate != null">
        edit_date = #{editDate},
      </if>
      <if test="deleted != null">
        deleted = #{deleted},
      </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 deleted = 0
    and id = #{id}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.cool.store.entity.HyPartnerLabelDO">
    update xfsg_partner_label
    set label_group_id = #{labelGroupId},
      label_name = #{labelName},
      edit_user_id = #{editUserId},
      edit_date = #{editDate},
      deleted = #{deleted},
      create_time = #{createTime},
      update_time = #{updateTime},
      create_user_id = #{createUserId},
      update_user_id = #{updateUserId},
      remark = #{remark}
    where id = #{id}
  </update>

  <select id="getLabelList" resultType="com.cool.store.vo.LabelListVo">
    SELECT t1.id, t2.id AS labelGroupId, t1.label_name, t2.label_group_name, t3.`name` AS editName, t3.mobile AS editMobile, t1.edit_date,t1.create_time as labelCreateTime,t2.create_time AS groupCreateTime
      FROM xfsg_partner_label t1
      LEFT JOIN xfsg_partner_label_group t2 ON t1.label_group_id = t2.id
      LEFT JOIN enterprise_user_${enterpriseId} t3 ON t1.edit_user_id = t3.user_id
      WHERE t1.deleted = 0 AND t2.deleted = 0
      <if test="labelName != null and labelName != ''">
        AND t1.label_name LIKE CONCAT('%', #{labelName} ,'%')
      </if>
      <if test="labelGroupId != null">
        AND t2.id = #{labelGroupId}
      </if>
    ORDER BY t2.create_time asc ,t2.id asc
  </select>

  <select id="whetherGroupInUse" resultType="java.lang.Boolean">
    SELECT COUNT(*)
      FROM xfsg_partner_label
      WHERE deleted = 0
      AND label_group_id = #{labelGroupId}
  </select>

  <select id="getLabelListByIds" resultMap="BaseResultMap">
    select * from xfsg_partner_label where deleted = 0
    <if test="labelIds!=null and labelIds.size>0">
      <foreach collection="labelIds" item="labelId" open="and id in (" close=")" separator=",">
        #{labelId}
      </foreach>
    </if>
  </select>

</mapper>