package com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.qjmh;

import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.qjmh.dto.QjmhBaseResult;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.qjmh.dto.QjmhCarDTO;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.qjmh.dto.QjmhCarParamPageDTO;
import com.cico.nest.lcdp.boot.core.qxsd.infrastructure.gatewayimpl.http.qjmh.dto.QjmhPageResultDTO;
import com.cico.nest.lcdp.framework.common.util.json.JsonUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * 请求全景门户
 * @author rfx
 * @date 2024/11/14
 */

@Component
@Slf4j
public class QjmhComponentMapper implements IQjmhCarService {

    @Resource
    private QjmhClientFeign qjmhClientFeign;


    /**
     * 隧道留存车辆清单接口
     * @param request
     * @return
     */
    @Override
    public List<QjmhCarDTO> getCarList(QjmhCarParamPageDTO request){
        request.setPageSize(1000);
        List<QjmhCarDTO> response = new ArrayList<>();
//        log.info("=========  请求隧道留存车流清单，入参：{}  =========", JsonUtils.toJsonString(request));
        QjmhBaseResult<Map<String, Object>> result = qjmhClientFeign.carList(request);
//        log.info("=========  请求隧道留存车流清单，返回结果：{}  =========", JsonUtils.toJsonString(request));
        if (result ==null || !result.getSuccess() || result.getResult()==null){
            return response;
        }
        String pageResultStr = JsonUtils.toJsonString(result.getResult().get("pageResult"));
        QjmhPageResultDTO<QjmhCarDTO> pageResultDTO = JsonUtils.parseObject(pageResultStr,QjmhPageResultDTO.class);
        response = JsonUtils.parseArray(JsonUtils.toJsonString(pageResultDTO.getRecords()),QjmhCarDTO.class);
        return response;
    }


}
