package com.huimv.produce.produce.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.common.utils.DataUill;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.produce.warning.entity.ProdWarningMsg;
import com.huimv.produce.produce.entity.ProdWorkPlan;
import com.huimv.produce.warning.service.IProdWarningMsgService;
import com.huimv.produce.produce.service.IProdWorkPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  工作计划
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-25
 */
@RestController
@RequestMapping("/prodWorkPlan")
public class ProdWorkPlanController {
    @Autowired
    private IProdWorkPlanService workPlanService;

    @Autowired
    private IProdWarningMsgService warningMsgService;

    @GetMapping("/listWorkPlan")
    public Result getCost(@RequestParam(name = "farmId") Integer farmId){
        List<ProdWorkPlan> list = workPlanService.list(new QueryWrapper<ProdWorkPlan>().eq("farm_id", farmId).eq("add_time", DataUill.getTimesmorning()));
        Map endMap = new HashMap();
        for (ProdWorkPlan workPlan : list) {
            String planName = workPlan.getPlanName();
            switch (planName){
                case "转舍计划":
                    endMap.put("transferHouse",workPlan);
                    break;
                case "普免计划":
                    endMap.put("ordinary",workPlan);
                    break;
                case "日常计划":
                    endMap.put("daily",workPlan);
                    break;
                case "免疫计划":
                    endMap.put("immune",workPlan);
                    break;
            }
        }
        ProdWorkPlan prodWorkPlan = new ProdWorkPlan();
        prodWorkPlan.setPlanTimes((int)warningMsgService.count(new QueryWrapper<ProdWarningMsg>().eq("farm_id", farmId).eq("add_time", DataUill.getTimesmorning())));
        prodWorkPlan.setPlanName("报警计划");

        endMap.put("warning",prodWorkPlan);
        return new Result(ResultCode.SUCCESS,endMap);
    }

    @GetMapping("/listLargeScreen")
    public Result listLargeScreen(@RequestParam(name = "farmId") Integer farmId){

        return workPlanService.listLargeScreen( farmId);
    }


    @GetMapping("/listScreenWorkPlan")
    public Result listScreenWorkPlan(@RequestParam(name = "farmId") Integer farmId){

        return workPlanService.listScreenWorkPlan( farmId);
    }
}
