using System;
using System.Collections.Generic;
using NPP.SmartSchedue.Api.Contracts.Services.Integration.Output;
namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Models
{
///
/// 验证违规信息
/// 通用的验证违规模型,用于各类验证场景
///
public class ValidationViolation
{
///
/// 违规ID
///
public string ViolationId { get; set; } = Guid.NewGuid().ToString();
///
/// 违规类型
///
public string ViolationType { get; set; } = string.Empty;
///
/// 违规描述
///
public string Description { get; set; } = string.Empty;
///
/// 违规严重程度
///
public ViolationSeverity Severity { get; set; } = ViolationSeverity.Medium;
///
/// 相关实体ID
///
public long EntityId { get; set; }
///
/// 相关实体类型
///
public string EntityType { get; set; } = string.Empty;
///
/// 违规详细信息
///
public Dictionary Details { get; set; } = new();
///
/// 建议解决方案
///
public List SuggestedSolutions { get; set; } = new();
///
/// 发现时间
///
public DateTime DetectedAt { get; set; } = DateTime.Now;
///
/// 是否为阻塞性问题
///
public bool IsBlockingIssue { get; set; } = false;
///
/// 业务影响度 (1-10)
///
public int BusinessImpact { get; set; } = 5;
///
/// 违规分类
///
public ViolationCategory Category { get; set; } = ViolationCategory.General;
///
/// 是否可通过审批强制执行
///
public bool CanOverrideWithApproval { get; set; } = true;
///
/// 所需审批级别
///
public ApprovalLevel RequiredApprovalLevel { get; set; } = ApprovalLevel.None;
///
/// 违规风险评估
///
public ViolationRiskAssessment RiskAssessment { get; set; } = new();
}
///
/// 验证警告信息
/// 通用的验证警告模型,用于各类验证场景
///
public class ValidationWarning
{
///
/// 警告ID
///
public string WarningId { get; set; } = Guid.NewGuid().ToString();
///
/// 警告类型
///
public string WarningType { get; set; } = string.Empty;
///
/// 警告消息
///
public string Message { get; set; } = string.Empty;
///
/// 警告级别
///
public WarningLevel Level { get; set; } = WarningLevel.Medium;
///
/// 相关实体ID
///
public long EntityId { get; set; }
///
/// 相关实体类型
///
public string EntityType { get; set; } = string.Empty;
///
/// 建议关注程度 (1-10)
///
public int AttentionLevel { get; set; } = 5;
///
/// 相关任务ID列表
///
public List RelatedTaskIds { get; set; } = new();
///
/// 建议操作
///
public string SuggestedAction { get; set; } = string.Empty;
///
/// 发现时间
///
public DateTime DetectedAt { get; set; } = DateTime.Now;
}
///
/// 约束违规信息
/// 专门用于约束评估过程中的违规记录,比通用违规类更轻量
///
public class ConstraintViolation
{
///
/// 违规ID
///
public string ViolationId { get; set; } = Guid.NewGuid().ToString();
///
/// 违规类型
///
public string ViolationType { get; set; } = string.Empty;
///
/// 违规描述
///
public string Description { get; set; } = string.Empty;
///
/// 违规严重程度
///
public ViolationSeverity Severity { get; set; } = ViolationSeverity.Medium;
///
/// 违规详细信息
///
public Dictionary Details { get; set; } = new();
///
/// 发现时间
///
public DateTime DetectedAt { get; set; } = DateTime.Now;
///
/// 是否为阻塞性问题
///
public bool IsBlockingIssue { get; set; } = false;
///
/// 业务影响度 (1-10)
///
public int BusinessImpact { get; set; } = 5;
///
/// 违规分类
///
public ViolationCategory Category { get; set; } = ViolationCategory.General;
///
/// 是否可通过审批强制执行
///
public bool CanOverrideWithApproval { get; set; } = true;
///
/// 所需审批级别
///
public ApprovalLevel RequiredApprovalLevel { get; set; } = ApprovalLevel.None;
///
/// 建议解决方案
///
public List SuggestedSolutions { get; set; } = new();
///
/// 违规风险评估
///
public ViolationRiskAssessment RiskAssessment { get; set; } = new();
///
/// 创建新的约束违规实例
///
public static ConstraintViolation Create(string violationType, string description, ViolationSeverity severity = ViolationSeverity.Medium)
{
return new ConstraintViolation
{
ViolationType = violationType,
Description = description,
Severity = severity,
DetectedAt = DateTime.Now
};
}
///
/// 创建阻塞性违规
///
public static ConstraintViolation CreateBlocking(string violationType, string description, ViolationSeverity severity = ViolationSeverity.High)
{
return new ConstraintViolation
{
ViolationType = violationType,
Description = description,
Severity = severity,
IsBlockingIssue = true,
DetectedAt = DateTime.Now
};
}
}
///
/// 违规类型枚举
/// 定义人员分配过程中可能出现的各种违规类型
///
public enum ViolationType
{
///
/// 通用违规
///
General = 0,
///
/// 资质不匹配
/// 业务场景:人员资质与任务要求不符
///
QualificationMismatch = 1,
///
/// 时间冲突
/// 业务场景:人员在同一时间段被分配多个任务
///
TimeConflict = 2,
///
/// 工作量超限
/// 业务场景:人员工作负载超过限制
///
WorkloadExceeded = 3,
///
/// 班次规则冲突
/// 业务场景:违反班次连续性、同天班次等规则
///
ShiftRuleViolation = 4,
///
/// 工作限制违规
/// 业务场景:违反连续工作天数、周班次数等限制
///
WorkLimitViolation = 5,
///
/// 系统状态违规
/// 业务场景:人员状态异常、系统配置问题等
///
SystemStateViolation = 6,
///
/// 业务规则冲突
/// 业务场景:违反项目特定规则、部门限制等
///
BusinessRuleViolation = 7
}
///
/// 违规严重程度枚举
/// 定义违规的严重程度级别,用于决策和审批流程
///
public enum ViolationSeverity
{
///
/// 信息级 - 纯信息提示,不影响分配
/// 业务场景:建议性信息、优化提示、统计数据
/// 处理方式:记录但不影响分配决策
///
Info = 0,
///
/// 低级 - 轻微问题,可接受
/// 业务场景:次优选择、轻微偏好违背、资源利用率稍低
/// 处理方式:允许分配,但降低优先级
///
Low = 1,
///
/// 警告级 - 需要关注但不阻止
/// 业务场景:连续工作天数较多、工作负载偏高、非首选班次
/// 处理方式:允许分配,但给出明确警告
///
Warning = 2,
///
/// 中级 - 需要关注的问题
/// 业务场景:技能匹配度不理想、班次连续性问题、资源冲突风险
/// 处理方式:默认阻止分配,可通过管理员审批
///
Medium = 3,
///
/// 高级 - 重要问题,建议阻止
/// 业务场景:工作限制超出、重要资质缺失、严重时间冲突
/// 处理方式:强烈建议阻止,需要高级权限审批
///
High = 4,
///
/// 错误级 - 业务规则违反,必须处理
/// 业务场景:违反硬性约束、安全规定冲突、合规性问题
/// 处理方式:阻止分配,必须修复后重试
///
Error = 5,
///
/// 严重级 - 系统级问题,完全阻止
/// 业务场景:数据完整性问题、系统状态异常、关键资源不可用
/// 处理方式:完全阻止分配,需要系统级修复
///
Critical = 6
}
///
/// 警告级别枚举
///
public enum WarningLevel
{
///
/// 低级警告
///
Low = 1,
///
/// 中级警告
///
Medium = 2,
///
/// 高级警告
///
High = 3
}
///
/// 违规分类枚举
///
public enum ViolationCategory
{
///
/// 通用违规
///
General = 0,
///
/// 资质相关违规
///
Qualification = 1,
///
/// 时间冲突违规
///
TimeConflict = 2,
///
/// 工作限制违规
///
WorkLimit = 3,
///
/// 班次规则违规
///
ShiftRule = 4,
///
/// 业务规则违规
///
BusinessRule = 5,
///
/// 安全规定违规
///
Safety = 6,
///
/// 合规性违规
///
Compliance = 7,
///
/// 系统状态违规
///
SystemState = 8
}
///
/// 审批级别枚举
///
public enum ApprovalLevel
{
///
/// 无需审批
///
None = 0,
///
/// 自动审批
///
Automatic = 1,
///
/// 主管审批
///
Supervisor = 2,
///
/// 管理员审批
///
Manager = 3,
///
/// 高级管理员审批
///
SeniorManager = 4,
///
/// 系统管理员审批
///
SystemAdmin = 5
}
///
/// 违规风险评估
///
public class ViolationRiskAssessment
{
///
/// 安全风险等级 (1-10)
///
public int SafetyRiskLevel { get; set; } = 1;
///
/// 合规风险等级 (1-10)
///
public int ComplianceRiskLevel { get; set; } = 1;
///
/// 运营风险等级 (1-10)
///
public int OperationalRiskLevel { get; set; } = 1;
///
/// 财务风险等级 (1-10)
///
public int FinancialRiskLevel { get; set; } = 1;
///
/// 综合风险评分 (1-10)
///
public double OverallRiskScore => (SafetyRiskLevel + ComplianceRiskLevel + OperationalRiskLevel + FinancialRiskLevel) / 4.0;
///
/// 风险描述
///
public string RiskDescription { get; set; } = string.Empty;
///
/// 缓解措施建议
///
public List MitigationSuggestions { get; set; } = new();
}
///
/// 违规严重程度判定辅助类
/// 智能排班系统违规严重程度业务逻辑判定器
/// 深度业务思考:根据不同业务场景智能判定违规的真实严重程度和处理方式
///
public static class ViolationSeverityJudge
{
///
/// 判定是否为阻塞性违规
/// 深度业务思考:根据严重程度和业务影响综合判断是否应该阻止分配
///
public static bool IsBlockingViolation(ViolationSeverity severity, int businessImpact = 5, ViolationCategory category = ViolationCategory.General)
{
// 信息级和低级违规不阻塞
if (severity <= ViolationSeverity.Low) return false;
// 警告级违规根据业务影响和分类判断
if (severity == ViolationSeverity.Warning)
{
// 安全和合规相关的警告需要阻塞
if (category == ViolationCategory.Safety || category == ViolationCategory.Compliance)
return businessImpact >= 7;
// 其他警告不阻塞
return false;
}
// 中级违规根据分类判断
if (severity == ViolationSeverity.Medium)
{
// 资质和安全相关的中级违规需要阻塞
return category == ViolationCategory.Qualification ||
category == ViolationCategory.Safety ||
category == ViolationCategory.Compliance;
}
// 高级及以上违规都需要阻塞
return severity >= ViolationSeverity.High;
}
///
/// 计算违规失败阈值
/// 深度业务思考:不同业务场景下的违规容忍度不同
///
public static ViolationSeverity GetFailureThreshold(ValidationContext context)
{
// 紧急情况下提高容忍度
if (context.IsEmergencyMode)
return ViolationSeverity.Error;
// 关键任务降低容忍度
if (context.IsCriticalTask)
return ViolationSeverity.Medium;
// 安全相关任务严格控制
if (context.IsSafetyRelated)
return ViolationSeverity.Warning;
// 默认阈值:高级违规
return ViolationSeverity.High;
}
///
/// 获取所需审批级别
///
public static ApprovalLevel GetRequiredApprovalLevel(ViolationSeverity severity, ViolationCategory category)
{
return (severity, category) switch
{
(ViolationSeverity.Info or ViolationSeverity.Low, _) => ApprovalLevel.None,
(ViolationSeverity.Warning, ViolationCategory.Safety or ViolationCategory.Compliance) => ApprovalLevel.Supervisor,
(ViolationSeverity.Warning, _) => ApprovalLevel.Automatic,
(ViolationSeverity.Medium, ViolationCategory.Safety) => ApprovalLevel.Manager,
(ViolationSeverity.Medium, _) => ApprovalLevel.Supervisor,
(ViolationSeverity.High, ViolationCategory.Safety or ViolationCategory.Compliance) => ApprovalLevel.SeniorManager,
(ViolationSeverity.High, _) => ApprovalLevel.Manager,
(ViolationSeverity.Error, ViolationCategory.SystemState) => ApprovalLevel.SystemAdmin,
(ViolationSeverity.Error, _) => ApprovalLevel.SeniorManager,
(ViolationSeverity.Critical, _) => ApprovalLevel.SystemAdmin,
_ => ApprovalLevel.None
};
}
///
/// 判断是否可以通过审批强制执行
///
public static bool CanOverrideWithApproval(ViolationSeverity severity, ViolationCategory category)
{
// 系统状态和关键安全违规不能强制执行
if (category == ViolationCategory.SystemState && severity >= ViolationSeverity.Error)
return false;
if (category == ViolationCategory.Safety && severity >= ViolationSeverity.Critical)
return false;
// 严重级系统违规不能强制执行
if (severity == ViolationSeverity.Critical &&
(category == ViolationCategory.SystemState || category == ViolationCategory.Compliance))
return false;
return true;
}
///
/// 计算违规权重
/// 用于验证评分计算
///
public static double GetViolationWeight(ViolationSeverity severity)
{
return severity switch
{
ViolationSeverity.Info => 0.5,
ViolationSeverity.Low => 1.0,
ViolationSeverity.Warning => 2.0,
ViolationSeverity.Medium => 5.0,
ViolationSeverity.High => 10.0,
ViolationSeverity.Error => 20.0,
ViolationSeverity.Critical => 50.0,
_ => 1.0
};
}
}
///
/// 验证上下文
/// 用于判定违规严重程度的业务上下文
///
public class ValidationContext
{
///
/// 是否为紧急模式
///
public bool IsEmergencyMode { get; set; } = false;
///
/// 是否为关键任务
///
public bool IsCriticalTask { get; set; } = false;
///
/// 是否与安全相关
///
public bool IsSafetyRelated { get; set; } = false;
///
/// 业务优先级 (1-10)
///
public int BusinessPriority { get; set; } = 5;
///
/// 验证模式
///
public ValidationMode Mode { get; set; } = ValidationMode.Standard;
///
/// 额外上下文信息
///
public Dictionary AdditionalContext { get; set; } = new();
}
///
/// 验证模式枚举
///
public enum ValidationMode
{
///
/// 标准验证
///
Standard = 0,
///
/// 严格验证
///
Strict = 1,
///
/// 宽松验证
///
Lenient = 2,
///
/// 紧急验证
///
Emergency = 3
}
///
/// 优化评分结果
/// 用于记录人员分配优化过程中的各项评分和决策信息
///
public class OptimizationScoreResult
{
///
/// 候选人信息
///
public object Candidate { get; set; }
///
/// 各维度评分
///
public Dictionary DimensionScores { get; set; } = new();
///
/// 优化总分
///
public double OptimizationScore { get; set; }
///
/// 置信度
///
public double Confidence { get; set; }
///
/// 推荐等级
///
public RecommendationLevel RecommendationLevel { get; set; }
///
/// 优化理由
///
public string OptimizationReason { get; set; } = string.Empty;
///
/// 风险评估
///
public RiskAssessment RiskAssessment { get; set; } = new();
}
///
/// 推荐等级枚举
///
public enum RecommendationLevel
{
///
/// 强烈推荐
///
HighlyRecommended = 5,
///
/// 推荐
///
Recommended = 4,
///
/// 可接受
///
Acceptable = 3,
///
/// 不推荐
///
NotRecommended = 2,
///
/// 不可行
///
NotFeasible = 1
}
///
/// 风险评估
///
public class RiskAssessment
{
///
/// 风险因子列表
///
public List RiskFactors { get; set; } = new();
///
/// 总体风险等级
///
public RiskLevel OverallRiskLevel { get; set; } = RiskLevel.Low;
///
/// 风险评分
///
public double RiskScore { get; set; }
///
/// 风险描述
///
public string RiskDescription { get; set; } = string.Empty;
///
/// 缓解建议
///
public List MitigationSuggestions { get; set; } = new();
}
///
/// 风险因子
///
public class RiskFactor
{
///
/// 风险类型
///
public string RiskType { get; set; } = string.Empty;
///
/// 风险描述
///
public string Description { get; set; } = string.Empty;
///
/// 风险等级
///
public RiskLevel Level { get; set; } = RiskLevel.Low;
///
/// 发生概率 (0-100)
///
public double Probability { get; set; }
///
/// 影响程度 (0-100)
///
public double Impact { get; set; }
}
///
/// 决策评分
///
public class DecisionScore
{
///
/// 最终评分
///
public double FinalScore { get; set; }
///
/// 置信度
///
public double ConfidenceLevel { get; set; }
///
/// 风险等级
///
public RiskLevel RiskLevel { get; set; } = RiskLevel.Low;
///
/// 决策理由
///
public string DecisionReason { get; set; } = string.Empty;
}
}