From 6727c89745faa938cc053fa67ea3b9f819f5cbfe Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期三, 16 七月 2025 16:46:20 +0800 Subject: [PATCH] bug修改 --- src/main/resources/mapper/PlatformMapper.xml | 3 src/main/java/com/linghu/service/impl/PlatformServiceImpl.java | 4 src/main/java/com/linghu/service/PlatformService.java | 2 src/main/java/com/linghu/service/impl/KeywordServiceImpl.java | 6 + src/main/java/com/linghu/controller/QuestionController.java | 32 ++++++++ pom.xml | 2 src/main/java/com/linghu/controller/PlatformController.java | 49 ++++++++++-- src/main/java/com/linghu/model/entity/Reference.java | 2 src/main/java/com/linghu/model/vo/ResultList2VO.java | 1 src/main/java/com/linghu/controller/CollectController.java | 19 +++- src/main/java/com/linghu/mapper/PlatformMapper.java | 3 src/main/resources/mapper/keywordMapper.xml | 13 +++ src/main/java/com/linghu/mapper/KeywordMapper.java | 2 src/main/java/com/linghu/controller/KeywordController.java | 9 + src/main/java/com/linghu/controller/TypeController.java | 52 ++++++++++++ src/main/java/com/linghu/model/dto/TaskResultResponse.java | 5 + 16 files changed, 176 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index bd57390..00786df 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>com.lingHu</groupId> <artifactId>lingHu</artifactId> - <version>0.0.1-SNAPSHOT</version> + <version>1.0.0</version> <name>lingHu</name> <description>lingHu</description> <properties> diff --git a/src/main/java/com/linghu/controller/CollectController.java b/src/main/java/com/linghu/controller/CollectController.java index eed4f0d..f1ae783 100644 --- a/src/main/java/com/linghu/controller/CollectController.java +++ b/src/main/java/com/linghu/controller/CollectController.java @@ -835,9 +835,9 @@ * @param domain 平台域名 * @return 已存在或新创建的Platform */ - private Platform getOrCreatePlatform(String domain) { + private Platform getOrCreatePlatform(String domain,String platformName) { // 1. 先尝试查询已存在的平台 - Platform platform = platformService.getPlatformByDomain(domain); + Platform platform = platformService.getPlatformByDomain(domain,platformName); if (platform != null) { return platform; } @@ -856,7 +856,12 @@ // 2.2 构建新平台对象 Platform newPlatform = new Platform(); newPlatform.setDomain(domain); - newPlatform.setPlatform_name(domain); // 平台名称默认使用域名,可根据实际需求调整 + if (platformName != null) { + newPlatform.setPlatform_name(platformName); + }else { + newPlatform.setPlatform_name(domain); + } + // 平台名称默认使用域名,可根据实际需求调整 newPlatform.setType_id(defaultType.getType_id()); newPlatform.setCreate_time(LocalDateTime.now()); // 补充创建时间 @@ -867,7 +872,7 @@ } catch (DuplicateKeyException e) { // 3. 若捕获到重复键异常,说明并发创建了,重新查询即可(此时数据库中已存在该平台) log.warn("平台domain={}已存在,无需重复创建", domain, e); - return platformService.getPlatformByDomain(domain); // 重新查询,一定能获取到 + return platformService.getPlatformByDomain(domain,platformName); // 重新查询,一定能获取到 } catch (Exception e) { // 处理其他异常(如数据库连接失败等) log.error("创建平台失败,domain={}", domain, e); @@ -1076,7 +1081,9 @@ reference.setNum(keyword.getNum()); reference.setTask_id(result.getTask_id()); reference.setKeyword_id(keyword.getKeyword_id()); - reference.setCreate_time(LocalDateTime.now()); + if (null!=ref.getPublish_time()) { + reference.setCreate_time(ref.getPublish_time().atStartOfDay()); + } /* // 处理平台和类型关联 Platform platform = platformService.getPlatformByDomain(reference.getDomain()); @@ -1109,7 +1116,7 @@ } */ // 关键:使用优化后的方法获取平台,避免重复创建 - Platform platform = getOrCreatePlatform(ref.getDomain()); + Platform platform = getOrCreatePlatform(ref.getDomain(),ref.getPlatform_name()); reference.setPlatform_id(platform.getPlatform_id()); reference.setType_id(platform.getType_id()); // 直接从平台获取类型ID,更可靠 // 添加到结果列表 diff --git a/src/main/java/com/linghu/controller/KeywordController.java b/src/main/java/com/linghu/controller/KeywordController.java index 751c723..e4de724 100644 --- a/src/main/java/com/linghu/controller/KeywordController.java +++ b/src/main/java/com/linghu/controller/KeywordController.java @@ -161,6 +161,8 @@ @RequestParam(value = "typeId", required = false) Integer typeId, @RequestParam(value = "isNow") Integer isNow) { Keyword keyword = keywordService.getById(keywordId); + + if (isNow == 0) { List<PlatformProportionVO> result = keywordMapper.getResultByTypeId(keywordId, questionId, keyword.getNum() , typeId); @@ -203,6 +205,7 @@ List<String> typeNameList = result.stream() .map(PlatformProportionVO::getType_name) .filter(Objects::nonNull) + .distinct() .collect(Collectors.toList()); // 3. 导出Excel @@ -463,11 +466,11 @@ // 定义日期格式化器 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); Map<String, FeedExportExcel> timeMap = references.stream() + .filter(excel -> excel.getCreate_time() != null) .collect(Collectors.toMap( excel -> excel.getCreate_time().format(formatter), - - excel -> excel, // Value映射 - (oldValue, newValue) -> oldValue // 键冲突处理(保留旧值) + excel -> excel, + (oldValue, newValue) -> oldValue )); try { diff --git a/src/main/java/com/linghu/controller/PlatformController.java b/src/main/java/com/linghu/controller/PlatformController.java index a1036df..2e79fb6 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 = "添加平台") @@ -125,15 +125,48 @@ @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") Integer isNow + ) { + List<Integer> platForm=new ArrayList<>(); + //先查找当前关键词下,所有的回答 的 所有的平台名称 + Keyword 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 (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 { + 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); diff --git a/src/main/java/com/linghu/controller/QuestionController.java b/src/main/java/com/linghu/controller/QuestionController.java index 0c2090c..6bc866d 100644 --- a/src/main/java/com/linghu/controller/QuestionController.java +++ b/src/main/java/com/linghu/controller/QuestionController.java @@ -5,10 +5,13 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.linghu.listener.QuestionExcelListener; +import com.linghu.mapper.KeywordMapper; +import com.linghu.mapper.ReferenceMapper; import com.linghu.model.common.ResponseResult; import com.linghu.model.dto.KeywordDto; import com.linghu.model.entity.Keyword; import com.linghu.model.entity.Question; +import com.linghu.model.entity.Reference; import com.linghu.model.excel.KeywordExcel; import com.linghu.model.excel.QuestionExcel; import com.linghu.service.KeywordService; @@ -39,6 +42,10 @@ private QuestionService questionService; @Autowired private KeywordService keywordService; + @Autowired + private KeywordMapper keywordMapper; + @Autowired + private ReferenceMapper referenceMapper; @PostMapping @ApiOperation(value = "添加提问词") @@ -164,6 +171,31 @@ } + @GetMapping("/notNullList") + @ApiOperation("根据关键词查询提问词列表") + public ResponseResult<List<Question>> notNullList(Integer keyword_id) { + Keyword keyword = keywordMapper.selectById(keyword_id); + + List<Reference> references = referenceMapper.selectList(new LambdaQueryWrapper<Reference>() + .eq(Reference::getKeyword_id, keyword_id) + .eq(Reference::getNum, keyword.getNum())); + List<Integer> questionIds = references.stream().map(Reference::getQuestion_id).distinct().collect(Collectors.toList()); + // 查询success状态的 当前轮数的 + LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Question::getKeyword_id, keyword_id); + queryWrapper.eq(Question::getStatus, "success"); + if ( !questionIds.isEmpty()) { + queryWrapper.in(Question::getQuestion_id, questionIds); + }else { + return ResponseResult.success(new ArrayList<>()); + } + + + List<Question> list = questionService.list(queryWrapper); + return ResponseResult.success(list); + + } + // 下载模板 @PostMapping("/downloadTemplate") @ApiOperation("下载模板") diff --git a/src/main/java/com/linghu/controller/TypeController.java b/src/main/java/com/linghu/controller/TypeController.java index 9296c81..fe65ac2 100644 --- a/src/main/java/com/linghu/controller/TypeController.java +++ b/src/main/java/com/linghu/controller/TypeController.java @@ -2,24 +2,36 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.linghu.mapper.KeywordMapper; +import com.linghu.mapper.ReferenceMapper; import com.linghu.model.common.ResponseResult; +import com.linghu.model.entity.Keyword; +import com.linghu.model.entity.Reference; import com.linghu.model.entity.Type; +import com.linghu.service.KeywordService; import com.linghu.service.TypeService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; @RestController -@RequestMapping("/type") + @RequestMapping("/type") @Api(value = "类型相关接口", tags = "设置-类型") public class TypeController { @Autowired private TypeService typeService; + @Autowired + private KeywordMapper keywordMapper; + @Autowired + private ReferenceMapper referenceMapper; @PostMapping @ApiOperation(value = "添加类型") @@ -92,12 +104,48 @@ return ResponseResult.error("批量删除类型失败"); } + @GetMapping("/list") @ApiOperation(value = "查询类型列表,不传页数和大小就查全部") public ResponseResult<List<Type>> list( @RequestParam(required = false) Integer page, - @RequestParam(required = false) Integer pageSize) { + @RequestParam(required = false) Integer pageSize, + @RequestParam(required = false) Integer keywordId, + @RequestParam(required = false) Integer questionId, + @RequestParam Integer isNow + ) { + List<Integer> typeIds=new ArrayList<>(); + //先查找当前关键词下,所有的回答 的 所有的平台名称 + Keyword keyword = keywordMapper.selectById(keywordId); + if (isNow==0){ + typeIds= keywordMapper.getTypeIds(keywordId,questionId,0); + }else { + typeIds= keywordMapper.getTypeIds(keywordId,questionId,keyword.getNum()); + } + + /* 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()) + ); + typeIds = references.stream().map(Reference::getType_id).filter(Objects::nonNull).distinct().collect(Collectors.toList()); + } + if (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) + ); + typeIds = references.stream().map(Reference::getType_id).filter(Objects::nonNull).distinct().collect(Collectors.toList()); + } +*/ LambdaQueryWrapper<Type> queryWrapper = new LambdaQueryWrapper<>(); + if (!typeIds.isEmpty()) { + queryWrapper.in(Type::getType_id, typeIds); + }else { + return ResponseResult.success(new ArrayList<>()); + } if (page != null && pageSize != null) { Page<Type> pageInfo = new Page<>(page, pageSize); diff --git a/src/main/java/com/linghu/mapper/KeywordMapper.java b/src/main/java/com/linghu/mapper/KeywordMapper.java index 8ca2e29..9d73fc8 100644 --- a/src/main/java/com/linghu/mapper/KeywordMapper.java +++ b/src/main/java/com/linghu/mapper/KeywordMapper.java @@ -23,6 +23,8 @@ List<PlatformProportionVO> getResultByTypeId(@Param("keywordId") Integer keywordId, @Param("questionId")Integer questionId, @Param("num")Integer num, @Param("typeId") Integer typeId); List<ResultListVO> getResultByPlatformId(@Param("keywordId") Integer keywordId, @Param("questionId")Integer questionId, @Param("num")Integer num, @Param("platformId") Integer platformId); + + List<Integer> getTypeIds(@Param("keywordId") Integer keywordId, @Param("questionId") Integer questionId, @Param("num") Integer num); } diff --git a/src/main/java/com/linghu/mapper/PlatformMapper.java b/src/main/java/com/linghu/mapper/PlatformMapper.java index 1bdaa37..9e33c25 100644 --- a/src/main/java/com/linghu/mapper/PlatformMapper.java +++ b/src/main/java/com/linghu/mapper/PlatformMapper.java @@ -2,6 +2,7 @@ import com.linghu.model.entity.Platform; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; /** * @author xy @@ -10,6 +11,6 @@ * @Entity com.linghu.model.entity.Platfrom */ public interface PlatformMapper extends BaseMapper<Platform> { - public Platform getPlatformByDomain(String domain); + public Platform getPlatformByDomain(@Param("domain") String domain, @Param("platformName") String platformName); } diff --git a/src/main/java/com/linghu/model/dto/TaskResultResponse.java b/src/main/java/com/linghu/model/dto/TaskResultResponse.java index f1dff21..dc6174b 100644 --- a/src/main/java/com/linghu/model/dto/TaskResultResponse.java +++ b/src/main/java/com/linghu/model/dto/TaskResultResponse.java @@ -1,10 +1,12 @@ package com.linghu.model.dto; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.NoArgsConstructor; import lombok.AllArgsConstructor; import java.time.Duration; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -53,5 +55,8 @@ private String title; private String url; private String domain; + @JsonFormat(pattern = "yyyy/MM/dd") + private LocalDate publish_time; + private String platform_name; } } \ No newline at end of file diff --git a/src/main/java/com/linghu/model/entity/Reference.java b/src/main/java/com/linghu/model/entity/Reference.java index 58db951..16e3cd0 100644 --- a/src/main/java/com/linghu/model/entity/Reference.java +++ b/src/main/java/com/linghu/model/entity/Reference.java @@ -46,7 +46,7 @@ /** * 创建时间 */ - @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS", timezone = "GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private LocalDateTime create_time; /** diff --git a/src/main/java/com/linghu/model/vo/ResultList2VO.java b/src/main/java/com/linghu/model/vo/ResultList2VO.java index ec19b44..87ef410 100644 --- a/src/main/java/com/linghu/model/vo/ResultList2VO.java +++ b/src/main/java/com/linghu/model/vo/ResultList2VO.java @@ -18,6 +18,7 @@ private Integer reference_id; @ApiModelProperty("平台名称") + @ExcelProperty("平台名称") private String platform_name; @ApiModelProperty("标题") diff --git a/src/main/java/com/linghu/service/PlatformService.java b/src/main/java/com/linghu/service/PlatformService.java index 18a0514..8aed301 100644 --- a/src/main/java/com/linghu/service/PlatformService.java +++ b/src/main/java/com/linghu/service/PlatformService.java @@ -9,5 +9,5 @@ * @createDate 2025-07-04 20:17:33 */ public interface PlatformService extends IService<Platform> { - public Platform getPlatformByDomain(String domain); + public Platform getPlatformByDomain(String domain,String platformName); } diff --git a/src/main/java/com/linghu/service/impl/KeywordServiceImpl.java b/src/main/java/com/linghu/service/impl/KeywordServiceImpl.java index 3c848df..21e800f 100644 --- a/src/main/java/com/linghu/service/impl/KeywordServiceImpl.java +++ b/src/main/java/com/linghu/service/impl/KeywordServiceImpl.java @@ -39,10 +39,12 @@ return ResponseResult.success(); } List<KeywordStaticsVO> statics = this.getBaseMapper().statics(keywordId, questionId, keyword.getNum()); - vo.setNowRecord(statics); + List<KeywordStaticsVO> top30 = statics.subList(0, Math.min(statics.size(), 30)); + vo.setNowRecord(top30); if (keyword.getNum() > 1) { statics = this.getBaseMapper().statics(keywordId, questionId, 1); - vo.setBeforeRecord(statics); + top30 = statics.subList(0, Math.min(statics.size(), 30)); + vo.setBeforeRecord(top30); } return ResponseResult.success(vo); } diff --git a/src/main/java/com/linghu/service/impl/PlatformServiceImpl.java b/src/main/java/com/linghu/service/impl/PlatformServiceImpl.java index d7cc4cd..7ac5f1e 100644 --- a/src/main/java/com/linghu/service/impl/PlatformServiceImpl.java +++ b/src/main/java/com/linghu/service/impl/PlatformServiceImpl.java @@ -20,8 +20,8 @@ @Resource private PlatformMapper platformMapper; @Override - public Platform getPlatformByDomain(String domain) { - return platformMapper.getPlatformByDomain(domain); + public Platform getPlatformByDomain(String domain,String platformName) { + return platformMapper.getPlatformByDomain(domain,platformName); } } diff --git a/src/main/resources/mapper/PlatformMapper.xml b/src/main/resources/mapper/PlatformMapper.xml index 6d032b8..af932e8 100644 --- a/src/main/resources/mapper/PlatformMapper.xml +++ b/src/main/resources/mapper/PlatformMapper.xml @@ -26,5 +26,8 @@ <include refid="Base_Column_List"/> from platform where domain = #{domain} + <if test="null != platformName and '' != platformName"> + and platform_name =#{platformName} + </if> </select> </mapper> diff --git a/src/main/resources/mapper/keywordMapper.xml b/src/main/resources/mapper/keywordMapper.xml index 83e3444..64a7496 100644 --- a/src/main/resources/mapper/keywordMapper.xml +++ b/src/main/resources/mapper/keywordMapper.xml @@ -50,7 +50,6 @@ p.platform_name ORDER BY total_repetitions DESC - LIMIT 30 </select> <select id="getResultByTypeId" resultType="com.linghu.model.vo.PlatformProportionVO"> SELECT @@ -123,4 +122,16 @@ ORDER BY r.repetition_num DESC </select> + <select id="getTypeIds" resultType="java.lang.Integer"> + SELECT DISTINCT t.type_id -- 使用 DISTINCT 去重,确保每个 type_id 只出现一次 + FROM reference r + JOIN platform p ON r.platform_id = p.platform_id + JOIN type t ON p.type_id = t.type_id + WHERE r.keyword_id = #{keywordId} + <if test="questionId != null"> + AND r.question_id = #{questionId} + </if> + AND r.num = #{num} + ORDER BY t.type_id -- 按 type_id 排序,结果更规范 + </select> </mapper> -- Gitblit v1.7.1