From b36ba9d3da79245376f5a8a1c31cddb1f9a6d1b5 Mon Sep 17 00:00:00 2001 From: huliguo <2023611923@qq.com> Date: 星期三, 09 七月 2025 09:12:55 +0800 Subject: [PATCH] 采集详情 --- src/main/java/com/linghu/model/excel/FeedExportExcel.java | 43 ++++++++ src/main/java/com/linghu/model/excel/ReferenceExcel.java | 23 ++++ src/main/java/com/linghu/model/vo/ResultByTypeIdVO.java | 14 ++ src/main/java/com/linghu/config/MybatisPlusConfig.java | 24 ++++ src/main/java/com/linghu/model/dto/ExportFeedDTO.java | 13 ++ pom.xml | 1 src/main/java/com/linghu/controller/KeywordController.java | 135 +++++++++++++++++++++++++- src/main/java/com/linghu/model/vo/ResultByPlatformVO.java | 14 ++ 8 files changed, 259 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1e8b972..f61e73e 100644 --- a/pom.xml +++ b/pom.xml @@ -99,6 +99,7 @@ <artifactId>jackson-databind</artifactId> <version>2.15.2</version> </dependency> + <dependency> <groupId>com.opencrypt</groupId> <artifactId>open-crypt</artifactId> diff --git a/src/main/java/com/linghu/config/MybatisPlusConfig.java b/src/main/java/com/linghu/config/MybatisPlusConfig.java new file mode 100644 index 0000000..2b9dfdf --- /dev/null +++ b/src/main/java/com/linghu/config/MybatisPlusConfig.java @@ -0,0 +1,24 @@ +package com.linghu.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan("com.linghu.mapper") +public class MybatisPlusConfig { + + /** + * 添加分页插件 + */ + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加 + // 如果有多数据源可以不配具体类型, 否则都建议配上具体的 DbType + return interceptor; + } +} \ No newline at end of file diff --git a/src/main/java/com/linghu/controller/KeywordController.java b/src/main/java/com/linghu/controller/KeywordController.java index 38c5b7b..d875871 100644 --- a/src/main/java/com/linghu/controller/KeywordController.java +++ b/src/main/java/com/linghu/controller/KeywordController.java @@ -6,9 +6,16 @@ import com.linghu.listener.KeywordExcelListener; import com.linghu.mapper.KeywordMapper; import com.linghu.model.common.ResponseResult; +import com.linghu.model.dto.ExportFeedDTO; import com.linghu.model.entity.Keyword; +import com.linghu.model.entity.Platform; import com.linghu.model.entity.Reference; +import com.linghu.model.entity.Type; +import com.linghu.model.excel.FeedExportExcel; +import com.linghu.model.excel.PlatformExcel; +import com.linghu.model.excel.ReferenceExcel; +import com.linghu.model.vo.*; import com.linghu.model.excel.KeywordExcel; import com.linghu.model.excel.PlatformExcel; import com.linghu.model.vo.KeywordStaticsListVO; @@ -29,6 +36,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.time.LocalDateTime; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -81,10 +90,21 @@ */ @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); + public ResponseResult<ResultByTypeIdVO> getResultByTypeId(@RequestParam("keywordId") Integer keywordId, + @RequestParam(value = "questionId", required = false) Integer questionId, + @RequestParam(value = "typeId", required = false) Integer typeId) { + ResultByTypeIdVO vo = new ResultByTypeIdVO(); + Keyword keyword = keywordService.getById(keywordId); + List<PlatformProportionVO> nowList = keywordMapper.getResultByTypeId(keywordId, questionId, + keyword.getNum(), typeId); + vo.setNowList(nowList); + if (keyword.getNum()>1){ + List<PlatformProportionVO> beforeList = keywordMapper.getResultByTypeId(keywordId, questionId, + keyword.getNum()-1, typeId); + vo.setBeforeList(beforeList); + } + + return ResponseResult.success(vo); } /** @@ -92,7 +112,7 @@ */ @PostMapping(value = "/exportGetResultByTypeId") @ApiOperation(value = "导出:根据类别查看") - public ResponseEntity<byte[]> exportGetResultByTypeId(@RequestParam("id") Integer keywordId, + public ResponseEntity<byte[]> exportGetResultByTypeId(@RequestParam("keywordId") Integer keywordId, @RequestParam(value = "questionId", required = false) Integer questionId, @RequestParam(value = "typeId", required = false) Integer typeId, @RequestParam(value = "isNow") Integer isNow) { @@ -117,10 +137,23 @@ */ @GetMapping("/getResultByPlatformId") @ApiOperation(value = "根据平台查看") - public ResponseResult<List<ResultListVO>> getResultByPlatformId(@RequestParam("id") Integer keywordId, + public ResponseResult<ResultByPlatformVO> getResultByPlatformId(@RequestParam("keywordId") Integer keywordId, @RequestParam(value = "questionId", required = false) Integer questionId, @RequestParam(value = "platformId", required = false) Integer platformId) { - return keywordService.getResultByPlatformId(keywordId, questionId, platformId); + ResultByPlatformVO vo = new ResultByPlatformVO(); + Keyword keyword = keywordService.getById(keywordId); + + List<ResultListVO> nowList = keywordMapper.getResultByPlatformId(keywordId, questionId, keyword.getNum(), + platformId); + vo.setNowList(nowList); + + if (keyword.getNum()>1){ + List<ResultListVO> beforeList = keywordMapper.getResultByPlatformId(keywordId, questionId, keyword.getNum()-1, + platformId); + vo.setBeforeList(beforeList); + } + + return ResponseResult.success(vo); } /** @@ -152,7 +185,7 @@ * 查看详情 */ @GetMapping("/getResultById") - @ApiOperation(value = "根据平台查看") + @ApiOperation(value = "查看") public ResponseResult getResultById(@RequestParam("referenceId") Integer referenceId) { Reference reference = referenceService.getById(referenceId); if (reference == null) { @@ -160,10 +193,96 @@ } return ResponseResult.success(reference); } + /** + * 下载模版 + */ + @GetMapping("/download") + @ApiOperation("下载投喂模板") + public ResponseEntity<byte[]> downTemplate() throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + EasyExcel.write(out, ReferenceExcel.class).sheet("投喂模板").doWrite(new ArrayList<>()); + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=platform_template.xlsx") + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(out.toByteArray()); + } /** * 投喂 */ + @PostMapping("/importFeed") + @ApiOperation("投喂") + public ResponseResult<List<FeedExportExcel>> importTemplate(@RequestParam("file") MultipartFile file) { + try { + // 检查文件是否为空 + if (file.isEmpty()) { + return ResponseResult.error("上传文件不能为空"); + } + + // 读取Excel数据 + List<ReferenceExcel> excelList = EasyExcel.read(file.getInputStream()) + .head(ReferenceExcel.class) + .sheet() + .doReadSync(); + + // 数据转换与验证 + List<String> errorMessages = new ArrayList<>(); + List<FeedExportExcel> result = new ArrayList<>(); + for (ReferenceExcel excel : excelList) { + // 检查必要字段 + if (!StringUtils.hasText(excel.getPlatform_name())) { + errorMessages.add("平台名称不能为空"); + continue; + } + if (!StringUtils.hasText(excel.getTitle())) { + errorMessages.add("标题不能为空"); + continue; + } + if (!StringUtils.hasText(String.valueOf(excel.getCreate_time()))) { + errorMessages.add("发布时间不能为空"); + continue; + } + if (!StringUtils.hasText(excel.getUrl())) { + errorMessages.add("发布网址不能为空"); + continue; + } + //todo 查询出当前这次的结果 做出对比 + + } + + // 处理错误 + if (!errorMessages.isEmpty()) { + return ResponseResult.error("数据验证失败: " + String.join("; ", errorMessages)); + } + + // 返回信息 + return ResponseResult.success(result); + } catch (Exception e) { + // 记录详细异常信息 + + return ResponseResult.error("文件解析失败:" + e.getMessage()); + } + } + + /** + * 导出投喂结果 + */ + @PostMapping("/exportFeed") + @ApiOperation(value = "导出投喂结果") + public ResponseEntity<byte[]> exportGetResultByPlatformId(@RequestBody ExportFeedDTO dto) { + // 3. 导出Excel + ByteArrayOutputStream out = new ByteArrayOutputStream(); + EasyExcel.write(out, FeedExportExcel.class) + .sheet("导出投喂结果") + .doWrite(dto.getExcels()); + + // 4. 构建响应 + return ResponseEntity.ok() + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=references_export.xlsx") + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(out.toByteArray()); + } + /** * 批量新增关键词 diff --git a/src/main/java/com/linghu/model/dto/ExportFeedDTO.java b/src/main/java/com/linghu/model/dto/ExportFeedDTO.java new file mode 100644 index 0000000..cc1006f --- /dev/null +++ b/src/main/java/com/linghu/model/dto/ExportFeedDTO.java @@ -0,0 +1,13 @@ +package com.linghu.model.dto; + +import com.linghu.model.excel.FeedExportExcel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ExportFeedDTO { + @ApiModelProperty("投喂结果") + private List<FeedExportExcel> excels; +} diff --git a/src/main/java/com/linghu/model/excel/FeedExportExcel.java b/src/main/java/com/linghu/model/excel/FeedExportExcel.java new file mode 100644 index 0000000..44d510c --- /dev/null +++ b/src/main/java/com/linghu/model/excel/FeedExportExcel.java @@ -0,0 +1,43 @@ +package com.linghu.model.excel; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class FeedExportExcel { + @ExcelProperty("平台名称") + @ApiModelProperty("平台名称") + private String platform_name; + @ApiModelProperty("平台是否匹配 0-否 1-是") + private Integer platformIs; + + @ExcelProperty("标题") + @ApiModelProperty("标题") + private String title; + @ApiModelProperty("标题是否匹配 0-否 1-是") + private Integer titleIs; + + + @ExcelProperty("发布时间") + @ApiModelProperty("发布时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime create_time; + + @ApiModelProperty("发布时间是否匹配 0-否 1-是") + private Integer createIs; + + @ExcelProperty("发布网址") + @ApiModelProperty("发布网址") + private String url; + @ApiModelProperty("发布网址是否匹配 0-否 1-是") + private Integer urlIs; + + @ExcelProperty("收录情况") + @ApiModelProperty("收录情况") + private String inclusionStatus; + +} diff --git a/src/main/java/com/linghu/model/excel/ReferenceExcel.java b/src/main/java/com/linghu/model/excel/ReferenceExcel.java new file mode 100644 index 0000000..f86141f --- /dev/null +++ b/src/main/java/com/linghu/model/excel/ReferenceExcel.java @@ -0,0 +1,23 @@ +package com.linghu.model.excel; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class ReferenceExcel { + @ExcelProperty("平台名称") + private String platform_name; + + @ExcelProperty("标题") + private String title; + @ExcelProperty("发布时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime create_time; + + @ExcelProperty("发布网址") + private String url; + +} \ No newline at end of file diff --git a/src/main/java/com/linghu/model/vo/ResultByPlatformVO.java b/src/main/java/com/linghu/model/vo/ResultByPlatformVO.java new file mode 100644 index 0000000..37c308c --- /dev/null +++ b/src/main/java/com/linghu/model/vo/ResultByPlatformVO.java @@ -0,0 +1,14 @@ +package com.linghu.model.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ResultByPlatformVO { + @ApiModelProperty("当前次结果查询") + private List<ResultListVO> nowList; + @ApiModelProperty("后一次结果查询") + private List<ResultListVO> beforeList; +} diff --git a/src/main/java/com/linghu/model/vo/ResultByTypeIdVO.java b/src/main/java/com/linghu/model/vo/ResultByTypeIdVO.java new file mode 100644 index 0000000..4f907ab --- /dev/null +++ b/src/main/java/com/linghu/model/vo/ResultByTypeIdVO.java @@ -0,0 +1,14 @@ +package com.linghu.model.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ResultByTypeIdVO { + @ApiModelProperty("当前次结果查询") + private List<PlatformProportionVO> nowList; + @ApiModelProperty("后一次结果查询") + private List<PlatformProportionVO> beforeList; +} -- Gitblit v1.7.1