zero 1 tuần trước cách đây
mục cha
commit
16ef4771a8

+ 2 - 2
src/main/java/com/cslg/ppa/controller/ReportController.java

@@ -73,8 +73,8 @@ public class ReportController {
     @Operation(summary = "移除报告的关联资讯")
     @PostMapping("/removeAssoArticleReport")
     public String removeAssoArticleReport(@RequestBody AssoReportArticleIdDTO vo) {
-        Integer id = reportService.removeAssoArticleReport(vo);
-        return Response.success(id);
+        reportService.removeAssoArticleReport(vo);
+        return Response.success("移除成功");
     }
 
     @Operation(summary = "导出报告信息")

+ 3 - 1
src/main/java/com/cslg/ppa/dto/AssoReportArticleIdDTO.java

@@ -2,8 +2,10 @@ package com.cslg.ppa.dto;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class AssoReportArticleIdDTO {
 
-    private Integer assoId;
+    private List<Integer> assoIds;
 }

+ 3 - 0
src/main/java/com/cslg/ppa/dto/GetArticleInfoDTO.java

@@ -3,6 +3,7 @@ package com.cslg.ppa.dto;
 import lombok.Data;
 
 import java.util.Date;
+import java.util.List;
 
 @Data
 public class GetArticleInfoDTO {
@@ -15,6 +16,8 @@ public class GetArticleInfoDTO {
     //类别 1 国家知识产权局 2 地方相关法律法规 3 判例   4国外相关资讯 5 行业资讯
     private Integer categoryId;
 
+    private List<Integer> categoryIds;
+
     //来源id
     private Integer sourceId;
 

+ 4 - 0
src/main/java/com/cslg/ppa/dto/UpdateArticleInfoDTO.java

@@ -2,6 +2,8 @@ package com.cslg.ppa.dto;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class UpdateArticleInfoDTO {
 
@@ -9,5 +11,7 @@ public class UpdateArticleInfoDTO {
 
     private Integer categoryId;
 
+    private List<Integer> categoryIds;
+
     private String digest;
 }

+ 23 - 0
src/main/java/com/cslg/ppa/entity/ArticleCategoryRelation.java

@@ -0,0 +1,23 @@
+package com.cslg.ppa.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@TableName("article_category_relation")
+public class ArticleCategoryRelation extends BaseEntity<ArticleCategoryRelation>{
+    //资讯ID
+    @TableField(value = "article_id")
+    private Integer articleId;
+
+    //类别ID
+    @TableField(value = "category_id")
+    private Integer categoryId;
+
+    //创建时间
+    @TableField(value = "create_time")
+    private Date createTime;
+}

+ 9 - 0
src/main/java/com/cslg/ppa/mapper/ArticleCategoryRelationMapper.java

@@ -0,0 +1,9 @@
+package com.cslg.ppa.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cslg.ppa.entity.ArticleCategoryRelation;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface ArticleCategoryRelationMapper extends BaseMapper<ArticleCategoryRelation> {
+}

+ 15 - 0
src/main/java/com/cslg/ppa/service/ArticleCategoryRelationService.java

@@ -0,0 +1,15 @@
+package com.cslg.ppa.service;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cslg.ppa.entity.ArticleCategoryRelation;
+import com.cslg.ppa.mapper.ArticleCategoryRelationMapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class ArticleCategoryRelationService extends ServiceImpl<ArticleCategoryRelationMapper, ArticleCategoryRelation> {
+}

+ 62 - 3
src/main/java/com/cslg/ppa/service/ArticleInfoService.java

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

+ 1 - 1
src/main/java/com/cslg/ppa/service/GetWebArticle/GetEcigaretteService.java

@@ -47,7 +47,7 @@ public class GetEcigaretteService {
     private SourceInfoMapper sourceInfoMapper;
 
 
-    //    @Scheduled(cron = "0 0 5 * * ?")
+//    @Scheduled(cron = "0 0 5 * * ?")
 //    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
     public void execute() {
         System.out.println(new Date() + "-------AddArticle-Begin");

+ 11 - 8
src/main/java/com/cslg/ppa/service/ReportService.java

@@ -200,15 +200,18 @@ public class ReportService extends ServiceImpl<ReportMapper, Report> {
         return reportId;
     }
 
-    public Integer removeAssoArticleReport(AssoReportArticleIdDTO vo) {
+    public void removeAssoArticleReport(AssoReportArticleIdDTO vo) {
         PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
-        Integer assoId = vo.getAssoId();
-        AssoReportArticle assoReportArticle = assoReportArticleMapper.selectById(assoId);
-        assoReportArticle.setIfUse(0);
-        assoReportArticle.setUpdateId(personnelVO.getId());
-        assoReportArticle.setUpdateTime(new Date());
-        assoReportArticle.updateById();
-        return assoId;
+        List<Integer> assoIds = vo.getAssoIds();
+        if (!CollectionUtils.isEmpty(assoIds)) {
+            for (Integer assoId : assoIds) {
+                AssoReportArticle assoReportArticle = assoReportArticleMapper.selectById(assoId);
+                assoReportArticle.setIfUse(0);
+                assoReportArticle.setUpdateId(personnelVO.getId());
+                assoReportArticle.setUpdateTime(new Date());
+                assoReportArticle.updateById();
+            }
+        }
     }
 
     public String exportReport(Integer reportId, Integer templateId) {

+ 0 - 2
src/main/java/com/cslg/ppa/service/commom/WeChatLoginCheckService.java

@@ -47,8 +47,6 @@ public class WeChatLoginCheckService {
 
     @Scheduled(cron = "0 0 11 * * ?")
     public void checkWeChatLoginStatus() {
-        final String s = RedisConf.WECHAT_TOKEN + RedisConf.SYMBOL_COLON;
-        System.out.println(s);
         log.info("开始检查微信登录状态...");
         String token = redisUtil.get(RedisConf.WECHAT_TOKEN + RedisConf.SYMBOL_COLON);
         String cookieStr = redisUtil.get(RedisConf.WECHAT_COOKIE + RedisConf.SYMBOL_COLON);

+ 12 - 0
src/main/java/com/cslg/ppa/vo/SelectArticleInfoVO.java

@@ -5,6 +5,7 @@ import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.util.Date;
+import java.util.List;
 
 @Data
 public class SelectArticleInfoVO {
@@ -36,4 +37,15 @@ public class SelectArticleInfoVO {
 
     private String wxArticleIcon;
 
+    // 所有关联的类别ID列表
+    private List<Integer> categoryIds;
+
+    // 所有关联的类别名称列表
+    private List<String> categoryNames;
+
+    // 格式化后的类别名称字符串(如:"国家知识产权局, 地方相关法律法规")
+    private String categoryNamesStr;
+
+    private String categoryIdsStr;
+
 }

+ 30 - 27
src/main/resources/mapper/ArticleInfoMapper.xml

@@ -3,30 +3,32 @@
 <mapper namespace="com.cslg.ppa.mapper.ArticleInfoMapper">
 
     <select id="selectArticleInfoList" resultType="com.cslg.ppa.vo.SelectArticleInfoVO">
-        select ai.id as articleId,
-               ai.title,
-               CASE
-                  WHEN ai.old_content IS NOT NULL AND ai.old_content != '' THEN ai.old_content
-                  ELSE ai.digest
-               END AS digest,
-               ai.category_id,
-               ai.source_id,
-               ai.public_time,
-               ai.create_time,
-               ai.article_url,
-               ai.wx_article_icon,
-               ca.name as categoryName,
-               si.source_name,
-               si.source_type
-        from article_info ai
-        left join category ca on ca.id = ai.category_id
-        left join source_info si on si.id = ai.source_id
+        SELECT
+        ai.id as articleId,
+        ai.title,
+        CASE
+            WHEN ai.old_content IS NOT NULL AND ai.old_content != '' THEN ai.old_content
+            ELSE ai.digest
+        END AS digest,
+        ai.source_id,
+        ai.public_time,
+        ai.create_time,
+        ai.article_url,
+        ai.wx_article_icon,
+        si.source_name,
+        si.source_type,
+        GROUP_CONCAT(acr.category_id) as categoryIdsStr,
+        GROUP_CONCAT(ca.name) as categoryNamesStr
+        FROM article_info ai
+        LEFT JOIN article_category_relation acr ON acr.article_id = ai.id
+        LEFT JOIN category ca ON ca.id = acr.category_id
+        LEFT JOIN source_info si ON si.id = ai.source_id
         <where>
             <if test="vo.key != null and vo.key != ''">
                 ai.title like concat('%',#{vo.key},'%')
             </if>
             <if test="vo.categoryId != null">
-                and ai.category_id = #{vo.categoryId}
+                and acr.category_id = #{vo.categoryId}
             </if>
             <if test="vo.sourceName != null and vo.sourceName != ''">
                 and si.source_name like concat('%',#{vo.sourceName},'%')
@@ -38,24 +40,25 @@
                 and ai.public_time &lt;= #{vo.endTime}
             </if>
         </where>
-        order by ai.public_time desc,ai.id desc
+        GROUP BY ai.id
+        ORDER BY ai.public_time DESC, ai.id DESC
         <if test="vo.pageNum != null and vo.pageSize != null">
-            limit
-            ${(vo.pageNum -1) * vo.pageSize},${vo.pageSize}
+            LIMIT ${(vo.pageNum -1) * vo.pageSize},${vo.pageSize}
         </if>
     </select>
 
     <select id="selectArticleInfoCount" resultType="java.lang.Long">
-        select count(*)
-        from article_info ai
-        left join category ca on ca.id = ai.category_id
-        left join source_info si on si.id = ai.source_id
+        SELECT COUNT(DISTINCT ai.id)
+        FROM article_info ai
+        LEFT JOIN article_category_relation acr ON acr.article_id = ai.id
+        LEFT JOIN category ca ON ca.id = acr.category_id
+        LEFT JOIN source_info si ON si.id = ai.source_id
         <where>
             <if test="vo.key != null and vo.key != ''">
                 ai.title like concat('%',#{vo.key},'%')
             </if>
             <if test="vo.categoryId != null">
-                and ai.category_id = #{vo.categoryId}
+                and acr.category_id = #{vo.categoryId}
             </if>
             <if test="vo.sourceName != null and vo.sourceName != ''">
                 and si.source_name like concat('%',#{vo.sourceName},'%')

+ 2 - 1
src/main/resources/mapper/ReportMapper.xml

@@ -18,7 +18,8 @@
                si.source_type
         from asso_report_article ara
         left join article_info ai on ai.id = ara.article_id
-        left join category ca on ca.id = ai.category_id
+        left join article_category_relation acr on acr.article_id = ai.id
+        left join category ca on ca.id = acr.category_id
         left join source_info si on si.id = ai.source_id
         where ara.report_id = #{reportId} and ara.if_use = 1
         order by ai.public_time asc

+ 10 - 0
src/test/java/com/cslg/ppa/PpaApplicationTests.java

@@ -26,6 +26,8 @@ import com.cslg.ppa.service.commom.FileManagerService;
 import com.cslg.ppa.service.commom.WeChatLoginCheckService;
 import com.cslg.ppa.service.commom.WeiXinApi;
 import com.cslg.ppa.vo.OneClickExportVO;
+import com.cslg.ppa.vo.SelectArticleInfoVO;
+import com.cslg.ppa.vo.SelectAssoReportArticleVO;
 import com.cslg.ppa.vo.SelectSourceAndConfigVO;
 import okhttp3.Cookie;
 import okhttp3.HttpUrl;
@@ -648,4 +650,12 @@ class PpaApplicationTests {
 //        System.out.println(list.size());
 
     }
+
+    @Test
+    void test4() {
+        SelectArticleInfoDTO vo = new SelectArticleInfoDTO();
+//        final List<SelectArticleInfoVO> selectArticleInfoVOS = articleInfoMapper.selectArticleInfoList(vo);
+        final List<SelectAssoReportArticleVO> selectAssoReportArticleVOS = reportMapper.selectAssoReportArticleList(1);
+        System.out.println("=============");
+    }
 }