package com.hzs.sale.wares.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.sale.wares.BdWaresExtend;
import com.hzs.common.domain.sale.wares.BdWaresMemberLimit;
import com.hzs.sale.order.param.WaresNumberParam;
import com.hzs.sale.order.vo.WaresPreSaleVo;
import com.hzs.sale.wares.mapper.BdWaresExtendMapper;
import com.hzs.sale.wares.service.IBdWaresExtendService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * 商品发布扩展表 服务实现类
 */
@Service
public class BdWaresExtendServiceImpl extends ServiceImpl<BdWaresExtendMapper, BdWaresExtend> implements IBdWaresExtendService {

    @Override
    public void updateWaresSalesAccrual(List<WaresNumberParam> waresNumberParamList) {
        if (waresNumberParamList != null && waresNumberParamList.size() > 0) {
            for (WaresNumberParam waresNumberParam : waresNumberParamList) {
                Integer pkWares = waresNumberParam.getPkWares();
                Integer number = waresNumberParam.getNumber();
                if (number == null) {
                    number = 0;
                }
                baseMapper.updateWaresSalesAccrual(pkWares, number);
            }
        }
    }

    @Override
    public void updatePutOnTimeAndPutOffTimeByWaresId(Integer waresId, Date putOnTime, Date putOffTime) {
        baseMapper.updatePutOnTimeAndPutOffTimeByWaresId(waresId, putOnTime, putOffTime);
    }

    @Override
    public List<WaresPreSaleVo> selectByWaresCodeList(Collection<String> waresCodeList, Integer specialArea) {
        return baseMapper.selectByWaresCodeList(waresCodeList, specialArea);
    }

    @Override
    public List<BdWaresExtend> listByPkWaresList(Collection<Integer> pkWaresList) {
        if (CollectionUtil.isNotEmpty(pkWaresList)) {
            return this.list(Wrappers.<BdWaresExtend>lambdaQuery()
                    .in(BdWaresExtend::getPkWares, pkWaresList)
                    .orderByAsc(BdWaresExtend::getPkWares)
            );
        }
        return Collections.emptyList();
    }

    @Override
    public int batchUpdateInventoryUse(List<BdWaresMemberLimit> limitList) {
        return baseMapper.batchUpdateInventoryUse(limitList);
    }

}
