mirror of https://gitee.com/xiaonuobase/snowy
【更新】优化返回文件流的接口的异常处理
parent
7013fd1568
commit
c4dae1ea1a
|
@ -99,7 +99,13 @@ public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(DevFileIdParam devFileIdParam, HttpServletResponse response) throws IOException {
|
public void download(DevFileIdParam devFileIdParam, HttpServletResponse response) throws IOException {
|
||||||
DevFile devFile = this.queryEntity(devFileIdParam.getId());
|
DevFile devFile;
|
||||||
|
try {
|
||||||
|
devFile = this.queryEntity(devFileIdParam.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
CommonResponseUtil.renderError(response, e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!devFile.getEngine().equals(DevFileEngineTypeEnum.LOCAL.getValue())) {
|
if(!devFile.getEngine().equals(DevFileEngineTypeEnum.LOCAL.getValue())) {
|
||||||
CommonResponseUtil.renderError(response, "非本地文件不支持此方式下载,id值为:" + devFile.getId());
|
CommonResponseUtil.renderError(response, "非本地文件不支持此方式下载,id值为:" + devFile.getId());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -344,17 +344,21 @@ public class GenBasicServiceImpl extends ServiceImpl<GenBasicMapper, GenBasic> i
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@Override
|
@Override
|
||||||
public void execGenZip(GenBasicIdParam genBasicIdParam, HttpServletResponse response) throws IOException {
|
public void execGenZip(GenBasicIdParam genBasicIdParam, HttpServletResponse response) throws IOException {
|
||||||
File tempFolder = this.genTempFolder(genBasicIdParam, response, true);
|
try {
|
||||||
if(tempFolder == null) {
|
File tempFolder = this.genTempFolder(genBasicIdParam, response, true);
|
||||||
CommonResponseUtil.renderError(response, "代码生成基础不存在,id值为:" + genBasicIdParam.getId());
|
if(tempFolder == null) {
|
||||||
return;
|
CommonResponseUtil.renderError(response, "代码生成基础不存在,id值为:" + genBasicIdParam.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 压缩
|
||||||
|
File zip = ZipUtil.zip(tempFolder);
|
||||||
|
// 压缩完毕删除临时目录
|
||||||
|
FileUtil.del(tempFolder);
|
||||||
|
// 下载
|
||||||
|
CommonDownloadUtil.download(zip, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
CommonResponseUtil.renderError(response, e.getMessage());
|
||||||
}
|
}
|
||||||
// 压缩
|
|
||||||
File zip = ZipUtil.zip(tempFolder);
|
|
||||||
// 压缩完毕删除临时目录
|
|
||||||
FileUtil.del(tempFolder);
|
|
||||||
// 下载
|
|
||||||
CommonDownloadUtil.download(zip, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
|
Loading…
Reference in New Issue