| | |
| | | <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> |
| | |
| | | * @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; |
| | | } |
| | |
| | | // 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()); // 补充创建时间 |
| | | |
| | |
| | | } 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); |
| | |
| | | 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()); |
| | |
| | | } |
| | | */ |
| | | // 关键:使用优化后的方法获取平台,避免重复创建 |
| | | 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,更可靠 |
| | | // 添加到结果列表 |
| | |
| | | @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); |
| | |
| | | List<String> typeNameList = result.stream() |
| | | .map(PlatformProportionVO::getType_name) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 3. 导出Excel |
| | |
| | | // 定义日期格式化器 |
| | | 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 { |
| | |
| | | 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; |
| | |
| | | private TypeService typeService; |
| | | @Autowired |
| | | private ReferenceMapper referenceMapper; |
| | | @Autowired |
| | | private KeywordMapper keywordMapper; |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加平台") |
| | |
| | | @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); |
| | |
| | | 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; |
| | |
| | | private QuestionService questionService; |
| | | @Autowired |
| | | private KeywordService keywordService; |
| | | @Autowired |
| | | private KeywordMapper keywordMapper; |
| | | @Autowired |
| | | private ReferenceMapper referenceMapper; |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加提问词") |
| | |
| | | |
| | | } |
| | | |
| | | @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("下载模板") |
| | |
| | | |
| | | 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 = "添加类型") |
| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | import com.linghu.model.entity.Platform; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | /** |
| | | * @author xy |
| | |
| | | * @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); |
| | | |
| | | } |
| | |
| | | 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; |
| | |
| | | private String title; |
| | | private String url; |
| | | private String domain; |
| | | @JsonFormat(pattern = "yyyy/MM/dd") |
| | | private LocalDate publish_time; |
| | | private String platform_name; |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | @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; |
| | | |
| | | /** |
| | |
| | | private Integer reference_id; |
| | | |
| | | @ApiModelProperty("平台名称") |
| | | @ExcelProperty("平台名称") |
| | | private String platform_name; |
| | | |
| | | @ApiModelProperty("标题") |
| | |
| | | * @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); |
| | | } |
| | |
| | | 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); |
| | | } |
| | |
| | | @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); |
| | | |
| | | } |
| | | } |
| | |
| | | <include refid="Base_Column_List"/> |
| | | from platform |
| | | where domain = #{domain} |
| | | <if test="null != platformName and '' != platformName"> |
| | | and platform_name =#{platformName} |
| | | </if> |
| | | </select> |
| | | </mapper> |
| | |
| | | p.platform_name |
| | | ORDER BY |
| | | total_repetitions DESC |
| | | LIMIT 30 |
| | | </select> |
| | | <select id="getResultByTypeId" resultType="com.linghu.model.vo.PlatformProportionVO"> |
| | | SELECT |
| | |
| | | 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> |