package com.jiayue.ipp.idp.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.ipp.common.data.entity.SysAlarm;
import com.jiayue.ipp.idp.service.SysAlarmService;
import com.jiayue.ipp.idp.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * idp_sys_alarm
 *
 * @author whc
 * @date 2022-03-18 15:49:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysalarm")
@Api(value = "sysalarm", tags = "idp_sys_alarm管理")
public class SysAlarmController {

    private final SysAlarmService sysAlarmService;

    /**
     * 分页查询
     *
     * @param page     分页对象
     * @param sysAlarm idp_sys_alarm
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    //@PreAuthorize("@pms.hasPermission('idp_sysalarm_get')")
    public R getSysAlarmPage(Page page, SysAlarm sysAlarm) {
        return R.ok(sysAlarmService.page(page, Wrappers.query(sysAlarm)));
    }

    /**
     * 通过id查询idp_sys_alarm
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_sysalarm_get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(sysAlarmService.getById(id));
    }

    /**
     * 新增idp_sys_alarm
     *
     * @param sysAlarm idp_sys_alarm
     * @return R
     */
    @ApiOperation(value = "新增idp_sys_alarm", notes = "新增idp_sys_alarm")
    //    @SysLog("新增idp_sys_alarm")
    @PostMapping
    //@PreAuthorize("@pms.hasPermission('idp_sysalarm_add')")
    public R save(@RequestBody SysAlarm sysAlarm) {
        return R.ok(sysAlarmService.save(sysAlarm));
    }

    /**
     * 修改idp_sys_alarm
     *
     * @param sysAlarm idp_sys_alarm
     * @return R
     */
    @ApiOperation(value = "修改idp_sys_alarm", notes = "修改idp_sys_alarm")
    //    @SysLog("修改idp_sys_alarm")
    @PutMapping
    //@PreAuthorize("@pms.hasPermission('idp_sysalarm_edit')")
    public R updateById(@RequestBody SysAlarm sysAlarm) {
        return R.ok(sysAlarmService.updateById(sysAlarm));
    }

    /**
     * 通过id删除idp_sys_alarm
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除idp_sys_alarm", notes = "通过id删除idp_sys_alarm")
    //    @SysLog("通过id删除idp_sys_alarm")
    @DeleteMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('idp_sysalarm_del')")
    public R removeById(@PathVariable String id) {
        return R.ok(sysAlarmService.removeById(id));
    }

}
