Commit 879c58a00c5f4047b161e0310f8526e29da0e2d9
Exists in
master
and in
1 other branch
Merge remote-tracking branch 'origin/master'
# Conflicts: # platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
Showing 4 changed files
- platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/Test.java
- platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
- platform-operate-api/src/main/resources/database.properties
platform-common/src/main/java/com/lyms/platform/common/utils/LoginUtil.java
View file @
879c58a
| ... | ... | @@ -15,14 +15,20 @@ |
| 15 | 15 | |
| 16 | 16 | public class LoginUtil { |
| 17 | 17 | private static Logger logger = LoggerFactory.getLogger("HTTP-INVOKE"); |
| 18 | - public static LoginContext register(String phone, String token, String typeId) { | |
| 19 | - StopWatch stopWatch = new StopWatch("register"); | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + public static LoginContext register(String userId, String phone,String account, String pwd, String token, String typeId) { | |
| 22 | + StopWatch stopWatch = new StopWatch("aouHospitalUser"); | |
| 20 | 23 | stopWatch.start("init http client"); |
| 21 | 24 | HttpClient client = new HttpClient(); |
| 22 | - PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/register.action"); | |
| 25 | + PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/checkUser.action"); | |
| 23 | 26 | NameValuePair[] data = { |
| 24 | 27 | new NameValuePair("phone", phone), |
| 28 | + new NameValuePair("account", account), | |
| 29 | + new NameValuePair("password", pwd), | |
| 25 | 30 | new NameValuePair("typeId", typeId), |
| 31 | + new NameValuePair("userId", userId) | |
| 26 | 32 | }; |
| 27 | 33 | post.setRequestBody(data); |
| 28 | 34 | post.setRequestHeader("Authorization", token); |
| 29 | 35 | |
| ... | ... | @@ -32,13 +38,16 @@ |
| 32 | 38 | client.executeMethod(post); |
| 33 | 39 | int statusCode = post.getStatusCode(); |
| 34 | 40 | String result = new String(post.getResponseBodyAsString()); |
| 41 | + | |
| 35 | 42 | post.releaseConnection(); |
| 36 | 43 | stopWatch.stop(); |
| 37 | 44 | if (200 == statusCode) { |
| 38 | 45 | stopWatch.start("parse json"); |
| 39 | 46 | LoginContext loginState = JsonUtil.str2Obj(result, LoginContext.class); |
| 40 | 47 | stopWatch.stop(); |
| 41 | - return loginState; | |
| 48 | + if (0 == loginState.getErrorcode()) { | |
| 49 | + return loginState; | |
| 50 | + } | |
| 42 | 51 | } |
| 43 | 52 | } catch (Exception e) { |
| 44 | 53 | e.printStackTrace(); |
| ... | ... | @@ -48,6 +57,43 @@ |
| 48 | 57 | return null; |
| 49 | 58 | } |
| 50 | 59 | |
| 60 | + public static LoginContext loginByAccount(String account, String pwd, String typeId, String token) { | |
| 61 | + StopWatch stopWatch = new StopWatch("loginHospitalUser"); | |
| 62 | + stopWatch.start("init http client"); | |
| 63 | + HttpClient client = new HttpClient(); | |
| 64 | + PostMethod post = new MessageUtil.UTF8PostMethod("http://passport.healthbaby.com.cn/v1/userLogin.action"); | |
| 65 | + NameValuePair[] data = { | |
| 66 | + new NameValuePair("account", account), | |
| 67 | + new NameValuePair("typeId", typeId), | |
| 68 | + new NameValuePair("password", org.apache.commons.lang.StringUtils.isBlank(pwd)?"p":md5(pwd).toUpperCase()) | |
| 69 | + }; | |
| 70 | + post.setRequestBody(data); | |
| 71 | + post.setRequestHeader("Authorization", token); | |
| 72 | + stopWatch.stop(); | |
| 73 | + try { | |
| 74 | + stopWatch.start("excuteMethod"); | |
| 75 | + client.executeMethod(post); | |
| 76 | + int statusCode = post.getStatusCode(); | |
| 77 | + String result = new String(post.getResponseBodyAsString()); | |
| 78 | + | |
| 79 | + post.releaseConnection(); | |
| 80 | + stopWatch.stop(); | |
| 81 | + LoginContext loginState = new LoginContext(); | |
| 82 | + if (200 == statusCode) { | |
| 83 | + stopWatch.start("parse json"); | |
| 84 | + loginState = JsonUtil.str2Obj(result, LoginContext.class); | |
| 85 | + stopWatch.stop(); | |
| 86 | + return loginState; | |
| 87 | + } | |
| 88 | + } catch (Exception e) { | |
| 89 | + e.printStackTrace(); | |
| 90 | + } finally { | |
| 91 | + logger.info(stopWatch.toString()); | |
| 92 | + } | |
| 93 | + return null; | |
| 94 | + } | |
| 95 | + | |
| 96 | + | |
| 51 | 97 | public static Integer aouHospitalUser(String account, String pwd, String typeId, String token) { |
| 52 | 98 | StopWatch stopWatch = new StopWatch("aouHospitalUser"); |
| 53 | 99 | stopWatch.start("init http client"); |
| ... | ... | @@ -121,7 +167,7 @@ |
| 121 | 167 | return null; |
| 122 | 168 | } |
| 123 | 169 | |
| 124 | - public static LoginContext login(String phone, String varCode, String typeId, String token) { | |
| 170 | + public static LoginContext loginByPhone(String phone, String varCode, String typeId, String token) { | |
| 125 | 171 | StopWatch stopWatch = new StopWatch("login"); |
| 126 | 172 | stopWatch.start("init http client"); |
| 127 | 173 | HttpClient client = new HttpClient(); |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/Test.java
View file @
879c58a
| ... | ... | @@ -8,17 +8,22 @@ |
| 8 | 8 | */ |
| 9 | 9 | public class Test { |
| 10 | 10 | public static void main(String[] args){ |
| 11 | - StopWatch stopWatch= new StopWatch("doctor-api-patient"); | |
| 12 | - stopWatch.start("query patients"); | |
| 13 | - add(); | |
| 14 | - stopWatch.stop(); | |
| 15 | - stopWatch.start("query patients1"); | |
| 16 | - add(); | |
| 17 | - stopWatch.stop(); | |
| 18 | - stopWatch.start("query patients2"); | |
| 19 | - add(); | |
| 20 | - stopWatch.stop(); | |
| 21 | - System.out.print(stopWatch); | |
| 11 | +// StopWatch stopWatch= new StopWatch("doctor-api-patient"); | |
| 12 | +// stopWatch.start("query patients"); | |
| 13 | +// add(); | |
| 14 | +// stopWatch.stop(); | |
| 15 | +// stopWatch.start("query patients1"); | |
| 16 | +// add(); | |
| 17 | +// stopWatch.stop(); | |
| 18 | +// stopWatch.start("query patients2"); | |
| 19 | +// add(); | |
| 20 | +// stopWatch.stop(); | |
| 21 | +// System.out.print(stopWatch); | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + String a = "*****"; | |
| 26 | + System.out.println(a.matches("^\\**$")); | |
| 22 | 27 | } |
| 23 | 28 | private static void add(){ |
| 24 | 29 | int a=0; |
platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/UsersController.java
View file @
879c58a
Diff suppressed. Click to show
| ... | ... | @@ -9,9 +9,7 @@ |
| 9 | 9 | import com.lyms.platform.common.constants.ErrorCodeConstants; |
| 10 | 10 | import com.lyms.platform.common.enums.UserTypeEnum; |
| 11 | 11 | import com.lyms.platform.common.enums.YnEnums; |
| 12 | -import com.lyms.platform.common.utils.JsonUtil; | |
| 13 | -import com.lyms.platform.common.utils.LoginUtil; | |
| 14 | -import com.lyms.platform.common.utils.ResultUtils; | |
| 12 | +import com.lyms.platform.common.utils.*; | |
| 15 | 13 | import com.lyms.platform.operate.web.facade.AccessPermissionFacade; |
| 16 | 14 | import com.lyms.platform.operate.web.result.FrontEndResult; |
| 17 | 15 | import com.lyms.platform.permission.model.*; |
| 18 | 16 | |
| ... | ... | @@ -24,8 +22,10 @@ |
| 24 | 22 | import org.springframework.stereotype.Controller; |
| 25 | 23 | import org.springframework.web.bind.annotation.*; |
| 26 | 24 | |
| 25 | +import javax.management.relation.Role; | |
| 27 | 26 | import javax.servlet.http.HttpServletRequest; |
| 28 | 27 | import javax.servlet.http.HttpServletResponse; |
| 28 | +import javax.validation.constraints.Pattern; | |
| 29 | 29 | import java.util.*; |
| 30 | 30 | |
| 31 | 31 | /** |
| ... | ... | @@ -52,6 +52,8 @@ |
| 52 | 52 | private String token; |
| 53 | 53 | @Value("#{configProperties['login.typeId']}") |
| 54 | 54 | private String typeId; |
| 55 | + @Value("#{configProperties['login.defaultPwd']}") | |
| 56 | + private String defaultPwd; | |
| 55 | 57 | @Autowired |
| 56 | 58 | private RolePermissionMapsService rolePermissionMapsService; |
| 57 | 59 | @Autowired |
| 58 | 60 | |
| ... | ... | @@ -61,9 +63,10 @@ |
| 61 | 63 | |
| 62 | 64 | private static final String LYMS = "龙源美生"; |
| 63 | 65 | |
| 64 | - private static final String ADMIN = "管理员"; | |
| 66 | + private static final String ADMIN="管理员"; | |
| 65 | 67 | |
| 66 | 68 | |
| 69 | + | |
| 67 | 70 | /** |
| 68 | 71 | * 获取管理员列表 |
| 69 | 72 | */ |
| ... | ... | @@ -71,10 +74,10 @@ |
| 71 | 74 | @ResponseBody |
| 72 | 75 | @TokenRequired |
| 73 | 76 | public FrontEndResult getAdminList(HttpServletResponse response, |
| 74 | - @RequestParam(value = "keyword", required = false) String keyword, | |
| 75 | - @RequestParam(value = "rolesId", required = false) Integer rolesId, | |
| 76 | - @RequestParam(value = "page", required = false) Integer page, | |
| 77 | - @RequestParam(value = "limit", required = false) Integer limit) { | |
| 77 | + @RequestParam(value = "keyword", required = false) String keyword, | |
| 78 | + @RequestParam(value = "rolesId", required = false) Integer rolesId, | |
| 79 | + @RequestParam(value = "page", required = false) Integer page, | |
| 80 | + @RequestParam(value = "limit", required = false) Integer limit) { | |
| 78 | 81 | |
| 79 | 82 | limit = limit == null ? 10 : limit; |
| 80 | 83 | page = page == null ? 1 : page; |
| ... | ... | @@ -91,7 +94,7 @@ |
| 91 | 94 | |
| 92 | 95 | List<Users> users = usersService.queryUsers2(usersQuery); |
| 93 | 96 | //设置用户角色信息 |
| 94 | - for (Users user : users) { | |
| 97 | + for(Users user : users) { | |
| 95 | 98 | user.setRoles(this.getUserRoles(user.getId())); |
| 96 | 99 | |
| 97 | 100 | user.setDepartmentses(departmentsService.getDepartments(user.getDeptId())); |
| ... | ... | @@ -107,6 +110,7 @@ |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | 112 | |
| 113 | + | |
| 110 | 114 | /** |
| 111 | 115 | * 获取用户列表 |
| 112 | 116 | */ |
| 113 | 117 | |
| 114 | 118 | |
| 115 | 119 | |
| 116 | 120 | |
| 117 | 121 | |
| 118 | 122 | |
| 119 | 123 | |
| 120 | 124 | |
| ... | ... | @@ -115,42 +119,42 @@ |
| 115 | 119 | @ResponseBody |
| 116 | 120 | public FrontEndResult getPermissions(HttpServletResponse response, |
| 117 | 121 | HttpServletRequest request, |
| 118 | - @RequestParam(value = "keyword", required = false) String keyword, | |
| 119 | - @RequestParam(value = "rolesId", required = false) Integer rolesId, | |
| 120 | - @RequestParam(value = "page", required = false) Integer page, | |
| 121 | - @RequestParam(value = "limit", required = false) Integer limit, | |
| 122 | - @RequestParam(value = "orgId", required = false) Integer orgId, | |
| 123 | - @RequestParam(value = "deptId", required = false) Integer deptId) { | |
| 122 | + @RequestParam(value = "keyword", required = false) String keyword, | |
| 123 | + @RequestParam(value = "rolesId", required = false) Integer rolesId, | |
| 124 | + @RequestParam(value = "page", required = false) Integer page, | |
| 125 | + @RequestParam(value = "limit", required = false) Integer limit, | |
| 126 | + @RequestParam(value = "orgId", required = false) Integer orgId, | |
| 127 | + @RequestParam(value = "deptId", required = false) Integer deptId) { | |
| 124 | 128 | LoginContext loginContext = (LoginContext) request.getAttribute("loginContext"); |
| 125 | 129 | Users u = usersService.getUsers(loginContext.getId()); |
| 126 | 130 | |
| 127 | 131 | |
| 128 | 132 | List<Integer> ids = null; |
| 129 | - if (u.getType().equals(UserTypeEnum.NORMAL_USER.getId())) { | |
| 130 | - if (null != u.getOrgId()) { | |
| 133 | + if(u.getType().equals(UserTypeEnum.NORMAL_USER.getId())) { | |
| 134 | + if(null != u.getOrgId()) { | |
| 131 | 135 | orgId = u.getOrgId(); |
| 132 | 136 | } else { |
| 133 | 137 | FrontEndResult frontEndResult = new FrontEndResult(); |
| 134 | - frontEndResult.setPageInfo(new PageInfo(0, 0, 0, 10)); | |
| 138 | + frontEndResult.setPageInfo(new PageInfo(0,0,0,10)); | |
| 135 | 139 | frontEndResult.setErrorcode(ErrorCodeConstants.SUCCESS); |
| 136 | - return frontEndResult; | |
| 140 | + return frontEndResult; | |
| 137 | 141 | } |
| 138 | - } else if (u.getType().equals(UserTypeEnum.PLATFORM_ADMIN.getId())) { | |
| 142 | + }else if(u.getType().equals(UserTypeEnum.PLATFORM_ADMIN.getId())) { | |
| 139 | 143 | List<Organization> organizations = accessPermissionFacade.findAccessPerminssionByUserId(u.getId()); |
| 140 | 144 | ids = new ArrayList<>(); |
| 141 | - if (CollectionUtils.isNotEmpty(organizations)) { | |
| 142 | - for (Organization organization : organizations) { | |
| 145 | + if(CollectionUtils.isNotEmpty(organizations)) { | |
| 146 | + for(Organization organization : organizations) { | |
| 143 | 147 | ids.add(organization.getId()); |
| 144 | 148 | } |
| 145 | 149 | } else { |
| 146 | 150 | FrontEndResult frontEndResult = new FrontEndResult(); |
| 147 | - frontEndResult.setPageInfo(new PageInfo(0, 0, 0, 10)); | |
| 151 | + frontEndResult.setPageInfo(new PageInfo(0,0,0,10)); | |
| 148 | 152 | frontEndResult.setErrorcode(ErrorCodeConstants.SUCCESS); |
| 149 | - return frontEndResult; | |
| 153 | + return frontEndResult; | |
| 150 | 154 | } |
| 151 | 155 | } |
| 152 | 156 | |
| 153 | - if (null != orgId) { | |
| 157 | + if(null != orgId) { | |
| 154 | 158 | ids = new ArrayList<>(); |
| 155 | 159 | ids.add(orgId); |
| 156 | 160 | } |
| ... | ... | @@ -174,7 +178,7 @@ |
| 174 | 178 | List<Users> users = usersService.queryUsers2(usersQuery); |
| 175 | 179 | List<Organization> organizations = null; |
| 176 | 180 | //设置用户角色信息 |
| 177 | - for (Users user : users) { | |
| 181 | + for(Users user : users) { | |
| 178 | 182 | organizations = new ArrayList<>(); |
| 179 | 183 | Organization organization = organizationService.getOrganization(user.getOrgId()); |
| 180 | 184 | user.setOrganization(organization); |
| ... | ... | @@ -184,7 +188,7 @@ |
| 184 | 188 | user.setRoles(this.getUserRoles(user.getId())); |
| 185 | 189 | user.setDepartmentses(departmentsService.getDepartments(user.getDeptId())); |
| 186 | 190 | |
| 187 | - user.setPwd(null); | |
| 191 | + user.setPwd(user.getPwd().replaceAll(".","*")); | |
| 188 | 192 | } |
| 189 | 193 | |
| 190 | 194 | FrontEndResult frontEndResult = new FrontEndResult(); |
| 191 | 195 | |
| ... | ... | @@ -197,13 +201,13 @@ |
| 197 | 201 | } |
| 198 | 202 | |
| 199 | 203 | //获取用户角色信息 |
| 200 | - private List<Roles> getUserRoles(Integer userId) { | |
| 204 | + private List<Roles> getUserRoles(Integer userId) { | |
| 201 | 205 | UserRoleMapsQuery query = new UserRoleMapsQuery(); |
| 202 | 206 | query.setUserId(userId); |
| 203 | 207 | query.setYn(YnEnums.YES.getId()); |
| 204 | 208 | List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(query); |
| 205 | 209 | List<Roles> roles = new ArrayList<>(); |
| 206 | - for (UserRoleMaps roleMaps : userRoleMapses) { | |
| 210 | + for(UserRoleMaps roleMaps : userRoleMapses) { | |
| 207 | 211 | roles.add(rolesService.getRoles(roleMaps.getRoleId())); |
| 208 | 212 | } |
| 209 | 213 | return roles; |
| 210 | 214 | |
| 211 | 215 | |
| 212 | 216 | |
| 213 | 217 | |
| 214 | 218 | |
| 215 | 219 | |
| ... | ... | @@ -230,33 +234,34 @@ |
| 230 | 234 | //code 不为空使用手机登录, password不为空时使用帐号登录 |
| 231 | 235 | UsersQuery usersQuery = new UsersQuery(); |
| 232 | 236 | usersQuery.setYn(YnEnums.YES.getId()); |
| 233 | - if (null != code) { | |
| 237 | + if(null != code) { | |
| 234 | 238 | usersQuery.setPhone(account); |
| 235 | 239 | } |
| 236 | - if (null != password) { | |
| 240 | + if(null != password) { | |
| 237 | 241 | usersQuery.setAccount(account); |
| 238 | 242 | } |
| 239 | 243 | List<Users> users = usersService.queryUsers(usersQuery); |
| 240 | - if (0 == users.size()) { | |
| 244 | + if(0 == users.size()) { | |
| 241 | 245 | ResultUtils.buildParameterErrorResultAndWrite(response, "该账户不存在"); |
| 242 | 246 | return; |
| 243 | 247 | } |
| 244 | 248 | |
| 245 | - if (!users.get(0).getEnable().equals(1)) { | |
| 249 | + Users u = users.get(0); | |
| 250 | + if(!u.getEnable().equals(1)) { | |
| 246 | 251 | ResultUtils.buildParameterErrorResultAndWrite(response, "该账户已被禁用"); |
| 247 | 252 | return; |
| 248 | 253 | } |
| 249 | 254 | |
| 250 | 255 | LoginContext loginContext = new LoginContext(); |
| 251 | 256 | loginContext.setErrormsg("服务器内部错误!"); |
| 252 | - if (null != code) { | |
| 253 | - loginContext = LoginUtil.login(account, code, typeId, token); | |
| 257 | + if(null != code) { | |
| 258 | + loginContext =LoginUtil.loginByPhone(account, code, typeId, token); | |
| 254 | 259 | } |
| 255 | - if (null != password) { | |
| 256 | - loginContext = LoginUtil.loginHospitalUser(account, password, typeId, token); | |
| 260 | + if(null != password) { | |
| 261 | + loginContext = LoginUtil.loginByAccount(account, password, typeId, token); | |
| 257 | 262 | } |
| 258 | 263 | |
| 259 | - if (null != loginContext && loginContext.getErrorcode().equals(0)) { | |
| 264 | + if(null != loginContext && loginContext.getErrorcode().equals(0)) { | |
| 260 | 265 | Users users1 = new Users(); |
| 261 | 266 | users1.setId(users.get(0).getId()); |
| 262 | 267 | users1.setLastLoginTime(new Date()); |
| ... | ... | @@ -265,7 +270,7 @@ |
| 265 | 270 | Map<String, Object> result = new HashMap<>(); |
| 266 | 271 | result.put("token", loginContext.getToken()); |
| 267 | 272 | ResultUtils.buildSuccessResultAndWrite(response, result); |
| 268 | - } else { | |
| 273 | + }else { | |
| 269 | 274 | ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.PARAMETER_ERROR, loginContext.getErrormsg()); |
| 270 | 275 | } |
| 271 | 276 | } |
| ... | ... | @@ -283,7 +288,7 @@ |
| 283 | 288 | ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse); |
| 284 | 289 | return; |
| 285 | 290 | } |
| 286 | - if (!phone.matches("^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$")) { | |
| 291 | + if(!phone.matches("^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$")) { | |
| 287 | 292 | ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse, "手机号不正确!"); |
| 288 | 293 | return; |
| 289 | 294 | } |
| 290 | 295 | |
| 291 | 296 | |
| ... | ... | @@ -292,18 +297,18 @@ |
| 292 | 297 | usersQuery.setPhone(phone); |
| 293 | 298 | usersQuery.setYn(YnEnums.YES.getId()); |
| 294 | 299 | List<Users> list = usersService.queryUsers(usersQuery); |
| 295 | - if (null == list || 0 == list.size()) { | |
| 300 | + if(null == list || 0 == list.size()) { | |
| 296 | 301 | ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse, "该账户不存在"); |
| 297 | 302 | return; |
| 298 | 303 | } |
| 299 | 304 | |
| 300 | - if (!list.get(0).getEnable().equals(1)) { | |
| 305 | + if(!list.get(0).getEnable().equals(1)) { | |
| 301 | 306 | ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse, "该账户已被禁用"); |
| 302 | 307 | return; |
| 303 | 308 | } |
| 304 | 309 | |
| 305 | 310 | LoginContext loginContext = LoginUtil.sendVerCode(phone, typeId, token); |
| 306 | - if (null != loginContext) { | |
| 311 | + if(null != loginContext) { | |
| 307 | 312 | ResultUtils.buildResultAndWrite(httpServletResponse, loginContext.getErrorcode(), loginContext.getErrormsg()); |
| 308 | 313 | return; |
| 309 | 314 | } |
| 310 | 315 | |
| ... | ... | @@ -320,14 +325,14 @@ |
| 320 | 325 | public void usersLoginMsg(HttpServletResponse response, HttpServletRequest request) { |
| 321 | 326 | LoginContext loginContext = (LoginContext) request.getAttribute("loginContext"); |
| 322 | 327 | Users users = null; |
| 323 | - if (null != loginContext) { | |
| 328 | + if(null != loginContext) { | |
| 324 | 329 | users = usersService.getUsers(loginContext.getId()); |
| 325 | 330 | } |
| 326 | 331 | |
| 327 | 332 | List<Permissions> permissions = null; |
| 328 | 333 | List<Roles> roles = new ArrayList<>(); |
| 329 | 334 | //超级管理员拥有所有角色和权限 |
| 330 | - if (users.getType().equals(UserTypeEnum.SUPPER_ADMIN.getId())) { | |
| 335 | + if(users.getType().equals(UserTypeEnum.SUPPER_ADMIN.getId())) { | |
| 331 | 336 | RolesQuery rolesQuery = new RolesQuery(); |
| 332 | 337 | rolesQuery.setYn(YnEnums.YES.getId()); |
| 333 | 338 | roles = rolesService.queryRoles(rolesQuery); |
| 334 | 339 | |
| 335 | 340 | |
| ... | ... | @@ -339,16 +344,16 @@ |
| 339 | 344 | |
| 340 | 345 | } |
| 341 | 346 | //其他用户 |
| 342 | - else if (users.getType().equals(UserTypeEnum.PLATFORM_ADMIN.getId()) || users.getType().equals(UserTypeEnum.NORMAL_USER.getId())) { | |
| 347 | + else if(users.getType().equals(UserTypeEnum.PLATFORM_ADMIN.getId()) || users.getType().equals(UserTypeEnum.NORMAL_USER.getId())){ | |
| 343 | 348 | //获取用户角色信息 |
| 344 | 349 | UserRoleMapsQuery query = new UserRoleMapsQuery(); |
| 345 | 350 | query.setUserId(users.getId()); |
| 346 | 351 | query.setYn(YnEnums.YES.getId()); |
| 347 | 352 | List<Integer> userRoleMapses = userRoleMapsService.queryUserRoleList(query); |
| 348 | - RolePermissionMapsQuery rolePermissionMapsQuery; | |
| 353 | + RolePermissionMapsQuery rolePermissionMapsQuery ; | |
| 349 | 354 | List<Integer> permissionIds = new ArrayList<>(); |
| 350 | - permissions = new ArrayList<>(); | |
| 351 | - for (Integer roleMaps : userRoleMapses) { | |
| 355 | + permissions = new ArrayList<>(); | |
| 356 | + for(Integer roleMaps : userRoleMapses) { | |
| 352 | 357 | roles.add(rolesService.getRoles(roleMaps)); |
| 353 | 358 | |
| 354 | 359 | //获取角色权限信息 |
| ... | ... | @@ -369,13 +374,14 @@ |
| 369 | 374 | } |
| 370 | 375 | } |
| 371 | 376 | }*/ |
| 372 | - } | |
| 373 | - List<Permissions> local = permissionsService.queryPermissionByRoleIds(userRoleMapses); | |
| 374 | - if (CollectionUtils.isNotEmpty(local)) { | |
| 375 | - for (Permissions permissions1 : local) { | |
| 376 | - if (!permissionIds.contains(permissions1.getId())) { | |
| 377 | - permissionIds.add(permissions1.getId()); | |
| 378 | - permissions.add(permissions1); | |
| 377 | + | |
| 378 | + List<Permissions> local = permissionsService.queryPermissionByRoleIds(roleMaps); | |
| 379 | + if(CollectionUtils.isNotEmpty(local)){ | |
| 380 | + for(Permissions permissions1:local){ | |
| 381 | + if(!permissionIds.contains(permissions1.getId())) { | |
| 382 | + permissionIds.add(permissions1.getId()); | |
| 383 | + permissions.add(permissions1); | |
| 384 | + } | |
| 379 | 385 | } |
| 380 | 386 | } |
| 381 | 387 | } |
| 382 | 388 | |
| ... | ... | @@ -383,14 +389,14 @@ |
| 383 | 389 | |
| 384 | 390 | |
| 385 | 391 | List<Organization> organizations = new ArrayList<>(); |
| 386 | - if (null != users.getOrgId() && UserTypeEnum.NORMAL_USER.getId().equals(users.getType())) { //普通用户 | |
| 392 | + if(null != users.getOrgId() && UserTypeEnum.NORMAL_USER.getId().equals(users.getType())) { //普通用户 | |
| 387 | 393 | Organization organization = organizationService.getOrganization(users.getOrgId()); |
| 388 | 394 | organizations.add(organization); |
| 389 | 395 | users.setOrganization(organization); |
| 390 | 396 | } else if (UserTypeEnum.PLATFORM_ADMIN.getId().equals(users.getType())) { //管理员 |
| 391 | - List<Organization> list2 = accessPermissionFacade.findAccessPerminssionByUserId(users.getId()); | |
| 392 | - if (CollectionUtils.isNotEmpty(list2)) { | |
| 393 | - for (Organization organization : list2) { | |
| 397 | + List<Organization> list2 =accessPermissionFacade.findAccessPerminssionByUserId(users.getId()); | |
| 398 | + if(CollectionUtils.isNotEmpty(list2)){ | |
| 399 | + for(Organization organization:list2){ | |
| 394 | 400 | organizations.add(organization); |
| 395 | 401 | } |
| 396 | 402 | } |
| 397 | 403 | |
| ... | ... | @@ -415,12 +421,12 @@ |
| 415 | 421 | @RequestMapping(value = "/users/userRole/{id}", method = RequestMethod.GET) |
| 416 | 422 | @TokenRequired |
| 417 | 423 | public void userRole(HttpServletResponse response, HttpServletRequest request, @PathVariable(value = "id") Integer id) { |
| 418 | - UserRoleMapsQuery query = new UserRoleMapsQuery(); | |
| 424 | + UserRoleMapsQuery query = new UserRoleMapsQuery(); | |
| 419 | 425 | query.setUserId(id); |
| 420 | 426 | query.setYn(YnEnums.YES.getId()); |
| 421 | 427 | List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(query); |
| 422 | 428 | List<Roles> roles = new ArrayList<>(); |
| 423 | - for (UserRoleMaps roleMaps : userRoleMapses) { | |
| 429 | + for(UserRoleMaps roleMaps : userRoleMapses) { | |
| 424 | 430 | roles.add(rolesService.getRoles(roleMaps.getRoleId())); |
| 425 | 431 | } |
| 426 | 432 | |
| 427 | 433 | |
| ... | ... | @@ -428,12 +434,13 @@ |
| 428 | 434 | } |
| 429 | 435 | |
| 430 | 436 | |
| 437 | + | |
| 431 | 438 | /** |
| 432 | 439 | * 管理员权限设置 |
| 433 | 440 | */ |
| 434 | 441 | @RequestMapping(value = "/adminPermissions", method = RequestMethod.POST) |
| 435 | 442 | @TokenRequired |
| 436 | - public void adminPermissions(HttpServletResponse response, @RequestParam(value = "userId") Integer userId, @RequestParam(value = "ids") String ids) { | |
| 443 | + public void adminPermissions(HttpServletResponse response,@RequestParam(value = "userId") Integer userId, @RequestParam(value = "ids") String ids){ | |
| 437 | 444 | |
| 438 | 445 | if (ids == null) { |
| 439 | 446 | ResultUtils.buildParameterErrorResultAndWrite(response); |
| ... | ... | @@ -452,7 +459,7 @@ |
| 452 | 459 | return; |
| 453 | 460 | } |
| 454 | 461 | |
| 455 | - if (!usersList.get(0).getType().equals(UserTypeEnum.PLATFORM_ADMIN.getId())) { | |
| 462 | + if(!usersList.get(0).getType().equals(UserTypeEnum.PLATFORM_ADMIN.getId())) { | |
| 456 | 463 | ResultUtils.buildParameterErrorResultAndWrite(response, "用户错误"); |
| 457 | 464 | return; |
| 458 | 465 | } |
| ... | ... | @@ -461,8 +468,8 @@ |
| 461 | 468 | UserOrganizationMapsQuery userOrganizationMapsQuery = new UserOrganizationMapsQuery(); |
| 462 | 469 | userOrganizationMapsQuery.setUserId(userId); |
| 463 | 470 | List<UserOrganizationMaps> userOrganizationMapsList = userOrganizationMapsService.queryUserOrganizationMaps(userOrganizationMapsQuery); |
| 464 | - if (0 < userOrganizationMapsList.size()) { | |
| 465 | - for (UserOrganizationMaps userOrganizationMaps : userOrganizationMapsList) { | |
| 471 | + if(0 < userOrganizationMapsList.size()) { | |
| 472 | + for(UserOrganizationMaps userOrganizationMaps : userOrganizationMapsList) { | |
| 466 | 473 | userOrganizationMaps.setYn(YnEnums.NO.getId()); |
| 467 | 474 | userOrganizationMapsService.updateUserOrganizationMaps(userOrganizationMaps); |
| 468 | 475 | } |
| 469 | 476 | |
| ... | ... | @@ -470,12 +477,12 @@ |
| 470 | 477 | |
| 471 | 478 | //添加最新权限映射 |
| 472 | 479 | String[] roleArrayIds = ids.split(","); |
| 473 | - Users user = usersList.get(0); | |
| 480 | + Users user = usersList.get(0); | |
| 474 | 481 | UserOrganizationMaps userOrganizationMaps = null; |
| 475 | 482 | Organization organization = null; |
| 476 | 483 | for (String id : roleArrayIds) { |
| 477 | 484 | organization = organizationService.getOrganization(Integer.valueOf(id)); |
| 478 | - if (null != organization) { | |
| 485 | + if(null != organization) { | |
| 479 | 486 | userOrganizationMaps = new UserOrganizationMaps(); |
| 480 | 487 | userOrganizationMaps.setUserId(user.getId()); |
| 481 | 488 | userOrganizationMaps.setOrgId(Integer.valueOf(id)); |
| ... | ... | @@ -494,7 +501,7 @@ |
| 494 | 501 | |
| 495 | 502 | |
| 496 | 503 | private Boolean isPhone(String phone) { |
| 497 | - return phone.matches("^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$"); | |
| 504 | + return phone.matches("^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$"); | |
| 498 | 505 | } |
| 499 | 506 | |
| 500 | 507 | /** |
| ... | ... | @@ -505,7 +512,7 @@ |
| 505 | 512 | public void addAdmin(HttpServletResponse response, |
| 506 | 513 | HttpServletRequest request, |
| 507 | 514 | @RequestParam(value = "name", required = false) String name, |
| 508 | - @RequestParam(value = "account", required = false) String account, | |
| 515 | + @RequestParam(value = "account", required = false)String account, | |
| 509 | 516 | @RequestParam(value = "phone") String phone, |
| 510 | 517 | @RequestParam(value = "enable", required = false) Integer enable, |
| 511 | 518 | @RequestParam(value = "remarks", required = false) String remarks, |
| ... | ... | @@ -518,7 +525,7 @@ |
| 518 | 525 | |
| 519 | 526 | |
| 520 | 527 | if (StringUtils.isBlank(roleIds) || |
| 521 | - StringUtils.isBlank(name) || StringUtils.isBlank(phone) || null == user) { | |
| 528 | + StringUtils.isBlank(name) || StringUtils.isBlank(phone) || null == user ) { | |
| 522 | 529 | ResultUtils.buildParameterErrorResultAndWrite(response); |
| 523 | 530 | return; |
| 524 | 531 | } |
| 525 | 532 | |
| ... | ... | @@ -569,9 +576,10 @@ |
| 569 | 576 | // users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); |
| 570 | 577 | |
| 571 | 578 | //关联登录中心ID |
| 572 | - LoginContext loginContext = LoginUtil.register(phone, token, typeId); | |
| 579 | + LoginContext loginContext = null; | |
| 580 | + loginContext = LoginUtil.register(null, phone, null, null, token, typeId); | |
| 573 | 581 | //0 成功 4009 已注册 |
| 574 | - if (loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 582 | + if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 575 | 583 | users.setLogincenterId(loginContext.getId()); |
| 576 | 584 | usersService.addUsers(users); |
| 577 | 585 | |
| ... | ... | @@ -580,7 +588,7 @@ |
| 580 | 588 | UserRoleMaps userRoleMaps = new UserRoleMaps(); |
| 581 | 589 | |
| 582 | 590 | String[] roleArrayIds = roleIds.split(","); |
| 583 | - List<Users> user1 = usersService.queryUsers(usersQuery); | |
| 591 | + List<Users> user1 = usersService.queryUsers(usersQuery); | |
| 584 | 592 | for (String id : roleArrayIds) { |
| 585 | 593 | Roles roles = rolesService.getRoles(Integer.valueOf(id)); |
| 586 | 594 | if (roles == null || roles.getYn() == YnEnums.NO.getId()) { |
| ... | ... | @@ -615,8 +623,9 @@ |
| 615 | 623 | @RequestParam(value = "deptId", required = false) Integer deptId, |
| 616 | 624 | @RequestParam(value = "ksId", required = false) Integer ksId, |
| 617 | 625 | @RequestParam(value = "name", required = false) String name, |
| 618 | - @RequestParam(value = "account", required = false) String account, | |
| 619 | - @RequestParam(value = "phone") String phone, | |
| 626 | + @RequestParam(value = "account", required = false)String account, | |
| 627 | + @RequestParam(value = "password", required = false) String password, | |
| 628 | + @RequestParam(value = "phone", required = false) String phone, | |
| 620 | 629 | @RequestParam(value = "enable", required = false) Integer enable, |
| 621 | 630 | @RequestParam(value = "remarks", required = false) String remarks, |
| 622 | 631 | @RequestParam(value = "roleIds") String roleIds) { |
| 623 | 632 | |
| 624 | 633 | |
| 625 | 634 | |
| ... | ... | @@ -627,17 +636,19 @@ |
| 627 | 636 | Users user = usersService.getUsers(loginState.getId()); |
| 628 | 637 | |
| 629 | 638 | |
| 630 | - if (StringUtils.isBlank(roleIds) || StringUtils.isBlank(phone) || null == user) { | |
| 639 | + if (StringUtils.isBlank(roleIds) || null == user|| (StringUtils.isBlank(account) && StringUtils.isBlank(phone))) { | |
| 631 | 640 | ResultUtils.buildParameterErrorResultAndWrite(response); |
| 632 | 641 | return; |
| 633 | 642 | } |
| 634 | 643 | |
| 635 | - if (!isPhone(phone)) { | |
| 644 | + if( StringUtils.isNotBlank(phone) && !isPhone(phone)) { | |
| 636 | 645 | ResultUtils.buildParameterErrorResultAndWrite(response, "手机号格式不正确"); |
| 637 | 646 | return; |
| 647 | + } else if(StringUtils.isNotBlank(account) && StringUtils.isBlank(password)) { | |
| 648 | + password = defaultPwd; | |
| 638 | 649 | } |
| 639 | 650 | |
| 640 | - if (deptId == null && ksId == null) { | |
| 651 | + if(deptId == null && ksId == null) { | |
| 641 | 652 | ResultUtils.buildParameterErrorResultAndWrite(response, "deptId or ksId required"); |
| 642 | 653 | return; |
| 643 | 654 | } |
| 644 | 655 | |
| 645 | 656 | |
| ... | ... | @@ -651,20 +662,34 @@ |
| 651 | 662 | return; |
| 652 | 663 | }*/ |
| 653 | 664 | if (user != null) { |
| 654 | - | |
| 655 | - //检查注册账户是否存在 | |
| 656 | 665 | UsersQuery usersQuery = new UsersQuery(); |
| 657 | - usersQuery.setPhone(phone); | |
| 658 | - usersQuery.setYn(YnEnums.YES.getId()); | |
| 659 | - List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 660 | - if (usersList.size() != 0) { | |
| 661 | - Map<String, Object> map = new HashMap<>(); | |
| 662 | - map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 663 | - map.put(ResultUtils.ERROR_MSG, "用户已存在"); | |
| 664 | - writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 665 | - return; | |
| 666 | + if(StringUtils.isNotBlank(phone)) { | |
| 667 | + //检查注册账户是否存在 | |
| 668 | + usersQuery.setPhone(phone); | |
| 669 | + usersQuery.setYn(YnEnums.YES.getId()); | |
| 670 | + List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 671 | + if (usersList.size() != 0) { | |
| 672 | + Map<String, Object> map = new HashMap<>(); | |
| 673 | + map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 674 | + map.put(ResultUtils.ERROR_MSG, "该手机号已使用"); | |
| 675 | + writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 676 | + return; | |
| 677 | + } | |
| 666 | 678 | } |
| 667 | 679 | |
| 680 | + if(StringUtils.isNotBlank(account)) { | |
| 681 | + usersQuery = new UsersQuery(); | |
| 682 | + usersQuery.setAccount(account); | |
| 683 | + usersQuery.setYn(YnEnums.YES.getId()); | |
| 684 | + if(0 != usersService.queryUsersCount(usersQuery)) { | |
| 685 | + Map<String, Object> map = new HashMap<>(); | |
| 686 | + map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 687 | + map.put(ResultUtils.ERROR_MSG, "该账户已存在"); | |
| 688 | + writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 689 | + return; | |
| 690 | + } | |
| 691 | + } | |
| 692 | + | |
| 668 | 693 | //准备添加数据 |
| 669 | 694 | Users users = new Users(); |
| 670 | 695 | users.setType(UserTypeEnum.NORMAL_USER.getId()); //1普通用户 |
| ... | ... | @@ -674,6 +699,7 @@ |
| 674 | 699 | users.setAccount(account); |
| 675 | 700 | users.setPhone(phone); |
| 676 | 701 | users.setEnable(enable); |
| 702 | + users.setPwd(password); | |
| 677 | 703 | users.setRemarks(remarks); |
| 678 | 704 | users.setKsId(ksId); |
| 679 | 705 | users.setPublishId(user.getId()); |
| 680 | 706 | |
| 681 | 707 | |
| ... | ... | @@ -684,10 +710,19 @@ |
| 684 | 710 | users.setLastLoginTime(new Date()); |
| 685 | 711 | // users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); |
| 686 | 712 | |
| 713 | + LoginContext loginContext = null; | |
| 714 | + | |
| 687 | 715 | //关联登录中心ID |
| 688 | - LoginContext loginContext = LoginUtil.register(phone, token, typeId); | |
| 716 | + if(StringUtils.isNotBlank(phone) || StringUtils.isNotBlank(account)) { | |
| 717 | + String pwd = null; | |
| 718 | + if(StringUtils.isNotBlank(password)) { | |
| 719 | + pwd = LoginUtil.md5(password).toUpperCase(); | |
| 720 | + } | |
| 721 | + loginContext = LoginUtil.register(null, phone,account, pwd, token, typeId); | |
| 722 | + } | |
| 723 | + | |
| 689 | 724 | //0 成功 4009 已注册 |
| 690 | - if (loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 725 | + if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 691 | 726 | users.setLogincenterId(loginContext.getId()); |
| 692 | 727 | usersService.addUsers(users); |
| 693 | 728 | |
| ... | ... | @@ -695,7 +730,7 @@ |
| 695 | 730 | UserRoleMaps userRoleMaps = new UserRoleMaps(); |
| 696 | 731 | |
| 697 | 732 | String[] roleArrayIds = roleIds.split(","); |
| 698 | - List<Users> user1 = usersService.queryUsers(usersQuery); | |
| 733 | + List<Users> user1 = usersService.queryUsers(usersQuery); | |
| 699 | 734 | for (String id : roleArrayIds) { |
| 700 | 735 | Roles roles = rolesService.getRoles(Integer.valueOf(id)); |
| 701 | 736 | if (roles == null || roles.getYn() == YnEnums.NO.getId()) { |
| ... | ... | @@ -718,102 +753,6 @@ |
| 718 | 753 | } |
| 719 | 754 | |
| 720 | 755 | |
| 721 | -// /** | |
| 722 | -// * 添加用户信息 | |
| 723 | -// */ | |
| 724 | -// @RequestMapping(value = "/users", method = RequestMethod.POST) | |
| 725 | -// @TokenRequired | |
| 726 | -// public void addUsers(HttpServletResponse response, | |
| 727 | -// HttpServletRequest request, | |
| 728 | -// @RequestParam(value = "type") Integer type, | |
| 729 | -// @RequestParam(value = "deptId") Integer deptId, | |
| 730 | -// @RequestParam(value = "orgId") Integer orgId, | |
| 731 | -// @RequestParam(value = "name", required = false) String name, | |
| 732 | -// @RequestParam(value = "account", required = false)String account, | |
| 733 | -// @RequestParam(value = "phone") String phone, | |
| 734 | -// @RequestParam(value = "enable") Integer enable, | |
| 735 | -// @RequestParam(value = "remarks", required = false) String remarks, | |
| 736 | -// @RequestParam(value = "roleIds") String roleIds) { | |
| 737 | -// | |
| 738 | -// | |
| 739 | -// //获取登录用户 | |
| 740 | -// LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | |
| 741 | -// Users user = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 742 | -// | |
| 743 | -// Departments departments = departmentsService.getDepartments(deptId); | |
| 744 | -// Organization organization = organizationService.getOrganization(orgId); | |
| 745 | -// | |
| 746 | -// if (type == null || StringUtils.isBlank(roleIds) || deptId == null || | |
| 747 | -// StringUtils.isBlank(name) || StringUtils.isBlank(phone) || null == user || null == departments || null == organization) { | |
| 748 | -// ResultUtils.buildParameterErrorResultAndWrite(response); | |
| 749 | -// return; | |
| 750 | -// } | |
| 751 | -// | |
| 752 | -// if (user != null) { | |
| 753 | -// | |
| 754 | -// //检查注册账户是否存在 | |
| 755 | -// UsersQuery usersQuery = new UsersQuery(); | |
| 756 | -// usersQuery.setPhone(phone); | |
| 757 | -// List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 758 | -// if (usersList.size() != 0) { | |
| 759 | -// Map<String, Object> map = new HashMap<>(); | |
| 760 | -// map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 761 | -// map.put(ResultUtils.ERROR_MSG, "用户已存在"); | |
| 762 | -// writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 763 | -// return; | |
| 764 | -// } | |
| 765 | -// | |
| 766 | -// //准备添加数据 | |
| 767 | -// Users users = new Users(); | |
| 768 | -// users.setType(type); | |
| 769 | -// users.setDeptId(deptId); | |
| 770 | -// users.setOrgId(orgId); | |
| 771 | -// users.setName(name); | |
| 772 | -// users.setAccount(account); | |
| 773 | -// users.setPhone(phone); | |
| 774 | -// users.setEnable(enable); | |
| 775 | -// users.setRemarks(remarks); | |
| 776 | -// users.setPublishId(user.getId()); | |
| 777 | -// users.setPublishName(user.getName()); | |
| 778 | -// users.setYn(YnEnums.YES.getId()); | |
| 779 | -// users.setModified(new Date()); | |
| 780 | -// users.setCreated(new Date()); | |
| 781 | -// users.setLastLoginTime(new Date()); | |
| 782 | -//// users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); | |
| 783 | -// | |
| 784 | -// //关联登录中心ID | |
| 785 | -// Integer loginCenterId = LoginUtil.register(phone, token, typeId); | |
| 786 | -// if(null == loginCenterId) { | |
| 787 | -// ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.SYSTEM_ERROR, "服务器内部错误"); | |
| 788 | -// return; | |
| 789 | -// } | |
| 790 | -// users.setLogincenterId(loginCenterId); | |
| 791 | -// | |
| 792 | -// usersService.addUsers(users); | |
| 793 | -// | |
| 794 | -// | |
| 795 | -// //如有角色,则对用户角色中间表新增 | |
| 796 | -// UserRoleMaps userRoleMaps = new UserRoleMaps(); | |
| 797 | -// | |
| 798 | -// String[] roleArrayIds = roleIds.split(","); | |
| 799 | -// List<Users> user1 = usersService.queryUsers(usersQuery); | |
| 800 | -// for (String id : roleArrayIds) { | |
| 801 | -// Roles roles = rolesService.getRoles(Integer.valueOf(id)); | |
| 802 | -// if (roles == null || roles.getYn() == YnEnums.NO.getId()) { | |
| 803 | -// continue; | |
| 804 | -// } | |
| 805 | -// | |
| 806 | -// if (user1.get(0).getId() != null) { | |
| 807 | -// userRoleMaps.setRoleId(Integer.valueOf(Integer.valueOf(id))); | |
| 808 | -// userRoleMaps.setUserId(user1.get(0).getId()); | |
| 809 | -// userRoleMaps.setYn(YnEnums.YES.getId()); | |
| 810 | -// userRoleMapsService.addUserRoleMaps(userRoleMaps); | |
| 811 | -// } | |
| 812 | -// } | |
| 813 | -// ResultUtils.buildSuccessResultAndWrite(response); | |
| 814 | -// } | |
| 815 | -// } | |
| 816 | - | |
| 817 | 756 | /** |
| 818 | 757 | * 用户修改 |
| 819 | 758 | */ |
| 820 | 759 | |
| 821 | 760 | |
| ... | ... | @@ -822,21 +761,22 @@ |
| 822 | 761 | public void updateUsers(HttpServletResponse response, |
| 823 | 762 | HttpServletRequest request, |
| 824 | 763 | @PathVariable(value = "id") Integer id, |
| 825 | - @RequestParam(value = "name", required = false) String name, | |
| 826 | - @RequestParam(value = "account", required = false) String account, | |
| 827 | - @RequestParam(value = "phone", required = false) String phone, | |
| 828 | - @RequestParam(value = "enable", required = false) Integer enable, | |
| 829 | - @RequestParam(value = "remarks", required = false) String remarks, | |
| 830 | - @RequestParam(value = "roleIds", required = false) String roleIds, | |
| 831 | - @RequestParam(value = "orgId", required = false) Integer orgId, | |
| 832 | - @RequestParam(value = "deptId", required = false) Integer deptId) { | |
| 764 | + @RequestParam(value = "name",required = false) String name, | |
| 765 | + @RequestParam(value = "account",required = false)String account, | |
| 766 | + @RequestParam(value = "password",required = false)String password, | |
| 767 | + @RequestParam(value = "phone",required = false) String phone, | |
| 768 | + @RequestParam(value = "enable",required = false) Integer enable, | |
| 769 | + @RequestParam(value = "remarks",required = false) String remarks, | |
| 770 | + @RequestParam(value = "roleIds",required = false) String roleIds, | |
| 771 | + @RequestParam(value = "orgId",required = false) Integer orgId, | |
| 772 | + @RequestParam(value = "deptId",required = false) Integer deptId) { | |
| 833 | 773 | |
| 834 | - if (null == roleIds) { | |
| 774 | + if(null == roleIds) { | |
| 835 | 775 | ResultUtils.buildParameterErrorResultAndWrite(response, "roleIds不能为空"); |
| 836 | 776 | return; |
| 837 | 777 | } |
| 838 | 778 | |
| 839 | - if (!(null != enable && (1 == enable || 2 == enable))) { | |
| 779 | + if(!(null != enable && (1 == enable || 2 == enable))) { | |
| 840 | 780 | ResultUtils.buildParameterErrorResultAndWrite(response, "enable参数错误"); |
| 841 | 781 | return; |
| 842 | 782 | } |
| 843 | 783 | |
| ... | ... | @@ -847,9 +787,13 @@ |
| 847 | 787 | if (user != null) { |
| 848 | 788 | |
| 849 | 789 | Users users = usersService.getUsers(id); |
| 850 | - if (null != users.getOtherAccount() && "1".equals(user.getOtherAccount() + "")) { | |
| 790 | + if(null!=users.getOtherAccount()&&"1".equals(user.getOtherAccount()+"")){ | |
| 851 | 791 | return; |
| 852 | 792 | } |
| 793 | + if(password.matches("^\\**$")) { | |
| 794 | + password = users.getPwd(); | |
| 795 | + } | |
| 796 | + | |
| 853 | 797 | //根据当前登录的用户判断是否 有管理员的权限 |
| 854 | 798 | /* List<String> list = userRoleMapsService.queryUserRoleName(loginState.getId()); |
| 855 | 799 | if(CollectionUtils.isEmpty(list) ||!list.contains(ADMIN)){ |
| ... | ... | @@ -859,7 +803,7 @@ |
| 859 | 803 | writeJson(response, JsonUtil.obj2JsonString(map)); |
| 860 | 804 | return; |
| 861 | 805 | }*/ |
| 862 | - if (null == users) { | |
| 806 | + if(null == users) { | |
| 863 | 807 | Map<String, Object> map = new HashMap<>(); |
| 864 | 808 | map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); |
| 865 | 809 | map.put(ResultUtils.ERROR_MSG, "用户不存在"); |
| 866 | 810 | |
| 867 | 811 | |
| 868 | 812 | |
| 869 | 813 | |
| ... | ... | @@ -868,35 +812,57 @@ |
| 868 | 812 | } |
| 869 | 813 | |
| 870 | 814 | |
| 871 | - //修改了手机号,不能修改已存在的手机号 | |
| 872 | - if (!new Integer(1).equals(users.getOtherAccount()) && !phone.equals(users.getPhone())) { | |
| 873 | - //检查账户是否存在 | |
| 874 | - UsersQuery usersQuery = new UsersQuery(); | |
| 875 | - usersQuery.setPhone(phone); | |
| 876 | - usersQuery.setYn(YnEnums.YES.getId()); | |
| 877 | - List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 878 | - if (0 < usersList.size()) { | |
| 879 | - Map<String, Object> map = new HashMap<>(); | |
| 880 | - map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 881 | - map.put(ResultUtils.ERROR_MSG, "手机号已存在"); | |
| 882 | - writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 883 | - return; | |
| 884 | - } | |
| 815 | + //修改了手机号, 帐号 密码 | |
| 816 | + if(!new Integer(1).equals(users.getOtherAccount())) { | |
| 817 | + if((StringUtils.isNotBlank(account) && !account.equals(users.getAccount())) || (StringUtils.isNotBlank(phone) && !phone.equals(users.getPhone())) || (StringUtils.isNotBlank(password) && !password.equals(users.getPwd()))) { | |
| 818 | + UsersQuery usersQuery = new UsersQuery(); | |
| 819 | + List<Users> usersList; | |
| 820 | + if(StringUtils.isNotBlank(phone) && !phone.equals(users.getPhone())) { | |
| 821 | + //检查手机号是否存在 | |
| 822 | + usersQuery.setPhone(phone); | |
| 823 | + usersQuery.setYn(YnEnums.YES.getId()); | |
| 824 | + usersList = usersService.queryUsers(usersQuery); | |
| 825 | + if (0 < usersList.size()) { | |
| 826 | + Map<String, Object> map = new HashMap<>(); | |
| 827 | + map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 828 | + map.put(ResultUtils.ERROR_MSG, "手机号已存在"); | |
| 829 | + writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 830 | + return; | |
| 831 | + } | |
| 832 | + } | |
| 885 | 833 | |
| 834 | + if(StringUtils.isNotBlank(account) && !account.equals(users.getAccount())) { | |
| 835 | + //检查账户是否存在 | |
| 836 | + usersQuery = new UsersQuery(); | |
| 837 | + usersQuery.setAccount(account); | |
| 838 | + usersQuery.setYn(YnEnums.YES.getId()); | |
| 839 | + usersList = usersService.queryUsers(usersQuery); | |
| 840 | + if (0 < usersList.size()) { | |
| 841 | + Map<String, Object> map = new HashMap<>(); | |
| 842 | + map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 843 | + map.put(ResultUtils.ERROR_MSG, "该帐号已存在"); | |
| 844 | + writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 845 | + return; | |
| 846 | + } | |
| 847 | + } | |
| 886 | 848 | |
| 887 | - LoginContext loginContext = LoginUtil.register(phone, token, typeId); | |
| 888 | - //0 成功 4009 已注册 | |
| 889 | - if (loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 890 | - users.setPhone(phone); | |
| 891 | - users.setLogincenterId(loginContext.getId()); | |
| 892 | - } else { | |
| 893 | - ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.SYSTEM_ERROR, loginContext.getErrormsg()); | |
| 894 | - return; | |
| 849 | + | |
| 850 | + | |
| 851 | + LoginContext loginContext = LoginUtil.register(users.getLogincenterId().toString(), phone, account, LoginUtil.md5(password).toUpperCase(), token, typeId); | |
| 852 | + //0 成功 4009 已注册 | |
| 853 | + if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 854 | + users.setPhone(phone); | |
| 855 | + users.setAccount(account); | |
| 856 | + users.setLogincenterId(loginContext.getId()); | |
| 857 | + } else { | |
| 858 | + ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.SYSTEM_ERROR, loginContext.getErrormsg()); | |
| 859 | + return; | |
| 860 | + } | |
| 895 | 861 | } |
| 896 | 862 | } |
| 897 | 863 | |
| 864 | + users.setPwd(password); | |
| 898 | 865 | users.setName(name); |
| 899 | - users.setAccount(account); | |
| 900 | 866 | users.setEnable(enable); |
| 901 | 867 | users.setRemarks(remarks); |
| 902 | 868 | users.setModified(new Date()); |
| 903 | 869 | |
| 904 | 870 | |
| 905 | 871 | |
| 906 | 872 | |
| 907 | 873 | |
| ... | ... | @@ -907,24 +873,33 @@ |
| 907 | 873 | |
| 908 | 874 | |
| 909 | 875 | //如有角色,则对用户角色中间表先删除后新增 |
| 910 | - if (null != roleIds) { | |
| 876 | + if(StringUtils.isNotBlank(roleIds)) { | |
| 877 | + | |
| 878 | + UserRoleMapsQuery userRoleMapsQuery = new UserRoleMapsQuery(); | |
| 879 | + userRoleMapsQuery.setUserId(users.getId()); | |
| 880 | + userRoleMapsQuery.setYn(YnEnums.YES.getId()); | |
| 881 | + List<UserRoleMaps> userRoleMapses = userRoleMapsService.queryUserRoleMaps(userRoleMapsQuery); | |
| 882 | + | |
| 883 | + | |
| 911 | 884 | String[] roleArrayIds = roleIds.split(","); |
| 912 | 885 | //判断角色是否有更新 |
| 913 | 886 | Boolean flag = false; |
| 914 | - if (null == users.getRoles()) flag = true; | |
| 915 | - if (!flag) { | |
| 887 | + if(CollectionUtils.isEmpty(userRoleMapses) || roleArrayIds.length != userRoleMapses.size()) flag = true; | |
| 888 | + if(!flag) { | |
| 916 | 889 | for (String s : roleArrayIds) { |
| 917 | - for (Roles role : users.getRoles()) { | |
| 918 | - if (s.equals(role.getId().toString())) continue; | |
| 919 | - flag = true; | |
| 890 | + boolean exist = false; | |
| 891 | + for(UserRoleMaps role : userRoleMapses) { | |
| 892 | + if(s.equals(role.getRoleId().toString())) { | |
| 893 | + exist = true; | |
| 894 | + } | |
| 920 | 895 | } |
| 921 | - if (flag) break; | |
| 896 | + if(!exist) break; | |
| 922 | 897 | } |
| 923 | 898 | } |
| 924 | 899 | |
| 925 | - if (flag) { | |
| 900 | + if(flag) { | |
| 926 | 901 | Integer _userId = users.getId(); |
| 927 | - UserRoleMapsQuery userRoleMapsQuery = new UserRoleMapsQuery(); | |
| 902 | + userRoleMapsQuery = new UserRoleMapsQuery(); | |
| 928 | 903 | userRoleMapsQuery.setUserId(_userId); |
| 929 | 904 | List<UserRoleMaps> roleMapsList = userRoleMapsService.queryUserRoleMaps(userRoleMapsQuery); |
| 930 | 905 | for (UserRoleMaps userRoleMaps : roleMapsList) { |
| ... | ... | @@ -935,7 +910,7 @@ |
| 935 | 910 | |
| 936 | 911 | UserRoleMaps userRoleMaps = new UserRoleMaps(); |
| 937 | 912 | for (String tmp : roleArrayIds) { |
| 938 | - if (StringUtils.isEmpty(tmp)) { | |
| 913 | + if(StringUtils.isEmpty(tmp)){ | |
| 939 | 914 | continue; |
| 940 | 915 | } |
| 941 | 916 | Roles roles = rolesService.getRoles(Integer.valueOf(tmp)); |
| ... | ... | @@ -961,7 +936,7 @@ |
| 961 | 936 | */ |
| 962 | 937 | @RequestMapping(value = "/users/enable", method = RequestMethod.POST) |
| 963 | 938 | @TokenRequired |
| 964 | - public void enableUsers(HttpServletResponse response, @RequestParam Integer id, @RequestParam Integer flag) { | |
| 939 | + public void enableUsers(HttpServletResponse response,@RequestParam Integer id, @RequestParam Integer flag) { | |
| 965 | 940 | |
| 966 | 941 | |
| 967 | 942 | //检查账户是否存在 |
| ... | ... | @@ -975,10 +950,10 @@ |
| 975 | 950 | writeJson(response, JsonUtil.obj2JsonString(map)); |
| 976 | 951 | return; |
| 977 | 952 | } |
| 978 | - Users users = null; | |
| 979 | - if (CollectionUtils.isNotEmpty(usersList)) { | |
| 980 | - users = usersList.get(0); | |
| 981 | - if (null != users.getOtherAccount() && "1".equals(users.getOtherAccount() + "")) { | |
| 953 | + Users users =null; | |
| 954 | + if(CollectionUtils.isNotEmpty(usersList)){ | |
| 955 | + users =usersList.get(0); | |
| 956 | + if(null!=users.getOtherAccount()&&"1".equals(users.getOtherAccount()+"")){ | |
| 982 | 957 | return; |
| 983 | 958 | } |
| 984 | 959 | } |
| 985 | 960 | |
| ... | ... | @@ -992,12 +967,14 @@ |
| 992 | 967 | } |
| 993 | 968 | |
| 994 | 969 | |
| 970 | + | |
| 971 | + | |
| 995 | 972 | /** |
| 996 | 973 | * 用户删除 |
| 997 | 974 | */ |
| 998 | 975 | @RequestMapping(value = "/users/{id}", method = RequestMethod.DELETE) |
| 999 | 976 | @TokenRequired |
| 1000 | - public void deleteUsers(HttpServletResponse response, @PathVariable Integer id) { | |
| 977 | + public void deleteUsers(HttpServletResponse response,@PathVariable Integer id) { | |
| 1001 | 978 | if (null == id) { |
| 1002 | 979 | ResultUtils.buildIdIsNull(response); |
| 1003 | 980 | return; |
| 1004 | 981 | |
| 1005 | 982 | |
| 1006 | 983 | |
| 1007 | 984 | |
| 1008 | 985 | |
| 1009 | 986 | |
| ... | ... | @@ -1039,62 +1016,30 @@ |
| 1039 | 1016 | } |
| 1040 | 1017 | |
| 1041 | 1018 | |
| 1042 | - /** | |
| 1043 | - * 修改用户密码 | |
| 1044 | - */ | |
| 1045 | - @RequestMapping(value = "/passwords", method = RequestMethod.PUT) | |
| 1046 | - @TokenRequired | |
| 1047 | - public void updateUserPwd(HttpServletResponse httpServletResponse, | |
| 1048 | - HttpServletRequest request, | |
| 1049 | - @RequestParam(value = "oldPwd") String oldPwd, | |
| 1050 | - @RequestParam(value = "newPwd") String newPwd) { | |
| 1051 | - Map<String, Object> resultMsgMap = new HashMap<String, Object>(); | |
| 1052 | - if (StringUtils.isBlank(oldPwd) || StringUtils.isBlank(newPwd)) { | |
| 1053 | - ResultUtils.buildParameterErrorResultAndWrite(httpServletResponse); | |
| 1054 | - return; | |
| 1055 | - } | |
| 1056 | - //获取登录用户 | |
| 1057 | - LoginContext loginContext = (LoginContext) request.getAttribute("loginContext"); | |
| 1058 | - Users users = usersService.getUsers(loginContext.getId()); | |
| 1059 | 1019 | |
| 1060 | - if (null != users) { | |
| 1061 | - //修改前的密码 | |
| 1062 | 1020 | |
| 1063 | - //验证之前的密码和数据库中的密码是否一致 | |
| 1064 | - if (null != users && LoginUtil.md5(oldPwd).equals(users.getPwd()) && !LoginUtil.md5(newPwd).equals(users.getPwd())) { | |
| 1065 | 1021 | |
| 1066 | - Users newUsers = new Users(); | |
| 1067 | - newUsers.setPwd(LoginUtil.md5(newPwd)); | |
| 1068 | - newUsers.setModified(new Date()); | |
| 1069 | - newUsers.setId(users.getId()); | |
| 1070 | - | |
| 1071 | - //修改数据库的值 | |
| 1072 | - usersService.updateUsers(newUsers); | |
| 1073 | - ResultUtils.buildSuccessResultAndWrite(httpServletResponse); | |
| 1074 | - } else { | |
| 1075 | - resultMsgMap.put(ResultUtils.ERROR_CODE, ConstantInterface.USER_PASSWORD_ERROR); | |
| 1076 | - resultMsgMap.put(ResultUtils.ERROR_MSG, "旧密码错误或新密码和旧密码相同"); | |
| 1077 | - writeJson(httpServletResponse, JsonUtil.obj2JsonString(resultMsgMap)); | |
| 1078 | - } | |
| 1079 | - } | |
| 1080 | - } | |
| 1081 | - | |
| 1082 | - | |
| 1083 | 1022 | /** |
| 1084 | 1023 | * 重置用户密码 |
| 1085 | 1024 | */ |
| 1086 | 1025 | @RequestMapping(value = "/passwords/reset", method = RequestMethod.PUT) |
| 1087 | 1026 | @TokenRequired |
| 1088 | - public void updatePassword(HttpServletResponse response, @RequestParam(value = "id") Integer id) { | |
| 1089 | - Users users = usersService.getUsers(id); | |
| 1027 | + public void updatePassword(HttpServletResponse response, @RequestParam(value = "userId") String id) { | |
| 1028 | + Users users = usersService.getUsers(Integer.valueOf(id)); | |
| 1090 | 1029 | if (users == null) { |
| 1091 | 1030 | ResultUtils.buildParameterErrorResultAndWrite(response, "用户ID不存在"); |
| 1092 | 1031 | return; |
| 1093 | 1032 | } |
| 1094 | - users.setPwd(LoginUtil.md5("123456")); | |
| 1033 | + users.setPwd(defaultPwd); | |
| 1095 | 1034 | users.setModified(new Date()); |
| 1096 | 1035 | usersService.updateUsers(users); |
| 1097 | - ResultUtils.buildSuccessResultAndWrite(response); | |
| 1036 | + LoginContext loginContext = LoginUtil.register(users.getLogincenterId().toString(), users.getPhone(),users.getAccount(), LoginUtil.md5(defaultPwd).toUpperCase(), token, typeId); | |
| 1037 | + if(loginContext.getErrorcode().equals(0)) { | |
| 1038 | + ResultUtils.buildSuccessResultAndWrite(response); | |
| 1039 | + } else { | |
| 1040 | + ResultUtils.buildResultAndWrite(response,ErrorCodeConstants.SYSTEM_ERROR, "系统错误"); | |
| 1041 | + } | |
| 1042 | + | |
| 1098 | 1043 | } |
| 1099 | 1044 | |
| 1100 | 1045 | @RequestMapping(value = "/logout", method = RequestMethod.GET) |