diff --git a/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java b/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java index fb6a94a4..4bc2d256 100644 --- a/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java +++ b/src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java @@ -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; @@ -24,7 +28,7 @@ public class DownLoadFileController { * @功能描述 下载文件: */ @RequestMapping("/zipDownload") - public void zipDownload(HttpServletRequest request,HttpServletResponse response) { + public void zipDownload(HttpServletRequest request, HttpServletResponse response) { try { String path = "static/upload/PrintServer.zip"; String fileName = "PrintServer.zip"; @@ -40,9 +44,9 @@ public class DownLoadFileController { while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ outputStream.write(buffer, 0, len); } - }catch (IOException e){ + } catch (IOException e) { e.printStackTrace(); - }finally { + } finally { assert inputStream != null; inputStream.close(); outputStream.close(); @@ -54,10 +58,10 @@ public class DownLoadFileController { /** * @param response - * @功能描述 下载文件: + * @功能描述 下载物料导入模板: */ @RequestMapping("/materialImportDownload") - public void materialImportDownload(HttpServletRequest request,HttpServletResponse response) { + public void materialImportDownload(HttpServletRequest request, HttpServletResponse response) { try { String path = "static/upload/materialImport.xlsx"; @@ -75,9 +79,9 @@ public class DownLoadFileController { while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ outputStream.write(buffer, 0, len); } - }catch (IOException e){ + } catch (IOException e) { e.printStackTrace(); - }finally { + } finally { assert inputStream != null; inputStream.close(); outputStream.close(); @@ -89,10 +93,10 @@ public class DownLoadFileController { /** * @param response - * @功能描述 下载文件: + * @功能描述 下载物料类型导入模板: */ @RequestMapping("/materialTypeImportDownload") - public void materialTypeImportDownload(HttpServletRequest request,HttpServletResponse response) { + public void materialTypeImportDownload(HttpServletRequest request, HttpServletResponse response) { try { String path = "static/upload/materialTypeImport.xlsx"; @@ -110,9 +114,9 @@ public class DownLoadFileController { while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ outputStream.write(buffer, 0, len); } - }catch (IOException e){ + } catch (IOException e) { e.printStackTrace(); - }finally { + } finally { assert inputStream != null; inputStream.close(); outputStream.close(); @@ -124,10 +128,10 @@ public class DownLoadFileController { /** * @param response - * @功能描述 下载文件: + * @功能描述 下载库存导入模板: */ @RequestMapping("/inventoryImportDownload") - public void inventoryImportDownload(HttpServletRequest request,HttpServletResponse response) { + public void inventoryImportDownload(HttpServletRequest request, HttpServletResponse response) { try { String path = "static/upload/inventoryImport.xlsx"; @@ -145,9 +149,9 @@ public class DownLoadFileController { while ((len = inputStream.read(buffer)) != -1) { /* 将流中内容写出去 .*/ outputStream.write(buffer, 0, len); } - }catch (IOException e){ + } catch (IOException e) { e.printStackTrace(); - }finally { + } finally { assert inputStream != null; inputStream.close(); outputStream.close(); @@ -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(); + } + } } diff --git a/src/main/resources/static/upload/helpDocumentForAdmin-mobile.pdf b/src/main/resources/static/upload/helpDocumentForAdmin-mobile.pdf new file mode 100644 index 00000000..8815a3d1 Binary files /dev/null and b/src/main/resources/static/upload/helpDocumentForAdmin-mobile.pdf differ diff --git a/src/main/resources/static/upload/helpDocumentForAdmin-pc.pdf b/src/main/resources/static/upload/helpDocumentForAdmin-pc.pdf new file mode 100644 index 00000000..2c84e09b Binary files /dev/null and b/src/main/resources/static/upload/helpDocumentForAdmin-pc.pdf differ diff --git a/src/main/resources/static/upload/helpDocumentForUser-mobile.pdf b/src/main/resources/static/upload/helpDocumentForUser-mobile.pdf new file mode 100644 index 00000000..48381e0b Binary files /dev/null and b/src/main/resources/static/upload/helpDocumentForUser-mobile.pdf differ diff --git a/src/main/resources/static/upload/helpDocumentForUser-pc.pdf b/src/main/resources/static/upload/helpDocumentForUser-pc.pdf new file mode 100644 index 00000000..357c4983 Binary files /dev/null and b/src/main/resources/static/upload/helpDocumentForUser-pc.pdf differ diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 34fee9f7..60a81753 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -85,6 +85,10 @@