package com.mosty.qwzx.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.model.dto.jcgl.TbJcglKfdDto;
import com.mosty.base.model.dto.jcgl.TbJcglXfllVo;
import com.mosty.base.feign.service.MostyJcglFeignService;
import com.mosty.base.model.dto.jcgl.TbJcglXfqyDto;
import com.mosty.base.model.entity.jcgl.TbJcglJwz;
import com.mosty.base.model.entity.jcgl.TbJcglKfd;
import com.mosty.base.model.entity.jcgl.TbJcglXfll;
import com.mosty.base.model.entity.jcgl.TbJcglXfqy;
import com.mosty.base.model.query.jcgl.TbJcglXfllQueryAllDto;
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;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dw
 * @since 2022/7/23
 * 外部调用基础管理接口
 **/
@Service
@Slf4j
public class TbJcglAdaptRemoteService {

    @Resource
    private MostyJcglFeignService mostyJcglFeignService;


    // 获取部门下的巡防力量信息
    public List<TbJcglXfllVo> getXfll(TbJcglXfllQueryAllDto dto) {
        ResponseResult<List<TbJcglXfllVo>> responseResult = mostyJcglFeignService.getXfll(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("获取部门下的巡防力量信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("获取部门下的巡防力量信息失败");
        }
        return responseResult.getData();
    }


    // 查询部门下的所有的辅警信息
    public List<TbJcglXfllVo> getFjList(String deptid) {
        ResponseResult<List<TbJcglXfllVo>> responseResult = mostyJcglFeignService.getFjList(deptid);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询部门下的所有的辅警信息失败 responseResult = {}", JSON.toJSONString(responseResult));
            return new ArrayList<>();
        }
        return responseResult.getData();
    }

    // 根据ID查询巡防区域
    public TbJcglXfqyDto getxfqById(String id) {
        ResponseResult<TbJcglXfqyDto> responseResult = mostyJcglFeignService.getxfqById(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("根据ID查询巡防区域失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("根据ID查询巡防区域失败");
        }
        return responseResult.getData();
    }

    // 根据ID查询快反点
    public TbJcglKfdDto getKfdById(String id) {
        ResponseResult<TbJcglKfdDto> responseResult = mostyJcglFeignService.getKfdById(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("根据ID查询快反点失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("根据ID查询快反点失败");
        }
        return responseResult.getData();
    }

    // 根据ID查询警务站
    public TbJcglJwz getJwzById(String id) {
        ResponseResult<TbJcglJwz> responseResult = mostyJcglFeignService.getJwzById(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("根据ID查询警务站失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("根据ID查询警务站失败");
        }
        return responseResult.getData();
    }


    // 查询部门下面人员数量
    public Integer getRysl(String ssbmdm) {
        ResponseResult<Integer> responseResult = mostyJcglFeignService.getRysl(ssbmdm);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("根据ID查询警务站失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("根据ID查询警务站失败");
        }
        return responseResult.getData();
    }

    // 查询查询巡防部门
    public List<TbJcglXfll> getBmAll() {
        ResponseResult<List<TbJcglXfll>> responseResult = mostyJcglFeignService.getBmAll();
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("查询巡防部门失败 responseResult = {}", JSON.toJSONString(responseResult));
            throw new BusinessException("查询巡防部门失败");
        }
        return responseResult.getData();
    }
}
