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.newWarning.entity.WarningJh;
import org.jeecg.modules.newWarning.service.WarningJhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

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


    @Autowired
    private WarningJhService warningJhService;

    //@GetMapping("/list")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<?> getAllJh(){
        List<WarningJh> list = warningJhService.list();
        return Result.OK(list);
    }

    @GetMapping("/detail")
    public Result<?> getDetailJh(@RequestParam(name="id",required=true) String id){
        WarningJh one = warningJhService.getById(id);
        return Result.OK(one);
    }

    @GetMapping("/del")
    public Result<?> delById(@RequestParam(name="id",required=true) String id){
        warningJhService.removeById(id);
        return Result.OK();
    }


    @GetMapping("/page")
    public Result<?> page(WarningJh warningJh,
                                @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        QueryWrapper<WarningJh> wrapper =new QueryWrapper<>();
        if(warningJh.getJh()!=null&& !Objects.equals(warningJh.getJh(), "")){
            wrapper.eq("jh",warningJh.getJh());
        }
        Page<WarningJh> page=new Page<WarningJh>(pageNo, pageSize);
        Page<WarningJh> pagelist = warningJhService.page(page, wrapper);
        return Result.OK(pagelist);
    }
    @PostMapping("/save")
    public Result<?> saveJh(@RequestBody WarningJh warningJh){
        warningJhService.saveOrUpdate(warningJh);
        return Result.OK();
    }

}
