Browse Source

添加帮助文档下载功能

lwx_dev
erdanergou 3 years ago
parent
commit
4992c479bc
  1. 95
      src/main/java/com/dreamchaser/depository_manage/controller/DownLoadFileController.java
  2. BIN
      src/main/resources/static/upload/helpDocumentForAdmin-mobile.pdf
  3. BIN
      src/main/resources/static/upload/helpDocumentForAdmin-pc.pdf
  4. BIN
      src/main/resources/static/upload/helpDocumentForUser-mobile.pdf
  5. BIN
      src/main/resources/static/upload/helpDocumentForUser-pc.pdf
  6. 13
      src/main/resources/templates/index.html
  7. 25
      src/main/resources/templates/pages/user/userInfo.html

95
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();
}
}
}

BIN
src/main/resources/static/upload/helpDocumentForAdmin-mobile.pdf

Binary file not shown.

BIN
src/main/resources/static/upload/helpDocumentForAdmin-pc.pdf

Binary file not shown.

BIN
src/main/resources/static/upload/helpDocumentForUser-mobile.pdf

Binary file not shown.

BIN
src/main/resources/static/upload/helpDocumentForUser-pc.pdf

Binary file not shown.

13
src/main/resources/templates/index.html

@ -85,6 +85,10 @@
<dd>
<a href="javascript:" class="login-out">退出登录</a>
</dd>
<dd>
<a href="javascript:" onclick="downLoadHelpDocument()">帮助文档</a>
</dd>
</dl>
</li>
<li class="layui-nav-item layuimini-select-bgcolor" lay-unselect>
@ -94,7 +98,7 @@
</div>
</div>
<!--无限极左侧菜单-->
<!--无限极左侧菜单-->b
<div class="layui-side layui-bg-black layuimini-menu-left">
</div>
@ -146,6 +150,9 @@
<script>
function downLoadHelpDocument(){
}
layui.use(['jquery', 'layer', 'miniAdmin'], function () {
var $ = layui.jquery,
@ -231,6 +238,10 @@
}
});
downLoadHelpDocument = function () {
window.open("/download/helpDocumentDownload", "_self");
}
});
</script>

25
src/main/resources/templates/pages/user/userInfo.html

@ -2,7 +2,7 @@
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>后台管理-登陆</title>
<title>后台管理</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
@ -10,7 +10,6 @@
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="/static/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<link rel="stylesheet" href="/static/css/public.css">
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
@ -19,6 +18,15 @@
</head>
<body>
<style>
.download{
text-align: center;
color: #888;
margin-top: 30px;
}
</style>
<div class="layui-container">
@ -44,6 +52,8 @@
<button class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" onclick="loginOut()">退出
</button>
</div>
<div class="download" onclick="downLoadHelpDocument()" >帮助文档</div>
</form>
</div>
</div>
@ -59,6 +69,10 @@
}
function downLoadHelpDocument(){
}
layui.use(['layer', 'form'], function () {
var form = layui.form,
$ = layui.jquery,
@ -102,9 +116,10 @@
}
})
}
$('body').on('click', '[data-refresh]', function () {
location.reload();
})
downLoadHelpDocument = function () {
window.open("/download/helpDocumentDownload", "_self");
}
});
</script>
</body>

Loading…
Cancel
Save