package com.sckw.slope.detection.controller;

import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson2.JSONObject;
import com.sckw.core.annotation.Log;
import com.sckw.core.web.response.HttpResult;

import com.sckw.slope.detection.model.param.DeviceQuery;
import com.sckw.slope.detection.model.param.IntegrationQuery;
import com.sckw.slope.detection.model.vo.IntegrationVo;
import com.sckw.slope.detection.service.BackTrackService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author s'k'y
 * @description 数据回溯controller
 * @date 2023-10-30 17:10:24
 */
@Slf4j
@RestController
@RequestMapping("/backtrack")
public class backTrackController {

    @Autowired
    BackTrackService backTrackService;


    @Log(description = "项目所属要素")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "项目所属要素", value = "/getParts", method = RequestMethod.GET)
    public HttpResult deviceAll(@RequestParam("projectId") String projectId) {
        log.info("项目所属要素 getParts param :{}",projectId);
        return backTrackService.getParts(projectId);
    }

    @Log(description = "返回要素所属于的设备")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "返回要素所属于的设备", value = "/getDeviceByParts", method = RequestMethod.GET)
    public HttpResult getDeviceByParts(@RequestParam("parts") String parts,@RequestParam("projectId") String projectId) {
        log.info("返回要素所属于的设备 getDeviceByParts param :{},projectID:{}",parts,projectId);
        return backTrackService.getDeviceByParts(parts,projectId);
    }

    @Log(description = "返回设备折线图")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "返回设备折线图", value = "/getDeviceChart", method = RequestMethod.GET)
    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd, @RequestParam("original") Integer original, HttpServletRequest request) throws ParseException {
        log.info("返回设备折线图 getDeviceChart param :{},part:{}",deviceId,part);
        return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd,original,request);
    }


    @Log(description = "集成分析列表")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "集成分析列表", value = "/getIntegrationList", method = RequestMethod.POST)
    public HttpResult select(@Valid @RequestBody IntegrationQuery integrationQuery, HttpServletRequest request) {
        log.info("集成分析列表 select param:{}", JSONObject.toJSONString(integrationQuery));
        return HttpResult.ok(backTrackService.getIntegrationList(integrationQuery, request));
    }

    @Log(description = "集成分析详情")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "集成分析详情", value = "/getIntegrationDetail", method = RequestMethod.GET)
    public HttpResult getIntegrationDetail(@RequestParam("integrationId") String integrationId) {
        log.info("集成分析详情 getIntegrationDetail param :{},",integrationId);
        return backTrackService.getIntegrationDetail(integrationId);
    }

    @Log(description = "新增集成分析")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
    @RequestMapping(name = "新增集成分析", value = "/integrationAdd", method = RequestMethod.POST)
    public HttpResult integrationAdd(@Valid @RequestBody IntegrationVo Vo, HttpServletRequest request) {
        log.info("新增集成分析 integrationAdd param:{}", JSONObject.toJSONString(Vo));
        return HttpResult.ok(backTrackService.integrationAdd(Vo, request));
    }

    @Log(description = "修改集成分析")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
            @RequestMapping(name = "修改集成分析", value = "/integrationUpdate", method = RequestMethod.POST)
    public HttpResult integrationUpdate(@Valid @RequestBody IntegrationVo Vo, HttpServletRequest request) {
                log.info("修改集成分析 integrationUpdate param:{}", JSONObject.toJSONString(Vo));
                return HttpResult.ok(backTrackService.integrationUpdate(Vo, request));
            }

    @Log(description = "返回选择设备的所有要素")
    //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
            @RequestMapping(name = "返回选择设备的所有要素", value = "/getPartsByDeviceId", method = RequestMethod.GET)
    public HttpResult getPartsByDeviceId(@RequestParam("deviceId") String deviceId) {
                log.info("返回选择设备的所有要素 getPartsByDeviceId deviceId:{}",deviceId);
                return backTrackService.getPartsByDeviceId(deviceId);
            }



}
