wiki优化
This commit is contained in:
@@ -12,7 +12,7 @@ import java.util.Date;
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public class WikiPage implements Serializable {
|
||||
|
||||
@@ -44,6 +44,11 @@ public class WikiPage implements Serializable {
|
||||
*/
|
||||
private Integer nodeType;
|
||||
|
||||
/**
|
||||
* 赞的数量
|
||||
*/
|
||||
private Integer zanNum;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@@ -114,6 +119,13 @@ public class WikiPage implements Serializable {
|
||||
public void setNodeType(Integer nodeType) {
|
||||
this.nodeType = nodeType;
|
||||
}
|
||||
public Integer getZanNum() {
|
||||
return zanNum;
|
||||
}
|
||||
|
||||
public void setZanNum(Integer zanNum) {
|
||||
this.zanNum = zanNum;
|
||||
}
|
||||
public Long getCreateUserId() {
|
||||
return createUserId;
|
||||
}
|
||||
@@ -172,6 +184,7 @@ public class WikiPage implements Serializable {
|
||||
", name=" + name +
|
||||
", parentId=" + parentId +
|
||||
", nodeType=" + nodeType +
|
||||
", zanNum=" + zanNum +
|
||||
", createUserId=" + createUserId +
|
||||
", createUserName=" + createUserName +
|
||||
", createTime=" + createTime +
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.zyplayer.doc.data.repository.manage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -11,7 +12,7 @@ import java.io.Serializable;
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public class WikiPageZan implements Serializable {
|
||||
|
||||
@@ -48,6 +49,11 @@ public class WikiPageZan implements Serializable {
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 是否有效 0=无效 1=有效
|
||||
*/
|
||||
private Integer yn;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -90,6 +96,13 @@ public class WikiPageZan implements Serializable {
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
public Integer getYn() {
|
||||
return yn;
|
||||
}
|
||||
|
||||
public void setYn(Integer yn) {
|
||||
this.yn = yn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -100,6 +113,7 @@ public class WikiPageZan implements Serializable {
|
||||
", createUserId=" + createUserId +
|
||||
", createUserName=" + createUserName +
|
||||
", createTime=" + createTime +
|
||||
", yn=" + yn +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.zyplayer.doc.data.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -9,8 +11,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public interface WikiPageMapper extends BaseMapper<WikiPage> {
|
||||
|
||||
|
||||
@Update("update wiki_page set zan_num=zan_num + #{numAdd} where id=#{id}")
|
||||
void updateZanNum(@Param("id") Long id, @Param("numAdd") Integer numAdd);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@ package com.zyplayer.doc.data.repository.manage.mapper;
|
||||
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public interface WikiPageZanMapper extends BaseMapper<WikiPageZan> {
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ public class CodeGenerator {
|
||||
|
||||
final String moduleName = "manage";
|
||||
// final String[] tableName = { "zyplayer_storage", "auth_info", "user_auth", "user_info" };
|
||||
final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
|
||||
// final String[] tableName = { "wiki_page" };
|
||||
// final String[] tableName = { "wiki_space", "wiki_page", "wiki_page_content", "wiki_page_file", "wiki_page_comment", "wiki_page_zan" };
|
||||
final String[] tableName = { "wiki_page" };
|
||||
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public interface WikiPageService extends IService<WikiPage> {
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
public interface WikiPageZanService extends IService<WikiPageZan> {
|
||||
|
||||
void zanPage(WikiPageZan wikiPageZan);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
@Service
|
||||
public class WikiPageServiceImpl extends ServiceImpl<WikiPageMapper, WikiPage> implements WikiPageService {
|
||||
|
||||
@@ -1,20 +1,55 @@
|
||||
package com.zyplayer.doc.data.service.manage.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
|
||||
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageMapper;
|
||||
import com.zyplayer.doc.data.repository.manage.mapper.WikiPageZanMapper;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageZanService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019-02-24
|
||||
* @since 2019-03-05
|
||||
*/
|
||||
@Service
|
||||
public class WikiPageZanServiceImpl extends ServiceImpl<WikiPageZanMapper, WikiPageZan> implements WikiPageZanService {
|
||||
|
||||
|
||||
@Resource
|
||||
WikiPageMapper wikiPageMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void zanPage(WikiPageZan wikiPageZan) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("create_user_id", currentUser.getUserId());
|
||||
wrapper.eq("page_id", wikiPageZan.getPageId());
|
||||
wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
|
||||
WikiPageZan pageZan = this.getOne(wrapper);
|
||||
if (pageZan != null) {
|
||||
if (Objects.equals(wikiPageZan.getYn(), pageZan.getYn())) {
|
||||
return;
|
||||
}
|
||||
wikiPageZan.setId(pageZan.getId());
|
||||
this.updateById(wikiPageZan);
|
||||
} else {
|
||||
wikiPageZan.setCreateTime(new Date());
|
||||
wikiPageZan.setCreateUserId(currentUser.getUserId());
|
||||
this.save(wikiPageZan);
|
||||
}
|
||||
int numAdd = wikiPageZan.getYn() == 1 ? 1 : -1;
|
||||
wikiPageMapper.updateZanNum(wikiPageZan.getPageId(), numAdd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,10 @@ import org.apache.dubbo.rpc.service.GenericService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
@@ -73,29 +70,34 @@ public class DubboController {
|
||||
private CuratorFramework serverClient;
|
||||
private CuratorFramework metadataClient;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
if (StringUtils.isNotBlank(serviceZookeeperUrl)) {
|
||||
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
|
||||
serverClient = CuratorFrameworkFactory.newClient(serviceZookeeperUrl, retryPolicy);
|
||||
serverClient.start();
|
||||
}
|
||||
if (StringUtils.isNotBlank(metadataZookeeperUrl)) {
|
||||
URL url = UrlUtils.parseURL(metadataZookeeperUrl, Collections.emptyMap());
|
||||
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
|
||||
if (!group.startsWith(Constants.PATH_SEPARATOR)) {
|
||||
group = Constants.PATH_SEPARATOR + group;
|
||||
private void initServerClient() {
|
||||
if (serverClient == null && StringUtils.isNotBlank(serviceZookeeperUrl)) {
|
||||
synchronized (DEFAULT_ROOT) {
|
||||
if (serverClient == null) {
|
||||
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
|
||||
serverClient = CuratorFrameworkFactory.newClient(serviceZookeeperUrl, retryPolicy);
|
||||
serverClient.start();
|
||||
}
|
||||
}
|
||||
this.root = group;
|
||||
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
|
||||
metadataClient = CuratorFrameworkFactory.newClient(metadataZookeeperUrl, retryPolicy);
|
||||
metadataClient.start();
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
private void preDestroy() {
|
||||
serverClient.close();
|
||||
private void initMetadataClient() {
|
||||
if (metadataClient == null && StringUtils.isNotBlank(metadataZookeeperUrl)) {
|
||||
synchronized (DEFAULT_ROOT) {
|
||||
if (metadataClient == null) {
|
||||
URL url = UrlUtils.parseURL(metadataZookeeperUrl, Collections.emptyMap());
|
||||
String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
|
||||
if (!group.startsWith(Constants.PATH_SEPARATOR)) {
|
||||
group = Constants.PATH_SEPARATOR + group;
|
||||
}
|
||||
this.root = group;
|
||||
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
|
||||
metadataClient = CuratorFrameworkFactory.newClient(metadataZookeeperUrl, retryPolicy);
|
||||
metadataClient.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,23 +207,6 @@ public class DubboController {
|
||||
return DocResponseJson.ok(dubboInfoVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文档详情,依据类名生成
|
||||
*
|
||||
* @author 暮光:城中城
|
||||
* @since 2019年2月10日
|
||||
**/
|
||||
@GetMapping(value = "/test")
|
||||
public DocResponseJson test() throws Exception {
|
||||
String path = getNodePath("com.zyplayer.dubbo.service.UserService", null, null, "dubbo-provider");
|
||||
if (metadataClient.checkExists().forPath(path) == null) {
|
||||
return DocResponseJson.ok(path);
|
||||
}
|
||||
String metadata = new String(metadataClient.getData().forPath(path));
|
||||
FullServiceDefinition fullServiceDefinition = JSON.parseObject(metadata, FullServiceDefinition.class);
|
||||
return DocResponseJson.ok(fullServiceDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文档详情,依据类名生成
|
||||
*
|
||||
@@ -341,6 +326,7 @@ public class DubboController {
|
||||
* @since 2019年2月10日
|
||||
**/
|
||||
private List<DubboInfo> getDubboInfoByZookeeper() throws Exception {
|
||||
this.initServerClient();
|
||||
List<String> dubboList = serverClient.getChildren().forPath("/dubbo");
|
||||
if (dubboList == null || dubboList.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
@@ -348,7 +334,7 @@ public class DubboController {
|
||||
List<DubboInfo> providerList = new LinkedList<>();
|
||||
for (String dubboStr : dubboList) {
|
||||
String path = "/dubbo/" + dubboStr + "/providers";
|
||||
if (metadataClient.checkExists().forPath(path) == null) {
|
||||
if (serverClient.checkExists().forPath(path) == null) {
|
||||
continue;
|
||||
}
|
||||
List<String> providers = serverClient.getChildren().forPath(path);
|
||||
@@ -389,6 +375,7 @@ public class DubboController {
|
||||
|
||||
private DubboDocInfo getDefinitionByMetadata(DubboRequestParam param) {
|
||||
try {
|
||||
this.initMetadataClient();
|
||||
String path = getNodePath(param.getService(), null, null, param.getApplication());
|
||||
if (metadataClient.checkExists().forPath(path) == null) {
|
||||
return null;
|
||||
|
||||
@@ -3,17 +3,16 @@ spring:
|
||||
name: zyplayer-doc-manage
|
||||
# mvc:
|
||||
# static-path-pattern: /**
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
server:
|
||||
port: 8082
|
||||
servlet:
|
||||
context-path: /zyplayer-doc-manage
|
||||
|
||||
multipart:
|
||||
enabled: true
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
zyplayer:
|
||||
doc:
|
||||
# dubbo相关配置
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.zyplayer.doc.test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class MediaTypeTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// MediaType xx = MediaType.parseMediaType("png");
|
||||
// System.out.println(xx.getSubtype());
|
||||
File file = new File("e:/tmp/wikiFiles/2019/03/04/dcf4b4357d5a454180cf54a5d8a2f868.jpg");
|
||||
// String path = file.get
|
||||
|
||||
String contentType = Files.probeContentType(file.toPath());
|
||||
System.out.println(contentType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,14 +11,17 @@ import com.zyplayer.doc.data.service.manage.WikiPageFileService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -41,30 +44,67 @@ public class WikiCommonController {
|
||||
@PostMapping("/upload")
|
||||
public ResponseJson<Object> upload(WikiPageFile wikiPageFile, @RequestParam("files") MultipartFile file) {
|
||||
//通过CommonsMultipartFile的方法直接写文件(注意这个时候)
|
||||
String fileName = file.getOriginalFilename();
|
||||
String fileSuffix = "";
|
||||
if (fileName != null && fileName.lastIndexOf(".") >= 0) {
|
||||
fileSuffix = fileName.substring(fileName.lastIndexOf("."));
|
||||
}
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
|
||||
File newFile = new File(path);
|
||||
if (!newFile.exists() && !newFile.mkdir()) {
|
||||
return DocResponseJson.warn("创建文件夹失败");
|
||||
}
|
||||
path += RandomUtil.simpleUUID() + fileSuffix;
|
||||
newFile = new File(path);
|
||||
try {
|
||||
String fileName = file.getOriginalFilename();
|
||||
String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
String path = uploadPath + "/" + DateTime.now().toString("yyyy/MM/dd") + "/";
|
||||
File newFile = new File(path);
|
||||
if (!newFile.exists()) {
|
||||
newFile.mkdir();
|
||||
}
|
||||
path += RandomUtil.simpleUUID() + fileSuffix;
|
||||
newFile = new File(path);
|
||||
file.transferTo(newFile);
|
||||
wikiPageFile.setFileUrl(path);
|
||||
wikiPageFile.setFileName(fileName);
|
||||
wikiPageFile.setCreateTime(new Date());
|
||||
wikiPageFile.setCreateUserId(currentUser.getUserId());
|
||||
wikiPageFile.setCreateUserName(currentUser.getUsername());
|
||||
wikiPageFile.setDelFlag(0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return DocResponseJson.warn("失败");
|
||||
return DocResponseJson.warn("保存文件失败");
|
||||
}
|
||||
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?fileId=" + wikiPageFile.getId());
|
||||
return DocResponseJson.ok(wikiPageFile);
|
||||
}
|
||||
|
||||
@GetMapping("/file")
|
||||
public ResponseJson<Object> file(Long fileId, HttpServletResponse response) {
|
||||
if (fileId == null || fileId <= 0) {
|
||||
return DocResponseJson.warn("请指定文件ID");
|
||||
}
|
||||
WikiPageFile pageFile = wikiPageFileService.getById(fileId);
|
||||
if (pageFile == null) {
|
||||
return DocResponseJson.warn("未找到指定文件");
|
||||
}
|
||||
try {
|
||||
String fileName = pageFile.getFileName();
|
||||
File file = new File(pageFile.getFileUrl());
|
||||
String contentType = Files.probeContentType(file.toPath());
|
||||
response.setContentType(contentType);
|
||||
response.setHeader("Content-disposition", "inline;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
// response.setHeader("Content-disposition", "inline;filename=" + fileName);
|
||||
// response.setHeader("Content-Disposition", "inline; fileName=" + fileName + ";filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
OutputStream os = response.getOutputStream();
|
||||
byte[] b = new byte[2048];
|
||||
int length;
|
||||
while ((length = inputStream.read(b)) > 0) {
|
||||
os.write(b, 0, length);
|
||||
}
|
||||
os.close();
|
||||
inputStream.close();
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
logger.info("失败:{}", e.getMessage());
|
||||
}
|
||||
return DocResponseJson.warn("获取文件失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ 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.WikiPageContent;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPageFile;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.WikiPageZan;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageContentService;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageService;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageZanService;
|
||||
import com.zyplayer.doc.wiki.controller.vo.WikiPageContentVo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -39,6 +41,8 @@ public class WikiPageController {
|
||||
WikiPageContentService wikiPageContentService;
|
||||
@Resource
|
||||
WikiPageFileService wikiPageFileService;
|
||||
@Resource
|
||||
WikiPageZanService wikiPageZanService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<List<WikiPage>> list(WikiPage wikiPage) {
|
||||
@@ -54,21 +58,31 @@ public class WikiPageController {
|
||||
|
||||
@PostMapping("/detail")
|
||||
public ResponseJson<WikiPageContentVo> detail(WikiPage wikiPage) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
WikiPage wikiPageSel = wikiPageService.getById(wikiPage.getId());
|
||||
|
||||
UpdateWrapper<WikiPageContent> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("page_id", wikiPage.getId());
|
||||
WikiPageContent pageContent = wikiPageContentService.getOne(wrapper);
|
||||
|
||||
// TODO 检查space是否开放访问
|
||||
UpdateWrapper<WikiPageFile> wrapperFile = new UpdateWrapper<>();
|
||||
wrapperFile.eq("page_id", wikiPage.getId());
|
||||
wrapper.eq("del_flag", 0);
|
||||
wrapperFile.eq("del_flag", 0);
|
||||
List<WikiPageFile> pageFiles = wikiPageFileService.list(wrapperFile);
|
||||
|
||||
for (WikiPageFile pageFile : pageFiles) {
|
||||
pageFile.setFileUrl("zyplayer-doc-wiki/common/file?fileId=" + pageFile.getId());
|
||||
}
|
||||
UpdateWrapper<WikiPageZan> wrapperZan = new UpdateWrapper<>();
|
||||
wrapperZan.eq("page_id", wikiPage.getId());
|
||||
wrapperZan.eq("create_user_id", currentUser.getUserId());
|
||||
wrapperZan.eq("yn", 1);
|
||||
WikiPageZan pageZan = wikiPageZanService.getOne(wrapperZan);
|
||||
WikiPageContentVo vo = new WikiPageContentVo();
|
||||
vo.setWikiPage(wikiPageSel);
|
||||
vo.setPageContent(pageContent);
|
||||
vo.setFileList(pageFiles);
|
||||
vo.setSelfZan((pageZan != null) ? 1 : 0);
|
||||
return DocResponseJson.ok(vo);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
package com.zyplayer.doc.wiki.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
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.WikiPageFile;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageFileService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文档控制器
|
||||
@@ -31,28 +22,31 @@ public class WikiPageFileController {
|
||||
@Resource
|
||||
WikiPageFileService wikiPageFileService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<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);
|
||||
return DocResponseJson.ok(fileList);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(WikiPageFile wikiPageFile) {
|
||||
Long id = wikiPageFile.getId();
|
||||
if (id != null && id > 0) {
|
||||
wikiPageFileService.updateById(wikiPageFile);
|
||||
} else {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
wikiPageFile.setCreateTime(new Date());
|
||||
wikiPageFile.setCreateUserId(currentUser.getUserId());
|
||||
wikiPageFileService.save(wikiPageFile);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
// @PostMapping("/list")
|
||||
// public ResponseJson<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?fileId=" + pageFile.getId());
|
||||
// }
|
||||
// return DocResponseJson.ok(fileList);
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/update")
|
||||
// public ResponseJson<Object> update(WikiPageFile wikiPageFile) {
|
||||
// Long id = wikiPageFile.getId();
|
||||
// if (id != null && id > 0) {
|
||||
// wikiPageFileService.updateById(wikiPageFile);
|
||||
// } else {
|
||||
// DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
// wikiPageFile.setCreateTime(new Date());
|
||||
// wikiPageFile.setCreateUserId(currentUser.getUserId());
|
||||
// wikiPageFileService.save(wikiPageFile);
|
||||
// }
|
||||
// return DocResponseJson.ok();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.zyplayer.doc.wiki.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
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.WikiPageZan;
|
||||
import com.zyplayer.doc.data.service.manage.WikiPageZanService;
|
||||
import org.slf4j.Logger;
|
||||
@@ -14,8 +11,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文档控制器
|
||||
@@ -31,29 +26,18 @@ public class WikiPageZanController {
|
||||
@Resource
|
||||
WikiPageZanService wikiPageZanService;
|
||||
|
||||
@PostMapping("/list")
|
||||
public ResponseJson<List<WikiPageZan>> list(WikiPageZan wikiPageZan) {
|
||||
UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("page_id", wikiPageZan.getPageId());
|
||||
wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
|
||||
List<WikiPageZan> zanList = wikiPageZanService.list(wrapper);
|
||||
return DocResponseJson.ok(zanList);
|
||||
}
|
||||
// @PostMapping("/list")
|
||||
// public ResponseJson<List<WikiPageZan>> list(WikiPageZan wikiPageZan) {
|
||||
// UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
|
||||
// wrapper.eq("page_id", wikiPageZan.getPageId());
|
||||
// wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
|
||||
// List<WikiPageZan> zanList = wikiPageZanService.list(wrapper);
|
||||
// return DocResponseJson.ok(zanList);
|
||||
// }
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseJson<Object> update(WikiPageZan wikiPageZan) {
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
UpdateWrapper<WikiPageZan> wrapper = new UpdateWrapper<>();
|
||||
wrapper.eq("create_uid", currentUser.getUserId());
|
||||
wrapper.eq("page_id", wikiPageZan.getPageId());
|
||||
wrapper.eq(wikiPageZan.getCommentId() != null, "comment_id", wikiPageZan.getCommentId());
|
||||
WikiPageZan pageZan = wikiPageZanService.getOne(wrapper);
|
||||
if (pageZan != null) {
|
||||
return DocResponseJson.warn("您已经赞过了哦~");
|
||||
}
|
||||
wikiPageZan.setCreateTime(new Date());
|
||||
wikiPageZan.setCreateUserId(currentUser.getUserId());
|
||||
wikiPageZanService.save(wikiPageZan);
|
||||
wikiPageZanService.zanPage(wikiPageZan);
|
||||
return DocResponseJson.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ public class WikiSpaceController {
|
||||
wrapper.in("type", 1, 2);
|
||||
} else if(wikiSpace.getType() == 1 || wikiSpace.getType() == 2) {
|
||||
wrapper.eq(wikiSpace.getType() != null, "type", wikiSpace.getType());
|
||||
wrapper.eq(Objects.equals(wikiSpace.getType(), 2), "create_uid", wikiSpace.getCreateUserId());
|
||||
wrapper.eq(Objects.equals(wikiSpace.getType(), 2), "create_user_id", wikiSpace.getCreateUserId());
|
||||
} else if(wikiSpace.getType() == 3) {
|
||||
wrapper.eq("create_uid", currentUser.getUserId());
|
||||
wrapper.eq("create_user_id", currentUser.getUserId());
|
||||
}
|
||||
List<WikiSpace> authList = wikiSpaceService.list(wrapper);
|
||||
return DocResponseJson.ok(authList);
|
||||
|
||||
@@ -10,6 +10,7 @@ public class WikiPageContentVo {
|
||||
private WikiPage wikiPage;
|
||||
private WikiPageContent pageContent;
|
||||
private List<WikiPageFile> fileList;
|
||||
private Integer selfZan;
|
||||
|
||||
public WikiPage getWikiPage() {
|
||||
return wikiPage;
|
||||
@@ -34,4 +35,12 @@ public class WikiPageContentVo {
|
||||
public void setFileList(List<WikiPageFile> fileList) {
|
||||
this.fileList = fileList;
|
||||
}
|
||||
|
||||
public Integer getSelfZan() {
|
||||
return selfZan;
|
||||
}
|
||||
|
||||
public void setSelfZan(Integer selfZan) {
|
||||
this.selfZan = selfZan;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,12 +46,14 @@
|
||||
<!--:before-remove="beforeRemove"-->
|
||||
<!--:on-exceed="handleExceed"-->
|
||||
<el-upload
|
||||
class="upload-demo"
|
||||
class="upload-page-file"
|
||||
action="zyplayer-doc-wiki/common/upload"
|
||||
:on-success="uploadFileSuccess"
|
||||
name="files"
|
||||
show-file-list
|
||||
multiple
|
||||
:limit="3">
|
||||
:data="uploadFormData"
|
||||
:limit="999">
|
||||
<el-button icon="el-icon-upload">上传附件</el-button>
|
||||
</el-upload>
|
||||
</div>
|
||||
@@ -69,6 +71,25 @@
|
||||
<div class="wiki-content">
|
||||
<div v-html="pageContent.content"></div>
|
||||
</div>
|
||||
<div style="margin-top: 10px; font-size: 14px;">
|
||||
<span style="vertical-align: top;" class="is-link">
|
||||
<img src="webjars/doc-wiki/img/zan.png" style="vertical-align: middle;">
|
||||
<span v-show="wikiPage.selfZan == 0" v-on:click="zanPage(1)">赞</span>
|
||||
<span v-show="wikiPage.selfZan == 1" v-on:click="zanPage(0)">踩</span>
|
||||
</span>
|
||||
<span style="margin-left: 10px;vertical-align: top;">
|
||||
<span v-if="wikiPage.selfZan == 0 && wikiPage.zanNum <= 0">成为第一个赞同者</span>
|
||||
<span v-else-if="wikiPage.selfZan == 0 && wikiPage.zanNum > 0"><span class="is-link" v-on:click="showZanPageUser">{{wikiPage.zanNum}}人</span>赞了它</span>
|
||||
<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum <= 1">我赞了它</span>
|
||||
<span v-else-if="wikiPage.selfZan == 1 && wikiPage.zanNum > 1"><span class="is-link" v-on:click="showZanPageUser">我和{{wikiPage.zanNum-1}}个其他人</span>赞了它</span>
|
||||
</span>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<el-input type="textarea" v-model="commentTextInput" :rows="2" placeholder="请输入评论内容"></el-input>
|
||||
<div align="right" style="margin-top: 5px;">
|
||||
<el-button v-on:click="submitPageComment">提交评论</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-row>
|
||||
<el-row type="border-card" v-show="rightContentType == 2">
|
||||
<div style="margin-bottom: 10px;">
|
||||
@@ -141,6 +162,9 @@
|
||||
pageContent: {},
|
||||
pageFileList: [],
|
||||
uploadFileList: [],
|
||||
uploadFormData: {pageId: 0},
|
||||
// 评论相关
|
||||
commentTextInput: ""
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -151,7 +175,26 @@
|
||||
this.init();
|
||||
},
|
||||
methods: {
|
||||
editWiki(){
|
||||
zanPage(yn) {
|
||||
var param = {yn: yn, pageId: app.wikiPage.id};
|
||||
ajaxTemp("zyplayer-doc-wiki/page/zan/update", "post", "json", param, function (json) {
|
||||
if (validateResult(json)) {
|
||||
app.wikiPage.selfZan = yn;
|
||||
app.wikiPage.zanNum = app.wikiPage.zanNum + (yn == 1 ? 1 : -1);
|
||||
}
|
||||
});
|
||||
},
|
||||
showZanPageUser() {
|
||||
|
||||
},
|
||||
submitPageComment() {
|
||||
Toast.success(app.commentTextInput);
|
||||
},
|
||||
uploadFileSuccess(response) {
|
||||
app.pageFileList.push(response.data);
|
||||
Toast.success("上传成功!");
|
||||
},
|
||||
editWiki() {
|
||||
this.rightContentType = 2;
|
||||
this.newPageId = app.wikiPage.id;
|
||||
this.newPageTitle = app.wikiPage.name;
|
||||
@@ -183,7 +226,7 @@
|
||||
ajaxTemp("zyplayer-doc-wiki/page/update", "post", "json", param, function (json) {
|
||||
if (validateResult(json)) {
|
||||
Toast.success("保存成功!");
|
||||
this.loadPageDetail(json.data.id);
|
||||
app.loadPageDetail(json.data.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -201,9 +244,12 @@
|
||||
var param = {id: pageId};
|
||||
ajaxTemp("zyplayer-doc-wiki/page/detail", "post", "json", param, function (json) {
|
||||
if (validateResult(json)) {
|
||||
app.wikiPage = json.data.wikiPage || {};
|
||||
var wikiPage = json.data.wikiPage || {};
|
||||
wikiPage.selfZan = json.data.selfZan || 0;
|
||||
app.wikiPage = wikiPage;
|
||||
app.pageContent = json.data.pageContent || {};
|
||||
app.pageFileList = json.data.fileList || [];
|
||||
app.uploadFormData = {pageId: app.wikiPage.id};
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -278,6 +324,9 @@
|
||||
.wiki-title{font-size: 20px;}
|
||||
.wiki-author{font-size: 14px;padding: 10px 0;}
|
||||
.wiki-content{font-size: 14px;}
|
||||
|
||||
.upload-page-file .el-upload-list{display: none;}
|
||||
.is-link{color: #1e88e5;cursor: pointer;}
|
||||
</style>
|
||||
</html>
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 433 B |
Reference in New Issue
Block a user