package com.huimv.produce.warning.controller;


import cn.hutool.core.util.ObjectUtil;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.produce.warning.entity.SysThreshold;
import com.huimv.produce.warning.service.ISysThresholdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/threshold")
public class SysThresholdController {


    @Autowired
    private ISysThresholdService thresholdService;

    @PostMapping("/addThreshold")
    public Result addThreshold(@RequestBody SysThreshold threshold){
        SysThreshold byId = thresholdService.getById(threshold.getFarmId());
        if (ObjectUtil.isEmpty(byId)){
            thresholdService.save(threshold);
        }else {
            thresholdService.updateById(threshold);
        }


        return new Result(10000,"设置成功",true);
    }

    @GetMapping("/getThreshold")
    public Result getThreshold(@RequestParam(name = "farmId") String farmId){
        return new Result(ResultCode.SUCCESS,thresholdService.getById(farmId));
    }

    @PostMapping("/listWarningInfoWeater")
    public Result listWarningInfoWeater(@RequestBody Map<String, String> map ) {
        return thresholdService.listWarningInfoWeater(map);
    }
}
