|
|
@@ -22,6 +22,9 @@ namespace Admin.NET.Plugin.AiDOP.MaterialWarehouse;
|
|
|
[NonUnify]
|
|
|
public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
{
|
|
|
+ /// <summary>主/系统租户哨兵:超管未选择目标租户时其 JWT TenantId 即此值,拒绝作为业务租户。</summary>
|
|
|
+ private const long MainTenantId = 1300000000001L;
|
|
|
+
|
|
|
private readonly ISqlSugarClient _db;
|
|
|
private readonly FlowEngineService _flowEngine;
|
|
|
private readonly UserManager _userManager;
|
|
|
@@ -33,6 +36,17 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
_userManager = userManager;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>严格可信租户解析:只来自认证后 JWT;无 Token(<=0) 或超管未选主租户 → 拒绝;不读前端 tenantId、无默认回退。</summary>
|
|
|
+ private long ResolveTenantOrThrow()
|
|
|
+ {
|
|
|
+ var tid = _userManager.TenantId;
|
|
|
+ if (tid <= 0)
|
|
|
+ throw Oops.Oh("无法确定当前租户,请重新登录或选择目标租户");
|
|
|
+ if (_userManager.SuperAdmin && tid == MainTenantId)
|
|
|
+ throw Oops.Oh("超级管理员操作前必须选择目标租户");
|
|
|
+ return tid;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 检验单流程状态(只读,供前端按钮控制)。
|
|
|
/// </summary>
|
|
|
@@ -97,6 +111,9 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
if (myTask.NodeId != IqcInspBillFlowConst.NodeInspect)
|
|
|
throw Oops.Oh("当前不在检验录入节点,无法提交检验结果");
|
|
|
|
|
|
+ // 写库前严格解析可信租户(无 Token / 超管未选主租户 → 抛错,不落库)
|
|
|
+ var tid = ResolveTenantOrThrow();
|
|
|
+
|
|
|
// 写检验结果(仅 pd/dhsl/bhgsl/clfs)
|
|
|
await _db.Ado.ExecuteCommandAsync(
|
|
|
"UPDATE qms_qcp_inspbill SET pd=@pd, dhsl=@dhsl, bhgsl=@bhgsl, clfs=@clfs WHERE id=@id AND tenant_id=@TenantId",
|
|
|
@@ -107,7 +124,7 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
new("@bhgsl", input.Bhgsl),
|
|
|
new("@clfs", input.Pd == 1 ? input.Clfs : null),
|
|
|
new("@id", input.Id),
|
|
|
- new("@TenantId", _userManager.TenantId),
|
|
|
+ new("@TenantId", tid),
|
|
|
});
|
|
|
|
|
|
// 推进 N1 → N2
|
|
|
@@ -177,10 +194,13 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
foreach (var q in new[] { input.DispositionQty, input.ConcessionQty, input.SelectionQty, input.ScrapQty })
|
|
|
if (q.HasValue && q.Value < 0) throw Oops.Oh("处置数量不能为负");
|
|
|
|
|
|
+ // 写库前严格解析可信租户(无 Token / 超管未选主租户 → 抛错,不落库)
|
|
|
+ var tid = ResolveTenantOrThrow();
|
|
|
+
|
|
|
// 检验单必须不合格(合格单无 SQE 节点)
|
|
|
var pdRows = await _db.Ado.SqlQueryAsync<int?>(
|
|
|
"SELECT pd FROM qms_qcp_inspbill WHERE id=@id AND tenant_id=@TenantId LIMIT 1",
|
|
|
- new List<SugarParameter> { new("@id", input.Id), new("@TenantId", _userManager.TenantId) });
|
|
|
+ new List<SugarParameter> { new("@id", input.Id), new("@TenantId", tid) });
|
|
|
if (pdRows.FirstOrDefault() != 1) throw Oops.Oh("仅不合格检验单(pd=1)可做 SQE 处置");
|
|
|
|
|
|
var inst = await GetLatestInstanceAsync(input.Id);
|
|
|
@@ -199,13 +219,13 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
// 来源单号
|
|
|
var srcRows = await _db.Ado.SqlQueryAsync<string>(
|
|
|
"SELECT lydjbh FROM qms_qcp_inspbill WHERE id=@id AND tenant_id=@TenantId LIMIT 1",
|
|
|
- new List<SugarParameter> { new("@id", input.Id), new("@TenantId", _userManager.TenantId) });
|
|
|
+ new List<SugarParameter> { new("@id", input.Id), new("@TenantId", tid) });
|
|
|
|
|
|
var now = DateTime.Now;
|
|
|
var disposition = new AdoS5IqcSqeDisposition
|
|
|
{
|
|
|
Id = YitIdHelper.NextId(),
|
|
|
- TenantId = _userManager.TenantId,
|
|
|
+ TenantId = tid,
|
|
|
OrgId = inst.OrgId,
|
|
|
InspbillId = input.Id,
|
|
|
InspbillNo = billNo,
|
|
|
@@ -245,9 +265,10 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
private async Task<string> EnsureBillExistsAsync(long id)
|
|
|
{
|
|
|
if (id <= 0) throw Oops.Oh("检验单 id 非法");
|
|
|
+ var tid = ResolveTenantOrThrow();
|
|
|
var rows = await _db.Ado.SqlQueryAsync<string>(
|
|
|
"SELECT FBILLNO FROM qms_qcp_inspbill WHERE id=@id AND tenant_id=@TenantId LIMIT 1",
|
|
|
- new List<SugarParameter> { new("@id", id), new("@TenantId", _userManager.TenantId) });
|
|
|
+ new List<SugarParameter> { new("@id", id), new("@TenantId", tid) });
|
|
|
if (rows.Count == 0) throw Oops.Oh("检验单不存在");
|
|
|
return rows[0] ?? id.ToString();
|
|
|
}
|
|
|
@@ -383,7 +404,7 @@ public class IqcInspBillFlowService : IDynamicApiController, ITransient
|
|
|
if (row == null || row.Pd != 0) return; // 仅合格回写
|
|
|
|
|
|
string billNo = string.IsNullOrWhiteSpace(row.BillNo) ? billId.ToString() : row.BillNo!;
|
|
|
- long tenantId = _userManager.TenantId;
|
|
|
+ long tenantId = ResolveTenantOrThrow();
|
|
|
var payload = JsonSerializer.Serialize(new
|
|
|
{
|
|
|
path = "/iqc/result",
|