标签模块实现
This commit is contained in:
parent
fcfb8b3cf9
commit
6356d963a1
@ -26,26 +26,32 @@ public abstract class AbstractService<T> implements Service<T> {
|
|||||||
modelClass = (Class<T>) pt.getActualTypeArguments()[0];
|
modelClass = (Class<T>) pt.getActualTypeArguments()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void save(T model) {
|
public void save(T model) {
|
||||||
mapper.insertSelective(model);
|
mapper.insertSelective(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void save(List<T> models) {
|
public void save(List<T> models) {
|
||||||
mapper.insertList(models);
|
mapper.insertList(models);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void deleteById(String id) {
|
public void deleteById(String id) {
|
||||||
mapper.deleteByPrimaryKey(id);
|
mapper.deleteByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void deleteByIds(String ids) {
|
public void deleteByIds(String ids) {
|
||||||
mapper.deleteByIds(ids);
|
mapper.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update(T model) {
|
public void update(T model) {
|
||||||
mapper.updateByPrimaryKeySelective(model);
|
mapper.updateByPrimaryKeySelective(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public T findById(String id) {
|
public T findById(String id) {
|
||||||
return mapper.selectByPrimaryKey(id);
|
return mapper.selectByPrimaryKey(id);
|
||||||
}
|
}
|
||||||
@ -63,14 +69,17 @@ public abstract class AbstractService<T> implements Service<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<T> findByIds(String ids) {
|
public List<T> findByIds(String ids) {
|
||||||
return mapper.selectByIds(ids);
|
return mapper.selectByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<T> findByCondition(Condition condition) {
|
public List<T> findByCondition(Condition condition) {
|
||||||
return mapper.selectByCondition(condition);
|
return mapper.selectByCondition(condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<T> findAll() {
|
public List<T> findAll() {
|
||||||
return mapper.selectAll();
|
return mapper.selectAll();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.rymcu.vertical.dto;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ronger
|
* @author ronger
|
||||||
@ -44,4 +45,6 @@ public class ArticleDTO {
|
|||||||
private Date updatedTime;
|
private Date updatedTime;
|
||||||
|
|
||||||
private Author articleAuthor;
|
private Author articleAuthor;
|
||||||
|
|
||||||
|
private List<ArticleTagDTO> tags;
|
||||||
}
|
}
|
||||||
|
21
src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java
Normal file
21
src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.rymcu.vertical.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ronger
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ArticleTagDTO {
|
||||||
|
private Integer idTag;
|
||||||
|
|
||||||
|
private String tagTitle;
|
||||||
|
|
||||||
|
private String tagUri;
|
||||||
|
|
||||||
|
private String tagDescription;
|
||||||
|
|
||||||
|
private String tagIconPath;
|
||||||
|
|
||||||
|
private Integer tagAuthorId;
|
||||||
|
}
|
@ -36,6 +36,8 @@ public class Tag implements Serializable,Cloneable {
|
|||||||
private String tagAd;
|
private String tagAd;
|
||||||
/** 是否显示全站侧边栏广告 */
|
/** 是否显示全站侧边栏广告 */
|
||||||
private String tagShowSideAd;
|
private String tagShowSideAd;
|
||||||
|
/** 标签状态 */
|
||||||
|
private String tagStatus;
|
||||||
/** 创建时间 */
|
/** 创建时间 */
|
||||||
private Date createdTime;
|
private Date createdTime;
|
||||||
/** 更新时间 */
|
/** 更新时间 */
|
||||||
|
@ -2,6 +2,7 @@ package com.rymcu.vertical.mapper;
|
|||||||
|
|
||||||
import com.rymcu.vertical.core.mapper.Mapper;
|
import com.rymcu.vertical.core.mapper.Mapper;
|
||||||
import com.rymcu.vertical.dto.ArticleDTO;
|
import com.rymcu.vertical.dto.ArticleDTO;
|
||||||
|
import com.rymcu.vertical.dto.ArticleTagDTO;
|
||||||
import com.rymcu.vertical.dto.Author;
|
import com.rymcu.vertical.dto.Author;
|
||||||
import com.rymcu.vertical.entity.Article;
|
import com.rymcu.vertical.entity.Article;
|
||||||
import com.rymcu.vertical.entity.ArticleContent;
|
import com.rymcu.vertical.entity.ArticleContent;
|
||||||
@ -27,4 +28,8 @@ public interface ArticleMapper extends Mapper<Article> {
|
|||||||
List<ArticleDTO> selectArticlesByTagName(@Param("tagName") String tagName);
|
List<ArticleDTO> selectArticlesByTagName(@Param("tagName") String tagName);
|
||||||
|
|
||||||
List<ArticleDTO> selectUserArticles(@Param("idUser") Integer idUser);
|
List<ArticleDTO> selectUserArticles(@Param("idUser") Integer idUser);
|
||||||
|
|
||||||
|
Integer deleteTagArticle(@Param("id") Integer id);
|
||||||
|
|
||||||
|
List<ArticleTagDTO> selectTags(@Param("idArticle") Integer idArticle);
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,8 @@ public interface TagMapper extends Mapper<Tag> {
|
|||||||
Integer selectCountUserTagById(@Param("idUser") Integer idUser, @Param("idTag") Integer idTag);
|
Integer selectCountUserTagById(@Param("idUser") Integer idUser, @Param("idTag") Integer idTag);
|
||||||
|
|
||||||
Integer insertUserTag(@Param("idTag") Integer idTag, @Param("idUser") Integer idUser, @Param("type") Integer type);
|
Integer insertUserTag(@Param("idTag") Integer idTag, @Param("idUser") Integer idUser, @Param("type") Integer type);
|
||||||
|
|
||||||
|
Integer deleteUnusedTag();
|
||||||
|
|
||||||
|
Integer update(@Param("idTag") Integer idTag, @Param("tagUri") String tagUri, @Param("tagIconPath") String tagIconPath, @Param("tagStatus") String tagStatus, @Param("tagDescription") String tagDescription);
|
||||||
}
|
}
|
||||||
|
@ -61,4 +61,11 @@ public interface ArticleService extends Service<Article> {
|
|||||||
* @return
|
* @return
|
||||||
* */
|
* */
|
||||||
Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException;
|
Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文章
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
* */
|
||||||
|
Map delete(Integer id);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.rymcu.vertical.entity.Tag;
|
|||||||
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
import com.rymcu.vertical.web.api.exception.BaseApiException;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ronger
|
* @author ronger
|
||||||
@ -20,4 +21,17 @@ public interface TagService extends Service<Tag> {
|
|||||||
* @return
|
* @return
|
||||||
* */
|
* */
|
||||||
Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException;
|
Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除未使用标签
|
||||||
|
* @return
|
||||||
|
* */
|
||||||
|
Map cleanUnusedTag();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加/更新标签
|
||||||
|
* @param tag
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map saveTag(Tag tag);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.rymcu.vertical.service.impl;
|
|||||||
|
|
||||||
import com.rymcu.vertical.core.service.AbstractService;
|
import com.rymcu.vertical.core.service.AbstractService;
|
||||||
import com.rymcu.vertical.dto.ArticleDTO;
|
import com.rymcu.vertical.dto.ArticleDTO;
|
||||||
|
import com.rymcu.vertical.dto.ArticleTagDTO;
|
||||||
import com.rymcu.vertical.dto.Author;
|
import com.rymcu.vertical.dto.Author;
|
||||||
import com.rymcu.vertical.entity.Article;
|
import com.rymcu.vertical.entity.Article;
|
||||||
import com.rymcu.vertical.entity.ArticleContent;
|
import com.rymcu.vertical.entity.ArticleContent;
|
||||||
@ -135,10 +136,30 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Map delete(Integer id) {
|
||||||
|
Map<String,String> map = new HashMap(1);
|
||||||
|
Integer result;
|
||||||
|
// 删除引用标签记录
|
||||||
|
result = articleMapper.deleteTagArticle(id);
|
||||||
|
if (result > 0){
|
||||||
|
result = articleMapper.deleteByPrimaryKey(id);
|
||||||
|
if (result < 1){
|
||||||
|
map.put("message", "删除失败!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
map.put("message", "删除失败!");
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
private ArticleDTO genArticle(ArticleDTO article,Integer type) {
|
private ArticleDTO genArticle(ArticleDTO article,Integer type) {
|
||||||
Author author = articleMapper.selectAuthor(article.getArticleAuthorId());
|
Author author = articleMapper.selectAuthor(article.getArticleAuthorId());
|
||||||
article.setArticleAuthor(author);
|
article.setArticleAuthor(author);
|
||||||
article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime()));
|
article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime()));
|
||||||
|
List<ArticleTagDTO> tags = articleMapper.selectTags(article.getIdArticle());
|
||||||
|
article.setTags(tags);
|
||||||
if(type == 1){
|
if(type == 1){
|
||||||
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
|
ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle());
|
||||||
article.setArticleContent(articleContent.getArticleContentHtml());
|
article.setArticleContent(articleContent.getArticleContentHtml());
|
||||||
|
@ -16,6 +16,8 @@ import javax.annotation.Resource;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ronger
|
* @author ronger
|
||||||
@ -45,12 +47,15 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
tag.setTagUri(URLEncoder.encode(tag.getTagTitle(),"UTF-8"));
|
tag.setTagUri(URLEncoder.encode(tag.getTagTitle(),"UTF-8"));
|
||||||
tag.setCreatedTime(new Date());
|
tag.setCreatedTime(new Date());
|
||||||
tag.setUpdatedTime(tag.getCreatedTime());
|
tag.setUpdatedTime(tag.getCreatedTime());
|
||||||
|
tag.setTagArticleCount(1);
|
||||||
tagMapper.insertSelective(tag);
|
tagMapper.insertSelective(tag);
|
||||||
addTagArticle = true;
|
addTagArticle = true;
|
||||||
addUserTag = true;
|
addUserTag = true;
|
||||||
} else {
|
} else {
|
||||||
Integer count = tagMapper.selectCountTagArticleById(tag.getIdTag(),article.getIdArticle());
|
Integer count = tagMapper.selectCountTagArticleById(tag.getIdTag(),article.getIdArticle());
|
||||||
if(count == 0){
|
if(count == 0){
|
||||||
|
tag.setTagArticleCount(tag.getTagArticleCount() + 1);
|
||||||
|
tagMapper.updateByPrimaryKeySelective(tag);
|
||||||
addTagArticle = true;
|
addTagArticle = true;
|
||||||
}
|
}
|
||||||
Integer countUserTag = tagMapper.selectCountUserTagById(user.getIdUser(),tag.getIdTag());
|
Integer countUserTag = tagMapper.selectCountUserTagById(user.getIdUser(),tag.getIdTag());
|
||||||
@ -69,4 +74,33 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Map cleanUnusedTag() {
|
||||||
|
Map map = new HashMap(1);
|
||||||
|
tagMapper.deleteUnusedTag();
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Map saveTag(Tag tag) {
|
||||||
|
Integer result = 0;
|
||||||
|
if (tag.getIdTag() == null) {
|
||||||
|
tag.setCreatedTime(new Date());
|
||||||
|
tag.setUpdatedTime(tag.getCreatedTime());
|
||||||
|
result = tagMapper.insertSelective(tag);
|
||||||
|
} else {
|
||||||
|
tag.setUpdatedTime(new Date());
|
||||||
|
result = tagMapper.update(tag.getIdTag(),tag.getTagUri(),tag.getTagIconPath(),tag.getTagStatus(),tag.getTagDescription());
|
||||||
|
}
|
||||||
|
Map map = new HashMap(1);
|
||||||
|
if (result == 0) {
|
||||||
|
map.put("message","操作失败!");
|
||||||
|
} else {
|
||||||
|
map.put("tag", tag);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.rymcu.vertical.entity.Topic;
|
|||||||
import com.rymcu.vertical.mapper.TopicMapper;
|
import com.rymcu.vertical.mapper.TopicMapper;
|
||||||
import com.rymcu.vertical.service.TopicService;
|
import com.rymcu.vertical.service.TopicService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -52,6 +53,7 @@ public class TopicServiceImpl extends AbstractService<Topic> implements TopicSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Map saveTopic(Topic topic) {
|
public Map saveTopic(Topic topic) {
|
||||||
Integer result = 0;
|
Integer result = 0;
|
||||||
if (topic.getIdTopic() == null) {
|
if (topic.getIdTopic() == null) {
|
||||||
|
@ -136,7 +136,7 @@ public class Utils {
|
|||||||
public static Map getArticlesGlobalResult(PageInfo<ArticleDTO> pageInfo) {
|
public static Map getArticlesGlobalResult(PageInfo<ArticleDTO> pageInfo) {
|
||||||
Map map = new HashMap(2);
|
Map map = new HashMap(2);
|
||||||
map.put("articles", pageInfo.getList());
|
map.put("articles", pageInfo.getList());
|
||||||
Map pagination = new HashMap(3);
|
Map pagination = new HashMap(4);
|
||||||
pagination.put("pageSize",pageInfo.getPageSize());
|
pagination.put("pageSize",pageInfo.getPageSize());
|
||||||
pagination.put("total",pageInfo.getTotal());
|
pagination.put("total",pageInfo.getTotal());
|
||||||
pagination.put("currentPage",pageInfo.getPageNum());
|
pagination.put("currentPage",pageInfo.getPageNum());
|
||||||
|
@ -6,9 +6,11 @@ import com.rymcu.vertical.core.result.GlobalResult;
|
|||||||
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
import com.rymcu.vertical.core.result.GlobalResultGenerator;
|
||||||
import com.rymcu.vertical.dto.admin.UserRoleDTO;
|
import com.rymcu.vertical.dto.admin.UserRoleDTO;
|
||||||
import com.rymcu.vertical.entity.Role;
|
import com.rymcu.vertical.entity.Role;
|
||||||
|
import com.rymcu.vertical.entity.Tag;
|
||||||
import com.rymcu.vertical.entity.Topic;
|
import com.rymcu.vertical.entity.Topic;
|
||||||
import com.rymcu.vertical.entity.User;
|
import com.rymcu.vertical.entity.User;
|
||||||
import com.rymcu.vertical.service.RoleService;
|
import com.rymcu.vertical.service.RoleService;
|
||||||
|
import com.rymcu.vertical.service.TagService;
|
||||||
import com.rymcu.vertical.service.TopicService;
|
import com.rymcu.vertical.service.TopicService;
|
||||||
import com.rymcu.vertical.service.UserService;
|
import com.rymcu.vertical.service.UserService;
|
||||||
import com.rymcu.vertical.util.Utils;
|
import com.rymcu.vertical.util.Utils;
|
||||||
@ -33,6 +35,8 @@ public class AdminController {
|
|||||||
private RoleService roleService;
|
private RoleService roleService;
|
||||||
@Resource
|
@Resource
|
||||||
private TopicService topicService;
|
private TopicService topicService;
|
||||||
|
@Resource
|
||||||
|
private TagService tagService;
|
||||||
|
|
||||||
@GetMapping("/users")
|
@GetMapping("/users")
|
||||||
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
|
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
|
||||||
@ -136,4 +140,40 @@ public class AdminController {
|
|||||||
return GlobalResultGenerator.genSuccessResult(map);
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tags")
|
||||||
|
public GlobalResult<Map<String, Object>> tags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
|
||||||
|
PageHelper.startPage(page, rows);
|
||||||
|
List<Tag> list = tagService.findAll();
|
||||||
|
PageInfo<Tag> pageInfo = new PageInfo<>(list);
|
||||||
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
|
map.put("tags", pageInfo.getList());
|
||||||
|
Map pagination = Utils.getPagination(pageInfo);
|
||||||
|
map.put("pagination", pagination);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/tag/clean-unused")
|
||||||
|
public GlobalResult<Map<String, Object>> cleanUnusedTag(){
|
||||||
|
Map map = tagService.cleanUnusedTag();
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tag/detail/{idTag}")
|
||||||
|
public GlobalResult<Tag> tagDetail(@PathVariable Integer idTag){
|
||||||
|
Tag tag = tagService.findById(idTag.toString());
|
||||||
|
return GlobalResultGenerator.genSuccessResult(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/tag/post")
|
||||||
|
public GlobalResult<Map> addTag(@RequestBody Tag tag){
|
||||||
|
Map map = tagService.saveTag(tag);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/tag/post")
|
||||||
|
public GlobalResult<Map> updateTag(@RequestBody Tag tag){
|
||||||
|
Map map = tagService.saveTag(tag);
|
||||||
|
return GlobalResultGenerator.genSuccessResult(map);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user