<?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="vip.xiaonuo.modular.feed.feedingfat.mapper.FeedingFatMapper">

<select id="getFeed" resultType="vip.xiaonuo.modular.feed.feedingfat.vo.FeedingFatVo">
    select
    CONVERT(IFNULL(SUM(CASE WHEN  DATE(create_time) =CURRENT_DATE THEN feed_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS todayFeed,
    CONVERT(IFNULL(SUM(CASE WHEN  DATE(create_time) =CURRENT_DATE THEN water_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS todayWater,
    CONVERT(IFNULL(SUM(CASE WHEN  DATE(create_time) =CURRENT_DATE THEN weigth_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS dayWeight,
 -- 昨日用量
    CONVERT(IFNULL(SUM(CASE WHEN create_time=DATE_SUB(CURDATE(),INTERVAL 1 DAY) THEN water_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS yesterdayWater,
    CONVERT(IFNULL(SUM(CASE WHEN create_time=DATE_SUB(CURDATE(),INTERVAL 1 DAY) THEN feed_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS yesterdayFeed
    FROM `feeding_fat` WHERE unit_id=${unitId} AND org_id =${orgId}
</select>

    <select id="listFeedPage" resultType="vip.xiaonuo.modular.feed.feedingfat.vo.FeedingFatVo">
    select
    create_time createDate,eartag_num eartagNum,device_code deviceCode,
    CONVERT(IFNULL(SUM(CASE WHEN  DATE(create_time) =CURRENT_DATE THEN feed_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS todayFeed,
    CONVERT(IFNULL(SUM(CASE WHEN  DATE(create_time) =CURRENT_DATE THEN water_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS todayWater,
    CONVERT(IFNULL(SUM(CASE WHEN  DATE(create_time) =CURRENT_DATE THEN weigth_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS dayWeight,
 -- 昨日用量
    CONVERT(IFNULL(SUM(CASE WHEN create_time=DATE_SUB(CURDATE(),INTERVAL 1 DAY) THEN water_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS yesterdayWater,
    CONVERT(IFNULL(SUM(CASE WHEN create_time=DATE_SUB(CURDATE(),INTERVAL 1 DAY) THEN feed_value ELSE 0 END), '0'), DECIMAL(10, 2)) AS yesterdayFeed
    FROM `feeding_fat`
    ${ew.customSqlSegment}
    group by eartag_num
    </select>

    <select id="listFeedDetail" resultType="vip.xiaonuo.modular.feed.feedingfat.vo.FeedingFatVo2">
        select create_time 'createDate',
        CONVERT(IFNULL(SUM(feed_value), '0'), DECIMAL(10, 2)) 'value'
        FROM feeding_fat
        ${ew.customSqlSegment}
        group BY DATE_FORMAT(create_time,'%Y-%m-%d')
        ORDER BY create_time ASC
    </select>
    <select id="listTempDetail" resultType="vip.xiaonuo.modular.feed.feedingfat.vo.FeedingFatVo2">
        select create_time 'createDate',
        CONVERT(IFNULL(SUM(temp), '0'), DECIMAL(10, 2)) 'value'
        FROM feeding_fat
        ${ew.customSqlSegment}
        group BY DATE_FORMAT(create_time,'%Y-%m-%d')
        ORDER BY create_time ASC
    </select>
    <select id="listActDetail" resultType="vip.xiaonuo.modular.feed.feedingfat.vo.FeedingFatVo2">
        select create_time 'createDate',
        CONVERT(IFNULL(SUM(feed_act), '0'), DECIMAL(10, 2)) 'value'
        FROM feeding_fat
        ${ew.customSqlSegment}
        group BY DATE_FORMAT(create_time,'%Y-%m-%d')
        ORDER BY create_time ASC
    </select>
    <select id="listWeightDetail" resultType="vip.xiaonuo.modular.feed.feedingfat.vo.FeedingFatVo2">
        select create_time 'createDate',
        CONVERT(IFNULL(SUM(weigth_value), '0'), DECIMAL(10, 2)) 'value'
        FROM feeding_fat
        ${ew.customSqlSegment}
        group BY DATE_FORMAT(create_time,'%Y-%m-%d')
        ORDER BY create_time ASC
    </select>
</mapper>