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);
}
Aggregations