package com.gyee.alarm.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.alarm.model.auto.ProEconAlarmConfiguration;
import com.gyee.alarm.model.auto.ProEconRuleUpdateEvent;
import com.gyee.alarm.model.vo.AjaxResult;
import com.gyee.alarm.model.vo.AjaxStatus;
import com.gyee.alarm.service.RuleUpdateEventService;
import com.gyee.alarm.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 规则修改记录 前端控制器
 * </p>
 *
 * @author shilin
 * @since 2023-08-15
 */
@RestController
@RequestMapping("/ruleupdate")
@Api(value = "报警规则修改记录", tags = "报警规则修改记录")
public class ProEconRuleUpdateEventController {


    @Autowired
    private RuleUpdateEventService ruleUpdateEventService;

    @ApiOperation(value = "分页查询报警规则修改日志")
    @GetMapping("/page")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "pagenum", value = "页号", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pagesize", value = "每页显示多少行", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "ruleName", value = "规则名称", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "ruleType", value = "规则类型", required = false, dataType = "string", paramType = "query")})

    public AjaxResult getRuleEventLog(
            @RequestParam(value = "pagenum") Integer pageNum,
            @RequestParam(value = "pagesize") Integer pageSize,
            @RequestParam(value = "ruleName", required = false) String ruleName,
            @RequestParam(value = "ruleType", required = false) String ruleType

    ) {
        IPage updateEventByPage =new Page();
        if(StringUtils.notEmp(pageNum) && StringUtils.notEmp(pageSize))
        {
            Page<ProEconRuleUpdateEvent> page = new Page(pageNum, pageSize);

             updateEventByPage = ruleUpdateEventService.getUpdateEventByPage(page, ruleName,ruleType);
        }

        if (StringUtils.notEmp(updateEventByPage)) {

            return AjaxResult.successData(AjaxStatus.success.code, updateEventByPage);
        } else {
            return AjaxResult.successData(AjaxStatus.loginexpire.code, "error");
        }
    }

}
