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

import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.basic.info.command.convertor.RzUserRecordCoConvertor;
import com.zcloud.basic.info.dto.RzUserRecordPageQry;
import com.zcloud.basic.info.dto.RzUserRecordListQry;
import com.zcloud.basic.info.dto.clientobject.RzUserRecordCO;
import com.zcloud.basic.info.persistence.dataobject.RzUserRecordDO;
import com.zcloud.basic.info.persistence.repository.RzUserRecordRepository;
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-05 14:00:37
 */
@Component
@AllArgsConstructor
public class RzUserRecordQueryExe {
    private final RzUserRecordRepository rzUserRecordRepository;
    private final RzUserRecordCoConvertor rzUserRecordCoConvertor;

    /**
     * 分页
     *
     * @return
     */
    public PageResponse<RzUserRecordCO> execute(RzUserRecordPageQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        PageResponse<RzUserRecordDO> pageResponse = rzUserRecordRepository.listPage(params);
        List<RzUserRecordCO> examCenterCOS = rzUserRecordCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public MultiResponse<RzUserRecordCO> execute(RzUserRecordListQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        List<RzUserRecordDO> list = rzUserRecordRepository.list(params);
        List<RzUserRecordCO> examCenterCOS = rzUserRecordCoConvertor.converDOsToCOs(list);
        return MultiResponse.of(examCenterCOS);
    }

    public SingleResponse<RzUserRecordCO> execute(Long id) {
        SingleResponse<RzUserRecordDO> rzUserRecordDO = rzUserRecordRepository.getInfoById(id);
        RzUserRecordCO co = new RzUserRecordCO();
        BeanUtils.copyProperties(rzUserRecordDO.getData(), co);
        return SingleResponse.of(co);
    }

}

