Merge branch 'dev' into 'master'

提交返回流

See merge request eshop/biz_service_ebtp_extend!15
This commit is contained in:
张银雪
2021-03-25 19:19:48 +08:00
3 changed files with 34 additions and 21 deletions

View File

@ -5,6 +5,7 @@ import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidClientVer
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidTemplateWarehouse; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidTemplateWarehouse;
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidClientVersionService; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidClientVersionService;
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidTemplateWarehouseService; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidTemplateWarehouseService;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@ -59,13 +60,14 @@ public class TemplateWarehouseController {
*/ */
@ApiOperation("获得客户端配置文件文件id") @ApiOperation("获得客户端配置文件文件id")
@GetMapping("/client/file") @GetMapping("/client/file")
public BaseResponse<ByteArrayOutputStream> getClientFile() throws IOException { public BaseResponse getClientFile() throws IOException {
String type = "ipassConfigFile"; String type = "ipassConfigFile";
BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type); BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type);
ByteArrayOutputStream clientVersion = bizBidClientVersionService.downloadFileByOId(templateWarehouse.getDocumentCenterId()); bizBidClientVersionService.downloadFileByOId(templateWarehouse.getDocumentCenterId());
return BaseResponse.success(clientVersion); return BaseResponse.success();
} }
/** /**
* 通过版本号获得对应客户端文件id * 通过版本号获得对应客户端文件id
* *
@ -73,8 +75,8 @@ public class TemplateWarehouseController {
*/ */
@ApiOperation("通过版本号获得对应客户端文件id") @ApiOperation("通过版本号获得对应客户端文件id")
@GetMapping("/client/{version}") @GetMapping("/client/{version}")
public BaseResponse<ByteArrayOutputStream> getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version) throws IOException { public BaseResponse getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version) throws IOException {
ByteArrayOutputStream clientVersion = bizBidClientVersionService.getClientByVersion(version); bizBidClientVersionService.getClientByVersion(version);
return BaseResponse.success(clientVersion); return BaseResponse.success();
} }
} }

View File

@ -20,7 +20,7 @@ public interface BizBidClientVersionService extends IBaseService<BizBidClientVer
* @param version * @param version
* @return * @return
*/ */
ByteArrayOutputStream getClientByVersion(String version) throws IOException; void getClientByVersion(String version) throws IOException;
ByteArrayOutputStream downloadFileByOId(String oId) throws IOException; void downloadFileByOId(String oId) throws IOException;
} }

View File

@ -8,17 +8,22 @@ import com.chinaunicom.mall.ebtp.extend.feign.client.DocumentCenterService;
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidClientVersion; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.entity.BizBidClientVersion;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.dao.BizBidClientVersionMapper; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.dao.BizBidClientVersionMapper;
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidClientVersionService; import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidClientVersionService;
import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseServiceImpl; import com.chinaunicom.mall.ebtp.common.base.service.impl.BaseServiceImpl;
import sun.nio.cs.ext.GBK;
import java.io.ByteArrayOutputStream; import javax.annotation.Resource;
import java.io.FileNotFoundException; import javax.servlet.ServletOutputStream;
import java.io.FileOutputStream; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.*;
import java.net.URLEncoder;
import java.util.Optional; import java.util.Optional;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 对数据表 biz_bid_client_version 操作的 serviceImpl * 对数据表 biz_bid_client_version 操作的 serviceImpl
@ -34,39 +39,45 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl<BizBidClient
private final ModelConvertor modelConvertor; private final ModelConvertor modelConvertor;
@Resource
private HttpServletResponse response;
@Override @Override
public ByteArrayOutputStream getClientByVersion(String version) throws IOException { public void getClientByVersion(String version) throws IOException {
QueryWrapper<BizBidClientVersion> query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version)); QueryWrapper<BizBidClientVersion> query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version));
BizBidClientVersion clientVersion = this.getOne(query); BizBidClientVersion clientVersion = this.getOne(query);
return this.downloadClientByOId(clientVersion.getDocumentCenterId()); this.downloadClientByOId(clientVersion.getDocumentCenterId());
} }
@Override @Override
public ByteArrayOutputStream downloadFileByOId(String objectId) throws IOException { public void downloadFileByOId(String objectId) throws IOException {
log.info("文档中心文件下载传入数据:"+ JsonUtils.objectToJson(objectId)); log.info("文档中心文件下载传入数据:"+ JsonUtils.objectToJson(objectId));
String objectInfo = documentCenterService.getObjectDetail(objectId); String objectInfo = documentCenterService.getObjectDetail(objectId);
log.info("文档中心文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo)); log.info("文档中心文件下载返回数据:"+ JsonUtils.objectToJson(objectInfo));
Optional<byte[]> optionalBytes = modelConvertor.toByteArray(objectInfo); Optional<byte[]> optionalBytes = modelConvertor.toByteArray(objectInfo);
log.info("文档中心文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); log.info("文档中心文件下载返回数据转为byte[]数据:"+ optionalBytes.get());
ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode("客户端配置文件", "utf-8"));
if(optionalBytes.isPresent()){ if(optionalBytes.isPresent()){
fileStream.write(optionalBytes.get()); outputStream.write(optionalBytes.get());
} }
return fileStream;
} }
public ByteArrayOutputStream downloadClientByOId(String objectId) throws IOException { public void downloadClientByOId(String objectId) throws IOException {
log.info("文档中心s文件下载传入数据"+ JsonUtils.objectToJson(objectId)); log.info("文档中心s文件下载传入数据"+ JsonUtils.objectToJson(objectId));
String objectInfo = documentCenterService.getObjectDetail(objectId); String objectInfo = documentCenterService.getObjectDetail(objectId);
log.info("文档中心s文件下载返回数据"+ JsonUtils.objectToJson(objectInfo)); log.info("文档中心s文件下载返回数据"+ JsonUtils.objectToJson(objectInfo));
Optional<byte[]> optionalBytes = modelConvertor.toByteArray(objectInfo); Optional<byte[]> optionalBytes = modelConvertor.toByteArray(objectInfo);
log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get()); log.info("文档中心s文件下载返回数据转为byte[]数据:"+ optionalBytes.get());
ByteArrayOutputStream fileStream = new ByteArrayOutputStream(); ByteArrayOutputStream fileStream = new ByteArrayOutputStream();
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition","attachment;filename="+ URLEncoder.encode("客户端安装包", "utf-8"));
if(optionalBytes.isPresent()){ if(optionalBytes.isPresent()){
fileStream.write(optionalBytes.get()); outputStream.write(optionalBytes.get());
} }
return fileStream;
} }
} }