package com.mosty.sjzx.remote;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.feign.service.MostyYjzlFeignService;
import com.mosty.base.model.dto.yjzl.TbYjxxDTO;
import com.mosty.base.model.dto.yjzl.TbZlxxInsertDto;
import com.mosty.base.model.entity.yjzl.TbYjxx;
import com.mosty.base.model.query.yjzl.TbYjxxQuery;
import com.mosty.base.model.query.yjzl.TbZlxxQuery;
import com.mosty.base.model.vo.yjzl.TbZlxxVo;
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 TbYjzlAdaptRrmoteService {

    private final MostyYjzlFeignService mostyYjzlFeignService;

    // 查询指令
    public Object selectInstructList(TbZlxxQuery dto) {
        ResponseResult<List<TbZlxxVo>> responseResult = mostyYjzlFeignService.selectInstructList(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询指令异常Result = {}", JSON.toJSONString(responseResult));
            return null;
        }
        return responseResult.getData();
    }

    // 查询预警信息
    public Object getPageList(TbYjxxQuery dto) {
        ResponseResult<IPage<TbYjxxDTO>> responseResult = mostyYjzlFeignService.getPageList(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询预警信息异常 Result = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询预警信息异常");
        }
        return responseResult.getData();
    }

    // 查询预警信息
    public List<TbYjxx> getYjxx30Day(TbYjxxQuery dto) {
        ResponseResult<List<TbYjxx>> responseResult = mostyYjzlFeignService.getYjxx30Day(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询预警信息异常 Result = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询预警信息异常");
        }
        return responseResult.getData();
    }

    // 添加指令信息
    public void addZl(TbZlxxInsertDto dto) {
        ResponseResult<Void> responseResult = mostyYjzlFeignService.addZl(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询预警信息异常 Result = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询预警信息异常");
        }
    }

    // 警情转换成指令
    public void andJqZl(String ssbmid,String jqid,String bbids,String zlxflx) {
        ResponseResult<Void> responseResult = mostyYjzlFeignService.andJqZl(ssbmid,jqid,bbids,zlxflx);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("警情转换成指令异常 Result = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("警情转换成指令异常");
        }
    }
}
