package com.gyee.alarm.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.alarm.init.CacheContext;
import com.gyee.alarm.model.auto.ProEconAlarmSwitch;
import com.gyee.alarm.model.auto.ProEconAlarmSwitch;
import com.gyee.alarm.model.vo.*;
import com.gyee.alarm.service.AlarmSwitchService;
import com.gyee.alarm.util.ExcelUtils;
import com.gyee.alarm.util.StringUtils;
import com.gyee.common.util.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;


@Slf4j
@RestController
@RequestMapping("/alarmswitch")
@CrossOrigin
@Api(value = "报警开关", tags = "报警开关")
public class AlarmSwitchController {


    @Autowired
    private AlarmSwitchService alarmSwitchService;

    @GetMapping(value = "/queryAll")
    @ApiOperation(value = "报警开关信息", notes = "报警开关信息")
    @ApiImplicitParams({})
    public AjaxResult queryAll() {

        List<ProEconAlarmSwitch> vos=new ArrayList<>();

        vos= alarmSwitchService.queryAll();

        if (StringUtils.notEmp(vos)) {

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

    //@UserLoginToken
    @PostMapping(value = "/save")
    @ResponseBody
    @ApiOperation(value = "进行修改和保存", notes = "进行修改和保存")
    public AjaxResult saveAndUpdateAlertrule(HttpServletRequest request, @RequestBody ProEconAlarmSwitch alarmRule) throws Exception {


        if (StringUtils.notEmp(alarmRule)) {

            boolean result = alarmSwitchService.saveAndUpdateAlertrule(alarmRule);

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


    }

    @DeleteMapping(value = "/delete")
    @ApiOperation(value = "删除", notes = "删除")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "id", value = "报警主键", required = true, dataType = "string", paramType = "query")})
    public AjaxResult deleteAlertrule(String id) {

        boolean i = alarmSwitchService.deleteAlertrule(id);

        if (StringUtils.notEmp(i)) {
            return AjaxResult.successData(AjaxStatus.success.code, i);
        } else {
            return AjaxResult.successData(AjaxStatus.error.code, "error");
        }
    }




}
