FrontUserController.java
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
package com.lhcredit.project.business.frontUser.controller;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
import com.fasterxml.jackson.core.type.TypeReference;
import com.github.pagehelper.PageHelper;
import com.lhcredit.common.constant.UserConstants;
import com.lhcredit.common.utils.JsonUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.web.page.PageDomain;
import com.lhcredit.framework.web.page.TableSupport;
import com.lhcredit.project.business.frontUser.domain.EmailAttachment;
import com.lhcredit.project.business.frontRole.domain.FrontRole;
import com.lhcredit.project.business.frontUser.domain.TempConf;
import com.lhcredit.project.business.frontRole.service.IFrontRoleService;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.templateConfiguration.service.ITemplateConfigurationService;
import com.lhcredit.project.system.dict.service.IDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.project.business.frontUser.domain.FrontUser;
import com.lhcredit.project.business.frontUser.service.IFrontUserService;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
/**
* 前端用户信息操作处理
*
* @author lhcredit
* @date 2024-05-13
*/
@Controller
@RequestMapping("/business/frontUser")
public class FrontUserController extends BaseController {
private String prefix = "business/frontUser";
@Autowired
private IFrontUserService frontUserService;
@Autowired
private IFrontRoleService frontRoleService;
@Resource
private ITemplateConfigurationService templateConfigurationService;
@Resource
private IDictDataService dictDataService;
@RequiresPermissions("business:frontUser:view")
@GetMapping()
public String frontUser() {
return prefix + "/frontUser";
}
/**
* 查询前端用户列表
*/
@RequiresPermissions("business:frontUser:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(FrontUser frontUser) {
//startPage();
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
if (StringUtils.isNull(pageNum)) {
pageNum = 1;
}
if (StringUtils.isNull(pageSize)) {
pageSize = 10;
}
if (StringUtils.isNotEmpty(pageDomain.getOrderByColumn())){
if (Objects.equals(pageDomain.getOrderByColumn(),"deptName")){
PageHelper.startPage(pageNum, pageSize,pageDomain.getOrderBy());
}else {
PageHelper.startPage(pageNum, pageSize,pageDomain.getOrderByColumn() + " " + pageDomain.getIsAsc());
}
}else {
PageHelper.startPage(pageNum, pageSize, "creditTime desc");
}
List<FrontUser> list = frontUserService.selectFrontUserList(frontUser);
return getDataTable(list);
}
/**
* 导出前端用户列表
*/
@RequiresPermissions("business:frontUser:export")
@Log(title = "前端用户", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(FrontUser frontUser) {
List<FrontUser> list = frontUserService.selectFrontUserList(frontUser);
ExcelUtil<FrontUser> util = new ExcelUtil<FrontUser>(FrontUser. class);
return util.exportExcel(list, "frontUser");
}
/**
* 新增前端用户
*/
@GetMapping("/add")
public String add( ModelMap mmap) {
mmap.put("roles", frontRoleService.selectFrontRoleList(new FrontRole()));
return prefix + "/add";
}
/**
* 新增前端用户
*/
@GetMapping("/addVx")
public String addVx(@RequestParam("openId") String openId, ModelMap mmap) {
mmap.put("roles", frontRoleService.selectFrontRoleList(new FrontRole()));
mmap.put("openId", openId);
return prefix + "/add";
}
/**
* 增加用户信息,根据选择的部门orgId,查询对应的模板名称
* 机构名称 org
* 类型 type 1:增加用户 2:编辑用户
*/
@GetMapping("/getTempConfByOrgId")
@ResponseBody
public AjaxResult getTempConfByOrgId(Long orgId, Long userId) throws IOException {
return AjaxResult.success(frontUserService.getTempConfByOrgId(orgId,userId));
}
/**
* 新增保存前端用户
*/
@RequiresPermissions("business:frontUser:add")
@Log(title = "前端用户", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(FrontUser frontUser) {
if (UserConstants.USER_NAME_NOT_UNIQUE.equals(frontUserService.checkLoginNameUnique(frontUser.getLoginName()))) {
return error("保存用户'" + frontUser.getLoginName() + "'失败,登录账号已存在");
}
frontUser.setCreateBy(ShiroUtils.getLoginName());
frontUser.setCreateTime(new Date());
frontUser.setUpdateBy(ShiroUtils.getLoginName());
frontUser.setUpdateTime(new Date());
return toAjax(frontUserService.insertFrontUser(frontUser));
}
/**
* 新增保存前端用户
*/
@RequiresPermissions("business:frontUser:add")
@Log(title = "前端用户", businessType = BusinessType.INSERT)
@PostMapping("/addNew")
@ResponseBody
public AjaxResult addSaveNew(FrontUser frontUser) {
if (UserConstants.USER_NAME_NOT_UNIQUE.equals(frontUserService.checkLoginNameUnique(frontUser.getLoginName()))) {
return error("保存用户'" + frontUser.getLoginName() + "'失败,登录账号已存在");
}
frontUser.setCreateBy(ShiroUtils.getLoginName());
frontUser.setCreateTime(new Date());
frontUser.setUpdateBy(ShiroUtils.getLoginName());
frontUser.setUpdateTime(new Date());
return toAjax(frontUserService.insertFrontUserNew(frontUser));
}
@Log(title = "批量创建用户监控默认分组、模板")
@GetMapping("/createGroupTemplate")
@ResponseBody
public AjaxResult createGroupTemplate() {
Date date = new Date();
List<FrontUser> frontUsers = frontUserService.selectFrontUserList(new FrontUser());
// 使用并行流替代原来的forEach
frontUsers.parallelStream().forEach(frontUser -> {
frontUserService.createGroupTemplate(frontUser, frontUser.getId(), date);
});
return AjaxResult.success();
}
/**
* 修改前端用户
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap) throws IOException {
FrontUser frontUser =frontUserService.selectFrontUserById(id);
/*if (StringUtils.isNotEmpty(frontUser.getReports())){
List<TempConf> tempConfByOrg = frontUserService.getTempConfByOrgId(frontUser.getOrgId(),null);
List<TempConf> tempConfList = JsonUtils.fromJson(frontUser.getReports(), new TypeReference<List<TempConf>>() {});
// 将 tempConfList 转换为 Map,以便快速查找
Map<String, TempConf> tempConfMap = tempConfList.stream()
.collect(Collectors.toMap(TempConf::getName, conf -> conf));
// 遍历 tempConfByOrg,如果存在相同id的对象,则拷贝属性
for (TempConf orgConf : tempConfByOrg) {
TempConf sourceConf = tempConfMap.get(orgConf.getName());
if (sourceConf != null) {
// 使用 Spring 的 BeanUtils 拷贝非空属性
BeanUtils.copyProperties(sourceConf, orgConf);
}
}
mmap.put("tempConfList", tempConfByOrg);
}
if (StringUtils.isNotEmpty(frontUser.getEmailAttachmentInfo())){
List<EmailAttachment> emailAttachmentList = JsonUtils.fromJson(frontUser.getReports(), new TypeReference<List<EmailAttachment>>() {});
mmap.put("emailAttachmentList", emailAttachmentList);
}*/
mmap.put("frontUser", frontUser);
mmap.put("roles", frontRoleService.selectRolesByUserId(Long.parseLong(id+"")));
return prefix + "/edit";
}
/**
* 修改保存前端用户
*/
@RequiresPermissions("business:frontUser:edit")
@Log(title = "前端用户", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(FrontUser frontUser) {
frontUser.setUpdateBy(ShiroUtils.getLoginName());
frontUser.setUpdateTime(new Date());
return toAjax(frontUserService.updateFrontUser(frontUser));
}
/**
* 删除前端用户
*/
@RequiresPermissions("business:frontUser:remove")
@Log(title = "前端用户", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
return toAjax(frontUserService.deleteFrontUserByIds(ids));
}
/**
* 校验用户名
*/
@PostMapping("/checkLoginNameUnique")
@ResponseBody
public String checkLoginNameUnique(FrontUser user) {
return frontUserService.checkLoginNameUnique(user.getLoginName());
}
/**
* 校验手机号码
*/
@PostMapping("/checkPhoneUnique")
@ResponseBody
public String checkPhoneUnique(FrontUser user) {
return frontUserService.checkPhoneUnique(user);
}
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
@GetMapping("/resetPwd/{id}")
public String resetPwd(@PathVariable("id") Long id, ModelMap mmap) {
mmap.put("user", frontUserService.selectFrontUserById(id));
return prefix + "/resetPwd";
}
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
@PostMapping("/resetPwd")
@ResponseBody
public AjaxResult resetPwd(FrontUserMon user) {
user.setModifyPsdPage(1);
return toAjax(frontUserService.resetUserPwd(user));
}
@PostMapping("/changeStatus")
@ResponseBody
public AjaxResult changeStatus(FrontUser user) {
return toAjax(frontUserService.changeStatus(user));
}
/**
* 根据部门 id 查询前台用户
* @param orgId
* @return
*/
@GetMapping("/getFrontUserByOrgId/{orgId}")
@ResponseBody
public AjaxResult getFrontUserByOrgId(@PathVariable("orgId") Long orgId) {
if (orgId == null) {
return AjaxResult.error("orgId 不能为空");
}
List<FrontUser> frontUserList = frontUserService.getFrontUserByOrgId(orgId);
return AjaxResult.success(frontUserList);
}
}