src/main/java/com/linghu/controller/KeywordController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/controller/OrderController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/controller/QuestionController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/mapper/KeywordMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/model/vo/KeywordStaticsListVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/model/vo/KeywordStaticsVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/model/vo/PlatformProportionVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/model/vo/ResultListVO.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/service/KeywordService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/linghu/service/impl/KeywordServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/keywordMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/linghu/controller/KeywordController.java
New file @@ -0,0 +1,149 @@ package com.linghu.controller; import com.alibaba.excel.EasyExcel; import com.linghu.mapper.KeywordMapper; import com.linghu.model.common.ResponseResult; import com.linghu.model.entity.Keyword; import com.linghu.model.entity.Reference; import com.linghu.model.vo.KeywordStaticsListVO; import com.linghu.model.vo.KeywordStaticsVO; import com.linghu.model.vo.PlatformProportionVO; import com.linghu.model.vo.ResultListVO; import com.linghu.service.KeywordService; import com.linghu.service.ReferenceService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayOutputStream; import java.util.List; @RestController @RequestMapping("/keyword") @Api(value = "采集详情相关接口", tags = "订单列表-采集列表-采集详情") public class KeywordController { @Autowired private KeywordService keywordService; @Autowired private KeywordMapper keywordMapper; @Autowired private ReferenceService referenceService; /** * 关键词统计 EChart图 */ @GetMapping("/statics") @ApiOperation(value = "EChart图") public ResponseResult<KeywordStaticsListVO> statics(@RequestParam("id") Integer keywordId, @RequestParam(value = "questionId",required = false) Integer questionId) { return keywordService.statics(keywordId,questionId); } @PostMapping(value = "/exportStatics") @ApiOperation(value = "EChart图导出") public ResponseEntity<byte[]> exportStatics(@RequestParam("id") Integer keywordId, @RequestParam(value = "questionId",required = false) Integer questionId, HttpServletResponse response) { Keyword keyword = keywordMapper.selectById(keywordId); List<KeywordStaticsVO> voList = keywordMapper.statics(keywordId,questionId,keyword.getNum()); // 3. 导出Excel ByteArrayOutputStream out = new ByteArrayOutputStream(); EasyExcel.write(out, KeywordStaticsVO.class) .sheet("引用数据") .doWrite(voList); // 4. 构建响应 return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=references_export.xlsx") .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(out.toByteArray()); } /** * 根据类别查看 */ @GetMapping("/getResultByTypeId") @ApiOperation(value = "根据类别查看") public ResponseResult<List<PlatformProportionVO>> getResultByTypeId(@RequestParam("id") Integer keywordId, @RequestParam(value = "questionId",required = false) Integer questionId, @RequestParam(value = "typeId",required = false) Integer typeId) { return keywordService.getResultByTypeId(keywordId,questionId,typeId); } /** * 导出:根据类别查看 */ @PostMapping(value = "/exportGetResultByTypeId") @ApiOperation(value = "导出:根据类别查看") public ResponseEntity<byte[]> exportGetResultByTypeId(@RequestParam("id") Integer keywordId, @RequestParam(value = "questionId",required = false) Integer questionId, @RequestParam(value = "typeId",required = false) Integer typeId,@RequestParam(value = "isNow") Integer isNow ) { Keyword keyword = keywordService.getById(keywordId); List<PlatformProportionVO> result = keywordMapper.getResultByTypeId(keywordId, questionId, keyword.getNum() - isNow, typeId); // 3. 导出Excel ByteArrayOutputStream out = new ByteArrayOutputStream(); EasyExcel.write(out, PlatformProportionVO.class) .sheet("引用数据") .doWrite(result); // 4. 构建响应 return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=references_export.xlsx") .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(out.toByteArray()); } /** * 根据平台查看 */ @GetMapping("/getResultByPlatformId") @ApiOperation(value = "根据平台查看") public ResponseResult<List<ResultListVO>> getResultByPlatformId(@RequestParam("id") Integer keywordId, @RequestParam(value = "questionId",required = false) Integer questionId, @RequestParam(value = "platformId",required = false) Integer platformId) { return keywordService.getResultByPlatformId(keywordId,questionId,platformId); } /** * 根据平台查看 0-当前轮 1-代表前1轮 2-代表前2轮 */ @GetMapping("/exportGetResultByPlatformId") @ApiOperation(value = "根据平台查看") public ResponseEntity<byte[]> exportGetResultByPlatformId(@RequestParam("id") Integer keywordId, @RequestParam(value = "questionId",required = false) Integer questionId, @RequestParam(value = "platformId",required = false) Integer platformId,@RequestParam(value = "isNow") Integer isNow) { Keyword keyword = keywordService.getById(keywordId); List<ResultListVO> result = keywordMapper.getResultByPlatformId(keywordId, questionId, keyword.getNum() - isNow, platformId); // 3. 导出Excel ByteArrayOutputStream out = new ByteArrayOutputStream(); EasyExcel.write(out, ResultListVO.class) .sheet("引用数据") .doWrite(result); // 4. 构建响应 return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=references_export.xlsx") .contentType(MediaType.APPLICATION_OCTET_STREAM) .body(out.toByteArray()); } /** * 查看详情 */ @GetMapping("/getResultById") @ApiOperation(value = "根据平台查看") public ResponseResult getResultById(@RequestParam("referenceId") Integer referenceId) { Reference reference = referenceService.getById(referenceId); if (reference == null) { return ResponseResult.error("该结果不存在"); } return ResponseResult.success(reference); } /** * 投喂 */ } src/main/java/com/linghu/controller/OrderController.java
@@ -8,6 +8,7 @@ import com.linghu.model.dto.OrderDto; import com.linghu.service.OrderService; import io.swagger.annotations.Api; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -21,6 +22,7 @@ */ @RestController @RequestMapping("/order") @Api(value = "订单管理", tags = "订单管理") public class OrderController { @Autowired src/main/java/com/linghu/controller/QuestionController.java
@@ -18,7 +18,7 @@ @RestController @RequestMapping("/question") @Api(value = "提问词相关接口", tags = "设置-提问词") @Api(value = "提问词相关接口", tags = "订单管理-提问词") public class QuestionController { @Autowired src/main/java/com/linghu/mapper/KeywordMapper.java
@@ -2,6 +2,13 @@ import com.linghu.model.entity.Keyword; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.linghu.model.vo.KeywordStaticsVO; import com.linghu.model.vo.PlatformProportionVO; import com.linghu.model.vo.ResultListVO; import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; /** * @author xy @@ -11,6 +18,11 @@ */ public interface KeywordMapper extends BaseMapper<Keyword> { List<KeywordStaticsVO> statics(@Param("keywordId") Integer keywordId, @Param("questionId")Integer questionId, @Param("num")Integer num); 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); } src/main/java/com/linghu/model/vo/KeywordStaticsListVO.java
New file @@ -0,0 +1,19 @@ package com.linghu.model.vo; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; import java.util.List; @Data @ApiModel("关键词统计") public class KeywordStaticsListVO { @ApiModelProperty("当前统计记录") private List<KeywordStaticsVO> nowRecord; @ApiModelProperty("统计记录-前一次") private List<KeywordStaticsVO> beforeRecord; } src/main/java/com/linghu/model/vo/KeywordStaticsVO.java
New file @@ -0,0 +1,22 @@ package com.linghu.model.vo; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; @Data @ApiModel("关键词统计") public class KeywordStaticsVO { @ApiModelProperty("发布平台") @ExcelProperty("发布平台") private String platformName; @ApiModelProperty("重复次数") @ExcelProperty("重复次数") private Integer totalRepetitions; @ApiModelProperty("平台分布占比") @ExcelProperty("平台分布占比") private BigDecimal repetitionRatio; } src/main/java/com/linghu/model/vo/PlatformProportionVO.java
New file @@ -0,0 +1,36 @@ package com.linghu.model.vo; import com.alibaba.excel.annotation.ExcelProperty; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.math.BigDecimal; @Data @ApiModel("") public class PlatformProportionVO { @ApiModelProperty("类型名称") @ExcelProperty("全部类型") private String typeName; @ApiModelProperty("平台名称") @ExcelProperty("平台名称") private String platformName; @ApiModelProperty("重复次数") @ExcelProperty("重复次数") private Integer totalRepetitions; @ApiModelProperty("全平台分布占比") @ExcelProperty("全平台分布占比") private BigDecimal allPlatformRatio; @ApiModelProperty("同类平台分布占比") @ExcelProperty("同类平台分布占比") private BigDecimal sameTypeRatio; } src/main/java/com/linghu/model/vo/ResultListVO.java
New file @@ -0,0 +1,36 @@ package com.linghu.model.vo; import com.alibaba.excel.annotation.ExcelProperty; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.time.LocalDateTime; @Data @ApiModel public class ResultListVO { @ApiModelProperty("结果id") private Integer referenceId; @ApiModelProperty("平台名称") @ExcelProperty("全部平台") private String platformName; @ApiModelProperty("标题") @ExcelProperty("标题") private String title; @ApiModelProperty("重复次数") @ExcelProperty("重复次数") private Integer repetitionNum; @ApiModelProperty("发布时间") @ExcelProperty("发布时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime createTime; @ExcelProperty("发布网址") private String url; } src/main/java/com/linghu/service/KeywordService.java
@@ -1,7 +1,13 @@ package com.linghu.service; import com.linghu.model.common.ResponseResult; import com.linghu.model.entity.Keyword; import com.baomidou.mybatisplus.extension.service.IService; import com.linghu.model.vo.KeywordStaticsListVO; import com.linghu.model.vo.PlatformProportionVO; import com.linghu.model.vo.ResultListVO; import java.util.List; /** * @author xy @@ -10,4 +16,9 @@ */ public interface KeywordService extends IService<Keyword> { ResponseResult<KeywordStaticsListVO> statics(Integer keywordId, Integer questionId); ResponseResult<List<PlatformProportionVO>> getResultByTypeId(Integer keywordId, Integer questionId, Integer typeId); ResponseResult<List<ResultListVO>> getResultByPlatformId(Integer keywordId, Integer questionId, Integer platformId); } src/main/java/com/linghu/service/impl/KeywordServiceImpl.java
@@ -1,10 +1,16 @@ package com.linghu.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.linghu.model.common.ResponseResult; import com.linghu.model.entity.Keyword; import com.linghu.model.vo.*; import com.linghu.model.vo.KeywordStaticsListVO; import com.linghu.service.KeywordService; import com.linghu.mapper.KeywordMapper; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; /** * @author xy @@ -12,8 +18,57 @@ * @createDate 2025-07-04 20:17:33 */ @Service public class KeywordServiceImpl extends ServiceImpl<KeywordMapper, Keyword> implements KeywordService{ public class KeywordServiceImpl extends ServiceImpl<KeywordMapper, Keyword> implements KeywordService{ @Override public ResponseResult<KeywordStaticsListVO> statics(Integer keywordId, Integer questionId) { KeywordStaticsListVO vo = new KeywordStaticsListVO(); //1.关键词是否存在 Keyword keyword = this.getById(keywordId); if (keyword == null) { return ResponseResult.error("关键词不存在"); } if (!"completed".equals(keyword.getStatus())){ return ResponseResult.error("关键词采集未完成"); } List<KeywordStaticsVO> statics = this.getBaseMapper().statics(keywordId,questionId,keyword.getNum()); vo.setNowRecord(statics); if (keyword.getNum()!=0){ statics = this.getBaseMapper().statics(keywordId,questionId,keyword.getNum()-1); vo.setBeforeRecord(statics); } return ResponseResult.success(vo); } @Override public ResponseResult<List<PlatformProportionVO>> getResultByTypeId(Integer keywordId, Integer questionId, Integer typeId) { //1.关键词是否存在 Keyword keyword = this.getById(keywordId); if (keyword == null) { return ResponseResult.error("关键词不存在"); } if (!"completed".equals(keyword.getStatus())){ return ResponseResult.error("关键词采集未完成"); } List<PlatformProportionVO> result = this.getBaseMapper().getResultByTypeId(keywordId, questionId, keyword.getNum(), typeId); return ResponseResult.success(result); } @Override public ResponseResult<List<ResultListVO>> getResultByPlatformId(Integer keywordId, Integer questionId, Integer platformId) { //1.关键词是否存在 Keyword keyword = this.getById(keywordId); if (keyword == null) { return ResponseResult.error("关键词不存在"); } if (!"completed".equals(keyword.getStatus())){ return ResponseResult.error("关键词采集未完成"); } List<ResultListVO> result = this.getBaseMapper().getResultByPlatformId(keywordId, questionId, keyword.getNum(), platformId); return ResponseResult.success(result); } } src/main/resources/mapper/keywordMapper.xml
@@ -17,4 +17,112 @@ keyword_id,order_id,keyword_name, num,task_id,status </sql> <select id="statics" resultType="com.linghu.model.vo.KeywordStaticsVO"> SELECT p.platform_name, SUM( r.repetition_num ) AS total_repetitions, ROUND( SUM( r.repetition_num ) * 100.0 / ( SELECT SUM( r2.repetition_num ) FROM reference r2 WHERE r2.keyword_id = #{keywordId} <if test = "questionId != null" > AND r2.question_id = #{questionId} </if> AND r2.num = #{num} ),2) AS repetition_ratio FROM reference r JOIN platform p ON r.platform_id = p.platform_id WHERE r.keyword_id = #{keywordId} <if test = "questionId != null" > AND r.question_id = #{questionId} </if> AND r.num = #{num} AND p.del_flag = 0 GROUP BY p.platform_id, p.platform_name ORDER BY total_repetitions DESC </select> <select id="getResultByTypeId" resultType="com.linghu.model.vo.PlatformProportionVO"> SELECT t.type_name, p.platform_name, SUM(r.repetition_num) AS total_repetitions, -- 全平台分布占比 = 当前平台重复次数 / 所有平台重复次数 ROUND(SUM(r.repetition_num) * 100.0 / ( SELECT SUM(r2.repetition_num) FROM reference r2 WHERE r2.keyword_id = #{keywordId} <if test="questionId != null"> AND r2.question_id = #{questionId} </if> AND r2.num = #{num} ), 2) AS all_platform_ratio, -- 同类平台分布占比 = 当前平台重复次数 / 同类型平台重复次数 ROUND(SUM(r.repetition_num) * 100.0 / ( SELECT SUM(r3.repetition_num) FROM reference r3 JOIN platform p3 ON r3.platform_id = p3.platform_id WHERE r3.keyword_id = #{keywordId} <if test="questionId != null"> AND r3.question_id = #{questionId} </if> AND r3.num = #{num} AND p3.type_id = p.type_id ), 2) AS same_type_ratio 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} <if test="typeId != null"> AND p.type_id = #{typeId} </if> AND p.del_flag = 0 AND t.del_flag = 0 GROUP BY t.type_id, t.type_name, p.platform_id, p.platform_name ORDER BY t.type_name, total_repetitions DESC </select> <select id="getResultByPlatformId" resultType="com.linghu.model.vo.ResultListVO"> SELECT r.reference_id, p.platform_name, r.title, r.repetition_num, r.create_time, r.url FROM reference r JOIN platform p ON r.platform_id = p.platform_id WHERE r.keyword_id = #{keywordId} <if test="questionId != null"> AND r.question_id = #{questionId} </if> AND r.num = #{num} <if test="platformId != null"> AND r.platform_id = #{platformId} </if> AND p.del_flag = 0 ORDER BY r.create_time DESC </select> </mapper>