| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.linghu.listener.PlatformExcelListener; |
| | | import com.linghu.listener.TypeDropdownWriteHandler; |
| | | import com.linghu.mapper.KeywordMapper; |
| | | import com.linghu.mapper.ReferenceMapper; |
| | | import com.linghu.model.common.ResponseResult; |
| | | import com.linghu.model.entity.Platform; |
| | | import com.linghu.model.entity.Reference; |
| | | import com.linghu.model.entity.Sectionalization; |
| | | import com.linghu.model.entity.Type; |
| | | import com.linghu.model.entity.*; |
| | | import com.linghu.model.excel.ExcelDataWithRow; |
| | | import com.linghu.model.excel.PlatformExcel; |
| | | import com.linghu.model.excel.UserExcel; |
| | |
| | | private TypeService typeService; |
| | | @Autowired |
| | | private ReferenceMapper referenceMapper; |
| | | @Autowired |
| | | private KeywordMapper keywordMapper; |
| | | |
| | | @PostMapping |
| | | @ApiOperation(value = "添加平台") |
| | |
| | | @ApiOperation(value = "删除平台") |
| | | public ResponseResult<Void> delete(@PathVariable Integer platformId) { |
| | | //平台被引用了没 |
| | | Integer count = referenceMapper.selectCount(new LambdaQueryWrapper<Reference>().eq(Reference::getPlatform_id, platformId)); |
| | | Integer count = Math.toIntExact(referenceMapper.selectCount(new LambdaQueryWrapper<Reference>().eq(Reference::getPlatform_id, platformId))); |
| | | if (count > 0) { |
| | | return ResponseResult.error("该平台被引用中,不能删除"); |
| | | } |
| | |
| | | @GetMapping("/list") |
| | | @ApiOperation("查询平台列表,不传页数和大小就查全部") |
| | | public ResponseResult<CustomPage<Platform>> list( |
| | | @RequestParam(required = false) Integer page, |
| | | @RequestParam(required = false) Integer pageSize, |
| | | @RequestParam(required = false) Integer type_id) { |
| | | @RequestParam(value = "page",required = false) Integer page, |
| | | @RequestParam(value = "pageSize",required = false) Integer pageSize, |
| | | @RequestParam(value = "type_id",required = false) Integer type_id, |
| | | @RequestParam(value = "keywordId", required = false) Integer keywordId, |
| | | @RequestParam(value = "questionId",required = false) Integer questionId, |
| | | @RequestParam(value = "isNow",required = false) Integer isNow |
| | | ) { |
| | | List<Integer> platForm=new ArrayList<>(); |
| | | //先查找当前关键词下,所有的回答 的 所有的平台名称 |
| | | Keyword keyword=new Keyword(); |
| | | if (keywordId!=null){ |
| | | keyword = keywordMapper.selectById(keywordId); |
| | | } |
| | | |
| | | if (keywordId != null && questionId == null) { |
| | | |
| | | List<Reference> references = referenceMapper.selectList(new LambdaQueryWrapper<Reference>() |
| | | .eq(Reference::getKeyword_id, keywordId) |
| | | .eq(Reference::getNum, isNow== 0 ? 1 : keyword.getNum()) |
| | | ); |
| | | platForm = references.stream().map(Reference::getPlatform_id).filter(Objects::nonNull).distinct().collect(Collectors.toList()); |
| | | } |
| | | if (keywordId != null && questionId != null) { |
| | | List<Reference> references = referenceMapper.selectList(new LambdaQueryWrapper<Reference>() |
| | | .eq(Reference::getKeyword_id, keywordId) |
| | | .eq(Reference::getNum, isNow== 0 ? 1 : keyword.getNum()) |
| | | .eq(Reference::getQuestion_id, questionId) |
| | | ); |
| | | platForm = references.stream().map(Reference::getPlatform_id).filter(Objects::nonNull).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | // 构建查询条件并添加排序(按创建时间倒序) |
| | | LambdaQueryWrapper<Platform> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.orderByDesc(Platform::getCreate_time); // 新增的排序条件 |
| | | if (!platForm.isEmpty()){ |
| | | queryWrapper.in(Platform::getPlatform_id, platForm); |
| | | }else { |
| | | if (page != null && pageSize != null){ |
| | | Page<Platform> pageInfo = new Page<>(page, pageSize); |
| | | Page<Platform> result = platformService.page(pageInfo, queryWrapper); |
| | | return ResponseResult.success(new CustomPage<>(result)); |
| | | }else { |
| | | CustomPage<Platform> customPage = new CustomPage<>(new Page<>()); |
| | | customPage.setRecords(new ArrayList<>()); |
| | | customPage.setTotal(0); |
| | | return ResponseResult.success(customPage); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (type_id != null) { |
| | | queryWrapper.eq(Platform::getType_id, type_id); |
| | | } |
| | | queryWrapper.orderByDesc(Platform::getCreate_time); // 新增的排序条件 |
| | | if (page != null && pageSize != null) { |
| | | Page<Platform> pageInfo = new Page<>(page, pageSize); |
| | | Page<Platform> result = platformService.page(pageInfo, queryWrapper); |