提交返回流
This commit is contained in:
@ -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.sevice.BizBidClientVersionService;
|
||||
import com.chinaunicom.mall.ebtp.extend.templatewarehouse.sevice.BizBidTemplateWarehouseService;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
@ -59,13 +60,14 @@ public class TemplateWarehouseController {
|
||||
*/
|
||||
@ApiOperation("获得客户端配置文件文件id")
|
||||
@GetMapping("/client/file")
|
||||
public BaseResponse<ByteArrayOutputStream> getClientFile() throws IOException {
|
||||
public BaseResponse getClientFile() throws IOException {
|
||||
String type = "ipassConfigFile";
|
||||
BizBidTemplateWarehouse templateWarehouse = templateWarehouseService.getTemplateByType(type);
|
||||
ByteArrayOutputStream clientVersion = bizBidClientVersionService.downloadFileByOId(templateWarehouse.getDocumentCenterId());
|
||||
return BaseResponse.success(clientVersion);
|
||||
bizBidClientVersionService.downloadFileByOId(templateWarehouse.getDocumentCenterId());
|
||||
return BaseResponse.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过版本号获得对应客户端文件id
|
||||
*
|
||||
@ -73,8 +75,8 @@ public class TemplateWarehouseController {
|
||||
*/
|
||||
@ApiOperation("通过版本号获得对应客户端文件id")
|
||||
@GetMapping("/client/{version}")
|
||||
public BaseResponse<ByteArrayOutputStream> getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version) throws IOException {
|
||||
ByteArrayOutputStream clientVersion = bizBidClientVersionService.getClientByVersion(version);
|
||||
return BaseResponse.success(clientVersion);
|
||||
public BaseResponse getClientByVersion(@ApiParam(value = "版本号", required = true) @PathVariable String version) throws IOException {
|
||||
bizBidClientVersionService.getClientByVersion(version);
|
||||
return BaseResponse.success();
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public interface BizBidClientVersionService extends IBaseService<BizBidClientVer
|
||||
* @param version
|
||||
* @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;
|
||||
}
|
||||
|
@ -8,17 +8,22 @@ 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.apache.commons.lang.time.DateFormatUtils;
|
||||
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 sun.nio.cs.ext.GBK;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Optional;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
* 对数据表 biz_bid_client_version 操作的 serviceImpl
|
||||
@ -34,39 +39,45 @@ public class BizBidClientVersionServiceImpl extends BaseServiceImpl<BizBidClient
|
||||
|
||||
private final ModelConvertor modelConvertor;
|
||||
|
||||
@Resource
|
||||
private HttpServletResponse response;
|
||||
|
||||
@Override
|
||||
public ByteArrayOutputStream getClientByVersion(String version) throws IOException {
|
||||
public void getClientByVersion(String version) throws IOException {
|
||||
QueryWrapper<BizBidClientVersion> query = new QueryWrapper<>(new BizBidClientVersion().setIpassVersion(version));
|
||||
BizBidClientVersion clientVersion = this.getOne(query);
|
||||
return this.downloadClientByOId(clientVersion.getDocumentCenterId());
|
||||
this.downloadClientByOId(clientVersion.getDocumentCenterId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ByteArrayOutputStream downloadFileByOId(String objectId) throws IOException {
|
||||
public void 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();
|
||||
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()){
|
||||
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));
|
||||
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();
|
||||
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()){
|
||||
fileStream.write(optionalBytes.get());
|
||||
outputStream.write(optionalBytes.get());
|
||||
}
|
||||
return fileStream;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user