feat(common): 升级 gf 框架版本至 v2.8.0 并优化模型时间字段

- 将 `github.com/gogf/gf/contrib/drivers/pgsql/v2` 和 redis 依赖从 v2.6.3 升级到 v2.8.0
- 使用 `*gtime.Time` 替代标准库 `time.Time` 以支持更灵活的时间处理
- 移除 Model 结构体中 CreateTime、UpdateTime 等字段的默认初始化逻辑
- 注释掉已弃用的 GDBM 函数,推荐使用 DBM
- 在 DBM 中添加 OnConflict("id") 配置以增强写入安全性
- 调整部分代码结构与调用方式以适配新版框架行为
```
This commit is contained in:
2025-11-17 12:59:46 +08:00
parent 4e5886dbf9
commit a95e6b8491
16 changed files with 51 additions and 61 deletions

View File

@@ -3,7 +3,7 @@ module blazing/contrib/drivers/pgsql
go 1.18 go 1.18
require ( require (
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.3 github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.8.0
github.com/gogf/gf/v2 v2.8.0 github.com/gogf/gf/v2 v2.8.0
gorm.io/driver/postgres v1.5.6 gorm.io/driver/postgres v1.5.6
gorm.io/gorm v1.25.7 gorm.io/gorm v1.25.7

View File

@@ -11,8 +11,7 @@ github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.3 h1:Q5wh3EHLksi0ej/KnBZBgr2MU6r3MISaEF341RjsBeI=
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.3/go.mod h1:4vzOwG+fZ76cGssHEhwao0Uto1nPpARPqgyZQ9ost/4=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=

View File

@@ -5,12 +5,12 @@ import (
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
) )
// Deprecated 请使用 cool.DBM 替代 // // Deprecated 请使用 cool.DBM 替代
func GDBM(m IModel) *gdb.Model { // func GDBM(m IModel) *gdb.Model {
return g.DB(m.GroupName()).Model(m.TableName()) // return g.DB(m.GroupName()).Model(m.TableName())
} // }
// DBM 根据model获取 *gdb.Model // DBM 根据model获取 *gdb.Model
func DBM(m IModel) *gdb.Model { func DBM(m IModel) *gdb.Model {
return g.DB(m.GroupName()).Model(m.TableName()) return g.DB(m.GroupName()).Model(m.TableName()).OnConflict("id")
} }

View File

@@ -1,7 +1,7 @@
package cool package cool
import ( import (
"time" "github.com/gogf/gf/v2/os/gtime"
) )
type IModel interface { type IModel interface {
@@ -16,10 +16,10 @@ type UserModel interface {
GroupName() string GroupName() string
} }
type Model struct { type Model struct {
ID uint `gorm:"primaryKey" json:"id"` ID uint `gorm:"primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:createTime;not null;index,priority:1;autoCreateTime:nano;comment:创建时间" json:"createTime"` // 创建时间 CreateTime *gtime.Time ` gorm:"column:createTime;not null;index,priority:1;autoCreateTime:nano;comment:创建时间" json:"createTime"` // 创建时间
UpdateTime time.Time `gorm:"column:updateTime;not null;index,priority:1;autoUpdateTime:nano;comment:更新时间" json:"updateTime"` // 更新时间 UpdateTime *gtime.Time ` gorm:"column:updateTime;not null;index,priority:1;autoUpdateTime:nano;comment:更新时间" json:"updateTime"` // 更新时间
DeletedAt time.Time `gorm:"index" json:"deletedAt"` DeletedAt *gtime.Time `gorm:"index" json:"deletedAt"`
} }
// 返回表名 // 返回表名
@@ -33,10 +33,5 @@ func (m *Model) GroupName() string {
} }
func NewModel() *Model { func NewModel() *Model {
return &Model{ return &Model{}
ID: 0,
CreateTime: time.Time{},
UpdateTime: time.Time{},
DeletedAt: time.Time{},
}
} }

View File

@@ -158,7 +158,7 @@ func init() {
glog.Debug(ctx, "修改权限 : ", event.Path) glog.Debug(ctx, "修改权限 : ", event.Path)
} }
glog.Debug(ctx, event) glog.Debug(ctx, event)
}, true) })
if err != nil { if err != nil {
glog.Fatal(ctx, err) glog.Fatal(ctx, err)

View File

@@ -8,7 +8,7 @@ require (
github.com/brunoga/deep v1.2.5 github.com/brunoga/deep v1.2.5
github.com/creasty/defaults v1.8.0 github.com/creasty/defaults v1.8.0
github.com/gobwas/ws v1.4.0 github.com/gobwas/ws v1.4.0
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3 github.com/gogf/gf/contrib/nosql/redis/v2 v2.8.0
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543 github.com/lunixbochs/struc v0.0.0-20241101090106-8d528fa2c543
github.com/panjf2000/ants/v2 v2.11.3 github.com/panjf2000/ants/v2 v2.11.3

View File

@@ -40,8 +40,7 @@ github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs= github.com/gobwas/ws v1.4.0 h1:CTaoG1tojrh4ucGPcoJFiAQUAsEWekEWvLy7GsVNqGs=
github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc= github.com/gobwas/ws v1.4.0/go.mod h1:G3gNqMNtPppf5XUz7O4shetPpcZ1VJ7zt18dlUeakrc=
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3 h1:tbN3rYVSi5MfCS5qAaZ1Xg3fSsyHeT++tJZqEiH1s4c=
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3/go.mod h1:2+evGu1xAlamaYuDdSqa7QCiwPTm1RrGsUFSMc8PyLc=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=

View File

@@ -23,8 +23,11 @@ type Effect41 struct {
} }
func (e *Effect41) SetArgs(t *input.Input, a ...int) { func (e *Effect41) SetArgs(t *input.Input, a ...int) {
n := e.Input.FightC.GetRand().Int31n(int32(e.Args()[1]-e.Args()[0]+1)) + int32(e.Args()[0])
e.EffectNode.SetArgs(t, a...) e.EffectNode.SetArgs(t, a...)
t1 := e.Input.FightC
t2 := t1.GetRand()
n := t2.Int31n(int32(e.Args()[1]-e.Args()[0]+1)) + int32(e.Args()[0])
e.EffectNode.Duration(int(n)) e.EffectNode.Duration(int(n))
} }

View File

@@ -66,7 +66,7 @@ type ContinuousDamage struct {
} }
// 技能命中前触发伤害1/8最大生命值真实伤害 // 技能命中前触发伤害1/8最大生命值真实伤害
func (e *ContinuousDamage) Skill_Hit_Pre_ex(attacker, defender *action.SelectSkillAction) bool { func (e *ContinuousDamage) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool {
damage := e.calculateDamage() damage := e.calculateDamage()
e.Ctx().Our.Damage(e.Input, &info.DamageZone{ e.Ctx().Our.Damage(e.Input, &info.DamageZone{
Type: info.DamageType.True, Type: info.DamageType.True,
@@ -87,7 +87,7 @@ type ParasiticSeed struct {
} }
// 技能命中前触发寄生效果 // 技能命中前触发寄生效果
func (e *ParasiticSeed) Skill_Hit_Pre(attacker, defender *action.SelectSkillAction) bool { func (e *ParasiticSeed) Skill_Hit_Pre_ex(attacker, defender *action.SelectSkillAction) bool {
// 过滤特定类型单位假设1是植物类型使用枚举替代魔法数字 // 过滤特定类型单位假设1是植物类型使用枚举替代魔法数字
if gconv.Int(e.Ctx().Our.CurrentPet.Type) == int(element.ElementTypeGrass) { if gconv.Int(e.Ctx().Our.CurrentPet.Type) == int(element.ElementTypeGrass) {
return true return true

View File

@@ -3,7 +3,7 @@ module blazing/login
go 1.19 go 1.19
require ( require (
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3 github.com/gogf/gf/contrib/nosql/redis/v2 v2.8.0
github.com/gogf/gf/v2 v2.8.0 github.com/gogf/gf/v2 v2.8.0
) )

View File

@@ -30,8 +30,6 @@ github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Px
github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4=
github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3 h1:tbN3rYVSi5MfCS5qAaZ1Xg3fSsyHeT++tJZqEiH1s4c=
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.3/go.mod h1:2+evGu1xAlamaYuDdSqa7QCiwPTm1RrGsUFSMc8PyLc=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=

View File

@@ -22,8 +22,7 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/gogf/gf/v2 v2.8.0 h1:CjxhbMiE7oqf6K8ZtGuKt3dQEwK4vL6LhiI+dI7tJGU=
github.com/gogf/gf/v2 v2.8.0/go.mod h1:Qu8nimKt9aupJQcdUL85tWF4Mfxocz97zUt8UC4abVI=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U= github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg= github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=

View File

@@ -18,6 +18,8 @@ func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model
if !ook { //不需要保存 if !ook { //不需要保存
return return
} }
tt.PlayerID = uint64(s.userid)
_, err := m.Save(tt) _, err := m.Save(tt)
if err != nil { if err != nil {
panic(err) panic(err)

View File

@@ -54,7 +54,7 @@ func (s *InfoService) Reg(nick string, color uint32) {
func (s *InfoService) Person(userid uint32) *model.PlayerInfo { func (s *InfoService) Person(userid uint32) *model.PlayerInfo {
m := cool.GDBM(s.Model).Where("player_id", userid) m := cool.DBM(s.Model).Where("player_id", userid)
var tt model.PlayerEX var tt model.PlayerEX
err := m.Scan(&tt) err := m.Scan(&tt)
if err != nil { if err != nil {

View File

@@ -84,8 +84,6 @@ func (s *LoginService) SetServerID(OnlineID uint16, Port uint16) error {
tttt.Port = Port tttt.Port = Port
tttt.OnlineID = OnlineID tttt.OnlineID = OnlineID
//t.Quit(int32(tttt.Port))
//m.Data(&model.ServerList{OnlineID: OnlineID, Port: Port}).Where("online_id", OnlineID).Update()
m.Save(tttt) m.Save(tttt)
return nil return nil

View File

@@ -3,44 +3,41 @@ package service
import ( import (
"blazing/cool" "blazing/cool"
"blazing/modules/blazing/model" "blazing/modules/blazing/model"
"encoding/json"
"time" "time"
) )
func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool { // func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
//todo待测试 // //todo待测试
var player T // var player T
m1 := cool.DBM(s.Model).Where("player_id", userid) // m1 := cool.DBM(s.Model).Where("player_id", userid)
m1.Scan(&player) // m1.Scan(&player)
// 方法2使用反射获取 // // 方法2使用反射获取
// 获取反射值对象 // // 获取反射值对象
ttt := player // ttt := player
//fmt.Println(dataField.Interface().(string)) // //fmt.Println(dataField.Interface().(string))
var tt F // var tt F
err := json.Unmarshal([]byte(ttt.GetData()), &tt) // err := json.Unmarshal([]byte(ttt.GetData()), &tt)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
tt1 := processFunc(tt) // tt1 := processFunc(tt)
tmep, err := json.Marshal(tt1) // tmep, err := json.Marshal(tt1)
if err != nil { // if err != nil {
panic(err) // panic(err)
} // }
ttt.SetData(string(tmep)) // ttt.SetData(string(tmep))
m1.Save(player) // m1.Save(player)
return false // return false
} // }
// 获取任务信息 // 获取任务信息
func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) { func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
var gg model.TaskEX var gg model.TaskEX
m1 := cool.GDBM(s.Model). m1 := s.GModel(s.Model).Where("task_id", id)
Where("player_id", s.userid).
Where("task_id", id)
m1.Scan(&gg) m1.Scan(&gg)
tre := t(&gg) tre := t(&gg)
if !tre { //不需要更新 if !tre { //不需要更新