xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 package com.dl.web.controller.system;
X 2
3 import cn.dev33.satoken.annotation.SaCheckPermission;
4 import com.dl.common.annotation.Log;
5 import com.dl.common.constant.UserConstants;
6 import com.dl.common.core.controller.BaseController;
7 import com.dl.common.core.domain.PageQuery;
8 import com.dl.common.core.domain.R;
9 import com.dl.common.core.page.TableDataInfo;
10 import com.dl.common.enums.BusinessType;
11 import com.dl.common.utils.poi.ExcelUtil;
12 import com.dl.system.domain.SysPost;
13 import com.dl.system.service.ISysPostService;
14 import lombok.RequiredArgsConstructor;
15 import org.springframework.validation.annotation.Validated;
16 import org.springframework.web.bind.annotation.*;
17
18 import javax.servlet.http.HttpServletResponse;
19 import java.util.List;
20
21 /**
22  * 岗位信息操作处理
23  *
24  * @author Lion Li
25  */
26 @Validated
27 @RequiredArgsConstructor
28 @RestController
29 @RequestMapping("/system/post")
30 public class SysPostController extends BaseController {
31
32     private final ISysPostService postService;
33
34     /**
35      * 获取岗位列表
36      */
37     @SaCheckPermission("system:post:list")
38     @GetMapping("/list")
39     public TableDataInfo<SysPost> list(SysPost post, PageQuery pageQuery) {
40         return postService.selectPagePostList(post, pageQuery);
41     }
42
43     /**
44      * 导出岗位列表
45      */
46     @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
47     @SaCheckPermission("system:post:export")
48     @PostMapping("/export")
49     public void export(SysPost post, HttpServletResponse response) {
50         List<SysPost> list = postService.selectPostList(post);
51         ExcelUtil.exportExcel(list, "岗位数据", SysPost.class, response);
52     }
53
54     /**
55      * 根据岗位编号获取详细信息
56      *
57      * @param postId 岗位ID
58      */
59     @SaCheckPermission("system:post:query")
60     @GetMapping(value = "/{postId}")
61     public R<SysPost> getInfo(@PathVariable String postId) {
62         return R.ok(postService.selectPostById(postId));
63     }
64
65     /**
66      * 新增岗位
67      */
68     @SaCheckPermission("system:post:add")
69     @Log(title = "岗位管理", businessType = BusinessType.INSERT)
70     @PostMapping
71     public R<Void> add(@Validated @RequestBody SysPost post) {
72         if (!postService.checkPostNameUnique(post)) {
73             return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
74         } else if (!postService.checkPostCodeUnique(post)) {
75             return R.fail("新增岗位'" + post.getPostName() + "'失败,岗位编码已存在");
76         }
77         return toAjax(postService.insertPost(post));
78     }
79
80     /**
81      * 修改岗位
82      */
83     @SaCheckPermission("system:post:edit")
84     @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
85     @PutMapping
86     public R<Void> edit(@Validated @RequestBody SysPost post) {
87         if (!postService.checkPostNameUnique(post)) {
88             return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
89         } else if (!postService.checkPostCodeUnique(post)) {
90             return R.fail("修改岗位'" + post.getPostName() + "'失败,岗位编码已存在");
91         }
92         return toAjax(postService.updatePost(post));
93     }
94
95     /**
96      * 删除岗位
97      *
98      * @param postIds 岗位ID串
99      */
100     @SaCheckPermission("system:post:remove")
101     @Log(title = "岗位管理", businessType = BusinessType.DELETE)
102     @DeleteMapping("/{postIds}")
103     public R<Void> remove(@PathVariable String[] postIds) {
104         return toAjax(postService.deletePostByIds(postIds));
105     }
106
107     /**
108      * 获取岗位选择框列表
109      */
110     @GetMapping("/optionselect")
111     public R<List<SysPost>> optionselect() {
112         List<SysPost> posts = postService.selectPostAll();
113         return R.ok(posts);
114     }
115 }