package com.sckw.transport.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.transport.dao.KwtWaybillOrderNodeMapper;
import com.sckw.transport.model.KwtWaybillOrderNode;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author PC
 */
@Repository
public class KwtWaybillOrderNodeRepository extends ServiceImpl<KwtWaybillOrderNodeMapper, KwtWaybillOrderNode> {

    /**
     * 根据运单ID查询节点轨迹列表
     *
     * @param wOrderId   运单ID
     * @param wSubtaskId 运单子单ID（可选）
     * @return 节点轨迹列表，按创建时间正序排列
     */
    public List<KwtWaybillOrderNode> queryNodesByOrderId(Long wOrderId, Long wSubtaskId) {
        LambdaQueryWrapper<KwtWaybillOrderNode> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(KwtWaybillOrderNode::getWOrderId, wOrderId);
        if (wSubtaskId != null) {
            wrapper.eq(KwtWaybillOrderNode::getWSubtaskId, wSubtaskId);
        }
        wrapper.orderByAsc(KwtWaybillOrderNode::getCreateTime);
        return this.list(wrapper);
    }
}
