<?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.slodon.b2b2c.dao.read.system.SysMediaReadMapper">
  <resultMap id="BaseResultMap" type="com.slodon.b2b2c.system.pojo.SysMedia">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="path" jdbcType="VARCHAR" property="path" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="file_type" jdbcType="VARCHAR" property="fileType" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="create_id" jdbcType="BIGINT" property="createId" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_id" jdbcType="BIGINT" property="updateId" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    id, name, path, type, status, file_type, store_id, create_id, create_time, update_id, 
    update_time
  </sql>
  <select id="selectByExample" parameterType="com.slodon.b2b2c.system.example.SysMediaExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from sys_media
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    select 
    <include refid="Base_Column_List" />
    from sys_media
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="countByExample" parameterType="com.slodon.b2b2c.system.example.SysMediaExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Oct 13 14:15:00 CST 2022.
    -->
    select count(*) from sys_media
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>

  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>

  <!--列表分页总条数-->
  <select id="mediaListPageCount" resultType="java.lang.Integer">
    SELECT COUNT(*)
    FROM sys_media T
    WHERE T.STATUS = 1
    <if test="typeLike != null">
      AND T.type = #{typeLike}
    </if>
    <if test="fileTypeLike != null">
      AND T.file_type in 
      <foreach collection="fileTypeLike" item="filetype" index="index" open="(" separator="," close=")">
        #{filetype}
      </foreach>
    </if>
    <if test="startTimeLike != null">
      AND T.create_time <![CDATA[ >= ]]> #{startTimeLike}
    </if>
    <if test="endTimeLike != null">
      AND T.create_time <![CDATA[ <= ]]> #{endTimeLike}
    </if>
    <if test="storeId != null">
      AND T.store_id = #{storeId}
    </if>
    <if test="nameLike != null">
      AND T.name like concat('%',#{nameLike},'%')
    </if>

  </select>


  <!--列表分页-->
  <select id="mediaListPage" resultMap="BaseResultMap">
    SELECT *,(select store_name from store s where s.store_id = T.store_id) storeName,
    (select vendor_name from vendor v where v.vendor_id = T.create_id) tplTypeName
    FROM sys_media T
    WHERE T.STATUS = 1
    <if test="typeLike != null">
      AND T.type = #{typeLike}
    </if>
    <if test="fileTypeLike != null">
      AND T.file_type in
      <foreach collection="fileTypeLike" item="filetype" index="index" open="(" separator="," close=")">
        #{filetype}
      </foreach>
    </if>
    <if test="startTimeLike != null">
      AND T.create_time <![CDATA[ >= ]]> #{startTimeLike}
    </if>
    <if test="endTimeLike != null">
      AND T.create_time <![CDATA[ <= ]]> #{endTimeLike}
    </if>
    <if test="storeId != null">
      AND T.store_id = #{storeId}
    </if>
    <if test="nameLike != null">
      AND T.name like concat('%',#{nameLike},'%')
    </if>
    order by T.create_time desc
    <include refid="limit"/>
  </select>


</mapper>