IMapCacheService.cs 6.86 KB
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Rcs.Domain.Enums;

namespace Rcs.Application.Services
{
    /// <summary>
    /// 地图缓存服务接口 - 负责地图数据的Redis缓存操作
    /// @author zzy
    /// </summary>
    public interface IMapCacheService
    {
        /// <summary>
        /// 从Redis获取地图完整数据(含节点、边、资源)
        /// @author zzy
        /// </summary>
        Task<MapCacheData?> GetMapAsync(Guid mapId);

        /// <summary>
        /// 获取所有地图ID列表
        /// @author zzy
        /// </summary>
        Task<IEnumerable<Guid>> GetAllMapIdsAsync();

        /// <summary>
        /// 获取所有地图数据
        /// @author zzy
        /// </summary>
        Task<IEnumerable<MapCacheData>> GetAllMapsAsync();

        /// <summary>
        /// 按MapCode分组获取地图(同一物理环境的不同厂商地图)
        /// @author zzy
        /// </summary>
        Task<Dictionary<string, List<MapCacheData>>> GetMapsGroupedByCodeAsync();

        /// <summary>
        /// 通过节点编码快速查找节点ID
        /// @author zzy
        /// </summary>
        Task<Guid?> GetNodeIdByCodeAsync(Guid mapId, string nodeCode);

        /// <summary>
        /// 更新单个地图缓存
        /// @author zzy
        /// </summary>
        Task UpdateMapCacheAsync(Guid mapId);

        /// <summary>
        /// 删除地图缓存
        /// @author zzy
        /// </summary>
        Task RemoveMapCacheAsync(Guid mapId);

        /// <summary>
        /// 根据坐标查询最近的MapNode,允许误差在EndDeviationPosition范围内
        /// @author zzy
        /// </summary>
        /// <param name="mapId">地图ID</param>
        /// <param name="x">X坐标</param>
        /// <param name="y">Y坐标</param>
        /// <returns>最近的节点,如果没有找到符合条件的节点则返回null</returns>
        Task<MapNodeCache?> GetNearestNodeAsync(Guid mapId, double x, double y);
    }

    /// <summary>
    /// 地图缓存数据
    /// @author zzy
    /// </summary>
    public class MapCacheData
    {
        public Guid MapId { get; set; }
        public string MapCode { get; set; } = string.Empty;
        public string MapName { get; set; } = string.Empty;
        public int MapType { get; set; }
        public string Version { get; set; } = string.Empty;
        public bool Active { get; set; }
        public List<MapNodeCache> Nodes { get; set; } = new();
        public List<MapEdgeCache> Edges { get; set; } = new();
        public List<MapResourceCache> Resources { get; set; } = new();
    }

    /// <summary>
    /// 节点缓存数据
    /// @author zzy
    /// </summary>
    public class MapNodeCache
    {
        public Guid NodeId { get; set; }
        public string NodeCode { get; set; } = string.Empty;
        public double X { get; set; }
        public double Y { get; set; }
        public double? Theta { get; set; }
        public int Type { get; set; }
        public bool Active { get; set; }
        public double? MaxCoordinateOffset { get; set; }
        /// <summary>
        /// 是否倒车进入
        /// @author zzy
        /// </summary>
        public bool IsReverseParking { get; set; }

        /// <summary>
        /// 是否允许旋转
        /// @author zzy
        /// </summary>
        public bool AllowRotate { get; set; }
    }

    /// <summary>
    /// 边缓存数据
    /// @author zzy
    /// </summary>
    public class MapEdgeCache
    {
        public Guid EdgeId { get; set; }
        public string EdgeCode { get; set; } = string.Empty;
        public Guid FromNode { get; set; }
        public Guid ToNode { get; set; }
        public double Length { get; set; }
        public double? Cost { get; set; }
        public bool Active { get; set; }

        /// <summary>
        /// 允许的行驶夹角角度列表(度)
        /// @author zzy
        /// </summary>
        public List<double>? OrientationRads { get; set; }

        /// <summary>
        /// 最大速度(米/秒)
        /// @author zzy
        /// </summary>
        public double? MaxSpeed { get; set; }

        /// <summary>
        /// 最大角度偏差(度)
        /// @author zzy
        /// </summary>
        public double? MaxRadDeviation { get; set; }

        /// <summary>
        /// 是否为曲线
        /// @author zzy
        /// </summary>
        public bool IsCurve { get; set; }

        /// <summary>
        /// NURBS控制点
        /// @author zzy
        /// </summary>
        public List<PointCache>? ControlPoints { get; set; }
    }

    /// <summary>
    /// 点缓存数据
    /// @author zzy
    /// </summary>
    public class PointCache
    {
        public double X { get; set; }
        public double Y { get; set; }
    }

    /// <summary>
    /// 资源区域缓存数据
    /// @author zzy
    /// </summary>
    public class MapResourceCache
    {
        public Guid ResourceId { get; set; }
        public string ResourceCode { get; set; } = string.Empty;
        public int Type { get; set; }
        public int? Capacity { get; set; }
        public List<PointCache>? LocationCoordinates { get; set; }

        /// <summary>
        /// 最大速度
        /// @author zzy
        /// </summary>
        public double MaxSpeed { get; set; }

        /// <summary>
        /// 能否旋转
        /// @author zzy
        /// </summary>
        public bool CanRotate { get; set; }

        /// <summary>
        /// 前置动作类型1(进入资源前)
        /// @author zzy
        /// </summary>
        public ActionType? PreAction1Type { get; set; }

        /// <summary>
        /// 前置网络动作集合1(进入资源前)
        /// @author zzy
        /// </summary>
        public List<Guid>? PreNetActions1 { get; set; }

        /// <summary>
        /// 后置动作类型1(进入资源后)
        /// @author zzy
        /// </summary>
        public ActionType? PostAction1Type { get; set; }

        /// <summary>
        /// 后置网络动作集合1(进入资源后)
        /// @author zzy
        /// </summary>
        public List<Guid>? PostNetActions1 { get; set; }

        /// <summary>
        /// 前置动作类型2(离开资源前)
        /// @author zzy
        /// </summary>
        public ActionType? PreAction2Type { get; set; }

        /// <summary>
        /// 前置网络动作集合2(离开资源前)
        /// @author zzy
        /// </summary>
        public List<Guid>? PreNetActions2 { get; set; }

        /// <summary>
        /// 后置动作类型2(离开资源后)
        /// @author zzy
        /// </summary>
        public ActionType? PostAction2Type { get; set; }

        /// <summary>
        /// 后置网络动作集合2(离开资源后)
        /// @author zzy
        /// </summary>
        public List<Guid>? PostNetActions2 { get; set; }
    }
}