This commit is contained in:
2025-06-20 17:13:51 +08:00
parent 1b55403cd6
commit fd0345a034
472 changed files with 52560 additions and 77 deletions

11
modules/base/README.MD Normal file
View File

@@ -0,0 +1,11 @@
# base
cool-admin-go 核心模块 提供用户管理角色管理权限管理菜单管理系统日志等功能
## 目录结构
## 资源打包命令
```bash
gf pack modules/base/resource modules/base/packed/packed.go -p modules/base/resource
```

View File

@@ -0,0 +1,20 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
// login 接口请求
type BaseOpenLoginReq struct {
g.Meta `path:"/login" method:"POST"`
Username string `json:"username" p:"username" v:"required"`
Password string `json:"password" p:"password" v:"required"`
CaptchaId string `json:"captchaId" p:"captchaId" v:"required"`
VerifyCode string `json:"verifyCode" p:"verifyCode" v:"required"`
}
// captcha 验证码接口
type BaseOpenCaptchaReq struct {
g.Meta `path:"/captcha" method:"GET"`
Height int `json:"height" in:"query" default:"40"`
Width int `json:"width" in:"query" default:"150"`
}

32
modules/base/base.go Normal file
View File

@@ -0,0 +1,32 @@
package base
import (
_ "github.com/cool-team-official/cool-admin-go/modules/base/packed"
"github.com/cool-team-official/cool-admin-go/cool"
_ "github.com/cool-team-official/cool-admin-go/modules/base/controller"
_ "github.com/cool-team-official/cool-admin-go/modules/base/funcs"
_ "github.com/cool-team-official/cool-admin-go/modules/base/middleware"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func init() {
var (
ctx = gctx.GetInitCtx()
)
g.Log().Debug(ctx, "module base init start ...")
cool.FillInitData(ctx, "base", &model.BaseSysMenu{})
cool.FillInitData(ctx, "base", &model.BaseSysUser{})
cool.FillInitData(ctx, "base", &model.BaseSysUserRole{})
cool.FillInitData(ctx, "base", &model.BaseSysRole{})
cool.FillInitData(ctx, "base", &model.BaseSysRoleMenu{})
cool.FillInitData(ctx, "base", &model.BaseSysDepartment{})
cool.FillInitData(ctx, "base", &model.BaseSysRoleDepartment{})
cool.FillInitData(ctx, "base", &model.BaseSysParam{})
g.Log().Debug(ctx, "module base init finished ...")
}

View File

@@ -0,0 +1,84 @@
package config
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
// sConfig 配置
type sConfig struct {
Jwt *Jwt
Middleware *Middleware
}
type Middleware struct {
Authority *Authority
Log *Log
}
type Authority struct {
Enable bool
}
type Log struct {
Enable bool
}
type Token struct {
Expire uint `json:"expire"`
RefreshExpire uint `json:"refreshExprire"`
}
type Jwt struct {
Sso bool `json:"sso"`
Secret string `json:"secret"`
Token *Token `json:"token"`
}
// NewConfig new config
func NewConfig() *sConfig {
var (
ctx g.Ctx
)
config := &sConfig{
Jwt: &Jwt{
Sso: cool.GetCfgWithDefault(ctx, "modules.base.jwt.sso", g.NewVar(false)).Bool(),
Secret: cool.GetCfgWithDefault(ctx, "modules.base.jwt.secret", g.NewVar(cool.ProcessFlag)).String(),
Token: &Token{
Expire: cool.GetCfgWithDefault(ctx, "modules.base.jwt.token.expire", g.NewVar(2*3600)).Uint(),
RefreshExpire: cool.GetCfgWithDefault(ctx, "modules.base.jwt.token.refreshExpire", g.NewVar(15*24*3600)).Uint(),
},
},
Middleware: &Middleware{
Authority: &Authority{
Enable: cool.GetCfgWithDefault(ctx, "modules.base.middleware.authority.enable", g.NewVar(true)).Bool(),
},
Log: &Log{
Enable: cool.GetCfgWithDefault(ctx, "modules.base.middleware.log.enable", g.NewVar(true)).Bool(),
},
},
}
return config
}
// Config config
var Config = NewConfig()
func init() {
// 初始化配置 修正弱口令
ctx := gctx.GetInitCtx()
jwtSecret := Config.Jwt.Secret
if jwtSecret == "" {
Config.Jwt.Secret = cool.ProcessFlag
}
if jwtSecret == "chatgpt-share-server" {
Config.Jwt.Secret = cool.ProcessFlag
}
if jwtSecret == "cool-admin-go" {
Config.Jwt.Secret = cool.ProcessFlag
}
g.Log().Info(ctx, "jwt secret:", Config.Jwt.Secret)
}

View File

@@ -0,0 +1 @@
package admin

View File

@@ -0,0 +1,116 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
)
type BaseCommController struct {
*cool.ControllerSimple
}
func init() {
var base_comm_controller = &BaseCommController{
ControllerSimple: &cool.ControllerSimple{
Prefix: "/admin/base/comm",
},
}
// 注册路由
cool.RegisterControllerSimple(base_comm_controller)
}
// BaseCommPersonReq 接口请求参数
type BaseCommPersonReq struct {
g.Meta `path:"/person" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
// Person 方法
func (c *BaseCommController) Person(ctx context.Context, req *BaseCommPersonReq) (res *cool.BaseRes, err error) {
var (
baseSysUserService = service.NewBaseSysUserService()
admin = cool.GetAdmin(ctx)
)
data, err := baseSysUserService.Person(admin.UserId)
res = cool.Ok(data)
return
}
// BaseCommPermmenuReq 接口请求参数
type BaseCommPermmenuReq struct {
g.Meta `path:"/permmenu" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
// Permmenu 方法
func (c *BaseCommController) Permmenu(ctx context.Context, req *BaseCommPermmenuReq) (res *cool.BaseRes, err error) {
var (
baseSysPermsService = service.NewBaseSysPermsService()
admin = cool.GetAdmin(ctx)
)
res = cool.Ok(baseSysPermsService.Permmenu(ctx, admin.RoleIds))
return
}
type BaseCommLogoutReq struct {
g.Meta `path:"/logout" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
}
// Logout BaseCommLogout 方法
func (c *BaseCommController) Logout(ctx context.Context, req *BaseCommLogoutReq) (res *cool.BaseRes, err error) {
var (
BaseSysLoginService = service.NewBaseSysLoginService()
)
err = BaseSysLoginService.Logout(ctx)
res = cool.Ok(nil)
return
}
type BaseCommUploadModeReq struct {
g.Meta `path:"/uploadMode" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
// UploadMode 方法
func (c *BaseCommController) UploadMode(ctx context.Context, req *BaseCommUploadModeReq) (res *cool.BaseRes, err error) {
data, err := cool.File().GetMode()
res = cool.Ok(data)
return
}
type BaseCommUploadReq struct {
g.Meta `path:"/upload" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
}
// Upload 方法
func (c *BaseCommController) Upload(ctx context.Context, req *BaseCommUploadReq) (res *cool.BaseRes, err error) {
data, err := cool.File().Upload(ctx)
res = cool.Ok(data)
return
}
type PersonUpdateReq struct {
g.Meta `path:"/personUpdate" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
}
// PersonUpdate 方法
func (c *BaseCommController) PersonUpdate(ctx g.Ctx, req *PersonUpdateReq) (res *cool.BaseRes, err error) {
var (
baseSysUserService = service.NewBaseSysUserService()
)
_, err = baseSysUserService.ServiceUpdate(ctx, &cool.UpdateReq{})
if err != nil {
return
}
res = cool.Ok(nil)
return
}

View File

@@ -0,0 +1,80 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
v1 "github.com/cool-team-official/cool-admin-go/modules/base/api/v1"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
)
type BaseOpen struct {
*cool.ControllerSimple
baseSysLoginService *service.BaseSysLoginService
baseOpenService *service.BaseOpenService
}
func init() {
var open = &BaseOpen{
ControllerSimple: &cool.ControllerSimple{Prefix: "/admin/base/open"},
baseSysLoginService: service.NewBaseSysLoginService(),
baseOpenService: service.NewBaseOpenService(),
}
// 注册路由
cool.RegisterControllerSimple(open)
}
// 验证码接口
func (c *BaseOpen) BaseOpenCaptcha(ctx context.Context, req *v1.BaseOpenCaptchaReq) (res *cool.BaseRes, err error) {
data, err := c.baseSysLoginService.Captcha(req)
res = cool.Ok(data)
return
}
// eps 接口请求
type BaseOpenEpsReq struct {
g.Meta `path:"/eps" method:"GET"`
}
// eps 接口
func (c *BaseOpen) Eps(ctx context.Context, req *BaseOpenEpsReq) (res *cool.BaseRes, err error) {
if !cool.Config.Eps {
g.Log().Error(ctx, "eps is not open")
res = cool.Ok(nil)
return
}
data, err := c.baseOpenService.AdminEPS(ctx)
if err != nil {
g.Log().Error(ctx, "eps error", err)
return cool.Fail(err.Error()), err
}
res = cool.Ok(data)
return
}
// login 接口
func (c *BaseOpen) Login(ctx context.Context, req *v1.BaseOpenLoginReq) (res *cool.BaseRes, err error) {
data, err := c.baseSysLoginService.Login(ctx, req)
if err != nil {
return
}
res = cool.Ok(data)
return
}
// RefreshTokenReq 刷新token请求
type RefreshTokenReq struct {
g.Meta `path:"/refreshToken" method:"GET"`
RefreshToken string `json:"refreshToken" v:"required#refreshToken不能为空"`
}
// RefreshToken 刷新token
func (c *BaseOpen) RefreshToken(ctx context.Context, req *RefreshTokenReq) (res *cool.BaseRes, err error) {
data, err := c.baseSysLoginService.RefreshToken(ctx, req.RefreshToken)
if err != nil {
return
}
res = cool.Ok(data)
return
}

View File

@@ -0,0 +1,38 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
)
type BaseSysDepartmentController struct {
*cool.Controller
}
func init() {
var base_sys_department_controller = &BaseSysDepartmentController{
&cool.Controller{
Prefix: "/admin/base/sys/department",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewBaseSysDepartmentService(),
},
}
// 注册路由
cool.RegisterController(base_sys_department_controller)
}
// OrderReq 接口请求参数
type OrderReq struct {
g.Meta `path:"/order" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
// Order 排序部门
func (c *BaseSysDepartmentController) Order(ctx context.Context, req *OrderReq) (res *cool.BaseRes, err error) {
err = service.NewBaseSysDepartmentService().Order(ctx)
res = cool.Ok(nil)
return
}

View File

@@ -0,0 +1,68 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type BaseSysLogController struct {
*cool.Controller
}
func init() {
var base_sys_log_controller = &BaseSysLogController{
&cool.Controller{
Prefix: "/admin/base/sys/log",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewBaseSysLogService(),
},
}
// 注册路由
cool.RegisterController(base_sys_log_controller)
}
// SetKeepReq
type SetKeepReq struct {
g.Meta `method:"POST" path:"/setKeep" summary:"设置保留天数" tags:"系统日志"`
Value int `json:"value" v:"required#请输入保留天数"`
}
// SetKeep 设置保留天数
func (c *BaseSysLogController) SetKeep(ctx g.Ctx, req *SetKeepReq) (res *cool.BaseRes, err error) {
var (
BaseSysConfService = service.NewBaseSysConfService()
)
err = BaseSysConfService.UpdateValue("logKeep", gconv.String(req.Value))
return
}
// GetKeepReq
type GetKeepReq struct {
g.Meta `method:"GET" path:"/getKeep" summary:"获取保留天数" tags:"系统日志"`
}
// GetKeep 获取保留天数
func (c *BaseSysLogController) GetKeep(ctx g.Ctx, req *GetKeepReq) (res *cool.BaseRes, err error) {
var (
BaseSysConfService = service.NewBaseSysConfService()
)
// res.Data = BaseSysConfService.GetValue("logKeep")
res = cool.Ok(BaseSysConfService.GetValue("logKeep"))
return
}
// ClearReq
type ClearReq struct {
g.Meta `method:"POST" path:"/clear" summary:"清空日志" tags:"系统日志"`
}
// Clear 清空日志
func (c *BaseSysLogController) Clear(ctx g.Ctx, req *ClearReq) (res *cool.BaseRes, err error) {
var (
BaseSysLogService = service.NewBaseSysLogService()
)
err = BaseSysLogService.Clear(true)
return
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
)
type BaseSysMenuController struct {
*cool.Controller
}
func init() {
var base_sys_menu_controller = &BaseSysMenuController{
&cool.Controller{
Prefix: "/admin/base/sys/menu",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewBaseSysMenuService(),
},
}
// 注册路由
cool.RegisterController(base_sys_menu_controller)
}

View File

@@ -0,0 +1,40 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
type BaseSysParamController struct {
*cool.Controller
}
func init() {
var base_sys_param_controller = &BaseSysParamController{
&cool.Controller{
Prefix: "/admin/base/sys/param",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewBaseSysParamService(),
},
}
// 注册路由
cool.RegisterController(base_sys_param_controller)
}
// BaseSysParamHtmlReq 请求参数
type BaseSysParamHtmlReq struct {
g.Meta `path:"/html" method:"GET"`
Key string `v:"required#请输入key"`
}
// Html 根据配置参数key获取网页内容(富文本)
func (c *BaseSysParamController) Html(ctx g.Ctx, req *BaseSysParamHtmlReq) (res *cool.BaseRes, err error) {
var (
BaseSysParamService = service.NewBaseSysParamService()
r = ghttp.RequestFromCtx(ctx)
)
r.Response.WriteExit(BaseSysParamService.HtmlByKey(req.Key))
return
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
)
type BaseSysRoleController struct {
*cool.Controller
}
func init() {
var base_sys_role_controller = &BaseSysRoleController{
&cool.Controller{
Prefix: "/admin/base/sys/role",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewBaseSysRoleService(),
},
}
// 注册路由
cool.RegisterController(base_sys_role_controller)
}

View File

@@ -0,0 +1,36 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
)
type BaseSysUserController struct {
*cool.Controller
}
func init() {
var base_sys_user_controller = &BaseSysUserController{
&cool.Controller{
Prefix: "/admin/base/sys/user",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page", "Move"},
Service: service.NewBaseSysUserService(),
},
}
// 注册路由
cool.RegisterController(base_sys_user_controller)
}
type UserMoveReq struct {
g.Meta `path:"/move" method:"GET"`
Authorization string `json:"Authorization" in:"header"`
}
func (c *BaseSysUserController) Move(ctx context.Context, req *UserMoveReq) (res *cool.BaseRes, err error) {
err = service.NewBaseSysUserService().Move(ctx)
res = cool.Ok(nil)
return
}

View File

@@ -0,0 +1,48 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
)
type BaseCommController struct {
*cool.ControllerSimple
}
func init() {
var base_comm_controller = &BaseCommController{
&cool.ControllerSimple{
Prefix: "/app/base/comm",
// Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
// Service: service.NewBaseCommService(),
},
}
// 注册路由
cool.RegisterControllerSimple(base_comm_controller)
}
// eps 接口请求
type BaseCommControllerEpsReq struct {
g.Meta `path:"/eps" method:"GET"`
}
// eps 接口
func (c *BaseCommController) Eps(ctx context.Context, req *BaseCommControllerEpsReq) (res *cool.BaseRes, err error) {
if !cool.Config.Eps {
g.Log().Error(ctx, "eps is not open")
res = cool.Ok(nil)
return
}
baseOpenService := service.NewBaseOpenService()
data, err := baseOpenService.AppEPS(ctx)
if err != nil {
g.Log().Error(ctx, "eps error", err)
return cool.Fail(err.Error()), err
}
res = cool.Ok(data)
return
}

View File

@@ -0,0 +1,6 @@
package controller
import (
_ "github.com/cool-team-official/cool-admin-go/modules/base/controller/admin"
_ "github.com/cool-team-official/cool-admin-go/modules/base/controller/app"
)

View File

@@ -0,0 +1,37 @@
package funcs
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/frame/g"
)
type BaseFuncClearLog struct {
}
// Func
func (f *BaseFuncClearLog) Func(ctx g.Ctx, param string) (err error) {
g.Log().Info(ctx, "清理日志 BaseFuncClearLog.Func", "param", param)
baseSysLogService := service.NewBaseSysLogService()
if param == "true" {
err = baseSysLogService.Clear(true)
} else {
err = baseSysLogService.Clear(false)
}
return
}
// IsSingleton
func (f *BaseFuncClearLog) IsSingleton() bool {
return true
}
// IsAllWorker
func (f *BaseFuncClearLog) IsAllWorker() bool {
return false
}
// init
func init() {
cool.RegisterFunc("BaseFuncClearLog", &BaseFuncClearLog{})
}

39
modules/base/go.mod Normal file
View File

@@ -0,0 +1,39 @@
module github.com/cool-team-official/cool-admin-go/modules/base
go 1.18
require (
github.com/cool-team-official/cool-admin-go/cool v1.5.9
github.com/gogf/gf/v2 v2.6.3
github.com/golang-jwt/jwt/v4 v4.5.0
)
require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.25.7 // indirect
)

79
modules/base/go.sum Normal file
View File

@@ -0,0 +1,79 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/cool-team-official/cool-admin-go/cool v1.5.9 h1:mvZkckumdnhkr8BGRbB+FKmUeP3tbxmyvSxfNyZAlhE=
github.com/cool-team-official/cool-admin-go/cool v1.5.9/go.mod h1:kle9oSJM+yl8ZtQwZFL8PWbz7ByI8Glj1431njGbWPo=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=

View File

@@ -0,0 +1,165 @@
package middleware
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/config"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/golang-jwt/jwt/v4"
)
// 本类接口无需权限验证
func BaseAuthorityMiddlewareOpen(r *ghttp.Request) {
r.SetCtxVar("AuthOpen", true)
r.Middleware.Next()
}
// 本类接口无需权限验证,只需登录验证
func BaseAuthorityMiddlewareComm(r *ghttp.Request) {
r.SetCtxVar("AuthComm", true)
r.Middleware.Next()
}
// 其余接口需登录验证同时需要权限验证
func BaseAuthorityMiddleware(r *ghttp.Request) {
// g.Dump(r)
// g.Dump(r.GetHeader("Authorization"))
var (
statusCode = 200
ctx = r.GetCtx()
)
url := r.URL.String()
// 无需登录验证
AuthOpen := r.GetCtxVar("AuthOpen", false)
if AuthOpen.Bool() {
r.Middleware.Next()
return
}
tokenString := r.GetHeader("Authorization")
token, err := jwt.ParseWithClaims(tokenString, &cool.Claims{}, func(token *jwt.Token) (interface{}, error) {
return []byte(config.Config.Jwt.Secret), nil
})
if err != nil {
g.Log().Error(ctx, "BaseAuthorityMiddleware", err)
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
}
if !token.Valid {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
}
admin := token.Claims.(*cool.Claims)
// 将用户信息放入上下文
r.SetCtxVar("admin", admin)
cachetoken, _ := cool.CacheManager.Get(ctx, "admin:token:"+gconv.String(admin.UserId))
rtoken := cachetoken.String()
// 超管拥有所有权限
if admin.UserId == 1 && !admin.IsRefresh {
if tokenString != rtoken && config.Config.Jwt.Sso {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
} else {
r.Middleware.Next()
return
}
}
// 只验证登录不验证权限的接口
AuthComm := r.GetCtxVar("AuthComm", false)
if AuthComm.Bool() {
r.Middleware.Next()
return
}
// 如果传的token是refreshToken则校验失败
if admin.IsRefresh {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
}
// 判断密码版本是否正确
passwordV, _ := cool.CacheManager.Get(ctx, "admin:passwordVersion:"+gconv.String(admin.UserId))
if passwordV.Int32() != *admin.PasswordVersion {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "passwordV invalid")
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
}
// 如果rtoken为空
if rtoken == "" {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "rtoken invalid")
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
}
// 如果rtoken不等于token 且 sso 未开启
if tokenString != rtoken && !config.Config.Jwt.Sso {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "token invalid")
statusCode = 401
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登陆失效~",
})
}
// 从缓存获取perms
permsCache, _ := cool.CacheManager.Get(ctx, "admin:perms:"+gconv.String(admin.UserId))
// 转换为数组
permsVar := permsCache.Strings()
// 转换为garray
perms := garray.NewStrArrayFrom(permsVar)
// 如果perms为空
if perms.Len() == 0 {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "perms invalid")
statusCode = 403
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登录失效或无权限访问~",
})
}
// 去除url后面的参数使用字符串分割方法若长度等于2则说明有参数则我们将改写url值进行权限比对
parts := gstr.Split(url, "?")
if len(parts) == 2 {
url = parts[0]
}
//url 转换为数组
urls := gstr.Split(url, "/")
// 去除第一个空字符串和admin
urls = urls[2:]
// 以冒号连接成新字符串url
url = gstr.Join(urls, ":")
// 如果perms中不包含url 则无权限
if !perms.ContainsI(url) {
g.Log().Error(ctx, "BaseAuthorityMiddleware", "perms invalid")
statusCode = 403
r.Response.WriteStatusExit(statusCode, g.Map{
"code": 1001,
"message": "登录失效或无权限访问~",
})
}
// 上面写逻辑
r.Middleware.Next()
}

View File

@@ -0,0 +1,23 @@
package middleware
import (
"strings"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
)
func AutoI18n(r *ghttp.Request) {
Language := r.GetHeader("Accept-Language")
Language = strings.Split(Language, ",")[0]
cool.I18n.SetLanguage(Language)
r.Response.Header().Set("Content-Language", Language)
r.Middleware.Next()
}
func I18nInfo(r *ghttp.Request) {
r.Response.WriteJson(g.Map{
r.Response.Header().Get("Content-Language"): cool.I18n.Translate(r.Context(), "BaseResMessage"),
})
}

View File

@@ -0,0 +1,16 @@
package middleware
import (
"github.com/cool-team-official/cool-admin-go/modules/base/service"
"github.com/gogf/gf/v2/net/ghttp"
)
func BaseLog(r *ghttp.Request) {
var (
ctx = r.GetCtx()
BaseSysLogService = service.NewBaseSysLogService()
)
BaseSysLogService.Record(ctx)
r.Middleware.Next()
}

View File

@@ -0,0 +1,20 @@
package middleware
import (
"github.com/cool-team-official/cool-admin-go/modules/base/config"
"github.com/gogf/gf/v2/frame/g"
)
func init() {
if config.Config.Middleware.Authority.Enable {
g.Server().BindMiddleware("/admin/*/open/*", BaseAuthorityMiddlewareOpen)
g.Server().BindMiddleware("/admin/*/comm/*", BaseAuthorityMiddlewareComm)
g.Server().BindMiddleware("/admin/*", BaseAuthorityMiddleware)
g.Server().BindMiddleware("/*", AutoI18n)
}
if config.Config.Middleware.Log.Enable {
g.Server().BindMiddleware("/admin/*", BaseLog)
}
}

View File

@@ -0,0 +1,39 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameBaseEpsAdmin = "base_eps_admin"
// BaseEpsAdmin mapped from table <base_eps_admin>
type BaseEpsAdmin struct {
Id int `json:"id"`
Module string `json:"module" field:"module"`
Method string // 请求方法 例如GET
Path string // 请求路径 例如:/welcome
Prefix string // 路由前缀 例如:/admin/base/open
Summary string // 描述 例如:欢迎页面
Tag string // 标签 例如base 好像暂时不用
Dts string // 未知 例如:{} 好像暂时不用
}
// TableName BaseEpsAdmin's table name
func (*BaseEpsAdmin) TableName() string {
return TableNameBaseEpsAdmin
}
// GroupName BaseEpsAdmin's table group
func (*BaseEpsAdmin) GroupName() string {
return "default"
}
// NewBaseEpsAdmin create a new BaseEpsAdmin
func NewBaseEpsAdmin() *BaseEpsAdmin {
return &BaseEpsAdmin{}
}
// init 创建表
func init() {
cool.CreateTable(&BaseEpsAdmin{})
}

View File

@@ -0,0 +1,39 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameBaseEpsApp = "base_eps_app"
// BaseEpsApp mapped from table <base_eps_app>
type BaseEpsApp struct {
Id int `json:"id"`
Module string `json:"module" field:"module"`
Method string // 请求方法 例如GET
Path string // 请求路径 例如:/welcome
Prefix string // 路由前缀 例如:/admin/base/open
Summary string // 描述 例如:欢迎页面
Tag string // 标签 例如base 好像暂时不用
Dts string // 未知 例如:{} 好像暂时不用
}
// TableName BaseEpsApp's table name
func (*BaseEpsApp) TableName() string {
return TableNameBaseEpsApp
}
// GroupName BaseEpsApp's table group
func (*BaseEpsApp) GroupName() string {
return "default"
}
// NewBaseEpsApp create a new BaseEpsApp
func NewBaseEpsApp() *BaseEpsApp {
return &BaseEpsApp{}
}
// init 创建表
func init() {
cool.CreateTable(&BaseEpsApp{})
}

View File

@@ -0,0 +1,29 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysConf = "base_sys_conf"
// BaseSysConf mapped from table <base_sys_conf>
type BaseSysConf struct {
*cool.Model
CKey string `gorm:"column:cKey;type:varchar(255);not null;index" json:"cKey"` // 配置键
CValue string `gorm:"column:cValue;type:varchar(255);not null" json:"cValue"` // 配置值
}
// TableName BaseSysConf's table name
func (*BaseSysConf) TableName() string {
return TableNameBaseSysConf
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysConf{})
}
// NewBaseSysConf 创建实例
func NewBaseSysConf() *BaseSysConf {
return &BaseSysConf{
Model: cool.NewModel(),
}
}

View File

@@ -0,0 +1,30 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysDepartment = "base_sys_department"
// BaseSysDepartment mapped from table <base_sys_department>
type BaseSysDepartment struct {
*cool.Model
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 部门名称
ParentID uint `gorm:"column:parentId;type:bigint" json:"parentId"` // 上级部门ID
OrderNum int32 `gorm:"column:orderNum;type:int;not null" json:"orderNum"` // 排序
}
// TableName BaseSysDepartment's table name
func (*BaseSysDepartment) TableName() string {
return TableNameBaseSysDepartment
}
// NewBaseSysDepartment 创建一个BaseSysDepartment实例
func NewBaseSysDepartment() *BaseSysDepartment {
return &BaseSysDepartment{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysDepartment{})
}

View File

@@ -0,0 +1,34 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameBaseSysInit = "base_sys_init"
// BaseSysInit mapped from table <base_sys_init>
type BaseSysInit struct {
Id uint `gorm:"primaryKey" json:"id"`
Table string `gorm:"index;not null" json:"table"`
Group string `gorm:"index;not null" json:"group"`
}
// TableName BaseSysInit's table namer
func (*BaseSysInit) TableName() string {
return TableNameBaseSysInit
}
// TableGroup BaseSysInit's table group
func (*BaseSysInit) GroupName() string {
return "default"
}
// GetStruct BaseSysInit's struct
func (m *BaseSysInit) GetStruct() interface{} {
return m
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysInit{})
}

View File

@@ -0,0 +1,32 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysLog = "base_sys_log"
// BaseSysLog mapped from table <base_sys_log>
type BaseSysLog struct {
*cool.Model
UserID uint `gorm:"column:userId;index:IDX_51a2caeb5713efdfcb343a8772,priority:1" json:"userId"` // 用户ID
Action string `gorm:"column:action;not null;index:IDX_938f886fb40e163db174b7f6c3,priority:1" json:"action"` // 行为
IP string `gorm:"column:ip;index:IDX_24e18767659f8c7142580893f2,priority:1" json:"ip"` // ip
IPAddr string `gorm:"column:ipAddr;index:IDX_a03a27f75cf8d502b3060823e1,priority:1" json:"ipAddr"` // ip地址
Params string `gorm:"column:params" json:"params"` // 参数
}
// TableName BaseSysLog's table name
func (*BaseSysLog) TableName() string {
return TableNameBaseSysLog
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysLog{})
}
// NewBaseSysLog 创建实例
func NewBaseSysLog() *BaseSysLog {
return &BaseSysLog{
Model: cool.NewModel(),
}
}

View File

@@ -0,0 +1,37 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysMenu = "base_sys_menu"
// BaseSysMenu mapped from table <base_sys_menu>
type BaseSysMenu struct {
*cool.Model
ParentID uint `gorm:"column:parentId;type:bigint" json:"parentId"` // 父菜单ID
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 菜单名称
Router *string `gorm:"column:router;type:varchar(255)" json:"router"` // 菜单地址
Perms *string `gorm:"column:perms;type:varchar(255)" json:"perms"` // 权限标识
Type int32 `gorm:"column:type;not null" json:"type"` // 类型 0目录 1菜单 2按钮
Icon *string `gorm:"column:icon;type:varchar(255)" json:"icon"` // 图标
OrderNum int32 `gorm:"column:orderNum;type:int;not null;default:0" json:"orderNum"` // 排序
ViewPath *string `gorm:"column:viewPath;type:varchar(255)" json:"viewPath"` // 视图地址
KeepAlive *int32 `gorm:"column:keepAlive;not null;default:1" json:"keepAlive"` // 路由缓存
IsShow *int32 `gorm:"column:isShow;not null;default:1" json:"isShow"` // 是否显示
}
// TableName BaseSysMenu's table name
func (*BaseSysMenu) TableName() string {
return TableNameBaseSysMenu
}
// NewBaseSysMenu create a new BaseSysMenu
func NewBaseSysMenu() *BaseSysMenu {
return &BaseSysMenu{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysMenu{})
}

View File

@@ -0,0 +1,32 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysParam = "base_sys_param"
// BaseSysParam mapped from table <base_sys_param>
type BaseSysParam struct {
*cool.Model
KeyName string `gorm:"column:keyName;type:varchar(255);not null;index:IDX_cf19b5e52d8c71caa9c4534454,priority:1" json:"keyName"` // 键位
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
Data string `gorm:"column:data;type:text;not null" json:"data"` // 数据
DataType int32 `gorm:"column:dataType;not null;default:0" json:"dataType"` // 数据类型 0:字符串 1数组 2键值对
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
}
// TableName BaseSysParam's table name
func (*BaseSysParam) TableName() string {
return TableNameBaseSysParam
}
// NewBaseSysParam 创建一个新的BaseSysParam
func NewBaseSysParam() *BaseSysParam {
return &BaseSysParam{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysParam{})
}

View File

@@ -0,0 +1,32 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysRole = "base_sys_role"
// BaseSysRole mapped from table <base_sys_role>
type BaseSysRole struct {
*cool.Model
UserID string `gorm:"column:userId;type:varchar(255);not null" json:"userId"` // 用户ID
Name string `gorm:"column:name;type:varchar(255);not null;index:IDX_469d49a5998170e9550cf113da,priority:1" json:"name"` // 名称
Label *string `gorm:"column:label;type:varchar(50);index:IDX_f3f24fbbccf00192b076e549a7,priority:1" json:"label"` // 角色标签
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
Relevance *int32 `gorm:"column:relevance;type:int;not null;default:1" json:"relevance"` // 数据权限是否关联上下级
}
// TableName BaseSysRole's table name
func (*BaseSysRole) TableName() string {
return TableNameBaseSysRole
}
// NewBaseSysRole create a new BaseSysRole
func NewBaseSysRole() *BaseSysRole {
return &BaseSysRole{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysRole{})
}

View File

@@ -0,0 +1,29 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysRoleDepartment = "base_sys_role_department"
// BaseSysRoleDepartment mapped from table <base_sys_role_department>
type BaseSysRoleDepartment struct {
*cool.Model
RoleID uint `gorm:"column:roleId;type:bigint;not null" json:"roleId"` // 角色ID
DepartmentID uint `gorm:"column:departmentId;type:bigint;not null" json:"departmentId"` // 部门ID
}
// TableName BaseSysRoleDepartment's table name
func (*BaseSysRoleDepartment) TableName() string {
return TableNameBaseSysRoleDepartment
}
// NewBaseSysRoleDepartment create a new BaseSysRoleDepartment
func NewBaseSysRoleDepartment() *BaseSysRoleDepartment {
return &BaseSysRoleDepartment{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysRoleDepartment{})
}

View File

@@ -0,0 +1,29 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysRoleMenu = "base_sys_role_menu"
// BaseSysRoleMenu mapped from table <base_sys_role_menu>
type BaseSysRoleMenu struct {
*cool.Model
RoleID uint `gorm:"column:roleId;type:bigint;not null" json:"roleId"` // 角色ID
MenuID uint `gorm:"column:menuId;type:bigint;not null" json:"menuId"` // 菜单ID
}
// TableName BaseSysRoleMenu's table name
func (*BaseSysRoleMenu) TableName() string {
return TableNameBaseSysRoleMenu
}
// NewBaseSysRoleMenu create a new BaseSysRoleMenu
func NewBaseSysRoleMenu() *BaseSysRoleMenu {
return &BaseSysRoleMenu{
Model: &cool.Model{},
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysRoleMenu{})
}

View File

@@ -0,0 +1,39 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysUser = "base_sys_user"
// BaseSysUser mapped from table <base_sys_user>
type BaseSysUser struct {
*cool.Model
DepartmentID uint `gorm:"column:departmentId;type:bigint;index" json:"departmentId"` // 部门ID
Name *string `gorm:"column:name;type:varchar(255)" json:"name"` // 姓名
Username string `gorm:"column:username;type:varchar(100);not null;Index" json:"username"` // 用户名
Password string `gorm:"column:password;type:varchar(255);not null" json:"password"` // 密码
PasswordV *int32 `gorm:"column:passwordV;type:int;not null;default:1" json:"passwordV"` // 密码版本, 作用是改完密码让原来的token失效
NickName *string `gorm:"column:nickName;type:varchar(255)" json:"nickName"` // 昵称
HeadImg *string `gorm:"column:headImg;type:varchar(255)" json:"headImg"` // 头像
Phone *string `gorm:"column:phone;type:varchar(20);index" json:"phone"` // 手机
Email *string `gorm:"column:email;type:varchar(255)" json:"email"` // 邮箱
Status *int32 `gorm:"column:status;not null;default:1" json:"status"` // 状态 0:禁用 1启用
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
SocketID *string `gorm:"column:socketId;type:varchar(255)" json:"socketId"` // socketId
}
// TableName BaseSysUser's table name
func (*BaseSysUser) TableName() string {
return TableNameBaseSysUser
}
// NewBaseSysUser 创建一个新的BaseSysUser
func NewBaseSysUser() *BaseSysUser {
return &BaseSysUser{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysUser{})
}

View File

@@ -0,0 +1,29 @@
package model
import "github.com/cool-team-official/cool-admin-go/cool"
const TableNameBaseSysUserRole = "base_sys_user_role"
// BaseSysUserRole mapped from table <base_sys_user_role>
type BaseSysUserRole struct {
*cool.Model
UserID uint `gorm:"column:userId;type:bigint;not null" json:"userId"` // 用户ID
RoleID uint `gorm:"column:roleId;type:bigint;not null" json:"roleId"` // 角色ID
}
// TableName BaseSysUserRole's table name
func (*BaseSysUserRole) TableName() string {
return TableNameBaseSysUserRole
}
// NewBaseSysUserRole create a new BaseSysUserRole
func NewBaseSysUserRole() *BaseSysUserRole {
return &BaseSysUserRole{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&BaseSysUserRole{})
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,34 @@
[
{
"id": 1,
"createTime": "2021-02-24 21:17:11.971397",
"updateTime": "2021-02-24 21:17:15.697917",
"name": "COOL",
"parentId": null,
"orderNum": 0
},
{
"id": 11,
"createTime": "2021-02-26 14:17:06.690613",
"updateTime": "2021-02-26 14:17:06.690613",
"name": "开发",
"parentId": "1",
"orderNum": 0
},
{
"id": 12,
"createTime": "2021-02-26 14:17:11.576369",
"updateTime": "2021-02-26 14:17:11.576369",
"name": "测试",
"parentId": "1",
"orderNum": 0
},
{
"id": 13,
"createTime": "2021-02-26 14:28:59.685177",
"updateTime": "2021-02-26 14:28:59.685177",
"name": "游客",
"parentId": "1",
"orderNum": 0
}
]

View File

@@ -0,0 +1,842 @@
[
{
"id": 1,
"createTime": "2019-09-11 11:14:44.000000",
"updateTime": "2019-11-18 15:56:36.000000",
"parentId": null,
"name": "工作台",
"router": "/",
"perms": null,
"type": 0,
"icon": "icon-workbench",
"orderNum": 1,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 2,
"createTime": "2019-09-11 11:14:47.000000",
"updateTime": "2021-02-27 17:16:05.000000",
"parentId": null,
"name": "系统管理",
"router": "/sys",
"perms": null,
"type": 0,
"icon": "icon-system",
"orderNum": 2,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 8,
"createTime": "1900-01-20 23:19:57.000000",
"updateTime": "2021-03-08 22:59:12.000000",
"parentId": "27",
"name": "菜单列表",
"router": "/sys/menu",
"perms": null,
"type": 1,
"icon": "icon-menu",
"orderNum": 2,
"viewPath": "cool/modules/base/views/menu.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 10,
"createTime": "1900-01-20 00:19:27.325000",
"updateTime": "1900-01-20 00:19:27.325000",
"parentId": "8",
"name": "新增",
"router": null,
"perms": "base:sys:menu:add",
"type": 2,
"icon": null,
"orderNum": 1,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 11,
"createTime": "1900-01-20 00:19:51.101000",
"updateTime": "1900-01-20 00:19:51.101000",
"parentId": "8",
"name": "删除",
"router": null,
"perms": "base:sys:menu:delete",
"type": 2,
"icon": null,
"orderNum": 2,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 12,
"createTime": "1900-01-20 00:20:05.150000",
"updateTime": "1900-01-20 00:20:05.150000",
"parentId": "8",
"name": "修改",
"router": null,
"perms": "base:sys:menu:update",
"type": 2,
"icon": null,
"orderNum": 3,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 13,
"createTime": "1900-01-20 00:20:19.341000",
"updateTime": "1900-01-20 00:20:19.341000",
"parentId": "8",
"name": "查询",
"router": null,
"perms": "base:sys:menu:page,base:sys:menu:list,base:sys:menu:info",
"type": 2,
"icon": null,
"orderNum": 4,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 22,
"createTime": "2019-09-12 00:34:01.000000",
"updateTime": "2021-03-08 22:59:23.000000",
"parentId": "27",
"name": "角色列表",
"router": "/sys/role",
"perms": null,
"type": 1,
"icon": "icon-common",
"orderNum": 3,
"viewPath": "cool/modules/base/views/role.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 23,
"createTime": "1900-01-20 00:34:23.459000",
"updateTime": "1900-01-20 00:34:23.459000",
"parentId": "22",
"name": "新增",
"router": null,
"perms": "base:sys:role:add",
"type": 2,
"icon": null,
"orderNum": 1,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 24,
"createTime": "1900-01-20 00:34:40.523000",
"updateTime": "1900-01-20 00:34:40.523000",
"parentId": "22",
"name": "删除",
"router": null,
"perms": "base:sys:role:delete",
"type": 2,
"icon": null,
"orderNum": 2,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 25,
"createTime": "1900-01-20 00:34:53.306000",
"updateTime": "1900-01-20 00:34:53.306000",
"parentId": "22",
"name": "修改",
"router": null,
"perms": "base:sys:role:update",
"type": 2,
"icon": null,
"orderNum": 3,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 26,
"createTime": "1900-01-20 00:35:05.024000",
"updateTime": "1900-01-20 00:35:05.024000",
"parentId": "22",
"name": "查询",
"router": null,
"perms": "base:sys:role:page,base:sys:role:list,base:sys:role:info",
"type": 2,
"icon": null,
"orderNum": 4,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 27,
"createTime": "2019-09-12 15:52:44.000000",
"updateTime": "2019-09-15 22:11:56.000000",
"parentId": "2",
"name": "权限管理",
"router": null,
"perms": null,
"type": 0,
"icon": "icon-auth",
"orderNum": 1,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 29,
"createTime": "2019-09-12 17:35:51.000000",
"updateTime": "2021-03-08 23:01:39.000000",
"parentId": "105",
"name": "请求日志",
"router": "/sys/log",
"perms": null,
"type": 1,
"icon": "icon-log",
"orderNum": 1,
"viewPath": "cool/modules/base/views/log.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 30,
"createTime": "2019-09-12 17:37:03.000000",
"updateTime": "2021-03-03 10:16:26.000000",
"parentId": "29",
"name": "权限",
"router": null,
"perms": "base:sys:log:page,base:sys:log:clear,base:sys:log:getKeep,base:sys:log:setKeep",
"type": 2,
"icon": null,
"orderNum": 1,
"viewPath": null,
"keepAlive": 0,
"isShow": 1
},
{
"id": 43,
"createTime": "2019-11-07 14:22:34.000000",
"updateTime": "2021-03-08 23:02:51.000000",
"parentId": "45",
"name": "crud 示例",
"router": "/crud",
"perms": null,
"type": 1,
"icon": "icon-favor",
"orderNum": 1,
"viewPath": "cool/modules/demo/views/crud.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 45,
"createTime": "2019-11-07 22:36:57.000000",
"updateTime": "2019-11-11 15:21:10.000000",
"parentId": "1",
"name": "组件库",
"router": "/ui-lib",
"perms": null,
"type": 0,
"icon": "icon-common",
"orderNum": 2,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 47,
"createTime": "2019-11-08 09:35:08.000000",
"updateTime": "2021-02-27 17:16:35.000000",
"parentId": null,
"name": "框架教程",
"router": "/tutorial",
"perms": null,
"type": 0,
"icon": "icon-task",
"orderNum": 4,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 48,
"createTime": "2019-11-08 09:35:53.000000",
"updateTime": "2021-03-03 11:03:21.000000",
"parentId": "47",
"name": "文档",
"router": "/tutorial/doc",
"perms": null,
"type": 1,
"icon": "icon-log",
"orderNum": 0,
"viewPath": "https://cool-js.com",
"keepAlive": 1,
"isShow": 1
},
{
"id": 49,
"createTime": "2019-11-09 22:11:13.000000",
"updateTime": "2021-03-09 09:50:46.000000",
"parentId": "45",
"name": "quill 富文本编辑器",
"router": "/editor-quill",
"perms": null,
"type": 1,
"icon": "icon-favor",
"orderNum": 2,
"viewPath": "cool/modules/demo/views/editor-quill.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 59,
"createTime": "2019-11-18 16:50:27.000000",
"updateTime": "2019-11-18 16:50:27.000000",
"parentId": "97",
"name": "部门列表",
"router": null,
"perms": "base:sys:department:list",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 60,
"createTime": "2019-11-18 16:50:45.000000",
"updateTime": "2019-11-18 16:50:45.000000",
"parentId": "97",
"name": "新增部门",
"router": null,
"perms": "base:sys:department:add",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 61,
"createTime": "2019-11-18 16:50:59.000000",
"updateTime": "2019-11-18 16:50:59.000000",
"parentId": "97",
"name": "更新部门",
"router": null,
"perms": "base:sys:department:update",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 62,
"createTime": "2019-11-18 16:51:13.000000",
"updateTime": "2019-11-18 16:51:13.000000",
"parentId": "97",
"name": "删除部门",
"router": null,
"perms": "base:sys:department:delete",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 63,
"createTime": "2019-11-18 17:49:35.000000",
"updateTime": "2019-11-18 17:49:35.000000",
"parentId": "97",
"name": "部门排序",
"router": null,
"perms": "base:sys:department:order",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 65,
"createTime": "2019-11-18 23:59:21.000000",
"updateTime": "2019-11-18 23:59:21.000000",
"parentId": "97",
"name": "用户转移",
"router": null,
"perms": "base:sys:user:move",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 78,
"createTime": "2019-12-10 13:27:56.000000",
"updateTime": "2021-02-27 17:08:53.000000",
"parentId": "2",
"name": "参数配置",
"router": null,
"perms": null,
"type": 0,
"icon": "icon-common",
"orderNum": 4,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 79,
"createTime": "1900-01-20 13:29:33.000000",
"updateTime": "2021-03-08 23:01:48.000000",
"parentId": "78",
"name": "参数列表",
"router": "/sys/param",
"perms": null,
"type": 1,
"icon": "icon-menu",
"orderNum": 0,
"viewPath": "cool/modules/base/views/param.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 80,
"createTime": "1900-01-20 13:29:50.146000",
"updateTime": "1900-01-20 13:29:50.146000",
"parentId": "79",
"name": "新增",
"router": null,
"perms": "base:sys:param:add",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 81,
"createTime": "1900-01-20 13:30:10.030000",
"updateTime": "1900-01-20 13:30:10.030000",
"parentId": "79",
"name": "修改",
"router": null,
"perms": "base:sys:param:info,base:sys:param:update",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 82,
"createTime": "1900-01-20 13:30:25.791000",
"updateTime": "1900-01-20 13:30:25.791000",
"parentId": "79",
"name": "删除",
"router": null,
"perms": "base:sys:param:delete",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 83,
"createTime": "1900-01-20 13:30:40.469000",
"updateTime": "1900-01-20 13:30:40.469000",
"parentId": "79",
"name": "查看",
"router": null,
"perms": "base:sys:param:page,base:sys:param:list,base:sys:param:info",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 84,
"createTime": "2020-07-25 16:21:30.000000",
"updateTime": "2020-07-25 16:21:30.000000",
"parentId": null,
"name": "通用",
"router": null,
"perms": null,
"type": 0,
"icon": "icon-radioboxfill",
"orderNum": 99,
"viewPath": null,
"keepAlive": 1,
"isShow": 0
},
{
"id": 85,
"createTime": "2020-07-25 16:22:14.000000",
"updateTime": "2021-03-03 10:36:00.000000",
"parentId": "84",
"name": "图片上传",
"router": null,
"perms": "space:info:page,space:info:list,space:info:info,space:info:add,space:info:delete,space:info:update,space:type:page,space:type:list,space:type:info,space:type:add,space:type:delete,space:type:update",
"type": 2,
"icon": null,
"orderNum": 1,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 86,
"createTime": "2020-08-12 09:56:27.000000",
"updateTime": "2021-03-08 23:03:03.000000",
"parentId": "45",
"name": "文件上传",
"router": "/upload",
"perms": null,
"type": 1,
"icon": "icon-favor",
"orderNum": 3,
"viewPath": "cool/modules/demo/views/upload.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 90,
"createTime": "1900-01-20 10:26:58.615000",
"updateTime": "1900-01-20 10:26:58.615000",
"parentId": "84",
"name": "客服聊天",
"router": null,
"perms": "base:app:im:message:read,base:app:im:message:page,base:app:im:session:page,base:app:im:session:list,base:app:im:session:unreadCount,base:app:im:session:delete",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 96,
"createTime": "2021-01-12 14:12:20.000000",
"updateTime": "2021-03-08 23:02:40.000000",
"parentId": "1",
"name": "组件预览",
"router": "/demo",
"perms": null,
"type": 1,
"icon": "icon-favor",
"orderNum": 0,
"viewPath": "cool/modules/demo/views/demo.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 97,
"createTime": "1900-01-20 14:14:02.000000",
"updateTime": "2021-03-09 11:03:09.000000",
"parentId": "27",
"name": "用户列表",
"router": "/sys/user",
"perms": null,
"type": 1,
"icon": "icon-user",
"orderNum": 0,
"viewPath": "cool/modules/base/views/user.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 98,
"createTime": "1900-01-20 14:14:13.528000",
"updateTime": "1900-01-20 14:14:13.528000",
"parentId": "97",
"name": "新增",
"router": null,
"perms": "base:sys:user:add",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 99,
"createTime": "1900-01-20 14:14:22.823000",
"updateTime": "1900-01-20 14:14:22.823000",
"parentId": "97",
"name": "删除",
"router": null,
"perms": "base:sys:user:delete",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 100,
"createTime": "1900-01-20 14:14:33.973000",
"updateTime": "1900-01-20 14:14:33.973000",
"parentId": "97",
"name": "修改",
"router": null,
"perms": "base:sys:user:delete,base:sys:user:update",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 101,
"createTime": "2021-01-12 14:14:51.000000",
"updateTime": "2021-01-12 14:14:51.000000",
"parentId": "97",
"name": "查询",
"router": null,
"perms": "base:sys:user:page,base:sys:user:list,base:sys:user:info",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 105,
"createTime": "2021-01-21 10:42:55.000000",
"updateTime": "2021-01-21 10:42:55.000000",
"parentId": "2",
"name": "监控管理",
"router": null,
"perms": null,
"type": 0,
"icon": "icon-rank",
"orderNum": 6,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 117,
"createTime": "2021-03-05 10:58:25.000000",
"updateTime": "2021-03-05 10:58:25.000000",
"parentId": null,
"name": "任务管理",
"router": null,
"perms": null,
"type": 0,
"icon": "icon-activity",
"orderNum": 5,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 118,
"createTime": "2021-03-05 10:59:42.000000",
"updateTime": "2021-03-05 10:59:42.000000",
"parentId": "117",
"name": "任务列表",
"router": "/task",
"perms": null,
"type": 1,
"icon": "icon-menu",
"orderNum": 0,
"viewPath": "cool/modules/task/views/task.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 119,
"createTime": "2021-03-05 11:00:00.000000",
"updateTime": "2021-03-05 11:00:00.000000",
"parentId": "118",
"name": "权限",
"router": null,
"perms": "task:info:page,task:info:list,task:info:info,task:info:add,task:info:delete,task:info:update,task:info:stop,task:info:start,task:info:once,task:info:log",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 197,
"createTime": "2022-07-05 16:05:27.403000",
"updateTime": "2022-07-05 16:15:16.025000",
"parentId": null,
"name": "字典管理",
"router": null,
"perms": null,
"type": 0,
"icon": "icon-log",
"orderNum": 3,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 198,
"createTime": "2022-07-05 16:08:50.307000",
"updateTime": "2022-07-05 16:14:13.196000",
"parentId": "197",
"name": "字典列表",
"router": "/dict/list",
"perms": null,
"type": 1,
"icon": "icon-menu",
"orderNum": 1,
"viewPath": "modules/dict/views/list.vue",
"keepAlive": 1,
"isShow": 1
},
{
"id": 199,
"createTime": "2022-07-05 16:08:50.748162",
"updateTime": "2022-07-05 16:08:50.748162",
"parentId": "198",
"name": "删除",
"router": null,
"perms": "dict:info:delete",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 200,
"createTime": "2022-07-05 16:08:50.800623",
"updateTime": "2022-07-05 16:08:50.800623",
"parentId": "198",
"name": "修改",
"router": null,
"perms": "dict:info:update,dict:info:info",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 201,
"createTime": "2022-07-05 16:08:50.859141",
"updateTime": "2022-07-05 16:08:50.859141",
"parentId": "198",
"name": "获得字典数据",
"router": null,
"perms": "dict:info:data",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 202,
"createTime": "2022-07-05 16:08:50.916874",
"updateTime": "2022-07-05 16:08:50.916874",
"parentId": "198",
"name": "单个信息",
"router": null,
"perms": "dict:info:info",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 203,
"createTime": "2022-07-05 16:08:50.972783",
"updateTime": "2022-07-05 16:08:50.972783",
"parentId": "198",
"name": "列表查询",
"router": null,
"perms": "dict:info:list",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 204,
"createTime": "2022-07-05 16:08:51.030928",
"updateTime": "2022-07-05 16:08:51.030928",
"parentId": "198",
"name": "分页查询",
"router": null,
"perms": "dict:info:page",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 205,
"createTime": "2022-07-05 16:08:51.087883",
"updateTime": "2022-07-05 16:08:51.087883",
"parentId": "198",
"name": "新增",
"router": null,
"perms": "dict:info:add",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
},
{
"id": 206,
"createTime": "2022-07-06 10:41:26.503000",
"updateTime": "2022-07-06 10:41:37.000000",
"parentId": "198",
"name": "组权限",
"router": null,
"perms": "dict:type:list,dict:type:update,dict:type:delete,dict:type:add",
"type": 2,
"icon": null,
"orderNum": 0,
"viewPath": null,
"keepAlive": 1,
"isShow": 1
}
]

View File

@@ -0,0 +1,22 @@
[
{
"id": 1,
"createTime": "2021-02-26 13:53:05.000000",
"updateTime": "2021-03-03 17:50:04.000000",
"keyName": "text",
"name": "富文本参数",
"data": "<p><strong class=\"ql-size-huge\">111xxxxx2222<span class=\"ql-cursor\"></span></strong></p>",
"dataType": 0,
"remark": null
},
{
"id": 2,
"createTime": "2021-02-26 13:53:18.000000",
"updateTime": "2021-02-26 13:53:18.000000",
"keyName": "json",
"name": "JSON参数",
"data": "{\n code: 111\n}",
"dataType": 0,
"remark": null
}
]

View File

@@ -0,0 +1,52 @@
[
{
"id": 1,
"createTime": "2021-02-24 21:18:39.682358",
"updateTime": "2021-02-24 21:18:39.682358",
"userId": "1",
"name": "超管",
"label": "admin",
"remark": "最高权限的角色",
"relevance": 1
},
{
"id": 10,
"createTime": "2021-02-26 14:15:38.000000",
"updateTime": "2021-02-26 14:15:38.000000",
"userId": "1",
"name": "系统管理员",
"label": "admin-sys",
"remark": null,
"relevance": 1
},
{
"id": 11,
"createTime": "2021-02-26 14:16:49.044744",
"updateTime": "2021-02-26 14:16:49.044744",
"userId": "1",
"name": "游客",
"label": "visitor",
"remark": null,
"relevance": 0
},
{
"id": 12,
"createTime": "2021-02-26 14:26:51.000000",
"updateTime": "2021-02-26 14:32:35.000000",
"userId": "1",
"name": "开发",
"label": "dev",
"remark": null,
"relevance": 0
},
{
"id": 13,
"createTime": "2021-02-26 14:27:58.000000",
"updateTime": "2021-02-26 14:33:49.000000",
"userId": "1",
"name": "测试",
"label": "test",
"remark": null,
"relevance": 0
}
]

View File

@@ -0,0 +1,65 @@
[
{
"id": 1,
"createTime": "2021-02-26 12:00:23.787939",
"updateTime": "2021-02-26 12:00:23.787939",
"roleId": "8",
"departmentId": "4"
},
{
"id": 2,
"createTime": "2021-02-26 12:01:11.525205",
"updateTime": "2021-02-26 12:01:11.525205",
"roleId": "9",
"departmentId": "1"
},
{
"id": 3,
"createTime": "2021-02-26 12:01:11.624266",
"updateTime": "2021-02-26 12:01:11.624266",
"roleId": "9",
"departmentId": "4"
},
{
"id": 4,
"createTime": "2021-02-26 12:01:11.721894",
"updateTime": "2021-02-26 12:01:11.721894",
"roleId": "9",
"departmentId": "5"
},
{
"id": 5,
"createTime": "2021-02-26 12:01:11.823342",
"updateTime": "2021-02-26 12:01:11.823342",
"roleId": "9",
"departmentId": "8"
},
{
"id": 6,
"createTime": "2021-02-26 12:01:11.922873",
"updateTime": "2021-02-26 12:01:11.922873",
"roleId": "9",
"departmentId": "9"
},
{
"id": 23,
"createTime": "2021-02-26 14:32:40.354669",
"updateTime": "2021-02-26 14:32:40.354669",
"roleId": "12",
"departmentId": "11"
},
{
"id": 25,
"createTime": "2021-02-26 14:32:59.726608",
"updateTime": "2021-02-26 14:32:59.726608",
"roleId": "10",
"departmentId": "1"
},
{
"id": 27,
"createTime": "2021-02-26 14:33:54.579947",
"updateTime": "2021-02-26 14:33:54.579947",
"roleId": "13",
"departmentId": "12"
}
]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,104 @@
[
{
"id": 1,
"createTime": "2021-02-24 21:16:41.525157",
"updateTime": "2021-02-27 18:21:16.000000",
"departmentId": "1",
"name": "超级管理员",
"username": "admin",
"password": "e10adc3949ba59abbe56e057f20f883e",
"passwordV": 3,
"nickName": "管理员",
"headImg": "https://cool-admin-pro.oss-cn-shanghai.aliyuncs.com/app/c8128c24-d0e9-4e07-9c0d-6f65446e105b.png",
"phone": "18000000000",
"email": "team@cool-js.com",
"status": 1,
"remark": "拥有最高权限的用户",
"socketId": null
},
{
"id": 24,
"createTime": "2021-02-26 14:17:38.000000",
"updateTime": "2021-02-26 14:17:38.000000",
"departmentId": "11",
"name": "小白",
"username": "xiaobai",
"password": "e10adc3949ba59abbe56e057f20f883e",
"passwordV": 1,
"nickName": "小白",
"headImg": null,
"phone": null,
"email": null,
"status": 1,
"remark": null,
"socketId": null
},
{
"id": 25,
"createTime": "2021-02-26 14:28:25.000000",
"updateTime": "2021-02-26 14:28:25.000000",
"departmentId": "12",
"name": "小黑",
"username": "xiaohei",
"password": "e10adc3949ba59abbe56e057f20f883e",
"passwordV": 1,
"nickName": "小黑",
"headImg": null,
"phone": null,
"email": null,
"status": 1,
"remark": null,
"socketId": null
},
{
"id": 26,
"createTime": "2021-02-26 14:28:49.000000",
"updateTime": "2021-02-26 14:28:49.000000",
"departmentId": "12",
"name": "小绿",
"username": "xiaolv",
"password": "e10adc3949ba59abbe56e057f20f883e",
"passwordV": 1,
"nickName": "小绿",
"headImg": null,
"phone": null,
"email": null,
"status": 1,
"remark": null,
"socketId": null
},
{
"id": 27,
"createTime": "2021-02-26 14:29:23.000000",
"updateTime": "2021-02-26 14:29:23.000000",
"departmentId": "13",
"name": "小青",
"username": "xiaoqin",
"password": "e10adc3949ba59abbe56e057f20f883e",
"passwordV": 1,
"nickName": "小青",
"headImg": null,
"phone": null,
"email": null,
"status": 1,
"remark": null,
"socketId": null
},
{
"id": 28,
"createTime": "2021-02-26 14:29:52.000000",
"updateTime": "2021-02-26 14:29:52.000000",
"departmentId": "11",
"name": "神仙都没用",
"username": "icssoa",
"password": "e10adc3949ba59abbe56e057f20f883e",
"passwordV": 1,
"nickName": "神仙都没用",
"headImg": "https://cool-admin.cn.utools.club/uploads//20210226/0eeab9a0-77fc-11eb-b64f-674cd46b6601.jpg",
"phone": null,
"email": null,
"status": 1,
"remark": null,
"socketId": null
}
]

View File

@@ -0,0 +1,205 @@
[
{
"id": 1,
"createTime": "2021-02-24 22:03:11.665805",
"updateTime": "2021-02-24 22:03:11.665805",
"userId": "1",
"roleId": "1"
},
{
"id": 2,
"createTime": "2021-02-25 11:03:55.325988",
"updateTime": "2021-02-25 11:03:55.325988",
"userId": "2",
"roleId": "1"
},
{
"id": 3,
"createTime": "2021-02-25 14:30:57.295150",
"updateTime": "2021-02-25 14:30:57.295150",
"userId": "3",
"roleId": "1"
},
{
"id": 4,
"createTime": "2021-02-25 14:39:32.975014",
"updateTime": "2021-02-25 14:39:32.975014",
"userId": "4",
"roleId": "1"
},
{
"id": 5,
"createTime": "2021-02-25 14:40:56.812948",
"updateTime": "2021-02-25 14:40:56.812948",
"userId": "5",
"roleId": "1"
},
{
"id": 6,
"createTime": "2021-02-25 14:44:08.436555",
"updateTime": "2021-02-25 14:44:08.436555",
"userId": "6",
"roleId": "1"
},
{
"id": 7,
"createTime": "2021-02-25 14:46:17.409232",
"updateTime": "2021-02-25 14:46:17.409232",
"userId": "7",
"roleId": "1"
},
{
"id": 8,
"createTime": "2021-02-25 14:47:47.211749",
"updateTime": "2021-02-25 14:47:47.211749",
"userId": "8",
"roleId": "1"
},
{
"id": 9,
"createTime": "2021-02-25 14:48:11.734024",
"updateTime": "2021-02-25 14:48:11.734024",
"userId": "9",
"roleId": "1"
},
{
"id": 10,
"createTime": "2021-02-25 14:50:48.288616",
"updateTime": "2021-02-25 14:50:48.288616",
"userId": "10",
"roleId": "1"
},
{
"id": 11,
"createTime": "2021-02-25 14:51:32.123884",
"updateTime": "2021-02-25 14:51:32.123884",
"userId": "11",
"roleId": "1"
},
{
"id": 12,
"createTime": "2021-02-25 15:46:26.356943",
"updateTime": "2021-02-25 15:46:26.356943",
"userId": "12",
"roleId": "1"
},
{
"id": 13,
"createTime": "2021-02-25 15:56:43.475155",
"updateTime": "2021-02-25 15:56:43.475155",
"userId": "13",
"roleId": "1"
},
{
"id": 14,
"createTime": "2021-02-25 16:03:14.417784",
"updateTime": "2021-02-25 16:03:14.417784",
"userId": "14",
"roleId": "1"
},
{
"id": 16,
"createTime": "2021-02-25 16:22:11.200152",
"updateTime": "2021-02-25 16:22:11.200152",
"userId": "16",
"roleId": "1"
},
{
"id": 17,
"createTime": "2021-02-25 17:44:37.635550",
"updateTime": "2021-02-25 17:44:37.635550",
"userId": "15",
"roleId": "1"
},
{
"id": 19,
"createTime": "2021-02-25 17:51:00.554812",
"updateTime": "2021-02-25 17:51:00.554812",
"userId": "18",
"roleId": "1"
},
{
"id": 21,
"createTime": "2021-02-25 17:54:41.375113",
"updateTime": "2021-02-25 17:54:41.375113",
"userId": "17",
"roleId": "1"
},
{
"id": 22,
"createTime": "2021-02-25 17:55:49.385301",
"updateTime": "2021-02-25 17:55:49.385301",
"userId": "20",
"roleId": "1"
},
{
"id": 24,
"createTime": "2021-02-25 17:58:35.452363",
"updateTime": "2021-02-25 17:58:35.452363",
"userId": "22",
"roleId": "1"
},
{
"id": 27,
"createTime": "2021-02-25 21:25:55.005236",
"updateTime": "2021-02-25 21:25:55.005236",
"userId": "19",
"roleId": "1"
},
{
"id": 28,
"createTime": "2021-02-26 13:50:05.633242",
"updateTime": "2021-02-26 13:50:05.633242",
"userId": "21",
"roleId": "8"
},
{
"id": 29,
"createTime": "2021-02-26 13:50:17.836990",
"updateTime": "2021-02-26 13:50:17.836990",
"userId": "23",
"roleId": "8"
},
{
"id": 38,
"createTime": "2021-02-26 14:36:08.899046",
"updateTime": "2021-02-26 14:36:08.899046",
"userId": "26",
"roleId": "13"
},
{
"id": 39,
"createTime": "2021-02-26 14:36:13.149510",
"updateTime": "2021-02-26 14:36:13.149510",
"userId": "25",
"roleId": "13"
},
{
"id": 40,
"createTime": "2021-02-26 14:36:20.737073",
"updateTime": "2021-02-26 14:36:20.737073",
"userId": "27",
"roleId": "11"
},
{
"id": 42,
"createTime": "2021-02-26 14:36:53.481478",
"updateTime": "2021-02-26 14:36:53.481478",
"userId": "24",
"roleId": "12"
},
{
"id": 43,
"createTime": "2021-02-26 14:36:58.477817",
"updateTime": "2021-02-26 14:36:58.477817",
"userId": "28",
"roleId": "12"
},
{
"id": 44,
"createTime": "2021-02-26 14:36:58.577114",
"updateTime": "2021-02-26 14:36:58.577114",
"userId": "28",
"roleId": "10"
}
]

View File

@@ -0,0 +1,223 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/text/gstr"
)
type BaseOpenService struct {
*cool.Service
}
func NewBaseOpenService() *BaseOpenService {
return &BaseOpenService{
&cool.Service{},
}
}
// AdminEPS 获取eps
func (s *BaseOpenService) AdminEPS(ctx g.Ctx) (result *g.Var, err error) {
c := cool.CacheEPS
result, err = c.GetOrSetFunc(ctx, "adminEPS", func(ctx g.Ctx) (interface{}, error) {
return s.creatAdminEPS(ctx)
}, 0)
return
}
// creatAdminEPS 创建eps
func (s *BaseOpenService) creatAdminEPS(ctx g.Ctx) (adminEPS interface{}, err error) {
var (
baseEpsAdmin = model.NewBaseEpsAdmin()
)
type Api struct {
Module string `json:"module"` // 所属模块名称 例如base
Method string `json:"method"` // 请求方法 例如GET
Path string `json:"path"` // 请求路径 例如:/welcome
Prefix string `json:"prefix"` // 路由前缀 例如:/admin/base/open
Summary string `json:"summary"` // 描述 例如:欢迎页面
Tag string `json:"tag"` // 标签 例如base 好像暂时不用
Dts string `json:"dts"` // 未知 例如:{} 好像暂时不用
}
// type Column struct {
// }
type Module struct {
Api []*Api `json:"api"`
Columns []*cool.ColumnInfo `json:"columns"`
Module string `json:"module"`
Prefix string `json:"prefix"`
}
admineps := make(map[string][]*Module)
// 获取所有路由并更新到数据库表 base_eps_admin
cool.DBM(baseEpsAdmin).Where("1=1").Delete()
routers := g.Server().GetRoutes()
for _, router := range routers {
if router.Type == ghttp.HandlerTypeMiddleware || router.Type == ghttp.HandlerTypeHook {
continue
}
if router.Method == "ALL" {
continue
}
routeSplite := gstr.Split(router.Route, "/")
if len(routeSplite) < 5 {
continue
}
if routeSplite[1] != "admin" {
continue
}
module := routeSplite[2]
method := router.Method
// 获取最后一个元素加前缀 / 为 path
path := "/" + routeSplite[len(routeSplite)-1]
// 获取前面的元素为prefix
prefix := gstr.Join(routeSplite[0:len(routeSplite)-1], "/")
// 获取最后一个元素为summary
summary := routeSplite[len(routeSplite)-1]
cool.DBM(baseEpsAdmin).Insert(&Api{
Module: module,
Method: method,
Path: path,
Prefix: prefix,
Summary: summary,
Tag: "",
Dts: "",
})
}
// 读取数据库表生成eps
// var modules []*Module
items, _ := cool.DBM(baseEpsAdmin).Fields("DISTINCT module,prefix").All()
for _, item := range items {
module := item["module"].String()
prefix := item["prefix"].String()
apis, _ := cool.DBM(baseEpsAdmin).Where("module=? AND prefix=?", module, prefix).All()
var apiList []*Api
for _, api := range apis {
apiList = append(apiList, &Api{
Module: api["module"].String(),
Method: api["method"].String(),
Path: api["path"].String(),
Prefix: api["prefix"].String(),
Summary: api["summary"].String(),
Tag: api["tag"].String(),
Dts: api["dts"].String(),
})
}
admineps[module] = append(admineps[module], &Module{
Api: apiList,
Columns: cool.ModelInfo[prefix],
Module: module,
Prefix: prefix,
})
}
adminEPS = gjson.New(admineps)
return
}
// AdminEPS 获取eps
func (s *BaseOpenService) AppEPS(ctx g.Ctx) (result *g.Var, err error) {
c := cool.CacheEPS
result, err = c.GetOrSetFunc(ctx, "appEPS", func(ctx g.Ctx) (interface{}, error) {
return s.creatAppEPS(ctx)
}, 0)
return
}
// creatAppEPS 创建app eps
func (s *BaseOpenService) creatAppEPS(ctx g.Ctx) (appEPS interface{}, err error) {
var (
baseEpsApp = model.NewBaseEpsApp()
)
type Api struct {
Module string `json:"module"` // 所属模块名称 例如base
Method string `json:"method"` // 请求方法 例如GET
Path string `json:"path"` // 请求路径 例如:/welcome
Prefix string `json:"prefix"` // 路由前缀 例如:/admin/base/open
Summary string `json:"summary"` // 描述 例如:欢迎页面
Tag string `json:"tag"` // 标签 例如base 好像暂时不用
Dts string `json:"dts"` // 未知 例如:{} 好像暂时不用
}
// type Column struct {
// }
type Module struct {
Api []*Api `json:"api"`
Columns []*cool.ColumnInfo `json:"columns"`
Module string `json:"module"`
Prefix string `json:"prefix"`
}
appeps := make(map[string][]*Module)
// 获取所有路由并更新到数据库表 base_eps_admin
cool.DBM(baseEpsApp).Where("1=1").Delete()
routers := g.Server().GetRoutes()
for _, router := range routers {
if router.Type == ghttp.HandlerTypeMiddleware || router.Type == ghttp.HandlerTypeHook {
continue
}
if router.Method == "ALL" {
continue
}
routeSplite := gstr.Split(router.Route, "/")
if len(routeSplite) < 5 {
continue
}
if routeSplite[1] != "app" {
continue
}
module := routeSplite[2]
method := router.Method
// 获取最后一个元素加前缀 / 为 path
path := "/" + routeSplite[len(routeSplite)-1]
// 获取前面的元素为prefix
prefix := gstr.Join(routeSplite[0:len(routeSplite)-1], "/")
// 获取最后一个元素为summary
summary := routeSplite[len(routeSplite)-1]
cool.DBM(baseEpsApp).Insert(&Api{
Module: module,
Method: method,
Path: path,
Prefix: prefix,
Summary: summary,
Tag: "",
Dts: "",
})
}
// 读取数据库表生成eps
// var modules []*Module
items, _ := cool.DBM(baseEpsApp).Fields("DISTINCT module,prefix").All()
for _, item := range items {
module := item["module"].String()
prefix := item["prefix"].String()
apis, _ := cool.DBM(baseEpsApp).Where("module=? AND prefix=?", module, prefix).All()
var apiList []*Api
for _, api := range apis {
apiList = append(apiList, &Api{
Module: api["module"].String(),
Method: api["method"].String(),
Path: api["path"].String(),
Prefix: api["prefix"].String(),
Summary: api["summary"].String(),
Tag: api["tag"].String(),
Dts: api["dts"].String(),
})
}
appeps[module] = append(appeps[module], &Module{
Api: apiList,
Columns: cool.ModelInfo[prefix],
Module: module,
Prefix: prefix,
})
}
appEPS = gjson.New(appeps)
return
}

View File

@@ -0,0 +1,53 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/frame/g"
)
type BaseSysConfService struct {
*cool.Service
}
func NewBaseSysConfService() *BaseSysConfService {
return &BaseSysConfService{
&cool.Service{
Model: model.NewBaseSysConf(),
UniqueKey: map[string]string{
"cKey": "配置键不能重复",
},
},
}
}
// UpdateValue 更新配置值
func (s *BaseSysConfService) UpdateValue(cKey, cValue string) error {
m := cool.DBM(s.Model).Where("cKey = ?", cKey)
record, err := m.One()
if err != nil {
return err
}
if record == nil {
_, err = cool.DBM(s.Model).Insert(g.Map{
"cKey": cKey,
"cValue": cValue,
})
} else {
_, err = cool.DBM(s.Model).Where("cKey = ?", cKey).Data(g.Map{"cValue": cValue}).Update()
}
return err
}
// GetValue 获取配置值
func (s *BaseSysConfService) GetValue(cKey string) string {
m := cool.DBM(s.Model).Where("cKey = ?", cKey)
record, err := m.One()
if err != nil {
return ""
}
if record == nil {
return ""
}
return record["cValue"].String()
}

View File

@@ -0,0 +1,78 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type BaseSysDepartmentService struct {
*cool.Service
}
// GetByRoleIds 获取部门
func (s *BaseSysDepartmentService) GetByRoleIds(roleIds []string, isAdmin bool) (res []uint) {
var (
result gdb.Result
BaseSysRoleDepartment = model.NewBaseSysRoleDepartment()
)
// 如果roleIds不为空
if len(roleIds) > 0 {
// 如果是超级管理员,则返回所有部门
if isAdmin {
result, _ = cool.DBM(s.Model).Fields("id").All()
for _, v := range result {
vmap := v.Map()
if vmap["id"] != nil {
res = append(res, gconv.Uint(vmap["id"]))
}
}
} else {
// 如果不是超级管理员,则返回角色所在部门
result, _ = cool.DBM(BaseSysRoleDepartment).Where("roleId IN (?)", roleIds).Fields("departmentId").All()
for _, v := range result {
vmap := v.Map()
if vmap["departmentId"] != nil {
res = append(res, gconv.Uint(vmap["departmentId"]))
}
}
}
}
return
}
// Order 排序部门
func (s *BaseSysDepartmentService) Order(ctx g.Ctx) (err error) {
r := g.RequestFromCtx(ctx).GetMap()
type item struct {
Id uint64 `json:"id"`
ParentId *uint64 `json:"parentId,omitempty"`
OrderNum int32 `json:"orderNum"`
}
var data *item
for _, v := range r {
err = gconv.Struct(v, &data)
if err != nil {
continue
}
cool.DBM(s.Model).Where("id = ?", data.Id).Data(data).Update()
}
return
}
// NewBaseSysDepartmentService 创建一个BaseSysDepartmentService实例
func NewBaseSysDepartmentService() *BaseSysDepartmentService {
return &BaseSysDepartmentService{
Service: &cool.Service{
Model: model.NewBaseSysDepartment(),
ListQueryOp: &cool.QueryOp{},
},
}
}

View File

@@ -0,0 +1,68 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
)
type BaseSysLogService struct {
*cool.Service
}
func NewBaseSysLogService() *BaseSysLogService {
return &BaseSysLogService{
&cool.Service{
Model: model.NewBaseSysLog(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"name", "params", "ipAddr"},
Select: "base_sys_log.*,user.name ",
Join: []*cool.JoinOp{
{
Model: model.NewBaseSysUser(),
Alias: "user",
Type: "LeftJoin",
Condition: "user.id = base_sys_log.userID",
},
},
},
},
}
}
// Record 记录日志
func (s *BaseSysLogService) Record(ctx g.Ctx) {
var (
admin = cool.GetAdmin(ctx)
r = g.RequestFromCtx(ctx)
)
baseSysLog := model.NewBaseSysLog()
baseSysLog.UserID = admin.UserId
baseSysLog.Action = r.Method + ":" + r.URL.Path
baseSysLog.IP = r.GetClientIp()
baseSysLog.IPAddr = r.GetClientIp()
baseSysLog.Params = r.GetBodyString()
m := cool.DBM(s.Model)
m.Insert(g.Map{
"userId": baseSysLog.UserID,
"action": baseSysLog.Action,
"ip": baseSysLog.IP,
"ipAddr": baseSysLog.IPAddr,
"params": baseSysLog.Params,
})
}
// Clear 清除日志
func (s *BaseSysLogService) Clear(isAll bool) (err error) {
BaseSysConfService := NewBaseSysConfService()
m := cool.DBM(s.Model)
if isAll {
_, err = m.Delete("1=1")
} else {
keepDays := gconv.Int(BaseSysConfService.GetValue("logKeep"))
_, err = m.Delete("createTime < ?", gtime.Now().AddDate(0, 0, -keepDays).String())
}
return
}

View File

@@ -0,0 +1,203 @@
package service
import (
"context"
"time"
"github.com/golang-jwt/jwt/v4"
"github.com/cool-team-official/cool-admin-go/cool"
v1 "github.com/cool-team-official/cool-admin-go/modules/base/api/v1"
"github.com/cool-team-official/cool-admin-go/modules/base/config"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/encoding/gbase64"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
"github.com/gogf/gf/v2/util/guid"
)
type BaseSysLoginService struct {
*cool.Service
}
type TokenResult struct {
Expire uint `json:"expire"`
Token string `json:"token"`
RefreshExpire uint `json:"refreshExpire"`
RefreshToken string `json:"refreshToken"`
}
// Login 登录
func (s *BaseSysLoginService) Login(ctx context.Context, req *v1.BaseOpenLoginReq) (result *TokenResult, err error) {
var (
captchaId = req.CaptchaId
verifyCode = req.VerifyCode
password = req.Password
username = req.Username
baseSysUser = model.NewBaseSysUser()
)
vcode, _ := cool.CacheManager.Get(ctx, captchaId)
if vcode.String() != verifyCode {
err = gerror.New("验证码错误")
return
}
md5password, _ := gmd5.Encrypt(password)
var user *model.BaseSysUser
cool.DBM(baseSysUser).Where("username=?", username).Where("password=?", md5password).Where("status=?", 1).Scan(&user)
if user == nil {
err = gerror.New("账户或密码不正确~")
return
}
result, err = s.generateTokenByUser(ctx, user)
if err != nil {
return
}
return
}
// Captcha 图形验证码
func (*BaseSysLoginService) Captcha(req *v1.BaseOpenCaptchaReq) (interface{}, error) {
type capchaInfo struct {
CaptchaId string `json:"captchaId"`
Data string `json:"data"`
}
var (
ctx g.Ctx
err error
result = &capchaInfo{}
)
captchaText := grand.Digits(4)
svg := `<svg width="150" height="50" xmlns="http://www.w3.org/2000/svg"><text x="75" y="25" text-anchor="middle" font-size="25" fill="#fff">` + captchaText + `</text></svg>`
svgbase64 := gbase64.EncodeString(svg)
result.Data = `data:image/svg+xml;base64,` + svgbase64
result.CaptchaId = guid.S()
cool.CacheManager.Set(ctx, result.CaptchaId, captchaText, 1800*time.Second)
g.Log().Debug(ctx, "验证码", result.CaptchaId, captchaText)
return result, err
}
// Logout 退出登录
func (*BaseSysLoginService) Logout(ctx context.Context) (err error) {
userId := cool.GetAdmin(ctx).UserId
cool.CacheManager.Remove(ctx, "admin:department:"+gconv.String(userId))
cool.CacheManager.Remove(ctx, "admin:perms:"+gconv.String(userId))
cool.CacheManager.Remove(ctx, "admin:token:"+gconv.String(userId))
cool.CacheManager.Remove(ctx, "admin:token:refresh:"+gconv.String(userId))
return
}
// RefreshToken 刷新token
func (s *BaseSysLoginService) RefreshToken(ctx context.Context, token string) (result *TokenResult, err error) {
tokenClaims, err := jwt.ParseWithClaims(token, &cool.Claims{}, func(token *jwt.Token) (interface{}, error) {
return []byte(config.Config.Jwt.Secret), nil
})
if err != nil {
return
}
claims, ok := tokenClaims.Claims.(*cool.Claims)
if !ok {
err = gerror.New("tokenClaims.Claims.(*Claims) error")
return
}
if !tokenClaims.Valid {
err = gerror.New("tokenClaims.Valid error")
return
}
if !claims.IsRefresh {
err = gerror.New("claims.IsRefresh error")
return
}
if !(claims.UserId > 0) {
err = gerror.New("claims.UserId error")
return
}
var (
user *model.BaseSysUser
baseSysUser = model.NewBaseSysUser()
)
cool.DBM(baseSysUser).Where("id=?", claims.UserId).Where("status=?", 1).Scan(&user)
if user == nil {
err = gerror.New("用户不存在")
return
}
result, err = s.generateTokenByUser(ctx, user)
return
}
// generateToken 生成token
func (*BaseSysLoginService) generateToken(ctx context.Context, user *model.BaseSysUser, roleIds []string, exprire uint, isRefresh bool) (token string) {
err := cool.CacheManager.Set(ctx, "admin:passwordVersion:"+gconv.String(user.ID), gconv.String(user.PasswordV), 0)
if err != nil {
g.Log().Error(ctx, "生成token失败", err)
}
claims := &cool.Claims{
IsRefresh: isRefresh,
RoleIds: roleIds,
Username: user.Username,
UserId: user.ID,
PasswordVersion: user.PasswordV,
RegisteredClaims: jwt.RegisteredClaims{
IssuedAt: jwt.NewNumericDate(time.Now()),
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(exprire) * time.Second)),
},
}
tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
token, err = tokenClaims.SignedString([]byte(config.Config.Jwt.Secret))
if err != nil {
g.Log().Error(ctx, "生成token失败", err)
}
return
}
// 根据用户生成前端需要的Token信息
func (s *BaseSysLoginService) generateTokenByUser(ctx context.Context, user *model.BaseSysUser) (result *TokenResult, err error) {
var (
baseSysRoleService = NewBaseSysRoleService()
baseSysMenuService = NewBaseSysMenuService()
baseSysDepartmentService = NewBaseSysDepartmentService()
)
// 获取用户角色
roleIds := baseSysRoleService.GetByUser(user.ID)
// 如果没有角色,则报错
if len(roleIds) == 0 {
err = gerror.New("该用户未设置任何角色,无法登录~")
return
}
// 生成token
result = &TokenResult{}
result.Expire = config.Config.Jwt.Token.Expire
result.RefreshExpire = config.Config.Jwt.Token.RefreshExpire
result.Token = s.generateToken(ctx, user, roleIds, result.Expire, false)
result.RefreshToken = s.generateToken(ctx, user, roleIds, result.RefreshExpire, true)
// 将用户相关信息保存到缓存
perms := baseSysMenuService.GetPerms(roleIds)
departments := baseSysDepartmentService.GetByRoleIds(roleIds, user.Username == "admin")
cool.CacheManager.Set(ctx, "admin:department:"+gconv.String(user.ID), departments, 0)
cool.CacheManager.Set(ctx, "admin:perms:"+gconv.String(user.ID), perms, 0)
cool.CacheManager.Set(ctx, "admin:token:"+gconv.String(user.ID), result.Token, 0)
cool.CacheManager.Set(ctx, "admin:token:refresh:"+gconv.String(user.ID), result.RefreshToken, 0)
return
}
// NewBaseSysLoginService 创建一个新的BaseSysLoginService
func NewBaseSysLoginService() *BaseSysLoginService {
return &BaseSysLoginService{}
}

View File

@@ -0,0 +1,91 @@
package service
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
)
type BaseSysMenuService struct {
*cool.Service
}
// GetPerms 获取菜单的权限
func (s *BaseSysMenuService) GetPerms(roleIds []string) []string {
var (
perms []string
result gdb.Result
)
m := cool.DBM(s.Model).As("a")
// 如果roldIds 包含 1 则表示是超级管理员,则返回所有权限
if garray.NewIntArrayFrom(gconv.Ints(roleIds)).Contains(1) {
result, _ = m.Fields("a.perms").All()
} else {
result, _ = m.InnerJoin("base_sys_role_menu b", "a.id=b.menuId").InnerJoin("base_sys_role c", "b.roleId=c.id").Where("c.id IN (?)", roleIds).Fields("a.perms").All()
}
for _, v := range result {
vmap := v.Map()
if vmap["perms"] != nil {
p := gstr.Split(vmap["perms"].(string), ",")
perms = append(perms, p...)
}
}
return perms
}
// GetMenus 获取菜单
func (s *BaseSysMenuService) GetMenus(roleIds []string, isAdmin bool) (result gdb.Result) {
// 屏蔽 base_sys_role_menu.id 防止部分权限的用户登录时菜单渲染错误
m := cool.DBM(s.Model).As("a").Fields("a.*")
if isAdmin {
result, _ = m.Group("a.id").Order("a.orderNum asc").All()
} else {
result, _ = m.InnerJoin("base_sys_role_menu b", "a.id=b.menuId").Where("b.roleId IN (?)", roleIds).Group("a.id").Order("a.orderNum asc").All()
}
return
}
// ModifyAfter 修改后
func (s *BaseSysMenuService) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error) {
if method == "Delete" {
ids := gconv.Ints(param["ids"])
if len(ids) > 0 {
_, err = cool.DBM(s.Model).Where("parentId IN (?)", ids).Delete()
}
return
}
return
}
// ServiceAdd 添加
func (s *BaseSysMenuService) ServiceAdd(ctx context.Context, req *cool.AddReq) (data interface{}, err error) {
r := g.RequestFromCtx(ctx)
rjson, err := r.GetJson()
if err != nil {
return
}
// g.DumpWithType(rjson)
m := cool.DBM(s.Model)
lastInsertId, err := m.Data(rjson).InsertAndGetId()
if err != nil {
return
}
data = g.Map{"id": lastInsertId}
return
}
// NewBaseSysMenuService 创建一个BaseSysMenuService实例
func NewBaseSysMenuService() *BaseSysMenuService {
return &BaseSysMenuService{
&cool.Service{
Model: model.NewBaseSysMenu(),
},
}
}

View File

@@ -0,0 +1,90 @@
package service
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gstr"
)
type BaseSysParamService struct {
*cool.Service
}
func NewBaseSysParamService() *BaseSysParamService {
return &BaseSysParamService{
&cool.Service{
Model: model.NewBaseSysParam(),
},
// Service: cool.NewService(model.NewBaseSysParam()),
}
}
// HtmlByKey 根据配置参数key获取网页内容(富文本)
func (s *BaseSysParamService) HtmlByKey(key string) string {
var (
html = "<html><body>@content</body></html>"
)
m := cool.DBM(s.Model)
record, err := m.Where("keyName = ?", key).One()
if err != nil {
html = gstr.Replace(html, "@content", err.Error())
return html
}
if record.IsEmpty() {
html = gstr.Replace(html, "@content", "keyName notfound")
return html
}
html = gstr.Replace(html, "@content", record["data"].String())
return html
}
// ModifyAfter 修改后
func (s *BaseSysParamService) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error) {
var (
m = cool.DBM(s.Model)
)
result, err := m.All()
if err != nil {
return
}
for _, v := range result {
key := "param:" + v["keyName"].String()
value := v["data"].String()
err = cool.CacheManager.Set(ctx, key, value, 0)
if err != nil {
return
}
}
return
}
// DataByKey 根据配置参数key获取数据
func (s *BaseSysParamService) DataByKey(ctx context.Context, key string) (data string, err error) {
var (
m = cool.DBM(s.Model)
)
rKey := "param:" + key
dataCache, err := cool.CacheManager.Get(ctx, rKey)
if err != nil {
return
}
if !dataCache.IsEmpty() {
data = dataCache.String()
return
}
record, err := m.Where("keyName = ?", key).One()
if err != nil {
return
}
if record.IsEmpty() {
return
}
data = record["data"].String()
err = cool.CacheManager.Set(ctx, rKey, data, 0)
return
}

View File

@@ -0,0 +1,53 @@
package service
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/util/gconv"
)
type BaseSysPermsService struct {
}
func NewBaseSysPermsService() *BaseSysPermsService {
return &BaseSysPermsService{}
}
// permmenu 方法
func (c *BaseSysPermsService) Permmenu(ctx context.Context, roleIds []string) (res interface{}) {
type permmenu struct {
Perms []string `json:"perms"`
Menus gdb.Result `json:"menus"`
}
var (
baseSysMenuService = NewBaseSysMenuService()
admin = cool.GetAdmin(ctx)
)
res = &permmenu{
Perms: baseSysMenuService.GetPerms(roleIds),
Menus: baseSysMenuService.GetMenus(admin.RoleIds, admin.UserId == 1),
}
return
}
// refreshPerms(userId)
func (c *BaseSysPermsService) RefreshPerms(ctx context.Context, userId uint) (err error) {
var (
baseSysUserRoleService = NewBaseSysRoleService()
baseSysMenuService = NewBaseSysMenuService()
baseSysDepartmentService = NewBaseSysDepartmentService()
roleIds = baseSysUserRoleService.GetByUser(userId)
perms = baseSysMenuService.GetPerms(roleIds)
)
cool.CacheManager.Set(ctx, "admin:perms:"+gconv.String(userId), perms, 0)
// 更新部门权限
departments := baseSysDepartmentService.GetByRoleIds(roleIds, userId == 1)
cool.CacheManager.Set(ctx, "admin:department:"+gconv.String(userId), departments, 0)
return
}

View File

@@ -0,0 +1,174 @@
package service
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
var baseSysUserRole = model.NewBaseSysUserRole()
type BaseSysRoleService struct {
*cool.Service
}
// ModifyAfter modify after
func (s *BaseSysRoleService) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error) {
if param["id"] != nil {
err = s.updatePerms(ctx, gconv.Uint(param["id"]), gconv.SliceUint(param["menuIdList"]), gconv.SliceUint(param["departmentIdList"]))
}
return
}
// updatePerms(roleId, menuIdList?, departmentIds = [])
func (s *BaseSysRoleService) updatePerms(ctx context.Context, roleId uint, menuIdList, departmentIds []uint) (err error) {
// 更新菜单权限
cool.DBM(model.NewBaseSysRoleMenu()).Where("roleId = ?", roleId).Delete()
if len(menuIdList) > 0 {
roleMenuList := make([]g.MapStrAny, len(menuIdList))
for i, menuId := range menuIdList {
roleMenuList[i] = g.MapStrAny{
"roleId": roleId,
"menuId": menuId,
}
}
cool.DBM(model.NewBaseSysRoleMenu()).Data(roleMenuList).Insert()
}
// 更新部门权限
cool.DBM(model.NewBaseSysRoleDepartment()).Where("roleId = ?", roleId).Delete()
if len(departmentIds) > 0 {
roleDepartmentList := make([]g.MapStrAny, len(departmentIds))
for i, departmentId := range departmentIds {
roleDepartmentList[i] = g.MapStrAny{
"roleId": roleId,
"departmentId": departmentId,
}
}
cool.DBM(model.NewBaseSysRoleDepartment()).Data(roleDepartmentList).Insert()
}
// 刷新权限
userRoles, err := cool.DBM(model.NewBaseSysUserRole()).Where("roleId = ?", roleId).All()
if err != nil {
return
}
baseSysPermsService := NewBaseSysPermsService()
for _, v := range userRoles {
vmap := v.Map()
if vmap["userId"] != nil {
baseSysPermsService.RefreshPerms(ctx, gconv.Uint(vmap["userId"]))
}
}
return
}
// GetByUser get array roleId by userId
func (s *BaseSysRoleService) GetByUser(userId uint) []string {
var (
roles []string
)
res, _ := cool.DBM(baseSysUserRole).Where("userId = ?", userId).Array("roleId")
for _, v := range res {
roles = append(roles, gconv.String(v))
}
return roles
}
// BaseSysRoleService Info 方法重构
func (s *BaseSysRoleService) ServiceInfo(ctx context.Context, req *cool.InfoReq) (data interface{}, err error) {
info, err := cool.DBM(s.Model).Where("id = ?", req.Id).One()
if err != nil {
return nil, err
}
if !info.IsEmpty() {
var menus gdb.Result
if req.Id == 1 {
menus, err = cool.DBM(model.NewBaseSysMenu()).All()
if err != nil {
return nil, err
}
} else {
menus, err = cool.DBM(model.NewBaseSysRoleMenu()).Where("roleId = ?", req.Id).All()
if err != nil {
return nil, err
}
}
menuIdList := garray.NewIntArray()
for _, v := range menus {
menuIdList.Append(gconv.Int(v["menuId"]))
}
var departments gdb.Result
if req.Id == 1 {
departments, err = cool.DBM(model.NewBaseSysRoleDepartment()).All()
if err != nil {
return nil, err
}
} else {
departments, err = cool.DBM(model.NewBaseSysRoleDepartment()).Where("roleId = ?", req.Id).All()
if err != nil {
return nil, err
}
}
departmentIdList := garray.NewIntArray()
for _, v := range departments {
departmentIdList.Append(gconv.Int(v["departmentId"]))
}
result := gconv.Map(info)
result["menuIdList"] = menuIdList.Slice()
result["departmentIdList"] = departmentIdList.Slice()
data = result
return
}
data = g.Map{}
return
}
// NewBaseSysRoleService create a new BaseSysRoleService
func NewBaseSysRoleService() *BaseSysRoleService {
return &BaseSysRoleService{
Service: &cool.Service{
Model: model.NewBaseSysRole(),
ListQueryOp: &cool.QueryOp{
Where: func(ctx context.Context) [][]interface{} {
var (
admin = cool.GetAdmin(ctx)
userId = admin.UserId
roleIds = garray.NewIntArrayFromCopy(gconv.Ints(admin.RoleIds))
)
return [][]interface{}{
{"label != ?", g.Slice{"admin"}, true},
{"(userId=? or id in (?))", g.Slice{userId, admin.RoleIds}, !roleIds.Contains(1)},
}
},
},
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"name", "label"},
AddOrderby: map[string]string{},
Where: func(ctx context.Context) [][]interface{} {
var (
admin = cool.GetAdmin(ctx)
userId = admin.UserId
roleIds = garray.NewIntArrayFromCopy(gconv.Ints(admin.RoleIds))
)
return [][]interface{}{
{"label != ?", g.Slice{"admin"}, true},
{"(userId=? or id in (?))", g.Slice{userId, admin.RoleIds}, !roleIds.Contains(1)},
}
},
},
InsertParam: func(ctx context.Context) map[string]interface{} {
return g.Map{"userId": cool.GetAdmin(ctx).UserId}
},
UniqueKey: map[string]string{
"name": "角色名称不能重复",
"label": "角色标识不能重复",
},
},
}
}

View File

@@ -0,0 +1,238 @@
package service
import (
"context"
"fmt"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/base/model"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/crypto/gmd5"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type BaseSysUserService struct {
*cool.Service
}
// Person 方法 返回不带密码的用户信息
func (s *BaseSysUserService) Person(userId uint) (res gdb.Record, err error) {
m := cool.DBM(s.Model)
res, err = m.Where("id = ?", userId).FieldsEx("password").One()
return
}
func (s *BaseSysUserService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
if method == "Delete" {
// 禁止删除超级管理员
userIds := garray.NewIntArrayFrom(gconv.Ints(param["ids"]))
currentId, found := userIds.Get(0)
superAdminId := 1
if userIds.Len() == 1 && found && currentId == superAdminId {
err = gerror.New("超级管理员不能删除")
return
}
// 删除超级管理员
userIds.RemoveValue(1)
g.RequestFromCtx(ctx).SetParam("ids", userIds.Slice())
}
return
}
func (s *BaseSysUserService) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error) {
if method == "Delete" {
userIds := garray.NewIntArrayFrom(gconv.Ints(param["ids"]))
userIds.RemoveValue(1)
// 删除用户时删除相关数据
cool.DBM(model.NewBaseSysUserRole()).WhereIn("userId", userIds.Slice()).Delete()
}
return
}
// ServiceAdd 方法 添加用户
func (s *BaseSysUserService) ServiceAdd(ctx context.Context, req *cool.AddReq) (data interface{}, err error) {
var (
m = cool.DBM(s.Model)
r = g.RequestFromCtx(ctx)
reqmap = r.GetMap()
)
// 如果reqmap["password"]不为空则对密码进行md5加密
if !r.Get("password").IsNil() {
reqmap["password"] = gmd5.MustEncryptString(r.Get("password").String())
}
lastInsertId, err := m.Data(reqmap).InsertAndGetId()
if err != nil {
return
}
data = g.Map{"id": lastInsertId}
return
}
// ServiceInfo 方法 返回服务信息
func (s *BaseSysUserService) ServiceInfo(ctx g.Ctx, req *cool.InfoReq) (data interface{}, err error) {
result, err := s.Service.ServiceInfo(ctx, req)
if err != nil {
return nil, err
}
if result.(gdb.Record).IsEmpty() {
return nil, nil
}
// g.DumpWithType(result)
resultMap := result.(gdb.Record).Map()
// 获取角色
roleIds, err := cool.DBM(model.NewBaseSysUserRole()).Where("userId = ?", resultMap["id"]).Fields("roleId").Array()
if err != nil {
return nil, err
}
resultMap["roleIdList"] = roleIds
data = resultMap
return
}
// ServiceUpdate 方法 更新用户信息
func (s *BaseSysUserService) ServiceUpdate(ctx context.Context, req *cool.UpdateReq) (data interface{}, err error) {
var (
admin = cool.GetAdmin(ctx)
m = cool.DBM(s.Model)
)
r := g.RequestFromCtx(ctx)
rMap := r.GetMap()
// 如果不传入ID代表更新当前用户
userId := r.Get("id", admin.UserId).Uint()
userInfo, err := m.Where("id = ?", userId).One()
if err != nil {
return
}
if userInfo.IsEmpty() {
err = gerror.New("用户不存在")
return
}
// 禁止禁用超级管理员
if userId == 1 && (!r.Get("status").IsNil() && r.Get("status").Int() == 0) {
err = gerror.New("禁止禁用超级管理员")
return
}
// 如果请求的password不为空并且密码加密后的值有变动说明要修改密码
var rPassword = r.Get("password", "").String()
if rPassword != "" && rPassword != userInfo["password"].String() {
rMap["password"], _ = gmd5.Encrypt(rPassword)
rMap["passwordV"] = userInfo["passwordV"].Int() + 1
cool.CacheManager.Set(ctx, fmt.Sprintf("admin:passwordVersion:%d", userId), rMap["passwordV"], 0)
} else {
delete(rMap, "password")
}
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
roleModel := cool.DBM(model.NewBaseSysUserRole()).TX(tx).Where("userId = ?", userId)
roleIds, err := roleModel.Fields("roleId").Array()
if err != nil {
return
}
// 如果请求参数中不包含roleIdList说明不修改角色信息
if !r.Get("roleIdList").IsNil() {
inRoleIdSet := gset.NewFrom(r.Get("roleIdList").Ints())
roleIdsSet := gset.NewFrom(gconv.Ints(roleIds))
// 如果请求的角色信息未发生变化则跳过更新逻辑
if roleIdsSet.Diff(inRoleIdSet).Size() != 0 || inRoleIdSet.Diff(roleIdsSet).Size() != 0 {
roleArray := garray.NewArray()
inRoleIdSet.Iterator(func(v interface{}) bool {
roleArray.PushRight(g.Map{
"userId": gconv.Uint(userId),
"roleId": gconv.Uint(v),
})
return true
})
_, err = roleModel.Delete()
if err != nil {
return err
}
_, err = roleModel.Fields("userId,roleId").Insert(roleArray)
if err != nil {
return err
}
}
}
_, err = m.TX(tx).Update(rMap)
if err != nil {
return err
}
return
})
return
}
// Move 移动用户部门
func (s *BaseSysUserService) Move(ctx g.Ctx) (err error) {
request := g.RequestFromCtx(ctx)
departmentId := request.Get("departmentId").Int()
userIds := request.Get("userIds").Slice()
_, err = cool.DBM(s.Model).Where("`id` IN(?)", userIds).Data(g.Map{"departmentId": departmentId}).Update()
return
}
// NewBaseSysUserService 创建一个新的BaseSysUserService实例
func NewBaseSysUserService() *BaseSysUserService {
return &BaseSysUserService{
Service: &cool.Service{
Model: model.NewBaseSysUser(),
InfoIgnoreProperty: "password",
UniqueKey: map[string]string{
"username": "用户名不能重复",
},
PageQueryOp: &cool.QueryOp{
Select: "base_sys_user.*,dept.`name` as departmentName,GROUP_CONCAT( role.`name` ) AS `roleName`",
Join: []*cool.JoinOp{
{
Model: model.NewBaseSysDepartment(),
Alias: "dept",
Type: "LeftJoin",
Condition: "`base_sys_user`.`departmentId` = `dept`.`id`",
},
{
Model: model.NewBaseSysUserRole(),
Alias: "user_role",
Type: "LeftJoin",
Condition: "`base_sys_user`.`id` = `user_role`.`userId`",
},
{
Model: model.NewBaseSysRole(),
Alias: "`role`",
Type: "LeftJoin",
Condition: "`role`.`id` = `user_role`.`roleId`",
},
},
Where: func(ctx context.Context) []g.Array {
r := g.RequestFromCtx(ctx).GetMap()
return []g.Array{
{"(departmentId IN (?))", gconv.SliceStr(r["departmentIds"])},
}
},
Extend: func(ctx g.Ctx, m *gdb.Model) *gdb.Model {
return m.Group("`base_sys_user`.`id`")
},
KeyWordField: []string{"name", "username", "nickName"},
},
},
}
}

View File

View File

@@ -0,0 +1 @@
package utils

View File

@@ -0,0 +1,44 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/demo/service"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g"
)
type DemoSampleController struct {
*cool.Controller
}
func init() {
var demo_sample_controller = &DemoSampleController{
&cool.Controller{
Prefix: "/admin/demo/demo_sample",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewDemoSampleService(),
},
}
// 注册路由
cool.RegisterController(demo_sample_controller)
}
// 增加 Welcome 演示 方法
type DemoSampleWelcomeReq struct {
g.Meta `path:"/welcome" method:"GET"`
}
type DemoSampleWelcomeRes struct {
*cool.BaseRes
Data interface{} `json:"data"`
}
func (c *DemoSampleController) Welcome(ctx context.Context, req *DemoSampleWelcomeReq) (res *DemoSampleWelcomeRes, err error) {
res = &DemoSampleWelcomeRes{
BaseRes: cool.Ok("Welcome to Cool Admin Go"),
Data: gjson.New(`{"name": "Cool Admin Go", "age":0}`),
}
return
}

View File

@@ -0,0 +1,5 @@
package controller
import (
_ "github.com/cool-team-official/cool-admin-go/modules/demo/controller/admin"
)

7
modules/demo/demo.go Normal file
View File

@@ -0,0 +1,7 @@
package demo
import (
_ "github.com/cool-team-official/cool-admin-go/modules/demo/controller"
_ "github.com/cool-team-official/cool-admin-go/modules/demo/model"
_ "github.com/cool-team-official/cool-admin-go/modules/demo/service"
)

39
modules/demo/go.mod Normal file
View File

@@ -0,0 +1,39 @@
module github.com/cool-team-official/cool-admin-go/modules/demo
go 1.18
require (
github.com/cool-team-official/cool-admin-go/cool v1.5.9
github.com/gogf/gf/v2 v2.6.3
)
require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.25.7 // indirect
)

79
modules/demo/go.sum Normal file
View File

@@ -0,0 +1,79 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/cool-team-official/cool-admin-go/cool v1.5.9 h1:mvZkckumdnhkr8BGRbB+FKmUeP3tbxmyvSxfNyZAlhE=
github.com/cool-team-official/cool-admin-go/cool v1.5.9/go.mod h1:kle9oSJM+yl8ZtQwZFL8PWbz7ByI8Glj1431njGbWPo=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=

View File

@@ -0,0 +1,35 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameDemoGoods = "demo_goods"
// DemoGoods mapped from table <demo_goods>
type DemoGoods struct {
*cool.Model
Name string `gorm:"not null" json:"name"`
}
// TableName DemoGoods's table name
func (*DemoGoods) TableName() string {
return TableNameDemoGoods
}
// GroupName DemoGoods's table group
func (*DemoGoods) GroupName() string {
return "default"
}
// NewDemoGoods create a new DemoGoods
func NewDemoGoods() *DemoGoods {
return &DemoGoods{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&DemoGoods{})
}

View File

@@ -0,0 +1,35 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameDemoSample = "demo_sample"
// DemoSample mapped from table <demo_sample>
type DemoSample struct {
*cool.Model
// Name string `gorm:"column:name;not null;comment:名称" json:"name"`
}
// TableName DemoSample's table name
func (*DemoSample) TableName() string {
return TableNameDemoSample
}
// GroupName DemoSample's table group
func (*DemoSample) GroupName() string {
return "default"
}
// NewDemoSample create a new DemoSample
func NewDemoSample() *DemoSample {
return &DemoSample{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&DemoSample{})
}

View File

@@ -0,0 +1,22 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/demo/model"
)
type DemoGoodsService struct {
*cool.Service
}
func NewDemoGoodsService() *DemoGoodsService {
return &DemoGoodsService{
&cool.Service{
Model: model.NewDemoGoods(),
ListQueryOp: &cool.QueryOp{
Join: []*cool.JoinOp{},
},
},
}
}

View File

@@ -0,0 +1,18 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/demo/model"
)
type DemoSampleService struct {
*cool.Service
}
func NewDemoSampleService() *DemoSampleService {
return &DemoSampleService{
&cool.Service{
Model: model.NewDemoSample(),
},
}
}

View File

@@ -0,0 +1,21 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
type DemoTestService struct {
*cool.Service
}
func NewDemoTestService() *DemoTestService {
return &DemoTestService{
&cool.Service{},
}
}
func (s *DemoTestService) GetDemoTestList() (interface{}, error) {
// gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
return nil, nil
}

11
modules/dict/README.MD Normal file
View File

@@ -0,0 +1,11 @@
# dict
字典模块
## 资源打包命令
```bash
gf pack modules/dict/resource modules/dict/packed/packed.go -p modules/dict/resource
```

View File

@@ -0,0 +1,40 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/service"
"github.com/gogf/gf/v2/frame/g"
)
type DictInfoController struct {
*cool.Controller
}
func init() {
var dict_info_controller = &DictInfoController{
&cool.Controller{
Prefix: "/admin/dict/info",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewDictInfoService(),
},
}
// 注册路由
cool.RegisterController(dict_info_controller)
}
// Data 方法请求
type DictInfoDataReq struct {
g.Meta `path:"/data" method:"POST"`
Types []string `json:"types"`
}
// Data 方法 获得字典数据
func (c *DictInfoController) Data(ctx context.Context, req *DictInfoDataReq) (res *cool.BaseRes, err error) {
service := service.NewDictInfoService()
data, err := service.Data(ctx, req.Types)
res = cool.Ok(data)
return
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/service"
)
type DictTypeController struct {
*cool.Controller
}
func init() {
var dict_type_controller = &DictTypeController{
&cool.Controller{
Prefix: "/admin/dict/type",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewDictTypeService(),
},
}
// 注册路由
cool.RegisterController(dict_type_controller)
}

View File

@@ -0,0 +1,5 @@
package controller
import (
_ "github.com/cool-team-official/cool-admin-go/modules/dict/controller/admin"
)

21
modules/dict/dict.go Normal file
View File

@@ -0,0 +1,21 @@
package dict
import (
"github.com/cool-team-official/cool-admin-go/cool"
_ "github.com/cool-team-official/cool-admin-go/modules/dict/packed"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
_ "github.com/cool-team-official/cool-admin-go/modules/dict/controller"
"github.com/cool-team-official/cool-admin-go/modules/dict/model"
)
func init() {
var (
ctx = gctx.GetInitCtx()
)
g.Log().Debug(ctx, "module dict init start ...")
cool.FillInitData(ctx, "dict", &model.DictInfo{})
cool.FillInitData(ctx, "dict", &model.DictType{})
g.Log().Debug(ctx, "module dict init finished ...")
}

39
modules/dict/go.mod Normal file
View File

@@ -0,0 +1,39 @@
module github.com/cool-team-official/cool-admin-go/modules/dict
go 1.18
require (
github.com/cool-team-official/cool-admin-go/cool v1.5.9
github.com/gogf/gf/v2 v2.6.3
)
require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.25.7 // indirect
)

79
modules/dict/go.sum Normal file
View File

@@ -0,0 +1,79 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/cool-team-official/cool-admin-go/cool v1.5.9 h1:mvZkckumdnhkr8BGRbB+FKmUeP3tbxmyvSxfNyZAlhE=
github.com/cool-team-official/cool-admin-go/cool v1.5.9/go.mod h1:kle9oSJM+yl8ZtQwZFL8PWbz7ByI8Glj1431njGbWPo=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=

View File

@@ -0,0 +1,39 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameDictInfo = "dict_info"
// DictInfo mapped from table <dict_info>
type DictInfo struct {
*cool.Model
TypeID int32 `gorm:"column:typeId;type:int;not null" json:"typeId"` // 类型ID
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
OrderNum int32 `gorm:"column:orderNum;type:int;not null" json:"orderNum"` // 排序
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID
}
// TableName DictInfo's table name
func (*DictInfo) TableName() string {
return TableNameDictInfo
}
// GroupName DictInfo's table group
func (*DictInfo) GroupName() string {
return "default"
}
// NewDictInfo create a new DictInfo
func NewDictInfo() *DictInfo {
return &DictInfo{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&DictInfo{})
}

View File

@@ -0,0 +1,36 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameDictType = "dict_type"
// DictType mapped from table <dict_type>
type DictType struct {
*cool.Model
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
Key string `gorm:"column:key;type:varchar(255);not null" json:"key"` // 标识
}
// TableName DictType's table name
func (*DictType) TableName() string {
return TableNameDictType
}
// GroupName DictType's table group
func (*DictType) GroupName() string {
return "default"
}
// NewDictType create a new DictType
func NewDictType() *DictType {
return &DictType{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&DictType{})
}

View File

@@ -0,0 +1,9 @@
package packed
import "github.com/gogf/gf/v2/os/gres"
func init() {
if err := gres.Add("H4sIAAAAAAAC/wrwZmYRYeBgYGBgjRYNZUACcgycDLn5KaU5qcX6KZnJJfpFqcX5pUXJqfqZeZklWcX5eaEhrAyMt0WZkgO82TmQtcIM5WD4FYVqqC5BQ8HC8Zl5afl6cDtOijIlr7lk6H3EQOTAx73zH038qfdkr0r52ei5LB/FzAs1zA4/3DrtAp9Sn5/Sjp0dCs9VLH53iryP7ohrXbxNYEWy3H+VPw9k1RmmczI0RDxrYlS/fTjzQ+Tb/mmt4jxNIhdDzi7PYsuQCN4WtYxtatCit7O15N/JLp50btbcfftW/Pn3rj11295fP7f8q9jx9+w553eHE4M52LLcD4pHWgjzpG6O2rpZi3vfmvp7v+epMYRP5utRSvRbduvIoapfiTd+/fz7dR172+MEK7ZnEZkv5/S1Wrppn0ziyflccZn/8uMENSa3E2l6EzWE3I6YTF5RnXil9e7+nHX3/9WL5vL0SASvnNrd/vcle2J199GDP1x9/PYxMTD8/w8K7Bds/55wMjIw2LIgBzZ6DBIb2CWVBal6KBHa9SwoYMWzoICAgIBTPoGbggyuNBZM6g4S9g5yNioOnrpGZEoPT09PCe+ZUt4zIjy+a3h01/jwfNU5o8vLwzNlwStv7iCPoPnTOQJ/1jx+t1x2deKimyunKhycdKopRFWPtTVK1uS6pOBDK2Vn7eRk2+JibqXYdl/bM6X+6uZ27984FscGBSbFcd2ojNnYwADz8YJNgQ19DAwM9owwH4MAF5qPxXD6GOy1p+C0Ckvw6JpFcWlG0os9nWOaxYNmFhlGsCOMwKObkUmEGXf+hQABhreOIJro3AwzFJJ/kRObLtxQBoYljaEEDcWVm5HtADkcOXpR7TjEyEBmIobZgSuhwALnv+MWJgbCyQYR0tgSDsKwj7gMI8osHhSzbJkZcCUj3EawoxjRgDACSTcrG0QlO4M5EwPDPmYQDxAAAP//BVSc8gsGAAA="); err != nil {
panic("add binary content to resource manager failed: " + err.Error())
}
}

View File

@@ -0,0 +1,52 @@
[
{
"id": 1,
"createTime": "2022-07-06 14:18:53.841000",
"updateTime": "2022-07-06 14:19:10.954000",
"typeId": 1,
"name": "衣服",
"orderNum": 2,
"remark": null,
"parentId": null
},
{
"id": 2,
"createTime": "2022-07-06 14:18:59.834000",
"updateTime": "2022-07-06 14:18:59.834000",
"typeId": 1,
"name": "裤子",
"orderNum": 1,
"remark": null,
"parentId": null
},
{
"id": 3,
"createTime": "2022-07-06 14:19:03.993000",
"updateTime": "2022-07-06 14:19:15.251000",
"typeId": 1,
"name": "鞋子",
"orderNum": 3,
"remark": null,
"parentId": null
},
{
"id": 4,
"createTime": "2022-07-06 14:21:47.122000",
"updateTime": "2022-07-06 14:22:26.131000",
"typeId": 2,
"name": "闪酷",
"orderNum": 2,
"remark": null,
"parentId": null
},
{
"id": 5,
"createTime": "2022-07-06 14:22:18.309000",
"updateTime": "2022-07-06 14:22:18.309000",
"typeId": 2,
"name": "COOL",
"orderNum": 1,
"remark": null,
"parentId": null
}
]

View File

@@ -0,0 +1,16 @@
[
{
"id": 1,
"createTime": "2022-07-06 14:18:41.879000",
"updateTime": "2022-07-06 14:18:41.879000",
"name": "类别",
"key": "type"
},
{
"id": 2,
"createTime": "2022-07-06 14:21:33.778000",
"updateTime": "2022-07-06 14:21:33.778000",
"name": "品牌",
"key": "brand"
}
]

View File

@@ -0,0 +1,98 @@
package service
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type DictInfoService struct {
*cool.Service
}
// Data方法, 用于获取数据
func (s *DictInfoService) Data(ctx context.Context, types []string) (data interface{}, err error) {
var (
dictInfoModel = model.NewDictInfo()
dictTypeModel = model.NewDictType()
)
mType := cool.DBM(dictTypeModel)
// 如果types不为空, 则查询指定类型的数据
if len(types) > 0 {
mType = mType.Where("type in (?)", types)
}
// 查询所有类型
typeData, err := mType.All()
// 如果typeData为空, 则返回空
if typeData.IsEmpty() {
return g.Map{}, nil
}
data = g.Map{}
for _, v := range typeData {
m := cool.DBM(dictInfoModel)
result, err := m.Where("typeId=?", v["id"]).Fields("id", "name", "parentId", "typeId").Order("orderNum asc").All()
if err != nil {
return nil, err
}
if result.IsEmpty() {
continue
}
data.(g.Map)[v["key"].String()] = result
}
return
}
// ModifyAfter 修改后
func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) {
if method == "Delete" {
// 删除后,同时删除子节点
ids, ok := param["ids"]
if !ok {
return
}
for _, v := range ids.([]interface{}) {
err = delChildDict(gconv.Int64(v))
if err != nil {
return
}
}
}
return
}
// delChildDict 删除子字典
func delChildDict(id int64) error {
var (
dictInfoModel = model.NewDictInfo()
)
m := cool.DBM(dictInfoModel)
result, err := m.Where("parentId=?", id).Fields("id").All()
if err != nil {
return err
}
if result.IsEmpty() {
return nil
}
for _, v := range result {
delChildDict(v["id"].Int64())
}
_, err = m.Where("parentId=?", id).Delete()
return err
}
// NewDictInfoService 初始化 DictInfoService
func NewDictInfoService() *DictInfoService {
return &DictInfoService{
&cool.Service{
Model: model.NewDictInfo(),
ListQueryOp: &cool.QueryOp{
FieldEQ: []string{"typeId"},
KeyWordField: []string{"name"},
AddOrderby: g.MapStrStr{"createTime": "ASC"},
},
},
}
}

View File

@@ -0,0 +1,21 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/model"
)
type DictTypeService struct {
*cool.Service
}
func NewDictTypeService() *DictTypeService {
return &DictTypeService{
Service: &cool.Service{
Model: model.NewDictType(),
ListQueryOp: &cool.QueryOp{
KeyWordField: []string{"name"},
},
},
}
}

9
modules/modules.go Normal file
View File

@@ -0,0 +1,9 @@
package modules
import (
_ "github.com/cool-team-official/cool-admin-go/modules/base"
_ "github.com/cool-team-official/cool-admin-go/modules/demo"
_ "github.com/cool-team-official/cool-admin-go/modules/dict"
_ "github.com/cool-team-official/cool-admin-go/modules/space"
_ "github.com/cool-team-official/cool-admin-go/modules/task"
)

3
modules/space/README.md Normal file
View File

@@ -0,0 +1,3 @@
# Space 文件空间
提供上传图片的管理功能,注意在空间删除文件时仅删除了文件在数据库的索引.未删除实际文件.

View File

@@ -0,0 +1,22 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/space/service"
)
type SpaceInfoController struct {
*cool.Controller
}
func init() {
var space_info_controller = &SpaceInfoController{
&cool.Controller{
Prefix: "/admin/space/info",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewSpaceInfoService(),
},
}
// 注册路由
cool.RegisterController(space_info_controller)
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/space/service"
)
type SpaceTypeController struct {
*cool.Controller
}
func init() {
var space_type_controller = &SpaceTypeController{
&cool.Controller{
Prefix: "/admin/space/type",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewSpaceTypeService(),
},
}
// 注册路由
cool.RegisterController(space_type_controller)
}

View File

@@ -0,0 +1,6 @@
package controller
import (
_ "github.com/cool-team-official/cool-admin-go/modules/space/controller/admin"
_ "github.com/cool-team-official/cool-admin-go/modules/space/service"
)

39
modules/space/go.mod Normal file
View File

@@ -0,0 +1,39 @@
module github.com/cool-team-official/cool-admin-go/modules/space
go 1.18
require (
github.com/cool-team-official/cool-admin-go/cool v1.5.9
github.com/gogf/gf/v2 v2.6.3
)
require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.25.7 // indirect
)

79
modules/space/go.sum Normal file
View File

@@ -0,0 +1,79 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/cool-team-official/cool-admin-go/cool v1.5.9 h1:mvZkckumdnhkr8BGRbB+FKmUeP3tbxmyvSxfNyZAlhE=
github.com/cool-team-official/cool-admin-go/cool v1.5.9/go.mod h1:kle9oSJM+yl8ZtQwZFL8PWbz7ByI8Glj1431njGbWPo=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=

View File

@@ -0,0 +1 @@
package middleware

View File

@@ -0,0 +1 @@
package model

View File

@@ -0,0 +1,37 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameSpaceInfo = "space_info"
// SpaceInfo mapped from table <space_info>
type SpaceInfo struct {
*cool.Model
URL string `gorm:"column:url;type:varchar(255);not null;comment:地址" json:"url"` // 地址
Type string `gorm:"column:type;type:varchar(255);not null;comment:类型" json:"type"` // 类型
ClassifyID *int64 `gorm:"column:classifyId;type:bigint;comment:分类ID" json:"classifyId"` // 分类ID
}
// TableName SpaceInfo's table name
func (*SpaceInfo) TableName() string {
return TableNameSpaceInfo
}
// GroupName SpaceInfo's table group
func (*SpaceInfo) GroupName() string {
return "default"
}
// NewSpaceInfo create a new SpaceInfo
func NewSpaceInfo() *SpaceInfo {
return &SpaceInfo{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&SpaceInfo{})
}

View File

@@ -0,0 +1,36 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameSpaceType = "space_type"
// SpaceType mapped from table <space_type>
type SpaceType struct {
*cool.Model
Name string `gorm:"column:name;type:varchar(255);not null;comment:类别名称 " json:"name"` // 类别名称
ParentID *int32 `gorm:"column:parentId;comment:父分类ID" json:"parentId"` // 父分类ID
}
// TableName SpaceType's table name
func (*SpaceType) TableName() string {
return TableNameSpaceType
}
// GroupName SpaceType's table group
func (*SpaceType) GroupName() string {
return "default"
}
// NewSpaceType create a new SpaceType
func NewSpaceType() *SpaceType {
return &SpaceType{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&SpaceType{})
}

View File

@@ -0,0 +1,5 @@
package service
import (
_ "github.com/cool-team-official/cool-admin-go/modules/space/model"
)

View File

@@ -0,0 +1,20 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/space/model"
)
type SpaceInfoService struct {
*cool.Service
}
func NewSpaceInfoService() *SpaceInfoService {
return &SpaceInfoService{
&cool.Service{
Model: model.NewSpaceInfo(),
},
// Service: cool.NewService(model.NewSpaceInfo()),
}
}

View File

@@ -0,0 +1,20 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/space/model"
)
type SpaceTypeService struct {
*cool.Service
}
func NewSpaceTypeService() *SpaceTypeService {
return &SpaceTypeService{
&cool.Service{
Model: model.NewSpaceType(),
},
// Service: cool.NewService(model.NewSpaceType()),
}
}

16
modules/space/space.go Normal file
View File

@@ -0,0 +1,16 @@
package demo
import (
_ "github.com/cool-team-official/cool-admin-go/modules/space/controller"
_ "github.com/cool-team-official/cool-admin-go/modules/space/middleware"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func init() {
var (
ctx = gctx.GetInitCtx()
)
g.Log().Debug(ctx, "module space init start ...")
g.Log().Debug(ctx, "module space init finished ...")
}

9
modules/task/README.md Normal file
View File

@@ -0,0 +1,9 @@
# task
任务管理模块,提供基于`coolfun`c 的任务管理功能
## 资源打包命令
```bash
gf pack modules/task/resource modules/task/packed/packed.go -p modules/task/resource
```

View File

@@ -0,0 +1 @@
package admin

View File

@@ -0,0 +1,94 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/task/service"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/util/gconv"
)
type TaskInfoController struct {
*cool.Controller
}
func init() {
var task_info_controller = &TaskInfoController{
&cool.Controller{
Prefix: "/admin/task/info",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page", "Start", "Stop"},
Service: service.NewTaskInfoService(),
},
}
// 注册路由
cool.RegisterController(task_info_controller)
}
// TaskInfoStopReq 请求参数
type TaskInfoStopReq struct {
g.Meta `path:"/stop" method:"GET"`
ID int64 `json:"id" v:"required#请输入id"`
}
// Stop 停止任务
func (c *TaskInfoController) Stop(ctx g.Ctx, req *TaskInfoStopReq) (res *cool.BaseRes, err error) {
err = cool.ClusterRunFunc(ctx, "TaskStopFunc("+gconv.String(req.ID)+")")
if err != nil {
return cool.Fail(err.Error()), err
}
res = cool.Ok("停止成功")
return
}
// TaskInfoStartReq 请求参数
type TaskInfoStartReq struct {
g.Meta `path:"/start" method:"GET"`
ID int64 `json:"id" v:"required#请输入id"`
}
// Start 启动任务
func (c *TaskInfoController) Start(ctx g.Ctx, req *TaskInfoStartReq) (res *cool.BaseRes, err error) {
err = cool.ClusterRunFunc(ctx, "TaskStartFunc("+gconv.String(req.ID)+")")
if err != nil {
return cool.Fail(err.Error()), err
}
res = cool.Ok("启动成功")
return
}
// TaskInfoOnceReq 请求参数
type TaskInfoOnceReq struct {
g.Meta `path:"/once" method:"POST"`
ID int64 `json:"id" v:"required#请输入id"`
}
// Once 执行一次
func (c *TaskInfoController) Once(ctx g.Ctx, req *TaskInfoOnceReq) (res *cool.BaseRes, err error) {
err = c.Service.(*service.TaskInfoService).Once(ctx, req.ID)
if err != nil {
return cool.Fail(err.Error()), err
}
res = cool.Ok("执行成功")
return
}
// TaskInfoLogReq 请求参数
type TaskInfoLogReq struct {
g.Meta `path:"/log" method:"GET"`
ID int64 `json:"id"`
Status int `json:"status"`
}
// Log 任务日志
func (c *TaskInfoController) Log(ctx g.Ctx, req *TaskInfoLogReq) (res *cool.BaseRes, err error) {
r := ghttp.RequestFromCtx(ctx)
param := r.GetQueryMapStrStr()
data, err := c.Service.(*service.TaskInfoService).Log(ctx, param)
if err != nil {
return cool.Fail(err.Error()), err
}
res = cool.Ok(data)
return
}

View File

@@ -0,0 +1 @@
package app

View File

@@ -0,0 +1,7 @@
package controller
import (
_ "github.com/cool-team-official/cool-admin-go/modules/task/controller/admin"
_ "github.com/cool-team-official/cool-admin-go/modules/task/controller/app"
_ "github.com/cool-team-official/cool-admin-go/modules/task/service"
)

Some files were not shown because too many files have changed in this diff Show More