|
|
@ -1,48 +1,40 @@
|
|
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
|
|
|
import com.ruoyi.biemo.business.domain.ZYUserInfo;
|
|
|
|
import com.ruoyi.biemo.business.domain.ZYUserInfo;
|
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
|
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysMenu;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginBody;
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.framework.web.service.SysLoginService;
|
|
|
|
|
|
|
|
import com.ruoyi.framework.web.service.SysPermissionService;
|
|
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
|
|
import com.ruoyi.system.domain.SysUserRole;
|
|
|
|
import com.ruoyi.system.domain.SysUserRole;
|
|
|
|
import com.ruoyi.system.mapper.SysDeptMapper;
|
|
|
|
import com.ruoyi.system.mapper.SysDeptMapper;
|
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
|
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
|
|
|
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
|
|
|
|
|
|
|
import com.ruoyi.system.service.ISysMenuService;
|
|
|
|
import com.ruoyi.web.config.exception.UnAuthorizedException;
|
|
|
|
import com.ruoyi.web.config.exception.UnAuthorizedException;
|
|
|
|
import com.ruoyi.web.config.security.JwtUser;
|
|
|
|
import com.ruoyi.web.config.security.JwtUser;
|
|
|
|
import com.ruoyi.web.config.security.LoginResult;
|
|
|
|
import com.ruoyi.web.config.security.LoginResult;
|
|
|
|
import com.ruoyi.web.config.security.TokenProvider;
|
|
|
|
import com.ruoyi.web.config.security.TokenProvider;
|
|
|
|
import com.ruoyi.web.util.RsaUtil;
|
|
|
|
|
|
|
|
import com.ruoyi.web.util.TzApi;
|
|
|
|
import com.ruoyi.web.util.TzApi;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
|
|
|
|
import org.apache.catalina.User;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysMenu;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginBody;
|
|
|
|
|
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
|
|
|
|
import com.ruoyi.framework.web.service.SysLoginService;
|
|
|
|
|
|
|
|
import com.ruoyi.framework.web.service.SysPermissionService;
|
|
|
|
|
|
|
|
import com.ruoyi.system.service.ISysMenuService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 登录验证
|
|
|
|
* 登录验证
|
|
|
@ -84,7 +76,7 @@ public class SysLoginController {
|
|
|
|
@PostMapping("/login")
|
|
|
|
@PostMapping("/login")
|
|
|
|
@ApiOperation("登录接口")
|
|
|
|
@ApiOperation("登录接口")
|
|
|
|
public AjaxResult login(@RequestBody(required = false) LoginBody loginBody,
|
|
|
|
public AjaxResult login(@RequestBody(required = false) LoginBody loginBody,
|
|
|
|
@RequestParam(required = false) String TOKEN) {
|
|
|
|
@RequestParam(required = false) String TOKEN) {
|
|
|
|
|
|
|
|
|
|
|
|
//todo user表中的deptId等于classId
|
|
|
|
//todo user表中的deptId等于classId
|
|
|
|
|
|
|
|
|
|
|
@ -92,7 +84,7 @@ public class SysLoginController {
|
|
|
|
String username = loginBody.getUsername();
|
|
|
|
String username = loginBody.getUsername();
|
|
|
|
SysUser sysUser = sysUserMapper.selectUserByStudentNumber(username);
|
|
|
|
SysUser sysUser = sysUserMapper.selectUserByStudentNumber(username);
|
|
|
|
// SysUser sysUser = sysUserMapper.selectUserByUserName(loginBody.getUsername());
|
|
|
|
// SysUser sysUser = sysUserMapper.selectUserByUserName(loginBody.getUsername());
|
|
|
|
String roleId= String.valueOf(sysUserRoleMapper.selectRoleIdByUserId(sysUser.getUserId()));
|
|
|
|
String roleId = String.valueOf(sysUserRoleMapper.selectRoleIdByUserId(sysUser.getUserId()));
|
|
|
|
if (("student".equals(loginBody.getRole()) && "2".equals(roleId)) || ("teacher".equals(loginBody.getRole()) && "100".equals(roleId)) || "admin".equals(loginBody.getUsername())) {
|
|
|
|
if (("student".equals(loginBody.getRole()) && "2".equals(roleId)) || ("teacher".equals(loginBody.getRole()) && "100".equals(roleId)) || "admin".equals(loginBody.getUsername())) {
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
// 生成令牌
|
|
|
|
// 生成令牌
|
|
|
@ -100,14 +92,14 @@ public class SysLoginController {
|
|
|
|
loginBody.getUuid());
|
|
|
|
loginBody.getUuid());
|
|
|
|
SysUser user = sysUserMapper.selectDeptIdByStudentNumber(loginBody.getUsername());
|
|
|
|
SysUser user = sysUserMapper.selectDeptIdByStudentNumber(loginBody.getUsername());
|
|
|
|
ajax.put(Constants.TOKEN, token);
|
|
|
|
ajax.put(Constants.TOKEN, token);
|
|
|
|
ajax.put("deptId",user.getDeptId());
|
|
|
|
ajax.put("deptId", user.getDeptId());
|
|
|
|
ajax.put("UserId",user.getUserId());
|
|
|
|
ajax.put("UserId", user.getUserId());
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId());
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId());
|
|
|
|
Long parentId = sysDept.getParentId();
|
|
|
|
Long parentId = sysDept.getParentId();
|
|
|
|
ajax.put("schoolId",parentId.toString()); //学校ID
|
|
|
|
ajax.put("schoolId", parentId.toString()); //学校ID
|
|
|
|
return ajax;
|
|
|
|
return ajax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new AjaxResult(403,"用户权限不正确");
|
|
|
|
return new AjaxResult(403, "用户权限不正确");
|
|
|
|
} else { // 2、智云单点登录
|
|
|
|
} else { // 2、智云单点登录
|
|
|
|
JwtUser jwtUser;
|
|
|
|
JwtUser jwtUser;
|
|
|
|
jwtUser = TokenProvider.getJWTUserByZhiYun(TOKEN);
|
|
|
|
jwtUser = TokenProvider.getJWTUserByZhiYun(TOKEN);
|
|
|
@ -135,18 +127,19 @@ public class SysLoginController {
|
|
|
|
String tokenWbdsj = loginService.login(sysUser.getUserName(), "123456", "1",
|
|
|
|
String tokenWbdsj = loginService.login(sysUser.getUserName(), "123456", "1",
|
|
|
|
String.valueOf(UUID.randomUUID()));
|
|
|
|
String.valueOf(UUID.randomUUID()));
|
|
|
|
ajax.put(Constants.TOKEN, tokenWbdsj);
|
|
|
|
ajax.put(Constants.TOKEN, tokenWbdsj);
|
|
|
|
ajax.put("deptId",sysUser.getDeptId()); //班级ID
|
|
|
|
ajax.put("deptId", sysUser.getDeptId()); //班级ID
|
|
|
|
ajax.put("UserId",sysUser.getUserId());
|
|
|
|
ajax.put("UserId", sysUser.getUserId());
|
|
|
|
|
|
|
|
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId());
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId());
|
|
|
|
Long parentId = sysDept.getParentId();
|
|
|
|
Long parentId = sysDept.getParentId();
|
|
|
|
ajax.put("schoolId",parentId.toString()); //学校ID
|
|
|
|
ajax.put("schoolId", parentId.toString()); //学校ID
|
|
|
|
return ajax;
|
|
|
|
return ajax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo 多加一个deptId
|
|
|
|
//todo 多加一个deptId
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取用户信息
|
|
|
|
* 获取用户信息
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -164,7 +157,7 @@ public class SysLoginController {
|
|
|
|
ajax.put("user", user);
|
|
|
|
ajax.put("user", user);
|
|
|
|
ajax.put("roles", roles);
|
|
|
|
ajax.put("roles", roles);
|
|
|
|
ajax.put("permissions", permissions);
|
|
|
|
ajax.put("permissions", permissions);
|
|
|
|
ajax.put("deptId",deptId); //这是班级ID
|
|
|
|
ajax.put("deptId", deptId); //这是班级ID
|
|
|
|
return ajax;
|
|
|
|
return ajax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -207,13 +200,20 @@ public class SysLoginController {
|
|
|
|
Integer classId = zyUserInfo.getClassId();
|
|
|
|
Integer classId = zyUserInfo.getClassId();
|
|
|
|
Long userId = Long.valueOf(zyUserId);
|
|
|
|
Long userId = Long.valueOf(zyUserId);
|
|
|
|
SysUser userInfo = sysUserMapper.selectUserById(userId);
|
|
|
|
SysUser userInfo = sysUserMapper.selectUserById(userId);
|
|
|
|
if (userInfo!=null) {
|
|
|
|
if (userInfo != null) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//填充用户信息
|
|
|
|
//填充用户信息
|
|
|
|
SysUser stuUser = new SysUser();
|
|
|
|
SysUser stuUser = new SysUser();
|
|
|
|
stuUser.setUserId(userId); //使用智云的
|
|
|
|
stuUser.setUserId(userId); //使用智云的
|
|
|
|
stuUser.setDeptId(Long.valueOf(classId));
|
|
|
|
|
|
|
|
|
|
|
|
//这里是老师用户,智云跳转没学校ID,设置成学校ID
|
|
|
|
|
|
|
|
if (classId == 0) {
|
|
|
|
|
|
|
|
System.out.println(classId);
|
|
|
|
|
|
|
|
stuUser.setDeptId(Long.valueOf(zyUserInfo.getSchoolId()));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stuUser.setDeptId(Long.valueOf(classId));
|
|
|
|
|
|
|
|
}
|
|
|
|
stuUser.setUserName(username);
|
|
|
|
stuUser.setUserName(username);
|
|
|
|
stuUser.setNickName(name);
|
|
|
|
stuUser.setNickName(name);
|
|
|
|
stuUser.setPassword(password);
|
|
|
|
stuUser.setPassword(password);
|
|
|
@ -227,27 +227,27 @@ public class SysLoginController {
|
|
|
|
users.add(stuUser);
|
|
|
|
users.add(stuUser);
|
|
|
|
|
|
|
|
|
|
|
|
//填充角色信息
|
|
|
|
//填充角色信息
|
|
|
|
SysUserRole sysUserRole =new SysUserRole();
|
|
|
|
SysUserRole sysUserRole = new SysUserRole();
|
|
|
|
sysUserRole.setUserId(userId);
|
|
|
|
sysUserRole.setUserId(userId);
|
|
|
|
if (roleId==3) {
|
|
|
|
if (roleId == 3) {
|
|
|
|
sysUserRole.setRoleId(100L); //100是老师 2是学生
|
|
|
|
sysUserRole.setRoleId(100L); //100是老师 2是学生
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (roleId==4){
|
|
|
|
if (roleId == 4) {
|
|
|
|
sysUserRole.setRoleId(2L);
|
|
|
|
sysUserRole.setRoleId(2L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
userRoleList.add(sysUserRole);
|
|
|
|
userRoleList.add(sysUserRole);
|
|
|
|
|
|
|
|
|
|
|
|
//填充学校和班级信息
|
|
|
|
//填充学校和班级信息
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(Long.valueOf(zyUserInfo.getSchoolId())); //判断学校是否存在
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(Long.valueOf(zyUserInfo.getSchoolId())); //判断学校是否存在
|
|
|
|
if (sysDept==null){
|
|
|
|
if (sysDept == null) {
|
|
|
|
//添加一条学校数据
|
|
|
|
//添加一条学校数据
|
|
|
|
SysDept newSysDept =new SysDept();
|
|
|
|
SysDept newSysDept = new SysDept();
|
|
|
|
newSysDept.setDeptId(Long.valueOf(zyUserInfo.getSchoolId()));
|
|
|
|
newSysDept.setDeptId(Long.valueOf(zyUserInfo.getSchoolId()));
|
|
|
|
newSysDept.setDeptName(zyUserInfo.getSchoolName());
|
|
|
|
newSysDept.setDeptName(zyUserInfo.getSchoolName());
|
|
|
|
newSysDept.setParentId(0L); //顶级节点
|
|
|
|
newSysDept.setParentId(0L); //顶级节点
|
|
|
|
newSysDept.setAncestors("0,100");
|
|
|
|
newSysDept.setAncestors("0,100");
|
|
|
|
Integer sort = sysDeptMapper.getOrderNumMax();
|
|
|
|
Integer sort = sysDeptMapper.getOrderNumMax();
|
|
|
|
newSysDept.setOrderNum(sort+1);//排序
|
|
|
|
newSysDept.setOrderNum(sort + 1);//排序
|
|
|
|
newSysDept.setCreateTime(new Date());
|
|
|
|
newSysDept.setCreateTime(new Date());
|
|
|
|
newSysDept.setUpdateBy(new Date().toString());
|
|
|
|
newSysDept.setUpdateBy(new Date().toString());
|
|
|
|
newSysDept.setStatus("0");
|
|
|
|
newSysDept.setStatus("0");
|
|
|
@ -255,11 +255,11 @@ public class SysLoginController {
|
|
|
|
sysDeptList.add(newSysDept);
|
|
|
|
sysDeptList.add(newSysDept);
|
|
|
|
|
|
|
|
|
|
|
|
//添加一条班级数据
|
|
|
|
//添加一条班级数据
|
|
|
|
SysDept newSysDeptByClass =new SysDept();
|
|
|
|
SysDept newSysDeptByClass = new SysDept();
|
|
|
|
newSysDeptByClass.setDeptId(Long.valueOf(zyUserInfo.getClassId()));
|
|
|
|
newSysDeptByClass.setDeptId(Long.valueOf(zyUserInfo.getClassId()));
|
|
|
|
newSysDeptByClass.setDeptName(zyUserInfo.getClassName());
|
|
|
|
newSysDeptByClass.setDeptName(zyUserInfo.getClassName());
|
|
|
|
newSysDeptByClass.setParentId(newSysDept.getDeptId()); //学校的ID
|
|
|
|
newSysDeptByClass.setParentId(newSysDept.getDeptId()); //学校的ID
|
|
|
|
newSysDeptByClass.setAncestors("0,100,"+newSysDept.getDeptId());
|
|
|
|
newSysDeptByClass.setAncestors("0,100," + newSysDept.getDeptId());
|
|
|
|
newSysDeptByClass.setOrderNum(1);//排序
|
|
|
|
newSysDeptByClass.setOrderNum(1);//排序
|
|
|
|
newSysDeptByClass.setCreateTime(new Date());
|
|
|
|
newSysDeptByClass.setCreateTime(new Date());
|
|
|
|
newSysDeptByClass.setUpdateBy(new Date().toString());
|
|
|
|
newSysDeptByClass.setUpdateBy(new Date().toString());
|
|
|
@ -267,18 +267,18 @@ public class SysLoginController {
|
|
|
|
newSysDeptByClass.setDelFlag("0");
|
|
|
|
newSysDeptByClass.setDelFlag("0");
|
|
|
|
sysDeptList.add(newSysDeptByClass);
|
|
|
|
sysDeptList.add(newSysDeptByClass);
|
|
|
|
|
|
|
|
|
|
|
|
}else { // 学校存在 判断班级是否存在
|
|
|
|
} else { // 学校存在 判断班级是否存在
|
|
|
|
SysDept sysDeptByClass = sysDeptMapper.selectDeptById(Long.valueOf(classId));
|
|
|
|
SysDept sysDeptByClass = sysDeptMapper.selectDeptById(Long.valueOf(classId));
|
|
|
|
//为空则新增一条数据
|
|
|
|
//为空则新增一条数据
|
|
|
|
if (sysDeptByClass==null){
|
|
|
|
if (sysDeptByClass == null) {
|
|
|
|
Long deptId = sysDept.getDeptId(); //已有的学校ID
|
|
|
|
Long deptId = sysDept.getDeptId(); //已有的学校ID
|
|
|
|
|
|
|
|
|
|
|
|
Integer classSort = sysDeptMapper.selectByParentId(deptId);
|
|
|
|
Integer classSort = sysDeptMapper.selectByParentId(deptId);
|
|
|
|
SysDept newSysDeptByClass =new SysDept();
|
|
|
|
SysDept newSysDeptByClass = new SysDept();
|
|
|
|
newSysDeptByClass.setDeptId(Long.valueOf(zyUserInfo.getClassId()));
|
|
|
|
newSysDeptByClass.setDeptId(Long.valueOf(zyUserInfo.getClassId()));
|
|
|
|
newSysDeptByClass.setDeptName(zyUserInfo.getClassName());
|
|
|
|
newSysDeptByClass.setDeptName(zyUserInfo.getClassName());
|
|
|
|
newSysDeptByClass.setParentId(deptId); //学校的ID
|
|
|
|
newSysDeptByClass.setParentId(deptId); //学校的ID
|
|
|
|
newSysDeptByClass.setAncestors("0,100,"+deptId);
|
|
|
|
newSysDeptByClass.setAncestors("0,100," + deptId);
|
|
|
|
newSysDeptByClass.setOrderNum(classSort);//排序
|
|
|
|
newSysDeptByClass.setOrderNum(classSort);//排序
|
|
|
|
newSysDeptByClass.setCreateTime(new Date());
|
|
|
|
newSysDeptByClass.setCreateTime(new Date());
|
|
|
|
newSysDeptByClass.setUpdateBy(new Date().toString());
|
|
|
|
newSysDeptByClass.setUpdateBy(new Date().toString());
|
|
|
|