Commit c53226a0 authored by xiandafu's avatar xiandafu
Browse files

preview

parent dd1f72e1
...@@ -25,4 +25,6 @@ beetlsql.dbStyle=org.beetl.sql.core.db.MySqlStyle ...@@ -25,4 +25,6 @@ beetlsql.dbStyle=org.beetl.sql.core.db.MySqlStyle
beetlsql.basePackage=com.ibeetl 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/**
\ No newline at end of file #文档预览服务的调用地址,参考https://gitee.com/kekingcn/file-online-preview 安装,没有配置也可以
file.previewURL=http://localhost:8012
...@@ -40,7 +40,7 @@ import com.ibeetl.starter.ObjectMapperJsonUtil; ...@@ -40,7 +40,7 @@ import com.ibeetl.starter.ObjectMapperJsonUtil;
@AutoConfigureAfter(JasonConfig.class) @AutoConfigureAfter(JasonConfig.class)
public class BeetlConf { public class BeetlConf {
@Autowired @Autowired
Environment env; Environment env;
@Autowired @Autowired
CorePlatformService platFormService; CorePlatformService platFormService;
...@@ -116,6 +116,16 @@ public class BeetlConf { ...@@ -116,6 +116,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() {
......
...@@ -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);
......
...@@ -158,6 +158,15 @@ public class LocalFileService implements FileService { ...@@ -158,6 +158,15 @@ public class LocalFileService implements FileService {
public void updateFile(String fileBatchId, String bizType, String bizId) { public void updateFile(String fileBatchId, String bizType, String bizId) {
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,6 +33,40 @@ public class FileSystemContorller { ...@@ -32,6 +33,40 @@ public class FileSystemContorller {
CorePlatformService platformService ; CorePlatformService platformService ;
private static final String MODEL = "/core/file"; private static final String MODEL = "/core/file";
/*附件类操作*/
@PostMapping(MODEL + "/uploadAttachment.json")
@ResponseBody
public JsonResult uploadFile(@RequestParam("file") MultipartFile file,String batchFileUUID,String bizType,String bizId) throws IOException {
if(file.isEmpty()) {
return JsonResult.fail();
}
CoreUser user = platformService.getCurrentUser();
CoreOrg org = platformService.getCurrentOrg();
FileItem fileItem = fileService.createFileItem(file.getOriginalFilename(), bizType, bizId, user.getId(), org.getId(), batchFileUUID,null);
OutputStream os = fileItem.openOutpuStream();
FileUtil.copy(file.getInputStream(), os);
return JsonResult.success(fileItem);
}
@PostMapping(MODEL + "/deleteAttachment.json")
@ResponseBody
public JsonResult deleteFile(Long fileId,String batchFileUUID ) throws IOException {
fileService.removeFile(fileId, batchFileUUID);
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 @Autowired
FileService fileService; FileService fileService;
@GetMapping(MODEL + "/get.do") @GetMapping(MODEL + "/get.do")
...@@ -46,26 +81,6 @@ public class FileSystemContorller { ...@@ -46,26 +81,6 @@ public class FileSystemContorller {
} }
return null; return null;
} }
@PostMapping(MODEL + "/upload.json")
@ResponseBody
public JsonResult upload(@RequestParam("file") MultipartFile file,String batchFileUUID,String bizType,String bizId) throws IOException {
if(file.isEmpty()) {
return JsonResult.fail();
}
CoreUser user = platformService.getCurrentUser();
CoreOrg org = platformService.getCurrentOrg();
FileItem fileItem = fileService.createFileItem(file.getOriginalFilename(), bizType, bizId, user.getId(), org.getId(), batchFileUUID,null);
OutputStream os = fileItem.openOutpuStream();
FileUtil.copy(file.getInputStream(), os);
return JsonResult.success(fileItem);
}
@PostMapping(MODEL + "/deleteFile.json")
@ResponseBody
public JsonResult deleteFile(Long fileId,String batchFileUUID ) throws IOException {
fileService.removeFile(fileId, batchFileUUID);
return JsonResult.success();
}
@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 {
......
<!--#
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