package com.jiayue.ipfcst.fileupload.service;

import com.jiayue.ipfcst.common.data.entity.UploadFileCode;
import com.jiayue.ipfcst.common.data.entity.UploadURL;
import com.jiayue.ipfcst.common.data.repository.UploadURLRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UploadURLService {
  @Autowired
  private UploadURLRepository uploadURLRepository;

  @Transactional
  public List<UploadURL> findAll(){
    return uploadURLRepository.findAll();
  }

  @Transactional
  public List<UploadURL> findByUploadCahnnelId(Integer id){
    return uploadURLRepository.findByUploadChannelId(id);
  }

  @Transactional
  public void save(UploadURL uploadURL){
    uploadURLRepository.save(uploadURL);
  }
  @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  public void saveCloud(UploadURL uploadURL){
    uploadURLRepository.save(uploadURL);
  }
  @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  public void saveCloud(List<UploadURL> beans) {
    if(beans != null && beans.size() > 0){
      uploadURLRepository.deleteAll();
      uploadURLRepository.saveAll(beans);
    }
  }

  @Transactional
  public void deleteByChannelId(Integer uploadChannelId){
    uploadURLRepository.deleteByUploadChannelId(uploadChannelId);
  }


}
