From ab10dd37cfe63373fd1e179f9c9be84fb4d7fa05 Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 16:44:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemplateWarehouseController.java | 37 ++------------ .../sevice/BizBidClientVersionService.java | 9 ++-- .../impl/BizBidClientVersionServiceImpl.java | 48 ++++--------------- src/main/resources/application-local.yml | 2 +- 4 files changed, 19 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/controller/TemplateWarehouseController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/controller/TemplateWarehouseController.java index b560d19..f5d3dfe 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/controller/TemplateWarehouseController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/controller/TemplateWarehouseController.java @@ -11,6 +11,7 @@ import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -58,38 +59,10 @@ public class TemplateWarehouseController { */ @ApiOperation("获得客户端配置文件文件id") @GetMapping("/client/file") - public BaseResponse getClientFile() throws IOException { + public BaseResponse getClientFile() throws IOException { String type = "ipassConfigFile"; BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type); - FileOutputStream clientVersion = bizBidClientVersionService.downloadFileByObjectId(templateWarehouse.getDocumentCenterId()); - return BaseResponse.success(clientVersion); - } - - /** - * 获得客户端配置文件相关信息 - * - * @return - */ - @ApiOperation("获得客户端配置文件文件id") - @GetMapping("/client/files") - public BaseResponse getClientFiles() throws IOException { - String type = "ipassConfigFile"; - BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type); - FileOutputStream clientVersion = bizBidClientVersionService.downloadFileByObjectIds(templateWarehouse.getDocumentCenterId()); - return BaseResponse.success(clientVersion); - } - - /** - * 获得客户端配置文件相关信息 - * - * @return - */ - @ApiOperation("获得客户端配置文件文件id") - @GetMapping("/client/filess") - public BaseResponse getClientFiless() throws IOException { - String type = "ipassConfigFile"; - BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type); - FileOutputStream clientVersion = bizBidClientVersionService.downloadFileByObjectIdss(templateWarehouse.getDocumentCenterId()); + ByteArrayOutputStream clientVersion = bizBidClientVersionService.downloadFileByOId(templateWarehouse.getDocumentCenterId()); return BaseResponse.success(clientVersion); } @@ -100,8 +73,8 @@ public class TemplateWarehouseController { */ @ApiOperation("通过版本号获得对应客户端文件id") @GetMapping("/client/{version}") - public BaseResponse getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version){ - BizBidClientVersion clientVersion = bizBidClientVersionService.getClientByVersion(version); + public BaseResponse getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version) throws IOException { + ByteArrayOutputStream clientVersion = bizBidClientVersionService.getClientByVersion(version); return BaseResponse.success(clientVersion); } } diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/BizBidClientVersionService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/BizBidClientVersionService.java index 2fb8124..0172b5b 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/BizBidClientVersionService.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/BizBidClientVersionService.java @@ -4,6 +4,7 @@ package com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice; import com.chinaunicom.mall.ebtp.common.base.service.IBaseService; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidClientVersion; +import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; @@ -19,11 +20,7 @@ public interface BizBidClientVersionService extends IBaseService query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version)); - return this.getOne(query); + BizBidClientVersion clientVersion = this.getOne(query); + return this.downloadClientByOId(clientVersion.getDocumentCenterId()); } @Override - public FileOutputStream downloadFileByObjectId(String objectId) throws IOException { + public ByteArrayOutputStream downloadFileByOId(String objectId) throws IOException { log.info("文档中心文件下载传入数据:"+ JsonUtils.objectToJson(objectId)); - String objectInfo = documentCenterService.getFileObjectDetail(objectId); + String objectInfo = documentCenterService.getObjectDetail(objectId); log.info("文档中心文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo)); Optional optionalBytes = modelConvertor.toByteArray(objectInfo); log.info("文档中心文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); - FileOutputStream fileOutputStream = null; + ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); if(optionalBytes.isPresent()){ - ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); fileStream.write(optionalBytes.get()); - log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+fileStream); - fileOutputStream.write(fileStream.toByteArray()); - log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+fileOutputStream); } - return fileOutputStream; + return fileStream; } - - @Override - public FileOutputStream downloadFileByObjectIds(String objectId) throws IOException { + public ByteArrayOutputStream downloadClientByOId(String objectId) throws IOException { log.info("文档中心s文件下载传入数据:"+ JsonUtils.objectToJson(objectId)); String objectInfo = documentCenterService.getObjectDetail(objectId); log.info("文档中心s文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo)); Optional optionalBytes = modelConvertor.toByteArray(objectInfo); log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); - FileOutputStream fileOutputStream = null; + ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); if(optionalBytes.isPresent()){ - ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); fileStream.write(optionalBytes.get()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileStream); - fileOutputStream.write(fileStream.toByteArray()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileOutputStream); } - return fileOutputStream; + return fileStream; } - - @Override - public FileOutputStream downloadFileByObjectIdss(String objectId) throws IOException { - log.info("文档中心s文件下载传入数据:"+ JsonUtils.objectToJson(objectId)); - String objectInfo = documentCenterService.getObjectDetail(objectId); - log.info("文档中心s文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo)); - Optional optionalBytes = modelConvertor.toByteArray(objectInfo); - log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); - FileOutputStream fileOutputStream = null; - if(optionalBytes.isPresent()){ - ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); - fileStream.write(optionalBytes.get()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileStream); - fileOutputStream = new FileOutputStream("C:\\test.txt"); - fileOutputStream.write(fileStream.toByteArray()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileOutputStream); - } - return fileOutputStream; - } } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 4c0be9d..bb85cf7 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,5 +1,5 @@ server: - port: 18018 + port: 9018 servlet: context-path: /