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


    <select id="listLargeScreen" resultType="com.huimv.produce.produce.entity.dto.ProdScreenDto">


            SELECT
            (SELECT IFNULL(stock_quantity,0)
            FROM `prod_stock`
             WHERE  farm_id = #{farmId}
             AND stock_name= "总存栏"  ORDER BY id DESC LIMIT 1) total,

             (SELECT IFNULL(month_money,0)
            FROM `prod_sales`
             WHERE  farm_id = #{farmId}
              ORDER BY id DESC LIMIT 1 ) money,

            IFNULL((SELECT SUM(plan_times)
            FROM `prod_work_plan`
             WHERE  farm_id = #{farmId}
              AND TO_DAYS(add_time) = TO_DAYS(NOW()) ),0)task,

           ( SELECT IFNULL(month_quantity,0)
            FROM `prod_sales`
             WHERE  farm_id = #{farmId}
              ORDER BY id DESC LIMIT 1 )quantity

    </select>
    <select id="listScreenWorkPlan" resultType="com.huimv.produce.produce.entity.dto.ScreenWorkPlan">


            SELECT
            (SELECT IFNULL(SUM(plan_times),0)
            FROM `prod_work_plan`
             WHERE  farm_id = #{farmId}
             AND plan_name= "免疫计划"   AND TO_DAYS(add_time) = TO_DAYS(NOW())  ) immunePlan,

             (SELECT IFNULL(SUM(plan_times),0)
            FROM `prod_work_plan`
             WHERE  farm_id = #{farmId}
             AND plan_name= "普免计划"   AND TO_DAYS(add_time) = TO_DAYS(NOW())  ) healthPlan,

             (SELECT IFNULL(SUM(plan_times),0)
            FROM `prod_work_plan`
             WHERE  farm_id = #{farmId}
             AND plan_name= "日常计划"   AND TO_DAYS(add_time) = TO_DAYS(NOW())  ) dayPlan,

             (SELECT IFNULL(SUM(plan_times),0)
            FROM `prod_work_plan`
             WHERE  farm_id = #{farmId}
             AND plan_name= "转舍计划"   AND TO_DAYS(add_time) = TO_DAYS(NOW())  ) turnPlan,


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

               (SELECT IFNULL(SUM(status_1),0)
            FROM `prod_sow_piglet_status`
             WHERE  farm_id = #{farmId}
              AND TO_DAYS(add_date) = TO_DAYS(NOW())  )  delivery,

               (SELECT IFNULL(SUM(status_2),0)
            FROM `prod_sow_piglet_status`
             WHERE  farm_id = #{farmId}
              AND TO_DAYS(add_date) = TO_DAYS(NOW())  )  weaning,

               (SELECT IFNULL(SUM(status_3),0)
            FROM `prod_sow_piglet_status`
             WHERE  farm_id = #{farmId}
              AND TO_DAYS(add_date) = TO_DAYS(NOW())  )  hybridization

    </select>
</mapper>
