Commit 43f455fc994fef6d9ddd4925f00a982fa8721486
1 parent
1cdde2f1a6
Exists in
master
and in
8 other branches
bug fix
添加用户时增加用户名密码登录
Showing 4 changed files with 194 additions and 166 deletions
- 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 @
43f455f
| ... | ... | @@ -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 @
43f455f
| ... | ... | @@ -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 @
43f455f
| ... | ... | @@ -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 |
| ... | ... | @@ -186,7 +188,7 @@ |
| 186 | 188 | user.setRoles(this.getUserRoles(user.getId())); |
| 187 | 189 | user.setDepartmentses(departmentsService.getDepartments(user.getDeptId())); |
| 188 | 190 | |
| 189 | - user.setPwd(null); | |
| 191 | + user.setPwd(user.getPwd().replaceAll(".","*")); | |
| 190 | 192 | } |
| 191 | 193 | |
| 192 | 194 | FrontEndResult frontEndResult = new FrontEndResult(); |
| ... | ... | @@ -244,7 +246,8 @@ |
| 244 | 246 | return; |
| 245 | 247 | } |
| 246 | 248 | |
| 247 | - if(!users.get(0).getEnable().equals(1)) { | |
| 249 | + Users u = users.get(0); | |
| 250 | + if(!u.getEnable().equals(1)) { | |
| 248 | 251 | ResultUtils.buildParameterErrorResultAndWrite(response, "该账户已被禁用"); |
| 249 | 252 | return; |
| 250 | 253 | } |
| 251 | 254 | |
| ... | ... | @@ -252,10 +255,10 @@ |
| 252 | 255 | LoginContext loginContext = new LoginContext(); |
| 253 | 256 | loginContext.setErrormsg("服务器内部错误!"); |
| 254 | 257 | if(null != code) { |
| 255 | - loginContext =LoginUtil.login(account, code, typeId, token); | |
| 258 | + loginContext =LoginUtil.loginByPhone(account, code, typeId, token); | |
| 256 | 259 | } |
| 257 | 260 | if(null != password) { |
| 258 | - loginContext = LoginUtil.loginHospitalUser(account, password, typeId, token); | |
| 261 | + loginContext = LoginUtil.loginByAccount(account, password, typeId, token); | |
| 259 | 262 | } |
| 260 | 263 | |
| 261 | 264 | if(null != loginContext && loginContext.getErrorcode().equals(0)) { |
| ... | ... | @@ -573,7 +576,8 @@ |
| 573 | 576 | // users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); |
| 574 | 577 | |
| 575 | 578 | //关联登录中心ID |
| 576 | - LoginContext loginContext = LoginUtil.register(phone, token, typeId); | |
| 579 | + LoginContext loginContext = null; | |
| 580 | + loginContext = LoginUtil.register(null, phone, null, null, token, typeId); | |
| 577 | 581 | //0 成功 4009 已注册 |
| 578 | 582 | if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { |
| 579 | 583 | users.setLogincenterId(loginContext.getId()); |
| ... | ... | @@ -620,7 +624,8 @@ |
| 620 | 624 | @RequestParam(value = "ksId", required = false) Integer ksId, |
| 621 | 625 | @RequestParam(value = "name", required = false) String name, |
| 622 | 626 | @RequestParam(value = "account", required = false)String account, |
| 623 | - @RequestParam(value = "phone") String phone, | |
| 627 | + @RequestParam(value = "password", required = false) String password, | |
| 628 | + @RequestParam(value = "phone", required = false) String phone, | |
| 624 | 629 | @RequestParam(value = "enable", required = false) Integer enable, |
| 625 | 630 | @RequestParam(value = "remarks", required = false) String remarks, |
| 626 | 631 | @RequestParam(value = "roleIds") String roleIds) { |
| 627 | 632 | |
| 628 | 633 | |
| ... | ... | @@ -631,14 +636,16 @@ |
| 631 | 636 | Users user = usersService.getUsers(loginState.getId()); |
| 632 | 637 | |
| 633 | 638 | |
| 634 | - if ( StringUtils.isBlank(roleIds) || StringUtils.isBlank(phone) || null == user ) { | |
| 639 | + if (StringUtils.isBlank(roleIds) || null == user|| (StringUtils.isBlank(account) && StringUtils.isBlank(phone))) { | |
| 635 | 640 | ResultUtils.buildParameterErrorResultAndWrite(response); |
| 636 | 641 | return; |
| 637 | 642 | } |
| 638 | 643 | |
| 639 | - if (!isPhone(phone)) { | |
| 644 | + if( StringUtils.isNotBlank(phone) && !isPhone(phone)) { | |
| 640 | 645 | ResultUtils.buildParameterErrorResultAndWrite(response, "手机号格式不正确"); |
| 641 | 646 | return; |
| 647 | + } else if(StringUtils.isNotBlank(account) && StringUtils.isBlank(password)) { | |
| 648 | + password = defaultPwd; | |
| 642 | 649 | } |
| 643 | 650 | |
| 644 | 651 | if(deptId == null && ksId == null) { |
| 645 | 652 | |
| 646 | 653 | |
| ... | ... | @@ -655,20 +662,34 @@ |
| 655 | 662 | return; |
| 656 | 663 | }*/ |
| 657 | 664 | if (user != null) { |
| 658 | - | |
| 659 | - //检查注册账户是否存在 | |
| 660 | 665 | UsersQuery usersQuery = new UsersQuery(); |
| 661 | - usersQuery.setPhone(phone); | |
| 662 | - usersQuery.setYn(YnEnums.YES.getId()); | |
| 663 | - List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 664 | - if (usersList.size() != 0) { | |
| 665 | - Map<String, Object> map = new HashMap<>(); | |
| 666 | - map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 667 | - map.put(ResultUtils.ERROR_MSG, "用户已存在"); | |
| 668 | - writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 669 | - 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 | + } | |
| 670 | 678 | } |
| 671 | 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 | + | |
| 672 | 693 | //准备添加数据 |
| 673 | 694 | Users users = new Users(); |
| 674 | 695 | users.setType(UserTypeEnum.NORMAL_USER.getId()); //1普通用户 |
| ... | ... | @@ -678,6 +699,7 @@ |
| 678 | 699 | users.setAccount(account); |
| 679 | 700 | users.setPhone(phone); |
| 680 | 701 | users.setEnable(enable); |
| 702 | + users.setPwd(password); | |
| 681 | 703 | users.setRemarks(remarks); |
| 682 | 704 | users.setKsId(ksId); |
| 683 | 705 | users.setPublishId(user.getId()); |
| 684 | 706 | |
| ... | ... | @@ -688,8 +710,17 @@ |
| 688 | 710 | users.setLastLoginTime(new Date()); |
| 689 | 711 | // users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); |
| 690 | 712 | |
| 713 | + LoginContext loginContext = null; | |
| 714 | + | |
| 691 | 715 | //关联登录中心ID |
| 692 | - 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 | + | |
| 693 | 724 | //0 成功 4009 已注册 |
| 694 | 725 | if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { |
| 695 | 726 | users.setLogincenterId(loginContext.getId()); |
| ... | ... | @@ -722,103 +753,6 @@ |
| 722 | 753 | } |
| 723 | 754 | |
| 724 | 755 | |
| 725 | - | |
| 726 | -// /** | |
| 727 | -// * 添加用户信息 | |
| 728 | -// */ | |
| 729 | -// @RequestMapping(value = "/users", method = RequestMethod.POST) | |
| 730 | -// @TokenRequired | |
| 731 | -// public void addUsers(HttpServletResponse response, | |
| 732 | -// HttpServletRequest request, | |
| 733 | -// @RequestParam(value = "type") Integer type, | |
| 734 | -// @RequestParam(value = "deptId") Integer deptId, | |
| 735 | -// @RequestParam(value = "orgId") Integer orgId, | |
| 736 | -// @RequestParam(value = "name", required = false) String name, | |
| 737 | -// @RequestParam(value = "account", required = false)String account, | |
| 738 | -// @RequestParam(value = "phone") String phone, | |
| 739 | -// @RequestParam(value = "enable") Integer enable, | |
| 740 | -// @RequestParam(value = "remarks", required = false) String remarks, | |
| 741 | -// @RequestParam(value = "roleIds") String roleIds) { | |
| 742 | -// | |
| 743 | -// | |
| 744 | -// //获取登录用户 | |
| 745 | -// LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); | |
| 746 | -// Users user = usersService.getUsersByLoginCenterId(loginState.getId()); | |
| 747 | -// | |
| 748 | -// Departments departments = departmentsService.getDepartments(deptId); | |
| 749 | -// Organization organization = organizationService.getOrganization(orgId); | |
| 750 | -// | |
| 751 | -// if (type == null || StringUtils.isBlank(roleIds) || deptId == null || | |
| 752 | -// StringUtils.isBlank(name) || StringUtils.isBlank(phone) || null == user || null == departments || null == organization) { | |
| 753 | -// ResultUtils.buildParameterErrorResultAndWrite(response); | |
| 754 | -// return; | |
| 755 | -// } | |
| 756 | -// | |
| 757 | -// if (user != null) { | |
| 758 | -// | |
| 759 | -// //检查注册账户是否存在 | |
| 760 | -// UsersQuery usersQuery = new UsersQuery(); | |
| 761 | -// usersQuery.setPhone(phone); | |
| 762 | -// List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 763 | -// if (usersList.size() != 0) { | |
| 764 | -// Map<String, Object> map = new HashMap<>(); | |
| 765 | -// map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 766 | -// map.put(ResultUtils.ERROR_MSG, "用户已存在"); | |
| 767 | -// writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 768 | -// return; | |
| 769 | -// } | |
| 770 | -// | |
| 771 | -// //准备添加数据 | |
| 772 | -// Users users = new Users(); | |
| 773 | -// users.setType(type); | |
| 774 | -// users.setDeptId(deptId); | |
| 775 | -// users.setOrgId(orgId); | |
| 776 | -// users.setName(name); | |
| 777 | -// users.setAccount(account); | |
| 778 | -// users.setPhone(phone); | |
| 779 | -// users.setEnable(enable); | |
| 780 | -// users.setRemarks(remarks); | |
| 781 | -// users.setPublishId(user.getId()); | |
| 782 | -// users.setPublishName(user.getName()); | |
| 783 | -// users.setYn(YnEnums.YES.getId()); | |
| 784 | -// users.setModified(new Date()); | |
| 785 | -// users.setCreated(new Date()); | |
| 786 | -// users.setLastLoginTime(new Date()); | |
| 787 | -//// users.setPwd(LoginUtil.md5(NumberUtils.getRandomString(6))); | |
| 788 | -// | |
| 789 | -// //关联登录中心ID | |
| 790 | -// Integer loginCenterId = LoginUtil.register(phone, token, typeId); | |
| 791 | -// if(null == loginCenterId) { | |
| 792 | -// ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.SYSTEM_ERROR, "服务器内部错误"); | |
| 793 | -// return; | |
| 794 | -// } | |
| 795 | -// users.setLogincenterId(loginCenterId); | |
| 796 | -// | |
| 797 | -// usersService.addUsers(users); | |
| 798 | -// | |
| 799 | -// | |
| 800 | -// //如有角色,则对用户角色中间表新增 | |
| 801 | -// UserRoleMaps userRoleMaps = new UserRoleMaps(); | |
| 802 | -// | |
| 803 | -// String[] roleArrayIds = roleIds.split(","); | |
| 804 | -// List<Users> user1 = usersService.queryUsers(usersQuery); | |
| 805 | -// for (String id : roleArrayIds) { | |
| 806 | -// Roles roles = rolesService.getRoles(Integer.valueOf(id)); | |
| 807 | -// if (roles == null || roles.getYn() == YnEnums.NO.getId()) { | |
| 808 | -// continue; | |
| 809 | -// } | |
| 810 | -// | |
| 811 | -// if (user1.get(0).getId() != null) { | |
| 812 | -// userRoleMaps.setRoleId(Integer.valueOf(Integer.valueOf(id))); | |
| 813 | -// userRoleMaps.setUserId(user1.get(0).getId()); | |
| 814 | -// userRoleMaps.setYn(YnEnums.YES.getId()); | |
| 815 | -// userRoleMapsService.addUserRoleMaps(userRoleMaps); | |
| 816 | -// } | |
| 817 | -// } | |
| 818 | -// ResultUtils.buildSuccessResultAndWrite(response); | |
| 819 | -// } | |
| 820 | -// } | |
| 821 | - | |
| 822 | 756 | /** |
| 823 | 757 | * 用户修改 |
| 824 | 758 | */ |
| ... | ... | @@ -829,6 +763,7 @@ |
| 829 | 763 | @PathVariable(value = "id") Integer id, |
| 830 | 764 | @RequestParam(value = "name",required = false) String name, |
| 831 | 765 | @RequestParam(value = "account",required = false)String account, |
| 766 | + @RequestParam(value = "password",required = false)String password, | |
| 832 | 767 | @RequestParam(value = "phone",required = false) String phone, |
| 833 | 768 | @RequestParam(value = "enable",required = false) Integer enable, |
| 834 | 769 | @RequestParam(value = "remarks",required = false) String remarks, |
| ... | ... | @@ -855,6 +790,10 @@ |
| 855 | 790 | if(null!=users.getOtherAccount()&&"1".equals(user.getOtherAccount()+"")){ |
| 856 | 791 | return; |
| 857 | 792 | } |
| 793 | + if(password.matches("^\\**$")) { | |
| 794 | + password = users.getPwd(); | |
| 795 | + } | |
| 796 | + | |
| 858 | 797 | //根据当前登录的用户判断是否 有管理员的权限 |
| 859 | 798 | /* List<String> list = userRoleMapsService.queryUserRoleName(loginState.getId()); |
| 860 | 799 | if(CollectionUtils.isEmpty(list) ||!list.contains(ADMIN)){ |
| 861 | 800 | |
| 862 | 801 | |
| 863 | 802 | |
| 864 | 803 | |
| ... | ... | @@ -873,35 +812,57 @@ |
| 873 | 812 | } |
| 874 | 813 | |
| 875 | 814 | |
| 876 | - //修改了手机号,不能修改已存在的手机号 | |
| 877 | - if(!new Integer(1).equals(users.getOtherAccount()) && !phone.equals(users.getPhone())) { | |
| 878 | - //检查账户是否存在 | |
| 879 | - UsersQuery usersQuery = new UsersQuery(); | |
| 880 | - usersQuery.setPhone(phone); | |
| 881 | - usersQuery.setYn(YnEnums.YES.getId()); | |
| 882 | - List<Users> usersList = usersService.queryUsers(usersQuery); | |
| 883 | - if (0 < usersList.size()) { | |
| 884 | - Map<String, Object> map = new HashMap<>(); | |
| 885 | - map.put(ResultUtils.ERROR_CODE, ConstantInterface.PARAMETER_ERROR); | |
| 886 | - map.put(ResultUtils.ERROR_MSG, "手机号已存在"); | |
| 887 | - writeJson(response, JsonUtil.obj2JsonString(map)); | |
| 888 | - return; | |
| 889 | - } | |
| 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 | + } | |
| 890 | 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 | + } | |
| 891 | 848 | |
| 892 | - LoginContext loginContext = LoginUtil.register(phone, token, typeId); | |
| 893 | - //0 成功 4009 已注册 | |
| 894 | - if(loginContext.getErrorcode().equals(0) || loginContext.getErrorcode().equals(4009)) { | |
| 895 | - users.setPhone(phone); | |
| 896 | - users.setLogincenterId(loginContext.getId()); | |
| 897 | - } else { | |
| 898 | - ResultUtils.buildResultAndWrite(response, ErrorCodeConstants.SYSTEM_ERROR, loginContext.getErrormsg()); | |
| 899 | - 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 | + } | |
| 900 | 861 | } |
| 901 | 862 | } |
| 902 | 863 | |
| 864 | + users.setPwd(password); | |
| 903 | 865 | users.setName(name); |
| 904 | - users.setAccount(account); | |
| 905 | 866 | users.setEnable(enable); |
| 906 | 867 | users.setRemarks(remarks); |
| 907 | 868 | users.setModified(new Date()); |
| 908 | 869 | |
| 909 | 870 | |
| 910 | 871 | |
| 911 | 872 | |
| ... | ... | @@ -912,24 +873,33 @@ |
| 912 | 873 | |
| 913 | 874 | |
| 914 | 875 | //如有角色,则对用户角色中间表先删除后新增 |
| 915 | - 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 | + | |
| 916 | 884 | String[] roleArrayIds = roleIds.split(","); |
| 917 | 885 | //判断角色是否有更新 |
| 918 | 886 | Boolean flag = false; |
| 919 | - if(null == users.getRoles()) flag = true; | |
| 887 | + if(CollectionUtils.isEmpty(userRoleMapses) || roleArrayIds.length != userRoleMapses.size()) flag = true; | |
| 920 | 888 | if(!flag) { |
| 921 | 889 | for (String s : roleArrayIds) { |
| 922 | - for(Roles role : users.getRoles()) { | |
| 923 | - if(s.equals(role.getId().toString())) continue; | |
| 924 | - flag = true; | |
| 890 | + boolean exist = false; | |
| 891 | + for(UserRoleMaps role : userRoleMapses) { | |
| 892 | + if(s.equals(role.getRoleId().toString())) { | |
| 893 | + exist = true; | |
| 894 | + } | |
| 925 | 895 | } |
| 926 | - if(flag) break; | |
| 896 | + if(!exist) break; | |
| 927 | 897 | } |
| 928 | 898 | } |
| 929 | 899 | |
| 930 | 900 | if(flag) { |
| 931 | 901 | Integer _userId = users.getId(); |
| 932 | - UserRoleMapsQuery userRoleMapsQuery = new UserRoleMapsQuery(); | |
| 902 | + userRoleMapsQuery = new UserRoleMapsQuery(); | |
| 933 | 903 | userRoleMapsQuery.setUserId(_userId); |
| 934 | 904 | List<UserRoleMaps> roleMapsList = userRoleMapsService.queryUserRoleMaps(userRoleMapsQuery); |
| 935 | 905 | for (UserRoleMaps userRoleMaps : roleMapsList) { |
| 936 | 906 | |
| ... | ... | @@ -1099,10 +1069,16 @@ |
| 1099 | 1069 | ResultUtils.buildParameterErrorResultAndWrite(response, "用户ID不存在"); |
| 1100 | 1070 | return; |
| 1101 | 1071 | } |
| 1102 | - users.setPwd(LoginUtil.md5("123456")); | |
| 1072 | + users.setPwd(defaultPwd); | |
| 1103 | 1073 | users.setModified(new Date()); |
| 1104 | 1074 | usersService.updateUsers(users); |
| 1105 | - ResultUtils.buildSuccessResultAndWrite(response); | |
| 1075 | + LoginContext loginContext = LoginUtil.register(users.getLogincenterId().toString(), null, null, LoginUtil.md5(defaultPwd).toUpperCase(), token, typeId); | |
| 1076 | + if(loginContext.getErrorcode().equals(0)) { | |
| 1077 | + ResultUtils.buildSuccessResultAndWrite(response); | |
| 1078 | + } else { | |
| 1079 | + ResultUtils.buildResultAndWrite(response,ErrorCodeConstants.SYSTEM_ERROR, "系统错误"); | |
| 1080 | + } | |
| 1081 | + | |
| 1106 | 1082 | } |
| 1107 | 1083 | |
| 1108 | 1084 | @RequestMapping(value = "/logout", method = RequestMethod.GET) |