<?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.dgtis.dorm.manager.db.dao.StorageMapper">
  <resultMap id="BaseResultMap" type="com.dgtis.dorm.manager.db.domain.Storage">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="key" jdbcType="VARCHAR" property="key" />
    <result column="old_name" jdbcType="VARCHAR" property="oldName" />
    <result column="new_name" jdbcType="VARCHAR" property="newName" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="size" jdbcType="INTEGER" property="size" />
    <result column="file_path" jdbcType="VARCHAR" property="filePath" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
    <result column="create_user_id" jdbcType="VARCHAR" property="createUserId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="modify_user_id" jdbcType="VARCHAR" property="modifyUserId" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="img_belongs" jdbcType="VARCHAR" property="imgBelongs" />
  </resultMap>

  <sql id="Base_Column_List">
    id, `key`, old_name, new_name, `type`, `size`, file_path, url, modify_time, create_user_id, 
    create_time, modify_user_id, deleted, img_belongs
  </sql>

  <select id="selectOneByExample" parameterType="com.dgtis.dorm.manager.db.domain.Storage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from zhll_storage
    <where>
      <if test="key != null and key != ''">
        `key` = #{key }
      </if>
    </where>
    limit 1
  </select>

  <select id="selectByExample" parameterType="com.dgtis.dorm.manager.db.domain.Storage" resultMap="BaseResultMap">
    select distinct
    <include refid="Base_Column_List" />
    from zhll_storage
    <where>
      <if test="key != null and key != ''">
        and `key` = #{key }
      </if>
      <if test="oldName != null and oldName != ''">
        and old_name like concat('%', #{oldName }, '%')
      </if>
      <if test="deleted != null">
        and deleted = #{deleted }
      </if>
    </where>
  </select>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from zhll_storage
    where id = #{id,jdbcType=INTEGER}
  </select>

  <insert id="insertSelective" parameterType="com.dgtis.dorm.manager.db.domain.Storage">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into zhll_storage
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="key != null">
        `key`,
      </if>
      <if test="oldName != null">
        old_name,
      </if>
      <if test="newName != null">
        new_name,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="size != null">
        `size`,
      </if>
      <if test="filePath != null">
        file_path,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="modifyTime != null">
        modify_time,
      </if>
      <if test="createUserId != null">
        create_user_id,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="modifyUserId != null">
        modify_user_id,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
      <if test="imgBelongs != null">
        img_belongs,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="key != null">
        #{key,jdbcType=VARCHAR},
      </if>
      <if test="oldName != null">
        #{oldName,jdbcType=VARCHAR},
      </if>
      <if test="newName != null">
        #{newName,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="size != null">
        #{size,jdbcType=INTEGER},
      </if>
      <if test="filePath != null">
        #{filePath,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        #{createUserId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyUserId != null">
        #{modifyUserId,jdbcType=VARCHAR},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=BIT},
      </if>
      <if test="imgBelongs != null">
        #{imgBelongs,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.dgtis.dorm.manager.db.domain.Storage">
    update zhll_storage
    <set>
      <if test="key != null">
        `key` = #{key,jdbcType=VARCHAR},
      </if>
      <if test="oldName != null">
        old_name = #{oldName,jdbcType=VARCHAR},
      </if>
      <if test="newName != null">
        new_name = #{newName,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=VARCHAR},
      </if>
      <if test="size != null">
        `size` = #{size,jdbcType=INTEGER},
      </if>
      <if test="filePath != null">
        file_path = #{filePath,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="modifyTime != null">
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        create_user_id = #{createUserId,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="modifyUserId != null">
        modify_user_id = #{modifyUserId,jdbcType=VARCHAR},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=BIT},
      </if>
      <if test="imgBelongs != null">
        img_belongs = #{imgBelongs,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from zhll_storage
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <select id="selectByKey"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from zhll_storage
    where key = #{key}
  </select>

  <select id="selectByKeys"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from zhll_storage
    where `key` in
    <foreach collection="keys" item="key" open="(" close=")" separator=",">
      #{key}
    </foreach>
  </select>
</mapper>