Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbiao committed Jan 20, 2020
2 parents 36d9df2 + 1355694 commit ae7c326
Show file tree
Hide file tree
Showing 79 changed files with 5,767 additions and 2,824 deletions.
7 changes: 6 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Change Log 更新说明
------------------------------
## 2020-01-13 v1.1.0
1. 安装gf官网建议项目目录进行重构
2. 使用gf gen model生成model层,但json使用驼峰格式
3. gf升级到最新版本V1.11.4

## 2020-01-13 v1.0.1
1. gf升级为V1.11.2,修改即将废弃函数
2. gtoken升级为v1.3.11
2. gtoken升级为v1.3.10

## 2019-12-24 v1.0.0
1. 发布gmanger v1.0.0 支持前后端分离
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
"gmanager/module/constants"
"gmanager/app/constants"
)

// Login 登录页面
Expand All @@ -16,7 +16,7 @@ func Welcome(r *ghttp.Request) {
}
}

// Login 登录页面
// 调试页面
func Debug(r *ghttp.Request) {
if constants.DEBUG {
constants.DEBUG = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/gogf/gf/os/glog"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv"
"gmanager/utils/base"
"gmanager/library/base"
)

func Error301(r *ghttp.Request) {
Expand Down
29 changes: 17 additions & 12 deletions module/common/loginAction.go → app/api/common/loginAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
"gmanager/module/constants"
"gmanager/module/system"
"gmanager/utils"
"gmanager/utils/base"
"gmanager/utils/bean"
"github.com/gogf/gf/util/gconv"
"gmanager/app/constants"
"gmanager/app/service/log"
"gmanager/app/service/user"
"gmanager/library"
"gmanager/library/base"
"gmanager/library/bean"
)

// Login 登录页面
Expand Down Expand Up @@ -42,7 +44,7 @@ func LoginSubmit(r *ghttp.Request) (string, interface{}) {
base.Fail(r, "用户名或密码为空")
}

model, err := system.SysUser{Username: username}.GetByUsername()
model, err := user.GetByUsername(username)
if err != nil {
base.Error(r, "服务异常,请联系管理员")
}
Expand Down Expand Up @@ -73,26 +75,29 @@ func LoginSubmit(r *ghttp.Request) (string, interface{}) {
}

// 登录日志
model.UpdateTime = utils.GetNow()
model.UpdateTime = library.GetNow()
model.UpdateId = model.Id
system.LogSave(model, system.LOGIN)
log.SaveLog(model, constants.LOGIN)

return username, sessionUser
}

// 登出
func LogoutBefore(r *ghttp.Request) bool {
userId := base.GetUser(r).Id
model := system.SysUser{Id: userId}.Get()
if model.Id != userId {
model, err := user.GetById(gconv.Int64(userId))
if err != nil {
glog.Warning("logout getUser error", err)
return false
} else if model.Id != userId {
// 登出用户不存在
glog.Warning("logout userId error", userId)
return false
}

// 登出日志
model.UpdateTime = utils.GetNow()
model.UpdateTime = library.GetNow()
model.UpdateId = userId
system.LogSave(model, system.LOGOUT)
log.SaveLog(model, constants.LOGOUT)
return true
}
132 changes: 132 additions & 0 deletions app/api/config/configAction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package config

import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"gmanager/app/service/config"
"gmanager/library/base"
)

type Action struct {
base.BaseRouter
}

// path: /index
func (action *Action) Index(r *ghttp.Request) {
tplFile := "pages/system/config_index.html"
err := r.Response.WriteTpl(tplFile, g.Map{
"now": gtime.Datetime(),
})

if err != nil {
glog.Error(err)
}
}

// path: /get/{id}
func (action *Action) Get(r *ghttp.Request) {
id := r.GetInt64("id")
model, err := config.GetById(id)
if err != nil {
base.Fail(r, err.Error())
}

base.Succ(r, model)
}

// path: /delete/{id}
func (action *Action) Delete(r *ghttp.Request) {
id := r.GetInt64("id")
_, err := config.Delete(id, base.GetUser(r).Id)
if err != nil {
base.Fail(r, err.Error())
}

base.Succ(r, "")
}

// path: /save
func (action *Action) Save(r *ghttp.Request) {
request := new(config.Request)
err := gconv.Struct(r.GetQueryMap(), request)
if err != nil {
glog.Error("save struct error", err)
base.Error(r, "获取参数异常")
}

request.UserId = base.GetUser(r).Id
_, err = config.Save(request)
if err != nil {
base.Fail(r, "保存失败")
}

base.Succ(r, "")
}

// path: /list
func (action *Action) List(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())

list, err := config.List(&form)
if err != nil {
glog.Error("page error", err)
base.Error(r, err.Error())
}

base.Succ(r, list)
}

// path: /page
func (action *Action) Page(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())
page, err := config.Page(&form)
if err != nil {
glog.Error("page error", err)
base.Error(r, err.Error())
}

base.Succ(r,
g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /jqgrid
func (action *Action) Jqgrid(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())
page, err := config.Page(&form)
if err != nil {
glog.Error("jqgrid error", err)
base.Error(r, err.Error())
}

r.Response.WriteJson(g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /type
func (action *Action) Type(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())

//userId := base.GetUser(r).Id
//user := SysUser{Id: userId}.Get()
form.SetParam("parentId", "0")
form.OrderBy = "sort asc,create_time desc"

list, err := config.List(&form)
if err != nil {
glog.Error("type error", err)
base.Error(r, err.Error())
}
base.Succ(r, list)
}
124 changes: 124 additions & 0 deletions app/api/department/departmentAction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package department

import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/os/glog"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv"
"gmanager/app/service/department"
"gmanager/library/base"
)

type Action struct {
base.BaseRouter
}

// path: /index
func (action *Action) Index(r *ghttp.Request) {
tplFile := "pages/system/department_index.html"
err := r.Response.WriteTpl(tplFile, g.Map{
"now": gtime.Datetime(),
})

if err != nil {
glog.Error(err)
}
}

// path: /get/{id}
func (action *Action) Get(r *ghttp.Request) {
id := r.GetInt64("id")
model, err := department.GetById(id)
if err != nil {
base.Fail(r, err.Error())
}

base.Succ(r, model)
}

// path: /delete/{id}
func (action *Action) Delete(r *ghttp.Request) {
id := r.GetInt64("id")

form := base.NewForm(g.Map{"parentId": id})
childModel, err := department.GetOne(&form)
if err != nil {
base.Fail(r, err.Error())
} else if childModel != nil && childModel.Id > 0 {
base.Fail(r, "请先删除子机构")
}

_, err = department.Delete(id, base.GetUser(r).Id)
if err != nil {
base.Fail(r, err.Error())
}

base.Succ(r, "")
}

// path: /save
func (action *Action) Save(r *ghttp.Request) {
request := new(department.Request)
err := gconv.Struct(r.GetQueryMap(), request)
if err != nil {
glog.Error("save struct error", err)
base.Error(r, "save error")
}

request.UserId = base.GetUser(r).Id
_, err = department.Save(request)
if err != nil {
base.Fail(r, "保存失败")
}

base.Succ(r, "")
}

// path: /list
func (action *Action) List(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())

list, err := department.List(&form)
if err != nil {
glog.Error("page error", err)
base.Error(r, err.Error())
}

base.Succ(r, list)
}

// path: /page
func (action *Action) Page(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())
page, err := department.Page(&form)
if err != nil {
glog.Error("page error", err)
base.Error(r, err.Error())
}

base.Succ(r,
g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}

// path: /jqgrid
func (action *Action) Jqgrid(r *ghttp.Request) {
form := base.NewForm(r.GetQueryMap())
page, err := department.Page(&form)
if err != nil {
glog.Error("jqgrid error", err)
base.Error(r, err.Error())
}

r.Response.WriteJson(g.Map{
"page": form.Page,
"rows": page,
"total": form.TotalPage,
"records": form.TotalSize,
})
}
Loading

0 comments on commit ae7c326

Please sign in to comment.