feat:qms阶段性提交
This commit is contained in:
@@ -87,6 +87,11 @@ public interface BusinessAssayTaskDetailMapper extends BaseMapperX<BusinessAssay
|
||||
return selectList(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>()
|
||||
.eqIfPresent(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskId));
|
||||
}
|
||||
|
||||
default Long selectCountByBusinessAssayTaskId(Long businessAssayTaskId) {
|
||||
return selectCount(new LambdaQueryWrapperX<BusinessAssayTaskDetailDO>()
|
||||
.eqIfPresent(BusinessAssayTaskDetailDO::getBusinessAssayTaskId, businessAssayTaskId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理批量删除删除
|
||||
|
||||
@@ -74,12 +74,19 @@ public interface BusinessSubParentSampleAssessmentProjectMapper extends BaseMapp
|
||||
return selectList(new LambdaQueryWrapper<BusinessSubParentSampleAssessmentProjectDO>()
|
||||
.eq(BusinessSubParentSampleAssessmentProjectDO::getConfigAssayMethodId, configAssayMethodId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
default List<BusinessSubParentSampleAssessmentProjectDO> selectByBusinessSubParentSampleAssessmentIdAndDictionaryProjectIds(Long businessSubParentSampleAssessmentId, List<Long> recheckDictionaryProjectIdList) {
|
||||
return selectList(new LambdaQueryWrapper<BusinessSubParentSampleAssessmentProjectDO>()
|
||||
.eq(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId, businessSubParentSampleAssessmentId)
|
||||
.in(BusinessSubParentSampleAssessmentProjectDO::getDictionaryProjectId, recheckDictionaryProjectIdList));
|
||||
}
|
||||
|
||||
default List<BusinessSubParentSampleAssessmentProjectDO> selectByBusinessSubParentSampleAssessmentId(Long businessSubParentSampleAssessmentId) {
|
||||
return selectList(new LambdaQueryWrapper<BusinessSubParentSampleAssessmentProjectDO>()
|
||||
.eq(BusinessSubParentSampleAssessmentProjectDO::getBusinessSubParentSampleAssessmentId, businessSubParentSampleAssessmentId));
|
||||
}
|
||||
|
||||
List<NoReportSubParentSampleAssessmentRespVO> selectNoReportSubParentSampleAssessment(@Param("reqVO") BusinessSubParentSampleAssessmentGroupReqVO reqVO);
|
||||
|
||||
|
||||
@@ -759,8 +759,8 @@ public class SampleAnalysisAuditServiceImpl implements SampleAnalysisAuditServic
|
||||
|
||||
}
|
||||
|
||||
//如果为自动上报
|
||||
if (QmsCommonConstant.AUTOMATIC.equals(configSubSampleMethodDO.getResultTreatmentWay())) {
|
||||
//如果为自动上报, 并且上报状态为待上报的
|
||||
if (QmsCommonConstant.AUTOMATIC.equals(configSubSampleMethodDO.getResultTreatmentWay()) && QmsCommonConstant.ASMT_PENDING_REPORT.equals(businessSubSampleAssessmentDO.getReportedStatus())) {
|
||||
automaticBusinessSubSampleIdList.add(businessSubSampleId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1366,10 +1366,22 @@ public class SampleAnalysisServiceImpl implements SampleAnalysisService {
|
||||
businessAssayTaskDataDO.setExternalInfomation(JSON.toJSONString(businessAssayTaskDataExternalInfomation));
|
||||
|
||||
}
|
||||
//任务id
|
||||
Long businessAssayTaskId = businessAssayTaskDetailList.stream().map(m -> m.getBusinessAssayTaskId()).distinct().findFirst().orElse(null);
|
||||
//查询任务下的明细
|
||||
Long taskCount = businessAssayTaskDetailMapper.selectCountByBusinessAssayTaskId(businessAssayTaskId);
|
||||
if (businessAssayTaskDetailList.size() == taskCount.intValue()) {//如果回退所有样品,则作废任务
|
||||
BusinessAssayTaskDO businessAssayTaskDO = businessAssayTaskMapper.selectById(businessAssayTaskId);
|
||||
businessAssayTaskDO.setTaskAssignStatus(QmsCommonConstant.VOID);
|
||||
|
||||
businessAssayTaskMapper.updateById(businessAssayTaskDO);
|
||||
}
|
||||
|
||||
//明细处理
|
||||
if (CollUtil.isNotEmpty(businessAssayTaskDetailList)) {
|
||||
businessAssayTaskDetailMapper.updateBatch(businessAssayTaskDetailList);
|
||||
}
|
||||
//任务明细处理
|
||||
if (CollUtil.isNotEmpty(businessAssayTaskDataDOList)) {
|
||||
businessAssayTaskDataMapper.updateBatch(businessAssayTaskDataDOList);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,9 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
||||
noReportSubParentSampleAssessmentMap.put(businessSubParentSampleAssessmentProjectDO.getSimpleName(), assessmentValue);
|
||||
businessSubParentSampleAssessmentProjectIds.append(businessSubParentSampleAssessmentProjectDO.getId()).append(",");
|
||||
}
|
||||
businessSubParentSampleAssessmentProjectIds.delete(businessSubParentSampleAssessmentProjectIds.length() -1, businessSubParentSampleAssessmentProjectIds.length());
|
||||
if (businessSubParentSampleAssessmentProjectIds.length() > 0) {
|
||||
businessSubParentSampleAssessmentProjectIds.delete(businessSubParentSampleAssessmentProjectIds.length() -1, businessSubParentSampleAssessmentProjectIds.length());
|
||||
}
|
||||
noReportSubParentSampleAssessmentMap.put("businessSubParentSampleAssessmentProjectIds", businessSubParentSampleAssessmentProjectIds.toString());
|
||||
noReportSubParentSampleAssessmentMap.put("businessSubParentSampleAssessmentId", noReportSubParentSampleAssessmentRespVO.getBusinessSubParentSampleAssessmentId());
|
||||
dataList.add(noReportSubParentSampleAssessmentMap);
|
||||
@@ -341,15 +343,15 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
||||
BusinessSubParentSampleAssessmentDO olBusinessSubParentSampleAssessmentDO = businessSubParentSampleAssessmentMapper.selectById(reqVO.getBusinessSubParentSampleAssessmentId());
|
||||
|
||||
//查询分样主样判定
|
||||
BusinessSubParentSampleAssessmentDO businessSubParentSampleAssessmentDO = businessSubParentSampleAssessmentMapper.selectByBusinessSubParentSampleIdAndConfigAssayMethodId(reqVO.getBusinessSubParentSampleId(), reqVO.getConfigAssayMethodId());
|
||||
if (businessSubParentSampleAssessmentDO == null) {
|
||||
//BusinessSubParentSampleAssessmentDO businessSubParentSampleAssessmentDO = businessSubParentSampleAssessmentMapper.selectByBusinessSubParentSampleIdAndConfigAssayMethodId(reqVO.getBusinessSubParentSampleId(), reqVO.getConfigAssayMethodId());
|
||||
if (olBusinessSubParentSampleAssessmentDO == null) {
|
||||
throw new ServiceException(1_032_050_000, "结果报送数据未找到");
|
||||
}
|
||||
|
||||
//复检的检测项目
|
||||
List<RecheckSubSampleParentMethodRespVO> recheckProjectList = reqVO.getRecheckProjectList();
|
||||
List<Long> recheckDictionaryProjectIdList = recheckProjectList.stream().map(m -> m.getDictionaryProjectId()).collect(Collectors.toList());
|
||||
List<BusinessSubParentSampleAssessmentProjectDO> businessSubParentSampleAssessmentProjectDOList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleAssessmentIdAndDictionaryProjectIds(businessSubParentSampleAssessmentDO.getId(), recheckDictionaryProjectIdList);
|
||||
List<BusinessSubParentSampleAssessmentProjectDO> businessSubParentSampleAssessmentProjectDOList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleAssessmentIdAndDictionaryProjectIds(olBusinessSubParentSampleAssessmentDO.getId(), recheckDictionaryProjectIdList);
|
||||
for (BusinessSubParentSampleAssessmentProjectDO businessSubParentSampleAssessmentProjectDO : businessSubParentSampleAssessmentProjectDOList) {
|
||||
businessSubParentSampleAssessmentProjectDO.setIsReported(QmsCommonConstant.NO);
|
||||
businessSubParentSampleAssessmentProjectDO.setAssessmentStatus(QmsCommonConstant.VOID);
|
||||
@@ -410,7 +412,8 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
||||
newBusinessSubSampleParentRetestDOList.add(businessSubSampleParentRetestDO );
|
||||
}
|
||||
|
||||
BusinessSubSampleAssessmentDO newBusinessSubSampleAssessmentDO = newSubSampleAssessmentDOList.stream().filter(f -> f.getBusinessSubParentSampleAssessmentId().equals(businessSubParentSampleAssessmentDO.getId())).findFirst().orElse(null);
|
||||
Long newBusinessSubParentSampleAssessmentId = newBusinessSubParentSampleAssessmentDO.getId();
|
||||
BusinessSubSampleAssessmentDO newBusinessSubSampleAssessmentDO = newSubSampleAssessmentDOList.stream().filter(f -> f.getBusinessSubParentSampleAssessmentId().equals(newBusinessSubParentSampleAssessmentId)).findFirst().orElse(null);
|
||||
if (newBusinessSubSampleAssessmentDO == null) {
|
||||
newBusinessSubSampleAssessmentDO = new BusinessSubSampleAssessmentDO();
|
||||
newBusinessSubSampleAssessmentDO.setId(IdWorker.getId());
|
||||
@@ -493,6 +496,11 @@ public class SampleResultReportingServiceImpl implements SampleResultReportingSe
|
||||
}
|
||||
}
|
||||
|
||||
List<BusinessSubParentSampleAssessmentProjectDO> allBusinessSubParentSampleAssessmentProjectList = businessSubParentSampleAssessmentProjectMapper.selectByBusinessSubParentSampleAssessmentId(olBusinessSubParentSampleAssessmentDO.getId());
|
||||
if (allBusinessSubParentSampleAssessmentProjectList.size() == businessSubParentSampleAssessmentProjectDOList.size()) {//如果复测项目都全部完成,则删除旧的结果报送
|
||||
businessSubParentSampleAssessmentMapper.deleteById(olBusinessSubParentSampleAssessmentDO.getId());
|
||||
}
|
||||
|
||||
if (CollUtil.isNotEmpty(businessSubParentSampleAssessmentProjectDOList)) {
|
||||
businessSubParentSampleAssessmentProjectMapper.updateBatch(businessSubParentSampleAssessmentProjectDOList);
|
||||
}
|
||||
|
||||
@@ -1,227 +1,226 @@
|
||||
package com.zt.plat.module.qms.framework.datapermission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.MultiDataPermissionHandler;
|
||||
import com.zt.plat.framework.common.biz.system.permission.PermissionCommonApi;
|
||||
import com.zt.plat.framework.common.biz.system.permission.dto.DeptDataPermissionRespDTO;
|
||||
import com.zt.plat.framework.common.enums.UserTypeEnum;
|
||||
import com.zt.plat.framework.common.util.collection.CollectionUtils;
|
||||
import com.zt.plat.framework.common.util.json.JsonUtils;
|
||||
import com.zt.plat.framework.mybatis.core.util.MyBatisUtils;
|
||||
import com.zt.plat.framework.security.core.LoginUser;
|
||||
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
|
||||
//import com.zt.plat.module.qms.core.aspect.annotation.QmsPermission;
|
||||
import com.zt.plat.framework.tenant.core.context.DeptContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.Alias;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.LongValue;
|
||||
import net.sf.jsqlparser.expression.NullValue;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
|
||||
import net.sf.jsqlparser.expression.operators.relational.*;
|
||||
import net.sf.jsqlparser.schema.Column;
|
||||
import net.sf.jsqlparser.schema.Table;
|
||||
import net.sf.jsqlparser.statement.select.ParenthesedSelect;
|
||||
import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||
import net.sf.jsqlparser.statement.select.SelectItem;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
|
||||
/*
|
||||
* QMS权限处理
|
||||
* 1、只能查看自己创建的数据
|
||||
* 2、部门领导可查看本部门数据
|
||||
* 3、模块管理员可查看本模块数据
|
||||
*
|
||||
* */
|
||||
@Component
|
||||
@Slf4j
|
||||
public class QMSMultiDataPermissionHandler implements MultiDataPermissionHandler {
|
||||
|
||||
@Autowired private PermissionCommonApi permissionApi;
|
||||
/**
|
||||
* LoginUser 的 Context 缓存 Key
|
||||
*/
|
||||
protected static final String QMS_PERMISSION_CONTEXT_KEY = "QMS_DATA_PERMISSION";
|
||||
static final Expression EXPRESSION_NULL = new NullValue();
|
||||
public static final String SYSTEM_USERS = "system_users";
|
||||
private static final String SYSTEM_USER_DEPT = "system_user_dept";
|
||||
private static final String DEPT_COLUMN_NAME = "dept_id";
|
||||
private static final String USER_COLUMN_NAME = "user_id";
|
||||
|
||||
@Override
|
||||
public Expression getSqlSegment(Table table, Expression where, String mappedStatementId) {
|
||||
log.error("QMSMultiDataPermissionHandler: Expression={}", where);
|
||||
|
||||
//获取注解
|
||||
if(!QMSPermissionContextHolder.shouldExecute())
|
||||
return null;
|
||||
try{
|
||||
Expression expression = buildExpression(table, where);
|
||||
return expression;
|
||||
}catch (Exception e){
|
||||
log.error("QMSMultiDataPermissionHandler: Expression={}", where);
|
||||
}finally {
|
||||
QMSPermissionContextHolder.clear();
|
||||
}
|
||||
return EXPRESSION_NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* 构建权限sql*/
|
||||
private Expression buildExpression(Table table, Expression where) {
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
if (loginUser == null) {
|
||||
return EXPRESSION_NULL;
|
||||
}
|
||||
//管理员用户,不进行权限处理
|
||||
if (ObjectUtil.notEqual(loginUser.getUserType(), UserTypeEnum.ADMIN.getValue())) {
|
||||
return null;
|
||||
}
|
||||
String deptIdCol = QMSPermissionContextHolder.getDeptIdColumn(); //部门id列
|
||||
String userIdCol = QMSPermissionContextHolder.getUserIdColumn(); //人员id列
|
||||
String deptDataRoleCodes = QMSPermissionContextHolder.getDeptDataRoleCode(); //部门数据权限角色。具有该角色,然后按角色的权限属性判断。从而获得人员允许查看的部门数据
|
||||
String moduleDataRoleCodes = QMSPermissionContextHolder.getModuleDataRoleCodes(); //模块数据权限角色。
|
||||
String custom = QMSPermissionContextHolder.getCustom(); //todo 自定义权限
|
||||
|
||||
List<String> allRoleCode = new ArrayList<>();
|
||||
if(!ObjectUtil.isEmpty(deptDataRoleCodes)){
|
||||
allRoleCode.addAll(Arrays.asList(deptDataRoleCodes.split( ",")));
|
||||
}
|
||||
if(!ObjectUtil.isEmpty(moduleDataRoleCodes)){
|
||||
allRoleCode.addAll(Arrays.asList(moduleDataRoleCodes.split( ",")));
|
||||
}
|
||||
//查询角色
|
||||
|
||||
String tableName = MyBatisUtils.getTableName(table);
|
||||
Alias tableAlias = table.getAlias();
|
||||
DeptDataPermissionRespDTO qmsDataPermission = loginUser.getContext(QMS_PERMISSION_CONTEXT_KEY, DeptDataPermissionRespDTO.class);
|
||||
if(qmsDataPermission == null){
|
||||
try{
|
||||
// DeptContextHolder.setRoleCodeList(allRoleCode);
|
||||
qmsDataPermission = permissionApi.getDeptDataPermission(loginUser.getId()).getCheckedData();
|
||||
}catch (Exception e){
|
||||
log.error("[getExpression][LoginUser({}) 获取角色权限为 null]", JsonUtils.toJsonString(loginUser));
|
||||
log.error("", e);
|
||||
}finally {
|
||||
//package com.zt.plat.module.qms.framework.datapermission;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollUtil;
|
||||
//import cn.hutool.core.util.ObjectUtil;
|
||||
//import cn.hutool.core.util.StrUtil;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.handler.MultiDataPermissionHandler;
|
||||
//import com.zt.plat.framework.common.biz.system.permission.PermissionCommonApi;
|
||||
//import com.zt.plat.framework.common.biz.system.permission.dto.DeptDataPermissionRespDTO;
|
||||
//import com.zt.plat.framework.common.enums.UserTypeEnum;
|
||||
//import com.zt.plat.framework.common.util.collection.CollectionUtils;
|
||||
//import com.zt.plat.framework.common.util.json.JsonUtils;
|
||||
//import com.zt.plat.framework.mybatis.core.util.MyBatisUtils;
|
||||
//import com.zt.plat.framework.security.core.LoginUser;
|
||||
//import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
|
||||
////import com.zt.plat.module.qms.core.aspect.annotation.QmsPermission;
|
||||
//import com.zt.plat.framework.tenant.core.context.DeptContextHolder;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import net.sf.jsqlparser.expression.Alias;
|
||||
//import net.sf.jsqlparser.expression.Expression;
|
||||
//import net.sf.jsqlparser.expression.LongValue;
|
||||
//import net.sf.jsqlparser.expression.NullValue;
|
||||
//import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
|
||||
//import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
|
||||
//import net.sf.jsqlparser.expression.operators.relational.*;
|
||||
//import net.sf.jsqlparser.schema.Column;
|
||||
//import net.sf.jsqlparser.schema.Table;
|
||||
//import net.sf.jsqlparser.statement.select.ParenthesedSelect;
|
||||
//import net.sf.jsqlparser.statement.select.PlainSelect;
|
||||
//import net.sf.jsqlparser.statement.select.SelectItem;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//import java.util.Set;
|
||||
//
|
||||
//import static java.util.Collections.singletonList;
|
||||
//
|
||||
//
|
||||
///*
|
||||
//* QMS权限处理
|
||||
//* 1、只能查看自己创建的数据
|
||||
//* 2、部门领导可查看本部门数据
|
||||
//* 3、模块管理员可查看本模块数据
|
||||
//*
|
||||
//* */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class QMSMultiDataPermissionHandler implements MultiDataPermissionHandler {
|
||||
//
|
||||
// @Autowired private PermissionCommonApi permissionApi;
|
||||
// /**
|
||||
// * LoginUser 的 Context 缓存 Key
|
||||
// */
|
||||
// protected static final String QMS_PERMISSION_CONTEXT_KEY = "QMS_DATA_PERMISSION";
|
||||
// static final Expression EXPRESSION_NULL = new NullValue();
|
||||
// public static final String SYSTEM_USERS = "system_users";
|
||||
// private static final String SYSTEM_USER_DEPT = "system_user_dept";
|
||||
// private static final String DEPT_COLUMN_NAME = "dept_id";
|
||||
// private static final String USER_COLUMN_NAME = "user_id";
|
||||
//
|
||||
// @Override
|
||||
// public Expression getSqlSegment(Table table, Expression where, String mappedStatementId) {
|
||||
// log.error("QMSMultiDataPermissionHandler: Expression={}", where);
|
||||
//
|
||||
// //获取注解
|
||||
// if(!QMSPermissionContextHolder.shouldExecute())
|
||||
// return null;
|
||||
// try{
|
||||
// Expression expression = buildExpression(table, where);
|
||||
// return expression;
|
||||
// }catch (Exception e){
|
||||
// log.error("QMSMultiDataPermissionHandler: Expression={}", where);
|
||||
// }finally {
|
||||
// QMSPermissionContextHolder.clear();
|
||||
// }
|
||||
// return EXPRESSION_NULL;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * 构建权限sql*/
|
||||
// private Expression buildExpression(Table table, Expression where) {
|
||||
// LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
// if (loginUser == null) {
|
||||
// return EXPRESSION_NULL;
|
||||
// }
|
||||
// //管理员用户,不进行权限处理
|
||||
// if (ObjectUtil.notEqual(loginUser.getUserType(), UserTypeEnum.ADMIN.getValue())) {
|
||||
// return null;
|
||||
// }
|
||||
// String deptIdCol = QMSPermissionContextHolder.getDeptIdColumn(); //部门id列
|
||||
// String userIdCol = QMSPermissionContextHolder.getUserIdColumn(); //人员id列
|
||||
// String deptDataRoleCodes = QMSPermissionContextHolder.getDeptDataRoleCode(); //部门数据权限角色。具有该角色,然后按角色的权限属性判断。从而获得人员允许查看的部门数据
|
||||
// String moduleDataRoleCodes = QMSPermissionContextHolder.getModuleDataRoleCodes(); //模块数据权限角色。
|
||||
// String custom = QMSPermissionContextHolder.getCustom(); //todo 自定义权限
|
||||
//
|
||||
// List<String> allRoleCode = new ArrayList<>();
|
||||
// if(!ObjectUtil.isEmpty(deptDataRoleCodes)){
|
||||
// allRoleCode.addAll(Arrays.asList(deptDataRoleCodes.split( ",")));
|
||||
// }
|
||||
// if(!ObjectUtil.isEmpty(moduleDataRoleCodes)){
|
||||
// allRoleCode.addAll(Arrays.asList(moduleDataRoleCodes.split( ",")));
|
||||
// }
|
||||
// String roleCodes = CollUtil.join(allRoleCode, ",");
|
||||
// String tableName = MyBatisUtils.getTableName(table);
|
||||
// Alias tableAlias = table.getAlias();
|
||||
// DeptDataPermissionRespDTO qmsDataPermission = loginUser.getContext(QMS_PERMISSION_CONTEXT_KEY, DeptDataPermissionRespDTO.class);
|
||||
// if(qmsDataPermission == null){
|
||||
// try{
|
||||
// qmsDataPermission = permissionApi.getDeptDataPermissionWithRoleCodes(loginUser.getId(), roleCodes).getCheckedData();
|
||||
// }catch (Exception e){
|
||||
// log.error("[getExpression][LoginUser({}) 获取角色权限为 null]", JsonUtils.toJsonString(loginUser));
|
||||
// log.error("", e);
|
||||
// }finally {
|
||||
// DeptContextHolder.clearRoleCodeList();
|
||||
}
|
||||
|
||||
if (qmsDataPermission == null) {
|
||||
log.error("[getExpression][LoginUser({}) 获取数据权限为 null]", JsonUtils.toJsonString(loginUser));
|
||||
throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 未返回数据权限", loginUser.getId(), tableName, tableAlias.getName()));
|
||||
}
|
||||
// 添加到上下文中,避免重复计算
|
||||
loginUser.setContext(QMS_PERMISSION_CONTEXT_KEY, qmsDataPermission);
|
||||
}
|
||||
Long ctxDeptId = DeptContextHolder.getDeptId();
|
||||
// 计算有效的部门与自查标记:当存在上下文部门且未被忽略时,强制仅使用该部门,以避免默认全量或空权限分支
|
||||
Set<Long> effectiveDeptIds = qmsDataPermission.getDeptIds();
|
||||
Boolean effectiveSelf = qmsDataPermission.getSelf();
|
||||
if (!DeptContextHolder.shouldIgnore() && ctxDeptId != null && ctxDeptId > 0L) {
|
||||
effectiveDeptIds = CollUtil.newHashSet(ctxDeptId);
|
||||
}
|
||||
// 情况一:仅当不存在上下文部门时,且 ALL 可查看全部,才无需拼接条件;若存在上下文部门则仍需基于该部门过滤
|
||||
if (ctxDeptId == null && qmsDataPermission.getAll()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 情况二:仅在有效部门集合为空且不可查看自己时,才认为无权限;若上下文提供部门,则跳过该兜底
|
||||
if (CollUtil.isEmpty(effectiveDeptIds) && Boolean.FALSE.equals(effectiveSelf)) {
|
||||
return new EqualsTo(null, null); // WHERE null = null,可以保证返回的数据为空
|
||||
}
|
||||
|
||||
// 情况三,拼接 Dept 和 Company User 的条件,最后组合
|
||||
Expression deptExpression = buildDeptExpression(tableName, deptIdCol, tableAlias, effectiveDeptIds);
|
||||
Expression userExpression = buildUserExpression(tableName, userIdCol, tableAlias, effectiveSelf, loginUser.getId());
|
||||
if (deptExpression == null && userExpression == null) {
|
||||
// TODO:获得不到条件的时候,暂时不抛出异常,而是不返回数据
|
||||
log.warn("[getExpression][LoginUser({}) Table({}/{}) DeptDataPermission({}) 构建的条件为空]",
|
||||
JsonUtils.toJsonString(loginUser), tableName, tableAlias, JsonUtils.toJsonString(qmsDataPermission));
|
||||
// throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 构建的条件为空",
|
||||
// loginUser.getId(), tableName, tableAlias.getName()));
|
||||
return null;
|
||||
}
|
||||
if (deptExpression == null) {
|
||||
return userExpression;
|
||||
}
|
||||
if (userExpression == null) {
|
||||
return deptExpression;
|
||||
}
|
||||
// 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE (dept_id IN ? OR user_id = ?)
|
||||
return new ParenthesedExpressionList(new OrExpression(deptExpression, userExpression));
|
||||
}
|
||||
|
||||
private Expression buildDeptExpression(String tableName, String columnName, Alias tableAlias, Set<Long> deptIds) {
|
||||
// 特殊处理:system_users 表没有 dept_id 字段,已经迁移到了 user_dept 表
|
||||
if (SYSTEM_USERS.equals(tableName)) {
|
||||
// system_users 走 exists 子查询 user_dept
|
||||
if (CollUtil.isEmpty(deptIds)) {
|
||||
return null;
|
||||
}
|
||||
// 构造 exists (select 1 from user_dept where user_dept.user_id = system_users.id and user_dept.dept_id in (...))
|
||||
PlainSelect plainSelect = new PlainSelect();
|
||||
plainSelect.setSelectItems(singletonList(new SelectItem<>(new LongValue(1))));
|
||||
Table userDept = new Table(SYSTEM_USER_DEPT);
|
||||
// 使用 user 表别名避免语法错误
|
||||
Table user = new Table(tableAlias == null ? tableName : tableAlias.getName());
|
||||
plainSelect.setFromItem(userDept);
|
||||
// where user_dept.user_id = system_users.id and user_dept.dept_id in (...)
|
||||
Column userDeptUserIdCol = new Column(userDept, USER_COLUMN_NAME);
|
||||
Column systemUsersIdCol = new Column(user, "id");
|
||||
EqualsTo userIdEquals = new EqualsTo(userDeptUserIdCol, systemUsersIdCol);
|
||||
Column userDeptDeptIdCol = new Column(userDept, DEPT_COLUMN_NAME);
|
||||
InExpression deptIn = new InExpression(userDeptDeptIdCol, new ParenthesedExpressionList<>(new ExpressionList<>(CollectionUtils.convertList(deptIds, LongValue::new))));
|
||||
Expression whereExp = new AndExpression(userIdEquals, deptIn);
|
||||
plainSelect.setWhere(whereExp);
|
||||
//
|
||||
ParenthesedSelect parenthesedSelect = new ParenthesedSelect();
|
||||
parenthesedSelect.setSelect(plainSelect);
|
||||
// 构建 exists 表达式
|
||||
ExistsExpression existsExpr = new ExistsExpression();
|
||||
existsExpr.setRightExpression(parenthesedSelect);
|
||||
return existsExpr;
|
||||
}
|
||||
if (StrUtil.isEmpty(columnName)) {
|
||||
return null;
|
||||
}
|
||||
// 如果为空,则无条件
|
||||
if (CollUtil.isEmpty(deptIds)) {
|
||||
return null;
|
||||
}
|
||||
// 拼接条件
|
||||
return new InExpression(MyBatisUtils.buildColumn(tableName, tableAlias, columnName),
|
||||
// Parenthesis 的目的,是提供 (1,2,3) 的 () 左右括号
|
||||
new ParenthesedExpressionList(new ExpressionList<LongValue>(CollectionUtils.convertList(deptIds, LongValue::new))));
|
||||
}
|
||||
|
||||
private Expression buildUserExpression(String tableName, String columnName, Alias tableAlias, Boolean self, Long userId) {
|
||||
// 如果不查看自己,则无需作为条件
|
||||
if (Boolean.FALSE.equals(self)) {
|
||||
return null;
|
||||
}
|
||||
if (StrUtil.isEmpty(columnName)) {
|
||||
return null;
|
||||
}
|
||||
// 拼接条件
|
||||
return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), new LongValue(userId));
|
||||
}
|
||||
|
||||
/*
|
||||
* */
|
||||
private DeptDataPermissionRespDTO getQmsDataPermission(){
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
// }
|
||||
//
|
||||
// if (qmsDataPermission == null) {
|
||||
// log.error("[getExpression][LoginUser({}) 获取数据权限为 null]", JsonUtils.toJsonString(loginUser));
|
||||
// throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 未返回数据权限", loginUser.getId(), tableName, tableAlias.getName()));
|
||||
// }
|
||||
// // 添加到上下文中,避免重复计算
|
||||
// loginUser.setContext(QMS_PERMISSION_CONTEXT_KEY, qmsDataPermission);
|
||||
// }
|
||||
// Long ctxDeptId = DeptContextHolder.getDeptId();
|
||||
// // 计算有效的部门与自查标记:当存在上下文部门且未被忽略时,强制仅使用该部门,以避免默认全量或空权限分支
|
||||
// Set<Long> effectiveDeptIds = qmsDataPermission.getDeptIds();
|
||||
// Boolean effectiveSelf = qmsDataPermission.getSelf();
|
||||
// if (!DeptContextHolder.shouldIgnore() && ctxDeptId != null && ctxDeptId > 0L) {
|
||||
// effectiveDeptIds = CollUtil.newHashSet(ctxDeptId);
|
||||
// }
|
||||
// // 情况一:仅当不存在上下文部门时,且 ALL 可查看全部,才无需拼接条件;若存在上下文部门则仍需基于该部门过滤
|
||||
// if (ctxDeptId == null && qmsDataPermission.getAll()) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // 情况二:仅在有效部门集合为空且不可查看自己时,才认为无权限;若上下文提供部门,则跳过该兜底
|
||||
// if (CollUtil.isEmpty(effectiveDeptIds) && Boolean.FALSE.equals(effectiveSelf)) {
|
||||
// return new EqualsTo(null, null); // WHERE null = null,可以保证返回的数据为空
|
||||
// }
|
||||
//
|
||||
// // 情况三,拼接 Dept 和 Company User 的条件,最后组合
|
||||
// Expression deptExpression = buildDeptExpression(tableName, deptIdCol, tableAlias, effectiveDeptIds);
|
||||
// Expression userExpression = buildUserExpression(tableName, userIdCol, tableAlias, effectiveSelf, loginUser.getId());
|
||||
// if (deptExpression == null && userExpression == null) {
|
||||
// // TODO:获得不到条件的时候,暂时不抛出异常,而是不返回数据
|
||||
// log.warn("[getExpression][LoginUser({}) Table({}/{}) DeptDataPermission({}) 构建的条件为空]",
|
||||
// JsonUtils.toJsonString(loginUser), tableName, tableAlias, JsonUtils.toJsonString(qmsDataPermission));
|
||||
//// throw new NullPointerException(String.format("LoginUser(%d) Table(%s/%s) 构建的条件为空",
|
||||
//// loginUser.getId(), tableName, tableAlias.getName()));
|
||||
// return null;
|
||||
// }
|
||||
// if (deptExpression == null) {
|
||||
// return userExpression;
|
||||
// }
|
||||
// if (userExpression == null) {
|
||||
// return deptExpression;
|
||||
// }
|
||||
// // 目前,如果有指定部门 + 可查看自己,采用 OR 条件。即,WHERE (dept_id IN ? OR user_id = ?)
|
||||
// return new ParenthesedExpressionList(new OrExpression(deptExpression, userExpression));
|
||||
// }
|
||||
//
|
||||
// private Expression buildDeptExpression(String tableName, String columnName, Alias tableAlias, Set<Long> deptIds) {
|
||||
// // 特殊处理:system_users 表没有 dept_id 字段,已经迁移到了 user_dept 表
|
||||
// if (SYSTEM_USERS.equals(tableName)) {
|
||||
// // system_users 走 exists 子查询 user_dept
|
||||
// if (CollUtil.isEmpty(deptIds)) {
|
||||
// return null;
|
||||
// }
|
||||
// // 构造 exists (select 1 from user_dept where user_dept.user_id = system_users.id and user_dept.dept_id in (...))
|
||||
// PlainSelect plainSelect = new PlainSelect();
|
||||
// plainSelect.setSelectItems(singletonList(new SelectItem<>(new LongValue(1))));
|
||||
// Table userDept = new Table(SYSTEM_USER_DEPT);
|
||||
// // 使用 user 表别名避免语法错误
|
||||
// Table user = new Table(tableAlias == null ? tableName : tableAlias.getName());
|
||||
// plainSelect.setFromItem(userDept);
|
||||
// // where user_dept.user_id = system_users.id and user_dept.dept_id in (...)
|
||||
// Column userDeptUserIdCol = new Column(userDept, USER_COLUMN_NAME);
|
||||
// Column systemUsersIdCol = new Column(user, "id");
|
||||
// EqualsTo userIdEquals = new EqualsTo(userDeptUserIdCol, systemUsersIdCol);
|
||||
// Column userDeptDeptIdCol = new Column(userDept, DEPT_COLUMN_NAME);
|
||||
// InExpression deptIn = new InExpression(userDeptDeptIdCol, new ParenthesedExpressionList<>(new ExpressionList<>(CollectionUtils.convertList(deptIds, LongValue::new))));
|
||||
// Expression whereExp = new AndExpression(userIdEquals, deptIn);
|
||||
// plainSelect.setWhere(whereExp);
|
||||
// //
|
||||
// ParenthesedSelect parenthesedSelect = new ParenthesedSelect();
|
||||
// parenthesedSelect.setSelect(plainSelect);
|
||||
// // 构建 exists 表达式
|
||||
// ExistsExpression existsExpr = new ExistsExpression();
|
||||
// existsExpr.setRightExpression(parenthesedSelect);
|
||||
// return existsExpr;
|
||||
// }
|
||||
// if (StrUtil.isEmpty(columnName)) {
|
||||
// return null;
|
||||
// }
|
||||
// // 如果为空,则无条件
|
||||
// if (CollUtil.isEmpty(deptIds)) {
|
||||
// return null;
|
||||
// }
|
||||
// // 拼接条件
|
||||
// return new InExpression(MyBatisUtils.buildColumn(tableName, tableAlias, columnName),
|
||||
// // Parenthesis 的目的,是提供 (1,2,3) 的 () 左右括号
|
||||
// new ParenthesedExpressionList(new ExpressionList<LongValue>(CollectionUtils.convertList(deptIds, LongValue::new))));
|
||||
// }
|
||||
//
|
||||
// private Expression buildUserExpression(String tableName, String columnName, Alias tableAlias, Boolean self, Long userId) {
|
||||
// // 如果不查看自己,则无需作为条件
|
||||
// if (Boolean.FALSE.equals(self)) {
|
||||
// return null;
|
||||
// }
|
||||
// if (StrUtil.isEmpty(columnName)) {
|
||||
// return null;
|
||||
// }
|
||||
// // 拼接条件
|
||||
// return new EqualsTo(MyBatisUtils.buildColumn(tableName, tableAlias, columnName), new LongValue(userId));
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * */
|
||||
// private DeptDataPermissionRespDTO getQmsDataPermission(){
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,42 +1,42 @@
|
||||
package com.zt.plat.module.qms.framework.mybatis;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||
import com.zt.plat.module.qms.framework.datapermission.QMSMultiDataPermissionHandler;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@Configuration
|
||||
public class QMSDataPermissionConfig implements SmartInitializingSingleton {
|
||||
@Autowired
|
||||
private MybatisPlusInterceptor mybatisPlusInterceptor;
|
||||
|
||||
@Autowired
|
||||
private QMSMultiDataPermissionHandler qmsMultiDataPermissionHandler;
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
List<InnerInterceptor> interceptors = mybatisPlusInterceptor.getInterceptors();
|
||||
// 避免重复注册
|
||||
boolean exists = interceptors.stream()
|
||||
.filter(i -> i instanceof DataPermissionInterceptor)
|
||||
.map(i -> (DataPermissionInterceptor) i)
|
||||
.anyMatch(i -> i.getDataPermissionHandler() == qmsMultiDataPermissionHandler);
|
||||
if (!exists) {
|
||||
mybatisPlusInterceptor.addInnerInterceptor(new DataPermissionInterceptor(qmsMultiDataPermissionHandler));
|
||||
}
|
||||
}
|
||||
|
||||
// @PostConstruct
|
||||
// public void addDataPermissionInterceptor() {
|
||||
//package com.zt.plat.module.qms.framework.mybatis;
|
||||
//
|
||||
//
|
||||
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor;
|
||||
//import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
|
||||
//import com.zt.plat.module.qms.framework.datapermission.QMSMultiDataPermissionHandler;
|
||||
//import jakarta.annotation.PostConstruct;
|
||||
//import org.aspectj.lang.annotation.After;
|
||||
//import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//@Configuration
|
||||
//public class QMSDataPermissionConfig implements SmartInitializingSingleton {
|
||||
// @Autowired
|
||||
// private MybatisPlusInterceptor mybatisPlusInterceptor;
|
||||
//
|
||||
// @Autowired
|
||||
// private QMSMultiDataPermissionHandler qmsMultiDataPermissionHandler;
|
||||
//
|
||||
// @Override
|
||||
// public void afterSingletonsInstantiated() {
|
||||
// List<InnerInterceptor> interceptors = mybatisPlusInterceptor.getInterceptors();
|
||||
// // 避免重复注册
|
||||
// boolean exists = interceptors.stream()
|
||||
// .filter(i -> i instanceof DataPermissionInterceptor)
|
||||
// .map(i -> (DataPermissionInterceptor) i)
|
||||
// .anyMatch(i -> i.getDataPermissionHandler() == qmsMultiDataPermissionHandler);
|
||||
// if (!exists) {
|
||||
// mybatisPlusInterceptor.addInnerInterceptor(new DataPermissionInterceptor(qmsMultiDataPermissionHandler));
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
//
|
||||
//// @PostConstruct
|
||||
//// public void addDataPermissionInterceptor() {
|
||||
////
|
||||
//// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.zt.plat.module.qms.resource.clientManage.controller.admin;
|
||||
|
||||
import com.zt.plat.module.infra.api.file.FileApi;
|
||||
import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
|
||||
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementPageReqVO;
|
||||
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementRespVO;
|
||||
import com.zt.plat.module.qms.resource.clientManage.controller.vo.VersionManagementSaveReqVO;
|
||||
@@ -54,6 +56,9 @@ public class VersionManagementController extends AbstractFileUploadController im
|
||||
|
||||
@Resource
|
||||
private VersionManagementService systemVersionManagementService;
|
||||
|
||||
@Resource
|
||||
private FileApi fileApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建客户端版本管理")
|
||||
@@ -138,6 +143,14 @@ public class VersionManagementController extends AbstractFileUploadController im
|
||||
String log = "";
|
||||
if (pageResult.getList().size() != 0) {
|
||||
VersionManagementDO versionManagementDO = pageResult.getList().get(0);
|
||||
//处理文件下载url
|
||||
Long fileId = Long.parseLong(versionManagementDO.getDownloadId());
|
||||
CommonResult<FileRespDTO> fileRet = fileApi.getFileInfo(fileId);
|
||||
FileRespDTO file = fileRet.getData();
|
||||
if(fileRet.isSuccess() && file != null) {
|
||||
versionManagementDO.setDownloadUrl(file.getUrl());
|
||||
}
|
||||
|
||||
version = versionManagementDO.getCurrentVersion();
|
||||
minVersion = versionManagementDO.getMinimumVersion();
|
||||
url = versionManagementDO.getDownloadUrl();
|
||||
@@ -165,6 +178,13 @@ public class VersionManagementController extends AbstractFileUploadController im
|
||||
return CommonResult.error(400, "没有可更新版本");
|
||||
}
|
||||
VersionManagementDO versionManagementDO = pageResult.getList().get(0);
|
||||
//处理文件下载url
|
||||
Long fileId = Long.parseLong(versionManagementDO.getDownloadId());
|
||||
CommonResult<FileRespDTO> fileRet = fileApi.getFileInfo(fileId);
|
||||
FileRespDTO file = fileRet.getData();
|
||||
if(fileRet.isSuccess() && file != null) {
|
||||
versionManagementDO.setDownloadUrl(file.getUrl());
|
||||
}
|
||||
|
||||
return success(BeanUtils.toBean(versionManagementDO, VersionManagementRespVO.class));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
@Mapper
|
||||
public interface DeviceInfomationMapper extends BaseMapperX<DeviceInfomationDO> {
|
||||
|
||||
@QmsPermission(deptDataRoleCodes = "")
|
||||
@QmsPermission(deptDataRoleCodes = "ytjyDeptAndSub", moduleDataRoleCodes = "qms_device_manager")
|
||||
default PageResult<DeviceInfomationDO> selectPage(DeviceInfomationPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<DeviceInfomationDO>()
|
||||
.eqIfPresent(DeviceInfomationDO::getProductId, reqVO.getProductId())
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
AND tcam.ASY_DEPT_ID = tbssag.ASY_DEPT_ID
|
||||
WHERE
|
||||
tbssa.DELETED = 0
|
||||
AND tbspsa.DELETED = 0
|
||||
AND tbssa.RPOD_STS = 'reported'
|
||||
AND tbspsa.IS_RPOD = 0
|
||||
<if test="reqVO.configAssayMethodName != null and reqVO.configAssayMethodName != ''">
|
||||
|
||||
Reference in New Issue
Block a user