|
|
@@ -23,6 +23,7 @@ public class S8ManualReportService : ITransient
|
|
|
private readonly SqlSugarRepository<AdoS8SceneConfig> _sceneRep;
|
|
|
private readonly SqlSugarRepository<AdoS0DepartmentMaster> _deptRep;
|
|
|
private readonly SqlSugarRepository<AdoS0LineMaster> _lineRep;
|
|
|
+ private readonly SqlSugarRepository<AdoS8ExceptionType> _typeRep;
|
|
|
private readonly UserManager _userManager;
|
|
|
private readonly FlowEngineService _flowEngine;
|
|
|
private readonly ILogger<S8ManualReportService> _logger;
|
|
|
@@ -34,6 +35,7 @@ public class S8ManualReportService : ITransient
|
|
|
SqlSugarRepository<AdoS8SceneConfig> sceneRep,
|
|
|
SqlSugarRepository<AdoS0DepartmentMaster> deptRep,
|
|
|
SqlSugarRepository<AdoS0LineMaster> lineRep,
|
|
|
+ SqlSugarRepository<AdoS8ExceptionType> typeRep,
|
|
|
UserManager userManager,
|
|
|
FlowEngineService flowEngine,
|
|
|
ILogger<S8ManualReportService> logger)
|
|
|
@@ -44,11 +46,30 @@ public class S8ManualReportService : ITransient
|
|
|
_sceneRep = sceneRep;
|
|
|
_deptRep = deptRep;
|
|
|
_lineRep = lineRep;
|
|
|
+ _typeRep = typeRep;
|
|
|
_userManager = userManager;
|
|
|
_flowEngine = flowEngine;
|
|
|
_logger = logger;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 主动提报推断 ExceptionTypeCode:场景下取启用且 SortNo 最小的一条。
|
|
|
+ /// baseline 异常类型当前 tenant_id=0/factory_id=0(全局基线),所以匹配条件为
|
|
|
+ /// (tenantId 命中 OR 0) AND (factoryId 命中 OR 0)。ClearFilter 兜底全局多租户过滤器。
|
|
|
+ /// 找不到返回 null(保持兼容)。
|
|
|
+ /// </summary>
|
|
|
+ private async Task<string?> InferExceptionTypeCodeAsync(long tenantId, long factoryId, string sceneCode)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(sceneCode)) return null;
|
|
|
+ return await _typeRep.AsQueryable().ClearFilter()
|
|
|
+ .Where(x => (x.TenantId == tenantId || x.TenantId == 0)
|
|
|
+ && (x.FactoryId == factoryId || x.FactoryId == 0)
|
|
|
+ && x.SceneCode == sceneCode && x.Enabled)
|
|
|
+ .OrderBy(x => x.SortNo)
|
|
|
+ .Select(x => x.TypeCode)
|
|
|
+ .FirstAsync();
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// TB001 异常提报审批流:自动监控 + 主动提报后软触发,失败仅 warn 日志,不阻断建单。
|
|
|
/// </summary>
|
|
|
@@ -127,6 +148,9 @@ public class S8ManualReportService : ITransient
|
|
|
// 提报人以服务端登录上下文为准,忽略前端传入;未登录上下文落 null。
|
|
|
var currentUserId = _userManager.UserId > 0 ? _userManager.UserId : (long?)null;
|
|
|
|
|
|
+ // 主动提报无前端 type 字段,按场景兜底推断;保证不进"未分类"桶。
|
|
|
+ var inferredType = await InferExceptionTypeCodeAsync(dto.TenantId, dto.FactoryId, dto.SceneCode.Trim());
|
|
|
+
|
|
|
var code = $"EX-{DateTime.Now:yyyyMMdd}-{Guid.NewGuid().ToString("N")[..8].ToUpperInvariant()}";
|
|
|
var entity = new AdoS8Exception
|
|
|
{
|
|
|
@@ -144,6 +168,7 @@ public class S8ManualReportService : ITransient
|
|
|
OccurrenceDeptId = dto.OccurrenceDeptId,
|
|
|
ResponsibleDeptId = dto.ResponsibleDeptId,
|
|
|
ReporterId = currentUserId,
|
|
|
+ ExceptionTypeCode = inferredType,
|
|
|
CreatedAt = DateTime.Now,
|
|
|
IsDeleted = false
|
|
|
};
|