From a52987c15542576259e287b87d61bdddace19732 Mon Sep 17 00:00:00 2001 From: "udf_admin@163.com" Date: Sun, 17 Dec 2017 21:46:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E4=B8=8B=E8=BD=BD=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../udf/core/utils/excel/ExportExcel.java | 4 +- .../aliyun/oss/api/download/DownConstant.java | 10 ++- .../aliyun/oss/api/download/DownLoad.java | 12 ++++ .../api/download/DownLoadProcessAspect.java | 13 ++-- .../aliyun/oss/api/download/DownloadInfo.java | 2 +- .../oss/service/DownLoadProcessService.java | 66 +++++++++++++++++++ .../aliyun/oss/web/AliyunOssController.java | 13 ++++ .../aliyun/oss/web/IAliuyinOssController.java | 17 +++++ 8 files changed, 126 insertions(+), 11 deletions(-) create mode 100644 udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoad.java create mode 100644 udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/service/DownLoadProcessService.java diff --git a/udf-starter-core/src/main/java/org/itkk/udf/core/utils/excel/ExportExcel.java b/udf-starter-core/src/main/java/org/itkk/udf/core/utils/excel/ExportExcel.java index 945d401..44c381f 100644 --- a/udf-starter-core/src/main/java/org/itkk/udf/core/utils/excel/ExportExcel.java +++ b/udf-starter-core/src/main/java/org/itkk/udf/core/utils/excel/ExportExcel.java @@ -109,9 +109,9 @@ public class ExportExcel { final int num16 = 16; final int num30 = 30; final int num256 = 256; - this.wb = new SXSSFWorkbook(rowAccessWindowSize); //有没有被关闭的风险 + this.wb = new SXSSFWorkbook(rowAccessWindowSize); //设置刷新行数大小 this.wb.setCompressTempFiles(true); // 缓冲区文件压缩 - this.sheet = this.wb.createSheet("Export"); + this.sheet = this.wb.createSheet(title); this.styles = createStyles(); // 创建标题 if (StringUtils.isNotBlank(title)) { 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 index 7d7a69b..12f3968 100644 --- 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 @@ -18,17 +18,21 @@ public class DownConstant { */ public enum DOWNLOAD_PROCESS_STATUS { /** - * 执行中 + * 待执行 */ STATUS_1(1), /** - * 执行完成 + * 执行中 */ STATUS_2(2), + /** + * 执行完成 + */ + STATUS_3(3), /** * 执行错误 */ - STATUS_3(3); + STATUS_4(4); /** * value diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoad.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoad.java new file mode 100644 index 0000000..d40f510 --- /dev/null +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownLoad.java @@ -0,0 +1,12 @@ +package org.itkk.udf.file.aliyun.oss.api.download; + +import java.lang.annotation.*; + +/** + * DownLoad + */ +@Documented +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface DownLoad { +} 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 index 66816d4..34b92da 100644 --- 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 @@ -19,6 +19,7 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import java.io.File; +import java.nio.file.Files; import java.util.concurrent.TimeUnit; /** @@ -66,7 +67,9 @@ public class DownLoadProcessAspect { * @param proceedingJoinPoint proceedingJoinPoint * @return Object */ - @Around("this(org.itkk.udf.file.aliyun.oss.api.download.IDownLoadProcess) && args(org.itkk.udf.file.aliyun.oss.api.download.DownLoadParam)") + @Around("this(org.itkk.udf.file.aliyun.oss.api.download.IDownLoadProcess)" + + " && @annotation(org.itkk.udf.file.aliyun.oss.api.download.DownLoad)" + + " && args(org.itkk.udf.file.aliyun.oss.api.download.DownLoadParam)") public Object around(ProceedingJoinPoint proceedingJoinPoint) { //定义返回值 Object result = null; @@ -81,7 +84,7 @@ public class DownLoadProcessAspect { info.setId(param.getId()); try { //更新缓存 - info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_1.value()); + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_2.value()); redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); //执行 result = proceedingJoinPoint.proceed(); @@ -90,14 +93,14 @@ public class DownLoadProcessAspect { //上传文件到阿里云OSS String objectKey = ossWarpper.uploadFile(param.getOssCode(), file); //删除本地文件 - file.delete(); + Files.delete(file.toPath()); //更新缓存 - info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_2.value()); + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_3.value()); info.setObjectKey(objectKey); redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); } catch (Throwable e) { //更新缓存 - info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_3.value()); + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_4.value()); info.setErrorMsg(e.getMessage()); redisTemplate.opsForValue().set(key, info, DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); //抛出异常 diff --git a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java index 053be4e..f40183c 100644 --- a/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java +++ b/udf-starter-file-aliyun-oss-api/src/main/java/org/itkk/udf/file/aliyun/oss/api/download/DownloadInfo.java @@ -20,7 +20,7 @@ public class DownloadInfo { /** * status */ - @ApiModelProperty(value = "下载状态 ( 1 : 执行中 , 2 : 执行完成 , 3 : 执行错误 )", required = true, dataType = "int") + @ApiModelProperty(value = "下载状态 ( 1 : 待执行 , 2 : 执行中 , 3 : 执行完成 , 4 : 执行错误 )", required = true, dataType = "int") private Integer status; /** diff --git a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/service/DownLoadProcessService.java b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/service/DownLoadProcessService.java new file mode 100644 index 0000000..33c186c --- /dev/null +++ b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/service/DownLoadProcessService.java @@ -0,0 +1,66 @@ +package org.itkk.udf.file.aliyun.oss.service; + +import org.itkk.udf.cache.redis.CacheRedisProperties; +import org.itkk.udf.file.aliyun.oss.api.download.DownConstant; +import org.itkk.udf.file.aliyun.oss.api.download.DownLoadProcessAspect; +import org.itkk.udf.file.aliyun.oss.api.download.DownloadInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +/** + * DownLoadProcessService + */ +@Service +public class DownLoadProcessService { + + /** + * redisTemplate + */ + @Autowired + private RedisTemplate redisTemplate; + + /** + * cacheRedisProperties + */ + @Autowired + private CacheRedisProperties cacheRedisProperties; + + /** + * generateDownLoadId + * + * @return String + */ + public String generateDownLoadId() { + //生成ID + String id = UUID.randomUUID().toString(); + //获得key + String key = cacheRedisProperties.getPrefix() + DownLoadProcessAspect.DOWNLOAD_CACHE_PREFIX + id; + //构造对象 + DownloadInfo info = new DownloadInfo(); + info.setId(id); + info.setStatus(DownConstant.DOWNLOAD_PROCESS_STATUS.STATUS_1.value()); + //更新缓存 + redisTemplate.opsForValue().set(key, info, DownLoadProcessAspect.DOWNLOAD_CACHE_EXPIRATION, TimeUnit.MINUTES); + //返回ID + return id; + } + + /** + * get + * + * @param id id + * @return DownloadInfo + */ + public DownloadInfo getDownloadInfo(String id) { + //获得key + String key = cacheRedisProperties.getPrefix() + DownLoadProcessAspect.DOWNLOAD_CACHE_PREFIX + id; + //获得缓存值 + Object cacheValue = redisTemplate.opsForValue().get(key); + //返回 + return cacheValue == null ? null : (DownloadInfo) cacheValue; + } +} diff --git a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java index 0ebcd1a..fef5e0f 100644 --- a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java +++ b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/AliyunOssController.java @@ -10,6 +10,8 @@ import org.itkk.udf.core.RestResponse; import org.itkk.udf.core.domain.aliyun.oss.OssParam; import org.itkk.udf.file.aliyun.oss.api.OssWarpper; import org.itkk.udf.file.aliyun.oss.api.domain.PolicyResult; +import org.itkk.udf.file.aliyun.oss.api.download.DownloadInfo; +import org.itkk.udf.file.aliyun.oss.service.DownLoadProcessService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; @@ -32,6 +34,12 @@ public class AliyunOssController implements IAliuyinOssController { @Autowired private OssWarpper ossWarpper; + /** + * downLoadProcessService + */ + @Autowired + private DownLoadProcessService downLoadProcessService; + @Override public RestResponse policy(@PathVariable String code) throws IOException { return new RestResponse<>(ossWarpper.getPolicy(code)); @@ -52,4 +60,9 @@ public class AliyunOssController implements IAliuyinOssController { public RestResponse checkExist(@RequestBody @Valid OssParam ossParam) { return new RestResponse<>(ossWarpper.checkExist(ossParam.getCode(), ossParam.getObjectKey())); } + + @Override + public RestResponse getDownloadInfo(@PathVariable String id) { + return new RestResponse<>(downLoadProcessService.getDownloadInfo(id)); + } } diff --git a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java index e44ed3c..48e5f33 100644 --- a/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java +++ b/udf-starter-file-aliyun-oss/src/main/java/org/itkk/udf/file/aliyun/oss/web/IAliuyinOssController.java @@ -13,6 +13,7 @@ import io.swagger.annotations.ApiOperation; import org.itkk.udf.core.RestResponse; import org.itkk.udf.core.domain.aliyun.oss.OssParam; import org.itkk.udf.file.aliyun.oss.api.domain.PolicyResult; +import org.itkk.udf.file.aliyun.oss.api.download.DownloadInfo; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -93,4 +94,20 @@ public interface IAliuyinOssController { @RequestMapping(value = "check/exist", method = RequestMethod.POST) RestResponse checkExist(@RequestBody @Valid OssParam ossParam); + /** + * 获得文件下载信息(供客户端轮询) + * + * @param id id + * @return RestResponse + */ + @ApiOperation(value = "FILE_ALIYUN_OSS_DOWNLOAD_INFO", notes = "获得文件下载信息(供客户端轮询)") + @ApiImplicitParams({ + @ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称", required = true, dataType = "string"), + @ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true, dataType = "string"), + @ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号", required = true, dataType = "string"), + @ApiImplicitParam(paramType = "path", name = "id", value = "文件下载ID", required = true, dataType = "string") + }) + @RequestMapping(value = "download/info/{id}", method = RequestMethod.GET) + RestResponse getDownloadInfo(@PathVariable String id); + }