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.EleLoadSetTreeVO;
import com.njcn.energy.pojo.vo.EleLoadSetVO;
import com.njcn.energy.service.EleLoadSetService;
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("/loadset")
@RequiredArgsConstructor
@Api(tags = "用能负荷类型配置")
public class EleLoadSetController extends BaseController {

    private final EleLoadSetService eleLoadSetService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getEleLoadSetDetail")
    @ApiOperation("用能负荷类型配置详情")
    public HttpResult<List<EleLoadSetVO>> getEleLoadSetDetail() {
        String methodDescribe = getMethodDescribe("getEleLoadSetDetail");
        List<EleLoadSetVO> list = eleLoadSetService.getEleLoadSetDetail();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEleLoadSetTree")
    @ApiOperation("用能负荷类型配置树")
    @ApiImplicitParam(name = "eleLoadSetVO", value = "配置参数", required = true)
    public HttpResult<EleLoadSetTreeVO> getEleLoadSetTree(@RequestBody @Validated EleLoadSetVO eleLoadSetVO) {
        String methodDescribe = getMethodDescribe("getEleLoadSetTree");
        EleLoadSetTreeVO list = eleLoadSetService.getEleLoadTree(eleLoadSetVO);
        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 = eleLoadSetService.add(eleParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
