Browse Source

。。。

wangwei 7 years ago
parent
commit
1032705b4e

+ 0 - 66
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/RolePrivilegeCloudServiceProvider.java

@@ -1,66 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.provider;
-
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import com.google.common.collect.Lists;
-
-import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
-import cn.com.qmth.examcloud.core.basic.api.RolePrivilegeCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.RoleBean;
-import cn.com.qmth.examcloud.core.basic.dao.PrivilegeGroupRepo;
-import cn.com.qmth.examcloud.core.basic.dao.PrivilegeRepo;
-import cn.com.qmth.examcloud.core.basic.dao.RolePrivilegeRelationRepo;
-import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
-import io.swagger.annotations.ApiOperation;
-
-/**
- * 角色权限服务
- *
- * @author WANGWEI
- * @date 2018年6月8日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@RestController
-@RequestMapping("${$rmp}" + "rolePrivilege")
-public class RolePrivilegeCloudServiceProvider extends ControllerSupport
-		implements
-			RolePrivilegeCloudService {
-
-	private static final long serialVersionUID = -4360164791713797878L;
-
-	@Autowired
-	RoleRepo roleRepo;
-
-	@Autowired
-	RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
-
-	@Autowired
-	PrivilegeRepo privilegeRepo;
-
-	@Autowired
-	PrivilegeGroupRepo privilegeGroupRepo;
-
-	@ApiOperation(value = "查询所有角色", notes = "")
-	@PostMapping("getAllRoles")
-	@Override
-	public List<RoleBean> getAllRoles() {
-		List<cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity> roleList = roleRepo.findAll();
-		List<RoleBean> roleBeanList = Lists.newArrayList();
-		for (cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity cur : roleList) {
-			RoleBean bean = new RoleBean();
-			bean.setRoleId(cur.getId());
-			bean.setRoleName(cur.getName());
-			bean.setRoleCode(cur.getCode());
-
-			roleBeanList.add(bean);
-		}
-
-		return roleBeanList;
-	}
-
-}

+ 0 - 24
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/RolePrivilegeCloudService.java

@@ -1,24 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api;
-
-import java.util.List;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.CloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.RoleBean;
-
-/**
- * 角色权限云服务
- * 
- * @author WANGWEI
- *
- */
-public interface RolePrivilegeCloudService extends CloudService {
-
-	/**
-	 * 获取所有角色
-	 *
-	 * @author WANGWEI
-	 * @return
-	 */
-	List<RoleBean> getAllRoles();
-
-}

+ 112 - 38
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -15,13 +15,20 @@ import cn.com.qmth.examcloud.commons.base.util.UUID;
 import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
 import cn.com.qmth.examcloud.commons.web.security.bean.Role;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
-import cn.com.qmth.examcloud.commons.web.support.ResponseStatus;
+import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
 import cn.com.qmth.examcloud.core.basic.api.UserCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.RoleBean;
-import cn.com.qmth.examcloud.core.basic.api.bean.UserBean;
-import cn.com.qmth.examcloud.core.basic.api.request.LoginReq;
-import cn.com.qmth.examcloud.core.basic.api.response.LoginResp;
+import cn.com.qmth.examcloud.core.basic.base.enums.AccountType;
+import cn.com.qmth.examcloud.core.basic.base.enums.UserType;
+import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
+import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
+import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
+import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
+import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
 import cn.com.qmth.examcloud.core.basic.service.AuthService;
+import cn.com.qmth.examcloud.core.basic.service.UserService;
 import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
 
 /**
@@ -40,48 +47,115 @@ public class AuthServiceImpl implements AuthService {
 	@Autowired
 	UserCloudService userCloudService;
 
+	@Autowired
+	UserService userService;
+
+	@Autowired
+	UserRepo userRepo;
+
+	@Autowired
+	OrgRepo orgRepo;
+
+	@Autowired
+	RoleRepo roleRepo;
+
+	@Autowired
+	StudentRepo studentRepo;
+
 	@Override
 	public User login(LoginInfo loginInfo) {
-		LoginReq loginReq = new LoginReq();
-		loginReq.setAccountType(loginInfo.getAccountType());
-		loginReq.setAccountValue(loginInfo.getAccountValue());
-		loginReq.setRootOrgId(loginInfo.getRootOrgId());
-		loginReq.setDomain(loginInfo.getDomain());
-		loginReq.setPassword(loginInfo.getPassword());
-		LoginResp loginResp = null;
-		try {
-			loginResp = userCloudService.login(loginReq);
-		} catch (StatusException e) {
-			if (e.getCode().equals(ResponseStatus.SERVER_ERROR.getCode())) {
-				throw e;
-			} else {
-				throw new StatusException("P-001001", "用户名或密码错误", e);
+
+		String rootOrgId = loginInfo.getRootOrgId();
+		Org rootOrg = null;
+		if (StringUtils.isBlank(rootOrgId)) {
+			if (StringUtils.isBlank(loginInfo.getDomain())) {
+				throw new StatusException("B-001001", "domain,rootOrgId 必须有一个不为空");
+			}
+
+			rootOrg = orgRepo.findFirstByParentIdAndCode(0L, loginInfo.getDomain());
+
+			if (null == rootOrg) {
+				throw new StatusException("B-001002", "机构不存在");
+			}
+
+			rootOrgId = String.valueOf(rootOrg.getId());
+
+		} else {
+			rootOrg = orgRepo.findOne(Long.valueOf(rootOrgId));
+			if (null == rootOrg) {
+				throw new StatusException("B-001002", "机构不存在");
 			}
 		}
-		UserBean userBean = loginResp.getUserBean();
 
+		String accountType = loginInfo.getAccountType();
+		String accountValue = loginInfo.getAccountValue();
+		String password = loginInfo.getPassword();
+
+		UserEntity userEntity = null;
+		Student student = null;
 		User user = new User();
+
+		// 常规账户登录
+		if (AccountType.COMMON_LOGIN_NAME.getCode().equals(accountType)) {
+			user.setUserType(UserType.COMMON.getCode());
+			userEntity = userService.getUser(Long.parseLong(rootOrgId), accountValue);
+		} else {
+			// 学生学号登录
+			if (AccountType.STUDENT_CODE.getCode().equals(accountType)) {
+				student = studentRepo.findByStudentCodeAndRootOrgId(accountValue, rootOrg.getId());
+			}
+			// 学生身份证号登录
+			else if (AccountType.STUDENT_IDENTITY_NUMBER.getCode().equals(accountType)) {
+				student = studentRepo.findByIdentityNumberAndRootOrgId(accountValue,
+						rootOrg.getId());
+			}
+
+			user.setUserType(UserType.STUDENT.getCode());
+			user.setStudentCode(student.getStudentCode());
+			user.setIdentityNumber(student.getIdentityNumber());
+
+			userEntity = userRepo.findOne(student.getUser().getId());
+			List<UserRole> roleList = Lists.newArrayList();
+			UserRole userRole = new UserRole();
+			userRole.setRoleCode(RoleMeta.STUDENT.name());
+			roleList.add(userRole);
+			userEntity.setUserRoles(roleList);
+		}
+
+		if (null == userEntity) {
+			throw new StatusException("B-001004", "用户不存在");
+		}
+		String rightPassword = userEntity.getPassword();
+		if (!rightPassword.equals(password)) {
+			throw new StatusException("B-001003", "密码错误");
+		}
+
 		List<Role> roleList = Lists.newArrayList();
 		user.setRoleList(roleList);
 
-		user.setUserType(userBean.getUserType());
-		user.setUserId(userBean.getUserId());
-		user.setStudentId(userBean.getStudentId());
-		user.setDisplayName(userBean.getDisplayName());
-		user.setRootOrgId(userBean.getRootOrgId());
-		user.setRootOrgName(userBean.getRootOrgName());
-		user.setOrgId(userBean.getOrgId());
-		user.setOrgName(userBean.getOrgName());
-		user.setIdentityNumber(userBean.getIdentityNumber());
-		user.setStudentCode(userBean.getStudentCode());
-
-		List<RoleBean> roleBeanList = userBean.getRoleList();
-
-		if (CollectionUtils.isNotEmpty(roleBeanList)) {
-			for (RoleBean cur : roleBeanList) {
-				Role role = new Role();
-				role.setRoleCode(cur.getRoleCode());
-				role.setRoleName(cur.getRoleName());
+		user.setUserId(userEntity.getId());
+		user.setDisplayName(userEntity.getLoginName());
+		user.setRootOrgId(userEntity.getRootOrgId());
+		user.setRootOrgName(rootOrg.getName());
+		user.setOrgId(userEntity.getOrgId());
+		if (null != user.getOrgId()) {
+			Org org = orgRepo.findOne(user.getOrgId());
+			user.setOrgName(org.getName());
+		}
+
+		List<UserRole> userRoles = userEntity.getUserRoles();
+
+		if (CollectionUtils.isNotEmpty(userRoles)) {
+			for (UserRole cur : userRoles) {
+				String roleCode = cur.getRoleCode();
+				cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity roleEntity = roleRepo
+						.findByCode(roleCode);
+				if (null == roleEntity) {
+					throw new StatusException("B-002002",
+							"role code is wrong. roleCode=" + roleCode);
+				}
+				Role role = new Role(roleEntity.getId(), roleEntity.getCode(),
+						roleEntity.getName());
 				roleList.add(role);
 			}
 		}