diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java index f64ace339..d54d22857 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java @@ -43,7 +43,7 @@ import java.util.stream.Collectors; /** * 租赁管理ApplicationService - * + * * @author gen * @date 2024-05-07 */ @@ -67,8 +67,9 @@ public class LeaseApplicationService { private StorageSectionApplicationService storageSectionApplicationService; @Autowired - private IShipperLeaseDetailsService shipperLeaseDetailsService; - + private IShipperLeaseDetailsService shipperLeaseDetailsService; + @Autowired + private SystemServiceFeign systemServiceFeign; /** * 分页查询租赁管理列表 @@ -76,36 +77,57 @@ public class LeaseApplicationService { public List queryList(LeaseDO leaseDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null && loginUser.getUserPo() != null){ - Long loginUserOrganizationId = loginUser.getUserPo().getOrganizationId(); - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = leaseDO.getOrganizationId(); // 前端传递的 organizationId - // 数据权限:根据organizationId来设置查询权限 - // organizationId等于2827时查询全部,其他仅查询各自组织的信息 - if (loginUserOrganizationId != null && loginUserOrganizationId.equals(2827L)) { + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { // 南光组织(organizationId=2827):可以查询所有组织的数据 - // 如果前端传递了 organizationId,使用前端传递的值进行过滤 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 - if (leaseDO.getOrganizationId() == null) { + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + leaseDO.setOrganizationId(frontendOrganizationId); + leaseDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 leaseDO.setOrganizationId(null); leaseDO.setTopOrganizationId(null); } } else { // 其他组织:设置organizationId,只查询当前组织的数据 - if (topOrganizationId != null && topOrganizationId != 1){ - leaseDO.setTopOrganizationId(topOrganizationId); + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + leaseDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + leaseDO.setOrganizationId(userOrganizationId); + } } - // 如果前端传递了organizationId,验证是否与当前登录用户的组织ID一致 - if (leaseDO.getOrganizationId() != null && !leaseDO.getOrganizationId().equals(loginUserOrganizationId)) { - // 前端传递了其他组织的organizationId,强制使用当前登录用户的组织ID,防止越权查询 - leaseDO.setOrganizationId(loginUserOrganizationId); + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (leaseDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + leaseDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + leaseDO.setTopOrganizationId(null); } } } return leaseDomainService.queryList(leaseDO); } - /** * 新增租赁管理 */ @@ -125,12 +147,9 @@ public class LeaseApplicationService { return leaseDomainService.insert(leaseDO); } - @Autowired - private SystemServiceFeign systemServiceFeign; - private void setWarehouseInfo(LeaseDO leaseDO) { AjaxResult ajaxResult = systemServiceFeign.getWarehouseInfoByWarehouseId(leaseDO.getWarehouseId()); - if(!"200".equals(String.valueOf(ajaxResult.get("code")))){ + if (!"200".equals(String.valueOf(ajaxResult.get("code")))) { throw new ServiceException("获取仓库信息失败"); } WarehouseFeignPO warehouseFeignPO = com.alibaba.fastjson.JSON.parseObject(com.alibaba.fastjson2.JSONObject.toJSONString(ajaxResult.get("data")), WarehouseFeignPO.class); @@ -170,19 +189,18 @@ public class LeaseApplicationService { /** * 获取租赁管理详细信息 */ - public LeasePO getInfo(Long leaseId) - { + public LeasePO getInfo(Long leaseId) { return leaseDomainService.getInfo(leaseId); } /** + * @param leaseIds + * @return Boolean * @description 批量作废租赁 * @author ZhouGY * @date 2024/5/13 9:46 - * @param leaseIds - * @return Boolean */ - public Boolean nullifyByIds(List leaseIds){ + public Boolean nullifyByIds(List leaseIds) { return leaseDomainService.nullifyByIds(leaseIds); } @@ -196,8 +214,8 @@ public class LeaseApplicationService { log.info("开始执行货主租赁明细定时任务"); // 计算前一天的日期,将时间设置为当天的0点0分0秒,只保留日期部分 final Date yesterday = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1)); - - LeaseDO leaseDO = new LeaseDO(); + + LeaseDO leaseDO = new LeaseDO(); leaseDO.setTime(yesterday); //查询有效期内的租赁 List leasePOS = queryList(leaseDO); @@ -207,10 +225,10 @@ public class LeaseApplicationService { List casualRental = leasePOS.stream() .filter(lease -> lease.getLeaseType().equals("散租")) .collect(Collectors.toList()); - + List shipperLeaseDetailsList = new ArrayList<>(); //需要保存或更新的数据 List shipperLeaseDetailsToUpdate = new ArrayList<>(); //需要更新的数据 - + // 查询已存在的货主租赁明细数据(用于判断是新增还是更新) ShipperLeaseDetailsDO queryDO = new ShipperLeaseDetailsDO(); queryDO.setBusinessDate(yesterday); @@ -218,18 +236,18 @@ public class LeaseApplicationService { // 构建已存在数据的Map,key为:业务日期+货主ID+仓库ID+租赁类型 Map existingMap = existingList.stream() .collect(Collectors.toMap( - item -> buildKey(yesterday, item.getShipperId(), item.getWarehouseId(), item.getLeaseType()), - item -> item, - (existing, replacement) -> existing // 如果有重复key,保留第一个 + item -> buildKey(yesterday, item.getShipperId(), item.getWarehouseId(), item.getLeaseType()), + item -> item, + (existing, replacement) -> existing // 如果有重复key,保留第一个 )); - + // 处理整租 for (LeasePO en : entireUnit) { String key = buildKey(yesterday, en.getShipperId(), en.getWarehouseId(), en.getLeaseType()); ShipperLeaseDetails shipperLeaseDetails = new ShipperLeaseDetails(); BeanUtils.copyProperties(en, shipperLeaseDetails); shipperLeaseDetails.setBusinessDate(yesterday); - + // 如果已存在,则更新;否则新增 if (existingMap.containsKey(key)) { ShipperLeaseDetailsPO existing = existingMap.get(key); @@ -239,7 +257,7 @@ public class LeaseApplicationService { shipperLeaseDetailsList.add(shipperLeaseDetails); } } - + // 处理散租:从租赁管理页面维护的面积,效期内的散租客户面积之和 for (LeasePO ca : casualRental) { String key = buildKey(yesterday, ca.getShipperId(), ca.getWarehouseId(), ca.getLeaseType()); @@ -249,7 +267,7 @@ public class LeaseApplicationService { // 散租面积直接使用租赁管理页面维护的面积 shipperLeaseDetails.setLeaseArea(ca.getLeaseArea()); log.info("货主:{},仓库:{},散租面积:{}(来自租赁管理)", ca.getCargoOwnerName(), ca.getWarehouseName(), ca.getLeaseArea()); - + // 如果已存在,则更新;否则新增 if (existingMap.containsKey(key)) { ShipperLeaseDetailsPO existing = existingMap.get(key); @@ -259,22 +277,22 @@ public class LeaseApplicationService { shipperLeaseDetailsList.add(shipperLeaseDetails); } } - + // 批量新增货主租赁明细 if (shipperLeaseDetailsList.size() > 0) { shipperLeaseDetailsService.saveBatch(shipperLeaseDetailsList); log.info("新增货主租赁明细{}条", shipperLeaseDetailsList.size()); } - + // 批量更新货主租赁明细 if (shipperLeaseDetailsToUpdate.size() > 0) { shipperLeaseDetailsService.updateBatchById(shipperLeaseDetailsToUpdate); log.info("更新货主租赁明细{}条", shipperLeaseDetailsToUpdate.size()); } - + log.info("货主租赁明细定时任务执行完成,业务日期:{}", DateUtil.formatDate(yesterday)); } - + /** * 构建唯一key:业务日期+货主ID+仓库ID+租赁类型 */ @@ -305,7 +323,7 @@ public class LeaseApplicationService { ); //获取总面积 BigDecimal totalArea = BigDecimal.ZERO; - StorageSectionDO storageSectionDO = new StorageSectionDO(); + StorageSectionDO storageSectionDO = new StorageSectionDO(); storageSectionDO.setWarehouseId(shipperLeaseDetailsDO.getWarehouseId()); storageSectionDO.setOpeningUp(1); List storageSectionPOS = storageSectionApplicationService.queryList(storageSectionDO); @@ -323,9 +341,9 @@ public class LeaseApplicationService { BigDecimal fractionalLeaseArea = BigDecimal.ZERO; //计算整租和散租 for (ShipperLeaseDetailsPO shipperLeaseDetail : shipperLeaseDetails) { - if (shipperLeaseDetail.getLeaseType().equals("整租")){ + if (shipperLeaseDetail.getLeaseType().equals("整租")) { entireLeaseArea = entireLeaseArea.add(shipperLeaseDetail.getLeaseArea()); - }else { + } else { fractionalLeaseArea = fractionalLeaseArea.add(shipperLeaseDetail.getLeaseArea()); } warehouseOccupancyRate.setWarehouseName(shipperLeaseDetail.getWarehouseName()); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/batch/BatchApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/batch/BatchApplicationService.java index 433041bed..c77a3a42f 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/batch/BatchApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/batch/BatchApplicationService.java @@ -39,10 +39,52 @@ public class BatchApplicationService { public List queryList(BatchDO batchDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - batchDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = batchDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + batchDO.setOrganizationId(frontendOrganizationId); + batchDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + batchDO.setOrganizationId(null); + batchDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + batchDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + batchDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (batchDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + batchDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + batchDO.setTopOrganizationId(null); + } } } List batchPOS = batchDomainService.queryList(batchDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/brand/BrandApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/brand/BrandApplicationService.java index f4652016b..4a9fa1554 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/brand/BrandApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/brand/BrandApplicationService.java @@ -37,10 +37,52 @@ public class BrandApplicationService { public List queryList(BrandDO brandDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - brandDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = brandDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + brandDO.setOrganizationId(frontendOrganizationId); + brandDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + brandDO.setOrganizationId(null); + brandDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + brandDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + brandDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (brandDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + brandDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + brandDO.setTopOrganizationId(null); + } } } return brandDomainService.queryList(brandDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java index 8a253446d..7fa3c5b55 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java @@ -43,10 +43,52 @@ public class MaterialBaseInfoApplicationService { public List queryList(MaterialBaseInfoDO materialBaseInfoDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - materialBaseInfoDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = materialBaseInfoDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + materialBaseInfoDO.setOrganizationId(frontendOrganizationId); + materialBaseInfoDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + materialBaseInfoDO.setOrganizationId(null); + materialBaseInfoDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + materialBaseInfoDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + materialBaseInfoDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (materialBaseInfoDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + materialBaseInfoDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + materialBaseInfoDO.setTopOrganizationId(null); + } } } return materialBaseInfoDomainService.queryList(materialBaseInfoDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialClassify/MaterialClassifyApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialClassify/MaterialClassifyApplicationService.java index bab615ff8..9ce33307e 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialClassify/MaterialClassifyApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/materialClassify/MaterialClassifyApplicationService.java @@ -29,10 +29,52 @@ public class MaterialClassifyApplicationService { public List queryList(MaterialClassifyDO materialClassifyDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - materialClassifyDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = materialClassifyDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + materialClassifyDO.setOrganizationId(frontendOrganizationId); + materialClassifyDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + materialClassifyDO.setOrganizationId(null); + materialClassifyDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + materialClassifyDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + materialClassifyDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (materialClassifyDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + materialClassifyDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + materialClassifyDO.setTopOrganizationId(null); + } } } return materialClassifyDomainService.queryList(materialClassifyDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/pack/PackApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/pack/PackApplicationService.java index 13326a0d6..4cfbfbe5a 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/pack/PackApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/pack/PackApplicationService.java @@ -38,10 +38,52 @@ public class PackApplicationService { public List queryList(PackDO packDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - packDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = packDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + packDO.setOrganizationId(frontendOrganizationId); + packDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + packDO.setOrganizationId(null); + packDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + packDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + packDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (packDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + packDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + packDO.setTopOrganizationId(null); + } } } return packDomainService.queryList(packDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocation/StorageLocationApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocation/StorageLocationApplicationService.java index 2d69d28eb..5ac9c4652 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocation/StorageLocationApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocation/StorageLocationApplicationService.java @@ -44,13 +44,56 @@ public class StorageLocationApplicationService { public List queryList(StorageLocationDO storageLocationDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - storageLocationDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = storageLocationDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + storageLocationDO.setOrganizationId(frontendOrganizationId); + storageLocationDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + storageLocationDO.setOrganizationId(null); + storageLocationDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + storageLocationDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + storageLocationDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (storageLocationDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + storageLocationDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + storageLocationDO.setTopOrganizationId(null); + } } + // 只有当前端没有明确传仓库条件时,才使用用户关联仓库缓存进行过滤; - // 避免出现“单据仓库=常温仓,但库位列表仍显示保税仓”的错配问题。 + // 避免出现"单据仓库=常温仓,但库位列表仍显示保税仓"的错配问题。 boolean hasWarehouseFilter = storageLocationDO.getWarehouseId() != null || (storageLocationDO.getWarehouseCode() != null && !storageLocationDO.getWarehouseCode().trim().isEmpty()) || (storageLocationDO.getWarehouseName() != null && !storageLocationDO.getWarehouseName().trim().isEmpty()); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocationGroup/StorageLocationGroupApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocationGroup/StorageLocationGroupApplicationService.java index 68e902720..ae86e3e37 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocationGroup/StorageLocationGroupApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageLocationGroup/StorageLocationGroupApplicationService.java @@ -28,14 +28,52 @@ public class StorageLocationGroupApplicationService { public List queryList(StorageLocationGroupDO storageLocationGroupDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - storageLocationGroupDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); - } - Long organizationId = loginUser.getUserPo().getOrganizationId(); - if (organizationId != null && organizationId != 1){ - storageLocationGroupDO.setOrganizationId(organizationId); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = storageLocationGroupDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + storageLocationGroupDO.setOrganizationId(frontendOrganizationId); + storageLocationGroupDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + storageLocationGroupDO.setOrganizationId(null); + storageLocationGroupDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + storageLocationGroupDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + storageLocationGroupDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (storageLocationGroupDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + storageLocationGroupDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + storageLocationGroupDO.setTopOrganizationId(null); + } } } return storageLocationGroupDomainService.queryList(storageLocationGroupDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageSection/StorageSectionApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageSection/StorageSectionApplicationService.java index 4df1b92dc..30b5d8d76 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageSection/StorageSectionApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/storageSection/StorageSectionApplicationService.java @@ -43,10 +43,52 @@ public class StorageSectionApplicationService { public List queryList(StorageSectionDO storageSectionDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - storageSectionDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = storageSectionDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + storageSectionDO.setOrganizationId(frontendOrganizationId); + storageSectionDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + storageSectionDO.setOrganizationId(null); + storageSectionDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + storageSectionDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + storageSectionDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (storageSectionDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + storageSectionDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + storageSectionDO.setTopOrganizationId(null); + } } } return storageSectionDomainService.queryList(storageSectionDO); diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/warehouse/WarehouseApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/warehouse/WarehouseApplicationService.java index 7765d64bb..02634b427 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/warehouse/WarehouseApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/warehouse/WarehouseApplicationService.java @@ -42,10 +42,52 @@ public class WarehouseApplicationService { public List queryList(WarehouseDO warehouseDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long organizationId = loginUser.getUserPo().getOrganizationId(); - if (organizationId != null && organizationId != 1){ - warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = warehouseDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + warehouseDO.setOrganizationId(frontendOrganizationId); + warehouseDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + warehouseDO.setOrganizationId(null); + warehouseDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + warehouseDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + warehouseDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (warehouseDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + warehouseDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + warehouseDO.setTopOrganizationId(null); + } } } return warehouseDomainService.queryList(warehouseDO); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/differentManage/DifferentManageApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/differentManage/DifferentManageApplicationService.java index 34cf8d9ab..3b21a29e6 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/differentManage/DifferentManageApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/differentManage/DifferentManageApplicationService.java @@ -32,10 +32,21 @@ public class DifferentManageApplicationService { public List queryList(DifferentManageDO differentManageDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null) { + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + // 当前登录用户组织ID为2827时,查询所有组织的数据 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 不设置organizationId,查询所有组织的数据 + differentManageDO.setOrganizationId(null); + } else { + // 其他情况,只查询当前登录用户所属组织的数据 + if (userOrganizationId != null) { + differentManageDO.setOrganizationId(userOrganizationId); + } + } Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); if (topOrganizationId != null && topOrganizationId != 1) { - differentManageDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + differentManageDO.setTopOrganizationId(topOrganizationId); } AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); differentManageDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/handoverTaskOrder/HandoverTaskOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/handoverTaskOrder/HandoverTaskOrderApplicationService.java index a2abba9fe..b8153c140 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/handoverTaskOrder/HandoverTaskOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/handoverTaskOrder/HandoverTaskOrderApplicationService.java @@ -63,13 +63,57 @@ public class HandoverTaskOrderApplicationService { public List queryList(HandoverTaskOrderDO handoverTaskOrderDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - handoverTaskOrderDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = handoverTaskOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + handoverTaskOrderDO.setOrganizationId(frontendOrganizationId); + handoverTaskOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + handoverTaskOrderDO.setOrganizationId(null); + handoverTaskOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + handoverTaskOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + handoverTaskOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (handoverTaskOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + handoverTaskOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + handoverTaskOrderDO.setTopOrganizationId(null); + } } AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); - handoverTaskOrderDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); + if (associationWarehouseCacheDO != null) { + handoverTaskOrderDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); + } } return handoverTaskOrderDomainService.queryList(handoverTaskOrderDO); } diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/investigationManage/InvestigationManageApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/investigationManage/InvestigationManageApplicationService.java index e753bf178..9108b6750 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/investigationManage/InvestigationManageApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/investigationManage/InvestigationManageApplicationService.java @@ -64,10 +64,21 @@ public class InvestigationManageApplicationService { public List queryList(InvestigationManageDO investigationManageDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null) { + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + // 当前登录用户组织ID为2827时,查询所有组织的数据 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 不设置organizationId,查询所有组织的数据 + investigationManageDO.setOrganizationId(null); + } else { + // 其他情况,只查询当前登录用户所属组织的数据 + if (userOrganizationId != null) { + investigationManageDO.setOrganizationId(userOrganizationId); + } + } Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); if (topOrganizationId != null && topOrganizationId != 1) { - investigationManageDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + investigationManageDO.setTopOrganizationId(topOrganizationId); } AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); investigationManageDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java index 1eff5f2c4..bc2a08264 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialBaseInfo/MaterialBaseInfoApplicationService.java @@ -59,10 +59,52 @@ public class MaterialBaseInfoApplicationService { public List queryList(MaterialBaseInfoDO materialBaseInfoDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - materialBaseInfoDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = materialBaseInfoDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + materialBaseInfoDO.setOrganizationId(frontendOrganizationId); + materialBaseInfoDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + materialBaseInfoDO.setOrganizationId(null); + materialBaseInfoDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + materialBaseInfoDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + materialBaseInfoDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (materialBaseInfoDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + materialBaseInfoDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + materialBaseInfoDO.setTopOrganizationId(null); + } } } List materialBaseInfoPOS = materialBaseInfoDomainService.queryList(materialBaseInfoDO); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialInventory/MaterialInventoryApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialInventory/MaterialInventoryApplicationService.java index 80c489e30..11667a13e 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/materialInventory/MaterialInventoryApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/materialInventory/MaterialInventoryApplicationService.java @@ -51,12 +51,24 @@ public class MaterialInventoryApplicationService { public List queryList(MaterialInventoryDO materialInventoryDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ + if (loginUser != null && loginUser.getUserPo() != null){ + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + // 当前登录用户组织ID为2827时,查询所有组织的数据 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 不设置organizationId,查询所有组织的数据 + materialInventoryDO.setOrganizationId(null); + } else { + // 其他情况,只查询当前登录用户所属组织的数据 + if (userOrganizationId != null) { + materialInventoryDO.setOrganizationId(userOrganizationId); + } + } + // 处理topOrganizationId逻辑 Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); if (topOrganizationId != null && topOrganizationId != 1){ - materialInventoryDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + materialInventoryDO.setTopOrganizationId(topOrganizationId); } - // 前端有传warehouseId则优先使用传参;未传时才使用“用户关联仓库”作为默认值 + // 前端有传warehouseId则优先使用传参;未传时才使用"用户关联仓库"作为默认值 if (materialInventoryDO.getWarehouseId() == null) { AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java index 5ae739c7c..13cb8b6d3 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/pickingOrder/PickingOrderApplicationService.java @@ -61,13 +61,53 @@ public class PickingOrderApplicationService { public List queryList(PickingOrderDO pickingOrderDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - pickingOrderDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = pickingOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + pickingOrderDO.setOrganizationId(frontendOrganizationId); + pickingOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + pickingOrderDO.setOrganizationId(null); + pickingOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + pickingOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + pickingOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (pickingOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + pickingOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + pickingOrderDO.setTopOrganizationId(null); + } } - //AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); - //pickingOrderDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); } List pickingOrderPOList = pickingOrderDomainService.queryList(pickingOrderDO); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftManage/ShiftManageApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftManage/ShiftManageApplicationService.java index 5af67514e..0c84bc688 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftManage/ShiftManageApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftManage/ShiftManageApplicationService.java @@ -67,10 +67,21 @@ public class ShiftManageApplicationService { public List queryList(ShiftManageDO shiftManageDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + // 当前登录用户组织ID为2827时,查询所有组织的数据 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 不设置organizationId,查询所有组织的数据 + shiftManageDO.setOrganizationId(null); + } else { + // 其他情况,只查询当前登录用户所属组织的数据 + if (userOrganizationId != null) { + shiftManageDO.setOrganizationId(userOrganizationId); + } + } Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - shiftManageDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (topOrganizationId != null && topOrganizationId != 1) { + shiftManageDO.setTopOrganizationId(topOrganizationId); } AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); shiftManageDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftMaterialDetail/ShiftMaterialDetailApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftMaterialDetail/ShiftMaterialDetailApplicationService.java index 256f592ea..08f0fae37 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftMaterialDetail/ShiftMaterialDetailApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/shiftMaterialDetail/ShiftMaterialDetailApplicationService.java @@ -119,7 +119,7 @@ public class ShiftMaterialDetailApplicationService { } // 性能优化:批量获取批次属性,避免N+1查询问题 - // 1. 收集所有唯一的materialBaseInfoId + // 1. 收集所有唯一的materialBaseInfoId(包括子项的,此时子项还未构建,所以直接遍历所有项) Set materialBaseInfoIdSet = list.stream() .map(ShiftMaterialDetailPO::getMaterialBaseInfoId) .filter(Objects::nonNull) @@ -146,18 +146,47 @@ public class ShiftMaterialDetailApplicationService { } } - // 3. 为每个物料明细设置更多属性(从库存表中获取值) - setMaterialMoreDetailListFromInventory(list, batchDetailMap); + // 3. 构建父子关系(类似queryListChildren的逻辑) + List parentList = list.stream() + .filter(e -> e.getLevel() != null && e.getLevel() == 1) + .collect(Collectors.toList()); - return list; + // 递归构建子项关系 + parentList.forEach(parent -> { + List children = getChildren(parent.getUniqueId(), list, 2); + parent.setChildren(children); + }); + + // 4. 为每个物料明细(包括子项)设置更多属性(从库存表中获取值) + setMaterialMoreDetailListFromInventoryRecursively(parentList, batchDetailMap); + + return parentList; } /** - * 为移位物料明细设置更多属性(从库存表中获取值) + * 递归获取子项 + */ + private List getChildren(Long parentUniqueId, List allList, Integer maxLevel) { + List childrenList = allList.stream() + .filter(materialDetailPO -> parentUniqueId != null && parentUniqueId.equals(materialDetailPO.getParentUniqueId())) + .collect(Collectors.toList()); + + if (!CollectionUtils.isEmpty(childrenList)) { + childrenList.forEach(child -> { + if (child.getLevel() != null && child.getLevel() < maxLevel) { + child.setChildren(getChildren(child.getUniqueId(), allList, maxLevel)); + } + }); + } + return childrenList; + } + + /** + * 为移位物料明细设置更多属性(从库存表中获取值),递归处理子项 * @param shiftMaterialDetailPOList 移位物料明细列表 * @param batchDetailMap 批次属性Map */ - private void setMaterialMoreDetailListFromInventory(List shiftMaterialDetailPOList, + private void setMaterialMoreDetailListFromInventoryRecursively(List shiftMaterialDetailPOList, Map> batchDetailMap) { if (CollectionUtils.isEmpty(shiftMaterialDetailPOList)) { return; @@ -235,6 +264,11 @@ public class ShiftMaterialDetailApplicationService { shiftMaterialDetailPO.getUniqueId(), shiftMaterialDetailPO.getMaterialBaseInfoId(), shiftMaterialDetailPO.getMaterialInventoryId(), materialMoreDetailList != null ? materialMoreDetailList.size() : 0); + + // 递归处理子项 + if (!CollectionUtils.isEmpty(shiftMaterialDetailPO.getChildren())) { + setMaterialMoreDetailListFromInventoryRecursively(shiftMaterialDetailPO.getChildren(), batchDetailMap); + } }); } diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java index 305a161a0..7e823acfe 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockInOrder/StockInOrderApplicationService.java @@ -68,10 +68,52 @@ public class StockInOrderApplicationService { public List queryList(StockInOrderDO stockInOrderDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - stockInOrderDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null){ + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = stockInOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + stockInOrderDO.setOrganizationId(frontendOrganizationId); + stockInOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + stockInOrderDO.setOrganizationId(null); + stockInOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + stockInOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + stockInOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (stockInOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + stockInOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + stockInOrderDO.setTopOrganizationId(null); + } } // 前端有传warehouseId则优先使用传参;未传时才使用"用户关联仓库"作为默认值 if (stockInOrderDO.getWarehouseId() == null) { diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutOrder/StockOutOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutOrder/StockOutOrderApplicationService.java index d24d10301..11926c071 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutOrder/StockOutOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutOrder/StockOutOrderApplicationService.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.mhd.common.core.constant.SnowFlakeConstants; import com.mhd.common.core.domain.po.UserPo; import com.mhd.common.core.enums.DictCode; @@ -23,14 +24,19 @@ import com.mhd.system.api.domain.WarehouseFeignPO; import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO; import com.mhd.system.api.domain.cache.SystemServiceCacheUtil; import com.mhd.system.api.model.LoginUser; +import com.mhd.wms.domain.materialInventory.entity.MaterialInventory; import com.mhd.wms.domain.materialInventory.repository.mapper.MaterialInventoryMapper; import com.mhd.wms.domain.materialInventory.repository.po.MaterialInventoryPO; import com.mhd.wms.domain.materialInventory.service.MaterialInventoryDomainService; import com.mhd.wms.domain.materialMoreDetail.repository.po.MaterialMoreDetailPO; +import com.mhd.wms.domain.outMaterialDetail.entity.OutMaterialDetail; +import com.mhd.wms.domain.outMaterialDetail.repository.facade.IOutMaterialDetailService; import com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialCheckPO; import com.mhd.wms.domain.outMaterialDetail.repository.po.OutMaterialDetailPO; import com.mhd.wms.domain.outMaterialDetail.repository.todo.OutMaterialDetailDO; import com.mhd.wms.domain.outMaterialDetail.service.OutMaterialDetailDomainService; +import com.mhd.wms.domain.stockOutOrder.entity.StockOutOrder; +import com.mhd.wms.domain.stockOutOrder.repository.facade.IStockOutOrderService; import com.mhd.wms.domain.stockOutOrder.repository.po.StockOutOrderPO; import com.mhd.wms.domain.stockOutOrder.repository.todo.StockOutOrderDO; import com.mhd.wms.domain.stockOutOrder.service.StockOutOrderDomainService; @@ -69,6 +75,10 @@ public class StockOutOrderApplicationService { private SystemServiceFeign systemServiceFeign; @Autowired private IdGenerator idGenerator; + @Autowired + private IStockOutOrderService stockOutOrderService; + @Autowired + private IOutMaterialDetailService outMaterialDetailService; /** @@ -85,6 +95,54 @@ public class StockOutOrderApplicationService { AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); stockOutOrderDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); }*/ + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = stockOutOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + stockOutOrderDO.setOrganizationId(frontendOrganizationId); + stockOutOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + stockOutOrderDO.setOrganizationId(null); + stockOutOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + stockOutOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + stockOutOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (stockOutOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + stockOutOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + stockOutOrderDO.setTopOrganizationId(null); + } + } + } return stockOutOrderDomainService.queryList(stockOutOrderDO); } @@ -522,10 +580,66 @@ public class StockOutOrderApplicationService { return stockOutOrderDomainService.manualAssign(assembleStockOutOrderDO); } + /** + * @description 手动分配 + * @author ZhouGY + * @date 2024/5/28 13:47 + * @param stockOutOrderDO + * @return Boolean + */ public Boolean autoAssign(StockOutOrderDO stockOutOrderDO){ + List outOrderIds = stockOutOrderDO.getOutOrderIds(); + if (outOrderIds == null || outOrderIds.isEmpty()){ + throw new ServiceException("出库单ID不能为空"); + } + Boolean result = true; + for (Long outOrderId : outOrderIds){ + StockOutOrderDO stockOutOrderD = new StockOutOrderDO(); + StockOutOrder stockOutOrderDb = stockOutOrderService.getById(outOrderId); + if (stockOutOrderDb == null){ + throw new ServiceException("出库单ID不存在"); + } + BeanUtils.copyProperties(stockOutOrderDb, stockOutOrderD); + List outMaterialDetailList = outMaterialDetailService.list(new QueryWrapper().lambda() + .eq(OutMaterialDetail::getOutOrderNumber, stockOutOrderDb.getOutOrderNumber())); + List materialDetailList = cn.hutool.core.bean.BeanUtil.copyToList(outMaterialDetailList, OutMaterialDetailDO.class); + for (OutMaterialDetailDO detail : materialDetailList) { + detail.setAllocationQuantity(detail.getQuantity()); + String batchRefNo = detail.getBatchRefNo(); + String sheetRefNo = detail.getSheetRefNo(); + String boxPalletNo = detail.getBoxPalletNo(); + Long materialBaseInfoId = detail.getMaterialBaseInfoId(); + List materialInventories = materialInventoryMapper.selectList(new QueryWrapper().lambda() + .eq(MaterialInventory::getBatchRefNo, batchRefNo) + .eq(MaterialInventory::getSheetRefNo, sheetRefNo) + .eq(MaterialInventory::getBoxPalletNo, boxPalletNo) + .eq(MaterialInventory::getMaterialBaseInfoId, materialBaseInfoId)); + if (materialInventories == null || materialInventories.isEmpty()) { + throw new ServiceException("库存不存在:" + batchRefNo + " " + sheetRefNo + " " + boxPalletNo); + } + MaterialInventory materialInventory = materialInventories.get(0); + detail.setMaterialInventoryId(materialInventory.getMaterialInventoryId()); + detail.setStorageLocationId(materialInventory.getStorageLocationId()); + detail.setStorageLocationName(materialInventory.getStorageLocationName()); + detail.setStorageLocationCode(materialInventory.getStorageLocationCode()); + detail.setStorageSectionId(materialInventory.getStorageSectionId()); + detail.setStorageName(materialInventory.getStorageName()); + detail.setStorageCode(materialInventory.getStorageCode()); + } + stockOutOrderD.setMaterialDetailList(materialDetailList); + StockOutOrderDO assembleStockOutOrderDO = assembleParamByOutOrder(stockOutOrderDO); + Boolean assignResult = stockOutOrderDomainService.autoAssign(assembleStockOutOrderDO); + if (!assignResult) { + result = false; + } + } + return result; + } + + /*public Boolean autoAssign(StockOutOrderDO stockOutOrderDO){ StockOutOrderDO assembleStockOutOrderDO = assembleParamByOutOrder(stockOutOrderDO); return stockOutOrderDomainService.autoAssign(assembleStockOutOrderDO); - } + }*/ /** * @description 取消分配 diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutTaskOrder/StockOutTaskOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutTaskOrder/StockOutTaskOrderApplicationService.java index 3d4a4bdfa..89cb55390 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutTaskOrder/StockOutTaskOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockOutTaskOrder/StockOutTaskOrderApplicationService.java @@ -46,13 +46,57 @@ public class StockOutTaskOrderApplicationService { public List queryList(StockOutTaskOrderDO stockOutTaskOrderDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - stockOutTaskOrderDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null) { + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = stockOutTaskOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + stockOutTaskOrderDO.setOrganizationId(frontendOrganizationId); + stockOutTaskOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + stockOutTaskOrderDO.setOrganizationId(null); + stockOutTaskOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + stockOutTaskOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + stockOutTaskOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (stockOutTaskOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + stockOutTaskOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + stockOutTaskOrderDO.setTopOrganizationId(null); + } } AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); - stockOutTaskOrderDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); + if (associationWarehouseCacheDO != null) { + stockOutTaskOrderDO.setWarehouseId(associationWarehouseCacheDO.getWarehouseId()); + } } return stockOutTaskOrderDomainService.queryList(stockOutTaskOrderDO); } diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockReceiptOrder/StockReceiptOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockReceiptOrder/StockReceiptOrderApplicationService.java index d3333ed15..f64287c34 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockReceiptOrder/StockReceiptOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockReceiptOrder/StockReceiptOrderApplicationService.java @@ -91,10 +91,52 @@ public class StockReceiptOrderApplicationService { public List queryList(StockReceiptOrderDO stockReceiptOrderDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - stockReceiptOrderDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null){ + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = stockReceiptOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + stockReceiptOrderDO.setOrganizationId(frontendOrganizationId); + stockReceiptOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + stockReceiptOrderDO.setOrganizationId(null); + stockReceiptOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + stockReceiptOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + stockReceiptOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (stockReceiptOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + stockReceiptOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + stockReceiptOrderDO.setTopOrganizationId(null); + } } try { AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java index 22acbc228..ad2ba418f 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/application/service/stockShelfOrder/StockShelfOrderApplicationService.java @@ -97,10 +97,52 @@ public class StockShelfOrderApplicationService { public List queryList(StockShelfOrderDO stockShelfOrderDO) { LoginUser loginUser = SecurityUtils.getLoginUser(); - if (loginUser != null){ - Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); - if (topOrganizationId != null && topOrganizationId != 1){ - stockShelfOrderDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + if (loginUser != null && loginUser.getUserPo() != null){ + Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); + Long frontendOrganizationId = stockShelfOrderDO.getOrganizationId(); // 前端传递的 organizationId + + // 数据权限:根据 organizationId 来设置查询权限 + // 当前登录用户的 organizationId 为 2827 时,可查全部组织数据;其他组织只能查自己 + if (userOrganizationId != null && userOrganizationId == 2827L) { + // 南光组织(organizationId=2827):可以查询所有组织的数据 + // 如果前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + // 如果前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + if (frontendOrganizationId != null) { + // 前端传递了 organizationId(包括2827或其他组织),使用前端传递的值进行过滤 + stockShelfOrderDO.setOrganizationId(frontendOrganizationId); + stockShelfOrderDO.setTopOrganizationId(null); // 明确设置为 null,避免使用 topOrganizationId 条件 + } else { + // 前端没有传递 organizationId,清空组织过滤条件,查询所有组织的数据 + stockShelfOrderDO.setOrganizationId(null); + stockShelfOrderDO.setTopOrganizationId(null); + } + } else { + // 其他组织:设置organizationId,只查询当前组织的数据 + // 如果前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (frontendOrganizationId != null && userOrganizationId != null) { + // 前端传递了 organizationId,验证是否与当前登录用户的组织ID一致 + if (!frontendOrganizationId.equals(userOrganizationId)) { + // 前端传递了其他组织的 organizationId,强制使用当前登录用户的组织ID,防止越权查询 + stockShelfOrderDO.setOrganizationId(userOrganizationId); + } + // 如果前端传递的 organizationId 与当前登录用户的组织ID一致,使用前端传递的值 + } else { + // 前端没有传递 organizationId,使用当前登录用户的组织ID + if (userOrganizationId != null) { + stockShelfOrderDO.setOrganizationId(userOrganizationId); + } + } + // 只有当 organizationId 为 null 时,才使用 topOrganizationId 作为查询条件 + // 如果 organizationId 不为 null,则优先使用 organizationId,不使用 topOrganizationId + if (stockShelfOrderDO.getOrganizationId() == null) { + Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId(); + if (topOrganizationId != null && topOrganizationId != 1) { + stockShelfOrderDO.setTopOrganizationId(topOrganizationId); + } + } else { + // 如果 organizationId 不为 null,清空 topOrganizationId,确保查询使用 organizationId + stockShelfOrderDO.setTopOrganizationId(null); + } } try { AssociationWarehouseCacheDO associationWarehouseCacheDO = SystemServiceCacheUtil.getAssociationWarehouseCache(loginUser.getUserid()); diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/inMaterialDetail/repository/persistence/InMaterialDetailImpl.java b/mhd_wms/src/main/java/com/mhd/wms/domain/inMaterialDetail/repository/persistence/InMaterialDetailImpl.java index d02e44bbc..8236b5e2a 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/inMaterialDetail/repository/persistence/InMaterialDetailImpl.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/inMaterialDetail/repository/persistence/InMaterialDetailImpl.java @@ -147,6 +147,10 @@ public class InMaterialDetailImpl extends ServiceImpl().lambda() - .set(MaterialBarCode::getDelFlag, 2) - .set(MaterialBarCode::getUpdateBy, loginUser.getUserid()) - .set(MaterialBarCode::getUpdateByName, loginUser.getUsername()) - .set(MaterialBarCode::getUpdateTime, new Date()) - .eq(MaterialBarCode::getMaterialBaseInfoId, materialBarCodeDOList.get(0).getMaterialBaseInfoId()) - .eq(MaterialBarCode::getDelFlag, 1)); + Long materialBaseInfoId = materialBarCodeDOList.get(0).getMaterialBaseInfoId(); + + // 先物理删除该物料的所有旧条码记录(包括已标记删除的),避免唯一性约束冲突 + // 因为唯一性约束 IDX_MATERIAL_BASE_ID_BAR_CODE 可能检查所有记录(包括 delFlag=2 的记录) + // 使用 Mapper 的 delete 方法进行物理删除,绕过逻辑删除拦截器 + materialBarCodeMapper.delete(new QueryWrapper().lambda() + .eq(MaterialBarCode::getMaterialBaseInfoId, materialBaseInfoId)); + + // 去重处理:确保没有重复的 material_base_info_id + bar_code 组合 + // 使用 LinkedHashMap 保持顺序,对所有记录进行去重 + // 对于 barCode 为 null 的记录,使用 packDetailId 来区分(因为唯一性约束可能不允许多个 null) + java.util.Map uniqueMap = new java.util.LinkedHashMap<>(); List materialBarCodeList = new ArrayList<>(); + for (MaterialBarCodeDO materialBarCodeDO : materialBarCodeDOList){ + String barCode = materialBarCodeDO.getBarCode(); + String key; + // 构建唯一性 key:material_base_info_id + bar_code + // 如果 barCode 为 null 或空,使用 packDetailId 来区分,避免多条 null 值违反唯一性约束 + if (barCode != null && !barCode.trim().isEmpty()) { + key = materialBaseInfoId + "_" + barCode.trim(); + } else { + // barCode 为 null 或空时,使用 packDetailId 来区分 + // 如果 packDetailId 也为 null,则使用固定值(只保留第一条) + Long packDetailId = materialBarCodeDO.getPackDetailId(); + key = materialBaseInfoId + "_null_" + (packDetailId != null ? packDetailId : "empty"); + } + // 如果已存在相同的组合,跳过(保留第一个),避免违反唯一性约束 + if (uniqueMap.containsKey(key)) { + continue; + } + // 创建新的条码记录 MaterialBarCode materialBarCode = new MaterialBarCode(); - BeanUtils.copyProperties(materialBarCodeDO,materialBarCode); + BeanUtils.copyProperties(materialBarCodeDO, materialBarCode); materialBarCode.setOrganizationId(userPo.getOrganizationId()); materialBarCode.setOrganizationName(userPo.getOrganizationName()); materialBarCode.setTopOrganizationId(userPo.getTopOrganizationId()); materialBarCode.setCreateBy(loginUser.getUserid()); materialBarCode.setCreateByName(loginUser.getUsername()); materialBarCode.setCreateTime(new Date()); + materialBarCode.setDelFlag(1); + // 添加到去重 Map 和列表 + uniqueMap.put(key, materialBarCode); materialBarCodeList.add(materialBarCode); } + if (CollectionUtils.isEmpty(materialBarCodeList)) { + return true; + } return this.saveBatch(materialBarCodeList); } @@ -157,7 +185,12 @@ public class MaterialBarCodeImpl extends ServiceImpl materialBarCodePOList = new ArrayList<>(); - BeanUtils.copyProperties(materialBarCodeList,materialBarCodePOList); + // 遍历列表,逐个复制每个对象的属性 + for (MaterialBarCode materialBarCode : materialBarCodeList) { + MaterialBarCodePO materialBarCodePO = new MaterialBarCodePO(); + BeanUtils.copyProperties(materialBarCode, materialBarCodePO); + materialBarCodePOList.add(materialBarCodePO); + } return materialBarCodePOList; } } diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/repository/persistence/ShiftManageImpl.java b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/repository/persistence/ShiftManageImpl.java index 1e0f11c85..69edf470c 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/repository/persistence/ShiftManageImpl.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/shiftManage/repository/persistence/ShiftManageImpl.java @@ -41,6 +41,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; @@ -113,7 +114,9 @@ public class ShiftManageImpl extends ServiceImpl setWarehouseInfo(e); //设置物料信息 setMaterialDetailInfo(e); - e.setUniqueId(idGenerator.snowflakeId(SnowFlakeConstants.wmsId)); + // 设置父级信息 + Long parentUniqueId = idGenerator.snowflakeId(SnowFlakeConstants.wmsId); + e.setUniqueId(parentUniqueId); e.setShiftNumber(shiftManage.getShiftNumber()); e.setOrganizationId(loginUser.getUserPo().getOrganizationId()); e.setOrganizationName(loginUser.getUserPo().getOrganizationName()); @@ -125,10 +128,74 @@ public class ShiftManageImpl extends ServiceImpl e.setUpdateBy(loginUser.getUserid()); e.setUpdateTime(new Date()); e.setSerialNumberManage(e.getSerialNumberManage()); + // 设置父级level为1 + if (e.getLevel() == null) { + e.setLevel(1); + } ShiftMaterialDetail shiftMaterialDetail = new ShiftMaterialDetail(); BeanUtils.copyProperties(e, shiftMaterialDetail); shiftMaterialDetail.setNewStorageLocationName(newStorageLocationName); shiftMaterialDetailList.add(shiftMaterialDetail); + + // 处理子项 + List shiftMaterialDetailDOChildList = e.getChildren(); + if (!CollectionUtils.isEmpty(shiftMaterialDetailDOChildList)) { + for (ShiftMaterialDetailDO shiftMaterialDetailDOChild : shiftMaterialDetailDOChildList) { + // 如果子项没有materialInventoryId,则从父级继承库存相关信息 + if (shiftMaterialDetailDOChild.getMaterialInventoryId() == null) { + // 从父级继承库存相关信息 + shiftMaterialDetailDOChild.setMaterialInventoryId(e.getMaterialInventoryId()); + shiftMaterialDetailDOChild.setMaterialBaseInfoId(e.getMaterialBaseInfoId()); + shiftMaterialDetailDOChild.setMaterialCode(e.getMaterialCode()); + shiftMaterialDetailDOChild.setMaterialName(e.getMaterialName()); + shiftMaterialDetailDOChild.setBarCode(e.getBarCode()); + shiftMaterialDetailDOChild.setInventoryQuantity(e.getInventoryQuantity()); + shiftMaterialDetailDOChild.setOldWarehouseId(e.getOldWarehouseId()); + shiftMaterialDetailDOChild.setOldWarehouseCode(e.getOldWarehouseCode()); + shiftMaterialDetailDOChild.setOldWarehouseName(e.getOldWarehouseName()); + shiftMaterialDetailDOChild.setOldStorageSectionId(e.getOldStorageSectionId()); + shiftMaterialDetailDOChild.setOldStorageCode(e.getOldStorageCode()); + shiftMaterialDetailDOChild.setOldStorageName(e.getOldStorageName()); + shiftMaterialDetailDOChild.setOldStorageLocationId(e.getOldStorageLocationId()); + shiftMaterialDetailDOChild.setOldStorageLocationCode(e.getOldStorageLocationCode()); + shiftMaterialDetailDOChild.setOldStorageLocationName(e.getOldStorageLocationName()); + shiftMaterialDetailDOChild.setBatchNumber(e.getBatchNumber()); + shiftMaterialDetailDOChild.setMaterialStatusCode(e.getMaterialStatusCode()); + shiftMaterialDetailDOChild.setMaterialStatusName(e.getMaterialStatusName()); + shiftMaterialDetailDOChild.setContainerId(e.getContainerId()); + shiftMaterialDetailDOChild.setContainerCode(e.getContainerCode()); + shiftMaterialDetailDOChild.setContainerType(e.getContainerType()); + shiftMaterialDetailDOChild.setContainerTypeName(e.getContainerTypeName()); + } else { + // 如果子项有materialInventoryId,则设置库存信息 + setMaterialInventory(shiftMaterialDetailDOChild); + } + // 设置库位信息和物料信息 + setWarehouseInfo(shiftMaterialDetailDOChild); + setMaterialDetailInfo(shiftMaterialDetailDOChild); + + // 设置子项的uniqueId和parentUniqueId + Long childUniqueId = idGenerator.snowflakeId(SnowFlakeConstants.wmsId); + shiftMaterialDetailDOChild.setUniqueId(childUniqueId); + shiftMaterialDetailDOChild.setParentUniqueId(parentUniqueId); + shiftMaterialDetailDOChild.setShiftNumber(shiftManage.getShiftNumber()); + shiftMaterialDetailDOChild.setOrganizationId(loginUser.getUserPo().getOrganizationId()); + shiftMaterialDetailDOChild.setOrganizationName(loginUser.getUserPo().getOrganizationName()); + shiftMaterialDetailDOChild.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); + shiftMaterialDetailDOChild.setCreateByName(loginUser.getUsername()); + shiftMaterialDetailDOChild.setCreateBy(loginUser.getUserid()); + shiftMaterialDetailDOChild.setCreateTime(new Date()); + shiftMaterialDetailDOChild.setUpdateByName(loginUser.getUsername()); + shiftMaterialDetailDOChild.setUpdateBy(loginUser.getUserid()); + shiftMaterialDetailDOChild.setUpdateTime(new Date()); + // 设置子项level为2 + shiftMaterialDetailDOChild.setLevel(2); + + ShiftMaterialDetail shiftMaterialDetailChild = new ShiftMaterialDetail(); + BeanUtils.copyProperties(shiftMaterialDetailDOChild, shiftMaterialDetailChild); + shiftMaterialDetailList.add(shiftMaterialDetailChild); + } + } }); iShiftMaterialDetailService.saveBatch(shiftMaterialDetailList); Boolean b; diff --git a/mhd_wms/src/main/java/com/mhd/wms/domain/stockOutOrder/service/StockOutOrderDomainService.java b/mhd_wms/src/main/java/com/mhd/wms/domain/stockOutOrder/service/StockOutOrderDomainService.java index 078fa0dac..2176a9a67 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/domain/stockOutOrder/service/StockOutOrderDomainService.java +++ b/mhd_wms/src/main/java/com/mhd/wms/domain/stockOutOrder/service/StockOutOrderDomainService.java @@ -249,7 +249,35 @@ public class StockOutOrderDomainService { return updateStockOutOrderByAllocation(stockOutOrderDb, stockOutOrderPO, 1); } + /** + * @description 手动分配 + * @author ZhouGY + * @date 2024/5/22 16:20 + * @param stockOutOrderDO + * @return Boolean + */ @Transactional(rollbackFor = Exception.class) + public Boolean autoAssign(StockOutOrderDO stockOutOrderDO){ + List outOrderIds = stockOutOrderDO.getOutOrderIds(); + if (outOrderIds == null || outOrderIds.isEmpty()){ + throw new ServiceException("出库单ID不能为空"); + } + StockOutOrder stockOutOrderDb = stockOutOrderService.getById(stockOutOrderDO.getOutOrderId()); + if (stockOutOrderDb == null){ + throw new ServiceException("出库单不存在"); + } + if (stockOutOrderDb.getStatus() > 3){ + throw new ServiceException("收货单已完成分配"); + } + List outMaterialDetailList = outMaterialDetailService.list(new QueryWrapper().lambda() + .eq(OutMaterialDetail::getOutOrderNumber, stockOutOrderDb.getOutOrderNumber())); + //修改物料明细信息 + StockOutOrderPO stockOutOrderPO = outMaterialDetailService.batchAssignUpdate(stockOutOrderDb.getOutOrderNumber(), stockOutOrderDO.getMaterialDetailList()); + //修改出库单 + return updateStockOutOrderByAllocation(stockOutOrderDb, stockOutOrderPO, 1); + } + + /*@Transactional(rollbackFor = Exception.class) public Boolean autoAssign(StockOutOrderDO stockOutOrderDO){ StockOutOrder stockOutOrderDb = stockOutOrderService.getById(stockOutOrderDO.getOutOrderId()); if (stockOutOrderDb == null){ @@ -273,7 +301,7 @@ public class StockOutOrderDomainService { StockOutOrderPO stockOutOrderPO = outMaterialDetailService.batchAssignUpdate(stockOutOrderDb.getOutOrderNumber(), stockOutOrderDO.getMaterialDetailList()); //修改出库单 return updateStockOutOrderByAllocation(stockOutOrderDb, stockOutOrderPO, 1); - } + }*/ /** * @description 手动取消分配(点击确认后直接取消分配) diff --git a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockOutOrder/StockOutOrderApi.java b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockOutOrder/StockOutOrderApi.java index 7d4fa5081..1d8385078 100644 --- a/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockOutOrder/StockOutOrderApi.java +++ b/mhd_wms/src/main/java/com/mhd/wms/interfaces/facadeApi/stockOutOrder/StockOutOrderApi.java @@ -173,6 +173,17 @@ public class StockOutOrderApi extends BaseController { } + /** + * 手动分配 + */ + @ApiOperation("自动分配") + @PostMapping("/autoAssign") + public AjaxResult autoAssign(@RequestBody StockOutOrderDTO stockOutOrderDTO) { + StockOutOrderDO stockOutOrderDO = new StockOutOrderDO(); + BeanUtils.copyProperties(stockOutOrderDTO, stockOutOrderDO); + return toAjax(stockOutOrderApplicationService.autoAssign(stockOutOrderDO)); + } + /** * 取消分配 */ @@ -325,12 +336,12 @@ public class StockOutOrderApi extends BaseController { /** * 自动分配 */ - @ApiOperation("自动分配") + /*@ApiOperation("自动分配") @PostMapping("/autoAssign") public AjaxResult autoAssign(@RequestBody StockOutOrderDTO stockOutOrderDTO) { StockOutOrderDO stockOutOrderDO = JSONUtil.toBean(JSONUtil.toJsonStr(stockOutOrderDTO), StockOutOrderDO.class); return toAjax(stockOutOrderApplicationService.autoAssign(stockOutOrderDO)); - } + }*/ @ApiOperation("关闭出库单")