package com.bonus.canteen.core.supply.service.impl;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.common.collect.Maps;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.supply.api.DrpAuthorityApi;
import com.bonus.canteen.core.supply.constant.DrpBusinessConstants;
import com.bonus.canteen.core.supply.constant.DrpQuantityMainFlagEnum;
import com.bonus.canteen.core.supply.constant.DrpSupplierStatusEnum;
import com.bonus.canteen.core.supply.domain.*;
import com.bonus.canteen.core.supply.dto.*;
import com.bonus.canteen.core.supply.mapper.*;
import com.bonus.canteen.core.supply.po.CategoryModel;
import com.bonus.canteen.core.supply.po.DrpSupplierModel;
import com.bonus.canteen.core.supply.service.DrpSupplierCategoryService;
import com.bonus.canteen.core.supply.service.DrpSupplierDeliverService;
import com.bonus.canteen.core.supply.service.DrpSupplierQualificationService;
import com.bonus.canteen.core.supply.service.DrpSupplierService;
import com.bonus.canteen.core.supply.vo.*;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.houqin.constant.DelFlagEnum;
import com.bonus.common.houqin.utils.id.Id;
import com.bonus.common.security.utils.SecurityUtils;
import com.github.pagehelper.page.PageMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.apache.commons.compress.utils.Lists;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;


@Service
public class DrpSupplierServiceImpl extends ServiceImpl<DrpSupplierMapper, DrpSupplier> implements DrpSupplierService {
   private static final Logger log = LoggerFactory.getLogger(DrpSupplierServiceImpl.class);

   @Resource
   private DrpSupplierCategoryService drpSupplierCategoryService;
   @Resource
   private DrpSupplierDeliverService drpSupplierDeliverService;

   @Resource
   private DrpSupplierQualificationService drpSupplierQualificationService;

   @Resource
   private DrpSupplierDeliverMapper drpSupplierDeliverMapper;

   @Resource
   private DrpSupplierQualificationMapper drpSupplierQualificationMapper;

   @Resource
   private DrpSupplierCategoryMapper drpSupplierCategoryMapper;

   @Resource
   private DrpAuthorityApi drpAuthorityApi;

   @Resource
   private DrpMenuMaterialSupplierMapper drpMenuMaterialSupplierMapper;

   @Resource
   private DrpMaterialWinBidRecordsMapper drpMaterialWinBidRecordsMapper;



   @Override
   public void addDrpSupplier(DrpSupplierAddDTO content) {
      List<DrpSupplier> check = this.baseMapper.selectList(new LambdaQueryWrapper<DrpSupplier>().eq(DrpSupplier::getSupplierName, content.getSupplierName()).eq(DrpSupplier::getDelFlag, DelFlagEnum.DEL_FALSE.key()));
      if (CollUtil.isNotEmpty(check)) {
         throw new ServiceException("供应商已存在");
      } else {
         if (ObjectUtil.isNotEmpty(content.getSupplierUserId())) {
           // Long checkSupplierUserId = ((DrpSupplierMapper)this.baseMapper).selectCount((Wrapper)Wrappers.lambdaQuery(DrpSupplier.class).eq(DrpSupplier::getSupplierUserId, content.getSupplierUserId()));
            Long checkSupplierUserId = this.baseMapper.selectCount(new LambdaQueryWrapper<DrpSupplier>().eq(DrpSupplier::getSupplierUserId, content.getSupplierUserId()));
            if (checkSupplierUserId > 0L) {
               //throw new LeException(I18n.getMessage("drp.supplier-is-bind", new Object[0]));
               throw new ServiceException("供应商已存在");
            }
         }

         DrpSupplier supplier = new DrpSupplier();
         BeanUtil.copyProperties(content, supplier, new String[0]);
         Long supplierId = Id.next();
         supplier.setSupplierId(supplierId);
         if (CollUtil.isNotEmpty(content.getCategoryIdList())) {
            this.insertSupplierCategoryBatch(content.getCategoryIdList(), supplierId);
         }

         String maxSupplierNumStr = this.baseMapper.getMaxSupplierNum(DelFlagEnum.DEL_FALSE.key(), DrpBusinessConstants.SUPPLIER_NUM_LENGTH);
         String supplierNum;
         if (CharSequenceUtil.isBlank(maxSupplierNumStr)) {
            supplierNum = "000001";
         } else {
            supplierNum = String.format("%06d", Integer.parseInt(maxSupplierNumStr) + 1);
         }

         supplier.setSupplierNum(supplierNum);
         supplier.setStatus(DrpSupplierStatusEnum.NORMAL.key());
         supplier.setDelFlag(DelFlagEnum.DEL_FALSE.key());
         supplier.setCreateBy(SecurityUtils.getUserId()+"");
         if (CollUtil.isNotEmpty(content.getAttachmentList())) {
            supplier.setAttachment(JSONObject.toJSONString(content.getAttachmentList()));
         }

         ((DrpSupplierMapper)this.baseMapper).insert(supplier);
         if (CollUtil.isNotEmpty(content.getDeliverVOList())) {
            content.getDeliverVOList().forEach((d) -> {
               d.setSupplierId(supplierId);
               this.drpSupplierDeliverService.add(d);
            });
         }

         List<DrpSupplierQualification> drpSupplierQualificationList = new ArrayList();
         Iterator var8 = content.getMainQualificationList().iterator();

         DrpSupplierQualificationSaveDTO drpSupplierQualificationSaveDTO;
         DrpSupplierQualification drpSupplierQualification;
         while(var8.hasNext()) {
            drpSupplierQualificationSaveDTO = (DrpSupplierQualificationSaveDTO)var8.next();
            drpSupplierQualification = new DrpSupplierQualification();
            BeanUtil.copyProperties(drpSupplierQualificationSaveDTO, drpSupplierQualification, new String[0]);
            drpSupplierQualification.setSupplierId(supplierId);
            drpSupplierQualification.setMainFlag(DrpQuantityMainFlagEnum.MAIN.getKey());
            drpSupplierQualification.setCreateBy(SecurityUtils.getUserId()+"");
            drpSupplierQualificationList.add(drpSupplierQualification);
         }

         this.drpSupplierQualificationService.saveBatch(drpSupplierQualificationList);
         if (!CollUtil.isEmpty(content.getOtherQualificationList())) {
            drpSupplierQualificationList.clear();
            var8 = content.getOtherQualificationList().iterator();

            while(var8.hasNext()) {
               drpSupplierQualificationSaveDTO = (DrpSupplierQualificationSaveDTO)var8.next();
               drpSupplierQualification = new DrpSupplierQualification();
               BeanUtil.copyProperties(drpSupplierQualificationSaveDTO, drpSupplierQualification, new String[0]);
               drpSupplierQualification.setSupplierId(supplierId);
               drpSupplierQualification.setMainFlag(DrpQuantityMainFlagEnum.OTHER.getKey());
               drpSupplierQualification.setCreateBy(SecurityUtils.getUserId()+"");
               drpSupplierQualificationList.add(drpSupplierQualification);
            }

            this.drpSupplierQualificationService.saveBatch(drpSupplierQualificationList);
         }
      }
   };

   protected void insertSupplierCategoryBatch(List<Long> categoryIdList, Long supplierId) {
      List<DrpSupplierCategory> supplierCategoryList = new ArrayList();
      Iterator var4 = categoryIdList.iterator();

      while(var4.hasNext()) {
         Long categoryId = (Long)var4.next();
         DrpSupplierCategory supplierCategory = new DrpSupplierCategory();
         supplierCategory.setSupplierId(supplierId);
         supplierCategory.setCategoryId(categoryId);
         supplierCategory.setCreateBy(SecurityUtils.getUserId()+"");
         supplierCategoryList.add(supplierCategory);
      }

      this.drpSupplierCategoryService.saveBatch(supplierCategoryList);
   }


   @Override
   public void removeBySupplierId(Long supplierId) {
      if (ObjectUtil.isEmpty(supplierId)) {
         log.info("***[库存中心_供应商管理]_删除供应商信息_传入的供应商id为空************");
         throw new ServiceException("_删除供应商信息_传入的供应商id为空");
      } else {
         this.baseMapper.update(null, Wrappers.lambdaUpdate(DrpSupplier.class).eq(DrpSupplier::getSupplierId, supplierId)
                 .set(DrpSupplier::getDelFlag, DelFlagEnum.DEL_TRUE.key())
                 .set(DrpSupplier::getSupplierUserId, (Object)null));
      }
   }

   @Override
   public void editDrpSupplier(DrpSupplierEditDTO content) {
      List<DrpSupplier> check = this.baseMapper.selectList(Wrappers.lambdaQuery(DrpSupplier.class).eq(DrpSupplier::getSupplierName, content.getSupplierName()).eq(DrpSupplier::getDelFlag, DelFlagEnum.DEL_FALSE.key()).ne(DrpSupplier::getSupplierId, content.getSupplierId()).select(DrpSupplier::getSupplierId));
      if (CollUtil.isNotEmpty(check)) {
         throw new ServiceException("所改名称已存在");
      } else {
         if (ObjectUtil.isNotEmpty(content.getSupplierUserId())) {
            Long checkSupplierUserId = this.baseMapper.selectCount(Wrappers.lambdaQuery(DrpSupplier.class).eq(DrpSupplier::getSupplierUserId, content.getSupplierUserId()).eq(DrpSupplier::getDelFlag, DelFlagEnum.DEL_FALSE.key()).ne(DrpSupplier::getSupplierId, content.getSupplierId()));
            if (checkSupplierUserId > 0L) {
               throw new ServiceException("人员已被绑定");
            }
         }

         DrpSupplier supplier = new DrpSupplier();
         BeanUtil.copyProperties(content, supplier, new String[0]);
         this.drpSupplierCategoryService.remove(Wrappers.lambdaQuery(DrpSupplierCategory.class).eq(DrpSupplierCategory::getSupplierId, content.getSupplierId()));
         if (CollUtil.isNotEmpty(content.getCategoryIdList())) {
            this.insertSupplierCategoryBatch(content.getCategoryIdList(), content.getSupplierId());
         }

         supplier.setDelFlag(DelFlagEnum.DEL_FALSE.key());
         if (CollUtil.isNotEmpty(content.getAttachmentList())) {
            supplier.setAttachment(JSONObject.toJSONString(content.getAttachmentList()));
         }

         if (CollUtil.isNotEmpty(content.getDeliverVOList())) {
            this.drpSupplierDeliverMapper.delete(Wrappers.lambdaQuery(DrpSupplierDeliver.class).eq(DrpSupplierDeliver::getSupplierId, supplier.getSupplierId()));
            content.getDeliverVOList().forEach((d) -> {
               d.setSupplierId(supplier.getSupplierId());
               this.drpSupplierDeliverService.add(d);
            });
         } else {
            this.drpSupplierDeliverMapper.delete(Wrappers.lambdaQuery(DrpSupplierDeliver.class).eq(DrpSupplierDeliver::getSupplierId, supplier.getSupplierId()));
         }

         ((DrpSupplierMapper)this.baseMapper).update(supplier, Wrappers.lambdaQuery(DrpSupplier.class).eq(DrpSupplier::getSupplierId, content.getSupplierId()));
         if (ObjectUtil.isEmpty(content.getSupplierUserId())) {
            ((DrpSupplierMapper)this.baseMapper).update(null, Wrappers.lambdaUpdate(DrpSupplier.class).eq(DrpSupplier::getSupplierId, content.getSupplierId()).set(DrpSupplier::getSupplierUserId, (Object)null));
         }

         Iterator var4 = content.getMainQualificationList().iterator();

         DrpSupplierQualification drpSupplierQualification;
         while(var4.hasNext()) {
            DrpSupplierQualificationUpdateDTO drpSupplierQualificationUpdateDTO = (DrpSupplierQualificationUpdateDTO)var4.next();
            drpSupplierQualification = new DrpSupplierQualification();
            BeanUtil.copyProperties(drpSupplierQualificationUpdateDTO, drpSupplierQualification, new String[0]);
            drpSupplierQualification.setUpdateBy(SecurityUtils.getUserId()+"");
            this.drpSupplierQualificationService.updateById(drpSupplierQualification);
         }

         if (CollUtil.isNotEmpty(content.getOtherQualificationList())) {
            this.drpSupplierQualificationMapper.delete(Wrappers.lambdaQuery(DrpSupplierQualification.class).eq(DrpSupplierQualification::getSupplierId, content.getSupplierId()).eq(DrpSupplierQualification::getMainFlag, DrpQuantityMainFlagEnum.OTHER.getKey()));
            var4 = content.getOtherQualificationList().iterator();

            while(var4.hasNext()) {
               DrpSupplierQualificationSaveDTO drpSupplierQualificationSaveDTO = (DrpSupplierQualificationSaveDTO)var4.next();
               drpSupplierQualification = new DrpSupplierQualification();
               BeanUtil.copyProperties(drpSupplierQualificationSaveDTO, drpSupplierQualification, new String[0]);
               drpSupplierQualification.setSupplierId(supplier.getSupplierId());
               drpSupplierQualification.setMainFlag(DrpQuantityMainFlagEnum.OTHER.getKey());
               this.drpSupplierQualificationService.save(drpSupplierQualification);
            }
         }

      }
   }


   @Override
   public void editDrpSupplierStatus(DrpSupplierEditStatusDTO content) {
      String username = SecurityUtils.getLoginUser().getUsername();
      this.baseMapper.update(null,Wrappers.lambdaUpdate(DrpSupplier.class).eq(DrpSupplier::getSupplierId, content.getSupplierId()).set(DrpSupplier::getStatus, content.getStatus()).set(DrpSupplier::getUpdateBy, username));
   }


   @Override
   public List<DrpSupplierPageVO> getDrpSupplierPage(DrpSupplierPageDTO content) {
      List<DrpSupplierPageVO>  detailList = this.baseMapper.selectAllList( content,DelFlagEnum.DEL_FALSE.key());
      if (CollUtil.isEmpty(detailList)) {
         return detailList;
      } else {
         Iterator var4 = detailList.iterator();

         while(var4.hasNext()) {
            DrpSupplierPageVO item = (DrpSupplierPageVO)var4.next();
            QueryWrapper<DrpSupplierCategory> queryWrapper = new QueryWrapper();
            queryWrapper.eq("dsc.supplier_id", item.getSupplierId());
            List<CategoryModel> categoryList = this.drpSupplierCategoryMapper.selectNameBySupplier(queryWrapper);
            if (CollUtil.isNotEmpty(categoryList)) {
               categoryList = (List)categoryList.stream().filter((a) -> {
                  return !ObjectUtil.isNull(a);
               }).collect(Collectors.toList());
            }

            item.setCategoryModelList(categoryList);
            List<DrpSupplierDeliverVO> deliverVOList = Lists.newArrayList();
            this.drpSupplierDeliverMapper.selectList(Wrappers.lambdaQuery(DrpSupplierDeliver.class).eq(DrpSupplierDeliver::getSupplierId, item.getSupplierId())).forEach((d) -> {
               DrpSupplierDeliverVO drpSupplierDeliverDTO = new DrpSupplierDeliverVO();
               BeanUtil.copyProperties(d, drpSupplierDeliverDTO, new String[0]);
               deliverVOList.add(drpSupplierDeliverDTO);
            });
            item.setDeliverVOList(deliverVOList);
            List<DrpSupplierQualification> qualificationList = this.drpSupplierQualificationService.list(Wrappers.lambdaQuery(DrpSupplierQualification.class).eq(DrpSupplierQualification::getSupplierId, item.getSupplierId()).eq(DrpSupplierQualification::getMainFlag, DrpQuantityMainFlagEnum.MAIN.getKey()));
            List<DrpSupplierQualificationDetailPageVO> qualificationDetailPageVOList = BeanUtil.copyToList(qualificationList, DrpSupplierQualificationDetailPageVO.class);
            item.setMainQualificationList(qualificationDetailPageVOList);
         }
         return detailList;
      }
   }

   @Override
   public List<DrpSupplierVO> listSupplier(DrpSupplierQueryDTO content) {
     // content.setAreaIdList(this.drpAuthorityApi.authAreaList(content.getAreaIdList()));
      return this.baseMapper.listSupplier(DrpSupplierStatusEnum.NORMAL.key(), DelFlagEnum.DEL_FALSE.key(), content);
   }


   @Override
   public Map<Long,List<DrpSupplierVO>> supplierByMaterialId(DrpSupplierDTO content) {
      List<DrpSupplierVO> listSupplier = ((DrpSupplierMapper)this.baseMapper).listSupplier(DrpSupplierStatusEnum.NORMAL.key(), DelFlagEnum.DEL_FALSE.key(), new DrpSupplierQueryDTO());
      Map<Long, DrpSupplierVO> drpSupplierVOMap = (Map)listSupplier.stream().collect(Collectors.toMap(DrpSupplierVO::getSupplierId, Function.identity()));
      Map<Long, List<DrpSupplierVO>> returnMap = Maps.newHashMap();
      if (CollUtil.isNotEmpty(content.getCategoryIds())) {
         this.packageData(content.getCategoryIds(), drpSupplierVOMap, returnMap);
         return returnMap;
      } else {
         return returnMap;
      }
   }

   protected void packageData(List<Long> categoryIdList, Map<Long, DrpSupplierVO> drpSupplierVOMap, Map<Long, List<DrpSupplierVO>> returnMap) {
      List<DrpSupplierCategory> menuMaterialCategoryList = this.drpSupplierCategoryMapper.selectList(Wrappers.lambdaQuery(DrpSupplierCategory.class).in(CollUtil.isNotEmpty(categoryIdList), DrpSupplierCategory::getCategoryId, categoryIdList));
      Map<Long, List<DrpSupplierCategory>> listMap = (Map)menuMaterialCategoryList.stream().collect(Collectors.groupingBy(DrpSupplierCategory::getCategoryId));
      if (CollUtil.isNotEmpty(listMap)) {
         listMap.forEach((key, value) -> {
            List<DrpSupplierVO> drpSupplierVOList = Lists.newArrayList();
            if (CollUtil.isNotEmpty(value)) {
               value.forEach((d) -> {
                  if (drpSupplierVOMap.get(d.getSupplierId()) != null) {
                     drpSupplierVOList.add((DrpSupplierVO)drpSupplierVOMap.get(d.getSupplierId()));
                  }

               });
            }

            returnMap.put(key, drpSupplierVOList);
         });
      }
   }

   @Override
   public void bidMaterialSupplier(DrpBidMaterialSupplierDTO content) {
      if (CollUtil.isNotEmpty(content.getMaterialIdList())) {
         content.getMaterialIdList().forEach((materialId) -> {
            content.setMaterialId(materialId);
            this.packageData(content);
         });
      }

      if (CollUtil.isNotEmpty(content.getCategoryIdList())) {
         content.getCategoryIdList().forEach((categoryId) -> {
            content.setCategoryId(categoryId);
            this.packageData(content);
         });
      } else {
         this.packageData(content);
      }
   }

   private void packageData(DrpBidMaterialSupplierDTO content) {
      DrpMenuMaterialSupplier drpMenuMaterialSupplier = this.drpMenuMaterialSupplierMapper.selectOne(Wrappers.lambdaQuery(DrpMenuMaterialSupplier.class).eq(DrpMenuMaterialSupplier::getCanteenId, content.getCanteenId()).eq(DrpMenuMaterialSupplier::getDelFlag, DelFlagEnum.DEL_FALSE.key()).eq(ObjectUtil.isNotNull(content.getMaterialId()), DrpMenuMaterialSupplier::getMaterialId, content.getMaterialId()).eq(ObjectUtil.isNotNull(content.getCategoryId()), DrpMenuMaterialSupplier::getCategoryId, content.getCategoryId()));
      if (ObjectUtil.isEmpty(drpMenuMaterialSupplier)) {
         drpMenuMaterialSupplier = new DrpMenuMaterialSupplier();
         drpMenuMaterialSupplier.setId(Id.next());
         drpMenuMaterialSupplier.setSupplierId(content.getSupplierId());
         drpMenuMaterialSupplier.setCanteenId(content.getCanteenId());
         drpMenuMaterialSupplier.setMaterialId(content.getMaterialId());
         drpMenuMaterialSupplier.setCategoryId(content.getCategoryId());
         drpMenuMaterialSupplier.setDelFlag(DelFlagEnum.DEL_FALSE.key());
         drpMenuMaterialSupplier.setAlternativeSupplier(content.getAlternativeSupplier());
         drpMenuMaterialSupplier.setIfSupply(content.getIfSupply());
         this.drpMenuMaterialSupplierMapper.insert(drpMenuMaterialSupplier);
      } else {
         drpMenuMaterialSupplier.setSupplierId(content.getSupplierId());
         drpMenuMaterialSupplier.setMaterialId(content.getMaterialId());
         drpMenuMaterialSupplier.setCanteenId(content.getCanteenId());
         drpMenuMaterialSupplier.setCategoryId(content.getCategoryId());
         drpMenuMaterialSupplier.setDelFlag(DelFlagEnum.DEL_FALSE.key());
         drpMenuMaterialSupplier.setAlternativeSupplier(content.getAlternativeSupplier());
         drpMenuMaterialSupplier.setIfSupply(content.getIfSupply());
         this.drpMenuMaterialSupplierMapper.updateById(drpMenuMaterialSupplier);
      }
   }

   @Override
   public List<DrpMaterialSupplierVO> getMaterialSupplier(DrpMaterialInfoDTO content) {
      List<DrpMaterialSupplierVO> drpMaterialSupplierList;
      if (!ObjectUtil.isNull(content.getConfigType()) && !ObjectUtil.equal(content.getConfigType(), 1)) {
         drpMaterialSupplierList = this.baseMapper.getCategorySupplier(content);
      } else {
         drpMaterialSupplierList = this.drpMaterialWinBidRecordsMapper.getMaterialSupplier(content);
         if (CollUtil.isEmpty(drpMaterialSupplierList)) {
            return drpMaterialSupplierList;
         }

         List<DrpMaterialBidRecordsSupplierVO> drpMaterialBidRecordsSupplierVOS = this.drpMaterialWinBidRecordsMapper.listSupplierPriceByMaterialIdList((List)drpMaterialSupplierList.stream().map(DrpMaterialSupplierVO::getMaterialId).collect(Collectors.toList()));
         Map<Long, List<DrpMaterialBidRecordsSupplierVO>> collect = (Map)drpMaterialBidRecordsSupplierVOS.stream().collect(Collectors.groupingBy(DrpMaterialBidRecordsSupplierVO::getMaterialId));
         List<MaterialAndUnitDTO> materialAndUnitDTOS = (List)drpMaterialSupplierList.stream().map((d) -> {
            return (new MaterialAndUnitDTO()).setMaterialId(d.getMaterialId()).setUnitId(d.getUnitId());
         }).collect(Collectors.toList());
         List<DrpLastOrderGoodsVO> lastOrderGoodsPriceList = this.drpMaterialWinBidRecordsMapper.getLastOrderGoodsPriceList(materialAndUnitDTOS, content.getAreaId());
         Map<String, DrpLastOrderGoodsVO> orderGoodsVOMap = (Map)lastOrderGoodsPriceList.stream().collect(Collectors.toMap((d) -> {
            Long var10000 = d.getMaterialId();
            return "" + var10000 + "-" + d.getUnitId();
         }, Function.identity(), (k1, k2) -> {
            return k1;
         }));
         if (CollUtil.isNotEmpty(drpMaterialSupplierList)) {
            drpMaterialSupplierList.forEach((d) -> {
               List<DrpMaterialBidRecordsSupplierVO> detailList = (List)collect.get(d.getMaterialId());
               List<DrpSupplierModel> nearestSupplierList = Lists.newArrayList();
               if (CollUtil.isNotEmpty(detailList)) {
                  detailList.forEach((e) -> {
                     DrpSupplierModel drpSupplierModel = new DrpSupplierModel();
                     drpSupplierModel.setSupplierId(e.getWinSupplierId());
                     drpSupplierModel.setSupplierName(e.getWinSupplierName());
                     nearestSupplierList.add(drpSupplierModel);
                  });
               }

               d.setNearestSupplierList(nearestSupplierList);
               Long var10001 = d.getMaterialId();
               DrpLastOrderGoodsVO drpLastOrderGoodsVO = (DrpLastOrderGoodsVO)orderGoodsVOMap.get("" + var10001 + "-" + d.getUnitId());
               d.setLastOrderGoods(drpLastOrderGoodsVO);
            });
         }
      }
      return drpMaterialSupplierList;
   }

   @Override
   public DrpSupplierMainInfoVO getMainInfoById(Long supplierId) {
      if (ObjectUtil.isEmpty(supplierId)) {
         throw new ServiceException("供应商id不能为空");
      } else {
         DrpSupplierMainInfoVO drpSupplierMainInfoVO = this.baseMapper.getSupplierMainInfoById(supplierId);
         List<DrpSupplierQualification> qualificationList = this.drpSupplierQualificationService.list(Wrappers.lambdaQuery(DrpSupplierQualification.class).eq(DrpSupplierQualification::getSupplierId, supplierId).eq(DrpSupplierQualification::getMainFlag, DrpQuantityMainFlagEnum.MAIN.getKey()));
         List<DrpSupplierQualificationDetailPageVO> qualificationDetailPageVOList = BeanUtil.copyToList(qualificationList, DrpSupplierQualificationDetailPageVO.class);
         drpSupplierMainInfoVO.setMainQualificationList(qualificationDetailPageVOList);
         return drpSupplierMainInfoVO;
      }
   }
}
