SysPostController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package com.zd.system.controller;
  2. import java.io.IOException;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletResponse;
  5. import com.zd.common.core.annotation.Log;
  6. import com.zd.common.core.annotation.PreAuthorize;
  7. import com.zd.common.core.log.BusinessType;
  8. import com.zd.common.core.utils.ExcelUtil;
  9. import com.zd.common.core.web.controller.BaseController;
  10. import com.zd.model.constant.UserConstants;
  11. import com.zd.model.domain.AjaxResult;
  12. import com.zd.model.domain.per.PerFun;
  13. import com.zd.model.domain.per.PerPrefix;
  14. import com.zd.model.page.TableDataInfo;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.validation.annotation.Validated;
  17. import org.springframework.web.bind.annotation.DeleteMapping;
  18. import org.springframework.web.bind.annotation.GetMapping;
  19. import org.springframework.web.bind.annotation.PathVariable;
  20. import org.springframework.web.bind.annotation.PostMapping;
  21. import org.springframework.web.bind.annotation.PutMapping;
  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.zd.common.core.utils.SecurityUtils;
  26. import com.zd.system.domain.SysPost;
  27. import com.zd.system.service.ISysPostService;
  28. /**
  29. * 职位信息操作处理
  30. *
  31. * @author zd
  32. */
  33. @RestController
  34. @RequestMapping("/post")
  35. public class SysPostController extends BaseController {
  36. @Autowired
  37. private ISysPostService postService;
  38. /**
  39. * 获取职位列表 "system:post:list"
  40. */
  41. @PreAuthorize(hasPermi = PerPrefix.SYSTEM_POST+ PerFun.LIST)
  42. @GetMapping("/list")
  43. public TableDataInfo list(SysPost post) {
  44. startPage();
  45. List<SysPost> list = postService.selectPostList(post);
  46. return getDataTable(list);
  47. }
  48. //"system:post:export"
  49. @Log(title = "职位管理", businessType = BusinessType.EXPORT)
  50. @PreAuthorize(hasPermi = PerPrefix.SYSTEM_POST+ PerFun.EXPORT)
  51. @PostMapping("/export")
  52. public void export(HttpServletResponse response, SysPost post) throws IOException {
  53. List<SysPost> list = postService.selectPostList(post);
  54. ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
  55. util.exportExcel(response, list, "职位数据");
  56. }
  57. /**
  58. * 根据职位编号获取详细信息 "system:post:query"
  59. */
  60. @PreAuthorize(hasPermi = PerPrefix.SYSTEM_POST+ PerFun.QUERY)
  61. @GetMapping(value = "/{postId}")
  62. public AjaxResult getInfo(@PathVariable Long postId) {
  63. return AjaxResult.success(postService.selectPostById(postId));
  64. }
  65. /**
  66. * 新增职位 "system:post:add"
  67. */
  68. @PreAuthorize(hasPermi = PerPrefix.SYSTEM_POST+ PerFun.ADD)
  69. @Log(title = "职位管理", businessType = BusinessType.INSERT)
  70. @PostMapping
  71. public AjaxResult add(@Validated @RequestBody SysPost post) {
  72. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  73. return AjaxResult.error("新增职位'" + post.getPostName() + "'失败,职位名称已存在");
  74. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  75. return AjaxResult.error("新增职位'" + post.getPostName() + "'失败,职位编码已存在");
  76. }
  77. post.setCreateBy(SecurityUtils.getUsername());
  78. return toAjax(postService.insertPost(post));
  79. }
  80. /**
  81. * 修改职位 "system:post:edit"
  82. */
  83. @PreAuthorize(hasPermi = PerPrefix.SYSTEM_POST+ PerFun.EDIT)
  84. @Log(title = "职位管理", businessType = BusinessType.UPDATE)
  85. @PutMapping
  86. public AjaxResult edit(@Validated @RequestBody SysPost post) {
  87. if (UserConstants.NOT_UNIQUE.equals(postService.checkPostNameUnique(post))) {
  88. return AjaxResult.error("修改职位'" + post.getPostName() + "'失败,职位名称已存在");
  89. } else if (UserConstants.NOT_UNIQUE.equals(postService.checkPostCodeUnique(post))) {
  90. return AjaxResult.error("修改职位'" + post.getPostName() + "'失败,职位编码已存在");
  91. }
  92. post.setUpdateBy(SecurityUtils.getUsername());
  93. return toAjax(postService.updatePost(post));
  94. }
  95. /**
  96. * 删除职位 "system:post:remove"
  97. */
  98. @PreAuthorize(hasPermi = PerPrefix.SYSTEM_POST+ PerFun.REMOVE)
  99. @Log(title = "职位管理", businessType = BusinessType.DELETE)
  100. @DeleteMapping("/{postIds}")
  101. public AjaxResult remove(@PathVariable Long[] postIds) {
  102. return toAjax(postService.deletePostByIds(postIds));
  103. }
  104. /**
  105. * 获取职位选择框列表
  106. */
  107. @GetMapping("/optionselect")
  108. public AjaxResult optionselect(SysPost post) {
  109. List<SysPost> posts = postService.selectPostAll(post);
  110. return AjaxResult.success(posts);
  111. }
  112. }