diff --git a/core/comm/db.go b/core/comm/db.go index 16b5bf9..c1cf7bd 100644 --- a/core/comm/db.go +++ b/core/comm/db.go @@ -8,12 +8,12 @@ import ( ) var ( - DbMain *xorm.Engine + DbSys *xorm.Engine DbMongo *mgo.Session ) func InitDb() error { - err := initDbMain() + err := initDbSys() if err != nil { return err } @@ -23,8 +23,8 @@ func InitDb() error { } return nil } -func initDbMain() error { - cnf := gocloud.CloudConf.Datasorce["main"] +func initDbSys() error { + cnf := gocloud.CloudConf.Datasorce["sys"] if !cnf.Enable { return nil } @@ -41,7 +41,7 @@ func initDbMain() error { println("db RegisterSqlTemplate error : " + err.Error()) } - DbMain = db + DbSys = db return nil } diff --git a/service/sysService/file.go b/service/sysService/file.go index f78de12..240c627 100644 --- a/service/sysService/file.go +++ b/service/sysService/file.go @@ -7,7 +7,7 @@ import ( func FindFile(uuid string) *models.SysFile { e := new(models.SysFile) - ok, err := comm.DbMain.Where("uuid=?", uuid).Get(e) + ok, err := comm.DbSys.Where("uuid=?", uuid).Get(e) if err != nil { return nil } diff --git a/service/sysService/param.go b/service/sysService/param.go index f6ed7d3..c96902c 100644 --- a/service/sysService/param.go +++ b/service/sysService/param.go @@ -10,7 +10,7 @@ import ( func FindParam(key string) *models.SysParam { e := new(models.SysParam) - ok, err := comm.DbMain.Where("name=?", key).Get(e) + ok, err := comm.DbSys.Where("name=?", key).Get(e) if err != nil { return nil } @@ -22,7 +22,7 @@ func FindParam(key string) *models.SysParam { func GetParam(key string) map[string]interface{} { e := new(models.SysParam) - ok, err := comm.DbMain.Where("name=?", key).Get(e) + ok, err := comm.DbSys.Where("name=?", key).Get(e) if err != nil { return nil } @@ -43,7 +43,7 @@ func GetParam(key string) map[string]interface{} { func SetParam(key string, val *map[string]interface{}, tits ...string) bool { e := new(models.SysParam) - ok, err := comm.DbMain.Where("name=?", key).Get(e) + ok, err := comm.DbSys.Where("name=?", key).Get(e) if err != nil { return false } @@ -58,12 +58,12 @@ func SetParam(key string, val *map[string]interface{}, tits ...string) bool { } if ok { - comm.DbMain.Where("uuid=?", e.Uuid).Update(e) + comm.DbSys.Where("uuid=?", e.Uuid).Update(e) } else { e.Uuid = uuid.NewV4().String() e.Name = key e.Times = time.Now() - comm.DbMain.Insert(e) + comm.DbSys.Insert(e) } return true diff --git a/service/sysService/role.go b/service/sysService/role.go index 1e60b48..819a7d6 100644 --- a/service/sysService/role.go +++ b/service/sysService/role.go @@ -9,7 +9,7 @@ import ( func FindRole(uuid string) *models.SysRole { e := new(models.SysRole) - ok, err := comm.DbMain.Where("uuid=?", uuid).Get(e) + ok, err := comm.DbSys.Where("uuid=?", uuid).Get(e) if err != nil { return nil } @@ -20,7 +20,7 @@ func FindRole(uuid string) *models.SysRole { } func FindPermission(uuid string) *models.SysPermssion { e := new(models.SysPermssion) - ok, err := comm.DbMain.Where("uuid=?", uuid).Get(e) + ok, err := comm.DbSys.Where("uuid=?", uuid).Get(e) if err != nil { return nil } @@ -36,7 +36,7 @@ func FindPermissions(uuids string) string { rets := "" permssions := make([]*models.SysPermssion, 0) - err := comm.DbMain.Where(builder.In("uuid", strings.Split(uuids, ","))).Find(&permssions) + err := comm.DbSys.Where(builder.In("uuid", strings.Split(uuids, ","))).Find(&permssions) if err == nil { ln := len(permssions) for i, o := range permssions { diff --git a/service/userService/role.go b/service/userService/role.go index a093942..521ad0c 100644 --- a/service/userService/role.go +++ b/service/userService/role.go @@ -16,7 +16,7 @@ import ( func FindTreePermission() []*modeluis.TreePermssion { rets := make([]*modeluis.TreePermssion, 0) - err := comm.DbMain.Where("parent is null or parent=''").OrderBy("sort ASC,id ASC").Find(&rets) + err := comm.DbSys.Where("parent is null or parent=''").OrderBy("sort ASC,id ASC").Find(&rets) if err != nil { println("findPermChilds err:" + err.Error()) return nil @@ -33,7 +33,7 @@ func findPermChilds(parent *modeluis.TreePermssion, upms map[string]bool) { return } childs := make([]*modeluis.TreePermssion, 0) - err := comm.DbMain.Where("parent=?", parent.Uuid).OrderBy("sort ASC,id ASC").Find(&childs) + err := comm.DbSys.Where("parent=?", parent.Uuid).OrderBy("sort ASC,id ASC").Find(&childs) if err != nil { println("findPermChilds err:" + err.Error()) return @@ -57,9 +57,9 @@ func FindUPermissions(uid string) []*modeluis.SysPermssion { } perms := make(map[string]*modeluis.SysPermssion) userRole := FindUserRole(uid) - //comm.DbMain.SqlTemplateClient("role.stpl") + //comm.DbSys.SqlTemplateClient("role.stpl") //rids:=strings.Split(userRole.RoleCodes,",") - ses := comm.DbMain.Where("uuid='common'") + ses := comm.DbSys.Where("uuid='common'") if len(userRole.RoleCodes) > 0 { rcds := strings.Split(userRole.RoleCodes, ",") ses.Or(builder.In("uuid", rcds)) @@ -75,7 +75,7 @@ func FindUPermissions(uid string) []*modeluis.SysPermssion { continue } permssions := make([]*modeluis.SysPermssion, 0) - ses := comm.DbMain.Where(builder.In("uuid", strings.Split(role.Perms, ","))) + ses := comm.DbSys.Where(builder.In("uuid", strings.Split(role.Perms, ","))) err := ses.Find(&permssions) if err != nil { println("FindUserPermission err:" + err.Error()) @@ -109,12 +109,12 @@ func FindUPermissions(uid string) []*modeluis.SysPermssion { } func FindUserRole(uid string) *models.SysUserRole { userRole := new(models.SysUserRole) - ok, err := comm.DbMain.Where("user_code=?", uid).Get(userRole) + ok, err := comm.DbSys.Where("user_code=?", uid).Get(userRole) if err != nil { println("FindUserPermission err:" + err.Error()) } else if !ok { userRole.UserCode = uid - comm.DbMain.Insert(userRole) + comm.DbSys.Insert(userRole) } return userRole } @@ -128,7 +128,7 @@ func FindUserRoles(uid string) []*modeluis.SysURole { } } roles := make([]*modeluis.SysURole, 0) - err := comm.DbMain.Where("uuid!='common'").Find(&roles) + err := comm.DbSys.Where("uuid!='common'").Find(&roles) if err != nil { println("FindUserRoles:" + err.Error()) } @@ -141,9 +141,9 @@ func FindUserRoles(uid string) []*modeluis.SysURole { func FindUserPermission(uid string) map[string]bool { perms := make(map[string]bool) userRole := FindUserRole(uid) - //comm.DbMain.SqlTemplateClient("role.stpl") + //comm.DbSys.SqlTemplateClient("role.stpl") //rids:=strings.Split(userRole.RoleCodes,",") - ses := comm.DbMain.Where("uuid='common'") + ses := comm.DbSys.Where("uuid='common'") if len(userRole.RoleCodes) > 0 { rcds := strings.Split(userRole.RoleCodes, ",") ses.Or(builder.In("uuid", rcds)) @@ -159,7 +159,7 @@ func FindUserPermission(uid string) map[string]bool { continue } permssions := make([]*models.SysPermssion, 0) - ses := comm.DbMain.Where(builder.In("uuid", strings.Split(role.Perms, ","))) + ses := comm.DbSys.Where(builder.In("uuid", strings.Split(role.Perms, ","))) if len(userRole.Limits) > 0 { rcds := strings.Split(userRole.Limits, ",") ses.And(builder.NotIn("uuid", rcds)) diff --git a/service/userService/user.go b/service/userService/user.go index 8659a4b..ca41508 100644 --- a/service/userService/user.go +++ b/service/userService/user.go @@ -14,7 +14,7 @@ func FindUUID(id string) *models.SysUser { return nil } e := new(models.SysUser) - ok, err := comm.DbMain.Where("uuid=?", id).Get(e) + ok, err := comm.DbSys.Where("uuid=?", id).Get(e) if err != nil { logger.Info("FindUserUUID err:", err.Error()) return nil @@ -26,7 +26,7 @@ func FindUUID(id string) *models.SysUser { } func FindName(name string) *models.SysUser { e := new(models.SysUser) - ok, err := comm.DbMain.Where("name=?", name).Get(e) + ok, err := comm.DbSys.Where("name=?", name).Get(e) if err != nil { logger.Info("FindName err:", err.Error()) return nil diff --git a/webs/sys/app.yml b/webs/sys/app.yml index a9db481..1647a7d 100644 --- a/webs/sys/app.yml +++ b/webs/sys/app.yml @@ -31,7 +31,7 @@ consul: reghost: localhost #tags: [123,345,654] datasorce: - main: + sys: enable: true driver: mysql url: root:root@tcp(localhost:3306)/test?charset=utf8 diff --git a/webs/sys/controller/user.go b/webs/sys/controller/user.go index 91828a1..129efd1 100644 --- a/webs/sys/controller/user.go +++ b/webs/sys/controller/user.go @@ -49,7 +49,7 @@ func (e *UserController) login(c *macaron.Context, ctj gocloud.ContJSON) { } usr.Logintm = time.Now() - comm.DbMain.Cols("logintm").Where("uuid=?", usr.Uuid).Update(usr) + comm.DbSys.Cols("logintm").Where("uuid=?", usr.Uuid).Update(usr) c.PlainText(200, []byte(usr.Uuid)) }