| | |
| | | package com.ycl.jxkg.controller.admin; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.ycl.jxkg.base.BaseApiController; |
| | | import com.ycl.jxkg.base.Result; |
| | | import com.ycl.jxkg.domain.ExamPaper; |
| | | import com.ycl.jxkg.domain.entity.ExamPaper; |
| | | import com.ycl.jxkg.domain.entity.ExamPaperQuestion; |
| | | import com.ycl.jxkg.domain.form.ExamPaperForm; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperEditRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamPaperPageRequestVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.ExamResponseVO; |
| | | import com.ycl.jxkg.domain.vo.admin.exam.QuestionExportVO; |
| | | import com.ycl.jxkg.enums.VisibilityEnum; |
| | | import com.ycl.jxkg.group.Add; |
| | | import com.ycl.jxkg.group.Update; |
| | | import com.ycl.jxkg.mapper.ExamPaperMapper; |
| | | import com.ycl.jxkg.service.ExamPaperQuestionService; |
| | | import com.ycl.jxkg.service.ExamPaperService; |
| | | import com.ycl.jxkg.utils.DateTimeUtil; |
| | | import com.ycl.jxkg.utils.PageInfoHelper; |
| | | import com.ycl.jxkg.vo.admin.exam.ExamPaperPageRequestVO; |
| | | import com.ycl.jxkg.vo.admin.exam.ExamPaperEditRequestVO; |
| | | import com.ycl.jxkg.vo.admin.exam.ExamResponseVO; |
| | | import com.github.pagehelper.PageInfo; |
| | | import org.springframework.beans.BeanUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.validation.Valid; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Validated |
| | | @RequiredArgsConstructor |
| | | @RestController("AdminExamPaperController") |
| | | @RequestMapping(value = "/api/admin/exam/paper") |
| | | public class ExamPaperController extends BaseApiController { |
| | | |
| | | private final ExamPaperService examPaperService; |
| | | |
| | | @Autowired |
| | | public ExamPaperController(ExamPaperService examPaperService) { |
| | | this.examPaperService = examPaperService; |
| | | } |
| | | private ExamPaperService examPaperService; |
| | | @Autowired |
| | | private ExamPaperQuestionService examPaperQuestionService; |
| | | @Autowired |
| | | private ExamPaperMapper baseMapper; |
| | | |
| | | @RequestMapping(value = "/page", method = RequestMethod.POST) |
| | | public Result<PageInfo<ExamResponseVO>> pageList(@RequestBody ExamPaperPageRequestVO model) { |
| | | PageInfo<ExamPaper> pageInfo = examPaperService.page(model); |
| | | PageInfo<ExamResponseVO> page = PageInfoHelper.copyMap(pageInfo, e -> { |
| | | ExamResponseVO vo = new ExamResponseVO(); |
| | | BeanUtils.copyProperties(e, vo); |
| | | vo.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); |
| | | return vo; |
| | | }); |
| | | PageInfo<ExamResponseVO> page = examPaperService.page(model); |
| | | return Result.ok(page); |
| | | } |
| | | |
| | | @RequestMapping(value = "/addPaper", method = RequestMethod.POST) |
| | | public Result taskExamPageList(@RequestBody @Validated(Add.class) ExamPaperForm form) { |
| | | if (!StringUtils.isBlank(form.getVisibility())) { |
| | | form.setVisibility(VisibilityEnum.fromCode(form.getVisibility()).getName()); |
| | | } |
| | | form.setCreateUser(getCurrentUser().getId()); |
| | | form.setCreateTime(new Date()); |
| | | |
| | | |
| | | @RequestMapping(value = "/taskExamPage", method = RequestMethod.POST) |
| | | public Result<PageInfo<ExamResponseVO>> taskExamPageList(@RequestBody ExamPaperPageRequestVO model) { |
| | | PageInfo<ExamPaper> pageInfo = examPaperService.taskExamPage(model); |
| | | PageInfo<ExamResponseVO> page = PageInfoHelper.copyMap(pageInfo, e -> { |
| | | ExamResponseVO vo = new ExamResponseVO(); |
| | | BeanUtils.copyProperties(e, vo); |
| | | vo.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); |
| | | return vo; |
| | | }); |
| | | return Result.ok(page); |
| | | return examPaperService.addPaper(form); |
| | | } |
| | | |
| | | |
| | | |
| | | @RequestMapping(value = "/edit", method = RequestMethod.POST) |
| | | public Result<ExamPaperEditRequestVO> edit(@RequestBody @Valid ExamPaperEditRequestVO model) { |
| | | ExamPaper examPaper = examPaperService.savePaperFromVM(model, getCurrentUser()); |
| | | ExamPaperEditRequestVO newVM = examPaperService.examPaperToVM(examPaper.getId()); |
| | | return Result.ok(newVM); |
| | | public Result edit(@RequestBody @Validated(Update.class) ExamPaperForm form) { |
| | | if (!StringUtils.isBlank(form.getVisibility())) { |
| | | form.setVisibility(VisibilityEnum.fromCode(form.getVisibility()).getName()); |
| | | } |
| | | return examPaperService.updateExamPaper(form); |
| | | } |
| | | |
| | | @RequestMapping(value = "/editQuestion", method = RequestMethod.POST) |
| | | public Result editQuestion(@RequestBody ExamPaperForm form) { |
| | | |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/selectQuestion/{id}", method = RequestMethod.POST) |
| | | public Result<ExamPaperQuestion> selectQuestion(@PathVariable Integer id) { |
| | | ExamPaperQuestion vo = examPaperQuestionService.selectById(id); |
| | | return Result.ok(vo); |
| | | } |
| | | |
| | | @RequestMapping(value = "/select/{id}", method = RequestMethod.POST) |
| | |
| | | |
| | | @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST) |
| | | public Result delete(@PathVariable Integer id) { |
| | | ExamPaper examPaper = examPaperService.selectById(id); |
| | | examPaper.setDeleted(true); |
| | | examPaperService.updateByIdFilter(examPaper); |
| | | baseMapper.deleteById(id); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @GetMapping("/my") |
| | | public Result myExamPaper(Integer paperType) { |
| | | List<ExamPaper> list = examPaperService.myExamPaper(paperType); |
| | | return Result.ok(list); |
| | | } |
| | | |
| | | @GetMapping("/download/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) { |
| | | examPaperService.importTemplate(response); |
| | | } |
| | | |
| | | @PostMapping("/export") |
| | | public void export(@RequestBody QuestionExportVO query, HttpServletResponse response) { |
| | | examPaperService.export(query, response); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | public Result importPaper(@RequestParam("file") MultipartFile file, @RequestParam("examPaper") String form) { |
| | | return examPaperService.importPaper(file, JSON.parseObject(form, ExamPaperForm.class)); |
| | | } |
| | | |
| | | } |