package com.njcn.energy.controller;

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.energy.pojo.param.EleParam;
import com.njcn.energy.pojo.vo.EleStatisticalTreeVO;
import com.njcn.energy.pojo.vo.EleStatisticalVO;
import com.njcn.energy.service.EleStatisticalSetService;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用能统计类型配置
 *
 * @author denghuajun
 * @version 1.0.0
 * @date 2022年04月14日 15:13
 */
@Slf4j
@RestController
@RequestMapping("/statistical")
@RequiredArgsConstructor
@Api(tags = "用能统计类型配置")
public class EleStatisticalSetController extends BaseController {

    private final EleStatisticalSetService eleStatisticalSetService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getEleStatisticalDetail")
    @ApiOperation("用能统计配置详情")
    public HttpResult<List<EleStatisticalVO>> getEleStatisticalDetail() {
        String methodDescribe = getMethodDescribe("getEleStatisticalDetail");
        List<EleStatisticalVO> list = eleStatisticalSetService.getEleStatisticalDetail();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEleStatisticalTree")
    @ApiOperation("用能统计配置树")
    @ApiImplicitParam(name = "eleStatisticalVO", value = "配置参数", required = true)
    public HttpResult<EleStatisticalTreeVO> getEleStatisticalTree(@RequestBody @Validated EleStatisticalVO eleStatisticalVO) {
        String methodDescribe = getMethodDescribe("getEleStatisticalTree");
        EleStatisticalTreeVO list = eleStatisticalSetService.getEleStatisticalTree(eleStatisticalVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("用能统计绑定指标")
    @ApiImplicitParam(name = "eleParam", value = "统计类型配置参数", required = true)
    public HttpResult<Boolean> add(@RequestBody @Validated EleParam eleParam) {
        String methodDescribe = getMethodDescribe("add");
        Boolean list = eleStatisticalSetService.add(eleParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
