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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.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.po.ext.PoOrderItemsExt;
import com.hzs.common.domain.scm.purchase.ext.IcPurchaseInBExt;
import com.hzs.scm.po.mapper.PoOrderItemsMapper;
import com.hzs.scm.po.service.IPoOrderItemsService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 采购订单明细 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-11-17
 */
@Service
public class PoOrderItemsServiceImpl extends ServiceImpl<PoOrderItemsMapper, PoOrderItems> implements IPoOrderItemsService {

    @Override
    public void deleteOrderItemsService(List<PoOrderItems> poOrderItemsList, Long pkMember) {
        baseMapper.deleteOrderItemsService(poOrderItemsList, pkMember);
    }

    @Override
    public void deleteOrderItemsByPkOrder(Long pkOrder, Long pkMember) {
        UpdateWrapper<PoOrderItems> 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(SaOrderFieldConstants.PK_ORDER, pkOrder);
        update(updateWrapper);
    }

    @Override
    public List<PoOrderItemsExt> queryPoOrderItemsByPk(Integer pkCountry, Long pkOrder) {
        return baseMapper.queryPoOrderItemsByPk(pkCountry, pkOrder);
    }

    @Override
    public List<PoOrderItemsExt> queryListPoOrderItemsByPk(Integer pkCountry, Long pkOrder) {
        return baseMapper.queryListPoOrderItemsByPk(pkCountry, pkOrder);
    }

    @Override
    public List<PoOrderItems> queryPoOrderItemsByList(List<Long> idList) {
        QueryWrapper<PoOrderItems> queryWrapper = new QueryWrapper<>();
        queryWrapper.in(SystemFieldConstants.PK_ID, idList);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public void updatePoOrderItemsTotalNum(List<IcPurchaseInBExt> icPurchaseInbList, Long pkMember) {
        baseMapper.updatePoOrderItemsTotalNum(icPurchaseInbList, pkMember);
    }
}
