121 lines
3.6 KiB
Go
121 lines
3.6 KiB
Go
package common
|
|
|
|
import (
|
|
config2 "SciencesServer/app/basic/config"
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/config"
|
|
"SciencesServer/serve/orm"
|
|
)
|
|
|
|
type synchronized struct {
|
|
iModel model.IModel
|
|
iValues func() interface{}
|
|
Catch func() interface{}
|
|
}
|
|
|
|
type caches struct {
|
|
iModel model.IModel
|
|
iValues func() interface{}
|
|
toCache func(values interface{})
|
|
}
|
|
|
|
func initModel() {
|
|
db := orm.GetDB()
|
|
|
|
function := func(synchronized ...*synchronized) {
|
|
for _, v := range synchronized {
|
|
if !db.Migrator().HasTable(v.iModel) {
|
|
_ = db.Migrator().CreateTable(v.iModel)
|
|
|
|
if v.iValues != nil && v.iValues() != nil {
|
|
db.Table(v.iModel.TableName()).Create(v.iValues())
|
|
}
|
|
} else if v.Catch != nil && v.Catch() != nil {
|
|
v.Catch()
|
|
}
|
|
}
|
|
}
|
|
function(
|
|
&synchronized{iModel: model.NewSysTenant()}, &synchronized{iModel: model.NewSysTenantMenu()},
|
|
&synchronized{iModel: model.NewSysConfig()},
|
|
&synchronized{iModel: model.NewSysMenu()}, &synchronized{iModel: model.NewSysAuth()},
|
|
&synchronized{iModel: model.NewSysUser(), iValues: func() interface{} {
|
|
return &model.SysUser{Account: "admin", Name: "商挈智能", Mobile: "13888888888", Password: "123456",
|
|
IsAdmin: model.SysUserAdministratorForAdmin, Remark: "超级管理员"}
|
|
}},
|
|
&synchronized{iModel: model.NewSysUserTenant()},
|
|
&synchronized{iModel: model.NewSysDepartment()},
|
|
&synchronized{iModel: model.NewSysRole()}, &synchronized{iModel: model.NewSysRoleMenu()}, &synchronized{iModel: model.NewSysRoleAuth()},
|
|
// 配置管理
|
|
&synchronized{iModel: model.NewSysConfig(), iValues: func() interface{} {
|
|
return nil
|
|
}},
|
|
&synchronized{iModel: model.NewSysPatent(), iValues: func() interface{} {
|
|
return nil
|
|
}},
|
|
&synchronized{iModel: model.NewSysIdentity(), iValues: func() interface{} {
|
|
out := make([]*model.SysIdentity, 0)
|
|
|
|
for k, v := range config2.TenantUserIdentityData {
|
|
registerCount := 1
|
|
|
|
if k == config2.TenantUserIdentityForCompany {
|
|
registerCount = -1
|
|
}
|
|
out = append(out, &model.SysIdentity{
|
|
Identity: k,
|
|
Name: v,
|
|
RegisterCount: registerCount,
|
|
IsExamine: 1,
|
|
})
|
|
}
|
|
return out
|
|
}},
|
|
// 日志管理
|
|
&synchronized{iModel: model.NewSysUserRole()},
|
|
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
|
// 用户管理
|
|
&synchronized{iModel: model.NewUserInstance()}, &synchronized{iModel: model.NewUserIdentity()},
|
|
&synchronized{iModel: model.NewUserPatent()}, &synchronized{iModel: model.NewUserBank()},
|
|
&synchronized{iModel: model.NewUserCompany()}, &synchronized{iModel: model.NewUserExpert()},
|
|
&synchronized{iModel: model.NewUserLaboratory()}, &synchronized{iModel: model.NewUserResearch()},
|
|
&synchronized{iModel: model.NewUserAgent()},
|
|
// 入驻管理
|
|
&synchronized{iModel: model.NewManageCompany()}, &synchronized{iModel: model.NewManageExpert()},
|
|
&synchronized{iModel: model.NewManageLaboratory()}, &synchronized{iModel: model.NewManageResearch()},
|
|
&synchronized{iModel: model.NewManageAgent()},
|
|
)
|
|
}
|
|
func initCacheMode() {
|
|
db := orm.GetDB()
|
|
|
|
function := func(cache ...*caches) {
|
|
for _, v := range cache {
|
|
if db.Migrator().HasTable(v.iModel) {
|
|
if v.iValues != nil {
|
|
if values := v.iValues(); values != nil {
|
|
v.toCache(values)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function(
|
|
&caches{iModel: model.NewSysTenant(), iValues: func() interface{} {
|
|
out := make([]*model.SysConfig, 0)
|
|
_ = model.Find(model.NewSysConfig(), &out)
|
|
return out
|
|
}, toCache: func(values interface{}) {
|
|
out := values.([]*model.SysConfig)
|
|
for _, v := range out {
|
|
config.SystemConfig[v.Key] = v.Value
|
|
}
|
|
}},
|
|
)
|
|
}
|
|
|
|
func Init() {
|
|
initModel()
|
|
initCacheMode()
|
|
}
|