<?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.huimv.produce.warning.mapper.BaseWarningInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.huimv.produce.warning.entity.BaseWarningInfo">
        <id column="id" property="id" />
        <result column="farm_id" property="farmId" />
        <result column="level" property="level" />
        <result column="msg" property="msg" />
        <result column="level_name" property="levelName" />
        <result column="warning_name" property="warningName" />
        <result column="warning_time" property="warningTime" />
        <result column="upload_time" property="uploadTime" />
        <result column="alarm_type" property="alarmType" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, farm_id,level,msg,level_name,warning_name,upload_time,alarm_type
    </sql>

    <!--自定义查询-->
    <select id="listBaseWarn" resultType="com.huimv.produce.warning.entity.BaseWarningInfoDto">
     SELECT msg,warning_name,warning_time  FROM  `base_warning_info`
     where upload_time BETWEEN '${startDate}' AND '${endDate}' and farm_id = ${farmId} ORDER BY upload_time DESC;
    </select>

    <!--今日查询-->
    <select id="listDayBaseWarn" resultType="com.huimv.produce.warning.entity.BaseWarningInfoDto">
   SELECT msg,warning_name,warning_time FROM  `base_warning_info`
WHERE TO_DAYS(upload_time) = TO_DAYS(NOW()) and farm_id = ${farmId} ORDER BY upload_time DESC;
    </select>
    <!--本周查询-->
    <select id="listWeekBaseWarn" resultType="com.huimv.produce.warning.entity.BaseWarningInfoDto">
   SELECT msg,warning_name,warning_time  FROM  `base_warning_info`
WHERE YEARWEEK(date_format(upload_time,'%Y-%m-%d')) = YEARWEEK(now()) and farm_id = ${farmId} ORDER BY upload_time DESC;
    </select>
    <!--本月查询-->
    <select id="listMonthBaseWarn" resultType="com.huimv.produce.warning.entity.BaseWarningInfoDto">
    SELECT msg,warning_name,warning_time FROM  `base_warning_info`
WHERE DATE_FORMAT( upload_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) AND farm_id = ${farmId} ORDER BY upload_time DESC
    </select>

    <select id="listData" resultType="com.huimv.produce.warning.entity.BaseWarningInfoDto">
    SELECT msg,warning_name,warning_time FROM  `base_warning_info`
        ${ew.customSqlSegment}
    </select>
</mapper>
