using Furion.DependencyInjection;
using Nirvana.Common;
using SqlSugar;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using YBDevice.Entity;

namespace YBDevice.CommonService.DevTypeInfo
{
    public class DeviceTypeService:IDeviceTypeService,ITransient
    {
        private readonly ISqlSugarRepository<YB_DeviceTypeApp> repository;
        private readonly SqlSugarClient dbClient;
        public DeviceTypeService(ISqlSugarRepository<YB_DeviceTypeApp> sqlSugarRepository)
        {
            repository = sqlSugarRepository;
            dbClient = repository.Context;
        }
        /// <summary>
        /// 获取合并的设备类型列表
        /// </summary>
        /// <param name="devtype">设备类型</param>
        /// <returns></returns>
        public async Task<List<int>> GetDevTypesAsync(int devtype)
        {
            List<int> devtypes = new List<int>();
            if (devtype > 0)
            {
                var devtypeconf = await dbClient.Queryable<YB_DeviceType>().FirstAsync(x => x.Code == devtype);
                if (devtypeconf != null)
                {
                    var devtypesStr = devtypeconf.Content.Split(',').ToList();
                    foreach (var item in devtypesStr)
                    {
                        devtypes.Add(item.ToInt());
                    }
                }
            }
            return devtypes;
        }
    }
}
