数据权限的修改

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
@@ -99,6 +99,8 @@ public class Verification extends BaseVOEntity implements Serializable,Cloneable
private Long topOrganizationId;
@ApiModelProperty("组织表ID")
private Long organizationId;
@ApiModelProperty("组织名称")
private String organizationName;
// @ApiModelProperty("是否月结:1-是,2-否")
// private Integer receivableType;
@ApiModelProperty("部门id")
@@ -56,4 +56,7 @@ public class AddressBookPo extends BaseVOEntity implements Serializable
private String synthesize;
@ApiModelProperty(name = "单位名称")
private String unitName;
@ApiModelProperty(name = "组织ID(用于数据权限过滤,内部使用)", hidden = true)
private Long organizationId;
}
@@ -24,6 +24,10 @@ public class RolePO extends BaseVOEntity implements Serializable {
private String roleTypeName = "";
@ApiModelProperty(name = "组织表ID")
private Long organizationId = 0L;
@ApiModelProperty(name = "组织名称")
private String organizationName = "";
@ApiModelProperty(name = "一级组织表ID")
private Long topOrganizationId = 0L;
@ApiModelProperty(name = "职务/角色权限字符,控制器中定义的权限字符,如:@PreAuthorize(`@ss.hasRole('admin')`)")
private String roleCode = "";
@ApiModelProperty(name = "职务/角色名称")
@@ -28,6 +28,8 @@ public class UserDriverListPo {
private String driverEnterpriseName="";
@ApiModelProperty(name = "登录账号(2-20位)")
private String userAccount = "";
@ApiModelProperty(name = "组织表ID")
private Long organizationId;
@ApiModelProperty(name = "组织名称")
private String organizationName = "";
@ApiModelProperty(name = "身份证号")
@@ -99,6 +99,8 @@ public class VerificationPo extends BaseVOEntity implements Serializable
private Long topOrganizationId;
@ApiModelProperty("组织表ID")
private Long organizationId;
@ApiModelProperty("组织名称")
private String organizationName;
// @ApiModelProperty("是否月结:1-是,2-否")
// private Integer receivableType;
@ApiModelProperty("部门id")
@@ -69,9 +69,37 @@ public class AddressBookApplicationService
// 获取登录人id
Long userId = SecurityUtils.getLoginUser().getUserid();
addressBookPo.setUserId(userId);
// 添加组织数据权限过滤
applyOrganizationDataPermissionForAddressBook(addressBookPo);
return addressBookDomainService.selectAddressBookList(addressBookPo);
}
/**
* 应用组织数据权限过滤(地址簿)
* 通过用户表关联来过滤组织数据
*/
private void applyOrganizationDataPermissionForAddressBook(AddressBookPo addressBookPo) {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827(南光组织),可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织:需要通过用户表关联来过滤,只查询同一组织下用户创建的地址簿
// 由于AddressBook表只有userId字段,需要在XML中通过用户表关联来过滤
addressBookPo.setOrganizationId(loginUserOrganizationId);
}
// 如果是2827组织,不设置organizationId,可以查询全部
}
} catch (Exception e) {
// 如果获取登录用户信息失败,不添加过滤条件,避免影响正常查询
}
}
/**
* 新增地址簿
*
@@ -156,12 +184,39 @@ public class AddressBookApplicationService
*/
public List<CommonRoutePo> selectCommonRouteList(CommonRouteDo commonRouteDo){
// 获取登录人id
// Long userId = SecurityUtils.getUserId()==0 ? 4L:SecurityUtils.getLoginUser().getUserid();
Long userId = SecurityUtils.getLoginUser().getUserid();
commonRouteDo.setCreateBy(userId);
// 添加组织数据权限过滤
applyOrganizationDataPermissionForCommonRoute(commonRouteDo);
return commonRouteDomainService.selectCommonRouteList(commonRouteDo);
}
/**
* 应用组织数据权限过滤(常用路线)
* 通过用户表关联来过滤组织数据
*/
private void applyOrganizationDataPermissionForCommonRoute(CommonRouteDo commonRouteDo) {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827(南光组织),可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织:需要通过用户表关联来过滤,只查询同一组织下用户创建的常用路线
// 由于CommonRoute表只有userId字段,需要在XML中通过用户表关联来过滤
commonRouteDo.setOrganizationId(loginUserOrganizationId);
}
// 如果是2827组织,不设置organizationId,可以查询全部
}
} catch (Exception e) {
// 如果获取登录用户信息失败,不添加过滤条件,避免影响正常查询
}
}
/**
* 新增常用路线
*
@@ -38,10 +38,30 @@ public class ContainerApplicationService {
public List<ContainerPO> queryList(ContainerDO containerDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
if (loginUser != null && loginUser.getUserPo() != null){
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
containerDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
// 数据权限:根据organizationId来设置查询权限
// organizationId等于2827时查询全部,其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (containerDO.getOrganizationId() == null) {
containerDO.setOrganizationId(null);
containerDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
if (topOrganizationId != null && topOrganizationId != 1){
containerDO.setTopOrganizationId(topOrganizationId);
}
// 如果前端传递了organizationId,验证是否与当前登录用户的组织ID一致
if (containerDO.getOrganizationId() != null && !containerDO.getOrganizationId().equals(loginUserOrganizationId)) {
// 前端传递了其他组织的organizationId,强制使用当前登录用户的组织ID,防止越权查询
containerDO.setOrganizationId(loginUserOrganizationId);
}
}
}
return containerDomainService.queryList(containerDO);
@@ -52,6 +72,13 @@ public class ContainerApplicationService {
* 新增容器管理
*/
public Boolean insert(ContainerDO containerDO) {
// 设置当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
containerDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
containerDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
containerDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
//翻译库区类型
setDataDict(containerDO);
return containerDomainService.insert(containerDO);
@@ -22,6 +22,7 @@ import com.mhd.common.core.web.domain.AjaxResult;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.SystemServiceFeign;
import com.mhd.system.api.model.LoginUser;
import com.mhd.common.core.domain.po.UserPo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -50,29 +51,117 @@ public class ExpenseAccountApplicationService {
/**
* 分页查询费用科目列表
*/
public List<ExpenseAccountPO> queryList(ExpenseAccountDO expenseAccountDO) {
setTopOrganizationIdLogin(expenseAccountDO);
return expenseAccountDomainService.queryList(expenseAccountDO);
try {
log.info("开始查询费用科目列表,参数:organizationId={}, topOrganizationId={}, expenseAccountDO={}",
expenseAccountDO.getOrganizationId(), expenseAccountDO.getTopOrganizationId(), expenseAccountDO);
setDataPermission(expenseAccountDO);
// 处理 createByName 和 updateByName 字段:
// 问题:ExpenseAccountAssembler 在查询场景下会自动设置 createByName 和 updateByName 为当前登录用户名
// 这会导致 SQL 中添加 create_by_name LIKE '%nanguang%' 和 update_by_name LIKE '%nanguang%' 条件
// 解决方案:
// 1. 如果查询所有组织(organizationId 和 topOrganizationId 都为 null),清空这些字段
// 2. 如果查询指定组织(organizationId 不为 null),且是南光组织查询,如果 createByName 或 updateByName 等于当前登录用户名,清空它们
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
String currentUserName = loginUser.getUsername();
if (expenseAccountDO.getOrganizationId() == null && expenseAccountDO.getTopOrganizationId() == null) {
// 查询所有组织的数据时,不应该通过创建者或更新者来过滤,清空这些字段
log.info("查询所有组织数据,清空 createByName 和 updateByName 过滤条件,避免限制查询结果");
expenseAccountDO.setCreateByName(null);
expenseAccountDO.setUpdateByName(null);
} else if (expenseAccountDO.getOrganizationId() != null && loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织查询指定组织时,如果 createByName 或 updateByName 等于当前登录用户名,说明可能是 Assembler 自动设置的
// 清空这些字段,避免限制查询结果(因为其他组织的数据可能不是当前登录用户创建的)
if (currentUserName != null) {
if (expenseAccountDO.getCreateByName() != null && expenseAccountDO.getCreateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 createByName 过滤条件(可能由 Assembler 自动设置)",
expenseAccountDO.getOrganizationId());
expenseAccountDO.setCreateByName(null);
}
if (expenseAccountDO.getUpdateByName() != null && expenseAccountDO.getUpdateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 updateByName 过滤条件(可能由 Assembler 自动设置)",
expenseAccountDO.getOrganizationId());
expenseAccountDO.setUpdateByName(null);
}
}
}
}
log.info("设置组织ID后,查询参数:organizationId={}, topOrganizationId={}, createByName={}, updateByName={}",
expenseAccountDO.getOrganizationId(), expenseAccountDO.getTopOrganizationId(),
expenseAccountDO.getCreateByName(), expenseAccountDO.getUpdateByName());
List<ExpenseAccountPO> result = expenseAccountDomainService.queryList(expenseAccountDO);
log.info("查询费用科目列表成功,返回数据条数:{}", result != null ? result.size() : 0);
return result;
} catch (Exception e) {
log.error("查询费用科目列表异常", e);
throw e;
}
}
public List<ExpenseAccountPO> treeCostSubject(ExpenseAccountDO expenseAccountDO){
setTopOrganizationIdLogin(expenseAccountDO);
setDataPermission(expenseAccountDO);
return expenseAccountDomainService.treeCostSubject(expenseAccountDO);
}
public List<ExpenseAccountPO> subjectTreeCost(ExpenseAccountDO expenseAccountDO){
setTopOrganizationIdLogin(expenseAccountDO);
setDataPermission(expenseAccountDO);
return expenseAccountDomainService.treeCostSubject(expenseAccountDO);
}
private void setTopOrganizationIdLogin(ExpenseAccountDO expenseAccountDO){
/**
* 根据当前登录用户的组织信息实现数据隔离
* 当前登录用户为组织ID字段organization_id为2827时可查全部组织数据,其他组织只能查自己
*/
private void setDataPermission(ExpenseAccountDO expenseAccountDO){
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
expenseAccountDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("费用科目查询 - 未获取到登录用户信息,跳过数据权限过滤");
return;
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 先保存前端传递的 organizationId(如果存在)
Long frontendOrganizationId = expenseAccountDO.getOrganizationId();
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId,使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
expenseAccountDO.setOrganizationId(frontendOrganizationId);
expenseAccountDO.setTopOrganizationId(null);
} else {
expenseAccountDO.setOrganizationId(null);
expenseAccountDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置 organizationId,只查询当前组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
log.warn("费用科目查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
expenseAccountDO.setOrganizationId(loginUserOrganizationId);
} else {
expenseAccountDO.setOrganizationId(frontendOrganizationId);
}
expenseAccountDO.setTopOrganizationId(topOrganizationId);
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
expenseAccountDO.setOrganizationId(loginUserOrganizationId);
}
expenseAccountDO.setTopOrganizationId(topOrganizationId);
}
}
}
@@ -287,12 +376,43 @@ public class ExpenseAccountApplicationService {
}
public List<QueryExpenseAccountPO> selectExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO){
setDataPermissionForSearch(searchExpenseAccountDO);
return expenseAccountDomainService.selectExpenseAccount(searchExpenseAccountDO);
}
public List<QueryExpenseAccountPO> selectOtherExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO){
setDataPermissionForSearch(searchExpenseAccountDO);
return expenseAccountDomainService.selectOtherExpenseAccount(searchExpenseAccountDO);
}
/**
* 为 SearchExpenseAccountDO 设置数据权限
*/
private void setDataPermissionForSearch(SearchExpenseAccountDO searchExpenseAccountDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("费用科目查询 - 未获取到登录用户信息,跳过数据权限过滤");
return;
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据,不设置组织过滤条件
searchExpenseAccountDO.setOrganizationId(null);
searchExpenseAccountDO.setTopOrganizationId(null);
} else {
// 其他组织:只查询当前组织的数据
if (loginUserOrganizationId != null) {
searchExpenseAccountDO.setOrganizationId(loginUserOrganizationId);
}
searchExpenseAccountDO.setTopOrganizationId(topOrganizationId);
}
}
public List<QueryExpenseAccountPO> selectSocialVehicleExpenseAccount(){
return expenseAccountDomainService.selectSocialVehicleExpenseAccount();
@@ -35,24 +35,190 @@ public class ServiceItemsManageApplicationService {
/**
* 分页查询服务项管理列表
*/
public List<ServiceItemsManagePO> queryList(ServiceItemsManageDO serviceItemsManageDO) {
setTopOrganizationIdLogin(serviceItemsManageDO);
return serviceItemsManageDomainService.queryList(serviceItemsManageDO);
try {
log.info("开始查询服务项管理列表,参数:organizationId={}, topOrganizationId={}, serviceItemsManageDO={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId(), serviceItemsManageDO);
// 先保存前端传递的 organizationId 和 topOrganizationId(如果存在)
// 注意:这里需要在设置权限逻辑之前保存,因为 Assembler 可能已经设置了这些值
Long frontendOrganizationId = serviceItemsManageDO.getOrganizationId();
Long frontendTopOrganizationId = serviceItemsManageDO.getTopOrganizationId();
// 获取登录用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
Long loginUserOrganizationId = null;
Long loginUserTopOrganizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
}
log.info("登录用户信息:loginUserOrganizationId={}, loginUserTopOrganizationId={}, 前端传递:frontendOrganizationId={}, frontendTopOrganizationId={}",
loginUserOrganizationId, loginUserTopOrganizationId, frontendOrganizationId, frontendTopOrganizationId);
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
serviceItemsManageDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件
log.info("南光组织查询指定组织:organizationId={}", frontendOrganizationId);
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
serviceItemsManageDO.setOrganizationId(null);
serviceItemsManageDO.setTopOrganizationId(null);
log.info("南光组织查询所有组织:不设置组织过滤条件");
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
log.warn("服务项管理查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
}
if (loginUserTopOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(loginUserTopOrganizationId);
}
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
}
if (loginUserTopOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(loginUserTopOrganizationId);
}
}
}
// 处理 createByName 和 updateByName 字段:
// 问题:Assembler 在查询场景下(serviceItemsManageId == null)会自动设置 createByName 和 updateByName 为当前登录用户名
// 这会导致 SQL 中添加 create_by_name LIKE '%nanguang%' 和 update_by_name LIKE '%nanguang%' 条件
// 解决方案:
// 1. 如果查询所有组织(organizationId 和 topOrganizationId 都为 null),清空这些字段
// 2. 如果查询指定组织(organizationId 不为 null),且是南光组织查询,如果 createByName 或 updateByName 等于当前登录用户名,清空它们
// 因为查询其他组织的数据时,不应该通过当前登录用户的名称来过滤
// 注意:这种方法可能会误判(如果前端确实传递了当前登录用户名作为查询条件),但这种情况很少见,且影响较小
String currentUserName = null;
if (loginUser != null && loginUser.getUserPo() != null) {
currentUserName = loginUser.getUsername();
}
if (serviceItemsManageDO.getOrganizationId() == null && serviceItemsManageDO.getTopOrganizationId() == null) {
// 查询所有组织的数据时,不应该通过创建者或更新者来过滤,清空这些字段
log.info("查询所有组织数据,清空 createByName 和 updateByName 过滤条件,避免限制查询结果");
serviceItemsManageDO.setCreateByName(null);
serviceItemsManageDO.setUpdateByName(null);
} else if (serviceItemsManageDO.getOrganizationId() != null && loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织查询指定组织时,如果 createByName 或 updateByName 等于当前登录用户名,说明可能是 Assembler 自动设置的
// 清空这些字段,避免限制查询结果(因为其他组织的数据可能不是当前登录用户创建的)
if (currentUserName != null) {
if (serviceItemsManageDO.getCreateByName() != null && serviceItemsManageDO.getCreateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 createByName 过滤条件(可能由 Assembler 自动设置)",
serviceItemsManageDO.getOrganizationId());
serviceItemsManageDO.setCreateByName(null);
}
if (serviceItemsManageDO.getUpdateByName() != null && serviceItemsManageDO.getUpdateByName().equals(currentUserName)) {
log.info("南光组织查询指定组织数据(organizationId={}),清空 updateByName 过滤条件(可能由 Assembler 自动设置)",
serviceItemsManageDO.getOrganizationId());
serviceItemsManageDO.setUpdateByName(null);
}
}
}
log.info("设置组织ID后,查询参数:organizationId={}, topOrganizationId={}, createByName={}, updateByName={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId(),
serviceItemsManageDO.getCreateByName(), serviceItemsManageDO.getUpdateByName());
List<ServiceItemsManagePO> result = serviceItemsManageDomainService.queryList(serviceItemsManageDO);
log.info("查询服务项管理列表成功,返回数据条数:{}", result != null ? result.size() : 0);
return result;
} catch (Exception e) {
log.error("查询服务项管理列表异常", e);
throw e;
}
}
public List<ServiceItemsManagePO> getCostTypeList(ServiceItemsManageDO serviceItemsManageDO){
setTopOrganizationIdLogin(serviceItemsManageDO);
return serviceItemsManageDomainService.getCostsType(serviceItemsManageDO);
}
private void setTopOrganizationIdLogin(ServiceItemsManageDO serviceItemsManageDO){
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
serviceItemsManageDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
try {
log.info("开始查询费用类别列表,参数:{}", serviceItemsManageDO);
// 先保存前端传递的 organizationId(如果存在)
Long frontendOrganizationId = serviceItemsManageDO.getOrganizationId();
// 获取登录用户信息
LoginUser loginUser = SecurityUtils.getLoginUser();
Long loginUserOrganizationId = null;
Long topOrganizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
}
// 数据权限:根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织(organizationId=2827):可以查询所有组织的数据
// 如果前端传递了 organizationId(包括2827),使用前端传递的值进行过滤
// 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
serviceItemsManageDO.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据
serviceItemsManageDO.setOrganizationId(null);
serviceItemsManageDO.setTopOrganizationId(null);
}
} else {
// 其他组织:设置organizationId,只查询当前组织的数据
// 其他组织只能查询自己组织的数据,不能查询其他组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询
log.warn("费用类别查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值
serviceItemsManageDO.setOrganizationId(frontendOrganizationId);
}
if (topOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(topOrganizationId);
}
} else {
// 前端没有传递 organizationId,使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
serviceItemsManageDO.setOrganizationId(loginUserOrganizationId);
}
if (topOrganizationId != null) {
serviceItemsManageDO.setTopOrganizationId(topOrganizationId);
}
}
}
log.info("设置组织ID后,费用类别查询参数:organizationId={}, topOrganizationId={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId());
List<ServiceItemsManagePO> result = serviceItemsManageDomainService.getCostsType(serviceItemsManageDO);
log.info("查询费用类别列表成功,返回数据条数:{}", result != null ? result.size() : 0);
return result;
} catch (Exception e) {
log.error("查询费用类别列表异常", e);
throw e;
}
}
@@ -56,6 +56,13 @@ public class WarehouseApplicationService {
* 新增仓库
*/
public Boolean insert(WarehouseDO warehouseDO) {
// 设置当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
warehouseDO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
//设置数据字典键值
setDataDict(warehouseDO);
return warehouseDomainService.insert(warehouseDO);
@@ -126,4 +126,7 @@ public class CommonRouteDo extends BaseVOEntity
@ApiModelProperty(name = "运费单价")
private BigDecimal freightUnitPrice;
@ApiModelProperty(name = "组织ID(用于数据权限过滤,内部使用)", hidden = true)
private Long organizationId;
}
@@ -10,6 +10,7 @@ import com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDO;
import com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDoMap;
import com.mhd.basic.domain.expenseAccount.repository.todo.SearchExpenseAccountDO;
import com.mhd.basic.interfaces.dto.expenseAccount.SearchExpenseAccountDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@ import java.util.List;
* @author gen
* @date 2024-06-04
*/
@Slf4j
@Service
public class ExpenseAccountImpl extends ServiceImpl<ExpenseAccountMapper, ExpenseAccount> implements IExpenseAccountService{
@Autowired
@@ -35,7 +37,15 @@ public class ExpenseAccountImpl extends ServiceImpl<ExpenseAccountMapper, Expens
@Override
public List<ExpenseAccountPO> queryList(ExpenseAccountDO expenseAccountDO)
{
return expenseAccountMapper.queryList(expenseAccountDO);
// 添加日志,记录查询参数
log.info("ExpenseAccountImpl.queryList 查询参数:topOrganizationId={}, subjectName={}, subjectCode={}, status={}",
expenseAccountDO.getTopOrganizationId(),
expenseAccountDO.getSubjectName(),
expenseAccountDO.getSubjectCode(),
expenseAccountDO.getStatus());
List<ExpenseAccountPO> result = expenseAccountMapper.queryList(expenseAccountDO);
log.info("ExpenseAccountImpl.queryList 查询结果:{} 条", result != null ? result.size() : 0);
return result;
}
@Override
@@ -39,5 +39,16 @@ public class QueryExpenseAccountPO {
@Excel(name = "上级科目名称")
private String upperSubject;
@ApiModelProperty("一级组织表ID")
@Excel(name = "一级组织表ID")
private Long topOrganizationId;
@ApiModelProperty("组织表ID")
@Excel(name = "组织表ID")
private Long organizationId;
@ApiModelProperty("组织名称")
@Excel(name = "组织名称")
private String organizationName;
}
@@ -25,4 +25,10 @@ public class SearchExpenseAccountDO{
@ApiModelProperty("社会车辆固定显示(1-是,2-否)")
private Integer societyStatus;
@ApiModelProperty("组织ID")
private Long organizationId;
@ApiModelProperty("上级组织ID")
private Long topOrganizationId;
}
@@ -22,7 +22,7 @@ public interface IServiceItemsManageService extends IService<ServiceItemsManage>
/**
* 查询费用类别
*/
public List<ServiceItemsManagePO> getCostType();
public List<ServiceItemsManagePO> getCostType(ServiceItemsManageDO serviceItemsManageDO);
/**
* 新增服务项管理
*/
@@ -21,6 +21,6 @@ public interface ServiceItemsManageMapper extends BaseMapper<ServiceItemsManage>
/**
* 查询费用类别
*/
public List<ServiceItemsManagePO> selectServiceTypes();
public List<ServiceItemsManagePO> selectServiceTypes(ServiceItemsManageDO serviceItemsManageDO);
}
@@ -6,6 +6,7 @@ import com.mhd.basic.domain.serviceItemsManage.entity.ServiceItemsManage;
import com.mhd.basic.domain.serviceItemsManage.repository.facade.IServiceItemsManageService;
import com.mhd.basic.domain.serviceItemsManage.repository.po.ServiceItemsManagePO;
import com.mhd.basic.domain.serviceItemsManage.repository.todo.ServiceItemsManageDO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -19,6 +20,7 @@ import java.util.List;
* @author gen
* @date 2024-06-03
*/
@Slf4j
@Service
public class ServiceItemsManageImpl extends ServiceImpl<ServiceItemsManageMapper, ServiceItemsManage> implements IServiceItemsManageService{
@Autowired
@@ -30,12 +32,80 @@ public class ServiceItemsManageImpl extends ServiceImpl<ServiceItemsManageMapper
@Override
public List<ServiceItemsManagePO> queryList(ServiceItemsManageDO serviceItemsManageDO)
{
return serviceItemsManageMapper.queryList(serviceItemsManageDO);
// 添加日志,记录查询参数
log.info("ServiceItemsManageImpl.queryList 查询参数:topOrganizationId={}, organizationId={}, serviceItemsName={}, serviceItemsCode={}",
serviceItemsManageDO.getTopOrganizationId(),
serviceItemsManageDO.getOrganizationId(),
serviceItemsManageDO.getServiceItemsName(),
serviceItemsManageDO.getServiceItemsCode());
// 构建SQL查询条件说明(用于日志,必须与 MyBatis XML 中的条件保持一致)
StringBuilder sqlCondition = new StringBuilder("WHERE del_flag = 1");
// 组织过滤条件(与 XML 中的 <if test="organizationId != null"> 和 <if test="topOrganizationId != null and organizationId == null"> 对应)
if (serviceItemsManageDO.getOrganizationId() != null) {
// 如果设置了 organizationId,添加 organization_id 条件
sqlCondition.append(" AND organization_id = ").append(serviceItemsManageDO.getOrganizationId());
sqlCondition.append(" AND organization_name IS NOT NULL");
sqlCondition.append(" AND organization_name != ''");
sqlCondition.append(" AND LENGTH(TRIM(organization_name)) > 0");
} else if (serviceItemsManageDO.getTopOrganizationId() != null) {
// 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件
sqlCondition.append(" AND top_organization_id = ").append(serviceItemsManageDO.getTopOrganizationId());
sqlCondition.append(" AND organization_name IS NOT NULL");
sqlCondition.append(" AND organization_name != ''");
sqlCondition.append(" AND LENGTH(TRIM(organization_name)) > 0");
} else {
// 如果 organizationId 和 topOrganizationId 都为 null,不添加组织过滤条件(查询所有组织的数据)
sqlCondition.append(" (无组织过滤条件,查询所有组织的数据)");
}
// 其他查询条件
if (serviceItemsManageDO.getCreateByName() != null && !serviceItemsManageDO.getCreateByName().isEmpty()) {
sqlCondition.append(" AND create_by_name LIKE '%").append(serviceItemsManageDO.getCreateByName()).append("%'");
}
if (serviceItemsManageDO.getUpdateByName() != null && !serviceItemsManageDO.getUpdateByName().isEmpty()) {
sqlCondition.append(" AND update_by_name LIKE '%").append(serviceItemsManageDO.getUpdateByName()).append("%'");
}
if (serviceItemsManageDO.getOrganizationName() != null && !serviceItemsManageDO.getOrganizationName().isEmpty()) {
sqlCondition.append(" AND organization_name LIKE '%").append(serviceItemsManageDO.getOrganizationName()).append("%'");
}
if (serviceItemsManageDO.getServiceItemsName() != null && !serviceItemsManageDO.getServiceItemsName().isEmpty()) {
sqlCondition.append(" AND service_items_name LIKE '%").append(serviceItemsManageDO.getServiceItemsName()).append("%'");
}
if (serviceItemsManageDO.getServiceItemsCode() != null && !serviceItemsManageDO.getServiceItemsCode().isEmpty()) {
sqlCondition.append(" AND service_items_code = '").append(serviceItemsManageDO.getServiceItemsCode()).append("'");
}
if (serviceItemsManageDO.getTaxRate() != null) {
sqlCondition.append(" AND tax_rate = ").append(serviceItemsManageDO.getTaxRate());
}
if (serviceItemsManageDO.getRemark() != null && !serviceItemsManageDO.getRemark().isEmpty()) {
sqlCondition.append(" AND remark LIKE '%").append(serviceItemsManageDO.getRemark()).append("%'");
}
log.info("ServiceItemsManageImpl.queryList 生成的SQL条件(预估):SELECT * FROM service_items_manage {}", sqlCondition.toString());
log.info("ServiceItemsManageImpl.queryList 实际执行的SQL请查看 MyBatis 日志,参数:organizationId={}, topOrganizationId={}, delFlag={}",
serviceItemsManageDO.getOrganizationId(), serviceItemsManageDO.getTopOrganizationId(), serviceItemsManageDO.getDelFlag());
List<ServiceItemsManagePO> result = serviceItemsManageMapper.queryList(serviceItemsManageDO);
log.info("ServiceItemsManageImpl.queryList 查询结果:{} 条", result != null ? result.size() : 0);
// 记录查询结果中的组织ID分布
if (result != null && !result.isEmpty()) {
StringBuilder orgIds = new StringBuilder();
for (ServiceItemsManagePO po : result) {
if (orgIds.length() > 0) {
orgIds.append(", ");
}
orgIds.append(po.getOrganizationId());
}
log.info("查询结果中的组织ID分布:{}", orgIds.toString());
}
return result;
}
@Override
public List<ServiceItemsManagePO> getCostType() {
return serviceItemsManageMapper.selectServiceTypes();
public List<ServiceItemsManagePO> getCostType(ServiceItemsManageDO serviceItemsManageDO) {
return serviceItemsManageMapper.selectServiceTypes(serviceItemsManageDO);
}
/**
* 新增服务项管理
@@ -37,7 +37,7 @@ public class ServiceItemsManageDomainService {
* 查询费用类型
*/
public List<ServiceItemsManagePO> getCostsType(ServiceItemsManageDO serviceItemsManageDO){
return serviceItemsManageService.getCostType();
return serviceItemsManageService.getCostType(serviceItemsManageDO);
}
@@ -27,8 +27,10 @@ public class ExpenseAccountAssembler {
*/
public ExpenseAccountDO toDO(ExpenseAccountDTO expenseAccountDTO) {
ExpenseAccountDO expenseAccountDO = new ExpenseAccountDO();
// 拷贝
BeanUtils.copyProperties(expenseAccountDTO, expenseAccountDO, IgnoreNullUtil.getNullPropertyNames(expenseAccountDTO));
// 如果 expenseAccountDTO 不为 null,才进行拷贝
if (expenseAccountDTO != null) {
BeanUtils.copyProperties(expenseAccountDTO, expenseAccountDO, IgnoreNullUtil.getNullPropertyNames(expenseAccountDTO));
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
@@ -36,28 +38,45 @@ public class ExpenseAccountAssembler {
String userName = loginUser.getUsername();
// 获取登录人id
Long userId = loginUser.getUserid();
if(expenseAccountDTO.getExpenseAccountId() != null){
// 只有在新增或编辑操作时才设置 createByName 和 updateByName
// 查询列表时不应该自动设置这些字段,否则会导致 SQL 中添加过滤条件,影响查询结果
if(expenseAccountDTO != null && expenseAccountDTO.getExpenseAccountId() != null){
// 编辑操作:只设置更新相关字段
if(userId != null){
expenseAccountDO.setUpdateBy(userId);
}else {
expenseAccountDO.setUpdateBy(new Long("0"));
}
expenseAccountDO.setUpdateByName(userName);
expenseAccountDO.setUpdateTime(new Date());
}else {
if(userId != null){
expenseAccountDO.setCreateBy(userId);
expenseAccountDO.setUpdateBy(userId);
}else {
expenseAccountDO.setCreateBy(new Long("0"));
expenseAccountDO.setUpdateBy(new Long("0"));
// 只有在 DTO 中没有传递 updateByName 时才设置(避免覆盖前端传递的值)
if(expenseAccountDO.getUpdateByName() == null || expenseAccountDO.getUpdateByName().isEmpty()){
expenseAccountDO.setUpdateByName(userName);
}
expenseAccountDO.setCreateByName(userName);
expenseAccountDO.setUpdateByName(userName);
expenseAccountDO.setCreateTime(new Date());
expenseAccountDO.setUpdateTime(new Date());
expenseAccountDO.setDelFlag(1);
} else if(expenseAccountDTO != null && expenseAccountDTO.getExpenseAccountId() == null) {
// expenseAccountId == null,可能是查询操作或新增操作
// 如果前端传递了 createByName 或 updateByName,说明是查询条件,不应该设置(已经在 BeanUtils.copyProperties 中拷贝了)
// 如果前端没有传递 createByName 和 updateByName,可能是新增操作,需要设置默认值
boolean hasQueryCondition = (expenseAccountDTO.getCreateByName() != null && !expenseAccountDTO.getCreateByName().isEmpty())
|| (expenseAccountDTO.getUpdateByName() != null && !expenseAccountDTO.getUpdateByName().isEmpty());
if(!hasQueryCondition) {
// 没有查询条件,可能是新增操作,设置默认值
if(userId != null){
expenseAccountDO.setCreateBy(userId);
expenseAccountDO.setUpdateBy(userId);
}else {
expenseAccountDO.setCreateBy(new Long("0"));
expenseAccountDO.setUpdateBy(new Long("0"));
}
expenseAccountDO.setCreateByName(userName);
expenseAccountDO.setUpdateByName(userName);
expenseAccountDO.setCreateTime(new Date());
expenseAccountDO.setUpdateTime(new Date());
expenseAccountDO.setDelFlag(1);
}
// 如果有查询条件(createByName 或 updateByName),说明是查询操作,不应该设置这些字段
// 字段值已经在 BeanUtils.copyProperties 中从 DTO 拷贝过来了
}
return expenseAccountDO;
}
@@ -27,8 +27,10 @@ public class ServiceItemsManageAssembler {
*/
public ServiceItemsManageDO toDO(ServiceItemsManageDTO serviceItemsManageDTO) {
ServiceItemsManageDO serviceItemsManageDO = new ServiceItemsManageDO();
// 拷贝
BeanUtils.copyProperties(serviceItemsManageDTO, serviceItemsManageDO, IgnoreNullUtil.getNullPropertyNames(serviceItemsManageDTO));
// 如果 serviceItemsManageDTO 不为 null,才进行拷贝
if (serviceItemsManageDTO != null) {
BeanUtils.copyProperties(serviceItemsManageDTO, serviceItemsManageDO, IgnoreNullUtil.getNullPropertyNames(serviceItemsManageDTO));
}
LoginUser loginUser = SecurityUtils.getLoginUser();
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
@@ -36,28 +38,49 @@ public class ServiceItemsManageAssembler {
String userName = loginUser.getUsername();
// 获取登录人id
Long userId = loginUser.getUserid();
if(serviceItemsManageDTO.getServiceItemsManageId() != null){
// 只有在新增或编辑操作时才设置 createByName 和 updateByName
// 查询列表时不应该自动设置这些字段,否则会导致 SQL 中添加过滤条件,影响查询结果
// 判断规则:
// 1. 如果 serviceItemsManageId != null,说明是编辑操作,只设置更新相关字段
// 2. 如果 serviceItemsManageId == null 且前端传递了 createByName 或 updateByName,说明是查询条件,不应该覆盖
// 3. 如果 serviceItemsManageId == null 且前端没有传递 createByName 和 updateByName,可能是新增操作,设置默认值
if(serviceItemsManageDTO != null && serviceItemsManageDTO.getServiceItemsManageId() != null){
// 编辑操作:只设置更新相关字段
if(userId != null){
serviceItemsManageDO.setUpdateBy(userId);
}else {
serviceItemsManageDO.setUpdateBy(new Long("0"));
}
serviceItemsManageDO.setUpdateByName(userName);
serviceItemsManageDO.setUpdateTime(new Date());
}else {
if(userId != null){
serviceItemsManageDO.setCreateBy(userId);
serviceItemsManageDO.setUpdateBy(userId);
}else {
serviceItemsManageDO.setCreateBy(new Long("0"));
serviceItemsManageDO.setUpdateBy(new Long("0"));
// 只有在 DTO 中没有传递 updateByName 时才设置(避免覆盖前端传递的值)
if(serviceItemsManageDO.getUpdateByName() == null || serviceItemsManageDO.getUpdateByName().isEmpty()){
serviceItemsManageDO.setUpdateByName(userName);
}
serviceItemsManageDO.setCreateByName(userName);
serviceItemsManageDO.setUpdateByName(userName);
serviceItemsManageDO.setCreateTime(new Date());
serviceItemsManageDO.setUpdateTime(new Date());
serviceItemsManageDO.setDelFlag(1);
} else if(serviceItemsManageDTO != null && serviceItemsManageDTO.getServiceItemsManageId() == null) {
// serviceItemsManageId == null,可能是查询操作或新增操作
// 如果前端传递了 createByName 或 updateByName,说明是查询条件,不应该设置(已经在 BeanUtils.copyProperties 中拷贝了)
// 如果前端没有传递 createByName 和 updateByName,可能是新增操作,需要设置默认值
boolean hasQueryCondition = (serviceItemsManageDTO.getCreateByName() != null && !serviceItemsManageDTO.getCreateByName().isEmpty())
|| (serviceItemsManageDTO.getUpdateByName() != null && !serviceItemsManageDTO.getUpdateByName().isEmpty());
if(!hasQueryCondition) {
// 没有查询条件,可能是新增操作,设置默认值
if(userId != null){
serviceItemsManageDO.setCreateBy(userId);
serviceItemsManageDO.setUpdateBy(userId);
}else {
serviceItemsManageDO.setCreateBy(new Long("0"));
serviceItemsManageDO.setUpdateBy(new Long("0"));
}
serviceItemsManageDO.setCreateByName(userName);
serviceItemsManageDO.setUpdateByName(userName);
serviceItemsManageDO.setCreateTime(new Date());
serviceItemsManageDO.setUpdateTime(new Date());
serviceItemsManageDO.setDelFlag(1);
}
// 如果有查询条件(createByName 或 updateByName),说明是查询操作,不应该设置这些字段
// 字段值已经在 BeanUtils.copyProperties 中从 DTO 拷贝过来了
}
return serviceItemsManageDO;
}
@@ -52,11 +52,29 @@ public class ExpenseAccountApi extends BaseController{
@GetMapping("/list")
public TableDataInfo list(ExpenseAccountDTO expenseAccountDTO)
{
//转换实体
ExpenseAccountDO expenseAccountDO = expenseAccountAssembler.toDO(expenseAccountDTO);
startPage();
List<ExpenseAccountPO> list = expenseAccountApplicationService.queryList(expenseAccountDO);
return getDataTable(list);
logger.info("收到查询费用科目列表请求,参数:{}", expenseAccountDTO);
try {
//转换实体,如果 expenseAccountDTO 为 null,创建一个新的对象
if (expenseAccountDTO == null) {
expenseAccountDTO = new ExpenseAccountDTO();
logger.info("expenseAccountDTO 为 null,创建新对象");
}
ExpenseAccountDO expenseAccountDO = expenseAccountAssembler.toDO(expenseAccountDTO);
logger.info("转换后的 ExpenseAccountDO{}", expenseAccountDO);
startPage();
logger.info("分页参数已设置");
List<ExpenseAccountPO> list = expenseAccountApplicationService.queryList(expenseAccountDO);
logger.info("查询完成,返回数据条数:{}", list != null ? list.size() : 0);
if (list != null && list.isEmpty()) {
logger.warn("查询结果为空,可能的原因:1.数据库中没有符合条件的数据 2.数据权限过滤 3.SQL查询条件问题");
logger.warn("查询条件:topOrganizationId={}, del_flag=1", expenseAccountDO.getTopOrganizationId());
}
return getDataTable(list);
} catch (Exception e) {
logger.error("查询费用科目列表失败", e);
e.printStackTrace();
return getDataTable(new ArrayList<>());
}
}
@ApiOperation("查询费用科目树型列表")
@@ -84,6 +102,32 @@ public class ExpenseAccountApi extends BaseController{
return AjaxResult.success(expenseAccountApplicationService.selectOtherExpenseAccount(searchExpenseAccountDO));
}
/**
* 测试查询 - 不设置组织ID,查看是否有数据
*/
@ApiOperation("测试查询费用科目列表(不设置组织ID")
@GetMapping("/testList")
public AjaxResult testList(ExpenseAccountDTO expenseAccountDTO)
{
logger.info("测试查询费用科目列表,不设置组织ID");
try {
if (expenseAccountDTO == null) {
expenseAccountDTO = new ExpenseAccountDTO();
}
ExpenseAccountDO expenseAccountDO = expenseAccountAssembler.toDO(expenseAccountDTO);
// 不设置组织ID,测试是否能查询到数据
expenseAccountDO.setTopOrganizationId(null);
logger.info("测试查询参数:{}", expenseAccountDO);
startPage();
List<ExpenseAccountPO> list = expenseAccountApplicationService.queryList(expenseAccountDO);
logger.info("测试查询结果:{} 条", list != null ? list.size() : 0);
return AjaxResult.success(list);
} catch (Exception e) {
logger.error("测试查询失败", e);
return AjaxResult.error("测试查询失败:" + e.getMessage());
}
}
@ApiOperation("查询费用科目-所有现金明细")
@GetMapping("/selectAllCashExpenseAccount")
public AjaxResult selectAllCashExpenseAccount(){
@@ -85,12 +85,25 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
if (ObjectUtil.isNull(loginUser)) {
throw new DigitalLogisticsException(UserError.TIMEOUT);
}
// 数据权限验证南光组织organizationId=2827可以删除所有组织的数据其他组织只能删除自己组织的数据
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
for (Long dictCode : dictCodes)
{
SysDictData data = selectDictDataById(dictCode);
if (ObjectUtil.notEqual(data.getTopOrganizationId(), loginUser.getUserPo().getTopOrganizationId())) {
throw new ServiceException("修改失败");
// 南光组织organizationId=2827可以删除所有组织的数据
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织可以删除不需要验证 topOrganizationId
} else {
// 其他组织只能删除自己组织的数据
// 使用 Objects.equals 安全比较处理 null 值的情况
if (!java.util.Objects.equals(data.getTopOrganizationId(), loginUserTopOrganizationId)) {
throw new ServiceException("删除失败:无权删除其他组织的字典数据");
}
}
dictDataMapper.deleteDictDataById(dictCode);
SysDictData dictData = new SysDictData();
dictData.setDictType(data.getDictType());
@@ -146,11 +159,25 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
if (ObjectUtil.isNull(sysDictData)) {
throw new ServiceException("字典数据未找到");
}
if ("Y".equals(sysDictData.getIsDefault())) {
throw new ServiceException("默认数据不允许修改");
}
if (ObjectUtil.notEqual(sysDictData.getTopOrganizationId(), loginUser.getUserPo().getTopOrganizationId())) {
throw new ServiceException("修改失败");
// 数据权限验证南光组织organizationId=2827可以修改所有组织的数据包括默认数据其他组织只能修改自己组织的数据包括默认数据
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long loginUserTopOrganizationId = loginUser.getUserPo().getTopOrganizationId();
Long dictDataTopOrganizationId = sysDictData.getTopOrganizationId();
Long dictDataOrganizationId = sysDictData.getOrganizationId();
// 南光组织organizationId=2827可以修改所有组织的数据包括默认数据
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织可以修改不需要验证 topOrganizationId
} else {
// 其他组织只能修改自己组织的数据包括默认数据
// 使用 Objects.equals 安全比较处理 null 值的情况
boolean isSameTopOrg = java.util.Objects.equals(dictDataTopOrganizationId, loginUserTopOrganizationId);
boolean isSameOrg = java.util.Objects.equals(dictDataOrganizationId, loginUserOrganizationId);
if (!isSameTopOrg || !isSameOrg) {
throw new ServiceException("修改失败:无权修改其他组织的字典数据");
}
}
data.setUpdateBy(loginUser.getUserPo().getUserName());
int row = dictDataMapper.updateDictData(data);
@@ -102,7 +102,7 @@
WHERE
a.del_flag = 1
<include refid="common_where"/>
order by account_type,service_items_code,upper_subject_code,show_seq
order by a.account_type,service_items_code,upper_subject_code,show_seq
</select>
<select id="selectCostSubject" parameterType="com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDO"
resultType="com.mhd.basic.domain.expenseAccount.repository.po.ExpenseAccountPO">
@@ -191,8 +191,24 @@
<if test="expenseAccountDO.updateTimeEnd != null and expenseAccountDO.updateTimeEnd != ''">
AND date_format(a.update_time,'%Y-%m-%d') <![CDATA[<=]]> #{expenseAccountDO.updateTimeEnd}
</if>
<if test="expenseAccountDO.topOrganizationId != null ">
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) -->
<if test="expenseAccountDO.organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and a.organization_id = #{expenseAccountDO.organizationId}
and a.organization_name IS NOT NULL
and a.organization_name != ''
and LENGTH(TRIM(a.organization_name)) > 0
</if>
<if test="expenseAccountDO.topOrganizationId != null and expenseAccountDO.organizationId == null">
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
and a.top_organization_id = #{expenseAccountDO.topOrganizationId}
and a.organization_name IS NOT NULL
and a.organization_name != ''
and LENGTH(TRIM(a.organization_name)) > 0
</if>
<if test="expenseAccountDO.organizationName != null and expenseAccountDO.organizationName != ''">
and a.organization_name like concat('%', #{expenseAccountDO.organizationName}, '%')
</if>
<if test="expenseAccountDO.serviceItemsCode != null and expenseAccountDO.serviceItemsCode != ''">
and b.service_items_code = #{expenseAccountDO.serviceItemsCode}
@@ -8,18 +8,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectServiceItemsManagePo1">
<where>
del_flag = 1
<!-- 删除标记:0-无状态,1-正常,2-已删除,查询时只查询正常的数据 -->
<choose>
<when test="delFlag != null">
and del_flag = #{delFlag}
</when>
<otherwise>
and del_flag = 1
</otherwise>
</choose>
<if test="createByName != null and createByName != ''">
and create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="topOrganizationId != null ">
and top_organization_id = #{topOrganizationId}
</if>
<if test="organizationId != null ">
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<!-- 如果 organizationId 和 topOrganizationId 都为 null,表示查询所有组织的数据(不添加组织过滤条件) -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and organization_id = #{organizationId}
and organization_name IS NOT NULL
and organization_name != ''
and LENGTH(TRIM(organization_name)) > 0
</if>
<if test="topOrganizationId != null and organizationId == null">
<!-- 如果设置了 topOrganizationId 但没有设置 organizationId,添加 top_organization_id 条件 -->
and top_organization_id = #{topOrganizationId}
and organization_name IS NOT NULL
and organization_name != ''
and LENGTH(TRIM(organization_name)) > 0
</if>
<if test="organizationName != null and organizationName != ''">
and organization_name like concat('%', #{organizationName}, '%')
@@ -42,12 +60,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTimeEnd != null and createTimeEnd != ''">
AND date_format(create_time,'%Y-%m-%d') <![CDATA[<=]]> #{createTimeEnd}
</if>
<if test="createByName != null and createByName != ''">
and create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="updateTimeStart != null and updateTimeStart != ''">
AND date_format(update_time,'%Y-%m-%d') <![CDATA[>=]]> #{updateTimeStart}
</if>
@@ -63,10 +75,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectServiceItemsManagePo1"/>
</select>
<select id="selectServiceTypes"
<select id="selectServiceTypes" parameterType="com.mhd.basic.domain.serviceItemsManage.repository.todo.ServiceItemsManageDO"
resultType="com.mhd.basic.domain.serviceItemsManage.repository.po.ServiceItemsManagePO">
select organization_name,service_items_code,service_items_name,tax_rate,CONCAT(service_items_name,service_items_code) cost_type
from service_items_manage
where del_flag = 1
<include refid="selectServiceItemsManagePo1"/>
</select>
</mapper>
@@ -9,6 +9,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.*
from
common_route a
<if test="commonRouteDo.organizationId != null">
LEFT JOIN "USER" u ON a.user_id = u.user_id AND u.del_flag = 0
</if>
WHERE
a.del_flag = 1
</sql>
@@ -26,6 +29,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and (a.mail_name like concat('%', #{commonRouteDo.synthesize}, '%') OR a.mail_phone LIKE concat('%', #{commonRouteDo.synthesize}, '%') OR a.mail_address_plot LIKE concat('%', #{commonRouteDo.synthesize}, '%')
OR a.addressee_name like concat('%', #{commonRouteDo.synthesize}, '%') OR a.addressee_phone LIKE concat('%', #{commonRouteDo.synthesize}, '%') OR a.addressee_address_plot LIKE concat('%', #{commonRouteDo.synthesize}, '%'))
</if>
<!-- 组织数据权限过滤:通过用户表关联来过滤组织数据 -->
<if test="commonRouteDo.organizationId != null">
and u.organization_id = #{commonRouteDo.organizationId}
</if>
</sql>
<select id="selectCommonRouteByCommonRouteId" parameterType="java.lang.Long"
@@ -140,27 +140,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectAddressBookList" parameterType="com.mhd.common.core.domain.po.AddressBookPo" resultMap="AddressBookResult">
<include refid="selectAddressBookVo"/>
SELECT
ab.*
FROM
address_book ab
<if test="organizationId != null">
LEFT JOIN "USER" u ON ab.user_id = u.user_id AND u.del_flag = 0
</if>
<where>
del_flag = 1
<if test="synthesize != null and synthesize != ''"> and (link_man like concat('%', #{synthesize}, '%') OR link_phone LIKE concat('%', #{synthesize}, '%') OR area_name LIKE concat('%', #{synthesize}, '%') OR address LIKE concat('%', #{synthesize}, '%') OR address_plot LIKE concat('%', #{synthesize}, '%')) </if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="linkMan != null and linkMan != ''"> and link_man = #{linkMan}</if>
<if test="linkPhone != null and linkPhone != ''"> and link_phone = #{linkPhone}</if>
<if test="provinceCode != null "> and province_code = #{provinceCode}</if>
<if test="cityCode != null "> and city_code = #{cityCode}</if>
<if test="countyCode != null "> and county_code = #{countyCode}</if>
<if test="provinceName != null and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
<if test="cityName != null and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
<if test="countyName != null and countyName != ''"> and county_name like concat('%', #{countyName}, '%')</if>
<if test="address != null and address != ''"> and address = #{address}</if>
<if test="doorplate != null and doorplate != ''"> and doorplate = #{doorplate}</if>
<if test="defaultStatus != null "> and default_status = #{defaultStatus}</if>
<if test="createByName != null and createByName != ''"> and create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and update_by_name like concat('%', #{updateByName}, '%')</if>
ab.del_flag = 1
<if test="synthesize != null and synthesize != ''"> and (ab.link_man like concat('%', #{synthesize}, '%') OR ab.link_phone LIKE concat('%', #{synthesize}, '%') OR ab.area_name LIKE concat('%', #{synthesize}, '%') OR ab.address LIKE concat('%', #{synthesize}, '%') OR ab.address_plot LIKE concat('%', #{synthesize}, '%')) </if>
<if test="userId != null "> and ab.user_id = #{userId}</if>
<if test="linkMan != null and linkMan != ''"> and ab.link_man = #{linkMan}</if>
<if test="linkPhone != null and linkPhone != ''"> and ab.link_phone = #{linkPhone}</if>
<if test="provinceCode != null "> and ab.province_code = #{provinceCode}</if>
<if test="cityCode != null "> and ab.city_code = #{cityCode}</if>
<if test="countyCode != null "> and ab.county_code = #{countyCode}</if>
<if test="provinceName != null and provinceName != ''"> and ab.province_name like concat('%', #{provinceName}, '%')</if>
<if test="cityName != null and cityName != ''"> and ab.city_name like concat('%', #{cityName}, '%')</if>
<if test="countyName != null and countyName != ''"> and ab.county_name like concat('%', #{countyName}, '%')</if>
<if test="address != null and address != ''"> and ab.address = #{address}</if>
<if test="doorplate != null and doorplate != ''"> and ab.doorplate = #{doorplate}</if>
<if test="defaultStatus != null "> and ab.default_status = #{defaultStatus}</if>
<if test="createByName != null and createByName != ''"> and ab.create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and ab.update_by_name like concat('%', #{updateByName}, '%')</if>
<!-- 组织数据权限过滤:通过用户表关联来过滤组织数据 -->
<if test="organizationId != null">
and u.organization_id = #{organizationId}
</if>
</where>
ORDER BY
create_time DESC
ab.create_time DESC
</select>
<select id="selectAddressBookListByManifestId" parameterType="java.lang.Long" resultMap="AddressBookResult">
@@ -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<>();
}
}
@@ -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);
//处理车队数据
@@ -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 时为顶级组织南光组织
// 与其他模块保持一致VerificationApplicationServiceTmsReceiptApplicationService等
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();
//复制之前角色的菜单
@@ -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) {
@@ -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());
// 不抛出异常允许继续执行因为角色可能在其他地方分配
}
}
/**
* 托运人待审核推送
*/
@@ -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);
//托运人总数
@@ -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);
@@ -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;
}
@@ -209,8 +209,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="organizationName != null and organizationName != ''">
and m.organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="topOrganizationId != null and topOrganizationId != ''">
and top_organization_id = #{topOrganizationId}
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
</if>
<if test="topOrganizationId != null">
<!-- 如果设置了 topOrganizationId,添加 top_organization_id 条件 -->
and m.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
<!-- 如果没有设置 organizationId,添加 organization_name IS NOT NULL 条件 -->
and m.organization_name IS NOT NULL
</if>
</if>
<if test="organizationIdList != null ">
AND m.organization_id in
@@ -377,7 +388,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id and d.del_flag = 1
where top_organization_id = #{organizationId} and m.del_flag = 1
<where>
m.del_flag = 1
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
</if>
<if test="topOrganizationId != null">
<!-- 如果设置了 topOrganizationId,添加 top_organization_id 条件 -->
and m.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
<!-- 如果没有设置 organizationId,添加 organization_name IS NOT NULL 条件 -->
and m.organization_name IS NOT NULL
</if>
</if>
</where>
</select>
</mapper>
@@ -25,6 +25,8 @@
a.role_id,
a.parent_role_id,
a.organization_id,
a.organization_name AS organizationName,
a.top_organization_id AS topOrganizationId,
a.role_code,
a.role_name,
a.role_remark,
@@ -51,6 +53,7 @@
a.del_flag = 1
<include refid="common_where"></include>
GROUP BY a.role_id
ORDER BY COALESCE(a.update_time, a.create_time) DESC
</select>
<select id="selectByOrganizationIdAndRoleCode"
parameterType="com.mhd.user.domain.roleAggregate.repository.todo.RoleDo"
@@ -119,6 +122,16 @@
</if>
<if test="organizationId !=null">
and a.organization_id = #{organizationId}
and a.organization_name IS NOT NULL
</if>
<if test="topOrganizationId !=null">
and a.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
and a.organization_name IS NOT NULL
</if>
</if>
<if test="organizationName != null and organizationName != ''">
and a.organization_name like concat('%' , #{organizationName} , '%')
</if>
<if test="organizationIds !=null">
and a.organization_id in
@@ -703,7 +703,10 @@
<!-- </foreach>-->
<!-- </if>-->
<if test="userDriverDO.organizationId != null"> and b.organization_id = #{userDriverDO.organizationId}</if>
<if test="userDriverDO.organizationId != null">
and b.organization_id = #{userDriverDO.organizationId}
and b.organization_name IS NOT NULL
</if>
<if test="userDriverDO.createBy != null">
and (b.create_by = #{userDriverDO.createBy}
or b.user_id = #{userDriverDO.createBy}
@@ -217,11 +217,19 @@
and a.user_id = #{userId}
</if>
<if test="organizationId !=null">
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
<if test="organizationId != null">
<!-- 如果设置了 organizationId,添加 organization_id 条件 -->
and a.organization_id = #{organizationId}
and a.organization_name IS NOT NULL
</if>
<if test="topOrganizationId !=null">
<if test="topOrganizationId != null">
<!-- 如果设置了 topOrganizationId,添加 top_organization_id 条件 -->
and a.top_organization_id = #{topOrganizationId}
<if test="organizationId == null">
<!-- 如果没有设置 organizationId,添加 organization_name IS NOT NULL 条件 -->
and a.organization_name IS NOT NULL
</if>
</if>
/*组织名称*/
<if test="organizationName != null and organizationName != ''">
@@ -708,7 +716,7 @@
</select>
<select id="findAllShipperInfo" resultType="com.mhd.user.interfaces.vo.QueryAllShipperInfoVo">
SELECT u.user_id, u.user_name, u.user_area_address, u.user_area_county_id, u.user_area_name ,u.user_phone,u.has_default_address,b.shipper_id,b.shipper_enterprise_name,u.DOCUMENT_PREPARER_NC_CODE,b.CUSTOMER_NC_CODE
SELECT u.user_id, u.user_name, u.user_area_address, u.user_area_county_id, u.user_area_name ,u.user_phone,u.has_default_address,b.shipper_id,b.shipper_enterprise_name,u.DOCUMENT_PREPARER_NC_CODE,b.CUSTOMER_NC_CODE,u.organization_id AS organizationId,u.top_organization_id AS topOrganizationId
FROM "USER" u
LEFT JOIN user_shipper b ON u.user_id = b.user_id
left join (select user_id, LISTAGG(r.role_name, '&amp;') WITHIN GROUP(ORDER BY r.role_name) AS roleName
@@ -723,9 +731,10 @@
<if test="userId !=null">
AND u.user_Id = #{userId}
</if>
/*一级组织ID*/
<if test="topOrganizationId !=null">
AND u.top_organization_id = #{topOrganizationId}
/*组织ID - 数据隔离:南光组织(organizationId=2827)查询全部,其他组织查询自己组织的数据*/
<if test="organizationId !=null">
AND u.organization_id = #{organizationId}
AND u.organization_name IS NOT NULL
</if>
GROUP BY u.user_id
</select>
@@ -114,7 +114,8 @@
b.shipper_enterprisel_auth_id,
a.user_phone,
a.user_name,
a.organization_name,
a.organization_id AS organizationId,
a.organization_name AS organizationName,
a.user_account,
a.user_member_code,
a.user_idcard_number,
@@ -124,11 +124,51 @@ public class BusinessDocumentApplicationService {
public List<BusinessDocumentPO> queryList(BusinessDocumentDO businessDocumentDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("运单管理查询 - 未获取到登录用户信息,跳过数据权限过滤");
return businessDocumentDomainService.queryList(businessDocumentDO);
}
UserPo userPo = loginUser.getUserPo();
if (userPo.getUserAccountType() == 3){
businessDocumentDO.setTopOrganizationId(userPo.getTopOrganizationId());
}else {
businessDocumentDO.setOrganizationId(userPo.getOrganizationId());
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 先保存前端传递的 organizationId如果存在
Long frontendOrganizationId = businessDocumentDO.getOrganizationId();
// 数据权限根据organizationId来设置查询权限
// organizationId等于2827时查询全部其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
// 如果前端传递了 organizationId使用前端传递的值进行过滤
// 如果前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
if (frontendOrganizationId != null) {
businessDocumentDO.setOrganizationId(frontendOrganizationId);
businessDocumentDO.setTopOrganizationId(null);
} else {
businessDocumentDO.setOrganizationId(null);
businessDocumentDO.setTopOrganizationId(null);
}
} else {
// 其他组织根据userAccountType设置组织过滤
if (userPo.getUserAccountType() == 3){
// 租户管理员使用topOrganizationId
if (topOrganizationId != null) {
businessDocumentDO.setTopOrganizationId(topOrganizationId);
}
businessDocumentDO.setOrganizationId(null);
} else {
// 其他用户使用organizationId
if (frontendOrganizationId != null && !frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的organizationId强制使用当前登录用户的组织ID防止越权查询
log.warn("运单管理查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
businessDocumentDO.setOrganizationId(loginUserOrganizationId);
} else if (frontendOrganizationId == null) {
businessDocumentDO.setOrganizationId(loginUserOrganizationId);
}
businessDocumentDO.setTopOrganizationId(null);
}
}
return businessDocumentDomainService.queryList(businessDocumentDO);
}
@@ -1347,6 +1387,21 @@ public class BusinessDocumentApplicationService {
detail.setUpdateBy(loginUser.getUserid());
detail.setUpdateByName(loginUser.getUsername());
detail.setUpdateTime(now);
// 设置审核人的组织ID和组织名称
if (loginUser.getUserPo() != null) {
Long organizationId = loginUser.getUserPo().getOrganizationId();
String organizationName = loginUser.getUserPo().getOrganizationName();
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (organizationId != null) {
detail.setOrganizationId(organizationId);
}
if (organizationName != null) {
detail.setOrganizationName(organizationName);
}
if (topOrganizationId != null) {
detail.setTopOrganizationId(topOrganizationId);
}
}
businessDocumentDetaliUpdateList.add(detail);
BusinessDocumentDetaliDTO detailDto = new BusinessDocumentDetaliDTO();
@@ -1401,6 +1456,7 @@ public class BusinessDocumentApplicationService {
Verification verification = new Verification();
verification.setOrganizationId(businessDocumentDetaliDTO.getOrganizationId());
verification.setTopOrganizationId(businessDocumentDetaliDTO.getTopOrganizationId());
verification.setOrganizationName(businessDocumentDetaliDTO.getOrganizationName());
verification.setVerificationStatus(1);//未支付
verification.setBusinessDocumentDetaliId(businessDocumentDetaliDTO.getBusinessDocumentDetaliId());
verification.setBusinessDocumentDetaliNumber(businessDocumentDetaliDTO.getBusinessDocumentDetaliNumber());
@@ -56,7 +56,7 @@ public class ReceivingAccountApplicationService {
}
/**
* 批量新增收款账户先删除所有再新增
* 批量新增收款账户追加式新增不删除旧数据
*
* @param receivingAccountDTOList 收款账户DTO列表
* @return 是否成功
@@ -65,9 +65,10 @@ public class ReceivingAccountApplicationService {
public Boolean batchInsert(List<ReceivingAccountDO> receivingAccountDTOList) {
log.info("批量新增收款账户,数量:{}", receivingAccountDTOList.size());
// 先删除所有现有数据
int deleteCount = receivingAccountRepository.deleteAll();
log.info("已删除现有收款账户数量:{}", deleteCount);
if (receivingAccountDTOList == null || receivingAccountDTOList.isEmpty()) {
log.warn("批量新增收款账户:数据列表为空");
return false;
}
List<ReceivingAccount> receivingAccountList = new ArrayList<>();
Date now = new Date();
@@ -75,17 +75,68 @@ public class ReconciliationApplicationService {
public List<ReconciliationPO> queryList(ReconciliationDO reconciliationDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
UserPo userPo = loginUser.getUserPo();
if (userPo.getUserAccountType() == 3) {
reconciliationDO.setTopOrganizationId(userPo.getTopOrganizationId());
} else if (userPo.getUserAccountType() == 2){
reconciliationDO.setOrganizationId(userPo.getOrganizationId());
// 先保存前端传递的 organizationId如果存在
Long frontendOrganizationId = reconciliationDO.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使用前端传递的值进行过滤
reconciliationDO.setOrganizationId(frontendOrganizationId);
reconciliationDO.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
reconciliationDO.setOrganizationId(null);
reconciliationDO.setTopOrganizationId(null);
}
} else {
if (loginUser.getRoleList().contains(RoleEnum.SHIPPER.getCode()) || loginUser.getRoleList().contains(RoleEnum.COMPANY.getCode())){
reconciliationDO.setUserId(userPo.getUserId());
}else {
reconciliationDO.setOrganizationId(userPo.getOrganizationId());
// 其他组织设置organizationId只查询当前组织的数据
// 其他组织只能查询自己组织的数据不能查询其他组织包括南光的数据
// 如果其他组织尝试查询南光organizationId=2827的数据返回空数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId验证是否与当前登录用户的组织ID一致
if (frontendOrganizationId.equals(2827L)) {
// 其他组织尝试查询南光的数据设置一个不存在的 organizationId返回空数据
reconciliationDO.setOrganizationId(-1L);
reconciliationDO.setTopOrganizationId(null);
} else if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId强制使用当前登录用户的组织ID防止越权查询
reconciliationDO.setOrganizationId(loginUserOrganizationId);
if (topOrganizationId != null) {
reconciliationDO.setTopOrganizationId(topOrganizationId);
}
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致使用前端传递的值
reconciliationDO.setOrganizationId(frontendOrganizationId);
if (topOrganizationId != null) {
reconciliationDO.setTopOrganizationId(topOrganizationId);
}
}
} else {
// 前端没有传递 organizationId根据用户账号类型设置组织过滤条件
if (userPo.getUserAccountType() == 3) {
reconciliationDO.setTopOrganizationId(topOrganizationId);
} else if (userPo.getUserAccountType() == 2){
reconciliationDO.setOrganizationId(loginUserOrganizationId);
} else {
if (loginUser.getRoleList().contains(RoleEnum.SHIPPER.getCode()) || loginUser.getRoleList().contains(RoleEnum.COMPANY.getCode())){
reconciliationDO.setUserId(userPo.getUserId());
}else {
reconciliationDO.setOrganizationId(loginUserOrganizationId);
}
}
}
}
return reconciliationDomainService.queryList(reconciliationDO);
}
@@ -50,13 +50,80 @@ public class TmsReceiptApplicationService {
public List<TmsReceiptPO> queryList(TmsReceiptDO tmsReceiptDO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null){
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1){
tmsReceiptDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("收款单查询 - 未获取到登录用户信息,跳过数据权限过滤");
return tmsReceiptDomainService.queryList(tmsReceiptDO);
}
// 先保存前端传递的 organizationId如果存在
Long frontendOrganizationId = tmsReceiptDO.getOrganizationId();
// 获取当前登录用户的组织信息
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
log.info("收款单查询 - 开始数据权限处理 - 登录用户组织ID: {}, topOrganizationId: {}, 前端传递组织ID: {}",
loginUserOrganizationId, topOrganizationId, frontendOrganizationId);
// 数据权限根据organizationId来设置查询权限
// organizationId等于2827时查询全部其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
// 如果前端传递了 organizationId使用前端传递的值进行过滤包括2827
// 如果前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId使用前端传递的值进行过滤
tmsReceiptDO.setOrganizationId(frontendOrganizationId);
tmsReceiptDO.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
tmsReceiptDO.setOrganizationId(null);
tmsReceiptDO.setTopOrganizationId(null);
}
} else {
// 其他组织设置organizationId只查询当前组织的数据
// 其他组织只能查询自己组织的数据不能查询其他组织包括南光的数据
// 如果其他组织尝试查询南光organizationId=2827的数据返回空数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId验证是否与当前登录用户的组织ID一致
if (frontendOrganizationId.equals(2827L)) {
// 其他组织尝试查询南光的数据设置一个不存在的 organizationId返回空数据
tmsReceiptDO.setOrganizationId(-1L);
tmsReceiptDO.setTopOrganizationId(null);
} else if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId强制使用当前登录用户的组织ID防止越权查询
tmsReceiptDO.setOrganizationId(loginUserOrganizationId);
if (topOrganizationId != null && topOrganizationId != 1) {
tmsReceiptDO.setTopOrganizationId(topOrganizationId);
}
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致使用前端传递的值
tmsReceiptDO.setOrganizationId(frontendOrganizationId);
if (topOrganizationId != null && topOrganizationId != 1) {
tmsReceiptDO.setTopOrganizationId(topOrganizationId);
}
}
} else {
// 前端没有传递 organizationId根据用户组织信息设置过滤条件
// 优先使用 topOrganizationId如果存在且不等于1否则使用 organizationId
if (topOrganizationId != null && topOrganizationId != 1) {
tmsReceiptDO.setTopOrganizationId(topOrganizationId);
tmsReceiptDO.setOrganizationId(null);
} else if (loginUserOrganizationId != null) {
tmsReceiptDO.setOrganizationId(loginUserOrganizationId);
tmsReceiptDO.setTopOrganizationId(null);
}
}
}
return tmsReceiptDomainService.queryList(tmsReceiptDO);
// 调试日志打印设置的查询条件
log.info("收款单查询 - 数据权限处理完成 - 登录用户组织ID: {}, 前端传递组织ID: {}, 最终查询条件 - organizationId: {}, topOrganizationId: {}, 是否为南光组织: {}",
loginUserOrganizationId, frontendOrganizationId, tmsReceiptDO.getOrganizationId(), tmsReceiptDO.getTopOrganizationId(),
(loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)));
List<TmsReceiptPO> result = tmsReceiptDomainService.queryList(tmsReceiptDO);
log.info("收款单查询 - 查询完成,返回数据条数: {}", result != null ? result.size() : 0);
return result;
}
@@ -351,6 +351,12 @@ public class InvoiceInfoManageApplicationService {
//数据装配
InvoiceInfo invoiceInfo = new InvoiceAssembler().toDo(invoiceInfoDto);
// 设置当前登录用户的组织信息
com.mhd.system.api.model.LoginUser loginUser = com.mhd.common.security.utils.SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
invoiceInfo.setOrganizationId(loginUser.getUserPo().getOrganizationId());
invoiceInfo.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
invoiceInfo.setInvoiceStatus(1);
invoiceInfo.setInvoiceHeader(invoiceInfoManagePo.getInvoiceHeader());
invoiceInfo.setWaybillAmount(new BigDecimal(invoiceInfoDto.getInvoiceOrderIds().length));
@@ -137,6 +137,12 @@ public class RevenueExpensesRecordApplicationService
throw new DigitalLogisticsException(UserError.TIMEOUT);
}
// 设置当前登录用户的组织信息
if (loginUser.getUserPo() != null) {
revenueExpensesRecord.setOrganizationId(loginUser.getUserPo().getOrganizationId());
revenueExpensesRecord.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
//支付通道
if(StringUtils.isNotEmpty(revenueExpensesRecord.getPayChannel())){
List<SysDictDataVo> timeTagEndVos = selectListByDictType(DictCode.pay_channel.getCode());
@@ -151,44 +151,58 @@ public class VerificationApplicationService
* @return 收入核销集合
*/
public List<VerificationPo> selectVerificationList(VerificationPo verificationPo){
List<VerificationPo> list = new ArrayList<>();
List<Long> organizationIdList = new ArrayList<>();
//获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("应付账单查询 - 未获取到登录用户信息,跳过数据权限过滤");
return verificationDomainService.selectVerificationList(verificationPo);
}
UserPo userPo = loginUser.getUserPo();
//当前组织id
Long organizationId = new Long("2");
OrganizationPo organizationPo = loginUser.getOrganizationPo();
if (organizationPo == null){
organizationIdList.add(userPo.getOrganizationId());
}else {
List<Long> organizationIdList1 = organizationPo.getOrganizationIdList();
if (organizationIdList1 != null && organizationIdList1.size() > 0){
organizationIdList.addAll(organizationIdList1);
}else {
organizationIdList.add(organizationPo.getOrganizationId());
// 先保存前端传递的 organizationId如果存在
Long frontendOrganizationId = verificationPo.getOrganizationId();
// 获取当前登录用户的组织信息
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 数据权限根据organizationId来设置查询权限
// topOrganizationId为null时为顶级组织南光组织查所有其他组织查自己
if (topOrganizationId == null) {
// 南光组织可以查询所有组织的数据
// 如果前端传递了 organizationId使用前端传递的值进行过滤
// 如果前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId使用前端传递的值进行过滤
verificationPo.setOrganizationId(frontendOrganizationId);
verificationPo.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
verificationPo.setOrganizationId(null);
verificationPo.setTopOrganizationId(null);
}
} else {
// 其他组织设置organizationId只查询当前组织的数据
// 其他组织只能查询自己组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的 organizationId强制使用当前登录用户的组织ID防止越权查询
verificationPo.setOrganizationId(loginUserOrganizationId);
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致使用前端传递的值
verificationPo.setOrganizationId(frontendOrganizationId);
}
verificationPo.setTopOrganizationId(topOrganizationId);
} else {
// 前端没有传递 organizationId使用当前登录用户的组织ID
verificationPo.setOrganizationId(loginUserOrganizationId);
verificationPo.setTopOrganizationId(topOrganizationId);
}
}
if(loginUser != null){
// if(loginUser.getUserPo() != null && loginUser.getUserPo().getOrganizationId() != null){
// organizationId = loginUser.getUserPo().getOrganizationId();
// AjaxResult info = specialLogisticsServiceFeign.getBranchByOrganizationId(organizationId);
// if("200".equals(String.valueOf(info.get("code")))){
// BranchPo branchPo = JSONObject.parseObject(JSONObject.toJSONString(info.get("data")), BranchPo.class);
// verificationPo.setBranchId(branchPo.getBranchId());
// }
// }
}
if (organizationIdList != null && organizationIdList.size() > 0){
organizationIdList.add(userPo.getOrganizationId());
}
// verificationPo.setOrganizationIdList(organizationIdList);
// verificationPo.setVerificationType(2);
// if (StringUtils.isNotBlank(verificationPo.getWaybillNumbers())){
// verificationPo.setWaybillNumberList(CollectionUtil.toList(verificationPo.getWaybillNumbers().split(",")));
// }
return verificationDomainService.selectOutVerificationList(verificationPo);
// return verificationDomainService.selectVerificationList(verificationPo);
}
/**
@@ -58,6 +58,11 @@ public class InvoiceOrderDomainService
*/
public int insertInvoiceOrder(InvoiceOrder invoiceOrder)
{
// 设置当前登录用户的组织信息
com.mhd.system.api.model.LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
invoiceOrder.setOrganizationId(loginUser.getUserPo().getOrganizationId());
}
invoiceOrder.setCreateTime(new Date());
invoiceOrder.setCreateBy(SecurityUtils.getUserId());
invoiceOrder.setCreateByName(SecurityUtils.getUsername());
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linke.finance.domain.receivingAccount.entity.ReceivingAccount;
import com.linke.finance.domain.receivingAccount.repository.po.ReceivingAccountPO;
import com.linke.finance.domain.receivingAccount.repository.todo.ReceivingAccountDO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@@ -46,6 +47,15 @@ public interface ReceivingAccountMapper extends BaseMapper<ReceivingAccount> {
*/
int deleteAll();
/**
* 根据组织ID删除收款账户删除当前组织的所有收款账户
*
* @param topOrganizationId 一级组织ID
* @param organizationId 组织ID
* @return 影响行数
*/
int deleteByOrganization(@Param("topOrganizationId") String topOrganizationId, @Param("organizationId") String organizationId);
/**
* 根据ID删除收款账户
*
@@ -60,6 +60,17 @@ public class ReceivingAccountRepository {
return receivingAccountMapper.deleteAll();
}
/**
* 根据组织ID删除收款账户删除当前组织的所有收款账户
*
* @param topOrganizationId 一级组织ID
* @param organizationId 组织ID
* @return 影响行数
*/
public int deleteByOrganization(String topOrganizationId, String organizationId) {
return receivingAccountMapper.deleteByOrganization(topOrganizationId, organizationId);
}
/**
* 根据ID删除收款账户
*
@@ -28,7 +28,7 @@ public class TmsReceiptDTO extends BaseVOEntity{
@ApiModelProperty("一级组织ID")
@Excel(name = "一级组织ID")
private Integer topOrganizationId;
private Long topOrganizationId;
@ApiModelProperty("收款单号")
@Excel(name = "收款单号")
@@ -107,22 +107,19 @@ public class TmsReceiptDTO extends BaseVOEntity{
@Excel(name = "是否删除", readConverterExp = "删除标记:0-无状态,1-正常,2-已删除")
private Integer delFlag;
@ApiModelProperty(name = "组织ID集合")
private List<Long> organizationIdList;
// @ApiModelProperty(name = "组织ID集合")
// @Excel(name = "组织ID集合")
// private List<Long> organizationIdList;
//
// @ApiModelProperty(name = "权限菜单ID")
// @Excel(name = "权限菜单ID")
// private Long permissionMenuId;
//
// @ApiModelProperty("组织表id")
// @Excel(name = "组织表id")
// private Long organizationId;
//
// @ApiModelProperty("组织名称")
// @Excel(name = "组织名称")
// private String organizationName;
@ApiModelProperty(name = "权限菜单ID")
private Long permissionMenuId;
@ApiModelProperty("组织表id")
@Excel(name = "组织表id")
private Long organizationId;
@ApiModelProperty("组织名称")
@Excel(name = "组织名称")
private String organizationName;
@ApiModelProperty("挂账原因")
@Excel(name = "挂账原因")
@@ -15,6 +15,8 @@ import com.linke.finance.domain.reconciliation.repository.po.FinacialReconciliat
import com.linke.finance.infrastructure.util.UniqueKeyUtil;
import com.linke.finance.interfaces.dto.InvoiceOrderDto;
import com.mhd.common.core.domain.dto.BusinessDocumentDetaliDTO;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import com.mhd.common.core.domain.dto.EditPaymentMethodDTO;
import com.mhd.common.log.annotation.Log;
import com.mhd.common.log.enums.BusinessType;
@@ -16,6 +16,8 @@ import com.mhd.common.core.utils.IgnoreNullUtil;
import com.mhd.common.core.utils.bean.BeanUtils;
import com.mhd.common.log.annotation.Log;
import com.mhd.common.log.enums.BusinessType;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -56,6 +58,39 @@ public class TmsReceiptApi extends BaseController{
// TmsReceiptDO tmsReceiptDO = tmsReceiptAssembler.toDO(tmsReceiptDTO);
TmsReceiptDO tmsReceiptDO = new TmsReceiptDO();
BeanUtils.copyProperties(tmsReceiptDTO, tmsReceiptDO);
// 获取当前登录用户的组织信息用于SQL中的数据隔离
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginOrgId = loginUser.getUserPo().getOrganizationId();
// 保存前端传入的组织查询条件如果有
Long frontendOrgId = tmsReceiptDO.getOrganizationId();
Long frontendTopOrgId = tmsReceiptDO.getTopOrganizationId();
// 如果当前登录用户的organizationId为2827南光组织可查询全部组织数据其他组织只能查询自己组织的数据
if (loginOrgId == null || !loginOrgId.equals(2827L)) {
// 其他组织只能查询自己组织的数据忽略前端传入的组织查询条件
Long topOrgId = loginUser.getUserPo().getTopOrganizationId();
Long orgId = loginUser.getUserPo().getOrganizationId();
// 强制使用当前登录用户的组织信息确保只能查询自己组织的数据
if (topOrgId != null) {
tmsReceiptDO.setTopOrganizationId(topOrgId);
}
if (orgId != null) {
tmsReceiptDO.setOrganizationId(orgId);
}
// 注意organizationName 条件仍然可以使用但会被 organizationId 条件限制只能查询自己组织的
} else {
// 南光组织organizationId = 2827可以查询全部组织数据
// 如果前端传入了组织查询条件organizationIdtopOrganizationId或organizationName则使用前端条件
// 如果前端没有传入任何组织查询条件则不设置组织ID过滤查询全部但organization_name IS NOT NULL仍会生效
if (frontendOrgId == null && frontendTopOrgId == null && (tmsReceiptDO.getOrganizationName() == null || tmsReceiptDO.getOrganizationName().isEmpty())) {
// 前端没有传入任何组织查询条件清空组织ID过滤查询全部组织数据
tmsReceiptDO.setTopOrganizationId(null);
tmsReceiptDO.setOrganizationId(null);
}
// 如果前端传入了组织查询条件则保留使用前端条件organizationIdtopOrganizationId或organizationName
}
}
startPage();
List<TmsReceiptPO> list = tmsReceiptApplicationService.queryList(tmsReceiptDO);
return getDataTable(list);
@@ -71,6 +106,22 @@ public class TmsReceiptApi extends BaseController{
//转换实体
ReceivingAccountDO receivingAccountDO = new ReceivingAccountDO();
BeanUtils.copyProperties(receivingAccountDTO, receivingAccountDO);
// 获取当前登录用户的组织信息用于数据隔离
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long organizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827南光组织可查询全部组织数据其他组织只能查询自己组织的数据
if (organizationId == null || !organizationId.equals(2827L)) {
Long topOrgId = loginUser.getUserPo().getTopOrganizationId();
Long orgId = loginUser.getUserPo().getOrganizationId();
if (topOrgId != null) {
receivingAccountDO.setTopOrganizationId(String.valueOf(topOrgId));
}
if (orgId != null) {
receivingAccountDO.setOrganizationId(String.valueOf(orgId));
}
}
}
startPage();
List<ReceivingAccountPO> list = receivingAccountApplicationService.queryList(receivingAccountDO);
return getDataTable(list);
@@ -87,6 +138,18 @@ public class TmsReceiptApi extends BaseController{
//转换实体
ReceivingAccountDO receivingAccountDO = new ReceivingAccountDO();
BeanUtils.copyProperties(receivingAccountDTO, receivingAccountDO);
// 获取当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
Long organizationId = loginUser.getUserPo().getOrganizationId();
if (topOrganizationId != null) {
receivingAccountDO.setTopOrganizationId(String.valueOf(topOrganizationId));
}
if (organizationId != null) {
receivingAccountDO.setOrganizationId(String.valueOf(organizationId));
}
}
return toAjax(receivingAccountApplicationService.insert(receivingAccountDO));
}
@@ -98,11 +161,28 @@ public class TmsReceiptApi extends BaseController{
@PostMapping("/batchAddAccount")
public AjaxResult batchAddAccount(@RequestBody List<ReceivingAccountDTO> receivingAccountDTOList)
{
// 获取当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
String topOrganizationId = null;
String organizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
Long topOrgId = loginUser.getUserPo().getTopOrganizationId();
Long orgId = loginUser.getUserPo().getOrganizationId();
if (topOrgId != null) {
topOrganizationId = String.valueOf(topOrgId);
}
if (orgId != null) {
organizationId = String.valueOf(orgId);
}
}
//转换实体
List<ReceivingAccountDO> receivingAccountDOList = new ArrayList<>();
for (ReceivingAccountDTO dto : receivingAccountDTOList) {
ReceivingAccountDO receivingAccountDO = new ReceivingAccountDO();
BeanUtils.copyProperties(dto, receivingAccountDO);
// 设置当前登录用户的组织信息
receivingAccountDO.setTopOrganizationId(topOrganizationId);
receivingAccountDO.setOrganizationId(organizationId);
receivingAccountDOList.add(receivingAccountDO);
}
return toAjax(receivingAccountApplicationService.batchInsert(receivingAccountDOList));
@@ -11,10 +11,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="topOrganizationId" column="top_organization_id" />
<result property="organizationId" column="organization_id" />
</resultMap>
<sql id="selectReceivingAccountPo">
select id, account_name, account_information, del_flag, create_time, update_time
select id, account_name, account_information, del_flag, create_time, update_time, top_organization_id, organization_id
from receiving_account
</sql>
@@ -30,6 +32,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="accountInformation != null and accountInformation != ''">
and account_information like concat('%', #{accountInformation}, '%')
</if>
<if test="topOrganizationId != null and topOrganizationId != ''">
and top_organization_id = #{topOrganizationId}
</if>
<if test="organizationId != null and organizationId != ''">
and organization_id = #{organizationId}
</if>
order by create_time desc
</where>
</sql>
@@ -47,6 +55,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="delFlag != null">del_flag,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="topOrganizationId != null and topOrganizationId != ''">top_organization_id,</if>
<if test="organizationId != null and organizationId != ''">organization_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="accountName != null and accountName != ''">#{accountName},</if>
@@ -54,6 +64,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="delFlag != null">#{delFlag},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="topOrganizationId != null and topOrganizationId != ''">#{topOrganizationId},</if>
<if test="organizationId != null and organizationId != ''">#{organizationId},</if>
</trim>
</insert>
@@ -84,4 +96,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_time = now()
where del_flag = 1
</update>
<update id="deleteByOrganization">
update receiving_account
set del_flag = 2,
update_time = now()
where del_flag = 1
<if test="topOrganizationId != null and topOrganizationId != ''">
and top_organization_id = #{topOrganizationId}
</if>
<if test="organizationId != null and organizationId != ''">
and organization_id = #{organizationId}
</if>
</update>
</mapper>
@@ -31,6 +31,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateByName" column="update_by_name" />
<result property="delFlag" column="del_flag" />
<result property="organizationId" column="organization_id" />
<result property="organizationName" column="organization_name" />
<result property="topOrganizationId" column="top_organization_id" />
<result property="approvalNumber" column="approval_number" />
<result property="isInvoice" column="is_invoice" />
@@ -134,12 +135,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateByName != null and updateByName != ''">
and a.update_by_name like concat('%', #{updateByName}, '%')
</if>
<!-- 组织ID过滤条件:如果设置了organizationId,则按组织ID精确匹配 -->
<if test="organizationId != null ">
and a.organization_id = #{organizationId}
</if>
<!-- 一级组织ID过滤条件:如果设置了topOrganizationId,则按一级组织ID匹配 -->
<if test="topOrganizationId != null ">
and a.top_organization_id = #{topOrganizationId}
</if>
<!-- 组织名称模糊查询条件:如果前端传入了组织名称,则按组织名称模糊匹配 -->
<if test="organizationName != null and organizationName != ''">
and a.organization_name LIKE CONCAT('%',#{organizationName},'%')
</if>
<!-- 当设置了组织相关查询条件时,确保organization_name不为null且不为空字符串 -->
<if test="organizationId != null or topOrganizationId != null or (organizationName != null and organizationName != '')">
and a.organization_name IS NOT NULL
and a.organization_name &lt;&gt; ''
and LENGTH(TRIM(a.organization_name)) > 0
</if>
<if test="collectionTimeStart != null and collectionTimeEnd != null">
AND (date_format(a.collection_time,'%Y-%m-%d') >= date_format(#{collectionTimeStart},'%Y-%m-%d')
and date_format(a.collection_time,'%Y-%m-%d') <![CDATA[<=]]> date_format(#{collectionTimeEnd},'%Y-%m-%d'))
@@ -45,8 +45,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="bankAccount" column="bank_account" />
<result property="oilNumber" column="oil_number" />
<result property="voucherImages" column="voucher_images" />
<result property="payChannel" column="pay_channel" />
<result property="payChannelName" column="pay_channel_name" />
<result property="kingdee" column="kingdee" />
<result property="kingdeeSubjectCode" column="kingdee_subject_code" />
@@ -95,8 +93,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bank_account,
oil_number,
voucher_images,
pay_channel,
pay_channel_name,
kingdee,
kingdee_subject_code,
kingdee_subject_name,
@@ -97,6 +97,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
<if test="accountInformation != null and accountInformation != ''">
and account_information like concat('%', #{accountInformation}, '%')
</if>
<!-- 无论什么情况,organization_name 都不能为空,也不能为空字符串 -->
and organization_name IS NOT NULL
and organization_name &lt;&gt; ''
and LENGTH(TRIM(organization_name)) > 0
<!-- 组织ID过滤条件:如果设置了organizationId,则按组织ID精确匹配 -->
<if test="organizationId != null ">
and organization_id = #{organizationId}
</if>
<!-- 一级组织ID过滤条件:如果设置了topOrganizationId,则按一级组织ID匹配 -->
<if test="topOrganizationId != null ">
and top_organization_id = #{topOrganizationId}
</if>
<!-- 组织名称模糊查询条件:如果前端传入了组织名称,则按组织名称模糊匹配 -->
<if test="organizationName != null and organizationName != ''">
and organization_name LIKE CONCAT('%',#{organizationName},'%')
</if>
order by create_time desc
</where>
@@ -47,61 +47,62 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="delFlag" column="del_flag" />
<result property="organizationId" column="organization_id" />
<result property="topOrganizationId" column="top_organization_id" />
<result property="organizationName" column="organization_name" />
</resultMap>
<sql id="selectVerificationVo">
SELECT
verification_id,
verification_status,
business_document_detali_id,
business_document_detali_number,
business_document_id,
business_document_number,
business_type,
inner_number,
enter_account_time,
expense_item,
first_subject,
first_subject_name,
second_subject,
second_subject_name,
verification_money,
pay_id,
pay_person,
pay_channel,
pay_channel_name,
bank_number,
receipt_number,
pay_remark,
account_holder_name,
account_holder_bank,
bank_account,
images,
audit_remark,
create_time,
create_by,
create_by_name,
update_time,
update_by,
update_by_name,
del_flag,
pay_way,
pay_way_name,
organization_id,
top_organization_id,
receivable_type,
department_id,
department_name,
payee,
pay_type,
license_number,
pay_id,
pay_name,
bill_remarks,
payment_method,
fuel_card_number
v.verification_id,
v.verification_status,
v.business_document_detali_id,
v.business_document_detali_number,
v.business_document_id,
v.business_document_number,
v.business_type,
v.inner_number,
v.enter_account_time,
v.expense_item,
v.first_subject,
v.first_subject_name,
v.second_subject,
v.second_subject_name,
v.verification_money,
v.pay_id,
v.pay_person,
v.pay_channel,
v.pay_channel_name,
v.bank_number,
v.receipt_number,
v.pay_remark,
v.account_holder_name,
v.account_holder_bank,
v.bank_account,
v.images,
v.audit_remark,
v.create_time,
v.create_by,
v.create_by_name,
v.update_time,
v.update_by,
v.update_by_name,
v.del_flag,
v.pay_way,
v.pay_way_name,
v.organization_id,
v.top_organization_id,
v.receivable_type,
v.department_id,
v.department_name,
v.payee,
v.pay_type,
v.license_number,
v.pay_name,
v.bill_remarks,
v.payment_method,
v.fuel_card_number,
v.organization_name
FROM
verification
verification v
</sql>
<select id="selectVerificationOneList" parameterType="com.mhd.common.core.domain.po.VerificationPo" resultMap="VerificationResult">
@@ -343,9 +344,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectVerificationList" parameterType="com.mhd.common.core.domain.po.VerificationPo" resultMap="VerificationResult">
<include refid="selectVerificationVo"/>
<where>
and del_flag = 1
and v.del_flag = 1
<!-- 组织查询条件:南光组织查所有,其他组织查自己 -->
<if test="organizationId != null">
<choose>
<!-- 南光组织判断:如果topOrganizationId为null,则为顶级组织(南光组织),查所有 -->
<when test="topOrganizationId == null">
<!-- 南光组织查所有数据,不添加组织过滤条件 -->
<!-- 如果organizationName为null,根据组织ID查询时不显示organizationName为null的数据 -->
<if test="organizationName == null or organizationName == ''">
AND v.organization_name IS NOT NULL
</if>
</when>
<otherwise>
<!-- 其他组织只查自己组织的数据 -->
AND v.organization_id = #{organizationId}
<!-- organizationName为null时,根据组织ID查询时不显示organizationName为null的数据 -->
<if test="organizationName == null or organizationName == ''">
AND v.organization_name IS NOT NULL
</if>
</otherwise>
</choose>
</if>
<if test="businessDocumentNumberList != null and businessDocumentNumberList.size() != 0">
AND business_document_number in
AND v.business_document_number in
<foreach item="waybill" collection="businessDocumentNumberList" open="(" separator="," close=")">
#{waybill}
</foreach>
@@ -369,55 +391,55 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- )-->
<!-- </if>-->
<if test="enterAccountTimeStart != null">
AND date_format(create_time,'%Y-%m-%d') >= #{enterAccountTimeStart}
AND date_format(v.create_time,'%Y-%m-%d') >= #{enterAccountTimeStart}
</if>
<if test="enterAccountTimeEnd != null">
AND date_format(create_time,'%Y-%m-%d') <![CDATA[<=]]> #{enterAccountTimeEnd}
AND date_format(v.create_time,'%Y-%m-%d') <![CDATA[<=]]> #{enterAccountTimeEnd}
</if>
<if test="cancelAfterVerificationTimeStart != null and cancelAfterVerificationTimeStart != ''">
AND date_format(cancel_after_verification_time,'%Y-%m-%d') >= #{cancelAfterVerificationTimeStart}
AND date_format(v.cancel_after_verification_time,'%Y-%m-%d') >= #{cancelAfterVerificationTimeStart}
</if>
<if test="cancelAfterVerificationTimeEnd != null and cancelAfterVerificationTimeEnd != ''">
AND date_format(cancel_after_verification_time,'%Y-%m-%d') <![CDATA[<=]]> #{cancelAfterVerificationTimeEnd}
AND date_format(v.cancel_after_verification_time,'%Y-%m-%d') <![CDATA[<=]]> #{cancelAfterVerificationTimeEnd}
</if>
<if test="cancelAfterVerificationType != null"> and cancel_after_verification_type = #{cancelAfterVerificationType}</if>
<if test="mailBranch != null"> and mail_branch = #{mailBranch}</if>
<if test="accountHolderBank != null and accountHolderBank != ''"> and account_holder_bank = #{accountHolderBank}</if>
<if test="accountHolderName != null and accountHolderName != ''"> and account_holder_name = #{accountHolderName}</if>
<if test="bankAccount != null and bankAccount != ''"> and bank_account = #{bankAccount}</if>
<if test="arriveBranch != null"> and arrive_branch = #{arriveBranch}</if>
<if test="verificationType != null "> and verification_type = #{verificationType}</if>
<if test="verificationStatusOne != null and verificationStatusOne != '0'.toString()"> and verification_status = #{verificationStatusOne}</if>
<if test="verificationStatus != null and verificationStatus == '5'.toString()"> and verification_status <![CDATA[<=]]> #{verificationStatus}</if>
<if test="verificationStatus != null and verificationStatus == '6'.toString()"> and verification_status = #{verificationStatus}</if>
<if test="innerNumber != null and innerNumber != ''"> and inner_number like concat('%', #{innerNumber}, '%')</if>
<if test="enterAccountTime != null "> and enter_account_time = #{enterAccountTime}</if>
<if test="firstSubject != null and firstSubject != ''"> and first_subject = #{firstSubject}</if>
<if test="secondSubject != null and secondSubject != ''"> and second_subject = #{secondSubject}</if>
<if test="verificationMoney != null "> and verification_money = #{verificationMoney}</if>
<if test="payPerson != null and payPerson != ''"> and pay_person = #{payPerson}</if>
<if test="payChannel != null and payChannel != ''"> and pay_channel = #{payChannel}</if>
<if test="bankNumber != null and bankNumber != ''"> and bank_number = #{bankNumber}</if>
<if test="receiptNumber != null and receiptNumber != ''"> and receipt_number = #{receiptNumber}</if>
<if test="collectionRemark != null and collectionRemark != ''"> and collection_remark = #{collectionRemark}</if>
<if test="waybillId != null "> and waybill_id = #{waybillId}</if>
<if test="waybillNumber != null and waybillNumber != ''"> and waybill_number like concat('%', #{waybillNumber}, '%')</if>
<if test="waybillRemark != null and waybillRemark != ''"> and waybill_remark = #{waybillRemark}</if>
<if test="waybillSource != null and waybillSource != ''"> and waybill_source = #{waybillSource}</if>
<if test="revenueExpensesNumber != null and revenueExpensesNumber != ''"> and revenue_expenses_number = #{revenueExpensesNumber}</if>
<if test="enterAccountId != null "> and enter_account_id = #{enterAccountId}</if>
<if test="enterAccountName != null and enterAccountName != ''"> and enter_account_name like concat('%', #{enterAccountName}, '%')</if>
<if test="cancelAfterVerificationId != null "> and cancel_after_verification_id = #{cancelAfterVerificationId}</if>
<if test="cancelAfterVerificationName != null and cancelAfterVerificationName != ''"> and cancel_after_verification_name like concat('%', #{cancelAfterVerificationName}, '%')</if>
<if test="cancelAfterVerificationTime != null "> and cancel_after_verification_time = #{cancelAfterVerificationTime}</if>
<if test="createByName != null and createByName != ''"> and create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and update_by_name like concat('%', #{updateByName}, '%')</if>
<if test="cancelAfterVerificationStatus != null and cancelAfterVerificationStatus == '5'.toString()"> and verification_status in (1,2,3,4,5)</if>
<if test="cancelAfterVerificationStatus != null and cancelAfterVerificationStatus == '6'.toString()"> and verification_status = 6</if>
<if test="inVerificationStatus != null"> and in_verification_status = #{inVerificationStatus}</if>
<if test="uuidCode != null"> and uuid_code = #{uuidCode}</if>
<if test="cancelAfterVerificationType != null"> and v.cancel_after_verification_type = #{cancelAfterVerificationType}</if>
<if test="mailBranch != null"> and v.mail_branch = #{mailBranch}</if>
<if test="accountHolderBank != null and accountHolderBank != ''"> and v.account_holder_bank = #{accountHolderBank}</if>
<if test="accountHolderName != null and accountHolderName != ''"> and v.account_holder_name = #{accountHolderName}</if>
<if test="bankAccount != null and bankAccount != ''"> and v.bank_account = #{bankAccount}</if>
<if test="arriveBranch != null"> and v.arrive_branch = #{arriveBranch}</if>
<if test="verificationType != null "> and v.verification_type = #{verificationType}</if>
<if test="verificationStatusOne != null and verificationStatusOne != '0'.toString()"> and v.verification_status = #{verificationStatusOne}</if>
<if test="verificationStatus != null and verificationStatus == '5'.toString()"> and v.verification_status <![CDATA[<=]]> #{verificationStatus}</if>
<if test="verificationStatus != null and verificationStatus == '6'.toString()"> and v.verification_status = #{verificationStatus}</if>
<if test="innerNumber != null and innerNumber != ''"> and v.inner_number like concat('%', #{innerNumber}, '%')</if>
<if test="enterAccountTime != null "> and v.enter_account_time = #{enterAccountTime}</if>
<if test="firstSubject != null and firstSubject != ''"> and v.first_subject = #{firstSubject}</if>
<if test="secondSubject != null and secondSubject != ''"> and v.second_subject = #{secondSubject}</if>
<if test="verificationMoney != null "> and v.verification_money = #{verificationMoney}</if>
<if test="payPerson != null and payPerson != ''"> and v.pay_person = #{payPerson}</if>
<if test="payChannel != null and payChannel != ''"> and v.pay_channel = #{payChannel}</if>
<if test="bankNumber != null and bankNumber != ''"> and v.bank_number = #{bankNumber}</if>
<if test="receiptNumber != null and receiptNumber != ''"> and v.receipt_number = #{receiptNumber}</if>
<if test="collectionRemark != null and collectionRemark != ''"> and v.collection_remark = #{collectionRemark}</if>
<if test="waybillId != null "> and v.waybill_id = #{waybillId}</if>
<if test="waybillNumber != null and waybillNumber != ''"> and v.waybill_number like concat('%', #{waybillNumber}, '%')</if>
<if test="waybillRemark != null and waybillRemark != ''"> and v.waybill_remark = #{waybillRemark}</if>
<if test="waybillSource != null and waybillSource != ''"> and v.waybill_source = #{waybillSource}</if>
<if test="revenueExpensesNumber != null and revenueExpensesNumber != ''"> and v.revenue_expenses_number = #{revenueExpensesNumber}</if>
<if test="enterAccountId != null "> and v.enter_account_id = #{enterAccountId}</if>
<if test="enterAccountName != null and enterAccountName != ''"> and v.enter_account_name like concat('%', #{enterAccountName}, '%')</if>
<if test="cancelAfterVerificationId != null "> and v.cancel_after_verification_id = #{cancelAfterVerificationId}</if>
<if test="cancelAfterVerificationName != null and cancelAfterVerificationName != ''"> and v.cancel_after_verification_name like concat('%', #{cancelAfterVerificationName}, '%')</if>
<if test="cancelAfterVerificationTime != null "> and v.cancel_after_verification_time = #{cancelAfterVerificationTime}</if>
<if test="createByName != null and createByName != ''"> and v.create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and v.update_by_name like concat('%', #{updateByName}, '%')</if>
<if test="cancelAfterVerificationStatus != null and cancelAfterVerificationStatus == '5'.toString()"> and v.verification_status in (1,2,3,4,5)</if>
<if test="cancelAfterVerificationStatus != null and cancelAfterVerificationStatus == '6'.toString()"> and v.verification_status = 6</if>
<if test="inVerificationStatus != null"> and v.in_verification_status = #{inVerificationStatus}</if>
<if test="uuidCode != null"> and v.uuid_code = #{uuidCode}</if>
</where>
order by create_time desc
order by v.create_time desc
</select>
<select id="selectVerificationByVerificationId" parameterType="java.lang.Long" resultMap="VerificationResult">
@@ -989,12 +1011,33 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY
a.create_time DESC, a.verification_id DESC
</select>
<select id="selectOutVerificationList" resultType="com.mhd.common.core.domain.po.VerificationPo">
<select id="selectOutVerificationList" parameterType="com.mhd.common.core.domain.po.VerificationPo" resultMap="VerificationResult">
<include refid="selectVerificationVo"/>
<where>
and del_flag = 1
and v.del_flag = 1
<!-- 组织查询条件:南光组织查所有,其他组织查自己 -->
<if test="organizationId != null">
<choose>
<!-- 南光组织判断:如果topOrganizationId为null,则为顶级组织(南光组织),查所有 -->
<when test="topOrganizationId == null">
<!-- 南光组织查所有数据,不添加组织过滤条件 -->
<!-- 如果organizationName为null,根据组织ID查询时不显示organizationName为null的数据 -->
<if test="organizationName == null or organizationName == ''">
AND v.organization_name IS NOT NULL
</if>
</when>
<otherwise>
<!-- 其他组织只查自己组织的数据 -->
AND v.organization_id = #{organizationId}
<!-- organizationName为null时,根据组织ID查询时不显示organizationName为null的数据 -->
<if test="organizationName == null or organizationName == ''">
AND v.organization_name IS NOT NULL
</if>
</otherwise>
</choose>
</if>
<if test="businessDocumentNumberList != null and businessDocumentNumberList.size() != 0">
AND business_document_number in
AND v.business_document_number in
<foreach item="waybill" collection="businessDocumentNumberList" open="(" separator="," close=")">
#{waybill}
</foreach>
@@ -1018,50 +1061,50 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- )-->
<!-- </if>-->
<if test="enterAccountTimeStart != null">
AND date_format(create_time,'%Y-%m-%d') >= #{enterAccountTimeStart}
AND date_format(v.create_time,'%Y-%m-%d') >= #{enterAccountTimeStart}
</if>
<if test="enterAccountTimeEnd != null">
AND date_format(create_time,'%Y-%m-%d') <![CDATA[<=]]> #{enterAccountTimeEnd}
AND date_format(v.create_time,'%Y-%m-%d') <![CDATA[<=]]> #{enterAccountTimeEnd}
</if>
<if test="paymentMethod != null ">
and payment_method = #{paymentMethod}
and v.payment_method = #{paymentMethod}
</if>
<if test="cancelAfterVerificationTimeStart != null and cancelAfterVerificationTimeStart != ''">
AND date_format(cancel_after_verification_time,'%Y-%m-%d') >= #{cancelAfterVerificationTimeStart}
AND date_format(v.cancel_after_verification_time,'%Y-%m-%d') >= #{cancelAfterVerificationTimeStart}
</if>
<if test="cancelAfterVerificationTimeEnd != null and cancelAfterVerificationTimeEnd != ''">
AND date_format(cancel_after_verification_time,'%Y-%m-%d') <![CDATA[<=]]> #{cancelAfterVerificationTimeEnd}
AND date_format(v.cancel_after_verification_time,'%Y-%m-%d') <![CDATA[<=]]> #{cancelAfterVerificationTimeEnd}
</if>
<!-- <if test="cancelAfterVerificationType != null"> and cancel_after_verification_type = #{cancelAfterVerificationType}</if>-->
<!-- <if test="mailBranch != null"> and mail_branch = #{mailBranch}</if>-->
<if test="accountHolderBank != null and accountHolderBank != ''"> and account_holder_bank = #{accountHolderBank}</if>
<if test="businessDocumentDetaliNumber != null and businessDocumentDetaliNumber != ''"> and business_document_detali_number like concat('%', #{businessDocumentDetaliNumber}, '%')</if>
<if test="accountHolderName != null and accountHolderName != ''"> and account_holder_name = #{accountHolderName}</if>
<if test="bankAccount != null and bankAccount != ''"> and bank_account = #{bankAccount}</if>
<if test="accountHolderBank != null and accountHolderBank != ''"> and v.account_holder_bank = #{accountHolderBank}</if>
<if test="businessDocumentDetaliNumber != null and businessDocumentDetaliNumber != ''"> and v.business_document_detali_number like concat('%', #{businessDocumentDetaliNumber}, '%')</if>
<if test="accountHolderName != null and accountHolderName != ''"> and v.account_holder_name = #{accountHolderName}</if>
<if test="bankAccount != null and bankAccount != ''"> and v.bank_account = #{bankAccount}</if>
<!-- <if test="arriveBranch != null"> and arrive_branch = #{arriveBranch}</if>-->
<!-- <if test="verificationType != null "> and verification_type = #{verificationType}</if>-->
<!-- <if test="verificationStatusOne != null and verificationStatusOne != '0'.toString()"> and verification_status = #{verificationStatusOne}</if>-->
<!-- <if test="verificationStatus != null and verificationStatus == '5'.toString()"> and verification_status <![CDATA[<=]]> #{verificationStatus}</if>-->
<if test="verificationStatus != null "> and verification_status = #{verificationStatus}</if>
<if test="businessType != null "> and business_type = #{businessType}</if>
<if test="innerNumber != null and innerNumber != ''"> and inner_number like concat('%', #{innerNumber}, '%')</if>
<if test="businessDocumentNumber != null and businessDocumentNumber != ''"> and business_document_number = #{businessDocumentNumber} </if>
<if test="expenseItem != null and expenseItem != ''"> and expense_item = #{expenseItem} </if>
<if test="enterAccountTime != null "> and enter_account_time = #{enterAccountTime}</if>
<if test="firstSubject != null and firstSubject != ''"> and first_subject = #{firstSubject}</if>
<if test="secondSubject != null and secondSubject != ''"> and second_subject = #{secondSubject}</if>
<if test="payType != null and payType != ''"> and pay_type = #{payType}</if>
<if test="payee != null and payee != ''"> and payee like concat('%', #{payee}, '%')</if>
<if test="payName != null and payName != ''"> and pay_name like concat('%', #{payName}, '%')</if>
<if test="licenseNumber != null and licenseNumber != ''"> and license_number like concat('%', #{licenseNumber}, '%')</if>
<if test="departmentName != null and departmentName != ''"> and department_name like concat('%', #{departmentName}, '%')</if>
<if test="verificationMoney != null "> and verification_money = #{verificationMoney}</if>
<if test="payPerson != null and payPerson != ''"> and pay_person = #{payPerson}</if>
<if test="payChannel != null and payChannel != ''"> and pay_channel = #{payChannel}</if>
<if test="bankNumber != null and bankNumber != ''"> and bank_number = #{bankNumber}</if>
<if test="receiptNumber != null and receiptNumber != ''"> and receipt_number = #{receiptNumber}</if>
<if test="verificationStatus != null "> and v.verification_status = #{verificationStatus}</if>
<if test="businessType != null "> and v.business_type = #{businessType}</if>
<if test="innerNumber != null and innerNumber != ''"> and v.inner_number like concat('%', #{innerNumber}, '%')</if>
<if test="businessDocumentNumber != null and businessDocumentNumber != ''"> and v.business_document_number = #{businessDocumentNumber} </if>
<if test="expenseItem != null and expenseItem != ''"> and v.expense_item = #{expenseItem} </if>
<if test="enterAccountTime != null "> and v.enter_account_time = #{enterAccountTime}</if>
<if test="firstSubject != null and firstSubject != ''"> and v.first_subject = #{firstSubject}</if>
<if test="secondSubject != null and secondSubject != ''"> and v.second_subject = #{secondSubject}</if>
<if test="payType != null and payType != ''"> and v.pay_type = #{payType}</if>
<if test="payee != null and payee != ''"> and v.payee like concat('%', #{payee}, '%')</if>
<if test="payName != null and payName != ''"> and v.pay_name like concat('%', #{payName}, '%')</if>
<if test="licenseNumber != null and licenseNumber != ''"> and v.license_number like concat('%', #{licenseNumber}, '%')</if>
<if test="departmentName != null and departmentName != ''"> and v.department_name like concat('%', #{departmentName}, '%')</if>
<if test="verificationMoney != null "> and v.verification_money = #{verificationMoney}</if>
<if test="payPerson != null and payPerson != ''"> and v.pay_person = #{payPerson}</if>
<if test="payChannel != null and payChannel != ''"> and v.pay_channel = #{payChannel}</if>
<if test="bankNumber != null and bankNumber != ''"> and v.bank_number = #{bankNumber}</if>
<if test="receiptNumber != null and receiptNumber != ''"> and v.receipt_number = #{receiptNumber}</if>
<!-- <if test="collectionRemark != null and collectionRemark != ''"> and collection_remark = #{collectionRemark}</if>-->
<!-- <if test="waybillId != null "> and waybill_id = #{waybillId}</if>-->
<!-- <if test="waybillNumber != null and waybillNumber != ''"> and waybill_number like concat('%', #{waybillNumber}, '%')</if>-->
@@ -1073,12 +1116,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- <if test="cancelAfterVerificationId != null "> and cancel_after_verification_id = #{cancelAfterVerificationId}</if>-->
<!-- <if test="cancelAfterVerificationName != null and cancelAfterVerificationName != ''"> and cancel_after_verification_name like concat('%', #{cancelAfterVerificationName}, '%')</if>-->
<!-- <if test="cancelAfterVerificationTime != null "> and cancel_after_verification_time = #{cancelAfterVerificationTime}</if>-->
<if test="createByName != null and createByName != ''"> and create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and update_by_name like concat('%', #{updateByName}, '%')</if>
<if test="createByName != null and createByName != ''"> and v.create_by_name like concat('%', #{createByName}, '%')</if>
<if test="updateByName != null and updateByName != ''"> and v.update_by_name like concat('%', #{updateByName}, '%')</if>
<!-- <if test="cancelAfterVerificationStatus != null and cancelAfterVerificationStatus == '5'.toString()"> and verification_status in (1,2,3,4,5)</if>-->
<!-- <if test="cancelAfterVerificationStatus != null and cancelAfterVerificationStatus == '6'.toString()"> and verification_status = 6</if>-->
</where>
order by create_time desc
order by v.create_time desc
</select>
@@ -303,8 +303,9 @@ public class MenuApplicationService {
Long tenantsId = organizationPo1.getTenantsId();
OrganizationPo organizationPo = iOrganizationSvc.selectOrganizationById(organizationId);
List<MenuVo> menuVos = new ArrayList<>();
//一级组织
if(organizationPo.getParentOrganizationId() == 0){
//一级组织organizationState == 1 表示是一级组织或者 topOrganizationId == null/0
if(organizationPo.getOrganizationState() != null && organizationPo.getOrganizationState() == 1
|| (organizationPo.getTopOrganizationId() == null || organizationPo.getTopOrganizationId() == 0)){
menuVos = menuDomainService.selectMenuIdListByTenantsId(organizationPo.getTenantsId(), 1);
}else {
menuVos = menuDomainService.selectMenuIdListByOrganizationId(organizationId);
@@ -100,6 +100,9 @@ public class OrganizationApplicationService {
* @return 组织列表信息
*/
public List<OrganizationPo> selectOrganizationList(OrganizationPo organizationPo, DataPermission dataPermission) {
// 添加组织数据权限过滤
applyOrganizationDataPermission(organizationPo);
if(dataPermission != null){
if(dataPermission.getOrganizationIdList() != null && dataPermission.getOrganizationIdList().size() > 0){
organizationPo.setOrganizationIdList(dataPermission.getOrganizationIdList());
@@ -457,7 +460,7 @@ public class OrganizationApplicationService {
if(parentOrganizationId != null && parentOrganizationId != 0L && CollectionUtil.isNotEmpty(menuIdList)){
//获取父级组织信息一级组织拥有自己的菜单非一级组织只拥有菜单权限
OrganizationPo organizationPo = iOrganizationSvc.selectOrganizationById(parentOrganizationId);
if(organizationPo.getParentOrganizationId() == 0L){
if(organizationPo.getTopOrganizationId() == 0L){
//获取一级组织对应的所有菜单
List<Long> allByTenantsId = menuDomainService.getMenuIdByTenantsId(organizationPo.getTenantsId(),null);
if (CollectionUtil.isNotEmpty(allByTenantsId)){
@@ -634,4 +637,51 @@ public class OrganizationApplicationService {
}
return list;
}
/**
* 应用组织数据权限过滤
*/
private void applyOrganizationDataPermission(OrganizationPo organizationPo) {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
// 先保存前端传递的 organizationId如果存在
Long frontendOrganizationId = organizationPo.getOrganizationId();
// 数据权限根据organizationId来设置查询权限
// organizationId等于2827时查询全部其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
// 如果前端传递了 organizationId使用前端传递的值进行过滤
// 如果前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
if (frontendOrganizationId != null) {
organizationPo.setOrganizationId(frontendOrganizationId);
organizationPo.setTopOrganizationId(null);
} else {
organizationPo.setOrganizationId(null);
organizationPo.setTopOrganizationId(null);
}
} else {
// 其他组织设置organizationId只查询当前组织的数据
if (frontendOrganizationId != null && !frontendOrganizationId.equals(loginUserOrganizationId)) {
// 前端传递了其他组织的organizationId强制使用当前登录用户的组织ID防止越权查询
log.warn("组织列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
organizationPo.setOrganizationId(loginUserOrganizationId);
} else if (frontendOrganizationId == null) {
organizationPo.setOrganizationId(loginUserOrganizationId);
}
if (topOrganizationId != null) {
organizationPo.setTopOrganizationId(topOrganizationId);
}
}
}
} catch (Exception e) {
log.warn("应用组织数据权限过滤失败,将不进行组织过滤: {}", e.getMessage());
// 如果获取登录用户信息失败不添加过滤条件避免影响正常查询
}
}
}
@@ -21,6 +21,8 @@ public class OrganizationPo extends BaseVOEntity implements Serializable {
private Long organizationId;
@ApiModelProperty(name = "上级组织表ID")
private Long parentOrganizationId;
@ApiModelProperty(name = "一级组织表ID")
private Long topOrganizationId;
@ApiModelProperty(name = "组织名称")
private String organizationName;
@ApiModelProperty(name = "员工数量")
@@ -139,6 +139,20 @@ public class VehicleApplicationService {
*/
@NeedSetValueMethod
public List<VehiclePo> selectVehicleList(VehiclePo vehiclePo, DataPermission dataPermission) {
// 获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("车辆列表查询 - 未获取到登录用户信息,跳过数据权限过滤");
return vehicleDomainService.selectVehicleList(vehiclePo);
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
// 先保存前端传递的 organizationId如果存在
Long frontendOrganizationId = vehiclePo.getOrganizationId();
if (dataPermission != null) {
if (CollUtil.isNotEmpty(dataPermission.getOrganizationIdList())) {
vehiclePo.setOrganizationIdList(dataPermission.getOrganizationIdList());
@@ -147,13 +161,52 @@ public class VehicleApplicationService {
vehiclePo.setCreateBy(dataPermission.getCreateBy());
}
}
//获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser.getUserPo().getBusinessType() == 2) {
vehiclePo.setCreateBy(loginUser.getUserPo().getUserId());
vehiclePo.setOrganizationId(null);
vehiclePo.setOrganizationIdList(null);
// businessType == 2 司机设置创建人过滤
if (userPo.getBusinessType() == 2) {
vehiclePo.setCreateBy(userPo.getUserId());
}
// 数据权限根据 organizationId 来设置查询权限
// 当前登录用户的 organizationId 2827 可查全部组织数据其他组织只能查自己
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
// 如果前端传递了 organizationId使用前端传递的值进行过滤
// 如果前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
if (frontendOrganizationId != null) {
vehiclePo.setOrganizationId(frontendOrganizationId);
vehiclePo.setTopOrganizationId(null);
vehiclePo.setOrganizationIdList(null);
} else {
vehiclePo.setOrganizationId(null);
vehiclePo.setTopOrganizationId(null);
vehiclePo.setOrganizationIdList(null);
}
} else {
// 其他组织设置 organizationId只查询当前组织的数据
if (frontendOrganizationId != null) {
// 前端传递了 organizationId验证是否与当前登录用户的组织ID一致
if (!frontendOrganizationId.equals(loginUserOrganizationId)) {
log.warn("车辆列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
vehiclePo.setOrganizationId(loginUserOrganizationId);
} else {
vehiclePo.setOrganizationId(frontendOrganizationId);
}
vehiclePo.setTopOrganizationId(topOrganizationId);
if (loginUserOrganizationId != null) {
vehiclePo.setOrganizationIdList(Collections.singletonList(loginUserOrganizationId));
}
} else {
// 前端没有传递 organizationId使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
vehiclePo.setOrganizationId(loginUserOrganizationId);
vehiclePo.setOrganizationIdList(Collections.singletonList(loginUserOrganizationId));
}
vehiclePo.setTopOrganizationId(topOrganizationId);
}
}
//查询所有已经被绑定的车辆
// try {
// R<List<Long>> vehicleIdList = userServiceFeign.getBindListByUserId(loginUser.getUserPo().getUserId());
@@ -193,6 +246,18 @@ public class VehicleApplicationService {
*/
@NeedSetValueMethod
public List<VehiclePo> getUnBindList(VehiclePo vehiclePo, DataPermission dataPermission) {
// 获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("未绑定车辆列表查询 - 未获取到登录用户信息,跳过数据权限过滤");
return vehicleDomainService.selectVehicleList(vehiclePo);
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
Long frontendOrganizationId = vehiclePo.getOrganizationId();
if (dataPermission != null) {
if (CollUtil.isNotEmpty(dataPermission.getOrganizationIdList())) {
vehiclePo.setOrganizationIdList(dataPermission.getOrganizationIdList());
@@ -201,12 +266,35 @@ public class VehicleApplicationService {
vehiclePo.setCreateBy(dataPermission.getCreateBy());
}
}
//获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser.getUserPo().getBusinessType() == 2) {
vehiclePo.setCreateBy(loginUser.getUserPo().getUserId());
vehiclePo.setOrganizationId(null);
// businessType == 2 司机设置创建人过滤
if (userPo.getBusinessType() == 2) {
vehiclePo.setCreateBy(userPo.getUserId());
}
// 数据权限根据 organizationId 来设置查询权限
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
if (frontendOrganizationId != null) {
vehiclePo.setOrganizationId(frontendOrganizationId);
} else {
vehiclePo.setOrganizationId(null);
}
vehiclePo.setTopOrganizationId(null);
vehiclePo.setOrganizationIdList(null);
} else {
// 其他组织只查询当前组织的数据
if (frontendOrganizationId != null && !frontendOrganizationId.equals(loginUserOrganizationId)) {
log.warn("未绑定车辆列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
vehiclePo.setOrganizationId(loginUserOrganizationId);
} else if (frontendOrganizationId == null) {
vehiclePo.setOrganizationId(loginUserOrganizationId);
}
vehiclePo.setTopOrganizationId(topOrganizationId);
if (loginUserOrganizationId != null) {
vehiclePo.setOrganizationIdList(Collections.singletonList(loginUserOrganizationId));
}
}
//查询所有已经被绑定的车辆
try {
@@ -247,12 +335,49 @@ public class VehicleApplicationService {
*/
@NeedSetValueMethod
public List<VehiclePo> selectBindVehicleList(VehiclePo vehiclePo, DataPermission dataPermission) {
// 获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("绑定车辆列表查询 - 未获取到登录用户信息,跳过数据权限过滤");
return vehicleDomainService.selectVehicleList(vehiclePo);
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
Long frontendOrganizationId = vehiclePo.getOrganizationId();
if (dataPermission != null) {
if (dataPermission.getOrganizationIdList() != null
&& dataPermission.getOrganizationIdList().size() > 0) {
vehiclePo.setOrganizationIdList(dataPermission.getOrganizationIdList());
}
}
// 数据权限根据 organizationId 来设置查询权限
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
if (frontendOrganizationId != null) {
vehiclePo.setOrganizationId(frontendOrganizationId);
} else {
vehiclePo.setOrganizationId(null);
}
vehiclePo.setTopOrganizationId(null);
vehiclePo.setOrganizationIdList(null);
} else {
// 其他组织只查询当前组织的数据
if (frontendOrganizationId != null && !frontendOrganizationId.equals(loginUserOrganizationId)) {
log.warn("绑定车辆列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
vehiclePo.setOrganizationId(loginUserOrganizationId);
} else if (frontendOrganizationId == null) {
vehiclePo.setOrganizationId(loginUserOrganizationId);
}
vehiclePo.setTopOrganizationId(topOrganizationId);
if (loginUserOrganizationId != null) {
vehiclePo.setOrganizationIdList(Collections.singletonList(loginUserOrganizationId));
}
}
List<VehiclePo> vehiclePos = vehicleDomainService.selectVehicleList(vehiclePo);
for (VehiclePo po : vehiclePos) {
Map<String, String> map = userServiceFeign.selectUserBindByVehicleId(po.getVehicleId());
@@ -269,24 +394,43 @@ public class VehicleApplicationService {
*/
@NeedSetValueMethod
public List<VehiclePo> selectStowageVehiclelist(VehiclePo vehiclePo) {
// if(dataPermission != null){
// if(dataPermission.getOrganizationIdList() != null && dataPermission.getOrganizationIdList().size() > 0){
// vehiclePo.setOrganizationIdList(dataPermission.getOrganizationIdList());
// }
// if(dataPermission.getCreateBy() != null){
// vehiclePo.setCreateBy(dataPermission.getCreateBy());
// }
// }
//获取登录人信息
// 获取登录人信息
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser == null || loginUser.getUserPo() == null) {
log.warn("配载车辆列表查询 - 未获取到登录用户信息,跳过数据权限过滤");
return vehicleDomainService.selectStowageVehiclelist(vehiclePo);
}
UserPo userPo = loginUser.getUserPo();
Long loginUserOrganizationId = userPo.getOrganizationId();
Long topOrganizationId = userPo.getTopOrganizationId();
Long frontendOrganizationId = vehiclePo.getOrganizationId();
if (ObjectUtil.equals(userPo.getUserAccountType(), 3)) {
vehiclePo.setUserAccountType(3);
vehiclePo.setTopOrganizationId(userPo.getTopOrganizationId());
} else {
vehiclePo.setTopOrganizationId(userPo.getTopOrganizationId());
vehiclePo.setOrganizationId(userPo.getOrganizationId());
}
// 数据权限根据 organizationId 来设置查询权限
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
if (frontendOrganizationId != null) {
vehiclePo.setOrganizationId(frontendOrganizationId);
} else {
vehiclePo.setOrganizationId(null);
}
vehiclePo.setTopOrganizationId(null);
} else {
// 其他组织只查询当前组织的数据
if (frontendOrganizationId != null && !frontendOrganizationId.equals(loginUserOrganizationId)) {
log.warn("配载车辆列表查询 - 前端传递的组织ID {} 与当前登录用户的组织ID {} 不一致,使用当前登录用户的组织ID进行过滤",
frontendOrganizationId, loginUserOrganizationId);
vehiclePo.setOrganizationId(loginUserOrganizationId);
} else if (frontendOrganizationId == null) {
vehiclePo.setOrganizationId(loginUserOrganizationId);
}
vehiclePo.setTopOrganizationId(topOrganizationId);
}
return vehicleDomainService.selectStowageVehiclelist(vehiclePo);
}
@@ -585,8 +729,18 @@ public class VehicleApplicationService {
if (currentVehiclePo != null) {
Vehicle vehicleForWlhy = new Vehicle(); // 使用领域对象
BeanUtils.copyProperties(currentVehiclePo, vehicleForWlhy);
vehicleWlhyDomainService.addVehicleInfo(vehicleForWlhy, 1); // 2 代表某种类型或状态
vehiclePendingReviewPush(loginUser);
vehicleForWlhy.setUserId(currentVehiclePo.getUserId());
try {
vehicleWlhyDomainService.addVehicleInfo(vehicleForWlhy, 1); // 1 代表绑定类型
vehiclePendingReviewPush(loginUser);
} catch (ServiceException e) {
// 同步网货失败时记录日志但不影响车辆保存
// 第一次新增时用户信息可能还未同步到网货系统导致失败
// 第二次新增时用户信息已存在可以成功同步
log.warn("同步网货信息失败,但不影响车辆保存: {}", e.getMessage());
// 如果业务要求必须同步成功可以取消下面的注释让异常抛出
// throw e;
}
} else {
log.warn("未能找到刚保存的车辆信息用于同步网货,VehicleId: {}", vehicle.getVehicleId());
}
@@ -607,11 +761,18 @@ public class VehicleApplicationService {
LoginUser loginUser = SecurityUtils.getLoginUser();
//当前组织id
Long organizationId = 0L;
Long topOrganizationId = 0L;
String organizationName = "";
if (loginUser != null) {
if (loginUser.getUserPo() != null && loginUser.getUserPo().getOrganizationId() != null) {
organizationId = loginUser.getUserPo().getOrganizationId();
organizationName = loginUser.getUserPo().getOrganizationName();
UserPo userPo = loginUser.getUserPo();
if (userPo != null) {
if (userPo.getOrganizationId() != null) {
organizationId = userPo.getOrganizationId();
organizationName = userPo.getOrganizationName();
}
if (userPo.getTopOrganizationId() != null) {
topOrganizationId = userPo.getTopOrganizationId();
}
}
}
UserConfigSwitchPo userConfigSwitchPo = commonApplicationService.getUserConfigSwitch();
@@ -660,8 +821,10 @@ public class VehicleApplicationService {
}
}
// 设置当前登录用户的组织信息
vehicle.setOrganizationId(organizationId);
vehicle.setOrganizationName(organizationName);
vehicle.setTopOrganizationId(topOrganizationId);
VehiclePo oldVehiclePo = null;
if (ObjectUtil.isNotNull(vehicle.getVehicleId())) {
@@ -830,12 +993,8 @@ public class VehicleApplicationService {
// }
// 6. 持久化操作 (统一的 insert update)
// 注意组织信息已在前面设置第670-673行这里不需要重复设置
if (ObjectUtil.isNull(vehicle.getVehicleId())) { // 新增
if (loginUser != null) {
vehicle.setOrganizationId(loginUser.getUserPo().getOrganizationId());
vehicle.setOrganizationName(loginUser.getUserPo().getOrganizationName());
vehicle.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
vehicleDomainService.insertVehicle(vehicle);
} else {
// 确保 vehicleId 是从 DTO 传递过来的并且 oldVehiclePo 已被正确加载
@@ -875,8 +1034,17 @@ public class VehicleApplicationService {
Vehicle vehicleForWlhy = new Vehicle(); // 使用领域对象
BeanUtils.copyProperties(currentVehiclePo, vehicleForWlhy);
vehicleForWlhy.setUserId(currentVehiclePo.getUserId());
vehicleWlhyDomainService.addVehicleInfo(vehicleForWlhy, 1); // 2 代表某种类型或状态
vehiclePendingReviewPush(loginUser);
try {
vehicleWlhyDomainService.addVehicleInfo(vehicleForWlhy, 1); // 1 代表绑定类型
vehiclePendingReviewPush(loginUser);
} catch (ServiceException e) {
// 同步网货失败时记录日志但不影响车辆保存
// 第一次新增时用户信息可能还未同步到网货系统导致失败
// 第二次新增时用户信息已存在可以成功同步
log.warn("同步网货信息失败,但不影响车辆保存: {}", e.getMessage());
// 如果业务要求必须同步成功可以取消下面的注释让异常抛出
// throw e;
}
} else {
log.warn("未能找到刚保存的车辆信息用于同步网货,VehicleId: {}", vehicle.getVehicleId());
}
@@ -22,6 +22,7 @@ import com.linke.transport.interfaces.dto.warehouse.inBoundOrder.InboundOrderDTO
import com.linke.transport.interfaces.dto.warehouse.inBoundOrder.InboundOrderDTO.Create;
import com.mhd.common.core.utils.OrderSequence;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
@@ -292,7 +293,7 @@ public class InboundOrderService extends ServiceImpl<InboundOrderMapper, Inbound
* 构建查询条件函数式封装
*/
private LambdaQueryWrapper<InboundOrder> buildQueryWrapper(InboundOrderDTO.Query queryDTO) {
return new LambdaQueryWrapper<InboundOrder>()
LambdaQueryWrapper<InboundOrder> wrapper = new LambdaQueryWrapper<InboundOrder>()
.like(StringUtils.hasText(queryDTO.getInboundOrderNo()),
InboundOrder::getInboundOrderNo, queryDTO.getInboundOrderNo())
.eq(Objects.nonNull(queryDTO.getOwnerId()),
@@ -304,8 +305,44 @@ public class InboundOrderService extends ServiceImpl<InboundOrderMapper, Inbound
.ge(Objects.nonNull(queryDTO.getInboundTimeStart()),
InboundOrder::getInboundTime,queryDTO.getInboundTimeStart())
.lt(Objects.nonNull(queryDTO.getInboundTimeEnd()),
InboundOrder::getInboundTime,queryDTO.getInboundTimeEnd())
.orderByDesc(InboundOrder::getInboundTime);
InboundOrder::getInboundTime,queryDTO.getInboundTimeEnd());
// 添加组织数据权限过滤
applyOrganizationDataPermission(wrapper);
return wrapper.orderByDesc(InboundOrder::getInboundTime);
}
/**
* 应用组织数据权限过滤
* 通过关联Material表来过滤组织数据
*/
private void applyOrganizationDataPermission(LambdaQueryWrapper<InboundOrder> wrapper) {
try {
com.mhd.system.api.model.LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827南光组织可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织需要通过Material关联来过滤
// 由于InboundOrder没有直接的组织字段需要通过明细关联Material来过滤
// 使用EXISTS子查询只查询包含当前组织物料的入库单
wrapper.exists(String.format(
"SELECT 1 FROM inbound_order_detail iod " +
"INNER JOIN material m ON iod.material_id = m.id AND m.is_deleted = 0 " +
"WHERE iod.inbound_order_id = inbound_order.id " +
"AND iod.is_deleted = 0 " +
"AND m.organization_id = '%s'",
loginUserOrganizationId));
}
// 如果是2827组织不添加过滤条件可以查询全部
}
} catch (Exception e) {
log.warn("应用组织数据权限过滤失败,将不进行组织过滤: {}", e.getMessage());
// 如果获取登录用户信息失败不添加过滤条件避免影响正常查询
}
}
/**
@@ -14,6 +14,7 @@ import com.linke.transport.domain.warehouse.material.repository.MaterialReposito
import com.linke.transport.infrastructure.warehouse.inventory.persistence.InventoryMapper;
import com.linke.transport.interfaces.dto.warehouse.inventory.InventoryDTO;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import java.math.BigDecimal;
import java.util.List;
import java.util.NoSuchElementException;
@@ -50,12 +51,63 @@ public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> {
// 1. 创建分页请求对象 (注意泛型是 VO)
Page<InventoryVO> page = new Page<>(queryDTO.getPageNo(), queryDTO.getPageSize());
// 2. 调用 Mapper 的自定义分页查询方法 (该方法执行 JOIN)
// 2. 应用组织数据权限过滤在XML中通过Material表的organizationId过滤
applyOrganizationDataPermission(queryDTO);
// 3. 调用 Mapper 的自定义分页查询方法 (该方法执行 JOIN)
return inventoryMapper.findInventoryList(page, queryDTO);
}
/**
* 应用组织数据权限过滤
* 设置organizationId到queryDTO中供XML使用
*/
private void applyOrganizationDataPermission(InventoryDTO.Query queryDTO) {
try {
com.mhd.system.api.model.LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827南光组织可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 设置organizationId到queryDTO中供XML使用
// 注意需要在InventoryDTO.Query中添加organizationId字段
// 由于Material的organizationId是String类型需要转换为String
if (queryDTO.getOrganizationId() == null) {
queryDTO.setOrganizationId(String.valueOf(loginUserOrganizationId));
}
}
// 如果是2827组织不设置organizationId可以查询全部
}
} catch (Exception e) {
log.warn("应用组织数据权限过滤失败,将不进行组织过滤: {}", e.getMessage());
}
}
public List<InventoryVO> listAllInventory(Long ownerId,String machineSerialNo) {
return inventoryMapper.findAllInventoryList(ownerId,machineSerialNo);
// 应用组织数据权限过滤
String organizationId = getOrganizationIdForFilter();
return inventoryMapper.findAllInventoryList(ownerId, machineSerialNo, organizationId);
}
/**
* 获取用于过滤的组织IDString类型因为Material表的organizationId是String
* @return 如果不是2827组织返回组织ID字符串如果是2827返回null可查全部
*/
private String getOrganizationIdForFilter() {
try {
LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
return String.valueOf(loginUserOrganizationId);
}
}
} catch (Exception e) {
log.warn("获取组织ID失败: {}", e.getMessage());
}
return null; // 2827组织或获取失败时返回null可查全部
}
/**
@@ -51,8 +51,12 @@ public class InventoryLedgerService extends ServiceImpl<InventoryLedgerMapper, I
.ge(Objects.nonNull(query.getEventTimeStart()),
InventoryLedger::getEventTime,query.getEventTimeStart())
.lt(Objects.nonNull(query.getEventTimeEnd()),
InventoryLedger::getEventTime,query.getEventTimeEnd())
.orderByDesc(InventoryLedger :: getId);
InventoryLedger::getEventTime,query.getEventTimeEnd());
// 添加组织数据权限过滤
applyOrganizationDataPermission(wrapper);
wrapper.orderByDesc(InventoryLedger :: getId);
return this.page(new Page<>(query.getPageNo(), query.getPageSize()), wrapper)
.convert(item -> {
@@ -62,6 +66,34 @@ public class InventoryLedgerService extends ServiceImpl<InventoryLedgerMapper, I
});
}
/**
* 应用组织数据权限过滤
* 通过关联Material表来过滤组织数据
*/
private void applyOrganizationDataPermission(LambdaQueryWrapper<InventoryLedger> wrapper) {
try {
com.mhd.system.api.model.LoginUser loginUser = com.mhd.common.security.utils.SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827南光组织可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织需要通过Material关联来过滤
// 由于InventoryLedger表中有materialId字段我们通过EXISTS子查询关联Material来过滤
wrapper.exists(String.format(
"SELECT 1 FROM material m " +
"WHERE m.id = inventory_ledger.material_id " +
"AND m.organization_id = '%s' AND m.is_deleted = 0",
loginUserOrganizationId));
}
// 如果是2827组织不添加过滤条件可以查询全部
}
} catch (Exception e) {
// 如果获取登录用户信息失败不添加过滤条件避免影响正常查询
}
}
/**
* 根据货主ID更新货主名称
* @param ownerId 货主ID
@@ -58,4 +58,6 @@ public class CreateMaterialCommand {
private String topOrganizationId;
/**组织相关*/
private String organizationId;
/**组织相关*/
private String organizationName;
}
@@ -38,7 +38,7 @@ public class MaterialCommandService {
command.getWeight(),
command.getMaterialVolume(),
command.getMaterialContent(),
command.getRemark(),command.getTopOrganizationId(),command.getOrganizationId(),
command.getRemark(),command.getTopOrganizationId(),command.getOrganizationId(),command.getOrganizationName(),
codeGenerator
);
return materialRepository.save(material).getId();
@@ -61,7 +61,7 @@ public class MaterialCommandService {
command.getWeight(),
command.getMaterialVolume(),
command.getMaterialContent(),
command.getRemark(),command.getTopOrganizationId(),command.getOrganizationId()
command.getRemark(),command.getTopOrganizationId(),command.getOrganizationId(),command.getOrganizationName()
);
materialRepository.update(material);
@@ -51,4 +51,6 @@ public class UpdateMaterialCommand {
private String topOrganizationId;
/**组织相关*/
private String organizationId;
/**组织相关*/
private String organizationName;
}
@@ -34,4 +34,10 @@ public class MaterialQueryCommand {
private BigDecimal materialVolume;
@ApiModelProperty(value = "物料内容")
private String materialContent;
@ApiModelProperty(value = "组织ID")
private String organizationId;
@ApiModelProperty(value = "组织名称")
private String organizationName;
@ApiModelProperty(value = "一级组织ID")
private String topOrganizationId;
}
@@ -5,6 +5,9 @@ import com.linke.transport.application.service.warehouse.material.vo.MaterialVO;
import com.linke.transport.domain.warehouse.material.exception.MaterialDomainException;
import com.linke.transport.domain.warehouse.material.repository.MaterialRepository;
import com.linke.transport.infrastructure.warehouse.material.converter.MaterialConverter;
import com.mhd.common.core.utils.StringUtils;
import com.mhd.system.api.model.LoginUser;
import com.mhd.common.security.utils.SecurityUtils;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
@@ -20,15 +23,79 @@ public class MaterialQueryService {
* 分页查询物料
*/
public IPage<MaterialVO> queryMaterials(MaterialQueryCommand param) {
return materialRepository.search(
// 先保存前端传递的 organizationId如果存在
String frontendOrganizationId = param.getOrganizationId();
// 获取当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
Long loginUserOrganizationId = null;
Long topOrganizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
}
// 数据权限根据organizationId来设置查询权限
// organizationId等于2827时查询全部其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827可以查询所有组织的数据
// 如果前端传递了 organizationId使用前端传递的值进行过滤包括2827
// 如果前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
if (StringUtils.isNotBlank(frontendOrganizationId)) {
// 前端传递了 organizationId使用前端传递的值进行过滤
param.setOrganizationId(frontendOrganizationId);
param.setTopOrganizationId(null);
} else {
// 前端没有传递 organizationId清空组织过滤条件查询所有组织的数据
param.setOrganizationId(null);
param.setTopOrganizationId(null);
}
} else {
// 其他组织设置organizationId只查询当前组织的数据
// 其他组织只能查询自己组织的数据不能查询其他组织包括南光的数据
// 如果其他组织尝试查询南光organizationId=2827的数据返回空数据
if (StringUtils.isNotBlank(frontendOrganizationId)) {
// 前端传递了 organizationId验证是否与当前登录用户的组织ID一致
if ("2827".equals(frontendOrganizationId)) {
// 其他组织尝试查询南光的数据设置一个不存在的 organizationId返回空数据
param.setOrganizationId("-1");
param.setTopOrganizationId(null);
} else if (!frontendOrganizationId.equals(String.valueOf(loginUserOrganizationId))) {
// 前端传递了其他组织的 organizationId强制使用当前登录用户的组织ID防止越权查询
param.setOrganizationId(String.valueOf(loginUserOrganizationId));
if (topOrganizationId != null) {
param.setTopOrganizationId(String.valueOf(topOrganizationId));
}
} else {
// 前端传递的 organizationId 与当前登录用户的组织ID一致使用前端传递的值
param.setOrganizationId(frontendOrganizationId);
if (topOrganizationId != null) {
param.setTopOrganizationId(String.valueOf(topOrganizationId));
}
}
} else {
// 前端没有传递 organizationId使用当前登录用户的组织ID
if (loginUserOrganizationId != null) {
param.setOrganizationId(String.valueOf(loginUserOrganizationId));
}
if (topOrganizationId != null) {
param.setTopOrganizationId(String.valueOf(topOrganizationId));
}
}
}
return materialRepository.search(
param.getShipper(),
param.getCategory(),
param.getName(),
param.getModel(),
param.getMaterialCode(),
param.getCodeManaged(),
param.getRemark(),
param.getCodeManaged(),
param.getRemark(),
param.getMaterialContent(),
param.getOrganizationId(),
param.getOrganizationName(),
param.getTopOrganizationId(),
param.getPageNo(),
param.getPageSize()
).convert(MaterialConverter :: convertToVO);
@@ -51,7 +118,32 @@ public class MaterialQueryService {
* @return 所有材料的列表以MaterialVO形式表示
*/
public List<MaterialVO> getAllMaterials(Long ownerId) {
return materialRepository.findAllMaterials(ownerId)
// 获取当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser();
String organizationId = null;
String topOrganizationId = null;
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
Long topOrgId = loginUser.getUserPo().getTopOrganizationId();
// 数据权限根据organizationId来设置查询权限
// organizationId等于2827时查询全部其他仅查询各自组织的信息
if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) {
// 南光组织organizationId=2827不设置组织过滤条件可以查询所有组织的数据
organizationId = null;
topOrganizationId = null;
} else {
// 其他组织设置organizationId只查询当前组织的数据
if (loginUserOrganizationId != null) {
organizationId = String.valueOf(loginUserOrganizationId);
}
if (topOrgId != null) {
topOrganizationId = String.valueOf(topOrgId);
}
}
}
return materialRepository.findAllMaterials(ownerId, organizationId, null, topOrganizationId)
.stream()
.map(MaterialConverter :: convertToVO)
.collect(Collectors.toList());
@@ -53,4 +53,10 @@ public class MaterialVO{
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
@ApiModelProperty("组织ID")
private String organizationId;
@ApiModelProperty("组织名称")
private String organizationName;
@ApiModelProperty("一级组织ID")
private String topOrganizationId;
}
@@ -21,6 +21,7 @@ import com.linke.transport.interfaces.dto.warehouse.outBoundOrder.OutboundOrderD
import com.linke.transport.interfaces.dto.warehouse.outBoundOrder.OutboundOrderDTO.Create;
import com.mhd.common.core.utils.OrderSequence;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -311,7 +312,7 @@ public class OutboundOrderService extends ServiceImpl<OutboundOrderMapper, Outbo
* 构建出库列表查询条件
*/
private LambdaQueryWrapper<OutboundOrder> buildListQueryWrapper(OutboundOrderDTO.Query queryDTO) {
return new LambdaQueryWrapper<OutboundOrder>()
LambdaQueryWrapper<OutboundOrder> wrapper = new LambdaQueryWrapper<OutboundOrder>()
.like(StringUtils.hasText(queryDTO.getOutboundOrderNo()),
OutboundOrder::getOutboundOrderNo, queryDTO.getOutboundOrderNo())
.eq(Objects.nonNull(queryDTO.getOwnerId()),
@@ -323,9 +324,44 @@ public class OutboundOrderService extends ServiceImpl<OutboundOrderMapper, Outbo
.ge(Objects.nonNull(queryDTO.getOutboundTimeStart()),
OutboundOrder::getOutboundTime,queryDTO.getOutboundTimeStart())
.lt(Objects.nonNull(queryDTO.getOutboundTimeEnd()),
OutboundOrder::getOutboundTime,queryDTO.getOutboundTimeEnd())
// 添加时间等其他查询条件
.orderByDesc(OutboundOrder::getOutboundTime); // 按出库时间降序
OutboundOrder::getOutboundTime,queryDTO.getOutboundTimeEnd());
// 添加组织数据权限过滤
applyOrganizationDataPermission(wrapper);
return wrapper.orderByDesc(OutboundOrder::getOutboundTime); // 按出库时间降序
}
/**
* 应用组织数据权限过滤
* 通过关联Material表来过滤组织数据
*/
private void applyOrganizationDataPermission(LambdaQueryWrapper<OutboundOrder> wrapper) {
try {
com.mhd.system.api.model.LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId();
// 如果当前登录用户的organizationId为2827南光组织可以查询全部组织数据
// 其他组织只能查询自己组织的数据
if (loginUserOrganizationId != null && !loginUserOrganizationId.equals(2827L)) {
// 其他组织需要通过Material关联来过滤
// 由于OutboundOrder没有直接的组织字段需要通过明细关联Material来过滤
// 使用EXISTS子查询只查询包含当前组织物料的出库单
wrapper.exists(String.format(
"SELECT 1 FROM outbound_order_detail ood " +
"INNER JOIN material m ON ood.material_id = m.id AND m.is_deleted = 0 " +
"WHERE ood.outbound_order_id = outbound_order.id " +
"AND ood.is_deleted = 0 " +
"AND m.organization_id = '%s'",
loginUserOrganizationId));
}
// 如果是2827组织不添加过滤条件可以查询全部
}
} catch (Exception e) {
log.warn("应用组织数据权限过滤失败,将不进行组织过滤: {}", e.getMessage());
// 如果获取登录用户信息失败不添加过滤条件避免影响正常查询
}
}
/**
@@ -243,9 +243,17 @@ public class VehicleWlhyDomainService
tmsVehicleDTO.setDrivingPermitExpDate(vehicle.getVehicleCheckoutPeriodValidity());
tmsVehicleDTO.setDrivingPermitNumber(vehicle.getVehicleFileNumber());
tmsVehicleDTO.setTransportPermitNumber(vehicle.getRoadTransportCertificateNo());
tmsVehicleDTO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
tmsVehicleDTO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
tmsVehicleDTO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
// 优先使用 vehicle 对象中保存的组织信息确保与数据库中的组织ID一致
// 如果 vehicle 中没有组织信息则使用当前登录用户的组织信息作为后备
if (vehicle.getOrganizationId() != null) {
tmsVehicleDTO.setOrganizationId(vehicle.getOrganizationId());
tmsVehicleDTO.setOrganizationName(vehicle.getOrganizationName());
tmsVehicleDTO.setTopOrganizationId(vehicle.getTopOrganizationId());
} else if (loginUser.getUserPo() != null) {
tmsVehicleDTO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
tmsVehicleDTO.setOrganizationName(loginUser.getUserPo().getOrganizationName());
tmsVehicleDTO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
if (vehicle.getUseStatus() == 2){
tmsVehicleDTO.setBlacklistStatus(1);
}else {
@@ -37,6 +37,8 @@ public class Material {
private String topOrganizationId;
/**组织相关*/
private String organizationId;
/**组织相关*/
private String organizationName;
// 私有构造方法
@@ -51,7 +53,7 @@ public class Material {
BigDecimal weight,
BigDecimal materialVolume,
String materialContent,
String remark,String topOrganizationId,String organizationId ) {
String remark,String topOrganizationId,String organizationId,String organizationName ) {
validateRequiredFields( category, name, unit);
this.ownerId = ownerId;
this.shipper = shipper;
@@ -69,6 +71,7 @@ public class Material {
this.updateTime = LocalDateTime.now();
this.topOrganizationId = topOrganizationId;
this.organizationId = organizationId;
this.organizationName = organizationName;
}
@@ -84,11 +87,11 @@ public class Material {
BigDecimal weight,
BigDecimal materialVolume,
String materialContent,
String remark,String topOrganizationId,String organizationId,
String remark,String topOrganizationId,String organizationId,String organizationName,
MaterialCodeGenerator codeGenerator) {
Material material = new Material(ownerId, shipper, category, name, model,
unit, value, codeManaged, weight, materialVolume, materialContent, remark,
topOrganizationId,organizationId
topOrganizationId,organizationId,organizationName
);
material.materialCode = codeGenerator.generate();
return material;
@@ -104,7 +107,7 @@ public class Material {
BigDecimal weight,
BigDecimal materialVolume,
String materialContent,
String remark,String topOrganizationId,String organizationId ) {
String remark,String topOrganizationId,String organizationId,String organizationName ) {
this.ownerId = ownerId;
this.shipper = shipper;
this.category = category;
@@ -120,6 +123,7 @@ public class Material {
this.updateTime = LocalDateTime.now();
this.topOrganizationId = topOrganizationId;
this.organizationId = organizationId;
this.organizationName = organizationName;
}
// 保留的核心校验
@@ -57,15 +57,19 @@ public interface MaterialRepository {
* @return 分页的物料数据
*/
IPage<Material> search(String shipper, String category, String name,String model,String materialCode,Boolean codeManaged,String remark,String materialContent,
String organizationId, String organizationName, String topOrganizationId,
Long current, Long size);
/**
* 获取所有物料
*
* @param ownerId 物料所属者ID
* @param organizationId 组织ID
* @param organizationName 组织名称
* @param topOrganizationId 一级组织ID
* @return 物料对象列表
*/
List<Material> findAllMaterials(Long ownerId);
List<Material> findAllMaterials(Long ownerId, String organizationId, String organizationName, String topOrganizationId);
/**
* 根据所属者ID更新所属者名称
@@ -44,5 +44,7 @@ public interface InventoryMapper extends BaseMapper<Inventory> {
*/
Page<InventoryVO> findInventoryList(@Param("page") Page<InventoryVO> page, @Param("query") InventoryDTO.Query query);
List<InventoryVO> findAllInventoryList(@Param("ownerId") Long ownerId,@Param("machineSerialNo")String machineSerialNo);
List<InventoryVO> findAllInventoryList(@Param("ownerId") Long ownerId,
@Param("machineSerialNo") String machineSerialNo,
@Param("organizationId") String organizationId);
}
@@ -40,4 +40,6 @@ public class MaterialDO {
private String topOrganizationId;
/**组织相关*/
private String organizationId;
/**组织相关*/
private String organizationName;
}
@@ -59,6 +59,7 @@ public class MaterialRepositoryImpl implements MaterialRepository {
@Override
public IPage<Material> search(String shipper, String category, String name, String model,String materialCode,Boolean codeManaged,String remark,String materialContent,
String organizationId, String organizationName, String topOrganizationId,
Long current, Long size) {
LambdaQueryWrapper<MaterialDO> wrapper = Wrappers.<MaterialDO>lambdaQuery()
.eq(StringUtils.isNotBlank(shipper), MaterialDO :: getShipper, shipper)
@@ -69,6 +70,12 @@ public class MaterialRepositoryImpl implements MaterialRepository {
.eq(null!=codeManaged, MaterialDO :: getCodeManaged, codeManaged)
.like(StringUtils.isNotBlank(remark), MaterialDO :: getRemark, remark)
.like(StringUtils.isNotBlank(materialContent), MaterialDO :: getMaterialContent, materialContent)
.eq(StringUtils.isNotBlank(organizationId), MaterialDO :: getOrganizationId, organizationId)
.like(StringUtils.isNotBlank(organizationName), MaterialDO :: getOrganizationName, organizationName)
.eq(StringUtils.isNotBlank(topOrganizationId), MaterialDO :: getTopOrganizationId, topOrganizationId)
// 当设置了 organizationId topOrganizationId 排除 organizationName null 的数据
.and(StringUtils.isNotBlank(organizationId) || StringUtils.isNotBlank(topOrganizationId),
w -> w.isNotNull(MaterialDO::getOrganizationName))
.orderByDesc(MaterialDO :: getCreateTime);
return materialMapper.selectPage(new Page<>(current, size), wrapper)
@@ -86,9 +93,18 @@ public class MaterialRepositoryImpl implements MaterialRepository {
}
@Override
public List<Material> findAllMaterials(Long ownerId) {
public List<Material> findAllMaterials(Long ownerId, String organizationId, String organizationName, String topOrganizationId) {
LambdaQueryWrapper<MaterialDO> wrapper = Wrappers.<MaterialDO>lambdaQuery()
.eq(Objects.nonNull(ownerId), MaterialDO :: getOwnerId, ownerId)
.eq(StringUtils.isNotBlank(organizationId), MaterialDO :: getOrganizationId, organizationId)
.like(StringUtils.isNotBlank(organizationName), MaterialDO :: getOrganizationName, organizationName)
.eq(StringUtils.isNotBlank(topOrganizationId), MaterialDO :: getTopOrganizationId, topOrganizationId)
// 当设置了 organizationId topOrganizationId 排除 organizationName null 的数据
.and(StringUtils.isNotBlank(organizationId) || StringUtils.isNotBlank(topOrganizationId),
w -> w.isNotNull(MaterialDO::getOrganizationName));
return materialMapper
.selectList(Wrappers.<MaterialDO>lambdaQuery().eq(Objects.nonNull(ownerId),MaterialDO :: getOwnerId, ownerId))
.selectList(wrapper)
.stream()
.map(MaterialConverter :: convert)
.collect(Collectors.toList());
@@ -51,7 +51,8 @@ public class InventoryDTO {
@ApiModelProperty(value = "创建时间")
private Date createdAtEnd;
@ApiModelProperty(value = "组织ID(用于数据权限过滤,内部使用)", hidden = true)
private String organizationId;
@ApiModelProperty(value = "页码,从1开始", required = true, example = "1")
@NotNull(message = "页码不能为空")
@@ -39,6 +39,19 @@ public class MaterialApi {
@PostMapping
@Log(title = "物料管理(PC)", description = "TMS-创建物料", businessType = BusinessType.INSERT)
public R<Long> createMaterial(@Valid @RequestBody CreateMaterialCommand command) {
// 设置当前登录用户的组织信息
com.mhd.system.api.model.LoginUser loginUser = com.mhd.common.security.utils.SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) {
if (command.getTopOrganizationId() == null) {
command.setTopOrganizationId(String.valueOf(loginUser.getUserPo().getTopOrganizationId()));
}
if (command.getOrganizationId() == null) {
command.setOrganizationId(String.valueOf(loginUser.getUserPo().getOrganizationId()));
}
if (command.getOrganizationName() == null) {
command.setOrganizationName(loginUser.getUserPo().getOrganizationName());
}
}
return R.ok(commandService.handle(command));
}
@@ -47,6 +47,10 @@
material m ON i.material_id = m.id AND m.is_deleted = 0
WHERE
i.is_deleted = 0
<!-- 组织数据权限过滤:通过Material表的organizationId过滤 -->
<if test="query.organizationId != null and query.organizationId != ''">
AND m.organization_id = #{query.organizationId}
</if>
<if test="query.ownerId != null">
AND i.owner_id = #{query.ownerId}
</if>
@@ -101,6 +105,10 @@
LEFT JOIN
material m ON i.material_id = m.id AND m.is_deleted = 0
WHERE i.is_deleted = 0
<!-- 组织数据权限过滤:通过Material表的organizationId过滤 -->
<if test="organizationId != null and organizationId != ''">
AND m.organization_id = #{organizationId}
</if>
<if test="ownerId != null">
AND i.owner_id = #{ownerId}
</if>
@@ -196,7 +196,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
<if test="useStatus != null "> and use_status = #{useStatus}</if>
<if test="organizationId != null "> and organization_id = #{organizationId}</if>
<if test="organizationName != null "> and organization_id like concat('%', #{organizationName}, '%')</if>
<if test="organizationName != null and organizationName != ''"> and organization_name like concat('%', #{organizationName}, '%')</if>
<if test="checkoutPersonName != null and checkoutPersonName != ''"> and checkout_person_name like concat('%', #{checkoutPersonName}, '%')</if>
<if test="checkoutDateStart != null">
AND checkout_date >= #{checkoutDateStart}