|
@@ -23,7 +23,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -662,5 +671,44 @@ public class CreditLineController extends BaseController {
|
|
|
}
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件下载
|
|
|
+ * @param pfiFileUrl 文件url
|
|
|
+ * @param resp
|
|
|
+ * @throws MalformedURLException
|
|
|
+ */
|
|
|
+ @PostMapping("/jpgAuthorization")
|
|
|
+ public void jpgAuthorization(@RequestParam(required=false) String pfiFileUrl, HttpServletResponse resp) throws MalformedURLException {
|
|
|
+ // 下载网络文件
|
|
|
+ int bytesum = 0;
|
|
|
+ int byteread = 0;
|
|
|
+ URL url = new URL(pfiFileUrl);
|
|
|
+ try {
|
|
|
+ URLConnection conn = url.openConnection();
|
|
|
+ InputStream fis = conn.getInputStream();
|
|
|
+ //1、得到文件的绝对路径,并且通过该路径得到一个字节输入流
|
|
|
+ //2、创建字节输出流
|
|
|
+ ServletOutputStream sos = resp.getOutputStream();
|
|
|
+ //4、设置文件编码
|
|
|
+ String filename = URLEncoder.encode("file.png", "UTF-8");//编码为UTF-8
|
|
|
+ //5、告知客户端(浏览器)要下载文件
|
|
|
+ resp.setHeader("content-disposition", "attachment;filename="+filename);
|
|
|
+ resp.setHeader("content-type", "image/png/pdf/doc/docx");//文件类型
|
|
|
+ //6、输出
|
|
|
+ byte[] b = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ while((len=fis.read(b)) != -1){
|
|
|
+ sos.write(b, 0, len);
|
|
|
+ }
|
|
|
+ sos.close();
|
|
|
+ fis.close();
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|