Merge branch 'dev' into 'master'
Dev See merge request eshop/biz_service_ebtp_extend!14
This commit is contained in:
@ -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);
|
||||
|
||||
}
|
@ -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<DocumentCenterService> {
|
||||
@Override
|
||||
public DocumentCenterService create(Throwable throwable) {
|
||||
DocumentCenterServiceFallbackImpl remoteProcessServiceFallback = new DocumentCenterServiceFallbackImpl();
|
||||
remoteProcessServiceFallback.setCause(throwable);
|
||||
return remoteProcessServiceFallback;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -11,6 +11,9 @@ 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;
|
||||
|
||||
@RestController
|
||||
@Api(tags = "模板仓库")
|
||||
@ -56,10 +59,11 @@ public class TemplateWarehouseController {
|
||||
*/
|
||||
@ApiOperation("获得客户端配置文件文件id")
|
||||
@GetMapping("/client/file")
|
||||
public BaseResponse<BizBidTemplateWarehouse> getClientFile(){
|
||||
public BaseResponse<ByteArrayOutputStream> getClientFile() throws IOException {
|
||||
String type = "ipassConfigFile";
|
||||
BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type);
|
||||
return BaseResponse.success(templateWarehouse);
|
||||
ByteArrayOutputStream clientVersion = bizBidClientVersionService.downloadFileByOId(templateWarehouse.getDocumentCenterId());
|
||||
return BaseResponse.success(clientVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,8 +73,8 @@ public class TemplateWarehouseController {
|
||||
*/
|
||||
@ApiOperation("通过版本号获得对应客户端文件id")
|
||||
@GetMapping("/client/{version}")
|
||||
public BaseResponse<BizBidClientVersion> getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version){
|
||||
BizBidClientVersion clientVersion = bizBidClientVersionService.getClientByVersion(version);
|
||||
public BaseResponse<ByteArrayOutputStream> getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version) throws IOException {
|
||||
ByteArrayOutputStream clientVersion = bizBidClientVersionService.getClientByVersion(version);
|
||||
return BaseResponse.success(clientVersion);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ 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;
|
||||
|
||||
/**
|
||||
* 对数据表 biz_bid_client_version 操作的 service
|
||||
* @author Auto create
|
||||
@ -16,7 +20,7 @@ public interface BizBidClientVersionService extends IBaseService<BizBidClientVer
|
||||
* @param version
|
||||
* @return
|
||||
*/
|
||||
BizBidClientVersion getClientByVersion(String version);
|
||||
|
||||
ByteArrayOutputStream getClientByVersion(String version) throws IOException;
|
||||
|
||||
ByteArrayOutputStream downloadFileByOId(String oId) throws IOException;
|
||||
}
|
||||
|
@ -2,23 +2,71 @@ 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;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.dao.BizBidClientVersionMapper;
|
||||
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidClientVersionService;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseServiceImpl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 对数据表 biz_bid_client_version 操作的 serviceImpl
|
||||
* @author Auto create
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class BizBidClientVersionServiceImpl extends BaseServiceImpl<BizBidClientVersionMapper, BizBidClientVersion> implements BizBidClientVersionService {
|
||||
|
||||
private final DocumentCenterService documentCenterService;
|
||||
|
||||
private final ModelConvertor modelConvertor;
|
||||
|
||||
@Override
|
||||
public ByteArrayOutputStream getClientByVersion(String version) throws IOException {
|
||||
QueryWrapper<BizBidClientVersion> query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version));
|
||||
BizBidClientVersion clientVersion = this.getOne(query);
|
||||
return this.downloadClientByOId(clientVersion.getDocumentCenterId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BizBidClientVersion getClientByVersion(String version) {
|
||||
QueryWrapper<BizBidClientVersion> query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version));
|
||||
return this.getOne(query);
|
||||
public ByteArrayOutputStream downloadFileByOId(String objectId) throws IOException {
|
||||
log.info("文档中心文件下载传入数据:"+ JsonUtils.objectToJson(objectId));
|
||||
String objectInfo = documentCenterService.getObjectDetail(objectId);
|
||||
log.info("文档中心文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo));
|
||||
Optional<byte[]> optionalBytes = modelConvertor.toByteArray(objectInfo);
|
||||
log.info("文档中心文件下载返回数据转为byte[]数据:"+ optionalBytes.get());
|
||||
ByteArrayOutputStream fileStream = new ByteArrayOutputStream();
|
||||
if(optionalBytes.isPresent()){
|
||||
fileStream.write(optionalBytes.get());
|
||||
}
|
||||
return fileStream;
|
||||
}
|
||||
|
||||
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<byte[]> optionalBytes = modelConvertor.toByteArray(objectInfo);
|
||||
log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get());
|
||||
ByteArrayOutputStream fileStream = new ByteArrayOutputStream();
|
||||
if(optionalBytes.isPresent()){
|
||||
fileStream.write(optionalBytes.get());
|
||||
}
|
||||
return fileStream;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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,6 +162,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:
|
||||
|
@ -121,6 +121,19 @@ mybatis-plus:
|
||||
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,6 +166,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:
|
||||
|
@ -126,6 +126,18 @@ mybatis-plus:
|
||||
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,6 +170,10 @@ 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:
|
||||
|
@ -124,6 +124,18 @@ mybatis-plus:
|
||||
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,6 +168,10 @@ 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:
|
||||
|
Reference in New Issue
Block a user