package com.sw.mes.yb.report.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.report.entity.BrokenBractBase;
import com.sw.mes.yb.report.entity.RecycledMaterialPlan;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface RecycledMaterialPlanDao extends BaseDao<RecycledMaterialPlan, Long> {

    RecycledMaterialPlan findByDate(Date date);

        @Query(value = "select \n" +
            "time,#日期\n" +
            "ifnull(sum(weight),0) as weight,#实际产出\n" +
            "ifnull(mp.plan_value,0) as planValue#计划产出\n" +
            "from\n" +
            "(select \n" +
            "DATE_FORMAT(DATE_SUB(install_time,INTERVAL 510 MINUTE),'%m-%d') as time,\n" +
            "sum(ifnull(weight,0)) as weight\n" +
            "from production_blast_furnace_detail_log\n" +
            "WHERE \n" +
            "install_time>=CONCAT(DATE_ADD(curdate(),interval -day(curdate() - 1) day),' 08:30:00')\n" +
            "and install_time<CONCAT(DATE_ADD(last_day(curdate()),interval 1 day),' 08:30:00')\n" +
            "GROUP BY DATE_FORMAT(DATE_SUB(install_time,INTERVAL 510 MINUTE),'%m-%d')#配料\n" +
            "\n" +
            "UNION ALL\n" +
            "select \n" +
            "DATE_FORMAT(DATE_SUB(fb.end_time,INTERVAL 510 MINUTE),'%m-%d') as time,\n" +
            "sum(ifnull(fd.weight,0)) as weight\n" +
            "from production_input_furnace_detail fd \n" +
            "LEFT JOIN production_input_furnace_burden fb ON fd.again_task_detail_id=fb.id\n" +
            "WHERE \n" +
            "fb.end_time>=CONCAT(DATE_ADD(curdate(),interval -day(curdate() - 1) day),' 08:30:00')\n" +
            "and fb.end_time<CONCAT(DATE_ADD(last_day(curdate()),interval 1 day),' 08:30:00')\n" +
            "GROUP BY DATE_FORMAT(DATE_SUB(fb.end_time,INTERVAL 510 MINUTE),'%m-%d')#灌料\n" +
            ")t#实际产出\n" +
            "LEFT JOIN (\n" +
            "select \n" +
            "DATE_FORMAT(date,'%m-%d') as date,\n" +
            "plan_value \n" +
            "from recycled_material_plan \n" +
            "WHERE date>=CONCAT(DATE_ADD(curdate(),interval -day(curdate() - 1) day),' 08:30:00')\n" +
            "and date<CONCAT(DATE_ADD(last_day(curdate()),interval 1 day),' 08:30:00')\n" +
            ") mp ON t.time=mp.date#计划产出\n" +
            "GROUP BY time",nativeQuery = true)
    List<Map<String, Object>> findAllData();
}
