package com.mosty.lzother.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.feign.service.MostyYjzlFeignService;
import com.mosty.base.model.dto.yjzl.GetLastYjDto;
import com.mosty.base.model.entity.lzother.TAlarmYjZl;
import com.mosty.base.model.entity.lzother.TAlarmYjgj;
import com.mosty.base.model.entity.rh.RhMyhtWarn;
import com.mosty.base.model.entity.yjzl.TbYjxx;
import com.mosty.base.model.entity.yjzl.TbZlxx;
import com.mosty.base.model.vo.lzother.TAlarmYjZlVo;
import com.mosty.base.model.vo.trs.VwAlermYjzlVo;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author dw
 * @since 2022/7/23
 * 外部调用公安机关要素接口
 **/
@Service
@Slf4j
public class TbYjzlAdaptRemoteService {

    @Resource
    private MostyYjzlFeignService mostyYjzlFeignService;

    // 同步拓尔思预警指令(高新)
    public void addTrsZl(VwAlermYjzlVo dto) {
        ResponseResult<Void> responseResult = this.mostyYjzlFeignService.addTrsZl(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("同步拓尔思预警指令失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("同步拓尔思预警指令失败");
        }
    }

    // 获取trs最新的一条指令信息
    public TbZlxx getLastZlxx() {
        ResponseResult<TbZlxx> responseResult = this.mostyYjzlFeignService.getLastZlxx();
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取trs最新的一条指令信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取trs最新的一条指令信息失败");
        }
        return responseResult.getData();
    }

    // 根据条件查询最新的预警信息
    public TbYjxx getLastYj(GetLastYjDto dto) {
        ResponseResult<TbYjxx> responseResult = this.mostyYjzlFeignService.getLastYj(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("根据条件查询最新的预警信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("根据条件查询最新的预警信息失败");
        }
        return responseResult.getData();
    }

    // 添加泸州拓尔思预警信息
    public void addYjxx(TAlarmYjgj item) {
        ResponseResult<Void> responseResult = this.mostyYjzlFeignService.addYjxx(item);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("添加泸州拓尔思预警信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("添加泸州拓尔思预警信息失败");
        }
    }

    // 添加融合预警信息失败
    public void addRhyj(RhMyhtWarn rhMyhtWarn) {
        ResponseResult<Void> responseResult = this.mostyYjzlFeignService.saveHryj(rhMyhtWarn);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("添加融合预警信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("添加融合预警信息失败");
        }
    }
}
