资讯保存草稿箱和发布时行业分类相关逻辑
This commit is contained in:
parent
7d8243c4f6
commit
af487fdb48
|
|
@ -64,6 +64,19 @@ public interface IndustryMapper {
|
||||||
"from draft_industry_rel where industry_id = #{industryId}")
|
"from draft_industry_rel where industry_id = #{industryId}")
|
||||||
Long countDraftIndustryRelList(@Param("industryId") Long industryId);
|
Long countDraftIndustryRelList(@Param("industryId") Long industryId);
|
||||||
|
|
||||||
|
|
||||||
|
@Delete("delete from news_industry_rel where news_id = #{newsId}")
|
||||||
|
void deleteNews(@Param("newsId") Long newsId);
|
||||||
|
|
||||||
|
@Delete("delete from draft_industry_rel where draft_id = #{draftId}")
|
||||||
|
void deleteDraft(@Param("draftId") Long draftId);
|
||||||
|
|
||||||
|
@Insert("insert into draft_industry_rel(draft_id, industry_id) values (#{draftId}, #{industryId})")
|
||||||
|
void saveDraftIndustryRel(@Param("draftId") Long draftId, @Param("industryId") Long industryId);
|
||||||
|
|
||||||
|
@Insert("insert into news_industry_rel(news_id, industry_id) values (#{newsId}, #{industryId})")
|
||||||
|
void saveNewsIndustryRel(@Param("newsId") Long newsId, @Param("industryId") Long industryId);
|
||||||
|
|
||||||
@Results({
|
@Results({
|
||||||
@Result(column = "id", property = "id", id = true),
|
@Result(column = "id", property = "id", id = true),
|
||||||
@Result(column = "parent_id", property = "parentId"),
|
@Result(column = "parent_id", property = "parentId"),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package com.jinrui.reference.core.model.dto.news;
|
package com.jinrui.reference.core.model.dto.news;
|
||||||
|
|
||||||
import com.jinrui.reference.core.model.vo.news.NewsDetailVO;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.jinrui.reference.core.model.vo.news.NewsDetailVO;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class SaveNewsDTO {
|
public class SaveNewsDTO {
|
||||||
|
|
@ -19,6 +20,9 @@ public class SaveNewsDTO {
|
||||||
|
|
||||||
private SaveDraftColumn column;
|
private SaveDraftColumn column;
|
||||||
|
|
||||||
|
private List<Long> industries;
|
||||||
|
|
||||||
|
|
||||||
private String content;
|
private String content;
|
||||||
// 不含html标签的纯文本
|
// 不含html标签的纯文本
|
||||||
private String contentText;
|
private String contentText;
|
||||||
|
|
@ -116,4 +120,12 @@ public class SaveNewsDTO {
|
||||||
public void setContentText(String contentText) {
|
public void setContentText(String contentText) {
|
||||||
this.contentText = contentText;
|
this.contentText = contentText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Long> getIndustries() {
|
||||||
|
return industries;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndustries(List<Long> industries) {
|
||||||
|
this.industries = industries;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,21 @@
|
||||||
package com.jinrui.reference.core.service;
|
package com.jinrui.reference.core.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
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;
|
||||||
|
|
@ -32,21 +48,6 @@ 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;
|
||||||
import com.jinrui.reference.core.model.vo.news.NewsVO;
|
import com.jinrui.reference.core.model.vo.news.NewsVO;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class NewsService {
|
public class NewsService {
|
||||||
|
|
@ -346,7 +347,7 @@ public class NewsService {
|
||||||
news.setEditorId(editorId);
|
news.setEditorId(editorId);
|
||||||
newsMapper.publishNews(news);
|
newsMapper.publishNews(news);
|
||||||
// zzp
|
// zzp
|
||||||
deleteNewsColumnAndTag(newsId);
|
deleteNewsRel(newsId);
|
||||||
try {
|
try {
|
||||||
SaveDraftTag saveDraftTag = saveNewsDTO.getTag();
|
SaveDraftTag saveDraftTag = saveNewsDTO.getTag();
|
||||||
if (saveDraftTag != null) {
|
if (saveDraftTag != null) {
|
||||||
|
|
@ -403,7 +404,17 @@ public class NewsService {
|
||||||
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<Long> saveDraftIndustries = saveNewsDTO.getIndustries();
|
||||||
|
if (!CollectionUtils.isEmpty(saveDraftIndustries)) {
|
||||||
|
for (Long industryId:saveDraftIndustries) {
|
||||||
|
industryMapper.saveNewsIndustryRel(newIdRl, industryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存发布新闻标签出错!", e);
|
||||||
|
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
||||||
|
}
|
||||||
return ResultObject.success();
|
return ResultObject.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,7 +454,7 @@ public class NewsService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
deleteNewsColumnAndTag(newsId);
|
deleteNewsRel(newsId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("删除新闻栏目标签异常!", e);
|
log.error("删除新闻栏目标签异常!", e);
|
||||||
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
||||||
|
|
@ -457,17 +468,17 @@ public class NewsService {
|
||||||
return ResultObject.success();
|
return ResultObject.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteNewsColumnAndTag(Long newsId) {
|
private void deleteNewsRel(Long newsId) {
|
||||||
columnMapper.deleteNews(newsId);
|
columnMapper.deleteNews(newsId);
|
||||||
tagMapper.deleteNews(newsId);
|
tagMapper.deleteNews(newsId);
|
||||||
|
industryMapper.deleteNews(newsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteDraft(Long draftId) {
|
private void deleteDraft(Long draftId) {
|
||||||
newsMapper.deleteDraft(draftId);
|
newsMapper.deleteDraft(draftId);
|
||||||
columnMapper.deleteDraft(draftId);
|
columnMapper.deleteDraft(draftId);
|
||||||
tagMapper.deleteDraft(draftId);
|
tagMapper.deleteDraft(draftId);
|
||||||
|
industryMapper.deleteDraft(draftId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResultObject<Void> saveNewDraft(SaveNewsDTO saveNewsDTO, News news) {
|
private ResultObject<Void> saveNewDraft(SaveNewsDTO saveNewsDTO, News news) {
|
||||||
|
|
@ -609,6 +620,66 @@ public class NewsService {
|
||||||
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存新闻行业分类关系
|
||||||
|
try {
|
||||||
|
List<Long> saveDraftIndustries = saveNewsDTO.getIndustries();
|
||||||
|
if (CollectionUtils.isEmpty(saveDraftIndustries)) {
|
||||||
|
industryMapper.deleteNews(newsId);
|
||||||
|
industryMapper.deleteDraft(draftId);
|
||||||
|
} else {
|
||||||
|
// 先查到这个行业分类有没有关联过
|
||||||
|
List<NewsIndustryRel> newsIndustryRelList = industryMapper.getNewsIndustryRelList(newsId);
|
||||||
|
|
||||||
|
// 如果前端传进来的没有,而库里有,就删掉
|
||||||
|
Set<Long> existedNewsIndustries = new HashSet<>();
|
||||||
|
for(NewsIndustryRel newsIndustryRel: newsIndustryRelList){
|
||||||
|
boolean isIn = false;
|
||||||
|
for (Long industryId : saveDraftIndustries) {
|
||||||
|
if(industryId == newsIndustryRel.getIndustryId()){
|
||||||
|
isIn = true;
|
||||||
|
existedNewsIndustries.add(industryId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!isIn){
|
||||||
|
industryMapper.deleteNews(newsIndustryRel.getNewsId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Long industryId : saveDraftIndustries) {
|
||||||
|
if (!existedNewsIndustries.contains(industryId)) {
|
||||||
|
industryMapper.saveNewsIndustryRel(newsId, industryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DraftIndustryRel> draftIndustryRelList = industryMapper.getDraftIndustryRelList(draftId);
|
||||||
|
Set<Long> existedDraftIndustries = new HashSet<>();
|
||||||
|
for(DraftIndustryRel draftIndustryRel: draftIndustryRelList){
|
||||||
|
boolean isIn = false;
|
||||||
|
for (Long industryId : saveDraftIndustries) {
|
||||||
|
if(industryId == draftIndustryRel.getIndustryId()){
|
||||||
|
isIn = true;
|
||||||
|
existedDraftIndustries.add(industryId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!isIn){
|
||||||
|
industryMapper.deleteDraft(draftIndustryRel.getDraftId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Long industryId : saveDraftIndustries) {
|
||||||
|
if (!existedDraftIndustries.contains(industryId)) {
|
||||||
|
industryMapper.saveDraftIndustryRel(draftId, industryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存发布新闻行业分类出错!", e);
|
||||||
|
return ResultObject.failed(500, "服务器错误,请联系系统管理员!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SaveDraftColumn column = saveNewsDTO.getColumn();
|
SaveDraftColumn column = saveNewsDTO.getColumn();
|
||||||
if (column != null) {
|
if (column != null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue