package com.huimv.admin.controller;


import com.huimv.admin.common.utils.Result;
import com.huimv.admin.entity.EnergyWarningThreshold;
import com.huimv.admin.entity.vo.EnergyThresholdVo;
import com.huimv.admin.service.IEnergyWarningThresholdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-02-14
 */
@RestController
@RequestMapping("/energy-warning-threshold")
@CrossOrigin
public class EnergyWarningThresholdController {

    @Autowired
    private IEnergyWarningThresholdService warningThresholdService;

    @RequestMapping("/list")
    public Result list(HttpServletRequest httpServletRequest, @RequestBody Map<String,String> paramsMap) {
        return warningThresholdService.list(httpServletRequest,paramsMap);
    }

    @RequestMapping("/add")
    public Result add(HttpServletRequest httpServletRequest, @RequestBody EnergyThresholdVo thresholdVo) {
        String farmId = thresholdVo.getFarmId();
        EnergyWarningThreshold energyWarningThreshold = thresholdVo.getRenChen().setFarmId(Integer.parseInt(farmId));
        EnergyWarningThreshold energyWarningThreshold1 = thresholdVo.getChanFang().setFarmId(Integer.parseInt(farmId));
        EnergyWarningThreshold energyWarningThreshold2 = thresholdVo.getBaoYu().setFarmId(Integer.parseInt(farmId));
        EnergyWarningThreshold energyWarningThreshold3 = thresholdVo.getYuFei().setFarmId(Integer.parseInt(farmId));
        EnergyWarningThreshold energyWarningThreshold4 = thresholdVo.getHouBei().setFarmId(Integer.parseInt(farmId));
        EnergyWarningThreshold energyWarningThreshold5 = thresholdVo.getGeLi().setFarmId(Integer.parseInt(farmId));
        energyWarningThreshold.setOther1("1");
        energyWarningThreshold1.setOther1("2");
        energyWarningThreshold2.setOther1("3");
        energyWarningThreshold3.setOther1("4");
        energyWarningThreshold4.setOther1("5");
        energyWarningThreshold5.setOther1("6");
        List<EnergyWarningThreshold> energyWarningThresholdList = new ArrayList<>();
        energyWarningThresholdList.add(energyWarningThreshold);
        energyWarningThresholdList.add(energyWarningThreshold1);
        energyWarningThresholdList.add(energyWarningThreshold2);
        energyWarningThresholdList.add(energyWarningThreshold3);
        energyWarningThresholdList.add(energyWarningThreshold4);
        energyWarningThresholdList.add(energyWarningThreshold5);
        return warningThresholdService.add(httpServletRequest, energyWarningThresholdList);
    }
}
