Commit 2a2f5a9f by yinyong

出纳附件文件下载

parent ca4d9d30
...@@ -299,4 +299,39 @@ public class CostListController { ...@@ -299,4 +299,39 @@ public class CostListController {
.contentType(MediaType.parseMediaType("application/octet-stream")) .contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(file.getInputStream())); .body(new InputStreamResource(file.getInputStream()));
} }
@GetMapping("downloadCashierAnnex")
public ResponseEntity<InputStreamResource> downCashierAnnex(HttpServletRequest request, HttpServletResponse response) throws IOException {
String detailNo = request.getParameter("detailNo");
CostDomain cost = costService.getByNo(detailNo);
String filePath = null;
String fileName = null;
if (null != cost) {
filePath = cost.getCashierFilePath();
if (null != filePath){
String[] split = filePath.split(".");
if (null != split && split.length>=1){
fileName = split[split.length-1];
}
}
}else {
return null;
}
FileSystemResource file = new FileSystemResource(filePath);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
// new String(fileName.getBytes("UTF-8"),"iso-8859-1") 解决文件下载的时候文件名乱码的问题
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", new String(fileName.getBytes("UTF-8"),"iso-8859-1")));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity
.ok()
.headers(headers)
.contentLength(file.contentLength())
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(file.getInputStream()));
}
} }
...@@ -68,6 +68,8 @@ public class CostDto { ...@@ -68,6 +68,8 @@ public class CostDto {
private Integer hasInvoice; private Integer hasInvoice;
private Integer rejectType; private Integer rejectType;
private Integer rejectTime; private Integer rejectTime;
private String cashierFilePath;
private String cashierDownloadPath;
public String getDic() { public String getDic() {
return dic; return dic;
...@@ -543,6 +545,22 @@ public class CostDto { ...@@ -543,6 +545,22 @@ public class CostDto {
this.rejectTime = rejectTime; this.rejectTime = rejectTime;
} }
public String getCashierFilePath() {
return cashierFilePath;
}
public void setCashierFilePath(String cashierFilePath) {
this.cashierFilePath = cashierFilePath;
}
public String getCashierDownloadPath() {
return cashierDownloadPath;
}
public void setCashierDownloadPath(String cashierDownloadPath) {
this.cashierDownloadPath = cashierDownloadPath;
}
@Override @Override
public String toString() { public String toString() {
return "CostDto{" + return "CostDto{" +
......
...@@ -64,9 +64,10 @@ public class CostCashiercallbackServiceImpl implements CostCashiercallbackServic ...@@ -64,9 +64,10 @@ public class CostCashiercallbackServiceImpl implements CostCashiercallbackServic
if(!downloadUrl.contains("uploadfile")) { if(!downloadUrl.contains("uploadfile")) {
continue; continue;
} }
String suffix = downloadUrl.substring(downloadUrl.lastIndexOf("."));
ResponseEntity<byte[]> response = restTemplate.exchange(downloadUrl, HttpMethod.GET, httpEntity, byte[].class); ResponseEntity<byte[]> response = restTemplate.exchange(downloadUrl, HttpMethod.GET, httpEntity, byte[].class);
try { try {
String filePath = PathUtil.getBasePath()+PathUtil.getPath("cashier/"+costNo+"/"+UUID.randomUUID()+"."+response.getHeaders().getContentType().getSubtype()); String filePath = PathUtil.getBasePath()+PathUtil.getPath("cashier/"+costNo+"/"+UUID.randomUUID()+suffix);
File file = new File(filePath); File file = new File(filePath);
if(!file.getParentFile().exists()){ if(!file.getParentFile().exists()){
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
......
...@@ -63,6 +63,8 @@ public class CostDomain { ...@@ -63,6 +63,8 @@ public class CostDomain {
private Integer hasInvoice; //发票状态 private Integer hasInvoice; //发票状态
private Integer rejectType; //驳回类型 private Integer rejectType; //驳回类型
private Date rejectTime; //财务驳回时间 private Date rejectTime; //财务驳回时间
private String cashierFilePath;
private String cashierDownloadPath;
public String getDic() { public String getDic() {
return dic; return dic;
...@@ -497,6 +499,22 @@ public class CostDomain { ...@@ -497,6 +499,22 @@ public class CostDomain {
this.rejectTime = rejectTime; this.rejectTime = rejectTime;
} }
public String getCashierFilePath() {
return cashierFilePath;
}
public void setCashierFilePath(String cashierFilePath) {
this.cashierFilePath = cashierFilePath;
}
public String getCashierDownloadPath() {
return cashierDownloadPath;
}
public void setCashierDownloadPath(String cashierDownloadPath) {
this.cashierDownloadPath = cashierDownloadPath;
}
@Override @Override
public String toString() { public String toString() {
return "CostDomain{" + return "CostDomain{" +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment