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

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.zcloud.basic.info.command.convertor.ImgFilesCoConvertor;
import com.zcloud.basic.info.domain.config.CodeConfig;
import com.zcloud.basic.info.domain.config.ImageConfig;
import com.zcloud.basic.info.dto.ImgFilesAddCmd;
import com.zcloud.basic.info.dto.ImgFilesPageQry;
import com.zcloud.basic.info.dto.ImgFilesQryCmd;
import com.zcloud.basic.info.dto.clientobject.ImgFilesCO;
import com.zcloud.basic.info.persistence.dataobject.ImgFilesDO;
import com.zcloud.basic.info.persistence.repository.ImgFilesRepository;
import com.zcloud.gbscommon.utils.PageQueryHelper;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

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



/**
* web-app
* @Author zhangyue
* @Date 2025-10-30 16:10:07
*/
@Component
@AllArgsConstructor
public class ImgFilesQueryExe {
    private final ImgFilesRepository imgFilesRepository;
    private final ImgFilesCoConvertor imgFilesCoConvertor;
    //image:
    //  path: https://jpfz.qhdsafety.com/gbsFileTest/

    private final ImageConfig imageConfig;
    /**
     * 分页
     *
     * @param imgFilesPageQry
     * @return
     */
    public PageResponse<ImgFilesCO> execute(ImgFilesPageQry imgFilesPageQry) {
        Map<String,Object> params = PageQueryHelper.toHashMap(imgFilesPageQry);
        PageResponse<ImgFilesDO> pageResponse = imgFilesRepository.listPage(params);
        List<ImgFilesCO> examCenterCOS = imgFilesCoConvertor.converDOsToCOs(pageResponse.getData());
        return PageResponse.of(examCenterCOS, pageResponse.getTotalCount(), pageResponse.getPageSize(), pageResponse.getPageIndex());
    }
    /**
     * list
     *
     * @param imgFilesQryCmd
     * @return
     */
    public MultiResponse<ImgFilesCO> executeList(ImgFilesQryCmd imgFilesQryCmd) {
        Map<String,Object> params = PageQueryHelper.toHashMap(imgFilesQryCmd);
        List<ImgFilesDO> imgFilesDOList = imgFilesRepository.listAll(params);
        List<ImgFilesCO> imgFilesCOList = imgFilesCoConvertor.converDOsToCOs(imgFilesDOList);
        return MultiResponse.of(imgFilesCOList);
    }

    public String getImagePath() {
        return imageConfig.getUrl();
    }
}

