<?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.xxfc.platform.activity.mapper.ActivityMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.activity.entity.Activity" id="activityMap">
        <result property="id" column="id"/>
        <result property="goodsType" column="goods_type"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="bmCloseTime" column="bm_close_time"/>
        <result property="trip" column="trip"/>
        <result property="provinceCode" column="province_code"/>
        <result property="province" column="province"/>
        <result property="cityCode" column="city_code"/>
        <result property="city" column="city"/>
        <result property="townCode" column="town_code"/>
        <result property="town" column="town"/>
        <result property="address" column="address"/>
        <result property="latitude" column="latitude"/>
        <result property="longitude" column="longitude"/>
        <result property="content" column="content"/>
        <result property="imgs" column="imgs"/>
        <result property="isCallTel" column="is_call_tel"/>
        <result property="status" column="status"/>
        <result property="crtTime" column="crt_time"/>
        <result property="ctrUser" column="ctr_user"/>
        <result property="updTime" column="upd_time"/>
        <result property="isDel" column="is_del"/>
        <result property="isSee" column="is_see"/>
    </resultMap>

    <select id="getAllByPage" resultType="com.xxfc.platform.activity.vo.ActivityVo" parameterType="com.xxfc.platform.activity.dto.ActivityDTO">
        select
        a.*,
        t.name as typeName,
        (
        CASE
        WHEN a.start_time >=#{time} THEN
        a.start_time -#{time}
        ELSE
        0
        END
        ) AS orderSort ,
        ( CASE
        WHEN a.start_time &lt;=  #{time} and a.end_time > #{time} THEN
        2
        WHEN a.start_time > #{time} THEN
        1
        ELSE
        3
        END
        ) AS  activityStatus

        from `activity` a
        LEFT JOIN activity_type t on a.type=t.type
        <where>
             a.is_del = 0
            <if test="goodsType != null">
                and a.`goods_type`=#{goodsType}
            </if>
            <if test="type != null">
                and a.`type`=#{type}
            </if>
            <if test="userId != null and userId > 0">
                and a.`user_id`=#{userId}
            </if>
            <if test="activityId != null and activityId > 0">
                and a.`id`=#{activityId}
            </if>
            <if test="startTime != null and  startTime > 0">
                and <![CDATA[
                a.`crt_time` >= #{startTime}
                ]]>
            </if>
            <if test="endTime != null  and  endTime > 0">
                and <![CDATA[
                a.`crt_time`<=#{endTime}
                ]]>
            </if>
        </where>
        ORDER BY activityStatus,sign(orderSort)DESC,ABS(orderSort)
    </select>
</mapper>