|
@@ -1,169 +0,0 @@
|
|
-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.security.enums.RoleMeta;
|
|
|
|
-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.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.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.UserService;
|
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 用户服务 controller
|
|
|
|
- *
|
|
|
|
- * @author WANGWEI
|
|
|
|
- *
|
|
|
|
- */
|
|
|
|
-@RestController
|
|
|
|
-@RequestMapping("${$rmp}" + "user")
|
|
|
|
-public class UserCloudServiceProvider extends ControllerSupport implements UserCloudService {
|
|
|
|
-
|
|
|
|
- private static final long serialVersionUID = -5270235759913273972L;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- UserService userService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- UserRepo userRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- OrgRepo orgRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- StudentRepo studentRepo;
|
|
|
|
-
|
|
|
|
- @ApiOperation(value = "登录", notes = "")
|
|
|
|
- @PostMapping("login")
|
|
|
|
- @Override
|
|
|
|
- public LoginResp login(@RequestBody LoginReq req) {
|
|
|
|
-
|
|
|
|
- String rootOrgId = req.getRootOrgId();
|
|
|
|
- Org rootOrg = null;
|
|
|
|
- if (StringUtils.isBlank(rootOrgId)) {
|
|
|
|
- if (StringUtils.isBlank(req.getDomain())) {
|
|
|
|
- throw new StatusException("B-001001", "domain,rootOrgId 必须有一个不为空");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rootOrg = orgRepo.findFirstByParentIdAndCode(0L, req.getDomain());
|
|
|
|
-
|
|
|
|
- if (null == rootOrg) {
|
|
|
|
- throw new StatusException("B-001002", "机构不存在");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rootOrgId = String.valueOf(rootOrg.getId());
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- rootOrg = orgRepo.findOne(Long.valueOf(rootOrgId));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String accountType = req.getAccountType();
|
|
|
|
- String accountValue = req.getAccountValue();
|
|
|
|
- String password = req.getPassword();
|
|
|
|
-
|
|
|
|
- UserBean userBean = new UserBean();
|
|
|
|
-
|
|
|
|
- // 常规账户登录
|
|
|
|
- if (AccountType.COMMON_LOGIN_NAME.getCode().equals(accountType)) {
|
|
|
|
- UserEntity user = userService.getUser(Long.parseLong(rootOrgId), accountValue);
|
|
|
|
- if (null == user) {
|
|
|
|
- throw new StatusException("B-001004", "用户不存在");
|
|
|
|
- }
|
|
|
|
- String rightPassword = user.getPassword();
|
|
|
|
- if (!rightPassword.equals(password)) {
|
|
|
|
- throw new StatusException("B-001003", "密码错误");
|
|
|
|
- }
|
|
|
|
- userBean.setUserType(UserType.COMMON.getCode());
|
|
|
|
- userBean.setUserId(user.getId());
|
|
|
|
- userBean.setDisplayName(user.getLoginName());
|
|
|
|
- userBean.setRootOrgId(user.getRootOrgId());
|
|
|
|
- userBean.setRootOrgName(rootOrg != null ? rootOrg.getName() : null);
|
|
|
|
- userBean.setOrgId(user.getOrgId());
|
|
|
|
- List<UserRole> userRoles = user.getUserRoles();
|
|
|
|
- ArrayList<RoleBean> roleList = Lists.newArrayList();
|
|
|
|
-
|
|
|
|
- if (CollectionUtils.isNotEmpty(userRoles)) {
|
|
|
|
- for (UserRole cur : userRoles) {
|
|
|
|
- RoleBean roleBean = new RoleBean();
|
|
|
|
- roleBean.setRoleCode(cur.getRoleCode());
|
|
|
|
- String roleName = RoleMeta.valueOf(cur.getRoleCode()).getName();
|
|
|
|
- roleBean.setRoleName(roleName);
|
|
|
|
- roleList.add(roleBean);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- userBean.setRoleList(roleList);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- // 学生学号登录
|
|
|
|
- else if (AccountType.STUDENT_CODE.getCode().equals(accountType)) {
|
|
|
|
- Student student = studentRepo.findByStudentCodeAndRootOrgId(accountValue,
|
|
|
|
- rootOrg.getId());
|
|
|
|
- userBean = setStudentUserInfo(password, student);
|
|
|
|
- }
|
|
|
|
- // 学生身份证号登录
|
|
|
|
- else if (AccountType.STUDENT_IDENTITY_NUMBER.getCode().equals(accountType)) {
|
|
|
|
- Student student = studentRepo.findByIdentityNumberAndRootOrgId(accountValue,
|
|
|
|
- rootOrg.getId());
|
|
|
|
- userBean = setStudentUserInfo(password, student);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- LoginResp resp = new LoginResp();
|
|
|
|
- resp.setUserBean(userBean);
|
|
|
|
-
|
|
|
|
- return resp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private UserBean setStudentUserInfo(String password, Student student) {
|
|
|
|
- UserBean userBean = new UserBean();
|
|
|
|
- if (null == student) {
|
|
|
|
- throw new StatusException("B-001005", "学生信息不存在");
|
|
|
|
- }
|
|
|
|
- UserEntity user = userRepo.findOne(student.getUser().getId());
|
|
|
|
- String rightPassword = user.getPassword();
|
|
|
|
- if (!rightPassword.equals(password)) {
|
|
|
|
- throw new StatusException("B-001003", "密码错误");
|
|
|
|
- }
|
|
|
|
- userBean.setUserType(UserType.STUDENT.getCode());
|
|
|
|
- userBean.setUserId(user.getId());
|
|
|
|
- userBean.setStudentId(student.getId());
|
|
|
|
- userBean.setDisplayName(user.getName());
|
|
|
|
- userBean.setRootOrgId(user.getRootOrgId());
|
|
|
|
- userBean.setOrgId(user.getOrgId());
|
|
|
|
- userBean.setStudentCode(student.getStudentCode());
|
|
|
|
- userBean.setIdentityNumber(student.getIdentityNumber());
|
|
|
|
- // 设置学生角色
|
|
|
|
- ArrayList<RoleBean> roleList = Lists.newArrayList();
|
|
|
|
- roleList.add(new RoleBean(RoleMeta.STUDENT.name(), RoleMeta.STUDENT.getName()));
|
|
|
|
- userBean.setRoleList(roleList);
|
|
|
|
-
|
|
|
|
- Org org = orgRepo.findOne(user.getOrgId());
|
|
|
|
- userBean.setOrgName(org.getName());
|
|
|
|
- return userBean;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|