diff --git a/initalize/mysql.go b/initalize/mysql.go index 75db586f..520c519f 100644 --- a/initalize/mysql.go +++ b/initalize/mysql.go @@ -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) diff --git a/model/gmodel/casbin_rule_gen.go b/model/gmodel/casbin_rule_gen.go new file mode 100644 index 00000000..57bd8599 --- /dev/null +++ b/model/gmodel/casbin_rule_gen.go @@ -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"} +} diff --git a/model/gmodel/casbin_rule_logic.go b/model/gmodel/casbin_rule_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/casbin_rule_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_admin_auth_role_gen.go b/model/gmodel/fs_admin_auth_role_gen.go new file mode 100644 index 00000000..f9075654 --- /dev/null +++ b/model/gmodel/fs_admin_auth_role_gen.go @@ -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"} +} diff --git a/model/gmodel/fs_admin_auth_role_logic.go b/model/gmodel/fs_admin_auth_role_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_admin_auth_role_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_admin_department_gen.go b/model/gmodel/fs_admin_department_gen.go new file mode 100644 index 00000000..25349b64 --- /dev/null +++ b/model/gmodel/fs_admin_department_gen.go @@ -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"} +} diff --git a/model/gmodel/fs_admin_department_logic.go b/model/gmodel/fs_admin_department_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_admin_department_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_admin_menu_gen.go b/model/gmodel/fs_admin_menu_gen.go new file mode 100644 index 00000000..230ea1b4 --- /dev/null +++ b/model/gmodel/fs_admin_menu_gen.go @@ -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"} +} diff --git a/model/gmodel/fs_admin_menu_logic.go b/model/gmodel/fs_admin_menu_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_admin_menu_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/model/gmodel/fs_merchant_category_gen.go b/model/gmodel/fs_merchant_category_gen.go index 732ec88b..b0c42cae 100644 --- a/model/gmodel/fs_merchant_category_gen.go +++ b/model/gmodel/fs_merchant_category_gen.go @@ -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"` // 添加时间 } diff --git a/model/gmodel/fs_merchant_category_logic.go b/model/gmodel/fs_merchant_category_logic.go index cbf8c138..e7061476 100644 --- a/model/gmodel/fs_merchant_category_logic.go +++ b/model/gmodel/fs_merchant_category_logic.go @@ -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 } diff --git a/model/gmodel/var_gen.go b/model/gmodel/var_gen.go index c7e2a11b..ad4f5db9 100644 --- a/model/gmodel/var_gen.go +++ b/model/gmodel/var_gen.go @@ -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), diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index e9d4694f..389a01e0 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -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.CodeDbRecordNotFoundErr, "the merchant category is not exists") + } + 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.CodeDbRecordNotFoundErr, "the default merchant category is not exists") + } + 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{}{})