ZhuDongming
2019-07-25 9a8498f1dbe3b7362a1a90682edfe062517e42c2
src/main/resources/mapper/HistoryMinutelyMapper.xml
@@ -93,14 +93,17 @@
                  </foreach>
               </otherwise>
            </choose>
           DATE_FORMAT(time,'${@com.moral.common.util.ReportTimeFormat@toMySqlTimeFormat(timePeriod.timeUnits)}') as format_time
        DATE_FORMAT(time,'${@com.moral.common.util.ReportTimeFormat@toMySqlTimeFormat(timePeriod.timeUnits)}') as
        format_time
           FROM
         `history_minutely` hmi
         <where>
            and hmi.time >= #{timePeriod.startTime}
            and hmi.time <![CDATA[<=]]> #{timePeriod.endTime}
            <if test="dataCondition.actualTime != null">
               and DATE_FORMAT(time,   '${@com.moral.common.util.ReportTimeFormat@toMySqlActualTimeFormat(dataCondition.timeUnits)}') = #{dataCondition.actualTime}
                and DATE_FORMAT(time,
                '${@com.moral.common.util.ReportTimeFormat@toMySqlActualTimeFormat(dataCondition.timeUnits)}') =
                #{dataCondition.actualTime}
            </if>
            and hmi.mac in (
            select mac from device dev
@@ -132,4 +135,38 @@
         </if>
          ORDER BY format_time asc
   </select>
    <!-- 无人机sensor查询 -->
    <select id="getSensorData" resultType="java.util.LinkedHashMap">
        SELECT
        <foreach collection="sensorKeys"
                 item="sensorKey" separator="," close=",">
            hm.json->'$.${sensorKey}[0]' as '${sensorKey}'
        </foreach>
        DATE_FORMAT(hm.time,'%Y-%m-%d %H:%i:%s') as uavDate
        FROM
        history_minutely as hm
        <where>
            <if test="mac!=null and mac!=''">
                and hm.mac=#{mac}
            </if>
        </where>
        <choose>
            <when test="startTime !=null and startTime != '' and endTime!=null and endTime !='' ">
                and hm.time >= #{startTime}
                and hm.time <![CDATA[<=]]> #{endTime}
            </when>
            <when test="startTime !=null and startTime != '' ">
                and hm.time >= #{startTime}
            </when>
            <when test="endTime !=null and endTime != '' ">
                and hm.time <![CDATA[<=]]> #{endTime}
            </when>
            <otherwise>
                and hm.time >= DATE_ADD(NOW(), INTERVAL -30 MINUTE)
                and hm.time <![CDATA[<=]]> now()
            </otherwise>
        </choose>
        ORDER BY hm.time
    </select>
</mapper>