package com.zcloud.primeport.command.query;

import com.alibaba.cola.dto.PageResponse;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import com.zcloud.primeport.command.convertor.MkmjPassageCoConvertor;
import com.zcloud.primeport.dto.MkmjPassagePageQry;
import com.zcloud.primeport.dto.clientobject.MkmjPassageCO;
import com.zcloud.primeport.persistence.dataobject.MkmjPassageDO;
import com.zcloud.primeport.persistence.repository.MkmjPassageRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

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

@Component
@AllArgsConstructor
public class MkmjPassageQueryExe {
    private final MkmjPassageRepository mkmjPassageRepository;
    private final MkmjPassageCoConvertor mkmjPassageCoConvertor;

    public PageResponse<MkmjPassageCO> execute(MkmjPassagePageQry mkmjPassagePageQry) {
        Map<String, Object> parmas = PageQueryHelper.toHashMap(mkmjPassagePageQry);
        PageResponse<MkmjPassageDO> pageResponse = mkmjPassageRepository.listPage(parmas);
        List<MkmjPassageCO> list = mkmjPassageCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(list, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }

    public MkmjPassageCO getInfoById(Long id) {
        return mkmjPassageCoConvertor.converDOToCO(mkmjPassageRepository.getById(id));
    }
}

