发布优化,数据权限优化

This commit is contained in:
cjw 2024-11-14 15:56:18 +08:00
parent d7b9a677d6
commit 877307a77e
9 changed files with 85 additions and 76 deletions

View File

@ -77,7 +77,7 @@ spring:
# 单个文件大小
max-file-size: 10MB
# 设置总上传的文件大小
max-request-size: 20MB
max-request-size: 50MB
mvc:
# 设置静态资源路径 防止所有请求都去查静态资源
static-path-pattern: /static/**

View File

@ -37,10 +37,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.util.ClassUtils;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
@ -133,44 +130,46 @@ public class PlusDataPermissionHandler {
context.setBeanResolver(beanResolver);
DataPermissionHelper.getContext().forEach(context::setVariable);
Set<String> conditions = new HashSet<>();
for (RoleDTO role : user.getRoles()) {
user.setRoleId(role.getRoleId());
// 获取角色权限泛型
DataScopeType type = DataScopeType.findCode(role.getDataScope());
if (ObjectUtil.isNull(type)) {
throw new ServiceException("角色数据范围异常 => " + role.getDataScope());
}
// 全部数据权限直接返回
if (type == DataScopeType.ALL) {
return "";
}
boolean isSuccess = false;
for (DataColumn dataColumn : dataColumns) {
if (dataColumn.key().length != dataColumn.value().length) {
throw new ServiceException("角色数据范围异常 => key与value长度不匹配");
List<RoleDTO> roles = user.getRoles();
if (roles != null && !roles.isEmpty()) {
for (RoleDTO role : roles) {
user.setRoleId(role.getRoleId());
// 获取角色权限泛型
DataScopeType type = DataScopeType.findCode(role.getDataScope());
if (ObjectUtil.isNull(type)) {
throw new ServiceException("角色数据范围异常 => " + role.getDataScope());
}
// 不包含 key 变量 则不处理
if (!StringUtils.containsAny(type.getSqlTemplate(),
Arrays.stream(dataColumn.key()).map(key -> "#" + key).toArray(String[]::new)
)) {
continue;
}
// 设置注解变量 key 为表达式变量 value 为变量值
for (int i = 0; i < dataColumn.key().length; i++) {
context.setVariable(dataColumn.key()[i], dataColumn.value()[i]);
// 全部数据权限直接返回
if (type == DataScopeType.ALL) {
return "";
}
boolean isSuccess = false;
for (DataColumn dataColumn : dataColumns) {
if (dataColumn.key().length != dataColumn.value().length) {
throw new ServiceException("角色数据范围异常 => key与value长度不匹配");
}
// 不包含 key 变量 则不处理
if (!StringUtils.containsAny(type.getSqlTemplate(),
Arrays.stream(dataColumn.key()).map(key -> "#" + key).toArray(String[]::new)
)) {
continue;
}
// 设置注解变量 key 为表达式变量 value 为变量值
for (int i = 0; i < dataColumn.key().length; i++) {
context.setVariable(dataColumn.key()[i], dataColumn.value()[i]);
}
// 解析sql模板并填充
String sql = parser.parseExpression(type.getSqlTemplate(), parserContext).getValue(context, String.class);
conditions.add(joinStr + sql);
isSuccess = true;
}
// 未处理成功则填充兜底方案
if (!isSuccess && StringUtils.isNotBlank(type.getElseSql())) {
conditions.add(joinStr + type.getElseSql());
// 解析sql模板并填充
String sql = parser.parseExpression(type.getSqlTemplate(), parserContext).getValue(context, String.class);
conditions.add(joinStr + sql);
isSuccess = true;
}
// 未处理成功则填充兜底方案
if (!isSuccess && StringUtils.isNotBlank(type.getElseSql())) {
conditions.add(joinStr + type.getElseSql());
}
}
}
if (CollUtil.isNotEmpty(conditions)) {
String sql = StreamUtils.join(conditions, Function.identity(), "");
return sql.substring(joinStr.length());

View File

@ -126,4 +126,6 @@ public class CounselorVo implements Serializable {
*/
private Integer reservationNum;
private List<String> qualificationUrlList;
}

View File

@ -16,10 +16,10 @@ import java.util.List;
public class EvaluationRecordWordData {
private String createTime;
private String schoolName;
// private String schoolName;
private String useTime;
private String nickName;
private String deptName;
// private String deptName;
private String sex;
private String scaleName;
private String scaleDetails;

View File

@ -17,21 +17,24 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.domain.Counselor;
import org.dromara.system.domain.CounselorExperience;
import org.dromara.system.domain.CounselorQualification;
import org.dromara.system.domain.bo.CounselorBo;
import org.dromara.system.domain.bo.QueryCounselorBo;
import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.CounselorVo;
import org.dromara.system.domain.vo.ScoreRateVo;
import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.mapper.CounselorExperienceMapper;
import org.dromara.system.mapper.CounselorMapper;
import org.dromara.system.mapper.CounselorQualificationMapper;
import org.dromara.system.mapper.ScoreRecordMapper;
import org.dromara.system.service.ICounselorService;
import org.dromara.system.domain.bo.SysUserBo;
import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.service.ISysUserService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -48,6 +51,7 @@ public class CounselorServiceImpl implements ICounselorService {
private final CounselorMapper baseMapper;
private final CounselorExperienceMapper experienceMapper;
private final CounselorQualificationMapper qualificationMapper;
private final ScoreRecordMapper scoreRecordMapper;
private final DictService dictService;
@ -72,7 +76,14 @@ public class CounselorServiceImpl implements ICounselorService {
Long l = experienceMapper.selectCount(new LambdaQueryWrapper<CounselorExperience>()
.eq(CounselorExperience::getCounselorId, id));
counselorVo.setExperienceNum(l.intValue());
List<CounselorQualification> qualificationList = qualificationMapper.selectList(new LambdaQueryWrapper<CounselorQualification>()
.eq(CounselorQualification::getCounselorId, id));
List<String> imageList = new ArrayList<>(qualificationList.size());
for (CounselorQualification qualification : qualificationList) {
String s = ossService.selectUrlByIds(qualification.getCertificateImage().toString());
imageList.add(s);
}
counselorVo.setQualificationUrlList(imageList);
Date practiceTime = counselorVo.getPracticeTime();
String betweenYear = DateUtils.getBetweenYear(practiceTime, new Date());
counselorVo.setPracticeString(betweenYear);

View File

@ -15,10 +15,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.dromara.common.core.constant.TenantConstants;
import org.dromara.common.core.service.DeptService;
import org.dromara.common.core.service.OssService;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
@ -40,7 +38,6 @@ import org.dromara.system.mapper.SysEvaluationRecordMapper;
import org.dromara.system.mapper.SysScaleMapper;
import org.dromara.system.mapper.SysUserMapper;
import org.dromara.system.service.IMyService;
import org.dromara.system.service.ISysConfigService;
import org.springframework.stereotype.Service;
import java.io.File;
@ -69,9 +66,9 @@ public class MyServiceImpl implements IMyService {
private final ReservationOrderMapper reservationOrderMapper;
private final SysUserMapper userMapper;
private final DeptService deptService;
//private final DeptService deptService;
private final OssService ossService;
private final ISysConfigService configService;
//private final ISysConfigService configService;
@Override
@ -194,13 +191,13 @@ public class MyServiceImpl implements IMyService {
}
EvaluationRecordWordData wordData = new EvaluationRecordWordData();
String name = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> configService.selectConfigByKey("sys.school.name"));
if (StringUtils.isEmpty(name)) {
wordData.setSchoolName(name);
} else {
wordData.setSchoolName("");
}
// String name = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> configService.selectConfigByKey("sys.school.name"));
// if (StringUtils.isEmpty(name)) {
// wordData.setSchoolName(name);
// } else {
// wordData.setSchoolName("");
// }
// wordData.setSchoolName("云舒心理健康成长平台");
SysEvaluationRecord sysEvaluationRecord = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> evaluationRecordMapper.selectById(recordId));
Date createTime = sysEvaluationRecord.getCreateTime();
Date updateTime = sysEvaluationRecord.getUpdateTime();
@ -209,12 +206,12 @@ public class MyServiceImpl implements IMyService {
SysUserVo user = userMapper.selectVoById(userId);
wordData.setNickName(user.getNickName());
if (user.getDeptId() != null) {
String s = deptService.selectDeptNameByIds(Long.toString(user.getDeptId()));
wordData.setDeptName(s);
} else {
wordData.setDeptName("");
}
// if (user.getDeptId() != null) {
// String s = deptService.selectDeptNameByIds(Long.toString(user.getDeptId()));
// wordData.setDeptName(s);
// } else {
// wordData.setDeptName("");
// }
wordData.setSex("0".equals(user.getSex()) ? "" : "");
SysScaleVo scale = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> scaleMapper.selectVoById(scaleId));
@ -320,7 +317,7 @@ public class MyServiceImpl implements IMyService {
}
Configure config = Configure.builder()
.bind("factors", new LoopRowTableRenderPolicy()).useSpringEL().build();
XWPFTemplate.compile(path, config).render(wordData);
XWPFTemplate.compile(path, config).render(wordData);
return wordPath;
}
}

View File

@ -14,7 +14,6 @@ import lombok.RequiredArgsConstructor;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.dromara.common.core.service.DeptService;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.SysEvaluationRecord;
@ -127,12 +126,12 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi
}
EvaluationRecordWordData wordData = new EvaluationRecordWordData();
String name = configService.selectConfigByKey("sys.school.name");
if (StringUtils.isEmpty(name)) {
wordData.setSchoolName(name);
} else {
wordData.setSchoolName("");
}
// String name = configService.selectConfigByKey("sys.school.name");
// if (StringUtils.isEmpty(name)) {
// wordData.setSchoolName(name);
// } else {
// wordData.setSchoolName("");
// }
SysEvaluationRecord sysEvaluationRecord = baseMapper.selectById(recordId);
Date createTime = sysEvaluationRecord.getCreateTime();
@ -142,12 +141,12 @@ public class SysEvaluationRecordServiceImpl implements ISysEvaluationRecordServi
SysUserVo user = userMapper.selectVoById(userId);
wordData.setNickName(user.getNickName());
if (user.getDeptId() != null) {
String s = deptService.selectDeptNameByIds(Long.toString(user.getDeptId()));
wordData.setDeptName(s);
} else {
wordData.setDeptName("");
}
// if (user.getDeptId() != null) {
// String s = deptService.selectDeptNameByIds(Long.toString(user.getDeptId()));
// wordData.setDeptName(s);
// } else {
// wordData.setDeptName("");
// }
wordData.setSex("0".equals(user.getSex()) ? "" : "");
SysScaleVo scale = scaleMapper.selectVoById(scaleId);

View File

@ -206,6 +206,7 @@ public class SysScalePublishServiceImpl implements ISysScalePublishService {
record.setDeptId(user.getDeptId());
record.setBatchNo(batchNo);
record.setScaleId(Long.parseLong(scaleId));
record.setPublishFlag(1);
//初始化字段
record.setStatus(0);
recordList.add(record);

View File

@ -73,7 +73,7 @@
select u.*
from sys_dept d
left join sys_user u on u.dept_id = d.dept_id
where u.user_type = 'student'
where u.user_type = 'app_user'
and u.del_flag = 0
and find_in_set(d.dept_id, #{deptIds})
</select>