|
@@ -43,134 +43,164 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
* @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
+ /**
|
|
|
+ * 树形结构查询(连表)
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public RPCBaseResponse<List<ShopWarehouseVo>> getWarehouseCountryForm(ShopWarehouseDto dto) {
|
|
|
// 查询所有库房数据
|
|
|
- LambdaQueryWrapper<ShopWarehouse> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- List<ShopWarehouse> shopWarehouseList = super.getListLink(queryWrapper);
|
|
|
+ List<ShopWarehouse> shopWarehouseList = super.getListLink(new LambdaQueryWrapper<>());
|
|
|
|
|
|
// 提取国家服务ID
|
|
|
Set<String> countryServeIds = shopWarehouseList.stream()
|
|
|
.map(ShopWarehouse::getCountryServeId)
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
- // 创建一个 Map 以便通过 countryServeId 查询到对应的国家数据
|
|
|
- Map<String, BaseCountryServeVo> baseCountryServeVoMap = new HashMap<>();
|
|
|
- if (!countryServeIds.isEmpty()) {
|
|
|
- // 使用 getFormId 方法查询国家信息
|
|
|
- for (String countryServeId : countryServeIds) {
|
|
|
- RPCBaseResponse<BaseCountryServeVo> response = countryAdapter.getFormId(countryServeId);
|
|
|
- if (response != null && response.getData() != null) {
|
|
|
- baseCountryServeVoMap.put(countryServeId, response.getData());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 查询国家信息
|
|
|
+ Map<String, BaseCountryServeVo> baseCountryServeVoMap = fetchCountryData(countryServeIds);
|
|
|
+
|
|
|
+ // 提取仓库 ID
|
|
|
+ Set<Long> ids = shopWarehouseList.stream()
|
|
|
+ .map(ShopWarehouse::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 获取用户和角色信息
|
|
|
+ Map<Long, List<ShopWarehouseStaffVo>> staffMap = fetchWarehouseTenantRoles(ids);
|
|
|
|
|
|
- // 创建一个 Map 用于快速查找每个仓库的父子关系
|
|
|
+ // 构建树形结构
|
|
|
Map<Long, ShopWarehouseVo> warehouseVoMap = new HashMap<>();
|
|
|
List<ShopWarehouseVo> tree = new ArrayList<>();
|
|
|
|
|
|
- // 一次性处理以创建树形结构
|
|
|
for (ShopWarehouse shopWarehouse : shopWarehouseList) {
|
|
|
- ShopWarehouseVo shopWarehouseVo = new ShopWarehouseVo();
|
|
|
- shopWarehouseVo.setId(shopWarehouse.getId());
|
|
|
- shopWarehouseVo.setCountryServeId(shopWarehouse.getCountryServeId());
|
|
|
- shopWarehouseVo.setWarehouseName(shopWarehouse.getWarehouseName());
|
|
|
- shopWarehouseVo.setLongitude(shopWarehouse.getLongitude());
|
|
|
- shopWarehouseVo.setLatitude(shopWarehouse.getLatitude());
|
|
|
- shopWarehouseVo.setDetailedAddress(shopWarehouse.getDetailedAddress());
|
|
|
- shopWarehouseVo.setStatus(shopWarehouse.getStatus());
|
|
|
- shopWarehouseVo.setParentId(shopWarehouse.getParentId());
|
|
|
- shopWarehouseVo.setDeleteFlag(shopWarehouse.getDeleteFlag());
|
|
|
- shopWarehouseVo.setMap(new HashMap<>());
|
|
|
-
|
|
|
- // 将国家信息放入 Map 中
|
|
|
- if (baseCountryServeVoMap.containsKey(shopWarehouse.getCountryServeId())) {
|
|
|
- shopWarehouseVo.getMap().put("countryServe", baseCountryServeVoMap.get(shopWarehouse.getCountryServeId()));
|
|
|
- }
|
|
|
-
|
|
|
- // 存储到 warehouseVoMap
|
|
|
+ ShopWarehouseVo shopWarehouseVo = mapToWarehouseVo(shopWarehouse, baseCountryServeVoMap, staffMap);
|
|
|
warehouseVoMap.put(shopWarehouse.getId(), shopWarehouseVo);
|
|
|
-
|
|
|
- // 添加到树或其父节点
|
|
|
- if (shopWarehouse.getParentId() == null || shopWarehouse.getParentId() == 0) {
|
|
|
- // 顶级节点
|
|
|
- tree.add(shopWarehouseVo);
|
|
|
- } else {
|
|
|
- // 非顶级节点,查找其父节点并添加到 children
|
|
|
- ShopWarehouseVo parentVo = warehouseVoMap.get(shopWarehouse.getParentId());
|
|
|
- if (parentVo != null) {
|
|
|
- if (parentVo.getChildren() == null) {
|
|
|
- parentVo.setChildren(new ArrayList<>());
|
|
|
- }
|
|
|
- parentVo.getChildren().add(shopWarehouseVo);
|
|
|
- }
|
|
|
- }
|
|
|
+ addToTree(tree, shopWarehouseVo, warehouseVoMap);
|
|
|
}
|
|
|
|
|
|
- // 返回树形结构
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", tree);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 分页动态查询(连表)
|
|
|
- * @param dto
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
public RPCBaseResponse<IPage<ShopWarehouseVo>> getWarehouseCountryPageForm(ShopWarehouseDto dto) {
|
|
|
// 创建分页对象
|
|
|
Page<ShopWarehouseVo> shopWarehousePage = new Page<>(dto.getCurrentPage(), dto.getPageSize());
|
|
|
|
|
|
- // 计算 OFFSET
|
|
|
- int offset = (int) ((dto.getCurrentPage() - 1) * dto.getPageSize());
|
|
|
-
|
|
|
- // 创建查询包装器
|
|
|
- LambdaQueryWrapper<ShopWarehouse> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
-
|
|
|
- // 动态添加查询条件
|
|
|
- if (dto.getWarehouseName() != null && !dto.getWarehouseName().isEmpty()) {
|
|
|
- queryWrapper.like(ShopWarehouse::getWarehouseName, dto.getWarehouseName());
|
|
|
- }
|
|
|
- if (dto.getCreateTime() != null) {
|
|
|
- queryWrapper.ge(ShopWarehouse::getCreateTime, dto.getCreateTime());
|
|
|
- }
|
|
|
- if (dto.getParentId() != null) {
|
|
|
- queryWrapper.eq(ShopWarehouse::getParentId, dto.getParentId());
|
|
|
- }
|
|
|
- if (dto.getDetailedAddress() != null && !dto.getDetailedAddress().isEmpty()) {
|
|
|
- queryWrapper.like(ShopWarehouse::getDetailedAddress, dto.getDetailedAddress());
|
|
|
- }
|
|
|
- if (dto.getStatus() != null) {
|
|
|
- queryWrapper.eq(ShopWarehouse::getStatus, dto.getStatus());
|
|
|
- }
|
|
|
- queryWrapper.eq(ShopWarehouse::getDeleteFlag, 0); // 查询未删除的记录
|
|
|
-
|
|
|
- // 执行查询,获取分页的库房数据
|
|
|
+ // 查询库房数据并计算总记录数
|
|
|
List<ShopWarehouseVo> warehouseList = shopWarehouseMapper.selectWarehouseWithCountry(
|
|
|
dto.getWarehouseName(),
|
|
|
dto.getStatus(),
|
|
|
dto.getParentId(),
|
|
|
dto.getPageSize(),
|
|
|
- offset
|
|
|
+ (int) ((dto.getCurrentPage() - 1) * dto.getPageSize())
|
|
|
);
|
|
|
-
|
|
|
- // 计算总记录数
|
|
|
int total = shopWarehouseMapper.countWarehouseWithCountry(dto.getWarehouseName(), dto.getStatus(), dto.getParentId());
|
|
|
|
|
|
- // 创建新的分页对象用于存储 ShopWarehouseVo
|
|
|
+ // 提取国家服务ID
|
|
|
+ Set<String> countryServeIds = warehouseList.stream()
|
|
|
+ .map(ShopWarehouseVo::getCountryServeId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 查询国家信息
|
|
|
+ Map<String, BaseCountryServeVo> baseCountryServeVoMap = fetchCountryData(countryServeIds);
|
|
|
+
|
|
|
+ // 提取仓库 ID
|
|
|
+ Set<Long> ids = warehouseList.stream()
|
|
|
+ .map(ShopWarehouseVo::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 获取用户和角色信息
|
|
|
+ Map<Long, List<ShopWarehouseStaffVo>> staffMap = fetchWarehouseTenantRoles(ids);
|
|
|
+
|
|
|
+ // 将国家信息和用户角色信息放入对应的仓库列表项中
|
|
|
+ for (ShopWarehouseVo warehouseVo : warehouseList) {
|
|
|
+ if (baseCountryServeVoMap.containsKey(warehouseVo.getCountryServeId())) {
|
|
|
+ warehouseVo.setMap(new HashMap<>()); // 初始化 map
|
|
|
+ warehouseVo.getMap().put("countryServe", baseCountryServeVoMap.get(warehouseVo.getCountryServeId()));
|
|
|
+ }
|
|
|
+ if (staffMap.containsKey(warehouseVo.getId())) {
|
|
|
+ warehouseVo.getMap().put("roles", staffMap.get(warehouseVo.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 封装返回
|
|
|
IPage<ShopWarehouseVo> pageVoLink = new Page<>();
|
|
|
pageVoLink.setRecords(warehouseList); // 设置转换后的记录列表
|
|
|
pageVoLink.setTotal(total); // 设置总条数
|
|
|
pageVoLink.setCurrent(shopWarehousePage.getCurrent()); // 设置当前页
|
|
|
pageVoLink.setSize(shopWarehousePage.getSize()); // 设置每页大小
|
|
|
|
|
|
- // 封装返回
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", pageVoLink);
|
|
|
}
|
|
|
|
|
|
+ private Map<String, BaseCountryServeVo> fetchCountryData(Set<String> countryServeIds) {
|
|
|
+ Map<String, BaseCountryServeVo> countryMap = new HashMap<>();
|
|
|
+ if (!countryServeIds.isEmpty()) {
|
|
|
+ for (String countryServeId : countryServeIds) {
|
|
|
+ RPCBaseResponse<BaseCountryServeVo> response = countryAdapter.getFormId(countryServeId);
|
|
|
+ if (response != null && response.getData() != null) {
|
|
|
+ countryMap.put(countryServeId, response.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return countryMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<Long, List<ShopWarehouseStaffVo>> fetchWarehouseTenantRoles(Set<Long> ids) {
|
|
|
+ Map<Long, List<ShopWarehouseStaffVo>> staffMap = new HashMap<>();
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ RPCBaseResponse<List<ShopWarehouseStaffVo>> response = getWarehouseTenantRole(String.valueOf(id));
|
|
|
+ if (response != null && response.getData() != null) {
|
|
|
+ staffMap.put(id, response.getData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return staffMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ShopWarehouseVo mapToWarehouseVo(ShopWarehouse shopWarehouse,
|
|
|
+ Map<String, BaseCountryServeVo> countryMap,
|
|
|
+ Map<Long, List<ShopWarehouseStaffVo>> staffMap) {
|
|
|
+ ShopWarehouseVo shopWarehouseVo = new ShopWarehouseVo();
|
|
|
+ shopWarehouseVo.setId(shopWarehouse.getId());
|
|
|
+ shopWarehouseVo.setCountryServeId(shopWarehouse.getCountryServeId());
|
|
|
+ shopWarehouseVo.setWarehouseName(shopWarehouse.getWarehouseName());
|
|
|
+ shopWarehouseVo.setLongitude(shopWarehouse.getLongitude());
|
|
|
+ shopWarehouseVo.setLatitude(shopWarehouse.getLatitude());
|
|
|
+ shopWarehouseVo.setDetailedAddress(shopWarehouse.getDetailedAddress());
|
|
|
+ shopWarehouseVo.setStatus(shopWarehouse.getStatus());
|
|
|
+ shopWarehouseVo.setParentId(shopWarehouse.getParentId());
|
|
|
+ shopWarehouseVo.setDeleteFlag(shopWarehouse.getDeleteFlag());
|
|
|
+ shopWarehouseVo.setMap(new HashMap<>());
|
|
|
+
|
|
|
+ if (countryMap.containsKey(shopWarehouse.getCountryServeId())) {
|
|
|
+ shopWarehouseVo.getMap().put("countryServe", countryMap.get(shopWarehouse.getCountryServeId()));
|
|
|
+ }
|
|
|
+ if (staffMap.containsKey(shopWarehouse.getId())) {
|
|
|
+ shopWarehouseVo.getMap().put("roles", staffMap.get(shopWarehouse.getId()));
|
|
|
+ }
|
|
|
+ return shopWarehouseVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addToTree(List<ShopWarehouseVo> tree, ShopWarehouseVo warehouseVo, Map<Long, ShopWarehouseVo> warehouseVoMap) {
|
|
|
+ if (warehouseVo.getParentId() == null || warehouseVo.getParentId() == 0) {
|
|
|
+ tree.add(warehouseVo);
|
|
|
+ } else {
|
|
|
+ ShopWarehouseVo parentVo = warehouseVoMap.get(warehouseVo.getParentId());
|
|
|
+ if (parentVo != null) {
|
|
|
+ if (parentVo.getChildren() == null) {
|
|
|
+ parentVo.setChildren(new ArrayList<>());
|
|
|
+ }
|
|
|
+ parentVo.getChildren().add(warehouseVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 库房关联人员(角色)查询
|
|
|
+ * 库房关联人员(角色)查询,通过库房id,查询用户以及角色
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
@@ -231,6 +261,8 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
if (user != null) {
|
|
|
result.setTenantSurname(user.getTenantSurname());
|
|
|
result.setTenantName(user.getTenantName());
|
|
|
+ //拼接全名
|
|
|
+ result.setTenantNameFull(user.getTenantSurname() + " " + user.getTenantName());
|
|
|
}
|
|
|
|
|
|
if (role != null) {
|
|
@@ -246,6 +278,4 @@ public class ShopWarehouseServiceImpl extends SysServiceImpl<ShopWarehouseMapper
|
|
|
return new RPCBaseResponse<>(200, "SUCCESS", resultList);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|