添加文件异步下载的功能

This commit is contained in:
udf_admin@163.com
2017-12-17 20:55:15 +08:00
parent ca9884ab6b
commit 092388508f
3 changed files with 25 additions and 4 deletions
@@ -30,6 +30,11 @@ public class DownLoadParam<T> implements Serializable {
*/
private String id;
/**
* ossCode
*/
private String ossCode;
/**
* 描述 : 消息体
*/
@@ -12,11 +12,13 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.itkk.udf.cache.redis.CacheRedisProperties;
import org.itkk.udf.core.exception.SystemRuntimeException;
import org.itkk.udf.file.aliyun.oss.api.OssWarpper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.concurrent.TimeUnit;
/**
@@ -52,13 +54,19 @@ public class DownLoadProcessAspect {
@Autowired
private CacheRedisProperties cacheRedisProperties;
/**
* ossWarpper
*/
@Autowired
private OssWarpper ossWarpper;
/**
* around
*
* @param proceedingJoinPoint proceedingJoinPoint
* @return Object
*/
@Around("this(org.itkk.udf.file.aliyun.oss.api.download.IDownLoadProcess)")
@Around("this(org.itkk.udf.file.aliyun.oss.api.download.IDownLoadProcess) && args(org.itkk.udf.file.aliyun.oss.api.download.DownLoadParam)")
public Object around(ProceedingJoinPoint proceedingJoinPoint) {
//定义返回值
Object result = null;
@@ -77,9 +85,15 @@ public class DownLoadProcessAspect {
redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES);
//执行
result = proceedingJoinPoint.proceed();
//获得本地文件
File file = (File) result;
//上传文件到阿里云OSS
String objectKey = ossWarpper.uploadFile(param.getOssCode(), file);
//删除本地文件
file.delete();
//更新缓存
info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_2.value());
info.setObjectKey(result.toString());
info.setObjectKey(objectKey);
redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES);
} catch (Throwable e) {
//更新缓存
@@ -6,6 +6,8 @@
*/
package org.itkk.udf.file.aliyun.oss.api.download;
import java.io.File;
/**
* 描述 : IDownLoadProcess
*
@@ -17,8 +19,8 @@ public interface IDownLoadProcess<T> {
* process
*
* @param param param
* @return String
* @return File
*/
String process(DownLoadParam<T> param);
File process(DownLoadParam<T> param);
}