文件编辑相关 上传,获取列表,下载
This commit is contained in:
parent
7bc80a5d76
commit
e52c0477b0
@ -21,10 +21,11 @@ public class FileUtil {
|
|||||||
// FileChannel in = new FileInputStream("src/demo20/data.txt").getChannel(),
|
// FileChannel in = new FileInputStream("src/demo20/data.txt").getChannel(),
|
||||||
// out = new FileOutputStream("src/demo20/data2.txt").getChannel();
|
// out = new FileOutputStream("src/demo20/data2.txt").getChannel();
|
||||||
// in.transferTo(0, in.size(), out);
|
// in.transferTo(0, in.size(), out);
|
||||||
System.out.println("outPath11"+outPath);
|
// OutputStream osm = new FileOutputStream(outPath);
|
||||||
OutputStream osm = new FileOutputStream(outPath);
|
// IOUtils.copy(in, osm);
|
||||||
System.out.println("outPath22"+outPath);
|
try (OutputStream osm = new FileOutputStream(outPath)) {
|
||||||
IOUtils.copy(in, osm);
|
IOUtils.copy(in, osm);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -20,10 +20,17 @@ import java.util.Date;
|
|||||||
//@NoArgsConstructor
|
//@NoArgsConstructor
|
||||||
//@AllArgsConstructor
|
//@AllArgsConstructor
|
||||||
public class onlyofficeDO extends BaseEntity {
|
public class onlyofficeDO extends BaseEntity {
|
||||||
|
@TableId(value = "ID", type = IdType.AUTO)
|
||||||
private Integer Id;
|
private Integer Id;
|
||||||
|
@TableField("file_name")
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
@TableField(value = "file_size")
|
||||||
private Long fileSize;
|
private Long fileSize;
|
||||||
|
@TableField(value = "file_type")
|
||||||
private String fileType;
|
private String fileType;
|
||||||
|
@TableField(value = "file_path")
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
@TableField(value = "upload_date")
|
||||||
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||||
private Date uploadDate;
|
private Date uploadDate;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.utils.DocumentCon
|
|||||||
import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.utils.FileUtil;
|
import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.utils.FileUtil;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.utils.Md5Utils;
|
import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.utils.Md5Utils;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.vo.Document;
|
import cn.iocoder.yudao.module.bpm.controller.admin.onlyoffice.vo.Document;
|
||||||
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.onlyoffice.onlyofficeDO;
|
||||||
import cn.iocoder.yudao.module.bpm.service.onlyoffice.document.DocumentService;
|
import cn.iocoder.yudao.module.bpm.service.onlyoffice.document.DocumentService;
|
||||||
import cn.iocoder.yudao.module.bpm.service.onlyoffice.fileupload.FileUploadService;
|
import cn.iocoder.yudao.module.bpm.service.onlyoffice.fileupload.FileUploadService;
|
||||||
import cn.iocoder.yudao.module.only.controller.admin.only.vo.onlyofPageReqVO;
|
import cn.iocoder.yudao.module.only.controller.admin.only.vo.onlyofPageReqVO;
|
||||||
@ -22,6 +23,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.dom4j.DocumentException;
|
||||||
import org.hashids.Hashids;
|
import org.hashids.Hashids;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
@ -46,10 +48,7 @@ import javax.validation.Valid;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
@ -80,11 +79,43 @@ public class onlyofController {
|
|||||||
@Resource
|
@Resource
|
||||||
private onlyofService onlyofService;
|
private onlyofService onlyofService;
|
||||||
|
|
||||||
@PostMapping("/create")
|
/**
|
||||||
@Operation(summary = "创建文件编辑")
|
* \
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:create')")
|
* 查询所有上传文档信息接口
|
||||||
public CommonResult<Integer> createonlyof(@Valid @RequestBody onlyofSaveReqVO createReqVO) {
|
*
|
||||||
return success(onlyofService.createonlyof(createReqVO));
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/filelist")
|
||||||
|
@Operation(summary = "获取文件列表")
|
||||||
|
@PreAuthorize("@ss.hasPermission('only:onlyof:filelist')")
|
||||||
|
public ResponseEntity<Object> listFile() {
|
||||||
|
System.out.println("fileList");
|
||||||
|
return new ResponseEntity<Object>(uploadService.list(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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());
|
||||||
|
if (file.isEmpty()){
|
||||||
|
throw new Exception("上传文件不能为空");
|
||||||
|
}
|
||||||
|
onlyofficeDO upload = new onlyofficeDO();
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
//更新保存文件信息到数据库
|
||||||
|
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);
|
||||||
|
uploadService.save(upload);
|
||||||
|
System.gc();
|
||||||
|
System.out.println("222"+upload);
|
||||||
|
|
||||||
|
return new ResponseEntity<Object>("上传成功", HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,8 +124,8 @@ public class onlyofController {
|
|||||||
* @param response
|
* @param response
|
||||||
*/
|
*/
|
||||||
@GetMapping("/download")
|
@GetMapping("/download")
|
||||||
@Operation(summary = "创建文件编辑")
|
@Operation(summary = "下载文件")
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:create')")
|
@PreAuthorize("@ss.hasPermission('only:onlyof:download')")
|
||||||
public void download(String name, HttpServletResponse response) {
|
public void download(String name, HttpServletResponse response) {
|
||||||
System.out.println("download---"+name+"-----"+response);
|
System.out.println("download---"+name+"-----"+response);
|
||||||
try {
|
try {
|
||||||
@ -105,8 +136,8 @@ public class onlyofController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/edit")
|
@GetMapping("/edit")
|
||||||
@Operation(summary = "更新文件编辑")
|
@Operation(summary = "编辑文件")
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:update')")
|
@PreAuthorize("@ss.hasPermission('only:onlyof:edit')")
|
||||||
public ModelAndView editDocFile(@RequestParam String name, String userName, String userId ,String token, Model model) {
|
public ModelAndView editDocFile(@RequestParam String name, String userName, String userId ,String token, Model model) {
|
||||||
String path = filePath+name;
|
String path = filePath+name;
|
||||||
System.out.println("path:"+path);
|
System.out.println("path:"+path);
|
||||||
@ -122,9 +153,20 @@ public class onlyofController {
|
|||||||
System.out.println(mav);
|
System.out.println(mav);
|
||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/callback")
|
||||||
|
@Operation(summary = "回调文件")
|
||||||
|
@PreAuthorize("@ss.hasPermission('only:onlyof:callback')")
|
||||||
|
public void saveDocumentFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
System.out.println("callback");
|
||||||
|
//处理编辑回调逻辑
|
||||||
|
callBack(request, response);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/editStatus")
|
@GetMapping("/editStatus")
|
||||||
@Operation(summary = "更新文件编辑")
|
@Operation(summary = "文件状态")
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:update')")
|
@PreAuthorize("@ss.hasPermission('only:onlyof:editStatus')")
|
||||||
public ResponseEntity<Object> getDoucmentEditStatus(String name) throws ParseException {
|
public ResponseEntity<Object> getDoucmentEditStatus(String name) throws ParseException {
|
||||||
System.out.println("editStatus");
|
System.out.println("editStatus");
|
||||||
String url = officeUrl+officeCommand;
|
String url = officeUrl+officeCommand;
|
||||||
@ -142,19 +184,10 @@ public class onlyofController {
|
|||||||
map.put("key", key);
|
map.put("key", key);
|
||||||
map.put("userdata", "sample userdata");
|
map.put("userdata", "sample userdata");
|
||||||
JSONObject obj = (JSONObject) new JSONParser().parse(FileUtil.editStatus(url, JSON.toJSONString(map)));
|
JSONObject obj = (JSONObject) new JSONParser().parse(FileUtil.editStatus(url, JSON.toJSONString(map)));
|
||||||
|
System.out.println("obj"+obj);
|
||||||
return new ResponseEntity<Object>(obj, HttpStatus.OK);
|
return new ResponseEntity<Object>(obj, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/callback")
|
|
||||||
@Operation(summary = "更新文件编辑")
|
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:update')")
|
|
||||||
public void saveDocumentFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
||||||
System.out.println("callback");
|
|
||||||
//处理编辑回调逻辑
|
|
||||||
callBack(request, response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理在线编辑文档的逻辑
|
* 处理在线编辑文档的逻辑
|
||||||
* @param request
|
* @param request
|
||||||
@ -215,37 +248,15 @@ public class onlyofController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/update")
|
|
||||||
@Operation(summary = "更新文件编辑")
|
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:update')")
|
|
||||||
// public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
|
|
||||||
// public ResponseEntity<Object> upload( String file) throws Exception {
|
|
||||||
public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file) throws Exception {
|
|
||||||
System.out.println("Open");
|
|
||||||
System.out.println("1111"+file.getOriginalFilename());
|
|
||||||
if (file.isEmpty()){
|
|
||||||
throw new Exception("上传文件不能为空");
|
|
||||||
}
|
|
||||||
// onlyofficeDO upload = new onlyofficeDO();
|
|
||||||
// System.out.println("3333"+upload);
|
|
||||||
// String fileName = file.getOriginalFilename();
|
|
||||||
// //更新保存文件信息到数据库
|
|
||||||
// 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(upload);
|
|
||||||
// uploadService.save(upload);
|
|
||||||
// System.out.println("a111");
|
|
||||||
|
|
||||||
return new ResponseEntity<Object>("上传成功", HttpStatus.OK);
|
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建文件编辑")
|
||||||
|
@PreAuthorize("@ss.hasPermission('only:onlyof:create')")
|
||||||
|
public CommonResult<Integer> createonlyof(@Valid @RequestBody onlyofSaveReqVO createReqVO) {
|
||||||
|
return success(onlyofService.createonlyof(createReqVO));
|
||||||
}
|
}
|
||||||
// public CommonResult<Boolean> updateonlyof(@Valid @RequestBody onlyofSaveReqVO updateReqVO) {
|
|
||||||
// onlyofService.updateonlyof(updateReqVO);
|
|
||||||
// return success(true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@DeleteMapping("/delete")
|
@DeleteMapping("/delete")
|
||||||
@Operation(summary = "删除文件编辑")
|
@Operation(summary = "删除文件编辑")
|
||||||
@ -286,31 +297,4 @@ public class onlyofController {
|
|||||||
BeanUtils.toBean(list, onlyofRespVO.class));
|
BeanUtils.toBean(list, onlyofRespVO.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/upload")
|
|
||||||
@PreAuthorize("@ss.hasPermission('only:onlyof:query')")
|
|
||||||
public String upload() {
|
|
||||||
return "56789";
|
|
||||||
}
|
|
||||||
// public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
|
|
||||||
// System.out.println("1111");
|
|
||||||
// if (file.isEmpty()){
|
|
||||||
// throw new Exception("上传文件不能为空");
|
|
||||||
// }
|
|
||||||
// onlyofficeDO upload = new onlyofficeDO();
|
|
||||||
// System.out.println("3333"+upload);
|
|
||||||
// String fileName = file.getOriginalFilename();
|
|
||||||
// //更新保存文件信息到数据库
|
|
||||||
// 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(upload);
|
|
||||||
// uploadService.save(upload);
|
|
||||||
// System.out.println("a111");
|
|
||||||
//
|
|
||||||
// return new ResponseEntity<Object>("上传成功", HttpStatus.OK);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user