82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using Abp.Application.Services;
|
|
using Abp.Authorization;
|
|
using Abp.Domain.Repositories;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using YunDa.ISAS.Application.Core;
|
|
using YunDa.ISAS.Application.Core.Session;
|
|
using YunDa.ISAS.Application.Core.SwaggerHelper;
|
|
using YunDa.ISAS.DataTransferObject;
|
|
using YunDa.SOMS.DataTransferObject.CommonDto;
|
|
using YunDa.SOMS.Entities.GeneralInformation;
|
|
|
|
namespace YunDa.ISAS.MongoDB.Application.DataMonitoring
|
|
{
|
|
public class ProtectionDeviceYCResultAppService : ISASAppServiceBase, IApplicationService
|
|
{
|
|
private readonly IRepository<ProtectionDeviceInfo, Guid> _protectionDeviceInfoRepository;
|
|
|
|
public ProtectionDeviceYCResultAppService(ISessionAppService sessionAppService,
|
|
IRepository<ProtectionDeviceInfo, Guid> protectionDeviceInfoRepository
|
|
) : base(sessionAppService)
|
|
{
|
|
_protectionDeviceInfoRepository = protectionDeviceInfoRepository;
|
|
}
|
|
/// <summary>
|
|
/// 获取装置5V电压曲线图
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[AbpAllowAnonymous]
|
|
[ShowApi]
|
|
[HttpGet]
|
|
public RequestResult<List<TimeValue>> Get5VTimeSeries(Guid equipmentInfoId,int index,DateTime startTime,DateTime endTime)
|
|
{
|
|
RequestResult<List<TimeValue>> rst = new RequestResult<List<TimeValue>>();
|
|
try
|
|
{
|
|
// 验证时间范围
|
|
if (startTime >= endTime)
|
|
{
|
|
throw new ArgumentException("Start time must be earlier than end time.");
|
|
}
|
|
|
|
// 初始化数据结果集
|
|
List<TimeValue> timeSeries = new List<TimeValue>();
|
|
|
|
Random random = new Random();
|
|
DateTime currentTime = startTime;
|
|
|
|
// 按随机间隔生成数据
|
|
while (currentTime <= endTime)
|
|
{
|
|
// 生成随机电压值 (假设范围为 4.8V 到 5.2V)
|
|
double voltage = 4.8 + random.NextDouble() * 0.4;
|
|
|
|
// 添加时间点和电压值
|
|
timeSeries.Add(new TimeValue
|
|
{
|
|
Time = currentTime,
|
|
Value = voltage
|
|
});
|
|
|
|
// 随机增加 1-3 秒
|
|
int randomSeconds = random.Next(1, 4); // [1, 3]
|
|
currentTime = currentTime.AddSeconds(randomSeconds);
|
|
}
|
|
rst.ResultData = timeSeries;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
return rst;
|
|
}
|
|
}
|
|
}
|