| | |
| | | )); |
| | | |
| | | //time |
| | | Map<LocalDateTime, FeedExportExcel> timeMap = references.stream() |
| | | // 定义日期格式化器 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | Map<String, FeedExportExcel> timeMap = references.stream() |
| | | .collect(Collectors.toMap( |
| | | FeedExportExcel::getCreate_time, // Key映射 |
| | | excel -> excel.getCreate_time().format(formatter), |
| | | |
| | | excel -> excel, // Value映射 |
| | | (oldValue, newValue) -> oldValue // 键冲突处理(保留旧值) |
| | | )); |
| | |
| | | errorMessages.add("发布网址不能为空"); |
| | | continue; |
| | | } |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime dateTime = LocalDateTime.parse(excel.getCreate_time(), formatter); |
| | | excel.setCreateTimeAsDateTime(dateTime); |
| | | FeedExportExcel feedExportExcel = getFeedExportExcel(excel, nameMap, urlMap, titleMap, timeMap); |
| | | result.add(feedExportExcel); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | private FeedExportExcel getFeedExportExcel(ReferenceExcel excel, Map<String, FeedExportExcel> nameMap, Map<String, FeedExportExcel> urlMap, Map<String, FeedExportExcel> titleMap, Map<LocalDateTime, FeedExportExcel> timeMap) { |
| | | private FeedExportExcel getFeedExportExcel(ReferenceExcel excel, Map<String, FeedExportExcel> nameMap, Map<String, FeedExportExcel> urlMap, Map<String, FeedExportExcel> titleMap, Map<String, FeedExportExcel> timeMap) { |
| | | FeedExportExcel vo=new FeedExportExcel(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | excel.setTimeString(excel.getCreate_time().format(formatter)); |
| | | vo.setPlatform_name(excel.getPlatform_name()); |
| | | vo.setTitle(excel.getTitle()); |
| | | vo.setCreate_time(excel.getCreateTimeAsDateTime()); |
| | | vo.setCreate_time(excel.getCreate_time()); |
| | | vo.setUrl(excel.getUrl()); |
| | | vo.setInclusionStatus("未收录"); |
| | | vo.setInclusionStatus("未选择"); |
| | | vo.setPlatformIs(0); |
| | | vo.setTitleIs(0); |
| | | vo.setUrlIs(0); |
| | |
| | | if (titleMap.containsKey(excel.getTitle())) { |
| | | vo.setTitleIs(1); |
| | | } |
| | | if (timeMap.containsKey(excel.getCreateTimeAsDateTime())) { |
| | | if (timeMap.containsKey(excel.getTimeString())) { |
| | | vo.setCreateIs(1); |
| | | } |
| | | return vo; |
| | |
| | | if (titleMap.containsKey(excel.getTitle())) { |
| | | vo.setTitleIs(1); |
| | | } |
| | | if (timeMap.containsKey(excel.getCreateTimeAsDateTime())) { |
| | | if (timeMap.containsKey(excel.getTimeString())) { |
| | | vo.setCreateIs(1); |
| | | } |
| | | return vo; |
| | |
| | | //标题 |
| | | if (titleMap.containsKey(excel.getTitle())) { |
| | | vo.setTitleIs(1); |
| | | if (timeMap.containsKey(excel.getCreateTimeAsDateTime())) { |
| | | if (timeMap.containsKey(excel.getTimeString())) { |
| | | vo.setCreateIs(1); |
| | | } |
| | | } |
| | | //时间 |
| | | if (timeMap.containsKey(excel.getCreateTimeAsDateTime())) { |
| | | if (timeMap.containsKey(excel.getTimeString())) { |
| | | vo.setCreateIs(1); |
| | | return vo; |
| | | } |
| | |
| | | public ResponseEntity<byte[]> exportGetResultByPlatformId(@RequestBody ExportFeedDTO dto) { |
| | | // 3. 导出Excel |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | EasyExcel.write(out, FeedExportExcel.class) |
| | | .sheet("导出投喂结果") |
| | | .doWrite(dto.getExcels()); |
| | | List<String> statusList = new ArrayList<>(); |
| | | statusList.add("未收录"); |
| | | statusList.add("已收录"); |
| | | statusList.add("未选择"); |
| | | // 3. 使用自定义的SheetWriteHandler来添加数据验证 |
| | | ExcelWriter excelWriter = EasyExcel.write(out, FeedExportExcel.class) |
| | | .registerWriteHandler(new SheetWriteHandler() { |
| | | @Override |
| | | public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, |
| | | WriteSheetHolder writeSheetHolder) { |
| | | Sheet sheet = writeSheetHolder.getSheet(); |
| | | |
| | | // 添加数据验证(下拉框) |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | CellRangeAddressList rangeList = new CellRangeAddressList( |
| | | 1, 65535, 2, 2); // D列(第4列) |
| | | |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint( |
| | | statusList.toArray(new String[0])); |
| | | DataValidation validation = helper.createValidation(constraint, rangeList); |
| | | sheet.addValidationData(validation); |
| | | } |
| | | }) |
| | | .build(); |
| | | |
| | | // 4. 写入空数据 |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("账号模板").build(); |
| | | excelWriter.write(dto.getExcels(), writeSheet); |
| | | excelWriter.finish(); |
| | | |
| | | // 4. 构建响应 |
| | | return ResponseEntity.ok() |
| | |
| | | @PostMapping("/updateKeyword") |
| | | @ApiOperation(value = "修改关键词") |
| | | public ResponseResult<String> updateKeyword(@RequestBody Keyword keyword) { |
| | | if(!"notSubmitted".equals(keyword.getStatus())){ |
| | | return ResponseResult.error("关键词已开始采集或采集完成不允许修改!"); |
| | | if("submitted".equals(keyword.getStatus())){ |
| | | return ResponseResult.error("关键词已开始采集不允许修改!"); |
| | | } |
| | | keywordService.updateById(keyword); |
| | | return ResponseResult.success("修改成功"); |
| | |
| | | @ApiOperation(value = "删除关键词") |
| | | public ResponseResult<String> deleteKeyword(@RequestParam("keywordId") Integer keywordId) { |
| | | Keyword keyword = keywordService.getById(keywordId); |
| | | if(!"notSubmitted".equals(keyword.getStatus())){ |
| | | return ResponseResult.error("关键词已开始采集或采集完成不允许删除!"); |
| | | if("submitted".equals(keyword.getStatus())){ |
| | | return ResponseResult.error("关键词已开始采集或不允许删除!"); |
| | | } |
| | | keywordService.removeById(keywordId); |
| | | return ResponseResult.success("删除成功"); |