From 1b6b900d88e109e5d1fe7a89d4c087148db4fd9d Mon Sep 17 00:00:00 2001
From: guyue <1721849008@qq.com>
Date: 星期日, 27 七月 2025 15:24:49 +0800
Subject: [PATCH] 重复次数计算增加问题id

---
 src/main/java/com/linghu/controller/PlatformController.java |   64 +++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/src/main/java/com/linghu/controller/PlatformController.java b/src/main/java/com/linghu/controller/PlatformController.java
index 030303d..3ea5942 100644
--- a/src/main/java/com/linghu/controller/PlatformController.java
+++ b/src/main/java/com/linghu/controller/PlatformController.java
@@ -10,12 +10,10 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.linghu.listener.PlatformExcelListener;
 import com.linghu.listener.TypeDropdownWriteHandler;
+import com.linghu.mapper.KeywordMapper;
 import com.linghu.mapper.ReferenceMapper;
 import com.linghu.model.common.ResponseResult;
-import com.linghu.model.entity.Platform;
-import com.linghu.model.entity.Reference;
-import com.linghu.model.entity.Sectionalization;
-import com.linghu.model.entity.Type;
+import com.linghu.model.entity.*;
 import com.linghu.model.excel.ExcelDataWithRow;
 import com.linghu.model.excel.PlatformExcel;
 import com.linghu.model.excel.UserExcel;
@@ -61,6 +59,8 @@
     private TypeService typeService;
     @Autowired
     private ReferenceMapper referenceMapper;
+    @Autowired
+    private KeywordMapper keywordMapper;
 
     @PostMapping
     @ApiOperation(value = "添加平台")
@@ -85,7 +85,7 @@
     @ApiOperation(value = "删除平台")
     public ResponseResult<Void> delete(@PathVariable Integer platformId) {
         //平台被引用了没
-        Integer count = referenceMapper.selectCount(new LambdaQueryWrapper<Reference>().eq(Reference::getPlatform_id, platformId));
+        Integer count = Math.toIntExact(referenceMapper.selectCount(new LambdaQueryWrapper<Reference>().eq(Reference::getPlatform_id, platformId)));
         if (count > 0) {
             return ResponseResult.error("该平台被引用中,不能删除");
         }
@@ -125,15 +125,59 @@
     @GetMapping("/list")
     @ApiOperation("查询平台列表,不传页数和大小就查全部")
     public ResponseResult<CustomPage<Platform>> list(
-            @RequestParam(required = false) Integer page,
-            @RequestParam(required = false) Integer pageSize,
-            @RequestParam(required = false) Integer type_id) {
+            @RequestParam(value = "page",required = false) Integer page,
+            @RequestParam(value = "pageSize",required = false) Integer pageSize,
+            @RequestParam(value = "type_id",required = false) Integer type_id,
+            @RequestParam(value = "keywordId", required = false) Integer keywordId,
+            @RequestParam(value = "questionId",required = false) Integer questionId,
+            @RequestParam(value = "isNow",required = false) Integer isNow
+            ) {
+        List<Integer> platForm=new ArrayList<>();
+        //先查找当前关键词下,所有的回答 的 所有的平台名称
+        Keyword keyword=new Keyword();
+        if (keywordId!=null){
+             keyword = keywordMapper.selectById(keywordId);
+        }
+
+        if (keywordId != null && questionId == null) {
+
+            List<Reference> references = referenceMapper.selectList(new LambdaQueryWrapper<Reference>()
+                    .eq(Reference::getKeyword_id, keywordId)
+                    .eq(Reference::getNum, isNow== 0 ? 1 : keyword.getNum())
+            );
+            platForm = references.stream().map(Reference::getPlatform_id).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+        }
+        if (keywordId != null && questionId != null) {
+            List<Reference> references = referenceMapper.selectList(new LambdaQueryWrapper<Reference>()
+                    .eq(Reference::getKeyword_id, keywordId)
+                    .eq(Reference::getNum, isNow== 0 ? 1 : keyword.getNum())
+                    .eq(Reference::getQuestion_id, questionId)
+            );
+            platForm = references.stream().map(Reference::getPlatform_id).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+        }
+
         // 构建查询条件并添加排序(按创建时间倒序)
         LambdaQueryWrapper<Platform> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.orderByDesc(Platform::getCreate_time); // 新增的排序条件
+        if (!platForm.isEmpty()){
+            queryWrapper.in(Platform::getPlatform_id, platForm);
+        }else {
+            if (page != null && pageSize != null){
+                Page<Platform> pageInfo = new Page<>(page, pageSize);
+                Page<Platform> result = platformService.page(pageInfo, queryWrapper);
+                return ResponseResult.success(new CustomPage<>(result));
+            }else {
+                CustomPage<Platform> customPage = new CustomPage<>(new Page<>());
+                customPage.setRecords(new ArrayList<>());
+                customPage.setTotal(0);
+                return ResponseResult.success(customPage);
+            }
+
+        }
+
         if (type_id != null) {
             queryWrapper.eq(Platform::getType_id, type_id);
         }
+        queryWrapper.orderByDesc(Platform::getCreate_time); // 新增的排序条件
         if (page != null && pageSize != null) {
             Page<Platform> pageInfo = new Page<>(page, pageSize);
             Page<Platform> result = platformService.page(pageInfo, queryWrapper);
@@ -261,7 +305,7 @@
                 platformService.saveBatch(platforms);
                 return ResponseResult.success("导入成功,新增" + platforms.size() + "条数据");
             } else {
-                return ResponseResult.success("导入完成,没有新增数据(所有数据均已存在)");
+                return ResponseResult.error("导入完成,没有新增数据(所有数据均已存在)");
             }
 
         } catch (Exception e) {

--
Gitblit v1.7.1