package com.zcloud.primeport.command.query;

import com.zcloud.primeport.command.convertor.MkmjSwipeCardRecordCoConvertor;
import com.zcloud.primeport.dto.MkmjSwipeCardRecordPageQry;
import com.zcloud.primeport.dto.clientobject.MkmjSwipeCardRecordCO;
import com.zcloud.primeport.persistence.dataobject.MkmjSwipeCardRecordDO;
import com.zcloud.primeport.persistence.repository.MkmjSwipeCardRecordRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.alibaba.cola.dto.PageResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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


/**
 * web-app
 *
 * @Author dearLin
 * @Date 2026-04-22 17:04:01
 */
@Component
@AllArgsConstructor
public class MkmjSwipeCardRecordQueryExe {
    private final MkmjSwipeCardRecordRepository mkmjSwipeCardRecordRepository;
    private final MkmjSwipeCardRecordCoConvertor mkmjSwipeCardRecordCoConvertor;

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public MkmjSwipeCardRecordCO queryById(Long id) {
        return mkmjSwipeCardRecordCoConvertor.converDOToCO(mkmjSwipeCardRecordRepository.getById(id));
    }

    /**
     * 分页
     *
     * @param mkmjSwipeCardRecordPageQry
     * @return
     */
    public PageResponse<MkmjSwipeCardRecordCO> execute(MkmjSwipeCardRecordPageQry mkmjSwipeCardRecordPageQry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(mkmjSwipeCardRecordPageQry);
        PageResponse<MkmjSwipeCardRecordDO> pageResponse = mkmjSwipeCardRecordRepository.listPage(params);
        List<MkmjSwipeCardRecordCO> examCenterCOS = mkmjSwipeCardRecordCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
}

