package com.zcloud.primeport.command.query;

import com.zcloud.primeport.command.convertor.VehicleDockLogCoConvertor;
import com.zcloud.primeport.dto.VehicleDockLogPageQry;
import com.zcloud.primeport.dto.clientobject.VehicleDockLogCO;
import com.zcloud.primeport.persistence.dataobject.VehicleDockLogDO;
import com.zcloud.primeport.persistence.repository.VehicleDockLogRepository;
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-14 14:53:30
 */
@Component
@AllArgsConstructor
public class VehicleDockLogQueryExe {
    private final VehicleDockLogRepository vehicleDockLogRepository;
    private final VehicleDockLogCoConvertor vehicleDockLogCoConvertor;

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public VehicleDockLogCO queryById(Long id) {
        return vehicleDockLogCoConvertor.converDOToCO(vehicleDockLogRepository.getById(id));
    }

    /**
     * 分页
     *
     * @param vehicleDockLogPageQry
     * @return
     */
    public PageResponse<VehicleDockLogCO> execute(VehicleDockLogPageQry vehicleDockLogPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(vehicleDockLogPageQry);
        PageResponse<VehicleDockLogDO> pageResponse = vehicleDockLogRepository.listPage(params);
        List<VehicleDockLogCO> examCenterCOS = vehicleDockLogCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

