- 未提交、新增已拒绝的黑名单记录可直接删除,不进入删除审批 - 已加入、删除已拒绝仍按原逻辑发起删除审批 - 新增审批中、删除审批中仍禁止删除 - 补充未生效状态可直接删除的状态机单测,45/45 通过
95 lines
3.7 KiB
C#
95 lines
3.7 KiB
C#
using YLErp.Model;
|
|
|
|
namespace YLErp.Modules.ClientModule
|
|
{
|
|
public static class ClientBlackApprovalPolicy
|
|
{
|
|
public static readonly string[] EffectiveStates =
|
|
{
|
|
client_black.已加入,
|
|
client_black.删除审批中,
|
|
client_black.删除已拒绝
|
|
};
|
|
|
|
public static bool IsEffective(string state)
|
|
{
|
|
return EffectiveStates.Contains(state);
|
|
}
|
|
|
|
public static bool CanSubmitAddition(string state)
|
|
{
|
|
return state == client_black.未提交 || state == client_black.新增已拒绝;
|
|
}
|
|
|
|
public static ClientBlackAdditionResult GetAdditionResult(bool hasApprovalProcess)
|
|
{
|
|
return hasApprovalProcess
|
|
? new ClientBlackAdditionResult(client_black.未提交, 0, false)
|
|
: new ClientBlackAdditionResult(client_black.已加入, -2, true);
|
|
}
|
|
|
|
public static bool CanRequestRemoval(string state)
|
|
{
|
|
return state == client_black.已加入 || state == client_black.删除已拒绝;
|
|
}
|
|
|
|
public static bool CanDeleteDraft(string state)
|
|
{
|
|
return state == client_black.未提交 || state == client_black.新增已拒绝;
|
|
}
|
|
|
|
public static ClientBlackRemovalResult GetRemovalResult(bool hasApprovalProcess)
|
|
{
|
|
return hasApprovalProcess
|
|
? new ClientBlackRemovalResult(client_black.删除审批中, 1, false)
|
|
: new ClientBlackRemovalResult(client_black.已加入, -2, true);
|
|
}
|
|
|
|
public static bool CanReplaceRemarks(string state)
|
|
{
|
|
return state != client_black.新增审批中 && state != client_black.删除审批中;
|
|
}
|
|
|
|
public static bool CanWithdraw(string state, int approvalProcess)
|
|
{
|
|
return approvalProcess == 1 &&
|
|
(state == client_black.新增审批中 || state == client_black.删除审批中);
|
|
}
|
|
|
|
public static string GetRejectedState(string state)
|
|
{
|
|
return state switch
|
|
{
|
|
client_black.新增审批中 => client_black.新增已拒绝,
|
|
client_black.删除审批中 => client_black.删除已拒绝,
|
|
_ => throw new ArgumentException("当前状态不允许拒绝审批", nameof(state))
|
|
};
|
|
}
|
|
|
|
public static ClientBlackWithdrawResult GetWithdrawResult(string state)
|
|
{
|
|
return state switch
|
|
{
|
|
client_black.新增审批中 => new ClientBlackWithdrawResult(client_black.未提交, 0),
|
|
client_black.删除审批中 => new ClientBlackWithdrawResult(client_black.已加入, -2),
|
|
_ => throw new ArgumentException("当前状态不允许撤回审批", nameof(state))
|
|
};
|
|
}
|
|
|
|
public static ClientBlackFinalResult GetFinalResult(string state)
|
|
{
|
|
return state switch
|
|
{
|
|
client_black.新增审批中 => new ClientBlackFinalResult(client_black.已加入, false),
|
|
client_black.删除审批中 => new ClientBlackFinalResult(null, true),
|
|
_ => throw new ArgumentException("当前状态不允许完成审批", nameof(state))
|
|
};
|
|
}
|
|
}
|
|
|
|
public readonly record struct ClientBlackWithdrawResult(string State, int ApprovalProcess);
|
|
public readonly record struct ClientBlackFinalResult(string State, bool ShouldDelete);
|
|
public readonly record struct ClientBlackAdditionResult(string State, int ApprovalProcess, bool IsEffective);
|
|
public readonly record struct ClientBlackRemovalResult(string State, int ApprovalProcess, bool ShouldDelete);
|
|
}
|