1.优化上次提交wiki条目右侧菜单栏展示效果
2.新增对于md的单个导入和批量导入 3.单个导入和批量导入的架子搭好
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,86 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||||
|
import com.zyplayer.doc.wiki.batch.entry.DocEntry;
|
||||||
|
import com.zyplayer.doc.wiki.batch.strategy.ConditionalStrategySelector;
|
||||||
|
import com.zyplayer.doc.wiki.batch.strategy.comb.ICombDependencyStrategy;
|
||||||
|
import com.zyplayer.doc.wiki.batch.strategy.file.IFileStrategy;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档批量导入功能
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class BatchDocImportManager {
|
||||||
|
|
||||||
|
@Value("${zyplayer.doc.wiki.upload-path:}")
|
||||||
|
private String uploadPath;
|
||||||
|
@Resource
|
||||||
|
ConditionalStrategySelector conditionalStrategySelector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档批量导入策略选择
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
public String importBatchDoc(WikiPageFile wikiPageFile, MultipartFile file) {
|
||||||
|
String suffix = FileUtil.getSuffix(file.getOriginalFilename());
|
||||||
|
try {
|
||||||
|
IFileStrategy strategy = conditionalStrategySelector.getStrategy(suffix, IFileStrategy.class);
|
||||||
|
if (null == strategy) {
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.info("暂时不支持{}格式文件的导入", suffix);
|
||||||
|
}
|
||||||
|
return "暂时不支持" + suffix + "格式文件的导入";
|
||||||
|
}
|
||||||
|
if (log.isInfoEnabled()) {
|
||||||
|
log.info("文档导入的格式为{},选择的策略为{}", suffix, strategy.getClass().getName());
|
||||||
|
}
|
||||||
|
String info = strategy.file(uploadPath, wikiPageFile, file);
|
||||||
|
if (null == info) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("导入文件发生错误{}", e.getMessage());
|
||||||
|
return "导入文件发生错误!";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档解析策略选择
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
public ArrayList<DocEntry> combDependency(File[] files) {
|
||||||
|
ArrayList<DocEntry> docs = new ArrayList<>();
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
docs.addAll(combDependency(file.listFiles()));
|
||||||
|
}
|
||||||
|
if (file.isFile()) {
|
||||||
|
String suffix = FileUtil.getSuffix(file);
|
||||||
|
ICombDependencyStrategy strategy = conditionalStrategySelector.getStrategy(suffix, ICombDependencyStrategy.class);
|
||||||
|
if (null == strategy) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
strategy.comb(docs, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.entry;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档实体
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 20230713
|
||||||
|
*/
|
||||||
|
public class DocEntry {
|
||||||
|
LinkedList<MediaEntry> medias = new LinkedList<>();
|
||||||
|
String context = "";
|
||||||
|
String name = "";
|
||||||
|
|
||||||
|
public LinkedList<MediaEntry> getMedias() {
|
||||||
|
return medias;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMedia(MediaEntry media) {
|
||||||
|
this.medias.add(media);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContext(String context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.entry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 媒体实体
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 20230713
|
||||||
|
*/
|
||||||
|
public class MediaEntry {
|
||||||
|
String oldFileLink;
|
||||||
|
String oldFileLinkName;
|
||||||
|
String oldFileName;
|
||||||
|
|
||||||
|
public String getOldFileLink() {
|
||||||
|
return oldFileLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldFileLink(String oldFileLink,String oldFileLinkName) {
|
||||||
|
this.oldFileLink = oldFileLink;
|
||||||
|
this.oldFileLinkName = oldFileLinkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOldFileLinkName() {
|
||||||
|
return oldFileLinkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldFileLinkName(String oldFileLinkName) {
|
||||||
|
this.oldFileLinkName = oldFileLinkName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOldFileName() {
|
||||||
|
return oldFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldFileName(String oldFileName) {
|
||||||
|
this.oldFileName = oldFileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.wiki.batch.strategy.base.IConditionalStrategy;
|
||||||
|
import org.springframework.beans.factory.ObjectProvider;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 策略选择器
|
||||||
|
* 只要是实现自IConditionalStrategy的策略,都能通过这个类按规则匹配
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class ConditionalStrategySelector {
|
||||||
|
Map<Class<?>,ConditionalStrategySeletorUnit> cache = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册所有策略
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
public ConditionalStrategySelector(ObjectProvider<List<IConditionalStrategy>> allStrategyObjectProvider) {
|
||||||
|
List<IConditionalStrategy> allStrategy = allStrategyObjectProvider.getIfAvailable();
|
||||||
|
Map<? extends Class<?>, List<IConditionalStrategy>> units = allStrategy.stream().collect(Collectors.groupingBy(iterm -> iterm.getClass().getInterfaces()[0]));
|
||||||
|
Set<? extends Map.Entry<? extends Class<?>, List<IConditionalStrategy>>> entries = units.entrySet();
|
||||||
|
//策略分类到一层缓存
|
||||||
|
for (Map.Entry<? extends Class<?>, List<IConditionalStrategy>> entry : entries) {
|
||||||
|
cache.put(entry.getKey(), new ConditionalStrategySeletorUnit(entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getStrategy(String condition,Class<?> clazz){
|
||||||
|
ConditionalStrategySeletorUnit conditionalStrategySeletorUnit= cache.get(clazz);
|
||||||
|
if (null == conditionalStrategySeletorUnit){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
T strategy = (T) conditionalStrategySeletorUnit.getStrategy(condition);
|
||||||
|
if (null == strategy) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConditionalStrategySeletorUnit<T extends IConditionalStrategy> {
|
||||||
|
List<T> strategys;
|
||||||
|
|
||||||
|
//策略集体实现到二层缓存
|
||||||
|
ConcurrentHashMap<String, T> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public ConditionalStrategySeletorUnit(List<T> strategys) {
|
||||||
|
this.strategys = strategys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getStrategy(String condition) {
|
||||||
|
T cacheStrategy = cache.get(condition);
|
||||||
|
if (null != cacheStrategy) {
|
||||||
|
return cacheStrategy;
|
||||||
|
}
|
||||||
|
for (T strategy : strategys) {
|
||||||
|
if (strategy.matchCondition(condition)) {
|
||||||
|
cache.put(condition, strategy);
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy.base;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件控制策略接口
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 20230713
|
||||||
|
*/
|
||||||
|
public interface IConditionalStrategy {
|
||||||
|
public String getCondition();
|
||||||
|
|
||||||
|
public default boolean matchCondition(String key){
|
||||||
|
return key.equals(getCondition());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy.comb;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.wiki.batch.entry.DocEntry;
|
||||||
|
import com.zyplayer.doc.wiki.batch.strategy.base.IConditionalStrategy;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件控制依赖梳理策略接口
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 20230717
|
||||||
|
*/
|
||||||
|
public interface ICombDependencyStrategy extends IConditionalStrategy {
|
||||||
|
public void comb(ArrayList<DocEntry> docs, File file);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy.comb;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import com.zyplayer.doc.wiki.batch.entry.DocEntry;
|
||||||
|
import com.zyplayer.doc.wiki.batch.entry.MediaEntry;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
/**
|
||||||
|
* MD格式内容分析策略
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class MDCombDependencyStrategy implements ICombDependencyStrategy {
|
||||||
|
private final static String LEFT_TAG = "![";
|
||||||
|
private final static String RIGHT_TAG_REG = "]\\(";
|
||||||
|
private final static String RIGHT_TAG = "](";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void comb(ArrayList<DocEntry> docs, File file) {
|
||||||
|
DocEntry docEntry = new DocEntry();
|
||||||
|
docEntry.setName(FileUtil.getName(file));
|
||||||
|
String info = FileUtil.readUtf8String(file);
|
||||||
|
docEntry.setContext(info);
|
||||||
|
while (info.indexOf(LEFT_TAG) >= 0 && info.indexOf(RIGHT_TAG) >= 0) {
|
||||||
|
String window = info;
|
||||||
|
while(window.indexOf(LEFT_TAG)>=0){
|
||||||
|
int leftOffset = window.indexOf(LEFT_TAG)+2;
|
||||||
|
window= window.substring(leftOffset);
|
||||||
|
int rightOffset = window.indexOf(")")+1;
|
||||||
|
window = window.substring(0,rightOffset);
|
||||||
|
}
|
||||||
|
String [] splitWindow = window.split(RIGHT_TAG_REG);
|
||||||
|
MediaEntry mediaEntry = new MediaEntry();
|
||||||
|
mediaEntry.setOldFileName(splitWindow[0]);
|
||||||
|
String realWindow = splitWindow[1].replace(")","");
|
||||||
|
int pos = realWindow.lastIndexOf(File.separator);
|
||||||
|
String oldFileLink = realWindow;
|
||||||
|
if (pos>0) {
|
||||||
|
realWindow= realWindow.substring(pos+1);
|
||||||
|
}
|
||||||
|
mediaEntry.setOldFileLink(file.getAbsolutePath().replace(file.getName(),"")+realWindow,oldFileLink);
|
||||||
|
info = info.substring(info.indexOf(window));
|
||||||
|
docEntry.addMedia(mediaEntry);
|
||||||
|
}
|
||||||
|
docs.add(docEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCondition() {
|
||||||
|
return "md";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy.file;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||||
|
import com.zyplayer.doc.wiki.batch.strategy.base.IConditionalStrategy;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件控制文件归档策略接口
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 20230717
|
||||||
|
*/
|
||||||
|
public interface IFileStrategy extends IConditionalStrategy {
|
||||||
|
public String file(String uploadPath, WikiPageFile wikiPageFile, MultipartFile file)throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy.file;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||||
|
import com.zyplayer.doc.data.service.manage.WikiPageService;
|
||||||
|
import com.zyplayer.doc.wiki.service.WikiPageFileServiceEx;
|
||||||
|
import com.zyplayer.doc.wiki.service.WikiPageUploadService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MD格式文件上传策略
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class MDFileStrategy implements IFileStrategy {
|
||||||
|
|
||||||
|
private final WikiPageService wikiPageService;
|
||||||
|
private final WikiPageUploadService wikipageUploadService;
|
||||||
|
private final WikiPageFileServiceEx wikiPageFileServiceEx;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String file(String uploadPath, WikiPageFile wikiPageFile, MultipartFile file)throws IOException{
|
||||||
|
Long pageID = wikiPageFile.getPageId();
|
||||||
|
WikiPage page = wikiPageService.getById(pageID);
|
||||||
|
WikiPage wikiPage = new WikiPage();
|
||||||
|
wikiPage.setName(file.getOriginalFilename().substring(0,file.getOriginalFilename().indexOf(".")));
|
||||||
|
Long spaceId = wikiPageFile.getId();
|
||||||
|
Long id = wikiPageFile.getPageId();
|
||||||
|
if (null != page) {
|
||||||
|
spaceId = page.getSpaceId();
|
||||||
|
id = page.getId();
|
||||||
|
}
|
||||||
|
wikiPage.setSpaceId(spaceId);
|
||||||
|
wikiPage.setParentId(id);
|
||||||
|
wikiPage.setEditorType(2);
|
||||||
|
String context ="";
|
||||||
|
wikipageUploadService.update(wikiPage,context,context);
|
||||||
|
wikiPageFile.setPageId(wikiPage.getId());
|
||||||
|
wikiPageFileServiceEx.uploadFile(wikiPageFile,file,0);
|
||||||
|
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/"+wikiPageFile.getUuid()+wikiPageFile.getFileName().substring(wikiPageFile.getFileName().indexOf("."));
|
||||||
|
context = FileUtil.readUtf8String(path);
|
||||||
|
wikipageUploadService.update(wikiPage,context,context);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCondition() {
|
||||||
|
return "md";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
package com.zyplayer.doc.wiki.batch.strategy.file;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ZipUtil;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||||
|
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
|
||||||
|
import com.zyplayer.doc.data.service.manage.WikiPageService;
|
||||||
|
import com.zyplayer.doc.wiki.batch.BatchDocImportManager;
|
||||||
|
import com.zyplayer.doc.wiki.batch.entry.DocEntry;
|
||||||
|
import com.zyplayer.doc.wiki.batch.entry.MediaEntry;
|
||||||
|
import com.zyplayer.doc.wiki.service.WikiPageUploadService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ZIP格式文件上传策略
|
||||||
|
*
|
||||||
|
* @author Sh1yu
|
||||||
|
* @since 2023年7月13日
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class ZIPFileStrategy implements IFileStrategy {
|
||||||
|
private final BatchDocImportManager batchDocImportManger;
|
||||||
|
private final WikiPageFileService wikiPageFileService;
|
||||||
|
private final WikiPageUploadService wikiPageUploadService;
|
||||||
|
private final WikiPageService wikiPageService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String file(String uploadPath, WikiPageFile wikiPageFile, MultipartFile file) throws IOException {
|
||||||
|
Long pageID = wikiPageFile.getPageId();
|
||||||
|
WikiPage page = wikiPageService.getById(pageID);
|
||||||
|
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
|
||||||
|
File dir = new File(path);
|
||||||
|
dir.mkdirs();
|
||||||
|
File localReplica = new File(path + file.hashCode() + file.getOriginalFilename());
|
||||||
|
localReplica.createNewFile();
|
||||||
|
file.transferTo(localReplica);
|
||||||
|
File unzip = ZipUtil.unzip(localReplica, CharsetUtil.CHARSET_GBK);
|
||||||
|
File[] files = unzip.listFiles();
|
||||||
|
ArrayList<DocEntry> docEntries = batchDocImportManger.combDependency(files);
|
||||||
|
for (DocEntry docEntry : docEntries) {
|
||||||
|
WikiPage wikiPage = new WikiPage();
|
||||||
|
wikiPage.setName(docEntry.getName());
|
||||||
|
Long spaceId = wikiPageFile.getId();
|
||||||
|
Long id = wikiPageFile.getPageId();
|
||||||
|
if (null != page) {
|
||||||
|
spaceId = page.getSpaceId();
|
||||||
|
id = page.getId();
|
||||||
|
}
|
||||||
|
wikiPage.setSpaceId(spaceId);
|
||||||
|
wikiPage.setParentId(id);
|
||||||
|
wikiPage.setEditorType(2);
|
||||||
|
String context = docEntry.getContext();
|
||||||
|
wikiPageUploadService.update(wikiPage, context, context);
|
||||||
|
LinkedList<MediaEntry> medias = docEntry.getMedias();
|
||||||
|
for (MediaEntry media : medias) {
|
||||||
|
File mediaFile = new File(media.getOldFileLink());
|
||||||
|
WikiPageFile mediaWikiPageFile = new WikiPageFile();
|
||||||
|
mediaWikiPageFile.setPageId(wikiPage.getId());
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
|
||||||
|
String savePath = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
|
||||||
|
File newFile = new File(savePath);
|
||||||
|
if (!newFile.exists() && !newFile.mkdirs()) {
|
||||||
|
log.warn("创建文件夹失败{}", savePath);
|
||||||
|
return "创建文件夹失败";
|
||||||
|
}
|
||||||
|
String simpleUUID = IdUtil.simpleUUID();
|
||||||
|
savePath += simpleUUID + "." + FileUtil.getSuffix(media.getOldFileLink());
|
||||||
|
newFile = new File(savePath);
|
||||||
|
try {
|
||||||
|
if (!mediaFile.exists()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
FileUtil.copy(mediaFile, newFile, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error("保存文件失败{}", savePath);
|
||||||
|
return "保存文件失败";
|
||||||
|
}
|
||||||
|
mediaWikiPageFile.setFileSize(FileUtil.size(mediaFile));
|
||||||
|
mediaWikiPageFile.setUuid(simpleUUID);
|
||||||
|
mediaWikiPageFile.setFileUrl(savePath);
|
||||||
|
mediaWikiPageFile.setFileName(media.getOldFileName());
|
||||||
|
mediaWikiPageFile.setCreateTime(new Date());
|
||||||
|
mediaWikiPageFile.setCreateUserId(currentUser.getUserId());
|
||||||
|
mediaWikiPageFile.setCreateUserName(currentUser.getUsername());
|
||||||
|
mediaWikiPageFile.setDelFlag(0);
|
||||||
|
wikiPageFileService.save(mediaWikiPageFile);
|
||||||
|
mediaWikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + mediaWikiPageFile.getUuid());
|
||||||
|
context = context.replace(media.getOldFileLinkName(), mediaWikiPageFile.getFileUrl());
|
||||||
|
}
|
||||||
|
wikiPageUploadService.update(wikiPage, context, context);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCondition() {
|
||||||
|
return "zip";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ import com.zyplayer.doc.data.config.security.DocUserDetails;
|
|||||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
import com.zyplayer.doc.data.repository.manage.entity.*;
|
import com.zyplayer.doc.data.repository.manage.entity.*;
|
||||||
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageContentMapper;
|
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageContentMapper;
|
||||||
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageMapper;
|
|
||||||
import com.zyplayer.doc.data.repository.manage.param.SearchByEsParam;
|
import com.zyplayer.doc.data.repository.manage.param.SearchByEsParam;
|
||||||
import com.zyplayer.doc.data.repository.manage.vo.SpaceNewsVo;
|
import com.zyplayer.doc.data.repository.manage.vo.SpaceNewsVo;
|
||||||
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
||||||
@@ -20,8 +19,8 @@ import com.zyplayer.doc.data.utils.CachePrefix;
|
|||||||
import com.zyplayer.doc.data.utils.CacheUtil;
|
import com.zyplayer.doc.data.utils.CacheUtil;
|
||||||
import com.zyplayer.doc.wiki.controller.vo.WikiPageContentVo;
|
import com.zyplayer.doc.wiki.controller.vo.WikiPageContentVo;
|
||||||
import com.zyplayer.doc.wiki.controller.vo.WikiPageVo;
|
import com.zyplayer.doc.wiki.controller.vo.WikiPageVo;
|
||||||
import com.zyplayer.doc.wiki.framework.common.MDToText;
|
|
||||||
import com.zyplayer.doc.wiki.framework.consts.SpaceType;
|
import com.zyplayer.doc.wiki.framework.consts.SpaceType;
|
||||||
|
import com.zyplayer.doc.wiki.service.WikiPageUploadService;
|
||||||
import com.zyplayer.doc.wiki.service.common.WikiPageAuthService;
|
import com.zyplayer.doc.wiki.service.common.WikiPageAuthService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -37,7 +36,6 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -47,6 +45,7 @@ import java.util.stream.Collectors;
|
|||||||
* 文档控制器
|
* 文档控制器
|
||||||
*
|
*
|
||||||
* @author 暮光:城中城
|
* @author 暮光:城中城
|
||||||
|
* @author Sh1yu
|
||||||
* @since 2019年2月17日
|
* @since 2019年2月17日
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -55,18 +54,20 @@ import java.util.stream.Collectors;
|
|||||||
@RequestMapping("/zyplayer-doc-wiki/page")
|
@RequestMapping("/zyplayer-doc-wiki/page")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WikiPageController {
|
public class WikiPageController {
|
||||||
|
|
||||||
private final WikiPageService wikiPageService;
|
private final WikiPageService wikiPageService;
|
||||||
private final WikiPageContentService wikiPageContentService;
|
private final WikiPageContentService wikiPageContentService;
|
||||||
private final WikiPageContentMapper wikiPageContentMapper;
|
private final WikiPageContentMapper wikiPageContentMapper;
|
||||||
private final WikiPageFileService wikiPageFileService;
|
private final WikiPageFileService wikiPageFileService;
|
||||||
private final WikiPageZanService wikiPageZanService;
|
private final WikiPageZanService wikiPageZanService;
|
||||||
private final WikiSpaceService wikiSpaceService;
|
private final WikiSpaceService wikiSpaceService;
|
||||||
private final WikiPageMapper wikiPageMapper;
|
|
||||||
private final WikiPageAuthService wikiPageAuthService;
|
private final WikiPageAuthService wikiPageAuthService;
|
||||||
|
private final WikiPageUploadService wikipageUploadService;
|
||||||
private final UserMessageService userMessageService;
|
private final UserMessageService userMessageService;
|
||||||
private final WikiPageHistoryService wikiPageHistoryService;
|
private final WikiPageHistoryService wikiPageHistoryService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public ResponseJson<List<WikiPageVo>> list(WikiPage wikiPage) {
|
public ResponseJson<List<WikiPageVo>> list(WikiPage wikiPage) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
@@ -87,7 +88,7 @@ public class WikiPageController {
|
|||||||
}
|
}
|
||||||
return DocResponseJson.ok(nodePageList);
|
return DocResponseJson.ok(nodePageList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/detail")
|
@PostMapping("/detail")
|
||||||
public ResponseJson<WikiPageContentVo> detail(WikiPage wikiPage) {
|
public ResponseJson<WikiPageContentVo> detail(WikiPage wikiPage) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
@@ -108,7 +109,7 @@ public class WikiPageController {
|
|||||||
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
|
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
|
||||||
wrapper.eq("page_id", wikiPage.getId());
|
wrapper.eq("page_id", wikiPage.getId());
|
||||||
WikiPageContent pageContent = wikiPageContentService.getOne(wrapper);
|
WikiPageContent pageContent = wikiPageContentService.getOne(wrapper);
|
||||||
|
|
||||||
UpdateWrapper<WikiPageFile> wrapperFile = new UpdateWrapper<>();
|
UpdateWrapper<WikiPageFile> wrapperFile = new UpdateWrapper<>();
|
||||||
wrapperFile.eq("page_id", wikiPage.getId());
|
wrapperFile.eq("page_id", wikiPage.getId());
|
||||||
wrapperFile.eq("del_flag", 0);
|
wrapperFile.eq("del_flag", 0);
|
||||||
@@ -148,7 +149,7 @@ public class WikiPageController {
|
|||||||
wikiPageSel.setViewNum(viewNum + 1);
|
wikiPageSel.setViewNum(viewNum + 1);
|
||||||
return DocResponseJson.ok(vo);
|
return DocResponseJson.ok(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/changeParent")
|
@PostMapping("/changeParent")
|
||||||
public ResponseJson<Object> changeParent(WikiPage wikiPage, Integer beforeSeq, Integer afterSeq) {
|
public ResponseJson<Object> changeParent(WikiPage wikiPage, Integer beforeSeq, Integer afterSeq) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
@@ -168,7 +169,7 @@ public class WikiPageController {
|
|||||||
wikiPageService.changeParent(wikiPageUp, beforeSeq, afterSeq);
|
wikiPageService.changeParent(wikiPageUp, beforeSeq, afterSeq);
|
||||||
return DocResponseJson.ok();
|
return DocResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public ResponseJson<Object> delete(Long pageId) {
|
public ResponseJson<Object> delete(Long pageId) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
@@ -193,94 +194,14 @@ public class WikiPageController {
|
|||||||
|
|
||||||
@PostMapping("/update")
|
@PostMapping("/update")
|
||||||
public ResponseJson<Object> update(WikiPage wikiPage, String content, String preview) {
|
public ResponseJson<Object> update(WikiPage wikiPage, String content, String preview) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
Object info = wikipageUploadService.update(wikiPage, content, preview);
|
||||||
WikiPageContent pageContent = new WikiPageContent();
|
if (null != info){
|
||||||
pageContent.setContent(content);
|
if (info instanceof WikiPage){
|
||||||
if (wikiPage.getEditorType() == 2) {
|
return DocResponseJson.ok(info);
|
||||||
preview = MDToText.mdToText(preview);
|
|
||||||
}
|
|
||||||
pageContent.setPreview(preview);
|
|
||||||
// 数据库是varchar(16000),所以如果不开启es的话搜索超过16000的文章就搜不到~,es存preview不截断
|
|
||||||
if (StringUtils.isNotBlank(preview) && preview.length() > 16000) {
|
|
||||||
pageContent.setPreview(preview.substring(0, 16000));
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(wikiPage.getName())) {
|
|
||||||
return DocResponseJson.warn("标题不能为空!");
|
|
||||||
}
|
|
||||||
Long pageId = wikiPage.getId();
|
|
||||||
Long spaceId = wikiPage.getSpaceId();
|
|
||||||
if (pageId != null && pageId > 0) {
|
|
||||||
WikiPage wikiPageSel = wikiPageService.getById(pageId);
|
|
||||||
// 编辑权限判断
|
|
||||||
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
|
||||||
String canEdit = wikiPageAuthService.canEdit(wikiSpaceSel, wikiPageSel.getEditType(), wikiPageSel.getId(), currentUser.getUserId());
|
|
||||||
if (canEdit != null) {
|
|
||||||
return DocResponseJson.warn(canEdit);
|
|
||||||
}
|
}
|
||||||
spaceId = wikiPageSel.getSpaceId();
|
return DocResponseJson.warn((String) info);
|
||||||
wikiPage.setSpaceId(null);
|
|
||||||
wikiPage.setEditType(null);
|
|
||||||
wikiPage.setUpdateTime(new Date());
|
|
||||||
wikiPage.setUpdateUserId(currentUser.getUserId());
|
|
||||||
wikiPage.setUpdateUserName(currentUser.getUsername());
|
|
||||||
wikiPageService.updateById(wikiPage);
|
|
||||||
// 详情
|
|
||||||
pageContent.setUpdateTime(new Date());
|
|
||||||
pageContent.setUpdateUserId(currentUser.getUserId());
|
|
||||||
pageContent.setUpdateUserName(currentUser.getUsername());
|
|
||||||
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
|
|
||||||
wrapper.eq("page_id", pageId);
|
|
||||||
wikiPageContentService.update(pageContent, wrapper);
|
|
||||||
// 给相关人发送消息
|
|
||||||
UserMessage userMessage = userMessageService.createUserMessage(currentUser, wikiPageSel.getId(), wikiPageSel.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_UPDATE);
|
|
||||||
userMessageService.addWikiMessage(userMessage);
|
|
||||||
} else {
|
|
||||||
Long parentId = Optional.ofNullable(wikiPage.getParentId()).orElse(0L);
|
|
||||||
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPage.getSpaceId());
|
|
||||||
if (wikiSpaceSel == null) {
|
|
||||||
return DocResponseJson.warn("未找到指定的空间!");
|
|
||||||
}
|
|
||||||
// 空间不是自己的
|
|
||||||
if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
|
|
||||||
return DocResponseJson.warn("您没有权限新增该空间的文章!");
|
|
||||||
}
|
|
||||||
// 空间不是自己的
|
|
||||||
if (SpaceType.isOthersPersonal(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
|
|
||||||
return DocResponseJson.warn("您没有权限新增该空间的文章!");
|
|
||||||
}
|
|
||||||
if (parentId > 0) {
|
|
||||||
WikiPage wikiPageParent = wikiPageService.getById(parentId);
|
|
||||||
if (!Objects.equals(wikiPage.getSpaceId(), wikiPageParent.getSpaceId())) {
|
|
||||||
return DocResponseJson.warn("当前空间和父页面的空间不一致,请重新选择父页面!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Integer lastSeq = wikiPageMapper.getLastSeq(wikiPage.getSpaceId(), parentId);
|
|
||||||
lastSeq = Optional.ofNullable(lastSeq).orElse(99999);
|
|
||||||
wikiPage.setSeqNo(lastSeq + 1);
|
|
||||||
wikiPage.setCreateTime(new Date());
|
|
||||||
wikiPage.setUpdateTime(new Date());
|
|
||||||
wikiPage.setCreateUserId(currentUser.getUserId());
|
|
||||||
wikiPage.setCreateUserName(currentUser.getUsername());
|
|
||||||
wikiPageService.save(wikiPage);
|
|
||||||
// 重置当前分支的所有节点seq值
|
|
||||||
wikiPageMapper.updateChildrenSeq(wikiPage.getSpaceId(), parentId);
|
|
||||||
// 详情
|
|
||||||
pageContent.setPageId(wikiPage.getId());
|
|
||||||
pageContent.setCreateTime(new Date());
|
|
||||||
pageContent.setCreateUserId(currentUser.getUserId());
|
|
||||||
pageContent.setCreateUserName(currentUser.getUsername());
|
|
||||||
wikiPageContentService.save(pageContent);
|
|
||||||
// 给相关人发送消息
|
|
||||||
UserMessage userMessage = userMessageService.createUserMessage(currentUser, wikiPage.getId(), wikiPage.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_CREATE);
|
|
||||||
userMessageService.addWikiMessage(userMessage);
|
|
||||||
}
|
}
|
||||||
try {
|
return DocResponseJson.warn("状态异常");
|
||||||
// 创建历史记录
|
|
||||||
wikiPageHistoryService.saveRecord(spaceId, wikiPage.getId(), content);
|
|
||||||
} catch (ConfirmException e) {
|
|
||||||
return DocResponseJson.warn(e.getMessage());
|
|
||||||
}
|
|
||||||
return DocResponseJson.ok(wikiPage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/rename")
|
@PostMapping("/rename")
|
||||||
@@ -322,7 +243,7 @@ public class WikiPageController {
|
|||||||
}
|
}
|
||||||
return DocResponseJson.ok(wikiPage);
|
return DocResponseJson.ok(wikiPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/unlock")
|
@PostMapping("/unlock")
|
||||||
public ResponseJson<Object> unlock(Long pageId) {
|
public ResponseJson<Object> unlock(Long pageId) {
|
||||||
String lockKey = CachePrefix.WIKI_LOCK_PAGE + pageId;
|
String lockKey = CachePrefix.WIKI_LOCK_PAGE + pageId;
|
||||||
@@ -335,7 +256,7 @@ public class WikiPageController {
|
|||||||
}
|
}
|
||||||
return DocResponseJson.ok();
|
return DocResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/lock")
|
@PostMapping("/lock")
|
||||||
public ResponseJson<Object> editLock(Long pageId) {
|
public ResponseJson<Object> editLock(Long pageId) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
@@ -349,13 +270,13 @@ public class WikiPageController {
|
|||||||
CacheUtil.put(lockKey, new DocUserDetails(currentUser.getUserId(), currentUser.getUsername()));
|
CacheUtil.put(lockKey, new DocUserDetails(currentUser.getUserId(), currentUser.getUsername()));
|
||||||
return DocResponseJson.ok();
|
return DocResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/searchByEs")
|
@PostMapping("/searchByEs")
|
||||||
public ResponseJson<Object> searchByEs(SearchByEsParam param) {
|
public ResponseJson<Object> searchByEs(SearchByEsParam param) {
|
||||||
param.setNewsType(1);
|
param.setNewsType(1);
|
||||||
return this.news(param);
|
return this.news(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/download")
|
@PostMapping("/download")
|
||||||
public ResponseJson<Object> download(Long pageId, HttpServletResponse response) {
|
public ResponseJson<Object> download(Long pageId, HttpServletResponse response) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
@@ -410,7 +331,7 @@ public class WikiPageController {
|
|||||||
}
|
}
|
||||||
return DocResponseJson.warn("导出失败");
|
return DocResponseJson.warn("导出失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/news")
|
@PostMapping("/news")
|
||||||
public ResponseJson<Object> news(SearchByEsParam param) {
|
public ResponseJson<Object> news(SearchByEsParam param) {
|
||||||
// 空间不是自己的
|
// 空间不是自己的
|
||||||
@@ -448,7 +369,7 @@ public class WikiPageController {
|
|||||||
});
|
});
|
||||||
return DocResponseJson.ok(spaceNewsVoList);
|
return DocResponseJson.ok(spaceNewsVoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Long, WikiSpace> getCanVisitWikiSpace(Long spaceId) {
|
private Map<Long, WikiSpace> getCanVisitWikiSpace(Long spaceId) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
List<WikiSpace> spaceList;
|
List<WikiSpace> spaceList;
|
||||||
@@ -467,7 +388,7 @@ public class WikiPageController {
|
|||||||
}
|
}
|
||||||
return spaceList.stream().collect(Collectors.toMap(WikiSpace::getId, val -> val));
|
return spaceList.stream().collect(Collectors.toMap(WikiSpace::getId, val -> val));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChildren(Map<Long, List<WikiPageVo>> listMap, List<WikiPageVo> nodePageList, String path) {
|
private void setChildren(Map<Long, List<WikiPageVo>> listMap, List<WikiPageVo> nodePageList, String path) {
|
||||||
if (nodePageList == null || listMap == null) {
|
if (nodePageList == null || listMap == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,35 +1,20 @@
|
|||||||
package com.zyplayer.doc.wiki.controller;
|
package com.zyplayer.doc.wiki.controller;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateTime;
|
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.zyplayer.doc.core.annotation.AuthMan;
|
import com.zyplayer.doc.core.annotation.AuthMan;
|
||||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||||
import com.zyplayer.doc.core.json.ResponseJson;
|
import com.zyplayer.doc.core.json.ResponseJson;
|
||||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
|
||||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
|
||||||
import com.zyplayer.doc.data.repository.manage.entity.UserMessage;
|
|
||||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
|
||||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||||
import com.zyplayer.doc.data.repository.manage.entity.WikiSpace;
|
import com.zyplayer.doc.wiki.batch.BatchDocImportManager;
|
||||||
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
import com.zyplayer.doc.wiki.service.WikiPageFileServiceEx;
|
||||||
import com.zyplayer.doc.data.repository.support.consts.UserMsgType;
|
|
||||||
import com.zyplayer.doc.data.service.manage.UserMessageService;
|
|
||||||
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
|
|
||||||
import com.zyplayer.doc.data.service.manage.WikiPageService;
|
|
||||||
import com.zyplayer.doc.data.service.manage.WikiSpaceService;
|
|
||||||
import com.zyplayer.doc.wiki.service.common.WikiPageAuthService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -37,6 +22,7 @@ import java.util.Map;
|
|||||||
* 文档控制器
|
* 文档控制器
|
||||||
*
|
*
|
||||||
* @author 暮光:城中城
|
* @author 暮光:城中城
|
||||||
|
* @author Sh1yu
|
||||||
* @since 2019年2月17日
|
* @since 2019年2月17日
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -46,60 +32,35 @@ import java.util.Map;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WikiPageFileController {
|
public class WikiPageFileController {
|
||||||
|
|
||||||
@Value("${zyplayer.doc.wiki.upload-path:}")
|
private final WikiPageFileServiceEx wikiPageFileServiceEx;
|
||||||
private String uploadPath;
|
private final BatchDocImportManager batchDocImportManger;
|
||||||
|
|
||||||
private final WikiPageFileService wikiPageFileService;
|
|
||||||
private final WikiSpaceService wikiSpaceService;
|
|
||||||
private final WikiPageService wikiPageService;
|
|
||||||
private final WikiPageAuthService wikiPageAuthService;
|
|
||||||
private final UserMessageService userMessageService;
|
|
||||||
|
|
||||||
// @PostMapping("/list")
|
/* @PostMapping("/list")
|
||||||
// public ResponseJson<List<WikiPageFile>> list(WikiPageFile wikiPageFile) {
|
public ResponseJson<List<WikiPageFile>> list(WikiPageFile wikiPageFile) {
|
||||||
// // TODO 检查space是否开放访问
|
// TODO 检查space是否开放访问
|
||||||
// UpdateWrapper<WikiPageFile> wrapper = new UpdateWrapper<>();
|
return DocResponseJson.ok(wikiPageFileServiceEx.list(wikiPageFile));
|
||||||
// wrapper.eq("del_flag", 0);
|
}*/
|
||||||
// wrapper.eq("page_id", wikiPageFile.getPageId());
|
|
||||||
// List<WikiPageFile> fileList = wikiPageFileService.list(wrapper);
|
|
||||||
// for (WikiPageFile pageFile : fileList) {
|
|
||||||
// pageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + pageFile.getUuid());
|
|
||||||
// }
|
|
||||||
// return DocResponseJson.ok(fileList);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public ResponseJson<Object> delete(WikiPageFile wikiPageFile) {
|
public ResponseJson<Object> delete(WikiPageFile wikiPageFile) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
String info = wikiPageFileServiceEx.delete(wikiPageFile);
|
||||||
Long id = wikiPageFile.getId();
|
if (null != info) {
|
||||||
if (id == null || id <= 0) {
|
return DocResponseJson.warn(info);
|
||||||
return DocResponseJson.warn("需指定删除的附件!");
|
|
||||||
}
|
}
|
||||||
WikiPageFile pageFileSel = wikiPageFileService.getById(wikiPageFile.getId());
|
|
||||||
WikiPage wikiPageSel = wikiPageService.getById(pageFileSel.getPageId());
|
|
||||||
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
|
||||||
// 权限判断
|
|
||||||
String canDeleteFile = wikiPageAuthService.canDeleteFile(wikiSpaceSel, pageFileSel.getPageId(), currentUser.getUserId());
|
|
||||||
if (canDeleteFile != null) {
|
|
||||||
return DocResponseJson.warn(canDeleteFile);
|
|
||||||
}
|
|
||||||
wikiPageFile.setDelFlag(1);
|
|
||||||
wikiPageFile.setUpdateUserId(currentUser.getUserId());
|
|
||||||
wikiPageFile.setUpdateUserName(currentUser.getUsername());
|
|
||||||
wikiPageFile.setUpdateTime(new Date());
|
|
||||||
wikiPageFileService.updateById(wikiPageFile);
|
|
||||||
// 给相关人发送消息
|
|
||||||
UserMessage userMessage = userMessageService.createUserMessage(currentUser, wikiPageSel.getId(), wikiPageSel.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_FILE_DEL);
|
|
||||||
userMessage.setAffectUserId(wikiPageSel.getCreateUserId());
|
|
||||||
userMessage.setAffectUserName(wikiPageSel.getCreateUserName());
|
|
||||||
userMessageService.addWikiMessage(userMessage);
|
|
||||||
return DocResponseJson.ok();
|
return DocResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/wangEditor/upload")
|
@PostMapping("/wangEditor/upload")
|
||||||
public Map<String, Object> wangEditorUpload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file) {
|
public Map<String, Object> wangEditorUpload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file) {
|
||||||
Map<String, Object> resultMap = new HashMap<>();
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
DocResponseJson docResponseJson = this.uploadFile(wikiPageFile, file);
|
Object result = wikiPageFileServiceEx.basicUpload(wikiPageFile, file);
|
||||||
|
DocResponseJson docResponseJson = DocResponseJson.warn("处理失败");
|
||||||
|
if (result instanceof WikiPageFile) {
|
||||||
|
docResponseJson = DocResponseJson.ok(result);
|
||||||
|
} else if (result != null) {
|
||||||
|
docResponseJson = DocResponseJson.error((String) result);
|
||||||
|
}
|
||||||
if (!docResponseJson.isOk()) {
|
if (!docResponseJson.isOk()) {
|
||||||
resultMap.put("errno", 1);
|
resultMap.put("errno", 1);
|
||||||
resultMap.put("message", docResponseJson.getErrMsg());
|
resultMap.put("message", docResponseJson.getErrMsg());
|
||||||
@@ -111,70 +72,23 @@ public class WikiPageFileController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public ResponseJson upload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file) {
|
public ResponseJson upload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file, boolean importFlag) {
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
if (importFlag) {
|
||||||
Long pageId = wikiPageFile.getPageId();
|
String info = batchDocImportManger.importBatchDoc(wikiPageFile, file);
|
||||||
if (pageId == null || pageId <= 0) {
|
if (null == info) {
|
||||||
return DocResponseJson.warn("未指定附件关联的文档");
|
return DocResponseJson.ok();
|
||||||
|
}
|
||||||
|
return DocResponseJson.warn(info);
|
||||||
}
|
}
|
||||||
WikiPage wikiPageSel = wikiPageService.getById(pageId);
|
Object result = wikiPageFileServiceEx.basicUpload(wikiPageFile, file);
|
||||||
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
if (result instanceof WikiPageFile) {
|
||||||
// 权限判断
|
return DocResponseJson.ok(result);
|
||||||
String canUploadFile = wikiPageAuthService.canUploadFile(wikiSpaceSel, wikiPageSel.getId(), currentUser.getUserId());
|
} else if (result != null) {
|
||||||
if (canUploadFile != null) {
|
return DocResponseJson.warn((String) result);
|
||||||
return DocResponseJson.warn(canUploadFile);
|
|
||||||
}
|
}
|
||||||
DocResponseJson docResponseJson = this.uploadFile(wikiPageFile, file);
|
return DocResponseJson.warn("未知异常");
|
||||||
if (!docResponseJson.isOk()) {
|
|
||||||
return docResponseJson;
|
|
||||||
}
|
|
||||||
// 给相关人发送消息
|
|
||||||
UserMessage userMessage = userMessageService.createUserMessage(currentUser, pageId, wikiPageSel.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_UPLOAD);
|
|
||||||
userMessage.setAffectUserId(wikiPageSel.getCreateUserId());
|
|
||||||
userMessage.setAffectUserName(wikiPageSel.getCreateUserName());
|
|
||||||
userMessageService.addWikiMessage(userMessage);
|
|
||||||
return DocResponseJson.ok(wikiPageFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 单纯的文件上传方法
|
|
||||||
*
|
|
||||||
* @param wikiPageFile
|
|
||||||
* @param file
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private DocResponseJson uploadFile(WikiPageFile wikiPageFile, MultipartFile file) {
|
|
||||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
|
||||||
String fileName = file.getOriginalFilename();
|
|
||||||
String fileSuffix = "";
|
|
||||||
if (fileName != null && fileName.lastIndexOf(".") >= 0) {
|
|
||||||
fileSuffix = fileName.substring(fileName.lastIndexOf("."));
|
|
||||||
}
|
|
||||||
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
|
|
||||||
File newFile = new File(path);
|
|
||||||
if (!newFile.exists() && !newFile.mkdirs()) {
|
|
||||||
return DocResponseJson.warn("创建文件夹失败");
|
|
||||||
}
|
|
||||||
String simpleUUID = IdUtil.simpleUUID();
|
|
||||||
path += simpleUUID + fileSuffix;
|
|
||||||
newFile = new File(path);
|
|
||||||
try {
|
|
||||||
file.transferTo(newFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return DocResponseJson.warn("保存文件失败");
|
|
||||||
}
|
|
||||||
wikiPageFile.setFileSize(file.getSize());
|
|
||||||
wikiPageFile.setUuid(simpleUUID);
|
|
||||||
wikiPageFile.setFileUrl(path);
|
|
||||||
wikiPageFile.setFileName(fileName);
|
|
||||||
wikiPageFile.setCreateTime(new Date());
|
|
||||||
wikiPageFile.setCreateUserId(currentUser.getUserId());
|
|
||||||
wikiPageFile.setCreateUserName(currentUser.getUsername());
|
|
||||||
wikiPageFile.setDelFlag(0);
|
|
||||||
wikiPageFileService.save(wikiPageFile);
|
|
||||||
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + wikiPageFile.getUuid());
|
|
||||||
return DocResponseJson.ok();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package com.zyplayer.doc.wiki.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateTime;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.UserMessage;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiSpace;
|
||||||
|
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
||||||
|
import com.zyplayer.doc.data.repository.support.consts.UserMsgType;
|
||||||
|
import com.zyplayer.doc.data.service.manage.UserMessageService;
|
||||||
|
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
|
||||||
|
import com.zyplayer.doc.data.service.manage.WikiPageService;
|
||||||
|
import com.zyplayer.doc.data.service.manage.WikiSpaceService;
|
||||||
|
import com.zyplayer.doc.wiki.service.common.WikiPageAuthService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档控制器
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @author sh1yu
|
||||||
|
* @since 2019年2月17日
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WikiPageFileServiceEx {
|
||||||
|
@Value("${zyplayer.doc.wiki.upload-path:}")
|
||||||
|
private String uploadPath;
|
||||||
|
|
||||||
|
private final WikiPageFileService wikiPageFileService;
|
||||||
|
private final WikiSpaceService wikiSpaceService;
|
||||||
|
private final WikiPageService wikiPageService;
|
||||||
|
private final WikiPageAuthService wikiPageAuthService;
|
||||||
|
private final UserMessageService userMessageService;
|
||||||
|
|
||||||
|
public List<WikiPageFile> list(WikiPageFile wikiPageFile) {
|
||||||
|
// TODO 检查space是否开放访问
|
||||||
|
UpdateWrapper<WikiPageFile> wrapper = new UpdateWrapper<>();
|
||||||
|
wrapper.eq("del_flag", 0);
|
||||||
|
wrapper.eq("page_id", wikiPageFile.getPageId());
|
||||||
|
List<WikiPageFile> fileList = wikiPageFileService.list(wrapper);
|
||||||
|
for (WikiPageFile pageFile : fileList) {
|
||||||
|
pageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + pageFile.getUuid());
|
||||||
|
}
|
||||||
|
return fileList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String delete(WikiPageFile wikiPageFile) {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
Long id = wikiPageFile.getId();
|
||||||
|
if (id == null || id <= 0) {
|
||||||
|
return "需指定删除的附件!";
|
||||||
|
}
|
||||||
|
WikiPageFile pageFileSel = wikiPageFileService.getById(wikiPageFile.getId());
|
||||||
|
WikiPage wikiPageSel = wikiPageService.getById(pageFileSel.getPageId());
|
||||||
|
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
||||||
|
// 权限判断
|
||||||
|
String canDeleteFile = wikiPageAuthService.canDeleteFile(wikiSpaceSel, pageFileSel.getPageId(), currentUser.getUserId());
|
||||||
|
if (canDeleteFile != null) {
|
||||||
|
return canDeleteFile;
|
||||||
|
}
|
||||||
|
wikiPageFile.setDelFlag(1);
|
||||||
|
wikiPageFile.setUpdateUserId(currentUser.getUserId());
|
||||||
|
wikiPageFile.setUpdateUserName(currentUser.getUsername());
|
||||||
|
wikiPageFile.setUpdateTime(new Date());
|
||||||
|
wikiPageFileService.updateById(wikiPageFile);
|
||||||
|
// 给相关人发送消息
|
||||||
|
UserMessage userMessage = userMessageService.createUserMessage(currentUser, wikiPageSel.getId(), wikiPageSel.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_FILE_DEL);
|
||||||
|
userMessage.setAffectUserId(wikiPageSel.getCreateUserId());
|
||||||
|
userMessage.setAffectUserName(wikiPageSel.getCreateUserName());
|
||||||
|
userMessageService.addWikiMessage(userMessage);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object basicUpload(WikiPageFile wikiPageFile, MultipartFile file) {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
Long pageId = wikiPageFile.getPageId();
|
||||||
|
if (pageId == null || pageId <= 0) {
|
||||||
|
return "未指定附件关联的文档";
|
||||||
|
}
|
||||||
|
WikiPage wikiPageSel = wikiPageService.getById(pageId);
|
||||||
|
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
||||||
|
// 权限判断
|
||||||
|
String canUploadFile = wikiPageAuthService.canUploadFile(wikiSpaceSel, wikiPageSel.getId(), currentUser.getUserId());
|
||||||
|
if (canUploadFile != null) {
|
||||||
|
return canUploadFile;
|
||||||
|
}
|
||||||
|
String info = this.uploadFile(wikiPageFile, file,0);
|
||||||
|
if (null != info) {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
// 给相关人发送消息
|
||||||
|
UserMessage userMessage = userMessageService.createUserMessage(currentUser, pageId, wikiPageSel.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_UPLOAD);
|
||||||
|
userMessage.setAffectUserId(wikiPageSel.getCreateUserId());
|
||||||
|
userMessage.setAffectUserName(wikiPageSel.getCreateUserName());
|
||||||
|
userMessageService.addWikiMessage(userMessage);
|
||||||
|
return wikiPageFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单纯的文件上传方法
|
||||||
|
*
|
||||||
|
* @param wikiPageFile
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String uploadFile(WikiPageFile wikiPageFile, MultipartFile file, Integer flag) {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
String fileSuffix = "";
|
||||||
|
if (fileName != null && fileName.lastIndexOf(".") >= 0) {
|
||||||
|
fileSuffix = fileName.substring(fileName.lastIndexOf("."));
|
||||||
|
}
|
||||||
|
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
|
||||||
|
File newFile = new File(path);
|
||||||
|
if (!newFile.exists() && !newFile.mkdirs()) {
|
||||||
|
return "创建文件夹失败";
|
||||||
|
}
|
||||||
|
String simpleUUID = IdUtil.simpleUUID();
|
||||||
|
path += simpleUUID + fileSuffix;
|
||||||
|
newFile = new File(path);
|
||||||
|
try {
|
||||||
|
file.transferTo(newFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return "保存文件失败";
|
||||||
|
}
|
||||||
|
wikiPageFile.setFileSize(file.getSize());
|
||||||
|
wikiPageFile.setUuid(simpleUUID);
|
||||||
|
wikiPageFile.setFileUrl(path);
|
||||||
|
wikiPageFile.setFileName(fileName);
|
||||||
|
wikiPageFile.setCreateTime(new Date());
|
||||||
|
wikiPageFile.setCreateUserId(currentUser.getUserId());
|
||||||
|
wikiPageFile.setCreateUserName(currentUser.getUsername());
|
||||||
|
wikiPageFile.setDelFlag(flag);
|
||||||
|
wikiPageFileService.save(wikiPageFile);
|
||||||
|
wikiPageFile.setFileUrl("zyplayer-doc-wiki/common/file?uuid=" + wikiPageFile.getUuid());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package com.zyplayer.doc.wiki.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.zyplayer.doc.core.exception.ConfirmException;
|
||||||
|
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||||
|
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.UserMessage;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiPageContent;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.entity.WikiSpace;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageContentMapper;
|
||||||
|
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageMapper;
|
||||||
|
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
|
||||||
|
import com.zyplayer.doc.data.repository.support.consts.UserMsgType;
|
||||||
|
import com.zyplayer.doc.data.service.manage.*;
|
||||||
|
import com.zyplayer.doc.wiki.framework.common.MDToText;
|
||||||
|
import com.zyplayer.doc.wiki.framework.consts.SpaceType;
|
||||||
|
import com.zyplayer.doc.wiki.service.common.WikiPageAuthService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档控制器
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @author sh1yu
|
||||||
|
* @since 2019年2月17日
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class WikiPageUploadService {
|
||||||
|
private final WikiPageService wikiPageService;
|
||||||
|
private final WikiPageContentService wikiPageContentService;
|
||||||
|
private final WikiSpaceService wikiSpaceService;
|
||||||
|
private final WikiPageMapper wikiPageMapper;
|
||||||
|
private final WikiPageAuthService wikiPageAuthService;
|
||||||
|
private final UserMessageService userMessageService;
|
||||||
|
private final WikiPageHistoryService wikiPageHistoryService;
|
||||||
|
|
||||||
|
|
||||||
|
public Object update(WikiPage wikiPage, String content, String preview) {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
WikiPageContent pageContent = new WikiPageContent();
|
||||||
|
pageContent.setContent(content);
|
||||||
|
if (wikiPage.getEditorType() == 2) {
|
||||||
|
preview = MDToText.mdToText(preview);
|
||||||
|
}
|
||||||
|
pageContent.setPreview(preview);
|
||||||
|
// 数据库是varchar(16000),所以如果不开启es的话搜索超过16000的文章就搜不到~,es存preview不截断
|
||||||
|
if (StringUtils.isNotBlank(preview) && preview.length() > 16000) {
|
||||||
|
pageContent.setPreview(preview.substring(0, 16000));
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(wikiPage.getName())) {
|
||||||
|
return "标题不能为空!";
|
||||||
|
}
|
||||||
|
Long pageId = wikiPage.getId();
|
||||||
|
Long spaceId = wikiPage.getSpaceId();
|
||||||
|
if (pageId != null && pageId > 0) {
|
||||||
|
WikiPage wikiPageSel = wikiPageService.getById(pageId);
|
||||||
|
// 编辑权限判断
|
||||||
|
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPageSel.getSpaceId());
|
||||||
|
String canEdit = wikiPageAuthService.canEdit(wikiSpaceSel, wikiPageSel.getEditType(), wikiPageSel.getId(), currentUser.getUserId());
|
||||||
|
if (canEdit != null) {
|
||||||
|
return canEdit;
|
||||||
|
}
|
||||||
|
spaceId = wikiPageSel.getSpaceId();
|
||||||
|
wikiPage.setSpaceId(null);
|
||||||
|
wikiPage.setEditType(null);
|
||||||
|
wikiPage.setUpdateTime(new Date());
|
||||||
|
wikiPage.setUpdateUserId(currentUser.getUserId());
|
||||||
|
wikiPage.setUpdateUserName(currentUser.getUsername());
|
||||||
|
wikiPageService.updateById(wikiPage);
|
||||||
|
// 详情
|
||||||
|
pageContent.setUpdateTime(new Date());
|
||||||
|
pageContent.setUpdateUserId(currentUser.getUserId());
|
||||||
|
pageContent.setUpdateUserName(currentUser.getUsername());
|
||||||
|
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
|
||||||
|
wrapper.eq("page_id", pageId);
|
||||||
|
wikiPageContentService.update(pageContent, wrapper);
|
||||||
|
// 给相关人发送消息
|
||||||
|
UserMessage userMessage = userMessageService.createUserMessage(currentUser, wikiPageSel.getId(), wikiPageSel.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_UPDATE);
|
||||||
|
userMessageService.addWikiMessage(userMessage);
|
||||||
|
} else {
|
||||||
|
Long parentId = Optional.ofNullable(wikiPage.getParentId()).orElse(0L);
|
||||||
|
WikiSpace wikiSpaceSel = wikiSpaceService.getById(wikiPage.getSpaceId());
|
||||||
|
if (wikiSpaceSel == null) {
|
||||||
|
return "未找到指定的空间!";
|
||||||
|
}
|
||||||
|
// 空间不是自己的
|
||||||
|
if (SpaceType.isOthersPrivate(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
|
||||||
|
return "您没有权限新增该空间的文章!";
|
||||||
|
}
|
||||||
|
// 空间不是自己的
|
||||||
|
if (SpaceType.isOthersPersonal(wikiSpaceSel.getType(), currentUser.getUserId(), wikiSpaceSel.getCreateUserId())) {
|
||||||
|
return "您没有权限新增该空间的文章!";
|
||||||
|
}
|
||||||
|
if (parentId > 0) {
|
||||||
|
WikiPage wikiPageParent = wikiPageService.getById(parentId);
|
||||||
|
if (!Objects.equals(wikiPage.getSpaceId(), wikiPageParent.getSpaceId())) {
|
||||||
|
return "当前空间和父页面的空间不一致,请重新选择父页面!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Integer lastSeq = wikiPageMapper.getLastSeq(wikiPage.getSpaceId(), parentId);
|
||||||
|
lastSeq = Optional.ofNullable(lastSeq).orElse(99999);
|
||||||
|
wikiPage.setSeqNo(lastSeq + 1);
|
||||||
|
wikiPage.setCreateTime(new Date());
|
||||||
|
wikiPage.setUpdateTime(new Date());
|
||||||
|
wikiPage.setCreateUserId(currentUser.getUserId());
|
||||||
|
wikiPage.setCreateUserName(currentUser.getUsername());
|
||||||
|
wikiPageService.save(wikiPage);
|
||||||
|
// 重置当前分支的所有节点seq值
|
||||||
|
wikiPageMapper.updateChildrenSeq(wikiPage.getSpaceId(), parentId);
|
||||||
|
// 详情
|
||||||
|
pageContent.setPageId(wikiPage.getId());
|
||||||
|
pageContent.setCreateTime(new Date());
|
||||||
|
pageContent.setCreateUserId(currentUser.getUserId());
|
||||||
|
pageContent.setCreateUserName(currentUser.getUsername());
|
||||||
|
wikiPageContentService.save(pageContent);
|
||||||
|
// 给相关人发送消息
|
||||||
|
UserMessage userMessage = userMessageService.createUserMessage(currentUser, wikiPage.getId(), wikiPage.getName(), DocSysType.WIKI, UserMsgType.WIKI_PAGE_CREATE);
|
||||||
|
userMessageService.addWikiMessage(userMessage);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 创建历史记录
|
||||||
|
wikiPageHistoryService.saveRecord(spaceId, wikiPage.getId(), content);
|
||||||
|
} catch (ConfirmException e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
return wikiPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
zyplayer-doc-wiki/src/main/resources/dist/assets/main-ed1a906d.js
vendored
Normal file
25
zyplayer-doc-wiki/src/main/resources/dist/assets/main-ed1a906d.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -5,11 +5,11 @@
|
|||||||
<link rel="icon" href="./wiki-logo.png" />
|
<link rel="icon" href="./wiki-logo.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>WIKI文档管理系统</title>
|
<title>WIKI文档管理系统</title>
|
||||||
<script type="module" crossorigin src="./assets/main-f7ee3e81.js"></script>
|
<script type="module" crossorigin src="./assets/main-ed1a906d.js"></script>
|
||||||
<link rel="modulepreload" crossorigin href="./assets/highlight.js-1b0b64aa.js">
|
<link rel="modulepreload" crossorigin href="./assets/highlight.js-1b0b64aa.js">
|
||||||
<link rel="modulepreload" crossorigin href="./assets/vue-650a4d10.js">
|
<link rel="modulepreload" crossorigin href="./assets/vue-650a4d10.js">
|
||||||
<link rel="modulepreload" crossorigin href="./assets/vendor-bc891dd6.js">
|
<link rel="modulepreload" crossorigin href="./assets/vendor-f8f18bc4.js">
|
||||||
<link rel="modulepreload" crossorigin href="./assets/vant-340d11c1.js">
|
<link rel="modulepreload" crossorigin href="./assets/vant-cc619247.js">
|
||||||
<link rel="modulepreload" crossorigin href="./assets/wangeditor-564d5916.js">
|
<link rel="modulepreload" crossorigin href="./assets/wangeditor-564d5916.js">
|
||||||
<link rel="stylesheet" href="./assets/style.bef1b736.css">
|
<link rel="stylesheet" href="./assets/style.bef1b736.css">
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user