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.EleEpdPqd;
import com.njcn.energy.service.IEleEpdPqdService;
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.web.bind.annotation.*;

import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/15 10:02
 */
@Slf4j
@RestController
@RequestMapping("/epd")
@RequiredArgsConstructor
@Api(tags = "电能质量数据管理")
public class EleEpdPqdController extends BaseController {

    private final IEleEpdPqdService eleEpdPqdService;

    @PostMapping("/add")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("新增电能质量数据")
    @ApiImplicitParam(name = "eleEpdPqd", value = "电能质量数据", required = true)
    public HttpResult<Boolean> add(@RequestBody EleEpdPqd eleEpdPqd){
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，电能质量数据为：{}", methodDescribe, eleEpdPqd);
        boolean result = eleEpdPqdService.addEpd(eleEpdPqd);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);

    }

    @PutMapping("/update")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("修改电能质量数据")
    @ApiImplicitParam(name = "eleEpdPqd", value = "电能质量数据", required = true)
    public HttpResult<Boolean> update(@RequestBody EleEpdPqd eleEpdPqd){
        String methodDescribe = getMethodDescribe("update");
        LogUtil.njcnDebug(log, "{}，电能质量数据为：{}", methodDescribe, eleEpdPqd);
        boolean result = eleEpdPqdService.updateEpd(eleEpdPqd);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @GetMapping("/findByName")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("根据名称查找数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", required = true),
            @ApiImplicitParam(name = "phase", value = "相别", required = true)
    })

    public HttpResult<EleEpdPqd> findByName(@RequestParam String name,@RequestParam String phase){
        String methodDescribe = getMethodDescribe("findByName");
        LogUtil.njcnDebug(log, "{}，名称为：{}", methodDescribe, name);
        EleEpdPqd eleEpdPqd = eleEpdPqdService.findByName(name,phase);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eleEpdPqd, methodDescribe);
    }


    @GetMapping("/getAllEpd")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取所有负荷指标")
    public HttpResult<List<EleEpdPqd>> getAllEpd() {
        String methodDescribe = getMethodDescribe("getAllEpd");
        List<EleEpdPqd> res = eleEpdPqdService.getAllEpd();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);

    }

}
