<?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.promotion.SpellTeamReadMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.promotion.pojo.SpellTeam">
    <id column="spell_team_id" property="spellTeamId" />
    <result column="spell_id" property="spellId" />
    <result column="spell_name" property="spellName" />
    <result column="store_id" property="storeId" />
    <result column="goods_id" property="goodsId" />
    <result column="goods_name" property="goodsName" />
    <result column="goods_image" property="goodsImage" />
    <result column="end_time" property="endTime" />
    <result column="finish_time" property="finishTime" />
    <result column="finish_type" property="finishType" />
    <result column="leader_member_id" property="leaderMemberId" />
    <result column="leader_member_name" property="leaderMemberName" />
    <result column="leader_pay_state" property="leaderPayState" />
    <result column="required_num" property="requiredNum" />
    <result column="joined_num" property="joinedNum" />
    <result column="state" property="state" />
    <result column="create_time" property="createTime" />
  </resultMap>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `spell_team_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.spellTeamIdNotEquals != null">
          AND `spell_team_id` != #{example.spellTeamIdNotEquals}
        </if>
        <if test="example.spellTeamIdIn != null">
          AND `spell_team_id` in (${example.spellTeamIdIn})
        </if>
        <if test="example.spellId != null">
          AND `spell_id` = #{example.spellId}
        </if>
        <if test="example.spellName != null">
          AND `spell_name` = #{example.spellName}
        </if>
        <if test="example.spellNameLike != null">
          AND `spell_name` like concat('%',#{example.spellNameLike},'%')
        </if>
        <if test="example.storeId != null">
          AND `store_id` = #{example.storeId}
        </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.goodsImage != null">
          AND `goods_image` = #{example.goodsImage}
        </if>
        <if test="example.endTimeAfter != null">
          AND `end_time` <![CDATA[ >= ]]> #{example.endTimeAfter}
        </if>
        <if test="example.endTimeBefore != null">
          AND `end_time` <![CDATA[ <= ]]> #{example.endTimeBefore}
        </if>
        <if test="example.finishTimeAfter != null">
          AND `finish_time` <![CDATA[ >= ]]> #{example.finishTimeAfter}
        </if>
        <if test="example.finishTimeBefore != null">
          AND `finish_time` <![CDATA[ <= ]]> #{example.finishTimeBefore}
        </if>
        <if test="example.finishType != null">
          AND `finish_type` = #{example.finishType}
        </if>
        <if test="example.leaderMemberId != null">
          AND `leader_member_id` = #{example.leaderMemberId}
        </if>
        <if test="example.leaderMemberName != null">
          AND `leader_member_name` = #{example.leaderMemberName}
        </if>
        <if test="example.leaderMemberNameLike != null">
          AND `leader_member_name` like concat('%',#{example.leaderMemberNameLike},'%')
        </if>
        <if test="example.leaderPayState != null">
          AND `leader_pay_state` = #{example.leaderPayState}
        </if>
        <if test="example.requiredNum != null">
          AND `required_num` = #{example.requiredNum}
        </if>
        <if test="example.joinedNum != null">
          AND `joined_num` = #{example.joinedNum}
        </if>
        <if test="example.state != null">
          AND `state` = #{example.state}
        </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.orderSnLike != null">
          AND `spell_team_id` in (select `spell_team_id` from `promotion_spell_team_member` where `order_sn` like CONCAT('%',#{example.orderSnLike},'%'))
        </if>
        <if test="example.memberNameLike != null">
          AND `spell_team_id` in (select `spell_team_id` from `promotion_spell_team_member` where `member_name` like CONCAT('%',#{example.memberNameLike},'%'))
        </if>
        <if test="example.orderStartTime != null">
          AND `spell_team_id` in (select `spell_team_id` from `promotion_spell_team_member`
          where `participate_time` <![CDATA[ >= ]]> #{example.orderStartTime} and `participate_time` <![CDATA[ <= ]]> #{example.orderEndTime})
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `spell_team_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.promotion.example.SpellTeamExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `promotion_spell_team`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_spell_team`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `promotion_spell_team`
    <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 `promotion_spell_team`
    <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 `promotion_spell_team`
    <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 `promotion_spell_team`
    <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>