diff --git a/admin/src/main/java/com/jinrui/reference/admin/controller/IndustryController.java b/admin/src/main/java/com/jinrui/reference/admin/controller/IndustryController.java new file mode 100644 index 0000000..26c8ee9 --- /dev/null +++ b/admin/src/main/java/com/jinrui/reference/admin/controller/IndustryController.java @@ -0,0 +1,24 @@ +package com.jinrui.reference.admin.controller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.jinrui.reference.core.service.TagService; + +/** + * 行业分类管理 + */ +@RestController +@RequestMapping("/industry") +public class IndustryController { + private static final Logger log = LoggerFactory.getLogger(IndustryController.class); + + private final IndustryService industryService; + + public IndustryController(IndustryService industryService) { + this.industryService = industryService; + } + +} diff --git a/core/src/main/java/com/jinrui/reference/core/mapper/IndustryMapper.java b/core/src/main/java/com/jinrui/reference/core/mapper/IndustryMapper.java new file mode 100644 index 0000000..2aec1be --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/mapper/IndustryMapper.java @@ -0,0 +1,34 @@ +package com.jinrui.reference.core.mapper; + +import java.util.Date; +import java.util.List; + +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.type.JdbcType; + +import com.jinrui.reference.core.model.entity.DraftIndustryRel; +import com.jinrui.reference.core.model.entity.Industry; +import com.jinrui.reference.core.model.entity.NewsIndustryRel; + +public interface IndustryMapper { + @Results({ + @Result(column = "id", property = "id", id = true), + @Result(column = "primay_name", property = "primayName"), + @Result(column = "secondary_name", property = "secondaryName"), + @Result(column = "create_time", property = "createTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP), + @Result(column = "update_time", property = "updateTime", javaType = Date.class, jdbcType = JdbcType.TIMESTAMP) + }) + @Select("select * from industry order by primary_name") + List queryAll(); + + @Select("select id, draft_id as draftId, industry_id as industryId " + + "from draft_industry_rel where draft_id = #{draftId}") + List getDraftIndustryRelList(@Param("draftId") Long draftId); + + @Select("select id, news_id as newsId, industry_id as industryId " + + "from news_industry_rel where news_id = #{newsId}") + List getNewsIndustryRelList(@Param("newsId") Long newsId); +} diff --git a/core/src/main/java/com/jinrui/reference/core/model/entity/DraftIndustryRel.java b/core/src/main/java/com/jinrui/reference/core/model/entity/DraftIndustryRel.java new file mode 100644 index 0000000..ad37bbb --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/model/entity/DraftIndustryRel.java @@ -0,0 +1,46 @@ +package com.jinrui.reference.core.model.entity; + +/** + * 资讯草稿 - 行业分类关联表 + */ +@SuppressWarnings("unused") +public class DraftIndustryRel { + /** + * 关联表ID + */ + private Long id; + + /** + * 资讯草稿ID + */ + private Long draftId; + + /** + * 行业分类ID + */ + private Long industryId; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getDraftId() { + return draftId; + } + + public void setDraftId(Long draftId) { + this.draftId = draftId; + } + + public Long getIndustryId() { + return industryId; + } + + public void setIndustryId(Long industryId) { + this.industryId = industryId; + } +} diff --git a/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java b/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java new file mode 100644 index 0000000..8625299 --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/model/entity/Industry.java @@ -0,0 +1,74 @@ +package com.jinrui.reference.core.model.entity; + +import java.util.Date; + +/** + * 行业分类 + */ +@SuppressWarnings("unused") +public class Industry { + /** + * 行业分类ID + */ + private Long id; + + /** + * 一级行业 + */ + private String primayName; + + /** + * 二级行业 + */ + private String secondaryName; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改时间 + */ + private Date updateTime; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getPrimayName() { + return primayName; + } + + public void setPrimayName(String primayName) { + this.primayName = primayName; + } + + public String getSecondaryName() { + return secondaryName; + } + + public void setSecondaryName(String secondaryName) { + this.secondaryName = secondaryName; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} diff --git a/core/src/main/java/com/jinrui/reference/core/model/entity/NewsIndustryRel.java b/core/src/main/java/com/jinrui/reference/core/model/entity/NewsIndustryRel.java new file mode 100644 index 0000000..38f494a --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/model/entity/NewsIndustryRel.java @@ -0,0 +1,46 @@ +package com.jinrui.reference.core.model.entity; + +/** + * 资讯 - 行业关联表 + */ +@SuppressWarnings("unused") +public class NewsIndustryRel { + /** + * 关联表ID + */ + private Long id; + + /** + * 资讯ID + */ + private Long newsId; + + /** + * 行业分类ID + */ + private Long industryId; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getNewsId() { + return newsId; + } + + public void setNewsId(Long newsId) { + this.newsId = newsId; + } + + public Long getIndustryId() { + return industryId; + } + + public void setIndustryId(Long industryId) { + this.industryId = industryId; + } +} diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailIndustry.java b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailIndustry.java new file mode 100644 index 0000000..4c31a56 --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailIndustry.java @@ -0,0 +1,24 @@ +package com.jinrui.reference.core.model.vo.news; + +@SuppressWarnings("unused") +public class NewsDetailIndustry { + private Long id; + + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailVO.java b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailVO.java index 0f5a3cd..81ce65e 100644 --- a/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailVO.java +++ b/core/src/main/java/com/jinrui/reference/core/model/vo/news/NewsDetailVO.java @@ -1,5 +1,7 @@ package com.jinrui.reference.core.model.vo.news; +import java.util.List; + import com.jinrui.reference.core.model.entity.News; import com.jinrui.reference.core.model.entity.NewsDraft; @@ -17,6 +19,8 @@ public class NewsDetailVO { private NewsDetailTag tag; private NewsDetailColumn column; + + private List industry; private String content; @@ -93,4 +97,12 @@ public class NewsDetailVO { public void setContent(String content) { this.content = content; } + + public List getIndustry() { + return industry; + } + + public void setIndustry(List industry) { + this.industry = industry; + } } diff --git a/core/src/main/java/com/jinrui/reference/core/service/IndustryService.java b/core/src/main/java/com/jinrui/reference/core/service/IndustryService.java new file mode 100644 index 0000000..a03ba68 --- /dev/null +++ b/core/src/main/java/com/jinrui/reference/core/service/IndustryService.java @@ -0,0 +1,22 @@ +package com.jinrui.reference.core.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.jinrui.reference.core.mapper.IndustryMapper; + +@Service +public class IndustryService { + private static final Logger log = LoggerFactory.getLogger(IndustryService.class); + + private final ObjectMapper objectMapper; + private final IndustryMapper industryMapper; + + public IndustryService(ObjectMapper objectMapper, IndustryMapper industryMapper) { + this.objectMapper = objectMapper; + this.industryMapper = industryMapper; + } + +} diff --git a/core/src/main/java/com/jinrui/reference/core/service/NewsService.java b/core/src/main/java/com/jinrui/reference/core/service/NewsService.java index bf00020..cfced35 100644 --- a/core/src/main/java/com/jinrui/reference/core/service/NewsService.java +++ b/core/src/main/java/com/jinrui/reference/core/service/NewsService.java @@ -3,6 +3,7 @@ package com.jinrui.reference.core.service; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.jinrui.reference.core.mapper.ColumnMapper; +import com.jinrui.reference.core.mapper.IndustryMapper; import com.jinrui.reference.core.mapper.NewsMapper; import com.jinrui.reference.core.mapper.TagMapper; import com.jinrui.reference.core.model.dto.news.SaveDraftColumn; @@ -12,10 +13,13 @@ import com.jinrui.reference.core.model.dto.news.SaveDraftTag; import com.jinrui.reference.core.model.dto.news.SaveNewsDTO; import com.jinrui.reference.core.model.entity.Column; import com.jinrui.reference.core.model.entity.DraftColumnRel; +import com.jinrui.reference.core.model.entity.DraftIndustryRel; import com.jinrui.reference.core.model.entity.DraftTagRel; +import com.jinrui.reference.core.model.entity.Industry; import com.jinrui.reference.core.model.entity.News; import com.jinrui.reference.core.model.entity.NewsColumnRel; import com.jinrui.reference.core.model.entity.NewsDraft; +import com.jinrui.reference.core.model.entity.NewsIndustryRel; import com.jinrui.reference.core.model.entity.NewsTagRel; import com.jinrui.reference.core.model.entity.Tag; import com.jinrui.reference.core.model.vo.PageObject; @@ -23,6 +27,7 @@ import com.jinrui.reference.core.model.vo.ResultObject; import com.jinrui.reference.core.model.vo.column.ColumnVO; import com.jinrui.reference.core.model.vo.news.NewsDetailColumn; import com.jinrui.reference.core.model.vo.news.NewsDetailColumnVip; +import com.jinrui.reference.core.model.vo.news.NewsDetailIndustry; import com.jinrui.reference.core.model.vo.news.NewsDetailTag; import com.jinrui.reference.core.model.vo.news.NewsDetailTagItem; import com.jinrui.reference.core.model.vo.news.NewsDetailVO; @@ -52,15 +57,18 @@ public class NewsService { private final ColumnMapper columnMapper; private final ObjectMapper objectMapper; private final TagMapper tagMapper; + private final IndustryMapper industryMapper; public NewsService(NewsMapper newsMapper, ColumnMapper columnMapper, ObjectMapper objectMapper, - TagMapper tagMapper) { + TagMapper tagMapper, + IndustryMapper industryMapper) { this.newsMapper = newsMapper; this.columnMapper = columnMapper; this.objectMapper = objectMapper; this.tagMapper = tagMapper; + this.industryMapper = industryMapper; } public ResultObject publish(long id, long editorId) { @@ -101,6 +109,9 @@ public class NewsService { Map tagMap = allTags.stream().collect(Collectors.toMap(Tag::getId, Function.identity())); List allColumns = columnMapper.queryAll(); Map columnMap = allColumns.stream().collect(Collectors.toMap(Column::getId, Function.identity())); + List allIndustrys = industryMapper.queryAll(); + Map industryMap = allIndustrys.stream().collect(Collectors.toMap(Industry::getId, Function.identity())); + Long draftId = news.getDraftId(); if (draftId != null) { NewsDraft newsDraft = newsMapper.getDraftDetail(draftId); @@ -171,6 +182,20 @@ public class NewsService { } newsDetailTag.setFieldArr(arr); } + List industryRelList = industryMapper.getDraftIndustryRelList(draftId); + List newsIndustryList = new ArrayList<>(); + newsDetailVO.setIndustry(newsIndustryList); + if (!CollectionUtils.isEmpty(industryRelList)) { + for (DraftIndustryRel rel: industryRelList) { + Long industryId = rel.getIndustryId(); + Industry industry = industryMap.get(industryId); + NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry(); + newsDetailIndustry.setId(industryId); + newsDetailIndustry.setName(industry.getPrimayName() + "-" + industry.getSecondaryName()); + newsIndustryList.add(newsDetailIndustry); + } + } + // List tagRelListNews = tagMapper.getNewsTagRelList(id); // NewsDetailTag newsDetailTag2 = new NewsDetailTag(); @@ -266,6 +291,20 @@ public class NewsService { } newsDetailTag.setFieldArr(arr); } + + List industryRelList = industryMapper.getNewsIndustryRelList(id); + List newsIndustryList = new ArrayList<>(); + newsDetailVO.setIndustry(newsIndustryList); + if (!CollectionUtils.isEmpty(industryRelList)) { + for (NewsIndustryRel rel: industryRelList) { + Long industryId = rel.getIndustryId(); + Industry industry = industryMap.get(industryId); + NewsDetailIndustry newsDetailIndustry = new NewsDetailIndustry(); + newsDetailIndustry.setId(industryId); + newsDetailIndustry.setName(industry.getPrimayName() + "-" + industry.getSecondaryName()); + newsIndustryList.add(newsDetailIndustry); + } + } return ResultObject.success(newsDetailVO); }