CollectQuestionController.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.zhongzheng.controller.collect;
  2. import java.util.List;
  3. import java.util.Arrays;
  4. import com.zhongzheng.common.utils.ServletUtils;
  5. import com.zhongzheng.framework.web.service.WxTokenService;
  6. import com.zhongzheng.modules.bank.vo.QuestionVo;
  7. import com.zhongzheng.modules.collect.bo.CollectQuestionAddBo;
  8. import com.zhongzheng.modules.collect.bo.CollectQuestionEditBo;
  9. import com.zhongzheng.modules.collect.bo.CollectQuestionQueryBo;
  10. import com.zhongzheng.modules.collect.domain.CollectQuestion;
  11. import com.zhongzheng.modules.collect.service.ICollectQuestionService;
  12. import com.zhongzheng.modules.collect.vo.CollectQuestionVo;
  13. import com.zhongzheng.modules.user.entity.ClientLoginUser;
  14. import lombok.RequiredArgsConstructor;
  15. import org.springframework.security.access.prepost.PreAuthorize;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.GetMapping;
  18. import org.springframework.web.bind.annotation.PostMapping;
  19. import org.springframework.web.bind.annotation.PutMapping;
  20. import org.springframework.web.bind.annotation.DeleteMapping;
  21. import org.springframework.web.bind.annotation.PathVariable;
  22. import org.springframework.web.bind.annotation.RequestBody;
  23. import org.springframework.web.bind.annotation.RequestMapping;
  24. import org.springframework.web.bind.annotation.RestController;
  25. import com.zhongzheng.common.annotation.Log;
  26. import com.zhongzheng.common.core.controller.BaseController;
  27. import com.zhongzheng.common.core.domain.AjaxResult;
  28. import com.zhongzheng.common.enums.BusinessType;
  29. import com.zhongzheng.common.utils.poi.ExcelUtil;
  30. import com.zhongzheng.common.core.page.TableDataInfo;
  31. import io.swagger.annotations.Api;
  32. import io.swagger.annotations.ApiOperation;
  33. /**
  34. * 收藏题目Controller
  35. *
  36. * @author ruoyi
  37. * @date 2021-06-24
  38. */
  39. @Api(value = "收藏题目控制器", tags = {"收藏题目管理"})
  40. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  41. @RestController
  42. @RequestMapping("/system/question")
  43. public class CollectQuestionController extends BaseController {
  44. private final ICollectQuestionService iCollectQuestionService;
  45. private final WxTokenService wxTokenService;
  46. /**
  47. * 查询收藏题目列表
  48. */
  49. @ApiOperation("查询收藏题目列表")
  50. @GetMapping("/list")
  51. public TableDataInfo<QuestionVo> list(CollectQuestionQueryBo bo) {
  52. ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
  53. bo.setUserId(loginUser.getUser().getUserId());
  54. startPage();
  55. List<QuestionVo> list = iCollectQuestionService.selectList(bo);
  56. return getDataTable(list);
  57. }
  58. /**
  59. * 获取收藏题目详细信息
  60. */
  61. @ApiOperation("获取收藏题目详细信息")
  62. @GetMapping("/{questionId}")
  63. public AjaxResult<CollectQuestion> getInfo(@PathVariable("questionId" ) Long questionId) {
  64. ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
  65. return AjaxResult.success(iCollectQuestionService.queryQuestionById(loginUser.getUser().getUserId(),questionId));
  66. }
  67. /**
  68. * 新增收藏题目
  69. */
  70. @ApiOperation("新增收藏题目")
  71. @Log(title = "收藏题目", businessType = BusinessType.INSERT)
  72. @PostMapping()
  73. public AjaxResult<Void> add(@RequestBody CollectQuestionAddBo bo) {
  74. ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
  75. bo.setUserId(loginUser.getUser().getUserId());
  76. return toAjax(iCollectQuestionService.insertByAddBo(bo) ? 1 : 0);
  77. }
  78. /**
  79. * 删除收藏题目
  80. */
  81. @ApiOperation("删除收藏题目")
  82. @Log(title = "收藏题目" , businessType = BusinessType.DELETE)
  83. @PostMapping("/delete/{collectQuestionIds}")
  84. public AjaxResult<Void> remove(@PathVariable Long[] collectQuestionIds) {
  85. return toAjax(iCollectQuestionService.deleteWithValidByIds(Arrays.asList(collectQuestionIds), true) ? 1 : 0);
  86. }
  87. }