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.EleEvt;
import com.njcn.energy.pojo.po.EleEvtParm;
import com.njcn.energy.service.IEleEvtParamService;
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 16:18
 */
@Slf4j
@RestController
@RequestMapping("/evtParam")
@RequiredArgsConstructor
@Api(tags = "单个设备事件数据管理")
public class EleEvtParamController extends BaseController {

    private final IEleEvtParamService eleEvtParamService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "eleEvtParam", value = "数据", required = true)
    public HttpResult<Boolean> add(@RequestBody EleEvtParm eleEvtParam){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，数据：{}", methodDescribe, eleEvtParam);
        boolean result = eleEvtParamService.addEleEvtParam(eleEvtParam);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

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

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

    @DeleteMapping("/deleteById")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("根据id删除数据")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    public HttpResult<Boolean> deleteById(@RequestParam String id){
        String methodDescribe = getMethodDescribe("deleteById");
        LogUtil.njcnDebug(log, "{}，id：{}", methodDescribe, id);
        boolean result = eleEvtParamService.deleteById(id);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }


}
