|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+package com.example.controller.system;
|
|
|
2
|
+
|
|
|
3
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
4
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
5
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
6
|
+import com.example.controller.BaseController;
|
|
|
7
|
+import com.example.entity.database.system.Post;
|
|
|
8
|
+import com.example.entity.input.PageInput;
|
|
|
9
|
+import com.example.model.AjaxResult;
|
|
|
10
|
+import com.example.service.system.IPostService;
|
|
|
11
|
+import com.example.util.annotation.Log;
|
|
|
12
|
+import com.example.util.enums.BusinessType;
|
|
|
13
|
+import com.example.util.helper.ExcelHelper;
|
|
|
14
|
+import com.example.util.helper.StringHelper;
|
|
|
15
|
+import io.swagger.annotations.Api;
|
|
|
16
|
+import io.swagger.annotations.ApiOperation;
|
|
|
17
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
18
|
+import org.springframework.web.bind.annotation.*;
|
|
|
19
|
+
|
|
|
20
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
21
|
+import java.util.Date;
|
|
|
22
|
+import java.util.List;
|
|
|
23
|
+
|
|
|
24
|
+@Api(value = "岗位信息表", tags = "岗位信息表")
|
|
|
25
|
+@RestController
|
|
|
26
|
+@RequestMapping("/system/post")
|
|
|
27
|
+public class PostController extends BaseController {
|
|
|
28
|
+ @Autowired
|
|
|
29
|
+ private IPostService postService;
|
|
|
30
|
+
|
|
|
31
|
+ /**
|
|
|
32
|
+ * 查看岗位列表
|
|
|
33
|
+ * @param input
|
|
|
34
|
+ * @param pageInput
|
|
|
35
|
+ * @return
|
|
|
36
|
+ */
|
|
|
37
|
+ @ApiOperation("列表")
|
|
|
38
|
+ @Log(title = "查看岗位列表",businessType = BusinessType.QUERY)
|
|
|
39
|
+ @GetMapping()
|
|
|
40
|
+ public AjaxResult getList(Post input, PageInput pageInput) {
|
|
|
41
|
+ LambdaQueryWrapper<Post> qw = new LambdaQueryWrapper();
|
|
|
42
|
+ qw.eq(input.getPostId() != null && input.getPostId() > 0, Post::getPostId, input.getPostId());
|
|
|
43
|
+ qw.like(!StringHelper.isEmpty(input.getPostCode()), Post::getPostCode, input.getPostCode());
|
|
|
44
|
+ qw.like(!StringHelper.isEmpty(input.getPostName()), Post::getPostName, input.getPostName());
|
|
|
45
|
+ qw.eq(input.getPostSort() != null && input.getPostSort() > 0, Post::getPostSort, input.getPostSort());
|
|
|
46
|
+ qw.like(!StringHelper.isEmpty(input.getStatus()), Post::getStatus, input.getStatus());
|
|
|
47
|
+ qw.like(!StringHelper.isEmpty(input.getCreateBy()), Post::getCreateBy, input.getCreateBy());
|
|
|
48
|
+ qw.eq(input.getCreateTime() != null, Post::getCreateTime, input.getCreateTime());
|
|
|
49
|
+ qw.like(!StringHelper.isEmpty(input.getUpdateBy()), Post::getUpdateBy, input.getUpdateBy());
|
|
|
50
|
+ qw.eq(input.getUpdateTime() != null, Post::getUpdateTime, input.getUpdateTime());
|
|
|
51
|
+ qw.like(!StringHelper.isEmpty(input.getRemark()), Post::getRemark, input.getRemark());
|
|
|
52
|
+ Page<Post> page = GetPage(pageInput);
|
|
|
53
|
+ if (page != null) {
|
|
|
54
|
+ IPage<Post> iPage = postService.getListPage(page, qw);
|
|
|
55
|
+ return Success("成功", iPage.getRecords(), iPage.getTotal());
|
|
|
56
|
+ } else {
|
|
|
57
|
+ return Success("成功", postService.getList(qw));
|
|
|
58
|
+ }
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ /**
|
|
|
62
|
+ * 查看岗位详情
|
|
|
63
|
+ * @param id
|
|
|
64
|
+ * @return
|
|
|
65
|
+ */
|
|
|
66
|
+ @ApiOperation("详情")
|
|
|
67
|
+ @Log(title = "查看岗位详情",businessType = BusinessType.QUERY)
|
|
|
68
|
+ @GetMapping("/{id}")
|
|
|
69
|
+ public AjaxResult getInfo(@PathVariable Long id) {
|
|
|
70
|
+ LambdaQueryWrapper<Post> qw = new LambdaQueryWrapper<>();
|
|
|
71
|
+ qw.eq(Post::getPostId, id).eq(Post::getStatus, "0");
|
|
|
72
|
+ Post entity = postService.getEntity(qw);
|
|
|
73
|
+ if (entity == null) {
|
|
|
74
|
+ return Error("岗位不存在!");
|
|
|
75
|
+ }
|
|
|
76
|
+ return Success("成功", entity);
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ /**
|
|
|
80
|
+ * 新增岗位
|
|
|
81
|
+ * @param input
|
|
|
82
|
+ * @return
|
|
|
83
|
+ */
|
|
|
84
|
+ @ApiOperation("新增")
|
|
|
85
|
+ @Log(title = "新增岗位",businessType = BusinessType.INSERT)
|
|
|
86
|
+ @PostMapping
|
|
|
87
|
+ public AjaxResult add(@RequestBody Post input) {
|
|
|
88
|
+ LambdaQueryWrapper<Post> qw = new LambdaQueryWrapper<>();
|
|
|
89
|
+ qw.eq(StringHelper.isNotEmpty(input.getPostName()), Post::getPostName, input.getPostName());
|
|
|
90
|
+
|
|
|
91
|
+ LambdaQueryWrapper<Post> qw2 = new LambdaQueryWrapper<>();
|
|
|
92
|
+ qw2.eq(StringHelper.isNotEmpty(input.getPostCode()), Post::getPostCode, input.getPostCode());
|
|
|
93
|
+ Post entity = postService.getEntity(qw);
|
|
|
94
|
+ Post entity2 = postService.getEntity(qw2);
|
|
|
95
|
+ input.setCreateBy(CurrentUser().getUserName());
|
|
|
96
|
+ input.setCreateTime(new Date());
|
|
|
97
|
+ if (entity != null) {
|
|
|
98
|
+ return Error("新增岗位'" + input.getPostName() + "'失败,岗位名称已存在");
|
|
|
99
|
+ } else if (entity2 != null) {
|
|
|
100
|
+ return Error("新增岗位'" + input.getPostName() + "'失败,岗位编码已存在");
|
|
|
101
|
+ }
|
|
|
102
|
+ boolean result = postService.insert(input);
|
|
|
103
|
+ if (result) {
|
|
|
104
|
+ return Success("成功");
|
|
|
105
|
+ } else {
|
|
|
106
|
+ return Error("新增失败");
|
|
|
107
|
+ }
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ /**
|
|
|
111
|
+ * 编辑
|
|
|
112
|
+ * @param input
|
|
|
113
|
+ * @return
|
|
|
114
|
+ */
|
|
|
115
|
+ @ApiOperation("编辑")
|
|
|
116
|
+ @Log(title = "修改岗位信息",businessType = BusinessType.UPDATE)
|
|
|
117
|
+ @PutMapping
|
|
|
118
|
+ public AjaxResult edit(@RequestBody Post input) {
|
|
|
119
|
+ LambdaQueryWrapper<Post> qw = new LambdaQueryWrapper<>();
|
|
|
120
|
+ LambdaQueryWrapper<Post> qw2 = new LambdaQueryWrapper<>();
|
|
|
121
|
+
|
|
|
122
|
+ if (StringHelper.isNotEmpty(input.getPostName())) {
|
|
|
123
|
+ qw.eq(Post::getPostName, input.getPostName());
|
|
|
124
|
+ Post entity = postService.getEntity(qw);
|
|
|
125
|
+ if (entity != null && !entity.getPostId().equals(input.getPostId())) {
|
|
|
126
|
+ return Error("修改岗位'" + input.getPostName() + "'失败,岗位名称已存在");
|
|
|
127
|
+ }
|
|
|
128
|
+ }
|
|
|
129
|
+ if (StringHelper.isNotEmpty(input.getPostCode())) {
|
|
|
130
|
+ qw2.eq(Post::getPostCode, input.getPostCode());
|
|
|
131
|
+ Post entity2 = postService.getEntity(qw2);
|
|
|
132
|
+
|
|
|
133
|
+ if (entity2 != null && !entity2.getPostId().equals(input.getPostId())) {
|
|
|
134
|
+ return Error("修改岗位'" + input.getPostName() + "'失败,岗位编码已存在");
|
|
|
135
|
+ }
|
|
|
136
|
+ }
|
|
|
137
|
+ input.setUpdateBy(CurrentUser().getUserName());
|
|
|
138
|
+ input.setUpdateTime(new Date());
|
|
|
139
|
+
|
|
|
140
|
+ boolean result = postService.update(input);
|
|
|
141
|
+ if (result) {
|
|
|
142
|
+ return Success("成功");
|
|
|
143
|
+ } else {
|
|
|
144
|
+ return Error("修改失败");
|
|
|
145
|
+ }
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+ /**
|
|
|
149
|
+ * 删除
|
|
|
150
|
+ * @param ids
|
|
|
151
|
+ * @return
|
|
|
152
|
+ */
|
|
|
153
|
+ @ApiOperation("删除")
|
|
|
154
|
+ @Log(title = "删除岗位",businessType = BusinessType.DELETE)
|
|
|
155
|
+ @DeleteMapping("/{ids}")
|
|
|
156
|
+ public AjaxResult delete(@PathVariable Long[] ids) {
|
|
|
157
|
+ LambdaQueryWrapper<Post> qw = new LambdaQueryWrapper<>();
|
|
|
158
|
+ qw.in(Post::getPostId, ids);
|
|
|
159
|
+ boolean delete = postService.delete(qw);
|
|
|
160
|
+ if (delete) {
|
|
|
161
|
+ return Success("成功");
|
|
|
162
|
+ } else {
|
|
|
163
|
+ return Error("删除失败");
|
|
|
164
|
+ }
|
|
|
165
|
+ }
|
|
|
166
|
+
|
|
|
167
|
+ @ApiOperation("导出Excel")
|
|
|
168
|
+ @Log(title = "导出Excel",businessType = BusinessType.EXPORT)
|
|
|
169
|
+ @PostMapping("/exportExcel")
|
|
|
170
|
+ public void ExportExcel(HttpServletResponse response) {
|
|
|
171
|
+ List<Post> list = postService.getList();
|
|
|
172
|
+ ExcelHelper<Post> excel = new ExcelHelper<>(Post.class);
|
|
|
173
|
+ excel.exportExcel(response, "xlsx", list);
|
|
|
174
|
+ }
|
|
|
175
|
+
|
|
|
176
|
+}
|