package com.jiayue.ipfcst.fileupload.service;

import com.jiayue.ipfcst.common.data.constant.enums.FeedbackFileStatusEnum;
import com.jiayue.ipfcst.common.data.constant.enums.FileTypeEnum;
import com.jiayue.ipfcst.common.data.entity.FeedbackFileLog;
import com.jiayue.ipfcst.common.data.repository.FeedbackFileLogRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 *
 * @author zy
 * @version 3.0
 */
@Service
@Slf4j
public class FeedbackFileLogService {
  @Autowired FeedbackFileLogRepository feedbackFileLogRepository;
  public List<FeedbackFileLog> getAll(){
    List<FeedbackFileLog> feedbackFileLogList = feedbackFileLogRepository.findAll();
    return feedbackFileLogList;
  }

  public List<FeedbackFileLog> getByFileTimeAndUploadObjectNoAndFileType(Integer uploadObjectNo, String fileTime, String fileType, String fileStatus) {
    FeedbackFileLog feedbackFileLog = new FeedbackFileLog();
    feedbackFileLog.setFileTime(new Date(Long.parseLong(fileTime)));
    feedbackFileLog.setUploadObjectNo(uploadObjectNo.toString());
    if (!fileType.equals("ALL")){
      FileTypeEnum fileTypeEnum = FileTypeEnum.valueOf(fileType);
      feedbackFileLog.setFileTypeEnum(fileTypeEnum);
    }
    if (!fileStatus.equals("ALL")){
      FeedbackFileStatusEnum feedbackFileStatusEnum = FeedbackFileStatusEnum.valueOf(fileStatus);
      feedbackFileLog.setFeedbackFileStatusEnum(feedbackFileStatusEnum);
    }
    List<FeedbackFileLog> feedbackFileLogList = feedbackFileLogRepository.findAll(Example.of(feedbackFileLog));
    return feedbackFileLogList;
  }
}
