|
|
@@ -1,5 +1,6 @@
|
|
|
package org.dromara.customer.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
@@ -12,15 +13,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.customer.domain.QualificationFile;
|
|
|
import org.dromara.customer.domain.SupplierInfo;
|
|
|
import org.dromara.customer.domain.SupplyArea;
|
|
|
import org.dromara.customer.domain.vo.SupplierContractVo;
|
|
|
import org.dromara.customer.domain.vo.SupplyAreaVo;
|
|
|
+import org.dromara.customer.service.IQualificationFileService;
|
|
|
import org.dromara.customer.service.ISupplierInfoService;
|
|
|
import org.dromara.customer.service.ISupplyAreaService;
|
|
|
import org.dromara.product.api.RemoteCategoryService;
|
|
|
import org.dromara.product.api.RemoteProductService;
|
|
|
import org.dromara.product.api.domain.RemoteProductBrand;
|
|
|
+import org.dromara.system.api.RemoteAddressAreaService;
|
|
|
+import org.dromara.system.api.domain.dto.AddressAreaDTO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -29,9 +34,12 @@ import org.dromara.customer.domain.vo.SupplierAuthorizeVo;
|
|
|
import org.dromara.customer.domain.SupplierAuthorize;
|
|
|
import org.dromara.customer.mapper.SupplierAuthorizeMapper;
|
|
|
import org.dromara.customer.service.ISupplierAuthorizeService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -53,13 +61,168 @@ public class SupplierAuthorizeServiceImpl extends ServiceImpl<SupplierAuthorize
|
|
|
|
|
|
private final StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
+ private final IQualificationFileService qualificationFileService;
|
|
|
+
|
|
|
@DubboReference
|
|
|
private final RemoteCategoryService remoteCategoryService;
|
|
|
|
|
|
@DubboReference
|
|
|
private final RemoteProductService remoteProductService;
|
|
|
|
|
|
- private static final String SUPPLY_CAPACITY_KEY = "supply_capacity:";
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteAddressAreaService remoteAddressAreaService;
|
|
|
+
|
|
|
+ // 日期格式化(yyyyMMdd)
|
|
|
+ private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ // 序号Key前缀
|
|
|
+ private static final String SEQ_KEY_PREFIX = "supplier:authorize:seq:";
|
|
|
+ // 序号过期时间(1天,避免Redis冗余数据)
|
|
|
+ private static final long EXPIRE_DAYS = 1;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增供应能力查询
|
|
|
+ *
|
|
|
+ * @param bo 供应能力查询
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertByBo(SupplierAuthorizeBo bo) {
|
|
|
+ // 1. 校验入参
|
|
|
+ if (bo.getCategoryIds() == null || bo.getCategoryIds().isEmpty()) {
|
|
|
+ throw new RuntimeException("品类ID列表不能为空");
|
|
|
+ }
|
|
|
+ if (bo.getQualificationFiles() == null) {
|
|
|
+ throw new RuntimeException("资质文件不能为空");
|
|
|
+ }
|
|
|
+ Date endDate = bo.getQualificationFiles().stream()
|
|
|
+ .filter(file -> file.getEndTime() != null)
|
|
|
+ .map(QualificationFile::getEndTime)
|
|
|
+ .min(Date::compareTo)
|
|
|
+ .orElse(null);
|
|
|
+ // 2. 遍历categoryIds,逐个插入主表
|
|
|
+ List<QualificationFile> allFiles = new ArrayList<>();
|
|
|
+ List<Long> categoryIds = bo.getCategoryIds();
|
|
|
+ for (Long categoryId : categoryIds) {
|
|
|
+ // 核心变更:从Redis生成唯一授权单号(替代数据库查询)
|
|
|
+ String authorizeNo =generateAuthorizeNo();
|
|
|
+
|
|
|
+ // 构建主表数据
|
|
|
+ SupplierAuthorize save = new SupplierAuthorize();
|
|
|
+ BeanUtils.copyProperties(bo, save);
|
|
|
+ save.setAuthorizeNo(authorizeNo);
|
|
|
+ save.setCategoryId(categoryId);
|
|
|
+ save.setAuthorizationEndTime(endDate);
|
|
|
+ save.setAuthorizedStatus("0");
|
|
|
+
|
|
|
+ // 插入主表(MyBatis-Plus自动回填ID)
|
|
|
+ int insert = baseMapper.insert(save);
|
|
|
+ Long approveId = save.getId();
|
|
|
+
|
|
|
+ // 构建关联文件数据
|
|
|
+ for (QualificationFile file : bo.getQualificationFiles()) {
|
|
|
+ QualificationFile saveFile = new QualificationFile();
|
|
|
+ BeanUtils.copyProperties(file, saveFile);
|
|
|
+ saveFile.setAuthorizeId(approveId);
|
|
|
+ saveFile.setAuthorizeNo(authorizeNo);
|
|
|
+ allFiles.add(saveFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean flag = false;
|
|
|
+ if (!allFiles.isEmpty()) {
|
|
|
+ flag = qualificationFileService.saveBatch(allFiles);
|
|
|
+ }
|
|
|
+
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改供应能力查询
|
|
|
+ *
|
|
|
+ * @param bo 供应能力查询
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(SupplierAuthorizeBo bo) {
|
|
|
+ Date endDate = bo.getQualificationFiles().stream()
|
|
|
+ .filter(file -> file.getEndTime() != null)
|
|
|
+ .map(QualificationFile::getEndTime)
|
|
|
+ .min(Date::compareTo)
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ // 步骤1:删除该授权单下的旧资质文件(先删后加,避免文件冗余)
|
|
|
+ LambdaQueryWrapper<QualificationFile> fileWrapper = new LambdaQueryWrapper<>();
|
|
|
+ fileWrapper.eq(QualificationFile::getAuthorizeId, bo.getId());
|
|
|
+ qualificationFileService.remove(fileWrapper);
|
|
|
+
|
|
|
+ // 步骤2:更新授权单主表信息
|
|
|
+ SupplierAuthorize update = new SupplierAuthorize();
|
|
|
+ BeanUtils.copyProperties(bo, update);
|
|
|
+ update.setAuthorizationEndTime(endDate);
|
|
|
+ // 如需保留原有授权单号,注释下面这行;如需重新生成,放开
|
|
|
+ // update.setAuthorizeNo(generateAuthorizeNo());
|
|
|
+
|
|
|
+ int updateCount = baseMapper.updateById(update);
|
|
|
+ if (updateCount == 0) {
|
|
|
+ throw new RuntimeException("授权单不存在,修改失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 步骤3:插入新的资质文件
|
|
|
+ List<QualificationFile> allFiles = new ArrayList<>();
|
|
|
+ Long approveId = bo.getId();
|
|
|
+ String authorizeNo = bo.getAuthorizeNo(); // 用原有授权单号
|
|
|
+ for (QualificationFile file : bo.getQualificationFiles()) {
|
|
|
+ QualificationFile saveFile = new QualificationFile();
|
|
|
+ BeanUtils.copyProperties(file, saveFile);
|
|
|
+ saveFile.setAuthorizeId(approveId);
|
|
|
+ saveFile.setAuthorizeNo(authorizeNo);
|
|
|
+ allFiles.add(saveFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量插入新文件
|
|
|
+ boolean flag = false;
|
|
|
+ if (!allFiles.isEmpty()) {
|
|
|
+ flag = qualificationFileService.saveBatch(allFiles);
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成当日自增序号
|
|
|
+ * @return 当日序号(如1、2、3...)
|
|
|
+ */
|
|
|
+ public int generateDailySeq() {
|
|
|
+ // 1. 生成当日Key(如supplier:authorize:seq:20260127)
|
|
|
+ String dateStr = DATE_FORMAT.format(new Date());
|
|
|
+ String seqKey = SEQ_KEY_PREFIX + dateStr;
|
|
|
+
|
|
|
+ // 2. Redis原子自增(不存在则初始化为1)
|
|
|
+ Long seq = stringRedisTemplate.opsForValue().increment(seqKey, 1);
|
|
|
+ int currentSeq = seq.intValue();
|
|
|
+
|
|
|
+ // 3. 首次生成时设置过期时间(仅执行一次)
|
|
|
+ if (currentSeq == 1) {
|
|
|
+ stringRedisTemplate.expire(seqKey, EXPIRE_DAYS, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+
|
|
|
+ return currentSeq;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成完整授权单号(日期+5位补零序号)
|
|
|
+ * @return 如2026012700001
|
|
|
+ */
|
|
|
+ public String generateAuthorizeNo() {
|
|
|
+ String dateStr = DATE_FORMAT.format(new Date());
|
|
|
+ int seq = generateDailySeq();
|
|
|
+ // 5位补零(如1→00001,10→00010)
|
|
|
+ String seqStr = String.format("%05d", seq);
|
|
|
+ return dateStr + seqStr;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 查询供应能力查询
|
|
|
@@ -188,8 +351,42 @@ public class SupplierAuthorizeServiceImpl extends ServiceImpl<SupplierAuthorize
|
|
|
// 设置转换后的Vo列表
|
|
|
voPage.setRecords(collect);
|
|
|
return TableDataInfo.build(voPage);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SupplierAuthorizeVo getBrandAuthorizeDetail(Long id) {
|
|
|
+ SupplierAuthorizeVo supplierAuthorizeVo = baseMapper.selectVoById(id);
|
|
|
+ if (supplierAuthorizeVo == null){
|
|
|
+ throw new RuntimeException("未找到授权信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ setSupplyAreaInfoForSingle(supplierAuthorizeVo);
|
|
|
+
|
|
|
+ // 查询资质文件列表并赋值给VO
|
|
|
+ List<QualificationFile> qualificationFiles = qualificationFileService.list(
|
|
|
+ new LambdaQueryWrapper<QualificationFile>()
|
|
|
+ .eq(QualificationFile::getAuthorizeId, id)
|
|
|
+ );
|
|
|
+ supplierAuthorizeVo.setQualificationFiles(qualificationFiles);
|
|
|
+
|
|
|
+ // 查询一级二级三级产品分类
|
|
|
+ Long categoryId = supplierAuthorizeVo.getCategoryId();
|
|
|
+ if (categoryId != null) {
|
|
|
+ // 调用远程分类服务获取完整的分类信息
|
|
|
+ Map<String, String> categoryMap = remoteCategoryService.getallCategoryNameById(
|
|
|
+ Collections.singletonMap(supplierAuthorizeVo.getId(), categoryId)
|
|
|
+ ).get(supplierAuthorizeVo.getId());
|
|
|
+
|
|
|
+ if (categoryMap != null) {
|
|
|
+ supplierAuthorizeVo.setCategorysMap(categoryMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return supplierAuthorizeVo;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private Map<Long, String> supplierBrandMap(List<Long> ids){
|
|
|
List<SupplierAuthorize> authorizeList = baseMapper.selectList(
|
|
|
new LambdaQueryWrapper<SupplierAuthorize>()
|
|
|
@@ -309,35 +506,9 @@ public class SupplierAuthorizeServiceImpl extends ServiceImpl<SupplierAuthorize
|
|
|
return lqw;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 新增供应能力查询
|
|
|
- *
|
|
|
- * @param bo 供应能力查询
|
|
|
- * @return 是否新增成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean insertByBo(SupplierAuthorizeBo bo) {
|
|
|
- SupplierAuthorize add = MapstructUtils.convert(bo, SupplierAuthorize.class);
|
|
|
- // stringRedisTemplate.opsForValue().set(RedisConstants.SUPPLY_CAPACITY_KEY+add.getId(),add);
|
|
|
- boolean flag = baseMapper.insert(add) > 0;
|
|
|
- if (flag){
|
|
|
- add.setId(add.getId());
|
|
|
- }
|
|
|
- return flag;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 修改供应能力查询
|
|
|
- *
|
|
|
- * @param bo 供应能力查询
|
|
|
- * @return 是否修改成功
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Boolean updateByBo(SupplierAuthorizeBo bo) {
|
|
|
- SupplierAuthorize update = MapstructUtils.convert(bo, SupplierAuthorize.class);
|
|
|
- validEntityBeforeSave(update);
|
|
|
- return baseMapper.updateById(update) > 0;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
@@ -362,26 +533,17 @@ public class SupplierAuthorizeServiceImpl extends ServiceImpl<SupplierAuthorize
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<SupplierAuthorizeVo> getAuthorizeDetailList(Long supplierId) {
|
|
|
+ public List<SupplierAuthorizeVo> getAuthorizeDetailList(Long supplierId,PageQuery pageQuery) {
|
|
|
LambdaQueryWrapper<SupplierAuthorize> lqw = new LambdaQueryWrapper<>();
|
|
|
lqw.eq(SupplierAuthorize::getSupplierId, supplierId);
|
|
|
- List<SupplierAuthorizeVo> supplierAuthorizeVos = baseMapper.selectVoList(lqw);
|
|
|
+ Page<SupplierAuthorize> page = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize());
|
|
|
+ IPage<SupplierAuthorizeVo> supplierAuthorizePage = baseMapper.selectVoPage(page,lqw);
|
|
|
+ List<SupplierAuthorizeVo> supplierAuthorizeVos = supplierAuthorizePage.getRecords();
|
|
|
setSupplierNames(supplierAuthorizeVos);
|
|
|
- //供应区域(省)
|
|
|
- Map<Long,List<String>> areaMap = supplierAuthorizeVos.stream().collect(Collectors.toMap(
|
|
|
- SupplierAuthorizeVo::getId,
|
|
|
- item -> Arrays.stream(item.getAuthorizedArea().split(",")).toList()
|
|
|
- ));
|
|
|
- Map<Long,String> provinceMap =supplyAreaService.queryProvincesorCity(supplierId,areaMap,1);
|
|
|
- provinceMap.forEach((id,province) -> {
|
|
|
- supplierAuthorizeVos.stream().filter(item -> item.getId().equals(id)).forEach(item -> item.setProvince(province));
|
|
|
- });
|
|
|
|
|
|
- //供应区域(市)
|
|
|
- Map<Long,String> cityMap =supplyAreaService.queryProvincesorCity(supplierId,areaMap,2);
|
|
|
- cityMap.forEach((id,city) -> {
|
|
|
- supplierAuthorizeVos.stream().filter(item -> item.getId().equals(id)).forEach(item -> item.setCity(city));
|
|
|
- });
|
|
|
+ // 使用AddressAreaService查询地区信息
|
|
|
+ setSupplyAreaInfo(supplierAuthorizeVos);
|
|
|
+
|
|
|
//一级 二级 三级 品目
|
|
|
Map<Long,Long> categoryMap = supplierAuthorizeVos.stream()
|
|
|
.filter(item -> item.getId() != null && item.getCategoryId() != null)
|
|
|
@@ -400,7 +562,182 @@ public class SupplierAuthorizeServiceImpl extends ServiceImpl<SupplierAuthorize
|
|
|
return supplierAuthorizeVos;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SupplierAuthorizeVo> srmgetAuthorizeDetailList(SupplierAuthorizeBo bo) {
|
|
|
+ LambdaQueryWrapper<SupplierAuthorize> lqw = new LambdaQueryWrapper<>();
|
|
|
+ lqw.eq(SupplierAuthorize::getSupplierId, bo.getSupplierId());
|
|
|
+
|
|
|
+ // 核心:省/市查询条件(合并字段用AND匹配)
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getProvince()) || ObjectUtil.isNotEmpty(bo.getCity())) {
|
|
|
+ lqw.and(wrapper -> {
|
|
|
+ // 1. 省份查询
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getProvince())) {
|
|
|
+ Long provinceId = remoteAddressAreaService.getIdsByName(bo.getProvince());
|
|
|
+ if (provinceId != null) {
|
|
|
+ wrapper.like(SupplierAuthorize::getAuthorizedArea, provinceId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 2. 城市查询(和省份用AND关联,必须同时满足)
|
|
|
+ if (ObjectUtil.isNotEmpty(bo.getCity())) {
|
|
|
+ Long cityId = remoteAddressAreaService.getIdsByName(bo.getCity());
|
|
|
+ if (cityId != null) {
|
|
|
+ wrapper.like(SupplierAuthorize::getAuthorizedArea, cityId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<SupplierAuthorizeVo> supplierAuthorizeVos = baseMapper.selectVoList(lqw);
|
|
|
+ setSupplierNames(supplierAuthorizeVos);
|
|
|
+
|
|
|
+ // 使用AddressAreaService查询地区信息
|
|
|
+ setSupplyAreaInfo(supplierAuthorizeVos);
|
|
|
+
|
|
|
+ //一级 二级 三级 品目
|
|
|
+ Map<Long,Long> categoryMap = supplierAuthorizeVos.stream()
|
|
|
+ .filter(item -> item.getId() != null && item.getCategoryId() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ SupplierAuthorizeVo::getId,
|
|
|
+ item ->item.getCategoryId()
|
|
|
+ ));
|
|
|
+
|
|
|
+ Map<Long, Map<String, String>> categorysMap = remoteCategoryService.getallCategoryNameById(categoryMap);
|
|
|
+
|
|
|
+ supplierAuthorizeVos.forEach(item -> {
|
|
|
+ Map<String, String> stringStringMap = categorysMap.get(item.getId());
|
|
|
+ item.setCategorysMap(stringStringMap);
|
|
|
+ });
|
|
|
+
|
|
|
+ return supplierAuthorizeVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用AddressAreaService设置单个供应区域信息(省和市)- 优化版本
|
|
|
+ *
|
|
|
+ * @param supplierAuthorizeVo 授权详情对象
|
|
|
+ */
|
|
|
+ private void setSupplyAreaInfoForSingle(SupplierAuthorizeVo supplierAuthorizeVo) {
|
|
|
+ if (supplierAuthorizeVo == null || StringUtils.isBlank(supplierAuthorizeVo.getAuthorizedArea())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析地区ID字符串
|
|
|
+ String[] areaIds = supplierAuthorizeVo.getAuthorizedArea().split(",");
|
|
|
+
|
|
|
+ // 收集所有有效的地区ID
|
|
|
+ Set<Long> validAreaIds = new HashSet<>();
|
|
|
+ for (String areaIdStr : areaIds) {
|
|
|
+ try {
|
|
|
+ Long areaId = Long.parseLong(areaIdStr.trim());
|
|
|
+ if (areaId != null) {
|
|
|
+ validAreaIds.add(areaId);
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 忽略无效的ID格式
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有有效的地区ID,直接返回
|
|
|
+ if (validAreaIds.isEmpty()) {
|
|
|
+ supplierAuthorizeVo.setProvince("");
|
|
|
+ supplierAuthorizeVo.setCity("");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询所有地区信息 - 一次性远程调用
|
|
|
+ List<AddressAreaDTO> areas = remoteAddressAreaService.listByIds(validAreaIds);
|
|
|
+
|
|
|
+ // 按地区级别分类存储
|
|
|
+ Set<String> provinces = new HashSet<>();
|
|
|
+ Set<String> cities = new HashSet<>();
|
|
|
+
|
|
|
+ for (AddressAreaDTO area : areas) {
|
|
|
+ if (area != null && area.getLevel() != null) {
|
|
|
+ if (area.getLevel() == 1) { // 省级
|
|
|
+ provinces.add(area.getAreaName());
|
|
|
+ } else if (area.getLevel() == 2) { // 市级
|
|
|
+ cities.add(area.getAreaName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置省份和城市信息到VO对象
|
|
|
+ supplierAuthorizeVo.setProvince(String.join(",", provinces));
|
|
|
+ supplierAuthorizeVo.setCity(String.join(",", cities));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 使用AddressAreaService批量设置供应区域信息(省和市)
|
|
|
+ *
|
|
|
+ * @param supplierAuthorizeVos 授权详情列表
|
|
|
+ */
|
|
|
+ private void setSupplyAreaInfo(List<SupplierAuthorizeVo> supplierAuthorizeVos) {
|
|
|
+ if (supplierAuthorizeVos == null || supplierAuthorizeVos.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 收集所有需要查询的地区ID
|
|
|
+ Set<Long> allAreaIds = new HashSet<>();
|
|
|
+ for (SupplierAuthorizeVo item : supplierAuthorizeVos) {
|
|
|
+ if (StringUtils.isNotBlank(item.getAuthorizedArea())) {
|
|
|
+ String[] areaIds = item.getAuthorizedArea().split(",");
|
|
|
+ for (String areaIdStr : areaIds) {
|
|
|
+ try {
|
|
|
+ Long areaId = Long.parseLong(areaIdStr.trim());
|
|
|
+ if (areaId != null) {
|
|
|
+ allAreaIds.add(areaId);
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ // 忽略无效的ID格式
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果没有地区ID需要查询,直接返回
|
|
|
+ if (allAreaIds.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量查询地区信息
|
|
|
+ List<AddressAreaDTO> areas = remoteAddressAreaService.listByIds(allAreaIds);
|
|
|
+
|
|
|
+ // 按地区ID建立索引映射,提高查找效率
|
|
|
+ Map<Long, AddressAreaDTO> areaIndexMap = areas.stream()
|
|
|
+ .collect(Collectors.toMap(AddressAreaDTO::getId, area -> area, (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ // 为每个授权项设置地区信息
|
|
|
+ for (SupplierAuthorizeVo item : supplierAuthorizeVos) {
|
|
|
+ if (StringUtils.isNotBlank(item.getAuthorizedArea())) {
|
|
|
+ String[] areaIds = item.getAuthorizedArea().split(",");
|
|
|
+
|
|
|
+ Set<String> provinces = new HashSet<>();
|
|
|
+ Set<String> cities = new HashSet<>();
|
|
|
|
|
|
+ for (String areaIdStr : areaIds) {
|
|
|
+ try {
|
|
|
+ Long areaId = Long.parseLong(areaIdStr.trim());
|
|
|
+ if (areaId != null) {
|
|
|
+ AddressAreaDTO area = areaIndexMap.get(areaId); // O(1) 查找
|
|
|
+ if (area != null && area.getLevel() != null) {
|
|
|
+ if (area.getLevel() == 1) { // 省级
|
|
|
+ provinces.add(area.getAreaName());
|
|
|
+ } else if (area.getLevel() == 2) { // 市级
|
|
|
+ cities.add(area.getAreaName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ item.setProvince(String.join(",", provinces));
|
|
|
+ item.setCity(String.join(",", cities));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void setSupplierNames(List<SupplierAuthorizeVo> records) {
|
|
|
if (records == null || records.isEmpty()) {
|