fix: 换货原因长度上限放宽到 500 字

从微信复制的多行换货说明常超过 100 字,创建换货单时报参数验证失败。
请求校验与模型字段长度同步改为 500;生产库已手动执行 ALTER,迁移文件随 Iteration/8-11 编号补充。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-11-03 11:15:28 +09:00
parent adcd4f5e9d
commit f44f1be0d1
3 changed files with 36 additions and 2 deletions

View File

@@ -9,7 +9,7 @@ type CreateExchangeRequest struct {
FlowType string `json:"flow_type" validate:"omitempty,oneof=shipping direct" enum:"shipping,direct" description:"换货流程类型 (shipping:物流换货, direct:直接换货)"`
NewIdentifier string `json:"new_identifier" validate:"omitempty,min=1,max=100" minLength:"1" maxLength:"100" description:"新资产输入标识,direct 流程必填;卡支持 ICCID、接入号、虚拟号,设备支持虚拟号、IMEI、SN"`
MigrateData *bool `json:"migrate_data" description:"是否执行全量迁移,direct 流程未传按 false 处理"`
ExchangeReason string `json:"exchange_reason" validate:"required,min=1,max=100" required:"true" minLength:"1" maxLength:"100" description:"换货原因"`
ExchangeReason string `json:"exchange_reason" validate:"required,min=1,max=500" required:"true" minLength:"1" maxLength:"500" description:"换货原因"`
Remark *string `json:"remark" validate:"omitempty,max=500" maxLength:"500" description:"备注"`
}

View File

@@ -0,0 +1,34 @@
package dto
import (
"strings"
"testing"
"github.com/go-playground/validator/v10"
)
// 换货原因按字符计数,上限 500:从微信复制的多行说明(含换行)不超过 500 字都应通过校验。
func TestCreateExchangeRequest_ExchangeReasonLength(t *testing.T) {
validate := validator.New()
multiLine := "862639070766110(门店:862639070766110机头,862639070743218后盖)\n\n" +
"862639070743218(厂家:862639070766110后盖,862639070743218机头)\n\n这两台后盖机头窜了。"
cases := []struct {
name string
reason string
wantErr bool
}{
{name: "多行说明124字", reason: multiLine, wantErr: false},
{name: "500个中文字", reason: strings.Repeat("换", 500), wantErr: false},
{name: "501个中文字", reason: strings.Repeat("换", 501), wantErr: true},
{name: "空", reason: "", wantErr: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
req := CreateExchangeRequest{OldAssetType: "device", OldIdentifier: "862639070743218", ExchangeReason: tc.reason}
err := validate.Struct(req)
if (err != nil) != tc.wantErr {
t.Fatalf("wantErr=%v, err=%v", tc.wantErr, err)
}
})
}
}

View File

@@ -56,7 +56,7 @@ type ExchangeOrder struct {
CompletedAt *time.Time `gorm:"column:completed_at;comment:换货完成时间,物流换货和直接换货完成后写入" json:"completed_at,omitempty"`
// 业务信息
ExchangeReason string `gorm:"column:exchange_reason;type:varchar(100);not null;comment:换货原因" json:"exchange_reason"`
ExchangeReason string `gorm:"column:exchange_reason;type:varchar(500);not null;comment:换货原因" json:"exchange_reason"`
Remark *string `gorm:"column:remark;type:text;comment:备注" json:"remark,omitempty"`
Status int `gorm:"column:status;type:int;not null;default:1;index:idx_exchange_order_status;comment:换货状态 1-待填写信息 2-待发货 3-已发货待确认 4-已完成 5-已取消" json:"status"`