优化结构

This commit is contained in:
Yvan
2026-08-28 17:42:53 +08:00
parent 9148c10c0c
commit 8d290f2954
9 changed files with 27 additions and 17 deletions
@@ -244,9 +244,6 @@ func validateCommunicationIntegrationConfig(kind, provider string, values map[st
}
for _, field := range definition.Fields {
value := integrationText(values, field.Key)
if provider == bizpayment.PaymentDouyin && field.Key == "platform_serial_no" {
value = integrationFirst(values, "platform_serial_no", "platform_cert_serial")
}
if field.Required && value == "" {
return fmt.Errorf("%s 缺少配置字段 %s", provider, field.Key)
}
@@ -316,7 +313,11 @@ func validatePaymentIntegrationConfig(provider string, values map[string]any) er
return errors.New("不支持的支付渠道")
}
for _, field := range definition.Fields {
if field.Required && integrationText(values, field.Key) == "" {
value := integrationText(values, field.Key)
if provider == bizpayment.PaymentDouyin && field.Key == "platform_serial_no" {
value = integrationFirst(values, "platform_serial_no", "platform_cert_serial")
}
if field.Required && value == "" {
return fmt.Errorf("%s 缺少配置字段 %s", provider, field.Key)
}
}
@@ -164,7 +164,7 @@ var integrationDefinitions = map[string][]IntegrationConfigDefinition{
paymentDefinition(bizpayment.PaymentApple, "Apple IAP", "Apple App Store Server API", map[string]any{"issuer_id": "", "key_id": "", "bundle_id": "", "private_key": "", "price_divisor": 10, "environment": "production", "test_product_id": "", "test_transaction_id": ""},
integrationField("issuer_id", "Issuer ID", true, false, "text"), integrationField("key_id", "Key ID", true, false, "text"), integrationField("bundle_id", "Bundle ID", true, false, "text"), integrationField("private_key", "P8 私钥", true, true, "textarea"), integrationField("price_divisor", "价格除数", false, false, "number"), integrationSelect("environment", "环境", false, "production", "sandbox"), integrationField("test_product_id", "测试商品 ID", false, false, "text"), integrationField("test_transaction_id", "沙箱交易 ID", false, false, "text")),
paymentDefinition(bizpayment.PaymentDouyin, "抖音支付", "抖音开放平台支付", map[string]any{"app_id": "", "merchant_id": "", "serial_no": "", "api_key": "", "private_key": "", "platform_cert": "", "platform_serial_no": "", "trade_type": "jsapi", "environment": "production"},
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("merchant_id", "商户号", true, false, "text"), integrationField("serial_no", "商户证书序列号", true, false, "text"), integrationField("api_key", "API 密钥", true, true, "password"), integrationField("private_key", "商户私钥", true, true, "textarea"), integrationField("platform_cert", "平台证书", true, true, "textarea"), integrationField("platform_serial_no", "平台证书序列号", false, false, "text"), integrationSelect("trade_type", "默认交易类型", false, "app", "jsapi", "h5", "native"), integrationSelect("environment", "环境", false, "production")),
integrationField("app_id", "应用 ID", true, false, "text"), integrationField("merchant_id", "商户号", true, false, "text"), integrationField("serial_no", "商户证书序列号", true, false, "text"), integrationField("api_key", "API 密钥", true, true, "password"), integrationField("private_key", "商户私钥", true, true, "textarea"), integrationField("platform_cert", "平台证书", true, true, "textarea"), integrationField("platform_serial_no", "平台证书序列号", true, false, "text"), integrationSelect("trade_type", "默认交易类型", false, "app", "jsapi", "h5", "native"), integrationSelect("environment", "环境", false, "production")),
paymentDefinition(bizpayment.PaymentQQ, "QQ 钱包", "QQ 钱包支付", map[string]any{"mch_id": "", "api_key": "", "sign_type": "MD5", "trade_type": "NATIVE", "cert_file": "", "key_file": "", "environment": "production"},
integrationField("mch_id", "商户号", true, false, "text"), integrationField("api_key", "API 密钥", true, true, "password"), integrationSelect("sign_type", "签名算法", false, "MD5", "HMAC-SHA256"), integrationSelect("trade_type", "默认交易类型", false, "JSAPI", "NATIVE", "APP", "MICROPAY"), integrationField("cert_file", "退款证书路径", false, false, "text"), integrationField("key_file", "退款私钥路径", false, true, "text"), integrationSelect("environment", "环境", false, "production")),
paymentDefinition(bizpayment.PaymentAllinPay, "通联支付", "通联收银宝支付", map[string]any{"cus_id": "", "app_id": "", "private_key": "", "public_key": "", "org_id": "", "pay_type": "W02", "query_order_type": "reqsn", "currency": "CNY", "environment": "production"},
+8 -2
View File
@@ -105,10 +105,16 @@ func (r *mediaRepo) DeleteUploadSession(ctx context.Context, id uint) error {
}
func (r *mediaRepo) UpsertChunk(ctx context.Context, uploadID uint, v *system.UploadChunk) error {
po := uploadChunkPO{UploadID: uploadID, ChunkIndex: v.Index, ChunkHash: v.Hash, Size: v.Size}
return r.data.DB().WithContext(ctx).Clauses(clause.OnConflict{
if err := r.data.DB().WithContext(ctx).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "upload_id"}, {Name: "chunk_index"}},
DoUpdates: clause.AssignmentColumns([]string{"chunk_hash", "size", "updated_at", "deleted_at"}),
}).Create(&po).Error
}).Create(&po).Error; err != nil {
return err
}
if err := r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("id = ? AND status = ?", uploadID, "uploading").Update("updated_at", time.Now()).Error; err != nil {
return err
}
return nil
}
func (r *mediaRepo) ListChunks(ctx context.Context, uploadID uint) ([]*system.UploadChunk, error) {
var pos []uploadChunkPO
+3
View File
@@ -309,6 +309,9 @@ func (h *Audit) CreateError(c *gin.Context) {
return
}
if err := h.recorder.CreateErrorMutationRequest(c.Request.Context(), &req); err != nil {
if h.logger != nil {
h.logger.ErrorContext(c.Request.Context(), "创建错误记录失败", "mod", "audit", "error", err)
}
Fail(c, "创建失败")
return
}
+1 -1
View File
@@ -70,7 +70,7 @@ func failureLogModule(path string) string {
}
func expectedClientFailure(message string) bool {
for _, value := range []string{"参数错误", "请输入用户名和密码", "验证码错误", "用户名不存在或者密码错误", "用户被禁止登录", "账号已锁定", "请求太过频繁", "权限不足", "密码已过期", "未登录", "token 失效", "令牌失效"} {
for _, value := range []string{"参数错误", "请输入用户名和密码", "验证码错误", "用户名不存在或者密码错误", "用户被禁止登录", "账号已锁定", "请求太过频繁", "权限不足", "密码已过期", "未登录", "token 失效", "token无效", "令牌失效"} {
if strings.Contains(message, value) {
return true
}
+1 -1
View File
@@ -13,7 +13,7 @@ import (
func SecurityRateLimit(settings *systemservice.SecurityService) gin.HandlerFunc {
return func(c *gin.Context) {
path := strings.TrimSuffix(c.Request.URL.Path, "/")
if !strings.HasSuffix(path, "/base/login") && !strings.HasSuffix(path, "/base/captcha") {
if !strings.HasSuffix(path, "/base/login") && !strings.HasSuffix(path, "/base/captcha") && !strings.HasSuffix(path, "/sysError/createSysError") {
c.Next()
return
}
+1 -1
View File
@@ -29,5 +29,5 @@ func RegisterAudit(group, public *gin.RouterGroup, h *handler.Audit) {
errors.PUT("/updateSysError", h.UpdateError)
errors.GET("/findSysError", h.Error)
errors.GET("/getSysErrorList", h.Errors)
public.Group("/sysError").POST("/createSysError", h.CreateError)
group.Group("/sysError").POST("/createSysError", h.CreateError)
}
+1 -1
View File
@@ -67,7 +67,7 @@ type ErrorRecordRequest struct {
type ErrorRecordMutationRequest struct {
ID uint `json:"ID"`
Form *string `json:"form" binding:"required"`
Info *string `json:"info"`
Info *string `json:"info" binding:"max=16384"`
Level string `json:"level"`
RequestID string `json:"request_id"`
TraceID string `json:"trace_id"`