package com.fjhx.service.logistics.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.base.Condition;
import com.fjhx.entity.logistics.LogisticsDetails;
import com.fjhx.mapper.logistics.LogisticsDetailsMapper;
import com.fjhx.params.logistics.LogisticsDetailsVo;
import com.fjhx.service.logistics.LogisticsDetailsService;
import com.fjhx.utils.Assert;
import com.fjhx.utils.wrapperUtil.IWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 物流明细 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2022-11-30
 */
@Service
public class LogisticsDetailsServiceImpl extends ServiceImpl<LogisticsDetailsMapper, LogisticsDetails> implements LogisticsDetailsService {

    @Override
    public Page<LogisticsDetails> getPage(Map<String, Object> condition) {

        IWrapper<LogisticsDetails> wrapper = IWrapper.getWrapper(condition);

        return page(condition, wrapper);
    }

    @Override
    public void add(LogisticsDetailsVo logisticsDetailsVo) {
        save(logisticsDetailsVo);
    }

    @Override
    public void edit(LogisticsDetailsVo logisticsDetailsVo) {
        updateById(logisticsDetailsVo);
    }

    @Override
    public void delete(LogisticsDetailsVo logisticsDetailsVo) {
        removeById(logisticsDetailsVo.getId());
    }

    @Override
    public List<Map<String, Object>> getLogisticsDetailsByLogisticsId(Condition condition) {
        Long id = condition.getLong("id");
        Assert.notEmpty(id, "物流单id不能为空");

        IWrapper<Object> wrapper = IWrapper.getWrapper(condition);
        wrapper.eq("ld.id", id);

        return baseMapper.getLogisticsDetailsByLogisticsId(wrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void submitLogisticsDetails(List<LogisticsDetails> logisticsDetailsList) {
        saveBatch(logisticsDetailsList);

        // 更新申购入库数量



        // 更新库存

    }

}
