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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.sale.deliver.SaDeliverItems;
import com.hzs.sale.deliver.mapper.SaDeliverItemsMapper;
import com.hzs.sale.deliver.service.ISaDeliverItemsService;
import com.hzs.sale.deliver.vo.DeliverBarCodeVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 发货单明细表 服务实现类
 */
@Service
public class SaDeliverItemsServiceImpl extends ServiceImpl<SaDeliverItemsMapper, SaDeliverItems> implements ISaDeliverItemsService {

    @Override
    public List<DeliverBarCodeVO> deliverCodeData(List<Long> idList, List<Long> orderIdList, Integer pkCountry, Integer bind) {
        return baseMapper.deliverCodeData(idList, orderIdList, pkCountry, bind);
    }

    @Override
    public List<SaDeliverItems> queryDeliverItemsByOrder(Long pkOrder,
                                                         List<Long> pkOrderItemList,
                                                         List<Integer> orderStatusList,
                                                         Integer pkCountry) {
        return baseMapper.queryDeliverItemsByOrder(pkOrder, pkOrderItemList, orderStatusList, pkCountry);
    }

    @Override
    public void deleteSaDeliverItems(Long pkOrder, List<Long> pkOrderItemsList) {
        LambdaUpdateWrapper<SaDeliverItems> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(SaDeliverItems::getDelFlag, EYesNo.NO.getIntValue());
        updateWrapper.set(SaDeliverItems::getModifiedTime, DateUtils.currentDateTime());
        updateWrapper.eq(SaDeliverItems::getPkOrder, pkOrder);
        if (pkOrderItemsList != null && pkOrderItemsList.size() > 0) {
            updateWrapper.in(SaDeliverItems::getPkOrderItems, pkOrderItemsList);
        }
        update(updateWrapper);
    }
}
