资讯详情接口页面增加行业分类返回数据

This commit is contained in:
sunflower2014 2025-05-27 19:53:27 +08:00
parent bf5abeab48
commit 35e2bc8f7f
9 changed files with 322 additions and 1 deletions

View File

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

View File

@ -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<Industry> queryAll();
@Select("select id, draft_id as draftId, industry_id as industryId " +
"from draft_industry_rel where draft_id = #{draftId}")
List<DraftIndustryRel> 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<NewsIndustryRel> getNewsIndustryRelList(@Param("newsId") Long newsId);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,7 @@
package com.jinrui.reference.core.model.vo.news; 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.News;
import com.jinrui.reference.core.model.entity.NewsDraft; import com.jinrui.reference.core.model.entity.NewsDraft;
@ -18,6 +20,8 @@ public class NewsDetailVO {
private NewsDetailColumn column; private NewsDetailColumn column;
private List<NewsDetailIndustry> industry;
private String content; private String content;
public NewsDetailVO() { public NewsDetailVO() {
@ -93,4 +97,12 @@ public class NewsDetailVO {
public void setContent(String content) { public void setContent(String content) {
this.content = content; this.content = content;
} }
public List<NewsDetailIndustry> getIndustry() {
return industry;
}
public void setIndustry(List<NewsDetailIndustry> industry) {
this.industry = industry;
}
} }

View File

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

View File

@ -3,6 +3,7 @@ package com.jinrui.reference.core.service;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.jinrui.reference.core.mapper.ColumnMapper; 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.NewsMapper;
import com.jinrui.reference.core.mapper.TagMapper; import com.jinrui.reference.core.mapper.TagMapper;
import com.jinrui.reference.core.model.dto.news.SaveDraftColumn; 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.dto.news.SaveNewsDTO;
import com.jinrui.reference.core.model.entity.Column; import com.jinrui.reference.core.model.entity.Column;
import com.jinrui.reference.core.model.entity.DraftColumnRel; 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.DraftTagRel;
import com.jinrui.reference.core.model.entity.Industry;
import com.jinrui.reference.core.model.entity.News; import com.jinrui.reference.core.model.entity.News;
import com.jinrui.reference.core.model.entity.NewsColumnRel; import com.jinrui.reference.core.model.entity.NewsColumnRel;
import com.jinrui.reference.core.model.entity.NewsDraft; 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.NewsTagRel;
import com.jinrui.reference.core.model.entity.Tag; import com.jinrui.reference.core.model.entity.Tag;
import com.jinrui.reference.core.model.vo.PageObject; 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.column.ColumnVO;
import com.jinrui.reference.core.model.vo.news.NewsDetailColumn; 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.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.NewsDetailTag;
import com.jinrui.reference.core.model.vo.news.NewsDetailTagItem; import com.jinrui.reference.core.model.vo.news.NewsDetailTagItem;
import com.jinrui.reference.core.model.vo.news.NewsDetailVO; import com.jinrui.reference.core.model.vo.news.NewsDetailVO;
@ -52,15 +57,18 @@ public class NewsService {
private final ColumnMapper columnMapper; private final ColumnMapper columnMapper;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
private final TagMapper tagMapper; private final TagMapper tagMapper;
private final IndustryMapper industryMapper;
public NewsService(NewsMapper newsMapper, public NewsService(NewsMapper newsMapper,
ColumnMapper columnMapper, ColumnMapper columnMapper,
ObjectMapper objectMapper, ObjectMapper objectMapper,
TagMapper tagMapper) { TagMapper tagMapper,
IndustryMapper industryMapper) {
this.newsMapper = newsMapper; this.newsMapper = newsMapper;
this.columnMapper = columnMapper; this.columnMapper = columnMapper;
this.objectMapper = objectMapper; this.objectMapper = objectMapper;
this.tagMapper = tagMapper; this.tagMapper = tagMapper;
this.industryMapper = industryMapper;
} }
public ResultObject<Void> publish(long id, long editorId) { public ResultObject<Void> publish(long id, long editorId) {
@ -101,6 +109,9 @@ public class NewsService {
Map<Long, Tag> tagMap = allTags.stream().collect(Collectors.toMap(Tag::getId, Function.identity())); Map<Long, Tag> tagMap = allTags.stream().collect(Collectors.toMap(Tag::getId, Function.identity()));
List<Column> allColumns = columnMapper.queryAll(); List<Column> allColumns = columnMapper.queryAll();
Map<Long, Column> columnMap = allColumns.stream().collect(Collectors.toMap(Column::getId, Function.identity())); Map<Long, Column> columnMap = allColumns.stream().collect(Collectors.toMap(Column::getId, Function.identity()));
List<Industry> allIndustrys = industryMapper.queryAll();
Map<Long, Industry> industryMap = allIndustrys.stream().collect(Collectors.toMap(Industry::getId, Function.identity()));
Long draftId = news.getDraftId(); Long draftId = news.getDraftId();
if (draftId != null) { if (draftId != null) {
NewsDraft newsDraft = newsMapper.getDraftDetail(draftId); NewsDraft newsDraft = newsMapper.getDraftDetail(draftId);
@ -171,6 +182,20 @@ public class NewsService {
} }
newsDetailTag.setFieldArr(arr); newsDetailTag.setFieldArr(arr);
} }
List<DraftIndustryRel> industryRelList = industryMapper.getDraftIndustryRelList(draftId);
List<NewsDetailIndustry> 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<NewsTagRel> tagRelListNews = tagMapper.getNewsTagRelList(id); // List<NewsTagRel> tagRelListNews = tagMapper.getNewsTagRelList(id);
// NewsDetailTag newsDetailTag2 = new NewsDetailTag(); // NewsDetailTag newsDetailTag2 = new NewsDetailTag();
@ -266,6 +291,20 @@ public class NewsService {
} }
newsDetailTag.setFieldArr(arr); newsDetailTag.setFieldArr(arr);
} }
List<NewsIndustryRel> industryRelList = industryMapper.getNewsIndustryRelList(id);
List<NewsDetailIndustry> 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); return ResultObject.success(newsDetailVO);
} }