文件编辑相关 上传,获取列表,下载
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled
Some checks failed
Java CI with Maven / build (11) (push) Has been cancelled
Java CI with Maven / build (17) (push) Has been cancelled
Java CI with Maven / build (8) (push) Has been cancelled
yudao-ui-admin CI / build (14.x) (push) Has been cancelled
yudao-ui-admin CI / build (16.x) (push) Has been cancelled
This commit is contained in:
parent
e52c0477b0
commit
c72386f984
@ -23,6 +23,7 @@ public class FileUtil {
|
||||
// in.transferTo(0, in.size(), out);
|
||||
// OutputStream osm = new FileOutputStream(outPath);
|
||||
// IOUtils.copy(in, osm);
|
||||
// System.out.println("saveFile"+in+" "+outPath);
|
||||
try (OutputStream osm = new FileOutputStream(outPath)) {
|
||||
IOUtils.copy(in, osm);
|
||||
}
|
||||
@ -35,7 +36,7 @@ public class FileUtil {
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void downLoadFile(String name, String filePath, HttpServletResponse response) throws IOException {
|
||||
public static void downLoadFile(String name, String filePath, HttpServletResponse response ) throws IOException {
|
||||
System.out.println("downLoadFile");
|
||||
String path = filePath + name;
|
||||
// path是指想要下载的文件的路径
|
||||
@ -69,6 +70,42 @@ public class FileUtil {
|
||||
outputStream.write(buffer);
|
||||
outputStream.flush();
|
||||
}
|
||||
public static void downLoadFileId(String name, String filePath, HttpServletResponse response,String id) throws IOException {
|
||||
// System.out.println("downLoadFile"+id);
|
||||
String path = filePath + name;
|
||||
// path是指想要下载的文件的路径
|
||||
File file = new File(path);
|
||||
//log.info(file.getPath());
|
||||
// 获取文件名
|
||||
String filename = file.getName().substring(id.length());
|
||||
// System.out.println("filename:"+filename);
|
||||
// 获取文件后缀名
|
||||
String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
|
||||
// System.out.println("ext:"+ext);
|
||||
// System.out.println("文件后缀名:" + ext);
|
||||
|
||||
// 将文件写入输入流
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
InputStream fis = new BufferedInputStream(fileInputStream);
|
||||
byte[] buffer = new byte[fis.available()];
|
||||
fis.read(buffer);
|
||||
fis.close();
|
||||
|
||||
// 清空response
|
||||
response.reset();
|
||||
// 设置response的Header
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
//Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
|
||||
//attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
|
||||
// filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
|
||||
// 告知浏览器文件的大小
|
||||
response.addHeader("Content-Length", "" + file.length());
|
||||
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
|
||||
response.setContentType("application/octet-stream");
|
||||
outputStream.write(buffer);
|
||||
outputStream.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑以后保存文件
|
||||
|
@ -69,14 +69,14 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
||||
// 插入子表
|
||||
createCommentList(knowledge.getId(), createReqVO.getComments());
|
||||
// 发起 BPM 流程
|
||||
Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
.setVariables(processInstanceVariables).setBusinessKey(String.valueOf(knowledge.getId()))
|
||||
.setStartUserSelectAssignees(createReqVO.getStartUserSelectAssignees()));
|
||||
|
||||
// 将工作流的编号,更新到 OA 请假单中
|
||||
knowledgeMapper.updateById(new KnowledgeDO().setId(knowledge.getId()).setProcessInstanceId(processInstanceId));
|
||||
// Map<String, Object> processInstanceVariables = new HashMap<>();
|
||||
// String processInstanceId = processInstanceApi.createProcessInstance(userId,
|
||||
// new BpmProcessInstanceCreateReqDTO().setProcessDefinitionKey(PROCESS_KEY)
|
||||
// .setVariables(processInstanceVariables).setBusinessKey(String.valueOf(knowledge.getId()))
|
||||
// .setStartUserSelectAssignees(createReqVO.getStartUserSelectAssignees()));
|
||||
//
|
||||
// // 将工作流的编号,更新到 OA 请假单中
|
||||
// knowledgeMapper.updateById(new KnowledgeDO().setId(knowledge.getId()).setProcessInstanceId(processInstanceId));
|
||||
try {
|
||||
if (isEsFlag){
|
||||
EsearchUtils.saveIndex(knowledge.getId(),createReqVO,indexName);
|
||||
|
@ -20,6 +20,7 @@ public interface DocumentService {
|
||||
* @return documentKey 文档key
|
||||
*/
|
||||
String buildDocument(String filePath, String fileName);
|
||||
String buildDocumentId(String filePath, String fileName,String id);
|
||||
|
||||
/**
|
||||
* 从缓从中获取文档信息
|
||||
|
@ -78,6 +78,39 @@ public class DocumentServiceImpl implements DocumentService{
|
||||
return JSON.toJSONString(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加使用id的生成
|
||||
* @param filePath
|
||||
* @param fileName
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String buildDocumentId(String filePath, String fileName,String id) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
}
|
||||
filePath = FilenameUtils.normalize(filePath);
|
||||
String fileType = StringUtils.lowerCase(FilenameUtils.getExtension(filePath));
|
||||
if (StringUtils.isBlank(fileType)) {
|
||||
}
|
||||
// 如果指定了文件名,则需要校验和实体文件格式是否一致
|
||||
if (StringUtils.isNotBlank(fileName) && !fileType.equalsIgnoreCase(FilenameUtils.getExtension(fileName))) {
|
||||
}
|
||||
File docFile = new File(filePath);
|
||||
// 校验文件实体
|
||||
preFileCheck(docFile);
|
||||
fileName = StringUtils.isNotBlank(fileName) ? fileName : docFile.getName();
|
||||
String fileKey = this.fileKey(docFile, fileName);
|
||||
Document document = Document.builder()
|
||||
.fileType(fileType)
|
||||
.title(fileName.substring(id.length()))
|
||||
.storage(filePath)
|
||||
.build();
|
||||
boolean cached = false;
|
||||
document.setKey(fileKey);
|
||||
return JSON.toJSONString(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document getDocument(String documentKey ) {
|
||||
Document doc = null;
|
||||
|
@ -79,6 +79,13 @@ public class onlyofController {
|
||||
@Resource
|
||||
private onlyofService onlyofService;
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得文件编辑分页")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:query')")
|
||||
public CommonResult<PageResult<onlyofRespVO>> getonlyofPage(@Valid onlyofPageReqVO pageReqVO) {
|
||||
PageResult<onlyofDO> pageResult = onlyofService.getonlyofPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, onlyofRespVO.class));
|
||||
}
|
||||
/**
|
||||
* \
|
||||
* 查询所有上传文档信息接口
|
||||
@ -89,15 +96,22 @@ public class onlyofController {
|
||||
@Operation(summary = "获取文件列表")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:filelist')")
|
||||
public ResponseEntity<Object> listFile() {
|
||||
System.out.println("fileList");
|
||||
// System.out.println("fileList");
|
||||
return new ResponseEntity<Object>(uploadService.list(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件编辑的上传文件接口
|
||||
* @param file
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "更新文件编辑")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:update')")
|
||||
public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
|
||||
System.out.println("update"+file.getOriginalFilename());
|
||||
public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws Exception {
|
||||
if (file.isEmpty()){
|
||||
throw new Exception("上传文件不能为空");
|
||||
}
|
||||
@ -106,14 +120,12 @@ public class onlyofController {
|
||||
//更新保存文件信息到数据库
|
||||
FileUtil.saveFile(file.getInputStream(),filePath+file.getOriginalFilename());
|
||||
upload.setUploadDate(new Date());
|
||||
upload.setFileName(fileName.substring(fileName.indexOf(".")));
|
||||
upload.setFilePath(filePath);
|
||||
upload.setFileName(file.getOriginalFilename());
|
||||
upload.setFileSize(file.getSize());
|
||||
System.out.println("111"+upload);
|
||||
// System.out.println("111"+upload);
|
||||
uploadService.save(upload);
|
||||
System.gc();
|
||||
System.out.println("222"+upload);
|
||||
|
||||
return new ResponseEntity<Object>("上传成功", HttpStatus.OK);
|
||||
}
|
||||
@ -127,7 +139,7 @@ public class onlyofController {
|
||||
@Operation(summary = "下载文件")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:download')")
|
||||
public void download(String name, HttpServletResponse response) {
|
||||
System.out.println("download---"+name+"-----"+response);
|
||||
// System.out.println("download---"+name+"-----"+response+"-----");
|
||||
try {
|
||||
FileUtil.downLoadFile(name,filePath,response);
|
||||
} catch (IOException e) {
|
||||
@ -135,40 +147,62 @@ public class onlyofController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文件的接口
|
||||
* @param name
|
||||
* @param userName
|
||||
* @param userId
|
||||
* @param token
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/edit")
|
||||
@Operation(summary = "编辑文件")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:edit')")
|
||||
public ModelAndView editDocFile(@RequestParam String name, String userName, String userId ,String token, Model model) {
|
||||
// System.out.println("edit");
|
||||
String path = filePath+name;
|
||||
System.out.println("path:"+path);
|
||||
// System.out.println("path:"+path);
|
||||
ModelAndView mav = new ModelAndView();
|
||||
Document document = documentService.getDocumentToken(documentService.buildDocument(path, name),token);
|
||||
mav.addObject("document", document);
|
||||
if (!documentService.canEdit(document)) {
|
||||
System.out.println("demo");
|
||||
// System.out.println("demo");
|
||||
return mav;
|
||||
}
|
||||
mav.addObject("documentEditParam", documentService.buildDocumentEditParamToken(userId, userName, name,token));
|
||||
mav.setViewName("editor");
|
||||
System.out.println(mav);
|
||||
// System.out.println(mav);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件编辑打开保存后的回调函数
|
||||
* @param request
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping("/callback")
|
||||
@Operation(summary = "回调文件")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:callback')")
|
||||
public void saveDocumentFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
System.out.println("callback");
|
||||
// System.out.println("callback");
|
||||
//处理编辑回调逻辑
|
||||
callBack(request, response);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件状态的接口
|
||||
* @param name
|
||||
* @return
|
||||
* @throws ParseException
|
||||
*/
|
||||
@GetMapping("/editStatus")
|
||||
@Operation(summary = "文件状态")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:editStatus')")
|
||||
public ResponseEntity<Object> getDoucmentEditStatus(String name) throws ParseException {
|
||||
System.out.println("editStatus");
|
||||
// System.out.println("editStatus");
|
||||
String url = officeUrl+officeCommand;
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("c", "forcesave");
|
||||
@ -184,7 +218,7 @@ public class onlyofController {
|
||||
map.put("key", key);
|
||||
map.put("userdata", "sample userdata");
|
||||
JSONObject obj = (JSONObject) new JSONParser().parse(FileUtil.editStatus(url, JSON.toJSONString(map)));
|
||||
System.out.println("obj"+obj);
|
||||
// System.out.println("obj"+obj);
|
||||
return new ResponseEntity<Object>(obj, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ -199,14 +233,10 @@ public class onlyofController {
|
||||
JSONObject jsonObj = null;
|
||||
System.out.println("===saveeditedfile------------");
|
||||
try {
|
||||
System.out.println("1111");
|
||||
writer = response.getWriter();
|
||||
System.out.println("2222");
|
||||
Scanner scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
|
||||
String body = scanner.hasNext() ? scanner.next() : "";
|
||||
System.out.println("4444: "+body);
|
||||
jsonObj = (JSONObject) new JSONParser().parse(body);
|
||||
System.out.println("5555");
|
||||
// jsonObj = (JSONObject) new JSONParser(body);
|
||||
System.out.println(jsonObj);
|
||||
System.out.println("===saveeditedfile:" + jsonObj.get("status"));
|
||||
@ -250,7 +280,7 @@ public class onlyofController {
|
||||
|
||||
|
||||
|
||||
|
||||
//下面是暂时没用到的接口留着
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建文件编辑")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:create')")
|
||||
@ -276,14 +306,6 @@ public class onlyofController {
|
||||
return success(BeanUtils.toBean(onlyof, onlyofRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得文件编辑分页")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:query')")
|
||||
public CommonResult<PageResult<onlyofRespVO>> getonlyofPage(@Valid onlyofPageReqVO pageReqVO) {
|
||||
PageResult<onlyofDO> pageResult = onlyofService.getonlyofPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, onlyofRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出文件编辑 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:export')")
|
||||
|
@ -19,7 +19,7 @@ public interface onlyofMapper extends BaseMapperX<onlyofDO> {
|
||||
|
||||
default PageResult<onlyofDO> selectPage(onlyofPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<onlyofDO>()
|
||||
.likeIfPresent(onlyofDO::getFileName, reqVO.getFileName())
|
||||
.eqIfPresent(onlyofDO::getFileName, reqVO.getFileName())
|
||||
.eqIfPresent(onlyofDO::getFileSize, reqVO.getFileSize())
|
||||
.eqIfPresent(onlyofDO::getFileType, reqVO.getFileType())
|
||||
.eqIfPresent(onlyofDO::getFilePath, reqVO.getFilePath())
|
||||
@ -29,4 +29,4 @@ public interface onlyofMapper extends BaseMapperX<onlyofDO> {
|
||||
.orderByDesc(onlyofDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" th:href="@{/css/viewer.css}">
|
||||
</head>
|
||||
<!--//整个文件就是前端打开的编辑窗口的配置-->
|
||||
<body>
|
||||
<div class="form">
|
||||
<div id="iframeEditor"></div>
|
||||
@ -13,7 +14,6 @@
|
||||
<pre th:text="${documentEditParam}">Document Edit Param</pre>
|
||||
</div>
|
||||
<script type="text/javascript" th:src="@{/js/jquery-1.8.2.js}"></script>
|
||||
<!-- <script type="text/javascript" src="http://192.168.1.3:7878/web-apps/apps/api/documents/api.js"></script>-->
|
||||
<script type="text/javascript" th:src="@{${documentServerApiJs}}"></script>
|
||||
<script type="text/javascript" th:src="@{/js/editor.js}"></script>
|
||||
<!-- 先通过 th:inline=“javascript” 添加到标签,这样js代码即可访问model中的属性 -->
|
||||
@ -21,5 +21,6 @@
|
||||
// js 中可以通过“[[${xxx}]]” 格式获得实际的值
|
||||
Editor.init([[${document}]], [[${documentEditParam}]]);
|
||||
</script>
|
||||
<!-- <script type="text/javascript" src="http://192.168.1.15:7878/web-apps/apps/api/documents/api.js"></script>-->
|
||||
</body>
|
||||
</html>
|
||||
|
@ -314,11 +314,12 @@ yudao:
|
||||
customer: E77DF18BE109F454A5CD319E44BF5177
|
||||
|
||||
debug: false
|
||||
|
||||
#本机的ip和端口号
|
||||
document:
|
||||
server:
|
||||
host: 192.168.1.3:48080
|
||||
# host: 192.168.1.3:20053
|
||||
host: 192.168.1.15:48080
|
||||
# host: 192.168.1.15:20053
|
||||
# docker的访问地址还有需要的配置
|
||||
files:
|
||||
savePath: D:\doc\
|
||||
docservice:
|
||||
@ -326,7 +327,7 @@ files:
|
||||
edited-docs: .docx|.xlsx|.csv|.pptx|.txt
|
||||
viewed-docs: .pdf|.djvu|.xps
|
||||
url:
|
||||
site: http://192.168.1.3:7878/
|
||||
site: http://192.168.1.15:7878/
|
||||
converter: ConvertService.ashx
|
||||
command: coauthoring/CommandService.ashx
|
||||
api: web-apps/apps/api/documents/api.js
|
||||
|
Loading…
Reference in New Issue
Block a user