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

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.basic.info.command.convertor.UserCorpCoConvertor;
import com.zcloud.basic.info.dto.UserCorpPageQry;
import com.zcloud.basic.info.dto.clientobject.UserCorpCO;
import com.zcloud.basic.info.persistence.dataobject.UserCorpDO;
import com.zcloud.basic.info.persistence.repository.UserCorpRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2025-12-02 11:13:33
 */
@Component
@AllArgsConstructor
public class UserCorpQueryExe {
    private final UserCorpRepository userCorpRepository;
    private final UserCorpCoConvertor userCorpCoConvertor;

    /**
     * 分页
     *
     * @param userCorpPageQry
     * @return
     */
    public PageResponse<UserCorpCO> execute(UserCorpPageQry userCorpPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(userCorpPageQry);
        PageResponse<UserCorpDO> pageResponse = userCorpRepository.listPage(params);
        List<UserCorpCO> examCenterCOS = userCorpCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

