package com.zcloud.zcGbsServicer.command.query;

import com.zcloud.zcGbsServicer.command.convertor.WaterSourceCoConvertor;
import com.zcloud.zcGbsServicer.dto.WaterSourcePageQry;
import com.zcloud.zcGbsServicer.dto.clientobject.WaterSourceCO;
import com.zcloud.zcGbsServicer.persistence.dataobject.WaterSourceDO;
import com.zcloud.zcGbsServicer.persistence.repository.WaterSourceRepository;
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 makejava
* @Date 2026-01-21 17:23:50
*/
@Component
@AllArgsConstructor
public class WaterSourceQueryExe {
    private final WaterSourceRepository waterSourceRepository;
    private final WaterSourceCoConvertor waterSourceCoConvertor;

    /**
    * 分页
    *
    * @param waterSourcePageQry
    * @return
    */
    public PageResponse<WaterSourceCO> execute(WaterSourcePageQry waterSourcePageQry) {
        Map<String,Object> params = PageQueryHelper.toHashMap(waterSourcePageQry);
        params.put("tenant_id", waterSourcePageQry.getEqCorpId());
        PageResponse<WaterSourceDO> pageResponse = waterSourceRepository.listPage(params);
        List<WaterSourceCO> examCenterCOS = waterSourceCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    /**
     * 详情
     */
    public WaterSourceCO getInfoById(Long id) {
        WaterSourceDO waterSourceDO = waterSourceRepository.getById(id);
        return waterSourceCoConvertor.converDOToCO(waterSourceDO);
    }
}

