前端代码

This commit is contained in:
liumengyu
2026-08-21 18:42:51 +08:00
parent 054947482f
commit 04e06a9c9a
762 changed files with 62992 additions and 0 deletions
@@ -0,0 +1,181 @@
package com.roomroot.jwgl.utils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.roomroot.common.constant.Constants;
import com.roomroot.common.core.domain.entity.SysRole;
import com.roomroot.common.core.domain.entity.SysUser;
import com.roomroot.common.core.domain.model.LoginUser;
import com.roomroot.common.exception.ServiceException;
import com.roomroot.common.utils.SecurityUtils;
import com.roomroot.common.utils.StringUtils;
import com.roomroot.jwgl.entity.JYB;
import com.roomroot.jwgl.entity.XYXX;
import com.roomroot.jwgl.mapper.JYBMapper;
import com.roomroot.jwgl.mapper.JYSDLBMapper;
import com.roomroot.jwgl.mapper.XYXXMapper;
import org.springframework.stereotype.Component;
import jakarta.annotation.Resource;
import java.util.List;
import static com.roomroot.jwgl.utils.AccountManagementConstants.ROLE_DEPARTMENT_PERSONNEL;
import static com.roomroot.jwgl.utils.AccountManagementConstants.ROLE_RESEARCH_OFFICE;
import static com.roomroot.jwgl.utils.AccountManagementConstants.ROLE_STUDENT;
import static com.roomroot.jwgl.utils.AccountManagementConstants.ROLE_TEACHER;
import static com.roomroot.jwgl.utils.BasicManagementConstants.FORBIDDEN;
/**
* 教务角色识别与本人数据范围。
* <p>管理员、机关人员(教务部)看全部;教员看本人;学员看本人。</p>
*/
@Component
public class JwglRoleHelper {
@Resource
private JYBMapper jybMapper;
@Resource
private XYXXMapper xyxxMapper;
@Resource
private JYSDLBMapper jysdlbMapper;
public boolean isAdmin() {
try {
if (SecurityUtils.isAdmin()) {
return true;
}
return hasRoleKey(Constants.SUPER_ADMIN);
} catch (Exception ex) {
return false;
}
}
public boolean isDepartmentPersonnel() {
return isAdmin() || hasRoleKey(ROLE_DEPARTMENT_PERSONNEL);
}
public boolean isResearchOffice() {
if (isDepartmentPersonnel()) {
return false;
}
if (hasRoleKey(ROLE_RESEARCH_OFFICE)) {
return true;
}
if (hasRoleKey(ROLE_TEACHER)) {
return false;
}
return StringUtils.isNotEmpty(findResearchOfficeId());
}
public boolean isTeacher() {
return !isDepartmentPersonnel() && !isResearchOffice() && hasRoleKey(ROLE_TEACHER);
}
public boolean isStudent() {
return !isDepartmentPersonnel() && !hasRoleKey(ROLE_TEACHER) && hasRoleKey(ROLE_STUDENT);
}
public String requireTeacherId() {
String teacherId = findTeacherId();
if (StringUtils.isEmpty(teacherId)) {
throw new ServiceException("当前登录用户不是教员,无法查看教员数据", FORBIDDEN);
}
return teacherId;
}
public String requireResearchOfficeId() {
String officeId = findResearchOfficeId();
if (StringUtils.isEmpty(officeId)) {
throw new ServiceException("当前登录用户不是教研室账号,无法审批本室申请", FORBIDDEN);
}
return officeId;
}
public String findResearchOfficeId() {
try {
String username = SecurityUtils.getUsername();
if (StringUtils.isEmpty(username) || jysdlbMapper == null) {
return null;
}
return jysdlbMapper.selectResearchOfficeIdByAccount(username);
} catch (Exception ignored) {
return null;
}
}
public String requireStudentId() {
String studentId = findStudentId();
if (StringUtils.isEmpty(studentId)) {
throw new ServiceException("当前登录用户不是学员,无法查看学员数据", FORBIDDEN);
}
return studentId;
}
public String findTeacherId() {
try {
String username = SecurityUtils.getUsername();
if (StringUtils.isNotEmpty(username)) {
String fromLogin = jybMapper.selectTeacherIdByAccount(username);
if (StringUtils.isNotEmpty(fromLogin)) {
return fromLogin.trim();
}
JYB byId = jybMapper.selectById(username);
if (byId != null) {
return byId.getJybh();
}
}
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = loginUser.getUser();
String nickName = user == null ? null : user.getNickName();
if (StringUtils.isNotEmpty(nickName)) {
List<JYB> matched = jybMapper.selectList(
new LambdaQueryWrapper<JYB>().eq(JYB::getJyxm, nickName));
if (matched != null && matched.size() == 1) {
return matched.get(0).getJybh();
}
}
} catch (Exception ignored) {
return null;
}
return null;
}
public String findStudentId() {
try {
String username = SecurityUtils.getUsername();
if (StringUtils.isNotEmpty(username)) {
XYXX byXh = xyxxMapper.selectOne(
new LambdaQueryWrapper<XYXX>().eq(XYXX::getXh, username));
if (byXh != null) {
return byXh.getBh();
}
XYXX byBh = xyxxMapper.selectById(username);
if (byBh != null) {
return byBh.getBh();
}
}
} catch (Exception ignored) {
return null;
}
return null;
}
private boolean hasRoleKey(String roleKey) {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = loginUser.getUser();
if (user == null || user.getRoles() == null || StringUtils.isEmpty(roleKey)) {
return false;
}
for (SysRole role : user.getRoles()) {
if (role != null && roleKey.equalsIgnoreCase(role.getRoleKey())) {
return true;
}
}
return false;
} catch (Exception ex) {
return false;
}
}
}