mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
首页、个人中心内容调整
This commit is contained in:
23
server/common/api/index.go
Normal file
23
server/common/api/index.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
)
|
||||
|
||||
type Index struct {
|
||||
ProjectApp application.Project
|
||||
MachineApp application.Machine
|
||||
DbApp application.Db
|
||||
RedisApp application.Redis
|
||||
}
|
||||
|
||||
func (i *Index) Count(rc *ctx.ReqCtx) {
|
||||
rc.ResData = map[string]interface{}{
|
||||
"projectNum": i.ProjectApp.Count(new(entity.Project)),
|
||||
"machineNum": i.MachineApp.Count(new(entity.Machine)),
|
||||
"dbNum": i.DbApp.Count(new(entity.Db)),
|
||||
"redisNum": i.RedisApp.Count(new(entity.Redis)),
|
||||
}
|
||||
}
|
||||
26
server/common/router/index.go
Normal file
26
server/common/router/index.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/common/api"
|
||||
devops_app "mayfly-go/server/devops/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitIndexRouter(router *gin.RouterGroup) {
|
||||
index := router.Group("common/index")
|
||||
i := &api.Index{
|
||||
ProjectApp: devops_app.ProjectApp,
|
||||
MachineApp: devops_app.MachineApp,
|
||||
DbApp: devops_app.DbApp,
|
||||
RedisApp: devops_app.RedisApp,
|
||||
}
|
||||
{
|
||||
// 首页基本信息统计
|
||||
index.GET("count", func(g *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(g).
|
||||
Handle(i.Count)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/apis/form"
|
||||
"mayfly-go/server/devops/apis/vo"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"strconv"
|
||||
@@ -1,12 +1,12 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/apis/form"
|
||||
"mayfly-go/server/devops/apis/vo"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/infrastructure/machine"
|
||||
@@ -78,6 +78,10 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
||||
if err = ctx.PermissionHandler(rc); err != nil {
|
||||
panic(biz.NewBizErr("没有权限"))
|
||||
}
|
||||
// 演示环境禁止非admin用户执行
|
||||
if rc.LoginAccount.Username != "admin" {
|
||||
panic(biz.NewBizErrCode(401, "非admin用户无权该操作"))
|
||||
}
|
||||
|
||||
cols := ginx.QueryInt(g, "cols", 80)
|
||||
rows := ginx.QueryInt(g, "rows", 40)
|
||||
@@ -1,4 +1,4 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/apis/form"
|
||||
"mayfly-go/server/devops/apis/vo"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"strconv"
|
||||
@@ -1,4 +1,4 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/apis/form"
|
||||
"mayfly-go/server/devops/apis/vo"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"strconv"
|
||||
@@ -1,11 +1,11 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/server/devops/apis/vo"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
sys_applicaiton "mayfly-go/server/sys/application"
|
||||
@@ -1,12 +1,12 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/devops/apis/form"
|
||||
"mayfly-go/server/devops/apis/vo"
|
||||
"mayfly-go/server/devops/api/form"
|
||||
"mayfly-go/server/devops/api/vo"
|
||||
"mayfly-go/server/devops/application"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"strconv"
|
||||
@@ -20,6 +20,8 @@ type Db interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Db) int64
|
||||
|
||||
// 根据条件获取
|
||||
GetDbBy(condition *entity.Db, cols ...string) error
|
||||
|
||||
@@ -50,6 +52,10 @@ func (d *dbAppImpl) GetPageList(condition *entity.Db, pageParam *model.PageParam
|
||||
return d.dbRepo.GetDbList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (d *dbAppImpl) Count(condition *entity.Db) int64 {
|
||||
return d.dbRepo.Count(condition)
|
||||
}
|
||||
|
||||
// 根据条件获取
|
||||
func (d *dbAppImpl) GetDbBy(condition *entity.Db, cols ...string) error {
|
||||
return d.dbRepo.GetDb(condition, cols...)
|
||||
|
||||
@@ -17,6 +17,8 @@ type Machine interface {
|
||||
|
||||
Save(entity *entity.Machine)
|
||||
|
||||
Count(condition *entity.Machine) int64
|
||||
|
||||
Delete(id uint64)
|
||||
|
||||
// 根据id获取
|
||||
@@ -40,6 +42,10 @@ func (m *machineAppImpl) GetMachineList(condition *entity.Machine, pageParam *mo
|
||||
return m.machineRepo.GetMachineList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (m *machineAppImpl) Count(condition *entity.Machine) int64 {
|
||||
return m.machineRepo.Count(condition)
|
||||
}
|
||||
|
||||
// 根据条件获取机器信息
|
||||
func (m *machineAppImpl) Save(me *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(machine.TestConn(me), "该机器无法连接: %s")
|
||||
|
||||
@@ -12,6 +12,8 @@ type Project interface {
|
||||
// 分页获取项目信息列表
|
||||
GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Project) int64
|
||||
|
||||
ListProjectByIds(ids []uint64, toEntity interface{}, orderBy ...string)
|
||||
|
||||
SaveProject(project *entity.Project)
|
||||
@@ -52,6 +54,10 @@ func (p *projectAppImpl) GetPageList(condition *entity.Project, pageParam *model
|
||||
return p.projectRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectAppImpl) Count(condition *entity.Project) int64 {
|
||||
return p.projectRepo.Count(condition)
|
||||
}
|
||||
|
||||
func (p *projectAppImpl) ListProjectByIds(ids []uint64, toEntity interface{}, orderBy ...string) {
|
||||
p.projectRepo.GetByIdIn(ids, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ type Redis interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Redis) int64
|
||||
|
||||
// 根据id获取
|
||||
GetById(id uint64, cols ...string) *entity.Redis
|
||||
|
||||
@@ -46,6 +48,10 @@ func (r *redisAppImpl) GetPageList(condition *entity.Redis, pageParam *model.Pag
|
||||
return r.redisRepo.GetRedisList(condition, pageParam, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (r *redisAppImpl) Count(condition *entity.Redis) int64 {
|
||||
return r.redisRepo.Count(condition)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (r *redisAppImpl) GetById(id uint64, cols ...string) *entity.Redis {
|
||||
return r.redisRepo.GetById(id, cols...)
|
||||
|
||||
@@ -9,6 +9,8 @@ type Db interface {
|
||||
// 分页获取机器信息列表
|
||||
GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Db) int64
|
||||
|
||||
// 根据条件获取账号信息
|
||||
GetDb(condition *entity.Db, cols ...string) error
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ type Machine interface {
|
||||
// 分页获取机器信息列表
|
||||
GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Machine) int64
|
||||
|
||||
// 根据条件获取账号信息
|
||||
GetMachine(condition *entity.Machine, cols ...string) error
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
type Project interface {
|
||||
GetPageList(condition *entity.Project, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Project) int64
|
||||
|
||||
GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string)
|
||||
|
||||
Save(p *entity.Project)
|
||||
|
||||
@@ -9,6 +9,8 @@ type Redis interface {
|
||||
// 分页获取机器信息列表
|
||||
GetRedisList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Count(condition *entity.Redis) int64
|
||||
|
||||
// 根据id获取
|
||||
GetById(id uint64, cols ...string) *entity.Redis
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toE
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (d *dbRepo) Count(condition *entity.Db) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (d *dbRepo) GetDb(condition *entity.Db, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
|
||||
@@ -15,6 +15,10 @@ func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (m *machineRepo) Count(condition *entity.Machine) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineRepo) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
|
||||
@@ -15,6 +15,10 @@ func (p *projectRepo) GetPageList(condition *entity.Project, pageParam *model.Pa
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (p *projectRepo) Count(condition *entity.Project) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
func (p *projectRepo) GetByIdIn(ids []uint64, toEntity interface{}, orderBy ...string) {
|
||||
model.GetByIdIn(new(entity.Project), toEntity, ids, orderBy...)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ func (r *redisRepo) GetRedisList(condition *entity.Redis, pageParam *model.PageP
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
}
|
||||
|
||||
func (r *redisRepo) Count(condition *entity.Redis) int64 {
|
||||
return model.CountBy(condition)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (r *redisRepo) GetById(id uint64, cols ...string) *entity.Redis {
|
||||
rd := new(entity.Redis)
|
||||
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/apis"
|
||||
"mayfly-go/server/devops/api"
|
||||
"mayfly-go/server/devops/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func InitDbRouter(router *gin.RouterGroup) {
|
||||
db := router.Group("dbs")
|
||||
{
|
||||
d := &apis.Db{DbApp: application.DbApp}
|
||||
d := &api.Db{DbApp: application.DbApp}
|
||||
// 获取所有数据库列表
|
||||
db.GET("", func(c *gin.Context) {
|
||||
rc := ctx.NewReqCtxWithGin(c)
|
||||
@@ -2,14 +2,14 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/apis"
|
||||
"mayfly-go/server/devops/api"
|
||||
"mayfly-go/server/devops/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitMachineRouter(router *gin.RouterGroup) {
|
||||
m := &apis.Machine{MachineApp: application.MachineApp}
|
||||
m := &api.Machine{MachineApp: application.MachineApp}
|
||||
db := router.Group("machines")
|
||||
{
|
||||
db.GET("", func(c *gin.Context) {
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/apis"
|
||||
"mayfly-go/server/devops/api"
|
||||
"mayfly-go/server/devops/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func InitMachineFileRouter(router *gin.RouterGroup) {
|
||||
machineFile := router.Group("machines")
|
||||
{
|
||||
mf := &apis.MachineFile{
|
||||
mf := &api.MachineFile{
|
||||
MachineFileApp: application.MachineFileApp,
|
||||
MachineApp: application.MachineApp}
|
||||
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/apis"
|
||||
"mayfly-go/server/devops/api"
|
||||
"mayfly-go/server/devops/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func InitMachineScriptRouter(router *gin.RouterGroup) {
|
||||
machines := router.Group("machines")
|
||||
{
|
||||
ms := &apis.MachineScript{
|
||||
ms := &api.MachineScript{
|
||||
MachineScriptApp: application.MachineScriptApp,
|
||||
MachineApp: application.MachineApp}
|
||||
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/apis"
|
||||
"mayfly-go/server/devops/api"
|
||||
"mayfly-go/server/devops/application"
|
||||
sys_applicaiton "mayfly-go/server/sys/application"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func InitProjectRouter(router *gin.RouterGroup) {
|
||||
m := &apis.Project{
|
||||
m := &api.Project{
|
||||
ProjectApp: application.ProjectApp,
|
||||
AccountApp: sys_applicaiton.AccountApp}
|
||||
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/devops/apis"
|
||||
"mayfly-go/server/devops/api"
|
||||
"mayfly-go/server/devops/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func InitRedisRouter(router *gin.RouterGroup) {
|
||||
redis := router.Group("redis")
|
||||
{
|
||||
rs := &apis.Redis{
|
||||
rs := &api.Redis{
|
||||
RedisApp: application.RedisApp,
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"fmt"
|
||||
"mayfly-go/base/config"
|
||||
"mayfly-go/base/middleware"
|
||||
devops_routers "mayfly-go/server/devops/routers"
|
||||
sys_routers "mayfly-go/server/sys/routers"
|
||||
common_index_router "mayfly-go/server/common/router"
|
||||
devops_router "mayfly-go/server/devops/router"
|
||||
gw_router "mayfly-go/server/gateway/router"
|
||||
sys_router "mayfly-go/server/sys/router"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -45,18 +47,21 @@ func InitRouter() *gin.Engine {
|
||||
// 设置路由组
|
||||
api := router.Group("/api")
|
||||
{
|
||||
sys_routers.InitCaptchaRouter(api)
|
||||
common_index_router.InitIndexRouter(api)
|
||||
|
||||
sys_routers.InitAccountRouter(api) // 注册account路由
|
||||
sys_routers.InitResourceRouter(api)
|
||||
sys_routers.InitRoleRouter(api)
|
||||
sys_router.InitCaptchaRouter(api)
|
||||
sys_router.InitAccountRouter(api) // 注册account路由
|
||||
sys_router.InitResourceRouter(api)
|
||||
sys_router.InitRoleRouter(api)
|
||||
|
||||
devops_routers.InitProjectRouter(api)
|
||||
devops_routers.InitDbRouter(api)
|
||||
devops_routers.InitRedisRouter(api)
|
||||
devops_routers.InitMachineRouter(api)
|
||||
devops_routers.InitMachineScriptRouter(api)
|
||||
devops_routers.InitMachineFileRouter(api)
|
||||
devops_router.InitProjectRouter(api)
|
||||
devops_router.InitDbRouter(api)
|
||||
devops_router.InitRedisRouter(api)
|
||||
devops_router.InitMachineRouter(api)
|
||||
devops_router.InitMachineScriptRouter(api)
|
||||
devops_router.InitMachineFileRouter(api)
|
||||
|
||||
gw_router.InitServiceRouter(api)
|
||||
}
|
||||
|
||||
return router
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"mayfly-go/base/global"
|
||||
"mayfly-go/base/httpclient"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/sys/apis/form"
|
||||
"mayfly-go/server/sys/apis/vo"
|
||||
"mayfly-go/server/sys/api/form"
|
||||
"mayfly-go/server/sys/api/vo"
|
||||
"mayfly-go/server/sys/application"
|
||||
"mayfly-go/server/sys/domain/entity"
|
||||
"strconv"
|
||||
@@ -22,8 +22,11 @@ type Account struct {
|
||||
AccountApp application.Account
|
||||
ResourceApp application.Resource
|
||||
RoleApp application.Role
|
||||
MsgApp application.Msg
|
||||
}
|
||||
|
||||
/** 登录者个人相关操作 **/
|
||||
|
||||
// @router /accounts/login [post]
|
||||
func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
loginForm := &form.LoginForm{}
|
||||
@@ -34,7 +37,7 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
biz.IsTrue(captcha.Verify(loginForm.Cid, loginForm.Captcha), "验证码错误")
|
||||
|
||||
account := &entity.Account{Username: loginForm.Username, Password: utils.Md5(loginForm.Password)}
|
||||
biz.ErrIsNil(a.AccountApp.GetAccount(account, "Id", "Username", "Password", "Status"), "用户名或密码错误")
|
||||
biz.ErrIsNil(a.AccountApp.GetAccount(account, "Id", "Username", "Status", "LastLoginTime", "LastLoginIp"), "用户名或密码错误")
|
||||
biz.IsTrue(account.IsEnable(), "该账号不可用")
|
||||
|
||||
var resources vo.AccountResourceVOList
|
||||
@@ -57,10 +60,12 @@ func (a *Account) Login(rc *ctx.ReqCtx) {
|
||||
go a.saveLogin(account, rc.GinCtx.ClientIP())
|
||||
|
||||
rc.ResData = map[string]interface{}{
|
||||
"token": ctx.CreateToken(account.Id, account.Username),
|
||||
"username": account.Username,
|
||||
"menus": menus.ToTrees(0),
|
||||
"permissions": permissions,
|
||||
"token": ctx.CreateToken(account.Id, account.Username),
|
||||
"username": account.Username,
|
||||
"lastLoginTime": account.LastLoginTime,
|
||||
"lastLoginIp": account.LastLoginIp,
|
||||
"menus": menus.ToTrees(0),
|
||||
"permissions": permissions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +75,20 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
|
||||
now := time.Now()
|
||||
updateAccount := &entity.Account{LastLoginTime: &now}
|
||||
updateAccount.Id = account.Id
|
||||
updateAccount.LastLoginIp = ip
|
||||
a.AccountApp.Update(updateAccount)
|
||||
|
||||
// 创建登录消息
|
||||
loginMsg := &entity.Msg{
|
||||
RecipientId: int64(account.Id),
|
||||
Msg: fmt.Sprintf("于%s登录", now.Format("2006-01-02 15:04:05")),
|
||||
Type: 1,
|
||||
}
|
||||
loginMsg.CreateTime = &now
|
||||
loginMsg.Creator = account.Username
|
||||
loginMsg.CreatorId = account.Id
|
||||
a.MsgApp.Create(loginMsg)
|
||||
|
||||
bodyMap, err := httpclient.NewRequest(fmt.Sprintf("http://ip-api.com/json/%s?lang=zh-CN", ip)).Get().BodyToMap()
|
||||
if err != nil {
|
||||
global.Log.Errorf("获取客户端ip地址信息失败:%s", err.Error())
|
||||
@@ -80,10 +97,47 @@ func (a *Account) saveLogin(account *entity.Account, ip string) {
|
||||
if bodyMap["status"].(string) == "fail" {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf("%s-%s登录", bodyMap["regionName"], bodyMap["city"])
|
||||
fmt.Printf(msg)
|
||||
msg := fmt.Sprintf("%s于%s-%s登录", account.Username, bodyMap["regionName"], bodyMap["city"])
|
||||
global.Log.Info(msg)
|
||||
}
|
||||
|
||||
// 获取个人账号信息
|
||||
func (a Account) AccountInfo(rc *ctx.ReqCtx) {
|
||||
ap := new(vo.AccountPersonVO)
|
||||
// 角色信息
|
||||
roles := new([]vo.AccountRoleVO)
|
||||
a.RoleApp.GetAccountRoles(rc.LoginAccount.Id, roles)
|
||||
|
||||
ap.Roles = *roles
|
||||
rc.ResData = ap
|
||||
}
|
||||
|
||||
// 更新个人账号信息
|
||||
func (a Account) UpdateAccount(rc *ctx.ReqCtx) {
|
||||
updateForm := &form.AccountUpdateForm{}
|
||||
ginx.BindJsonAndValid(rc.GinCtx, updateForm)
|
||||
|
||||
updateAccount := new(entity.Account)
|
||||
utils.Copy(updateAccount, updateForm)
|
||||
// 账号id为登录者账号
|
||||
updateAccount.Id = rc.LoginAccount.Id
|
||||
|
||||
if updateAccount.Password != "" {
|
||||
updateAccount.Password = utils.Md5(updateAccount.Password)
|
||||
}
|
||||
a.AccountApp.Update(updateAccount)
|
||||
}
|
||||
|
||||
// 获取账号接受的消息列表
|
||||
func (a Account) GetMsgs(rc *ctx.ReqCtx) {
|
||||
condition := &entity.Msg{
|
||||
RecipientId: int64(rc.LoginAccount.Id),
|
||||
}
|
||||
rc.ResData = a.MsgApp.GetPageList(condition, ginx.GetPageParam(rc.GinCtx), new([]entity.Msg))
|
||||
}
|
||||
|
||||
/** 后台账号操作 **/
|
||||
|
||||
// @router /accounts [get]
|
||||
func (a *Account) Accounts(rc *ctx.ReqCtx) {
|
||||
condition := &entity.Account{}
|
||||
@@ -1,4 +1,4 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/captcha"
|
||||
@@ -5,7 +5,5 @@ type AccountCreateForm struct {
|
||||
}
|
||||
|
||||
type AccountUpdateForm struct {
|
||||
Password *string `json:"password" binding:"required,min=6,max=16"`
|
||||
|
||||
RePassword *string `json:"rePassword" binding:"required,min=4,max=16"`
|
||||
Password *string `json:"password" binding:"min=6,max=16"`
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/sys/apis/form"
|
||||
"mayfly-go/server/sys/apis/vo"
|
||||
"mayfly-go/server/sys/api/form"
|
||||
"mayfly-go/server/sys/api/vo"
|
||||
"mayfly-go/server/sys/application"
|
||||
"mayfly-go/server/sys/domain/entity"
|
||||
)
|
||||
@@ -1,11 +1,11 @@
|
||||
package apis
|
||||
package api
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/base/ginx"
|
||||
"mayfly-go/base/utils"
|
||||
"mayfly-go/server/sys/apis/form"
|
||||
"mayfly-go/server/sys/apis/vo"
|
||||
"mayfly-go/server/sys/api/form"
|
||||
"mayfly-go/server/sys/api/vo"
|
||||
"mayfly-go/server/sys/application"
|
||||
"mayfly-go/server/sys/domain/entity"
|
||||
"strconv"
|
||||
@@ -12,9 +12,15 @@ type AccountManageVO struct {
|
||||
LastLoginTime *time.Time `json:"lastLoginTime"`
|
||||
}
|
||||
|
||||
// 账号角色信息
|
||||
type AccountRoleVO struct {
|
||||
Name *string `json:"name"`
|
||||
Status int `json:"status"`
|
||||
CreateTime *time.Time `json:"createTime"`
|
||||
Creator string `json:"creator"`
|
||||
}
|
||||
|
||||
// 账号个人信息
|
||||
type AccountPersonVO struct {
|
||||
Roles []AccountRoleVO `json:"roles"` // 角色信息
|
||||
}
|
||||
30
server/sys/application/msg_app.go
Normal file
30
server/sys/application/msg_app.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/sys/domain/entity"
|
||||
"mayfly-go/server/sys/domain/repository"
|
||||
"mayfly-go/server/sys/infrastructure/persistence"
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Create(msg *entity.Msg)
|
||||
}
|
||||
|
||||
type msgAppImpl struct {
|
||||
msgRepo repository.Msg
|
||||
}
|
||||
|
||||
var MsgApp Msg = &msgAppImpl{
|
||||
msgRepo: persistence.MsgDao,
|
||||
}
|
||||
|
||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (a *msgAppImpl) Create(msg *entity.Msg) {
|
||||
a.msgRepo.Insert(msg)
|
||||
}
|
||||
@@ -12,6 +12,7 @@ type Account struct {
|
||||
Password string `json:"-"`
|
||||
Status int8 `json:"status"`
|
||||
LastLoginTime *time.Time `json:"lastLoginTime"`
|
||||
LastLoginIp string `json:"lastLoginIp"`
|
||||
}
|
||||
|
||||
func (a *Account) TableName() string {
|
||||
|
||||
20
server/sys/domain/entity/msg.go
Normal file
20
server/sys/domain/entity/msg.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Msg struct {
|
||||
Id uint64 `json:"id"`
|
||||
CreateTime *time.Time `json:"createTime"`
|
||||
CreatorId uint64 `json:"creatorId"`
|
||||
Creator string `json:"creator"`
|
||||
|
||||
Type int `json:"type"`
|
||||
Msg string `json:"msg"`
|
||||
RecipientId int64 `json:"recipientId"` // 接受者id
|
||||
}
|
||||
|
||||
func (a *Msg) TableName() string {
|
||||
return "t_sys_msg"
|
||||
}
|
||||
12
server/sys/domain/repository/msg.go
Normal file
12
server/sys/domain/repository/msg.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/sys/domain/entity"
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult
|
||||
|
||||
Insert(msg *entity.Msg)
|
||||
}
|
||||
20
server/sys/infrastructure/persistence/msg_repo.go
Normal file
20
server/sys/infrastructure/persistence/msg_repo.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/sys/domain/entity"
|
||||
"mayfly-go/server/sys/domain/repository"
|
||||
)
|
||||
|
||||
type msgRepo struct{}
|
||||
|
||||
var MsgDao repository.Msg = &msgRepo{}
|
||||
|
||||
func (m *msgRepo) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity)
|
||||
}
|
||||
|
||||
func (m *msgRepo) Insert(account *entity.Msg) {
|
||||
biz.ErrIsNil(model.Insert(account), "新增消息记录失败")
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/sys/apis"
|
||||
"mayfly-go/server/sys/api"
|
||||
"mayfly-go/server/sys/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -10,10 +10,11 @@ import (
|
||||
|
||||
func InitAccountRouter(router *gin.RouterGroup) {
|
||||
account := router.Group("sys/accounts")
|
||||
a := &apis.Account{
|
||||
a := &api.Account{
|
||||
AccountApp: application.AccountApp,
|
||||
ResourceApp: application.ResourceApp,
|
||||
RoleApp: application.RoleApp,
|
||||
MsgApp: application.MsgApp,
|
||||
}
|
||||
{
|
||||
// 用户登录
|
||||
@@ -22,6 +23,22 @@ func InitAccountRouter(router *gin.RouterGroup) {
|
||||
rc.Handle(a.Login)
|
||||
})
|
||||
|
||||
// 获取个人账号信息
|
||||
account.GET("/self", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(a.AccountInfo)
|
||||
})
|
||||
|
||||
// 更新个人账号信息
|
||||
account.PUT("/self", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(a.UpdateAccount)
|
||||
})
|
||||
|
||||
account.GET("/msgs", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(a.GetMsgs)
|
||||
})
|
||||
|
||||
/** 后台管理接口 **/
|
||||
|
||||
// 获取所有用户列表
|
||||
account.GET("", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(a.Accounts)
|
||||
@@ -2,7 +2,7 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/sys/apis"
|
||||
"mayfly-go/server/sys/api"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -11,7 +11,7 @@ func InitCaptchaRouter(router *gin.RouterGroup) {
|
||||
captcha := router.Group("sys/captcha")
|
||||
{
|
||||
captcha.GET("", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).WithNeedToken(false).Handle(apis.GenerateCaptcha)
|
||||
ctx.NewReqCtxWithGin(c).WithNeedToken(false).Handle(api.GenerateCaptcha)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/sys/apis"
|
||||
"mayfly-go/server/sys/api"
|
||||
"mayfly-go/server/sys/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitResourceRouter(router *gin.RouterGroup) {
|
||||
r := &apis.Resource{ResourceApp: application.ResourceApp}
|
||||
r := &api.Resource{ResourceApp: application.ResourceApp}
|
||||
db := router.Group("sys/resources")
|
||||
{
|
||||
// db.GET("/account", func(c *gin.Context) {
|
||||
@@ -2,14 +2,14 @@ package routers
|
||||
|
||||
import (
|
||||
"mayfly-go/base/ctx"
|
||||
"mayfly-go/server/sys/apis"
|
||||
"mayfly-go/server/sys/api"
|
||||
"mayfly-go/server/sys/application"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitRoleRouter(router *gin.RouterGroup) {
|
||||
r := &apis.Role{
|
||||
r := &api.Role{
|
||||
RoleApp: application.RoleApp,
|
||||
ResourceApp: application.ResourceApp,
|
||||
}
|
||||
Reference in New Issue
Block a user