using System.ComponentModel; using Admin.Bodk.Device.Entities.Dto; using Admin.Bodk.Device.Entities.equipment; using Admin.NET.Core; using Furion.DatabaseAccessor; using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; using Mapster; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using NewLife.Caching; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; namespace Admin.Bodk.Device.Services; /// /// 服务管理 /// [ApiDescriptionSettings(Order = 2)] public class SupportService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _baseRep; private readonly SqlSugarRepository _supportRep; private readonly ICache _cache; public SupportService(SqlSugarRepository baseRep, SqlSugarRepository supportRep, ICache cache) { _baseRep = baseRep; _supportRep = supportRep; _cache = cache; } /// /// 获取检测信息列表 /// /// /// [DisplayName("获取检测信息列表")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] public async Task> PostGetDetectionList(BaseInput input) { List items = new List(); items.Add(new SupportOutput() { State = "检测中", Name = "检测1", DetectionServiceId = "dd123323", DetectionServiceType = 0 }); items.Add(new SupportOutput() { State = "已完成", Name = "检测2", DetectionServiceId = "dd1233213", DetectionServiceType = 1 }); items.Add(new SupportOutput() { State = "已完成", Name = "检测3", DetectionServiceId = "dd1233213", DetectionServiceType = 1 }); return new SqlSugarPagedList() { Page = 1, PageSize = 20, Items = items, Total = 3 }; } /// /// 获取细胞服务列表 /// /// /// [DisplayName("获取细胞服务列表")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)] public async Task> PostGetCellList(BaseInput input) { List items = new List(); var cache = _cache.Get("bodk:device:M9hjashdfkj863478236478:summary"); items.Add(new CellOutput() { Code = "BT00D0015314A", Activity = "98%", Temperature = -192.5, Humidity = "0.5%", Density = "1*10^7个/ml", Capacity = "1.8ml", Type = 1, Location = "松山湖", LastOperationTime = null, DeviceInfo = new DeviceInfo() { DeviceId = 23223232, PicUrl = "", LiquidNitrogenHeight = cache is null ? 180 : cache.LiquidHeight, Temperature = cache is null ? -195.2 : cache.TankTopTemperature, Humidity = cache is null ? "0.01%" : $"{cache.TankTopTemperaturecache?.CavityHumidity.ToString("0.0")}%", Address = "广东省东莞市松山湖园区科技二路宏远新智汇1栋", Name = "M9_01", CellBaseInfo = new CellBaseInfo() { BaseName = "松山湖", BaseId = 13545 } } }); return new SqlSugarPagedList() { Page = 1, PageSize = 20, Items = items, Total = 3 }; } /// /// 增加服务 /// /// /// [UnitOfWork] [ApiDescriptionSettings(Name = "Add"), HttpPost] [DisplayName("增加服务")] public async Task AddSupport(SupportAddInput input) { if (input is null) throw Oops.Oh("参数不能为空"); var equipment = input.Adapt(); var newEquipment = await _supportRep.AsInsertable(equipment).ExecuteReturnEntityAsync(); // if (input?.TaskChainList is { Count: > 0 }) // { // foreach (var taskChain in input.TaskChainList) // { // taskChain.EquipmentId = newEquipment.Id; // await _taskChainRepository.AsInsertable(taskChain).ExecuteReturnEntityAsync(); // } // } return newEquipment.Id; } }