package com.jiayue.ipfcst.console.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.DataLimitation;
import com.jiayue.ipfcst.console.service.DataLimitationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dataLimitationController/")
@Slf4j
public class DataLimitationController {
  @Autowired
  private DataLimitationService dataLimitationService;

  @GetMapping(value = "queryDataLimitationServicea/{startTime}/{endTime}")
  public ResponseVO queryDataLimitation(@PathVariable Long startTime,
                                                @PathVariable Long endTime){
    List<DataLimitation> list = new ArrayList<>();
    try {
      list= dataLimitationService.queryDataLimitation(startTime,endTime);
      return ResponseVO.success(list);
    }catch (Exception e) {
      log.error("系统错误：", e);
    } finally {
      list = dataLimitationService.queryDataLimitation(startTime,endTime);
      return ResponseVO.success(list);
    }
  }
  /**
   * 保存人工干预数据(POST请求)
   *
   * @param
   * @return 保存结果
   */
  @PutMapping(value = "saveDataLimitation")
  public ResponseVO saveDataLimitation(@RequestBody List<Map<String,String>> list, Long startTime, String fileType) {
    try {

      if(dataLimitationService.saveDataLimitation(list)){
        return ResponseVO.success("保存成功");
      }else{
        return ResponseVO.success("保存失败");
      }

    } catch (RuntimeException e) {
      log.error("系统错误：", e);
      return ResponseVO.fail("保存失败,运行时异常");
    }
  }
}
