|
|
|
using DS.Module.Core;
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
using DS.Module.Core.Log;
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
using DS.WMS.Core.Sys.Dtos;
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
using DS.WMS.Core.Sys.Interface;
|
|
|
|
using Google.Cloud.Storage.V1;
|
|
|
|
using Mapster;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Sys.Method;
|
|
|
|
|
|
|
|
public class LogAuditService : ILogAuditService
|
|
|
|
{
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
private readonly IUser user;
|
|
|
|
private readonly ISaasDbService saasService;
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
public LogAuditService(IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataResult<List<AuditLogRes>> GetAuditLogList(PageRequest request)
|
|
|
|
{
|
|
|
|
//序列化查询条件
|
|
|
|
var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition);
|
|
|
|
var data = saasService.GetLogDb().Queryable<SysLogAudit>().Filter(null,true)
|
|
|
|
.Where(whereList)
|
|
|
|
.Select<AuditLogRes>().ToQueryPage(request.PageCondition);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DataResult<AuditLogRes> GetAuditLogInfo(string id)
|
|
|
|
{
|
|
|
|
var data = saasService.GetLogDb().Queryable<SysLogAudit>().Filter(null,true)
|
|
|
|
.Where(a => a.Id == long.Parse(id))
|
|
|
|
.Select<AuditLogRes>()
|
|
|
|
.First();
|
|
|
|
return DataResult<AuditLogRes>.Success(data,MultiLanguageConst.DataQuerySuccess);
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 获取订舱类操作日志列表
|
|
|
|
/// <summary>
|
|
|
|
/// 获取订舱类操作日志列表
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">业务ID</param>
|
|
|
|
/// <returns>返回操作日志列表</returns>
|
|
|
|
public async Task<DataResult<List<AuditLogBookingDto>>> GetAuditLogBookingList(long id)
|
|
|
|
{
|
|
|
|
List<AuditLogBookingDto> list = new List<AuditLogBookingDto>();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var logList = await saasService.GetLogDb().Queryable<SysLogAudit>().Filter(null, true)
|
|
|
|
.Where(a => a.Id == id).ToListAsync();
|
|
|
|
|
|
|
|
if (logList.Count > 0)
|
|
|
|
{
|
|
|
|
list = logList.Select(a =>
|
|
|
|
{
|
|
|
|
var model = new AuditLogBookingDto
|
|
|
|
{
|
|
|
|
Type = a.OperateType,
|
|
|
|
BookingId = a.KeyId,
|
|
|
|
CreatedTime = a.CreateTime,
|
|
|
|
CreatedUserId = a.CreateBy,
|
|
|
|
FromFunc = "",
|
|
|
|
Id = a.Id,
|
|
|
|
TenantId = a.TenantId,
|
|
|
|
details = new List<AuditLogBookingDetailDto>()
|
|
|
|
};
|
|
|
|
|
|
|
|
DiffLogTableInfo oldObj = null;
|
|
|
|
DiffLogTableInfo newObj = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
oldObj = JsonConvert.DeserializeObject<DiffLogTableInfo>(a.OldValue);
|
|
|
|
}
|
|
|
|
catch (Exception e1)
|
|
|
|
{
|
|
|
|
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.BookingSlotAuditLogDeserializeError)), e1.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
newObj = JsonConvert.DeserializeObject<DiffLogTableInfo>(a.NewValue);
|
|
|
|
}
|
|
|
|
catch (Exception e2)
|
|
|
|
{
|
|
|
|
throw new Exception(string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.BookingSlotAuditLogDeserializeError)), e2.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldObj != null && newObj != null)
|
|
|
|
{
|
|
|
|
model.details = oldObj.Columns.Join(newObj.Columns, l => l.ColumnName, r => r.ColumnName, (l, r) =>
|
|
|
|
{
|
|
|
|
string left = l.Value != null ? l.Value.ToString() : "";
|
|
|
|
string right = r.Value != null ? r.Value.ToString() : "";
|
|
|
|
|
|
|
|
if (!left.Equals(right))
|
|
|
|
{
|
|
|
|
return new
|
|
|
|
{
|
|
|
|
IsDiff = true,
|
|
|
|
Obj = new AuditLogBookingDetailDto
|
|
|
|
{
|
|
|
|
Field = !string.IsNullOrWhiteSpace(l.ColumnDescription) ? l.ColumnDescription : l.ColumnName,
|
|
|
|
OldValue = left,
|
|
|
|
NewValue = right,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new
|
|
|
|
{
|
|
|
|
IsDiff = false,
|
|
|
|
Obj = new AuditLogBookingDetailDto
|
|
|
|
{
|
|
|
|
Field = !string.IsNullOrWhiteSpace(l.ColumnDescription) ? l.ColumnDescription : l.ColumnName,
|
|
|
|
OldValue = left,
|
|
|
|
NewValue = right,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}).Where(a => a.IsDiff).Select(a => a.Obj).ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}).OrderByDescending(a => a.CreatedTime).ToList();
|
|
|
|
|
|
|
|
return DataResult<List<AuditLogBookingDto>>.Success(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
//查询日志异常
|
|
|
|
return DataResult<List<AuditLogBookingDto>>.FailedData(list, string.Format(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.BookingSlotAuditLogError)),e.Message));
|
|
|
|
}
|
|
|
|
|
|
|
|
return DataResult<List<AuditLogBookingDto>>.FailedData(list);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|