Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-08-28 17:01:44 +08:00
commit f41bea0201
38 changed files with 316 additions and 113 deletions

4
go.mod
View File

@ -102,7 +102,7 @@ require (
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 // indirect
@ -110,7 +110,7 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.14.0 // indirect
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/automaxprocs v1.5.2 // indirect
golang.org/x/net v0.12.0 // indirect

View File

@ -37,7 +37,7 @@ func InitMysql(sourceMysql string) *gorm.DB {
sqlDB.SetMaxIdleConns(4)
// SetMaxOpenConns 设置打开数据库连接的最大数量。
sqlDB.SetMaxOpenConns(10)
sqlDB.SetMaxOpenConns(25)
// SetConnMaxLifetime 设置了连接可复用的最大时间。
sqlDB.SetConnMaxLifetime(time.Minute * 20)

View File

@ -0,0 +1,24 @@
package gmodel
import (
"gorm.io/gorm"
)
// casbin_rule
type CasbinRule struct {
PType *string `gorm:"default:'';" json:"p_type"` //
V0 *string `gorm:"default:'';" json:"v0"` //
V1 *string `gorm:"default:'';" json:"v1"` //
V2 *string `gorm:"default:'';" json:"v2"` //
V3 *string `gorm:"default:'';" json:"v3"` //
V4 *string `gorm:"default:'';" json:"v4"` //
V5 *string `gorm:"default:'';" json:"v5"` //
}
type CasbinRuleModel struct {
db *gorm.DB
name string
}
func NewCasbinRuleModel(db *gorm.DB) *CasbinRuleModel {
return &CasbinRuleModel{db: db, name: "casbin_rule"}
}

View File

@ -0,0 +1,2 @@
package gmodel
// TODO: 使用model的属性做你想做的

View File

@ -0,0 +1,33 @@
package gmodel
import (
"gorm.io/gorm"
"time"
)
// fs_admin_auth_role 后台--角色表
type FsAdminAuthRole struct {
Id int64 `gorm:"primary_key;default:0;" json:"id"` // 序号
RolePid *int64 `gorm:"default:0;" json:"role_pid"` // 上级角色
RoleName *string `gorm:"default:'';" json:"role_name"` //
DataAuthType *int64 `gorm:"default:1;" json:"data_auth_type"` // 数据权限类型
DataAuth *string `gorm:"default:'';" json:"data_auth"` //
Status *int64 `gorm:"default:2;" json:"status"` // 状态:1=启用,2=停用
Remark *string `gorm:"default:'';" json:"remark"` //
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序权重
CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` //
UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` //
DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` //
CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除1=是 0=否
}
type FsAdminAuthRoleModel struct {
db *gorm.DB
name string
}
func NewFsAdminAuthRoleModel(db *gorm.DB) *FsAdminAuthRoleModel {
return &FsAdminAuthRoleModel{db: db, name: "fs_admin_auth_role"}
}

View File

@ -0,0 +1,2 @@
package gmodel
// TODO: 使用model的属性做你想做的

View File

@ -0,0 +1,35 @@
package gmodel
import (
"gorm.io/gorm"
"time"
)
// fs_admin_department 后台--部门表
type FsAdminDepartment struct {
Id int64 `gorm:"primary_key;default:0;" json:"id"` // 序号
DeptPid *int64 `gorm:"default:0;" json:"dept_pid"` // 上级部门
DeptNo *string `gorm:"default:'';" json:"dept_no"` //
DeptName *string `gorm:"default:'';" json:"dept_name"` //
ShortName *string `gorm:"default:'';" json:"short_name"` //
UserId *int64 `gorm:"default:0;" json:"user_id"` // 部门负责人
Phone *string `gorm:"default:'';" json:"phone"` //
Status *int64 `gorm:"default:2;" json:"status"` // 状态:1=启用,2=停用
Remark *string `gorm:"default:'';" json:"remark"` //
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序权重
CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` //
UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` //
DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` //
CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除1=是 0=否
}
type FsAdminDepartmentModel struct {
db *gorm.DB
name string
}
func NewFsAdminDepartmentModel(db *gorm.DB) *FsAdminDepartmentModel {
return &FsAdminDepartmentModel{db: db, name: "fs_admin_department"}
}

View File

@ -0,0 +1,2 @@
package gmodel
// TODO: 使用model的属性做你想做的

View File

@ -0,0 +1,33 @@
package gmodel
import (
"gorm.io/gorm"
"time"
)
// fs_admin_menu 后台--菜单表
type FsAdminMenu struct {
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 序号
Pid *int64 `gorm:"default:0;" json:"pid"` // 上级菜单
Name *string `gorm:"default:'';" json:"name"` //
Path *string `gorm:"default:'';" json:"path"` //
Hide *string `gorm:"default:'';" json:"hide"` //
Metadata *[]byte `gorm:"default:'';" json:"metadata"` // 元数据,json格式
Remark *string `gorm:"default:'';" json:"remark"` //
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序权重
CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` //
UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` //
DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` //
CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除1=是 0=否
}
type FsAdminMenuModel struct {
db *gorm.DB
name string
}
func NewFsAdminMenuModel(db *gorm.DB) *FsAdminMenuModel {
return &FsAdminMenuModel{db: db, name: "fs_admin_menu"}
}

View File

@ -0,0 +1,2 @@
package gmodel
// TODO: 使用model的属性做你想做的

View File

@ -12,6 +12,7 @@ type FsMerchantCategory struct {
Icon *string `gorm:"default:'';" json:"icon"` // 图标
RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
IsDefault *int64 `gorm:"default:0;" json:"is_default"` // 是否是默认商家类型0非1是
Status *int64 `gorm:"default:0;" json:"status"` // 状态
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
}

View File

@ -14,8 +14,10 @@ func (m *FsMerchantCategoryModel) FindOne(ctx context.Context, id int64) (resp *
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error
return resp, err
}
func (m *FsMerchantCategoryModel) FindRandOne(ctx context.Context) (resp *FsMerchantCategory, err error) {
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ?", 1).Order("RAND()").Take(&resp).Error
// 获取默认那个
func (m *FsMerchantCategoryModel) FindDefualtOne(ctx context.Context) (resp *FsMerchantCategory, err error) {
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ? and is_default = ?", 1, 1).Take(&resp).Error
return resp, err
}

View File

@ -4,7 +4,11 @@ import "gorm.io/gorm"
// AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除
type AllModelsGen struct {
CasbinRule *CasbinRuleModel // casbin_rule
FsAddress *FsAddressModel // fs_address 用户地址表
FsAdminAuthRole *FsAdminAuthRoleModel // fs_admin_auth_role 后台--角色表
FsAdminDepartment *FsAdminDepartmentModel // fs_admin_department 后台--部门表
FsAdminMenu *FsAdminMenuModel // fs_admin_menu 后台--菜单表
FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息
FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息
FsAuthItemChild *FsAuthItemChildModel // fs_auth_item_child 角色和权限关系表
@ -103,7 +107,11 @@ type AllModelsGen struct {
func NewAllModels(gdb *gorm.DB) *AllModelsGen {
models := &AllModelsGen{
CasbinRule: NewCasbinRuleModel(gdb),
FsAddress: NewFsAddressModel(gdb),
FsAdminAuthRole: NewFsAdminAuthRoleModel(gdb),
FsAdminDepartment: NewFsAdminDepartmentModel(gdb),
FsAdminMenu: NewFsAdminMenuModel(gdb),
FsAuthAssignment: NewFsAuthAssignmentModel(gdb),
FsAuthItem: NewFsAuthItemModel(gdb),
FsAuthItemChild: NewFsAuthItemChildModel(gdb),

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9980
ReplicaId: 10
MainAddress: "https://server.fusen.3718.cn:9900"
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -2,7 +2,9 @@ Name: backend
Host: localhost
Port: 9901
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen_backend_2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: 0.0.0.0
Port: 9920
ReplicaId: 15
Timeout: 15000 #服务超时时间(毫秒)
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9902
ReplicaId: 20
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9903
ReplicaId: 25
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -4,7 +4,9 @@ Port: 9904
ReplicaId: 30
Timeout: 15000 #服务超时时间
MainAddress: "http://localhost:9900"
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9905
ReplicaId: 35
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9906
ReplicaId: 40
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9907
ReplicaId: 45
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: 0.0.0.0
Port: 9915
ReplicaId: 50
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -1,7 +1,9 @@
Name: product-model
Host: localhost
Port: 9909
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: 0.0.0.0
ReplicaId: 65
Port: 9917
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9910
ReplicaId: 60
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9908
ReplicaId: 55
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -54,16 +54,23 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
//选了商家类型
if req.MerchantType > 0 {
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType)
} else {
//随机获取一个商家类型
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindRandOne(l.ctx)
}
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of merchant type found")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeOK, "the merchant category is not exists", []interface{}{})
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant category")
}
} else {
//获取默认的那个
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindDefualtOne(l.ctx)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return resp.SetStatusWithMessage(basic.CodeOK, "the default merchant category is not exists", []interface{}{})
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default merchant category")
}
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant type info")
}
if *merchantInfo.RecommendProduct == "" {
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})

View File

@ -3,7 +3,9 @@ Host: 0.0.0.0
Port: 9919
ReplicaId: 70
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: 0.0.0.0
Port: 9916
ReplicaId: 75
Timeout: 150000 #服务超时时间(毫秒)
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -3,7 +3,9 @@ Host: localhost
Port: 9911
ReplicaId: 80
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -5,6 +5,8 @@ ReplicaId: 85
Timeout: 150000 #服务超时时间
MaxBytes: 104857600 #传输字节大小
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Env: "test"
Auth:
AccessSecret: fusen2023

View File

@ -3,7 +3,9 @@ Host: 0.0.0.0
Port: 9914
ReplicaId: 95
Timeout: 15000 #服务超时时间
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
SourceMysql: "fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen"
Log:
Stat: false
Auth:
AccessSecret: fusen2023
AccessExpire: 2592000

View File

@ -59,7 +59,7 @@ var (
CheckOrigin: func(r *http.Request) bool {
return true
},
//写的缓存池
//写的缓冲队列
WriteBufferPool: &buffPool,
//是否支持压缩
EnableCompression: false,
@ -75,8 +75,8 @@ type wsConnectItem struct {
closeChan chan struct{} //ws连接关闭chan(基本属性)
isClose bool //是否已经关闭(基本属性)
uniqueId string //ws连接唯一标识(基本属性)
inChan chan []byte //接受消息缓冲(基本属性)
outChan chan []byte //要发送回客户端的消息缓冲(基本属性)
inChan chan []byte //接受消息缓冲队列(基本属性)
outChan chan []byte //要发送回客户端的消息缓冲队列(基本属性)
mutex sync.Mutex //互斥锁(基本属性)
userId int64 //用户id(基本属性)
guestId int64 //游客id(基本属性)
@ -268,7 +268,7 @@ func (w *wsConnectItem) close() {
logx.Info("###websocket:", w.uniqueId, " uid:", w.userId, " gid:", w.guestId, " is closed")
}
// 读取出口缓冲数据输出返回给浏览器端
// 读取出口缓冲队列数据输出返回给浏览器端
func (w *wsConnectItem) writeLoop() {
defer func() {
if err := recover(); err != nil {
@ -289,7 +289,7 @@ func (w *wsConnectItem) writeLoop() {
}
}
// 接受客户端发来的消息并写入入口缓冲
// 接受客户端发来的消息并写入入口缓冲队列
func (w *wsConnectItem) readLoop() {
defer func() {
if err := recover(); err != nil {
@ -300,7 +300,7 @@ func (w *wsConnectItem) readLoop() {
select {
case <-w.closeChan: //如果关闭了
return
default:
default: //收取消息
msgType, data, err := w.conn.ReadMessage()
if err != nil {
logx.Error("接受信息错误:", err)
@ -308,10 +308,9 @@ func (w *wsConnectItem) readLoop() {
w.close()
return
}
//ping的消息不处理
if msgType != websocket.PingMessage {
//消息传入缓冲通道
w.inChan <- data
//ping/pong/close的消息不处理
if msgType != websocket.PingMessage && msgType != websocket.PongMessage && msgType != websocket.CloseMessage {
w.sendToInChan(data)
}
}
}
@ -334,7 +333,7 @@ func (w *wsConnectItem) sendLoop() {
}
}
// 把要传递给客户端的数据放入出口缓冲
// 把要传递给客户端的数据放入出口缓冲队列
func (w *wsConnectItem) sendToOutChan(data []byte) {
select {
case <-w.closeChan:
@ -346,6 +345,18 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
}
}
// 发送接受到的消息到入口缓冲队列中
func (w *wsConnectItem) sendToInChan(data []byte) {
select {
case <-w.closeChan: //关闭了
return
case w.inChan <- data:
return
case <-time.After(time.Second * 3): //3秒超时丢弃
return
}
}
// 格式化为websocket标准返回格式
func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data interface{}) []byte {
d := websocket_data.DataTransferData{
@ -356,7 +367,7 @@ func (w *wsConnectItem) respondDataFormat(msgType constants.Websocket, data inte
return b
}
// 处理入口缓冲中不同类型的数据(分发处理)
// 处理入口缓冲队列中不同类型的数据(分发处理)
func (w *wsConnectItem) dealwithReciveData(data []byte) {
var parseInfo websocket_data.DataTransferData
if err := json.Unmarshal(data, &parseInfo); err != nil {

View File

@ -82,18 +82,18 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a
}
//记录收到unity渲染结果时间以及上传渲染图耗时时间
ws.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
Option: 2,
TaskId: req.TaskId,
TaskProperty: renderTask{
UnityRenderEndTime: unityRenderEndTime,
UploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
option: 2,
taskId: req.TaskId,
taskProperty: renderTask{
unityRenderEndTime: unityRenderEndTime,
uploadUnityRenderImageTakesTime: uploadUnityRenderImageTakesTime,
},
})
//发送处理并删除任务
ws.deleteRenderTask(renderImageControlChanItem{
Option: 0, //0删除 1添加 2修改耗时属性
TaskId: req.TaskId,
RenderNotifyImageUrl: uploadRes.ResourceUrl,
option: 0, //0删除 1添加 2修改耗时属性
taskId: req.TaskId,
renderNotifyImageUrl: uploadRes.ResourceUrl,
})
return true
})

View File

@ -27,36 +27,36 @@ type extendRenderProperty struct {
// 渲染任务新增移除的控制通道的数据
type renderImageControlChanItem struct {
Option int // 0删除 1添加
TaskId string //map的key
RenderId string // map的val(增加任务时候传)
RenderNotifyImageUrl string //渲染回调数据(删除任务时候传)
TaskProperty renderTask //渲染任务的属性
option int // 0删除 1添加
taskId string //map的key
renderId string // map的val(增加任务时候传)
renderNotifyImageUrl string //渲染回调数据(删除任务时候传)
taskProperty renderTask //渲染任务的属性
}
// 渲染任务属性
type renderTask struct {
RenderId string //渲染id(前端传的)
CombineTakesTime int64 //合刀版图耗时
UploadCombineImageTakesTime int64 //上传刀版图耗时
UnityRenderBeginTime int64 //发送给unity时间
UnityRenderEndTime int64 //unity回调结果时间
UploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间
renderId string //渲染id(前端传的)
combineTakesTime int64 //合刀版图耗时
uploadCombineImageTakesTime int64 //上传刀版图耗时
unityRenderBeginTime int64 //发送给unity时间
unityRenderEndTime int64 //unity回调结果时间
uploadUnityRenderImageTakesTime int64 //上传unity渲染结果图时间
}
// 发送到渲染缓冲
// 发送到渲染缓冲队列
func (w *wsConnectItem) sendToRenderChan(data []byte) {
select {
case <-w.closeChan: //已经关闭
return
case w.extendRenderProperty.renderChan <- data: //发入到缓冲
case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列
return
case <-time.After(time.Second * 3): //三秒没进入缓冲就丢弃
case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃
return
}
}
// 渲染发送到组装数据组装数据(缓冲)
// 渲染发送到组装数据组装数据(缓冲队列)
func (w *wsConnectItem) renderImage() {
for {
select {
@ -181,9 +181,9 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) {
//###########################################
//把需要渲染的图片任务加进去
w.createRenderTask(renderImageControlChanItem{
Option: 1, //0删除 1添加 2修改耗时属性
TaskId: taskId,
RenderId: renderImageData.RenderId,
option: 1, //0删除 1添加 2修改耗时属性
taskId: taskId,
renderId: renderImageData.RenderId,
})
//组装数据
if err = w.assembleRenderData(taskId, renderImageData, productTemplate, model3dInfo, element, productFirstSize); err != nil {
@ -247,11 +247,11 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
}
//记录刀版图合成消耗时间跟上传刀版图时间
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
Option: 2,
TaskId: taskId,
TaskProperty: renderTask{
CombineTakesTime: res.DiffTimeLogoCombine,
UploadCombineImageTakesTime: res.DiffTimeUploadFile,
option: 2,
taskId: taskId,
taskProperty: renderTask{
combineTakesTime: res.DiffTimeLogoCombine,
uploadCombineImageTakesTime: res.DiffTimeUploadFile,
},
})
logx.Info("合成刀版图成功,合成刀版图数据:", combineReq, ",logo图片:", info.RenderData.Logo, " 刀版图:", *res.ResourceUrl)
@ -349,10 +349,10 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
}
//记录发送到unity时间
w.modifyRenderTaskTimeConsuming(renderImageControlChanItem{
Option: 2,
TaskId: taskId,
TaskProperty: renderTask{
UnityRenderBeginTime: unityRenderBeginTime,
option: 2,
taskId: taskId,
taskProperty: renderTask{
unityRenderBeginTime: unityRenderBeginTime,
},
})
logx.Info("发送到unity成功,刀版图:", combineImage, " 请求unity的数据:", string(postDataBytes))
@ -362,7 +362,7 @@ func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.Re
// 增加渲染任务
func (w *wsConnectItem) createRenderTask(data renderImageControlChanItem) {
//强制设为增加
data.Option = 1
data.option = 1
select {
case <-w.closeChan: //关闭
return
@ -376,7 +376,7 @@ func (w *wsConnectItem) createRenderTask(data renderImageControlChanItem) {
// 渲染回调处理并删除渲染任务
func (w *wsConnectItem) deleteRenderTask(data renderImageControlChanItem) {
//强制设为删除
data.Option = 0
data.option = 0
select {
case <-w.closeChan: //关闭
return
@ -389,12 +389,12 @@ func (w *wsConnectItem) deleteRenderTask(data renderImageControlChanItem) {
// 修改耗时属性(只有耗时属性可以更新)
func (w *wsConnectItem) modifyRenderTaskTimeConsuming(data renderImageControlChanItem) {
if data.TaskId == "" {
if data.taskId == "" {
logx.Error("设置耗时属性需要的task_id不能为空")
return
}
//强制设为修改耗时属性
data.Option = 2
data.option = 2
select {
case <-w.closeChan: //关闭
return
@ -417,34 +417,34 @@ func (w *wsConnectItem) operationRenderTask() {
case <-w.closeChan:
return
case data := <-w.extendRenderProperty.renderImageTaskCtlChan:
switch data.Option {
switch data.option {
case 0: //渲染结果回调,删除任务
//存在任务,则发送渲染结果给前端
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
if taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]; ok {
CombineTakesTime := "0ms"
UnityRenderTakesTime := "0ms"
uploadCombineImageTakesTime := "0ms"
uploadUnityRenderImageTakesTime := "0ms"
//合图时间
if taskData.CombineTakesTime > 0 {
CombineTakesTime = fmt.Sprintf("%dms", taskData.CombineTakesTime)
if taskData.combineTakesTime > 0 {
CombineTakesTime = fmt.Sprintf("%dms", taskData.combineTakesTime)
}
//上传刀版图时间
if taskData.UploadCombineImageTakesTime > 0 {
uploadCombineImageTakesTime = fmt.Sprintf("%dms", taskData.UploadCombineImageTakesTime)
if taskData.uploadCombineImageTakesTime > 0 {
uploadCombineImageTakesTime = fmt.Sprintf("%dms", taskData.uploadCombineImageTakesTime)
}
//unity渲染时间
if taskData.UnityRenderBeginTime > 0 && taskData.UnityRenderEndTime > 0 {
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.UnityRenderEndTime-taskData.UnityRenderBeginTime)
if taskData.unityRenderBeginTime > 0 && taskData.unityRenderEndTime > 0 {
UnityRenderTakesTime = fmt.Sprintf("%dms", taskData.unityRenderEndTime-taskData.unityRenderBeginTime)
}
//上传unity渲染图耗时
if taskData.UploadUnityRenderImageTakesTime > 0 {
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.UploadUnityRenderImageTakesTime)
if taskData.uploadUnityRenderImageTakesTime > 0 {
uploadUnityRenderImageTakesTime = fmt.Sprintf("%dms", taskData.uploadUnityRenderImageTakesTime)
}
//发送到出口
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{
RenderId: taskData.RenderId,
Image: data.RenderNotifyImageUrl,
RenderId: taskData.renderId,
Image: data.renderNotifyImageUrl,
RenderProcessTime: websocket_data.RenderProcessTime{
CombineTakesTime: CombineTakesTime,
UnityRenderTakesTime: UnityRenderTakesTime,
@ -454,32 +454,32 @@ func (w *wsConnectItem) operationRenderTask() {
}))
}
//删除任务
delete(w.extendRenderProperty.renderImageTask, data.TaskId)
delete(w.extendRenderProperty.renderImageTask, data.taskId)
case 1: //新增任务
w.extendRenderProperty.renderImageTask[data.TaskId] = &renderTask{
RenderId: data.RenderId,
w.extendRenderProperty.renderImageTask[data.taskId] = &renderTask{
renderId: data.renderId,
}
case 2: //修改(耗时)属性
if taskData, ok := w.extendRenderProperty.renderImageTask[data.TaskId]; ok {
if taskData, ok := w.extendRenderProperty.renderImageTask[data.taskId]; ok {
//合图耗时
if data.TaskProperty.CombineTakesTime != 0 {
taskData.CombineTakesTime = data.TaskProperty.CombineTakesTime
if data.taskProperty.combineTakesTime != 0 {
taskData.combineTakesTime = data.taskProperty.combineTakesTime
}
//上传合图耗时
if data.TaskProperty.UploadCombineImageTakesTime != 0 {
taskData.UploadCombineImageTakesTime = data.TaskProperty.UploadCombineImageTakesTime
if data.taskProperty.uploadCombineImageTakesTime != 0 {
taskData.uploadCombineImageTakesTime = data.taskProperty.uploadCombineImageTakesTime
}
//上传渲染结果图耗时
if data.TaskProperty.UploadUnityRenderImageTakesTime != 0 {
taskData.UploadUnityRenderImageTakesTime = data.TaskProperty.UploadUnityRenderImageTakesTime
if data.taskProperty.uploadUnityRenderImageTakesTime != 0 {
taskData.uploadUnityRenderImageTakesTime = data.taskProperty.uploadUnityRenderImageTakesTime
}
//发送unity时间
if data.TaskProperty.UnityRenderBeginTime != 0 {
taskData.UnityRenderBeginTime = data.TaskProperty.UnityRenderBeginTime
if data.taskProperty.unityRenderBeginTime != 0 {
taskData.unityRenderBeginTime = data.taskProperty.unityRenderBeginTime
}
//收到unity返回的时间
if data.TaskProperty.UnityRenderEndTime != 0 {
taskData.UnityRenderEndTime = data.TaskProperty.UnityRenderEndTime
if data.taskProperty.unityRenderEndTime != 0 {
taskData.unityRenderEndTime = data.taskProperty.unityRenderEndTime
}
}
}

View File

@ -123,6 +123,7 @@ func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx any, LogicReque
Code: 510,
Message: err.Error(),
})
return nil, err
}
// 如果端点有请求结构体则使用httpx.Parse方法从HTTP请求体中解析请求数据

View File

@ -102,8 +102,9 @@ func (upload *Upload) UploadFileByBase64(req *UploadBaseReq) (*UploadBaseRes, er
// 创建S3对象存储请求
s3req, _ = svc.PutObjectRequest(
&s3.PutObjectInput{
Bucket: bucketName,
Key: &resourceId,
Bucket: bucketName,
Key: &resourceId,
CacheControl: aws.String("no-cache, must-revalidate"),
},
)
@ -226,8 +227,9 @@ func (upload *Upload) UploadFileByByte(req *UploadBaseReq) (*UploadBaseRes, erro
// 创建S3对象存储请求
s3req, _ = svc.PutObjectRequest(
&s3.PutObjectInput{
Bucket: bucketName,
Key: &resourceId,
Bucket: bucketName,
Key: &resourceId,
CacheControl: aws.String("no-cache, must-revalidate"),
},
)