package com.zcloud.zcGbsServicer.command.query;

import com.zcloud.zcGbsServicer.command.convertor.ResourceDeviceCoConvertor;
import com.zcloud.zcGbsServicer.dto.ResourceDevicePageQry;
import com.zcloud.zcGbsServicer.dto.clientobject.ResourceDeviceCO;
import com.zcloud.zcGbsServicer.persistence.dataobject.ResourceDeviceDO;
import com.zcloud.zcGbsServicer.persistence.repository.ResourceDeviceRepository;
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 makejava
* @Date 2026-01-21 17:23:16
*/
@Component
@AllArgsConstructor
public class ResourceDeviceQueryExe {
    private final ResourceDeviceRepository resourceDeviceRepository;
    private final ResourceDeviceCoConvertor resourceDeviceCoConvertor;

    /**
    * 分页
    *
    * @param resourceDevicePageQry
    * @return
    */
    public PageResponse<ResourceDeviceCO> execute(ResourceDevicePageQry resourceDevicePageQry) {
        Map<String,Object> params = PageQueryHelper.toHashMap(resourceDevicePageQry);
        PageResponse<ResourceDeviceDO> pageResponse = resourceDeviceRepository.listPage(params);
            List<ResourceDeviceCO> examCenterCOS = resourceDeviceCoConvertor.converDOsToCOs(pageResponse.getData());
                return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

