bug更改

This commit is contained in:
秦鸿展
2026-04-22 15:21:36 +08:00
parent 1cb6b79a52
commit 882aa8740e
4 changed files with 23 additions and 42 deletions
@@ -17,7 +17,6 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -73,36 +72,6 @@ public class AssociationWarehouseApplicationService {
} }
} }
/**
* 排除「默认仓」关联(is_default=2),与 Mapper 条件双保险,避免 OGNL/参数未绑定导致仍查出默认行。
*/
private List<AssociationWarehousePO> filterExcludeDefaultWarehouse(
AssociationWarehouseDO associationWarehouseDO,
List<AssociationWarehousePO> list) {
if (!Boolean.TRUE.equals(associationWarehouseDO.getExcludeDefaultWarehouse())
|| list == null || list.isEmpty()) {
return list;
}
return list.stream()
.filter(po -> po.getIsDefault() == null || !Objects.equals(po.getIsDefault(), 2))
.collect(Collectors.toList());
}
/**
* 按「组织 + 仓库」查该仓下全部绑定(未带 correlationId)时,默认排除新建仓自动产生的默认仓关联(is_default=2)。
* 需要保留时显式传 excludeDefaultWarehouse=false。
* 仅在没有显式指定 excludeDefaultWarehouse 时生效。
*/
private void applyDefaultExcludeForWarehouseBindList(AssociationWarehouseDO associationWarehouseDO) {
if (associationWarehouseDO.getExcludeDefaultWarehouse() != null) {
return;
}
if (associationWarehouseDO.getWarehouseId() != null
&& associationWarehouseDO.getCorrelationId() == null) {
associationWarehouseDO.setExcludeDefaultWarehouse(true);
}
}
/** /**
* 分页查询关联仓库列表 * 分页查询关联仓库列表
*/ */
@@ -128,16 +97,14 @@ public class AssociationWarehouseApplicationService {
associationWarehousePO.setTopOrganizationId(warehousePO.getTopOrganizationId()); associationWarehousePO.setTopOrganizationId(warehousePO.getTopOrganizationId());
associationWarehousePOList.add(associationWarehousePO); associationWarehousePOList.add(associationWarehousePO);
}); });
return filterExcludeDefaultWarehouse(associationWarehouseDO, associationWarehousePOList); return associationWarehousePOList;
}else { }else {
applyAssociationWarehouseOrgScope(associationWarehouseDO, loginUser); applyAssociationWarehouseOrgScope(associationWarehouseDO, loginUser);
// 未指定仓库时:只查当前登录人在关联表中的记录;指定了 warehouseId 时:查该仓下全部绑定(绑定用户列表),勿收窄为当前用户 // 未指定仓库时:只查当前登录人在关联表中的记录;指定了 warehouseId 时:查该仓下全部绑定(绑定用户列表),勿收窄为当前用户
if (associationWarehouseDO.getWarehouseId() == null) { if (associationWarehouseDO.getWarehouseId() == null) {
associationWarehouseDO.setCorrelationId(loginUser.getUserid()); associationWarehouseDO.setCorrelationId(loginUser.getUserid());
} }
applyDefaultExcludeForWarehouseBindList(associationWarehouseDO); return associationWarehouseDomainService.queryList(associationWarehouseDO);
return filterExcludeDefaultWarehouse(associationWarehouseDO,
associationWarehouseDomainService.queryList(associationWarehouseDO));
} }
} }
@@ -146,9 +113,7 @@ public class AssociationWarehouseApplicationService {
if (loginUser != null && loginUser.getUserPo() != null) { if (loginUser != null && loginUser.getUserPo() != null) {
applyAssociationWarehouseOrgScope(associationWarehouseDO, loginUser); applyAssociationWarehouseOrgScope(associationWarehouseDO, loginUser);
} }
applyDefaultExcludeForWarehouseBindList(associationWarehouseDO); List<AssociationWarehousePO> associationWarehousePOList = associationWarehouseDomainService.queryList(associationWarehouseDO);
List<AssociationWarehousePO> associationWarehousePOList = filterExcludeDefaultWarehouse(associationWarehouseDO,
associationWarehouseDomainService.queryList(associationWarehouseDO));
return associationWarehousePOList.stream() return associationWarehousePOList.stream()
.map(AssociationWarehousePO::getCorrelationId) .map(AssociationWarehousePO::getCorrelationId)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -133,17 +133,30 @@ public class AssociationWarehouseImpl extends ServiceImpl<AssociationWarehouseMa
} }
/** /**
* 批量删除关联仓库 * 批量删除关联仓库。is_default=2(新建仓自动产生的默认仓绑定)不可删,调用方传入的 id 会被过滤。
*/ */
@Override @Override
public Boolean delete(Long[] associationWarehouseIds ) { public Boolean delete(Long[] associationWarehouseIds ) {
List<AssociationWarehouse> list = new ArrayList<>(); List<AssociationWarehouse> list = new ArrayList<>();
for (Long id : associationWarehouseIds) { for (Long id : associationWarehouseIds) {
if (id == null) {
continue;
}
AssociationWarehouse row = this.getById(id);
if (row == null) {
continue;
}
if (row.getIsDefault() != null && row.getIsDefault() == 2) {
continue;
}
AssociationWarehouse associationWarehouse = new AssociationWarehouse(); AssociationWarehouse associationWarehouse = new AssociationWarehouse();
associationWarehouse.setAssociationWarehouseId(id); associationWarehouse.setAssociationWarehouseId(id);
associationWarehouse.setDelFlag(2); associationWarehouse.setDelFlag(2);
list.add(associationWarehouse); list.add(associationWarehouse);
} }
if (list.isEmpty()) {
return Boolean.TRUE;
}
return this.updateBatchById(list); return this.updateBatchById(list);
} }
@@ -40,9 +40,9 @@ public class AssociationWarehouseApi extends BaseController{
private AssociationWarehouseAssembler associationWarehouseAssembler; private AssociationWarehouseAssembler associationWarehouseAssembler;
/** /**
* 分页查询关联仓库列表。按组织+仓库(warehouseId)查该仓全部绑定时,默认不返回 is_default=2默认仓关联行;需要含该条时传 excludeDefaultWarehouse=false * 分页查询关联仓库列表;含 is_default=2默认仓关联。删除时此类记录不可删
*/ */
@ApiOperation("查询关联仓库列表(按仓查绑定时默认不含 is_default=2") @ApiOperation("查询关联仓库列表")
@GetMapping("/list") @GetMapping("/list")
public AjaxResult list(AssociationWarehouseDTO associationWarehouseDTO) public AjaxResult list(AssociationWarehouseDTO associationWarehouseDTO)
{ {
@@ -52,7 +52,7 @@ public class AssociationWarehouseApi extends BaseController{
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@ApiOperation("查询仓库关联的用户 id 集合(按仓查时默认不含仅 is_default=2 的绑定)") @ApiOperation("查询仓库关联的用户 id 集合")
@GetMapping("/queryListCorrelationId") @GetMapping("/queryListCorrelationId")
public AjaxResult listUser(AssociationWarehouseDTO associationWarehouseDTO) public AjaxResult listUser(AssociationWarehouseDTO associationWarehouseDTO)
{ {
@@ -49,9 +49,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="warehouseId != null "> <if test="warehouseId != null ">
and a.warehouse_id = #{warehouseId} and a.warehouse_id = #{warehouseId}
</if> </if>
<!-- 查询含 is_default=2 的默认仓关联行;is_default=2 仅在删除/保存绑定时在 Service 中过滤,不再在 SQL 中排除 -->
<!--
<if test="excludeDefaultWarehouse != null and excludeDefaultWarehouse"> <if test="excludeDefaultWarehouse != null and excludeDefaultWarehouse">
and (a.is_default is null or a.is_default &lt;&gt; 2) and (a.is_default is null or a.is_default &lt;&gt; 2)
</if> </if>
-->
<if test="warehouseCode != null and warehouseCode != ''"> <if test="warehouseCode != null and warehouseCode != ''">
and a.warehouse_code = #{warehouseCode} and a.warehouse_code = #{warehouseCode}
</if> </if>