|
@@ -1,15 +1,26 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
+import com.bstek.ureport.console.designer.ReportUtils;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.manager.entity.FormulaBase;
|
|
|
import org.springblade.manager.mapper.FormulaBaseMapper;
|
|
|
import org.springblade.manager.vo.FormulaBaseVo;
|
|
|
import org.springblade.manager.vo.FormulaType;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -32,4 +43,36 @@ public class FormulaBaseService extends BaseServiceImpl<FormulaBaseMapper, Formu
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public void download(HttpServletResponse response, String url) throws IOException {
|
|
|
+ Resource resource =ResourceUtil.getResource(url);
|
|
|
+ if(resource.isFile()){
|
|
|
+ int index = url.lastIndexOf("/");
|
|
|
+ String urls = url.substring(0, index + 1);
|
|
|
+ String name = url.substring(index + 1);
|
|
|
+ url = urls + URLEncoder.encode(name, "UTF-8");
|
|
|
+ BufferedInputStream bis = new BufferedInputStream(resource.getInputStream());
|
|
|
+ BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
|
|
|
+ String[] fileNameList = url.split("/");
|
|
|
+ // 设置文件ContentType类型,这样设置,会自动判断下载文件类型
|
|
|
+ response.setContentType("application/multipart/form-data");
|
|
|
+ String fileName = new String(fileNameList[fileNameList.length - 1].getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
|
|
+ try {
|
|
|
+ byte[] cache= new byte[4098];
|
|
|
+ int size;
|
|
|
+ while((size=bis.read(cache))>-1){
|
|
|
+ bos.write(cache,0,size);
|
|
|
+ }
|
|
|
+ bos.flush();
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ ioe.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ bos.close();
|
|
|
+ bis.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|