wangwei 7 years ago
parent
commit
4f34552692

+ 75 - 12
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/UserCloudServiceProvider.java

@@ -1,17 +1,30 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 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.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.basic.api.UserCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.UserInfo;
-import cn.com.qmth.examcloud.core.basic.api.request.GetUserInfoReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetUserInfoResp;
+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.dao.OrgRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
 import cn.com.qmth.examcloud.core.basic.dao.entity.User;
+import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
 import cn.com.qmth.examcloud.core.basic.service.UserService;
 import io.swagger.annotations.ApiOperation;
 
@@ -28,21 +41,71 @@ public class UserCloudServiceProvider extends ControllerSupport implements UserC
 	@Autowired
 	UserService userService;
 
-	@ApiOperation(value = "获取用户信息", notes = "获取用户信息")
+	@Autowired
+	OrgRepo orgRepo;
+
+	@ApiOperation(value = "登录", notes = "")
 	@PostMapping("getUserInfo")
 	@Override
-	public GetUserInfoResp getUserInfo(@RequestBody GetUserInfoReq req) {
+	public LoginResp login(@RequestBody LoginReq req) {
 
-		GetUserInfoResp resp = new GetUserInfoResp();
 		String rootOrgId = req.getRootOrgId();
-		String loginName = req.getLoginName();
 
-		User user = userService.getUser(Long.parseLong(rootOrgId), loginName);
+		if (StringUtils.isBlank(rootOrgId)) {
+			if (StringUtils.isBlank(req.getDomain())) {
+				throw new StatusException("B-001001", "domain,rootOrgId 必须有一个不为空");
+			}
+
+			Org org = orgRepo.findFirstByParentIdAndCode(0L, req.getDomain());
+
+			rootOrgId = String.valueOf(org.getRootId());
+
+			if (StringUtils.isBlank(rootOrgId)) {
+				throw new StatusException("B-001002", "domain错误");
+			}
+		}
+
+		String accountType = req.getAccountType();
+		String accountValue = req.getAccountValue();
+		String password = req.getPassword();
+
+		UserBean userBean = new UserBean();
+
+		// 一般账户登录
+		if (AccountType.COMMON_LOGIN_NAME.getCode().equals(accountType)) {
+			User user = userService.getUser(Long.parseLong(rootOrgId), accountValue);
+			String rightPassword = user.getPassword();
+			if (!rightPassword.equals(password)) {
+				throw new StatusException("B-001003", "密码错误");
+			}
+			userBean.setId(user.getId());
+			userBean.setRootOrgId(user.getRootOrgId());
+
+			List<UserRole> userRoles = user.getUserRoles();
+			ArrayList<RoleBean> roleList = Lists.newArrayList();
+
+			if (CollectionUtils.isNotEmpty(userRoles)) {
+				for (UserRole cur : userRoles) {
+					RoleBean roleBean = new RoleBean();
+					roleBean.setRoleId(cur.getRoleCode());
+					roleBean.setRoleName("待完善");
+					roleList.add(roleBean);
+				}
+			}
+
+		}
+		// 学生学号登录
+		else if (AccountType.STUDENT_CODE.getCode().equals(accountType)) {
+
+		}
+		// 学生身份证号登录
+		else if (AccountType.STUDENT_IDENTITY_NUMBER.getCode().equals(accountType)) {
+
+		}
+
+		LoginResp resp = new LoginResp();
+		resp.setUserBean(userBean);
 
-		UserInfo userInfo = new UserInfo();
-		userInfo.setRootOrgId(user.getRootOrgId());
-		userInfo.setLoginName(user.getLoginName());
-		resp.setUserInfo(userInfo);
 		return resp;
 	}
 

+ 3 - 3
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/UserCloudService.java

@@ -1,7 +1,7 @@
 package cn.com.qmth.examcloud.core.basic.api;
 
-import cn.com.qmth.examcloud.core.basic.api.request.GetUserInfoReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetUserInfoResp;
+import cn.com.qmth.examcloud.core.basic.api.request.LoginReq;
+import cn.com.qmth.examcloud.core.basic.api.response.LoginResp;
 
 /**
  * 用户云服务
@@ -18,6 +18,6 @@ public interface UserCloudService {
 	 * @param req
 	 * @return
 	 */
-	GetUserInfoResp getUserInfo(GetUserInfoReq req);
+	LoginResp login(LoginReq req);
 
 }

+ 36 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/bean/RoleBean.java

@@ -0,0 +1,36 @@
+package cn.com.qmth.examcloud.core.basic.api.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018525
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class RoleBean implements JsonSerializable {
+
+	private static final long serialVersionUID = -916123953402843015L;
+
+	private String roleId;
+
+	private String roleName;
+
+	public String getRoleId() {
+		return roleId;
+	}
+
+	public void setRoleId(String roleId) {
+		this.roleId = roleId;
+	}
+
+	public String getRoleName() {
+		return roleName;
+	}
+
+	public void setRoleName(String roleName) {
+		this.roleName = roleName;
+	}
+
+}

+ 57 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/bean/UserBean.java

@@ -0,0 +1,57 @@
+package cn.com.qmth.examcloud.core.basic.api.bean;
+
+import java.util.List;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018525
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class UserBean implements JsonSerializable {
+
+	private static final long serialVersionUID = -4157068941699776174L;
+
+	/**
+	 * 用户ID
+	 */
+	private Long id;
+
+	/**
+	 * 顶级机构ID
+	 */
+	private Long rootOrgId;
+
+	/**
+	 * 角色集合
+	 */
+	private List<RoleBean> roleList;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public List<RoleBean> getRoleList() {
+		return roleList;
+	}
+
+	public void setRoleList(List<RoleBean> roleList) {
+		this.roleList = roleList;
+	}
+
+}

+ 0 - 29
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/bean/UserInfo.java

@@ -1,29 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.bean;
-
-import java.io.Serializable;
-
-public class UserInfo implements Serializable {
-
-	private static final long serialVersionUID = 7939545789907406883L;
-
-	private Long rootOrgId;
-
-	private String loginName;
-
-	public Long getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(Long rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public String getLoginName() {
-		return loginName;
-	}
-
-	public void setLoginName(String loginName) {
-		this.loginName = loginName;
-	}
-
-}

+ 0 - 43
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/bean/UserRole.java

@@ -1,43 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.bean;
-
-import java.io.Serializable;
-
-/**
- * @author WANGWEI
- *
- */
-public class UserRole implements Serializable {
-
-	private static final long serialVersionUID = -5202947216906275866L;
-
-	private Long id;
-
-	private String appCode;
-
-	private String roleCode;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public String getAppCode() {
-		return appCode;
-	}
-
-	public void setAppCode(String appCode) {
-		this.appCode = appCode;
-	}
-
-	public String getRoleCode() {
-		return roleCode;
-	}
-
-	public void setRoleCode(String roleCode) {
-		this.roleCode = roleCode;
-	}
-
-}

+ 0 - 39
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/request/GetUserInfoReq.java

@@ -1,39 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.request;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.BaseRequest;
-
-/**
- * @author WANGWEI
- *
- */
-public class GetUserInfoReq extends BaseRequest {
-
-	private static final long serialVersionUID = 3858312269358420299L;
-
-	/**
-	 * 顶级机构ID
-	 */
-	private String rootOrgId;
-
-	/**
-	 * 登陆名
-	 */
-	private String loginName;
-
-	public String getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(String rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public String getLoginName() {
-		return loginName;
-	}
-
-	public void setLoginName(String loginName) {
-		this.loginName = loginName;
-	}
-
-}

+ 78 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/request/LoginReq.java

@@ -0,0 +1,78 @@
+package cn.com.qmth.examcloud.core.basic.api.request;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.BaseRequest;
+
+/**
+ * @author WANGWEI
+ *
+ */
+public class LoginReq extends BaseRequest {
+
+	private static final long serialVersionUID = 3858312269358420299L;
+
+	/**
+	 * 顶级机构ID
+	 */
+	private String rootOrgId;
+
+	/**
+	 * 域名
+	 */
+	private String domain;
+
+	/**
+	 * 登陆账号类型
+	 */
+	private String accountType;
+
+	/**
+	 * 登陆账号值
+	 */
+	private String accountValue;
+
+	/**
+	 * 密码
+	 */
+	private String password;
+
+	public String getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(String rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public String getDomain() {
+		return domain;
+	}
+
+	public void setDomain(String domain) {
+		this.domain = domain;
+	}
+
+	public String getAccountType() {
+		return accountType;
+	}
+
+	public void setAccountType(String accountType) {
+		this.accountType = accountType;
+	}
+
+	public String getAccountValue() {
+		return accountValue;
+	}
+
+	public void setAccountValue(String accountValue) {
+		this.accountValue = accountValue;
+	}
+
+	public String getPassword() {
+		return password;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+}

+ 0 - 19
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/response/GetUserInfoResp.java

@@ -1,19 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.response;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.BaseResponse;
-import cn.com.qmth.examcloud.core.basic.api.bean.UserInfo;
-
-public class GetUserInfoResp extends BaseResponse {
-	private static final long serialVersionUID = 1618003517901624074L;
-
-	private UserInfo userInfo;
-
-	public UserInfo getUserInfo() {
-		return userInfo;
-	}
-
-	public void setUserInfo(UserInfo userInfo) {
-		this.userInfo = userInfo;
-	}
-
-}

+ 20 - 0
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/response/LoginResp.java

@@ -0,0 +1,20 @@
+package cn.com.qmth.examcloud.core.basic.api.response;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.BaseResponse;
+import cn.com.qmth.examcloud.core.basic.api.bean.UserBean;
+
+public class LoginResp extends BaseResponse {
+
+	private static final long serialVersionUID = 1618003517901624074L;
+
+	private UserBean userBean;
+
+	public UserBean getUserBean() {
+		return userBean;
+	}
+
+	public void setUserBean(UserBean userBean) {
+		this.userBean = userBean;
+	}
+
+}

+ 24 - 0
examcloud-core-basic-base/pom.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>cn.com.qmth.examcloud.core.basic</groupId>
+		<artifactId>examcloud-core-basic</artifactId>
+		<version>2.0-SNAPSHOT</version>
+	</parent>
+	<artifactId>examcloud-core-basic-base</artifactId>
+
+	<dependencies>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.commons</groupId>
+			<artifactId>examcloud-commons-web</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.commons</groupId>
+			<artifactId>examcloud-commons-dto</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+	</dependencies>
+
+</project>

+ 64 - 0
examcloud-core-basic-base/src/main/java/cn/com/qmth/examcloud/core/basic/base/enums/AccountType.java

@@ -0,0 +1,64 @@
+package cn.com.qmth.examcloud.core.basic.base.enums;
+
+/**
+ * 账户类型
+ *
+ * @author WANGWEI
+ * @date 2018525
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public enum AccountType {
+
+	/**
+	 * 学生学号
+	 */
+	STUDENT_CODE("STUDENT_CODE", "学号"),
+
+	/**
+	 * 学生身份证号
+	 */
+	STUDENT_IDENTITY_NUMBER("STUDENT_IDENTITY_NUMBER", "学号"),
+
+	/**
+	 * 一般登录名(非学生登录)
+	 */
+	COMMON_LOGIN_NAME("COMMON_LOGIN_NAME", "一般登录名");
+
+	// ===========================================================================
+
+	/**
+	 * 码
+	 */
+	private String code;
+
+	/**
+	 * 描述
+	 */
+	private String desc;
+
+	/**
+	 * 构造函数
+	 *
+	 * @param code
+	 * @param desc
+	 */
+	private AccountType(String code, String desc) {
+		this.code = code;
+		this.desc = desc;
+	}
+
+	/**
+	 * @return the code
+	 */
+	public String getCode() {
+		return code;
+	}
+
+	/**
+	 * @return the desc
+	 */
+	public String getDesc() {
+		return desc;
+	}
+
+}

+ 5 - 0
examcloud-core-basic-base/src/main/java/cn/com/qmth/examcloud/core/basic/base/util/BaseUtil.java

@@ -0,0 +1,5 @@
+package cn.com.qmth.examcloud.core.basic.base.util;
+
+public class BaseUtil {
+
+}

+ 2 - 7
examcloud-core-basic-dao/pom.xml

@@ -10,13 +10,8 @@
 
 	<dependencies>
 		<dependency>
-			<groupId>cn.com.qmth.examcloud.commons</groupId>
-			<artifactId>examcloud-commons-web</artifactId>
-			<version>${examcloud.version}</version>
-		</dependency>
-		<dependency>
-			<groupId>cn.com.qmth.examcloud.commons</groupId>
-			<artifactId>examcloud-commons-dto</artifactId>
+			<groupId>cn.com.qmth.examcloud.core.basic</groupId>
+			<artifactId>examcloud-core-basic-base</artifactId>
 			<version>${examcloud.version}</version>
 		</dependency>
 	</dependencies>

+ 22 - 22
pom.xml

@@ -1,23 +1,23 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<parent>
-		<groupId>cn.com.qmth.examcloud</groupId>
-		<artifactId>examcloud-parent</artifactId>
-		<version>2.0-SNAPSHOT</version>
-	</parent>
-	<groupId>cn.com.qmth.examcloud.core.basic</groupId>
-	<artifactId>examcloud-core-basic</artifactId>
-	<packaging>pom</packaging>
-
-	<modules>
-		<module>examcloud-core-basic-api</module>
-		<module>examcloud-core-basic-api-client</module>
-		<module>examcloud-core-basic-api-provider</module>
-		<module>examcloud-core-basic-service</module>
-		<module>examcloud-core-basic-dao</module>
-		<module>examcloud-core-basic-starter</module>
-	</modules>
-
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>cn.com.qmth.examcloud</groupId>
+		<artifactId>examcloud-parent</artifactId>
+		<version>2.0-SNAPSHOT</version>
+	</parent>
+	<groupId>cn.com.qmth.examcloud.core.basic</groupId>
+	<artifactId>examcloud-core-basic</artifactId>
+	<packaging>pom</packaging>
+
+	<modules>
+		<module>examcloud-core-basic-base</module>
+		<module>examcloud-core-basic-api</module>
+		<module>examcloud-core-basic-api-client</module>
+		<module>examcloud-core-basic-api-provider</module>
+		<module>examcloud-core-basic-service</module>
+		<module>examcloud-core-basic-dao</module>
+		<module>examcloud-core-basic-starter</module>
+	</modules>
+
 </project>