namespace Admin.NET.Plugin.AiDOP.Entity.S8.OrderFlow;
///
/// S8-ORDER-CHAIN-BODY-PRODUCTION-ORDER-LEVEL-SEED-FIX-1:
/// S8 订单执行链路本体生产「工序明细」表(baseline + 订单级 SEED)。
///
/// order_id / order_code 允许为空:
/// - NULL → baseline / PPT 级别基线行(scenario_code=BASELINE_PPT)
/// - 非 NULL → 订单级行(scenario_code=ORDER_LEVEL)
///
/// process_code 取值:P10 / P20 / P30 / P40 / TOTAL(合计行 sort_no=5)。
/// pi_days / actual_days 使用 decimal(6,3) 承载 1 工序 0.441 等尾差修正后的 3 位小数精度。
/// achievement_rate 使用 decimal(5,4),取值范围 0.0000~1.0000;TOTAL 行 baseline 来自 fixture(0.90 黄)、订单级按 plan_qty 加权平均。
/// achievement_status 来自 fixture 表格颜色(baseline)或 ≥0.95 green / ≥0.80 yellow / 否则 red(订单级派生)。
///
[SugarTable("ado_s8_order_flow_manufacturing_process", "S8 订单执行链路本体生产工序明细")]
[SugarIndex("idx_order_flow_mfg_process_baseline", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(ProcessCode), OrderByType.Asc)]
[SugarIndex("idx_order_flow_mfg_process_order", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(OrderCode), OrderByType.Asc)]
[SugarIndex("idx_order_flow_mfg_process_scenario", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(ScenarioCode), OrderByType.Asc, nameof(IsDeleted), OrderByType.Asc)]
public class AdoS8OrderFlowManufacturingProcess
{
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, ColumnDataType = "bigint")]
public long Id { get; set; }
/// NULL = baseline 行;非 NULL = 订单级行。
[SugarColumn(ColumnName = "order_id", ColumnDataType = "bigint", IsNullable = true)]
public long? OrderId { get; set; }
/// NULL = baseline 行;非 NULL = 订单业务键。
[SugarColumn(ColumnName = "order_code", Length = 64, IsNullable = true)]
public string? OrderCode { get; set; }
/// 工序编码:P10 / P20 / P30 / P40 / TOTAL。
[SugarColumn(ColumnName = "process_code", Length = 16)]
public string ProcessCode { get; set; } = string.Empty;
/// 工序名称:10工序 / 20工序 / 30工序 / 40工序 / 合计。
[SugarColumn(ColumnName = "process_name", Length = 32)]
public string ProcessName { get; set; } = string.Empty;
/// PI 标准工时(天)。常量:1.0 / 1.0 / 2.5 / 1.5;TOTAL=6。decimal(6,3)。
[SugarColumn(ColumnName = "pi_days", DecimalDigits = 3, Length = 6)]
public decimal PiDays { get; set; }
/// 实际工时(天)。订单级按 stage.actual_days 守恒尾差修正;TOTAL = stage.actual_days。decimal(6,3)。
[SugarColumn(ColumnName = "actual_days", DecimalDigits = 3, Length = 6)]
public decimal ActualDays { get; set; }
/// 周期状态:green / yellow / red。actual ≤ pi green / ≤ pi*1.2 yellow / 否则 red(seed 时固化,运行期不重判)。
[SugarColumn(ColumnName = "cycle_status", Length = 16)]
public string CycleStatus { get; set; } = "green";
/// 计划台次。baseline fixture: 45/3/15/2/NULL;订单级 round(baseline*ratio);TOTAL 行 NULL。
[SugarColumn(ColumnName = "plan_qty", ColumnDataType = "int", IsNullable = true)]
public int? PlanQty { get; set; }
/// 计划达成率。decimal(5,4),取值 0.0000~1.0000;TOTAL baseline=0.9000(fixture 锚),订单级 TOTAL 由 plan_qty 加权平均。
[SugarColumn(ColumnName = "achievement_rate", DecimalDigits = 4, Length = 5, IsNullable = true)]
public decimal? AchievementRate { get; set; }
/// 达成状态:green / yellow / red;baseline 由 fixture 颜色固定,订单级由 rate 阈值派生(≥0.95 green / ≥0.80 yellow / 否则 red)。
[SugarColumn(ColumnName = "achievement_status", Length = 16)]
public string AchievementStatus { get; set; } = string.Empty;
/// 排序号 1..5(10工序/20工序/30工序/40工序/合计)。
[SugarColumn(ColumnName = "sort_no", ColumnDataType = "int")]
public int SortNo { get; set; }
/// BASELINE_PPT / ORDER_LEVEL。
[SugarColumn(ColumnName = "scenario_code", Length = 16)]
public string ScenarioCode { get; set; } = "BASELINE_PPT";
/// SEED / IMPORT / AGG。同 (order_code, process_code) IMPORT/AGG 行存在时优先采用,SEED 仅兜底。
[SugarColumn(ColumnName = "data_source", Length = 16)]
public string DataSource { get; set; } = "SEED";
[SugarColumn(ColumnName = "tenant_id", ColumnDataType = "bigint")]
public long TenantId { get; set; }
[SugarColumn(ColumnName = "factory_id", ColumnDataType = "bigint")]
public long FactoryId { get; set; }
[SugarColumn(ColumnName = "created_at")]
public DateTime CreatedAt { get; set; } = DateTime.Now;
[SugarColumn(ColumnName = "updated_at", IsNullable = true)]
public DateTime? UpdatedAt { get; set; }
[SugarColumn(ColumnName = "is_deleted", ColumnDataType = "boolean")]
public bool IsDeleted { get; set; }
}