PostController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the dreamlu.net developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: Chill 庄骞 (smallchill@163.com)
  16. */
  17. package org.springblade.modules.system.controller;
  18. import com.baomidou.mybatisplus.core.metadata.IPage;
  19. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  20. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. import io.swagger.annotations.ApiParam;
  24. import lombok.AllArgsConstructor;
  25. import org.springblade.core.boot.ctrl.BladeController;
  26. import org.springblade.core.cache.utils.CacheUtil;
  27. import org.springblade.core.launch.constant.AppConstant;
  28. import org.springblade.core.mp.support.Condition;
  29. import org.springblade.core.mp.support.Query;
  30. import org.springblade.core.secure.BladeUser;
  31. import org.springblade.core.tenant.annotation.NonDS;
  32. import org.springblade.core.tool.api.R;
  33. import org.springblade.core.tool.utils.Func;
  34. import org.springblade.modules.system.entity.Post;
  35. import org.springblade.modules.system.service.IPostService;
  36. import org.springblade.modules.system.vo.PostVO;
  37. import org.springblade.modules.system.wrapper.PostWrapper;
  38. import org.springframework.web.bind.annotation.*;
  39. import javax.validation.Valid;
  40. import java.util.List;
  41. import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
  42. /**
  43. * 岗位表 控制器
  44. *
  45. * @author Chill
  46. */
  47. @NonDS
  48. @RestController
  49. @AllArgsConstructor
  50. @RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/post")
  51. @Api(value = "岗位表", tags = "岗位表接口")
  52. public class PostController extends BladeController {
  53. private final IPostService postService;
  54. /**
  55. * 详情
  56. */
  57. @GetMapping("/detail")
  58. @ApiOperationSupport(order = 1)
  59. @ApiOperation(value = "详情", notes = "传入post")
  60. public R<PostVO> detail(Post post) {
  61. Post detail = postService.getOne(Condition.getQueryWrapper(post));
  62. return R.data(PostWrapper.build().entityVO(detail));
  63. }
  64. /**
  65. * 分页 岗位表
  66. */
  67. @GetMapping("/list")
  68. @ApiOperationSupport(order = 2)
  69. @ApiOperation(value = "分页", notes = "传入post")
  70. public R<IPage<PostVO>> list(Post post, Query query) {
  71. IPage<Post> pages = postService.page(Condition.getPage(query), Condition.getQueryWrapper(post));
  72. return R.data(PostWrapper.build().pageVO(pages));
  73. }
  74. /**
  75. * 自定义分页 岗位表
  76. */
  77. @GetMapping("/page")
  78. @ApiOperationSupport(order = 3)
  79. @ApiOperation(value = "分页", notes = "传入post")
  80. public R<IPage<PostVO>> page(PostVO post, Query query) {
  81. IPage<PostVO> pages = postService.selectPostPage(Condition.getPage(query), post);
  82. return R.data(pages);
  83. }
  84. /**
  85. * 新增 岗位表
  86. */
  87. @PostMapping("/save")
  88. @ApiOperationSupport(order = 4)
  89. @ApiOperation(value = "新增", notes = "传入post")
  90. public R save(@Valid @RequestBody Post post) {
  91. CacheUtil.clear(SYS_CACHE);
  92. return R.status(postService.save(post));
  93. }
  94. /**
  95. * 修改 岗位表
  96. */
  97. @PostMapping("/update")
  98. @ApiOperationSupport(order = 5)
  99. @ApiOperation(value = "修改", notes = "传入post")
  100. public R update(@Valid @RequestBody Post post) {
  101. CacheUtil.clear(SYS_CACHE);
  102. return R.status(postService.updateById(post));
  103. }
  104. /**
  105. * 新增或修改 岗位表
  106. */
  107. @PostMapping("/submit")
  108. @ApiOperationSupport(order = 6)
  109. @ApiOperation(value = "新增或修改", notes = "传入post")
  110. public R submit(@Valid @RequestBody Post post) {
  111. CacheUtil.clear(SYS_CACHE);
  112. return R.status(postService.saveOrUpdate(post));
  113. }
  114. /**
  115. * 删除 岗位表
  116. */
  117. @PostMapping("/remove")
  118. @ApiOperationSupport(order = 7)
  119. @ApiOperation(value = "逻辑删除", notes = "传入ids")
  120. public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
  121. CacheUtil.clear(SYS_CACHE);
  122. return R.status(postService.deleteLogic(Func.toLongList(ids)));
  123. }
  124. /**
  125. * 下拉数据源
  126. */
  127. @GetMapping("/select")
  128. @ApiOperationSupport(order = 8)
  129. @ApiOperation(value = "下拉数据源", notes = "传入post")
  130. public R<List<Post>> select(String tenantId, BladeUser bladeUser) {
  131. List<Post> list = postService.list(Wrappers.<Post>query().lambda().eq(Post::getTenantId, Func.toStrWithEmpty(tenantId, bladeUser.getTenantId())));
  132. return R.data(list);
  133. }
  134. }