package com.zcloud.primeport.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.primeport.command.convertor.VehicleViolationsCoConvertor;
import com.zcloud.primeport.dto.VehicleViolationsPageQry;
import com.zcloud.primeport.dto.clientobject.VehicleViolationsCO;
import com.zcloud.primeport.persistence.dataobject.VehicleViolationsDO;
import com.zcloud.primeport.persistence.repository.VehicleViolationsRepository;
import io.swagger.annotations.ApiModelProperty;
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:29
 */
@Component
@AllArgsConstructor
public class VehicleViolationsQueryExe {
    private final VehicleViolationsRepository vehicleViolationsRepository;
    private final VehicleViolationsCoConvertor vehicleViolationsCoConvertor;

    /**
     * 分页
     *
     * @param vehicleViolationsPageQry
     * @return
     */
    public PageResponse<VehicleViolationsCO> execute(VehicleViolationsPageQry vehicleViolationsPageQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(vehicleViolationsPageQry);
        PageResponse<VehicleViolationsDO> pageResponse = vehicleViolationsRepository.listPage(parmas);
        List<VehicleViolationsCO> examCenterCOS = vehicleViolationsCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public PageResponse<VehicleViolationsCO> violationRecordslistPage(VehicleViolationsPageQry qry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(qry);
        PageResponse<VehicleViolationsDO> pageResponse = vehicleViolationsRepository.violationRecordslistPage(parmas);
        List<VehicleViolationsCO> examCenterCOS = vehicleViolationsCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public VehicleViolationsCO getInfoById(Long id) {
        VehicleViolationsDO byId = vehicleViolationsRepository.getById(id);
        return vehicleViolationsCoConvertor.converDOToCO(byId);
    }
}

