操控平台后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
4.6 KiB

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;
/// <summary>
/// 服务管理
/// </summary>
[ApiDescriptionSettings(Order = 2)]
public class SupportService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<Entities.Base> _baseRep;
private readonly SqlSugarRepository<Entities.Support> _supportRep;
private readonly ICache _cache;
public SupportService(SqlSugarRepository<Entities.Base> baseRep, SqlSugarRepository<Entities.Support> supportRep,
ICache cache)
{
_baseRep = baseRep;
_supportRep = supportRep;
_cache = cache;
}
/// <summary>
/// 获取检测信息列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[DisplayName("获取检测信息列表")]
[Authorize(AuthenticationSchemes =
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
public async Task<SqlSugarPagedList<SupportOutput>> PostGetDetectionList(BaseInput input)
{
List<SupportOutput> items = new List<SupportOutput>();
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<SupportOutput>() { Page = 1, PageSize = 20, Items = items, Total = 3 };
}
/// <summary>
/// 获取细胞服务列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[DisplayName("获取细胞服务列表")]
[Authorize(AuthenticationSchemes =
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
public async Task<SqlSugarPagedList<CellOutput>> PostGetCellList(BaseInput input)
{
List<CellOutput> items = new List<CellOutput>();
var cache = _cache.Get<dynamic>("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<CellOutput>() { Page = 1, PageSize = 20, Items = items, Total = 3 };
}
/// <summary>
/// 增加服务
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[UnitOfWork]
[ApiDescriptionSettings(Name = "Add"), HttpPost]
[DisplayName("增加服务")]
public async Task<long> AddSupport(SupportAddInput input)
{
if (input is null) throw Oops.Oh("参数不能为空");
var equipment = input.Adapt<Entities.Support>();
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;
}
}