|
@@ -19,6 +19,8 @@ import org.dromara.customer.domain.bo.SupplierAuthorizeBo;
|
|
|
import org.dromara.customer.domain.vo.SupplierInformationVo;
|
|
import org.dromara.customer.domain.vo.SupplierInformationVo;
|
|
|
import org.dromara.customer.service.ISupplierProcurementService;
|
|
import org.dromara.customer.service.ISupplierProcurementService;
|
|
|
import org.dromara.customer.service.ISupplyAreaService;
|
|
import org.dromara.customer.service.ISupplyAreaService;
|
|
|
|
|
+import org.dromara.product.api.RemoteCategoryService;
|
|
|
|
|
+import org.dromara.product.api.RemoteProductService;
|
|
|
import org.dromara.system.api.RemoteComStaffService;
|
|
import org.dromara.system.api.RemoteComStaffService;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -27,6 +29,7 @@ import org.dromara.customer.domain.vo.SupplierInfoVo;
|
|
|
import org.dromara.customer.domain.SupplierInfo;
|
|
import org.dromara.customer.domain.SupplierInfo;
|
|
|
import org.dromara.customer.mapper.SupplierInfoMapper;
|
|
import org.dromara.customer.mapper.SupplierInfoMapper;
|
|
|
import org.dromara.customer.service.ISupplierInfoService;
|
|
import org.dromara.customer.service.ISupplierInfoService;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -50,6 +53,8 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Su
|
|
|
|
|
|
|
|
private final RemoteComStaffService remoteComStaffService;
|
|
private final RemoteComStaffService remoteComStaffService;
|
|
|
|
|
|
|
|
|
|
+ private final RemoteCategoryService remoteCategoryService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询供应商信息
|
|
* 查询供应商信息
|
|
|
*
|
|
*
|
|
@@ -102,6 +107,7 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Su
|
|
|
targetVo.setProvince(provinceNames);
|
|
targetVo.setProvince(provinceNames);
|
|
|
targetVo.setCity(cityNames);
|
|
targetVo.setCity(cityNames);
|
|
|
|
|
|
|
|
|
|
+
|
|
|
return targetVo;
|
|
return targetVo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -186,6 +192,13 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Su
|
|
|
return targetVo;
|
|
return targetVo;
|
|
|
})
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
+ //获取供应类别
|
|
|
|
|
+ Map<Long, String> supplierCategoryMap = supplierInformationVos.stream().collect(Collectors.toMap(SupplierInformationVo::getId, SupplierInformationVo::getOperatingCategory));
|
|
|
|
|
+ //查询供应品类
|
|
|
|
|
+ Map<Long, String> supplierCategoryNameMap = supplierCategoryNamesMap(supplierCategoryMap);
|
|
|
|
|
+ supplierInformationVos.forEach(vo -> {
|
|
|
|
|
+ vo.setOperatingCategory(supplierCategoryNameMap.get(vo.getId()));
|
|
|
|
|
+ });
|
|
|
for (SupplierInformationVo vo : supplierInformationVos) {
|
|
for (SupplierInformationVo vo : supplierInformationVos) {
|
|
|
// 查询管理人员和采购人员
|
|
// 查询管理人员和采购人员
|
|
|
Long id = vo.getId();
|
|
Long id = vo.getId();
|
|
@@ -235,6 +248,66 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Su
|
|
|
return supplierInformationVos;
|
|
return supplierInformationVos;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private Map<Long, String> supplierCategoryNamesMap(Map<Long, String> supplierCategoryMap) {
|
|
|
|
|
+ Set<Long> allCategoryIds = new HashSet<>();
|
|
|
|
|
+ for (String categoryIdStr : supplierCategoryMap.values()) {
|
|
|
|
|
+ // 拆分品类ID字符串(如"1,2,3" → ["1","2","3"])
|
|
|
|
|
+ String[] idArr = categoryIdStr.split(",");
|
|
|
|
|
+ for (String idStr : idArr) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Long categoryId = Long.parseLong(idStr.trim()); // 去除空格,避免格式问题
|
|
|
|
|
+ allCategoryIds.add(categoryId);
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ // 异常处理:ID格式错误时跳过,不影响整体逻辑
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 批量查询品类ID→名称的映射
|
|
|
|
|
+ Map<Long, String> categoryIdToNameMap = new HashMap<>();
|
|
|
|
|
+ if (!allCategoryIds.isEmpty()) {
|
|
|
|
|
+ categoryIdToNameMap = remoteCategoryService.getCategoryNamebyIds(allCategoryIds);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 转换supplierCategoryMap为“供应商ID→拼接的品类名称”
|
|
|
|
|
+ Map<Long, String> supplierCategoryNameMap = new HashMap<>();
|
|
|
|
|
+ for (Map.Entry<Long, String> entry : supplierCategoryMap.entrySet()) {
|
|
|
|
|
+ Long supplierId = entry.getKey(); // 供应商ID
|
|
|
|
|
+ String categoryIdStr = entry.getValue(); // 品类ID字符串(如"1,2,3")
|
|
|
|
|
+
|
|
|
|
|
+ // 处理空值:无品类ID则存空字符串
|
|
|
|
|
+ if (!StringUtils.isNotBlank(categoryIdStr)) {
|
|
|
|
|
+ supplierCategoryNameMap.put(supplierId, "");
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 拆分品类ID并拼接名称
|
|
|
|
|
+ StringBuilder nameBuilder = new StringBuilder();
|
|
|
|
|
+ String[] idArr = categoryIdStr.split(",");
|
|
|
|
|
+ for (String idStr : idArr) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Long categoryId = Long.parseLong(idStr.trim());
|
|
|
|
|
+ // 获取品类名称(无匹配则用空字符串兜底)
|
|
|
|
|
+ String categoryName = categoryIdToNameMap.getOrDefault(categoryId, "");
|
|
|
|
|
+ // 非空名称才拼接,避免多余分隔符
|
|
|
|
|
+ if (StringUtils.isNotBlank(categoryName)) {
|
|
|
|
|
+ if (nameBuilder.length() > 0) {
|
|
|
|
|
+ nameBuilder.append(","); // 分隔符可改为中文逗号“,”
|
|
|
|
|
+ }
|
|
|
|
|
+ nameBuilder.append(categoryName);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 将拼接结果存入新Map
|
|
|
|
|
+ supplierCategoryNameMap.put(supplierId, nameBuilder.toString());
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return supplierCategoryNameMap;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 查询符合条件的供应商信息列表
|
|
* 查询符合条件的供应商信息列表
|
|
|
*
|
|
*
|
|
@@ -301,8 +374,6 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Su
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getType()), SupplierInfo::getType, bo.getType());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getType()), SupplierInfo::getType, bo.getType());
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getOwnedCompany()), SupplierInfo::getOwnedCompany, bo.getOwnedCompany());
|
|
lqw.eq(StringUtils.isNotBlank(bo.getOwnedCompany()), SupplierInfo::getOwnedCompany, bo.getOwnedCompany());
|
|
|
lqw.eq(bo.getPushStatus() != null, SupplierInfo::getPushStatus, bo.getPushStatus());
|
|
lqw.eq(bo.getPushStatus() != null, SupplierInfo::getPushStatus, bo.getPushStatus());
|
|
|
- lqw.eq(bo.getCreated() != null, SupplierInfo::getCreated, bo.getCreated());
|
|
|
|
|
- lqw.eq(bo.getModify() != null, SupplierInfo::getModify, bo.getModify());
|
|
|
|
|
lqw.eq(bo.getValidityFromDate() != null, SupplierInfo::getValidityFromDate, bo.getValidityFromDate());
|
|
lqw.eq(bo.getValidityFromDate() != null, SupplierInfo::getValidityFromDate, bo.getValidityFromDate());
|
|
|
lqw.eq(bo.getValidityToDate() != null, SupplierInfo::getValidityToDate, bo.getValidityToDate());
|
|
lqw.eq(bo.getValidityToDate() != null, SupplierInfo::getValidityToDate, bo.getValidityToDate());
|
|
|
lqw.eq(bo.getRowNo() != null, SupplierInfo::getRowNo, bo.getRowNo());
|
|
lqw.eq(bo.getRowNo() != null, SupplierInfo::getRowNo, bo.getRowNo());
|
|
@@ -375,6 +446,61 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Su
|
|
|
IPage<SupplierInfo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
|
IPage<SupplierInfo> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
|
|
|
|
|
|
|
IPage<SupplierInfo> resultPage = baseMapper.selectPage(page, lqw);
|
|
IPage<SupplierInfo> resultPage = baseMapper.selectPage(page, lqw);
|
|
|
|
|
+ List<SupplierInfo> records = resultPage.getRecords();
|
|
|
|
|
+ // 3. 批量处理省份/城市名称(核心优化:批量查库,避免循环查)
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(records)) {
|
|
|
|
|
+ // 3.1 提取所有供应商ID
|
|
|
|
|
+ Set<Long> supplierIds = records.stream()
|
|
|
|
|
+ .map(SupplierInfo::getId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+
|
|
|
|
|
+ if (!supplierIds.isEmpty()) {
|
|
|
|
|
+ // 3.2 批量查询所有供应商的省级(level=1)和市级(level=2)地址
|
|
|
|
|
+ LambdaQueryWrapper<SupplyArea> areaLqw = Wrappers.lambdaQuery();
|
|
|
|
|
+ areaLqw.in(SupplyArea::getSupplierId, supplierIds)
|
|
|
|
|
+ .in(SupplyArea::getLevel, "1", "2") // 同时查省级和市级
|
|
|
|
|
+ .select(SupplyArea::getSupplierId, SupplyArea::getLevel, SupplyArea::getAreaName);
|
|
|
|
|
+
|
|
|
|
|
+ List<SupplyArea> allSupplyAreas = supplyAreaService.list(areaLqw);
|
|
|
|
|
+
|
|
|
|
|
+ // 3.3 按【供应商ID+级别】分组,方便快速匹配
|
|
|
|
|
+ // key: 供应商ID + "_" + 级别(如 "1001_1"),value: 该级别下的名称列表
|
|
|
|
|
+ Map<String, List<String>> areaGroupMap = allSupplyAreas.stream()
|
|
|
|
|
+ .filter(area -> {
|
|
|
|
|
+ // 过滤无效数据
|
|
|
|
|
+ return area.getSupplierId() != null
|
|
|
|
|
+ && StringUtils.isNotBlank(area.getLevel())
|
|
|
|
|
+ && StringUtils.isNotBlank(area.getAreaName());
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
|
|
+ // 分组key:供应商ID_级别
|
|
|
|
|
+ area -> area.getSupplierId() + "_" + area.getLevel(),
|
|
|
|
|
+ // 收集该分组下的所有区域名称
|
|
|
|
|
+ Collectors.mapping(SupplyArea::getAreaName, Collectors.toList())
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ // 3.4 给每个SupplierInfo设置省份/城市名称
|
|
|
|
|
+ for (SupplierInfo item : records) {
|
|
|
|
|
+ Long id = item.getId();
|
|
|
|
|
+ if (id == null) {
|
|
|
|
|
+ item.setProvince("");
|
|
|
|
|
+ item.setCity("");
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取省级名称(level=1)
|
|
|
|
|
+ List<String> provinceNames = areaGroupMap.getOrDefault(id + "_1", new ArrayList<>());
|
|
|
|
|
+ String provinceStr = provinceNames.stream().collect(Collectors.joining(","));
|
|
|
|
|
+ item.setProvince(provinceStr);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取市级名称(level=2)
|
|
|
|
|
+ List<String> cityNames = areaGroupMap.getOrDefault(id + "_2", new ArrayList<>());
|
|
|
|
|
+ String cityStr = cityNames.stream().collect(Collectors.joining(","));
|
|
|
|
|
+ item.setCity(cityStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return resultPage;
|
|
return resultPage;
|
|
|
}
|
|
}
|