修复合同到期时间与终止恢复规则
- 合同动作中文化并将到期时间设为必填\n- 隐藏修订记录无业务意义的删除时间\n- 禁止已终止合同直接启用,统一三端状态规则\n- 补充回归测试、模拟数据回填和中文文档
This commit is contained in:
@@ -144,11 +144,11 @@ func CreateGasorderContract(ctx *gin.Context) {
|
||||
DefaultDeliveryFee int64 `json:"default_delivery_fee"`
|
||||
SignedAt time.Time `json:"signed_at" binding:"required"`
|
||||
EffectiveAt time.Time `json:"effective_at" binding:"required"`
|
||||
ExpiredAt *time.Time `json:"expired_at"`
|
||||
ExpiredAt *time.Time `json:"expired_at" binding:"required"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || request.DefaultDeliveryFee < 0 ||
|
||||
request.SignedAt.IsZero() || request.EffectiveAt.IsZero() ||
|
||||
(request.ExpiredAt != nil && !request.ExpiredAt.After(request.EffectiveAt)) {
|
||||
request.ExpiredAt == nil || !request.ExpiredAt.After(request.EffectiveAt) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
@@ -213,10 +213,10 @@ func UpdateGasorderContract(ctx *gin.Context) {
|
||||
DefaultDeliveryFee int64 `json:"default_delivery_fee"`
|
||||
SignedAt time.Time `json:"signed_at" binding:"required"`
|
||||
EffectiveAt time.Time `json:"effective_at" binding:"required"`
|
||||
ExpiredAt *time.Time `json:"expired_at"`
|
||||
ExpiredAt *time.Time `json:"expired_at" binding:"required"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil || request.DefaultDeliveryFee < 0 ||
|
||||
(request.ExpiredAt != nil && !request.ExpiredAt.After(request.EffectiveAt)) {
|
||||
request.ExpiredAt == nil || !request.ExpiredAt.After(request.EffectiveAt) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
@@ -307,11 +307,11 @@ func TerminateGasorderContract(ctx *gin.Context) {
|
||||
func RenewGasorderContract(ctx *gin.Context) {
|
||||
var request struct {
|
||||
EffectiveAt time.Time `json:"effective_at" binding:"required"`
|
||||
ExpiredAt *time.Time `json:"expired_at"`
|
||||
ExpiredAt *time.Time `json:"expired_at" binding:"required"`
|
||||
Reason string `json:"reason" binding:"required"`
|
||||
}
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil ||
|
||||
(request.ExpiredAt != nil && !request.ExpiredAt.After(request.EffectiveAt)) {
|
||||
request.ExpiredAt == nil || !request.ExpiredAt.After(request.EffectiveAt) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
@@ -351,7 +351,7 @@ func changeGasorderContract(ctx *gin.Context, action string, target int) {
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Where("identity = ?", ctx.Param("identity")).First(&contract).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if action == "activate" && contract.ContractStatus != common.StatusDraft && contract.ContractStatus != common.StatusTerminated {
|
||||
if action == "activate" && !contractCanActivate(contract.ContractStatus) {
|
||||
return errContractCannotActivate
|
||||
}
|
||||
if action == "terminate" && contract.ContractStatus != common.StatusActive {
|
||||
@@ -395,6 +395,11 @@ func changeGasorderContract(ctx *gin.Context, action string, target int) {
|
||||
infra.Response.Success(ctx, gin.H{"updated": true, "contract_status": target})
|
||||
}
|
||||
|
||||
// contractCanActivate 限制启用动作仅用于首次启用草稿合同,终止合同必须通过续签恢复。
|
||||
func contractCanActivate(status int) bool {
|
||||
return status == common.StatusDraft
|
||||
}
|
||||
|
||||
// isContractChangeBusinessError 仅允许预定义业务原因透传,避免泄露数据库内部错误。
|
||||
func isContractChangeBusinessError(err error) bool {
|
||||
return errors.Is(err, errContractCannotActivate) ||
|
||||
|
||||
@@ -106,6 +106,18 @@ func TestContractRevisionKeepsSingleContractHistory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestTerminatedContractCannotActivate 验证终止合同不能绕过续签流程直接恢复生效。
|
||||
func TestTerminatedContractCannotActivate(t *testing.T) {
|
||||
if !contractCanActivate(common.StatusDraft) {
|
||||
t.Fatal("草稿合同应允许首次启用")
|
||||
}
|
||||
for _, status := range []int{common.StatusActive, common.StatusExpired, common.StatusTerminated} {
|
||||
if contractCanActivate(status) {
|
||||
t.Fatalf("合同状态 %d 不应允许直接启用", status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContractDeliveryRequiresDirectGasOwnership(t *testing.T) {
|
||||
if !contractDeliveryMatchesGas(10, 10) {
|
||||
t.Fatal("合同气站的直属配送点被错误拒绝")
|
||||
|
||||
Reference in New Issue
Block a user