package com.ruoyi.system.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.DateUtils;
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.TElectronicFenceKeyMapper;
import com.ruoyi.system.domain.TElectronicFenceKey;
import com.ruoyi.system.service.ITElectronicFenceKeyService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-14
 */
@Service
public class TElectronicFenceKeyServiceImpl implements ITElectronicFenceKeyService {
    private static final Logger log = LoggerFactory.getLogger(TElectronicFenceKeyServiceImpl.class);
    @Autowired
    private TElectronicFenceKeyMapper tElectronicFenceKeyMapper;

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

    /**
     * 查询【请填写功能名称】列表
     *
     * @param tElectronicFenceKey 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<TElectronicFenceKey> selectTElectronicFenceKeyList(TElectronicFenceKey tElectronicFenceKey) {
        return tElectronicFenceKeyMapper.selectTElectronicFenceKeyList(tElectronicFenceKey);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param tElectronicFenceKey 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertTElectronicFenceKey(TElectronicFenceKey tElectronicFenceKey) {
        tElectronicFenceKey.setCreateTime(DateUtils.getNowDate());
        return tElectronicFenceKeyMapper.insertTElectronicFenceKey(tElectronicFenceKey);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param tElectronicFenceKey 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateTElectronicFenceKey(TElectronicFenceKey tElectronicFenceKey) {
        tElectronicFenceKey.setUpdateTime(DateUtils.getNowDate());
        return tElectronicFenceKeyMapper.updateTElectronicFenceKey(tElectronicFenceKey);
    }

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

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

    @Override
    public List<TElectronicFenceKey> selectTElectronicFenceKey() {
        return tElectronicFenceKeyMapper.selectTElectronicFenceKey();
    }

    @Override
    public TElectronicFenceKey selectAccessAvailableElectronicFenceKey() {
        //获取所有的Key
        List<TElectronicFenceKey> tElectronicFenceKeys = tElectronicFenceKeyMapper.selectTElectronicFenceKey();
        if (tElectronicFenceKeys != null && !tElectronicFenceKeys.isEmpty()) {
            log.info("获取高德所有amap_key：{} .", JSONObject.toJSONString(tElectronicFenceKeys));
            return tElectronicFenceKeys.get(0);
        } else {
            log.error("获取高德所有amap_key为空.");
        }
        return null;
    }
}
