UserSaveComponent.java
2.65 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
package com.ui.ctrl;
import com.ui.User.UserAuthLocal;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.User;
import com.ui.test.TestCommonAlarmData;
import com.ui.test.TestCommonData;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
/**
* 测试转用
*/
@Component
public class UserSaveComponent {
@Autowired
HttpRestClient httpRestClient;
@Autowired
UserAuthLocal userAuthLocal;
public BaseResponse saveUser( User user, HttpSession session) {
BaseResponse baseResponse = null;
if (StringUtils.isNotBlank(user.getModules()) && StringUtils.endsWith(user.getModules(), ",")) {
user.setModules(user.getModules().substring(0, user.getModules().length() - 1));
}
if (StringUtils.isNotBlank(user.getModuleGroups()) && StringUtils.endsWith(user.getModuleGroups(), ",")) {
user.setModuleGroups(user.getModuleGroups().substring(0, user.getModuleGroups().length() - 1));
}
if(StringUtils.isBlank(user.getEmail())||StringUtils.isBlank(user.getMobile())){
return new BaseResponse(201, "邮箱、手机号不能为空");
}
if(StringUtils.isBlank(user.getLadpName())){
user.setLadpName(user.getEmail().substring(0,user.getEmail().indexOf("@")));
}
if (user.getId() < 1) {//add
if (userAuthLocal.getUserByname(user.getName()) != null) {
return new BaseResponse(201, "用户已经存在");
}
user.setPwd(RandomStringUtils.random(8, true, true));
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_INSERT, user, BaseResponse.class);
} else {
User u = (User) session.getAttribute("user");
String username = u.getName();
if ("admin".equals(user.getName()) && !"admin".equals(username)) {
return new BaseResponse(201, "此用户无法修改");
}
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_UPDATE, user, BaseResponse.class);
}
userAuthLocal.flushUser(user.getName());
return baseResponse;
}
}