package com.zcloud.primeport.command.query;

import com.zcloud.primeport.command.convertor.EVehicleArrivalDepartureInfoCoConvertor;
import com.zcloud.primeport.dto.EVehicleArrivalDepartureInfoPageQry;
import com.zcloud.primeport.dto.clientobject.EVehicleArrivalDepartureInfoCO;
import com.zcloud.primeport.persistence.dataobject.EVehicleArrivalDepartureInfoDO;
import com.zcloud.primeport.persistence.repository.EVehicleArrivalDepartureInfoRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.alibaba.cola.dto.PageResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author dearLin
 * @Date 2026-05-27 17:45:44
 */
@Component
@AllArgsConstructor
public class EVehicleArrivalDepartureInfoQueryExe {
    private final EVehicleArrivalDepartureInfoRepository eVehicleArrivalDepartureInfoRepository;
    private final EVehicleArrivalDepartureInfoCoConvertor eVehicleArrivalDepartureInfoCoConvertor;

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public EVehicleArrivalDepartureInfoCO queryById(Long id) {
        return eVehicleArrivalDepartureInfoCoConvertor.converDOToCO(eVehicleArrivalDepartureInfoRepository.getById(id));
    }

    /**
     * 分页
     *
     * @param eVehicleArrivalDepartureInfoPageQry
     * @return
     */
    public PageResponse<EVehicleArrivalDepartureInfoCO> execute(EVehicleArrivalDepartureInfoPageQry eVehicleArrivalDepartureInfoPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(eVehicleArrivalDepartureInfoPageQry);
        PageResponse<EVehicleArrivalDepartureInfoDO> pageResponse = eVehicleArrivalDepartureInfoRepository.listPage(params);
        List<EVehicleArrivalDepartureInfoCO> examCenterCOS = eVehicleArrivalDepartureInfoCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

