package com.friday.executor.common;

import com.friday.base.common.annotation.MethodLog;
import com.friday.base.common.response.DubboResult;
import com.friday.operation.api.executor.dto.common.InterProviderRequest;
import com.friday.operation.api.executor.dto.common.InterProviderResult;
import com.friday.operation.api.executor.service.IInterProviderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Author YaoYao
 * @Date Created In 13:57 2023/4/4
 * @Description 资讯接口服务
 * @Modified By
 */
@Service
@Slf4j
public class InterProviderHelper implements IInterProviderService {
    @Value("${dubbo.inter.provider.bond.authority.key}")
    private String authKey;

    @Override
    @MethodLog
    public DubboResult<InterProviderResult> queryData(InterProviderRequest request){
        try {
//            // 封装查询参数
//            ParamData paramData = new ParamData();
//            // 查询字段 为空则查询全部字段
//            paramData.setKey(authKey);
//            paramData.setStartrow(request.getStartRow());
//            paramData.setRownum(request.getRowNum() == 0 ? 1000 : request.getRowNum());
//            paramData.setResource(request.getResource());
//            String[] fields = {};
//            if(Objects.nonNull(request.getSelectedFields())){
//                fields = request.getSelectedFields();
//            }
//            paramData.setSelectedFields(fields);
//            paramData.setParamMaps(request.getParamMaps());
//            ResultData resultData = interProvider.getResourceData(paramData);
//            InterProviderResult rst = InterProviderResult.builder()
//                    .success(true)
//                    .dataCount(resultData.getDataCount())
//                    .totalCount(resultData.getTotalCount())
//                    .failMsg(resultData.getMsg())
//                    .selectedFields(fields)
//                    .dataList(resultData.getDataList())
//                    .build();
            return DubboResult.newSuccess(new InterProviderResult());
        } catch (Exception e){
            log.error("查询资讯接口异常", e);
            return DubboResult.newFailure(DubboResult.SERVER_EXCEPTION, "查询资讯接口异常:" + e.getMessage());
        }
    }
}
