数据权限的修改

This commit is contained in:
1745237360-cloud
2026-01-10 16:39:33 +08:00
parent 29b24e8450
commit 4b427e1b2e
97 changed files with 3056 additions and 466 deletions
@@ -71,5 +71,5 @@ public interface MotorcadeRepositoryInterface extends IService<Motorcade>
List<MotorcadePo> getAllOtherMotorcade(Long userId);
List<MotorcadePo> queryNonePagingList(Long organizationId);
List<MotorcadePo> queryNonePagingList(Long organizationId, Long topOrganizationId);
}
@@ -26,7 +26,7 @@ public interface MotorcadeMapper extends BaseMapper<Motorcade>
*/
public List<MotorcadePo> queryList(MotorcadeDO motorcadeDo);
List<MotorcadePo> queryNonePagingList(@Param("organizationId") Long organizationId);
List<MotorcadePo> queryNonePagingList(@Param("organizationId") Long organizationId, @Param("topOrganizationId") Long topOrganizationId);
/**
* 查询我加入的所以车队id
@@ -130,7 +130,7 @@ public class MotorcadeRepositoryImpl extends ServiceImpl<MotorcadeMapper, Motorc
}
@Override
public List<MotorcadePo> queryNonePagingList(Long organizationId) {
return motorcadeMapper.queryNonePagingList(organizationId);
public List<MotorcadePo> queryNonePagingList(Long organizationId, Long topOrganizationId) {
return motorcadeMapper.queryNonePagingList(organizationId, topOrganizationId);
}
}
@@ -182,11 +182,7 @@ public class MotorcadeDomainService {
}
public List<MotorcadePo> queryNonePagingList() {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null &&loginUser.getUserPo().getTopOrganizationId()!= null){
return motorcadeInterface.queryNonePagingList(loginUser.getUserPo().getTopOrganizationId());
}
return Collections.emptyList();
public List<MotorcadePo> queryNonePagingList(Long organizationId, Long topOrganizationId) {
return motorcadeInterface.queryNonePagingList(organizationId, topOrganizationId);
}
}
@@ -25,6 +25,10 @@ public class RoleEntity extends BaseVOEntity {
private Integer roleType;
@ApiModelProperty(name = "组织表ID")
private Long organizationId;
@ApiModelProperty(name = "组织名称")
private String organizationName;
@ApiModelProperty(name = "一级组织表ID")
private Long topOrganizationId;
@ApiModelProperty(name = "职务/角色权限字符,控制器中定义的权限字符,如:@PreAuthorize(`@ss.hasRole('admin')`)")
private String roleCode;
@ApiModelProperty(name = "职务/角色名称")
@@ -17,6 +17,10 @@ public class RoleDo extends BaseVOEntity implements Serializable {
private Long parentRoleId;
@ApiModelProperty(name = "组织表ID")
private Long organizationId;
@ApiModelProperty(name = "组织名称")
private String organizationName;
@ApiModelProperty(name = "一级组织表ID")
private Long topOrganizationId;
@ApiModelProperty(name = "角色业务场景数据字典ID")
private Long roleBusinessExampleId;
@ApiModelProperty(name = "角色业务场景名称")
@@ -1,6 +1,7 @@
package com.mhd.user.domain.userAggregate.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -130,4 +131,22 @@ public class UserDriverEntity extends BaseVOEntity {
@ApiModelProperty(name = "用户身份")
private Integer userIdentity;
/**
* 一级组织表ID
*/
@ApiModelProperty(name = "一级组织表ID")
private Long topOrganizationId;
/**
* 组织表ID
*/
@ApiModelProperty(name = "组织表ID")
private Long organizationId;
/**
* 组织名称
*/
@ApiModelProperty(name = "组织名称")
private String organizationName;
}
@@ -194,4 +194,13 @@ public class UserShipperEntity extends BaseVOEntity {
@ApiModelProperty(name = "客户nc编码")
private String customerNcCode;
@ApiModelProperty(name = "一级组织表ID")
private Long topOrganizationId;
@ApiModelProperty(name = "组织表ID")
private Long organizationId;
@ApiModelProperty(name = "组织名称")
private String organizationName;
}
@@ -26,6 +26,14 @@ public class UserDriverFactory {
String userName = loginUser.getUsername();
// 获取登录人id
Long userId = loginUser.getUserid();
// 设置组织信息:如果 userDriverDO 中没有设置组织信息,则使用当前登录用户的组织信息
if (userDriverEntity.getOrganizationId() == null && loginUser.getUserPo() != null) {
userDriverEntity.setOrganizationId(loginUser.getUserPo().getOrganizationId());
userDriverEntity.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
userDriverEntity.setOrganizationName(loginUser.getUserPo().getOrganizationName());
}
if(userDriverDO.getDriverId() != null){
if(userId != null){
userDriverEntity.setUpdateBy(userId);
@@ -54,6 +62,8 @@ public class UserDriverFactory {
public UserDriverEntity getUserDriverEntityByOpen(UserDriverDO userDriverDO) {
UserDriverEntity userDriverEntity = new UserDriverEntity();
BeanUtils.copyProperties(userDriverDO,userDriverEntity, IgnoreNullUtil.getNullPropertyNames(userDriverDO));
// 设置组织信息:从 userDriverDO 中复制,如果为空则保持null(开放接口可能由外部系统设置)
if(userDriverDO.getDriverId() != null){
userDriverEntity.setUpdateBy(new Long("0"));
@@ -69,7 +69,7 @@ public interface UserRepositoryInterface extends IService<UserEntity> {
UserEntity selectByTopOrganizationId(Long organizationId);
List<QueryAllShipperInfoVo> findAllShipperInfo(Long userId, Long topOrganizationId);
List<QueryAllShipperInfoVo> findAllShipperInfo(Long userId, Long organizationId);
String finShipperEnterpriseNamedByUserId(Long userId);
@@ -68,7 +68,7 @@ public interface UserMapper extends BaseMapper<UserEntity> {
UserEntity selectByTopOrganizationId(@Param("organizationId") Long organizationId);
List<QueryAllShipperInfoVo> findAllShipperInfo(@Param("userId") Long userId, @Param("topOrganizationId") Long topOrganizationId);
List<QueryAllShipperInfoVo> findAllShipperInfo(@Param("userId") Long userId, @Param("organizationId") Long organizationId);
String finShipperEnterpriseNamedByUserId(@Param("userId") Long userId);
@@ -160,8 +160,8 @@ public class UserRepositoryImpl extends ServiceImpl<UserMapper,UserEntity> imple
}
@Override
public List<QueryAllShipperInfoVo> findAllShipperInfo(Long userId, Long topOrganizationId) {
return userMapper.findAllShipperInfo(userId,topOrganizationId);
public List<QueryAllShipperInfoVo> findAllShipperInfo(Long userId, Long organizationId) {
return userMapper.findAllShipperInfo(userId, organizationId);
}
@Override
@@ -100,8 +100,12 @@ public class UserShipperPo implements Serializable {
@ApiModelProperty(name = "营业执照照片")
private String shipperEnterpriseLicenseFrontUrl = "";
@ApiModelProperty(name = "组织表ID")
private Long organizationId;
@ApiModelProperty(name = "组织名称")
private String organizationName = "";
private String organizationName;
// @ApiModelProperty(name = '一级组织表ID')
private Long topOrganizationId;
@ApiModelProperty(name = "创建者姓名")
private String createByName = "";
@@ -246,8 +246,8 @@ public class UserDomainService {
return userRepositoryInterface.selectByTopOrganizationId(organizationId);
}
public List<QueryAllShipperInfoVo> findAllShipperInfo(Long userId, Long topOrganizationId) {
return userRepositoryInterface.findAllShipperInfo(userId,topOrganizationId);
public List<QueryAllShipperInfoVo> findAllShipperInfo(Long userId, Long organizationId) {
return userRepositoryInterface.findAllShipperInfo(userId, organizationId);
}
public String findUserNameByUserId(Long userId){
@@ -92,13 +92,71 @@ public class UserDriverDomainService {
*/
// @DataPermissions(cacheName = "master")
public List<UserDriverListPo> userDriverList(UserDriverDO userDriverDO) {
// 首先保存前端传递的 organizationId(如果存在)
Long frontendOrganizationId = userDriverDO.getOrganizationId();
//获取当前登陆人
LoginUser loginUser = SecurityUtils.getLoginUser();
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
if (loginUser.getUserPo().getBusinessType() == 2){
userDriverDO.setCreateBy(loginUser.getUserPo().getUserId());
userDriverDO.setOrganizationId(null);
// 当 businessType == 2 时,如果前端没有传递 organizationId,清空组织过滤条件
if (frontendOrganizationId == null) {
userDriverDO.setOrganizationId(null);
}
}
userDriverDO.setTopOrganizationId(loginUser.getUserPo().getOrganizationId());
// 数据权限:查询权限根据 organizationId 来设置
// 当 organizationId 是 2827 时查询全部,其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId,使用前端传递的值进行过滤(包括2827)
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,使用前端传递的值进行过滤
userDriverDO.setOrganizationId(frontendOrganizationId);
userDriverDO.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
userDriverDO.setOrganizationId(null);
userDriverDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
// 其他组织只能查询自己组织的数据,不能查询其他组织(包括南光)的数据
// 如果其他组织尝试查询南光(organizationId=2827)的数据,返回空数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (frontendOrganizationId.equals(2827L)) {
// 其他组织尝试查询南光的数据,设置一个不存在的 organizationId,返回空数据
userDriverDO.setOrganizationId(-1L);
userDriverDO.setTopOrganizationId(null);
} else if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
userDriverDO.setOrganizationId(loginUserOrganizationId);
if (topOrganizationId != null) {
userDriverDO.setTopOrganizationId(topOrganizationId);
}
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
userDriverDO.setOrganizationId(frontendOrganizationId);
if (topOrganizationId != null) {
userDriverDO.setTopOrganizationId(topOrganizationId);
}
}
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
userDriverDO.setOrganizationId(loginUserOrganizationId);
}
if (topOrganizationId != null) {
userDriverDO.setTopOrganizationId(topOrganizationId);
}
}
}
return userDriverRepositoryInterface.userDriverList(userDriverDO);
}
@@ -49,10 +49,13 @@ public class UserShipperDomainService {
// @DataPermissions(cacheName = "master")
public List<UserShipperPo> userShipperList(UserShipperDO userShipperDO) {
// 数据权限逻辑已在 UserShipperApplicationService.userShipperList 中处理
// 这里不再重复处理数据权限,直接使用传入的参数进行查询
//获取当前登陆人
LoginUser loginUser = SecurityUtils.getLoginUser();
userShipperDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
if(loginUser.getUserPo().getBusinessType()==1||loginUser.getUserPo().getBusinessType()==3||loginUser.getUserPo().getUserAccountType()==5){
if(loginUser != null && loginUser.getUserPo() != null &&
(loginUser.getUserPo().getBusinessType()==1||loginUser.getUserPo().getBusinessType()==3||loginUser.getUserPo().getUserAccountType()==5)){
userShipperDO.setUserId(loginUser.getUserid());
}
return userShipperRepositoryInterface.selectList(userShipperDO);
@@ -278,9 +278,17 @@ public class UserWlhyDomainService {
tmsShipperDTO.setIdCardEndDate(idCardEndDate);
Date idCardStartDate = DateUtil.parse(userPo.getUserIdcardDateFrom());
tmsShipperDTO.setIdCardStartDate(idCardStartDate);
tmsShipperDTO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
tmsShipperDTO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
tmsShipperDTO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
// 优先使用 userShipperEntity 对象中保存的组织信息,确保与数据库中的组织ID一致
// 如果 userShipperEntity 中没有组织信息,则使用当前登录用户的组织信息作为后备
if (userShipperEntity.getOrganizationId() != null) {
tmsShipperDTO.setOrganizationId(userShipperEntity.getOrganizationId());
tmsShipperDTO.setOrganizationName(userShipperEntity.getOrganizationName());
tmsShipperDTO.setTopOrganizationId(userShipperEntity.getTopOrganizationId());
} else if (loginUser.getUserPo() != null) {
tmsShipperDTO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
tmsShipperDTO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
tmsShipperDTO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
tmsShipperDTO.setCompanyName(userShipperEntity.getShipperEnterpriseName());
return tmsShipperDTO;
}
@@ -640,9 +648,17 @@ public class UserWlhyDomainService {
TmsDriverAddOrUpdateDTO tmsDriverAddOrUpdateDTO = new TmsDriverAddOrUpdateDTO();
tmsDriverAddOrUpdateDTO.setAddress(userPo.getUserAreaAddress());
tmsDriverAddOrUpdateDTO.setRegisteredAddress(userPo.getUserAreaAddress());
tmsDriverAddOrUpdateDTO.setTopOrganizationId(userPo.getTopOrganizationId());
tmsDriverAddOrUpdateDTO.setOrganizationId(userPo.getOrganizationId());
tmsDriverAddOrUpdateDTO.setOrganizationName(userPo.getOrganizationName());
// 优先使用 userDriverDO 对象中保存的组织信息,确保与数据库中的组织ID一致
// 如果 userDriverDO 中没有组织信息,则使用 userPo 中的组织信息作为后备
if (userDriverDO.getOrganizationId() != null) {
tmsDriverAddOrUpdateDTO.setTopOrganizationId(userDriverDO.getTopOrganizationId());
tmsDriverAddOrUpdateDTO.setOrganizationId(userDriverDO.getOrganizationId());
tmsDriverAddOrUpdateDTO.setOrganizationName(userDriverDO.getOrganizationName());
} else if (userPo != null) {
tmsDriverAddOrUpdateDTO.setTopOrganizationId(userPo.getTopOrganizationId());
tmsDriverAddOrUpdateDTO.setOrganizationId(userPo.getOrganizationId());
tmsDriverAddOrUpdateDTO.setOrganizationName(userPo.getOrganizationName());
}
tmsDriverAddOrUpdateDTO.setSzwlUserId(userDriverDO.getUserId());
Integer type = userDriverDO.getDriverType() != 1 ? 1 : 0;
tmsDriverAddOrUpdateDTO.setType(type);