<?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.summit.mapper.ActivityMapper">
    <select id="selectByQuery" resultType="com.xxfc.platform.summit.entity.Activity"
            parameterType="com.xxfc.platform.summit.pojo.ActivityQuery">
        select * from fc_activity
        where
        is_del=0

        <if test="title != null and title.trim() != '' ">
            and title like CONCAT('%',#{title},'%')
        </if>
        <if test="startTime != null">
            and from_unixtime(start_time/1000,'%Y-%m-%e %H')=from_unixtime(unix_timestamp(), '%Y-%m-%e %H')
        </if>
        <if test="status != null and status == 1">
            and (status=#{status} or (status=0 and  (start_time/1000) &gt;= unix_timestamp())  )
        </if>
        <if test="status != null and status == 2">
            and (status=#{status} or (status=0 and  (start_time/1000) &lt; unix_timestamp() and (end_time/1000)&gt;=unix_timestamp()))
        </if>
        <if test="status != null and status == 3">
            and (status=#{status} or (status=0 and   (end_time/1000)&lt;unix_timestamp()))
        </if>
        <if test="type ==2">
          and  is_publish=1
          and is_show=1
        </if>
        order  by  rank asc , start_time desc
    </select>

    <select id="getdinate" parameterType="java.util.Map" resultType="BigDecimal">
         select
            IFNULL(ROUND(( (2 * ASIN( SQRT( POW( SIN((latitude * PI() / 180.0- #{params.latitude}* PI() / 180.0)/2), 2)+COS( latitude * PI() / 180.0)*COS( #{params.latitude} * PI() / 180.0)
            *POW(SIN((longitude * PI() / 180.0 - #{params.longitude}* PI() /180.0)/2),2))))*6378.137)*10000)/10000 ,0 ) AS distance
         FROM fc_activity WHERE id=#{params.id}
    </select>
</mapper>