2025-03-12 14:57:42 +08:00
using FreeRedis ;
using JiShe.CollectBus.Ammeters ;
using JiShe.CollectBus.Common.Consts ;
2025-03-12 16:29:38 +08:00
using JiShe.CollectBus.Devices ;
2025-03-12 14:57:42 +08:00
using JiShe.CollectBus.FreeRedisProvider ;
using JiShe.CollectBus.FreeSql ;
using JiShe.CollectBus.Watermeter ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Mvc ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using Volo.Abp.DependencyInjection ;
2025-03-12 16:29:38 +08:00
using Volo.Abp.Domain.Repositories ;
2025-03-12 14:57:42 +08:00
namespace JiShe.CollectBus.Workers
{
/// <summary>
/// 能耗系统定时采集服务
/// </summary>
[AllowAnonymous]
//[Route($"/energy/app/scheduled")]
public class EnergySystemScheduledMeterReadingService : BasicScheduledMeterReadingService
{
2025-03-12 16:29:38 +08:00
private readonly IRepository < Device , Guid > _deviceRepository ;
public EnergySystemScheduledMeterReadingService ( IRepository < Device , Guid > deviceRepository )
{
this . _deviceRepository = deviceRepository ;
}
2025-03-12 14:57:42 +08:00
public sealed override string SystemType = > SystemTypeConst . Energy ;
/// <summary>
/// 获取电表信息
/// </summary>
/// <param name="gatherCode">采集端Code</param>
/// <returns></returns>
//[HttpGet]
//[Route($"ammeter/list")]
public override async Task < List < AmmeterInfo > > GetAmmeterInfoList ( string gatherCode = "V4-Gather-8890" )
{
string sql = $ @ "SELECT C.ID,C.Name,C.FocusID,C.SingleRate,C.MeteringCode,C.Code AS BrandType,C.Baudrate,C.Password,C.MeteringPort,C.[Address] AS AmmerterAddress,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,CONCAT(B.AreaCode, B.[Address]) AS FocusAddress
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 ";
if ( ! string . IsNullOrWhiteSpace ( gatherCode ) )
{
sql = $@"{sql} A.GatherCode = '{gatherCode}'" ;
}
return await SqlProvider . Instance . Change ( DbEnum . EnergyDB )
. Ado
. QueryAsync < AmmeterInfo > ( sql ) ;
}
/// <summary>
/// 获取水表信息
/// </summary>
/// <param name="gatherCode">采集端Code</param>
/// <returns></returns>
//[HttpGet]
//[Route($"ammeter/list")]
public override async Task < List < WatermeterInfo > > GetWatermeterInfoList ( string gatherCode = "V4-Gather-8890" )
{
string sql = $ @ "SELECT
A . ID ,
A . Name ,
A . FocusID ,
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 ,
B . LastTime
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 ";
if ( ! string . IsNullOrWhiteSpace ( gatherCode ) )
{
sql = $@"{sql} AND C.GatherCode= '{gatherCode}'" ;
}
return await SqlProvider . Instance . Change ( DbEnum . EnergyDB )
. Ado
. QueryAsync < WatermeterInfo > ( sql ) ;
}
}
}