using Admin.NET.Plugin.ApprovalFlow;
using Admin.NET.Plugin.ApprovalFlow.Service;
namespace Admin.NET.Plugin.AiDOP.FinishedWarehouse;
///
/// S7 FQC 成品检验单流程常量(BizType / 节点码 / 角色码 / 角色固定 Id / UAT)。集中避免散落字符串。
/// 最小线性流程:start → N1_INSPECT(检验员) → N2_SUP_REVIEW(检验主管) → end(无网关、无 SQE)。
///
public static class FqcInspBillFlowConst
{
/// 流程业务类型编码
public const string BizType = "S7_FQC_INSPBILL";
/// N1 检验员检验节点
public const string NodeInspect = "N1_INSPECT";
/// N2 检验主管审核节点
public const string NodeSupervisor = "N2_SUP_REVIEW";
/// GW_RESULT 排他网关(按 disposition_required 分流:==1→N3,否则→end)
public const string GatewayResult = "GW_RESULT";
/// N3 QE 处置节点(不合格 pd=1 进入)
public const string NodeDisposition = "N3_QE_DISPOSITION";
/// 检验员角色编码
public const string RoleInspectorCode = "ROLE_S7_FQC_INSPECTOR";
/// 检验主管角色编码
public const string RoleSupervisorCode = "ROLE_S7_FQC_SUPERVISOR";
/// 质量工程师(QE)角色编码
public const string RoleQeCode = "ROLE_S7_FQC_QE";
/// 检验员角色固定 Id(种子与流程定义共用;S7 段 1329915020xxx,避开 S5 的 1329915010xxx)
public const long RoleInspectorId = 1329915020001L;
/// 检验主管角色固定 Id
public const long RoleSupervisorId = 1329915020002L;
/// QE 角色固定 Id
public const long RoleQeId = 1329915020003L;
/// 流程定义版本(v2 加入 GW_RESULT/N3_QE_DISPOSITION;seed 幂等升级依据)
public const int FlowDefinitionVersion = 2;
/// UAT 冒烟绑定账号(同绑三角色,仅 UAT 自审)
public const string UatAccount = "superAdmin.NET";
// 检验任务执行状态 FINSPECTSTATUS:未检验 / 检验中 / 检验完成
public const string InspectStatusDone = "检验完成";
// pd 判定:0=合格 1=不合格 | clfs 处理方式:0=让步接收 1=挑选 2=报废
// QE 处置类型(string,仅记录方案,不触发实际动作)
public const string DispTypeRework = "REWORK";
public const string DispTypeConcession = "CONCESSION";
public const string DispTypeScrap = "SCRAP";
public const string DispTypeOther = "OTHER";
}
///
/// S7 FQC 成品检验单审批流回调处理器(BizType=S7_FQC_INSPBILL)。
///
/// 本批(检验员+主管最小闭环)Handler 全部 no-op:不写 qms、不写库存/仓储/生产状态、不发额外通知。
/// 检验业务结果 pd/hgsl/bhgsl/clfs 与检验任务 qms_fqcbj 字段由 FqcInspBillFlowService.submit-result 在事务内写入;
/// 审批节点/待办/审核状态由 ApprovalFlowInstance 承载,绝不写入 qms_qcpp_inspbill.FBILLSTATUS 或 qms_fqcbj.FINSPECTSTATUS。
/// GetBizData 仅返回基础信息供流程日志/展示(本批线性流程无网关条件)。
///
public class FqcInspBillFlowBizHandler : IFlowBizHandler, ITransient
{
public string BizType => FqcInspBillFlowConst.BizType;
private readonly ISqlSugarClient _db;
public FqcInspBillFlowBizHandler(ISqlSugarClient db)
{
_db = db;
}
/// 流程发起后回调:本批 no-op。
public Task OnFlowStarted(long bizId, long instanceId) => Task.CompletedTask;
/// 单节点完成回调:本批 no-op。
public Task OnNodeCompleted(long bizId, long instanceId, string nodeId, string nodeName, long? approverUserId) => Task.CompletedTask;
/// 流程结束回调:本批 no-op(不写 qms/库存/仓储/生产;审核结果由 ApprovalFlowInstance 状态承载)。
public Task OnFlowCompleted(long bizId, long instanceId, FlowInstanceStatusEnum finalStatus, long? lastApproverId) => Task.CompletedTask;
///
/// 返回检验单基础信息 + 网关判据 disposition_required(GW_RESULT 按此分流:==1→N3,否则→end)。
///
/// disposition_required 由 pd 在 C# 侧计算(pd 为 varchar,直接在流程定义写 "pd == 1" 会 string==int 脆弱):
/// pd 去空后 == "1"(不合格) → 1(进 QE 处置);null/"0"/其它值 → 0(合格结束)。检验员 N1 已写 pd,主管 N2 通过后网关读取。
///
public async Task> GetBizData(long bizId)
{
var rows = await _db.Ado.SqlQueryAsync(
"SELECT FBILLNO AS BillNo, FMATERIALCFG AS MaterialCode, wlmc AS MaterialName, pd AS Pd, clfs AS Clfs FROM qms_qcpp_inspbill WHERE id=@id LIMIT 1",
new List { new("@id", bizId) });
var r = rows.FirstOrDefault();
var dispositionRequired = (r?.Pd?.Trim() == "1") ? 1 : 0;
if (r == null) return new Dictionary { ["disposition_required"] = dispositionRequired };
return new Dictionary
{
["billNo"] = r.BillNo ?? "",
["materialCode"] = r.MaterialCode ?? "",
["materialName"] = r.MaterialName ?? "",
["pd"] = r.Pd ?? "",
["clfs"] = r.Clfs ?? -1,
["disposition_required"] = dispositionRequired,
};
}
private class FqcInspBillFlowBizData
{
public string? BillNo { get; set; }
public string? MaterialCode { get; set; }
public string? MaterialName { get; set; }
public string? Pd { get; set; }
public int? Clfs { get; set; }
}
}