package com.zcloud.basic.info.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.basic.info.command.convertor.CorpQualificationInfoCoConvertor;
import com.zcloud.basic.info.dto.CorpQualificationInfoPageQry;
import com.zcloud.basic.info.dto.clientobject.CorpQualificationInfoCO;
import com.zcloud.basic.info.persistence.dataobject.CorpQualificationInfoDO;
import com.zcloud.basic.info.persistence.repository.CorpQualificationInfoRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2025-10-29 16:02:46
 */
@Component
@AllArgsConstructor
public class CorpQualificationInfoQueryExe {
    private final CorpQualificationInfoRepository corpQualificationInfoRepository;
    private final CorpQualificationInfoCoConvertor corpQualificationInfoCoConvertor;

    /**
     * 分页
     *
     * @param corpQualificationInfoPageQry
     * @return
     */
    public PageResponse<CorpQualificationInfoCO> execute(CorpQualificationInfoPageQry corpQualificationInfoPageQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(corpQualificationInfoPageQry);
        PageResponse<CorpQualificationInfoDO> pageResponse = corpQualificationInfoRepository.listPage(parmas);
        List<CorpQualificationInfoCO> examCenterCOS = corpQualificationInfoCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public CorpQualificationInfoCO getInfoById(Long id) {
        CorpQualificationInfoDO corpQualificationInfoDO = corpQualificationInfoRepository.getById(id);
        CorpQualificationInfoCO corpQualificationInfoCO =new CorpQualificationInfoCO();
        BeanUtils.copyProperties(corpQualificationInfoDO, corpQualificationInfoCO);
        return corpQualificationInfoCO;
    }
}

