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

import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.basic.info.command.convertor.UserQualificationInfoCoConvertor;
import com.zcloud.basic.info.dto.UserQualificationInfoPageQry;
import com.zcloud.basic.info.dto.clientobject.UserQualificationInfoCO;
import com.zcloud.basic.info.persistence.dataobject.UserQualificationInfoDO;
import com.zcloud.basic.info.persistence.repository.UserQualificationInfoRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

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



/**
* web-app
* @Author SondonYong
* @Date 2025-10-31 09:50:37
*/
@Component
@AllArgsConstructor
public class UserQualificationInfoQueryExe {
    private final UserQualificationInfoRepository userQualificationInfoRepository;
    private final UserQualificationInfoCoConvertor userQualificationInfoCoConvertor;

    /**
    * 分页
    *
    * @param userQualificationInfoPageQry
    * @return
    */
    public PageResponse<UserQualificationInfoCO> execute(UserQualificationInfoPageQry userQualificationInfoPageQry) {


        Map<String,Object> params = PageQueryHelper.toHashMap(userQualificationInfoPageQry);
        PageResponse<UserQualificationInfoDO> pageResponse = userQualificationInfoRepository.listPage(params);
        if(pageResponse != null && pageResponse.getData() != null && pageResponse.getData().size() > 0){
            List<UserQualificationInfoCO> examCenterCOS = userQualificationInfoCoConvertor.converDOsToCOs(pageResponse.getData());
            return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
        }else {
            return PageResponse.of(0, 0);
        }
    }

    public MultiResponse<UserQualificationInfoCO> executeList(UserQualificationInfoPageQry userQualificationInfoPageQry) {

        Map<String,Object> params = PageQueryHelper.toHashMap(userQualificationInfoPageQry);
        MultiResponse<UserQualificationInfoDO> listResponse = userQualificationInfoRepository.list(params);
        if(listResponse != null && listResponse.getData() != null && listResponse.getData().size() > 0){
            List<UserQualificationInfoCO> examCenterCOS = userQualificationInfoCoConvertor.converDOsToCOs(listResponse.getData());
            return MultiResponse.of(examCenterCOS);
        }else {
            return MultiResponse.of(new ArrayList<>());
        }

    }

    public SingleResponse<UserQualificationInfoCO> execute(Long id) {
        SingleResponse<UserQualificationInfoDO> userQualificationInfoDO = userQualificationInfoRepository.getInfoById(id);
        UserQualificationInfoCO co = new UserQualificationInfoCO();
        if(userQualificationInfoDO != null && userQualificationInfoDO.getData() != null){
            BeanUtils.copyProperties(userQualificationInfoDO.getData(),co);
        }
        return SingleResponse.of(co);

    }
}

