<?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.goods.GoodsExtendReadMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.goods.pojo.GoodsExtend">
    <id column="extend_id" property="extendId" />
    <result column="goods_id" property="goodsId" />
    <result column="main_spec_id" property="mainSpecId" />
    <result column="spec_json" property="specJson" />
    <result column="attribute_json" property="attributeJson" />
    <result column="online_time" property="onlineTime" />
    <result column="create_vendor_id" property="createVendorId" />
    <result column="create_time" property="createTime" />
    <result column="audit_reason" property="auditReason" />
    <result column="audit_comment" property="auditComment" />
    <result column="follow_number" property="followNumber" />
    <result column="click_number" property="clickNumber" />
    <result column="offline_reason" property="offlineReason" />
    <result column="offline_comment" property="offlineComment" />
    <result column="province_code" property="provinceCode" />
    <result column="city_code" property="cityCode" />
    <result column="freight_id" property="freightId" />
    <result column="freight_fee" property="freightFee" />
    <result column="related_template_id_top" property="relatedTemplateIdTop" />
    <result column="related_template_id_bottom" property="relatedTemplateIdBottom" />
    <result column="goods_details" property="goodsDetails" />
    <result column="goods_parameter" property="goodsParameter" />
  </resultMap>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `extend_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.extendIdNotEquals != null">
          AND `extend_id` != #{example.extendIdNotEquals}
        </if>
        <if test="example.extendIdIn != null">
          AND `extend_id` in (${example.extendIdIn})
        </if>
        <if test="example.goodsId != null">
          AND `goods_id` = #{example.goodsId}
        </if>
        <if test="example.mainSpecId != null">
          AND `main_spec_id` = #{example.mainSpecId}
        </if>
        <if test="example.specJson != null">
          AND `spec_json` = #{example.specJson}
        </if>
        <if test="example.attributeJson != null">
          AND `attribute_json` = #{example.attributeJson}
        </if>
        <if test="example.onlineTimeAfter != null">
          AND `online_time` <![CDATA[ >= ]]> #{example.onlineTimeAfter}
        </if>
        <if test="example.onlineTimeBefore != null">
          AND `online_time` <![CDATA[ <= ]]> #{example.onlineTimeBefore}
        </if>
        <if test="example.createVendorId != null">
          AND `create_vendor_id` = #{example.createVendorId}
        </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.auditReason != null">
          AND `audit_reason` = #{example.auditReason}
        </if>
        <if test="example.auditReasonLike != null">
          AND `audit_reason` like concat('%',#{example.auditReasonLike},'%')
        </if>
        <if test="example.auditComment != null">
          AND `audit_comment` = #{example.auditComment}
        </if>
        <if test="example.followNumber != null">
          AND `follow_number` = #{example.followNumber}
        </if>
        <if test="example.clickNumber != null">
          AND `click_number` = #{example.clickNumber}
        </if>
        <if test="example.offlineReason != null">
          AND `offline_reason` = #{example.offlineReason}
        </if>
        <if test="example.offlineReasonLike != null">
          AND `offline_reason` like concat('%',#{example.offlineReasonLike},'%')
        </if>
        <if test="example.offlineComment != null">
          AND `offline_comment` = #{example.offlineComment}
        </if>
        <if test="example.provinceCode != null">
          AND `province_code` = #{example.provinceCode}
        </if>
        <if test="example.cityCode != null">
          AND `city_code` = #{example.cityCode}
        </if>
        <if test="example.freightId != null">
          AND `freight_id` = #{example.freightId}
        </if>
        <if test="example.freightFee != null">
          AND `freight_fee` = #{example.freightFee}
        </if>
        <if test="example.relatedTemplateIdTop != null">
          AND `related_template_id_top` = #{example.relatedTemplateIdTop}
        </if>
        <if test="example.relatedTemplateIdBottom != null">
          AND `related_template_id_bottom` = #{example.relatedTemplateIdBottom}
        </if>
        <if test="example.goodsDetails != null">
          AND `goods_details` = #{example.goodsDetails}
        </if>
        <if test="example.goodsParameter != null">
          AND `goods_parameter` = #{example.goodsParameter}
        </if>
        <if test="example.storeId != null">
          AND `goods_id` IN ( SELECT goods_id FROM `goods` WHERE store_id = #{example.storeId} )
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `extend_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.goods.example.GoodsExtendExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `goods_extend`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `goods_extend`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `goods_extend`
    <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 `goods_extend`
    <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 `goods_extend`
    <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 `goods_extend`
    <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="listResByExample" resultMap="resultMap">
    select goods_id, click_number, follow_number
    from goods_extend
    ORDER BY `extend_id` DESC
  </select>
</mapper>