<?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.GoodsCommentReadMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.goods.pojo.GoodsComment">
    <id column="comment_id" property="commentId" />
    <result column="member_id" property="memberId" />
    <result column="member_name" property="memberName" />
    <result column="score" property="score" />
    <result column="content" property="content" />
    <result column="create_time" property="createTime" />
    <result column="goods_id" property="goodsId" />
    <result column="goods_name" property="goodsName" />
    <result column="product_id" property="productId" />
    <result column="spec_values" property="specValues" />
    <result column="store_id" property="storeId" />
    <result column="store_name" property="storeName" />
    <result column="order_sn" property="orderSn" />
    <result column="order_product_id" property="orderProductId" />
    <result column="reply_id" property="replyId" />
    <result column="reply_name" property="replyName" />
    <result column="reply_content" property="replyContent" />
    <result column="state" property="state" />
    <result column="admin_id" property="adminId" />
    <result column="image" property="image" />
  </resultMap>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `comment_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.commentIdNotEquals != null">
          AND `comment_id` != #{example.commentIdNotEquals}
        </if>
        <if test="example.commentIdIn != null">
          AND `comment_id` in (${example.commentIdIn})
        </if>
        <if test="example.memberId != null">
          AND `member_id` = #{example.memberId}
        </if>
        <if test="example.memberName != null">
          AND `member_name` = #{example.memberName}
        </if>
        <if test="example.memberNameLike != null">
          AND `member_name` like concat('%',#{example.memberNameLike},'%')
        </if>
        <if test="example.score != null">
          AND `score` = #{example.score}
        </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.goodsId != null">
          AND `goods_id` = #{example.goodsId}
        </if>
        <if test="example.goodsName != null">
          AND `goods_name` = #{example.goodsName}
        </if>
        <if test="example.goodsNameLike != null">
          AND `goods_name` like concat('%',#{example.goodsNameLike},'%')
        </if>
        <if test="example.productId != null">
          AND `product_id` = #{example.productId}
        </if>
        <if test="example.specValues != null">
          AND `spec_values` = #{example.specValues}
        </if>
        <if test="example.storeId != null">
          AND `store_id` = #{example.storeId}
        </if>
        <if test="example.storeName != null">
          AND `store_name` = #{example.storeName}
        </if>
        <if test="example.storeNameLike != null">
          AND `store_name` like concat('%',#{example.storeNameLike},'%')
        </if>
        <if test="example.orderSn != null">
          AND `order_sn` = #{example.orderSn}
        </if>
        <if test="example.orderSnLike != null">
          AND `order_sn` like concat('%',#{example.orderSnLike},'%')
        </if>
        <if test="example.orderProductId != null">
          AND `order_product_id` = #{example.orderProductId}
        </if>
        <if test="example.replyId != null">
          AND `reply_id` = #{example.replyId}
        </if>
        <if test="example.replyName != null">
          AND `reply_name` = #{example.replyName}
        </if>
        <if test="example.replyNameLike != null">
          AND `reply_name` like concat('%',#{example.replyNameLike},'%')
        </if>
        <if test="example.replyContent != null">
          AND `reply_content` = #{example.replyContent}
        </if>
        <if test="example.replyContentLike != null">
          AND `reply_content` like concat('%',#{example.replyContentLike},'%')
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </if>
        <if test="example.stateIn != null">
          AND `state` in (${example.stateIn})
        </if>
        <if test="example.stateNotIn != null">
          AND `state` not in (${example.stateNotIn})
        </if>
        <if test="example.stateNotEquals != null">
          AND `state` != #{example.stateNotEquals}
        </if>
        <if test="example.adminId != null">
          AND `admin_id` = #{example.adminId}
        </if>
        <if test="example.image != null">
          AND `image` = #{example.image}
        </if>
        <if test="example.gradeName != null and example.gradeName !='' and example.gradeName == 'high'">
          AND `score` &gt; 3
        </if>
        <if test="example.gradeName != null and example.gradeName !='' and example.gradeName == 'middle'">
          AND `score` IN (2,3)
        </if>
        <if test="example.gradeName != null and example.gradeName !='' and example.gradeName == 'low'">
          AND `score` = 1
        </if>
        <if test="example.gradeName != null and example.gradeName !='' and example.gradeName == 'hasPic'">
          AND `image` is NOT NULL AND `image` != ''
        </if>
        <if test="example.scores != null and example.scores !=''">
          AND `score` IN  (${example.scores})
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `comment_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.GoodsCommentExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `goods_comment`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `goods_comment`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `goods_comment`
    <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_comment`
    <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_comment`
    <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_comment`
    <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="avgScoreByExample" resultType="java.lang.Integer">
    SELECT
    sum(score)
    FROM `goods_comment`
    <include refid="whereCondition" />
  </select>
</mapper>