package com.zcloud.domain.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.domain.command.convertor.DomainDepartmentUserCoConvertor;
import com.zcloud.domain.dto.DomainDepartmentUserPageQry;
import com.zcloud.domain.dto.clientobject.DomainDepartmentUserCO;
import com.zcloud.domain.persistence.dataobject.DomainDepartmentUserDO;
import com.zcloud.domain.persistence.repository.DomainDepartmentUserRepository;
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 2026-01-27 11:29:09
 */
@Component
@AllArgsConstructor
public class DomainDepartmentUserQueryExe {
    private final DomainDepartmentUserRepository domainDepartmentUserRepository;
    private final DomainDepartmentUserCoConvertor domainDepartmentUserCoConvertor;

    /**
     * 分页
     *
     * @param domainDepartmentUserPageQry
     * @return
     */
    public PageResponse<DomainDepartmentUserCO> execute(DomainDepartmentUserPageQry domainDepartmentUserPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(domainDepartmentUserPageQry);
        PageResponse<DomainDepartmentUserDO> pageResponse = domainDepartmentUserRepository.listPage(params);
        List<DomainDepartmentUserCO> examCenterCOS = domainDepartmentUserCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public List<DomainDepartmentUserCO> listAll(DomainDepartmentUserPageQry qry) {

        List<DomainDepartmentUserDO> listByDomainDepartmentId = domainDepartmentUserRepository.getListByDomainDepartmentId(qry.getDomainDepartmentId());
        return domainDepartmentUserCoConvertor.converDOsToCOs(listByDomainDepartmentId);
    }
}

