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

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.PwRDnOperatingParam;
import com.njcn.device.pms.pojo.vo.PwRDnOperatingIndexCommonVO;
import com.njcn.device.pms.service.distribution.RDnOperatingIndexMService;
import com.njcn.device.pms.service.distribution.RDnOperatingYService;
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("/pwROperatingIndex")
@Api(tags = "配网-运行指标统计")
public class PwRDnOperatingIndexController extends BaseController {

    private final RDnOperatingIndexMService rDnOperatingIndexMService; //月

    private final RDnOperatingYService rDnOperatingYService; //年

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

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

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