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.mapper.EleIntegrityMapper;
import com.njcn.energy.pojo.param.DataArrayParam;
import com.njcn.energy.pojo.po.DataArray;
import com.njcn.energy.pojo.po.DataMould;
import com.njcn.energy.pojo.vo.EleIntegrityVO;
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.*;
import springfox.documentation.annotations.ApiIgnore;

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

/**
 * 类的介绍：
 *
 * @author xuyang
 * @version 1.0.0
 * @createTime 2022/3/31 19:37
 */
@Slf4j
@RestController
@RequestMapping("/integrity")
@RequiredArgsConstructor
@Api(tags = "完整性管理")
@Validated
public class EleIntegrityController extends BaseController {

    private final IEleIntegrityService eleIntegrityService;

    private final EleIntegrityMapper eleIntegrityMapper;

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

    @PostMapping("/getPowerLineId")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取在线用采监测点")
    @ApiIgnore
    public HttpResult<List<String>> getPowerLineId(){
        String methodDescribe = getMethodDescribe("getPowerLineId");
        List<String> list = eleIntegrityMapper.getPowerLineId();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @PostMapping("/getAirLineId")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取在线空调监测点")
    @ApiIgnore
    public HttpResult<List<String>> getAirLineId(){
        String methodDescribe = getMethodDescribe("getAirLineId");
        List<String> list = eleIntegrityMapper.getAirLineId();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


}
