diff --git a/src/main/java/com/rymcu/vertical/dto/admin/TopicTagDTO.java b/src/main/java/com/rymcu/vertical/dto/admin/TopicTagDTO.java new file mode 100644 index 0000000..dc7b5fb --- /dev/null +++ b/src/main/java/com/rymcu/vertical/dto/admin/TopicTagDTO.java @@ -0,0 +1,14 @@ +package com.rymcu.vertical.dto.admin; + +import lombok.Data; + +/** + * @author ronger + */ +@Data +public class TopicTagDTO { + + private Integer idTopic; + + private Integer idTag; +} diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index f365dd5..ae9c19d 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -23,7 +23,7 @@ public interface ArticleMapper extends Mapper
{ ArticleContent selectArticleContent(@Param("idArticle") Integer idArticle); - List selectArticlesByTopicName(@Param("topicName") String topicName); + List selectArticlesByTopicUri(@Param("topicName") String topicName); List selectArticlesByTagName(@Param("tagName") String tagName); diff --git a/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java b/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java index f945a37..266d867 100644 --- a/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/TopicMapper.java @@ -3,17 +3,60 @@ package com.rymcu.vertical.mapper; import com.rymcu.vertical.core.mapper.Mapper; import com.rymcu.vertical.dto.admin.TagDTO; import com.rymcu.vertical.dto.admin.TopicDTO; +import com.rymcu.vertical.entity.Tag; import com.rymcu.vertical.entity.Topic; import org.apache.ibatis.annotations.Param; import java.util.List; +/** + * @author ronger + */ public interface TopicMapper extends Mapper { + /** + * 获取导航主题 + * @return + */ List selectTopicNav(); + /** + * @param topicUri + * @return + */ TopicDTO selectTopicByTopicUri(@Param("topicUri") String topicUri); + /** + * @param idTopic + * @return + */ List selectTopicTag(@Param("idTopic") Integer idTopic); + /** + * @param idTopic + * @param topicTitle + * @param topicUri + * @param topicIconPath + * @param topicNva + * @param topicStatus + * @param topicSort + * @param topicDescription + * @return + */ Integer update(@Param("idTopic") Integer idTopic, @Param("topicTitle") String topicTitle, @Param("topicUri") String topicUri, @Param("topicIconPath") String topicIconPath, @Param("topicNva") String topicNva, @Param("topicStatus") String topicStatus, @Param("topicSort") Integer topicSort, @Param("topicDescription") String topicDescription); + + /** + * @param idTopic + * @param tagTitle + * @return + */ + List selectUnbindTagsById(@Param("idTopic") Integer idTopic, @Param("tagTitle") String tagTitle); + + Integer insertTopicTag(@Param("idTopic") Integer idTopic, @Param("idTag") Integer idTag); + + /** + * @param idTopic + * @param idTag + * @return + */ + Integer deleteTopicTag(@Param("idTopic") Integer idTopic, @Param("idTag") Integer idTag); } diff --git a/src/main/java/com/rymcu/vertical/service/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index 871c8d9..91e87c2 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -36,7 +36,7 @@ public interface ArticleService extends Service
{ * @param name * @return * */ - List findArticlesByTopicName(String name); + List findArticlesByTopicUri(String name); /** * 查询标签下文章列表 diff --git a/src/main/java/com/rymcu/vertical/service/TopicService.java b/src/main/java/com/rymcu/vertical/service/TopicService.java index 8b8a6e5..cffce69 100644 --- a/src/main/java/com/rymcu/vertical/service/TopicService.java +++ b/src/main/java/com/rymcu/vertical/service/TopicService.java @@ -1,6 +1,8 @@ package com.rymcu.vertical.service; import com.rymcu.vertical.core.service.Service; +import com.rymcu.vertical.dto.admin.TopicTagDTO; +import com.rymcu.vertical.entity.Tag; import com.rymcu.vertical.entity.Topic; import java.util.List; @@ -32,4 +34,26 @@ public interface TopicService extends Service { * @return * */ Map saveTopic(Topic topic); + + /** + * 查询未绑定标签 + * @param idTopic + * @param tagTitle + * @return + */ + List findUnbindTagsById(Integer idTopic, String tagTitle); + + /** + * 绑定标签 + * @param topicTag + * @return + */ + Map bindTopicTag(TopicTagDTO topicTag); + + /** + * 取消绑定标签 + * @param topicTag + * @return + */ + Map unbindTopicTag(TopicTagDTO topicTag); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java index eeb22b1..d60f618 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -61,8 +61,8 @@ public class ArticleServiceImpl extends AbstractService
implements Arti } @Override - public List findArticlesByTopicName(String name) { - List articleDTOS = articleMapper.selectArticlesByTopicName(name); + public List findArticlesByTopicUri(String name) { + List articleDTOS = articleMapper.selectArticlesByTopicUri(name); return articleDTOS; } diff --git a/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java index 333c159..3a05146 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TopicServiceImpl.java @@ -5,9 +5,12 @@ import com.github.pagehelper.PageInfo; import com.rymcu.vertical.core.service.AbstractService; import com.rymcu.vertical.dto.admin.TagDTO; import com.rymcu.vertical.dto.admin.TopicDTO; +import com.rymcu.vertical.dto.admin.TopicTagDTO; +import com.rymcu.vertical.entity.Tag; import com.rymcu.vertical.entity.Topic; import com.rymcu.vertical.mapper.TopicMapper; import com.rymcu.vertical.service.TopicService; +import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -74,4 +77,38 @@ public class TopicServiceImpl extends AbstractService implements TopicSer } return map; } + + @Override + public List findUnbindTagsById(Integer idTopic, String tagTitle) { + if (StringUtils.isBlank(tagTitle)) { + tagTitle = ""; + } + return topicMapper.selectUnbindTagsById(idTopic,tagTitle); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Map bindTopicTag(TopicTagDTO topicTag) { + Integer result = topicMapper.insertTopicTag(topicTag.getIdTopic(), topicTag.getIdTag()); + Map map = new HashMap(1); + if (result == 0) { + map.put("message", "操作失败!"); + } else { + map.put("topicTag", topicTag); + } + return map; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Map unbindTopicTag(TopicTagDTO topicTag) { + Integer result = topicMapper.deleteTopicTag(topicTag.getIdTopic(), topicTag.getIdTag()); + Map map = new HashMap(1); + if (result == 0) { + map.put("message", "操作失败!"); + } else { + map.put("topicTag", topicTag); + } + return map; + } } diff --git a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java index 7b87193..2249a76 100644 --- a/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/vertical/web/api/admin/AdminController.java @@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; +import com.rymcu.vertical.dto.admin.TopicTagDTO; import com.rymcu.vertical.dto.admin.UserRoleDTO; import com.rymcu.vertical.entity.Role; import com.rymcu.vertical.entity.Tag; @@ -18,6 +19,7 @@ import org.apache.commons.lang.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -128,6 +130,32 @@ public class AdminController { return GlobalResultGenerator.genSuccessResult(topic); } + @GetMapping("/topic/unbind-topic-tags") + public GlobalResult unbindTopicTags(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, HttpServletRequest request){ + Integer idTopic = Integer.valueOf(request.getParameter("idTopic")); + String tagTitle = request.getParameter("tagTitle"); + PageHelper.startPage(page, rows); + List list = topicService.findUnbindTagsById(idTopic, tagTitle); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap<>(2); + map.put("tags", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + @PostMapping("/topic/bind-topic-tag") + public GlobalResult bindTopicTag(@RequestBody TopicTagDTO topicTag){ + Map map = topicService.bindTopicTag(topicTag); + return GlobalResultGenerator.genSuccessResult(map); + } + + @DeleteMapping("/topic/unbind-topic-tag") + public GlobalResult unbindTopicTag(@RequestBody TopicTagDTO topicTag){ + Map map = topicService.unbindTopicTag(topicTag); + return GlobalResultGenerator.genSuccessResult(map); + } + @PostMapping("/topic/post") public GlobalResult addTopic(@RequestBody Topic topic){ Map map = topicService.saveTopic(topic); diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 238cabe..9376b97 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -78,8 +78,11 @@ - + select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id + where exists(select * from vertical_tag_article vta where vta.id_article = art.id and exists(select * from vertical_topic_tag vtt + left join vertical_tag vt on vtt.id_tag = vt.id where vt.id = vta.id_tag and exists(select * from vertical_topic topic + where topic.id = vtt.id_topic and topic.topic_uri = #{topicName}))) order by updated_time desc select id,topic_title,topic_uri,topic_icon_path from vertical_topic where topic_nva = 0 and topic_status = 0 order by topic_sort - + select vt.id,vt.tag_title,vt.tag_uri,vt.tag_description,vt.tag_icon_path from vertical_tag vt left join vertical_topic_tag vtt on vt.id = vtt.id_tag where vtt.id_topic = #{idTopic} order by vtt.created_time desc + + \ No newline at end of file