|
|
@@ -8,12 +8,19 @@ namespace Admin.NET.Plugin.AiDOP.Service.S8;
|
|
|
|
|
|
public class S8ManualReportService : ITransient
|
|
|
{
|
|
|
+ // 合法严重度白名单(与 GetFormOptionsAsync.severities 同源);前端/后端默认值 MEDIUM。
|
|
|
+ private static readonly HashSet<string> AllowedSeverities = new(StringComparer.Ordinal)
|
|
|
+ {
|
|
|
+ "CRITICAL", "HIGH", "MEDIUM", "LOW"
|
|
|
+ };
|
|
|
+
|
|
|
private readonly SqlSugarRepository<AdoS8Exception> _rep;
|
|
|
private readonly SqlSugarRepository<AdoS8ExceptionTimeline> _timelineRep;
|
|
|
private readonly SqlSugarRepository<AdoS8Evidence> _evidenceRep;
|
|
|
private readonly SqlSugarRepository<AdoS8SceneConfig> _sceneRep;
|
|
|
private readonly SqlSugarRepository<AdoS0DepartmentMaster> _deptRep;
|
|
|
private readonly SqlSugarRepository<AdoS0LineMaster> _lineRep;
|
|
|
+ private readonly UserManager _userManager;
|
|
|
|
|
|
public S8ManualReportService(
|
|
|
SqlSugarRepository<AdoS8Exception> rep,
|
|
|
@@ -21,7 +28,8 @@ public class S8ManualReportService : ITransient
|
|
|
SqlSugarRepository<AdoS8Evidence> evidenceRep,
|
|
|
SqlSugarRepository<AdoS8SceneConfig> sceneRep,
|
|
|
SqlSugarRepository<AdoS0DepartmentMaster> deptRep,
|
|
|
- SqlSugarRepository<AdoS0LineMaster> lineRep)
|
|
|
+ SqlSugarRepository<AdoS0LineMaster> lineRep,
|
|
|
+ UserManager userManager)
|
|
|
{
|
|
|
_rep = rep;
|
|
|
_timelineRep = timelineRep;
|
|
|
@@ -29,6 +37,7 @@ public class S8ManualReportService : ITransient
|
|
|
_sceneRep = sceneRep;
|
|
|
_deptRep = deptRep;
|
|
|
_lineRep = lineRep;
|
|
|
+ _userManager = userManager;
|
|
|
}
|
|
|
|
|
|
public async Task<object> GetFormOptionsAsync(long tenantId, long factoryId)
|
|
|
@@ -72,6 +81,14 @@ public class S8ManualReportService : ITransient
|
|
|
if (string.IsNullOrWhiteSpace(dto.Title)) throw new S8BizException("标题必填");
|
|
|
if (string.IsNullOrWhiteSpace(dto.SceneCode)) throw new S8BizException("场景必填");
|
|
|
|
|
|
+ // 严重度白名单校验:空值兜底为 MEDIUM;非法值直接拒绝,避免 P3 等错位写入。
|
|
|
+ var severity = string.IsNullOrWhiteSpace(dto.Severity) ? "MEDIUM" : dto.Severity.Trim();
|
|
|
+ if (!AllowedSeverities.Contains(severity))
|
|
|
+ throw new S8BizException($"严重度 {severity} 非法,仅允许 CRITICAL/HIGH/MEDIUM/LOW");
|
|
|
+
|
|
|
+ // 提报人以服务端登录上下文为准,忽略前端传入;未登录上下文落 null。
|
|
|
+ var currentUserId = _userManager.UserId > 0 ? _userManager.UserId : (long?)null;
|
|
|
+
|
|
|
var code = $"EX-{DateTime.Now:yyyyMMdd}-{Guid.NewGuid().ToString("N")[..8].ToUpperInvariant()}";
|
|
|
var entity = new AdoS8Exception
|
|
|
{
|
|
|
@@ -83,12 +100,12 @@ public class S8ManualReportService : ITransient
|
|
|
SceneCode = dto.SceneCode.Trim(),
|
|
|
SourceType = "MANUAL",
|
|
|
Status = "NEW",
|
|
|
- Severity = string.IsNullOrWhiteSpace(dto.Severity) ? "MEDIUM" : dto.Severity,
|
|
|
+ Severity = severity,
|
|
|
PriorityScore = 0,
|
|
|
PriorityLevel = "P3",
|
|
|
OccurrenceDeptId = dto.OccurrenceDeptId,
|
|
|
ResponsibleDeptId = dto.ResponsibleDeptId,
|
|
|
- ReporterId = dto.ReporterId,
|
|
|
+ ReporterId = currentUserId,
|
|
|
CreatedAt = DateTime.Now,
|
|
|
IsDeleted = false
|
|
|
};
|
|
|
@@ -103,7 +120,7 @@ public class S8ManualReportService : ITransient
|
|
|
ActionLabel = "创建",
|
|
|
FromStatus = null,
|
|
|
ToStatus = "NEW",
|
|
|
- OperatorId = dto.ReporterId,
|
|
|
+ OperatorId = currentUserId,
|
|
|
ActionRemark = "主动提报",
|
|
|
CreatedAt = DateTime.Now
|
|
|
});
|