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

import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpSupplierSimpleVo;
import com.bonus.canteen.core.supply.purchase.mapper.DrpPurchaseMenuMaterialSupplierMapper;
import com.bonus.canteen.core.supply.purchase.service.DrpMenuMaterialSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class DrpMenuMaterialSupplierServiceImpl implements DrpMenuMaterialSupplierService {
   @Autowired
   private DrpPurchaseMenuMaterialSupplierMapper drpPurchaseMenuMaterialSupplierMapper;

//   @Transactional(
//      rollbackFor = {Exception.class}
//   )
//   public void add(DrpMenuMaterialSupplierAddDTO content) {
//      if (CollUtil.isNotEmpty(content.getDrpMenuMaterialSupplierDetailAddDTOList())) {
//         content.getDrpMenuMaterialSupplierDetailAddDTOList().forEach((d) -> {
//            this.drpMenuMaterialSupplierMapper.delete((Wrapper)((LambdaQueryWrapper)Wrappers.lambdaQuery(DrpMenuMaterialSupplier.class).eq(DrpMenuMaterialSupplier::getCanteenId, d.getCanteenId())).and((wrapper) -> {
//               ((LambdaQueryWrapper)((LambdaQueryWrapper)wrapper.eq(DrpMenuMaterialSupplier::getMaterialId, content.getMaterialId())).or()).eq(DrpMenuMaterialSupplier::getCategoryId, content.getCategoryId());
//            }));
//            DrpMenuMaterialSupplier drpMenuMaterialSupplier = new DrpMenuMaterialSupplier();
//            drpMenuMaterialSupplier.setId(Id.next());
//            drpMenuMaterialSupplier.setCanteenId(d.getCanteenId());
//            drpMenuMaterialSupplier.setSupplierId(d.getSupplierId());
//            drpMenuMaterialSupplier.setMaterialId(content.getMaterialId());
//            drpMenuMaterialSupplier.setDelFlag(LeConstants.COMMON_NO);
//            drpMenuMaterialSupplier.setCategoryId(content.getCategoryId());
//            String userName = (String)SecureManager.getSubjectName().get();
//            drpMenuMaterialSupplier.setCrby(userName);
//            drpMenuMaterialSupplier.setCrtime(LocalDateTime.now());
//            drpMenuMaterialSupplier.setUpby(userName);
//            drpMenuMaterialSupplier.setUptime(LocalDateTime.now());
//            this.drpMenuMaterialSupplierMapper.insert(drpMenuMaterialSupplier);
//         });
//      }
//
//   }
//
//   public List<DrpMenuMaterialSupplierDetailVO> detail(Long content) {
//      return this.drpMenuMaterialSupplierMapper.detail(content);
//   }
//
//   public List<DrpMenuMaterialSupplierCanteenVO> getSupplierByMaterialIdAndCanteenId(DrpMenuMaterialSupplierQueryDTO content) {
//      return this.drpMenuMaterialSupplierMapper.getSupplierByMaterialIdAndCanteenId(content);
//   }

   public HashSet<DrpSupplierSimpleVo> dealSupplierCertificate(Long certId, HashSet<DrpSupplierSimpleVo> finalResult) {
      if (CollUtil.isEmpty(finalResult)) {
         return new HashSet();
      } else {
         List<Long> supplierIdList = finalResult.stream().map(DrpSupplierSimpleVo::getSupplierId).collect(Collectors.toList());
         return this.drpPurchaseMenuMaterialSupplierMapper.getMaterialSupplierCert(certId, supplierIdList);
      }
   }

//   public List<DrpSupplierMaterialCertVO> checkSupplierMaterialCert(DrpSupplierMaterialCertDTO content) {
//      return this.drpMenuMaterialSupplierMapper.checkSupplierMaterialCert(content);
//   }
}
