全量资讯概念标签不存在则创建逻辑优化
This commit is contained in:
parent
0809534b3b
commit
6863147014
|
|
@ -1,12 +1,7 @@
|
|||
package com.jinrui.reference.admin.controller;
|
||||
|
||||
import com.jinrui.reference.admin.model.entity.AdminUser;
|
||||
import com.jinrui.reference.admin.service.AdminJwtService;
|
||||
import com.jinrui.reference.core.model.dto.news.SaveTagsDTO;
|
||||
import com.jinrui.reference.core.model.vo.PageObject;
|
||||
import com.jinrui.reference.core.model.vo.ResultObject;
|
||||
import com.jinrui.reference.core.model.vo.tag.TagVO;
|
||||
import com.jinrui.reference.core.service.TagService;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
|
@ -18,6 +13,14 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.jinrui.reference.admin.model.entity.AdminUser;
|
||||
import com.jinrui.reference.admin.service.AdminJwtService;
|
||||
import com.jinrui.reference.core.model.dto.news.SaveTagsDTO;
|
||||
import com.jinrui.reference.core.model.vo.PageObject;
|
||||
import com.jinrui.reference.core.model.vo.ResultObject;
|
||||
import com.jinrui.reference.core.model.vo.tag.TagVO;
|
||||
import com.jinrui.reference.core.service.TagService;
|
||||
|
||||
/**
|
||||
* 标签管理
|
||||
*/
|
||||
|
|
@ -265,4 +268,19 @@ public class TagController {
|
|||
@RequestParam(value = "direction", required = false, defaultValue = "asc") String direction) {
|
||||
return queryTag(token, parent, needChildren, keyword, 1L, page, size, orderBy, direction);
|
||||
}
|
||||
|
||||
@GetMapping("/concept")
|
||||
public ResultObject<List<TagVO>> queryConcept(@RequestHeader("auth-token") String token) {
|
||||
AdminUser adminUser = AdminJwtService.parseToken(token);
|
||||
if (adminUser == null) {
|
||||
log.warn("解析token {}拿不到AdminUser对象!", token);
|
||||
return ResultObject.failed("登陆Token有误,请联系系统管理员!");
|
||||
}
|
||||
|
||||
if (!adminUser.isActive()) {
|
||||
log.warn("当前用户已被封禁! id = {}", adminUser.getId());
|
||||
return ResultObject.failed("当前用户已被封禁!请联系系统管理员!");
|
||||
}
|
||||
return tagService.getAllConceptTag();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.jinrui.reference.core.model.entity.NewsTagRel;
|
|||
import com.jinrui.reference.core.model.entity.Tag;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Result;
|
||||
import org.apache.ibatis.annotations.Results;
|
||||
|
|
@ -61,8 +62,12 @@ public interface TagMapper {
|
|||
@Insert("insert into news_tag_rel(news_id, tag_id) values (#{newsId}, #{tagId})")
|
||||
void saveNewsTagRel(@Param("newsId") Long newsId, @Param("tagId") Long tagId);
|
||||
|
||||
@Insert("insert into tag(parent_id, name, create_time, update_time) values (#{parentId},#{name}, now(), now())")
|
||||
void saveTag(@Param("parentId") Long parentId, @Param("name") String name);
|
||||
// @Insert("insert into tag(parent_id, name, create_time, update_time) values (#{parentId},#{name}, now(), now())")
|
||||
// void saveTag(@Param("parentId") Long parentId, @Param("name") String name);
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
|
||||
@Insert("insert into tag(parent_id, parent_name, name, level, create_time, update_time) values (#{parentId},#{parentName}, #{name},#{level}, now(), now())")
|
||||
void saveTag(Tag tag);
|
||||
|
||||
@Insert("update tag set name=#{name}, update_time=now() where id=#{id}")
|
||||
void updateTag(@Param("id") Long id, @Param("name") String name);
|
||||
|
|
@ -73,6 +78,7 @@ public interface TagMapper {
|
|||
@Results({
|
||||
@Result(column = "id", property = "id", id = true),
|
||||
@Result(column = "parent_id", property = "parentId"),
|
||||
@Result(column = "parent_name", property = "parentName"),
|
||||
@Result(column = "name", property = "name"),
|
||||
@Result(column = "create_time", property = "createTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP),
|
||||
@Result(column = "update_time", property = "updateTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ public class Tag {
|
|||
|
||||
private String parentName;
|
||||
|
||||
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
|
|
@ -85,6 +88,14 @@ public class Tag {
|
|||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
if (ObjectUtils.isEmpty(this.getParentName())) {
|
||||
return this.getName();
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ public class TagVO {
|
|||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* 父级标签名称
|
||||
*/
|
||||
private String parentName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
|
@ -43,6 +49,7 @@ public class TagVO {
|
|||
public TagVO(Tag tag) {
|
||||
this.id = tag.getId();
|
||||
this.name = tag.getName();
|
||||
this.parentName = tag.getParentName();
|
||||
this.createTime = tag.getCreateTime();
|
||||
this.updateTime = tag.getUpdateTime();
|
||||
}
|
||||
|
|
@ -86,4 +93,12 @@ public class TagVO {
|
|||
public void setChildren(List<TagVO> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getParentName() {
|
||||
return parentName;
|
||||
}
|
||||
|
||||
public void setParentName(String parentName) {
|
||||
this.parentName = parentName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,14 +77,6 @@ public class NewsInfoService {
|
|||
this.industryMapper = industryMapper;
|
||||
this.newsMapper = newsMapper;
|
||||
this.newsTagsMapper = newsTagsMapper;
|
||||
|
||||
NewsTags newsTags = newsTagsMapper.getNewsTagsByNewsId("102694660");
|
||||
for (String conceptLabel: newsTags.getConceptLabel()) {
|
||||
System.out.println("+++++++++++++++++++++conceptLabel++++++++++++++++++++++" + conceptLabel);
|
||||
}
|
||||
for (String industryLabel: newsTags.getIndustryLabel()) {
|
||||
System.out.println("+++++++++++++++++++++industryLabel++++++++++++++++++++++" + industryLabel);
|
||||
}
|
||||
}
|
||||
|
||||
public ResultObject<Void> publish(String id, long editorId) {
|
||||
|
|
@ -156,7 +148,12 @@ public class NewsInfoService {
|
|||
}
|
||||
}
|
||||
if (!isFound) {
|
||||
tagMapper.saveTag(1L, sourcename);
|
||||
Tag sourceTag = new Tag();
|
||||
sourceTag.setParentId(1L);
|
||||
sourceTag.setName(sourcename);
|
||||
sourceTag.setLevel(1);
|
||||
tagMapper.saveTag(sourceTag);
|
||||
tagMapper.saveNewsTagRel(newsId, sourceTag.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,15 +161,46 @@ public class NewsInfoService {
|
|||
if (!ObjectUtils.isEmpty(conceptLabels)) {
|
||||
List<Tag> tags = tagMapper.queryAll().stream().filter(e -> !ObjectUtils.isEmpty(e.getParentName())).collect(Collectors.toList());
|
||||
for (String conceptLabel: conceptLabels) {
|
||||
boolean existed = false;
|
||||
for (Tag tag:tags) {
|
||||
if (conceptLabel.equals(tag.getDisplayName())) {
|
||||
tagMapper.saveNewsTagRel(newsId, tag.getId());
|
||||
existed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!existed) {
|
||||
Long conceptTagId = saveConceptLabel(conceptLabel);
|
||||
tagMapper.saveNewsTagRel(newsId, conceptTagId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Long saveConceptLabel(String conceptLabel) {
|
||||
String[] conceptTags = conceptLabel.split("-");
|
||||
Tag levelOneTag = new Tag();
|
||||
levelOneTag.setParentId(6L);
|
||||
levelOneTag.setLevel(1);
|
||||
levelOneTag.setName(conceptTags[0]);
|
||||
tagMapper.saveTag(levelOneTag);
|
||||
if (conceptTags.length > 1) {
|
||||
Tag levelTwoTag = new Tag();
|
||||
levelTwoTag.setParentId(levelOneTag.getId());
|
||||
levelTwoTag.setLevel(2);
|
||||
levelTwoTag.setParentName(conceptTags[0]);
|
||||
levelTwoTag.setName(conceptTags[1]);
|
||||
return levelTwoTag.getId();
|
||||
}
|
||||
return levelOneTag.getId();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String a = "对外开放-出海50";
|
||||
String[] tags = a.split("-");
|
||||
System.out.println(tags[0]);
|
||||
System.out.println(tags[1]);
|
||||
}
|
||||
|
||||
public ResultObject<NewsInfoDetailVO> detail(String id) {
|
||||
|
||||
|
|
@ -230,9 +258,9 @@ public class NewsInfoService {
|
|||
for (Industry industry: allIndustrys) {
|
||||
if (Objects.equals(industry.getDisplayName(), industryLabel)) {
|
||||
NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry();
|
||||
newsDetailIndustry.setId(newsDetailIndustry.getId());
|
||||
newsDetailIndustry.setPrimaryName(newsDetailIndustry.getPrimaryName());
|
||||
newsDetailIndustry.setSecondaryName(newsDetailIndustry.getSecondaryName());
|
||||
newsDetailIndustry.setId(industry.getId());
|
||||
newsDetailIndustry.setPrimaryName(industry.getPrimaryName());
|
||||
newsDetailIndustry.setSecondaryName(industry.getSecondaryName());
|
||||
industries.add(newsDetailIndustry);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import org.springframework.util.CollectionUtils;
|
|||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -122,7 +123,19 @@ public class TagService {
|
|||
* 目前来源标签写死为1
|
||||
* id=1的初始化的时候就是来源标签
|
||||
*/
|
||||
tagMapper.saveTag(parentId, name);
|
||||
Tag tag = new Tag();
|
||||
tag.setParentId(parentId);
|
||||
if (parentId == 1L || parentId == 6L) {
|
||||
tag.setLevel(1);
|
||||
} else {
|
||||
tag.setLevel(2);
|
||||
Tag parentTag = tagMapper.queryById(parentId);
|
||||
if (parentTag != null) {
|
||||
tag.setParentName(parentTag.getName());
|
||||
}
|
||||
}
|
||||
tag.setName(name);
|
||||
tagMapper.saveTag(tag);
|
||||
return ResultObject.success();
|
||||
}
|
||||
|
||||
|
|
@ -166,4 +179,15 @@ public class TagService {
|
|||
tagMapper.deleteTag(id);
|
||||
return ResultObject.success();
|
||||
}
|
||||
|
||||
public ResultObject<List<TagVO>> getAllConceptTag() {
|
||||
List<TagVO> result = new LinkedList<>();
|
||||
List<Tag> levelOneTags = tagMapper.queryTag(6L, null, null, "id", "asc");
|
||||
for (Tag levelOneTag: levelOneTags) {
|
||||
result.add(new TagVO(levelOneTag));
|
||||
List<Tag> levelTwoTags = tagMapper.queryTag(levelOneTag.getId(), null, null, "id", "asc");
|
||||
result.addAll(levelTwoTags.stream().map(TagVO::new).collect(Collectors.toList()));
|
||||
}
|
||||
return ResultObject.success(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue