日志
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
zpc 2026-04-22 15:27:46 +08:00
parent 4357530d59
commit 1e5043a978
3 changed files with 78 additions and 6 deletions

View File

@ -70,11 +70,13 @@ namespace ZR.Admin.WebApi.Controllers.Business
try
{
var newRecord = _OdfCableFaultsService.GetFirst(f => f.Id == response);
var cableName = _OdfCableFaultsService.GetCableNameByFaultId(response);
string newData = BuildAuditJson(new Dictionary<string, object>
{
["Id"] = newRecord.Id,
["关联光缆ID"] = newRecord.CableId,
["故障时间"] = newRecord.FaultTime,
["所属光缆"] = cableName,
["故障时间"] = newRecord.FaultTime.ToString("yyyy-MM-dd HH:mm:ss"),
["人员"] = newRecord.Personnel,
["故障原因"] = newRecord.FaultReason,
["表显故障里程"] = newRecord.Mileage,
@ -106,13 +108,17 @@ namespace ZR.Admin.WebApi.Controllers.Business
[Log(Title = "干线故障", BusinessType = BusinessType.UPDATE)]
public IActionResult IncrementFaultCount(int id)
{
// 记录旧数据
// 记录旧数据(含故障时间列表和所属光缆名称)
var oldFault = _OdfCableFaultsService.GetFirst(f => f.Id == id);
var oldFaultTimes = _OdfCableFaultsService.GetFaultTimesByFaultIds(new List<int> { id });
var oldTimesStr = BuildFaultTimesDisplay(oldFault.FaultTime, oldFaultTimes.ContainsKey(id) ? oldFaultTimes[id] : new List<DateTime>());
var cableName = _OdfCableFaultsService.GetCableNameByFaultId(id);
string oldData = BuildAuditJson(new Dictionary<string, object>
{
["Id"] = oldFault.Id,
["关联光缆ID"] = oldFault.CableId,
["故障时间"] = oldFault.FaultTime,
["所属光缆"] = cableName,
["故障时间"] = oldTimesStr,
["人员"] = oldFault.Personnel,
["故障原因"] = oldFault.FaultReason,
["表显故障里程"] = oldFault.Mileage,
@ -130,13 +136,16 @@ namespace ZR.Admin.WebApi.Controllers.Business
// 执行更新
var response = _OdfCableFaultsService.IncrementFaultCount(id);
// 记录新数据
// 记录新数据(含更新后的故障时间列表)
var newFault = _OdfCableFaultsService.GetFirst(f => f.Id == id);
var newFaultTimes = _OdfCableFaultsService.GetFaultTimesByFaultIds(new List<int> { id });
var newTimesStr = BuildFaultTimesDisplay(newFault.FaultTime, newFaultTimes.ContainsKey(id) ? newFaultTimes[id] : new List<DateTime>());
string newData = BuildAuditJson(new Dictionary<string, object>
{
["Id"] = newFault.Id,
["关联光缆ID"] = newFault.CableId,
["故障时间"] = newFault.FaultTime,
["所属光缆"] = cableName,
["故障时间"] = newTimesStr,
["人员"] = newFault.Personnel,
["故障原因"] = newFault.FaultReason,
["表显故障里程"] = newFault.Mileage,
@ -174,10 +183,27 @@ namespace ZR.Admin.WebApi.Controllers.Business
{
// 查旧数据
var oldRecord = _OdfCableFaultsService.GetFirst(f => f.Id == id);
var oldFaultTimes = _OdfCableFaultsService.GetFaultTimesByFaultIds(new List<int> { id });
var oldTimesStr = BuildFaultTimesDisplay(oldRecord.FaultTime, oldFaultTimes.ContainsKey(id) ? oldFaultTimes[id] : new List<DateTime>());
var cableName = _OdfCableFaultsService.GetCableNameByFaultId(id);
string oldData = BuildAuditJson(new Dictionary<string, object>
{
["Id"] = oldRecord.Id,
["关联光缆ID"] = oldRecord.CableId,
["所属光缆"] = cableName,
["故障时间"] = oldTimesStr,
["人员"] = oldRecord.Personnel,
["故障原因"] = oldRecord.FaultReason,
["表显故障里程"] = oldRecord.Mileage,
["表显里程矫正"] = oldRecord.MileageCorrection,
["地点描述"] = oldRecord.Location,
["纬度"] = oldRecord.Latitude,
["经度"] = oldRecord.Longitude,
["备注"] = oldRecord.Remark,
["提交人用户ID"] = oldRecord.UserId,
["创建时间"] = oldRecord.CreatedAt,
["更新时间"] = oldRecord.UpdatedAt,
["故障发生频次"] = oldRecord.FaultCount,
});
// 执行更新
@ -185,10 +211,26 @@ namespace ZR.Admin.WebApi.Controllers.Business
// 查新数据
var newRecord = _OdfCableFaultsService.GetFirst(f => f.Id == id);
var newFaultTimes = _OdfCableFaultsService.GetFaultTimesByFaultIds(new List<int> { id });
var newTimesStr = BuildFaultTimesDisplay(newRecord.FaultTime, newFaultTimes.ContainsKey(id) ? newFaultTimes[id] : new List<DateTime>());
string newData = BuildAuditJson(new Dictionary<string, object>
{
["Id"] = newRecord.Id,
["关联光缆ID"] = newRecord.CableId,
["所属光缆"] = cableName,
["故障时间"] = newTimesStr,
["人员"] = newRecord.Personnel,
["故障原因"] = newRecord.FaultReason,
["表显故障里程"] = newRecord.Mileage,
["表显里程矫正"] = newRecord.MileageCorrection,
["地点描述"] = newRecord.Location,
["纬度"] = newRecord.Latitude,
["经度"] = newRecord.Longitude,
["备注"] = newRecord.Remark,
["提交人用户ID"] = newRecord.UserId,
["创建时间"] = newRecord.CreatedAt,
["更新时间"] = newRecord.UpdatedAt,
["故障发生频次"] = newRecord.FaultCount,
});
// 写入审计日志
@ -227,11 +269,15 @@ namespace ZR.Admin.WebApi.Controllers.Business
foreach (var id in idList)
{
var oldRecord = _OdfCableFaultsService.GetFirst(f => f.Id == id);
var delFaultTimes = _OdfCableFaultsService.GetFaultTimesByFaultIds(new List<int> { id });
var delTimesStr = BuildFaultTimesDisplay(oldRecord.FaultTime, delFaultTimes.ContainsKey(id) ? delFaultTimes[id] : new List<DateTime>());
var delCableName = _OdfCableFaultsService.GetCableNameByFaultId(id);
string oldData = BuildAuditJson(new Dictionary<string, object>
{
["Id"] = oldRecord.Id,
["关联光缆ID"] = oldRecord.CableId,
["故障时间"] = oldRecord.FaultTime,
["所属光缆"] = delCableName,
["故障时间"] = delTimesStr,
["人员"] = oldRecord.Personnel,
["故障原因"] = oldRecord.FaultReason,
["表显故障里程"] = oldRecord.Mileage,
@ -431,5 +477,15 @@ namespace ZR.Admin.WebApi.Controllers.Business
}
return mileage ?? "";
}
/// <summary>
/// 构建故障时间显示字符串(首次故障时间 + 频次时间列表)
/// </summary>
private static string BuildFaultTimesDisplay(DateTime faultTime, List<DateTime> faultTimes)
{
var times = new List<string> { faultTime.ToString("yyyy-MM-dd HH:mm:ss") };
times.AddRange(faultTimes.Select(t => t.ToString("yyyy-MM-dd HH:mm:ss")));
return string.Join(", ", times);
}
}
}

View File

@ -53,5 +53,10 @@ namespace ZR.Service.Business.IBusinessService
/// 更新表显里程矫正
/// </summary>
int UpdateMileageCorrection(int id, string mileageCorrection);
/// <summary>
/// 根据故障ID获取所属光缆名称
/// </summary>
string GetCableNameByFaultId(int faultId);
}
}

View File

@ -481,5 +481,16 @@ namespace ZR.Service.Business
fault.UpdatedAt = DateTime.Now;
return Update(fault, true);
}
/// <summary>
/// 根据故障ID获取所属光缆名称
/// </summary>
public string GetCableNameByFaultId(int faultId)
{
var fault = GetFirst(f => f.Id == faultId);
if (fault == null) return "";
var cable = Context.Queryable<OdfCables>().Where(c => c.Id == fault.CableId).First();
return cable?.CableName ?? "";
}
}
}