LearnQuestionsController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package com.ruoyi.web.controller.learn;
  2. import java.util.List;
  3. import java.util.stream.Collectors;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.alibaba.fastjson2.JSONObject;
  6. import com.ruoyi.enums.CardAction;
  7. import com.ruoyi.enums.QuestionType;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.springframework.security.access.prepost.PreAuthorize;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.*;
  14. import com.ruoyi.common.annotation.Log;
  15. import com.ruoyi.common.core.controller.BaseController;
  16. import com.ruoyi.common.core.domain.AjaxResult;
  17. import com.ruoyi.common.enums.BusinessType;
  18. import com.ruoyi.learn.domain.LearnQuestions;
  19. import com.ruoyi.learn.service.ILearnQuestionsService;
  20. import com.ruoyi.common.utils.poi.ExcelUtil;
  21. import com.ruoyi.common.core.page.TableDataInfo;
  22. /**
  23. * 试题Controller
  24. *
  25. * @author ruoyi
  26. * @date 2025-09-18
  27. */
  28. @RestController
  29. @RequestMapping("/learn/questions")
  30. @Api(tags = "后台-学习 - 题")
  31. public class LearnQuestionsController extends BaseController
  32. {
  33. @Autowired
  34. private ILearnQuestionsService learnQuestionsService;
  35. /**
  36. * 查询试题列表
  37. */
  38. @PreAuthorize("@ss.hasPermi('learn:questions:list')")
  39. @GetMapping("/list")
  40. @ApiOperation("查询列表")
  41. public TableDataInfo list(LearnQuestions learnQuestions)
  42. {
  43. startPage();
  44. if(null != learnQuestions.getTypeId()) {
  45. QuestionType qt = QuestionType.of(learnQuestions.getTypeId());
  46. learnQuestions.setQtpye(qt.getTitle());
  47. learnQuestions.setTypeId(null);
  48. }
  49. List<LearnQuestions> list = learnQuestionsService.selectLearnQuestionsList(learnQuestions);
  50. return getDataTable(list);
  51. }
  52. /**
  53. * 导出试题列表
  54. */
  55. @PreAuthorize("@ss.hasPermi('learn:questions:export')")
  56. @Log(title = "试题", businessType = BusinessType.EXPORT)
  57. @PostMapping("/export")
  58. public void export(HttpServletResponse response, LearnQuestions learnQuestions)
  59. {
  60. List<LearnQuestions> list = learnQuestionsService.selectLearnQuestionsList(learnQuestions);
  61. ExcelUtil<LearnQuestions> util = new ExcelUtil<LearnQuestions>(LearnQuestions.class);
  62. util.exportExcel(response, list, "试题数据");
  63. }
  64. /**
  65. * 获取试题详细信息
  66. */
  67. @PreAuthorize("@ss.hasPermi('learn:questions:query')")
  68. @GetMapping(value = "/{id}")
  69. public AjaxResult getInfo(@PathVariable("id") Long id)
  70. {
  71. return success(learnQuestionsService.selectLearnQuestionsById(id));
  72. }
  73. /**
  74. * 新增试题
  75. */
  76. @PreAuthorize("@ss.hasPermi('learn:questions:add')")
  77. @Log(title = "试题", businessType = BusinessType.INSERT)
  78. @PostMapping
  79. public AjaxResult add(@RequestBody LearnQuestions learnQuestions)
  80. {
  81. return toAjax(learnQuestionsService.insertLearnQuestions(learnQuestions));
  82. }
  83. /**
  84. * 修改试题
  85. */
  86. @PreAuthorize("@ss.hasPermi('learn:questions:edit')")
  87. @Log(title = "试题", businessType = BusinessType.UPDATE)
  88. @PutMapping
  89. public AjaxResult edit(@RequestBody LearnQuestions learnQuestions)
  90. {
  91. return toAjax(learnQuestionsService.updateLearnQuestions(learnQuestions));
  92. }
  93. /**
  94. * 删除试题
  95. */
  96. @PreAuthorize("@ss.hasPermi('learn:questions:remove')")
  97. @Log(title = "试题", businessType = BusinessType.DELETE)
  98. @DeleteMapping("/{ids}")
  99. public AjaxResult remove(@PathVariable Long[] ids)
  100. {
  101. return toAjax(learnQuestionsService.deleteLearnQuestionsByIds(ids));
  102. }
  103. @Log(title = "修改题型", businessType = BusinessType.UPDATE)
  104. @PostMapping("/changeType")
  105. @ApiOperation("修改题型")
  106. public AjaxResult updateQuestionType(@RequestBody JSONObject param)
  107. {
  108. QuestionType qt = QuestionType.of(param.getInteger("type"));
  109. List<Long> ids = param.getList ("ids", Long.class);
  110. learnQuestionsService.updateQuestionType(qt.getTitle(), ids);
  111. return AjaxResult.success();
  112. }
  113. }