package com.zcloud.primeport.command.query;

import com.zcloud.primeport.command.convertor.EVehicleBasicInfoCoConvertor;
import com.zcloud.primeport.dto.EVehicleBasicInfoPageQry;
import com.zcloud.primeport.dto.clientobject.EVehicleBasicInfoCO;
import com.zcloud.primeport.persistence.dataobject.EVehicleBasicInfoDO;
import com.zcloud.primeport.persistence.repository.EVehicleBasicInfoRepository;
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-04-23 10:04:33
 */
@Component
@AllArgsConstructor
public class EVehicleBasicInfoQueryExe {
    private final EVehicleBasicInfoRepository eVehicleBasicInfoRepository;
    private final EVehicleBasicInfoCoConvertor eVehicleBasicInfoCoConvertor;

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public EVehicleBasicInfoCO queryById(Long id) {
        return eVehicleBasicInfoCoConvertor.converDOToCO(eVehicleBasicInfoRepository.getById(id));
    }

    /**
     * 分页
     *
     * @param eVehicleBasicInfoPageQry
     * @return
     */
    public PageResponse<EVehicleBasicInfoCO> execute(EVehicleBasicInfoPageQry eVehicleBasicInfoPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(eVehicleBasicInfoPageQry);
        PageResponse<EVehicleBasicInfoDO> pageResponse = eVehicleBasicInfoRepository.listPage(params);
        List<EVehicleBasicInfoCO> examCenterCOS = eVehicleBasicInfoCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

