package org.jeecg.modules.newWarning.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.dataVue.entity.OperatingConditionThreshold;
import org.jeecg.modules.dataVue.service.OperatingConditionThresholdService;
import org.jeecg.modules.newWarning.entity.NewWarnHistory;
import org.jeecg.modules.newWarning.entity.RecalculateWarn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 预警监测表 前端控制器
 * </p>
 *
 * @author zrj
 * @since 2022-12-09
 */
@RestController
@RequestMapping("/newWarn/OperatingConditionThreshold")
@Slf4j
public class OperatingConditionThresholdController {


    @Autowired
    private OperatingConditionThresholdService service;


    @GetMapping("/page")
    public Result<?> page(@RequestParam("jh")String jh,
                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                          @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        QueryWrapper<OperatingConditionThreshold> wrapper =new QueryWrapper<>();
        if(jh!=null&& !Objects.equals(jh, "")){
            wrapper.like("jh",jh);
        }
        wrapper.orderByDesc("jh");
        Page<OperatingConditionThreshold> page=new Page<OperatingConditionThreshold>(pageNo, pageSize);
        Page<OperatingConditionThreshold> pagelist = service.page(page, wrapper);
        return Result.OK(pagelist);
    }

    @GetMapping("/getByJh")
    public Result<?> getByJh(@RequestParam(name="jh",required=true) String jh){
        QueryWrapper<OperatingConditionThreshold> wrapper =new QueryWrapper<>();
        wrapper.eq("JH",jh);
        OperatingConditionThreshold one = service.getOne(wrapper);
        return Result.OK(one);
    }

    @PostMapping("/save")
    public Result<?> saveJh(@RequestBody OperatingConditionThreshold OperatingConditionThreshold){
        service.saveOrUpdate(OperatingConditionThreshold);
        return Result.OK();
    }

}
