package com.mosty.base.manager.remote;

import com.alibaba.fastjson.JSON;
import com.mosty.base.model.dto.yszx.TbYsGajgDto;
import com.mosty.base.feign.service.MostyYszxFeignService;
import com.mosty.base.model.vo.yszx.TbYsGajgVo;
import com.mosty.common.base.domain.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

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

    @Resource
    private MostyYszxFeignService tbYszxFeignService;

    /**
     * 添加公安机要素
     *
     * @param dto
     * @return
     */
    public int addGajg(TbYsGajgDto dto) {
        ResponseResult<Integer> responseResult = tbYszxFeignService.add(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("调用添加公安机关要素失败 responseResult = {}", JSON.toJSONString(responseResult));
            return 0;
        }
        return responseResult.getData();
    }

    /**
     * 编辑公安机要素
     *
     * @param dto
     * @return
     */
    public void updateGajg(TbYsGajgDto dto) {
        ResponseResult<Void> responseResult = tbYszxFeignService.update(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("调用修改公安机关要素失败  responseResult = {}", JSON.toJSONString(responseResult));
        }
    }

    /**
     * 查询公安机关要素详情
     *
     * @param id
     * @return
     */
    public TbYsGajgVo getGajgInfo(String id) {
        ResponseResult<TbYsGajgVo> responseResult = tbYszxFeignService.getInfo(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("调用查询公安机关要素详情失败  responseResult = {}", JSON.toJSONString(responseResult));
            return null;
        }
        return responseResult.getData();
    }

    /**
     * 删除公安机关要素
     *
     * @param id
     * @return
     */
    public void delEntity(String id) {
        ResponseResult<Void> responseResult = tbYszxFeignService.delEntity(id);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("调用删除公安机关要素失败  responseResult = {}", JSON.toJSONString(responseResult));
        }
    }

    /**
     *根据必巡点id 和来源表名 删除公安机关要素
     *
     * @param dto
     * @return
     */
    public void delEntity(TbYsGajgDto dto) {
        ResponseResult<Void> responseResult = tbYszxFeignService.delEntity(dto);
        if (responseResult == null || !responseResult.isSuccess()) {
            log.error("调用删除公安机关要素失败  responseResult = {}", JSON.toJSONString(responseResult));
        }
    }
}
