<?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.produce.mapper.ProdSalesMapper">


    <select id="countMonth" resultType="com.huimv.produce.produce.entity.dto.ProdSalesDto">
        SELECT
        IFNULL(SUM(today_quantity),0) quantity,IFNULL(SUM(today_money),0) money
        FROM `prod_sales`
        ${ew.customSqlSegment}

    </select>
    <select id="listClientHome" resultType="com.huimv.produce.produce.entity.dto.ClientHomeDto">


        SELECT
        (SELECT COUNT(*)
        FROM `prod_warning_msg`
        WHERE farm_id = #{farmId} AND TO_DAYS(add_time) = TO_DAYS(NOW())) warning,

       IFNULL((SELECT today_money
        FROM `prod_sales`
        WHERE farm_id = #{farmId} AND TO_DAYS(NOW( ) ) - TO_DAYS( add_date) = 1  ) ,0)money,

       IFNULL ( (SELECT today_quantity
        FROM `prod_sales`
        WHERE farm_id = #{farmId} AND TO_DAYS(NOW( ) ) - TO_DAYS( add_date) = 1  ),0) quantity,

        IFNULL (( SELECT SUM(today_quantity)
        FROM `prod_sales`
        WHERE farm_id =  #{farmId}  AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) &lt;=DATE(add_date)) ,0) weekQuantity
    </select>
</mapper>
