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

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.fastjson.JSON;
import com.zcloud.basic.info.command.convertor.sync.SyncDepartmentCoConvertor;
import com.zcloud.basic.info.command.convertor.sync.SyncUserCoConvertor;
import com.zcloud.basic.info.dto.clientobject.sync.SyncDepartmentCO;
import com.zcloud.basic.info.dto.clientobject.sync.SyncUserCO;
import com.zcloud.basic.info.dto.sync.SyncDepartmentQryPageCmd;
import com.zcloud.basic.info.dto.sync.SyncUserQryPageCmd;
import com.zcloud.basic.info.persistence.dataobject.sync.SyncDepartmentDO;
import com.zcloud.basic.info.persistence.dataobject.sync.SyncUserDO;
import com.zcloud.basic.info.persistence.repository.sync.SyncDepartmentRepository;
import com.zcloud.basic.info.persistence.repository.sync.SyncUserRepository;
import com.zcloud.basic.info.utils.SyncPageResponse;
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 zhangyue
 * @Date 2025-11-04 14:07:36
 */
@Component
@AllArgsConstructor
public class SyncQueryExe {
    private final SyncUserRepository syncUserRepository;
    private final SyncUserCoConvertor syncUserCoConvertor;
    private final SyncDepartmentRepository syncDepartmentRepository;
    private final SyncDepartmentCoConvertor syncDepartmentCoConvertor;
    public SyncPageResponse listPageSyncUser(SyncUserQryPageCmd cmd) {
        Map<String, Object> params = PageQueryHelper.toHashMap(cmd);
        PageResponse<SyncUserDO> pageResponse = syncUserRepository.listPageSyncUser(params);
        List<SyncUserCO> userCOList = syncUserCoConvertor.converDOsToCOs(pageResponse.getData());

        return SyncPageResponse.of(userCOList, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
    public SyncPageResponse listPageSyncDepartment(SyncDepartmentQryPageCmd cmd) {
        Map<String, Object> params = PageQueryHelper.toHashMap(cmd);
        PageResponse<SyncDepartmentDO> pageResponse = syncDepartmentRepository.listPageSyncDepartment(params);
        List<SyncDepartmentCO> userCOList = syncDepartmentCoConvertor.converDOsToCOs(pageResponse.getData());

        return SyncPageResponse.of(userCOList, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

