2025-04-23 16:17:29 +08:00
|
|
|
|
using JiShe.CollectBus.Application.Contracts;
|
2025-04-25 09:28:20 +08:00
|
|
|
|
using JiShe.CollectBus.Common;
|
2025-03-12 14:57:42 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
2025-04-10 14:12:14 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Helpers;
|
2025-04-30 12:36:54 +08:00
|
|
|
|
using JiShe.CollectBus.DataChannels;
|
2025-03-12 14:57:42 +08:00
|
|
|
|
using JiShe.CollectBus.FreeSql;
|
2025-03-14 14:24:38 +08:00
|
|
|
|
using JiShe.CollectBus.GatherItem;
|
2025-04-17 20:28:50 +08:00
|
|
|
|
using JiShe.CollectBus.IoTDB.Interface;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-05-13 14:51:38 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Devices;
|
2025-03-18 22:43:24 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.MeterReadingRecords;
|
2025-04-19 00:30:58 +08:00
|
|
|
|
using JiShe.CollectBus.Kafka.Internal;
|
2025-04-25 14:42:11 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
2025-04-29 10:12:09 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Models;
|
2025-03-12 14:57:42 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2025-03-13 10:51:16 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-04-17 13:54:18 +08:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2025-05-14 14:40:34 +08:00
|
|
|
|
using Volo.Abp.Guids;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
|
2025-03-12 14:57:42 +08:00
|
|
|
|
|
2025-03-14 14:38:08 +08:00
|
|
|
|
namespace JiShe.CollectBus.ScheduledMeterReading
|
2025-03-12 14:57:42 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 能耗系统定时采集服务
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
//[Route($"/energy/app/scheduled")]
|
|
|
|
|
|
public class EnergySystemScheduledMeterReadingService : BasicScheduledMeterReadingService
|
|
|
|
|
|
{
|
2025-04-28 16:37:31 +08:00
|
|
|
|
string systemType = string.Empty;
|
2025-04-09 17:29:30 +08:00
|
|
|
|
string serverTagName = string.Empty;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
private readonly ILogger<BasicScheduledMeterReadingService> _logger;
|
2025-04-24 17:48:20 +08:00
|
|
|
|
private readonly IProtocolService _protocolService;
|
2025-05-14 14:40:34 +08:00
|
|
|
|
private readonly IGuidGenerator _guidGenerator;
|
2025-04-21 22:57:49 +08:00
|
|
|
|
|
2025-04-16 17:36:46 +08:00
|
|
|
|
public EnergySystemScheduledMeterReadingService(
|
|
|
|
|
|
ILogger<EnergySystemScheduledMeterReadingService> logger,
|
2025-04-30 12:36:54 +08:00
|
|
|
|
IDataChannelManageService dataChannelManage,
|
|
|
|
|
|
IRedisDataCacheService redisDataCacheService,
|
2025-04-21 10:17:40 +08:00
|
|
|
|
IIoTDbProvider dbProvider,
|
2025-04-24 17:48:20 +08:00
|
|
|
|
IProtocolService protocolService,
|
2025-05-14 14:40:34 +08:00
|
|
|
|
IGuidGenerator guidGenerator,
|
2025-04-30 12:36:54 +08:00
|
|
|
|
IOptions<KafkaOptionConfig> kafkaOptions,
|
|
|
|
|
|
IOptions<ServerApplicationOptions> applicationOptions)
|
2025-04-16 17:36:46 +08:00
|
|
|
|
: base(logger,
|
2025-04-30 12:36:54 +08:00
|
|
|
|
dataChannelManage,
|
2025-04-23 16:17:29 +08:00
|
|
|
|
redisDataCacheService,
|
2025-04-17 13:54:18 +08:00
|
|
|
|
dbProvider,
|
2025-04-24 17:48:20 +08:00
|
|
|
|
protocolService,
|
2025-05-14 14:40:34 +08:00
|
|
|
|
guidGenerator,
|
2025-04-25 09:28:20 +08:00
|
|
|
|
kafkaOptions,
|
|
|
|
|
|
applicationOptions)
|
2025-03-12 16:29:38 +08:00
|
|
|
|
{
|
2025-04-25 09:28:20 +08:00
|
|
|
|
serverTagName = applicationOptions.Value.ServerTagName;
|
2025-04-28 16:37:31 +08:00
|
|
|
|
systemType = applicationOptions.Value.SystemType;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
_logger = logger;
|
2025-04-24 17:48:20 +08:00
|
|
|
|
_protocolService = protocolService;
|
2025-05-14 14:40:34 +08:00
|
|
|
|
_guidGenerator = guidGenerator;
|
2025-03-12 16:29:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-28 16:37:31 +08:00
|
|
|
|
public sealed override string SystemType => systemType;
|
2025-03-12 14:57:42 +08:00
|
|
|
|
|
2025-04-09 17:29:30 +08:00
|
|
|
|
public sealed override string ServerTagName => serverTagName;
|
|
|
|
|
|
|
2025-03-14 14:24:38 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取采集项列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public override async Task<List<GatherItemInfo>> GetGatherItemByDataTypes()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string sql = $"SELECT DataType,ItemCode FROM TB_GatherItem(NOLOCK) WHERE [State]=0";
|
|
|
|
|
|
return await SqlProvider.Instance.Change(DbEnum.EnergyDB)
|
|
|
|
|
|
.Ado
|
|
|
|
|
|
.QueryAsync<GatherItemInfo>(sql, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-12 14:57:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取电表信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="gatherCode">采集端Code</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
//[HttpGet]
|
|
|
|
|
|
//[Route($"ammeter/list")]
|
2025-05-13 14:51:38 +08:00
|
|
|
|
public override async Task<List<DeviceInfo>> GetAmmeterInfoList(string gatherCode = "V4-Gather-8890")
|
2025-03-12 14:57:42 +08:00
|
|
|
|
{
|
2025-05-15 14:05:18 +08:00
|
|
|
|
//#if DEBUG
|
|
|
|
|
|
// var redisCacheDeviceInfoHashKeyTemp = $"CollectBus:Energy:JiSheCollectBus109:DeviceInfo";
|
|
|
|
|
|
|
|
|
|
|
|
// List<DeviceInfo> ammeterInfos = FreeRedisProvider.Instance.Get<List<DeviceInfo>>(redisCacheDeviceInfoHashKeyTemp);//542400504
|
|
|
|
|
|
|
|
|
|
|
|
// if (ammeterInfos == null || ammeterInfos.Count <= 0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// ammeterInfos = new List<DeviceInfo>();
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// //ammeterInfos.Add(new DeviceInfo()
|
|
|
|
|
|
// //{
|
|
|
|
|
|
// // Baudrate = 2400,
|
|
|
|
|
|
// // FocusAddress = "442400040",
|
|
|
|
|
|
// // Name = "保利单箱电表1",
|
|
|
|
|
|
// // FocusId = 95780,
|
|
|
|
|
|
// // DatabaseBusiID = 1,
|
|
|
|
|
|
// // MeteringCode = 0,
|
|
|
|
|
|
// // MeterAddress = "442405000040",
|
|
|
|
|
|
// // MeterId = 127035,
|
|
|
|
|
|
// // TypeName = 1,
|
|
|
|
|
|
// // DataTypes = "581,589,592,597,601",
|
|
|
|
|
|
// // TimeDensity = 15,
|
|
|
|
|
|
// // BrandType = "DTS1980",
|
|
|
|
|
|
// // MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// // ProjectID = 1,
|
|
|
|
|
|
// // MeteringPort = MeteringPortConst.MeteringPortTwo,
|
|
|
|
|
|
// // Password = "000000",
|
|
|
|
|
|
// //});
|
|
|
|
|
|
|
|
|
|
|
|
// //ammeterInfos.Add(new DeviceInfo()
|
|
|
|
|
|
// //{
|
|
|
|
|
|
// // Baudrate = 2400,
|
|
|
|
|
|
// // FocusAddress = "442400039",
|
|
|
|
|
|
// // Name = "保利单箱电表2",
|
|
|
|
|
|
// // FocusId = 69280,
|
|
|
|
|
|
// // DatabaseBusiID = 1,
|
|
|
|
|
|
// // MeteringCode = 0,
|
|
|
|
|
|
// // MeterAddress = "442405000039",
|
|
|
|
|
|
// // MeterId = 95594,
|
|
|
|
|
|
// // TypeName = 1,
|
|
|
|
|
|
// // DataTypes = "581,589,592,597,601",
|
|
|
|
|
|
// // TimeDensity = 15,
|
|
|
|
|
|
// // BrandType = "DTS1980",
|
|
|
|
|
|
// // MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// // ProjectID = 1,
|
|
|
|
|
|
// // MeteringPort = MeteringPortConst.MeteringPortTwo,
|
|
|
|
|
|
// // Password = "000000",
|
|
|
|
|
|
// //});
|
|
|
|
|
|
|
|
|
|
|
|
// //ammeterInfos.Add(new DeviceInfo()
|
|
|
|
|
|
// //{
|
|
|
|
|
|
// // Baudrate = 2400,
|
|
|
|
|
|
// // FocusAddress = "402440506",
|
|
|
|
|
|
// // Name = "中环半导体9#冷却泵-220KW(三相电表)",
|
|
|
|
|
|
// // FocusId = 106857,
|
|
|
|
|
|
// // DatabaseBusiID = 1,
|
|
|
|
|
|
// // MeteringCode = 0,
|
|
|
|
|
|
// // MeterAddress = "402410040506",
|
|
|
|
|
|
// // MeterId = 139059,
|
|
|
|
|
|
// // TypeName = 3,
|
|
|
|
|
|
// // DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679",
|
|
|
|
|
|
// // TimeDensity = 15,
|
|
|
|
|
|
// // BrandType = "DTS1980",
|
|
|
|
|
|
// // Password = "000000",
|
|
|
|
|
|
// // ProjectID = 1,
|
|
|
|
|
|
// // MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// // MeteringPort = MeteringPortConst.MeteringPortTwo,
|
|
|
|
|
|
// //});
|
|
|
|
|
|
|
2025-05-15 14:05:18 +08:00
|
|
|
|
|
|
|
|
|
|
// ammeterInfos.Add(new DeviceInfo()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Baudrate = 2400,
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// FocusAddress = "942411321",
|
|
|
|
|
|
// Name = "DDS1980-T4(5-60) ML307A 长稳 942408011321",
|
|
|
|
|
|
// FocusId = 57682,
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// DatabaseBusiID = 1,
|
|
|
|
|
|
// MeteringCode = 0,
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// MeterAddress = "942408011321",
|
|
|
|
|
|
// MeterId = 78970,
|
|
|
|
|
|
// TypeName = 3,
|
|
|
|
|
|
// DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679",
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// TimeDensity = 15,
|
|
|
|
|
|
// BrandType = "DTS1980",
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// Password = "000000",
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// ProjectID = 1,
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// MeterType = MeterTypeEnum.Ammeter,
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// MeteringPort = MeteringPortConst.MeteringPortTwo,
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
2025-05-18 13:36:11 +08:00
|
|
|
|
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// ammeterInfos.Add(new DeviceInfo()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Baudrate = 2400,
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// FocusAddress = "942411319",
|
|
|
|
|
|
// Name = "DDS1980-T4(5-60) ML307A 长稳 942408011319",
|
|
|
|
|
|
// FocusId = 57685,
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// DatabaseBusiID = 1,
|
|
|
|
|
|
// MeteringCode = 0,
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// MeterAddress = "942408011319",
|
|
|
|
|
|
// MeterId = 78973,
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// TypeName = 3,
|
|
|
|
|
|
// DataTypes = "449,503,581,582,583,584,585,586,587,588,589,590,591,592,593,594,597,598,599,600,601,602,603,604,605,606,607,608,661,663,677,679",
|
|
|
|
|
|
// TimeDensity = 15,
|
|
|
|
|
|
// BrandType = "DTS1980",
|
|
|
|
|
|
// Password = "000000",
|
|
|
|
|
|
// ProjectID = 1,
|
|
|
|
|
|
// MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// MeteringPort = MeteringPortConst.MeteringPortTwo,
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-18 13:36:11 +08:00
|
|
|
|
// FreeRedisProvider.Instance.Set(redisCacheDeviceInfoHashKeyTemp, ammeterInfos);
|
2025-05-15 14:05:18 +08:00
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// return ammeterInfos;
|
|
|
|
|
|
//#else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#endif
|
|
|
|
|
|
|
2025-05-13 14:51:38 +08:00
|
|
|
|
|
|
|
|
|
|
try
|
2025-04-23 09:42:09 +08:00
|
|
|
|
{
|
2025-05-13 14:51:38 +08:00
|
|
|
|
string sql = $@"SELECT
|
2025-05-18 13:36:11 +08:00
|
|
|
|
C.ID as MeterId,
|
|
|
|
|
|
C.Name,
|
|
|
|
|
|
C.FocusID as FocusId,
|
|
|
|
|
|
C.SingleRate,
|
|
|
|
|
|
C.MeteringCode,
|
|
|
|
|
|
C.Code AS BrandType,
|
|
|
|
|
|
C.Baudrate,
|
|
|
|
|
|
C.Password,
|
|
|
|
|
|
C.MeteringPort,
|
|
|
|
|
|
C.[Address] AS MeterAddress,
|
|
|
|
|
|
C.TypeName,
|
|
|
|
|
|
C.Protocol,
|
|
|
|
|
|
C.TripState,
|
|
|
|
|
|
C.[State],
|
|
|
|
|
|
B.[Address],
|
|
|
|
|
|
B.AreaCode,
|
|
|
|
|
|
B.AutomaticReport,
|
|
|
|
|
|
D.DataTypes,
|
|
|
|
|
|
B.TimeDensity,
|
|
|
|
|
|
A.GatherCode,
|
|
|
|
|
|
C.Special,
|
|
|
|
|
|
C.[ProjectID],
|
|
|
|
|
|
B.AbnormalState,
|
|
|
|
|
|
B.LastTime,
|
|
|
|
|
|
1 as MeterType,
|
|
|
|
|
|
CONCAT(B.AreaCode, B.[Address]) AS FocusAddress,
|
|
|
|
|
|
(select top 1 DatabaseBusiID from TB_Project where ID = B.ProjectID) AS DatabaseBusiID
|
|
|
|
|
|
FROM TB_GatherInfo(NOLOCK) AS A
|
|
|
|
|
|
INNER JOIN TB_FocusInfo(NOLOCK) AS B ON A.ID = B.GatherInfoID AND B.RemoveState >= 0 AND B.State>=0
|
|
|
|
|
|
INNER JOIN TB_AmmeterInfo(NOLOCK) AS C ON B.ID = C.FocusID AND C.State>= 0 AND C.State<100
|
|
|
|
|
|
INNER JOIN TB_AmmeterGatherItem(NOLOCK) AS D ON C.ID = D.AmmeterID AND D.State>=0
|
|
|
|
|
|
WHERE 1=1 and C.Special = 0 ";
|
2025-05-13 14:51:38 +08:00
|
|
|
|
//TODO 记得移除特殊表过滤
|
|
|
|
|
|
|
2025-05-15 14:05:18 +08:00
|
|
|
|
|
2025-05-18 13:36:11 +08:00
|
|
|
|
#if DEBUG
|
|
|
|
|
|
//// sql = $@"{sql} and c.Address in('542410000504','442405000040','442405000039','402410040506')";
|
2025-05-20 16:53:36 +08:00
|
|
|
|
//sql = $@"{sql} and c.Address in('402410040506')";
|
2025-05-15 14:05:18 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-05-13 14:51:38 +08:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(gatherCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
sql = $@"{sql} AND A.GatherCode = '{gatherCode}'";
|
|
|
|
|
|
}
|
|
|
|
|
|
return await SqlProvider.Instance.Change(DbEnum.EnergyDB)
|
|
|
|
|
|
.Ado
|
|
|
|
|
|
.QueryAsync<DeviceInfo>(sql);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
2025-05-14 14:40:34 +08:00
|
|
|
|
{
|
2025-05-13 14:51:38 +08:00
|
|
|
|
throw ex;
|
2025-04-23 09:42:09 +08:00
|
|
|
|
}
|
2025-05-15 11:23:08 +08:00
|
|
|
|
|
2025-03-12 14:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-23 16:17:29 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取电表阀控配置
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="currentTime">阀控的时间</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public override async Task<List<AmmeterAutoValveControlSetting>> GetAmmeterAutoValveControlSetting(string currentTime)
|
|
|
|
|
|
{
|
2025-05-13 14:51:38 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string sql = $@"SELECT A.*,B.AmmeterID as MeterId,E.GatherCode,D.AreaCode,D.[Address],CONCAT(D.AreaCode, D.[Address]) AS FocusAddress,D.ID as FocusId
|
2025-04-23 16:17:29 +08:00
|
|
|
|
FROM TB_AutoTripTask(nolock) AS A
|
|
|
|
|
|
INNER JOIN TB_AutoTripAmmeter(nolock) AS B ON A.ID=B.TripTaskID
|
|
|
|
|
|
INNER JOIN TB_AmmeterInfo(nolock) AS C ON B.AmmeterID=C.ID
|
|
|
|
|
|
INNER JOIN TB_FocusInfo(nolock) AS D ON D.ID=C.FocusID
|
|
|
|
|
|
INNER JOIN TB_GatherInfo(NOLOCK) AS E ON E.ID=D.GatherInfoID
|
2025-04-30 15:57:14 +08:00
|
|
|
|
WHERE A.IsForbid=0 and A.State<>-1 and E.GatherCode LIKE '%V4%' ";
|
2025-04-23 16:17:29 +08:00
|
|
|
|
|
2025-05-13 14:51:38 +08:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentTime))
|
|
|
|
|
|
{
|
|
|
|
|
|
sql = $@"{sql} AND A.TripTime = '{currentTime}'";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return await SqlProvider.Instance.Change(DbEnum.EnergyDB)
|
|
|
|
|
|
.Ado
|
|
|
|
|
|
.QueryAsync<AmmeterAutoValveControlSetting>(sql);
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
2025-05-13 14:51:38 +08:00
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
2025-04-23 16:17:29 +08:00
|
|
|
|
|
2025-05-13 14:51:38 +08:00
|
|
|
|
throw;
|
|
|
|
|
|
}
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 电表自动阀控
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
2025-04-30 12:36:54 +08:00
|
|
|
|
public override async Task<List<MeterReadingTelemetryPacketInfo>> AmmeterScheduledAutoValveControl()
|
2025-04-25 09:28:20 +08:00
|
|
|
|
{
|
2025-04-23 16:17:29 +08:00
|
|
|
|
var currentTime = DateTime.Now;
|
|
|
|
|
|
string currentTimeStr = $"{currentTime:HH:mm}";
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2025-05-14 23:28:44 +08:00
|
|
|
|
{
|
2025-05-14 14:40:34 +08:00
|
|
|
|
#if DEBUG
|
2025-05-14 23:28:44 +08:00
|
|
|
|
//电表自动阀控缓存
|
|
|
|
|
|
string redisCacheDeviceSettingInfoHashKey = $"redisCacheDeviceSettingInfoHashKey_{SystemType}_{ServerTagName}";
|
|
|
|
|
|
|
2025-05-18 13:36:11 +08:00
|
|
|
|
var settingInfos = FreeRedisProvider.Instance.Get<List<AmmeterAutoValveControlSetting>>(redisCacheDeviceSettingInfoHashKey);
|
2025-05-14 23:28:44 +08:00
|
|
|
|
if (settingInfos == null || settingInfos.Count <= 0)
|
2025-05-14 15:21:33 +08:00
|
|
|
|
{
|
2025-05-14 23:28:44 +08:00
|
|
|
|
settingInfos = new List<AmmeterAutoValveControlSetting>();
|
2025-05-15 23:59:10 +08:00
|
|
|
|
//settingInfos.Add(new AmmeterAutoValveControlSetting()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// AmmerterAddress = "442405000040",
|
|
|
|
|
|
// FocusAddress = "442400040",
|
|
|
|
|
|
// FocusId = 57683,
|
|
|
|
|
|
// ProjectID = 1,
|
|
|
|
|
|
// TripType = "on",
|
|
|
|
|
|
// TripTime = $"{DateTime.Now:HH:mm}",
|
|
|
|
|
|
// MeterId = 78971,
|
|
|
|
|
|
// LoopType = "EachDay",
|
|
|
|
|
|
// EachDayWithout = "周六,周日",
|
|
|
|
|
|
// TimeDensity = 15,
|
|
|
|
|
|
//});
|
|
|
|
|
|
//settingInfos.Add(new AmmeterAutoValveControlSetting()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// AmmerterAddress = "442405000039",
|
|
|
|
|
|
// FocusAddress = "442400039",
|
|
|
|
|
|
// FocusId = 57684,
|
|
|
|
|
|
// ProjectID = 1,
|
|
|
|
|
|
// TripType = "on",
|
|
|
|
|
|
// TripTime = $"{DateTime.Now:HH:mm}",
|
|
|
|
|
|
// MeterId = 78972,
|
|
|
|
|
|
// LoopType = "EachDay",
|
|
|
|
|
|
// EachDayWithout = "周六,周日",
|
|
|
|
|
|
// TimeDensity = 15,
|
|
|
|
|
|
//});
|
2025-05-18 13:36:11 +08:00
|
|
|
|
|
2025-05-15 23:59:10 +08:00
|
|
|
|
//settingInfos.Add(new AmmeterAutoValveControlSetting()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// AmmerterAddress = "542410000504",
|
|
|
|
|
|
// FocusAddress = "542400504",
|
|
|
|
|
|
// FocusId = 57686,
|
|
|
|
|
|
// ProjectID = 1,
|
|
|
|
|
|
// TripType = "on",
|
|
|
|
|
|
// TripTime = $"{DateTime.Now:HH:mm}",
|
|
|
|
|
|
// MeterId = 78974,
|
|
|
|
|
|
// LoopType = "EachDay",
|
|
|
|
|
|
// EachDayWithout = "周六,周日",
|
|
|
|
|
|
// TimeDensity = 15,
|
|
|
|
|
|
//});
|
2025-05-15 11:23:08 +08:00
|
|
|
|
|
2025-05-18 13:36:11 +08:00
|
|
|
|
//settingInfos.Add(new AmmeterAutoValveControlSetting()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// MeterType = MeterTypeEnum.Ammeter,
|
|
|
|
|
|
// AmmerterAddress = "402410040506",
|
|
|
|
|
|
// FocusAddress = "402440506",
|
|
|
|
|
|
// FocusId = 57685,
|
|
|
|
|
|
// ProjectID = 1,
|
|
|
|
|
|
// TripType = "on",
|
|
|
|
|
|
// TripTime = $"{DateTime.Now:HH:mm}",
|
|
|
|
|
|
// MeterId = 78973,
|
|
|
|
|
|
// LoopType = "EachDay",
|
|
|
|
|
|
// EachDayWithout = "周六,周日",
|
|
|
|
|
|
// TimeDensity = 15,
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
2025-05-14 23:28:44 +08:00
|
|
|
|
settingInfos.Add(new AmmeterAutoValveControlSetting()
|
|
|
|
|
|
{
|
|
|
|
|
|
MeterType = MeterTypeEnum.Ammeter,
|
2025-05-15 11:23:08 +08:00
|
|
|
|
AmmerterAddress = "402410040506",
|
|
|
|
|
|
FocusAddress = "402440506",
|
2025-05-15 14:05:18 +08:00
|
|
|
|
FocusId = 57685,
|
|
|
|
|
|
ProjectID = 1,
|
|
|
|
|
|
TripType = "on",
|
|
|
|
|
|
TripTime = $"{DateTime.Now:HH:mm}",
|
|
|
|
|
|
MeterId = 78973,
|
|
|
|
|
|
LoopType = "EachDay",
|
2025-05-18 16:04:23 +08:00
|
|
|
|
EachDayWithout = "周六",
|
2025-05-15 14:05:18 +08:00
|
|
|
|
TimeDensity = 15,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-05-14 23:28:44 +08:00
|
|
|
|
FreeRedisProvider.Instance.Set(redisCacheDeviceSettingInfoHashKey, settingInfos);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-18 13:36:11 +08:00
|
|
|
|
List<DeviceInfo> meterInfos = await GetAmmeterInfoList();
|
2025-05-14 14:40:34 +08:00
|
|
|
|
#else
|
2025-04-24 17:48:20 +08:00
|
|
|
|
//获取电表阀控配置
|
2025-04-23 16:17:29 +08:00
|
|
|
|
var settingInfos = await GetAmmeterAutoValveControlSetting(currentTimeStr);
|
|
|
|
|
|
if (settingInfos == null || settingInfos.Count <= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 电表自动阀控时,阀控数据为空, -101");
|
2025-04-30 12:36:54 +08:00
|
|
|
|
return null;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
2025-05-14 15:21:33 +08:00
|
|
|
|
|
2025-05-14 14:40:34 +08:00
|
|
|
|
//设备hash缓存key
|
|
|
|
|
|
string redisCacheDeviceInfoHashKey = $"{string.Format(RedisConst.CacheDeviceInfoHashKey, SystemType, ServerTagName)}";
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, List<DeviceInfo>> keyValuePairsTemps = FreeRedisProvider.Instance.HGetAll<List<DeviceInfo>>(redisCacheDeviceInfoHashKey);
|
|
|
|
|
|
List<DeviceInfo> meterInfos = new List<DeviceInfo>();
|
|
|
|
|
|
List<string> focusAddressDataLista = new List<string>();
|
|
|
|
|
|
foreach (var item in keyValuePairsTemps)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var subItem in item.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (subItem.MeterType == MeterTypeEnum.Ammeter && subItem.TimeDensity == 15)
|
|
|
|
|
|
{
|
|
|
|
|
|
meterInfos.Add(subItem);
|
|
|
|
|
|
focusAddressDataLista.Add(subItem.MeterId.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-15 11:23:08 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-23 16:17:29 +08:00
|
|
|
|
List<MeterReadingTelemetryPacketInfo> taskList = new List<MeterReadingTelemetryPacketInfo>();
|
2025-04-25 09:28:20 +08:00
|
|
|
|
|
2025-04-23 16:17:29 +08:00
|
|
|
|
foreach (var settingInfo in settingInfos)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool isGenerate = false;
|
|
|
|
|
|
switch (settingInfo.LoopType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case "Once":
|
|
|
|
|
|
isGenerate = CommonHelper.JudgeIsGenerate_Once(settingInfo.OnceWithDate.Value, currentTime);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "EachDay":
|
|
|
|
|
|
isGenerate = CommonHelper.JudgeIsGenerate_Day(settingInfo.EachDayWithout, currentTime);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "EachWeek":
|
|
|
|
|
|
isGenerate = CommonHelper.JudgeIsGenerate_Week(settingInfo.EachWeekWith, currentTime);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "EachMonth":
|
|
|
|
|
|
isGenerate = CommonHelper.JudgeIsGenerate_Month(settingInfo.EachMonthWith, currentTime);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!isGenerate)//不生成,跳入下一循环
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取对应的缓存电表信息
|
2025-05-18 13:36:11 +08:00
|
|
|
|
var ammeterInfo = meterInfos.Where(d => d.MeterId == settingInfo.MeterId).FirstOrDefault();
|
2025-05-14 14:40:34 +08:00
|
|
|
|
if (ammeterInfo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 电表自动阀控时,未找到对应电表信息,电表Id={settingInfo.MeterId}, -102");
|
|
|
|
|
|
continue;
|
2025-05-18 13:36:11 +08:00
|
|
|
|
}
|
2025-05-14 14:40:34 +08:00
|
|
|
|
|
2025-04-23 16:17:29 +08:00
|
|
|
|
bool tripStateResult = false;
|
2025-04-27 09:40:31 +08:00
|
|
|
|
string itemCode = T37612012PacketItemCodeConst.AFN10HFN01H;
|
2025-04-24 23:39:39 +08:00
|
|
|
|
string subItemCode = string.Empty;
|
2025-05-14 23:28:44 +08:00
|
|
|
|
if (settingInfo.TripType.Equals("on"))//当前电表断闸,需要合闸
|
2025-04-23 16:17:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
ammeterInfo.TripState = 0;
|
|
|
|
|
|
tripStateResult = true;
|
2025-05-14 17:41:39 +08:00
|
|
|
|
subItemCode = T6452007PacketItemCodeConst.C1C011C;
|
2025-05-15 11:23:08 +08:00
|
|
|
|
if (ammeterInfo.TypeName > 3)
|
2025-04-24 23:39:39 +08:00
|
|
|
|
{
|
2025-05-14 17:41:39 +08:00
|
|
|
|
subItemCode = T6452007PacketItemCodeConst.C1C011B;
|
2025-04-24 23:39:39 +08:00
|
|
|
|
}
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
2025-05-14 23:28:44 +08:00
|
|
|
|
else if (settingInfo.TripType.Equals("off"))//当前电表合闸,需要断闸
|
2025-04-23 16:17:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
ammeterInfo.TripState = 1;
|
|
|
|
|
|
tripStateResult = false;
|
2025-05-14 17:41:39 +08:00
|
|
|
|
subItemCode = T6452007PacketItemCodeConst.C1C011A;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError($"集中器[{settingInfo.FocusAddress}],[{settingInfo.MeterId}]阀控命令错误:{settingInfo.TripType},-102");
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2025-04-25 09:28:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-04-24 17:48:20 +08:00
|
|
|
|
//根据电表型号获取协议插件
|
|
|
|
|
|
var protocolPlugin = await _protocolService.GetProtocolServiceAsync(ammeterInfo.BrandType);
|
2025-04-23 16:17:29 +08:00
|
|
|
|
if (protocolPlugin == null)
|
|
|
|
|
|
{
|
2025-04-24 17:48:20 +08:00
|
|
|
|
_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有找到对应的协议组件,-105");
|
2025-04-30 12:36:54 +08:00
|
|
|
|
return null;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-24 23:39:39 +08:00
|
|
|
|
ProtocolBuildResponse builderResponse = await protocolPlugin.BuildAsync(new ProtocolBuildRequest()
|
2025-04-23 16:17:29 +08:00
|
|
|
|
{
|
2025-04-24 17:48:20 +08:00
|
|
|
|
FocusAddress = ammeterInfo.FocusAddress,
|
2025-05-20 16:41:58 +08:00
|
|
|
|
Pn = 0,//ammeterInfo.MeteringCode,现有协议里面阀控必须传0,不能根据档案的MeteringCode值走。
|
2025-04-27 09:40:31 +08:00
|
|
|
|
ItemCode = itemCode,
|
2025-04-24 23:39:39 +08:00
|
|
|
|
SubProtocolRequest = new SubProtocolBuildRequest()
|
|
|
|
|
|
{
|
2025-05-13 14:51:38 +08:00
|
|
|
|
MeterAddress = ammeterInfo.MeterAddress,
|
2025-04-24 23:39:39 +08:00
|
|
|
|
Password = ammeterInfo.Password,
|
|
|
|
|
|
ItemCode = subItemCode,
|
2025-05-14 23:28:44 +08:00
|
|
|
|
Baudrate = ammeterInfo.Baudrate,
|
|
|
|
|
|
MeteringPort = ammeterInfo.MeteringPort
|
2025-04-24 23:39:39 +08:00
|
|
|
|
}
|
2025-04-24 17:48:20 +08:00
|
|
|
|
});
|
2025-04-25 09:28:20 +08:00
|
|
|
|
|
2025-04-27 17:27:04 +08:00
|
|
|
|
|
|
|
|
|
|
var meterReadingRecords = CreateAmmeterPacketInfo(
|
|
|
|
|
|
ammeterInfo: ammeterInfo,
|
|
|
|
|
|
timestamps: currentTime.GetDateTimeOffset().ToUnixTimeNanoseconds(),
|
|
|
|
|
|
builderResponse: builderResponse,
|
|
|
|
|
|
itemCode: itemCode,
|
|
|
|
|
|
subItemCode: subItemCode,
|
|
|
|
|
|
pendingCopyReadTime: currentTime,
|
2025-04-29 10:12:09 +08:00
|
|
|
|
creationTime: currentTime,
|
2025-05-14 14:40:34 +08:00
|
|
|
|
packetType: TelemetryPacketTypeEnum.AmmeterAutoValveControl,
|
|
|
|
|
|
_guidGenerator);
|
2025-04-23 16:17:29 +08:00
|
|
|
|
taskList.Add(meterReadingRecords);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (taskList == null || taskList.Count <= 0)
|
|
|
|
|
|
{
|
2025-04-24 17:48:20 +08:00
|
|
|
|
_logger.LogError($"{nameof(AmmeterScheduledAutoValveControl)} 定时阀控运行时间{currentTime}没有自动阀控任务生成,-106");
|
2025-04-30 12:36:54 +08:00
|
|
|
|
return null;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-30 12:36:54 +08:00
|
|
|
|
return taskList;
|
2025-04-23 16:17:29 +08:00
|
|
|
|
//todo 阀控记录入库,推送到新的服务
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-12 14:57:42 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取水表信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="gatherCode">采集端Code</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
//[HttpGet]
|
|
|
|
|
|
//[Route($"ammeter/list")]
|
2025-05-13 14:51:38 +08:00
|
|
|
|
public override async Task<List<DeviceInfo>> GetWatermeterInfoList(string gatherCode = "V4-Gather-8890")
|
2025-03-12 14:57:42 +08:00
|
|
|
|
{
|
2025-05-13 14:51:38 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string sql = $@"SELECT
|
2025-04-15 16:48:35 +08:00
|
|
|
|
A.ID as MeterId,
|
2025-03-12 14:57:42 +08:00
|
|
|
|
A.Name,
|
2025-04-15 16:48:35 +08:00
|
|
|
|
A.FocusID as FocusId,
|
2025-03-12 14:57:42 +08:00
|
|
|
|
A.MeteringCode,
|
|
|
|
|
|
A.Baudrate,
|
|
|
|
|
|
A.MeteringPort,
|
|
|
|
|
|
A.[Address] AS MeterAddress,
|
|
|
|
|
|
A.[Password],
|
|
|
|
|
|
A.TypeName,
|
|
|
|
|
|
A.Protocol,
|
|
|
|
|
|
A.Code,
|
|
|
|
|
|
A.LinkType,
|
|
|
|
|
|
A.HaveValve,
|
|
|
|
|
|
A.MeterType AS MeterTypeName,
|
|
|
|
|
|
A.MeterBrand,
|
|
|
|
|
|
A.TimesRate,
|
|
|
|
|
|
A.TimeDensity,
|
|
|
|
|
|
A.TripState,
|
|
|
|
|
|
B.[Address],
|
|
|
|
|
|
B.AreaCode,
|
|
|
|
|
|
B.AutomaticReport,
|
|
|
|
|
|
A.[State],
|
|
|
|
|
|
C.GatherCode,
|
|
|
|
|
|
A.[ProjectID],
|
|
|
|
|
|
B.AbnormalState,
|
2025-03-21 11:48:31 +08:00
|
|
|
|
B.LastTime,
|
2025-05-13 14:51:38 +08:00
|
|
|
|
2 as MeterType,
|
2025-03-21 11:48:31 +08:00
|
|
|
|
CONCAT(B.AreaCode, B.[Address]) AS FocusAddress,
|
|
|
|
|
|
(select top 1 DatabaseBusiID from TB_Project where ID = b.ProjectID) AS DatabaseBusiID
|
2025-03-12 14:57:42 +08:00
|
|
|
|
FROM [dbo].[TB_WatermeterInfo](NOLOCK) AS A
|
|
|
|
|
|
INNER JOIN [dbo].[TB_FocusInfo](NOLOCK) AS B ON A.FocusID=B.ID AND B.RemoveState >= 0 AND B.State>=0
|
|
|
|
|
|
INNER JOIN [dbo].[TB_GatherInfo](NOLOCK) AS C ON B.GatherInfoID=C.ID
|
|
|
|
|
|
WHERE A.State>=0 AND A.State<100 ";
|
|
|
|
|
|
|
2025-05-13 14:51:38 +08:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(gatherCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
sql = $@"{sql} AND C.GatherCode= '{gatherCode}'";
|
|
|
|
|
|
}
|
|
|
|
|
|
return await SqlProvider.Instance.Change(DbEnum.EnergyDB)
|
|
|
|
|
|
.Ado
|
|
|
|
|
|
.QueryAsync<DeviceInfo>(sql);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
2025-03-12 14:57:42 +08:00
|
|
|
|
{
|
2025-05-13 14:51:38 +08:00
|
|
|
|
|
|
|
|
|
|
throw;
|
2025-03-12 14:57:42 +08:00
|
|
|
|
}
|
2025-04-23 16:17:29 +08:00
|
|
|
|
}
|
2025-03-12 14:57:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|