package com.storlead.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.storlead.system.mapper.FileResourceMapper;
import com.storlead.system.pojo.entity.FileResourceEntity;
import com.storlead.system.service.FileResourceService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文件系统 服务实现类
 * </p>
 *
 * @author chenkq
 * @since 2022-08-22
 */
@Service
@Log4j2
public class FileResourceServiceImpl extends ServiceImpl<FileResourceMapper, FileResourceEntity> implements FileResourceService {
//    @Resource
//    private FastFileStorageClient storageClient;
//
//    public String upload(MultipartFile multipartFile) throws Exception {
//        String originalFilename = multipartFile.getOriginalFilename().substring(multipartFile.getOriginalFilename().lastIndexOf(".") + 1);
//        StorePath storePath = this.storageClient.uploadFile(multipartFile.getInputStream(),multipartFile.getSize(), originalFilename, null);
////        StorePath storePath = this.storageClient.uploadImageAndCrtThumbImage(multipartFile.getInputStream(),multipartFile.getSize(), originalFilename, null);
//        return "/files/"+storePath.getFullPath();
//    }
//
//    public byte[] download(String fileUrl) {
//        String group = fileUrl.substring(0, fileUrl.indexOf("/"));
//        String path = fileUrl.substring(fileUrl.indexOf("/") + 1);
//        byte[] bytes = storageClient.downloadFile(group, path, new DownloadByteArray());
//        return bytes;
//    }


//    public void deleteFile(String fileUrl) {
//        if (StringUtils.isEmpty(fileUrl)) {
//            log.info("fileUrl == >>文件路径为空...");
//            return;
//        }
//        try {
//            //对根据传入的url删除文件
//            StorePath storePath = StorePath.praseFromUrl(fileUrl);
//            storageClient.deleteFile(storePath.getGroup(), storePath.getPath());
//            //删除上传所产生的缩略图
//            val split = fileUrl.split("\\.");
//            split[0] += "_60x60.";
//            String fileUrl2 = split[0] + split[1];
//            StorePath storePath2 = StorePath.praseFromUrl(fileUrl2);
//            storageClient.deleteFile(storePath2.getGroup(), storePath2.getPath());
//        } catch (Exception e) {
//            log.info(e.getMessage());
//        }
//    }
}
