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.po.EleRateSet;
import com.njcn.energy.pojo.vo.EleRateVO;
import com.njcn.energy.service.EleRateSetService;
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月13日 19:34
 */
@Slf4j
@RestController
@RequestMapping("/rate")
@RequiredArgsConstructor
@Api(tags = "电度费率配置")
public class EleRateSetController extends BaseController {

    private final EleRateSetService eleRateSetService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getEleRateDetail")
    @ApiOperation("费率详情")
    public HttpResult<List<EleRateVO>> getEleRateDetail() {
        String methodDescribe = getMethodDescribe("getEleRateDetail");
        List<EleRateVO> list = eleRateSetService.getEleRateDetail();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("费率配置")
    @ApiImplicitParam(name = "eleRateSet", value = "费率参数", required = true)
    public HttpResult<Boolean> add(@RequestBody @Validated EleRateSet eleRateSet) {
        String methodDescribe = getMethodDescribe("save");
        Boolean list = eleRateSetService.add(eleRateSet);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}
