package com.njcn.device.pq.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.param.AlarmParam;
import com.njcn.device.pq.pojo.param.TerminalCheckParam;
import com.njcn.device.pq.pojo.vo.TerminalAlarmVO;
import com.njcn.device.pq.pojo.vo.TerminalCheckVO;
import com.njcn.device.pq.service.TerminalAlarmService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * pqs
 * 终端告警管理
 * @author cdf
 * @date 2022/5/12
 */
@Slf4j
@Api(tags = "终端告警管理")
@RestController
@RequestMapping("/alarm")
@RequiredArgsConstructor
public class TerminalAlarmController extends BaseController {

    private final TerminalAlarmService terminalAlarmService;

    /**
     * 查询告警主列表
     * @author cdf
     * @date 2022/5/17
     */
    @PostMapping("/alarmList")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询告警主列表")
    @ApiImplicitParam(name = "alarmParam", value = "告警类型")
    public HttpResult<Page<TerminalAlarmVO>> alarmInfoList(@RequestBody @Validated AlarmParam alarmParam){
        String methodDescribe = getMethodDescribe("alarmInfoList");
        Page<TerminalAlarmVO> res = terminalAlarmService.alarmList(alarmParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }

    /**
     * 获取告警详情
     * @author cdf
     * @date 2022/5/23
     */
    @PostMapping("/alarmDetail")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取告警详情")
    @ApiImplicitParam(name = "alarmParam", value = "告警类型")
    public HttpResult<List<TerminalAlarmVO>> alarmInfoDetail(@RequestBody @Validated AlarmParam alarmParam){
        String methodDescribe = getMethodDescribe("alarmInfoDetail");
        List<TerminalAlarmVO> res = terminalAlarmService.alarmDetail(alarmParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    /**
     * 批量修改告警
     * @author cdf
     * @date 2022/5/23
     */
    @PostMapping("updateAlarmInfo")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.UPDATE)
    @ApiOperation("批量修改告警")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "告警类型"),
            @ApiImplicitParam(name = "devLineId", value = "监测点装置id"),

    })
    public HttpResult<Object> updateAlarmInfo(@RequestParam("type") String type,@RequestParam("devLineId")String devLineId){
        String methodDescribe = getMethodDescribe("updateAlarmInfo");
        terminalAlarmService.updateAlarmInfo(type,devLineId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    /**
     * 终端周期检测告警
     * @author cdf
     * @date 2022/5/23
     */
    @PostMapping("/terminalCheckPage")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("终端检测告警")
    @ApiImplicitParam(name = "terminalCheckParam", value = "告警类型")
    public HttpResult<Page<TerminalCheckVO>> terminalCheckPage(@RequestBody @Validated TerminalCheckParam terminalCheckParam){
        String methodDescribe = getMethodDescribe("terminalCheckPage");
        Page<TerminalCheckVO> res = terminalAlarmService.terminalCheckPage(terminalCheckParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }

}
