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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.drp.dto.DrpMaterialProcureAddDTO;
import com.bonus.canteen.core.drp.mapper.DrpMaterialProcureMapper;
import com.bonus.canteen.core.drp.model.DrpMaterialProcure;
import com.bonus.canteen.core.drp.service.DrpMaterialProcureService;
import com.bonus.common.houqin.utils.id.Id;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DrpMaterialProcureServiceImpl implements DrpMaterialProcureService {
   @Resource
   @Lazy
   private DrpMaterialProcureMapper drpMaterialProcureMapper;

   @Override
   public void add(List<DrpMaterialProcureAddDTO> content) {
      if (CollUtil.isNotEmpty(content)) {
         this.drpMaterialProcureMapper.delete(Wrappers.lambdaQuery(DrpMaterialProcure.class)
                 .eq(DrpMaterialProcure::getMaterialId, ((DrpMaterialProcureAddDTO)content.get(0)).getMaterialId()));
         content.forEach((drpMaterialProcureAddDTO) -> {
            DrpMaterialProcure drpMaterialProcure = new DrpMaterialProcure();
            BeanUtil.copyProperties(drpMaterialProcureAddDTO, drpMaterialProcure, new String[0]);
            drpMaterialProcure.setId(Id.next());
            this.drpMaterialProcureMapper.insert(drpMaterialProcure);
         });
      }

   }

//   public List<DrpMaterialProcure> detail(Long content) {
//      return this.drpMaterialProcureMapper.selectList((Wrapper)Wrappers.lambdaQuery(DrpMaterialProcure.class).eq(DrpMaterialProcure::getMaterialId, content));
//   }
//
//   public List<DrpMaterialProcureVO> getCountByMaterialId(List<DrpMaterialProcureCountDTO> content) {
//      List<DrpMaterialProcureVO> drpMaterialProcureVOList = Lists.newArrayList();
//      if (CollUtil.isNotEmpty(content)) {
//         Iterator var3 = content.iterator();
//
//         while(var3.hasNext()) {
//            DrpMaterialProcureCountDTO drpMaterialProcureCountDTO = (DrpMaterialProcureCountDTO)var3.next();
//            DrpMaterialProcureVO drpMaterialProcureVO = this.drpMaterialProcureMapper.getCountByMaterialId(drpMaterialProcureCountDTO);
//            if (drpMaterialProcureVO != null) {
//               drpMaterialProcureVOList.add(drpMaterialProcureVO);
//            }
//         }
//      }
//
//      return drpMaterialProcureVOList;
//   }


}
