package com.hzs.member.empty.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.member.empty.CuMemberEmptyProduct;
import com.hzs.common.domain.member.empty.ext.CuMemberEmptyProductExt;
import com.hzs.member.empty.mapper.CuMemberEmptyProductMapper;
import com.hzs.member.empty.service.ICuMemberEmptyProductService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 空单批次明细产品 服务实现类
 *
 * @author hzs
 * @since 2023-08-28
 */
@Service
public class CuMemberEmptyProductServiceImpl extends ServiceImpl<CuMemberEmptyProductMapper, CuMemberEmptyProduct> implements ICuMemberEmptyProductService {

    @Override
    public int deleteBatch(List<CuMemberEmptyProduct> emptyProductList, Long pkMemberEmpty, Long userId) {
        return baseMapper.deleteBatch(emptyProductList, pkMemberEmpty, userId);
    }

    @Override
    public int insertOrUpdateBatch(List<CuMemberEmptyProduct> emptyProductList, Long userId) {
        return baseMapper.insertOrUpdateBatch(emptyProductList, userId);
    }

    @Override
    public Map<Long, List<CuMemberEmptyProductExt>> queryProductList(List<Long> emptyDetailIdList) {
        Map<Long, List<CuMemberEmptyProductExt>> resultMap = new HashMap<>();

        List<CuMemberEmptyProductExt> resultList = baseMapper.queryProductList(emptyDetailIdList);
        if (CollectionUtil.isNotEmpty(resultList)) {
            for (CuMemberEmptyProductExt productExt : resultList) {
                resultMap.computeIfAbsent(productExt.getPkMemberEmptyDetail(), k -> new ArrayList<>()).add(productExt);
            }
        }
        return resultMap;
    }

}
