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


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.domain.sale.wares.BdWaresExtend;
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.Date;
import java.util.List;

/**
 * <p>
 * 商品发布扩展表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2022-09-09
 */
@Service
public class BdWaresExtendServiceImpl extends ServiceImpl<BdWaresExtendMapper, BdWaresExtend> implements IBdWaresExtendService {
    /**
     * 修改销量
     * @param waresNumberParamList
     */
    @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);
            }
        }

    }
    /**
     * 修改上下架时间
     * @param waresId
     */
    @Override
    public void updatePutOnTime(Integer waresId) {
        baseMapper.updatePutOnTime(waresId);
    }

    /**
     * 修改上下架时间
     * @param waresId
     */
    @Override
    public void updatePutOffTime(Integer waresId) {
        baseMapper.updatePutOffTime(waresId);
    }
    /**
     * 根据商品id修改拓展表（可以赋值空值）
     * @param waresExtend
     */
    @Override
    public void updateByPkWares(BdWaresExtend waresExtend) {
        baseMapper.updateByPkWares(waresExtend);
    }
    /**
     * 设置上下架时间
     * @param waresId
     * @param putOnTime
     * @param putOffTime
     */
    @Override
    public void updatePutOnTimeAndPutOffTimeByWaresId(Integer waresId, Date putOnTime, Date putOffTime) {
        baseMapper.updatePutOnTimeAndPutOffTimeByWaresId( waresId,  putOnTime,  putOffTime);
    }

    /**
     * 根据商品编号查询 每个商品所剩余的预售数量
     * @param waresCodeList
     * @param specialArea
     * @return
     */
    @Override
    public List<WaresPreSaleVo> selectByWaresCodeList(Collection<String> waresCodeList, Integer specialArea) {
        return baseMapper.selectByWaresCodeList(waresCodeList, specialArea);
    }
}
