|
|
@@ -12,6 +12,7 @@ import com.cslg.ppa.dto.ArticleInfoIdDTO;
|
|
|
import com.cslg.ppa.dto.GetArticleInfoDTO;
|
|
|
import com.cslg.ppa.dto.SelectArticleInfoDTO;
|
|
|
import com.cslg.ppa.dto.UpdateArticleInfoDTO;
|
|
|
+import com.cslg.ppa.entity.ArticleCategoryRelation;
|
|
|
import com.cslg.ppa.entity.ArticleInfo;
|
|
|
import com.cslg.ppa.entity.AssoReportArticle;
|
|
|
import com.cslg.ppa.entity.BaseEntity;
|
|
|
@@ -33,8 +34,10 @@ import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@@ -45,14 +48,16 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
private ArticleInfoMapper articleInfoMapper;
|
|
|
@Autowired
|
|
|
private AssoReportArticleMapper assoReportArticleMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private DifyService difyService;
|
|
|
+ @Autowired
|
|
|
+ private ArticleCategoryRelationService articleCategoryRelationService;
|
|
|
|
|
|
public void batchAddArticleInfo(List<GetArticleInfoDTO> articleInfoDTOS) {
|
|
|
if (!CollectionUtils.isEmpty(articleInfoDTOS)) {
|
|
|
for (GetArticleInfoDTO articleInfoDTO : articleInfoDTOS) {
|
|
|
if (StringUtils.isNotEmpty(articleInfoDTO.getTitle())) {
|
|
|
+ //类别是地区资讯,那么根据摘要区分是否可一键导出报告
|
|
|
if (articleInfoDTO.getCategoryId() == 2) {
|
|
|
String str = null;
|
|
|
try {
|
|
|
@@ -66,6 +71,10 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
articleInfoDTO.setIfExportFromLocal(0);
|
|
|
}
|
|
|
}
|
|
|
+ Integer categoryId = articleInfoDTO.getCategoryId();
|
|
|
+ List<Integer> categoryIds = new ArrayList<>();
|
|
|
+ categoryIds.add(categoryId);
|
|
|
+ articleInfoDTO.setCategoryIds(categoryIds);
|
|
|
this.addArticleInfo(articleInfoDTO);
|
|
|
}
|
|
|
}
|
|
|
@@ -78,7 +87,6 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
ArticleInfo articleInfo = new ArticleInfo();
|
|
|
articleInfo.setTitle(infoDTO.getTitle());
|
|
|
articleInfo.setDigest(infoDTO.getDigest());
|
|
|
- articleInfo.setCategoryId(infoDTO.getCategoryId());
|
|
|
articleInfo.setPublicTime(infoDTO.getPublicTime());
|
|
|
articleInfo.setArticleUrl(infoDTO.getArticleUrl());
|
|
|
articleInfo.setSourceId(infoDTO.getSourceId());
|
|
|
@@ -86,6 +94,17 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
articleInfo.setIfExportFromLocal(infoDTO.getIfExportFromLocal());
|
|
|
articleInfo.setOldContent(infoDTO.getOldContent());
|
|
|
articleInfo.insert();
|
|
|
+
|
|
|
+ // 添加资讯与类别的关联关系
|
|
|
+ List<Integer> categoryIds = infoDTO.getCategoryIds();
|
|
|
+ if (!CollectionUtils.isEmpty(categoryIds)) {
|
|
|
+ for (Integer categoryId : categoryIds) {
|
|
|
+ ArticleCategoryRelation relation = new ArticleCategoryRelation();
|
|
|
+ relation.setArticleId(articleInfo.getId());
|
|
|
+ relation.setCategoryId(categoryId);
|
|
|
+ relation.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -96,6 +115,27 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
*/
|
|
|
public String selectArticleInfoList(SelectArticleInfoDTO vo) {
|
|
|
List<SelectArticleInfoVO> articleInfoVOS = articleInfoMapper.selectArticleInfoList(vo);
|
|
|
+ // 处理类别名称格式化
|
|
|
+ if (!CollectionUtils.isEmpty(articleInfoVOS)) {
|
|
|
+ for (SelectArticleInfoVO articleInfoVO : articleInfoVOS) {
|
|
|
+ // 将逗号分隔的类别ID转换为列表
|
|
|
+ String categoryIdsStr = articleInfoVO.getCategoryIdsStr();
|
|
|
+ if (StringUtils.isNotBlank(categoryIdsStr)) {
|
|
|
+ List<Integer> categoryIds = Arrays.stream(categoryIdsStr.split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ articleInfoVO.setCategoryIds(categoryIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将逗号分隔的类别名称转换为列表和格式化字符串
|
|
|
+ String categoryNamesStr = articleInfoVO.getCategoryNamesStr();
|
|
|
+ if (StringUtils.isNotBlank(categoryNamesStr)) {
|
|
|
+ List<String> categoryNames = Arrays.asList(categoryNamesStr.split(","));
|
|
|
+ articleInfoVO.setCategoryNames(categoryNames);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
Long count = articleInfoMapper.selectArticleInfoCount(vo);
|
|
|
Records records = new Records();
|
|
|
records.setTotal(count);
|
|
|
@@ -115,8 +155,22 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
Integer articleId = infoDTO.getArticleId();
|
|
|
ArticleInfo articleInfo = articleInfoMapper.selectById(articleId);
|
|
|
articleInfo.setDigest(infoDTO.getDigest());
|
|
|
- articleInfo.setCategoryId(infoDTO.getCategoryId());
|
|
|
articleInfo.updateById();
|
|
|
+
|
|
|
+ // 先删除原有的关联关系
|
|
|
+ articleCategoryRelationService.remove(new LambdaQueryWrapper<ArticleCategoryRelation>()
|
|
|
+ .eq(ArticleCategoryRelation::getArticleId, articleId));
|
|
|
+
|
|
|
+ // 再添加新的关联关系
|
|
|
+ List<Integer> categoryIds = infoDTO.getCategoryIds();
|
|
|
+ if (!CollectionUtils.isEmpty(categoryIds)) {
|
|
|
+ for (Integer categoryId : categoryIds) {
|
|
|
+ ArticleCategoryRelation relation = new ArticleCategoryRelation();
|
|
|
+ relation.setArticleId(articleId);
|
|
|
+ relation.setCategoryId(categoryId);
|
|
|
+ relation.insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
return articleInfo.getId();
|
|
|
}
|
|
|
|
|
|
@@ -132,6 +186,11 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
|
|
|
if (!CollectionUtils.isEmpty(articles)) {
|
|
|
throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "该条资讯正在被报告使用中,无法删除");
|
|
|
}
|
|
|
+
|
|
|
+ // 删除资讯与类别的关联关系
|
|
|
+ articleCategoryRelationService.remove(new LambdaQueryWrapper<ArticleCategoryRelation>()
|
|
|
+ .in(ArticleCategoryRelation::getArticleId, articleIds));
|
|
|
+
|
|
|
articleInfoMapper.deleteBatchIds(articleIds);
|
|
|
}
|
|
|
}
|