PostController.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
  3. * <p>
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. * <p>
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. * <p>
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springblade.modules.system.controller;
  17. import com.baomidou.mybatisplus.core.metadata.IPage;
  18. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  19. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  20. import io.swagger.annotations.Api;
  21. import io.swagger.annotations.ApiOperation;
  22. import io.swagger.annotations.ApiParam;
  23. import lombok.AllArgsConstructor;
  24. import org.springblade.core.boot.ctrl.BladeController;
  25. import org.springblade.core.launch.constant.AppConstant;
  26. import org.springblade.core.mp.support.Condition;
  27. import org.springblade.core.mp.support.Query;
  28. import org.springblade.core.secure.BladeUser;
  29. import org.springblade.core.secure.utils.SecureUtil;
  30. import org.springblade.core.tool.api.R;
  31. import org.springblade.core.tool.utils.Func;
  32. import org.springblade.modules.system.entity.Post;
  33. import org.springblade.modules.system.service.IPostService;
  34. import org.springblade.modules.system.vo.PostVO;
  35. import org.springblade.modules.system.wrapper.PostWrapper;
  36. import org.springframework.web.bind.annotation.*;
  37. import javax.validation.Valid;
  38. import java.util.List;
  39. /**
  40. * 岗位表 控制器
  41. *
  42. * @author Chill
  43. */
  44. @RestController
  45. @AllArgsConstructor
  46. @RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/post")
  47. @Api(value = "岗位表", tags = "岗位表接口")
  48. public class PostController extends BladeController {
  49. private IPostService postService;
  50. /**
  51. * 详情
  52. */
  53. @GetMapping("/detail")
  54. @ApiOperationSupport(order = 1)
  55. @ApiOperation(value = "详情", notes = "传入post")
  56. public R<PostVO> detail(Post post) {
  57. Post detail = postService.getOne(Condition.getQueryWrapper(post));
  58. return R.data(PostWrapper.build().entityVO(detail));
  59. }
  60. /**
  61. * 分页 岗位表
  62. */
  63. @GetMapping("/list")
  64. @ApiOperationSupport(order = 2)
  65. @ApiOperation(value = "分页", notes = "传入post")
  66. public R<IPage<PostVO>> list(Post post, Query query) {
  67. IPage<Post> pages = postService.page(Condition.getPage(query), Condition.getQueryWrapper(post));
  68. return R.data(PostWrapper.build().pageVO(pages));
  69. }
  70. /**
  71. * 自定义分页 岗位表
  72. */
  73. @GetMapping("/page")
  74. @ApiOperationSupport(order = 3)
  75. @ApiOperation(value = "分页", notes = "传入post")
  76. public R<IPage<PostVO>> page(PostVO post, Query query) {
  77. IPage<PostVO> pages = postService.selectPostPage(Condition.getPage(query), post);
  78. return R.data(pages);
  79. }
  80. /**
  81. * 新增 岗位表
  82. */
  83. @PostMapping("/save")
  84. @ApiOperationSupport(order = 4)
  85. @ApiOperation(value = "新增", notes = "传入post")
  86. public R save(@Valid @RequestBody Post post) {
  87. return R.status(postService.save(post));
  88. }
  89. /**
  90. * 修改 岗位表
  91. */
  92. @PostMapping("/update")
  93. @ApiOperationSupport(order = 5)
  94. @ApiOperation(value = "修改", notes = "传入post")
  95. public R update(@Valid @RequestBody Post post) {
  96. return R.status(postService.updateById(post));
  97. }
  98. /**
  99. * 新增或修改 岗位表
  100. */
  101. @PostMapping("/submit")
  102. @ApiOperationSupport(order = 6)
  103. @ApiOperation(value = "新增或修改", notes = "传入post")
  104. public R submit(@Valid @RequestBody Post post) {
  105. post.setTenantId(SecureUtil.getTenantId());
  106. return R.status(postService.saveOrUpdate(post));
  107. }
  108. /**
  109. * 删除 岗位表
  110. */
  111. @PostMapping("/remove")
  112. @ApiOperationSupport(order = 7)
  113. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  114. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  115. return R.status(postService.deleteLogic(Func.toLongList(ids)));
  116. }
  117. /**
  118. * 下拉数据源
  119. */
  120. @GetMapping("/select")
  121. @ApiOperationSupport(order = 8)
  122. @ApiOperation(value = "下拉数据源", notes = "传入post")
  123. public R<List<Post>> select(String tenantId, BladeUser bladeUser) {
  124. List<Post> list = postService.list(Wrappers.<Post>query().lambda().eq(Post::getTenantId, Func.toStr(tenantId, bladeUser.getTenantId())));
  125. return R.data(list);
  126. }
  127. }