新建题库,查询题库需要权限
This commit is contained in:
parent
af1102a1b9
commit
a07f29f9b2
@ -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<AiolRepo, IAiolRepoService> {
|
||||
@Autowired
|
||||
private IAiolRepoService aiolRepoService;
|
||||
@Autowired
|
||||
private IAiolEntityPermissionService aiolEntityPermissionService;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseApi;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
@ -224,16 +232,62 @@ public class AiolRepoController extends JeecgController<AiolRepo, IAiolRepoServi
|
||||
}
|
||||
|
||||
@GetMapping("repoList")
|
||||
@Operation(summary = "获取所有题库")
|
||||
public Result<List<AiolRepo>> repoList() {
|
||||
return Result.ok(aiolRepoService.list());
|
||||
@Operation(summary = "获取有权限的所有题库")
|
||||
public Result<List<AiolRepo>> 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<AiolEntityPermission> list = aiolEntityPermissionService.list(new QueryWrapper<AiolEntityPermission>()
|
||||
.eq("user_id", sysUser.getId())
|
||||
.eq("entity_type", "repo")
|
||||
);
|
||||
if (list.isEmpty()) {
|
||||
return Result.error("该用户没有权限访问任意题库");
|
||||
}
|
||||
List<String> 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<String> courseAdd(@RequestBody AiolRepo repo) {
|
||||
return aiolRepoService.save(repo) ? Result.OK("添加成功!") : Result.error("添加失败!");
|
||||
@Transactional
|
||||
public Result<String> 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());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user