Commit c53226a0 authored by xiandafu's avatar xiandafu
Browse files

preview

parent dd1f72e1
...@@ -26,3 +26,5 @@ beetlsql.basePackage=com.ibeetl ...@@ -26,3 +26,5 @@ beetlsql.basePackage=com.ibeetl
app.name=Spring Boot开发平台 app.name=Spring Boot开发平台
logging.pattern.console=%-4relative [%thread] %-5level %logger{256} %M %L - %msg%n logging.pattern.console=%-4relative [%thread] %-5level %logger{256} %M %L - %msg%n
spring.devtools.restart.exclude=templates/** spring.devtools.restart.exclude=templates/**
#文档预览服务的调用地址,参考https://gitee.com/kekingcn/file-online-preview 安装,没有配置也可以
file.previewURL=http://localhost:8012
...@@ -117,6 +117,16 @@ public class BeetlConf { ...@@ -117,6 +117,16 @@ public class BeetlConf {
}); });
groupTemplate.registerFunction("env", new Function() {
@Override
public String call(Object[] paras, Context ctx) {
String key = (String)paras[0];
return env.getProperty(key);
}
});
groupTemplate.registerFunction("dataAccessList", new Function() { groupTemplate.registerFunction("dataAccessList", new Function() {
@Override @Override
......
...@@ -30,6 +30,8 @@ public interface FileService { ...@@ -30,6 +30,8 @@ public interface FileService {
public FileItem loadFileItemByPath(String path); public FileItem loadFileItemByPath(String path);
public FileItem getFileItemById(Long id); public FileItem getFileItemById(Long id);
public FileItem getFileItemById(Long id,String batchFileId);
public List<FileItem> queryByUserId(Long userId,List<FileTag> tags); public List<FileItem> queryByUserId(Long userId,List<FileTag> tags);
public List<FileItem> queryByBiz(String bizType,String bizId); public List<FileItem> queryByBiz(String bizType,String bizId);
public List<FileItem> queryByBatchId(String fileBatchId); public List<FileItem> queryByBatchId(String fileBatchId);
......
...@@ -159,6 +159,15 @@ public class LocalFileService implements FileService { ...@@ -159,6 +159,15 @@ public class LocalFileService implements FileService {
dbHelper.fileDao.updateBatchIdInfo(bizType, bizId, fileBatchId); dbHelper.fileDao.updateBatchIdInfo(bizType, bizId, fileBatchId);
} }
@Override
public FileItem getFileItemById(Long id, String fileBatchId) {
CoreFile file = dbHelper.getFileItemById(id);
if(!file.getFileBatchId().equals(fileBatchId)){
return null;
}
return this.getFileItem(file);
}
......
package com.ibeetl.admin.core.util;
import java.util.UUID;
public class UUIDUtil {
public static String uuid() {
UUID uuid = UUID.randomUUID();
String randomUUIDString = uuid.toString();
return randomUUIDString;
}
}
package com.ibeetl.admin.core.util.beetl;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.beetl.core.Context;
import org.beetl.core.Function;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ibeetl.admin.core.file.FileItem;
import com.ibeetl.admin.core.file.FileService;
@Component
public class FileFunction implements Function {
@Autowired
FileService fileService;
@Override
public List<FileItem> call(Object[] paras, Context arg1) {
String attachmentId = (String)paras[0];
if(StringUtils.isEmpty(attachmentId)) {
return Collections.EMPTY_LIST;
}
return fileService.queryByBatchId(attachmentId);
}
}
package com.ibeetl.admin.core.util.beetl;
import org.beetl.core.Context;
import org.beetl.core.Function;
import com.ibeetl.admin.core.util.UUIDUtil;
public class UUIDFunction implements Function {
@Override
public String call(Object[] arg0, Context arg1) {
return UUIDUtil.uuid();
}
}
...@@ -11,6 +11,7 @@ import org.apache.commons.logging.LogFactory; ...@@ -11,6 +11,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
...@@ -32,23 +33,11 @@ public class FileSystemContorller { ...@@ -32,23 +33,11 @@ public class FileSystemContorller {
CorePlatformService platformService ; CorePlatformService platformService ;
private static final String MODEL = "/core/file"; private static final String MODEL = "/core/file";
@Autowired
FileService fileService; /*附件类操作*/
@GetMapping(MODEL + "/get.do") @PostMapping(MODEL + "/uploadAttachment.json")
public ModelAndView index(HttpServletResponse response,String id) throws IOException {
String path = id;
response.setContentType("text/html; charset = UTF-8");
FileItem fileItem = fileService.loadFileItemByPath(path);
response.setHeader("Content-Disposition", "attachment; filename="+fileItem.getName());
fileItem.copy(response.getOutputStream());
if(fileItem.isTemp()) {
fileItem.delete();
}
return null;
}
@PostMapping(MODEL + "/upload.json")
@ResponseBody @ResponseBody
public JsonResult upload(@RequestParam("file") MultipartFile file,String batchFileUUID,String bizType,String bizId) throws IOException { public JsonResult uploadFile(@RequestParam("file") MultipartFile file,String batchFileUUID,String bizType,String bizId) throws IOException {
if(file.isEmpty()) { if(file.isEmpty()) {
return JsonResult.fail(); return JsonResult.fail();
} }
...@@ -60,13 +49,39 @@ public class FileSystemContorller { ...@@ -60,13 +49,39 @@ public class FileSystemContorller {
return JsonResult.success(fileItem); return JsonResult.success(fileItem);
} }
@PostMapping(MODEL + "/deleteFile.json") @PostMapping(MODEL + "/deleteAttachment.json")
@ResponseBody @ResponseBody
public JsonResult deleteFile(Long fileId,String batchFileUUID ) throws IOException { public JsonResult deleteFile(Long fileId,String batchFileUUID ) throws IOException {
fileService.removeFile(fileId, batchFileUUID); fileService.removeFile(fileId, batchFileUUID);
return JsonResult.success(); return JsonResult.success();
} }
@GetMapping(MODEL + "/download/{fileId}/{batchFileUUID}/{name}")
public ModelAndView download(HttpServletResponse response,@PathVariable Long fileId,@PathVariable String batchFileUUID ) throws IOException {
FileItem item = fileService.getFileItemById(fileId,batchFileUUID);
response.setHeader("Content-Disposition", "attachment; filename="+item.getName());
item.copy(response.getOutputStream());
return null;
}
/*execl 导入导出*/
@Autowired
FileService fileService;
@GetMapping(MODEL + "/get.do")
public ModelAndView index(HttpServletResponse response,String id) throws IOException {
String path = id;
response.setContentType("text/html; charset = UTF-8");
FileItem fileItem = fileService.loadFileItemByPath(path);
response.setHeader("Content-Disposition", "attachment; filename="+fileItem.getName());
fileItem.copy(response.getOutputStream());
if(fileItem.isTemp()) {
fileItem.delete();
}
return null;
}
@GetMapping(MODEL + "/downloadTemplate.do") @GetMapping(MODEL + "/downloadTemplate.do")
public ModelAndView dowloadTemplate(HttpServletResponse response,String path) throws IOException { public ModelAndView dowloadTemplate(HttpServletResponse response,String path) throws IOException {
response.setContentType("text/html; charset = UTF-8"); response.setContentType("text/html; charset = UTF-8");
......
<!--#
var name = name!"attachement";
var uploadURL = ctxPath+"/core/file/uploadAttachment.json";
var chooseId = name+"List";
var uploadId = name+"ListAction";
var filesListId = name+"DataList";
//加载已经在数据库列表
var files = (isNew=="true")?[]:core.file(batchFileUUID);
-->
<div class="layui-upload">
<input type="hidden" name="${name}" value="${batchFileUUID}"/>
<button type="button" class="layui-btn layui-btn-normal"
id="${chooseId}">选择多文件</button>
<button type="button" class="layui-btn" id="${uploadId}">开始上传</button>
<div class="layui-upload-list">
<table class="layui-table">
<thead>
<tr>
<th>编号</th>
<th>文件名</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody id="${filesListId}">
<!--# for(file in files){ -->
<tr>
<td>${file.id}</td>
<td>${file.name}</td>
<td>成功</td>
<td>
<button class="layui-btn layui-btn-mini demo-preview">预览</button>
<button class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</button>
</td>
</tr>
<!--# } -->
</tbody>
</table>
</div>
</div>
<script>
var previewStr = '<button class="layui-btn layui-btn-mini demo-preview">预览</button>';
var deleteStr = '<button class="layui-btn layui-btn-mini demo-delete layui-btn-danger">删除</button>';
layui.use('upload',
function() {
var $ = layui.jquery,
upload = layui.upload;
var demoListView = $('#${filesListId}'),
uploadListIns = upload.render({
elem: '#${chooseId}',
url: '${uploadURL}',
accept: 'file',
multiple: true,
auto: false,
data: {
"batchFileUUID": "${batchFileUUID}",
"bizId":"${bizId!}",
"bizType":"${bizType}"
},
bindAction: '#${uploadId}',
choose: function(obj) {
var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
//读取本地文件
obj.preview(function(index, file, result) {
var tr = $(['<tr id="${name}Upload-' + index + '">', '<td></td>', '<td>' + file.name + '</td>', '<td>等待上传</td>', '<td>', '<button class="layui-btn layui-btn-mini demo-reload layui-hide">重传</button>', '<button class="layui-btn layui-btn-mini layui-btn-danger demo-cancel">取消</button>', '</td>', '</tr>'].join(''));
//单个重传
tr.find('.demo-reload').on('click',
function() {
obj.upload(index, file);
});
//取消
tr.find('.demo-cancel').on('click',
function() {
delete files[index]; //删除对应的文件
tr.remove();
uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
});
demoListView.append(tr);
});
},
done: function(res, index, upload) {
if (res.code != 0) {
this.error(index, upload);
return
} //上传成功
var tr = demoListView.find('tr#${name}Upload-' + index),
tds = tr.children();
tds.eq(0).html( res.data.id);
tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
tds.eq(3).html(previewStr + deleteStr); //清空操作
initTr(tr);
return delete this.files[index]; //删除文件队列已经上传成功的文件
},
error: function(index, upload) {
var tr = demoListView.find('tr#${name}upload-' + index),
tds = tr.children();
tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
}
});
var trs = demoListView.children();
for (var i = 0; i < trs.length; i++) {
initTr($(trs[i]));
}
function initTr(tr) {
var tds = tr.children();
var fileId = tds.eq(0).html();
var fileName= tds.eq(1).html();
tr.find('.demo-delete').on('click',function() {
Common.post("/core/file/deleteAttachment.json", {
"fileId": fileId,
"batchFileUUID": "${batchFileUUID}"
},
function() {
tr.remove();
uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
Common.info("删除成功");
});
return false;
});
//预览服务器文件
tr.find('.demo-preview').on('click',
function() {
//文件下载地址
var file = encodeURIComponent("http://localhost:8080/core/file/"+fileId+"/${batchFileUUID}/"+fileName);
console.log(file);
//8012为预览服务器地址,参考 https://gitee.com/kekingcn/file-online-preview 安装
Common.openDlg("http://localhost:8012/onlinePreview?url="+file,fileName+"预览")
//window.open("http://localhost:8012/onlinePreview?url="+file);
return false;
});
}
});
</script>
Supports Markdown
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