|
@@ -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;
|
|
|
}
|
|
|
|