package com.jiayue.ipfcst.fileupload.controller;

import com.jiayue.ipfcst.common.core.web.vo.ResponseVO;
import com.jiayue.ipfcst.common.data.entity.UploadFileLog;
import com.jiayue.ipfcst.fileupload.service.UploadFileLogService;
import com.jiayue.ipfcst.fileupload.util.FileConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 接口服务类
 *
 * @author xsl
 * @version 3.0
 */
@RestController
@RequestMapping("uploadFileOpenInterface")
@Slf4j
public class UploadFileOpenInterfaceController {

  private final UploadFileLogService uploadFileLogService;

  public UploadFileOpenInterfaceController(UploadFileLogService uploadFileLogService) {
    this.uploadFileLogService = uploadFileLogService;
  }

  /**
   * 查看上报缓存中的文件
   * @return
   */
  @RequestMapping(value = "/getFileCache")
  public ResponseVO getFileCache() {
    log.info("访问上报缓存。。。。。。。");
    List list = new ArrayList<>();
    for(Map.Entry<String, UploadFileLog> vo : FileConstant.readyUploadFileMap.entrySet()){
      list.add(vo.getValue());
    }
    return ResponseVO.success(list);
  }

  /**
   * 更新D5000文件状态
   * @param remoteIp
   * @param fileName
   * @param uploadStatus
   * @return
   */
  @RequestMapping(value = "/updateD5000FileStatus/{remoteIp}/{fileName}/{uploadStatus}")
  public String updateD5000FileStatus(@PathVariable final String remoteIp, @PathVariable final String fileName, @PathVariable final String uploadStatus) {
    try {
      uploadFileLogService.updateD5000FileStatus(remoteIp, fileName,uploadStatus);
      return "1";
    } catch (Exception be) {
      log.error("更新D5000文件状态出错" + be);
      return "0";
    }
  }

  /**
   * 获取上报对象状态
   * @return
   */
  @RequestMapping(value = "/getUploadObjectStatus")
  public ResponseVO getUploadObjectStatus() {
    log.info("获取上报对象状态。。。。。。。");
    List list = new ArrayList<>();
    list.add(FileConstant.channelStatusMap);
    return ResponseVO.success(list);
  }
}
