| | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.linghu.listener.QuestionExcelListener; |
| | | import com.linghu.model.common.ResponseResult; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static jdk.nashorn.internal.runtime.regexp.joni.Config.log; |
| | | |
| | | @RestController |
| | | @RequestMapping("/question") |
| | |
| | | @ApiOperation(value = "修改提问词") |
| | | @Transactional |
| | | public ResponseResult<List<Question>> update(@RequestBody KeywordDto keywordDto) { |
| | | if (!"notSubmitted".equals(keywordDto.getStatus() )){ |
| | | return ResponseResult.error("该关键词已提交或者已采集完成不允许修改提问词!"); |
| | | //查询question的状态 |
| | | //遍历 |
| | | for (Question q : keywordDto.getQuestionList()) { |
| | | if ("success".equals(q.getStatus())) { |
| | | return ResponseResult.error("该提问词已采集"); |
| | | } |
| | | } |
| | | LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Question::getKeyword_id, keywordDto.getKeyword_id()); |
| | | questionService.remove(queryWrapper); |
| | | questionService.updateBatchById(keywordDto.getQuestionList()); |
| | | |
| | | List<Question> questionList = Arrays.stream(keywordDto.getQuestions().split("\\n")) |
| | | .filter(q -> !q.trim().isEmpty()) |
| | | .map(q -> { |
| | | Question question = new Question(); |
| | | question.setKeyword_id(keywordDto.getKeyword_id()); |
| | | question.setQuestion(q.trim()); |
| | | question.setStatus("pending"); |
| | | // if (!"notSubmitted".equals(keywordDto.getStatus() )){ |
| | | // return ResponseResult.error("该关键词已提交或者已采集完成不允许修改提问词!"); |
| | | // } |
| | | // LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>(); |
| | | // queryWrapper.eq(Question::getKeyword_id, keywordDto.getKeyword_id()); |
| | | // questionService.remove(queryWrapper); |
| | | |
| | | return question; |
| | | }).collect(Collectors.toList()); |
| | | // List<Question> questionList = Arrays.stream(keywordDto.getQuestions().split("\\n")) |
| | | // .filter(q -> !q.trim().isEmpty()) |
| | | // .map(q -> { |
| | | // Question question = new Question(); |
| | | // question.setKeyword_id(keywordDto.getKeyword_id()); |
| | | // question.setQuestion(q.trim()); |
| | | // question.setStatus("pending"); |
| | | // |
| | | // return question; |
| | | // }).collect(Collectors.toList()); |
| | | |
| | | boolean success = questionService.saveBatch(questionList); |
| | | // questionService.saveBatch(questionList); |
| | | |
| | | return ResponseResult.success(); |
| | | |
| | | |
| | | if(success) { |
| | | return ResponseResult.success(questionList); |
| | | } |
| | | |
| | | @PutMapping("/update") |
| | | @ApiOperation(value = "修改单个提问词") |
| | | public ResponseResult<Void> update(@RequestBody Question questions) { |
| | | boolean success = questionService.updateById(questions); |
| | | if (success) { |
| | | return ResponseResult.success(); |
| | | } |
| | | return ResponseResult.error("更新提问词失败"); |
| | | } |
| | | |
| | | // @PutMapping |
| | | // @ApiOperation(value = "修改提问词") |
| | | // public ResponseResult<Void> update(@RequestBody Question questions) { |
| | | // boolean success = questionService.updateById(questions); |
| | | // if (success) { |
| | | // return ResponseResult.success(); |
| | | // } |
| | | // return ResponseResult.error("更新提问词失败"); |
| | | // } |
| | | |
| | | // @DeleteMapping("/batch") |
| | | // @Transactional |
| | | // public ResponseResult<Void> batchDelete(@RequestBody List<Integer> |
| | | // questionIds) { |
| | | // List<Question> questions = questionIds.stream().map(id -> { |
| | | // Question question = new Question(); |
| | | // question.setQuestion_id(id); |
| | | // return question; |
| | | // }).collect(Collectors.toList()); |
| | | |
| | | // boolean success = questionService.updateBatchById(questions); |
| | | // if (success) { |
| | | // return ResponseResult.success(); |
| | | // } |
| | | // return ResponseResult.error("批量删除提问词失败"); |
| | | // } |
| | | @DeleteMapping("/batch") |
| | | @Transactional |
| | | @ApiOperation(value = "批量删除提问词") |
| | | public ResponseResult<Void> batchDelete(@RequestBody List<Integer> questionIds) { |
| | | System.out.println(questionIds.toString()); |
| | | questionService.removeByIds(questionIds); |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | | @GetMapping("/list") |
| | | @ApiOperation("根据关键词查询提问词列表") |