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

import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.basic.info.command.convertor.RzUserCoConvertor;
import com.zcloud.basic.info.dto.RzUserPageQry;
import com.zcloud.basic.info.dto.RzUserListQry;
import com.zcloud.basic.info.dto.clientobject.RzUserCO;
import com.zcloud.basic.info.persistence.dataobject.RzUserDO;
import com.zcloud.basic.info.persistence.repository.RzUserRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.beans.BeanUtils;

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


/**
 * web-app
 *
 * @Author SondonYong
 * @Date 2025-12-02 17:15:56
 */
@Component
@AllArgsConstructor
public class RzUserQueryExe {
    private final RzUserRepository rzUserRepository;
    private final RzUserCoConvertor rzUserCoConvertor;

    /**
     * 分页
     *
     * @return
     */
    public PageResponse<RzUserCO> execute(RzUserPageQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        PageResponse<RzUserDO> pageResponse = rzUserRepository.listPage(params);
        List<RzUserCO> examCenterCOS = rzUserCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public MultiResponse<RzUserCO> execute(RzUserListQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        List<RzUserDO> list = rzUserRepository.list(params);
        List<RzUserCO> examCenterCOS = rzUserCoConvertor.converDOsToCOs(list);
        return MultiResponse.of(examCenterCOS);
    }

    public SingleResponse<RzUserCO> execute(Long id) {
        SingleResponse<RzUserDO> rzUserDO = rzUserRepository.getInfoById(id);
        RzUserCO co = new RzUserCO();
        BeanUtils.copyProperties(rzUserDO.getData(), co);
        return SingleResponse.of(co);
    }

}

