From 15cde06082621ac3a3a594157a7537b568187694 Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 15:07:48 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feign/client/DocumentCenterService.java | 39 ++++++++ .../DocumentCenterServiceFallbackFactory.java | 22 +++++ .../feign/factory/FeignConfiguration.java | 92 +++++++++++++++++++ .../DocumentCenterServiceFallbackImpl.java | 32 +++++++ .../ebtp/extend/feign/utils/UrlConstants.java | 17 ++++ .../TemplateWarehouseController.java | 7 +- .../sevice/BizBidClientVersionService.java | 5 +- .../impl/BizBidClientVersionServiceImpl.java | 29 ++++++ src/main/resources/application-local.yml | 21 ++++- src/main/resources/application-pro.yml | 24 ++++- src/main/resources/application-test.yml | 20 +++- src/main/resources/application-uat.yml | 20 +++- 12 files changed, 316 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/feign/client/DocumentCenterService.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/DocumentCenterServiceFallbackFactory.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/FeignConfiguration.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/feign/fallback/DocumentCenterServiceFallbackImpl.java create mode 100644 src/main/java/com/chinaunicom/mall/ebtp/extend/feign/utils/UrlConstants.java diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/client/DocumentCenterService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/client/DocumentCenterService.java new file mode 100644 index 0000000..5f32239 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/client/DocumentCenterService.java @@ -0,0 +1,39 @@ +package com.chinaunicom.mall.ebtp.extend.feign.client; + +import com.chinaunicom.mall.ebtp.extend.feign.factory.FeignConfiguration; +import com.chinaunicom.mall.ebtp.extend.feign.factory.DocumentCenterServiceFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * 连接山分的文档中心服务 + * + * @author Ajaxfan + */ + +@FeignClient(value = "${mconfig.feign.name.documentcenter}", + fallbackFactory = DocumentCenterServiceFallbackFactory.class, + configuration = FeignConfiguration.class) +public interface DocumentCenterService { + + /** + * 通过附件id查询明细 + * + * @param fileId + * @return + */ + @RequestMapping(method = RequestMethod.POST, value = "v1.0/files/downloadFileAllStream") + String getObjectDetail(@RequestParam("fileId") String fileId); + + /** + * 通过附件id查询明细 + * + * @param fileId + * @return + */ + @RequestMapping(method = RequestMethod.POST, value = "v1.0/files/downloadStream") + String getFileObjectDetail(@RequestParam("fileId") String fileId); + +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/DocumentCenterServiceFallbackFactory.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/DocumentCenterServiceFallbackFactory.java new file mode 100644 index 0000000..d23317b --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/DocumentCenterServiceFallbackFactory.java @@ -0,0 +1,22 @@ +package com.chinaunicom.mall.ebtp.extend.feign.factory; + +import com.chinaunicom.mall.ebtp.extend.feign.client.DocumentCenterService; +import com.chinaunicom.mall.ebtp.extend.feign.fallback.DocumentCenterServiceFallbackImpl; +import feign.hystrix.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * 断路器 + * + * @author dino + * @date 2020/11/26 9:39 + */ +@Component +public class DocumentCenterServiceFallbackFactory implements FallbackFactory { + @Override + public DocumentCenterService create(Throwable throwable) { + DocumentCenterServiceFallbackImpl remoteProcessServiceFallback = new DocumentCenterServiceFallbackImpl(); + remoteProcessServiceFallback.setCause(throwable); + return remoteProcessServiceFallback; + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/FeignConfiguration.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/FeignConfiguration.java new file mode 100644 index 0000000..712e402 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/factory/FeignConfiguration.java @@ -0,0 +1,92 @@ +package com.chinaunicom.mall.ebtp.extend.feign.factory; + +import com.alibaba.fastjson.JSONObject; +import com.chinaunicom.mall.ebtp.extend.feign.utils.UrlConstants; +import feign.RequestInterceptor; +import feign.RequestTemplate; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +@Slf4j +@Configuration +public class FeignConfiguration implements RequestInterceptor { + + @Override + public void apply(RequestTemplate requestTemplate) { + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if(attributes!=null){ + HttpServletRequest request = attributes.getRequest(); + log.info("token=======requestTemplate.headers"+requestTemplate.headers()); + String access_token = request.getHeader("Authorization"); + log.info("token======="+access_token); + if(access_token==null || StringUtils.isBlank(access_token)){ + access_token = getAccessToken(); + log.info("token=======access_token==="+access_token); + requestTemplate.header(HttpHeaders.AUTHORIZATION, "Bearer "+access_token); + } + }else{ + String access_token = getAccessToken(); + log.info("token=======attributes==null==="+access_token); + requestTemplate.header(HttpHeaders.AUTHORIZATION, "Bearer "+access_token); + } + } + + public static String getAccessToken () { + StringBuffer strBf = new StringBuffer(); + try { + URL realUrl = new URL(UrlConstants.clientHttpUrl); + //将realUrl以 open方法返回的urlConnection 连接强转为HttpURLConnection连接 (标识一个url所引用的远程对象连接) + HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();// 此时cnnection只是为一个连接对象,待连接中 + //设置连接输出流为true,默认false (post请求是以流的方式隐式的传递参数) + connection.setDoOutput(true); + //设置连接输入流为true + connection.setDoInput(true); + //设置请求方式为post + connection.setRequestMethod("POST"); + //post请求缓存设为false + connection.setUseCaches(false); + //设置该HttpURLConnection实例是否自动执行重定向 + connection.setInstanceFollowRedirects(true); + //设置请求头里面的各个属性 (以下为设置内容的类型,设置为经过urlEncoded编码过的from参数) + connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); + //建立连接 (请求未开始,直到connection.getInputStream()方法调用时才发起,以上各个参数设置需在此方法之前进行) + connection.connect(); + //创建输入输出流,用于往连接里面输出携带的参数,(输出内容为?后面的内容) + DataOutputStream dataout = new DataOutputStream(connection.getOutputStream()); +// String query = data.toString(); +// //将参数输出到连接 +// dataout.write(query.getBytes("UTF-8")); + // 输出完成后刷新并关闭流 + dataout.flush(); + dataout.close(); // 重要且易忽略步骤 (关闭流,切记!) + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8")); + String lines; + while ((lines = reader.readLine()) != null) { + lines = new String(lines.getBytes(), "utf-8"); + strBf.append(lines); + } + reader.close(); + connection.disconnect(); + log.info("toke返回数据:---------------------- "+strBf.toString()); + } catch (Exception e) { + log.info("toke返回数据:---------------------- "+e.getMessage()); + } + JSONObject json=JSONObject.parseObject(strBf.toString()); + if((boolean)json.get("success")){ + return ((JSONObject)json.get("data")).get("value").toString(); + } + return null; + } +} + diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/fallback/DocumentCenterServiceFallbackImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/fallback/DocumentCenterServiceFallbackImpl.java new file mode 100644 index 0000000..79a9a62 --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/fallback/DocumentCenterServiceFallbackImpl.java @@ -0,0 +1,32 @@ +package com.chinaunicom.mall.ebtp.extend.feign.fallback; + +import com.chinaunicom.mall.ebtp.extend.feign.client.DocumentCenterService; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 熔断 + * + * @author dino + * @date 2020/11/26 9:39 + */ +@Slf4j +@Component +public class DocumentCenterServiceFallbackImpl implements DocumentCenterService { + + @Setter + private Throwable cause; + + @Override + public String getObjectDetail(String fileId) { + return null; + } + + @Override + public String getFileObjectDetail(String fileId) { + return null; + } +} diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/utils/UrlConstants.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/utils/UrlConstants.java new file mode 100644 index 0000000..f172b9b --- /dev/null +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/feign/utils/UrlConstants.java @@ -0,0 +1,17 @@ +package com.chinaunicom.mall.ebtp.extend.feign.utils; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "document") +public class UrlConstants { + public static String clientHttpUrl; + + @Value("${document.clientHttpUrl}") + public void setClientHttpUrl(String confPath) { + clientHttpUrl = confPath; + } + +} 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 d964576..d312c2d 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,8 @@ import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.FileOutputStream; +import java.io.IOException; @RestController @Api(tags = "模板仓库") @@ -56,10 +58,11 @@ public class TemplateWarehouseController { */ @ApiOperation("获得客户端配置文件文件id") @GetMapping("/client/file") - public BaseResponse getClientFile(){ + public BaseResponse getClientFile() throws IOException { String type = "ipassConfigFile"; BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type); - return BaseResponse.success(templateWarehouse); + FileOutputStream clientVersion = bizBidClientVersionService.downloadFileByObjectId(templateWarehouse.getDocumentCenterId()); + 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 06ce4ed..b640327 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,9 @@ 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.FileOutputStream; +import java.io.IOException; + /** * 对数据表 biz_bid_client_version 操作的 service * @author Auto create @@ -18,5 +21,5 @@ public interface BizBidClientVersionService extends IBaseService implements BizBidClientVersionService { + private final DocumentCenterService documentCenterService; + + private final ModelConvertor modelConvertor; @Override public BizBidClientVersion getClientByVersion(String version) { QueryWrapper query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version)); return this.getOne(query); } + + + @Override + public FileOutputStream downloadFileByObjectId(String objectId) throws IOException { + Optional optionalBytes = modelConvertor.toByteArray(documentCenterService.getObjectDetail(objectId)); + FileOutputStream fileOutputStream = null; + if(optionalBytes.isPresent()){ + ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); + fileOutputStream.write(fileStream.toByteArray()); + } + return fileOutputStream; + } } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index a3eb753..4c0be9d 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -116,7 +116,19 @@ mybatis-plus: db-config: # logic-delete-field: flag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) @TableLogic logic-delete-value: deleted # 逻辑已删除值 - logic-not-delete-value: normal # 逻辑未删除值 + logic-not-delete-value: normal # 逻辑未删除 + +# --------------feign ------------ +feign: + httpclient: + enabled: false + okhttp: + enabled: true + client: + config: + default: + connect-timeout: 20000 + read-timeout: 20000 hystrix: command: @@ -150,7 +162,12 @@ mconfig: resps: biz-service-ebtp-resps #应答结构化服务 rsms: biz-service-ebtp-rsms #评审结构化服务 tender: biz-service-ebtp-tender #投标服务 - + documentcenter: core-service-document-center #文档中心 + + +document: + clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749 + # 用户暴露给 prometheus 的健康数据 management: endpoints: diff --git a/src/main/resources/application-pro.yml b/src/main/resources/application-pro.yml index 3d79d3b..4128b33 100644 --- a/src/main/resources/application-pro.yml +++ b/src/main/resources/application-pro.yml @@ -120,7 +120,20 @@ mybatis-plus: # logic-delete-field: flag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) @TableLogic logic-delete-value: deleted # 逻辑已删除值 logic-not-delete-value: normal # 逻辑未删除值 - + + +# --------------feign ------------ +feign: + httpclient: + enabled: false + okhttp: + enabled: true + client: + config: + default: + connect-timeout: 20000 + read-timeout: 20000 + hystrix: command: default: @@ -153,8 +166,13 @@ mconfig: resps: biz-service-ebtp-resps #应答结构化服务 rsms: biz-service-ebtp-rsms #评审结构化服务 tender: biz-service-ebtp-tender #投标服务 - -# 用户暴露给 prometheus 的健康数据 + documentcenter: core-service-document-center #文档中心 + + +document: + clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749 + +# 用户暴露给 prometheus 的健康数据 management: endpoints: web: diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 95f21e1..d34e52a 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -125,7 +125,19 @@ mybatis-plus: # logic-delete-field: flag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) @TableLogic logic-delete-value: deleted # 逻辑已删除值 logic-not-delete-value: normal # 逻辑未删除值 - + +# --------------feign ------------ +feign: + httpclient: + enabled: false + okhttp: + enabled: true + client: + config: + default: + connect-timeout: 20000 + read-timeout: 20000 + hystrix: command: default: @@ -158,7 +170,11 @@ mconfig: resps: biz-service-ebtp-resps #应答结构化服务 rsms: biz-service-ebtp-rsms #评审结构化服务 tender: biz-service-ebtp-tender #投标服务 - + documentcenter: core-service-document-center #文档中心 + +document: + clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749 + # 用户暴露给 prometheus 的健康数据 management: endpoints: diff --git a/src/main/resources/application-uat.yml b/src/main/resources/application-uat.yml index dfb59c4..d30ec4b 100644 --- a/src/main/resources/application-uat.yml +++ b/src/main/resources/application-uat.yml @@ -123,7 +123,19 @@ mybatis-plus: # logic-delete-field: flag # 全局逻辑删除的实体字段名(since 3.3.0,配置后可以忽略不配置步骤2) @TableLogic logic-delete-value: deleted # 逻辑已删除值 logic-not-delete-value: normal # 逻辑未删除值 - + +# --------------feign ------------ +feign: + httpclient: + enabled: false + okhttp: + enabled: true + client: + config: + default: + connect-timeout: 20000 + read-timeout: 20000 + hystrix: command: default: @@ -156,7 +168,11 @@ mconfig: resps: biz-service-ebtp-resps #应答结构化服务 rsms: biz-service-ebtp-rsms #评审结构化服务 tender: biz-service-ebtp-tender #投标服务 - + documentcenter: core-service-document-center #文档中心 + +document: + clientHttpUrl: http://10.242.31.158:8100/auth/oauth/token?grant_type=client_credentials&client_id=bVS46ElU&client_secret=58ea04ba02475c8da2321cc99849d2a10f15b749 + # 用户暴露给 prometheus 的健康数据 management: endpoints: From d0549fa12df180abaf2244ef507977bd88ad29ed Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 15:27:36 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sevice/impl/BizBidClientVersionServiceImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java index 2584a3e..006834f 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java @@ -3,6 +3,7 @@ package com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.chinaunicom.ebtp.mall.cloud.attachment.sdk.convertor.ModelConvertor; +import com.chinaunicom.mall.ebtp.common.util.JsonUtils; import com.chinaunicom.mall.ebtp.extend.feign.client.DocumentCenterService; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidClientVersion; import lombok.RequiredArgsConstructor; @@ -42,11 +43,18 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl optionalBytes = modelConvertor.toByteArray(documentCenterService.getObjectDetail(objectId)); + log.info("文档中心文件下载传入数据:"+ JsonUtils.objectToJson(objectId)); + String objectInfo = documentCenterService.getObjectDetail(objectId); + log.info("文档中心文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo)); + Optional optionalBytes = modelConvertor.toByteArray(objectInfo); + log.info("文档中心文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); FileOutputStream fileOutputStream = null; if(optionalBytes.isPresent()){ ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); + fileStream.write(optionalBytes.get()); + log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileStream)); fileOutputStream.write(fileStream.toByteArray()); + log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileOutputStream)); } return fileOutputStream; } From 8ab8112829e9ea7a86982efccc91d89597f14b3b Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 15:48:17 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemplateWarehouseController.java | 14 +++++++++++++ .../sevice/BizBidClientVersionService.java | 2 ++ .../impl/BizBidClientVersionServiceImpl.java | 21 ++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) 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 d312c2d..503e433 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 @@ -65,6 +65,20 @@ public class TemplateWarehouseController { 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); + } + /** * 通过版本号获得对应客户端文件id * 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 b640327..a6d021e 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 @@ -22,4 +22,6 @@ public interface BizBidClientVersionService extends IBaseService optionalBytes = modelConvertor.toByteArray(objectInfo); log.info("文档中心文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); @@ -58,4 +58,23 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl optionalBytes = modelConvertor.toByteArray(objectInfo); + log.info("文档中心s文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); + FileOutputStream fileOutputStream = null; + if(optionalBytes.isPresent()){ + ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); + fileStream.write(optionalBytes.get()); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileStream)); + fileOutputStream.write(fileStream.toByteArray()); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileOutputStream)); + } + return fileOutputStream; + } } From 56486f2c2e0e55b1d41fbb57596af4a1050da04a Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 15:53:22 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemplateWarehouseController.java | 14 +++++++++++++ .../sevice/BizBidClientVersionService.java | 2 ++ .../impl/BizBidClientVersionServiceImpl.java | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+) 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 503e433..b560d19 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 @@ -79,6 +79,20 @@ public class TemplateWarehouseController { 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()); + return BaseResponse.success(clientVersion); + } + /** * 通过版本号获得对应客户端文件id * 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 a6d021e..2fb8124 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 @@ -24,4 +24,6 @@ public interface BizBidClientVersionService extends IBaseService optionalBytes = modelConvertor.toByteArray(objectInfo); + log.info("文档中心s文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); + FileOutputStream fileOutputStream = null; + if(optionalBytes.isPresent()){ + ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); + fileStream.write(optionalBytes.get()); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileStream)); + fileOutputStream = new FileOutputStream("C:\\test.txt"); + fileOutputStream.write(fileStream.toByteArray()); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileOutputStream)); + } + return fileOutputStream; + } } From dfbb00e3e0e13d59f621bea50dd7769d0527f4c9 Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 16:28:56 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/BizBidClientVersionServiceImpl.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java index b549f42..c0c4b79 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/templatewarehouse/sevice/impl/BizBidClientVersionServiceImpl.java @@ -47,14 +47,14 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl optionalBytes = modelConvertor.toByteArray(objectInfo); - log.info("文档中心文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); + log.info("文档中心文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); FileOutputStream fileOutputStream = null; if(optionalBytes.isPresent()){ ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); fileStream.write(optionalBytes.get()); - log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileStream)); + log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+fileStream); fileOutputStream.write(fileStream.toByteArray()); - log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileOutputStream)); + log.info("文档中心文件下载返回数据转为ByteArrayOutputStream数据:"+fileOutputStream); } return fileOutputStream; } @@ -66,14 +66,14 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl optionalBytes = modelConvertor.toByteArray(objectInfo); - log.info("文档中心s文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); + log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); FileOutputStream fileOutputStream = null; if(optionalBytes.isPresent()){ ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); fileStream.write(optionalBytes.get()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileStream)); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileStream); fileOutputStream.write(fileStream.toByteArray()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileOutputStream)); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileOutputStream); } return fileOutputStream; } @@ -85,15 +85,15 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl optionalBytes = modelConvertor.toByteArray(objectInfo); - log.info("文档中心s文件下载返回数据转为byte[]数据:"+ JsonUtils.objectToJson(optionalBytes)); + log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); FileOutputStream fileOutputStream = null; if(optionalBytes.isPresent()){ ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); fileStream.write(optionalBytes.get()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileStream)); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileStream); fileOutputStream = new FileOutputStream("C:\\test.txt"); fileOutputStream.write(fileStream.toByteArray()); - log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+ JsonUtils.objectToJson(fileOutputStream)); + log.info("文档中心s文件下载返回数据转为ByteArrayOutputStream数据:"+fileOutputStream); } return fileOutputStream; } 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 6/7] =?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: / From 2c9ce47ed5d1a730fa5da7a57d627aa6d96df981 Mon Sep 17 00:00:00 2001 From: zhangyx <1254353766@qq.com> Date: Thu, 25 Mar 2021 16:45:19 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application-local.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index bb85cf7..4c0be9d 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,5 +1,5 @@ server: - port: 9018 + port: 18018 servlet: context-path: /