S6ProcessInspectionService.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. using Admin.NET.Plugin.AiDOP.Manufacturing.Dto;
  2. namespace Admin.NET.Plugin.AiDOP.Manufacturing;
  3. /// <summary>
  4. /// S6 过程检验单 服务(Phase 1B):生产指令 → 自动唯一解析过程检规 → 生成检验单 + 检规快照 → 只读详情。
  5. ///
  6. /// prepare:入参仅 workOrderNo。后端自解析 CurrentTenant(AidopTenantScope)+ 加载生产指令(mdp_std_work_order_schedule)
  7. /// → S6ProcessSpecResolver 按 (tenant, item_code, order_date) 唯一解析。
  8. /// 仅 MATCHED 才幂等生成/复用检验单 + 冻结检规快照(同一事务);NO_MATCH/AMBIGUOUS/INVALID 一律不写库、原样返回状态。
  9. /// 无人工检规选择;全程 tenant 显式过滤;快照生成后详情只读快照,不再回查 S0。
  10. /// FACTORY_SCOPE = PARTIAL(S0 检规无 factory_id,安全边界为 Tenant;factory 仅随单据承载不做过滤)。
  11. /// </summary>
  12. [ApiDescriptionSettings(Order = 304, Description = "过程检验单")]
  13. [Route("api/S6ProcessInspection")]
  14. [NonUnify]
  15. public class S6ProcessInspectionService : IDynamicApiController, ITransient
  16. {
  17. private readonly ISqlSugarClient _db;
  18. private readonly UserManager _userManager;
  19. private readonly S6ProcessSpecResolver _resolver;
  20. public S6ProcessInspectionService(ISqlSugarClient db, UserManager userManager, S6ProcessSpecResolver resolver)
  21. {
  22. _db = db;
  23. _userManager = userManager;
  24. _resolver = resolver;
  25. }
  26. private long ResolveTenantOrThrow() => Infrastructure.AidopTenantScope.ResolveOrThrow(_userManager);
  27. /// <summary>
  28. /// 准备过程检验单:解析检规,MATCHED 则幂等生成/复用检验单 + 快照,返回 billId + status。
  29. /// </summary>
  30. [DisplayName("准备过程检验单")]
  31. [HttpPost("prepare")]
  32. public async Task<S6ProcessInspectionPrepareResult> Prepare([FromBody] S6ProcessInspectionPrepareInput input)
  33. {
  34. var res = new S6ProcessInspectionPrepareResult();
  35. if (input == null || string.IsNullOrWhiteSpace(input.WorkOrderNo))
  36. {
  37. res.Status = S6SpecResolveStatus.NoMatch;
  38. res.Message = "缺少工单编号。";
  39. return res;
  40. }
  41. var tid = ResolveTenantOrThrow();
  42. var wo = input.WorkOrderNo.Trim();
  43. // 加载生产指令(严格租户;跨租户/不存在 → 明确拒绝,不泄漏)
  44. var pi = await _db.Ado.SqlQuerySingleAsync<ProdInstrRow>(
  45. """
  46. SELECT work_order AS WorkOrder, lot_serial AS LotSerial, item_code AS ItemCode, item_name AS ItemName,
  47. specification AS Specification, factory_id AS FactoryId, order_date AS OrderDate
  48. FROM mdp_std_work_order_schedule
  49. WHERE tenant_id=@TenantId AND work_order=@Wo LIMIT 1
  50. """,
  51. new List<SugarParameter> { new("@TenantId", tid), new("@Wo", wo) });
  52. if (pi == null)
  53. {
  54. res.Status = S6SpecResolveStatus.NoMatch;
  55. res.Message = "未找到该工单的生产指令。";
  56. return res;
  57. }
  58. // ReferenceDate 取检验时点(now):过程检验在当前执行,应采用"检验时点当前有效"的检规;
  59. // 生产指令 OrderDate 是下单时点,可能早于检规生效日(sxrj),用它会漏掉当前有效检规。(§9 明确说明)
  60. var refDate = DateTime.Now;
  61. var resolve = await _resolver.ResolveAsync(tid, pi.ItemCode, refDate);
  62. res.Status = resolve.Status;
  63. res.Message = resolve.Message;
  64. res.SpecCode = resolve.SpecCode;
  65. res.SpecVersion = resolve.SpecVersion;
  66. res.CandidateCount = resolve.CandidateCount;
  67. if (resolve.Status != S6SpecResolveStatus.Matched || resolve.CandidateCount != 1 || resolve.MatchedSpecId is not { } specId)
  68. return res; // 非唯一解析:不写库
  69. // 幂等:已有 active(DRAFT/ACTIVE) 检验单 → 复用
  70. var existingId = await _db.Ado.SqlQuerySingleAsync<long?>(
  71. """
  72. SELECT id FROM ado_s6_process_inspection_bill
  73. WHERE tenant_id=@TenantId AND work_order_no=@Wo AND inspection_status IN ('DRAFT','ACTIVE')
  74. ORDER BY id DESC LIMIT 1
  75. """,
  76. new List<SugarParameter> { new("@TenantId", tid), new("@Wo", wo) });
  77. if (existingId is { } eid && eid > 0)
  78. {
  79. res.BillId = eid;
  80. res.Reused = true;
  81. return res;
  82. }
  83. // 生成:检验单 + 快照头 + 快照明细(同一事务,任一失败全回滚)
  84. var uid = _userManager.UserId;
  85. var uname = _userManager.RealName ?? _userManager.Account;
  86. try
  87. {
  88. _db.Ado.BeginTran();
  89. await _db.Ado.ExecuteCommandAsync(
  90. """
  91. INSERT INTO ado_s6_process_inspection_bill
  92. (tenant_id, factory_id, work_order_no, lot_serial, item_code, item_name, specification,
  93. spec_id, spec_code, spec_version, inspection_status, created_by, created_by_name)
  94. VALUES (@TenantId, @FactoryId, @Wo, @Lot, @ItemCode, @ItemName, @Spec,
  95. @SpecId, @SpecCode, @SpecVersion, 'DRAFT', @Uid, @Uname)
  96. """,
  97. new List<SugarParameter>
  98. {
  99. new("@TenantId", tid),
  100. new("@FactoryId", (object?)pi.FactoryId ?? DBNull.Value),
  101. new("@Wo", wo),
  102. new("@Lot", (object?)pi.LotSerial ?? DBNull.Value),
  103. new("@ItemCode", (object?)pi.ItemCode ?? DBNull.Value),
  104. new("@ItemName", (object?)pi.ItemName ?? DBNull.Value),
  105. new("@Spec", (object?)pi.Specification ?? DBNull.Value),
  106. new("@SpecId", specId),
  107. new("@SpecCode", (object?)resolve.SpecCode ?? DBNull.Value),
  108. new("@SpecVersion", (object?)resolve.SpecVersion ?? DBNull.Value),
  109. new("@Uid", (object?)uid ?? DBNull.Value),
  110. new("@Uname", (object?)uname ?? DBNull.Value),
  111. });
  112. var billId = await _db.Ado.GetLongAsync("SELECT LAST_INSERT_ID()");
  113. await _db.Ado.ExecuteCommandAsync(
  114. """
  115. INSERT INTO ado_s6_process_inspection_snapshot_head
  116. (tenant_id, bill_id, spec_id, spec_code, spec_version, effective_date, item_code, specification, source_tenant_id)
  117. VALUES (@TenantId, @BillId, @SpecId, @SpecCode, @SpecVersion, @Eff, @ItemCode, @Spec, @TenantId)
  118. """,
  119. new List<SugarParameter>
  120. {
  121. new("@TenantId", tid),
  122. new("@BillId", billId),
  123. new("@SpecId", specId),
  124. new("@SpecCode", (object?)resolve.SpecCode ?? DBNull.Value),
  125. new("@SpecVersion", (object?)resolve.SpecVersion ?? DBNull.Value),
  126. new("@Eff", (object?)resolve.EffectiveDate ?? DBNull.Value),
  127. new("@ItemCode", (object?)pi.ItemCode ?? DBNull.Value),
  128. new("@Spec", (object?)pi.Specification ?? DBNull.Value),
  129. });
  130. var lineCount = await _db.Ado.ExecuteCommandAsync(
  131. """
  132. INSERT INTO ado_s6_process_inspection_snapshot_line
  133. (tenant_id, bill_id, source_line_id, inspection_item, process_code, process_name, method,
  134. spec_value, tech_standard, lower_limit, upper_limit, inspection_frequency, result_type, sort_no, sample_count)
  135. SELECT @TenantId, @BillId, z.id, z.jyxm, z.gxdh, z.gxmc, z.jyff,
  136. z.jygg, z.jsbz, z.xx, z.sx, z.jypc, z.lrlx, NULL, z.sample_count
  137. FROM qms_gcjygfzb z
  138. WHERE z.tenant_id=@TenantId AND z.glid=@SpecId
  139. """,
  140. new List<SugarParameter> { new("@TenantId", tid), new("@BillId", billId), new("@SpecId", specId) });
  141. if (lineCount <= 0)
  142. throw Oops.Oh("过程检验规范无有效明细,无法生成检验单。");
  143. _db.Ado.CommitTran();
  144. res.BillId = billId;
  145. res.Reused = false;
  146. return res;
  147. }
  148. catch
  149. {
  150. _db.Ado.RollbackTran();
  151. throw;
  152. }
  153. }
  154. /// <summary>过程检验单只读详情(单据 + 快照头 + 快照明细)。跨租户/不存在返回 null。</summary>
  155. [DisplayName("过程检验单详情")]
  156. [HttpGet("detail")]
  157. public async Task<S6ProcessInspectionDetailDto?> GetDetail([FromQuery] long billId)
  158. {
  159. if (billId <= 0) return null;
  160. var tid = ResolveTenantOrThrow();
  161. var pars = new List<SugarParameter> { new("@TenantId", tid), new("@BillId", billId) };
  162. var dto = await _db.Ado.SqlQuerySingleAsync<S6ProcessInspectionDetailDto>(
  163. """
  164. SELECT b.id AS BillId, b.work_order_no AS WorkOrderNo, b.lot_serial AS LotSerial, b.item_code AS ItemCode,
  165. b.item_name AS ItemName, b.specification AS Specification, b.spec_id AS SpecId, b.spec_code AS SpecCode,
  166. b.spec_version AS SpecVersion, h.effective_date AS EffectiveDate, b.inspection_status AS InspectionStatus,
  167. b.created_by_name AS CreatedByName, b.create_time AS CreateTime
  168. FROM ado_s6_process_inspection_bill b
  169. LEFT JOIN ado_s6_process_inspection_snapshot_head h ON h.bill_id=b.id AND h.tenant_id=@TenantId
  170. WHERE b.tenant_id=@TenantId AND b.id=@BillId LIMIT 1
  171. """, pars);
  172. if (dto == null) return null;
  173. dto.Lines = await _db.Ado.SqlQueryAsync<S6ProcessInspectionSnapshotLineDto>(
  174. """
  175. SELECT id AS Id, inspection_item AS InspectionItem, process_code AS ProcessCode, process_name AS ProcessName,
  176. method AS Method, spec_value AS SpecValue, tech_standard AS TechStandard, lower_limit AS LowerLimit,
  177. upper_limit AS UpperLimit, inspection_frequency AS InspectionFrequency, result_type AS ResultType,
  178. sort_no AS SortNo, sample_count AS SampleCount
  179. FROM ado_s6_process_inspection_snapshot_line
  180. WHERE tenant_id=@TenantId AND bill_id=@BillId ORDER BY id
  181. """, pars);
  182. // 已录样本 + 后端计算的单项/整单判定(刷新可恢复)
  183. var samples = await LoadResultItemsAsync(tid, billId);
  184. var byLine = samples.GroupBy(s => s.SnapshotLineId).ToDictionary(g => g.Key, g => g.OrderBy(x => x.SampleIndex).ToList());
  185. var itemAgg = new List<(string, string)>();
  186. foreach (var line in dto.Lines)
  187. {
  188. var recorded = byLine.TryGetValue(line.Id, out var list) ? list : new List<ResultItemRow>();
  189. line.Samples = recorded.Select(r => new S6ProcessInspectionResultSampleDto
  190. {
  191. SampleIndex = r.SampleIndex,
  192. ActualNumeric = r.ActualNumeric,
  193. ActualNonNumeric = r.ActualNonNumeric,
  194. Judgement = r.Judgement,
  195. Remark = r.Remark
  196. }).ToList();
  197. var (status, result) = S6ProcessInspectionJudge.AggregateItem(line.SampleCount ?? 1, recorded.Select(r => r.Judgement ?? "").ToList());
  198. line.ItemStatus = status;
  199. line.ItemResult = result;
  200. itemAgg.Add((status, result));
  201. }
  202. var head = await _db.Ado.SqlQuerySingleAsync<ResultHeadRow>(
  203. "SELECT status AS Status, overall_result AS OverallResult FROM ado_s6_process_inspection_result WHERE tenant_id=@TenantId AND bill_id=@BillId LIMIT 1", pars);
  204. dto.OverallStatus = head?.Status ?? S6ItemStatus.NotStarted;
  205. dto.OverallResult = head?.OverallResult ?? S6ProcessInspectionJudge.AggregateOverall(itemAgg);
  206. return dto;
  207. }
  208. /// <summary>
  209. /// 保存检验结果(草稿,可部分)。逐样本 upsert(幂等 UK bill+line+sample),后端按快照自动判定,
  210. /// 重算单项/整单结果,结果头置 IN_PROGRESS;同一事务。前端传的任何判定/租户/限值一律忽略。
  211. /// </summary>
  212. [DisplayName("保存过程检验结果")]
  213. [HttpPost("saveResult")]
  214. public async Task<S6SaveResultOutput> SaveResult([FromBody] S6SaveResultInput input)
  215. {
  216. if (input == null || input.BillId <= 0)
  217. return new S6SaveResultOutput { Ok = false, Message = "缺少检验单。" };
  218. var tid = ResolveTenantOrThrow();
  219. var cfg = await LoadSnapshotConfigAsync(tid, input.BillId);
  220. if (cfg.Count == 0)
  221. return new S6SaveResultOutput { Ok = false, Message = "检验单不存在或无检规快照。" };
  222. var cfgById = cfg.ToDictionary(c => c.Id);
  223. var uid = _userManager.UserId;
  224. var uname = _userManager.RealName ?? _userManager.Account;
  225. var now = DateTime.Now;
  226. try
  227. {
  228. _db.Ado.BeginTran();
  229. var resultId = await EnsureResultHeaderAsync(tid, input.BillId, uid, uname, now);
  230. foreach (var s in input.Samples ?? new List<S6SaveResultSample>())
  231. {
  232. if (!cfgById.TryGetValue(s.SnapshotLineId, out var line)) continue; // 只认本单快照行
  233. var required = line.SampleCount is > 0 ? line.SampleCount!.Value : 1;
  234. if (s.SampleIndex < 1 || s.SampleIndex > required) continue; // 样本序号越界忽略
  235. var clear = string.IsNullOrWhiteSpace(s.ActualValue);
  236. var delPars = new List<SugarParameter> { new("@t", tid), new("@bill", input.BillId), new("@line", s.SnapshotLineId), new("@idx", s.SampleIndex) };
  237. if (clear)
  238. {
  239. await _db.Ado.ExecuteCommandAsync(
  240. "DELETE FROM ado_s6_process_inspection_result_item WHERE tenant_id=@t AND bill_id=@bill AND snapshot_line_id=@line AND sample_index=@idx", delPars);
  241. continue;
  242. }
  243. var judge = S6ProcessInspectionJudge.JudgeSample(line.ResultType, s.ActualValue, line.LowerLimit, line.UpperLimit);
  244. var isNumeric = string.Equals((line.ResultType ?? "").Trim(), S6ResultType.Numeric, StringComparison.OrdinalIgnoreCase);
  245. object numVal = isNumeric && S6ProcessInspectionJudge.ParseNumeric(s.ActualValue) is { } n ? n : DBNull.Value;
  246. object nonNumVal = !isNumeric ? (object)(s.ActualValue?.Trim().ToUpperInvariant() ?? string.Empty) : DBNull.Value;
  247. await _db.Ado.ExecuteCommandAsync(
  248. """
  249. INSERT INTO ado_s6_process_inspection_result_item
  250. (tenant_id, bill_id, result_id, snapshot_line_id, result_type, sample_index, actual_numeric, actual_non_numeric, judgement, remark, inspector_id, inspection_time)
  251. VALUES (@t,@bill,@rid,@line,@rt,@idx,@num,@nonnum,@judge,@remark,@uid,@now)
  252. ON DUPLICATE KEY UPDATE actual_numeric=VALUES(actual_numeric), actual_non_numeric=VALUES(actual_non_numeric),
  253. judgement=VALUES(judgement), remark=VALUES(remark), inspector_id=VALUES(inspector_id), inspection_time=VALUES(inspection_time)
  254. """,
  255. new List<SugarParameter>
  256. {
  257. new("@t", tid), new("@bill", input.BillId), new("@rid", resultId), new("@line", s.SnapshotLineId),
  258. new("@rt", (object?)line.ResultType ?? DBNull.Value), new("@idx", s.SampleIndex),
  259. new("@num", numVal), new("@nonnum", nonNumVal), new("@judge", judge),
  260. new("@remark", (object?)s.Remark ?? DBNull.Value), new("@uid", (object?)uid ?? DBNull.Value), new("@now", now)
  261. });
  262. }
  263. var (overallStatus, overallResult) = await RecomputeAndPersistHeaderAsync(tid, input.BillId, complete: false, now);
  264. _db.Ado.CommitTran();
  265. return new S6SaveResultOutput { Ok = true, OverallStatus = overallStatus, OverallResult = overallResult };
  266. }
  267. catch
  268. {
  269. _db.Ado.RollbackTran();
  270. throw;
  271. }
  272. }
  273. /// <summary>
  274. /// 完成检验。校验所有项目均已录满(COMPLETED),否则 INSPECTION_INCOMPLETE;通过则置 COMPLETED + 整单判定 + completed_at。同一事务。
  275. /// </summary>
  276. [DisplayName("完成过程检验")]
  277. [HttpPost("complete")]
  278. public async Task<S6SaveResultOutput> Complete([FromBody] S6CompleteInput input)
  279. {
  280. if (input == null || input.BillId <= 0)
  281. return new S6SaveResultOutput { Ok = false, Message = "缺少检验单。" };
  282. var tid = ResolveTenantOrThrow();
  283. var cfg = await LoadSnapshotConfigAsync(tid, input.BillId);
  284. if (cfg.Count == 0)
  285. return new S6SaveResultOutput { Ok = false, Message = "检验单不存在或无检规快照。" };
  286. var itemAgg = await AggregateItemsAsync(tid, input.BillId, cfg);
  287. if (!S6ProcessInspectionJudge.AllItemsCompleted(itemAgg))
  288. throw Oops.Oh("INSPECTION_INCOMPLETE:仍有检验项目未录满样本,无法完成检验。");
  289. var now = DateTime.Now;
  290. try
  291. {
  292. _db.Ado.BeginTran();
  293. var (overallStatus, overallResult) = await RecomputeAndPersistHeaderAsync(tid, input.BillId, complete: true, now);
  294. _db.Ado.CommitTran();
  295. return new S6SaveResultOutput { Ok = true, OverallStatus = overallStatus, OverallResult = overallResult };
  296. }
  297. catch
  298. {
  299. _db.Ado.RollbackTran();
  300. throw;
  301. }
  302. }
  303. // ── 内部:快照配置 / 结果读取 / 聚合 ──
  304. private async Task<List<SnapCfgRow>> LoadSnapshotConfigAsync(long tid, long billId) =>
  305. await _db.Ado.SqlQueryAsync<SnapCfgRow>(
  306. """
  307. SELECT id AS Id, result_type AS ResultType, lower_limit AS LowerLimit, upper_limit AS UpperLimit, sample_count AS SampleCount
  308. FROM ado_s6_process_inspection_snapshot_line WHERE tenant_id=@t AND bill_id=@bill ORDER BY id
  309. """, new List<SugarParameter> { new("@t", tid), new("@bill", billId) });
  310. private async Task<List<ResultItemRow>> LoadResultItemsAsync(long tid, long billId) =>
  311. await _db.Ado.SqlQueryAsync<ResultItemRow>(
  312. """
  313. SELECT snapshot_line_id AS SnapshotLineId, sample_index AS SampleIndex, actual_numeric AS ActualNumeric,
  314. actual_non_numeric AS ActualNonNumeric, judgement AS Judgement, remark AS Remark
  315. FROM ado_s6_process_inspection_result_item WHERE tenant_id=@t AND bill_id=@bill ORDER BY snapshot_line_id, sample_index
  316. """, new List<SugarParameter> { new("@t", tid), new("@bill", billId) });
  317. private async Task<List<(string Status, string Result)>> AggregateItemsAsync(long tid, long billId, List<SnapCfgRow> cfg)
  318. {
  319. var items = await LoadResultItemsAsync(tid, billId);
  320. var byLine = items.GroupBy(i => i.SnapshotLineId).ToDictionary(g => g.Key, g => g.Select(x => x.Judgement ?? "").ToList());
  321. return cfg.Select(c => S6ProcessInspectionJudge.AggregateItem(
  322. c.SampleCount is > 0 ? c.SampleCount!.Value : 1,
  323. byLine.TryGetValue(c.Id, out var js) ? js : new List<string>())).ToList();
  324. }
  325. private async Task<long> EnsureResultHeaderAsync(long tid, long billId, long? uid, string? uname, DateTime now)
  326. {
  327. var pars = new List<SugarParameter> { new("@t", tid), new("@bill", billId), new("@uid", (object?)uid ?? DBNull.Value), new("@uname", (object?)uname ?? DBNull.Value), new("@now", now) };
  328. await _db.Ado.ExecuteCommandAsync(
  329. """
  330. INSERT INTO ado_s6_process_inspection_result (tenant_id, bill_id, work_order_no, item_code, status, inspector_id, inspector_name, started_at)
  331. SELECT @t, @bill, b.work_order_no, b.item_code, 'IN_PROGRESS', @uid, @uname, @now
  332. FROM ado_s6_process_inspection_bill b WHERE b.tenant_id=@t AND b.id=@bill
  333. AND NOT EXISTS (SELECT 1 FROM ado_s6_process_inspection_result r WHERE r.tenant_id=@t AND r.bill_id=@bill)
  334. """, pars);
  335. return await _db.Ado.SqlQuerySingleAsync<long>(
  336. "SELECT id FROM ado_s6_process_inspection_result WHERE tenant_id=@t AND bill_id=@bill LIMIT 1",
  337. new List<SugarParameter> { new("@t", tid), new("@bill", billId) });
  338. }
  339. private async Task<(string Status, string Result)> RecomputeAndPersistHeaderAsync(long tid, long billId, bool complete, DateTime now)
  340. {
  341. var cfg = await LoadSnapshotConfigAsync(tid, billId);
  342. var itemAgg = await AggregateItemsAsync(tid, billId, cfg);
  343. var overallResult = S6ProcessInspectionJudge.AggregateOverall(itemAgg);
  344. var anyRecorded = itemAgg.Any(i => i.Status != S6ItemStatus.NotStarted);
  345. var status = complete ? S6ItemStatus.Completed : (anyRecorded ? S6ItemStatus.InProgress : S6ItemStatus.NotStarted);
  346. var pars = new List<SugarParameter>
  347. {
  348. new("@t", tid), new("@bill", billId), new("@status", status), new("@overall", overallResult),
  349. new("@completedAt", complete ? now : (object)DBNull.Value)
  350. };
  351. // completed_at 与 status 严格一致:仅 COMPLETED 有值;一旦回退(再次保存改动)即清空,避免 IN_PROGRESS 却残留完成时间。
  352. await _db.Ado.ExecuteCommandAsync(
  353. """
  354. UPDATE ado_s6_process_inspection_result
  355. SET status=@status, overall_result=@overall, completed_at=CASE WHEN @status='COMPLETED' THEN @completedAt ELSE NULL END, update_time=NOW()
  356. WHERE tenant_id=@t AND bill_id=@bill
  357. """, pars);
  358. return (status, overallResult);
  359. }
  360. private sealed class ProdInstrRow
  361. {
  362. public string? WorkOrder { get; set; }
  363. public string? LotSerial { get; set; }
  364. public string? ItemCode { get; set; }
  365. public string? ItemName { get; set; }
  366. public string? Specification { get; set; }
  367. public long? FactoryId { get; set; }
  368. public DateTime? OrderDate { get; set; }
  369. }
  370. private sealed class SnapCfgRow
  371. {
  372. public long Id { get; set; }
  373. public string? ResultType { get; set; }
  374. public string? LowerLimit { get; set; }
  375. public string? UpperLimit { get; set; }
  376. public int? SampleCount { get; set; }
  377. }
  378. private sealed class ResultItemRow
  379. {
  380. public long SnapshotLineId { get; set; }
  381. public int SampleIndex { get; set; }
  382. public decimal? ActualNumeric { get; set; }
  383. public string? ActualNonNumeric { get; set; }
  384. public string? Judgement { get; set; }
  385. public string? Remark { get; set; }
  386. }
  387. private sealed class ResultHeadRow
  388. {
  389. public string? Status { get; set; }
  390. public string? OverallResult { get; set; }
  391. }
  392. }