package com.zcxk.rmcp.web.controller;


import com.zcxk.core.common.enums.RespCodeEnum;
import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.core.mysql.pageing.Pagination;
import com.zcxk.rmcp.api.dto.alarm.AlarmTypeDto;
import com.zcxk.rmcp.api.dto.alarm.AlarmTypePageDto;
import com.zcxk.rmcp.web.service.AlarmTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author heyumin
 * @date 2021-07-30 9:44
 */
@Controller
@ResponseBody
@RequestMapping("alarmType")
@Api(tags = "异常类型管理")
public class AlarmTypeController {

    @Autowired
    private AlarmTypeService alarmTypeService;

    @PostMapping("/getAlarmTypePage")
    @ApiOperation(value = "查询异常类型分页")
    public AjaxMessage<Pagination<AlarmTypeDto>> getAlarmTypePage(
            @RequestBody AlarmTypePageDto alarmTypePageDto) {
        Pagination<AlarmTypeDto> pageInfo = alarmTypeService.getAlarmTypePage(alarmTypePageDto);
        return AjaxMessage.success(pageInfo);
    }

    @GetMapping("/getAlarmTypeList")
    @ApiOperation(value = "查询异常类型列表")
    public AjaxMessage<List<AlarmTypeDto>> getAlarmTypeList(
    ) {
        List<AlarmTypeDto> list = alarmTypeService.getAlarmTypeList();
        return  AjaxMessage.success(list);
    }



    @PostMapping("add")
    @ApiOperation(value = "添加异常类型")
    public AjaxMessage <Void> add(
            @ApiParam(value = "异常类型", required = true) @RequestBody AlarmTypeDto alarmType
    ) {
        alarmTypeService.add(alarmType);
        return AjaxMessage.success();
    }

    @PostMapping("edit")
    @ApiOperation(value = "编辑异常类型")
    public AjaxMessage <Void> edit(
            @ApiParam(value = "异常类型", required = true) @RequestBody AlarmTypeDto alarmType
    ) {
        alarmTypeService.edit(alarmType);
        return AjaxMessage.success();
    }

    @PostMapping("delete")
    @ApiOperation(value = "删除")
    public AjaxMessage <Void> delete(
            @ApiParam(value = "异常类型id", required = true) @RequestBody List<Integer>ids
    ) {
        int result=alarmTypeService.delete(ids);
        if(result==1){
            return AjaxMessage.fail(RespCodeEnum.ALAM_TYPE_DELETION_ERROR);

        }
        return AjaxMessage.success();
    }
    @PostMapping("deleteAll")
    @ApiOperation(value = "删除全部")
    public AjaxMessage <Void> deleteAll()

     {
        int result=alarmTypeService.deleteAll();
        if(result==1){
            return AjaxMessage.fail(RespCodeEnum.ALAM_TYPE_DELETION_ERROR);
        }
         return AjaxMessage.success();
    }

    @PostMapping("updateStatus")
    @ApiOperation(value = "启用/禁用异常类型")
    public AjaxMessage <Void> updateStatus(
            @ApiParam(value = "异常类型id", required = true) @RequestParam(required = true) Integer id
    ) {
        alarmTypeService.updateStatus(id);
        return AjaxMessage.success();
    }


}
