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

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.basic.info.command.convertor.DepartmentSuperviseCoConvertor;
import com.zcloud.basic.info.dto.DepartmentSupervisePageQry;
import com.zcloud.basic.info.dto.clientobject.DepartmentSuperviseCO;
import com.zcloud.basic.info.persistence.dataobject.DepartmentSuperviseDO;
import com.zcloud.basic.info.persistence.repository.DepartmentSuperviseRepository;
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-11-10 14:13:46
 */
@Component
@AllArgsConstructor
public class DepartmentSuperviseQueryExe {
    private final DepartmentSuperviseRepository departmentSuperviseRepository;
    private final DepartmentSuperviseCoConvertor departmentSuperviseCoConvertor;

    /**
     * 分页
     *
     * @param departmentSupervisePageQry
     * @return
     */
    public PageResponse<DepartmentSuperviseCO> execute(DepartmentSupervisePageQry departmentSupervisePageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(departmentSupervisePageQry);
        PageResponse<DepartmentSuperviseDO> pageResponse = departmentSuperviseRepository.listPage(params);
        List<DepartmentSuperviseCO> examCenterCOS = departmentSuperviseCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

