| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.linghu.model.common.ResponseResult; |
| | | import com.linghu.model.dto.KeywordDto; |
| | | import com.linghu.model.entity.Question; |
| | | import com.linghu.model.excel.KeywordExcel; |
| | | import com.linghu.service.QuestionService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import com.linghu.model.dto.KeywordDto; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | |
| | | return ResponseResult.error("添加提问词失败"); |
| | | } |
| | | |
| | | // @DeleteMapping("/{questionId}") |
| | | // public ResponseResult<Void> delete(@PathVariable Integer questionId) { |
| | | // Question question = new Question(); |
| | | // question.setQuestion_id(questionId); |
| | | // question.setDel_flag(1); |
| | | // boolean success = questionService.updateById(question); |
| | | @DeleteMapping("/{questionId}") |
| | | @ApiOperation(value = "删除提问词") |
| | | public ResponseResult<Void> delete(@PathVariable Integer questionId) { |
| | | |
| | | boolean success = questionService.removeById(questionId); |
| | | if (success) { |
| | | return ResponseResult.success(); |
| | | } |
| | | return ResponseResult.error("删除提问词失败"); |
| | | } |
| | | |
| | | // @PutMapping |
| | | // @Transactional |
| | | // public ResponseResult<Void> update(@RequestBody List<Question> questions) { |
| | | // boolean success = questionService.updateBatchById(questions); |
| | | // // 不存在的问题id就新增 |
| | | // List<Question> newQuestions = questions.stream() |
| | | // .filter(q -> q.getQuestion_id() == null) |
| | | // .collect(Collectors.toList()); |
| | | // if (!newQuestions.isEmpty()) { |
| | | // questionService.saveBatch(newQuestions); |
| | | // } |
| | | // if (success) { |
| | | // return ResponseResult.success(); |
| | | // } |
| | | // return ResponseResult.error("删除提问词失败"); |
| | | // return ResponseResult.error("更新提问词失败"); |
| | | // } |
| | | |
| | | @PutMapping |
| | | @Transactional |
| | | public ResponseResult<Void> update(@RequestBody List<Question> questions) { |
| | | boolean success = questionService.updateBatchById(questions); |
| | | // 不存在的问题id就新增 |
| | | List<Question> newQuestions = questions.stream() |
| | | .filter(q -> q.getQuestion_id() == null) |
| | | .collect(Collectors.toList()); |
| | | if (!newQuestions.isEmpty()) { |
| | | questionService.saveBatch(newQuestions); |
| | | } |
| | | @ApiOperation(value = "修改提问词") |
| | | public ResponseResult<Void> update(@RequestBody Question questions) { |
| | | boolean success = questionService.updateById(questions); |
| | | if (success) { |
| | | return ResponseResult.success(); |
| | | } |
| | | return ResponseResult.error("更新提问词失败"); |
| | | } |
| | | |
| | | @GetMapping("/{questionId}") |
| | | public ResponseResult<Question> getById(@PathVariable Integer questionId) { |
| | | Question question = questionService.getById(questionId); |
| | | if (question != null) { |
| | | return ResponseResult.success(question); |
| | | } |
| | | return ResponseResult.error("提问词不存在"); |
| | | } |
| | | |
| | | // @DeleteMapping("/batch") |
| | |
| | | // } |
| | | |
| | | @GetMapping("/list") |
| | | public ResponseResult<List<Question>> list() { |
| | | @ApiOperation("根据关键词查询提问词列表") |
| | | public ResponseResult<List<Question>> list(Integer keyword_id) { |
| | | LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Question::getKeyword_id, keyword_id); |
| | | List<Question> list = questionService.list(queryWrapper); |
| | | return ResponseResult.success(list); |
| | | |