package com.zcloud.primeport.persistence.repository.impl;

import com.zcloud.primeport.persistence.dataobject.EVehicleArrivalDepartureInfoDO;
import com.zcloud.primeport.persistence.mapper.EVehicleArrivalDepartureInfoMapper;
import com.zcloud.primeport.persistence.repository.EVehicleArrivalDepartureInfoRepository;
import com.alibaba.cola.dto.PageResponse;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.gbscommon.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * web-infrastructure
 *
 * @Author dearLin
 * @Date 2026-05-27 17:45:44
 */
@Service
@RequiredArgsConstructor
public class EVehicleArrivalDepartureInfoRepositoryImpl extends BaseRepositoryImpl<EVehicleArrivalDepartureInfoMapper, EVehicleArrivalDepartureInfoDO> implements EVehicleArrivalDepartureInfoRepository {
    private final EVehicleArrivalDepartureInfoMapper eVehicleArrivalDepartureInfoMapper;

    @Override
    public PageResponse<EVehicleArrivalDepartureInfoDO> listPage(Map<String, Object> params) {
        IPage<EVehicleArrivalDepartureInfoDO> iPage = new Query<EVehicleArrivalDepartureInfoDO>().getPage(params);
        QueryWrapper<EVehicleArrivalDepartureInfoDO> queryWrapper = new QueryWrapper<>();
        queryWrapper = PageQueryHelper.createPageQueryWrapper(queryWrapper, params);
        if (params.get("startVehicleArrivalTime") != null && !"".equals(params.get("startVehicleArrivalTime"))) {
            queryWrapper.ge("vehicle_arrival_time", params.get("startVehicleArrivalTime"));
        }
        if (params.get("endVehicleArrivalTime") != null && !"".equals(params.get("endVehicleArrivalTime"))) {
            queryWrapper.le("vehicle_arrival_time", params.get("endVehicleArrivalTime"));
        }
        if (params.get("startVehicleDepartureTime") != null && !"".equals(params.get("startVehicleDepartureTime"))) {
            queryWrapper.ge("vehicle_departure_time", params.get("startVehicleDepartureTime"));
        }
        if (params.get("endVehicleDepartureTime") != null && !"".equals(params.get("endVehicleDepartureTime"))) {
            queryWrapper.le("vehicle_departure_time", params.get("endVehicleDepartureTime"));
        }
        queryWrapper.orderByDesc("create_time");
        IPage<EVehicleArrivalDepartureInfoDO> result = eVehicleArrivalDepartureInfoMapper.selectPage(iPage, queryWrapper);
        return PageHelper.pageToResponse(result, result.getRecords());
    }
}

