package com.zcloud.primeport.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.primeport.command.convertor.VehicleBlackCoConvertor;
import com.zcloud.primeport.dto.VehicleBlackPageQry;
import com.zcloud.primeport.dto.clientobject.VehicleBlackCO;
import com.zcloud.primeport.persistence.dataobject.VehicleBlackDO;
import com.zcloud.primeport.persistence.repository.VehicleBlackRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:27
 */
@Component
@AllArgsConstructor
public class VehicleBlackQueryExe {
    private final VehicleBlackRepository vehicleBlackRepository;
    private final VehicleBlackCoConvertor vehicleBlackCoConvertor;

    /**
     * 分页
     *
     * @param vehicleBlackPageQry
     * @return
     */
    public PageResponse<VehicleBlackCO> execute(VehicleBlackPageQry vehicleBlackPageQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(vehicleBlackPageQry);
        PageResponse<VehicleBlackDO> pageResponse = vehicleBlackRepository.listPage(parmas);
        List<VehicleBlackCO> examCenterCOS = vehicleBlackCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public VehicleBlackCO getInfoById(Long id) {
        VehicleBlackDO data = vehicleBlackRepository.getInfoById(id);
        return vehicleBlackCoConvertor.converDOToCO(data);
    }
}

