Browse Source

用户角色修改时连接超时,不使用之前修改用户信息链接,新加了一个链接

wangmh 8 years ago
parent
commit
b1eabd6506

+ 29 - 13
src/main/java/com/uas/platform/b2b/controller/UserController.java

@@ -5,6 +5,7 @@ import java.util.List;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import com.uas.platform.b2b.model.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
@@ -18,10 +19,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import com.uas.platform.b2b.model.Enterprise;
-import com.uas.platform.b2b.model.User;
-import com.uas.platform.b2b.model.UserInfo;
-import com.uas.platform.b2b.model.Vendor;
 import com.uas.platform.b2b.service.UserService;
 import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.b2b.support.TokenService;
@@ -126,7 +123,6 @@ public class UserController {
 	/**
 	 * 邮箱地址是否可用
 	 * 
-	 * @param email
 	 * @return
 	 */
 	@RequestMapping(value = "/getuu", method = RequestMethod.GET)
@@ -142,7 +138,7 @@ public class UserController {
 	/**
 	 * 验证用户输入的密码是否正确
 	 * 
-	 * @param email
+	 * @param password
 	 * @return
 	 */
 	@RequestMapping(value = "/checkPassword", method = RequestMethod.GET)
@@ -158,12 +154,14 @@ public class UserController {
 		return new ResponseEntity<String>(HttpStatus.EXPECTATION_FAILED);
 	}
 
-	/**
-	 * 修改用户密码
-	 * 
-	 * @param email
-	 * @return
-	 */
+    /**
+     * 修改用户密码
+     *
+     * @param session
+     * @param password
+     * @param newPassword
+     * @return
+     */
 	@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
 	public ResponseEntity<String> updatePassword(HttpSession session, String password, String newPassword) {
 		User user = SystemSession.getUser();
@@ -212,9 +210,27 @@ public class UserController {
 		return new ResponseEntity<String>(HttpStatus.OK);
 	}
 
+	/**
+	 * 修改用户角色
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/update/role", method = RequestMethod.POST)
+	@ResponseBody
+	public ResponseEntity<String> updateUserRole(@RequestBody String json, HttpServletRequest request) {
+		User user = FlexJsonUtils.fromJson(json, User.class);
+		user = userService.updateUserRole(user);
+		if (user != null) {
+			logger.log("用户信息", "修改用户权限,UU:" + user.getUserUU());
+			if (SystemSession.getUser().getUserUU().equals(user.getUserUU()))
+				request.getSession().setAttribute("user", user);
+		}
+		return new ResponseEntity<String>(HttpStatus.OK);
+	}
+
 	/**
 	 * 删除用户
-	 * 
+	 *
 	 * @param
 	 * @return
 	 */

+ 4 - 1
src/main/java/com/uas/platform/b2b/service/UserService.java

@@ -193,7 +193,9 @@ public interface UserService {
 	/**
 	 * 忘记密码,根据邮箱验证码重设密码
 	 * 
-	 * @param type
+	 * @param userUU
+	 * @param newPwd
+	 * @param checkcode
 	 */
 	public void resetPwdByCheckcode(Long userUU, String newPwd, String checkcode);
 
@@ -325,4 +327,5 @@ public interface UserService {
 	Boolean getDistribute(Long custUU);
 
 
+	User updateUserRole(User user);
 }

+ 41 - 0
src/main/java/com/uas/platform/b2b/service/impl/UserServiceImpl.java

@@ -252,6 +252,47 @@ public class UserServiceImpl implements UserService {
 		}
 	}
 
+
+	@Override
+	public User updateUserRole(User user) {
+		User newUser = userDao.findOne(user.getUserUU());
+		if (newUser == null) {
+			throw new IllegalOperatorException("该用户不存在,请刷新重试");
+		}
+		// 修改用户角色,只对用户的当前企业的角色进行修改
+		if (!CollectionUtils.isEmpty(user.getRoles())) {
+			Set<Role> existRoles = newUser.getRoles();
+			if (existRoles != null) {// 保留用户在其他企业的角色
+				Iterator<Role> iterator = existRoles.iterator();
+				Long currentEnuu = SystemSession.getUser().getEnterprise().getUu();
+				while (iterator.hasNext()) {
+					Role role = iterator.next();
+					if(role.getEnUU().equals(currentEnuu)) {
+						iterator.remove();
+					}
+				}
+			} else {
+				existRoles = new HashSet<>();
+				newUser.setRoles(existRoles);
+			}
+			for(Role role : user.getRoles()) {
+				existRoles.add(role);
+			}
+		}
+		try {
+			newUser = userDao.save(newUser);
+		} catch (Exception e) {
+			throw new RuntimeException(e.getMessage());
+		}
+		if (SystemSession.getUser().getUserUU().equals(newUser.getUserUU())) {
+			newUser.setCurrentEnterprise(SystemSession.getUser().getEnterprise().getUu());
+			newUser.setCurrentEnterpriseRoles();
+			SystemSession.setUser(newUser);
+		}
+		return newUser;
+	}
+
+
 	@Override
 	public User updatePassword(User user, String password, String newPassword) {
 		boolean result = user.getUserPwd().equals(Md5Utils.encode(password, user.getUserUU()));

+ 1 - 1
src/main/webapp/resources/js/index/app.js

@@ -11180,7 +11180,7 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
             if (save) {
                 if (user.userUU) {
                     user.roles = $scope.checked;
-                    AccountUser.update({}, user, function () {
+                    AccountUser.updateRole({}, user, function () {
                         toaster.pop('success', '提示', '保存成功');
                         $modalInstance.close(true);
                     }, function (response) {