package com.huimv.admin.controller;


import com.huimv.admin.common.utils.Result;
import com.huimv.admin.entity.GasThreshold;
import com.huimv.admin.entity.ProtThreshold;
import com.huimv.admin.entity.vo.GasThresholdVo;
import com.huimv.admin.service.IGasThresholdService;
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.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 气体阈值 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-02-21
 */
@RestController
@RequestMapping("/gas-threshold")
@CrossOrigin
public class GasThresholdController {

    @Autowired
    private IGasThresholdService gasThresholdService;

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

    @RequestMapping("/edit")
    public Result list(HttpServletRequest httpServletRequest, @RequestBody GasThresholdVo gasThresholdVo) {
        String farmId = gasThresholdVo.getFarmId();
        GasThreshold gasThreshold = gasThresholdVo.getPigpen().setFarmId(Integer.parseInt(farmId));
        gasThreshold.setGasType(1);
        GasThreshold gasThreshold1 = gasThresholdVo.getPeople().setFarmId(Integer.parseInt(farmId));
        GasThreshold gasThreshold2 = gasThresholdVo.getAbove().setFarmId(Integer.parseInt(farmId));
        GasThreshold gasThreshold3 = gasThresholdVo.getUnder().setFarmId(Integer.parseInt(farmId));
        gasThreshold1.setGasType(4);
        gasThreshold2.setGasType(2);
        gasThreshold3.setGasType(3);
        List<GasThreshold> gasThresholds = new LinkedList<>();
        gasThresholds.add(gasThreshold);
        gasThresholds.add(gasThreshold1);
        gasThresholds.add(gasThreshold2);
        gasThresholds.add(gasThreshold3);
        return gasThresholdService.edit(httpServletRequest, gasThresholds);
    }
}
