package com.hzs.scm.trans.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.SaOrderFieldConstants;
import com.hzs.common.core.constant.ScmFieldConstants;
import com.hzs.common.core.constant.SystemFieldConstants;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.scm.po.PoOrderItems;
import com.hzs.common.domain.scm.purchase.ext.IcPurchaseInBExt;
import com.hzs.common.domain.scm.trans.TransferOrderItems;
import com.hzs.common.domain.scm.trans.ext.IcTransInBExt;
import com.hzs.common.domain.scm.trans.ext.IcTransOutBExt;
import com.hzs.scm.trans.mapper.TransferOrderItemsMapper;
import com.hzs.scm.trans.service.ITransferOrderItemsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 采购入库明细 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-12-04
 */
@Service
public class TransferOrderItemsServiceImpl extends ServiceImpl<TransferOrderItemsMapper, TransferOrderItems> implements ITransferOrderItemsService {

    @Override
    public void deleteTransferOrderItemsService(List<TransferOrderItems> transferOrderItemsList, Long pkMember) {
        baseMapper.deleteOrderItemsService(transferOrderItemsList, pkMember);
    }

    @Override
    public void deleteTransferOrderItemsByPkOrder(Long pkTransfer, Long pkMember) {
        UpdateWrapper<TransferOrderItems> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EYesNo.NO.getIntValue());
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, pkMember);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, DateUtils.currentDateTime());
        updateWrapper.eq(ScmFieldConstants.PK_TRANSFER, pkTransfer);
        update(updateWrapper);
    }

    @Override
    public List<TransferOrderItems> queryTransferOrderItemsByPk(Integer pkCountry, Long pkTransfer) {
        return baseMapper.queryTransferOrderItemsByPk(pkCountry, pkTransfer);
    }

    @Override
    public List<TransferOrderItems> queryTransferOrderItemsByList(List<Long> idList) {
        return null;
    }

    @Override
    public void updateTransferOrderItemsTotalInNum(List<IcTransInBExt> transferInbList, Long pkMember) {
        baseMapper.updateTransferOrderItemsTotalInNum(transferInbList, pkMember);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateTransferOrderItemsTotalOutNum(List<IcTransOutBExt> transferOutbList, Long pkMember) {
        baseMapper.updateTransferOrderItemsTotalOutNum(transferOutbList, pkMember);
        baseMapper.updateTransferOrderItemsTotalOutEnd(transferOutbList);
    }
}
