Search in sources :

Example 6 with QiNiuConfig

use of com.dimple.project.common.domain.QiNiuConfig in project DimpleBlog by martin-chips.

the class QiNiuServiceImpl method deleteQiNiuContent.

@Override
public int deleteQiNiuContent(String ids) {
    QiNiuConfig qiNiuConfig = getQiNiuConfig();
    if (!qiNiuConfig.check()) {
        throw new CustomException("七牛云配置信息不完整,请先填写七牛云配置信息");
    }
    Long[] idArray = ConvertUtils.toLongArray(ids);
    // 查询
    List<QiNiuContent> qiNiuContentList = qiNiuContentMapper.selectContentByIds(idArray);
    for (QiNiuContent qiNiuContent : qiNiuContentList) {
        if (Objects.isNull(qiNiuContent) || StringUtils.isEmpty(qiNiuContent.getName())) {
            throw new CustomException("数据异常");
        }
        // 构造一个带指定Zone对象的配置类
        Configuration cfg = new Configuration(QiNiuUtils.getRegion(qiNiuConfig.getZone()));
        Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
        BucketManager bucketManager = new BucketManager(auth, cfg);
        try {
            bucketManager.delete(qiNiuContent.getBucket(), qiNiuContent.getName());
        } catch (QiniuException e) {
            log.error("删除七牛云图片出错,{},", e.getMessage(), e);
        // 出错后删除本地数据库文件
        }
    }
    return qiNiuContentMapper.deleteContentByIds(idArray);
}
Also used : QiniuException(com.qiniu.common.QiniuException) Configuration(com.qiniu.storage.Configuration) BucketManager(com.qiniu.storage.BucketManager) Auth(com.qiniu.util.Auth) QiNiuConfig(com.dimple.project.common.domain.QiNiuConfig) QiNiuContent(com.dimple.project.tool.domain.QiNiuContent) CustomException(com.dimple.common.exception.CustomException)

Aggregations

QiNiuConfig (com.dimple.project.common.domain.QiNiuConfig)6 CustomException (com.dimple.common.exception.CustomException)4 QiNiuContent (com.dimple.project.tool.domain.QiNiuContent)4 Auth (com.qiniu.util.Auth)4 Configuration (com.qiniu.storage.Configuration)3 Config (com.dimple.project.system.domain.Config)2 QiniuException (com.qiniu.common.QiniuException)2 BucketManager (com.qiniu.storage.BucketManager)2 Response (com.qiniu.http.Response)1 UploadManager (com.qiniu.storage.UploadManager)1 DefaultPutRet (com.qiniu.storage.model.DefaultPutRet)1 FileInfo (com.qiniu.storage.model.FileInfo)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1