only office文件上传修改uuid参数为cDate
This commit is contained in:
parent
d52cc0c932
commit
a81d88984e
@ -32,7 +32,7 @@ public interface DocumentService {
|
||||
* @param documentKey
|
||||
* @return
|
||||
*/
|
||||
Document getDocumentToken(String documentKey,String token, String uuid);
|
||||
Document getDocumentToken(String documentKey,String token, String cDate);
|
||||
|
||||
|
||||
/**
|
||||
@ -57,7 +57,7 @@ public interface DocumentService {
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
DocumentEditParam buildDocumentEditParamToken(String userId, String userName, String fileName,String token,String uuid);
|
||||
DocumentEditParam buildDocumentEditParamToken(String userId, String userName, String fileName,String token,String cDate);
|
||||
|
||||
/**
|
||||
* 编辑后保存文档实体文件
|
||||
|
@ -133,7 +133,7 @@ public class DocumentServiceImpl implements DocumentService{
|
||||
return doc;
|
||||
}
|
||||
@Override
|
||||
public Document getDocumentToken(String documentKey,String token, String uuid) {
|
||||
public Document getDocumentToken(String documentKey,String token, String cDate) {
|
||||
Document doc = null;
|
||||
|
||||
try {
|
||||
@ -146,7 +146,7 @@ public class DocumentServiceImpl implements DocumentService{
|
||||
}
|
||||
// 从缓存中取出后,再绑定非必需缓存字段(节省缓存大小)
|
||||
// doc.setKey(documentKey);
|
||||
doc.setUrl(fileUrlToken(doc.getTitle(),token,uuid));
|
||||
doc.setUrl(fileUrlToken(doc.getTitle(),token,cDate));
|
||||
if (log.isDebugEnabled()) {
|
||||
log.info(doc.toString());
|
||||
}
|
||||
@ -200,8 +200,8 @@ public class DocumentServiceImpl implements DocumentService{
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
private String fileUrlToken(String filename,String token, String uuid) {
|
||||
return String.format(DocumentConstants.OFFICE_API_DOC_FILE, getServerHost(), "?name="+filename+"&uuid="+uuid+"&token="+token);
|
||||
private String fileUrlToken(String filename,String token, String cDate) {
|
||||
return String.format(DocumentConstants.OFFICE_API_DOC_FILE, getServerHost(), "?name="+filename+"&cDate="+cDate+"&token="+token);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,9 +241,9 @@ public class DocumentServiceImpl implements DocumentService{
|
||||
.build();
|
||||
}
|
||||
@Override
|
||||
public DocumentEditParam buildDocumentEditParamToken(String userId, String userName, String fileName,String token, String uuid) {
|
||||
public DocumentEditParam buildDocumentEditParamToken(String userId, String userName, String fileName,String token, String cDate) {
|
||||
return DocumentEditParam.builder()
|
||||
.callbackUrl(callbackUrl(fileName)+"&uuid="+uuid+"&token="+token)
|
||||
.callbackUrl(callbackUrl(fileName)+"&cDate="+cDate+"&token="+token)
|
||||
.user(DocumentEditParam.UserBean.builder()
|
||||
.id(userId)
|
||||
.name(userName)
|
||||
|
@ -109,8 +109,8 @@ public class onlyofController {
|
||||
@PostMapping("/update")
|
||||
@Operation(summary = "更新文件编辑")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:update')")
|
||||
public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file,@RequestParam("uuid") String uuid,HttpServletRequest request) throws Exception {
|
||||
uuid = uuid.isEmpty() ? uuid : uuid + "\\";
|
||||
public ResponseEntity<Object> upload(@RequestParam("file") MultipartFile file,@RequestParam("cDate") String cDate,HttpServletRequest request) throws Exception {
|
||||
cDate = cDate.isEmpty() ? cDate : cDate + "\\";
|
||||
// System.out.println("update"+file.getOriginalFilename()+uuid);
|
||||
if (file.isEmpty()){
|
||||
throw new Exception("上传文件不能为空");
|
||||
@ -118,9 +118,9 @@ public class onlyofController {
|
||||
onlyofficeDO upload = new onlyofficeDO();
|
||||
String fileName = file.getOriginalFilename();
|
||||
//更新保存文件信息到数据库
|
||||
FileUtil.saveFile(file.getInputStream(),filePath+uuid+file.getOriginalFilename(),filePath+uuid);
|
||||
FileUtil.saveFile(file.getInputStream(),filePath+cDate+file.getOriginalFilename(),filePath+cDate);
|
||||
upload.setUploadDate(new Date());
|
||||
upload.setFilePath(filePath+uuid);
|
||||
upload.setFilePath(filePath+cDate);
|
||||
upload.setFileName(file.getOriginalFilename());
|
||||
upload.setFileSize(file.getSize());
|
||||
// System.out.println("111"+upload);
|
||||
@ -142,21 +142,21 @@ public class onlyofController {
|
||||
@GetMapping("/edit")
|
||||
@Operation(summary = "编辑文件")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:edit')")
|
||||
public ModelAndView editDocFile(@RequestParam String name, String userName, String userId ,String uuid ,String token, Model model) {
|
||||
String uuid2 = "";
|
||||
uuid2 = uuid.isEmpty() ? uuid : uuid + "\\";
|
||||
String path = filePath+uuid2+name;
|
||||
public ModelAndView editDocFile(@RequestParam String name, String userName, String userId ,String cDate ,String token, Model model) {
|
||||
String cDate2 = "";
|
||||
cDate2 = cDate.isEmpty() ? cDate : cDate + "\\";
|
||||
String path = filePath+cDate2+name;
|
||||
// System.out.println("path:"+path);
|
||||
// System.out.println("edit"+uuid2);
|
||||
// System.out.println("token"+token);
|
||||
ModelAndView mav = new ModelAndView();
|
||||
Document document = documentService.getDocumentToken(documentService.buildDocument(path, name),token,uuid);
|
||||
Document document = documentService.getDocumentToken(documentService.buildDocument(path, name),token,cDate);
|
||||
mav.addObject("document", document);
|
||||
if (!documentService.canEdit(document)) {
|
||||
// System.out.println("demo");
|
||||
return mav;
|
||||
}
|
||||
mav.addObject("documentEditParam", documentService.buildDocumentEditParamToken(userId, userName, name,token,uuid2));
|
||||
mav.addObject("documentEditParam", documentService.buildDocumentEditParamToken(userId, userName, name,token,cDate2));
|
||||
mav.setViewName("editor");
|
||||
// System.out.println(mav);
|
||||
return mav;
|
||||
@ -170,11 +170,11 @@ public class onlyofController {
|
||||
@GetMapping("/download")
|
||||
@Operation(summary = "下载文件")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:download')")
|
||||
public void download(String name, String uuid,HttpServletResponse response) {
|
||||
uuid = uuid.equals("") ? uuid : uuid + "\\";
|
||||
public void download(String name, String cDate,HttpServletResponse response) {
|
||||
cDate = cDate.equals("") ? cDate : cDate + "\\";
|
||||
// System.out.println("download: "+name+"---"+response+"---"+uuid);
|
||||
try {
|
||||
FileUtil.downLoadFile(name,filePath+uuid,response);
|
||||
FileUtil.downLoadFile(name,filePath+cDate,response);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -189,10 +189,10 @@ public class onlyofController {
|
||||
@RequestMapping("/callback")
|
||||
@Operation(summary = "回调文件")
|
||||
@PreAuthorize("@ss.hasPermission('only:onlyof:callback')")
|
||||
public void saveDocumentFile(HttpServletRequest request, HttpServletResponse response,String uuid) throws IOException {
|
||||
public void saveDocumentFile(HttpServletRequest request, HttpServletResponse response,String cDate) throws IOException {
|
||||
// System.out.println("callback"+uuid);
|
||||
//处理编辑回调逻辑
|
||||
callBack(request, response,uuid);
|
||||
callBack(request, response,cDate);
|
||||
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ public class onlyofController {
|
||||
6 - document is being edited, but the current document state is saved,
|
||||
7 - error has occurred while force saving the document.
|
||||
* */
|
||||
private void callBack(HttpServletRequest request, HttpServletResponse response, String uuid) throws IOException {
|
||||
private void callBack(HttpServletRequest request, HttpServletResponse response, String cDate) throws IOException {
|
||||
PrintWriter writer = null;
|
||||
JSONObject jsonObj = null;
|
||||
// System.out.println("===saveeditedfile------------");
|
||||
@ -253,7 +253,7 @@ public class onlyofController {
|
||||
// System.out.println(jsonObj);
|
||||
// System.out.println("===saveeditedfile:" + jsonObj.get("status"));
|
||||
if ((long) jsonObj.get("status") == 2) {
|
||||
FileUtil.callBackSaveDocument(jsonObj,filePath+uuid,request, response);
|
||||
FileUtil.callBackSaveDocument(jsonObj,filePath+cDate,request, response);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
@ -269,14 +269,14 @@ public class onlyofController {
|
||||
if ((long) jsonObj.get("status") == 6) {
|
||||
//处理当文档正在编辑为关闭时,下载文档
|
||||
if (((String)jsonObj.get("userdata")).equals("sample userdata")){
|
||||
FileUtil.callBackSaveDocument(jsonObj,filePath+uuid,request, response);
|
||||
FileUtil.callBackSaveDocument(jsonObj,filePath+cDate,request, response);
|
||||
}
|
||||
|
||||
// System.out.println("====保存失败:");
|
||||
writer.write("{\"error\":1}");
|
||||
} else {
|
||||
//执行删除编辑时下载保存的文件:
|
||||
FileUtil.deleteTempFile(filePath+uuid,request.getParameter("fileName"));
|
||||
FileUtil.deleteTempFile(filePath+cDate,request.getParameter("fileName"));
|
||||
writer.write("{\"error\":0}");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user