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

import com.alibaba.cola.dto.MultiResponse;
import com.zcloud.basic.info.command.convertor.UserJobHandoverCoConvertor;
import com.zcloud.basic.info.dto.UserJobHandoverPageQry;
import com.zcloud.basic.info.dto.UserJobHandoverListQry;
import com.zcloud.basic.info.dto.clientobject.UserJobHandoverCO;
import com.zcloud.basic.info.persistence.dataobject.UserJobHandoverDO;
import com.zcloud.basic.info.persistence.repository.UserJobHandoverRepository;
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 14:08:56
 */
@Component
@AllArgsConstructor
public class UserJobHandoverQueryExe {
    private final UserJobHandoverRepository userJobHandoverRepository;
    private final UserJobHandoverCoConvertor userJobHandoverCoConvertor;

    /**
     * 分页
     *
     * @return
     */
    public PageResponse<UserJobHandoverCO> execute(UserJobHandoverPageQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        PageResponse<UserJobHandoverDO> pageResponse = userJobHandoverRepository.listPage(params);
        List<UserJobHandoverCO> examCenterCOS = userJobHandoverCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public MultiResponse<UserJobHandoverCO> execute(UserJobHandoverListQry qry) {
        Map<String, Object> params = PageQueryHelper.toHashMap(qry);
        List<UserJobHandoverDO> list = userJobHandoverRepository.list(params);
        List<UserJobHandoverCO> examCenterCOS = userJobHandoverCoConvertor.converDOsToCOs(list);
        return MultiResponse.of(examCenterCOS);
    }

    public SingleResponse<UserJobHandoverCO> execute(Long id) {
        SingleResponse<UserJobHandoverDO> userJobHandoverDO = userJobHandoverRepository.getInfoById(id);
        UserJobHandoverCO co = new UserJobHandoverCO();
        BeanUtils.copyProperties(userJobHandoverDO.getData(), co);
        return SingleResponse.of(co);
    }

}

