2021-11-02 10:02:52 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"ArmedPolice/app/common/model"
|
|
|
|
"ArmedPolice/config"
|
|
|
|
"ArmedPolice/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(
|
2021-11-02 17:01:04 +08:00
|
|
|
&synchronized{iModel: model.NewSysTenant()},
|
2021-11-02 10:02:52 +08:00
|
|
|
&synchronized{iModel: model.NewSysConfig()},
|
|
|
|
&synchronized{iModel: model.NewSysMenu()}, &synchronized{iModel: model.NewSysAuth()},
|
|
|
|
&synchronized{iModel: model.NewSysUser(), iValues: func() interface{} {
|
2021-11-02 16:22:07 +08:00
|
|
|
return &model.SysUser{Account: "admin", Name: "超级管理员", Mobile: "13888888888", Password: "123456",
|
2021-11-02 10:02:52 +08:00
|
|
|
IsAdmin: model.SysUserAdministratorForAdmin, Remark: "超级管理员"}
|
|
|
|
}},
|
|
|
|
&synchronized{iModel: model.NewSysRole()}, &synchronized{iModel: model.NewSysRoleMenu()}, &synchronized{iModel: model.NewSysRoleAuth()},
|
|
|
|
&synchronized{iModel: model.NewSysUserRole()},
|
|
|
|
// 日志管理
|
|
|
|
&synchronized{iModel: model.NewSysLog()}, &synchronized{iModel: model.NewSysUserLoginLog()},
|
2021-11-05 15:27:04 +08:00
|
|
|
&synchronized{iModel: model.NewSysBreakdown()},
|
2021-11-15 17:32:23 +08:00
|
|
|
// 公告管理
|
|
|
|
&synchronized{iModel: model.NewManageNotice()},
|
2021-11-02 16:22:07 +08:00
|
|
|
// 功能信息
|
2021-11-16 11:46:44 +08:00
|
|
|
&synchronized{iModel: model.NewManageSupplier()}, &synchronized{iModel: model.NewManageSupplierEvaluate()},
|
2021-11-09 14:08:02 +08:00
|
|
|
&synchronized{iModel: model.NewManageEquipment()}, &synchronized{iModel: model.NewManageEquipmentMaterial()},
|
2021-11-04 11:10:51 +08:00
|
|
|
&synchronized{iModel: model.NewManageMaterial()}, &synchronized{iModel: model.NewManageMaterialSupplier()},
|
|
|
|
&synchronized{iModel: model.NewManageMaterialPurchase()}, &synchronized{iModel: model.NewManageMaterialWarehouse()},
|
2021-11-11 14:05:52 +08:00
|
|
|
&synchronized{iModel: model.NewWorkInstance()}, &synchronized{iModel: model.NewWorkMaterial()}, &synchronized{iModel: model.NewWorkProgress()},
|
2021-11-19 09:24:15 +08:00
|
|
|
&synchronized{iModel: model.NewWorkSchedule()}, &synchronized{iModel: model.NewWorkPurchase()},
|
2021-11-12 11:14:58 +08:00
|
|
|
&synchronized{iModel: model.NewWorkRepair()}, &synchronized{iModel: model.NewWorkRepairDetail()},
|
2021-11-02 10:02:52 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
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(
|
2021-11-15 17:32:23 +08:00
|
|
|
&caches{iModel: model.NewSysConfig(), iValues: func() interface{} {
|
2021-11-02 10:02:52 +08:00
|
|
|
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() {
|
2021-11-15 17:32:23 +08:00
|
|
|
if *config.Init {
|
|
|
|
initModel()
|
|
|
|
}
|
2021-11-02 10:02:52 +08:00
|
|
|
initCacheMode()
|
|
|
|
}
|