<?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.seller.VendorResourcesReadMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.seller.pojo.VendorResources">
    <id column="resources_id" property="resourcesId" />
    <result column="pid" property="pid" />
    <result column="content" property="content" />
    <result column="create_time" property="createTime" />
    <result column="state" property="state" />
    <result column="grade" property="grade" />
    <result column="url" property="url" />
    <result column="front_path" property="frontPath" />
  </resultMap>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `resources_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.resourcesIdNotEquals != null">
          AND `resources_id` != #{example.resourcesIdNotEquals}
        </if>
        <if test="example.resourcesIdIn != null">
          AND `resources_id` in (${example.resourcesIdIn})
        </if>
        <if test="example.pid != null">
          AND `pid` = #{example.pid}
        </if>
        <if test="example.pidIn != null">
          AND `pid` in (${example.pidIn})
        </if>
        <if test="example.pidNotEquals != null">
          AND `pid` != #{example.pidNotEquals}
        </if>
        <if test="example.content != null">
          AND `content` = #{example.content}
        </if>
        <if test="example.contentLike != null">
          AND `content` like concat('%',#{example.contentLike},'%')
        </if>
        <if test="example.createTimeAfter != null">
          AND `create_time` <![CDATA[ >= ]]> #{example.createTimeAfter}
        </if>
        <if test="example.createTimeBefore != null">
          AND `create_time` <![CDATA[ <= ]]> #{example.createTimeBefore}
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </if>
        <if test="example.grade != null">
          AND `grade` = #{example.grade}
        </if>
        <if test="example.url != null">
          AND `url` = #{example.url}
        </if>
        <if test="example.frontPath != null">
          AND `front_path` = #{example.frontPath}
        </if>
        <if test="example.frontPathNotEquals != null">
          AND `front_path` != #{example.frontPathNotEquals}
        </if>
        <if test="example.roleId != null">
          AND (`resources_id` IN ( SELECT resources_id FROM `vendor_resources_roles` WHERE roles_id = #{example.roleId} ) or `pid` = -1)
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `resources_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.seller.example.VendorResourcesExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `vendor_resources`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `vendor_resources`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `vendor_resources`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `vendor_resources`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `vendor_resources`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `vendor_resources`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
</mapper>