新建的仓库需要默认绑定当前登录账号

3.仓库绑定用户时只查询非默认用户IS_DEFAULT=1
This commit is contained in:
秦鸿展
2026-04-20 23:47:19 +08:00
parent 9da405b7f2
commit 70936024a8
9 changed files with 241 additions and 34 deletions
@@ -1,10 +1,11 @@
package com.mhd.basic.application.service.associationWarehouse; package com.mhd.basic.application.service.associationWarehouse;
import com.mhd.basic.application.service.warehouse.WarehouseApplicationService;
import com.mhd.basic.domain.warehouse.repository.po.WarehousePO; import com.mhd.basic.domain.warehouse.repository.po.WarehousePO;
import com.mhd.basic.domain.warehouse.repository.todo.WarehouseDO; import com.mhd.basic.domain.warehouse.repository.todo.WarehouseDO;
import com.mhd.basic.domain.warehouse.service.WarehouseDomainService;
import com.mhd.common.core.enums.RoleEnum; import com.mhd.common.core.enums.RoleEnum;
import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO; import com.mhd.system.api.domain.cache.AssociationWarehouseCacheDO;
import com.mhd.basic.common.org.OrganizationQueryScope;
import com.mhd.basic.domain.associationWarehouse.repository.po.AssociationWarehousePO; import com.mhd.basic.domain.associationWarehouse.repository.po.AssociationWarehousePO;
import com.mhd.basic.domain.associationWarehouse.repository.todo.AssociationWarehouseDO; import com.mhd.basic.domain.associationWarehouse.repository.todo.AssociationWarehouseDO;
import com.mhd.basic.domain.associationWarehouse.service.AssociationWarehouseDomainService; import com.mhd.basic.domain.associationWarehouse.service.AssociationWarehouseDomainService;
@@ -16,6 +17,7 @@ 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;
/** /**
@@ -30,8 +32,76 @@ public class AssociationWarehouseApplicationService {
@Autowired @Autowired
private AssociationWarehouseDomainService associationWarehouseDomainService; private AssociationWarehouseDomainService associationWarehouseDomainService;
@Autowired @Autowired
private WarehouseDomainService warehouseDomainService; private WarehouseApplicationService warehouseApplicationService;
/**
* 与 {@link com.mhd.basic.application.service.materialClassify.MaterialClassifyApplicationService#queryList} 一致的组织数据权限
*/
private void applyAssociationWarehouseOrgScope(AssociationWarehouseDO associationWarehouseDO, LoginUser loginUser) {
if (loginUser == null || loginUser.getUserPo() == null) {
return;
}
Long userOrganizationId = OrganizationQueryScope.resolveLoginOrganizationId(loginUser);
Long frontendOrganizationId = associationWarehouseDO.getOrganizationId();
if (userOrganizationId != null && userOrganizationId.equals(2827L)) {
if (frontendOrganizationId != null) {
associationWarehouseDO.setOrganizationId(frontendOrganizationId);
associationWarehouseDO.setTopOrganizationId(null);
} else {
associationWarehouseDO.setOrganizationId(null);
associationWarehouseDO.setTopOrganizationId(null);
}
} else {
if (frontendOrganizationId != null && userOrganizationId != null) {
if (!frontendOrganizationId.equals(userOrganizationId)) {
associationWarehouseDO.setOrganizationId(userOrganizationId);
}
} else {
if (userOrganizationId != null) {
associationWarehouseDO.setOrganizationId(userOrganizationId);
}
}
if (associationWarehouseDO.getOrganizationId() == null) {
Long topOrganizationId = loginUser.getUserPo().getTopOrganizationId();
if (topOrganizationId != null && topOrganizationId != 1) {
associationWarehouseDO.setTopOrganizationId(topOrganizationId);
}
} else {
associationWarehouseDO.setTopOrganizationId(null);
}
}
}
/**
* 排除「默认仓」关联(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);
}
}
/** /**
* 分页查询关联仓库列表 * 分页查询关联仓库列表
@@ -40,11 +110,13 @@ public class AssociationWarehouseApplicationService {
public List<AssociationWarehousePO> queryList(AssociationWarehouseDO associationWarehouseDO) { public List<AssociationWarehousePO> queryList(AssociationWarehouseDO associationWarehouseDO) {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser.getUserPo().getRoleCode().equals(RoleEnum.SUPER_ADMIN.getCode()) || loginUser.getUserPo().getRoleCode().equals(RoleEnum.PLAT_ADMIN.getCode())){ if (loginUser.getUserPo().getRoleCode().equals(RoleEnum.SUPER_ADMIN.getCode()) || loginUser.getUserPo().getRoleCode().equals(RoleEnum.PLAT_ADMIN.getCode())){
// 与 warehouseApi/list 一致:走 WarehouseApplicationService,尊重请求中的 organizationId / top 等条件,不能使用空的 WarehouseDO 直查询库
WarehouseDO warehouseDO = new WarehouseDO(); WarehouseDO warehouseDO = new WarehouseDO();
if (loginUser.getUserPo().getRoleCode().equals(RoleEnum.PLAT_ADMIN.getCode())){ warehouseDO.setOrganizationId(associationWarehouseDO.getOrganizationId());
warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); warehouseDO.setTopOrganizationId(associationWarehouseDO.getTopOrganizationId());
} warehouseDO.setWarehouseCode(associationWarehouseDO.getWarehouseCode());
List<WarehousePO> warehousePOList = warehouseDomainService.queryList(warehouseDO); warehouseDO.setWarehouseName(associationWarehouseDO.getWarehouseName());
List<WarehousePO> warehousePOList = warehouseApplicationService.queryList(warehouseDO);
List<AssociationWarehousePO> associationWarehousePOList = new ArrayList<>(); List<AssociationWarehousePO> associationWarehousePOList = new ArrayList<>();
warehousePOList.forEach(warehousePO -> { warehousePOList.forEach(warehousePO -> {
AssociationWarehousePO associationWarehousePO = new AssociationWarehousePO(); AssociationWarehousePO associationWarehousePO = new AssociationWarehousePO();
@@ -56,18 +128,27 @@ public class AssociationWarehouseApplicationService {
associationWarehousePO.setTopOrganizationId(warehousePO.getTopOrganizationId()); associationWarehousePO.setTopOrganizationId(warehousePO.getTopOrganizationId());
associationWarehousePOList.add(associationWarehousePO); associationWarehousePOList.add(associationWarehousePO);
}); });
return associationWarehousePOList; return filterExcludeDefaultWarehouse(associationWarehouseDO, associationWarehousePOList);
}else { }else {
associationWarehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); applyAssociationWarehouseOrgScope(associationWarehouseDO, loginUser);
// 未指定仓库时:只查当前登录人在关联表中的记录;指定了 warehouseId 时:查该仓下全部绑定(绑定用户列表),勿收窄为当前用户
if (associationWarehouseDO.getWarehouseId() == null) {
associationWarehouseDO.setCorrelationId(loginUser.getUserid()); associationWarehouseDO.setCorrelationId(loginUser.getUserid());
return associationWarehouseDomainService.queryList(associationWarehouseDO); }
applyDefaultExcludeForWarehouseBindList(associationWarehouseDO);
return filterExcludeDefaultWarehouse(associationWarehouseDO,
associationWarehouseDomainService.queryList(associationWarehouseDO));
} }
} }
public List<Long> queryListCorrelationId(AssociationWarehouseDO associationWarehouseDO) { public List<Long> queryListCorrelationId(AssociationWarehouseDO associationWarehouseDO) {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
associationWarehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); if (loginUser != null && loginUser.getUserPo() != null) {
List<AssociationWarehousePO> associationWarehousePOList = associationWarehouseDomainService.queryList(associationWarehouseDO); applyAssociationWarehouseOrgScope(associationWarehouseDO, loginUser);
}
applyDefaultExcludeForWarehouseBindList(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());
@@ -2,9 +2,11 @@ package com.mhd.basic.application.service.warehouse;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.mhd.basic.domain.associationWarehouse.entity.AssociationWarehouse; import com.mhd.basic.domain.associationWarehouse.entity.AssociationWarehouse;
import com.mhd.basic.domain.associationWarehouse.repository.facade.IAssociationWarehouseService; import com.mhd.basic.domain.associationWarehouse.repository.facade.IAssociationWarehouseService;
import com.mhd.basic.domain.warehouse.repository.po.WarehousePO; import com.mhd.basic.domain.warehouse.repository.po.WarehousePO;
import com.mhd.basic.common.org.OrganizationQueryScope;
import com.mhd.basic.domain.warehouse.repository.po.po.WarehouseLinkagePO; import com.mhd.basic.domain.warehouse.repository.po.po.WarehouseLinkagePO;
import com.mhd.basic.domain.warehouse.repository.todo.WarehouseDO; import com.mhd.basic.domain.warehouse.repository.todo.WarehouseDO;
import com.mhd.basic.domain.warehouse.service.WarehouseDomainService; import com.mhd.basic.domain.warehouse.service.WarehouseDomainService;
@@ -17,9 +19,12 @@ import com.mhd.system.service.ISysDictTypeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import com.mhd.common.core.utils.StringUtils;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -46,7 +51,7 @@ public class WarehouseApplicationService {
public List<WarehousePO> queryList(WarehouseDO warehouseDO) { public List<WarehousePO> queryList(WarehouseDO warehouseDO) {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) { if (loginUser != null && loginUser.getUserPo() != null) {
Long userOrganizationId = loginUser.getUserPo().getOrganizationId(); Long userOrganizationId = OrganizationQueryScope.resolveLoginOrganizationId(loginUser);
Long frontendOrganizationId = warehouseDO.getOrganizationId(); // 前端传递的 organizationId Long frontendOrganizationId = warehouseDO.getOrganizationId(); // 前端传递的 organizationId
// 数据权限:根据 organizationId 来设置查询权限 // 数据权限:根据 organizationId 来设置查询权限
@@ -127,19 +132,100 @@ public class WarehouseApplicationService {
/** /**
* 新增仓库 * 新增仓库(写入主表后默认在 association_warehouse 绑定当前登录用户,便于按绑定关系展示)
*/ */
@Transactional(rollbackFor = Exception.class)
public Boolean insert(WarehouseDO warehouseDO) { public Boolean insert(WarehouseDO warehouseDO) {
// 设置当前登录用户的组织信息
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
if (loginUser != null && loginUser.getUserPo() != null) { if (loginUser != null) {
Long orgId = OrganizationQueryScope.resolveLoginOrganizationId(loginUser);
if (orgId != null) {
warehouseDO.setOrganizationId(orgId);
} else if (loginUser.getUserPo() != null && loginUser.getUserPo().getOrganizationId() != null) {
warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId()); warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
warehouseDO.setOrganizationName(loginUser.getUserPo().getOrganizationName()); }
String orgName = null;
if (loginUser.getUserPo() != null && StringUtils.isNotEmpty(loginUser.getUserPo().getOrganizationName())) {
orgName = loginUser.getUserPo().getOrganizationName();
}
if (StringUtils.isEmpty(orgName) && loginUser.getOrganizationPo() != null) {
orgName = loginUser.getOrganizationPo().getOrganizationName();
}
if (StringUtils.isNotEmpty(orgName)) {
warehouseDO.setOrganizationName(orgName);
}
if (loginUser.getUserPo() != null && loginUser.getUserPo().getTopOrganizationId() != null) {
warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
} }
if (loginUser.getUserid() != null) {
if (warehouseDO.getCreateBy() == null) {
warehouseDO.setCreateBy(loginUser.getUserid());
}
if (warehouseDO.getUpdateBy() == null) {
warehouseDO.setUpdateBy(loginUser.getUserid());
}
}
if (StringUtils.isEmpty(warehouseDO.getCreateByName())) {
String showName = loginUser.getUsername();
if (loginUser.getUserPo() != null && StringUtils.isNotEmpty(loginUser.getUserPo().getUserName())) {
showName = loginUser.getUserPo().getUserName();
}
warehouseDO.setCreateByName(showName);
}
if (StringUtils.isEmpty(warehouseDO.getUpdateByName())) {
String showName = loginUser.getUsername();
if (loginUser.getUserPo() != null && StringUtils.isNotEmpty(loginUser.getUserPo().getUserName())) {
showName = loginUser.getUserPo().getUserName();
}
warehouseDO.setUpdateByName(showName);
}
}
//设置数据字典键值 //设置数据字典键值
setDataDict(warehouseDO); setDataDict(warehouseDO);
return warehouseDomainService.insert(warehouseDO); Boolean ok = warehouseDomainService.insert(warehouseDO);
if (Boolean.TRUE.equals(ok) && warehouseDO.getWarehouseId() != null && loginUser != null && loginUser.getUserid() != null) {
saveDefaultUserWarehouseAssociation(warehouseDO, loginUser);
}
return ok;
}
/**
* 新增仓库后默认关联当前用户(若已存在相同仓库+用户则跳过)
*/
private void saveDefaultUserWarehouseAssociation(WarehouseDO warehouseDO, LoginUser loginUser) {
long exists = associationWarehouseService.count(new QueryWrapper<AssociationWarehouse>().lambda()
.eq(AssociationWarehouse::getWarehouseId, warehouseDO.getWarehouseId())
.eq(AssociationWarehouse::getCorrelationId, loginUser.getUserid())
.eq(AssociationWarehouse::getDelFlag, 1));
if (exists > 0) {
return;
}
String createName = loginUser.getUsername();
if (loginUser.getUserPo() != null && StringUtils.isNotEmpty(loginUser.getUserPo().getUserName())) {
createName = loginUser.getUserPo().getUserName();
}
// 与切换默认仓一致:先取消该用户下其它「默认」,再绑定新建仓库为默认(is_default: 1-否 2-是)
associationWarehouseService.update(null, new UpdateWrapper<AssociationWarehouse>().lambda()
.set(AssociationWarehouse::getIsDefault, 1)
.set(AssociationWarehouse::getUpdateBy, loginUser.getUserid())
.set(AssociationWarehouse::getUpdateByName, createName)
.eq(AssociationWarehouse::getCorrelationId, loginUser.getUserid())
.eq(AssociationWarehouse::getIsDefault, 2)
.eq(AssociationWarehouse::getDelFlag, 1));
AssociationWarehouse row = new AssociationWarehouse();
row.setWarehouseId(warehouseDO.getWarehouseId());
row.setWarehouseCode(warehouseDO.getWarehouseCode());
row.setWarehouseName(warehouseDO.getWarehouseName());
row.setCorrelationId(loginUser.getUserid());
row.setOrganizationId(warehouseDO.getOrganizationId());
row.setOrganizationName(warehouseDO.getOrganizationName());
row.setTopOrganizationId(warehouseDO.getTopOrganizationId());
row.setDelFlag(1);
row.setIsDefault(2);
row.setCreateBy(loginUser.getUserid());
row.setCreateByName(createName);
row.setCreateTime(new Date());
associationWarehouseService.save(row);
} }
/** /**
@@ -121,9 +121,13 @@ public class AssociationWarehouseImpl extends ServiceImpl<AssociationWarehouseMa
associationWarehouse.setCreateTime(new Date()); associationWarehouse.setCreateTime(new Date());
associationWarehouseList.add(associationWarehouse); associationWarehouseList.add(associationWarehouse);
} }
//标记删除 // 先删该仓下「非默认仓」绑定,再批量插入本次提交的用户;保留 is_default=2(如新建仓自动写入的创建人默认仓),避免前端列表不展示该条却全量保存时被误删
remove(new QueryWrapper<AssociationWarehouse>().lambda() remove(new QueryWrapper<AssociationWarehouse>().lambda()
.eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId())); .eq(AssociationWarehouse::getWarehouseId, associationWarehouseDO.getWarehouseId())
.eq(AssociationWarehouse::getDelFlag, 1)
.and(w -> w.isNull(AssociationWarehouse::getIsDefault)
.or()
.ne(AssociationWarehouse::getIsDefault, 2)));
} }
return saveBatch(associationWarehouseList); return saveBatch(associationWarehouseList);
} }
@@ -69,6 +69,11 @@ public class AssociationWarehouseDO extends BaseVOEntity{
@ApiModelProperty(name = "关联用户id集合") @ApiModelProperty(name = "关联用户id集合")
private List<Long> correlationIdList; private List<Long> correlationIdList;
/**
* 为 true 时查询排除「默认仓」关联(is_default=2),例如绑定用户列表不展示新建仓时自动生成的创建人默认关联。
*/
private Boolean excludeDefaultWarehouse;
@ApiModelProperty("是否批量: 1-是 2-否 ") @ApiModelProperty("是否批量: 1-是 2-否 ")
@Excel(name = "是否批量: 1-是 2-否 ") @Excel(name = "是否批量: 1-是 2-否 ")
private Integer isBatch; private Integer isBatch;
@@ -40,7 +40,11 @@ public class WarehouseImpl extends ServiceImpl<WarehouseMapper, Warehouse> imple
public Boolean insert(WarehouseDO warehouseDO) { public Boolean insert(WarehouseDO warehouseDO) {
Warehouse warehouse = new Warehouse(); Warehouse warehouse = new Warehouse();
BeanUtils.copyProperties(warehouseDO,warehouse); BeanUtils.copyProperties(warehouseDO,warehouse);
return this.save(warehouse); boolean saved = this.save(warehouse);
if (saved && warehouse.getWarehouseId() != null) {
warehouseDO.setWarehouseId(warehouse.getWarehouseId());
}
return saved;
} }
/** /**
@@ -1,10 +1,12 @@
package com.mhd.basic.interfaces.assember.warehouse; package com.mhd.basic.interfaces.assember.warehouse;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.mhd.basic.common.org.OrganizationQueryScope;
import com.mhd.basic.domain.warehouse.repository.todo.WarehouseDO; import com.mhd.basic.domain.warehouse.repository.todo.WarehouseDO;
import com.mhd.basic.interfaces.dto.warehouse.WarehouseDTO; import com.mhd.basic.interfaces.dto.warehouse.WarehouseDTO;
import com.mhd.common.core.exception.digitalLogisticsException.DigitalLogisticsException; import com.mhd.common.core.exception.digitalLogisticsException.DigitalLogisticsException;
import com.mhd.common.core.exception.digitalLogisticsException.UserError; import com.mhd.common.core.exception.digitalLogisticsException.UserError;
import com.mhd.common.core.utils.StringUtils;
import com.mhd.common.core.utils.bean.BeanUtils; import com.mhd.common.core.utils.bean.BeanUtils;
import com.mhd.common.core.utils.IgnoreNullUtil; import com.mhd.common.core.utils.IgnoreNullUtil;
import com.mhd.common.security.utils.SecurityUtils; import com.mhd.common.security.utils.SecurityUtils;
@@ -63,11 +65,26 @@ public class WarehouseAssembler {
warehouseDO.setCreateBy(new Long("0")); warehouseDO.setCreateBy(new Long("0"));
warehouseDO.setUpdateBy(new Long("0")); warehouseDO.setUpdateBy(new Long("0"));
} }
Long orgId = OrganizationQueryScope.resolveLoginOrganizationId(loginUser);
if (orgId != null) {
warehouseDO.setOrganizationId(orgId);
} else if (loginUser.getUserPo() != null) {
warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId()); warehouseDO.setOrganizationId(loginUser.getUserPo().getOrganizationId());
warehouseDO.setOrganizationName(loginUser.getUserPo().getOrganizationName()); }
String orgName = loginUser.getUserPo() != null ? loginUser.getUserPo().getOrganizationName() : null;
if (StringUtils.isEmpty(orgName) && loginUser.getOrganizationPo() != null) {
orgName = loginUser.getOrganizationPo().getOrganizationName();
}
warehouseDO.setOrganizationName(orgName);
if (loginUser.getUserPo() != null) {
warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId()); warehouseDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
warehouseDO.setCreateByName(userName); }
warehouseDO.setUpdateByName(userName); String displayName = userName;
if (loginUser.getUserPo() != null && StringUtils.isNotEmpty(loginUser.getUserPo().getUserName())) {
displayName = loginUser.getUserPo().getUserName();
}
warehouseDO.setCreateByName(displayName);
warehouseDO.setUpdateByName(displayName);
warehouseDO.setCreateTime(new Date()); warehouseDO.setCreateTime(new Date());
warehouseDO.setUpdateTime(new Date()); warehouseDO.setUpdateTime(new Date());
warehouseDO.setDelFlag(1); warehouseDO.setDelFlag(1);
@@ -68,4 +68,7 @@ public class AssociationWarehouseDTO extends BaseVOEntity{
@ApiModelProperty(name = "关联用户id集合") @ApiModelProperty(name = "关联用户id集合")
private List<Long> correlationIdList; private List<Long> correlationIdList;
@ApiModelProperty("是否排除默认仓关联(is_default=2)。按仓查询且未带 correlationId 时后端默认可为 true;需要包含默认行时传 false")
private Boolean excludeDefaultWarehouse;
} }
@@ -40,19 +40,19 @@ public class AssociationWarehouseApi extends BaseController{
private AssociationWarehouseAssembler associationWarehouseAssembler; private AssociationWarehouseAssembler associationWarehouseAssembler;
/** /**
* 分页查询关联仓库列表 * 分页查询关联仓库列表。按组织+仓库(warehouseId)查该仓全部绑定时,默认不返回 is_default=2(默认仓)关联行;需要含该条时传 excludeDefaultWarehouse=false。
*/ */
@ApiOperation("查询关联仓库列表") @ApiOperation("查询关联仓库列表(按仓查绑定时默认不含 is_default=2")
@GetMapping("/list") @GetMapping("/list")
public AjaxResult list(AssociationWarehouseDTO associationWarehouseDTO) public AjaxResult list(AssociationWarehouseDTO associationWarehouseDTO)
{ {
//转换实体 //转换实体(组织数据权限在 AssociationWarehouseApplicationService 与其它模块对齐)
AssociationWarehouseDO associationWarehouseDO = associationWarehouseAssembler.toDO(associationWarehouseDTO); AssociationWarehouseDO associationWarehouseDO = associationWarehouseAssembler.toDO(associationWarehouseDTO);
List<AssociationWarehousePO> list = associationWarehouseApplicationService.queryList(associationWarehouseDO); List<AssociationWarehousePO> list = associationWarehouseApplicationService.queryList(associationWarehouseDO);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
@ApiOperation("查询仓库关联的用户集合") @ApiOperation("查询仓库关联的用户 id 集合(按仓查时默认不含仅 is_default=2 的绑定)")
@GetMapping("/queryListCorrelationId") @GetMapping("/queryListCorrelationId")
public AjaxResult listUser(AssociationWarehouseDTO associationWarehouseDTO) public AjaxResult listUser(AssociationWarehouseDTO associationWarehouseDTO)
{ {
@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="organizationName" column="organization_name" /> <result property="organizationName" column="organization_name" />
<result property="topOrganizationId" column="top_organization_id" /> <result property="topOrganizationId" column="top_organization_id" />
<result property="correlationId" column="correlation_id" /> <result property="correlationId" column="correlation_id" />
<result property="isDefault" column="is_default" />
<result property="warehouseId" column="warehouse_id" /> <result property="warehouseId" column="warehouse_id" />
<result property="warehouseCode" column="warehouse_code" /> <result property="warehouseCode" column="warehouse_code" />
<result property="warehouseName" column="warehouse_name" /> <result property="warehouseName" column="warehouse_name" />
@@ -25,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectAssociationWarehousePo"> <sql id="selectAssociationWarehousePo">
a.association_warehouse_id, a.organization_id, a.organization_name, a.top_organization_id, a.association_warehouse_id, a.organization_id, a.organization_name, a.top_organization_id,
a.correlation_id, a.warehouse_id, a.warehouse_code, a.warehouse_name, a.create_time, a.correlation_id, a.is_default, a.warehouse_id, a.warehouse_code, a.warehouse_name, a.create_time,
a.create_by, a.create_by_name, a.update_time, a.update_by, a.update_by_name, a.del_flag a.create_by, a.create_by_name, a.update_time, a.update_by, a.update_by_name, a.del_flag
</sql> </sql>
@@ -42,9 +43,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="correlationId != null "> <if test="correlationId != null ">
and a.correlation_id = #{correlationId} and a.correlation_id = #{correlationId}
</if> </if>
<if test="isDefault != null ">
and a.is_default = #{isDefault}
</if>
<if test="warehouseId != null "> <if test="warehouseId != null ">
and a.warehouse_id = #{warehouseId} and a.warehouse_id = #{warehouseId}
</if> </if>
<if test="excludeDefaultWarehouse != null and excludeDefaultWarehouse">
and (a.is_default is null or a.is_default &lt;&gt; 2)
</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>