PlanController.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.aijiuyi.admin.controller;
  2. import com.aijiuyi.admin.common.annotation.Log;
  3. import com.aijiuyi.admin.common.entity.Result;
  4. import com.aijiuyi.admin.common.enums.OperationType;
  5. import com.aijiuyi.admin.controller.dto.PlanQueryDTO;
  6. import com.aijiuyi.admin.controller.dto.PlanSaveDTO;
  7. import com.aijiuyi.admin.entity.Plan;
  8. import com.aijiuyi.admin.service.PlanService;
  9. import com.baomidou.mybatisplus.core.metadata.IPage;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.*;
  12. import javax.validation.Valid;
  13. import java.util.List;
  14. /**
  15. * 方案管理 Controller
  16. * 提供方案的新增、编辑、发布、下架、删除等接口
  17. */
  18. @RestController
  19. @RequestMapping("/plan")
  20. public class PlanController {
  21. @Autowired
  22. private PlanService planService;
  23. /**
  24. * 分页查询方案列表
  25. *
  26. * @param queryDTO 查询条件
  27. * @return 分页结果
  28. */
  29. @GetMapping("/page")
  30. @Log(value = "查询方案列表", module = "方案管理", operationType = OperationType.QUERY)
  31. public Result<IPage<Plan>> page(PlanQueryDTO queryDTO) {
  32. return Result.success(planService.pageList(queryDTO));
  33. }
  34. /**
  35. * 获取已有创作人列表(用于筛选下拉框)
  36. *
  37. * @return 创作人名称列表
  38. */
  39. @GetMapping("/authors")
  40. @Log(value = "查询方案创作人列表", module = "方案管理", operationType = OperationType.QUERY)
  41. public Result<List<String>> listAuthors() {
  42. return Result.success(planService.listAuthors());
  43. }
  44. /**
  45. * 查询方案详情(含步骤列表)
  46. *
  47. * @param id 方案ID
  48. * @return 方案详情
  49. */
  50. @GetMapping("/{id}")
  51. @Log(value = "查询方案详情", module = "方案管理", operationType = OperationType.QUERY)
  52. public Result<PlanSaveDTO> getById(@PathVariable Long id) {
  53. return Result.success(planService.getDetail(id));
  54. }
  55. /**
  56. * 新增方案(可保存草稿或直接发布)
  57. *
  58. * @param dto 方案信息(含步骤)
  59. * @return 新增方案ID
  60. */
  61. @PostMapping
  62. @Log(value = "新增方案", module = "方案管理", operationType = OperationType.INSERT)
  63. public Result<Long> add(@RequestBody @Valid PlanSaveDTO dto) {
  64. return Result.success(planService.addPlan(dto));
  65. }
  66. /**
  67. * 修改方案信息(含步骤)
  68. *
  69. * @param dto 方案信息(含步骤)
  70. * @return 操作结果
  71. */
  72. @PutMapping
  73. @Log(value = "修改方案信息", module = "方案管理", operationType = OperationType.UPDATE)
  74. public Result<Void> update(@RequestBody @Valid PlanSaveDTO dto) {
  75. planService.updatePlan(dto);
  76. return Result.success();
  77. }
  78. /**
  79. * 删除方案(逻辑删除,草稿或已下架可删)
  80. *
  81. * @param id 方案ID
  82. * @return 操作结果
  83. */
  84. @DeleteMapping("/{id}")
  85. @Log(value = "删除方案", module = "方案管理", operationType = OperationType.DELETE)
  86. public Result<Void> delete(@PathVariable Long id) {
  87. planService.deletePlan(id);
  88. return Result.success();
  89. }
  90. /**
  91. * 批量删除方案(草稿或已下架可删,需二次确认)
  92. *
  93. * @param ids 方案ID列表
  94. * @return 操作结果
  95. */
  96. @DeleteMapping("/batch")
  97. @Log(value = "批量删除方案", module = "方案管理", operationType = OperationType.DELETE)
  98. public Result<Void> batchDelete(@RequestBody List<Long> ids) {
  99. planService.batchDeletePlan(ids);
  100. return Result.success();
  101. }
  102. /**
  103. * 发布方案(草稿 → 已发布)
  104. *
  105. * @param id 方案ID
  106. * @return 操作结果
  107. */
  108. @PutMapping("/{id}/publish")
  109. @Log(value = "发布方案", module = "方案管理", operationType = OperationType.UPDATE)
  110. public Result<Void> publish(@PathVariable Long id) {
  111. planService.publishPlan(id);
  112. return Result.success();
  113. }
  114. /**
  115. * 批量发布方案
  116. *
  117. * @param ids 方案ID列表
  118. * @return 操作结果
  119. */
  120. @PutMapping("/batch/publish")
  121. @Log(value = "批量发布方案", module = "方案管理", operationType = OperationType.UPDATE)
  122. public Result<Void> batchPublish(@RequestBody List<Long> ids) {
  123. planService.batchPublishPlan(ids);
  124. return Result.success();
  125. }
  126. /**
  127. * 下架方案(已发布 → 已下架)
  128. *
  129. * @param id 方案ID
  130. * @return 操作结果
  131. */
  132. @PutMapping("/{id}/offshelf")
  133. @Log(value = "下架方案", module = "方案管理", operationType = OperationType.UPDATE)
  134. public Result<Void> offshelf(@PathVariable Long id) {
  135. planService.offshelfPlan(id);
  136. return Result.success();
  137. }
  138. /**
  139. * 批量下架方案
  140. *
  141. * @param ids 方案ID列表
  142. * @return 操作结果
  143. */
  144. @PutMapping("/batch/offshelf")
  145. @Log(value = "批量下架方案", module = "方案管理", operationType = OperationType.UPDATE)
  146. public Result<Void> batchOffshelf(@RequestBody List<Long> ids) {
  147. planService.batchOffshelfPlan(ids);
  148. return Result.success();
  149. }
  150. }