package com.njcn.energy.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.PatternRegex;
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.common.utils.LogUtil;
import com.njcn.energy.pojo.dto.OnlineRateDTO;
import com.njcn.energy.pojo.vo.EleIntegrityVO;
import com.njcn.energy.service.IEleInformationService;
import com.njcn.energy.service.IEleIntegrityService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/4/20 14:57
 */
@Slf4j
@RestController
@RequestMapping("/onlineRate")
@RequiredArgsConstructor
@Api(tags = "在线率管理")
@Validated
public class EleOnlineRateController extends BaseController {

    private final IEleInformationService eleInformationService;

    @PostMapping("/getDeviceTime")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("装置在线率数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "起始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true)
    })
    @ApiIgnore
    public HttpResult<List<OnlineRateDTO>> getDeviceTime(@RequestParam @Pattern(regexp = PatternRegex.TIME_SECOND_FORMAT, message = "时间格式错误") String startTime, @RequestParam @Pattern(regexp = PatternRegex.TIME_SECOND_FORMAT, message = "时间格式错误") String endTime){
        String methodDescribe = getMethodDescribe("getDeviceTime");
        LogUtil.njcnDebug(log, "{}，起始时间：{}，结束时间：{}", methodDescribe, startTime, endTime);
        List<OnlineRateDTO> list = eleInformationService.getDeviceTime(startTime,endTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @PostMapping("/getOnlineRateTree")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("用能终端在线率树表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "起始时间", required = true),
            @ApiImplicitParam(name = "endTime", value = "结束时间", required = true)
    })
    public HttpResult<List<EleIntegrityVO>> getOnlineRateTree(@RequestParam @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误") String startTime, @RequestParam @Pattern(regexp = PatternRegex.TIME_FORMAT, message = "时间格式错误") String endTime){
        String methodDescribe = getMethodDescribe("getOnlineRateTree");
        LogUtil.njcnDebug(log, "{}，起始时间：{}，结束时间：{}", methodDescribe, startTime, endTime);
        List<EleIntegrityVO> list = eleInformationService.getOnlineRateTree(startTime,endTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}
