package com.trade.service.filestorage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.trade.service.contract.entity.ESignFlow;
import com.trade.service.filestorage.dto.FileStorage;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trade.common.exception.ServiceException;
import com.trade.service.filestorage.entity.TFileStorage;
import com.trade.service.filestorage.mapper.TFileStorageMapper;
import com.trade.service.filestorage.service.TFileStorageService;

import java.util.List;

/**
 * <p>
 * 文件存储信息表 服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2024-04-01
 */
@Service
public class TFileStorageServiceImp extends ServiceImpl<TFileStorageMapper, TFileStorage> implements TFileStorageService {

    @Override
    public TFileStorage add(TFileStorage fileStorage) {
        boolean saved = save(fileStorage);
        if (!saved) {
            throw new ServiceException("保存文件记录失败");
        }
        return getById(fileStorage.getId());
    }

    @Override
    public TFileStorage getFileStorageById(Long fileId) {
        return getById(fileId);
    }

    @Override
    public List<TFileStorage> getFilesByBizNoAndBizType(String bizNo, String bizType) {
        QueryWrapper<TFileStorage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("biz_no", bizNo).eq("biz_type", bizType);
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public List<TFileStorage> getFilesByBizAndFileType(String bizNo, String bizType, String fileType) {
        QueryWrapper<TFileStorage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("biz_no", bizNo).eq("biz_type", bizType).eq("file_type", fileType);
        return getBaseMapper().selectList(queryWrapper);
    }
}
