| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | |
| | | @ApiOperation(value = "EChart图") |
| | | public ResponseResult<KeywordStaticsListVO> statics(@RequestParam("id") Integer keywordId, |
| | | @RequestParam(value = "questionId", required = false) Integer questionId) { |
| | | // |
| | | return keywordService.statics(keywordId, questionId); |
| | | } |
| | | |
| | | @GetMapping("/getTime") |
| | | @ApiOperation(value = "查看时间") |
| | | public ResponseResult<GetTimeVO> getTime(@RequestParam("id") Integer keywordId,@RequestParam(value = "questionId", required = false) Integer questionId) { |
| | | // |
| | | GetTimeVO vo = new GetTimeVO(); |
| | | Keyword keyword = keywordService.getById(keywordId); |
| | | |
| | | LambdaQueryWrapper<Reference> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Reference::getKeyword_id, keywordId); |
| | | if (questionId != null) { |
| | | queryWrapper.eq(Reference::getQuestion_id, questionId); |
| | | } |
| | | queryWrapper.eq(Reference::getNum,keyword.getNum()); |
| | | |
| | | List<Reference> list = referenceService.list(queryWrapper); |
| | | if (null != list && !list.isEmpty()) { |
| | | vo.setNow(list.get(0).getCreate_time()); |
| | | } |
| | | //首次 |
| | | LambdaQueryWrapper<Reference> queryWrapper2 = new LambdaQueryWrapper<>(); |
| | | queryWrapper2.eq(Reference::getKeyword_id, keywordId); |
| | | if (questionId != null) { |
| | | queryWrapper2.eq(Reference::getQuestion_id, questionId); |
| | | } |
| | | queryWrapper2.eq(Reference::getNum,1); |
| | | |
| | | List<Reference> list2 = referenceService.list(queryWrapper2); |
| | | if (null != list2 && !list2.isEmpty()) { |
| | | vo.setFirst(list2.get(0).getCreate_time()); |
| | | } |
| | | |
| | | return ResponseResult.success(vo); |
| | | } |
| | | |
| | | |
| | | @PostMapping(value = "/exportStatics") |
| | | @ApiOperation(value = "EChart图导出") |
| | | public ResponseEntity<byte[]> exportStatics(@RequestBody ExportStaticsDTO exportStaticsDTO) { |
| | | |
| | | Keyword keyword = keywordMapper.selectById(exportStaticsDTO.getKeywordId()); |
| | | List<KeywordStaticsVO> voList = keywordMapper.statics(exportStaticsDTO.getKeywordId(), exportStaticsDTO.getQuestionId(), keyword.getNum()); |
| | | List<KeywordStaticsVO> voList=new ArrayList<>(); |
| | | if (exportStaticsDTO.getIsFirst()==0){ |
| | | voList = keywordMapper.statics(exportStaticsDTO.getKeywordId(), exportStaticsDTO.getQuestionId(), keyword.getNum()); |
| | | |
| | | }else { |
| | | voList = keywordMapper.statics(exportStaticsDTO.getKeywordId(), exportStaticsDTO.getQuestionId(), 1); |
| | | |
| | | } |
| | | |
| | | // 3. 导出Excel |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | |
| | | if (isNow == 0) { |
| | | List<PlatformProportionVO> result = keywordMapper.getResultByTypeId(keywordId, questionId, |
| | | keyword.getNum() , typeId); |
| | | // 检查列表是否为空或只包含null元素 |
| | | boolean isValid = result != null && result.stream() |
| | | .anyMatch(Objects::nonNull); |
| | | |
| | | return ResponseResult.success(result); |
| | | } |
| | | if (isNow > 0 && keyword.getNum()>isNow){ |
| | | List<PlatformProportionVO> result = keywordMapper.getResultByTypeId(keywordId, questionId, |
| | | keyword.getNum() - isNow, typeId); |
| | | |
| | | return ResponseResult.success(result); |
| | | return isValid ? ResponseResult.success(result) |
| | | : ResponseResult.success(new ArrayList<>()); |
| | | }else { |
| | | return ResponseResult.success(new ArrayList<>()); |
| | | List<PlatformProportionVO> result = keywordMapper.getResultByTypeId(keywordId, questionId, 1, typeId); |
| | | boolean isValid = result != null && result.stream() |
| | | .anyMatch(Objects::nonNull); |
| | | |
| | | return isValid ? ResponseResult.success(result) |
| | | : ResponseResult.success(new ArrayList<>()); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | @ApiOperation(value = "导出:根据类别查看") |
| | | public ResponseEntity<byte[]> exportGetResultByTypeId(@RequestBody ExportGetResultDTO dto) { |
| | | Keyword keyword = keywordService.getById(dto.getKeywordId()); |
| | | List<PlatformProportionVO> result = keywordMapper.getResultByTypeId(dto.getKeywordId(), dto.getQuestionId(), |
| | | keyword.getNum() - dto.getIsNow(), dto.getTypeId()); |
| | | List<PlatformProportionVO> result =new ArrayList<>(); |
| | | |
| | | if (dto.getIsNow()==0){ |
| | | result = keywordMapper.getResultByTypeId(dto.getKeywordId(), dto.getQuestionId(), |
| | | keyword.getNum() , dto.getTypeId()); |
| | | }else { |
| | | result = keywordMapper.getResultByTypeId(dto.getKeywordId(), dto.getQuestionId(), |
| | | 1 , dto.getTypeId()); |
| | | } |
| | | |
| | | |
| | | |
| | | // 3. 导出Excel |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | EasyExcel.write(out, PlatformProportionVO.class) |
| | |
| | | @RequestParam(value = "platformId", required = false) Integer platformId, |
| | | @RequestParam(value = "isNow") Integer isNow) { |
| | | Keyword keyword = keywordService.getById(keywordId); |
| | | if (isNow==0){ |
| | | if (isNow == 0) { |
| | | List<ResultListVO> result = keywordMapper.getResultByPlatformId(keywordId, questionId, keyword.getNum(), |
| | | platformId); |
| | | return ResponseResult.success(result); |
| | | } |
| | | if (isNow > 0 && keyword.getNum()>isNow){ |
| | | List<ResultListVO> result = keywordMapper.getResultByPlatformId(keywordId, questionId, keyword.getNum() - isNow, |
| | | platformId); |
| | | boolean isValid = result != null && result.stream() |
| | | .anyMatch(Objects::nonNull); |
| | | |
| | | return ResponseResult.success(result); |
| | | }else { |
| | | return ResponseResult.success(new ArrayList<>()); |
| | | return isValid ? ResponseResult.success(result) |
| | | : ResponseResult.success(new ArrayList<>()); |
| | | } else { |
| | | List<ResultListVO> result = keywordMapper.getResultByPlatformId(keywordId, questionId, 1, |
| | | platformId); |
| | | boolean isValid = result != null && result.stream() |
| | | .anyMatch(Objects::nonNull); |
| | | |
| | | return isValid ? ResponseResult.success(result) |
| | | : ResponseResult.success(new ArrayList<>()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | @ApiOperation(value = "导出:根据平台查看") |
| | | public ResponseEntity<byte[]> exportGetResultByPlatformId(@RequestBody ExportGetResultByPlatformIdDTO dto) { |
| | | Keyword keyword = keywordService.getById(dto.getKeywordId()); |
| | | List<ResultListVO> result = keywordMapper.getResultByPlatformId(dto.getKeywordId(), dto.getQuestionId(), keyword.getNum() - dto.getIsNow(), |
| | | dto.getPlatformId()); |
| | | List<ResultListVO> result=new ArrayList<>(); |
| | | if (dto.getIsNow()==0){ |
| | | result = keywordMapper.getResultByPlatformId(dto.getKeywordId(), dto.getQuestionId(), keyword.getNum(), |
| | | dto.getPlatformId()); |
| | | }else { |
| | | result = keywordMapper.getResultByPlatformId(dto.getKeywordId(), dto.getQuestionId(), 1, |
| | | dto.getPlatformId()); |
| | | } |
| | | // 3. 导出Excel |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | EasyExcel.write(out, ResultListVO.class) |
| | |
| | | @PostMapping("/updateKeyword") |
| | | @ApiOperation(value = "修改关键词") |
| | | public ResponseResult<String> updateKeyword(@RequestBody Keyword keyword) { |
| | | if(!"notSubmitted".equals(keyword.getStatus())){ |
| | | return ResponseResult.error("关键词已开始采集或采集完成不允许修改!"); |
| | | } |
| | | keywordService.updateById(keyword); |
| | | return ResponseResult.success("修改成功"); |
| | | } |
| | |
| | | @DeleteMapping("/deleteKeyword") |
| | | @ApiOperation(value = "删除关键词") |
| | | public ResponseResult<String> deleteKeyword(@RequestParam("keywordId") Integer keywordId) { |
| | | Keyword keyword = keywordService.getById(keywordId); |
| | | if(!"notSubmitted".equals(keyword.getStatus())){ |
| | | return ResponseResult.error("关键词已开始采集或采集完成不允许删除!"); |
| | | } |
| | | keywordService.removeById(keywordId); |
| | | return ResponseResult.success("删除成功"); |
| | | } |
| | |
| | | return ResponseResult.error("导入失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | //根据关键词id查询任务id |
| | | |
| | | |
| | | } |