package com.zcloud.zcGbsServicer.command.query;

import com.zcloud.zcGbsServicer.command.convertor.FireResourceCoConvertor;
import com.zcloud.zcGbsServicer.dto.FireResourceStaPageQry;
import com.zcloud.zcGbsServicer.dto.clientobject.FireResourceStaCO;
import com.zcloud.zcGbsServicer.persistence.dataobject.FireResourceStaDO;
import com.zcloud.zcGbsServicer.persistence.repository.FireResourceRepository;
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;

@Component
@AllArgsConstructor
public class FireResourceQueryExe {

    private FireResourceRepository fireResourceRepository;
    private FireResourceCoConvertor fireResourceCoConvertor;

    public PageResponse<FireResourceStaCO> execute(FireResourceStaPageQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        PageResponse<FireResourceStaDO> pageResponse = fireResourceRepository.listPage(params);
        List<FireResourceStaCO> cos = fireResourceCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(cos, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

}
