116 lines
3.2 KiB
C#
Raw Normal View History

2025-04-02 17:46:33 +08:00
using System;
using System.Collections.Generic;
2024-12-19 16:07:07 +08:00
using System.Threading.Tasks;
2025-04-07 10:56:40 +08:00
using Apache.IoTDB.DataStructure;
using Apache.IoTDB;
using Confluent.Kafka;
2025-04-02 17:46:33 +08:00
using JiShe.CollectBus.Ammeters;
2024-12-19 16:07:07 +08:00
using JiShe.CollectBus.FreeSql;
2025-04-02 17:46:33 +08:00
using JiShe.CollectBus.IoTDBProvider;
2025-03-14 14:28:04 +08:00
using JiShe.CollectBus.IotSystems.PrepayModel;
2024-12-19 16:07:07 +08:00
using Microsoft.AspNetCore.Authorization;
2025-04-03 16:46:26 +08:00
using Microsoft.AspNetCore.Mvc;
2025-04-07 10:56:40 +08:00
using Microsoft.Extensions.Options;
2025-04-07 16:44:25 +08:00
using JiShe.CollectBus.IoTDBProvider.Context;
2025-04-08 17:44:42 +08:00
using Microsoft.Extensions.Logging;
2024-12-19 16:07:07 +08:00
namespace JiShe.CollectBus.Samples;
public class SampleAppService : CollectBusAppService, ISampleAppService
{
2025-04-08 17:44:42 +08:00
private readonly ILogger<SampleAppService> _logger;
2025-04-02 17:46:33 +08:00
private readonly IIoTDBProvider _iotDBProvider;
2025-04-07 16:44:25 +08:00
private readonly IoTDBRuntimeContext _dbContext;
2025-04-07 10:56:40 +08:00
private readonly IoTDBOptions _options;
2025-04-02 17:46:33 +08:00
2025-04-07 16:44:25 +08:00
public SampleAppService(IIoTDBProvider iotDBProvider, IOptions<IoTDBOptions> options,
2025-04-08 17:44:42 +08:00
IoTDBRuntimeContext dbContext, ILogger<SampleAppService> logger)
2025-04-02 17:46:33 +08:00
{
_iotDBProvider = iotDBProvider;
2025-04-07 10:56:40 +08:00
_options = options.Value;
2025-04-07 16:44:25 +08:00
_dbContext = dbContext;
2025-04-08 17:44:42 +08:00
_logger = logger;
2025-04-02 17:46:33 +08:00
}
2025-04-03 16:46:26 +08:00
[HttpGet]
2025-04-08 17:44:42 +08:00
public async Task UseSessionPool(long timestamps)
2025-04-02 17:46:33 +08:00
{
2025-04-08 17:44:42 +08:00
string? messageHexString = null;
if (timestamps == 0)
{
timestamps = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
_logger.LogError($"timestamps_{timestamps}");
}
else
{
messageHexString = messageHexString + timestamps;
}
2025-04-02 17:46:33 +08:00
ElectricityMeter meter = new ElectricityMeter()
{
2025-04-03 16:46:26 +08:00
SystemName = "energy",
2025-04-03 15:38:31 +08:00
DeviceId = "402440506",
2025-04-02 17:46:33 +08:00
DeviceType = "Ammeter",
Current = 10,
MeterModel = "DDZY-1980",
ProjectCode = "10059",
2025-04-07 16:44:25 +08:00
Voltage = 10,
2025-04-08 17:44:42 +08:00
IssuedMessageHexString = messageHexString,
Timestamps = timestamps,
2025-04-02 17:46:33 +08:00
};
2025-04-07 16:44:25 +08:00
await _iotDBProvider.InsertAsync(meter);
2025-04-02 17:46:33 +08:00
}
2025-04-07 10:56:40 +08:00
[HttpGet]
2025-04-07 16:44:25 +08:00
public async Task UseTableSessionPool()
2025-04-07 10:56:40 +08:00
{
2025-04-07 16:44:25 +08:00
//_dbContext.UseTableSessionPool = true;
_iotDBProvider.SwitchSessionPool(true);
2025-04-07 10:56:40 +08:00
2025-04-07 16:44:25 +08:00
ElectricityMeter meter = new ElectricityMeter()
2025-04-07 10:56:40 +08:00
{
2025-04-07 16:44:25 +08:00
SystemName = "energy",
DeviceId = "402440506",
DeviceType = "Ammeter",
Current = 10,
MeterModel = "DDZY-1980",
ProjectCode = "10059",
Voltage = 10,
Timestamps = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
};
await _iotDBProvider.InsertAsync(meter);
2025-04-07 10:56:40 +08:00
}
2024-12-19 16:07:07 +08:00
public Task<SampleDto> GetAsync()
{
return Task.FromResult(
new SampleDto
{
Value = 42
}
);
}
[Authorize]
public Task<SampleDto> GetAuthorizedAsync()
{
return Task.FromResult(
new SampleDto
{
Value = 42
}
);
}
[AllowAnonymous]
public async Task<List<Vi_BaseAmmeterInfo>> Test()
{
var ammeterList = await SqlProvider.Instance.Change(DbEnum.PrepayDB).Select<Vi_BaseAmmeterInfo>().Where(d => d.TB_CustomerID == 5).Take(10).ToListAsync();
return ammeterList;
}
}