|
@@ -69,8 +69,23 @@ public class QuestionController extends BaseController {
|
|
|
entity.setUpdateTime(new Date());
|
|
|
questionService.update(entity);
|
|
|
|
|
|
+ // 每次修改把答案删除,重新添加答案
|
|
|
+ answerService.deleteByQuestionId(entity.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 添加答案
|
|
|
+ List<AnswerRequest> answers = param.getAnswers();
|
|
|
+ for (AnswerRequest an :answers) {
|
|
|
+ AnswerEntity answerEntity = new AnswerEntity();
|
|
|
+ BeanUtils.copyProperties(an, answerEntity);
|
|
|
+ answerEntity.setQuestionId(entity.getId());
|
|
|
+ answerService.save(answerEntity);
|
|
|
}
|
|
|
- answerService.setQuestionId(entity.getId(), param.getAnswerId());
|
|
|
+
|
|
|
+
|
|
|
+// answerService.setQuestionId(entity.getId(), param.getAnswerId());
|
|
|
|
|
|
return Result.success();
|
|
|
}
|
|
@@ -87,11 +102,13 @@ public class QuestionController extends BaseController {
|
|
|
|
|
|
List<AnswerEntity> answers = answerService.findByQuestionId(id);
|
|
|
|
|
|
- HashMap<Object, Object> resultMap = new HashMap<>();
|
|
|
- resultMap.put("question", entity);
|
|
|
- resultMap.put("answer", answers);
|
|
|
+// HashMap<Object, Object> resultMap = new HashMap<>();
|
|
|
+// resultMap.put("question", entity);
|
|
|
+// resultMap.put("answer", answers);
|
|
|
+
|
|
|
+ entity.setAnswers(answers);
|
|
|
|
|
|
- return Result.success(resultMap);
|
|
|
+ return Result.success(entity);
|
|
|
}
|
|
|
|
|
|
@WebControllerLog(description = "题库管理-删除")
|
|
@@ -103,32 +120,32 @@ public class QuestionController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @WebControllerLog(description = "题库管理-新增/修改答案")
|
|
|
- @ApiOperation("新增/修改答案")
|
|
|
- @PostMapping("answer")
|
|
|
- public Result answer(@RequestBody AnswerRequest param) {
|
|
|
-
|
|
|
- AnswerEntity entity = null;
|
|
|
-
|
|
|
-
|
|
|
- Long id = param.getId();
|
|
|
- if (id == null) {
|
|
|
- entity = new AnswerEntity();
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
- answerService.save(entity);
|
|
|
- } else {
|
|
|
- entity = answerService.findById(param.getId());
|
|
|
- if (entity == null) {
|
|
|
- log.error("对象不存在: {}", id);
|
|
|
- return Result.failure("对象不存在");
|
|
|
- }
|
|
|
-
|
|
|
- BeanUtils.copyProperties(param, entity);
|
|
|
- entity.setUpdateTime(new Date());
|
|
|
- answerService.update(entity);
|
|
|
- }
|
|
|
-
|
|
|
- return Result.success(entity);
|
|
|
- }
|
|
|
+// @WebControllerLog(description = "题库管理-新增/修改答案")
|
|
|
+// @ApiOperation("新增/修改答案")
|
|
|
+// @PostMapping("answer")
|
|
|
+// public Result answer(@RequestBody AnswerRequest param) {
|
|
|
+//
|
|
|
+// AnswerEntity entity = null;
|
|
|
+//
|
|
|
+//
|
|
|
+// Long id = param.getId();
|
|
|
+// if (id == null) {
|
|
|
+// entity = new AnswerEntity();
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
+// answerService.save(entity);
|
|
|
+// } else {
|
|
|
+// entity = answerService.findById(param.getId());
|
|
|
+// if (entity == null) {
|
|
|
+// log.error("对象不存在: {}", id);
|
|
|
+// return Result.failure("对象不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
+// entity.setUpdateTime(new Date());
|
|
|
+// answerService.update(entity);
|
|
|
+// }
|
|
|
+//
|
|
|
+// return Result.success(entity);
|
|
|
+// }
|
|
|
|
|
|
}
|