package com.njcn.mysql.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.njcn.mysql.bo.po.RStatDataPltD;
import com.njcn.mysql.service.OracleToMysqlService;
import com.njcn.mysql.util.MaxValueProcessor;
import com.njcn.oracle.bo.param.DataAsynParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Validated
@Slf4j
@RestController
@RequestMapping("/dataConversion")
@Api(tags = "oracle数据转入mysql")
@AllArgsConstructor
public class OracleToMysqlController {

    private final OracleToMysqlService oracleToMysqlService;

    @GetMapping("/dayHarmRateV")
    @ApiOperation("day_harmrate_v转成r_stat_data_harmrate_v_d")
    public Boolean dayHarmRateVSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertDayHarmRateV(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/pqsIntegrity")
    @ApiOperation("pqs_integrity转成r_stat_integrity_d")
    public Boolean pqsIntegritySync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertPqsIntegrity(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dayVSync")
    @ApiOperation("day_v转成r_stat_data_v_d")
    public Boolean dayVSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertDayV(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/limitRateSync")
    @ApiOperation("limit_rate转成r_stat_limit_rate_d")
    public Boolean limitRateSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertLimitRate(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/limitTargetSync")
    @ApiOperation("limit_target转成r_stat_limit_target_d")
    public Boolean limitTargetSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertLimitTarget(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dayComAssesSync")
    @ApiOperation("PQS_ComAsses转成r_stat_comasses_data")
    public Boolean dayComAssesSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertComAsses(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dayAssesSync")
    @ApiOperation("PQS_ASSES转成r_stat_asses_d")
    public Boolean dayAssesSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertAsses(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dayISync")
    @ApiOperation("day_i转成r_stat_data_i_d")
    public Boolean dayISync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertDataI(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dayPltSync")
    @ApiOperation("day_plt转成r_stat_data_plt_d")
    public Boolean dayPltSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertPlt(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dayFlickerSync")
    @ApiOperation("day_flicker转成r_stat_data_flicker_d")
    public Boolean dayFlickerSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertFlicker(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }


    @GetMapping("/dayInHarmVSync")
    @ApiOperation("day_inharm_v转成r_stat_data_inharm_v_d")
    public Boolean dayInHarmVSync(@RequestParam("startDateTime")String startDateTime, @RequestParam("endDateTime")String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATE_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATE_PATTERN));
        oracleToMysqlService.insertInHarmV(startDateTime,endDateTime);
        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/LineRunFlag")
    @ApiOperation("监测点状态同步")
    public Boolean LineRunFlagSync() {
        System.out.println("--------------------------------监测点运行状态同步------------------------------------");
        oracleToMysqlService.LineRunFlag();
        System.out.println("-----------------------------------------------------------------------------------\n");
        return true;
    }

    @GetMapping("/lineSubstation")
    @ApiOperation("监测点电网变电站同步")
    public Boolean LineSubstation() {
        System.out.println("--------------------------------监测点电网侧变电站同步------------------------------------");
        oracleToMysqlService.lineSubstation();
        System.out.println("-----------------------------------------------------------------------------------\n");
        return true;
    }


}
