package com.ozs.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ozs.entity.VehiclePosition;
import com.ozs.entity.vo.VehiclePositionResp;
import com.ozs.mapper.VehiclePositionMapper;
import com.ozs.service.VehiclePositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 机车行驶表 服务实现类
 * </p>
 *
 * @author ozs
 * @since 2023-04-11
 */
@Service
public class VehiclePositionServiceImpl extends ServiceImpl<VehiclePositionMapper, VehiclePosition> implements VehiclePositionService {

    @Autowired
    private VehiclePositionMapper vehiclePositionMapper;

    @Override
    public List<VehiclePosition> selectVehiclePositionList(VehiclePositionResp vehiclePositionResp) {
        List<VehiclePosition> list = vehiclePositionMapper.list(vehiclePositionResp.getVehicleCode(),vehiclePositionResp.getRailwayCode(),
                vehiclePositionResp.getLineDir(),vehiclePositionResp.getStatus());
        return list;
    }

    @Override
    public IPage listToPage(List list, int pageNum, int pageSize) {
        List pageList = new ArrayList<>();
        int curIdx = pageNum > 1 ? (pageNum - 1) * pageSize : 0;
        for (int i = 0; i < pageSize && curIdx + i < list.size(); i++) {
            pageList.add(list.get(curIdx + i));
        }
        IPage page = new Page<>(pageNum, pageSize);
        page.setRecords(pageList);
        page.setTotal(list.size());
        return page;
    }
}
