This commit is contained in:
yangduo 2024-07-31 20:17:11 +08:00
parent 8bb0996d7d
commit 898e8d31f0
11 changed files with 169 additions and 36 deletions

View File

@ -1,12 +1,13 @@
package system package system
import ( import (
"f5"
"main/constant" "main/constant"
"main/model/system" "main/model/system"
"f5"
"github.com/gin-gonic/gin"
"net/http" "net/http"
"strconv" "strconv"
"github.com/gin-gonic/gin"
) )
type AnncApi struct { type AnncApi struct {
@ -14,7 +15,7 @@ type AnncApi struct {
func (this *AnncApi) AnncList(c *gin.Context) { func (this *AnncApi) AnncList(c *gin.Context) {
var anncList []system.Annc var anncList []system.Annc
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Find(&anncList).Error err := f5.GetApp().GetOrmDb(constant.CONF_DB).Find(&anncList).Error
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -39,7 +40,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
return return
} }
var count int64 var count int64
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_announcement").Where("model = ?", annc.Model).Where("type = ?", annc.Type).Count(&count) f5.GetApp().GetOrmDb(constant.CONF_DB).Table(annc.TableName()).Where("model = ?", annc.Model).Where("type = ?", annc.Type).Count(&count)
if count > 0 { if count > 0 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -48,7 +49,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
return return
} }
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&annc).Error err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(&annc).Error
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -65,7 +66,8 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
func (this *AnncApi) UpdateAnnc(c *gin.Context) { func (this *AnncApi) UpdateAnnc(c *gin.Context) {
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64) idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
var count int64 var count int64
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_announcement").Where("idx = ?", idx).Count(&count) annc := system.Annc{}
f5.GetApp().GetOrmDb(constant.CONF_DB).Table(annc.TableName()).Where("idx = ?", idx).Count(&count)
if count < 1 { if count < 1 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -73,7 +75,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
}) })
return return
} }
annc := system.Annc{}
if err := c.ShouldBindJSON(&annc); err != nil { if err := c.ShouldBindJSON(&annc); err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -81,7 +83,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
}) })
return return
} }
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&annc).Error err := f5.GetApp().GetOrmDb(constant.CONF_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&annc).Error
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,

View File

@ -2,11 +2,12 @@ package system
import ( import (
"f5" "f5"
"github.com/gin-gonic/gin"
"main/constant" "main/constant"
"main/model/system" "main/model/system"
"net/http" "net/http"
"strconv" "strconv"
"github.com/gin-gonic/gin"
) )
type AuditApi struct { type AuditApi struct {
@ -14,7 +15,7 @@ type AuditApi struct {
func (this *AuditApi) AuditList(c *gin.Context) { func (this *AuditApi) AuditList(c *gin.Context) {
var auditList []system.Audit var auditList []system.Audit
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Find(&auditList).Error err := f5.GetApp().GetOrmDb(constant.CONF_DB).Find(&auditList).Error
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -39,7 +40,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
return return
} }
var count int64 var count int64
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_audit").Where("model = ?", audit.Model).Count(&count) f5.GetApp().GetOrmDb(constant.CONF_DB).Table(audit.TableName()).Where("model = ?", audit.Model).Count(&count)
if count > 0 { if count > 0 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -48,7 +49,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
return return
} }
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&audit).Error err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(&audit).Error
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -64,8 +65,9 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
func (this *AuditApi) UpdateAudit(c *gin.Context) { func (this *AuditApi) UpdateAudit(c *gin.Context) {
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64) idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
audit := system.Audit{}
var count int64 var count int64
f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Table("t_audit").Where("idx = ?", idx).Count(&count) f5.GetApp().GetOrmDb(constant.CONF_DB).Table(audit.TableName()).Where("idx = ?", idx).Count(&count)
if count < 1 { if count < 1 {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -73,7 +75,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
}) })
return return
} }
audit := system.Audit{}
if err := c.ShouldBindJSON(&audit); err != nil { if err := c.ShouldBindJSON(&audit); err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
@ -81,7 +83,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
}) })
return return
} }
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&audit).Error err := f5.GetApp().GetOrmDb(constant.CONF_DB).Select("*").Omit("idx").Where("idx = ?", idx).Updates(&audit).Error
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,

View File

@ -18,10 +18,10 @@ func (this *GameSwitchApi) List(c *gin.Context) {
page := c.DefaultQuery("page", "") page := c.DefaultQuery("page", "")
result := []*system.GameSwitch{} result := []*system.GameSwitch{}
f5.GetGoStyleDb().PageQuery( f5.GetGoStyleDb().PageQuery(
constant.GAME_DB, constant.CONF_DB,
q5.ToInt32(pagesize), q5.ToInt32(pagesize),
q5.ToInt32(page), q5.ToInt32(page),
"SELECT * FROM t_switch WHERE 1=1", "SELECT * FROM t_game_switch WHERE 1=1",
[]string{}, []string{},
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...), f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
"", "",
@ -69,7 +69,7 @@ func (this *GameSwitchApi) Add(c *gin.Context) {
return return
} }
if err := f5.GetApp().GetOrmDb(constant.GAME_DB).Where("switch_name = ?", req.Name).Take(new(system.GameSwitch)).Error; err == nil { if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Where("switch_name = ?", req.Name).Take(new(system.GameSwitch)).Error; err == nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
"message": "已存在", "message": "已存在",
@ -83,7 +83,7 @@ func (this *GameSwitchApi) Add(c *gin.Context) {
gswitch.Remark = req.Remark gswitch.Remark = req.Remark
gswitch.CreateTime = nowDaySeconds gswitch.CreateTime = nowDaySeconds
gswitch.ModifyTime = nowDaySeconds gswitch.ModifyTime = nowDaySeconds
if err := f5.GetApp().GetOrmDb(constant.GAME_DB).Create(gswitch).Error; err != nil { if err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(gswitch).Error; err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 1, "code": 1,
"message": err.Error(), "message": err.Error(),
@ -111,7 +111,7 @@ func (this *GameSwitchApi) Edit(c *gin.Context) {
return return
} }
gswitch := new(system.GameSwitch) gswitch := new(system.GameSwitch)
db := f5.GetApp().GetOrmDb(constant.GAME_DB) db := f5.GetApp().GetOrmDb(constant.CONF_DB)
if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil { if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) { if !f5.IsOrmErrRecordNotFound(err) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
@ -159,7 +159,7 @@ func (this *GameSwitchApi) Del(c *gin.Context) {
return return
} }
gswitch := new(system.GameSwitch) gswitch := new(system.GameSwitch)
db := f5.GetApp().GetOrmDb(constant.GAME_DB) db := f5.GetApp().GetOrmDb(constant.CONF_DB)
if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil { if err := db.Take(gswitch, "switch_name = ?", req.Name).Error; err != nil {
if !f5.IsOrmErrRecordNotFound(err) { if !f5.IsOrmErrRecordNotFound(err) {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{

View File

@ -13,8 +13,8 @@ import (
) )
type app struct { type app struct {
initCb func() initCb func()
unInitCb func() unInitCb func()
} }
func (this *app) GetPkgName() string { func (this *app) GetPkgName() string {
@ -91,6 +91,14 @@ func (this *app) registerDataSources() {
mt.Table.MailDb.GetById(0).GetPasswd(), mt.Table.MailDb.GetById(0).GetPasswd(),
mt.Table.MailDb.GetById(0).GetDatabase(), mt.Table.MailDb.GetById(0).GetDatabase(),
) )
f5.GetApp().RegisterOrmDb(
constant.CONF_DB,
mt.Table.ConfDb.GetById(0).GetHost(),
mt.Table.ConfDb.GetById(0).GetPort(),
mt.Table.ConfDb.GetById(0).GetUser(),
mt.Table.ConfDb.GetById(0).GetPasswd(),
mt.Table.ConfDb.GetById(0).GetDatabase(),
)
f5.GetGoStyleDb().RegisterDataSource( f5.GetGoStyleDb().RegisterDataSource(
constant.MAIL_DB, constant.MAIL_DB,
mt.Table.MailDb.GetById(0).GetHost(), mt.Table.MailDb.GetById(0).GetHost(),
@ -121,21 +129,31 @@ func (this *app) registerDataSources() {
1, 1,
mt.Table.NFTDb.GetById(0).GetMaxOpenConns(), mt.Table.NFTDb.GetById(0).GetMaxOpenConns(),
mt.Table.NFTDb.GetById(0).GetMaxIdleConns()) mt.Table.NFTDb.GetById(0).GetMaxIdleConns())
f5.GetGoStyleDb().RegisterDataSource(
constant.CONF_DB,
mt.Table.ConfDb.GetById(0).GetHost(),
mt.Table.ConfDb.GetById(0).GetPort(),
mt.Table.ConfDb.GetById(0).GetUser(),
mt.Table.ConfDb.GetById(0).GetPasswd(),
mt.Table.ConfDb.GetById(0).GetDatabase(),
1,
mt.Table.ConfDb.GetById(0).GetMaxOpenConns(),
mt.Table.ConfDb.GetById(0).GetMaxIdleConns())
} }
func (this *app) AddSession(accountId string) string { func (this *app) AddSession(accountId string) string {
/* /*
this.sessionLock.Lock() this.sessionLock.Lock()
defer this.sessionLock.Unlock() defer this.sessionLock.Unlock()
uuid := f5.GetApp().NewGlobalUuid() uuid := f5.GetApp().NewGlobalUuid()
str := fmt.Sprintf("%s%d%s%d", accountId, uuid, randStringBytes(12), time.Now().Unix()) str := fmt.Sprintf("%s%d%s%d", accountId, uuid, randStringBytes(12), time.Now().Unix())
md5New := md5.New() md5New := md5.New()
strByte := []byte(str) strByte := []byte(str)
md5New.Write(strByte) md5New.Write(strByte)
md5String := hex.EncodeToString(md5New.Sum(nil)) md5String := hex.EncodeToString(md5New.Sum(nil))
token := accountId + "|" + md5String token := accountId + "|" + md5String
this.sessionHash[accountId] = token this.sessionHash[accountId] = token
return token return token
*/ */
return "" return ""
} }

View File

@ -11,6 +11,7 @@ const (
ACCOUNT_DB = "accountdb" ACCOUNT_DB = "accountdb"
MAIL_DB = "maildb" MAIL_DB = "maildb"
BCNFT_DB = "bcnftdb" BCNFT_DB = "bcnftdb"
CONF_DB = "confdb"
) )
const ( const (

View File

@ -11,5 +11,5 @@ type Annc struct {
} }
func (this Annc) TableName() string { func (this Annc) TableName() string {
return "t_announcement" return "t_login_annc"
} }

View File

@ -10,5 +10,5 @@ type GameSwitch struct {
} }
func (GameSwitch) TableName() string { func (GameSwitch) TableName() string {
return "t_switch" return "t_game_switch"
} }

View File

@ -0,0 +1,14 @@
package mt
import (
"f5"
"mtb"
)
type ConfDb struct {
mtb.ConfDb
}
type ConfDbTable struct {
f5.IdMetaTable[ConfDb]
}

View File

@ -15,6 +15,7 @@ type table struct {
Config *ConfigTable Config *ConfigTable
NFTDb *NFTDbTable NFTDb *NFTDbTable
Permission *PermissionTable Permission *PermissionTable
ConfDb *ConfDbTable
} }
var Table = f5.New(func(this *table) { var Table = f5.New(func(this *table) {
@ -62,5 +63,10 @@ var Table = f5.New(func(this *table) {
this.PrimKey = "" this.PrimKey = ""
}) })
this.ConfDb = f5.New(func(this *ConfDbTable) {
this.FileName = "../config/confdb.mysql.json"
this.PrimKey = ""
})
this.Permission = new(PermissionTable) this.Permission = new(PermissionTable)
}) })

View File

@ -105,6 +105,19 @@ type NFTDb struct {
_flags2_ uint64 _flags2_ uint64
} }
type ConfDb struct {
host string
port int32
user string
passwd string
database string
max_open_conns int32
max_idle_conns int32
_flags1_ uint64
_flags2_ uint64
}
func (this *AdminCluster) GetInstanceId() int32 { func (this *AdminCluster) GetInstanceId() int32 {
return this.instance_id return this.instance_id
} }
@ -481,6 +494,62 @@ func (this *NFTDb) HasMaxIdleConns() bool {
return (this._flags1_ & (uint64(1) << 7)) > 0 return (this._flags1_ & (uint64(1) << 7)) > 0
} }
func (this *ConfDb) GetHost() string {
return this.host
}
func (this *ConfDb) HasHost() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0
}
func (this *ConfDb) GetPort() int32 {
return this.port
}
func (this *ConfDb) HasPort() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0
}
func (this *ConfDb) GetUser() string {
return this.user
}
func (this *ConfDb) HasUser() bool {
return (this._flags1_ & (uint64(1) << 3)) > 0
}
func (this *ConfDb) GetPasswd() string {
return this.passwd
}
func (this *ConfDb) HasPasswd() bool {
return (this._flags1_ & (uint64(1) << 4)) > 0
}
func (this *ConfDb) GetDatabase() string {
return this.database
}
func (this *ConfDb) HasDatabase() bool {
return (this._flags1_ & (uint64(1) << 5)) > 0
}
func (this *ConfDb) GetMaxOpenConns() int32 {
return this.max_open_conns
}
func (this *ConfDb) HasMaxOpenConns() bool {
return (this._flags1_ & (uint64(1) << 6)) > 0
}
func (this *ConfDb) GetMaxIdleConns() int32 {
return this.max_idle_conns
}
func (this *ConfDb) HasMaxIdleConns() bool {
return (this._flags1_ & (uint64(1) << 7)) > 0
}
func (this *AdminCluster) LoadFromKv(kv map[string]interface{}) { func (this *AdminCluster) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv) f5.ReadMetaTableField(&this.instance_id, "instance_id", &this._flags1_, 1, kv)
@ -555,3 +624,13 @@ func (this *NFTDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.max_open_conns, "max_open_conns", &this._flags1_, 6, kv) f5.ReadMetaTableField(&this.max_open_conns, "max_open_conns", &this._flags1_, 6, kv)
f5.ReadMetaTableField(&this.max_idle_conns, "max_idle_conns", &this._flags1_, 7, kv) f5.ReadMetaTableField(&this.max_idle_conns, "max_idle_conns", &this._flags1_, 7, kv)
} }
func (this *ConfDb) LoadFromKv(kv map[string]interface{}) {
f5.ReadMetaTableField(&this.host, "host", &this._flags1_, 1, kv)
f5.ReadMetaTableField(&this.port, "port", &this._flags1_, 2, kv)
f5.ReadMetaTableField(&this.user, "user", &this._flags1_, 3, kv)
f5.ReadMetaTableField(&this.passwd, "passwd", &this._flags1_, 4, kv)
f5.ReadMetaTableField(&this.database, "database", &this._flags1_, 5, kv)
f5.ReadMetaTableField(&this.max_open_conns, "max_open_conns", &this._flags1_, 6, kv)
f5.ReadMetaTableField(&this.max_idle_conns, "max_idle_conns", &this._flags1_, 7, kv)
}

View File

@ -84,3 +84,14 @@ message NFTDb
optional int32 max_open_conns = 6; optional int32 max_open_conns = 6;
optional int32 max_idle_conns = 7; optional int32 max_idle_conns = 7;
} }
message ConfDb
{
optional string host = 1;
optional int32 port = 2;
optional string user = 3;
optional string passwd = 4;
optional string database = 5;
optional int32 max_open_conns = 6;
optional int32 max_idle_conns = 7;
}