package com.ruoyi.system.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TElectronicFenceKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TElectronicFenceServiceMapper;
import com.ruoyi.system.domain.TElectronicFenceService;
import com.ruoyi.system.service.ITElectronicFenceServiceService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-14
 */
@Service
public class TElectronicFenceServiceServiceImpl implements ITElectronicFenceServiceService {

    private static final Logger log = LoggerFactory.getLogger(TElectronicFenceServiceServiceImpl.class);
    @Autowired
    private TElectronicFenceServiceMapper tElectronicFenceServiceMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public TElectronicFenceService selectTElectronicFenceServiceById(Long id) {
        return tElectronicFenceServiceMapper.selectTElectronicFenceServiceById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param tElectronicFenceService 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TElectronicFenceService> selectTElectronicFenceServiceList(TElectronicFenceService tElectronicFenceService) {
        return tElectronicFenceServiceMapper.selectTElectronicFenceServiceList(tElectronicFenceService);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tElectronicFenceService 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTElectronicFenceService(TElectronicFenceService tElectronicFenceService) {
        tElectronicFenceService.setCreateTime(DateUtils.getNowDate());
        return tElectronicFenceServiceMapper.insertTElectronicFenceService(tElectronicFenceService);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tElectronicFenceService 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTElectronicFenceService(TElectronicFenceService tElectronicFenceService) {
        tElectronicFenceService.setUpdateTime(DateUtils.getNowDate());
        return tElectronicFenceServiceMapper.updateTElectronicFenceService(tElectronicFenceService);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTElectronicFenceServiceByIds(Long[] ids) {
        return tElectronicFenceServiceMapper.deleteTElectronicFenceServiceByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteTElectronicFenceServiceById(Long id) {
        return tElectronicFenceServiceMapper.deleteTElectronicFenceServiceById(id);
    }

    @Override
    public List<TElectronicFenceService> selectTElectronicFenceServiceByKeyId(Long keyId) {
        return tElectronicFenceServiceMapper.selectTElectronicFenceServiceByKeyId(keyId);
    }

    @Override
    public TElectronicFenceService selectAccessAvailableElectronicFenceServiceByKeyId(Long keyId) {
        //获取所有的Key
        List<TElectronicFenceService> electronicFenceServices = tElectronicFenceServiceMapper.selectTElectronicFenceServiceByKeyId(keyId);
        if (electronicFenceServices != null && !electronicFenceServices.isEmpty()) {
            log.info("获取高德所有amap_service：{} .", JSONObject.toJSONString(electronicFenceServices));
            return electronicFenceServices.get(0);
        } else {
            log.error("获取高德所有amap_service为空,去创建！");
            //TODO 根据key创建高德服务

        }
        return null;
    }
}
