Search in sources :

Example 1 with IOssStrategy

use of com.ruoyi.oss.service.IOssStrategy in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysOssServiceImpl method deleteWithValidByIds.

@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
    if (isValid) {
    // 做一些业务上的校验,判断是否需要校验
    }
    List<SysOss> list = baseMapper.selectBatchIds(ids);
    for (SysOss sysOss : list) {
        IOssStrategy storage = OssFactory.instance(sysOss.getService());
        storage.delete(sysOss.getUrl());
    }
    return baseMapper.deleteBatchIds(ids) > 0;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) IOssStrategy(com.ruoyi.oss.service.IOssStrategy)

Example 2 with IOssStrategy

use of com.ruoyi.oss.service.IOssStrategy in project RuoYi-Vue-Plus by JavaLionLi.

the class SysOssServiceImpl method upload.

@Override
public SysOss upload(MultipartFile file) {
    String originalfileName = file.getOriginalFilename();
    String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
    IOssStrategy storage = OssFactory.instance();
    UploadResult uploadResult;
    try {
        uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
    } catch (IOException e) {
        throw new ServiceException(e.getMessage());
    }
    // 保存文件信息
    SysOss oss = new SysOss();
    oss.setUrl(uploadResult.getUrl());
    oss.setFileSuffix(suffix);
    oss.setFileName(uploadResult.getFilename());
    oss.setOriginalName(originalfileName);
    oss.setService(storage.getServiceType().getValue());
    baseMapper.insert(oss);
    return oss;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) IOssStrategy(com.ruoyi.oss.service.IOssStrategy) UploadResult(com.ruoyi.oss.entity.UploadResult) IOException(java.io.IOException)

Example 3 with IOssStrategy

use of com.ruoyi.oss.service.IOssStrategy in project RuoYi-Vue-Plus by JavaLionLi.

the class SysOssServiceImpl method deleteWithValidByIds.

@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
    if (isValid) {
    // 做一些业务上的校验,判断是否需要校验
    }
    List<SysOss> list = baseMapper.selectBatchIds(ids);
    for (SysOss sysOss : list) {
        IOssStrategy storage = OssFactory.instance(sysOss.getService());
        storage.delete(sysOss.getUrl());
    }
    return baseMapper.deleteBatchIds(ids) > 0;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) IOssStrategy(com.ruoyi.oss.service.IOssStrategy)

Example 4 with IOssStrategy

use of com.ruoyi.oss.service.IOssStrategy in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysOssServiceImpl method upload.

@Override
public SysOss upload(MultipartFile file) {
    String originalfileName = file.getOriginalFilename();
    String suffix = StringUtils.substring(originalfileName, originalfileName.lastIndexOf("."), originalfileName.length());
    IOssStrategy storage = OssFactory.instance();
    UploadResult uploadResult;
    try {
        uploadResult = storage.uploadSuffix(file.getBytes(), suffix, file.getContentType());
    } catch (IOException e) {
        throw new ServiceException(e.getMessage());
    }
    // 保存文件信息
    SysOss oss = new SysOss();
    oss.setUrl(uploadResult.getUrl());
    oss.setFileSuffix(suffix);
    oss.setFileName(uploadResult.getFilename());
    oss.setOriginalName(originalfileName);
    oss.setService(storage.getServiceType().getValue());
    baseMapper.insert(oss);
    return oss;
}
Also used : SysOss(com.ruoyi.system.domain.SysOss) ServiceException(com.ruoyi.common.exception.ServiceException) IOssStrategy(com.ruoyi.oss.service.IOssStrategy) UploadResult(com.ruoyi.oss.entity.UploadResult) IOException(java.io.IOException)

Aggregations

IOssStrategy (com.ruoyi.oss.service.IOssStrategy)4 SysOss (com.ruoyi.system.domain.SysOss)4 ServiceException (com.ruoyi.common.exception.ServiceException)2 UploadResult (com.ruoyi.oss.entity.UploadResult)2 IOException (java.io.IOException)2