专题-标签管理

This commit is contained in:
x ronger 2019-12-26 00:05:28 +08:00
parent 1a6142c446
commit 23627d1fc6
10 changed files with 186 additions and 8 deletions

View File

@ -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;
}

View File

@ -23,7 +23,7 @@ public interface ArticleMapper extends Mapper<Article> {
ArticleContent selectArticleContent(@Param("idArticle") Integer idArticle); ArticleContent selectArticleContent(@Param("idArticle") Integer idArticle);
List<ArticleDTO> selectArticlesByTopicName(@Param("topicName") String topicName); List<ArticleDTO> selectArticlesByTopicUri(@Param("topicName") String topicName);
List<ArticleDTO> selectArticlesByTagName(@Param("tagName") String tagName); List<ArticleDTO> selectArticlesByTagName(@Param("tagName") String tagName);

View File

@ -3,17 +3,60 @@ package com.rymcu.vertical.mapper;
import com.rymcu.vertical.core.mapper.Mapper; import com.rymcu.vertical.core.mapper.Mapper;
import com.rymcu.vertical.dto.admin.TagDTO; import com.rymcu.vertical.dto.admin.TagDTO;
import com.rymcu.vertical.dto.admin.TopicDTO; import com.rymcu.vertical.dto.admin.TopicDTO;
import com.rymcu.vertical.entity.Tag;
import com.rymcu.vertical.entity.Topic; import com.rymcu.vertical.entity.Topic;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
/**
* @author ronger
*/
public interface TopicMapper extends Mapper<Topic> { public interface TopicMapper extends Mapper<Topic> {
/**
* 获取导航主题
* @return
*/
List<Topic> selectTopicNav(); List<Topic> selectTopicNav();
/**
* @param topicUri
* @return
*/
TopicDTO selectTopicByTopicUri(@Param("topicUri") String topicUri); TopicDTO selectTopicByTopicUri(@Param("topicUri") String topicUri);
/**
* @param idTopic
* @return
*/
List<TagDTO> selectTopicTag(@Param("idTopic") Integer idTopic); List<TagDTO> 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); 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<Tag> 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);
} }

View File

@ -36,7 +36,7 @@ public interface ArticleService extends Service<Article> {
* @param name * @param name
* @return * @return
* */ * */
List<ArticleDTO> findArticlesByTopicName(String name); List<ArticleDTO> findArticlesByTopicUri(String name);
/** /**
* 查询标签下文章列表 * 查询标签下文章列表

View File

@ -1,6 +1,8 @@
package com.rymcu.vertical.service; package com.rymcu.vertical.service;
import com.rymcu.vertical.core.service.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 com.rymcu.vertical.entity.Topic;
import java.util.List; import java.util.List;
@ -32,4 +34,26 @@ public interface TopicService extends Service<Topic> {
* @return * @return
* */ * */
Map saveTopic(Topic topic); Map saveTopic(Topic topic);
/**
* 查询未绑定标签
* @param idTopic
* @param tagTitle
* @return
*/
List<Tag> findUnbindTagsById(Integer idTopic, String tagTitle);
/**
* 绑定标签
* @param topicTag
* @return
*/
Map bindTopicTag(TopicTagDTO topicTag);
/**
* 取消绑定标签
* @param topicTag
* @return
*/
Map unbindTopicTag(TopicTagDTO topicTag);
} }

View File

@ -61,8 +61,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
} }
@Override @Override
public List<ArticleDTO> findArticlesByTopicName(String name) { public List<ArticleDTO> findArticlesByTopicUri(String name) {
List<ArticleDTO> articleDTOS = articleMapper.selectArticlesByTopicName(name); List<ArticleDTO> articleDTOS = articleMapper.selectArticlesByTopicUri(name);
return articleDTOS; return articleDTOS;
} }

View File

@ -5,9 +5,12 @@ import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.core.service.AbstractService; import com.rymcu.vertical.core.service.AbstractService;
import com.rymcu.vertical.dto.admin.TagDTO; import com.rymcu.vertical.dto.admin.TagDTO;
import com.rymcu.vertical.dto.admin.TopicDTO; 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.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.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -74,4 +77,38 @@ public class TopicServiceImpl extends AbstractService<Topic> implements TopicSer
} }
return map; return map;
} }
@Override
public List<Tag> 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;
}
} }

View File

@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.core.result.GlobalResult; 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.TopicTagDTO;
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.Tag;
@ -18,6 +19,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -128,6 +130,32 @@ public class AdminController {
return GlobalResultGenerator.genSuccessResult(topic); 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<Tag> list = topicService.findUnbindTagsById(idTopic, tagTitle);
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);
}
@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") @PostMapping("/topic/post")
public GlobalResult<Map> addTopic(@RequestBody Topic topic){ public GlobalResult<Map> addTopic(@RequestBody Topic topic){
Map map = topicService.saveTopic(topic); Map map = topicService.saveTopic(topic);

View File

@ -78,8 +78,11 @@
<select id="selectArticleContent" resultMap="ArticleContentResultMap"> <select id="selectArticleContent" resultMap="ArticleContentResultMap">
select article_content,article_content_html from vertical_article_content where id_article = #{idArticle} select article_content,article_content_html from vertical_article_content where id_article = #{idArticle}
</select> </select>
<select id="selectArticlesByTopicName" resultMap="DTOResultMap"> <select id="selectArticlesByTopicUri" resultMap="DTOResultMap">
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id order by updated_time desc 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> </select>
<select id="selectArticlesByTagName" resultMap="DTOResultMap"> <select id="selectArticlesByTagName" resultMap="DTOResultMap">
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id order by updated_time desc select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id order by updated_time desc

View File

@ -34,18 +34,47 @@
<id column="tag_description" property="tagDescription"/> <id column="tag_description" property="tagDescription"/>
<id column="tag_icon_path" property="tagIconPath"/> <id column="tag_icon_path" property="tagIconPath"/>
</resultMap> </resultMap>
<resultMap id="TagResultMap" type="com.rymcu.vertical.entity.Tag">
<!--
WARNING - @mbg.generated
-->
<id column="id" property="idTag"/>
<id column="tag_title" property="tagTitle"/>
<id column="tag_icon_path" property="tagIconPath"/>
<id column="tag_uri" property="tagUri"/>
<id column="tag_description" property="tagDescription"/>
<id column="tag_view_count" property="tagViewCount"/>
<id column="tag_article_count" property="tagArticleCount"/>
<id column="tag_ad" property="tagAd"/>
<id column="tag_show_side_ad" property="tagShowSideAd"/>
<id column="created_time" property="createdTime"/>
<id column="updated_time" property="updatedTime"/>
</resultMap>
<insert id="insertTopicTag">
insert into vertical_topic_tag (id_topic, id_tag, created_time, updated_time) values (#{idTopic}, #{idTag}, sysdate(), sysdate())
</insert>
<update id="update"> <update id="update">
update vertical_topic set topic_title = #{topicTitle},topic_uri = #{topicUri},topic_icon_path = #{topicIconPath} update vertical_topic set topic_title = #{topicTitle},topic_uri = #{topicUri},topic_icon_path = #{topicIconPath}
,topic_nva = #{topicNva},topic_status = #{topicStatus},topic_sort = #{topicSort},topic_description = #{topicDescription} ,topic_nva = #{topicNva},topic_status = #{topicStatus},topic_sort = #{topicSort},topic_description = #{topicDescription}
where id = #{idTopic} where id = #{idTopic}
</update> </update>
<delete id="deleteTopicTag">
delete from vertical_topic_tag where id_topic = #{idTopic} and id_tag = #{idTag}
</delete>
<select id="selectTopicNav" resultMap="BaseResultMap"> <select id="selectTopicNav" resultMap="BaseResultMap">
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 id,topic_title,topic_uri,topic_icon_path from vertical_topic where topic_nva = 0 and topic_status = 0 order by topic_sort
</select> </select>
<select id="selectTopicByTopicUri" resultMap="DTOResultMap"> <select id="selectTopicByTopicUri" resultMap="DTOResultMap">
select id,topic_title,topic_uri,topic_icon_path,topic_description,topic_tag_count,topic_status from vertical_topic where topic_uri = #{topicUri} select id,topic_title,topic_uri,topic_icon_path,topic_description,topic_tag_count,topic_status from vertical_topic where topic_uri = #{topicUri}
</select> </select>
<select id="selectTopicTag" resultType="com.rymcu.vertical.dto.admin.TagDTO"> <select id="selectTopicTag" resultMap="TagDTOResultMap">
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} 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
</select>
<select id="selectUnbindTagsById" resultMap="TagResultMap">
select * from vertical_tag vt where not exists(select * from vertical_topic_tag vtt where vtt.id_topic = #{idTopic} and vtt.id_tag = vt.id)
<if test="tagTitle != '' and tagTitle != null">
and vt.tag_title = #{tagTitle}
</if>
order by vt.created_time desc
</select> </select>
</mapper> </mapper>