package com.jiayue.ipfcst.fileupload.service;

import com.jiayue.ipfcst.common.data.entity.UploadFileLogDetail;
import com.jiayue.ipfcst.common.data.repository.UploadFileLogDetailRepository;
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.List;

/**
 * 上报日志明细service
 * @author zy
 * @version 3.0
 */
@Service
@Slf4j
public class UploadFileLogDetailService {
  @Autowired
  private UploadFileLogDetailRepository uploadFileLogDetailRepository;

  /**
   * 根据上报日志id查询明细
   * @param uploadFileLogId
   * @return UploadFileLogDetail 上报明细
   *
   */
  public List<UploadFileLogDetail> getByFileLogId(Integer uploadFileLogId){
    UploadFileLogDetail uploadFileLogDetail = new UploadFileLogDetail();
    uploadFileLogDetail.setUploadFileLogId(uploadFileLogId);
    List<UploadFileLogDetail> list = uploadFileLogDetailRepository.findAll(Example.of(uploadFileLogDetail));
    return list;
  }

  /*
  * 根据上报日志id删除明细
  * */
  public void deleteByUploadFileLogId(Integer uploadFileLogId){
    try{
      List<UploadFileLogDetail> list = getByFileLogId(uploadFileLogId);
      for(UploadFileLogDetail uploadFileLogDetail : list){
        uploadFileLogDetailRepository.deleteById(uploadFileLogDetail.getId());
      }
    }catch (Exception e){
      log.info("根据上报日志id删除明细异常:"+e);
    }

  }
}
