S8ManualReportService.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. using Admin.NET.Plugin.AiDOP.Dto.S8;
  2. using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
  3. using Admin.NET.Plugin.AiDOP.Entity.S0.Warehouse;
  4. using Admin.NET.Plugin.AiDOP.Entity.S8;
  5. using Admin.NET.Plugin.AiDOP.Infrastructure.S8;
  6. using Admin.NET.Plugin.AiDOP.Service.S8.Rules;
  7. using Admin.NET.Plugin.ApprovalFlow.Service;
  8. using Microsoft.Extensions.Logging;
  9. namespace Admin.NET.Plugin.AiDOP.Service.S8;
  10. public class S8ManualReportService : ITransient
  11. {
  12. // 合法严重度白名单(与 GetFormOptionsAsync.severities 同源);前端/后端默认值 MEDIUM。
  13. private static readonly HashSet<string> AllowedSeverities = new(StringComparer.Ordinal)
  14. {
  15. "CRITICAL", "HIGH", "MEDIUM", "LOW"
  16. };
  17. // S8-PROCESS-NODE-S1S7-ALIGN-1:process_node_code 当前阶段对齐 S1-S7 订单主流程。
  18. // 优先 module_code(已是 S1-S7),其次按 scene_code 反推;都无法识别则 null。
  19. private static string? ResolveProcessNodeCode(string? sceneCode, string? moduleCode)
  20. {
  21. if (!string.IsNullOrWhiteSpace(moduleCode) && S8ModuleCode.All.Contains(moduleCode))
  22. return moduleCode;
  23. var fromScene = S8ModuleCode.FromScene(sceneCode);
  24. if (!string.IsNullOrWhiteSpace(fromScene) && S8ModuleCode.All.Contains(fromScene))
  25. return fromScene;
  26. return null;
  27. }
  28. /// <summary>
  29. /// S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1:建单 module_code 派生统一入口。
  30. /// 优先级:显式 module → hit module → 单模块 sceneCode(S1-S7)→ exception_type.scene_code。
  31. /// 严格 S1-S7 校验,不接受 legacy 复合 scene;最终无法确定时返回 null(caller 决定记日志或拒绝)。
  32. /// </summary>
  33. private async Task<string?> ResolveModuleCodeAsync(
  34. string? explicitModuleCode,
  35. string? hitModuleCode,
  36. string? sceneCode,
  37. string? exceptionTypeCode)
  38. {
  39. var byExplicit = S8ModuleCode.Normalize(explicitModuleCode);
  40. if (byExplicit != null) return byExplicit;
  41. var byHit = S8ModuleCode.Normalize(hitModuleCode);
  42. if (byHit != null) return byHit;
  43. var byScene = S8ModuleCode.FromCanonicalScene(sceneCode);
  44. if (byScene != null) return byScene;
  45. if (!string.IsNullOrWhiteSpace(exceptionTypeCode))
  46. {
  47. var typeScene = await _typeRep.AsQueryable().ClearFilter()
  48. .Where(t => t.TypeCode == exceptionTypeCode && t.Enabled)
  49. .OrderByDescending(t => t.FactoryId)
  50. .Select(t => t.SceneCode)
  51. .FirstAsync();
  52. var byType = S8ModuleCode.FromCanonicalScene(typeScene);
  53. if (byType != null) return byType;
  54. }
  55. return null;
  56. }
  57. private readonly SqlSugarRepository<AdoS8Exception> _rep;
  58. private readonly SqlSugarRepository<AdoS8ExceptionTimeline> _timelineRep;
  59. private readonly SqlSugarRepository<AdoS8Evidence> _evidenceRep;
  60. private readonly SqlSugarRepository<AdoS8SceneConfig> _sceneRep;
  61. private readonly SqlSugarRepository<AdoS0DepartmentMaster> _deptRep;
  62. private readonly SqlSugarRepository<AdoS0LineMaster> _lineRep;
  63. private readonly SqlSugarRepository<AdoS8ExceptionType> _typeRep;
  64. private readonly UserManager _userManager;
  65. private readonly FlowEngineService _flowEngine;
  66. private readonly ILogger<S8ManualReportService> _logger;
  67. public S8ManualReportService(
  68. SqlSugarRepository<AdoS8Exception> rep,
  69. SqlSugarRepository<AdoS8ExceptionTimeline> timelineRep,
  70. SqlSugarRepository<AdoS8Evidence> evidenceRep,
  71. SqlSugarRepository<AdoS8SceneConfig> sceneRep,
  72. SqlSugarRepository<AdoS0DepartmentMaster> deptRep,
  73. SqlSugarRepository<AdoS0LineMaster> lineRep,
  74. SqlSugarRepository<AdoS8ExceptionType> typeRep,
  75. UserManager userManager,
  76. FlowEngineService flowEngine,
  77. ILogger<S8ManualReportService> logger)
  78. {
  79. _rep = rep;
  80. _timelineRep = timelineRep;
  81. _evidenceRep = evidenceRep;
  82. _sceneRep = sceneRep;
  83. _deptRep = deptRep;
  84. _lineRep = lineRep;
  85. _typeRep = typeRep;
  86. _userManager = userManager;
  87. _flowEngine = flowEngine;
  88. _logger = logger;
  89. }
  90. /// <summary>
  91. /// 主动提报推断 ExceptionTypeCode:场景下取启用且 SortNo 最小的一条。
  92. /// baseline 异常类型当前 tenant_id=0/factory_id=0(全局基线),所以匹配条件为
  93. /// (tenantId 命中 OR 0) AND (factoryId 命中 OR 0)。ClearFilter 兜底全局多租户过滤器。
  94. /// 找不到返回 null(保持兼容)。
  95. /// </summary>
  96. private async Task<string?> InferExceptionTypeCodeAsync(long tenantId, long factoryId, string sceneCode)
  97. {
  98. if (string.IsNullOrWhiteSpace(sceneCode)) return null;
  99. return await _typeRep.AsQueryable().ClearFilter()
  100. .Where(x => (x.TenantId == tenantId || x.TenantId == 0)
  101. && (x.FactoryId == factoryId || x.FactoryId == 0)
  102. && x.SceneCode == sceneCode && x.Enabled)
  103. .OrderBy(x => x.SortNo)
  104. .Select(x => x.TypeCode)
  105. .FirstAsync();
  106. }
  107. /// <summary>
  108. /// TB001 异常提报审批流:自动监控 + 主动提报后软触发,失败仅 warn 日志,不阻断建单。
  109. /// </summary>
  110. private async Task TryStartIntakeFlowAsync(AdoS8Exception entity)
  111. {
  112. try
  113. {
  114. await _flowEngine.StartFlow(new StartFlowInput
  115. {
  116. BizType = "EXCEPTION_REPORT",
  117. BizId = entity.Id,
  118. BizNo = entity.ExceptionCode,
  119. Title = $"异常提报 - {entity.ExceptionCode}",
  120. Comment = entity.SourceType == "AUTO_WATCH" ? "自动监控触发" : "主动提报触发",
  121. BizData = new Dictionary<string, object>
  122. {
  123. ["sceneCode"] = entity.SceneCode ?? "",
  124. ["exceptionTypeCode"] = entity.ExceptionTypeCode ?? "",
  125. ["sourceType"] = entity.SourceType ?? ""
  126. }
  127. });
  128. }
  129. catch (Exception ex)
  130. {
  131. _logger.LogWarning(ex, "TB001 异常提报审批流触发失败 ExceptionId={Id} ExceptionCode={Code}", entity.Id, entity.ExceptionCode);
  132. }
  133. }
  134. public async Task<object> GetFormOptionsAsync(long tenantId, long factoryId)
  135. {
  136. var scenes = await _sceneRep.AsQueryable()
  137. .Where(x => x.TenantId == tenantId && x.FactoryId == factoryId && x.Enabled)
  138. .OrderBy(x => x.SortNo)
  139. .Select(x => new { value = x.SceneCode, label = x.SceneName })
  140. .ToListAsync();
  141. // ClearFilter:DepartmentMaster.tenant_id 属 S0 域租户,不与登录 token TenantId 一致;
  142. // 用 factory_ref_id 做硬边界,安全等价。同 BUG-S8-EMPLOYEES-TENANT-FILTER 协议。
  143. var departments = await _deptRep.AsQueryable().ClearFilter()
  144. .Where(x => x.FactoryRefId == factoryId)
  145. .OrderBy(x => x.Department)
  146. .Take(500)
  147. .Select(x => new { value = x.Id, label = x.Descr ?? x.Department })
  148. .ToListAsync();
  149. var lines = await _lineRep.AsQueryable().ClearFilter()
  150. .Where(x => x.FactoryRefId == factoryId)
  151. .OrderBy(x => x.Line)
  152. .Take(500)
  153. .Select(x => new { value = x.Id, label = x.Describe ?? x.Line })
  154. .ToListAsync();
  155. return new
  156. {
  157. scenes,
  158. severities = new[]
  159. {
  160. new { value = "CRITICAL", label = "紧急" },
  161. new { value = "HIGH", label = "高" },
  162. new { value = "MEDIUM", label = "中" },
  163. new { value = "LOW", label = "低" }
  164. },
  165. departments,
  166. lines,
  167. materials = Array.Empty<object>()
  168. };
  169. }
  170. public async Task<AdoS8ManualReportResultDto> CreateAsync(AdoS8ManualReportCreateDto dto)
  171. {
  172. if (string.IsNullOrWhiteSpace(dto.Title)) throw new S8BizException("标题必填");
  173. if (string.IsNullOrWhiteSpace(dto.SceneCode)) throw new S8BizException("场景必填");
  174. // 严重度白名单校验:空值兜底为 MEDIUM;非法值直接拒绝,避免 P3 等错位写入。
  175. var severity = string.IsNullOrWhiteSpace(dto.Severity) ? "MEDIUM" : dto.Severity.Trim();
  176. if (!AllowedSeverities.Contains(severity))
  177. throw new S8BizException($"严重度 {severity} 非法,仅允许 CRITICAL/HIGH/MEDIUM/LOW");
  178. // 提报人以服务端登录上下文为准,忽略前端传入;未登录上下文落 null。
  179. var currentUserId = _userManager.UserId > 0 ? _userManager.UserId : (long?)null;
  180. // 主动提报无前端 type 字段,按场景兜底推断;保证不进"未分类"桶。
  181. var inferredType = await InferExceptionTypeCodeAsync(dto.TenantId, dto.FactoryId, dto.SceneCode.Trim());
  182. // S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1:手工提报 module_code 严格按 S1-S7 派生;
  183. // dto 暂不携带显式 module_code,按 scene → exception_type.scene 链路降级。
  184. var resolvedModule = await ResolveModuleCodeAsync(
  185. explicitModuleCode: null,
  186. hitModuleCode: null,
  187. sceneCode: dto.SceneCode.Trim(),
  188. exceptionTypeCode: inferredType);
  189. if (resolvedModule == null)
  190. {
  191. _logger.LogWarning(
  192. "manual_report_module_code_unresolved sceneCode={SceneCode} exceptionTypeCode={TypeCode} title={Title}",
  193. dto.SceneCode, inferredType, dto.Title);
  194. }
  195. var code = $"EX-{DateTime.Now:yyyyMMdd}-{Guid.NewGuid().ToString("N")[..8].ToUpperInvariant()}";
  196. var entity = new AdoS8Exception
  197. {
  198. TenantId = dto.TenantId,
  199. FactoryId = dto.FactoryId,
  200. ExceptionCode = code,
  201. Title = dto.Title.Trim(),
  202. Description = dto.Description,
  203. SceneCode = dto.SceneCode.Trim(),
  204. SourceType = "MANUAL",
  205. Status = "NEW",
  206. Severity = severity,
  207. PriorityScore = 0,
  208. PriorityLevel = "P3",
  209. OccurrenceDeptId = dto.OccurrenceDeptId,
  210. ResponsibleDeptId = dto.ResponsibleDeptId,
  211. ReporterId = currentUserId,
  212. ExceptionTypeCode = inferredType,
  213. ModuleCode = resolvedModule,
  214. ProcessNodeCode = ResolveProcessNodeCode(dto.SceneCode.Trim(), resolvedModule),
  215. CreatedAt = DateTime.Now,
  216. IsDeleted = false
  217. };
  218. await _rep.AsTenant().UseTranAsync(async () =>
  219. {
  220. entity = await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  221. await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline
  222. {
  223. ExceptionId = entity.Id,
  224. ActionCode = "CREATE",
  225. ActionLabel = "创建",
  226. FromStatus = null,
  227. ToStatus = "NEW",
  228. OperatorId = currentUserId,
  229. ActionRemark = "主动提报",
  230. CreatedAt = DateTime.Now
  231. });
  232. }, ex => throw ex);
  233. await TryStartIntakeFlowAsync(entity);
  234. return new AdoS8ManualReportResultDto
  235. {
  236. ExceptionId = entity.Id,
  237. ExceptionCode = entity.ExceptionCode,
  238. TaskId = entity.Id
  239. };
  240. }
  241. /// <summary>
  242. /// G01-06:自动建单分支(非第二套创建主链)。
  243. /// 这是本服务内的自动监控建单路径,与 <see cref="CreateAsync"/> 并列,
  244. /// 复用同一仓储(_rep / _timelineRep)、同一事务边界、同一 ExceptionCode 生成规则、
  245. /// 同一时间线主链(ActionCode="CREATE"、ToStatus="NEW");仅差异点:
  246. /// - SourceType 标识为自动监控来源
  247. /// - 填入 SourceRuleId / SourceDataSourceId / SourcePayload / RelatedObjectCode 追溯
  248. /// - ExceptionTypeCode 固定 EQUIP_FAULT(G-01 首版唯一映射)
  249. /// - SceneCode 固定 S2(G-01 首版唯一场景,迁移后从 S2S6_PRODUCTION 切到单模块 S2)
  250. /// 不做补偿、重试、对账;失败由调用方接住。
  251. /// </summary>
  252. public async Task<AdoS8Exception> CreateFromWatchAsync(S8WatchHitResult hit)
  253. {
  254. if (hit.SourceRuleId <= 0 || string.IsNullOrWhiteSpace(hit.RelatedObjectCode))
  255. throw new S8BizException("自动建单缺失追溯键");
  256. var code = $"EX-{DateTime.Now:yyyyMMdd}-{Guid.NewGuid().ToString("N")[..8].ToUpperInvariant()}";
  257. var title = $"[自动] 设备 {hit.RelatedObjectCode} {hit.TriggerCondition} {hit.ThresholdValue}(当前 {hit.CurrentValue})";
  258. // S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1:固定 SceneCode=S2 + ExceptionTypeCode=EQUIP_FAULT,
  259. // 派生链路通过 ResolveModuleCodeAsync 严格按 S1-S7 走(结果稳定为 S2,但消除 FromScene 的 legacy 兼容路径)。
  260. var resolvedModule = await ResolveModuleCodeAsync(
  261. explicitModuleCode: null,
  262. hitModuleCode: null,
  263. sceneCode: S8SceneCode.S2,
  264. exceptionTypeCode: "EQUIP_FAULT");
  265. if (resolvedModule == null)
  266. {
  267. _logger.LogWarning(
  268. "auto_watch_module_code_unresolved sceneCode={SceneCode} exceptionTypeCode={TypeCode} ruleId={RuleId}",
  269. S8SceneCode.S2, "EQUIP_FAULT", hit.SourceRuleId);
  270. }
  271. var entity = new AdoS8Exception
  272. {
  273. // 租户/工厂:与 S8WatchSchedulerService.RunOnceAsync 当前固定上下文一致。
  274. TenantId = 1,
  275. FactoryId = 1,
  276. ExceptionCode = code,
  277. Title = title,
  278. Description = null,
  279. SceneCode = S8SceneCode.S2,
  280. // 首版自动监控建单来源标识(字符串值,先不抽常量类)。
  281. SourceType = "AUTO_WATCH",
  282. Status = "NEW",
  283. Severity = string.IsNullOrWhiteSpace(hit.Severity) ? "MEDIUM" : hit.Severity,
  284. PriorityScore = 0,
  285. PriorityLevel = "P3",
  286. // 首版兜底口径:Hit 未提供部门时置 0 仅为保证“能建成标准异常单并进入主链”,
  287. // 不是最终业务部门语义;后续需由上游查询结果提供,或在专项任务中补口径。
  288. OccurrenceDeptId = hit.OccurrenceDeptId ?? 0,
  289. ResponsibleDeptId = hit.ResponsibleDeptId ?? 0,
  290. ReporterId = null,
  291. CreatedAt = DateTime.Now,
  292. IsDeleted = false,
  293. // G-01 首版唯一异常类型映射(baseline 已迁后 EQUIP_FAULT 属 S2 制造协同场景)。
  294. ExceptionTypeCode = "EQUIP_FAULT",
  295. ModuleCode = resolvedModule,
  296. // S8-PROCESS-NODE-S1S7-ALIGN-1:process_node_code 与 module 对齐 S1-S7。
  297. ProcessNodeCode = ResolveProcessNodeCode(S8SceneCode.S2, resolvedModule),
  298. // 追溯三件套(自动建单必填口径)。
  299. SourceRuleId = hit.SourceRuleId,
  300. SourceDataSourceId = hit.DataSourceId,
  301. SourcePayload = hit.SourcePayload,
  302. RelatedObjectCode = hit.RelatedObjectCode
  303. };
  304. await _rep.AsTenant().UseTranAsync(async () =>
  305. {
  306. entity = await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  307. await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline
  308. {
  309. ExceptionId = entity.Id,
  310. ActionCode = "CREATE",
  311. ActionLabel = "创建",
  312. FromStatus = null,
  313. ToStatus = "NEW",
  314. OperatorId = null,
  315. ActionRemark = "自动建单",
  316. CreatedAt = DateTime.Now
  317. });
  318. }, ex => throw ex);
  319. await TryStartIntakeFlowAsync(entity);
  320. return entity;
  321. }
  322. /// <summary>
  323. /// R2 自动建单分支(TIMEOUT 等新 evaluator 走此路径)。
  324. /// 与 <see cref="CreateFromWatchAsync"/> 并列:复用同一仓储 / 事务 / 时间线 ActionCode;
  325. /// 差异点:消费 <see cref="S8RuleHit"/> 一份命中模型,把 R2 新列(DedupKey / LastDetectedAt /
  326. /// SourceRuleCode / SourceObjectType / SourceObjectId)落齐;ExceptionTypeCode 由 hit 自带,
  327. /// 不再硬编码 EQUIP_FAULT。RecoveredAt 本轮不写。
  328. /// 调用方负责前置检查 ExceptionTypeCode 是否在 baseline;本方法不再二次校验。
  329. /// </summary>
  330. public async Task<AdoS8Exception> CreateFromHitAsync(S8RuleHit hit)
  331. {
  332. if (hit.SourceRuleId <= 0 || string.IsNullOrWhiteSpace(hit.RelatedObjectCode))
  333. throw new S8BizException("自动建单缺失追溯键");
  334. var effectiveScene = string.IsNullOrWhiteSpace(hit.SceneCode) ? S8SceneCode.S2 : hit.SceneCode;
  335. // S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1:R2 自动建单 module_code 派生统一走严格 S1-S7 链路;
  336. // hit.ModuleCode(evaluator 显式)→ rule/hit.SceneCode(当前 DB 100% S1-S7)→ exception_type.scene_code。
  337. var resolvedModule = await ResolveModuleCodeAsync(
  338. explicitModuleCode: null,
  339. hitModuleCode: hit.ModuleCode,
  340. sceneCode: effectiveScene,
  341. exceptionTypeCode: hit.ExceptionTypeCode);
  342. if (resolvedModule == null)
  343. {
  344. _logger.LogWarning(
  345. "auto_watch_hit_module_code_unresolved sceneCode={SceneCode} hitModule={HitModule} typeCode={TypeCode} ruleCode={RuleCode}",
  346. hit.SceneCode, hit.ModuleCode, hit.ExceptionTypeCode, hit.SourceRuleCode);
  347. }
  348. var code = $"EX-{DateTime.Now:yyyyMMdd}-{Guid.NewGuid().ToString("N")[..8].ToUpperInvariant()}";
  349. var entity = new AdoS8Exception
  350. {
  351. // 与 CreateFromWatchAsync 当前固定上下文一致;R2 不变更租户/工厂上下文语义。
  352. TenantId = 1,
  353. FactoryId = 1,
  354. ExceptionCode = code,
  355. Title = string.IsNullOrWhiteSpace(hit.Title)
  356. ? $"[自动] {hit.SourceObjectType} {hit.SourceObjectId}"
  357. : hit.Title,
  358. Description = null,
  359. SceneCode = effectiveScene,
  360. SourceType = "AUTO_WATCH",
  361. Status = "NEW",
  362. Severity = string.IsNullOrWhiteSpace(hit.Severity) ? "MEDIUM" : hit.Severity,
  363. PriorityScore = 0,
  364. PriorityLevel = "P3",
  365. OccurrenceDeptId = hit.OccurrenceDeptId ?? 0,
  366. ResponsibleDeptId = hit.ResponsibleDeptId ?? 0,
  367. ReporterId = null,
  368. CreatedAt = DateTime.Now,
  369. IsDeleted = false,
  370. ExceptionTypeCode = hit.ExceptionTypeCode,
  371. ModuleCode = resolvedModule,
  372. // S8-PROCESS-NODE-S1S7-ALIGN-1:process_node_code 与 module 对齐 S1-S7。
  373. ProcessNodeCode = ResolveProcessNodeCode(effectiveScene, resolvedModule),
  374. SourceRuleId = hit.SourceRuleId,
  375. SourceDataSourceId = hit.DataSourceId == 0 ? null : hit.DataSourceId,
  376. SourcePayload = hit.SourcePayload,
  377. RelatedObjectCode = hit.RelatedObjectCode,
  378. // R2 新列回填
  379. DedupKey = hit.DedupKey,
  380. LastDetectedAt = hit.DetectedAt,
  381. RecoveredAt = null,
  382. SourceRuleCode = hit.SourceRuleCode,
  383. SourceObjectType = hit.SourceObjectType,
  384. SourceObjectId = hit.SourceObjectId
  385. };
  386. await _rep.AsTenant().UseTranAsync(async () =>
  387. {
  388. entity = await _rep.AsInsertable(entity).ExecuteReturnEntityAsync();
  389. await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline
  390. {
  391. ExceptionId = entity.Id,
  392. ActionCode = "CREATE",
  393. ActionLabel = "创建",
  394. FromStatus = null,
  395. ToStatus = "NEW",
  396. OperatorId = null,
  397. ActionRemark = "自动建单(R2)",
  398. CreatedAt = DateTime.Now
  399. });
  400. }, ex => throw ex);
  401. await TryStartIntakeFlowAsync(entity);
  402. return entity;
  403. }
  404. public async Task<AdoS8Exception?> GetAsync(long id) =>
  405. await _rep.GetByIdAsync(id);
  406. public async Task<AdoS8Evidence> AddAttachmentAsync(long id, AdoS8AttachmentCreateDto dto)
  407. {
  408. var entity = await _rep.GetFirstAsync(x => x.Id == id && !x.IsDeleted)
  409. ?? throw new S8BizException("异常不存在");
  410. if (string.IsNullOrWhiteSpace(dto.FileName) || string.IsNullOrWhiteSpace(dto.FileUrl))
  411. throw new S8BizException("附件名称和地址必填");
  412. var evidence = new AdoS8Evidence
  413. {
  414. ExceptionId = id,
  415. EvidenceType = string.IsNullOrWhiteSpace(dto.EvidenceType) ? "file" : dto.EvidenceType,
  416. FileName = dto.FileName.Trim(),
  417. FileUrl = dto.FileUrl.Trim(),
  418. SourceSystem = dto.SourceSystem,
  419. UploadedBy = dto.UploadedBy,
  420. UploadedAt = DateTime.Now,
  421. IsDeleted = false
  422. };
  423. await _evidenceRep.InsertAsync(evidence);
  424. return evidence;
  425. }
  426. }