fix 优化apilog和设备上传log
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
using Dlhis.Entity.Basic.Enums;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Request
|
namespace Dlhis.Basic.Device.Request;
|
||||||
{
|
|
||||||
public class ApiLogRequest :PageDto
|
|
||||||
{
|
|
||||||
public string message { get; set; }
|
|
||||||
|
|
||||||
[EnumDataType(typeof(ApiLogEnumType)),]
|
public class ApiLogRequest : PageDto
|
||||||
public ApiLogEnumType? Type { get; set; }
|
{
|
||||||
}
|
/// <summary>
|
||||||
|
/// 日志级别 LogLevel
|
||||||
|
/// </summary>
|
||||||
|
[EnumDataType(typeof(LogLevel))]
|
||||||
|
public LogLevel? Level { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,56 @@
|
|||||||
using SqlSugar;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Response
|
namespace Dlhis.Basic.Device.Response;
|
||||||
|
|
||||||
|
public class ApiLogResponse
|
||||||
{
|
{
|
||||||
public class ApiLogResponse
|
/// <summary>
|
||||||
|
/// 时间UTC
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public string Timestamp { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 产生时间
|
||||||
|
/// </summary>
|
||||||
|
public DateTime RaiseTime
|
||||||
{
|
{
|
||||||
/// <summary>
|
get
|
||||||
/// 时间
|
{
|
||||||
/// </summary>
|
return DateTime.Parse(Timestamp).ToLocalTime();
|
||||||
public string Timestamp { get; set; }
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 级别
|
|
||||||
/// </summary>
|
|
||||||
public string Level { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 模板
|
|
||||||
/// </summary>
|
|
||||||
public string Template { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 消息内容
|
|
||||||
/// </summary>
|
|
||||||
public string Message { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异常内容
|
|
||||||
/// </summary>
|
|
||||||
public string Exception { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 属性
|
|
||||||
/// </summary>
|
|
||||||
public string Properties { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 时间
|
|
||||||
/// </summary>
|
|
||||||
public DateTime _ts { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 级别
|
||||||
|
/// </summary>
|
||||||
|
public string Level { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public string Template { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 消息内容
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异常内容
|
||||||
|
/// </summary>
|
||||||
|
public string Exception { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public string Properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间
|
||||||
|
/// </summary>
|
||||||
|
[JsonIgnore]
|
||||||
|
public DateTime _TS { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using Kurisu.SqlSugar.Services;
|
|||||||
using Mapster;
|
using Mapster;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.Basic.Device.Services.Implements;
|
namespace Dlhis.Basic.Device.Services.Implements;
|
||||||
|
|
||||||
@@ -247,10 +248,10 @@ public class DeviceService : IDeviceService
|
|||||||
var offlineNumber = await GetOfflineDevicesCount(devices);
|
var offlineNumber = await GetOfflineDevicesCount(devices);
|
||||||
|
|
||||||
var res = new DeviceNumberResponse
|
var res = new DeviceNumberResponse
|
||||||
{
|
{
|
||||||
OfflineNumber = offlineNumber.Count,
|
OfflineNumber = offlineNumber.Count,
|
||||||
TotalNumber = devices.Count,
|
TotalNumber = devices.Count,
|
||||||
OnlineNumber = devices.Count- offlineNumber.Count
|
OnlineNumber = devices.Count - offlineNumber.Count
|
||||||
};
|
};
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -270,14 +271,14 @@ public class DeviceService : IDeviceService
|
|||||||
foreach (var device in devices)
|
foreach (var device in devices)
|
||||||
{
|
{
|
||||||
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||||
if (regis == null)
|
if (regis == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
||||||
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
||||||
{
|
{
|
||||||
list.Add(device);
|
list.Add(device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
@@ -307,7 +308,7 @@ public class DeviceService : IDeviceService
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
//离线
|
//离线
|
||||||
var offDevices =await GetOfflineDevicesCount(devices);
|
var offDevices = await GetOfflineDevicesCount(devices);
|
||||||
var offids = offDevices.Select(x => x.Id).ToList();
|
var offids = offDevices.Select(x => x.Id).ToList();
|
||||||
|
|
||||||
if (request.IsOnAndOff)
|
if (request.IsOnAndOff)
|
||||||
@@ -372,28 +373,19 @@ public class DeviceService : IDeviceService
|
|||||||
};
|
};
|
||||||
list.Add(res);
|
list.Add(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Pagination<ApiLogResponse>> GetLogsAsync(ApiLogRequest request)
|
public async Task<Pagination<ApiLogResponse>> GetLogsAsync(ApiLogRequest request)
|
||||||
{
|
{
|
||||||
var level = request.Type.ToString();
|
var logs = await _dbContext.ChangeDb("log").Queryable<ApiLogEntity>()
|
||||||
return await Scoped.Request.Value.CreateAsync(async (sp) =>
|
.WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search))
|
||||||
{
|
.WhereIF(request.Level.HasValue, x => x.Level == request.Level)
|
||||||
var configuration = sp.GetService<IConfiguration>();
|
|
||||||
var logConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value;
|
|
||||||
|
|
||||||
//todo 切换连接字符串
|
|
||||||
var dbContext = sp.GetService<IDbContext>();
|
|
||||||
dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString;
|
|
||||||
var logs = await dbContext.Queryable<ApiLogEntity>()
|
|
||||||
.WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message))
|
|
||||||
.WhereIF(!level.IsEmpty(), x => x.Level == level)
|
|
||||||
.Select<ApiLogResponse>()
|
.Select<ApiLogResponse>()
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
return logs;
|
|
||||||
|
|
||||||
});
|
return logs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Kurisu.AspNetCore;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Kurisu.AspNetCore;
|
||||||
using Kurisu.AspNetCore.Startup;
|
using Kurisu.AspNetCore.Startup;
|
||||||
using Kurisu.Core.DataAccess.Entity;
|
using Kurisu.Core.DataAccess.Entity;
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
@@ -14,26 +15,58 @@ public class SqlSugarPack : BaseAppPack
|
|||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSqlSugar();
|
services.AddSqlSugar(sp =>
|
||||||
|
{
|
||||||
|
var configuration = sp.GetService<IConfiguration>();
|
||||||
|
|
||||||
|
return new List<ConnectionConfig>
|
||||||
|
{
|
||||||
|
new ConnectionConfig
|
||||||
|
{
|
||||||
|
ConfigId = "face",
|
||||||
|
|
||||||
|
ConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value,
|
||||||
|
DbType = DbType.MySql,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
|
||||||
|
MoreSettings = new ConnMoreSettings
|
||||||
|
{
|
||||||
|
DisableNvarchar = true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new ConnectionConfig
|
||||||
|
{
|
||||||
|
ConfigId = "log",
|
||||||
|
|
||||||
|
ConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value,
|
||||||
|
DbType = DbType.MySql,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
|
||||||
|
MoreSettings = new ConnMoreSettings
|
||||||
|
{
|
||||||
|
DisableNvarchar = true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
using var scope = app.ApplicationServices.CreateScope();
|
using var scope = app.ApplicationServices.CreateScope();
|
||||||
var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
var db = scope.ServiceProvider.GetService<IDbContext>();
|
||||||
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false))
|
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false))
|
||||||
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
|
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
db.DbMaintenance.CreateDatabase();
|
db.Client.DbMaintenance.CreateDatabase();
|
||||||
db.CodeFirst.InitTables(tables);
|
db.Client.CodeFirst.InitTables(tables);
|
||||||
|
|
||||||
//using var scopeFace = app.ApplicationServices.CreateScope();
|
var faceDb = db.ChangeDb("face");
|
||||||
//var dbFace = scopeFace.ServiceProvider.GetService<ISqlSugarClient>();
|
faceDb.DbMaintenance.CreateDatabase();
|
||||||
//var faceConnectionString = Configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
faceDb.CodeFirst.InitTables<GainfoFaceEntity>();
|
||||||
//dbFace.CurrentConnectionConfig.ConnectionString = faceConnectionString;
|
|
||||||
//dbFace.DbMaintenance.CreateDatabase();
|
|
||||||
//dbFace.CodeFirst.InitTables<GainfoFaceEntity>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ public class EnumsController : ControllerBase
|
|||||||
})
|
})
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
//todo cache 速度
|
|
||||||
var dbTypes = _dbContext.Queryable<BasicTypeEntity>().OrderBy(x => x.Sequence).ToList();
|
var dbTypes = _dbContext.Queryable<BasicTypeEntity>().OrderBy(x => x.Sequence).ToList();
|
||||||
var dbResult = dbTypes.GroupBy(x => x.Type).Select(g =>
|
var dbResult = dbTypes.GroupBy(x => x.Type).Select(g =>
|
||||||
{
|
{
|
||||||
@@ -77,6 +76,29 @@ public class EnumsController : ControllerBase
|
|||||||
|
|
||||||
result.AddRange(dbResult);
|
result.AddRange(dbResult);
|
||||||
|
|
||||||
|
result.Add(GetCurrentEnums("LogLevel", "日志级别", typeof(LogLevel)));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static CommonEnumResponse GetCurrentEnums(string code, string name, Type enumType)
|
||||||
|
{
|
||||||
|
return new CommonEnumResponse
|
||||||
|
{
|
||||||
|
Code = code,
|
||||||
|
Name = name,
|
||||||
|
Data = enumType.GetFields(BindingFlags.Public | BindingFlags.Static).Select(item =>
|
||||||
|
{
|
||||||
|
var e = (Enum)Enum.Parse(item.FieldType, item.GetValue(null).ToString());
|
||||||
|
var fd = e.GetDescription();
|
||||||
|
return new KeyValueDto
|
||||||
|
{
|
||||||
|
Key = fd,
|
||||||
|
Value = (int)item.GetValue(null)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +1,55 @@
|
|||||||
using Kurisu.Core.DataAccess.Entity;
|
using Microsoft.Extensions.Logging;
|
||||||
using Kurisu.SqlSugar;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using SqlSugar.DbConvert;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Dlhis.Entity.Basic.Entity
|
namespace Dlhis.Entity.Basic.Entity;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// api日志表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable(TableName = "Logs", TableDescription = "api日志表")]
|
||||||
|
public class ApiLogEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// api日志表
|
/// 时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarTable(TableName = "Logs", TableDescription = "api日志表")]
|
[SugarColumn(ColumnDescription = "时间")]
|
||||||
public class ApiLogEntity
|
public string Timestamp { get; set; }
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 时间
|
|
||||||
/// </summary>
|
|
||||||
[SugarColumn(ColumnDescription = "时间")]
|
|
||||||
public string Timestamp { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 级别
|
/// 级别
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "级别")]
|
[SugarColumn(ColumnDescription = "级别", SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||||
public string Level { get; set; }
|
public LogLevel Level { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模板
|
/// 模板
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "模板")]
|
[SugarColumn(ColumnDescription = "模板")]
|
||||||
public string Template { get; set; }
|
public string Template { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 消息内容
|
/// 消息内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "消息内容")]
|
[SugarColumn(ColumnDescription = "消息内容")]
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异常内容
|
/// 异常内容
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "异常内容")]
|
[SugarColumn(ColumnDescription = "异常内容")]
|
||||||
public string Exception { get; set; }
|
public string Exception { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 属性
|
/// 属性
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "属性")]
|
[SugarColumn(ColumnDescription = "属性")]
|
||||||
public string Properties { get; set; }
|
public string Properties { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 时间
|
/// 时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDescription = "时间")]
|
[SugarColumn(ColumnDescription = "时间")]
|
||||||
public DateTime _ts { get; set; }
|
public DateTime _ts { get; set; }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,6 @@ public class GainfoFaceEntity : SugarBaseEntity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 人脸
|
/// 人脸
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnDataType = "text", IsNullable = false)]
|
[SugarColumn(ColumnDataType = "longtext", IsNullable = false)]
|
||||||
public string Face { get; set; }
|
public string Face { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Dlhis.Entity.Basic.Enums
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// api日志状态
|
|
||||||
/// </summary>
|
|
||||||
[Description("api日志状态")]
|
|
||||||
public enum ApiLogEnumType
|
|
||||||
{
|
|
||||||
Information = 1,
|
|
||||||
|
|
||||||
Warning = 2,
|
|
||||||
|
|
||||||
Error = 3,
|
|
||||||
|
|
||||||
Fatal = 4,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Kurisu.SqlSugar" Version="0.0.7" />
|
<PackageReference Include="Kurisu.SqlSugar" Version="0.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -34,18 +34,6 @@ public class DeviceUploadLogsController : ControllerBase
|
|||||||
return await _deviceUploadLogService.GetPageAsync(request);
|
return await _deviceUploadLogService.GetPageAsync(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 上传记录
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="request"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpPost("record")]
|
|
||||||
[IgnoreTenant]
|
|
||||||
public async Task UploadLogAsync(DeviceUploadLogUploadRequest request)
|
|
||||||
{
|
|
||||||
await _deviceUploadLogService.UploadLogAsync(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 批量上传记录
|
/// 批量上传记录
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -57,5 +45,4 @@ public class DeviceUploadLogsController : ControllerBase
|
|||||||
{
|
{
|
||||||
await _deviceUploadLogService.UploadLogsAsync(requests);
|
await _deviceUploadLogService.UploadLogsAsync(requests);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||||
|
|
||||||
public class DeviceUploadLogResponse
|
public class DeviceUploadLogResponse
|
||||||
{
|
{
|
||||||
@@ -29,4 +31,7 @@ public class DeviceUploadLogResponse
|
|||||||
/// 上传时间
|
/// 上传时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime RaiseDateTime { get; set; }
|
public DateTime RaiseDateTime { get; set; }
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
public string OriginUserUniqueNo { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
@@ -9,8 +8,6 @@ public interface IDeviceUploadLogService : IScopeDependency
|
|||||||
{
|
{
|
||||||
Task<Pagination<DeviceUploadLogResponse>> GetPageAsync(DeviceUploadLogPageRequest request);
|
Task<Pagination<DeviceUploadLogResponse>> GetPageAsync(DeviceUploadLogPageRequest request);
|
||||||
|
|
||||||
Task UploadLogAsync(DeviceUploadLogUploadRequest request);
|
|
||||||
|
|
||||||
Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests);
|
Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
using System.Configuration;
|
using System.Linq.Expressions;
|
||||||
using System.Linq.Expressions;
|
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||||
using Kurisu.AspNetCore.Scope;
|
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Attributes;
|
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using NetTaste;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
|
namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
|
||||||
@@ -29,40 +23,34 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
public async Task<Pagination<DeviceUploadLogResponse>> GetPageAsync(DeviceUploadLogPageRequest request)
|
public async Task<Pagination<DeviceUploadLogResponse>> GetPageAsync(DeviceUploadLogPageRequest request)
|
||||||
{
|
{
|
||||||
var page = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
var page = await _dbContext.Queryable<DeviceUploadLogEntity>()
|
||||||
.LeftJoin<GainfoEntity>((deviceUp, ga) => deviceUp.UserUniqueNo == ga.No)
|
|
||||||
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, deviceUp => deviceUp.RaiseDateTime >= request.SearchDateTimePeriod.Start)
|
.WhereIF(request.SearchDateTimePeriod?.Start.HasValue == true, deviceUp => deviceUp.RaiseDateTime >= request.SearchDateTimePeriod.Start)
|
||||||
.WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, deviceUp => deviceUp.RaiseDateTime <= request.SearchDateTimePeriod.End)
|
.WhereIF(request.SearchDateTimePeriod?.End.HasValue == true, deviceUp => deviceUp.RaiseDateTime <= request.SearchDateTimePeriod.End)
|
||||||
.Select((deviceUp, ga) => new DeviceUploadLogResponse
|
.Select((deviceUp) => new DeviceUploadLogResponse
|
||||||
{
|
{
|
||||||
|
OriginUserUniqueNo = deviceUp.UserUniqueNo,
|
||||||
DeviceUniqueNo = deviceUp.DeviceUniqueNo,
|
DeviceUniqueNo = deviceUp.DeviceUniqueNo,
|
||||||
Id = deviceUp.Id,
|
Id = deviceUp.Id,
|
||||||
RaiseDateTime = deviceUp.RaiseDateTime,
|
RaiseDateTime = deviceUp.RaiseDateTime,
|
||||||
UserNo = ga.No,
|
//UserNo = ga.No,
|
||||||
UserCode = ga.Code,
|
//UserCode = ga.Code,
|
||||||
UserName = ga.Name,
|
//UserName = ga.Name,
|
||||||
})
|
})
|
||||||
.ToPageListAsync(request);
|
.ToPageListAsync(request);
|
||||||
|
|
||||||
|
var gainfos = await _dbContext.Queryable<GainfoEntity>().ToListAsync();
|
||||||
|
page.Data.ForEach(item =>
|
||||||
|
{
|
||||||
|
_ = int.TryParse(item.OriginUserUniqueNo, out var userId);
|
||||||
|
|
||||||
|
var gainfo = gainfos.FirstOrDefault(x => x.No == item.OriginUserUniqueNo || x.Id == userId || x.Code == item.OriginUserUniqueNo);
|
||||||
|
item.UserNo = gainfo?.No;
|
||||||
|
item.UserCode = gainfo?.Code;
|
||||||
|
item.UserName = gainfo?.Name;
|
||||||
|
});
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UploadLogAsync(DeviceUploadLogUploadRequest request)
|
|
||||||
{
|
|
||||||
var device = await _dbContext.Queryable<DeviceEntity>().Where(x => x.UniqueNo == request.DeviceUniqueNo).SingleAsync();
|
|
||||||
device.ThrowIfNull("设备信息不存在");
|
|
||||||
|
|
||||||
var entity = new DeviceUploadLogEntity
|
|
||||||
{
|
|
||||||
DeviceUniqueNo = request.DeviceUniqueNo,
|
|
||||||
// UploadTime = request.UploadTime,
|
|
||||||
UserUniqueNo = request.UserUniqueNo,
|
|
||||||
TenantId = device.TenantId,
|
|
||||||
};
|
|
||||||
|
|
||||||
await _dbContext.InsertAsync(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests)
|
public async Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests)
|
||||||
{
|
{
|
||||||
//判断存在的记录
|
//判断存在的记录
|
||||||
@@ -105,5 +93,5 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
|
|
||||||
await _dbContext.InsertAsync(records);
|
await _dbContext.InsertAsync(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user