package com.nantian.cloud.dbcapp.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.cloud.dbcapp.mapper.record.FileExportMapper;
import com.nantian.cloud.dbcapp.service.FileExportService;
import com.nantian.cloud.dbcapp.vo.FileExportVO;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

/**
 * 离线生成文件
 *
 * @author dengjian
 * @Date 2024/11/14 9:26
 */
@Service
public class FileExportServiceImpl extends ServiceImpl<FileExportMapper, FileExportVO> implements FileExportService {




    @Override
    public Boolean verifyFileExportByFileName(String fileName){
        FileExportVO verifyFile = baseMapper.getFileExportByFileName(fileName);
        if (null != verifyFile && "0".equals(verifyFile.getCompleted())){
            return false;
        }
        return true;
    }


    @Override
    public int saveFileExport(FileExportVO fileExportVO){
        return baseMapper.saveFileExport(fileExportVO);
    }

    @Override
    public int updateFileExport(FileExportVO fileExportVO){
        return baseMapper.updateFileExport(fileExportVO);
    }

    @Override
    public int deleteFileExportById(Integer id) {
        FileExportVO info = baseMapper.getFileExportById(id);
        if (null != info){
            File file = new File(info.getFilePath());
            if (file.exists()){
                file.delete();
            }
        }
        return baseMapper.deleteFileExportById(id);
    }

    @Override
    public IPage<FileExportVO> getFileExportList(Page page,String fileName) {
        return baseMapper.getFileExportList(page,fileName);
    }


    @Override
    public FileExportVO getFileExportById(Integer id) {
        return baseMapper.getFileExportById(id);
    }
}
