|
|
|
@ -1,5 +1,9 @@ |
|
|
|
package com.dreamchaser.depository_manage.controller; |
|
|
|
|
|
|
|
import com.dreamchaser.depository_manage.config.PortConfig; |
|
|
|
import com.dreamchaser.depository_manage.entity.UserByPort; |
|
|
|
import com.dreamchaser.depository_manage.security.pool.AuthenticationTokenPool; |
|
|
|
import com.dreamchaser.depository_manage.utils.DeviceUtil; |
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
@ -54,7 +58,7 @@ public class DownLoadFileController { |
|
|
|
|
|
|
|
/** |
|
|
|
* @param response |
|
|
|
* @功能描述 下载文件: |
|
|
|
* @功能描述 下载物料导入模板: |
|
|
|
*/ |
|
|
|
@RequestMapping("/materialImportDownload") |
|
|
|
public void materialImportDownload(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
@ -89,7 +93,7 @@ public class DownLoadFileController { |
|
|
|
|
|
|
|
/** |
|
|
|
* @param response |
|
|
|
* @功能描述 下载文件: |
|
|
|
* @功能描述 下载物料类型导入模板: |
|
|
|
*/ |
|
|
|
@RequestMapping("/materialTypeImportDownload") |
|
|
|
public void materialTypeImportDownload(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
@ -124,7 +128,7 @@ public class DownLoadFileController { |
|
|
|
|
|
|
|
/** |
|
|
|
* @param response |
|
|
|
* @功能描述 下载文件: |
|
|
|
* @功能描述 下载库存导入模板: |
|
|
|
*/ |
|
|
|
@RequestMapping("/inventoryImportDownload") |
|
|
|
public void inventoryImportDownload(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
@ -158,13 +162,60 @@ public class DownLoadFileController { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/helpDocumentDownload") |
|
|
|
public void helpDocumentDownload(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
try { |
|
|
|
String path = "static/upload/helpDocumentForAdmin-pc.pdf"; |
|
|
|
String userAgent = request.getHeader("user-agent"); |
|
|
|
// 判断当前使用的设备为移动端还是pc端
|
|
|
|
boolean b = DeviceUtil.checkAgentIsMobile(userAgent); |
|
|
|
// 获取访问token
|
|
|
|
String token = request.getHeader("user-token"); |
|
|
|
if (token == null) { |
|
|
|
token = (String) request.getSession().getAttribute("userToken"); |
|
|
|
} |
|
|
|
UserByPort userToken = AuthenticationTokenPool.getUserToken(token); |
|
|
|
Integer maindeparment = userToken.getMaindeparment(); |
|
|
|
if (b) { |
|
|
|
// 如果是移动端
|
|
|
|
if (PortConfig.roleAdminorgList.contains(maindeparment)) { |
|
|
|
path = "static/upload/helpDocumentForAdmin-mobile.pdf"; |
|
|
|
} else { |
|
|
|
path = "static/upload/helpDocumentForUser-mobile.pdf"; |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
// 如果是pc端
|
|
|
|
if (PortConfig.roleAdminorgList.contains(maindeparment)) { |
|
|
|
path = "static/upload/helpDocumentForAdmin-pc.pdf"; |
|
|
|
} else { |
|
|
|
path = "static/upload/helpDocumentForUser-pc.pdf"; |
|
|
|
} |
|
|
|
} |
|
|
|
String fileName = "helpDocument.pdf"; |
|
|
|
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); |
|
|
|
response.setContentType("content-type:octet-stream"); |
|
|
|
/* .getClassLoader() 方法是在静态文件路径添加一个/ */ |
|
|
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(path); |
|
|
|
OutputStream outputStream = response.getOutputStream(); |
|
|
|
try { |
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
int len; |
|
|
|
assert inputStream != null; |
|
|
|
while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ |
|
|
|
outputStream.write(buffer, 0, len); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} finally { |
|
|
|
assert inputStream != null; |
|
|
|
inputStream.close(); |
|
|
|
outputStream.close(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|