From af1102a1b905bcc7e7472897d074a5dae89bacfa Mon Sep 17 00:00:00 2001 From: Lqc Date: Mon, 8 Sep 2025 16:26:51 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=BF=94=E5=9B=9Eid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/modules/aiol/controller/AiolPaperController.java | 2 +- .../jeecg/modules/aiol/controller/AiolQuestionController.java | 2 +- .../org/jeecg/modules/aiol/controller/AiolRepoController.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java index 543712b2..8c81b8d4 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolPaperController.java @@ -89,7 +89,7 @@ public class AiolPaperController extends JeecgController add(@RequestBody AiolPaper aiolPaper) { aiolPaperService.save(aiolPaper); - return Result.OK("添加成功!"); + return Result.OK(aiolPaper.getId()); } /** diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionController.java index e549de26..e3fd502d 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolQuestionController.java @@ -101,7 +101,7 @@ public class AiolQuestionController extends JeecgController edit(@RequestBody AiolRepo aiolRepo) { aiolRepoService.updateById(aiolRepo); - return Result.OK("编辑成功!"); + return Result.OK(aiolRepo.getId()); } /** From a07f29f9b202b7e8c5be48a0111c324c5f41b6c5 Mon Sep 17 00:00:00 2001 From: Lqc Date: Mon, 8 Sep 2025 17:21:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=A2=98=E5=BA=93?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E8=AF=A2=E9=A2=98=E5=BA=93=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiol/controller/AiolRepoController.java | 64 +++++++++++++++++-- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java index 22c4e7c9..46be4481 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java @@ -16,12 +16,16 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import org.apache.poi.ss.usermodel.Workbook; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.system.api.ISysBaseAPI; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.query.QueryRuleEnum; +import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.UUIDGenerator; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.aiol.constant.EntityLinkConst; +import org.jeecg.modules.aiol.dto.CourseWithTeacherInfo; import org.jeecg.modules.aiol.dto.QuestionAnswerDTO; import org.jeecg.modules.aiol.dto.QuestionExcelDTO; import org.jeecg.modules.aiol.entity.*; @@ -65,6 +69,10 @@ import org.apache.shiro.authz.annotation.RequiresPermissions; public class AiolRepoController extends JeecgController { @Autowired private IAiolRepoService aiolRepoService; + @Autowired + private IAiolEntityPermissionService aiolEntityPermissionService; + @Autowired + private ISysBaseAPI sysBaseApi; /** * 分页列表查询 @@ -224,16 +232,62 @@ public class AiolRepoController extends JeecgController> repoList() { - return Result.ok(aiolRepoService.list()); + @Operation(summary = "获取有权限的所有题库") + public Result> repoList(HttpServletRequest request) { + // 尝试获取token,判断用户id + String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); + if (token != null && !token.trim().isEmpty()) { + try { + String username = JwtUtil.getUsername(token); + LoginUser sysUser = sysBaseApi.getUserByName(username); + + if (sysUser != null) { + // 获取用户有权限的题库ID列表 + List list = aiolEntityPermissionService.list(new QueryWrapper() + .eq("user_id", sysUser.getId()) + .eq("entity_type", "repo") + ); + if (list.isEmpty()) { + return Result.error("该用户没有权限访问任意题库"); + } + List repoIds = list.stream().map(AiolEntityPermission::getEntityId).collect(Collectors.toList()); + // 根据ID列表查询题库 + return Result.ok(repoMapper.selectBatchIds(repoIds)); + } + } catch (Exception e) { + // token无效或解析失败,忽略错误,继续执行原有逻辑 + log.debug("Token解析失败,按未登录用户处理: {}", e.getMessage()); + } + } + return Result.error("请检查登录状态"); } @PostMapping(value = "/courseAdd") @Operation(summary = "课程新建题库") - public Result courseAdd(@RequestBody AiolRepo repo) { - return aiolRepoService.save(repo) ? Result.OK("添加成功!") : Result.error("添加失败!"); + @Transactional + public Result courseAdd(@RequestBody AiolRepo repo,HttpServletRequest request) { + aiolRepoService.save(repo); + AiolEntityPermission aiolEntityPermission = new AiolEntityPermission(); + aiolEntityPermission.setEntityId(repo.getId()); + aiolEntityPermission.setEntityType("repo"); + // 尝试获取token,判断用户id + String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN); + if (token != null && !token.trim().isEmpty()) { + try { + String username = JwtUtil.getUsername(token); + LoginUser sysUser = sysBaseApi.getUserByName(username); + + if (sysUser != null) { + aiolEntityPermission.setUserId(sysUser.getId()); + } + } catch (Exception e) { + // token无效或解析失败,忽略错误,继续执行原有逻辑 + log.debug("Token解析失败,按未登录用户处理: {}", e.getMessage()); + } + } + aiolEntityPermissionService.save(aiolEntityPermission); + return Result.OK(repo.getId()); } From 877f6b604605f1922e7dbd4ec27c0986f72529f4 Mon Sep 17 00:00:00 2001 From: Lqc Date: Wed, 10 Sep 2025 12:57:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=A2=98=E5=BA=93=E6=9D=83=E9=99=90?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=88=A0=E9=99=A4=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aiol/controller/AiolRepoController.java | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java index 46be4481..ef66bf37 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-aiol/src/main/java/org/jeecg/modules/aiol/controller/AiolRepoController.java @@ -37,6 +37,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; +import org.jeecg.modules.system.entity.SysUser; +import org.jeecg.modules.system.service.ISysUserService; import org.jeecgframework.poi.excel.ExcelExportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; @@ -213,6 +215,8 @@ public class AiolRepoController extends JeecgController> userList( + @RequestParam(required = false) String username, + @RequestParam(required = false) String employeeNumber) { + + // 创建查询条件 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + // 当用户名不为空时,添加用户名查询条件(模糊查询) + if (StringUtils.isNotBlank(username)) { + queryWrapper.like(SysUser::getUsername, username); + } + + // 当用户工号不为空时,添加工号查询条件(精确查询) + if (StringUtils.isNotBlank(employeeNumber)) { + queryWrapper.eq(SysUser::getWorkNo, employeeNumber); + } + + // 执行查询 + List userList = sysUserService.list(queryWrapper); + + // 返回结果 + return Result.ok(userList); + } + + + @PostMapping("addPermission") + @Operation(summary = "添加权限") + @Transactional + public Result addPermission(@RequestParam String userId, @RequestParam String repoId) { + AiolEntityPermission aiolEntityPermission = new AiolEntityPermission(); + aiolEntityPermission.setEntityId(repoId); + aiolEntityPermission.setEntityType("repo"); + aiolEntityPermission.setUserId(userId); + aiolEntityPermissionService.saveOrUpdate(aiolEntityPermission); + return Result.OK(); + } + + //获取有权限的用户 + @GetMapping("userListByRepoId/{repoId}") + @Operation(summary = "获取题库有权限的用户列表") + public Result> userListByRepoId(@PathVariable String repoId) { + // 获取用户有权限的题库ID列表 + List list = aiolEntityPermissionService.list(new QueryWrapper() + .eq("entity_id", repoId) + .eq("entity_type", "repo") + ); + if (list.isEmpty()) { + return Result.error("该题库下没有有权限用户或该题库不存在"); + } + List userIds = list.stream().map(AiolEntityPermission::getUserId).collect(Collectors.toList()); + // 根据ID列表查询用户 + return Result.ok(sysUserService.listByIds(userIds)); + } + + @DeleteMapping("deletePermission") + @Operation(summary = "删除权限") + @Transactional + public Result deletePermission(@RequestParam String userId, @RequestParam String repoId) { + AiolEntityPermission aiolEntityPermission = new AiolEntityPermission(); + aiolEntityPermission.setEntityId(repoId); + aiolEntityPermission.setEntityType("repo"); + aiolEntityPermission.setUserId(userId); + aiolEntityPermissionService.remove(new QueryWrapper<>(aiolEntityPermission)); + return Result.OK(); + } + + @GetMapping("/questionList/{repoId}") @Operation(summary = "查询题库下题目")