Merge branch 'refs/heads/dev_qinhongzhan' into dev
# Conflicts: # mhd-auth/src/main/resources/bootstrap.yml # mhd-gateway/src/main/resources/bootstrap.yml # mhd-modules/mhd-system/src/main/resources/bootstrap.yml # mhd-user-center/src/main/java/com/mhd/user/domain/userAggregate/entity/UserShipperEntity.java # mhd-user-center/src/main/resources/bootstrap.yml # mhd_finance/src/main/java/com/linke/finance/application/server/reconciliation/ReconciliationApplicationService.java # mhd_transport/src/main/java/com/linke/transport/application/service/warehouse/material/command/CreateMaterialCommand.java
This commit is contained in:
+290
-5
@@ -40,9 +40,11 @@ import com.mhd.user.domain.roleAggregate.repository.todo.RoleDo;
|
||||
import com.mhd.user.domain.roleAggregate.service.RoleDomainService;
|
||||
import com.mhd.user.domain.userAggregate.entity.DriverVehicleBind;
|
||||
import com.mhd.user.domain.userAggregate.entity.UserRoleEntity;
|
||||
import com.mhd.common.core.domain.po.UserRoleMenuPO;
|
||||
import com.mhd.user.domain.userAggregate.repository.po.UserDriverEnterprisePo;
|
||||
import com.mhd.user.domain.userAggregate.repository.po.UserDriverPo;
|
||||
import com.mhd.user.domain.userAggregate.repository.todo.*;
|
||||
import com.mhd.user.domain.userAggregate.repository.todo.UserDO;
|
||||
import com.mhd.user.domain.motorcade.service.MotorcadeRecordDomainService;
|
||||
import com.mhd.user.domain.userAggregate.service.*;
|
||||
import com.mhd.user.infrastructure.feign.SpecialLogisticsFeign;
|
||||
@@ -131,7 +133,55 @@ public class MotorcadeApplicationService {
|
||||
public List<MotorcadePo> queryList(MotorcadeDO motorcadeDo) {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null && loginUser.getUserPo() != null){
|
||||
motorcadeDo.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
Long organizationId = userPo.getOrganizationId();
|
||||
Long topOrganizationId = userPo.getTopOrganizationId();
|
||||
|
||||
// 数据权限:根据 organizationId 来设置查询权限
|
||||
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
|
||||
if (organizationId != null && organizationId.equals(2827L)) {
|
||||
// 南光组织(organizationId=2827):可以查询所有组织的数据
|
||||
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
Long frontendOrganizationId = motorcadeDo.getOrganizationId();
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
motorcadeDo.setOrganizationId(frontendOrganizationId);
|
||||
motorcadeDo.setTopOrganizationId(null);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
motorcadeDo.setOrganizationId(null);
|
||||
motorcadeDo.setTopOrganizationId(null);
|
||||
}
|
||||
} else {
|
||||
// 其他组织:设置 organizationId,只查询当前组织的数据
|
||||
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
|
||||
Long frontendOrganizationId = motorcadeDo.getOrganizationId();
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||
if (!frontendOrganizationId.equals(organizationId)) {
|
||||
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||
log.warn("车队列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
|
||||
frontendOrganizationId, organizationId);
|
||||
motorcadeDo.setOrganizationId(organizationId);
|
||||
} else {
|
||||
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
|
||||
motorcadeDo.setOrganizationId(frontendOrganizationId);
|
||||
}
|
||||
if (topOrganizationId != null) {
|
||||
motorcadeDo.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
} else {
|
||||
// 前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||
motorcadeDo.setOrganizationId(organizationId);
|
||||
if (topOrganizationId != null) {
|
||||
motorcadeDo.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.info("车队列表查询 - 设置组织ID后,查询参数:organizationId={}, topOrganizationId={}",
|
||||
motorcadeDo.getOrganizationId(), motorcadeDo.getTopOrganizationId());
|
||||
}
|
||||
return motorcadeDomainService.queryList(motorcadeDo);
|
||||
}
|
||||
@@ -656,16 +706,28 @@ public class MotorcadeApplicationService {
|
||||
|
||||
motorcadeDo.setMotorcadeHeaderName(userPo.getUserName());
|
||||
motorcadeDo.setMotorcadeHeaderAccount(userPo.getUserAccount());
|
||||
motorcadeDo.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
||||
motorcadeDo.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
||||
motorcadeDo.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
|
||||
|
||||
// 设置当前登录用户的组织信息
|
||||
UserPo loginUserPo = loginUser.getUserPo();
|
||||
if (loginUserPo != null) {
|
||||
motorcadeDo.setOrganizationId(loginUserPo.getOrganizationId());
|
||||
motorcadeDo.setOrganizationName(loginUserPo.getOrganizationName());
|
||||
motorcadeDo.setTopOrganizationId(loginUserPo.getTopOrganizationId());
|
||||
log.info("新增车队 - 设置当前登录用户的组织信息,组织ID: {}, 组织名称: {}, 顶级组织ID: {}",
|
||||
loginUserPo.getOrganizationId(), loginUserPo.getOrganizationName(), loginUserPo.getTopOrganizationId());
|
||||
} else {
|
||||
log.warn("新增车队 - 当前登录用户信息为空,无法设置组织信息");
|
||||
}
|
||||
|
||||
motorcadeDo.setMotorcadeStatus(2L);
|
||||
//获取车队承运编码
|
||||
motorcadeDo.setDriverEnterpriseCode(userPo.getUserAccount());
|
||||
|
||||
// 设置当前登录用户的创建信息
|
||||
motorcadeDo.setCreateBy(loginUser.getUserid());
|
||||
motorcadeDo.setCreateByName(loginUser.getUsername());
|
||||
motorcadeDo.setCreateTime(DateUtil.date());
|
||||
log.info("新增车队 - 设置创建人信息,创建人ID: {}, 创建人姓名: {}", loginUser.getUserid(), loginUser.getUsername());
|
||||
motorcadeDomainService.insert(motorcadeDo);
|
||||
MotorcadeDriver motorcadeDriver = new MotorcadeDriverAssembler().getEntity();
|
||||
motorcadeDriver.setMotorcadeId(motorcadeDo.getMotorcadeId());
|
||||
@@ -674,9 +736,210 @@ public class MotorcadeApplicationService {
|
||||
if(!flag){
|
||||
throw new ServiceException("新增车队失败");
|
||||
}
|
||||
|
||||
// 新增车队时,更新车队长的用户信息(角色、用户类型、用户身份)
|
||||
updateCaptainUserInfo(motorcadeDo.getMotorcadeHeaderId(), loginUser);
|
||||
|
||||
// 新增车队时,给车队长分配"车队长"角色
|
||||
assignCaptainRoleToUser(motorcadeDo.getMotorcadeHeaderId(), loginUser);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新车队长的用户信息(角色代码、角色名称、业务类型等)
|
||||
* @param captainUserId 车队长用户ID
|
||||
* @param loginUser 当前登录用户
|
||||
*/
|
||||
private void updateCaptainUserInfo(Long captainUserId, LoginUser loginUser) {
|
||||
if (captainUserId == null || loginUser == null || loginUser.getUserPo() == null) {
|
||||
log.warn("更新用户信息失败 - 车队长用户ID或登录用户信息为空");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("新增车队 - 更新车队长的用户信息,车队长用户ID: {}", captainUserId);
|
||||
|
||||
try {
|
||||
// 获取当前登录用户的角色信息,用于设置车队长的角色
|
||||
Long loginUserId = loginUser.getUserPo().getUserId();
|
||||
List<UserRoleMenuPO> loginUserRoleList = userRoleDomainService.selectRolesByUserId(loginUserId);
|
||||
|
||||
String roleCode = RoleEnum.CAPTAIN.getCode();
|
||||
String roleName = RoleEnum.CAPTAIN.getName();
|
||||
|
||||
// 从当前登录用户的角色中查找"车队长"角色,获取角色名称
|
||||
if (CollUtil.isNotEmpty(loginUserRoleList)) {
|
||||
for (UserRoleMenuPO loginUserRole : loginUserRoleList) {
|
||||
if (RoleEnum.CAPTAIN.getCode().equals(loginUserRole.getRoleCode())) {
|
||||
roleCode = loginUserRole.getRoleCode();
|
||||
roleName = loginUserRole.getRoleName();
|
||||
log.info("从当前登录用户的角色中获取车队长角色信息 - 角色代码: {}, 角色名称: {}", roleCode, roleName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 更新车队长的用户信息
|
||||
UserDO userDO = new UserDO();
|
||||
userDO.setUserId(captainUserId);
|
||||
userDO.setRoleCode(roleCode);
|
||||
userDO.setRoleName(roleName);
|
||||
|
||||
// 设置业务类型:如果用户已经是司机,则设置为司机&车队长(3),否则设置为车队长(2)
|
||||
UserPo captainUserPo = userApplicationService.selectByUserId(captainUserId);
|
||||
if (captainUserPo != null) {
|
||||
Integer businessType = captainUserPo.getBusinessType();
|
||||
// 业务类型:1=客户,2=司机,3=司机&车队长,4=客户&司机
|
||||
if (businessType != null && businessType == 2) {
|
||||
// 如果用户已经是司机,设置为司机&车队长(3)
|
||||
userDO.setBusinessType(3);
|
||||
log.info("车队长用户业务类型设置为:司机&车队长(3),原业务类型:{}", businessType);
|
||||
} else if (businessType != null && businessType == 4) {
|
||||
// 如果用户是客户&司机,设置为客户&司机&车队长(保持为4,或者可以设置为5如果有的话)
|
||||
// 这里暂时保持为4,或者根据业务需求调整
|
||||
userDO.setBusinessType(4);
|
||||
log.info("车队长用户业务类型保持为:客户&司机(4),原业务类型:{}", businessType);
|
||||
} else {
|
||||
// 如果用户不是司机,设置为车队长(2)
|
||||
userDO.setBusinessType(2);
|
||||
log.info("车队长用户业务类型设置为:车队长(2),原业务类型:{}", businessType);
|
||||
}
|
||||
} else {
|
||||
// 如果查询不到用户信息,默认设置为车队长(2)
|
||||
userDO.setBusinessType(2);
|
||||
log.warn("查询不到车队长用户信息,默认设置业务类型为:车队长(2)");
|
||||
}
|
||||
|
||||
// 设置组织信息(从当前登录用户获取)
|
||||
UserPo loginUserPo = loginUser.getUserPo();
|
||||
if (loginUserPo != null) {
|
||||
userDO.setOrganizationId(loginUserPo.getOrganizationId());
|
||||
userDO.setOrganizationName(loginUserPo.getOrganizationName());
|
||||
userDO.setTopOrganizationId(loginUserPo.getTopOrganizationId());
|
||||
log.info("设置车队长的组织信息 - 组织ID: {}, 组织名称: {}, 顶级组织ID: {}",
|
||||
loginUserPo.getOrganizationId(), loginUserPo.getOrganizationName(), loginUserPo.getTopOrganizationId());
|
||||
}
|
||||
|
||||
// 更新用户信息
|
||||
UserPo updateResult = userApplicationService.updateUser(userDO);
|
||||
if (updateResult != null && updateResult.getUserId() != null) {
|
||||
log.info("成功更新车队长的用户信息 - 用户ID: {}, 角色代码: {}, 角色名称: {}, 业务类型: {}, 组织ID: {}, 组织名称: {}",
|
||||
captainUserId, roleCode, roleName, userDO.getBusinessType(),
|
||||
userDO.getOrganizationId(), userDO.getOrganizationName());
|
||||
} else {
|
||||
log.warn("更新车队长的用户信息失败 - 更新结果为null,用户ID: {}, 请检查用户是否存在", captainUserId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新车队长的用户信息失败 - 用户ID: {}, 错误信息: {}", captainUserId, e.getMessage(), e);
|
||||
// 不抛出异常,允许继续执行,但记录详细错误信息
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将"车队长"角色分配给车队创建时的车队长用户
|
||||
* 优先从当前登录用户的角色中获取"车队长"角色,如果找不到,再根据组织ID查询
|
||||
* @param captainUserId 车队长用户ID
|
||||
* @param loginUser 当前登录用户
|
||||
*/
|
||||
private void assignCaptainRoleToUser(Long captainUserId, LoginUser loginUser) {
|
||||
if (captainUserId == null || loginUser == null || loginUser.getUserPo() == null) {
|
||||
log.warn("分配角色失败 - 车队长用户ID或登录用户信息为空");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("新增车队 - 分配车队长角色,车队长用户ID: {}", captainUserId);
|
||||
|
||||
Long loginUserId = loginUser.getUserPo().getUserId();
|
||||
Long organizationId = loginUser.getUserPo().getOrganizationId();
|
||||
|
||||
// 优先从当前登录用户的角色中查找"车队长"角色
|
||||
List<UserRoleMenuPO> loginUserRoleList = userRoleDomainService.selectRolesByUserId(loginUserId);
|
||||
RoleEntity roleEntity = null;
|
||||
|
||||
if (CollUtil.isNotEmpty(loginUserRoleList)) {
|
||||
log.info("当前登录用户共有 {} 个角色,查找车队长角色", loginUserRoleList.size());
|
||||
for (UserRoleMenuPO loginUserRole : loginUserRoleList) {
|
||||
if (RoleEnum.CAPTAIN.getCode().equals(loginUserRole.getRoleCode())) {
|
||||
// 找到"车队长"角色,使用当前登录用户的角色ID
|
||||
log.info("从当前登录用户的角色中找到车队长角色 - 角色ID: {}, 角色代码: {}", loginUserRole.getRoleId(), loginUserRole.getRoleCode());
|
||||
roleEntity = new RoleEntity();
|
||||
roleEntity.setRoleId(loginUserRole.getRoleId());
|
||||
roleEntity.setRoleCode(loginUserRole.getRoleCode());
|
||||
roleEntity.setRoleName(loginUserRole.getRoleName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前登录用户没有"车队长"角色,根据组织ID查询
|
||||
if (ObjectUtil.isNull(roleEntity)) {
|
||||
if (organizationId == null) {
|
||||
log.warn("当前登录用户的组织ID为空,无法查询车队长角色");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("当前登录用户没有车队长角色,根据组织ID查询 - 组织ID: {}, 角色代码: {}", organizationId, RoleEnum.CAPTAIN.getCode());
|
||||
|
||||
// 查询"车队长"角色
|
||||
RoleDo roleDo = new RoleDo();
|
||||
roleDo.setRoleCode(RoleEnum.CAPTAIN.getCode());
|
||||
roleDo.setOrganizationId(organizationId);
|
||||
|
||||
roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
|
||||
// 如果当前组织查询不到,尝试回退查询(不检查 organization_name IS NOT NULL)
|
||||
if (ObjectUtil.isNull(roleEntity)) {
|
||||
log.warn("使用 organization_name IS NOT NULL 条件查询不到角色,尝试回退查询(不检查 organization_name)- 组织ID: {}, 角色代码: {}", organizationId, RoleEnum.CAPTAIN.getCode());
|
||||
com.mhd.common.core.domain.po.RolePO rolePO = roleDomainService.selectByRoleCodeAndOrganizationId(RoleEnum.CAPTAIN.getCode(), organizationId);
|
||||
if (ObjectUtil.isNotNull(rolePO)) {
|
||||
// 将 RolePO 转换为 RoleEntity
|
||||
roleEntity = new RoleEntity();
|
||||
roleEntity.setRoleId(rolePO.getRoleId());
|
||||
roleEntity.setRoleCode(rolePO.getRoleCode());
|
||||
roleEntity.setRoleName(rolePO.getRoleName());
|
||||
roleEntity.setRoleRemark(rolePO.getRoleRemark());
|
||||
roleEntity.setRoleDataScope(rolePO.getRoleDataScope());
|
||||
roleEntity.setRoleStatus(rolePO.getRoleStatus());
|
||||
roleEntity.setRoleType(rolePO.getRoleType());
|
||||
roleEntity.setOrganizationId(rolePO.getOrganizationId());
|
||||
roleEntity.setOrganizationName(rolePO.getOrganizationName());
|
||||
roleEntity.setTopOrganizationId(rolePO.getTopOrganizationId());
|
||||
log.info("回退查询成功找到角色 - 角色ID: {}, 角色名称: {}, 组织名称: {}", roleEntity.getRoleId(), roleEntity.getRoleName(), roleEntity.getOrganizationName());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果还是查询不到,尝试使用顶级组织ID查询
|
||||
if (ObjectUtil.isNull(roleEntity)) {
|
||||
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
||||
if (topOrganizationId != null && topOrganizationId.equals(organizationId)) {
|
||||
log.info("当前组织查询不到角色,尝试使用顶级组织ID查询 - 顶级组织ID: {}, 角色代码: {}", topOrganizationId, RoleEnum.CAPTAIN.getCode());
|
||||
roleDo.setOrganizationId(null);
|
||||
roleDo.setTopOrganizationId(topOrganizationId);
|
||||
roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(roleEntity)) {
|
||||
log.info("找到车队长角色 - 角色ID: {}, 角色名称: {}", roleEntity.getRoleId(), roleEntity.getRoleName());
|
||||
UserRoleDo userRoleDo = new UserRoleDo();
|
||||
userRoleDo.setUserId(captainUserId);
|
||||
userRoleDo.setRoleId(roleEntity.getRoleId());
|
||||
|
||||
// 判断是否已存在相应角色
|
||||
List<UserRoleEntity> userRoleEntities = userRoleDomainService.selectList(userRoleDo);
|
||||
if (CollUtil.isEmpty(userRoleEntities)) {
|
||||
userRoleDomainService.addUserRole(userRoleDo);
|
||||
log.info("成功分配车队长角色给用户 - 角色ID: {}, 角色名称: {}", roleEntity.getRoleId(), roleEntity.getRoleName());
|
||||
} else {
|
||||
log.info("用户已存在车队长角色,跳过 - 角色ID: {}", roleEntity.getRoleId());
|
||||
}
|
||||
} else {
|
||||
log.warn("未找到车队长角色 - 组织ID: {}, 角色代码: {}, 请检查该组织下是否配置了该角色", organizationId, RoleEnum.CAPTAIN.getCode());
|
||||
// 不抛出异常,允许继续执行,因为角色可能在其他地方分配
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@NeedSetValueField
|
||||
public Boolean editWeb(MotorcadeDO motorcadeDo) {
|
||||
@@ -1166,7 +1429,29 @@ public class MotorcadeApplicationService {
|
||||
return motorcadeDomainService.queryList(motorcadeDo);
|
||||
}
|
||||
public List<MotorcadePo> queryNonePagingList() {
|
||||
return motorcadeDomainService.queryNonePagingList();
|
||||
// 获取当前登录用户的组织信息,用于数据权限过滤
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser != null && loginUser.getUserPo() != null) {
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
Long organizationId = userPo.getOrganizationId();
|
||||
Long topOrganizationId = userPo.getTopOrganizationId();
|
||||
|
||||
// 数据权限:根据 organizationId 来设置查询权限
|
||||
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
|
||||
if (organizationId != null && organizationId.equals(2827L)) {
|
||||
// 南光组织(organizationId=2827):可以查询所有组织的数据,传递 null 表示不限制
|
||||
log.info("查询车队列表(不分页) - 南光组织,查询所有组织的数据");
|
||||
return motorcadeDomainService.queryNonePagingList(null, null);
|
||||
} else {
|
||||
// 其他组织:只能查询自己组织的数据
|
||||
if (organizationId != null) {
|
||||
log.info("查询车队列表(不分页) - 其他组织,查询组织ID: {}", organizationId);
|
||||
return motorcadeDomainService.queryNonePagingList(organizationId, topOrganizationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.warn("查询车队列表(不分页) - 未获取到登录用户信息或组织ID,返回空列表");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -146,6 +146,10 @@ public class OpenUserApplicationService {
|
||||
userDriverDO.setUserId(userPo.getUserId());
|
||||
userDriverDO.setDriverEnterpriseCode(openDriverDto.getDriverEnterpriseCode());
|
||||
userDriverDO.setDataSources(openDriverDto.getDataSources());
|
||||
// 设置组织信息
|
||||
userDriverDO.setOrganizationId(sysTenantsPo.getOrganizationId());
|
||||
userDriverDO.setTopOrganizationId(sysTenantsPo.getTopOrganizationId());
|
||||
userDriverDO.setOrganizationName(sysTenantsPo.getOrganizationName());
|
||||
userDriverDomainService.saveUserDriverByOpen(userDriverDO);
|
||||
|
||||
//处理车队数据
|
||||
|
||||
+185
-8
@@ -83,21 +83,77 @@ public class RoleApplicationService {
|
||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
||||
}
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
|
||||
// 先保存前端传递的 organizationId(如果存在)
|
||||
Long frontendOrganizationId = roleDo.getOrganizationId();
|
||||
|
||||
// 获取登录用户信息
|
||||
Long loginUserOrganizationId = null;
|
||||
Long topOrganizationId = null;
|
||||
if (userPo != null) {
|
||||
loginUserOrganizationId = userPo.getOrganizationId();
|
||||
topOrganizationId = userPo.getTopOrganizationId();
|
||||
}
|
||||
|
||||
if (userPo.getUserAccountType() != null && userPo.getUserAccountType() == 5){
|
||||
roleDo.setCreateBy(userPo.getCreateBy());
|
||||
}else {
|
||||
UserDataPermissionQueryDTO userDataPermissionQueryDTO = new UserDataPermissionQueryDTO();
|
||||
userDataPermissionQueryDTO.setPermissionMenuId(roleDo.getPermissionMenuId());
|
||||
userDataPermissionQueryDTO = userDataPermissionApplicationService.getUserDataPermissionQueryDTO(userDataPermissionQueryDTO);
|
||||
|
||||
// 在复制属性之前,先保存前端传递的 organizationId(如果存在)
|
||||
// 因为 BeanUtils.copyProperties 可能会覆盖掉前端传递的值
|
||||
Long savedFrontendOrganizationId = frontendOrganizationId;
|
||||
|
||||
BeanUtils.copyProperties(userDataPermissionQueryDTO, roleDo, IgnoreNullUtil.getNullPropertyNames(userDataPermissionQueryDTO));
|
||||
UserPo loginUserPo = loginUser.getUserPo();
|
||||
if (ObjectUtil.isNull(roleDo.getOrganizationId())) {
|
||||
roleDo.setOrganizationId(loginUserPo.getOrganizationId());
|
||||
|
||||
// 重新获取前端传递的 organizationId(优先使用前端传递的值)
|
||||
// 对于南光组织,如果前端传递了 organizationId,必须使用前端传递的值
|
||||
Long currentFrontendOrganizationId = savedFrontendOrganizationId != null ? savedFrontendOrganizationId : roleDo.getOrganizationId();
|
||||
|
||||
// 数据权限:查询权限根据 organizationId 来设置,与其他模块保持一致
|
||||
// organizationId等于2827时,为南光组织,查所有;其他组织查自己
|
||||
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
|
||||
// 南光组织(organizationId=2827):可以查询所有组织的数据
|
||||
// 如果前端传递了 organizationId(包括2827),使用前端传递的值进行过滤
|
||||
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
if (currentFrontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
|
||||
roleDo.setOrganizationId(currentFrontendOrganizationId);
|
||||
roleDo.setTopOrganizationId(null);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
roleDo.setOrganizationId(null);
|
||||
roleDo.setTopOrganizationId(null);
|
||||
}
|
||||
if (!Strings.isNullOrEmpty(loginUserPo.getRoleCode()) && RoleEnum.SUPER_ADMIN.getCode().equals(loginUserPo.getRoleCode())) {
|
||||
//角色等级:0-无状态,1-内置角色,2-组织角色
|
||||
roleDo.setRoleGrade(1);
|
||||
} else {
|
||||
roleDo.setRoleGrade(2);
|
||||
}
|
||||
} else {
|
||||
// 其他组织:设置organizationId,只查询当前组织的数据
|
||||
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
|
||||
if (currentFrontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||
if (!currentFrontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||
log.warn("角色查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
|
||||
currentFrontendOrganizationId, loginUserOrganizationId);
|
||||
roleDo.setOrganizationId(loginUserOrganizationId);
|
||||
} else {
|
||||
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
|
||||
roleDo.setOrganizationId(currentFrontendOrganizationId);
|
||||
}
|
||||
roleDo.setTopOrganizationId(topOrganizationId);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||
roleDo.setOrganizationId(loginUserOrganizationId);
|
||||
roleDo.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
roleDo.setRoleGrade(2);
|
||||
}
|
||||
}
|
||||
@@ -144,8 +200,39 @@ public class RoleApplicationService {
|
||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
||||
}
|
||||
UserPo loginUserPo = loginUser.getUserPo();
|
||||
if (ObjectUtil.isNull(roleDo.getOrganizationId())) {
|
||||
roleDo.setOrganizationId(loginUserPo.getOrganizationId());
|
||||
|
||||
// 保存前端传递的 organizationId
|
||||
Long frontendOrganizationId = roleDo.getOrganizationId();
|
||||
Long loginUserOrganizationId = loginUserPo.getOrganizationId();
|
||||
|
||||
// 数据权限:查询权限根据 organizationId 来设置,与其他模块保持一致
|
||||
// organizationId等于2827时,为南光组织,查所有;其他组织查自己
|
||||
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
|
||||
// 南光组织(organizationId=2827):可以查询所有组织的数据
|
||||
// 如果前端传递了 organizationId 且不等于 2827,使用前端传递的值进行过滤
|
||||
// 如果前端没有传递 organizationId 或传递的是 2827,清空组织过滤条件,查询所有组织的数据
|
||||
if (frontendOrganizationId != null && !frontendOrganizationId.equals(2827L)) {
|
||||
// 前端传递了其他组织的 organizationId,使用前端传递的值进行过滤
|
||||
roleDo.setOrganizationId(frontendOrganizationId);
|
||||
roleDo.setTopOrganizationId(null);
|
||||
} else {
|
||||
// 前端没有传递 organizationId 或传递的是 2827,清空组织过滤条件,查询所有组织的数据
|
||||
roleDo.setOrganizationId(null);
|
||||
roleDo.setTopOrganizationId(null);
|
||||
}
|
||||
} else {
|
||||
// 其他组织:设置organizationId,只查询当前组织的数据
|
||||
if (ObjectUtil.isNull(frontendOrganizationId)) {
|
||||
roleDo.setOrganizationId(loginUserOrganizationId);
|
||||
} else {
|
||||
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||
log.warn("角色查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
|
||||
frontendOrganizationId, loginUserOrganizationId);
|
||||
roleDo.setOrganizationId(loginUserOrganizationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return roleDomainService.selectList(roleDo);
|
||||
}
|
||||
@@ -226,10 +313,36 @@ public class RoleApplicationService {
|
||||
}
|
||||
UserPo loginUserPo = loginUser.getUserPo();
|
||||
|
||||
//校验组织ID是否存在
|
||||
if(ObjectUtil.isNull(roleDo.getOrganizationId())){
|
||||
roleDo.setOrganizationId(loginUserPo.getOrganizationId());
|
||||
// 数据隔离:校验组织ID和权限,与其他模块保持一致
|
||||
Long frontendOrganizationId = roleDo.getOrganizationId();
|
||||
Long loginUserOrganizationId = loginUserPo.getOrganizationId();
|
||||
Long topOrganizationId = loginUserPo.getTopOrganizationId();
|
||||
|
||||
// 判断是否为南光组织:topOrganizationId == null 时为顶级组织(南光组织)
|
||||
// 与其他模块保持一致(VerificationApplicationService、TmsReceiptApplicationService等)
|
||||
boolean isNanguangOrg = (topOrganizationId == null);
|
||||
|
||||
if (ObjectUtil.isNull(frontendOrganizationId)) {
|
||||
// 如果前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||
roleDo.setOrganizationId(loginUserOrganizationId);
|
||||
} else {
|
||||
// 如果前端传递了 organizationId,需要进行数据权限校验
|
||||
if (isNanguangOrg) {
|
||||
// 南光组织:可以为任何组织创建角色,使用前端传递的 organizationId
|
||||
roleDo.setOrganizationId(frontendOrganizationId);
|
||||
log.info("南光组织创建角色 - 目标组织ID: {}", frontendOrganizationId);
|
||||
} else {
|
||||
// 其他组织:只能为自己组织创建角色,不能为其他组织创建角色
|
||||
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||
log.warn("非南光组织尝试为其他组织创建角色 - 登录用户组织ID: {}, 尝试创建的组织ID: {}",
|
||||
loginUserOrganizationId, frontendOrganizationId);
|
||||
throw new ServiceException("无权限为其他组织创建角色,只能为本组织创建角色");
|
||||
}
|
||||
// 使用当前登录用户的组织ID
|
||||
roleDo.setOrganizationId(loginUserOrganizationId);
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(roleDo.getRoleId())) {
|
||||
RolePO rolePO = roleDomainService.selectByRoleId(roleDo.getRoleId());
|
||||
if (rolePO == null) {
|
||||
@@ -254,7 +367,58 @@ public class RoleApplicationService {
|
||||
if (roleEntity != null){
|
||||
throw new ServiceException("角色编码重复");
|
||||
}
|
||||
roleDo.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
||||
// 设置组织信息:保留传入的 organizationId,如果为 null 则使用当前登录用户的组织ID
|
||||
// 注意:不能强制覆盖传入的 organizationId,否则会导致角色保存到错误的组织下
|
||||
if (roleDo.getOrganizationId() == null) {
|
||||
roleDo.setOrganizationId(loginUserPo.getOrganizationId());
|
||||
roleDo.setOrganizationName(loginUserPo.getOrganizationName());
|
||||
roleDo.setTopOrganizationId(loginUserPo.getTopOrganizationId());
|
||||
} else {
|
||||
// 如果传入了 organizationId,需要根据该 organizationId 查询对应的 organizationName
|
||||
// 如果 organizationName 为空,尝试通过 Feign 查询组织信息
|
||||
if (roleDo.getOrganizationName() == null || roleDo.getOrganizationName().isEmpty()) {
|
||||
try {
|
||||
AjaxResult orgInfo = organizationServiceFeign.getInfo(roleDo.getOrganizationId());
|
||||
if (orgInfo != null && "200".equals(String.valueOf(orgInfo.get("code")))) {
|
||||
JSONObject data = (JSONObject) orgInfo.get("data");
|
||||
if (data != null && data.containsKey("organizationName")) {
|
||||
roleDo.setOrganizationName(data.getString("organizationName"));
|
||||
log.info("通过 ProductServiceFeign 获取到组织名称: {}", roleDo.getOrganizationName());
|
||||
}
|
||||
}
|
||||
// 如果查询失败,使用当前登录用户的组织名称作为默认值
|
||||
if (roleDo.getOrganizationName() == null || roleDo.getOrganizationName().isEmpty()) {
|
||||
roleDo.setOrganizationName(loginUserPo.getOrganizationName());
|
||||
log.warn("无法通过 organizationId {} 获取组织名称,使用当前登录用户的组织名称作为默认值", roleDo.getOrganizationId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("通过 ProductServiceFeign 获取组织名称失败: {},使用当前登录用户的组织名称作为默认值", e.getMessage());
|
||||
roleDo.setOrganizationName(loginUserPo.getOrganizationName());
|
||||
}
|
||||
}
|
||||
// 如果 topOrganizationId 为空,尝试从组织信息中获取,否则使用当前登录用户的顶级组织ID
|
||||
if (roleDo.getTopOrganizationId() == null) {
|
||||
try {
|
||||
AjaxResult orgInfo = organizationServiceFeign.getInfo(roleDo.getOrganizationId());
|
||||
if (orgInfo != null && "200".equals(String.valueOf(orgInfo.get("code")))) {
|
||||
JSONObject data = (JSONObject) orgInfo.get("data");
|
||||
if (data != null && data.containsKey("topOrganizationId")) {
|
||||
Object topOrgId = data.get("topOrganizationId");
|
||||
if (topOrgId != null) {
|
||||
roleDo.setTopOrganizationId(Long.parseLong(topOrgId.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果查询失败,使用当前登录用户的顶级组织ID作为默认值
|
||||
if (roleDo.getTopOrganizationId() == null) {
|
||||
roleDo.setTopOrganizationId(loginUserPo.getTopOrganizationId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("通过 ProductServiceFeign 获取顶级组织ID失败: {},使用当前登录用户的顶级组织ID作为默认值", e.getMessage());
|
||||
roleDo.setTopOrganizationId(loginUserPo.getTopOrganizationId());
|
||||
}
|
||||
}
|
||||
}
|
||||
roleDo.setCreateBy(loginUserPo.getUserId());
|
||||
roleDo.setCreateByName(loginUserPo.getUserName());
|
||||
roleDo.setCreateTime(new Date());
|
||||
@@ -263,6 +427,19 @@ public class RoleApplicationService {
|
||||
roleDo.setUpdateTime(new Date());
|
||||
//删除标记:0-无状态,1-正常,2-已删除
|
||||
roleDo.setDelFlag(1);
|
||||
|
||||
// 添加调试日志,确认保存的角色信息
|
||||
log.info("新增角色 - 组织ID: {}, 组织名称: {}, 角色代码: {}, 角色名称: {}, 顶级组织ID: {}",
|
||||
roleDo.getOrganizationId(), roleDo.getOrganizationName(), roleDo.getRoleCode(),
|
||||
roleDo.getRoleName(), roleDo.getTopOrganizationId());
|
||||
|
||||
// 确保 organizationName 不为空,否则查询时会查不到
|
||||
if (roleDo.getOrganizationName() == null || roleDo.getOrganizationName().isEmpty()) {
|
||||
log.error("新增角色失败 - organizationName 为空!组织ID: {}, 角色代码: {}",
|
||||
roleDo.getOrganizationId(), roleDo.getRoleCode());
|
||||
throw new ServiceException("组织名称不能为空,请检查组织信息是否正确");
|
||||
}
|
||||
|
||||
int i = roleDomainService.addRole(roleDo);
|
||||
Long roleId = roleDo.getRoleId();
|
||||
//复制之前角色的菜单
|
||||
|
||||
+120
-11
@@ -330,17 +330,82 @@ public class UserApplicationService {
|
||||
* @Date 2023/1/12 14:58
|
||||
*/
|
||||
public List<UserPo> staffList(UserDO userDo) {
|
||||
// 首先保存前端传递的 organizationId(如果存在)
|
||||
Long frontendOrganizationId = userDo.getOrganizationId();
|
||||
|
||||
//获取当前登陆人
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
throw new DigitalLogisticsException(UserError.TIMEOUT);
|
||||
}
|
||||
if (userPo.getRoleCode().contains(RoleEnum.PLAT_ADMIN.getCode()) && ObjectUtil.equal(userPo.getOrganizationId(),userPo.getTopOrganizationId())){
|
||||
userDo.setTopOrganizationId(userPo.getTopOrganizationId());
|
||||
}else {
|
||||
userDo.setOrganizationId(userPo.getOrganizationId());
|
||||
|
||||
Long loginUserOrganizationId = userPo.getOrganizationId();
|
||||
Long topOrganizationId = userPo.getTopOrganizationId();
|
||||
|
||||
// 数据权限:查询权限根据 organizationId 来设置
|
||||
// 当 organizationId 是 2827 时查询全部,其他仅查询各自组织的信息
|
||||
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
|
||||
// 南光组织(organizationId=2827):可以查询所有组织的数据
|
||||
// 如果前端传递了 organizationId,使用前端传递的值进行过滤(包括2827)
|
||||
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
userDo.setOrganizationId(frontendOrganizationId);
|
||||
userDo.setTopOrganizationId(null);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
// 但如果用户是平台管理员且 organizationId 等于 topOrganizationId,使用 topOrganizationId
|
||||
if (userPo.getRoleCode() != null && userPo.getRoleCode().contains(RoleEnum.PLAT_ADMIN.getCode())
|
||||
&& ObjectUtil.equal(loginUserOrganizationId, topOrganizationId)) {
|
||||
userDo.setTopOrganizationId(topOrganizationId);
|
||||
userDo.setOrganizationId(null);
|
||||
} else {
|
||||
userDo.setOrganizationId(null);
|
||||
userDo.setTopOrganizationId(null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 其他组织:设置organizationId,只查询当前组织的数据
|
||||
// 其他组织只能查询自己组织的数据,不能查询其他组织(包括南光)的数据
|
||||
// 如果其他组织尝试查询南光(organizationId=2827)的数据,返回空数据
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||
if (frontendOrganizationId.equals(2827L)) {
|
||||
// 其他组织尝试查询南光的数据,设置一个不存在的 organizationId,返回空数据
|
||||
userDo.setOrganizationId(-1L);
|
||||
userDo.setTopOrganizationId(null);
|
||||
} else if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||
userDo.setOrganizationId(loginUserOrganizationId);
|
||||
if (topOrganizationId != null) {
|
||||
userDo.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
} else {
|
||||
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
|
||||
userDo.setOrganizationId(frontendOrganizationId);
|
||||
if (topOrganizationId != null) {
|
||||
userDo.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||
// 如果用户是平台管理员且 organizationId 等于 topOrganizationId,使用 topOrganizationId
|
||||
if (userPo.getRoleCode() != null && userPo.getRoleCode().contains(RoleEnum.PLAT_ADMIN.getCode())
|
||||
&& ObjectUtil.equal(loginUserOrganizationId, topOrganizationId)) {
|
||||
userDo.setTopOrganizationId(topOrganizationId);
|
||||
userDo.setOrganizationId(null);
|
||||
} else {
|
||||
if (loginUserOrganizationId != null) {
|
||||
userDo.setOrganizationId(loginUserOrganizationId);
|
||||
}
|
||||
if (topOrganizationId != null) {
|
||||
userDo.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return userDomainService.selectList(userDo);
|
||||
}
|
||||
|
||||
@@ -1084,6 +1149,19 @@ public class UserApplicationService {
|
||||
if (ObjectUtil.isNull(userDO.getOrganizationId())) {
|
||||
userDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
||||
userDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
|
||||
} else {
|
||||
// 如果前端传递了 organizationId,根据 organizationId 查询组织信息,获取正确的组织名称
|
||||
AjaxResult orgInfoResult = productServiceFeign.getInfo(userDO.getOrganizationId());
|
||||
String orgInfoCode = orgInfoResult.get("code").toString();
|
||||
if ("200".equals(orgInfoCode)) {
|
||||
Object orgData = orgInfoResult.get("data");
|
||||
if (ObjectUtil.isNotNull(orgData)) {
|
||||
OrganizationPo organizationPo = BeanUtil.toBean(orgData, OrganizationPo.class);
|
||||
if (ObjectUtil.isNotNull(organizationPo)) {
|
||||
userDO.setOrganizationName(organizationPo.getOrganizationName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
UserPo userPo = new UserPo();
|
||||
//先根据组织ID获取一级组织
|
||||
@@ -1151,7 +1229,15 @@ public class UserApplicationService {
|
||||
}
|
||||
BeanUtils.copyProperties(userEntity, userPo);
|
||||
//同步网货平台员工信息
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
try {
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
} catch (Exception e) {
|
||||
// 同步网货失败时,记录日志但不影响用户保存
|
||||
// 避免同步失败导致整个事务回滚,用户数据无法保存
|
||||
log.warn("同步网货平台员工信息失败,但不影响用户保存: {}", e.getMessage());
|
||||
// 如果业务要求必须同步成功,可以取消下面的注释,让异常抛出
|
||||
// throw e;
|
||||
}
|
||||
return userPo;
|
||||
}
|
||||
}
|
||||
@@ -1249,7 +1335,12 @@ public class UserApplicationService {
|
||||
}
|
||||
BeanUtils.copyProperties(userEntity, userPo);
|
||||
//同步网货平台员工信息
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
try {
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
} catch (Exception e) {
|
||||
// 同步网货失败时,记录日志但不影响用户保存
|
||||
log.warn("同步网货平台员工信息失败,但不影响用户保存: {}", e.getMessage());
|
||||
}
|
||||
return userPo;
|
||||
}
|
||||
}
|
||||
@@ -1342,7 +1433,12 @@ public class UserApplicationService {
|
||||
}
|
||||
BeanUtils.copyProperties(userEntity, userPo);
|
||||
//同步网货平台员工信息
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
try {
|
||||
wlhyDomainService.addOrEditPlatformUser(userEntity);
|
||||
} catch (Exception e) {
|
||||
// 同步网货失败时,记录日志但不影响用户保存
|
||||
log.warn("同步网货平台员工信息失败,但不影响用户保存: {}", e.getMessage());
|
||||
}
|
||||
return userPo;
|
||||
}
|
||||
}
|
||||
@@ -4823,12 +4919,25 @@ public class UserApplicationService {
|
||||
if (Objects.isNull(loginUser)){
|
||||
throw new ServiceException("当前用户不存在!");
|
||||
}
|
||||
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
||||
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
|
||||
Long filterOrganizationId = null;
|
||||
Long userId = null;
|
||||
if(loginUser.getUserPo().getBusinessType()==1||loginUser.getUserPo().getBusinessType()==3||loginUser.getUserPo().getUserAccountType()==5){
|
||||
userId = loginUser.getUserid();
|
||||
|
||||
// 数据隔离:根据 organizationId 字段来实现
|
||||
// 如果当前登录用户的organizationId为2827,可查询全部组织数据;其他组织只能查询自己组织的数据
|
||||
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
|
||||
// 南光组织:查询所有组织的数据,不设置 organizationId 和 userId 过滤条件
|
||||
filterOrganizationId = null;
|
||||
userId = null;
|
||||
} else {
|
||||
// 其他组织:只查询自己组织的数据
|
||||
filterOrganizationId = loginUserOrganizationId;
|
||||
// 如果当前登录用户是货主或企业用户,只查询当前登录用户的信息
|
||||
if(loginUser.getUserPo().getBusinessType()==1||loginUser.getUserPo().getBusinessType()==3||loginUser.getUserPo().getUserAccountType()==5){
|
||||
userId = loginUser.getUserid();
|
||||
}
|
||||
}
|
||||
return userDomainService.findAllShipperInfo(userId,topOrganizationId);
|
||||
return userDomainService.findAllShipperInfo(userId, filterOrganizationId);
|
||||
}
|
||||
|
||||
private QueryAllShipperInfoVo convertToVo(UserEntity userEntity) {
|
||||
|
||||
+116
@@ -323,6 +323,14 @@ public class UserDriverApplicationService {
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
// 设置当前登录用户的组织信息
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
if (userPo != null) {
|
||||
userDriverDO.setOrganizationId(userPo.getOrganizationId());
|
||||
userDriverDO.setOrganizationName(userPo.getOrganizationName());
|
||||
userDriverDO.setTopOrganizationId(userPo.getTopOrganizationId());
|
||||
}
|
||||
|
||||
if(userDriverDO.getUserDriverType()==1&&StringUtils.isBlank(userDriverDO.getDepartmentId())){
|
||||
throw new ServiceException("请维护司机部门信息");
|
||||
}
|
||||
@@ -344,6 +352,9 @@ public class UserDriverApplicationService {
|
||||
if (ObjectUtil.isNull(userDriverDO.getUserId())) {
|
||||
throw new ServiceException("用户ID未设置,无法继续司机认证流程");
|
||||
}
|
||||
|
||||
// 新增承运人时,使用当前登录账号的用户角色
|
||||
assignLoginUserRolesToDriver(userDriverDO.getUserId(), loginUser);
|
||||
|
||||
// 新增的自有司机,默认审核通过
|
||||
if (userDriverDO.getUserDriverType().equals(UserDriverConstants.OWN_DIVER)){
|
||||
@@ -580,6 +591,111 @@ public class UserDriverApplicationService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将"个人司机"角色分配给新创建的承运人用户
|
||||
* 优先从当前登录用户的角色中获取"个人司机"角色,如果找不到,再根据组织ID查询
|
||||
* @param driverUserId 承运人用户ID
|
||||
* @param loginUser 当前登录用户
|
||||
*/
|
||||
private void assignLoginUserRolesToDriver(Long driverUserId, LoginUser loginUser) {
|
||||
if (driverUserId == null || loginUser == null || loginUser.getUserPo() == null) {
|
||||
log.warn("分配角色失败 - 承运人用户ID或登录用户信息为空");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("新增承运人 - 分配个人司机角色,承运人用户ID: {}", driverUserId);
|
||||
|
||||
Long loginUserId = loginUser.getUserPo().getUserId();
|
||||
Long organizationId = loginUser.getUserPo().getOrganizationId();
|
||||
|
||||
// 优先从当前登录用户的角色中查找"个人司机"角色
|
||||
List<UserRoleMenuPO> loginUserRoleList = userRoleDomainService.selectRolesByUserId(loginUserId);
|
||||
RoleEntity roleEntity = null;
|
||||
|
||||
if (CollUtil.isNotEmpty(loginUserRoleList)) {
|
||||
log.info("当前登录用户共有 {} 个角色,查找个人司机角色", loginUserRoleList.size());
|
||||
for (UserRoleMenuPO loginUserRole : loginUserRoleList) {
|
||||
if (RoleEnum.DRIVER.getCode().equals(loginUserRole.getRoleCode())) {
|
||||
// 找到"个人司机"角色,使用当前登录用户的角色ID
|
||||
log.info("从当前登录用户的角色中找到个人司机角色 - 角色ID: {}, 角色代码: {}", loginUserRole.getRoleId(), loginUserRole.getRoleCode());
|
||||
roleEntity = new RoleEntity();
|
||||
roleEntity.setRoleId(loginUserRole.getRoleId());
|
||||
roleEntity.setRoleCode(loginUserRole.getRoleCode());
|
||||
roleEntity.setRoleName(loginUserRole.getRoleName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前登录用户没有"个人司机"角色,根据组织ID查询
|
||||
if (ObjectUtil.isNull(roleEntity)) {
|
||||
if (organizationId == null) {
|
||||
log.warn("当前登录用户的组织ID为空,无法查询个人司机角色");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("当前登录用户没有个人司机角色,根据组织ID查询 - 组织ID: {}, 角色代码: {}", organizationId, RoleEnum.DRIVER.getCode());
|
||||
|
||||
// 查询"个人司机"角色
|
||||
RoleDo roleDo = new RoleDo();
|
||||
roleDo.setRoleCode(RoleEnum.DRIVER.getCode());
|
||||
roleDo.setOrganizationId(organizationId);
|
||||
|
||||
roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
|
||||
// 如果当前组织查询不到,尝试回退查询(不检查 organization_name IS NOT NULL)
|
||||
if (ObjectUtil.isNull(roleEntity)) {
|
||||
log.warn("使用 organization_name IS NOT NULL 条件查询不到角色,尝试回退查询(不检查 organization_name)- 组织ID: {}, 角色代码: {}", organizationId, RoleEnum.DRIVER.getCode());
|
||||
com.mhd.common.core.domain.po.RolePO rolePO = roleDomainService.selectByRoleCodeAndOrganizationId(RoleEnum.DRIVER.getCode(), organizationId);
|
||||
if (ObjectUtil.isNotNull(rolePO)) {
|
||||
// 将 RolePO 转换为 RoleEntity
|
||||
roleEntity = new RoleEntity();
|
||||
roleEntity.setRoleId(rolePO.getRoleId());
|
||||
roleEntity.setRoleCode(rolePO.getRoleCode());
|
||||
roleEntity.setRoleName(rolePO.getRoleName());
|
||||
roleEntity.setRoleRemark(rolePO.getRoleRemark());
|
||||
roleEntity.setRoleDataScope(rolePO.getRoleDataScope());
|
||||
roleEntity.setRoleStatus(rolePO.getRoleStatus());
|
||||
roleEntity.setRoleType(rolePO.getRoleType());
|
||||
roleEntity.setOrganizationId(rolePO.getOrganizationId());
|
||||
roleEntity.setOrganizationName(rolePO.getOrganizationName());
|
||||
roleEntity.setTopOrganizationId(rolePO.getTopOrganizationId());
|
||||
log.info("回退查询成功找到角色 - 角色ID: {}, 角色名称: {}, 组织名称: {}", roleEntity.getRoleId(), roleEntity.getRoleName(), roleEntity.getOrganizationName());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果还是查询不到,尝试使用顶级组织ID查询
|
||||
if (ObjectUtil.isNull(roleEntity)) {
|
||||
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
|
||||
if (topOrganizationId != null && topOrganizationId.equals(organizationId)) {
|
||||
log.info("当前组织查询不到角色,尝试使用顶级组织ID查询 - 顶级组织ID: {}, 角色代码: {}", topOrganizationId, RoleEnum.DRIVER.getCode());
|
||||
roleDo.setOrganizationId(null);
|
||||
roleDo.setTopOrganizationId(topOrganizationId);
|
||||
roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotNull(roleEntity)) {
|
||||
log.info("找到个人司机角色 - 角色ID: {}, 角色名称: {}", roleEntity.getRoleId(), roleEntity.getRoleName());
|
||||
UserRoleDo userRoleDo = new UserRoleDo();
|
||||
userRoleDo.setUserId(driverUserId);
|
||||
userRoleDo.setRoleId(roleEntity.getRoleId());
|
||||
|
||||
// 判断是否已存在相应角色
|
||||
List<UserRoleEntity> userRoleEntities = userRoleDomainService.selectList(userRoleDo);
|
||||
if (CollUtil.isEmpty(userRoleEntities)) {
|
||||
userRoleDomainService.addUserRole(userRoleDo);
|
||||
log.info("成功分配个人司机角色给承运人用户 - 角色ID: {}, 角色名称: {}", roleEntity.getRoleId(), roleEntity.getRoleName());
|
||||
} else {
|
||||
log.info("承运人用户已存在个人司机角色,跳过 - 角色ID: {}", roleEntity.getRoleId());
|
||||
}
|
||||
} else {
|
||||
log.warn("未找到个人司机角色 - 组织ID: {}, 角色代码: {}, 请检查该组织下是否配置了该角色", organizationId, RoleEnum.DRIVER.getCode());
|
||||
// 不抛出异常,允许继续执行,因为角色可能在其他地方分配
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 托运人待审核推送
|
||||
*/
|
||||
|
||||
+149
-21
@@ -29,6 +29,7 @@ import com.mhd.system.api.service.webSocket.AsyncWebSocketApplicationService;
|
||||
import com.mhd.user.domain.roleAggregate.entity.RoleEntity;
|
||||
import com.mhd.user.domain.roleAggregate.repository.todo.RoleDo;
|
||||
import com.mhd.user.domain.roleAggregate.service.RoleDomainService;
|
||||
import com.mhd.common.core.domain.po.RolePO;
|
||||
import com.mhd.user.domain.userAggregate.entity.UserRoleEntity;
|
||||
import com.mhd.user.domain.userAggregate.entity.UserShipperEntity;
|
||||
import com.mhd.user.domain.userAggregate.event.ShipperEventPublisher;
|
||||
@@ -118,17 +119,80 @@ public class UserShipperApplicationService {
|
||||
*/
|
||||
@NeedSetValueMethod
|
||||
public List<UserShipperPo> userShipperList(UserShipperDO userShipperDO) {
|
||||
// userShipperDO.setTopOrganizationId(SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId());
|
||||
List<UserShipperPo> userShipperList=userShipperDomainService.userShipperList(userShipperDO);
|
||||
for(UserShipperPo userShipperPo:userShipperList){
|
||||
R<TmsShipper> tmsShipper=wlhyServiceFeign.queryBySzwlUserId(userShipperPo.getUserId());
|
||||
// 获取登录人信息
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser == null || loginUser.getUserPo() == null) {
|
||||
log.warn("托运人列表查询 - 未获取到登录用户信息,跳过数据权限过滤");
|
||||
List<UserShipperPo> userShipperList = userShipperDomainService.userShipperList(userShipperDO);
|
||||
return processShipperList(userShipperList);
|
||||
}
|
||||
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
|
||||
// 先保存前端传递的 organizationId(如果存在)
|
||||
Long frontendOrganizationId = userShipperDO.getOrganizationId();
|
||||
|
||||
// 获取当前登录用户的组织信息
|
||||
Long loginUserOrganizationId = userPo.getOrganizationId();
|
||||
Long topOrganizationId = userPo.getTopOrganizationId();
|
||||
|
||||
// 数据权限:根据 organizationId 来设置查询权限
|
||||
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
|
||||
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
|
||||
// 南光组织(organizationId=2827):可以查询所有组织的数据
|
||||
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
userShipperDO.setOrganizationId(frontendOrganizationId);
|
||||
userShipperDO.setTopOrganizationId(null);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
userShipperDO.setOrganizationId(null);
|
||||
userShipperDO.setTopOrganizationId(null);
|
||||
}
|
||||
} else {
|
||||
// 其他组织:设置 organizationId,只查询当前组织的数据
|
||||
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||
log.warn("托运人列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
|
||||
frontendOrganizationId, loginUserOrganizationId);
|
||||
userShipperDO.setOrganizationId(loginUserOrganizationId);
|
||||
} else {
|
||||
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
|
||||
userShipperDO.setOrganizationId(frontendOrganizationId);
|
||||
}
|
||||
if (topOrganizationId != null) {
|
||||
userShipperDO.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
} else {
|
||||
// 前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||
userShipperDO.setOrganizationId(loginUserOrganizationId);
|
||||
if (topOrganizationId != null) {
|
||||
userShipperDO.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<UserShipperPo> userShipperList = userShipperDomainService.userShipperList(userShipperDO);
|
||||
return processShipperList(userShipperList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理托运人列表,填充网货平台数据
|
||||
*/
|
||||
private List<UserShipperPo> processShipperList(List<UserShipperPo> userShipperList) {
|
||||
for(UserShipperPo userShipperPo : userShipperList){
|
||||
R<TmsShipper> tmsShipper = wlhyServiceFeign.queryBySzwlUserId(userShipperPo.getUserId());
|
||||
if (tmsShipper.getCode() == R.SUCCESS) {
|
||||
if(ObjectUtil.isNotNull(tmsShipper.getData())){
|
||||
userShipperPo.setAuthorizedQuota(tmsShipper.getData().getCreditLine());
|
||||
userShipperPo.setSettlementDay(tmsShipper.getData().getSettlementInterval());
|
||||
userShipperPo.setAuthorizedUsedAmount(tmsShipper.getData().getUsedQuota());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return userShipperList;
|
||||
@@ -154,6 +218,13 @@ public class UserShipperApplicationService {
|
||||
if (ObjectUtil.isNull(loginUser)) {
|
||||
throw new DigitalLogisticsException(UserError.USER_NULL);
|
||||
}
|
||||
// 设置当前登录用户的组织信息
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
if (userPo != null) {
|
||||
userShipperDO.setOrganizationId(userPo.getOrganizationId());
|
||||
userShipperDO.setOrganizationName(userPo.getOrganizationName());
|
||||
userShipperDO.setTopOrganizationId(userPo.getTopOrganizationId());
|
||||
}
|
||||
// 2023年5月22日,改动为个人认证和企业认证分开认证,所以此处需要根据前端认证的角色,给不同的字段赋值
|
||||
if (userShipperDO.getShipperType() == null) {
|
||||
throw new ServiceException("角色类型不能为空");
|
||||
@@ -652,28 +723,33 @@ public class UserShipperApplicationService {
|
||||
String roleCodes = null;
|
||||
//实名认证通过此时赋值企业、个人货主角色
|
||||
if (userShipperDO.getShipperAuthStatus() == 3) {
|
||||
RoleDo roleDo = new RoleDo();
|
||||
if (userShipperDO.getAuthType() == 1) {
|
||||
roleDo.setRoleCode(RoleEnum.SHIPPER.getCode());
|
||||
} else if (userShipperDO.getAuthType() == 2) {
|
||||
roleDo.setRoleCode(RoleEnum.COMPANY.getCode());
|
||||
} else {
|
||||
throw new ServiceException("角色未找到");
|
||||
// 新增委托方时,使用当前登录账号的用户角色
|
||||
Long loginUserId = loginUser.getUserPo().getUserId();
|
||||
log.info("新增委托方 - 使用当前登录用户的角色,登录用户ID: {}", loginUserId);
|
||||
|
||||
// 获取当前登录用户的所有角色
|
||||
List<UserRoleMenuPO> loginUserRoleList = userRoleDomainService.selectRolesByUserId(loginUserId);
|
||||
if (CollUtil.isEmpty(loginUserRoleList)) {
|
||||
log.warn("当前登录用户没有角色,登录用户ID: {}", loginUserId);
|
||||
throw new ServiceException("当前登录用户没有角色,无法分配给委托方");
|
||||
}
|
||||
roleDo.setOrganizationId(loginUser.getUserPo().getOrganizationId());
|
||||
RoleEntity roleEntity = roleDomainService.selectByOrganizationIdAndRoleCode(roleDo);
|
||||
if (ObjectUtil.isNotNull(roleEntity)) {
|
||||
|
||||
log.info("当前登录用户共有 {} 个角色", loginUserRoleList.size());
|
||||
|
||||
// 将当前登录用户的所有角色分配给新创建的委托方用户
|
||||
for (UserRoleMenuPO loginUserRole : loginUserRoleList) {
|
||||
UserRoleDo userRoleDo = new UserRoleDo();
|
||||
userRoleDo.setUserId(userShipperDO.getUserId());
|
||||
userRoleDo.setRoleId(roleEntity.getRoleId());
|
||||
// userApplicationService.assignUserRoles(userRoleDo);
|
||||
//判断是否已存在相应角色
|
||||
userRoleDo.setRoleId(loginUserRole.getRoleId());
|
||||
|
||||
// 判断是否已存在相应角色
|
||||
List<UserRoleEntity> userRoleEntities = userRoleDomainService.selectList(userRoleDo);
|
||||
if (CollUtil.isEmpty(userRoleEntities)) {
|
||||
userRoleDomainService.addUserRole(userRoleDo);
|
||||
log.info("成功分配角色给委托方用户 - 角色ID: {}, 角色代码: {}", loginUserRole.getRoleId(), loginUserRole.getRoleCode());
|
||||
} else {
|
||||
log.info("委托方用户已存在该角色,跳过 - 角色ID: {}, 角色代码: {}", loginUserRole.getRoleId(), loginUserRole.getRoleCode());
|
||||
}
|
||||
} else {
|
||||
throw new ServiceException("当前组织无相应角色");
|
||||
}
|
||||
//审核通过后,调用用户开通钱包
|
||||
AccountCashWalletDto accountCashWalletDto = new AccountCashWalletDto();
|
||||
@@ -773,7 +849,59 @@ public class UserShipperApplicationService {
|
||||
*/
|
||||
public Map<String, String> userShipperCount(UserShipperDO userShipperDO) {
|
||||
Map<String, String> res = new HashMap<>();
|
||||
// userShipperDO.setTopOrganizationId(SecurityUtils.getLoginUser().getUserPo().getTopOrganizationId());
|
||||
|
||||
// 获取登录人信息
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
if (loginUser == null || loginUser.getUserPo() == null) {
|
||||
log.warn("托运人统计查询 - 未获取到登录用户信息,跳过数据权限过滤");
|
||||
} else {
|
||||
UserPo userPo = loginUser.getUserPo();
|
||||
|
||||
// 先保存前端传递的 organizationId(如果存在)
|
||||
Long frontendOrganizationId = userShipperDO.getOrganizationId();
|
||||
|
||||
// 获取当前登录用户的组织信息
|
||||
Long loginUserOrganizationId = userPo.getOrganizationId();
|
||||
Long topOrganizationId = userPo.getTopOrganizationId();
|
||||
|
||||
// 数据权限:根据 topOrganizationId 来设置查询权限,与其他模块保持一致
|
||||
// topOrganizationId 为 null 时,为顶级组织(南光组织),查所有;其他组织查自己
|
||||
if (topOrganizationId == null) {
|
||||
// 南光组织:可以查询所有组织的数据
|
||||
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,使用前端传递的值进行过滤
|
||||
userShipperDO.setOrganizationId(frontendOrganizationId);
|
||||
userShipperDO.setTopOrganizationId(null);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
|
||||
userShipperDO.setOrganizationId(null);
|
||||
userShipperDO.setTopOrganizationId(null);
|
||||
}
|
||||
} else {
|
||||
// 其他组织:设置 organizationId,只查询当前组织的数据
|
||||
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
|
||||
if (frontendOrganizationId != null) {
|
||||
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
|
||||
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
|
||||
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
|
||||
log.warn("托运人统计查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
|
||||
frontendOrganizationId, loginUserOrganizationId);
|
||||
userShipperDO.setOrganizationId(loginUserOrganizationId);
|
||||
} else {
|
||||
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
|
||||
userShipperDO.setOrganizationId(frontendOrganizationId);
|
||||
}
|
||||
userShipperDO.setTopOrganizationId(topOrganizationId);
|
||||
} else {
|
||||
// 前端没有传递 organizationId,使用当前登录用户的组织ID
|
||||
userShipperDO.setOrganizationId(loginUserOrganizationId);
|
||||
userShipperDO.setTopOrganizationId(topOrganizationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//先将所有托运人查询出来,然后再进行
|
||||
List<UserShipperPo> userShipperPoList = userShipperDomainService.userShipperAndRoleList(userShipperDO);
|
||||
//托运人总数
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-6
@@ -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 = "职务/角色名称")
|
||||
|
||||
+4
@@ -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 = "角色业务场景名称")
|
||||
|
||||
+19
@@ -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;
|
||||
}
|
||||
|
||||
+9
@@ -197,4 +197,13 @@ public class UserShipperEntity extends BaseVOEntity {
|
||||
|
||||
@ApiModelProperty("结算币种")
|
||||
private String settlementCurrency;
|
||||
|
||||
@ApiModelProperty(name = "一级组织表ID")
|
||||
private Long topOrganizationId;
|
||||
|
||||
@ApiModelProperty(name = "组织表ID")
|
||||
private Long organizationId;
|
||||
|
||||
@ApiModelProperty(name = "组织名称")
|
||||
private String organizationName;
|
||||
}
|
||||
|
||||
+10
@@ -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"));
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+5
-1
@@ -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 = "";
|
||||
|
||||
|
||||
+2
-2
@@ -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){
|
||||
|
||||
+60
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -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);
|
||||
|
||||
+22
-6
@@ -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);
|
||||
|
||||
@@ -64,4 +64,10 @@ public class QueryAllShipperInfoVo {
|
||||
|
||||
@ApiModelProperty(name = "客户nc编码")
|
||||
private String customerNcCode;
|
||||
|
||||
@ApiModelProperty(name = "组织ID")
|
||||
private Long organizationId;
|
||||
|
||||
@ApiModelProperty(name = "一级组织ID")
|
||||
private Long topOrganizationId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user