<?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.sckw.system.dao.SysDictDao">
  <resultMap id="BaseResultMap" type="com.sckw.system.model.SysDict">
    <id column="id" jdbcType="BIGINT" property="id" />
    <id column="dict_id" jdbcType="BIGINT" property="dictId" />
    <result column="value" jdbcType="VARCHAR" property="value" />
    <result column="label" jdbcType="VARCHAR" property="label" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="description" jdbcType="VARCHAR" property="description" />
    <result column="sort" jdbcType="DECIMAL" property="sort" />
    <result column="parent_id" jdbcType="VARCHAR" property="parentId" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="create_by" jdbcType="BIGINT" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
  </resultMap>

  <sql id="Base_Column_List">
    id, dict_id, value, label, type, description, sort, parent_id, remark, status, create_by,
    create_time, update_by, update_time, del_flag, url
  </sql>

  <insert id="insert" parameterType="com.sckw.system.model.SysDict">
    insert into sys_dict
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="dictId != null">
        dict_id,
      </if>
      <if test="value != null">
        value,
      </if>
      <if test="label != null">
        label,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="description != null">
        description,
      </if>
      <if test="sort != null">
        sort,
      </if>
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="remark != null">
        remark,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="delFlag != null">
        del_flag,
      </if>
      <if test="url != null">
        url,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="dictId != null">
        #{dictId,jdbcType=BIGINT},
      </if>
      <if test="value != null">
        #{value,jdbcType=VARCHAR},
      </if>
      <if test="label != null">
        #{label,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        #{description,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=DECIMAL},
      </if>
      <if test="parentId != null">
        #{parentId,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        #{remark,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="update" parameterType="com.sckw.system.model.SysDict">
    update sys_dict
    <set>
      <if test="dictId != null">
        dict_id = #{dictId,jdbcType=BIGINT},
      </if>
      <if test="value != null">
        value = #{value,jdbcType=VARCHAR},
      </if>
      <if test="label != null">
        label = #{label,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=VARCHAR},
      </if>
      <if test="description != null">
        description = #{description,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=DECIMAL},
      </if>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=BIGINT},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="delFlag != null">
        del_flag = #{delFlag,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="selectByKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from sys_dict
    where id = #{id,jdbcType=BIGINT}
  </select>

  <select id="findPage" resultMap="BaseResultMap" parameterType="java.util.Map" >
    select
    <include refid="Base_Column_List" />
    from sys_dict
    where del_flag = 0
    <if test="type != null and type != ''">
      and type = #{type, jdbcType=VARCHAR}
    </if>
    <if test="label != null and label != ''">
      and label = #{label, jdbcType=VARCHAR}
    </if>
    <if test="value != null and value != ''">
      and value = #{value, jdbcType=VARCHAR}
    </if>
    ORDER BY type, create_time desc
  </select>

  <select id="findList" resultType="java.util.Map" parameterType="java.util.Map" >
    select
      id, value, label, type, description, remark,url
    from sys_dict
    where del_flag = 0
    <if test="type != null and type != ''">
      and type = #{type, jdbcType=VARCHAR}
    </if>
    <if test="label != null and label != ''">
      and label = #{label, jdbcType=VARCHAR}
    </if>
    <if test="value != null and value != ''">
      and value = #{value, jdbcType=VARCHAR}
    </if>
    ORDER BY sort
  </select>

  <select id="queryByType" resultType="com.sckw.system.model.SysDict">
    select * from sys_dict where del_flag = 0 and type = #{type}
  </select>

  <select id="queryUnitDict" resultType="com.sckw.system.model.SysDict">
    select *
      from sys_dict
     where del_flag = 0
       and dict_id = #{dictTypeId}
       and (value = #{value} or label = #{label})
  </select>

  <select id="queryByTypeAndValue" resultType="com.sckw.system.model.SysDict">
    select *
    from sys_dict
    where del_flag = 0
      and type = #{type}
      and value = #{value} limit 1
  </select>

  <select id="selectAll" resultType="com.sckw.system.model.SysDict">
    select *
      from sys_dict
     where del_flag = 0
  </select>

  <select id="selectByKeys" resultType="com.sckw.system.model.SysDict">
    select
    <include refid="Base_Column_List" />
    from sys_dict
    where del_flag = 0
     and id in
     <foreach collection="list" separator="," open="(" close=")" item="item">
       #{item}
     </foreach>
  </select>

</mapper>