diff --git a/udf-starter-file-aliyun-oss-api/pom.xml b/udf-starter-file-aliyun-oss-api/pom.xml index 2c9d6b3..4c48a66 100644 --- a/udf-starter-file-aliyun-oss-api/pom.xml +++ b/udf-starter-file-aliyun-oss-api/pom.xml @@ -20,6 +20,11 @@ org.itkk.udf udf-starter-core + + + org.itkk.udf + udf-starter-cache-redis + com.aliyun.oss diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/OssWarpper.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/OssWarpper.java index 37a66fc..7825437 100644 --- a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/OssWarpper.java +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/OssWarpper.java @@ -182,8 +182,9 @@ public class OssWarpper { * * @param code code * @param file file + * @return String */ - public void uploadFile(String code, File file) { + public String uploadFile(String code, File file) { //判空 if (!aliyunOssProperties.getAuth().containsKey(code) || !aliyunOssProperties.getPath().containsKey(code)) { throw new ParameterValidException("aliyun oss code:" + code + "未定义", null); @@ -194,7 +195,9 @@ public class OssWarpper { //实例化oss对象 OSSClient client = new OSSClient(auth.getEndPoint(), auth.getAccessId(), auth.getAccessKey()); try { - client.putObject(path.getBucketName(), file.getName(), file); + String objectKey = "upload/" + file.getName(); + client.putObject(path.getBucketName(), objectKey, file); + return objectKey; } finally { client.shutdown(); } diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownConstant.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownConstant.java new file mode 100644 index 0000000..7d7a69b --- /dev/null +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownConstant.java @@ -0,0 +1,63 @@ +/** + * BaseMqConstant.java + * Created at 2016-12-05 + * Created by Administrator + * Copyright (C) 2016 egridcloud.com, All rights reserved. + */ +package org.itkk.udf.file.aliyun.oss.api.download; + +/** + * 描述 : DownConstant + * + * @author Administrator + */ +public class DownConstant { + + /** + * 下载状态 + */ + public enum DOWNLOAD_PROCESS_STATUS { + /** + * 执行中 + */ + STATUS_1(1), + /** + * 执行完成 + */ + STATUS_2(2), + /** + * 执行错误 + */ + STATUS_3(3); + + /** + * value + */ + private Integer value; + + /** + * PAY_TYPE + * + * @param value value + */ + DOWNLOAD_PROCESS_STATUS(Integer value) { + this.value = value; + } + + /** + * value + * + * @return Integer + */ + public Integer value() { + return this.value; + } + } + + /** + * 描述 : 私有化构造函数 + */ + private DownConstant() { + } + +} diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoadParam.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoadParam.java new file mode 100644 index 0000000..4e1b0d6 --- /dev/null +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoadParam.java @@ -0,0 +1,38 @@ +/** + * Message.java + * Created at 2016-09-19 + * Created by wangkang + * Copyright (C) 2016 itkk.org, All rights reserved. + */ +package org.itkk.udf.file.aliyun.oss.api.download; + +import lombok.Data; +import lombok.ToString; + +import java.io.Serializable; + +/** + * 描述 : 下载消息 + * + * @author wangkang + */ +@Data +@ToString +public class DownLoadParam implements Serializable { + + /** + * 描述 : id + */ + private static final long serialVersionUID = 1L; + + /** + * 描述 : 消息ID + */ + private String id; + + /** + * 描述 : 消息体 + */ + private T body; //NOSONAR + +} diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoadProcessAspect.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoadProcessAspect.java new file mode 100644 index 0000000..1920f8c --- /dev/null +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoadProcessAspect.java @@ -0,0 +1,97 @@ +/** + * RabbitmqListenerAspect.java + * Created at 2016-11-17 + * Created by wangkang + * Copyright (C) 2016 itkk.org, All rights reserved. + */ +package org.itkk.udf.file.aliyun.oss.api.download; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +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.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.util.concurrent.TimeUnit; + +/** + * 描述 : DownLoadProcessAspect + * + * @author wangkang + */ +@Aspect +@Component +@Order(101) +@Slf4j +public class DownLoadProcessAspect { + + /** + * DOWNLOAD_CACHE_PREFIX + */ + public static final String DOWNLOAD_CACHE_PREFIX = ":DOWNLOAD_CACHE:"; + + /** + * DOWNLOAD_CACHE_EXPIRATION + */ + public static final long DOWNLOAD_CACHE_EXPIRATION = 10; + + /** + * redisTemplate + */ + @Autowired + private RedisTemplate redisTemplate; + + /** + * cacheRedisProperties + */ + @Autowired + private CacheRedisProperties cacheRedisProperties; + + /** + * around + * + * @param proceedingJoinPoint proceedingJoinPoint + * @return Object + */ + @Around("this(org.itkk.udf.file.aliyun.oss.api.download.IDownLoadProcess)") + public Object around(ProceedingJoinPoint proceedingJoinPoint) { + //定义返回值 + Object result = null; + //判断类型 + if (proceedingJoinPoint.getTarget() instanceof IDownLoadProcess) { + //获得参数 + DownLoadParam param = (DownLoadParam) proceedingJoinPoint.getArgs()[0]; + //获得key + String key = cacheRedisProperties.getPrefix() + DOWNLOAD_CACHE_PREFIX + param.getId(); + //构造对象 + DownloadInfo info = new DownloadInfo(); + info.setId(param.getId()); + try { + //更新缓存 + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_1.value()); + redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); + //执行 + result = proceedingJoinPoint.proceed(); + //更新缓存 + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_2.value()); + info.setObjectKey(result.toString()); + redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); + } catch (Throwable e) { + //更新缓存 + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_3.value()); + info.setErrorMsg(e.getMessage()); + redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); + //抛出异常 + throw new SystemRuntimeException(e); + } + } + //返回 + return result; + } + +} diff --git a/udf-starter-core/src/main/java/org/itkk/udf/core/domain/aliyun/oss/DownloadInfo.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java similarity index 78% rename from udf-starter-core/src/main/java/org/itkk/udf/core/domain/aliyun/oss/DownloadInfo.java rename to udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java index bc80299..053be4e 100644 --- a/udf-starter-core/src/main/java/org/itkk/udf/core/domain/aliyun/oss/DownloadInfo.java +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java @@ -1,4 +1,4 @@ -package org.itkk.udf.core.domain.aliyun.oss; +package org.itkk.udf.file.aliyun.oss.api.download; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -20,7 +20,7 @@ public class DownloadInfo { /** * status */ - @ApiModelProperty(value = "下载状态 ( 1 : 待执行 , 2 : 执行中 , 3 : 执行完成 , 4 : 执行错误 )", required = true, dataType = "int") + @ApiModelProperty(value = "下载状态 ( 1 : 执行中 , 2 : 执行完成 , 3 : 执行错误 )", required = true, dataType = "int") private Integer status; /** diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/IDownLoadProcess.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/IDownLoadProcess.java new file mode 100644 index 0000000..a6f0451 --- /dev/null +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/IDownLoadProcess.java @@ -0,0 +1,24 @@ +/** + * IRabbitmqListener.java + * Created at 2016-11-17 + * Created by wangkang + * Copyright (C) 2016 itkk.org, All rights reserved. + */ +package org.itkk.udf.file.aliyun.oss.api.download; + +/** + * 描述 : IDownLoadProcess + * + * @author wangkang + */ +public interface IDownLoadProcess { + + /** + * process + * + * @param param param + * @return String + */ + String process(DownLoadParam param); + +}