package com.mosty.sjzx.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.feign.service.MostyQwzxFeignService;
import com.mosty.base.model.dto.qwzx.TbQwXfbbQueryByJlDto;
import com.mosty.base.model.entity.qwzx.TbQwXfbb;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 勤务中心远程调用
 */
@Slf4j
@Service
@AllArgsConstructor
public class TbQwzxAdaptRemoteService {

    private final MostyQwzxFeignService mostyQwzxFeignService;

    // 根据设备ID查询该设备所在的巡组
    public List<TbQwXfbb> getBbList(String sbid) {
        ResponseResult<List<TbQwXfbb>> responseResult = mostyQwzxFeignService.getBbList(sbid);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取巡组信息 失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取巡组信息异常！");
        }
        return responseResult.getData();
    }

    // 查询报备信息
    public TbQwXfbb getBbxxInfo(String id) {
        ResponseResult<TbQwXfbb> responseResult = mostyQwzxFeignService.getBbxxInfo(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询报备信息 失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询报备信息异常！");
        }
        return responseResult.getData();
    }

    // 查询范围内的最近的巡组信息
    public TbQwXfbb getBbxxByJi(TbQwXfbbQueryByJlDto dto) {
        ResponseResult<TbQwXfbb> responseResult = mostyQwzxFeignService.getBbxxByJi(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询范围内的最近的巡组信息 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询范围内的最近的巡组信息异常！");
        }
        return responseResult.getData();
    }

    // 根据巡区获取报备id
    public List<TbQwXfbb> getBbidByXq(String xqid) {
        ResponseResult<List<TbQwXfbb>> responseResult = mostyQwzxFeignService.getBbidByXq(xqid);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询范围内的最近的巡组信息 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询范围内的最近的巡组信息异常！");
        }
        return responseResult.getData();
    }

}
