package com.hzs.scm.store.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.SystemFieldConstants;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.scm.store.IcStoreOutB;
import com.hzs.common.domain.scm.store.ext.IcStoreOutBExt;
import com.hzs.common.domain.scm.store.ext.IcStoreOutHExt;
import com.hzs.scm.store.mapper.IcStoreOutBMapper;
import com.hzs.scm.store.service.IIcStoreOutBService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 店铺出库单明细表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2024-05-11
 */
@Service
public class IcStoreOutBServiceImpl extends ServiceImpl<IcStoreOutBMapper, IcStoreOutB> implements IIcStoreOutBService {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateStoreOutItemStatus(List<IcStoreOutHExt> storeOutList, Integer orderStatus, Long pkMember) {
        List<Long> itemIdList = new ArrayList<>();
        for (IcStoreOutHExt storeOutExt : storeOutList) {
            for (IcStoreOutBExt icStoreOutBiExt : storeOutExt.getStoreOutBiExtList()) {
                itemIdList.add(icStoreOutBiExt.getPkId());
            }
        }
        UpdateWrapper<IcStoreOutB> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SaOrderFieldConstants.ORDER_STATUS, orderStatus);
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, pkMember);
        updateWrapper.set(SystemFieldConstants.MODIFIED_TIME, DateUtils.currentDateTime());
        updateWrapper.in(SystemFieldConstants.PK_ID,itemIdList);
        update(updateWrapper);
    }
}
