| | |
| | | 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; |
| | |
| | | |
| | | 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; |
| | |
| | | */ |
| | | @GetMapping("/getResultByTypeId") |
| | | @ApiOperation(value = "根据类别查看") |
| | | public ResponseResult<List<PlatformProportionVO>> getResultByTypeId(@RequestParam("id") Integer keywordId, |
| | | public ResponseResult<ResultByTypeIdVO> getResultByTypeId(@RequestParam("keywordId") Integer keywordId, |
| | | @RequestParam(value = "questionId", required = false) Integer questionId, |
| | | @RequestParam(value = "typeId", required = false) Integer typeId) { |
| | | return keywordService.getResultByTypeId(keywordId, questionId, 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @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) { |
| | |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 查看详情 |
| | | */ |
| | | @GetMapping("/getResultById") |
| | | @ApiOperation(value = "根据平台查看") |
| | | @ApiOperation(value = "查看") |
| | | public ResponseResult getResultById(@RequestParam("referenceId") Integer referenceId) { |
| | | Reference reference = referenceService.getById(referenceId); |
| | | if (reference == null) { |
| | |
| | | } |
| | | 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()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量新增关键词 |