From c46f49af9e766aed0ba583fce0efab98ebcdf76c Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期二, 18 六月 2024 17:12:06 +0800 Subject: [PATCH] 管理员增加学生端权限 --- src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java | 72 ++++++++++++++++------------------- 1 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java b/src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java index 210d56c..24b66b4 100644 --- a/src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java +++ b/src/main/java/com/ycl/jxkg/controller/student/QuestionAnswerController.java @@ -1,28 +1,30 @@ package com.ycl.jxkg.controller.student; import com.ycl.jxkg.base.BaseApiController; -import com.ycl.jxkg.base.RestResponse; -import com.ycl.jxkg.domain.ExamPaperQuestionCustomerAnswer; -import com.ycl.jxkg.domain.Subject; -import com.ycl.jxkg.domain.TextContent; +import com.ycl.jxkg.base.Result; +import com.ycl.jxkg.domain.entity.ExamPaperQuestionCustomerAnswer; +import com.ycl.jxkg.domain.entity.Subject; +import com.ycl.jxkg.domain.entity.TextContent; import com.ycl.jxkg.domain.question.QuestionObject; import com.ycl.jxkg.service.ExamPaperQuestionCustomerAnswerService; import com.ycl.jxkg.service.QuestionService; import com.ycl.jxkg.service.SubjectService; import com.ycl.jxkg.service.TextContentService; -import com.ycl.jxkg.utility.DateTimeUtil; -import com.ycl.jxkg.utility.HtmlUtil; -import com.ycl.jxkg.utility.JsonUtil; -import com.ycl.jxkg.utility.PageInfoHelper; -import com.ycl.jxkg.viewmodel.admin.question.QuestionEditRequestVM; -import com.ycl.jxkg.viewmodel.student.exam.ExamPaperSubmitItemVM; -import com.ycl.jxkg.viewmodel.student.question.answer.QuestionAnswerVM; -import com.ycl.jxkg.viewmodel.student.question.answer.QuestionPageStudentRequestVM; -import com.ycl.jxkg.viewmodel.student.question.answer.QuestionPageStudentResponseVM; +import com.ycl.jxkg.utils.DateTimeUtil; +import com.ycl.jxkg.utils.HtmlUtil; +import com.ycl.jxkg.utils.JsonUtil; +import com.ycl.jxkg.utils.PageInfoHelper; +import com.ycl.jxkg.domain.vo.admin.question.QuestionEditRequestVO; +import com.ycl.jxkg.domain.vo.student.exam.ExamPaperSubmitItemVO; +import com.ycl.jxkg.domain.vo.student.question.answer.QuestionAnswerVO; +import com.ycl.jxkg.domain.vo.student.question.answer.QuestionPageStudentRequestVO; +import com.ycl.jxkg.domain.vo.student.question.answer.QuestionPageStudentResponseVO; import com.github.pagehelper.PageInfo; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.BeanUtils; import org.springframework.web.bind.annotation.*; +@RequiredArgsConstructor @RestController("StudentQuestionAnswerController") @RequestMapping(value = "/api/student/question/answer") public class QuestionAnswerController extends BaseApiController { @@ -32,42 +34,34 @@ private final TextContentService textContentService; private final SubjectService subjectService; - @Autowired - public QuestionAnswerController(ExamPaperQuestionCustomerAnswerService examPaperQuestionCustomerAnswerService, QuestionService questionService, TextContentService textContentService, SubjectService subjectService) { - this.examPaperQuestionCustomerAnswerService = examPaperQuestionCustomerAnswerService; - this.questionService = questionService; - this.textContentService = textContentService; - this.subjectService = subjectService; - } - @RequestMapping(value = "/page", method = RequestMethod.POST) - public RestResponse<PageInfo<QuestionPageStudentResponseVM>> pageList(@RequestBody QuestionPageStudentRequestVM model) { + public Result<PageInfo<QuestionPageStudentResponseVO>> pageList(@RequestBody QuestionPageStudentRequestVO model) { model.setCreateUser(getCurrentUser().getId()); PageInfo<ExamPaperQuestionCustomerAnswer> pageInfo = examPaperQuestionCustomerAnswerService.studentPage(model); - PageInfo<QuestionPageStudentResponseVM> page = PageInfoHelper.copyMap(pageInfo, q -> { - Subject subject = subjectService.selectById(q.getSubjectId()); - QuestionPageStudentResponseVM vm = modelMapper.map(q, QuestionPageStudentResponseVM.class); - vm.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime())); - TextContent textContent = textContentService.selectById(q.getQuestionTextContentId()); - QuestionObject questionObject = JsonUtil.toJsonObject(textContent.getContent(), QuestionObject.class); + PageInfo<QuestionPageStudentResponseVO> page = PageInfoHelper.copyMap(pageInfo, q -> { + Subject subject = subjectService.getById(q.getSubjectId()); + QuestionPageStudentResponseVO vo = new QuestionPageStudentResponseVO(); + BeanUtils.copyProperties(q, vo); + vo.setCreateTime(DateTimeUtil.dateFormat(q.getCreateTime())); + QuestionObject questionObject = JsonUtil.toJsonObject(q.getQuestionContent(), QuestionObject.class); String clearHtml = HtmlUtil.clear(questionObject.getTitleContent()); - vm.setShortTitle(clearHtml); - vm.setSubjectName(subject.getName()); - return vm; + vo.setShortTitle(clearHtml); + vo.setSubjectName(subject.getName()); + return vo; }); - return RestResponse.ok(page); + return Result.ok(page); } @RequestMapping(value = "/select/{id}", method = RequestMethod.POST) - public RestResponse<QuestionAnswerVM> select(@PathVariable Integer id) { - QuestionAnswerVM vm = new QuestionAnswerVM(); - ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer = examPaperQuestionCustomerAnswerService.selectById(id); - ExamPaperSubmitItemVM questionAnswerVM = examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(examPaperQuestionCustomerAnswer); - QuestionEditRequestVM questionVM = questionService.getQuestionEditRequestVM(examPaperQuestionCustomerAnswer.getQuestionId()); + public Result<QuestionAnswerVO> select(@PathVariable Integer id) { + QuestionAnswerVO vm = new QuestionAnswerVO(); + ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer = examPaperQuestionCustomerAnswerService.getById(id); + ExamPaperSubmitItemVO questionAnswerVM = examPaperQuestionCustomerAnswerService.examPaperQuestionCustomerAnswerToVM(examPaperQuestionCustomerAnswer); + QuestionEditRequestVO questionVM = questionService.getQuestionEditRequestVM(examPaperQuestionCustomerAnswer.getQuestionId()); vm.setQuestionVM(questionVM); vm.setQuestionAnswerVM(questionAnswerVM); - return RestResponse.ok(vm); + return Result.ok(vm); } } -- Gitblit v1.8.0