|
|
|
@ -5,9 +5,12 @@ import java.util.*;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.ruoyi.biemo.business.domain.ZYUserInfo;
|
|
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
|
|
import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
|
|
import com.ruoyi.common.utils.ServletUtils;
|
|
|
|
|
import com.ruoyi.framework.web.service.TokenService;
|
|
|
|
|
import com.ruoyi.system.domain.SysUserRole;
|
|
|
|
|
import com.ruoyi.system.mapper.SysDeptMapper;
|
|
|
|
|
import com.ruoyi.system.mapper.SysUserMapper;
|
|
|
|
|
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
|
|
|
|
import com.ruoyi.web.config.exception.UnAuthorizedException;
|
|
|
|
@ -18,6 +21,7 @@ import com.ruoyi.web.util.RsaUtil;
|
|
|
|
|
import com.ruoyi.web.util.TzApi;
|
|
|
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -67,6 +71,9 @@ public class SysLoginController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysDeptMapper sysDeptMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录方法
|
|
|
|
@ -79,6 +86,8 @@ public class SysLoginController {
|
|
|
|
|
public AjaxResult login(@RequestBody(required = false) LoginBody loginBody,
|
|
|
|
|
@RequestParam(required = false) String TOKEN) {
|
|
|
|
|
|
|
|
|
|
//todo user表中的deptId等于classId
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(TOKEN)) {
|
|
|
|
|
String username = loginBody.getUsername();
|
|
|
|
|
SysUser sysUser = sysUserMapper.selectUserByStudentNumber(username);
|
|
|
|
@ -123,12 +132,18 @@ public class SysLoginController {
|
|
|
|
|
String tokenWbdsj = loginService.login(sysUser.getUserName(), "123456", "1",
|
|
|
|
|
String.valueOf(UUID.randomUUID()));
|
|
|
|
|
ajax.put(Constants.TOKEN, tokenWbdsj);
|
|
|
|
|
ajax.put("deptId",sysUser.getDeptId());
|
|
|
|
|
ajax.put("deptId",sysUser.getDeptId()); //班级ID
|
|
|
|
|
ajax.put("UserId",sysUser.getUserId());
|
|
|
|
|
|
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(sysUser.getDeptId());
|
|
|
|
|
Long parentId = sysDept.getParentId();
|
|
|
|
|
ajax.put("schoolId",parentId.toString()); //学校ID
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo 多加一个deptId
|
|
|
|
|
/**
|
|
|
|
|
* 获取用户信息
|
|
|
|
|
*
|
|
|
|
@ -142,9 +157,11 @@ public class SysLoginController {
|
|
|
|
|
// 权限集合
|
|
|
|
|
Set<String> permissions = permissionService.getMenuPermission(user);
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
Long deptId = user.getDeptId();
|
|
|
|
|
ajax.put("user", user);
|
|
|
|
|
ajax.put("roles", roles);
|
|
|
|
|
ajax.put("permissions", permissions);
|
|
|
|
|
ajax.put("deptId",deptId); //这是班级ID
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -169,43 +186,111 @@ public class SysLoginController {
|
|
|
|
|
return AjaxResult.success(menuService.buildMenus(menus));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @ApiOperation("根据用户Code查询该用户是否存在个人赛用户数据,存在则返回,不存在则新增后返回,用于智云3.0创建用户后调用该接口创建用户个人赛")
|
|
|
|
|
// @PostMapping("/checkOrCreateForexSimulationUser")
|
|
|
|
|
// public String checkOrCreateForexSimulationUser(@RequestBody List<ZYUserInfo> zyUserInfoList,
|
|
|
|
|
// @RequestParam String systemOwner) {
|
|
|
|
|
// System.out.println(systemOwner);
|
|
|
|
|
// List<SysUser> users = new ArrayList<>();
|
|
|
|
|
// for (int i = 0; i < zyUserInfoList.size(); i++) {
|
|
|
|
|
// ZYUserInfo zyUserInfo = zyUserInfoList.get(i);
|
|
|
|
|
// Integer zyUserId = zyUserInfo.getUserId();
|
|
|
|
|
// String username = zyUserInfo.getUsername(); // studentid
|
|
|
|
|
// String name = zyUserInfo.getName();
|
|
|
|
|
// String password = zyUserInfo.getPassword();
|
|
|
|
|
// Integer roleId = zyUserInfo.getRoleId(); //3教师 4学生
|
|
|
|
|
//
|
|
|
|
|
// SysUser userInfo = sysUserMapper.selectUserById(Long.valueOf(zyUserId));
|
|
|
|
|
// if (userInfo!=null) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// SysUser stuUser = new SysUser();
|
|
|
|
|
// stuUser.setUserid(IdUtil.randomUUID());
|
|
|
|
|
// stuUser.setStudentId(zyUserInfo.getUsername());
|
|
|
|
|
// stuUser.setName(name);
|
|
|
|
|
// stuUser.setUsername(username);
|
|
|
|
|
// stuUser.setClassId(zyUserInfo.getClassId().toString());
|
|
|
|
|
// stuUser.setPassword(password);
|
|
|
|
|
// stuUser.setPhone(zyUserInfo.getPhone());
|
|
|
|
|
// stuUser.setMajor(zyUserInfo.getMajorName());
|
|
|
|
|
// stuUser.setRoleId(roleId);
|
|
|
|
|
// stuUser.setSchoolId(zyUserInfo.getSchoolId().toString());
|
|
|
|
|
// stuUser.setSchoolName(zyUserInfo.getSchoolName());
|
|
|
|
|
// stuUser.setCreateTime(new Date());
|
|
|
|
|
// users.add(stuUser);
|
|
|
|
|
// }
|
|
|
|
|
// if (users.isEmpty()) {
|
|
|
|
|
// return "账号已全部存在";
|
|
|
|
|
// }
|
|
|
|
|
// userInfoMapper.batchInsertUserInfo(users);
|
|
|
|
|
// return "ok";
|
|
|
|
|
// }
|
|
|
|
|
@ApiOperation("根据用户Code查询该用户是否存在个人赛用户数据,存在则返回,不存在则新增后返回,用于智云3.0创建用户后调用该接口创建用户个人赛")
|
|
|
|
|
@PostMapping("/checkOrCreateForexSimulationUser")
|
|
|
|
|
public String checkOrCreateForexSimulationUser(@RequestBody List<ZYUserInfo> zyUserInfoList,
|
|
|
|
|
@RequestParam String systemOwner) {
|
|
|
|
|
System.out.println(systemOwner);
|
|
|
|
|
List<SysUser> users = new ArrayList<>();
|
|
|
|
|
List<SysUserRole> userRoleList = new ArrayList<>();
|
|
|
|
|
List<SysDept> sysDeptList = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < zyUserInfoList.size(); i++) {
|
|
|
|
|
ZYUserInfo zyUserInfo = zyUserInfoList.get(i);
|
|
|
|
|
Integer zyUserId = zyUserInfo.getUserId();
|
|
|
|
|
String username = zyUserInfo.getUsername(); // studentid
|
|
|
|
|
String name = zyUserInfo.getName();
|
|
|
|
|
String password = zyUserInfo.getPassword();
|
|
|
|
|
Integer roleId = zyUserInfo.getRoleId(); //3教师 4学生
|
|
|
|
|
Integer classId = zyUserInfo.getClassId();
|
|
|
|
|
Long userId = Long.valueOf(zyUserId);
|
|
|
|
|
SysUser userInfo = sysUserMapper.selectUserById(userId);
|
|
|
|
|
if (userInfo!=null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//填充用户信息
|
|
|
|
|
SysUser stuUser = new SysUser();
|
|
|
|
|
stuUser.setUserId(userId); //使用智云的
|
|
|
|
|
stuUser.setDeptId(Long.valueOf(classId));
|
|
|
|
|
stuUser.setUserName(username);
|
|
|
|
|
stuUser.setNickName(name);
|
|
|
|
|
stuUser.setPassword(password);
|
|
|
|
|
stuUser.setPhonenumber(zyUserInfo.getPhone());
|
|
|
|
|
stuUser.setStuClass(zyUserInfo.getClassName());
|
|
|
|
|
stuUser.setStudentNumber(zyUserInfo.getUsername());
|
|
|
|
|
stuUser.setCreateTime(new Date());
|
|
|
|
|
stuUser.setStatus("0");
|
|
|
|
|
stuUser.setDelFlag("0");
|
|
|
|
|
|
|
|
|
|
users.add(stuUser);
|
|
|
|
|
|
|
|
|
|
//填充角色信息
|
|
|
|
|
SysUserRole sysUserRole =new SysUserRole();
|
|
|
|
|
sysUserRole.setUserId(userId);
|
|
|
|
|
if (roleId==3) {
|
|
|
|
|
sysUserRole.setRoleId(100L); //100是老师 2是学生
|
|
|
|
|
}
|
|
|
|
|
if (roleId==4){
|
|
|
|
|
sysUserRole.setRoleId(2L);
|
|
|
|
|
}
|
|
|
|
|
userRoleList.add(sysUserRole);
|
|
|
|
|
|
|
|
|
|
//填充学校和班级信息
|
|
|
|
|
SysDept sysDept = sysDeptMapper.selectDeptById(Long.valueOf(zyUserInfo.getSchoolId())); //判断学校是否存在
|
|
|
|
|
if (sysDept==null){
|
|
|
|
|
//添加一条学校数据
|
|
|
|
|
SysDept newSysDept =new SysDept();
|
|
|
|
|
newSysDept.setDeptId(Long.valueOf(zyUserInfo.getSchoolId()));
|
|
|
|
|
newSysDept.setDeptName(zyUserInfo.getSchoolName());
|
|
|
|
|
newSysDept.setParentId(0L); //顶级节点
|
|
|
|
|
newSysDept.setAncestors("0,100");
|
|
|
|
|
Integer sort = sysDeptMapper.getOrderNumMax();
|
|
|
|
|
newSysDept.setOrderNum(sort+1);//排序
|
|
|
|
|
newSysDept.setCreateTime(new Date());
|
|
|
|
|
newSysDept.setUpdateBy(new Date().toString());
|
|
|
|
|
newSysDept.setStatus("0");
|
|
|
|
|
newSysDept.setDelFlag("0");
|
|
|
|
|
sysDeptList.add(newSysDept);
|
|
|
|
|
|
|
|
|
|
//添加一条班级数据
|
|
|
|
|
SysDept newSysDeptByClass =new SysDept();
|
|
|
|
|
newSysDeptByClass.setDeptId(Long.valueOf(zyUserInfo.getClassId()));
|
|
|
|
|
newSysDeptByClass.setDeptName(zyUserInfo.getClassName());
|
|
|
|
|
newSysDeptByClass.setParentId(newSysDept.getDeptId()); //学校的ID
|
|
|
|
|
newSysDeptByClass.setAncestors("0,100,"+newSysDept.getDeptId());
|
|
|
|
|
newSysDeptByClass.setOrderNum(1);//排序
|
|
|
|
|
newSysDeptByClass.setCreateTime(new Date());
|
|
|
|
|
newSysDeptByClass.setUpdateBy(new Date().toString());
|
|
|
|
|
newSysDeptByClass.setStatus("0");
|
|
|
|
|
newSysDeptByClass.setDelFlag("0");
|
|
|
|
|
sysDeptList.add(newSysDeptByClass);
|
|
|
|
|
|
|
|
|
|
}else { // 学校存在 判断班级是否存在
|
|
|
|
|
SysDept sysDeptByClass = sysDeptMapper.selectDeptById(Long.valueOf(classId));
|
|
|
|
|
//为空则新增一条数据
|
|
|
|
|
if (sysDeptByClass==null){
|
|
|
|
|
Long deptId = sysDept.getDeptId(); //已有的学校ID
|
|
|
|
|
|
|
|
|
|
Integer classSort = sysDeptMapper.selectByParentId(deptId);
|
|
|
|
|
SysDept newSysDeptByClass =new SysDept();
|
|
|
|
|
newSysDeptByClass.setDeptId(Long.valueOf(zyUserInfo.getClassId()));
|
|
|
|
|
newSysDeptByClass.setDeptName(zyUserInfo.getClassName());
|
|
|
|
|
newSysDeptByClass.setParentId(deptId); //学校的ID
|
|
|
|
|
newSysDeptByClass.setAncestors("0,100,"+deptId);
|
|
|
|
|
newSysDeptByClass.setOrderNum(classSort);//排序
|
|
|
|
|
newSysDeptByClass.setCreateTime(new Date());
|
|
|
|
|
newSysDeptByClass.setUpdateBy(new Date().toString());
|
|
|
|
|
newSysDeptByClass.setStatus("0");
|
|
|
|
|
newSysDeptByClass.setDelFlag("0");
|
|
|
|
|
sysDeptList.add(newSysDeptByClass);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (users.isEmpty()) {
|
|
|
|
|
return "账号已全部存在";
|
|
|
|
|
}
|
|
|
|
|
sysUserMapper.batchInsertUserInfo(users);
|
|
|
|
|
sysUserRoleMapper.batchUserRole(userRoleList);
|
|
|
|
|
sysDeptMapper.batchInsertUserInfo(sysDeptList);
|
|
|
|
|
return "ok";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|