调整
This commit is contained in:
parent
8bb0996d7d
commit
898e8d31f0
@ -1,12 +1,13 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"f5"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AnncApi struct {
|
||||
@ -14,7 +15,7 @@ type AnncApi struct {
|
||||
|
||||
func (this *AnncApi) AnncList(c *gin.Context) {
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -39,7 +40,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -48,7 +49,7 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&annc).Error
|
||||
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(&annc).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -65,7 +66,8 @@ func (this *AnncApi) AddAnnc(c *gin.Context) {
|
||||
func (this *AnncApi) UpdateAnnc(c *gin.Context) {
|
||||
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -73,7 +75,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
annc := system.Annc{}
|
||||
|
||||
if err := c.ShouldBindJSON(&annc); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -81,7 +83,7 @@ func (this *AnncApi) UpdateAnnc(c *gin.Context) {
|
||||
})
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
|
@ -2,11 +2,12 @@ package system
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"github.com/gin-gonic/gin"
|
||||
"main/constant"
|
||||
"main/model/system"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AuditApi struct {
|
||||
@ -14,7 +15,7 @@ type AuditApi struct {
|
||||
|
||||
func (this *AuditApi) AuditList(c *gin.Context) {
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -39,7 +40,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -48,7 +49,7 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err := f5.GetApp().GetOrmDb(constant.ACCOUNT_DB).Create(&audit).Error
|
||||
err := f5.GetApp().GetOrmDb(constant.CONF_DB).Create(&audit).Error
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -64,8 +65,9 @@ func (this *AuditApi) AddAudit(c *gin.Context) {
|
||||
|
||||
func (this *AuditApi) UpdateAudit(c *gin.Context) {
|
||||
idx, _ := strconv.ParseUint(c.Param("idx"), 10, 64)
|
||||
audit := system.Audit{}
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -73,7 +75,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
audit := system.Audit{}
|
||||
|
||||
if err := c.ShouldBindJSON(&audit); err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
@ -81,7 +83,7 @@ func (this *AuditApi) UpdateAudit(c *gin.Context) {
|
||||
})
|
||||
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 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 1,
|
||||
|
@ -18,10 +18,10 @@ func (this *GameSwitchApi) List(c *gin.Context) {
|
||||
page := c.DefaultQuery("page", "")
|
||||
result := []*system.GameSwitch{}
|
||||
f5.GetGoStyleDb().PageQuery(
|
||||
constant.GAME_DB,
|
||||
constant.CONF_DB,
|
||||
q5.ToInt32(pagesize),
|
||||
q5.ToInt32(page),
|
||||
"SELECT * FROM t_switch WHERE 1=1",
|
||||
"SELECT * FROM t_game_switch WHERE 1=1",
|
||||
[]string{},
|
||||
f5.GetDbFilter().Comp([]f5.DbQueryFilter{}...),
|
||||
"",
|
||||
@ -69,7 +69,7 @@ func (this *GameSwitchApi) Add(c *gin.Context) {
|
||||
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{
|
||||
"code": 1,
|
||||
"message": "已存在",
|
||||
@ -83,7 +83,7 @@ func (this *GameSwitchApi) Add(c *gin.Context) {
|
||||
gswitch.Remark = req.Remark
|
||||
gswitch.CreateTime = 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{
|
||||
"code": 1,
|
||||
"message": err.Error(),
|
||||
@ -111,7 +111,7 @@ func (this *GameSwitchApi) Edit(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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 !f5.IsOrmErrRecordNotFound(err) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
@ -159,7 +159,7 @@ func (this *GameSwitchApi) Del(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
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 !f5.IsOrmErrRecordNotFound(err) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
@ -91,6 +91,14 @@ func (this *app) registerDataSources() {
|
||||
mt.Table.MailDb.GetById(0).GetPasswd(),
|
||||
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(
|
||||
constant.MAIL_DB,
|
||||
mt.Table.MailDb.GetById(0).GetHost(),
|
||||
@ -121,6 +129,16 @@ func (this *app) registerDataSources() {
|
||||
1,
|
||||
mt.Table.NFTDb.GetById(0).GetMaxOpenConns(),
|
||||
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 {
|
||||
|
@ -11,6 +11,7 @@ const (
|
||||
ACCOUNT_DB = "accountdb"
|
||||
MAIL_DB = "maildb"
|
||||
BCNFT_DB = "bcnftdb"
|
||||
CONF_DB = "confdb"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -11,5 +11,5 @@ type Annc struct {
|
||||
}
|
||||
|
||||
func (this Annc) TableName() string {
|
||||
return "t_announcement"
|
||||
return "t_login_annc"
|
||||
}
|
||||
|
@ -10,5 +10,5 @@ type GameSwitch struct {
|
||||
}
|
||||
|
||||
func (GameSwitch) TableName() string {
|
||||
return "t_switch"
|
||||
return "t_game_switch"
|
||||
}
|
||||
|
14
server/adminserver/mt/ConfDb.go
Normal file
14
server/adminserver/mt/ConfDb.go
Normal file
@ -0,0 +1,14 @@
|
||||
package mt
|
||||
|
||||
import (
|
||||
"f5"
|
||||
"mtb"
|
||||
)
|
||||
|
||||
type ConfDb struct {
|
||||
mtb.ConfDb
|
||||
}
|
||||
|
||||
type ConfDbTable struct {
|
||||
f5.IdMetaTable[ConfDb]
|
||||
}
|
@ -15,6 +15,7 @@ type table struct {
|
||||
Config *ConfigTable
|
||||
NFTDb *NFTDbTable
|
||||
Permission *PermissionTable
|
||||
ConfDb *ConfDbTable
|
||||
}
|
||||
|
||||
var Table = f5.New(func(this *table) {
|
||||
@ -62,5 +63,10 @@ var Table = f5.New(func(this *table) {
|
||||
this.PrimKey = ""
|
||||
})
|
||||
|
||||
this.ConfDb = f5.New(func(this *ConfDbTable) {
|
||||
this.FileName = "../config/confdb.mysql.json"
|
||||
this.PrimKey = ""
|
||||
})
|
||||
|
||||
this.Permission = new(PermissionTable)
|
||||
})
|
||||
|
@ -105,6 +105,19 @@ type NFTDb struct {
|
||||
_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 {
|
||||
return this.instance_id
|
||||
}
|
||||
@ -481,6 +494,62 @@ func (this *NFTDb) HasMaxIdleConns() bool {
|
||||
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{}) {
|
||||
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_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)
|
||||
}
|
||||
|
@ -84,3 +84,14 @@ message NFTDb
|
||||
optional int32 max_open_conns = 6;
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user