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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user