package com.huimv.admin.controller;


import com.huimv.admin.common.utils.Result;
import com.huimv.admin.entity.ProtThreshold;
import com.huimv.admin.entity.vo.ProtThresholdVo;
import com.huimv.admin.service.IProtThresholdService;
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-14
 */
@RestController
@CrossOrigin
@RequestMapping("/prot-threshold")
public class ProtThresholdController {
    @Autowired
    private IProtThresholdService protThresholdService;

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

    @RequestMapping("/add")
    public Result add(HttpServletRequest httpServletRequest, @RequestBody ProtThresholdVo protThresholdVo) {
        String farmId = protThresholdVo.getFarmId();
        ProtThreshold protThreshold = protThresholdVo.getIn().setFarmId(Integer.parseInt(farmId));
        ProtThreshold protThreshold1 = protThresholdVo.getDeal().setFarmId(Integer.parseInt(farmId));
        ProtThreshold protThreshold2 = protThresholdVo.getOut().setFarmId(Integer.parseInt(farmId));
         protThreshold.setProtType(1);
         protThreshold1.setProtType(2);
         protThreshold2.setProtType(3);
        List<ProtThreshold> protThresholdList = new LinkedList<>();
        protThresholdList.add(protThreshold);
        protThresholdList.add(protThreshold1);
        protThresholdList.add(protThreshold2);
        return protThresholdService.add(httpServletRequest,protThresholdList);
    }
}
