package com.mosty.yjzl.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.feign.service.MostyJcglFeignService;
import com.mosty.base.feign.service.MostyYszxFeignService;
import com.mosty.base.model.dto.jcgl.TbJcglXfllVo;
import com.mosty.base.model.dto.yszx.TbYsDlDTO;
import com.mosty.base.model.dto.yszx.TbYsSxtDto;
import com.mosty.base.model.entity.yszx.TbYsDl;
import com.mosty.base.model.query.yszx.TbYsSxtPageOneQuery;
import com.mosty.base.model.vo.yszx.TbYsDlDto;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 要素中心远程调用
 */
@Slf4j
@Service
@AllArgsConstructor
public class TbYszxAdaptRemoteService {

    private final MostyYszxFeignService mostyYszxFeignService;

    // 获取感知源详细信息
    public TbYsSxtDto getSxtInfoVo(String id) {
        ResponseResult<TbYsSxtDto> responseResult = mostyYszxFeignService.getSxtInfoVo(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取感知源详细信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取感知源详细信息失败");
        }
        return responseResult.getData();
    }

    // 根据设备编号查询摄像头详情
    public TbYsSxtDto getInfoBySbbh(String sbbh) {
        ResponseResult<TbYsSxtDto> responseResult = mostyYszxFeignService.getInfoBySbbh(sbbh);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取感知源详细信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取感知源详细信息失败");
        }
        return responseResult.getData();
    }

    // 查询摄像头信息
    public TbYsSxtDto selectGzy(TbYsSxtPageOneQuery dto) {
        ResponseResult<TbYsSxtDto> responseResult = mostyYszxFeignService.selectGzy(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取感知源信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取感知源信息失败");
        }
        return responseResult.getData();
    }

    // 添加摄像头信息
    public Integer addSxt(TbYsSxtDto dto) {
        ResponseResult<Integer> responseResult = mostyYszxFeignService.addSxt(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("添加摄像头信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("添加摄像头信息失败");
        }
        return responseResult.getData();
    }

    // 添加地理要素信息
    public Integer addDlYs(TbYsDlDto dto) {
        ResponseResult<Integer> responseResult = mostyYszxFeignService.addDlYs(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("添加地理要素信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("添加地理要素信息失败");
        }
        return responseResult.getData();
    }

    // 根据名称查询地理要素
    public TbYsDl selectDlys(String ysmc) {
        ResponseResult<TbYsDl> responseResult = mostyYszxFeignService.selectDlys(ysmc);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("根据名称查询地理要素失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("根据名称查询地理要素失败");
        }
        return responseResult.getData();
    }
}
