Commit 47b22720 by guojuxing

微盟批量导入同步门店模板

parent 8fdef92b
package com.gic.enterprise.web.controller.wm;
import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -32,34 +36,26 @@ public class WmStoreSyncController {
@RequestMapping("wm-store-import-template")
public void wmStoreImportTemplate(HttpServletRequest request, HttpServletResponse response)
throws IOException {
String fileName = " 门店同步模板.xls";
OutputStream fo = null;
InputStream in = null;
try {
response.setContentType("text/html;charset=gbk");
response.setHeader("Content-Disposition",
"attachment; filename=" + new String(fileName.getBytes("gbk"), "ISO-8859-1"));
ClassPathResource res = new ClassPathResource("exceltemplate/wm_store_import_template.xls");
String userAgent = request.getHeader("User-Agent").toLowerCase();
String fileName = "门店同步模板.xls";
if (userAgent.contains("firefox")) {
byte[] bytesName = fileName.getBytes("UTF-8");
fileName = new String(bytesName, "ISO-8859-1");
response.setHeader("content-disposition", "attachment;fileName=" + fileName);
} else {
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));
}
fo = response.getOutputStream();
String filePath = ClassLoader.getSystemResource("exceltemplate/wm_store_import_template.xls").getPath();
LOGGER.info("门店同步模板路径:{}", filePath);
in = new FileInputStream(new File(filePath));
byte[] b = new byte[1024];
int len = 0;
while ((len = in.read(b)) != -1) {
fo.write(b, 0, len);
}
fo.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fo != null) {
fo.close();
}
if (in != null) {
in.close();
}
InputStream is = res.getInputStream();
OutputStream out = response.getOutputStream();
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = is.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
out.close();
is.close();
}
}
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