AdoSmartOpsImprovementAction.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. using Admin.NET.Core;
  2. namespace Admin.NET.Plugin.AiDOP.Entity;
  3. [SugarTable("ado_smart_ops_improvement_action", "智慧诊断改善行动项")]
  4. [SugarIndex("uk_improve_action_seq", nameof(TenantId), OrderByType.Asc, nameof(PlanId), OrderByType.Asc, nameof(SequenceNo), OrderByType.Asc, IsUnique = true)]
  5. [SugarIndex("idx_improve_action_owner", nameof(TenantId), OrderByType.Asc, nameof(OwnerUserId), OrderByType.Asc, nameof(Status), OrderByType.Asc)]
  6. [SugarIndex("idx_improve_action_due", nameof(TenantId), OrderByType.Asc, nameof(DueDate), OrderByType.Asc)]
  7. public class AdoSmartOpsImprovementAction : ITenantIdFilter
  8. {
  9. [SugarColumn(ColumnName = "id", ColumnDescription = "主键", IsPrimaryKey = true, IsIdentity = true)]
  10. public long Id { get; set; }
  11. [SugarColumn(ColumnName = "tenant_id", ColumnDescription = "租户")]
  12. public long? TenantId { get; set; }
  13. [SugarColumn(ColumnName = "factory_id", ColumnDescription = "工厂")]
  14. public long FactoryId { get; set; }
  15. [SugarColumn(ColumnName = "plan_id", ColumnDescription = "改善计划")]
  16. public long PlanId { get; set; }
  17. [SugarColumn(ColumnName = "sequence_no", ColumnDescription = "序号")]
  18. public int SequenceNo { get; set; }
  19. [SugarColumn(ColumnName = "content", ColumnDescription = "内容", Length = 500)]
  20. public string Content { get; set; } = "";
  21. [SugarColumn(ColumnName = "owner_user_id", ColumnDescription = "负责人用户", IsNullable = true)]
  22. public long? OwnerUserId { get; set; }
  23. [SugarColumn(ColumnName = "owner_name", ColumnDescription = "负责人/部门", Length = 100, IsNullable = true)]
  24. public string? OwnerName { get; set; }
  25. [SugarColumn(ColumnName = "due_date", ColumnDescription = "计划完成日", IsNullable = true)]
  26. public DateTime? DueDate { get; set; }
  27. [SugarColumn(ColumnName = "status", ColumnDescription = "状态", Length = 32)]
  28. public string Status { get; set; } = SmartOpsImprovementActionStatus.Pending;
  29. [SugarColumn(ColumnName = "completed_at", ColumnDescription = "实际完成时间", IsNullable = true)]
  30. public DateTime? CompletedAt { get; set; }
  31. [SugarColumn(ColumnName = "proof_remark", ColumnDescription = "完成证明/备注", ColumnDataType = "text", IsNullable = true)]
  32. public string? ProofRemark { get; set; }
  33. [SugarColumn(ColumnName = "version", ColumnDescription = "乐观锁")]
  34. public int Version { get; set; } = 1;
  35. [SugarColumn(ColumnName = "create_user_id", IsNullable = true)]
  36. public long? CreateUserId { get; set; }
  37. [SugarColumn(ColumnName = "update_user_id", IsNullable = true)]
  38. public long? UpdateUserId { get; set; }
  39. [SugarColumn(ColumnName = "create_time")]
  40. public DateTime CreateTime { get; set; } = DateTime.Now;
  41. [SugarColumn(ColumnName = "update_time")]
  42. public DateTime UpdateTime { get; set; } = DateTime.Now;
  43. }
  44. [SugarTable("ado_smart_ops_improvement_action_log", "智慧诊断改善行动项日志")]
  45. [SugarIndex("idx_improve_action_log", nameof(TenantId), OrderByType.Asc, nameof(ActionId), OrderByType.Asc, nameof(CreateTime), OrderByType.Desc)]
  46. public class AdoSmartOpsImprovementActionLog : ITenantIdFilter
  47. {
  48. [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
  49. public long Id { get; set; }
  50. [SugarColumn(ColumnName = "tenant_id")]
  51. public long? TenantId { get; set; }
  52. [SugarColumn(ColumnName = "action_id")]
  53. public long ActionId { get; set; }
  54. [SugarColumn(ColumnName = "plan_id")]
  55. public long PlanId { get; set; }
  56. [SugarColumn(ColumnName = "operation", Length = 32)]
  57. public string Operation { get; set; } = "";
  58. [SugarColumn(ColumnName = "before_json", ColumnDataType = "text", IsNullable = true)]
  59. public string? BeforeJson { get; set; }
  60. [SugarColumn(ColumnName = "after_json", ColumnDataType = "text", IsNullable = true)]
  61. public string? AfterJson { get; set; }
  62. [SugarColumn(ColumnName = "operator_user_id", IsNullable = true)]
  63. public long? OperatorUserId { get; set; }
  64. [SugarColumn(ColumnName = "remark", Length = 500, IsNullable = true)]
  65. public string? Remark { get; set; }
  66. [SugarColumn(ColumnName = "create_time")]
  67. public DateTime CreateTime { get; set; } = DateTime.Now;
  68. }
  69. [SugarTable("ado_smart_ops_improvement_action_notice", "改善行动项通知去重")]
  70. [SugarIndex("uk_improve_action_notice", nameof(TenantId), OrderByType.Asc, nameof(ActionId), OrderByType.Asc, nameof(NoticeType), OrderByType.Asc, nameof(NoticeDate), OrderByType.Asc, IsUnique = true)]
  71. public class AdoSmartOpsImprovementActionNotice : ITenantIdFilter
  72. {
  73. [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
  74. public long Id { get; set; }
  75. [SugarColumn(ColumnName = "tenant_id")]
  76. public long? TenantId { get; set; }
  77. [SugarColumn(ColumnName = "action_id")]
  78. public long ActionId { get; set; }
  79. [SugarColumn(ColumnName = "notice_type", Length = 32)]
  80. public string NoticeType { get; set; } = "";
  81. [SugarColumn(ColumnName = "notice_date", ColumnDataType = "date")]
  82. public DateTime NoticeDate { get; set; }
  83. [SugarColumn(ColumnName = "notice_id", IsNullable = true)]
  84. public long? NoticeId { get; set; }
  85. [SugarColumn(ColumnName = "create_time")]
  86. public DateTime CreateTime { get; set; } = DateTime.Now;
  87. }
  88. public static class SmartOpsImprovementActionStatus
  89. {
  90. public const string Pending = "pending";
  91. public const string InProgress = "in_progress";
  92. public const string Completed = "completed";
  93. public const string Cancelled = "cancelled";
  94. public static string Normalize(string? raw)
  95. {
  96. return (raw ?? "").Trim().ToLowerInvariant() switch
  97. {
  98. "completed" or "done" => Completed,
  99. "doing" or "in_progress" => InProgress,
  100. "cancelled" or "canceled" => Cancelled,
  101. _ => Pending,
  102. };
  103. }
  104. public static bool CanTransition(string from, string to)
  105. {
  106. from = Normalize(from);
  107. to = Normalize(to);
  108. if (from == to) return true;
  109. return (from, to) switch
  110. {
  111. (Pending, InProgress) => true,
  112. (Pending, Cancelled) => true,
  113. (InProgress, Completed) => true,
  114. (InProgress, Cancelled) => true,
  115. (InProgress, Pending) => true,
  116. (Cancelled, Pending) => true,
  117. _ => false,
  118. };
  119. }
  120. public static bool IsOpen(string? status)
  121. {
  122. var normalized = Normalize(status);
  123. return normalized is Pending or InProgress;
  124. }
  125. public static bool IsOverdue(string? status, DateTime? dueDate, DateTime today) =>
  126. IsOpen(status) && dueDate.HasValue && dueDate.Value.Date < today.Date;
  127. public static string DisplayStatus(string? status, DateTime? dueDate, DateTime today) =>
  128. IsOverdue(status, dueDate, today) ? "overdue" : Normalize(status);
  129. }
  130. public static class SmartOpsImprovementNoticeType
  131. {
  132. public const string Assigned = "assigned";
  133. public const string DueSoon = "due_soon";
  134. public const string Overdue = "overdue";
  135. public const string StatusChanged = "status_changed";
  136. public static string NoticeKey(long tenantId, long actionId, string noticeType, DateTime date) =>
  137. $"{tenantId}:{actionId}:{noticeType}:{date:yyyy-MM-dd}";
  138. }
  139. [SugarTable("ado_smart_ops_improvement_verify_log", "改善计划有效性评价日志")]
  140. [SugarIndex("idx_improve_verify_log", nameof(TenantId), OrderByType.Asc, nameof(PlanId), OrderByType.Asc, nameof(CreateTime), OrderByType.Desc)]
  141. public class AdoSmartOpsImprovementVerifyLog : ITenantIdFilter
  142. {
  143. [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
  144. public long Id { get; set; }
  145. [SugarColumn(ColumnName = "tenant_id")]
  146. public long? TenantId { get; set; }
  147. [SugarColumn(ColumnName = "plan_id")]
  148. public long PlanId { get; set; }
  149. [SugarColumn(ColumnName = "auto_result", Length = 32, IsNullable = true)]
  150. public string? AutoResult { get; set; }
  151. [SugarColumn(ColumnName = "manual_result", Length = 32, IsNullable = true)]
  152. public string? ManualResult { get; set; }
  153. [SugarColumn(ColumnName = "remark", ColumnDataType = "text", IsNullable = true)]
  154. public string? Remark { get; set; }
  155. [SugarColumn(ColumnName = "operator_user_id", IsNullable = true)]
  156. public long? OperatorUserId { get; set; }
  157. [SugarColumn(ColumnName = "create_time")]
  158. public DateTime CreateTime { get; set; } = DateTime.Now;
  159. }