package com.njcn.device.pms.controller.majornetwork;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.BizParamConstant;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pms.pojo.param.ROperatingIndexParam;
import com.njcn.device.pms.pojo.vo.ROperatingIndexCommonVO;
import com.njcn.device.pms.service.majornetwork.ROperatingIndexMService;
import com.njcn.device.pms.service.majornetwork.ROperatingIndexYService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Title ROperatingIndexController
 * @Package com.njcn.device.pms.controller.majornetwork
 * @Author jianghaifei
 * @Date 2022-11-09 16:18
 * @Version V1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/rOperatingIndex")
@Api(tags = "主网-运行指标统计")
public class ROperatingIndexController extends BaseController {

    private final ROperatingIndexMService rOperatingIndexMService; //月

    private final ROperatingIndexYService rOperatingIndexYService; //年

    @PostMapping("/getOperatingList")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询运行指标统计(主网)")
    public HttpResult<List<ROperatingIndexCommonVO>> getOperatingList(@RequestBody ROperatingIndexParam rOperatingIndexParam) {
        String methodDescribe = getMethodDescribe("getOperatingList");
        Integer type = rOperatingIndexParam.getType();
        if (type == null) {
            throw new BusinessException(CommonResponseEnum.INVALID_PARAMETER, "参数日期维度【type】非法");
        }
        List<ROperatingIndexCommonVO> list;

        if (BizParamConstant.STAT_BIZ_YEAR.equals(type.toString())) {
            //年
            list = rOperatingIndexYService.getOperatingList(rOperatingIndexParam);
        } else if (BizParamConstant.STAT_BIZ_MONTH.equals(type.toString())) {
            //月
            list = rOperatingIndexMService.getOperatingList(rOperatingIndexParam);
        } else {
            throw new BusinessException(CommonResponseEnum.INVALID_PARAMETER, "参数日期维度【type】非法");
        }

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
}
