增加下载

master
wj 2 years ago
parent b7c2690d56
commit fe092c66a3

@ -0,0 +1,25 @@
package com.glxp.api.constant;
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum StatusEnum {
/**
*
*/
FAILED(1, "失败"),
/**
*
*/
SUCCESS(2, "成功"),
;
@EnumValue
private Integer code;
private String remark;
}

@ -12,10 +12,7 @@ import com.glxp.api.annotation.AuthRuleAnnotation;
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.BasicExportStatusEnum;
import com.glxp.api.constant.BasicExportTypeEnum;
import com.glxp.api.constant.BasicProcessStatus;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.constant.*;
import com.glxp.api.dao.auth.*;
import com.glxp.api.dao.basic.*;
import com.glxp.api.dao.inout.*;
@ -62,8 +59,12 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.List;
@ -359,7 +360,7 @@ public class SpsSyncDownloadController {
.taskId(taskId)
.startTime(new Date())
.endTime(new Date())
.status(1)
.status(StatusEnum.SUCCESS.getCode())
.updateTime(new Date())
.type(upLoadRequest.getExportType().getRemark())
.idDatas(upLoadRequest.getExportType().getKey())
@ -1142,5 +1143,63 @@ public class SpsSyncDownloadController {
return ResultVOUtils.success("上传成功");
}
@GetMapping("/sps/sync/download/info/file")
public void downloadFile(HttpServletResponse response,String id){
if (StrUtil.isBlank(id)) {
throw new RuntimeException("缺少唯一标识");
}
BasicDownloadStatusEntity info = basicDownloadService.getById(id);
if (info == null) {
throw new RuntimeException("数据不存在");
}
if (StrUtil.isBlank(info.getCacheFilePath())) {
throw new RuntimeException("文件未生成");
}
File file = new File(info.getCacheFilePath());
if (!file.exists()) {
throw new RuntimeException("文件丢失");
}
String[] split = info.getCacheFilePath().split("/");
String enFileName = URLEncoder.encode(split[split.length - 1], StandardCharsets.UTF_8);
// 设值返回文件属性,浏览器会根据属性调用下载文件方法
response.addHeader("Content-Disposition", "attachment;filename=" + enFileName);
// 前端获取文件名,需要解码
response.addHeader("downLoadName", enFileName);
// 定义输出流
ServletOutputStream outputStream = null;
FileInputStream fileInputStream = null;
try {
outputStream = response.getOutputStream();
// 定义输出类型为二进制流输出
response.setContentType("application/octet-stream");
fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
// 把流写入response
outputStream.write(bytes);
// flush落盘
outputStream.flush();
// 关闭输出流
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}

@ -1,5 +1,6 @@
package com.glxp.api.dao.sync;
import com.glxp.api.dao.BaseMapperPlus;
import com.glxp.api.entity.sync.BasicDownloadStatusEntity;
import com.glxp.api.req.sync.BasicDownloadRequest;
import org.apache.ibatis.annotations.Mapper;
@ -8,7 +9,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface BasicDownloadDao {
public interface BasicDownloadDao extends BaseMapperPlus<BasicDownloadDao,BasicDownloadStatusEntity,BasicDownloadStatusEntity> {
List<BasicDownloadStatusEntity> filterDownloadStatus(BasicDownloadRequest basicDownloadRequest);

@ -1,12 +1,13 @@
package com.glxp.api.service.sync;
import com.baomidou.mybatisplus.extension.service.IService;
import com.glxp.api.entity.sync.BasicDownloadStatusEntity;
import com.glxp.api.req.sync.BasicDownloadRequest;
import java.util.List;
public interface BasicDownloadService {
public interface BasicDownloadService extends IService<BasicDownloadStatusEntity> {
BasicDownloadStatusEntity findByData(String idDatas, Integer status);

@ -1,6 +1,7 @@
package com.glxp.api.service.sync.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.dao.sync.BasicDownloadDao;
import com.glxp.api.entity.sync.BasicDownloadStatusEntity;
@ -15,7 +16,7 @@ import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class BasicDownloadServiceImpl implements BasicDownloadService {
public class BasicDownloadServiceImpl extends ServiceImpl<BasicDownloadDao,BasicDownloadStatusEntity> implements BasicDownloadService {
@Resource
BasicDownloadDao basicDownloadDao;

Loading…
Cancel
Save