@@ -1,9 +1,6 @@
using Dlhis.Basic.Device.Request ;
using Dlhis.Basic.Device.Request ;
using Dlhis.Basic.Device.Response ;
using Dlhis.Entity.Basic.Entity ;
using Dlhis.Entity.Canteen.Entities ;
using Dlhis.Entity.Canteen.Enums ;
using Dlhis.Entity.Device.Entities ;
using Dlhis.Entity.Device.Enums ;
using Dlhis.Sys.Api ;
@@ -17,7 +14,6 @@ using Kurisu.AspNetCore.Utils.Extensions;
using Mapster ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Linq ;
using SqlSugar ;
namespace Dlhis.Basic.Device.Services.Implements ;
@@ -252,7 +248,6 @@ public class DeviceService : IDeviceService
}
catch ( Exception )
{
}
true . ThrowIfTrue ( $"设备已添加{factory}厂区" ) ;
@@ -293,7 +288,6 @@ public class DeviceService : IDeviceService
{
FuncsStr = device . Funcs . ToString ( ) ,
ConnectionInfoStr = device . ConnectionInfo
} , true )
. SingleAsync ( ) ;
@@ -328,6 +322,7 @@ public class DeviceService : IDeviceService
} ;
return res ;
}
/// <summary>
/// 获取离线设备
/// </summary>
@@ -349,22 +344,17 @@ public class DeviceService : IDeviceService
} )
. ToListAsync ( ) ;
var onlineDevices = deviceRegistries
. Where ( x = >
var onlineDevices = deviceRegistries . Where ( x = >
{
if ( x . HeartbeatInterval < = 0 )
{
return true ;
}
if ( x . HeartbeatInterval < = 0 ) return true ;
return x . LastHeartbeatTime . AddSeconds ( x . HeartbeatInterval * 3 ) > = now ;
} )
. Select ( x = > new
{
x . UniqueNo ,
x . UniqueNo
} )
. ToList ( ) ;
var onlineUniqueNos = new List < string > ( ) ;
onlineDevices . ForEach ( x = > onlineUniqueNos . Add ( x . UniqueNo ) ) ;
@@ -384,7 +374,6 @@ public class DeviceService : IDeviceService
FuncsStr = d . Funcs . ToString ( ) ,
Brand = dt . Brand ,
Type = d . Type ,
} , true )
. ToPageListAsync ( request ) ;
@@ -393,93 +382,15 @@ public class DeviceService : IDeviceService
public async Task < Pagination < DevicePageResponse > > GetAttendanceOfflineAsync ( DeviceOnlineAndOfflineRequest request )
{
var devices = await _dbContext . Queryable < DeviceEntity > ( ) . Where ( x = > x . Type = = DeviceTypeEnumType . Attendance | | ( x . Type = = DeviceTypeEnumType . Door & & x . As Attendance) ) . ToListAsync ( ) ;
//离线
var offDevices = await GetOfflineDevicesCount ( devices ) ;
var offids = offDevices . Select ( x = > x . Id ) . ToList ( ) ;
if ( request . IsOnAndOff )
{
//离线
var offpage = await _dbContext . Queryable < DeviceEntity > ( )
. LeftJoin < DeviceTemplateEntity > ( ( d , dt ) = > d . TemplateCode = = dt . Code )
. Where ( d = > d . Type = = DeviceTypeEnumType . Attendance )
. Where ( d = > offids . Contains ( d . Id ) )
. Select ( ( d , dt ) = > new DevicePageResponse
{
FuncsStr = d . Funcs . ToString ( ) ,
Brand = dt . Brand ,
Type = d . Type ,
} , true )
. ToPageListAsync ( request ) ;
return offpage ;
return await GetDeviceStatusPageAsync ( request . IsOnAndOff , request , DeviceTypeEnumType . Attendance ) ;
}
//在线
var ids = devices . Select ( x = > x . Id ) . ToList ( ) ;
List < long > onids = ids . Except ( offids ) . ToList ( ) ;
var page = await _dbContext . Queryable < DeviceEntity > ( )
. LeftJoin < DeviceTemplateEntity > ( ( d , dt ) = > d . TemplateCode = = dt . Code )
. Where ( d = > d . Type = = DeviceTypeEnumType . Attendance )
. Where ( d = > onids . Contains ( d . Id ) )
. Select ( ( d , dt ) = > new DevicePageResponse
{
FuncsStr = d . Funcs . ToString ( ) ,
Brand = dt . Brand ,
Type = d . Type ,
} , true )
. ToPageListAsync ( request ) ;
return page ;
}
public async Task < Pagination < DevicePageResponse > > GetDoorOfflineAsync ( GetDoorOfflineRequest request )
{
var devices = await _dbContext . Queryable < DeviceEntity > ( ) . Where ( x = > x . Type = = DeviceTypeEnumType . Door ) . ToListAsync ( ) ;
var offDevices = await GetOfflineDevicesCount ( devices ) ;
var offids = offDevices . Select ( x = > x . Id ) . ToList ( ) ;
if ( request . IsOnAndOff )
{
//离线
var offpage = await _dbContext . Queryable < DeviceEntity > ( )
. LeftJoin < DeviceTemplateEntity > ( ( d , dt ) = > d . TemplateCode = = dt . Code )
. Where ( d = > d . Type = = DeviceTypeEnumType . Door )
. Where ( d = > offids . Contains ( d . Id ) )
. Select ( ( d , dt ) = > new DevicePageResponse
{
FuncsStr = d . Funcs . ToString ( ) ,
Brand = dt . Brand ,
Type = d . Type ,
} , true )
. ToPageListAsync ( request ) ;
return offpage ;
return await GetDeviceStatusPageAsync ( request . IsOnAndOff , request , DeviceTypeEnumType . Door ) ;
}
//在线
var ids = devices . Select ( x = > x . Id ) . ToList ( ) ;
List < long > onids = ids . Except ( offids ) . ToList ( ) ;
var page = await _dbContext . Queryable < DeviceEntity > ( )
. LeftJoin < DeviceTemplateEntity > ( ( d , dt ) = > d . TemplateCode = = dt . Code )
. Where ( d = > d . Type = = DeviceTypeEnumType . Door )
. Where ( d = > onids . Contains ( d . Id ) )
. Select ( ( d , dt ) = > new DevicePageResponse
{
FuncsStr = d . Funcs . ToString ( ) ,
Brand = dt . Brand ,
Type = d . Type ,
} , true )
. ToPageListAsync ( request ) ;
return page ;
}
public async Task < List < RecentNumberResponse > > GetRecentNumbersAsync ( )
{
@@ -509,7 +420,35 @@ public class DeviceService : IDeviceService
return list ;
}
//************************************************************* help methods ************************************************************************
private async Task < Pagination < DevicePageResponse > > GetDeviceStatusPageAsync ( bool isOnAndOff , PageDto pageDto , DeviceTypeEnumType deviceType )
{
var devices = deviceType = = DeviceTypeEnumType . Attendance
? await _dbContext . Queryable < DeviceEntity > ( ) . Where ( x = > x . Type = = DeviceTypeEnumType . Attendance | | ( x . Type = = DeviceTypeEnumType . Door & & x . AsAttendance ) ) . ToListAsync ( )
: await _dbContext . Queryable < DeviceEntity > ( ) . Where ( x = > x . Type = = DeviceTypeEnumType . Door ) . ToListAsync ( ) ;
var offDevices = await GetOfflineDevicesCount ( devices ) ;
//离线
var ids = offDevices . Select ( x = > x . Id ) . ToList ( ) ;
if ( ! isOnAndOff )
{
ids = devices . Select ( x = > x . Id ) . Except ( ids ) . ToList ( ) ;
}
return await _dbContext . Queryable < DeviceEntity > ( )
. LeftJoin < DeviceTemplateEntity > ( ( d , dt ) = > d . TemplateCode = = dt . Code )
. Where ( d = > d . Type = = DeviceTypeEnumType . Attendance )
. Where ( d = > ids . Contains ( d . Id ) )
. WhereIF ( pageDto . Search . IsPresent ( ) , d = > d . UniqueNo = = pageDto . Search
| | d . DeployPlace . Contains ( pageDto . Search ) )
. Select ( ( d , dt ) = > new DevicePageResponse
{
FuncsStr = d . Funcs . ToString ( ) ,
Brand = dt . Brand ,
Type = d . Type ,
} , true )
. ToPageListAsync ( pageDto ) ;
}
}