fix 代码优化
This commit is contained in:
@@ -23,4 +23,9 @@ public class DeviceGroupSaveRequest
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(DeviceTypeEnumType))]
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
|
||||
@@ -29,6 +29,11 @@ public class DeviceGroupTreeResponse
|
||||
/// </summary>
|
||||
public DeviceTypeEnumType? Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分组类型描述
|
||||
/// </summary>
|
||||
|
||||
@@ -85,10 +85,32 @@ public class DevicePageResponse
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
|
||||
|
||||
//*********************************************************附加信息**************************************************************/
|
||||
|
||||
/// <summary>
|
||||
/// 最后心跳时间
|
||||
/// </summary>
|
||||
public DateTime? LastHeartbeatTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否在线
|
||||
/// </summary>
|
||||
public bool IsOnline { get; set; }
|
||||
public bool IsOnline
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!LastHeartbeatTime.HasValue)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
if (HeartbeatInterval <= 0)
|
||||
return true;
|
||||
else
|
||||
return LastHeartbeatTime.Value.AddSeconds(HeartbeatInterval * 3) >= DateTime.Now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消费总额
|
||||
@@ -103,7 +125,7 @@ public class DevicePageResponse
|
||||
/// <summary>
|
||||
/// 营业点code
|
||||
/// </summary>
|
||||
public string BusinessPlaceCode { get; set; }
|
||||
public Guid? BusinessPlaceCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业点名称
|
||||
|
||||
@@ -11,11 +11,9 @@ using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -32,73 +30,35 @@ public class DeviceService : IDeviceService
|
||||
{
|
||||
var page = await _dbContext.Queryable<DeviceEntity>()
|
||||
.LeftJoin<DeviceTemplateEntity>((d, dt) => d.TemplateCode == dt.Code)
|
||||
.LeftJoin<DeviceRegistryEntity>((d, dt, dr) => d.UniqueNo == dr.DeviceUniqueNo)
|
||||
.LeftJoin<BusinessPlaceEntity>((d, dt, dr, bp) => dr.BusinessPlaceCode == bp.Code)
|
||||
.WhereIF(request.Type.HasValue, (d, dt) => d.Type == request.Type)
|
||||
.Select((d, dt) => new DevicePageResponse
|
||||
.Select((d, dt, dr, bp) => new DevicePageResponse
|
||||
{
|
||||
FuncsStr = d.Funcs.ToString(),
|
||||
Brand = dt.Brand,
|
||||
Type = d.Type,
|
||||
BusinessPlaceCode = bp.Code,
|
||||
BusinessPlaceName = bp.Name,
|
||||
LastHeartbeatTime = dr.LastHeartbeatTime
|
||||
}, true)
|
||||
.ToPageListAsync(request);
|
||||
|
||||
var now = DateTime.Now;
|
||||
var deviceUniqueNos = page.Data.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var balanceRecords = await _dbContext.Queryable<BalanceRecordEntity>().Where(x => x.Type == BalanceRecordTypeEnumType.Out)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceInfo))
|
||||
.Select(x => new
|
||||
{
|
||||
x.Amount,
|
||||
x.UserCode
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select((x, d) => new
|
||||
{
|
||||
d.HeartbeatInterval,
|
||||
x.LastHeartbeatTime,
|
||||
x.DeviceUniqueNo,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var Registries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.ToListAsync();
|
||||
var BusinessPlaces = await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var res in page.Data)
|
||||
{
|
||||
var regis = Registries.Where(x => x.DeviceUniqueNo == res.UniqueNo).FirstOrDefault();
|
||||
if (regis != null)
|
||||
{
|
||||
var place = BusinessPlaces.Where(x => x.Code == regis.BusinessPlaceCode).FirstOrDefault();
|
||||
if (place != null)
|
||||
{
|
||||
res.BusinessPlaceCode = regis.BusinessPlaceCode.ToString();
|
||||
res.BusinessPlaceName = place.Name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
page.Data.ForEach(device =>
|
||||
{
|
||||
device.Amount = balanceRecords.Sum(x => x.Amount);
|
||||
device.UserCount = balanceRecords.DistinctBy(x => x.UserCode).Count();
|
||||
|
||||
var r = deviceRegistries.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (r == null)
|
||||
{
|
||||
device.IsOnline = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (r.HeartbeatInterval <= 0)
|
||||
{
|
||||
device.IsOnline = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
device.IsOnline = r.LastHeartbeatTime.AddSeconds(r.HeartbeatInterval * 3) >= now;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return page;
|
||||
@@ -290,7 +250,7 @@ public class DeviceService : IDeviceService
|
||||
public async Task<DeviceNumberResponse> GetDeviceNumberAsync()
|
||||
{
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().Where(x => x.Type == DeviceTypeEnumType.Attendance || (x.Type == DeviceTypeEnumType.Door && x.AsAttendance)).ToListAsync();
|
||||
|
||||
|
||||
var offlineNumber = await GetOfflineDevicesCount(devices);
|
||||
|
||||
var res = new DeviceNumberResponse
|
||||
@@ -333,7 +293,7 @@ public class DeviceService : IDeviceService
|
||||
return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now;
|
||||
|
||||
})
|
||||
.Select(x => new
|
||||
.Select(x => new
|
||||
{
|
||||
UniqueNo = x.UniqueNo,
|
||||
})
|
||||
@@ -345,7 +305,7 @@ public class DeviceService : IDeviceService
|
||||
var list = devices.Where(x => offUniqueNos.Contains(x.UniqueNo)).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<Pagination<DevicePageResponse>> GetAttendanceTotalAsync(AttendanceTotalRequest request)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user