BMS项目管理数据权限
This commit is contained in:
+41
-4
@@ -37,10 +37,47 @@ public class ProjectManageApplicationService {
|
|||||||
*/
|
*/
|
||||||
public List<ProjectManagePO> queryList(ProjectManageDO projectManageDO) {
|
public List<ProjectManagePO> queryList(ProjectManageDO projectManageDO) {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
if (loginUser != null){
|
if (loginUser != null && loginUser.getUserPo() != null) {
|
||||||
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
|
||||||
if (topOrganizationId != null && topOrganizationId != 1){
|
Long loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
||||||
projectManageDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
|
Long frontendOrganizationId = projectManageDO.getOrganizationId();
|
||||||
|
|
||||||
|
// 根据当前登录用户的所属组织ID进行数据权限控制:
|
||||||
|
// 当组织ID为 2827(南光)时,可查询全部组织数据;其他组织只能查询本组织数据
|
||||||
|
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
|
||||||
|
// 南光组织(organizationId=2827):可以查询所有组织的数据
|
||||||
|
if (frontendOrganizationId != null) {
|
||||||
|
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
|
||||||
|
projectManageDO.setOrganizationId(frontendOrganizationId);
|
||||||
|
projectManageDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件
|
||||||
|
} else {
|
||||||
|
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||||
|
projectManageDO.setOrganizationId(null);
|
||||||
|
projectManageDO.setTopOrganizationId(null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 其他组织:只能查询本组织数据
|
||||||
|
if (frontendOrganizationId != null) {
|
||||||
|
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||||
|
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||||
|
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||||
|
projectManageDO.setOrganizationId(loginUserOrganizationId);
|
||||||
|
} else {
|
||||||
|
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
|
||||||
|
projectManageDO.setOrganizationId(frontendOrganizationId);
|
||||||
|
}
|
||||||
|
if (loginUserTopOrganizationId != null) {
|
||||||
|
projectManageDO.setTopOrganizationId(loginUserTopOrganizationId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||||
|
if (loginUserOrganizationId != null) {
|
||||||
|
projectManageDO.setOrganizationId(loginUserOrganizationId);
|
||||||
|
}
|
||||||
|
if (loginUserTopOrganizationId != null) {
|
||||||
|
projectManageDO.setTopOrganizationId(loginUserTopOrganizationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return projectManageDomainService.queryList(projectManageDO);
|
return projectManageDomainService.queryList(projectManageDO);
|
||||||
|
|||||||
+31
-5
@@ -6,6 +6,7 @@ import com.mhd.basic.interfaces.dto.projectManage.ProjectManageDTO;
|
|||||||
import com.mhd.common.core.exception.digitalLogisticsException.DigitalLogisticsException;
|
import com.mhd.common.core.exception.digitalLogisticsException.DigitalLogisticsException;
|
||||||
import com.mhd.common.core.exception.digitalLogisticsException.UserError;
|
import com.mhd.common.core.exception.digitalLogisticsException.UserError;
|
||||||
import com.mhd.common.core.utils.bean.BeanUtils;
|
import com.mhd.common.core.utils.bean.BeanUtils;
|
||||||
|
import com.mhd.common.core.utils.StringUtils;
|
||||||
import com.mhd.common.core.utils.IgnoreNullUtil;
|
import com.mhd.common.core.utils.IgnoreNullUtil;
|
||||||
import com.mhd.common.security.utils.SecurityUtils;
|
import com.mhd.common.security.utils.SecurityUtils;
|
||||||
import com.mhd.system.api.model.LoginUser;
|
import com.mhd.system.api.model.LoginUser;
|
||||||
@@ -28,24 +29,47 @@ public class ProjectManageAssembler {
|
|||||||
public ProjectManageDO toDO(ProjectManageDTO projectManageDTO) {
|
public ProjectManageDO toDO(ProjectManageDTO projectManageDTO) {
|
||||||
ProjectManageDO projectManageDO = new ProjectManageDO();
|
ProjectManageDO projectManageDO = new ProjectManageDO();
|
||||||
// 拷贝
|
// 拷贝
|
||||||
BeanUtils.copyProperties(projectManageDTO, projectManageDO, IgnoreNullUtil.getNullPropertyNames(projectManageDTO));
|
if (projectManageDTO != null) {
|
||||||
|
BeanUtils.copyProperties(projectManageDTO, projectManageDO, IgnoreNullUtil.getNullPropertyNames(projectManageDTO));
|
||||||
|
}
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
if (ObjectUtil.isNull(loginUser)) {
|
if (ObjectUtil.isNull(loginUser)) {
|
||||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
||||||
}
|
}
|
||||||
String userName = loginUser.getUsername();
|
// 优先使用用户姓名,其次真实姓名,最后账号,保持与其他模块一致
|
||||||
|
String userName = null;
|
||||||
|
if (loginUser.getUserPo() != null && StringUtils.isNotEmpty(loginUser.getUserPo().getUserName())) {
|
||||||
|
userName = loginUser.getUserPo().getUserName();
|
||||||
|
} else if (StringUtils.isNotEmpty(loginUser.getRealname())) {
|
||||||
|
userName = loginUser.getRealname();
|
||||||
|
} else {
|
||||||
|
userName = loginUser.getUsername();
|
||||||
|
}
|
||||||
// 获取登录人id
|
// 获取登录人id
|
||||||
Long userId = loginUser.getUserid();
|
Long userId = loginUser.getUserid();
|
||||||
if(projectManageDTO.getProjectManageId() != null){
|
|
||||||
|
if (projectManageDTO != null && projectManageDTO.getProjectManageId() != null) {
|
||||||
|
// 编辑操作:只设置更新相关字段
|
||||||
if(userId != null){
|
if(userId != null){
|
||||||
projectManageDO.setUpdateBy(userId);
|
projectManageDO.setUpdateBy(userId);
|
||||||
}else {
|
}else {
|
||||||
projectManageDO.setUpdateBy(new Long("0"));
|
projectManageDO.setUpdateBy(new Long("0"));
|
||||||
}
|
}
|
||||||
projectManageDO.setUpdateByName(userName);
|
// 只有在 DO 中没有传递 updateByName 时才设置(避免覆盖前端传递的值)
|
||||||
|
if (StringUtils.isEmpty(projectManageDO.getUpdateByName())) {
|
||||||
|
projectManageDO.setUpdateByName(userName);
|
||||||
|
}
|
||||||
projectManageDO.setUpdateTime(new Date());
|
projectManageDO.setUpdateTime(new Date());
|
||||||
|
|
||||||
}else {
|
} else if (projectManageDTO != null && projectManageDTO.getProjectManageId() == null) {
|
||||||
|
// projectManageId == null,可能是查询操作或新增操作
|
||||||
|
// 如果前端传递了 createByName 或 updateByName,说明是查询条件,不应该设置(已经在 BeanUtils.copyProperties 中拷贝了)
|
||||||
|
boolean hasQueryCondition =
|
||||||
|
(StringUtils.isNotEmpty(projectManageDTO.getCreateByName()))
|
||||||
|
|| (StringUtils.isNotEmpty(projectManageDTO.getUpdateByName()));
|
||||||
|
|
||||||
|
if (!hasQueryCondition) {
|
||||||
|
// 没有查询条件,可能是新增操作,设置默认值
|
||||||
if(userId != null){
|
if(userId != null){
|
||||||
projectManageDO.setCreateBy(userId);
|
projectManageDO.setCreateBy(userId);
|
||||||
projectManageDO.setUpdateBy(userId);
|
projectManageDO.setUpdateBy(userId);
|
||||||
@@ -58,6 +82,8 @@ public class ProjectManageAssembler {
|
|||||||
projectManageDO.setCreateTime(new Date());
|
projectManageDO.setCreateTime(new Date());
|
||||||
projectManageDO.setUpdateTime(new Date());
|
projectManageDO.setUpdateTime(new Date());
|
||||||
projectManageDO.setDelFlag(1);
|
projectManageDO.setDelFlag(1);
|
||||||
|
}
|
||||||
|
// 如果有查询条件(createByName 或 updateByName),说明是查询操作,不应该强制覆盖这些字段
|
||||||
}
|
}
|
||||||
return projectManageDO;
|
return projectManageDO;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="projectManageDO.projectEndTimeEnd != null and projectManageDO.projectEndTimeEnd != ''">
|
<if test="projectManageDO.projectEndTimeEnd != null and projectManageDO.projectEndTimeEnd != ''">
|
||||||
AND date_format(end_date,'%Y-%m-%d') <![CDATA[<=]]> #{projectManageDO.projectEndTimeEnd}
|
AND date_format(end_date,'%Y-%m-%d') <![CDATA[<=]]> #{projectManageDO.projectEndTimeEnd}
|
||||||
</if>
|
</if>
|
||||||
<if test="projectManageDO.topOrganizationId != null ">
|
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
|
||||||
|
<!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) -->
|
||||||
|
<if test="projectManageDO.organizationId != null">
|
||||||
|
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
|
||||||
|
and organization_id = #{projectManageDO.organizationId}
|
||||||
|
</if>
|
||||||
|
<if test="projectManageDO.topOrganizationId != null and projectManageDO.organizationId == null">
|
||||||
|
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
|
||||||
and top_organization_id = #{projectManageDO.topOrganizationId}
|
and top_organization_id = #{projectManageDO.topOrganizationId}
|
||||||
</if>
|
</if>
|
||||||
</sql>
|
</sql>
|
||||||
|
|||||||
Reference in New Issue
Block a user