<?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.environ.eco.mapper.SysFodderMapper">



    <select id="countDayValue" resultType="com.huimv.environ.eco.entity.SysFodder">

        SELECT
            id,SUM(`value`)'value' ,create_time,floor_id,fodder_id
        FROM `sys_fodder`
        ${ew.customSqlSegment}
        GROUP BY DATE_FORMAT(create_time,"%y-%m-%d")
    </select>

    <select id="countAllDayValue" resultType="com.huimv.environ.eco.entity.dto.FodderDto">

        SELECT
             DATE_FORMAT(create_time,"%m-%d") screate_time,floor_id,
            IFNULL( (SELECT SUM(`value`)  FROM `sys_fodder` WHERE floor_id =1 AND  DATE_FORMAT( f.`create_time`,"%m-%d") = DATE_FORMAT(create_time,"%m-%d")  ),0)'onevalue' ,
            IFNULL(  (SELECT SUM(`value`)  FROM `sys_fodder` WHERE floor_id =2  AND  DATE_FORMAT( f.`create_time`,"%m-%d") = DATE_FORMAT(create_time,"%m-%d") ),0) 'twovalue',
            IFNULL( (SELECT SUM(`value`)  FROM `sys_fodder` WHERE floor_id =3  AND  DATE_FORMAT( f.`create_time`,"%m-%d") = DATE_FORMAT(create_time,"%m-%d")),0) 'threevalue'
        FROM `sys_fodder` f
            ${ew.customSqlSegment}
        GROUP BY  screate_time
    </select>
    <select id="countAllValue" resultType="java.lang.Integer">
        SELECT
            IFNULL(SUM(`value`),0)
        FROM `sys_fodder`
        ${ew.customSqlSegment}

    </select>
    <select id="fodderMapper" resultType="com.huimv.environ.eco.entity.dto.ScreenDto">
      SELECT
         (SELECT MIN(`value`) FROM `sys_humidity`  WHERE TO_DAYS(`create_time`) = TO_DAYS(NOW()) AND farm_id  = #{farmId} AND `value` &gt;= 0  )minHum ,
         (SELECT MAX(`value`) FROM `sys_humidity`  WHERE TO_DAYS(`create_time`) = TO_DAYS(NOW()) AND farm_id  = #{farmId}  AND `value` &lt;= 100  )maxHum,
        (SELECT MAX(`value`) FROM `sys_temperature` WHERE TO_DAYS(`create_time`) = TO_DAYS(NOW())  AND farm_id  = #{farmId} AND `value` &lt;= 50 )maxTem,
         (SELECT MIN(`value`) FROM `sys_temperature` WHERE TO_DAYS(`create_time`) = TO_DAYS(NOW())  AND farm_id  = #{farmId}  AND `value` &gt;= -50 )minTem,
         (SELECT ROUND(SUM(`increase_value`),2) FROM`sys_month_water` WHERE TO_DAYS(`create_time`) = TO_DAYS(NOW()) AND farm_id  = #{farmId}  ) dayWater,
         (SELECT ROUND(SUM(`increase_value`),2) FROM `sys_month_water` WHERE DATE_FORMAT( `create_time`, '%Y%m' ) =DATE_FORMAT( CURDATE( ) , '%Y%m' )  AND farm_id  = #{farmId}   ) monthWater
    </select>


</mapper>
