package com.trade.service.salesorder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trade.service.salesorder.domain.SalesOrderLogistics;
import com.trade.service.salesorder.mapper.SalesOrderLogisticsMapper;
import com.trade.service.salesorder.service.ISalesOrderContainerService;
import com.trade.service.salesorder.service.ISalesOrderLogisticsService;
import com.trade.service.salesorder.vo.SalesOrderLogisticsDtlVO;
import com.trade.service.salesorder.vo.SalesOrderLogisticsSearch;
import com.trade.service.salesorder.vo.SalesOrderLogisticsVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 销售订单-物流信息 服务实现类
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-06
 */
@Service
public class SalesOrderLogisticsServiceImpl extends ServiceImpl<SalesOrderLogisticsMapper, SalesOrderLogistics> implements ISalesOrderLogisticsService {

    @Resource
    private ISalesOrderContainerService salesOrderContainerService;


    @Override
    public SalesOrderLogistics getByOrderId(Long orderId) {
        return getBaseMapper().selectOne(new QueryWrapper<SalesOrderLogistics>().eq("order_id", orderId));
    }

    @Override
    public PageInfo<SalesOrderLogisticsVO> queryListBySearch(SalesOrderLogisticsSearch search) {
        PageHelper.startPage(search.getPage(), search.getRows());
        List<SalesOrderLogisticsVO> list = this.baseMapper.queryListBySearch(search);
        return new PageInfo<>(list);
    }

    @Override
    public SalesOrderLogisticsDtlVO getDetailByOrderNo(String orderNo) {
        SalesOrderLogisticsDtlVO salesOrderLogisticsDtlVO = this.baseMapper.getDetailByOrderNo(orderNo);
        if (null != salesOrderLogisticsDtlVO) {
            salesOrderLogisticsDtlVO.setSalesOrderContainerList(
                    salesOrderContainerService.listByLogisticsId(salesOrderLogisticsDtlVO.getId()));
        }
        return salesOrderLogisticsDtlVO;
    }
}
