<?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.dict.SysDictGroupMapper">
  <resultMap id="BaseResultMap" type="com.cool.store.entity.dict.SysDictGroupDO">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="group_name" jdbcType="VARCHAR" property="groupName" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
    <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, group_name, remark, deleted, create_user_id, update_user_id, create_time, update_time
  </sql>
  <insert id="insertSelective" keyColumn="id" keyProperty="record.id" useGeneratedKeys="true">
    insert into sys_dict_group_${enterpriseId}
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="record.groupName != null">
        group_name,
      </if>
      <if test="record.remark != null">
        remark,
      </if>
      <if test="record.deleted != null">
        deleted,
      </if>
      <if test="record.createUserId != null">
        create_user_id,
      </if>
      <if test="record.updateUserId != null">
        update_user_id,
      </if>
      <if test="record.createTime != null">
        create_time,
      </if>
      <if test="record.updateTime != null">
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="record.groupName != null">
        #{record.groupName},
      </if>
      <if test="record.remark != null">
        #{record.remark},
      </if>
      <if test="record.deleted != null">
        #{record.deleted},
      </if>
      <if test="record.createUserId != null">
        #{record.createUserId},
      </if>
      <if test="record.updateUserId != null">
        #{record.updateUserId},
      </if>
      <if test="record.createTime != null">
        #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        #{record.updateTime},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective">
    update sys_dict_group_${enterpriseId}
    <set>
      <if test="record.groupName != null">
        group_name = #{record.groupName},
      </if>
      <if test="record.remark != null">
        remark = #{record.remark},
      </if>
      <if test="record.deleted != null">
        deleted = #{record.deleted},
      </if>
      <if test="record.createUserId != null">
        create_user_id = #{record.createUserId},
      </if>
      <if test="record.updateUserId != null">
        update_user_id = #{record.updateUserId},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime},
      </if>
    </set>
    where id = #{record.id}
  </update>

  <update id="deleteByIds">
    UPDATE sys_dict_group_${enterpriseId}
    SET deleted = 1
    WHERE id IN
    <foreach item="id" collection="ids" separator="," open="(" close=")">
      #{id}
    </foreach>
    AND deleted = 0
  </update>

  <select id="selectById" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List" />
    FROM sys_dict_group_${enterpriseId}
    WHERE id = #{id} AND deleted = 0 LIMIT 1
  </select>

  <select id="selectList" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List"/>
    FROM sys_dict_group_${enterpriseId}
    WHERE deleted = 0
    <if test="dto.groupName != null and dto.groupName != ''">
      AND group_name LIKE CONCAT('%', #{dto.groupName}, '%')
    </if>
    <if test="dto.remark != null and dto.remark != ''">
      AND remark LIKE CONCAT('%', #{dto.remark}, '%')
    </if>
    ORDER BY create_time ASC
  </select>
</mapper>