package com.yeejoin.amos.boot.module.jxiop.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IdxBizPvPointProcessVariableClassification;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author system_generator
 * @date 2023-08-11
 */
@RestController
@Api(tags = "智能分析")
@RequestMapping(value = "/analyse")
public class AnalyseController extends BaseController {

    @Autowired
    CommonServiceImpl commonServiceImpl;

    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "工况测点区间划分-风机", notes = "工况测点区间划分-风机")
    @GetMapping(value = "/getFanConditionVariablesByTime")
    public ResponseModel<String> getFanConditionVariablesByTime(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
            Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
            Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
            startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
            endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
        }
        return ResponseHelper.buildResponse(commonServiceImpl.getFanConditionVariablesByTimeThread(startTime, endTime));
    }
    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "工况测点区间划分-光伏", notes = "工况测点区间划分-光伏")
    @GetMapping(value = "/getPvConditionVariablesByTime")
    public ResponseModel<String> getPvConditionVariablesByTime(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
       if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
           Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
           Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
           startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
           endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
       }
        return ResponseHelper.buildResponse(commonServiceImpl.getPvConditionVariablesByTimeThread(startTime, endTime));
    }
    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "相关性分析-风机", notes = "相关性分析-风机")
    @GetMapping(value = "/getFanConditionVariablesByTimeAnalyse")
    public ResponseModel<String> getFanConditionVariablesByTimeAnalyse(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
            Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
            Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
            startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
            endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
        }
        return ResponseHelper.buildResponse(commonServiceImpl.getFanConditionVariablesByTimeAnalyseThread(startTime, endTime));
    }
    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "相关性分析-风机", notes = "相关性分析-风机")
    @GetMapping(value = "/getPvConditionVariablesByTimeAnalyse")
    public ResponseModel<String> getPvConditionVariablesByTimeAnalyse(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
            Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
            Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
            startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
            endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
        }
        return ResponseHelper.buildResponse(commonServiceImpl.getPvConditionVariablesByTimeAnalyseThread(startTime, endTime));
    }
    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "中心值计算-风机", notes = "中心值计算-风机")
    @GetMapping(value = "/getFanConditionVariablesByTimeAnalyse1")
    public ResponseModel<String> getFanConditionVariablesByTimeAnalyse1(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
            Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
            Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
            startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
            endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
        }
        return ResponseHelper.buildResponse(commonServiceImpl.getFanConditionVariablesByTimeAnalyse1Thread(startTime, endTime));
    }
    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "中心值计算-光伏", notes = "中心值计算-光伏")
    @GetMapping(value = "/getPvConditionVariablesByTimeAnalyse1")
    public ResponseModel<String> getPvConditionVariablesByTimeAnalyse1(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
            Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
            Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
            startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
            endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
        }
        return ResponseHelper.buildResponse(commonServiceImpl.getPvConditionVariablesByTimeAnalyse1Thread(startTime, endTime));
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "获取influxdb数据", notes = "获取influxdb数据")
    @GetMapping(value = "/getInfluxdbDataByConditon")
    public ResponseModel<Map<String, Object>> getInfluxdbDataByConditon(@RequestParam String stationType, @RequestParam String pointId, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime) {
        if (StringUtils.isEmpty(startTime) && StringUtils.isEmpty(endTime) ){
            Date currentDayStartTime = null;
            try {
                currentDayStartTime = DateUtils.minDateOfMonth(new Date());
            } catch (Exception e) {
                e.printStackTrace();
            }
            Date currentDayEndTime = DateUtils.getCurrentMonthEndTime(new Date());
            startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
            endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
        }
        return ResponseHelper.buildResponse(commonServiceImpl.getInfluxdbDataByConditon(stationType,pointId,startTime, endTime)) ;
    }


    @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
    @ApiOperation(httpMethod = "GET", value = "根据测点查单位信息", notes = "根据测点查单位信息")
    @GetMapping(value = "/getUnitByIndexAddress")
    public ResponseModel<Map<String, String>> getUnitByIndexAddress(@RequestParam String stationType, @RequestParam String pointId) {
        return ResponseHelper.buildResponse(commonServiceImpl.getUnitByIndexAddress(stationType, pointId));
    }
}
