package com.njcn.oracle.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.njcn.oracle.bo.param.DataAsynParam;
import com.njcn.oracle.service.IOracleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javassist.compiler.ast.StringL;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * Description:
 * Date: 2024/1/3  14:57【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/data")
@Api(tags = "数据同步")
@AllArgsConstructor
public class DataSyncController {


    private final IOracleService oracleService;

    /**
     * 将时间区间拆解为24小时分区，小于24小时，仅查询当前时间区间，目前不支持指定时分秒
     * 暂且不用多线程处理，因无法控制数据指标数和时间范围多大，担心
     *
     * @param dataAsynParam
     */
    @PostMapping("/dataSync")
    @ApiOperation("数据同步")
    @ApiImplicitParam(name = "dataAsynParam", value = "数据同步参数", required = true)
    public Boolean dataSync(@RequestBody DataAsynParam dataAsynParam) {

        oracleService.dataBacthSysc(dataAsynParam);

        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }

    @GetMapping("/dataSyncHours")
    @ApiOperation("数据同步")
    public Boolean dataSyncHours(@RequestParam("startDateTime")   String startDateTime,@RequestParam("endDateTime")  String endDateTime) {
        DataAsynParam dataAsynParam = new DataAsynParam();
        dataAsynParam.setStartDateTime(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATETIME_PATTERN));
        dataAsynParam.setEndDateTime(LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATETIME_PATTERN));
        oracleService.dataSyncHours(dataAsynParam);

        return true;// HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, "数据同步");
    }


}
