This commit is contained in:
孟帅
2024-03-07 20:08:56 +08:00
parent 6dd8cbadad
commit 0fbc1ad47c
246 changed files with 9441 additions and 2293 deletions

View File

@@ -1,3 +1,8 @@
// Package admin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package admin
import (

View File

@@ -11,7 +11,10 @@ import (
"github.com/gogf/gf/v2/frame/g"
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/library/dict"
"hotgo/internal/library/hgorm"
"hotgo/internal/model"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/adminin"
"hotgo/internal/model/input/form"
"hotgo/internal/service"
@@ -25,6 +28,7 @@ func NewAdminPost() *sAdminPost {
func init() {
service.RegisterAdminPost(NewAdminPost())
dict.RegisterFunc("adminPostOption", "岗位选项", service.AdminPost().Option)
}
// Delete 删除
@@ -156,6 +160,24 @@ func (s *sAdminPost) List(ctx context.Context, in *adminin.PostListInp) (list []
return
}
// Option 岗位选项
func (s *sAdminPost) Option(ctx context.Context) (opts []*model.Option, err error) {
var list []*entity.AdminPost
if err = dao.AdminPost.Ctx(ctx).OrderAsc(dao.AdminPost.Columns().Sort).Scan(&list); err != nil {
return nil, err
}
if len(list) == 0 {
opts = make([]*model.Option, 0)
return
}
for _, v := range list {
opts = append(opts, dict.GenHashOption(v.Id, v.Name))
}
return
}
// GetMemberByStartName 获取指定用户的第一岗位
func (s *sAdminPost) GetMemberByStartName(ctx context.Context, memberId int64) (name string, err error) {
// 默认取第一岗位

View File

@@ -1,3 +1,8 @@
// Package admin
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package admin
import (
@@ -237,7 +242,7 @@ func (s *sAdminSite) handleLogin(ctx context.Context, mb *entity.AdminMember) (r
}
var dept *entity.AdminDept
if err = g.Model("admin_dept").Ctx(ctx).Fields("id,status").Where("id", mb.DeptId).Scan(&dept); err != nil || dept == nil {
if err = dao.AdminDept.Ctx(ctx).Fields("id,status").Where("id", mb.DeptId).Scan(&dept); err != nil || dept == nil {
err = gerror.Wrap(err, "获取部门信息失败,请稍后重试!")
return
}
@@ -279,7 +284,7 @@ func (s *sAdminSite) handleLogin(ctx context.Context, mb *entity.AdminMember) (r
// BindUserContext 绑定用户上下文
func (s *sAdminSite) BindUserContext(ctx context.Context, claims *model.Identity) (err error) {
var mb *entity.AdminMember
if err = g.Model("admin_member").Ctx(ctx).Where("id", claims.Id).Scan(&mb); err != nil {
if err = dao.AdminMember.Ctx(ctx).Where("id", claims.Id).Scan(&mb); err != nil {
err = gerror.Wrap(err, "获取用户信息失败,请稍后重试!")
return
}
@@ -295,7 +300,7 @@ func (s *sAdminSite) BindUserContext(ctx context.Context, claims *model.Identity
}
var role *entity.AdminRole
if err = g.Model("admin_role").Ctx(ctx).Fields("id,key,status").Where("id", mb.RoleId).Scan(&role); err != nil || role == nil {
if err = dao.AdminRole.Ctx(ctx).Fields("id,key,status").Where("id", mb.RoleId).Scan(&role); err != nil || role == nil {
err = gerror.Wrap(err, "获取角色信息失败,请稍后重试!")
return
}
@@ -306,7 +311,7 @@ func (s *sAdminSite) BindUserContext(ctx context.Context, claims *model.Identity
}
var dept *entity.AdminDept
if err = g.Model("admin_dept").Ctx(ctx).Fields("id,status").Where("id", mb.DeptId).Scan(&dept); err != nil || dept == nil {
if err = dao.AdminDept.Ctx(ctx).Fields("id,status").Where("id", mb.DeptId).Scan(&dept); err != nil || dept == nil {
err = gerror.Wrap(err, "获取部门信息失败,请稍后重试!")
return
}

View File

@@ -38,3 +38,25 @@ func (s *sCommonUpload) UploadFile(ctx context.Context, uploadType string, file
}
return
}
// CheckMultipart 检查文件分片
func (s *sCommonUpload) CheckMultipart(ctx context.Context, in *sysin.CheckMultipartInp) (res *sysin.CheckMultipartModel, err error) {
data, err := storager.CheckMultipart(ctx, in.CheckMultipartParams)
if err != nil {
return nil, err
}
res = new(sysin.CheckMultipartModel)
res.CheckMultipartModel = data
return
}
// UploadPart 上传分片
func (s *sCommonUpload) UploadPart(ctx context.Context, in *sysin.UploadPartInp) (res *sysin.UploadPartModel, err error) {
data, err := storager.UploadPart(ctx, in.UploadPartParams)
if err != nil {
return nil, err
}
res = new(sysin.UploadPartModel)
res.UploadPartModel = data
return
}

View File

@@ -21,7 +21,7 @@ func (s *sHook) accessLog(r *ghttp.Request) {
return
}
var ctx = contexts.Detach(r.Context())
var ctx = r.Context()
if contexts.Get(ctx) == nil {
return
}

View File

@@ -1,3 +1,8 @@
// Package hook
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package hook
import (
@@ -65,7 +70,7 @@ func (s *sHook) lastAdminActive(r *ghttp.Request) {
}
var (
ctx = contexts.Detach(r.Context())
ctx = r.Context()
member = contexts.GetUser(ctx)
)

View File

@@ -1,3 +1,8 @@
// Package middleware
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package middleware
import (

View File

@@ -30,10 +30,11 @@ import (
)
type sMiddleware struct {
LoginUrl string // 登录路由地址
DemoWhiteList g.Map // 演示模式放行的路由白名单
FilterRoutes map[string]ghttp.RouterItem // 支持预处理的web路由
routeMutex sync.Mutex
LoginUrl string // 登录路由地址
DemoWhiteList g.Map // 演示模式放行的路由白名单
NotRecordRequest g.Map // 不记录请求数据的路由(当前请求数据过大时会影响响应效率,可以将路径放到该选项中改善)
FilterRoutes map[string]ghttp.RouterItem // 支持预处理的web路由
routeMutex sync.Mutex
}
func init() {
@@ -48,6 +49,10 @@ func NewMiddleware() *sMiddleware {
"/admin/site/mobileLogin": struct{}{}, // 手机号登录
"/admin/genCodes/preview": struct{}{}, // 预览代码
},
NotRecordRequest: g.Map{
"/admin/upload/file": struct{}{}, // 上传文件
"/admin/upload/uploadPart": struct{}{}, // 上传分片
},
}
}
@@ -63,8 +68,11 @@ func (s *sMiddleware) Ctx(r *ghttp.Request) {
r.SetCtx(ctx)
}
data := g.Map{
"request.body": gjson.New(r.GetBodyString()),
data := make(g.Map)
if _, ok := s.NotRecordRequest[r.URL.Path]; ok {
data["request.body"] = gjson.New(nil)
} else {
data["request.body"] = gjson.New(r.GetBodyString())
}
contexts.Init(r, &model.Context{
@@ -75,6 +83,8 @@ func (s *sMiddleware) Ctx(r *ghttp.Request) {
if len(r.Cookie.GetSessionId()) == 0 {
r.Cookie.SetSessionId(gctx.CtxId(r.Context()))
}
r.SetCtx(r.GetNeverDoneCtx())
r.Middleware.Next()
}
@@ -98,7 +108,7 @@ func (s *sMiddleware) CORS(r *ghttp.Request) {
r.Middleware.Next()
}
// DemoLimit 演示系操作限制
// DemoLimit 演示系操作限制
func (s *sMiddleware) DemoLimit(r *ghttp.Request) {
isDemo := g.Cfg().MustGet(r.Context(), "hotgo.isDemo", false)
if !isDemo.Bool() {

View File

@@ -1,3 +1,8 @@
// Package middleware
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package middleware
import (

View File

@@ -1,3 +1,8 @@
// Package middleware
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package middleware
import (

View File

@@ -1,3 +1,8 @@
// Package middleware
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package middleware
import (
@@ -36,9 +41,19 @@ func (s *sMiddleware) GetFilterRoutes(r *ghttp.Request) map[string]ghttp.RouterI
return s.FilterRoutes
}
// GenFilterRouteKey 生成路由唯一key
func (s *sMiddleware) GenFilterRouteKey(router *ghttp.Router) string {
return router.Method + " " + router.Uri
// GenFilterRequestKey 根据请求生成唯一key
func (s *sMiddleware) GenFilterRequestKey(r *ghttp.Request) string {
return s.GenRouteKey(r.Method, r.Request.URL.Path)
}
// GenFilterRouteKey 根据路由生成唯一key
func (s *sMiddleware) GenFilterRouteKey(r *ghttp.Router) string {
return s.GenRouteKey(r.Method, r.Uri)
}
// GenRouteKey 生成唯一key
func (s *sMiddleware) GenRouteKey(method, path string) string {
return method + " " + path
}
// PreFilter 请求输入预处理

View File

@@ -22,6 +22,16 @@ import (
func (s *sMiddleware) ResponseHandler(r *ghttp.Request) {
r.Middleware.Next()
// 错误状态码接管
switch r.Response.Status {
case 403:
r.Response.Writeln("403 - 网站拒绝显示此网页")
return
case 404:
r.Response.Writeln("404 - 你似乎来到了没有知识存在的荒原…")
return
}
contentType := getContentType(r)
// 已存在响应
if contentType != consts.HTTPContentTypeStream && r.Response.BufferLength() > 0 && contexts.Get(r.Context()).Response != nil {

View File

@@ -1,3 +1,8 @@
// Package pay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package pay
// 订单创建

View File

@@ -1,3 +1,8 @@
// Package pay
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package pay
// 异步通知
@@ -15,8 +20,16 @@ import (
"hotgo/internal/library/payment"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/payin"
"hotgo/internal/service"
)
// RegisterNotifyCall 注册支付成功回调方法
func (s *sPay) RegisterNotifyCall() {
payment.RegisterNotifyCallMap(map[string]payment.NotifyCallFunc{
consts.OrderGroupAdminOrder: service.AdminOrder().PayNotify, // 后台充值订单
})
}
// Notify 异步通知
func (s *sPay) Notify(ctx context.Context, in *payin.PayNotifyInp) (res *payin.PayNotifyModel, err error) {
data, err := payment.New(in.PayType).Notify(ctx, payin.NotifyInp{})

View File

@@ -11,10 +11,10 @@ import (
"github.com/gogf/gf/v2/text/gstr"
"hotgo/internal/consts"
"hotgo/internal/library/addons"
"hotgo/internal/library/dict"
"hotgo/internal/model/input/form"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"sort"
)
type sSysAddons struct{}
@@ -83,8 +83,7 @@ func (s *sSysAddons) List(ctx context.Context, in *sysin.AddonsListInp) (list []
row.Skeleton.Logo = consts.AddonsGroupIconMap[row.Skeleton.Group]
}
row.GroupName = consts.AddonsGroupNameMap[row.Skeleton.Group]
row.GroupName = dict.GetOptionLabel(consts.AddonsGroupOptions, row.Skeleton.Group)
list = append(list, row)
i++
}
@@ -93,42 +92,23 @@ func (s *sSysAddons) List(ctx context.Context, in *sysin.AddonsListInp) (list []
return
}
// Selects 选项
func (s *sSysAddons) Selects(ctx context.Context, in *sysin.AddonsSelectsInp) (res *sysin.AddonsSelectsModel, err error) {
res = new(sysin.AddonsSelectsModel)
for k, v := range consts.AddonsGroupNameMap {
res.GroupType = append(res.GroupType, &form.Select{
Value: k,
Name: v,
Label: v,
})
}
sort.Sort(res.GroupType)
for k, v := range consts.AddonsInstallStatusNameMap {
res.Status = append(res.Status, &form.Select{
Value: k,
Name: v,
Label: v,
})
}
sort.Sort(res.Status)
return
}
// Build 提交生成
func (s *sSysAddons) Build(ctx context.Context, in *sysin.AddonsBuildInp) (err error) {
genConfig, err := service.SysConfig().GetLoadGenerate(ctx)
config, err := service.SysConfig().GetLoadGenerate(ctx)
if err != nil {
return
}
if genConfig == nil || genConfig.Addon == nil {
if config == nil || config.Addon == nil {
err = gerror.New("没有找到有效的生成或插件配置,请检查配置文件是否正常")
return
}
return addons.Build(ctx, in.Skeleton, genConfig.Addon)
option := new(addons.BuildOption)
option.Config = config.Addon
option.Skeleton = in.Skeleton
option.Extend = in.Extend
return addons.Build(ctx, option)
}
// Install 安装模块

View File

@@ -64,7 +64,7 @@ func (s *sSysBlacklist) Edit(ctx context.Context, in *sysin.BlacklistEditInp) (e
return
}
// Status 更新部门状态
// Status 更新状态
func (s *sSysBlacklist) Status(ctx context.Context, in *sysin.BlacklistStatusInp) (err error) {
defer s.VariableLoad(ctx, err)
// 修改
@@ -72,7 +72,7 @@ func (s *sSysBlacklist) Status(ctx context.Context, in *sysin.BlacklistStatusInp
return
}
// View 获取指定字典类型信息
// View 获取指定信息
func (s *sSysBlacklist) View(ctx context.Context, in *sysin.BlacklistViewInp) (res *sysin.BlacklistViewModel, err error) {
err = dao.SysBlacklist.Ctx(ctx).Where("id", in.Id).Scan(&res)
return

View File

@@ -174,12 +174,6 @@ func (s *sSysConfig) GetLoadTCP(ctx context.Context) (conf *model.TCPConfig, err
return
}
// GetLoadCache 获取本地缓存配置
func (s *sSysConfig) GetLoadCache(ctx context.Context) (conf *model.CacheConfig, err error) {
err = g.Cfg().MustGet(ctx, "cache").Scan(&conf)
return
}
// GetLoadGenerate 获取本地生成配置
func (s *sSysConfig) GetLoadGenerate(ctx context.Context) (conf *model.GenerateConfig, err error) {
err = g.Cfg().MustGet(ctx, "hggen").Scan(&conf)

View File

@@ -1,9 +1,9 @@
// Package sys
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.11.5
// @AutoGenerate Version 2.12.10
package sys
import (

View File

@@ -7,10 +7,12 @@ package sys
import (
"context"
"errors"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/library/dict"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
)
@@ -146,6 +148,15 @@ func (s *sSysDictData) GetTypes(ctx context.Context, id int64) (types []string,
// Select 获取列表
func (s *sSysDictData) Select(ctx context.Context, in *sysin.DataSelectInp) (list sysin.DataSelectModel, err error) {
// 优先从内置字典中获取
options, err := dict.GetOptions(ctx, in.Type)
if err == nil {
return options, nil
}
if !errors.Is(err, dict.NotExistKeyError) {
return nil, err
}
mod := dao.SysDictData.Ctx(ctx).Where("type", in.Type)
if err = mod.Order("sort asc,id desc").Scan(&list); err != nil {
err = gerror.Wrap(err, consts.ErrorORM)

View File

@@ -11,6 +11,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/library/dict"
"hotgo/internal/library/hgorm"
"hotgo/internal/model/entity"
"hotgo/internal/model/input/sysin"
@@ -114,18 +115,70 @@ func (s *sSysDictType) TreeSelect(ctx context.Context, in *sysin.DictTreeSelectI
}
list = s.treeList(0, models)
list = append(list, s.BuiltinSelect()...)
return
}
for _, v := range list {
// 父类一律禁止选中
if len(v.Children) > 0 {
v.Disabled = true
for _, v2 := range v.Children {
if len(v2.Children) > 0 {
v2.Disabled = true
}
}
}
// BuiltinSelect 内置字典选项
func (s *sSysDictType) BuiltinSelect() (list []*sysin.DictTypeTree) {
top := &sysin.DictTypeTree{
SysDictType: entity.SysDictType{
Id: dict.BuiltinId,
Pid: 0,
},
Label: "内置字典",
Value: dict.BuiltinId,
Key: dict.BuiltinId,
}
enums := &sysin.DictTypeTree{
SysDictType: entity.SysDictType{
Id: dict.EnumsId,
Pid: dict.BuiltinId,
},
Label: "枚举字典",
Value: dict.EnumsId,
Key: dict.EnumsId,
}
for _, v := range dict.GetAllEnums() {
children := &sysin.DictTypeTree{
SysDictType: entity.SysDictType{
Id: v.Id,
Pid: dict.EnumsId,
},
Label: v.Label,
Value: v.Id,
Key: v.Id,
}
enums.Children = append(enums.Children, children)
}
fun := &sysin.DictTypeTree{
SysDictType: entity.SysDictType{
Id: dict.FuncId,
Pid: dict.BuiltinId,
},
Label: "方法字典",
Value: dict.FuncId,
Key: dict.FuncId,
}
for _, v := range dict.GetAllFunc() {
children := &sysin.DictTypeTree{
SysDictType: entity.SysDictType{
Id: v.Id,
Pid: dict.FuncId,
},
Label: v.Label,
Value: v.Id,
Key: v.Id,
}
fun.Children = append(fun.Children, children)
}
top.Children = append(top.Children, enums, fun)
list = append(list, top)
return
}

View File

@@ -242,6 +242,10 @@ func (s *sSysLog) View(ctx context.Context, in *sysin.LogViewInp) (res *sysin.Lo
return
}
if res == nil {
return
}
if g.Cfg().MustGet(ctx, "hotgo.isDemo", false).Bool() {
res.HeaderData = gjson.New(`{
"none": [

View File

@@ -1,3 +1,8 @@
// Package tcpserver
// @Link https://github.com/bufanyun/hotgo
// @Copyright Copyright (c) 2023 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
package tcpserver
import (