package com.njcn.energy.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
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.common.utils.LogUtil;
import com.njcn.energy.pojo.po.EleALM;
import com.njcn.energy.service.IEleAlmService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/15 18:48
 */
@Slf4j
@RestController
@RequestMapping("/alm")
@RequiredArgsConstructor
@Api(tags = "设备告警数据管理")
public class EleAlmController extends BaseController {


    private final IEleAlmService eleAlmService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增设备告警数据")
    @ApiImplicitParam(name = "eleAlM", value = "设备告警数据", required = true)
    public HttpResult<Boolean> add(@RequestBody EleALM eleAlM){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，设备告警数据：{}", methodDescribe, eleAlM);
        boolean result = eleAlmService.addAlm(eleAlM);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PutMapping("/update")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("修改设备告警数据")
    @ApiImplicitParam(name = "eleAlM", value = "设备告警数据", required = true)
    public HttpResult<Boolean> update(@RequestBody EleALM eleAlM){
        String methodDescribe = getMethodDescribe("update");
        LogUtil.njcnDebug(log, "{}，设备告警数据：{}", methodDescribe, eleAlM);
        boolean result = eleAlmService.updateAlm(eleAlM);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @GetMapping("/findByName")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("根据名称查找数据")
    @ApiImplicitParam(name = "name", value = "名称", required = true)
    public HttpResult<EleALM> findByName(@RequestParam String name){
        String methodDescribe = getMethodDescribe("findByName");
        LogUtil.njcnDebug(log, "{}，名称为：{}", methodDescribe, name);
        EleALM eleAlM = eleAlmService.findByName(name);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eleAlM, methodDescribe);
    }


}
