2025-03-12 09:58:37 +08:00
using FreeRedis ;
using FreeSql ;
using JiShe.CollectBus.FreeRedisProvider ;
using JiShe.CollectBus.FreeSql ;
2024-12-19 16:07:07 +08:00
using JiShe.CollectBus.Localization ;
2025-03-12 09:58:37 +08:00
using JiShe.CollectBus.Workers.DTO.Energy ;
2024-12-19 16:07:07 +08:00
using Microsoft.AspNetCore.Mvc ;
2025-03-12 09:58:37 +08:00
using System.Collections.Generic ;
using System.Threading.Tasks ;
2024-12-19 16:07:07 +08:00
using Volo.Abp.Application.Services ;
namespace JiShe.CollectBus ;
[ApiExplorerSettings(GroupName = CollectBusDomainSharedConsts.Business)]
public abstract class CollectBusAppService : ApplicationService
{
public IFreeSqlProvider SqlProvider = > LazyServiceProvider . LazyGetRequiredService < IFreeSqlProvider > ( ) ;
2025-03-12 09:58:37 +08:00
protected IRedisClient ? FreeRedis = > LazyServiceProvider . LazyGetService < IFreeRedisProviderService > ( ) ? . FreeRedis ;
2024-12-19 16:07:07 +08:00
protected CollectBusAppService ( )
{
LocalizationResource = typeof ( CollectBusResource ) ;
ObjectMapperContext = typeof ( CollectBusApplicationModule ) ;
}
2025-03-12 09:58:37 +08:00
#region 能 耗 相 关
/// <summary>
/// 查找当前采集器下所有电表
/// </summary>
/// <param name="gatherCode">采集端Code</param>
/// <returns></returns>
protected async Task < List < EnergyAmmeterInfoDto > > GetAmmetersByGatherCode ( 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
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 A . GatherCode = { gatherCode } ";
return await SqlProvider . Instance . Change ( DbEnum . EnergyDB ) . Select < EnergyAmmeterInfoDto > ( sql ) . ToListAsync ( ) ;
}
#endregion
2024-12-19 16:07:07 +08:00
}