From 63e35191877352b2579ff47b0e3b823a031df6ce Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Wed, 19 Mar 2025 10:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index a459e19..2de2162 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -128,11 +128,15 @@ public class SysLoginController { map.put("token", token); SysUser sysUser = sysUserMapper.selectUserByUserName(String.valueOf(map.get("username"))); AjaxResult ajax = AjaxResult.success(); + + // 生成令牌 - String tokenWbdsj = loginService.login(sysUser.getUserName(), "123456", "1", - String.valueOf(UUID.randomUUID())); - ajax.put(Constants.TOKEN, tokenWbdsj); +// String tokenWbdsj = loginService.login(sysUser.getUserName(), "123456", "1", +// String.valueOf(UUID.randomUUID())); +// ajax.put(Constants.TOKEN, tokenWbdsj); + ajax.put("token", token); + ajax.put("roleId", loginResult.getRoleId()); //班级名称为空, 是老师账号 if (sysUser.getStuClass() != null) { ajax.put("deptId", sysUser.getDeptId()); //班级ID @@ -143,8 +147,8 @@ public class SysLoginController { ajax.put("schoolId", sysUser.getDeptId()); //老师账号的deptId就是存的学校ID } ajax.put("UserId", sysUser.getUserId()); - - + ajax.put("name", loginResult.getName()); + ajax.put("username", loginResult.getUsername()); return ajax; } } @@ -200,7 +204,9 @@ public class SysLoginController { public String checkOrCreateForexSimulationUser(@RequestBody List zyUserInfoList) { List users = new ArrayList<>(); List userRoleList = new ArrayList<>(); - List sysDeptList = new ArrayList<>(); + // 使用 Map 去重 + Map sysDeptMap = new HashMap<>(); + for (int i = 0; i < zyUserInfoList.size(); i++) { ZYUserInfo zyUserInfo = zyUserInfoList.get(i); Integer zyUserId = zyUserInfo.getUserId(); @@ -269,7 +275,7 @@ public class SysLoginController { newSysDept.setUpdateBy(new Date().toString()); newSysDept.setStatus("0"); newSysDept.setDelFlag("0"); - sysDeptList.add(newSysDept); + sysDeptMap.put(newSysDept.getDeptId(), newSysDept); // 使用 Map 去重 //添加一条班级数据 SysDept newSysDeptByClass = new SysDept(); @@ -282,7 +288,7 @@ public class SysLoginController { newSysDeptByClass.setUpdateBy(new Date().toString()); newSysDeptByClass.setStatus("0"); newSysDeptByClass.setDelFlag("0"); - sysDeptList.add(newSysDeptByClass); + sysDeptMap.put(newSysDeptByClass.getDeptId(), newSysDeptByClass); // 使用 Map 去重 } else { // 学校存在 判断班级是否存在 SysDept sysDeptByClass = sysDeptMapper.selectDeptById(Long.valueOf(classId)); @@ -301,13 +307,15 @@ public class SysLoginController { newSysDeptByClass.setUpdateBy(new Date().toString()); newSysDeptByClass.setStatus("0"); newSysDeptByClass.setDelFlag("0"); - sysDeptList.add(newSysDeptByClass); + sysDeptMap.put(newSysDeptByClass.getDeptId(), newSysDeptByClass); // 使用 Map 去重 } } } if (users.isEmpty()) { return "账号已全部存在"; } + // 将 Map 转换为 List + List sysDeptList = new ArrayList<>(sysDeptMap.values()); sysUserMapper.batchInsertUserInfo(users); sysUserRoleMapper.batchUserRole(userRoleList); sysDeptMapper.batchInsertUserInfo(sysDeptList);