<?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.SysDayWaterMapper">

    <select id="countWater" resultType="java.lang.Double">
        SELECT  ROUND(SUM(`increase_value`),2)
        FROM   `sys_month_water`
        ${ew.customSqlSegment}

    </select>
    <select id="listAllWater" resultType="com.huimv.environ.eco.entity.SysDayWater">

        SELECT
        id,ROUND(SUM(`increase_value`),2) 'value' , create_time, room_id,month_water_id FROM `sys_month_water`

            ${ew.customSqlSegment}

              GROUP BY DATE_FORMAT(create_time,"%y-%m-%d")

    </select>
    <select id="listDay" resultType="com.huimv.environ.eco.entity.SysDayWater">

          SELECT id, IFNULL(ROUND(SUM(`increase_value`),2),0) 'value' ,create_time ,room_id,farm_id FROM `sys_month_water`
        ${ew.customSqlSegment}

       GROUP BY DATE_FORMAT( `create_time`, '%m%d' )
    </select>


    <select id="countMonthAndWeek" resultType="com.huimv.environ.eco.entity.dto.DayWaterDto">
                    SELECT
             (SELECT
             IFNULL(ROUND(SUM(`increase_value`),2) ,0)
            FROM  `sys_month_water`
                ${ew.customSqlSegment} AND PERIOD_DIFF( DATE_FORMAT( NOW( ) , '%Y%m' ) , DATE_FORMAT( create_time, '%Y%m' ) ) =1 ) lastMonth,


            (SELECT
           IFNULL(ROUND(SUM(`increase_value`),2) ,0)
            FROM  `sys_month_water`
              ${ew.customSqlSegment} AND PERIOD_DIFF( DATE_FORMAT( NOW( ) , '%Y%m' ) , DATE_FORMAT( create_time, '%Y%m' ) ) =2) lastTwoMonth,


            (SELECT
         IFNULL(ROUND(SUM(`increase_value`),2) ,0)
            FROM  `sys_month_water`
               ${ew.customSqlSegment} AND YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) =YEARWEEK(NOW())-1 ) lastWeek,


            (SELECT
           IFNULL(ROUND(SUM(`increase_value`),2) ,0)
            FROM  `sys_month_water`
               ${ew.customSqlSegment} AND YEARWEEK(DATE_FORMAT(create_time,'%Y-%m-%d')) =YEARWEEK(NOW())-2 )lastTwoWeek


    </select>


</mapper>
