mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-12-28 02:55:59 +08:00
发布v2.2.10版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/api/backend/menu"
|
||||
"hotgo/api/backend/role"
|
||||
"hotgo/api/admin/menu"
|
||||
"hotgo/api/admin/role"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/casbin"
|
||||
|
||||
101
server/internal/logic/admin/monitor.go
Normal file
101
server/internal/logic/admin/monitor.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcron"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
"github.com/shirou/gopsutil/net"
|
||||
"hotgo/internal/library/location"
|
||||
"hotgo/internal/model"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/format"
|
||||
"hotgo/utility/simple"
|
||||
"runtime"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type sAdminMonitor struct {
|
||||
data *model.MonitorData
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
func NewAdminMonitor() *sAdminMonitor {
|
||||
return &sAdminMonitor{
|
||||
data: new(model.MonitorData),
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterAdminMonitor(NewAdminMonitor())
|
||||
}
|
||||
|
||||
// StartMonitor 启动服务监控
|
||||
func (s *sAdminMonitor) StartMonitor(ctx context.Context) {
|
||||
simple.SafeGo(ctx, func(ctx context.Context) {
|
||||
s.data.STartTime = gtime.Now()
|
||||
intranetIP, err := location.GetLocalIP()
|
||||
if err != nil {
|
||||
g.Log().Infof(ctx, "parse intranetIP err:%+v", err)
|
||||
}
|
||||
s.data.IntranetIP = intranetIP
|
||||
|
||||
publicIP, err := location.GetPublicIP(ctx)
|
||||
if err != nil {
|
||||
g.Log().Infof(ctx, "parse publicIP err:%+v", err)
|
||||
}
|
||||
s.data.PublicIP = publicIP
|
||||
|
||||
_, err = gcron.Add(ctx, "@every 1s", func(ctx context.Context) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
s.netIO()
|
||||
s.loadAvg()
|
||||
}, "AdminMonitorCronJob")
|
||||
if err != nil {
|
||||
g.Log().Warningf(ctx, "StartMonitor CronJob err:%+v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// GetMeta 获取监控元数据
|
||||
func (s *sAdminMonitor) GetMeta(ctx context.Context) *model.MonitorData {
|
||||
return s.data
|
||||
}
|
||||
|
||||
func (s *sAdminMonitor) loadAvg() {
|
||||
pl, _ := load.Avg()
|
||||
counter := model.LoadAvgStats{
|
||||
Time: gtime.Now(),
|
||||
Avg: pl.Load1,
|
||||
Ratio: pl.Load1 / (float64(runtime.NumCPU()) * 2) * 100,
|
||||
}
|
||||
|
||||
s.data.LoadAvg = append(s.data.LoadAvg, &counter)
|
||||
if len(s.data.LoadAvg) > 10 {
|
||||
s.data.LoadAvg = append(s.data.LoadAvg[:0], s.data.LoadAvg[(1):]...)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *sAdminMonitor) netIO() {
|
||||
var counter model.NetIOCounters
|
||||
ni, _ := net.IOCounters(true)
|
||||
counter.Time = gtime.Now()
|
||||
for _, v := range ni {
|
||||
counter.BytesSent += v.BytesSent
|
||||
counter.BytesRecv += v.BytesRecv
|
||||
}
|
||||
|
||||
if len(s.data.NetIO) > 0 {
|
||||
lastNetIO := s.data.NetIO[len(s.data.NetIO)-1]
|
||||
sub := counter.Time.Sub(lastNetIO.Time).Seconds()
|
||||
counter.Down = format.Round2Float64((float64(counter.BytesRecv - lastNetIO.BytesRecv)) / sub)
|
||||
counter.UP = format.Round2Float64((float64(counter.BytesSent - lastNetIO.BytesSent)) / sub)
|
||||
}
|
||||
|
||||
s.data.NetIO = append(s.data.NetIO, &counter)
|
||||
if len(s.data.NetIO) > 10 {
|
||||
s.data.NetIO = append(s.data.NetIO[:0], s.data.NetIO[(1):]...)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/api/backend/role"
|
||||
"hotgo/api/admin/role"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/casbin"
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
// Package admin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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/os/gctx"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/hgorm"
|
||||
"hotgo/internal/library/hgorm/handler"
|
||||
"hotgo/internal/model/input/adminin"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/excel"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sAdminTest struct{}
|
||||
|
||||
func NewAdminTest() *sAdminTest {
|
||||
return &sAdminTest{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterAdminTest(NewAdminTest())
|
||||
}
|
||||
|
||||
// Model Orm模型
|
||||
func (s *sAdminTest) Model(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
return handler.Model(dao.Test.Ctx(ctx), option...)
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sAdminTest) List(ctx context.Context, in adminin.TestListInp) (list []*adminin.TestListModel, totalCount int, err error) {
|
||||
mod := s.Model(ctx)
|
||||
|
||||
if in.Title != "" {
|
||||
mod = mod.WhereLike(dao.Test.Columns().Title, "%"+in.Title+"%")
|
||||
}
|
||||
|
||||
if in.Content != "" {
|
||||
mod = mod.WhereLike(dao.Test.Columns().Content, "%"+in.Content+"%")
|
||||
}
|
||||
|
||||
if in.Status > 0 {
|
||||
mod = mod.Where(dao.Test.Columns().Status, in.Status)
|
||||
}
|
||||
|
||||
if in.Switch > 0 {
|
||||
mod = mod.Where(dao.Test.Columns().Switch, in.Switch)
|
||||
}
|
||||
|
||||
if len(in.Price) > 0 {
|
||||
if in.Price[0] > float64(0) && in.Price[1] > float64(0) {
|
||||
mod = mod.WhereBetween(dao.Test.Columns().Price, in.Price[0], in.Price[1])
|
||||
} else if in.Price[0] > float64(0) && in.Price[1] == float64(0) {
|
||||
mod = mod.WhereGTE(dao.Test.Columns().Price, in.Price[0])
|
||||
} else if in.Price[0] == float64(0) && in.Price[1] > float64(0) {
|
||||
mod = mod.WhereLTE(dao.Test.Columns().Price, in.Price[1])
|
||||
}
|
||||
}
|
||||
|
||||
if in.ActivityAt != nil {
|
||||
mod = mod.Where(dao.Test.Columns().ActivityAt, in.ActivityAt)
|
||||
}
|
||||
|
||||
if len(in.CreatedAt) == 2 {
|
||||
mod = mod.WhereBetween(dao.Test.Columns().CreatedAt, in.CreatedAt[0], in.CreatedAt[1])
|
||||
}
|
||||
|
||||
if !in.Flag.IsNil() {
|
||||
mod = mod.Where(fmt.Sprintf(`JSON_CONTAINS(%s,'%v')`, dao.Test.Columns().Flag, in.Flag))
|
||||
}
|
||||
|
||||
if !in.Hobby.IsNil() {
|
||||
mod = mod.Where(fmt.Sprintf(`JSON_CONTAINS(%s,'%v')`, dao.Test.Columns().Hobby, in.Hobby))
|
||||
}
|
||||
|
||||
//// 关联表testCategory
|
||||
//mod = mod.LeftJoin(hgorm.GenJoinOnRelation(
|
||||
// dao.Test.Table(), dao.Test.Columns().CategoryId, // 主表表名,关联条件
|
||||
// dao.TestCategory.Table(), "testCategory", dao.TestCategory.Columns().Id, // 关联表表名,别名,关联条件
|
||||
//)...)
|
||||
//
|
||||
//mod = mod.Where(`testCategory.`+dao.TestCategory.Columns().Name, "微信公众号")
|
||||
|
||||
totalCount, err = mod.Clone().Count(1)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
|
||||
if totalCount == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
////关联表select
|
||||
//fields, err := hgorm.GenJoinSelect(ctx, adminin.TestListModel{}, dao.Test, []*hgorm.Join{
|
||||
// {Dao: dao.TestCategory, Alias: "testCategory"},
|
||||
// //{Dao: dao.TestCategory, Alias: "testCategory"},
|
||||
//})
|
||||
|
||||
fields, err := hgorm.GenSelect(ctx, adminin.TestListModel{}, dao.Test)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = mod.Fields(fields).Handler(handler.FilterAuth, handler.ForceCache).Page(in.Page, in.PerPage).OrderAsc(dao.Test.Columns().Sort).OrderDesc(dao.Test.Columns().Id).Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Export 导出
|
||||
func (s *sAdminTest) Export(ctx context.Context, in adminin.TestListInp) (err error) {
|
||||
list, totalCount, err := s.List(ctx, in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...}
|
||||
tags, err := convert.GetEntityDescTags(adminin.TestExportModel{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
fileName = "测试导出-" + gctx.CtxId(ctx) + ".xlsx"
|
||||
sheetName = fmt.Sprintf("索引条件共%v行,共%v页,当前导出是第%v页,本页共%v行", totalCount, form.CalPageCount(totalCount, in.PerPage), in.Page, len(list))
|
||||
exports []adminin.TestExportModel
|
||||
)
|
||||
|
||||
if err = gconv.Scan(list, &exports); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 修改/新增
|
||||
func (s *sAdminTest) Edit(ctx context.Context, in adminin.TestEditInp) (err error) {
|
||||
if err = hgorm.IsUnique(ctx, dao.Test, g.Map{dao.Test.Columns().Qq: in.Qq}, "QQ号码已存在,请换一个", in.Id); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 修改
|
||||
if in.Id > 0 {
|
||||
in.UpdatedBy = contexts.GetUserId(ctx)
|
||||
_, err = s.Model(ctx).Where(dao.Test.Columns().Id, in.Id).Data(in).Update()
|
||||
return
|
||||
}
|
||||
|
||||
// 新增
|
||||
in.CreatedBy = contexts.GetUserId(ctx)
|
||||
_, err = s.Model(ctx, &handler.Option{FilterAuth: false}).Data(in).Insert()
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除
|
||||
func (s *sAdminTest) Delete(ctx context.Context, in adminin.TestDeleteInp) (err error) {
|
||||
_, err = s.Model(ctx).Where(dao.Test.Columns().Id, in.Id).Delete()
|
||||
return
|
||||
}
|
||||
|
||||
// Status 更新状态
|
||||
func (s *sAdminTest) Status(ctx context.Context, in adminin.TestStatusInp) (err error) {
|
||||
if in.Id <= 0 {
|
||||
err = gerror.New("ID不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
|
||||
// 修改
|
||||
_, err = s.Model(ctx).Where(dao.Test.Columns().Id, in.Id).Data(g.Map{
|
||||
dao.Test.Columns().Status: in.Status,
|
||||
dao.Test.Columns().UpdatedBy: contexts.GetUserId(ctx),
|
||||
}).Update()
|
||||
return
|
||||
}
|
||||
|
||||
// Switch 更新开关状态
|
||||
func (s *sAdminTest) Switch(ctx context.Context, in adminin.TestSwitchInp) (err error) {
|
||||
var fields = []string{
|
||||
dao.Test.Columns().Switch,
|
||||
// ...
|
||||
}
|
||||
|
||||
if !validate.InSliceString(fields, in.Key) {
|
||||
err = gerror.New("开关键名不在白名单")
|
||||
return
|
||||
}
|
||||
|
||||
// 修改
|
||||
_, err = s.Model(ctx).Where(dao.Test.Columns().Id, in.Id).Data(g.Map{
|
||||
in.Key: in.Value,
|
||||
dao.Test.Columns().UpdatedBy: contexts.GetUserId(ctx),
|
||||
}).Update()
|
||||
return
|
||||
}
|
||||
|
||||
// MaxSort 最大排序
|
||||
func (s *sAdminTest) MaxSort(ctx context.Context, in adminin.TestMaxSortInp) (res *adminin.TestMaxSortModel, err error) {
|
||||
if err = dao.Test.Ctx(ctx).Fields(dao.Test.Columns().Sort).OrderDesc(dao.Test.Columns().Sort).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
res = new(adminin.TestMaxSortModel)
|
||||
}
|
||||
|
||||
res.Sort = form.DefaultMaxSort(ctx, res.Sort)
|
||||
return
|
||||
}
|
||||
|
||||
// View 获取指定字典类型信息
|
||||
func (s *sAdminTest) View(ctx context.Context, in adminin.TestViewInp) (res *adminin.TestViewModel, err error) {
|
||||
err = s.Model(ctx).Where(dao.Test.Columns().Id, in.Id).Scan(&res)
|
||||
return
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package common
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package hook
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -16,12 +16,11 @@ import (
|
||||
"hotgo/utility/simple"
|
||||
)
|
||||
|
||||
// AccessLog 访问日志
|
||||
func (s *sHook) AccessLog(r *ghttp.Request) {
|
||||
// accessLog 访问日志
|
||||
func (s *sHook) accessLog(r *ghttp.Request) {
|
||||
if r.IsFileRequest() {
|
||||
return
|
||||
}
|
||||
|
||||
var ctx = r.Context()
|
||||
modelCtx := contexts.Get(ctx)
|
||||
if modelCtx == nil {
|
||||
@@ -33,7 +32,7 @@ func (s *sHook) AccessLog(r *ghttp.Request) {
|
||||
|
||||
simple.SafeGo(ctx, func(ctx context.Context) {
|
||||
if err := service.SysLog().AutoLog(ctx); err != nil {
|
||||
g.Log().Warningf(ctx, "hook AccessLog err:%+v", err)
|
||||
g.Log().Warningf(ctx, "hook accessLog err:%+v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// Package hook
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package hook
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
@@ -20,3 +21,8 @@ func init() {
|
||||
func New() *sHook {
|
||||
return &sHook{}
|
||||
}
|
||||
|
||||
func (s *sHook) AfterOutput(r *ghttp.Request) {
|
||||
s.accessLog(r)
|
||||
s.lastAdminActive(r)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/os/gtimer"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/utility/simple"
|
||||
"sync"
|
||||
@@ -58,30 +59,30 @@ func allow(memberId int64) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// LastActive 更新用户最后活跃
|
||||
func (s *sHook) LastActive(r *ghttp.Request) {
|
||||
// lastAdminActive 更新后台用户最后活跃
|
||||
func (s *sHook) lastAdminActive(r *ghttp.Request) {
|
||||
if r.IsFileRequest() {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
ctx = r.Context()
|
||||
memberId = contexts.GetUserId(ctx)
|
||||
ctx = r.Context()
|
||||
member = contexts.GetUser(ctx)
|
||||
)
|
||||
|
||||
if memberId == 0 {
|
||||
if member == nil || member.App != consts.AppAdmin {
|
||||
return
|
||||
}
|
||||
|
||||
if allow(memberId) {
|
||||
if allow(member.Id) {
|
||||
simple.SafeGo(ctx, func(ctx context.Context) {
|
||||
_, err := g.Model("admin_member").Ctx(ctx).
|
||||
Where("id", memberId).
|
||||
Where("id", member.Id).
|
||||
WhereLT("last_active_at", gtime.Now()).
|
||||
Data(g.Map{"last_active_at": gtime.Now()}).
|
||||
Update()
|
||||
if err != nil {
|
||||
g.Log().Warningf(ctx, "hook LastActive err:%+v, memberId:%v", err, memberId)
|
||||
g.Log().Warningf(ctx, "hook lastActive err:%+v, memberId:%v", err, member.Id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package middleware
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package middleware
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Package middleware
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package middleware
|
||||
|
||||
import (
|
||||
@@ -12,8 +11,10 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"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"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/addons"
|
||||
"hotgo/internal/library/cache"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/jwt"
|
||||
@@ -94,13 +95,35 @@ func (s *sMiddleware) DemoLimit(r *ghttp.Request) {
|
||||
r.Middleware.Next()
|
||||
}
|
||||
|
||||
// Addon 插件中间件
|
||||
func (s *sMiddleware) Addon(r *ghttp.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
)
|
||||
|
||||
if contexts.Get(ctx).Module == "" {
|
||||
g.Log().Warning(ctx, "application module is not initialized.")
|
||||
return
|
||||
}
|
||||
|
||||
// 替换掉应用模块前缀
|
||||
path := gstr.Replace(r.URL.Path, "/"+contexts.Get(ctx).Module+"/", "", 1)
|
||||
ss := gstr.Explode("/", path)
|
||||
if len(ss) == 0 {
|
||||
g.Log().Warning(ctx, "addon was not recognized.")
|
||||
return
|
||||
}
|
||||
|
||||
contexts.SetAddonName(ctx, addons.GetModule(ss[0]).GetSkeleton().Name)
|
||||
r.Middleware.Next()
|
||||
}
|
||||
|
||||
// inspectAuth 检查并完成身份认证
|
||||
func inspectAuth(r *ghttp.Request, appName string) error {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
user = new(model.Identity)
|
||||
authorization = jwt.GetAuthorization(r)
|
||||
c = cache.New()
|
||||
customCtx = &model.Context{}
|
||||
)
|
||||
|
||||
@@ -109,7 +132,7 @@ func inspectAuth(r *ghttp.Request, appName string) error {
|
||||
}
|
||||
|
||||
// 获取jwtToken
|
||||
jwtToken := consts.RedisJwtToken + gmd5.MustEncryptString(authorization)
|
||||
jwtToken := consts.CacheJwtToken + gmd5.MustEncryptString(authorization)
|
||||
jwtSign := g.Cfg().MustGet(ctx, "jwt.sign", "hotgo")
|
||||
|
||||
data, ParseErr := jwt.ParseToken(authorization, jwtSign.Bytes())
|
||||
@@ -123,18 +146,18 @@ func inspectAuth(r *ghttp.Request, appName string) error {
|
||||
}
|
||||
|
||||
// 判断token跟redis的缓存的token是否一样
|
||||
isContains, containsErr := c.Contains(ctx, jwtToken)
|
||||
isContains, containsErr := cache.Instance().Contains(ctx, jwtToken)
|
||||
if containsErr != nil {
|
||||
return gerror.Newf("token无效! err :%+v", ParseErr.Error())
|
||||
}
|
||||
if !isContains {
|
||||
return gerror.New("token已过期")
|
||||
return gerror.Newf("token已过期")
|
||||
}
|
||||
|
||||
// 是否开启多端登录
|
||||
if multiPort := g.Cfg().MustGet(ctx, "jwt.multiPort", true); !multiPort.Bool() {
|
||||
key := consts.RedisJwtUserBind + appName + ":" + gconv.String(user.Id)
|
||||
originJwtToken, originErr := c.Get(ctx, key)
|
||||
if !g.Cfg().MustGet(ctx, "jwt.multiPort", true).Bool() {
|
||||
key := consts.CacheJwtUserBind + appName + ":" + gconv.String(user.Id)
|
||||
originJwtToken, originErr := cache.Instance().Get(ctx, key)
|
||||
if originErr != nil {
|
||||
return gerror.Newf("信息异常,请重新登录! err :%+v", originErr.Error())
|
||||
}
|
||||
@@ -167,6 +190,5 @@ func inspectAuth(r *ghttp.Request, appName string) error {
|
||||
}
|
||||
}
|
||||
contexts.SetUser(ctx, customCtx.User)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package middleware
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package middleware
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
149
server/internal/logic/sys/addons.go
Normal file
149
server/internal/logic/sys/addons.go
Normal file
@@ -0,0 +1,149 @@
|
||||
// Package sys
|
||||
// @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 sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/addons"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type sSysAddons struct{}
|
||||
|
||||
func NewSysAddons() *sSysAddons {
|
||||
return &sSysAddons{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysAddons(NewSysAddons())
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysAddons) List(ctx context.Context, in sysin.AddonsListInp) (list []*sysin.AddonsListModel, totalCount int, err error) {
|
||||
sks := addons.GetSkeletons()
|
||||
if len(sks) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
i int
|
||||
_, perPage, offset = form.CalPage(ctx, in.Page, in.PerPage)
|
||||
)
|
||||
|
||||
for k, skeleton := range sks {
|
||||
ok := k >= offset && i <= perPage
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
row := new(sysin.AddonsListModel)
|
||||
row.Skeleton = *skeleton
|
||||
|
||||
if in.Group > 0 {
|
||||
if row.Skeleton.Group != in.Group {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if in.Name != "" {
|
||||
if row.Skeleton.Label != in.Name && row.Skeleton.Name != in.Name {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
install, err := addons.ScanInstall(row.Skeleton.GetModule())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if install == nil {
|
||||
row.InstallStatus = consts.AddonsInstallStatusNo
|
||||
row.InstallVersion = "v0.0.0"
|
||||
} else {
|
||||
row.InstallStatus = install.Status
|
||||
row.InstallVersion = install.Version
|
||||
row.CanSave = gstr.CompareVersion(row.Skeleton.Version, install.Version) > 0
|
||||
}
|
||||
|
||||
if in.Status > 0 {
|
||||
if row.InstallStatus != in.Status {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if row.Skeleton.Logo == "" {
|
||||
row.Skeleton.Logo, _ = consts.AddonsGroupIconMap[row.Skeleton.Group]
|
||||
}
|
||||
|
||||
row.GroupName, _ = consts.AddonsGroupNameMap[row.Skeleton.Group]
|
||||
|
||||
list = append(list, row)
|
||||
i++
|
||||
}
|
||||
|
||||
totalCount = len(sks)
|
||||
|
||||
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 res, nil
|
||||
}
|
||||
|
||||
// Build 提交生成
|
||||
func (s *sSysAddons) Build(ctx context.Context, in sysin.AddonsBuildInp) (err error) {
|
||||
genConfig, err := service.SysConfig().GetLoadGenerate(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if genConfig == nil || genConfig.Addon == nil {
|
||||
err = gerror.New("没有找到有效的生成或插件配置,请检查配置文件是否正常")
|
||||
return
|
||||
}
|
||||
|
||||
return addons.Build(ctx, in.Skeleton, genConfig.Addon)
|
||||
}
|
||||
|
||||
// Install 安装模块
|
||||
func (s *sSysAddons) Install(ctx context.Context, in sysin.AddonsInstallInp) (err error) {
|
||||
return addons.Install(in.GetModule())
|
||||
}
|
||||
|
||||
// Upgrade 更新模块
|
||||
func (s *sSysAddons) Upgrade(ctx context.Context, in sysin.AddonsUpgradeInp) (err error) {
|
||||
return addons.Upgrade(in.GetModule())
|
||||
}
|
||||
|
||||
// UnInstall 卸载模块
|
||||
func (s *sSysAddons) UnInstall(ctx context.Context, in sysin.AddonsUnInstallInp) (err error) {
|
||||
return addons.UnInstall(in.GetModule())
|
||||
}
|
||||
150
server/internal/logic/sys/addons_config.go
Normal file
150
server/internal/logic/sys/addons_config.go
Normal file
@@ -0,0 +1,150 @@
|
||||
// Package sys
|
||||
// @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 sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
var AddonsMaskDemoField []string
|
||||
|
||||
type sSysAddonsConfig struct{}
|
||||
|
||||
func NewSysAddonsConfig() *sSysAddonsConfig {
|
||||
return &sSysAddonsConfig{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysAddonsConfig(NewSysAddonsConfig())
|
||||
}
|
||||
|
||||
// GetConfigByGroup 获取指定分组的配置
|
||||
func (s *sSysAddonsConfig) GetConfigByGroup(ctx context.Context, in sysin.GetAddonsConfigInp) (res *sysin.GetAddonsConfigModel, err error) {
|
||||
if in.AddonName == "" {
|
||||
return nil, gerror.New("插件名称不能为空")
|
||||
}
|
||||
if in.Group == "" {
|
||||
return nil, gerror.New("分组不能为空")
|
||||
}
|
||||
var (
|
||||
mod = dao.SysAddonsConfig.Ctx(ctx)
|
||||
models []*entity.SysAddonsConfig
|
||||
)
|
||||
|
||||
if err = mod.Fields("key", "value", "type").
|
||||
Where("addon_name", in.AddonName).
|
||||
Where("group", in.Group).
|
||||
Scan(&models); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false)
|
||||
|
||||
if len(models) > 0 {
|
||||
res = new(sysin.GetAddonsConfigModel)
|
||||
res.List = make(g.Map, len(models))
|
||||
for _, v := range models {
|
||||
val, err := s.ConversionType(ctx, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.List[v.Key] = val
|
||||
if isDemo.Bool() && gstr.InArray(AddonsMaskDemoField, v.Key) {
|
||||
res.List[v.Key] = consts.DemoTips
|
||||
res.List[v.Key] = consts.DemoTips
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ConversionType 转换类型
|
||||
func (s *sSysAddonsConfig) ConversionType(ctx context.Context, models *entity.SysAddonsConfig) (value interface{}, err error) {
|
||||
if models == nil {
|
||||
return nil, gerror.New("数据不存在")
|
||||
}
|
||||
return consts.ConvType(models.Value, models.Type), nil
|
||||
}
|
||||
|
||||
// UpdateConfigByGroup 更新指定分组的配置
|
||||
func (s *sSysAddonsConfig) UpdateConfigByGroup(ctx context.Context, in sysin.UpdateAddonsConfigInp) error {
|
||||
if in.AddonName == "" {
|
||||
return gerror.New("插件名称不能为空")
|
||||
}
|
||||
if in.Group == "" {
|
||||
return gerror.New("分组不能为空")
|
||||
}
|
||||
var (
|
||||
mod = dao.SysAddonsConfig.Ctx(ctx)
|
||||
models []*entity.SysAddonsConfig
|
||||
)
|
||||
if err := mod.
|
||||
Where("addon_name", in.AddonName).
|
||||
Where("group", in.Group).
|
||||
Scan(&models); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := dao.SysAddonsConfig.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
for k, v := range in.List {
|
||||
row := s.getConfigByKey(k, models)
|
||||
// 新增
|
||||
if row == nil {
|
||||
//row.Id = 0
|
||||
//row.Key = k
|
||||
//row.Value = gconv.String(v)
|
||||
//row.Group = in.Group
|
||||
//row.Status = consts.StatusEnabled
|
||||
//row.CreatedAt = gtime.Now()
|
||||
//row.UpdatedAt = gtime.Now()
|
||||
//_, err := dao.SysAddonsConfig.Ctx(ctx).Data(row).Insert()
|
||||
//if err != nil {
|
||||
// err = gerror.Wrap(err, consts.ErrorORM)
|
||||
// return err
|
||||
//}
|
||||
//continue
|
||||
return gerror.Newf("暂不支持从前台添加变量,请先在数据库表[%v]中配置变量:%v", dao.SysAddonsConfig.Table(), k)
|
||||
}
|
||||
|
||||
// 更新
|
||||
_, err := dao.SysAddonsConfig.Ctx(ctx).Where("id", row.Id).Data(g.Map{"value": v, "updated_at": gtime.Now()}).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *sSysAddonsConfig) getConfigByKey(key string, models []*entity.SysAddonsConfig) *entity.SysAddonsConfig {
|
||||
if len(models) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, v := range models {
|
||||
if key == v.Key {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -161,6 +161,7 @@ func (s *sSysAttachment) List(ctx context.Context, in sysin.AttachmentListInp) (
|
||||
if err != nil {
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
for _, v := range list {
|
||||
v.SizeFormat = format.FileSize(v.Size)
|
||||
v.FileUrl = service.CommonUpload().LastUrl(ctx, conf, v.FileUrl, v.Drive)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -172,7 +172,7 @@ func (s *sSysBlacklist) Load(ctx context.Context) {
|
||||
Where(dao.SysBlacklist.Columns().Status, consts.StatusEnabled).
|
||||
Array()
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, "load blacklist fail:%+v", err)
|
||||
g.Log().Fatalf(ctx, "load blacklist fail:%+v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package sys
|
||||
|
||||
import (
|
||||
@@ -40,6 +39,12 @@ func init() {
|
||||
service.RegisterSysConfig(NewSysConfig())
|
||||
}
|
||||
|
||||
// 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) {
|
||||
generate := g.Cfg().MustGet(ctx, "hggen")
|
||||
@@ -217,7 +222,7 @@ func (s *sSysConfig) UpdateConfigByGroup(ctx context.Context, in sysin.UpdateCon
|
||||
// return err
|
||||
//}
|
||||
//continue
|
||||
return gerror.Newf("暂不支持从前台添加变量,请从数据库中添加变量:%v", k)
|
||||
return gerror.Newf("暂不支持从前台添加变量,请先在数据库表[%v]中配置变量:%v", dao.SysConfig.Table(), k)
|
||||
}
|
||||
|
||||
// 更新
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.1.2
|
||||
// @AutoGenerate Date 2023-02-08 17:47:32
|
||||
// @AutoGenerate Version 2.1.4
|
||||
// @AutoGenerate Date 2023-02-20 16:41:58
|
||||
//
|
||||
package sys
|
||||
|
||||
@@ -77,7 +77,6 @@ func (s *sSysCurdDemo) List(ctx context.Context, in sysin.CurdDemoListInp) (list
|
||||
|
||||
totalCount, err = mod.Clone().Count(1)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -90,11 +89,7 @@ func (s *sSysCurdDemo) List(ctx context.Context, in sysin.CurdDemoListInp) (list
|
||||
{Dao: dao.TestCategory, Alias: "testCategory"},
|
||||
})
|
||||
|
||||
if err = mod.Fields(fields).Page(in.Page, in.PerPage).OrderAsc(dao.SysGenCurdDemo.Columns().Sort).OrderDesc(dao.SysGenCurdDemo.Columns().Id).Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
|
||||
err = mod.Fields(fields).Page(in.Page, in.PerPage).OrderAsc(dao.SysGenCurdDemo.Columns().Sort).OrderDesc(dao.SysGenCurdDemo.Columns().Id).Scan(&list)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,7 +157,6 @@ func (s *sSysCurdDemo) Delete(ctx context.Context, in sysin.CurdDemoDeleteInp) (
|
||||
// MaxSort 获取生成演示最大排序
|
||||
func (s *sSysCurdDemo) MaxSort(ctx context.Context, in sysin.CurdDemoMaxSortInp) (res *sysin.CurdDemoMaxSortModel, err error) {
|
||||
if err = dao.SysGenCurdDemo.Ctx(ctx).Fields(dao.SysGenCurdDemo.Columns().Sort).OrderDesc(dao.SysGenCurdDemo.Columns().Sort).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package sys
|
||||
|
||||
import (
|
||||
@@ -13,10 +12,12 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/hggen"
|
||||
"hotgo/internal/model"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
@@ -53,6 +54,25 @@ func (s *sSysGenCodes) Edit(ctx context.Context, in sysin.GenCodesEditInp) (res
|
||||
err = gerror.New("实体名称不能为空")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in.GenType == consts.GenCodesTypeCurd {
|
||||
var temp *model.GenerateAppCrudTemplate
|
||||
cfg := fmt.Sprintf("hggen.application.crud.templates.%v", in.GenTemplate)
|
||||
if err = g.Cfg().MustGet(ctx, cfg).Scan(&temp); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if temp == nil {
|
||||
err = gerror.Newf("选择的模板不存在:%v", cfg)
|
||||
return
|
||||
}
|
||||
|
||||
if temp.IsAddon && in.AddonName == "" {
|
||||
err = gerror.New("插件模板必须选择一个有效的插件")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 修改
|
||||
in.UpdatedAt = gtime.Now()
|
||||
if in.Id > 0 {
|
||||
@@ -212,16 +232,27 @@ func (s *sSysGenCodes) TableSelect(ctx context.Context, in sysin.GenCodesTableSe
|
||||
return nil, err
|
||||
}
|
||||
|
||||
patternStr := `addon_(\w+)_`
|
||||
repStr := ``
|
||||
|
||||
for _, v := range lists {
|
||||
if gstr.InArray(disableTables, v.Value) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 如果是插件模块,则移除掉插件表前缀
|
||||
defVarName := gstr.SubStrFromEx(v.Value, config.Prefix)
|
||||
bt, err := gregex.Replace(patternStr, []byte(repStr), []byte(defVarName))
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
defVarName = gstr.CaseCamel(string(bt))
|
||||
|
||||
row := new(sysin.GenCodesTableSelectModel)
|
||||
row = v
|
||||
row.DefTableComment = v.Label
|
||||
row.DaoName = gstr.CaseCamel(gstr.SubStrFromEx(v.Value, config.Prefix))
|
||||
row.DefVarName = row.DaoName
|
||||
row.DefVarName = defVarName
|
||||
row.DefAlias = gstr.CaseCamelLower(gstr.SubStrFromEx(v.Value, config.Prefix))
|
||||
row.Name = fmt.Sprintf("%s (%s)", v.Value, v.Label)
|
||||
row.Label = row.Name
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -135,6 +135,7 @@ func (s *sSysLog) AutoLog(ctx context.Context) error {
|
||||
err = queue.Push(consts.QueueLogTopic, data)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.RealWrite(ctx, data)
|
||||
return
|
||||
})
|
||||
@@ -195,15 +196,12 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
||||
appId = user.App
|
||||
}
|
||||
|
||||
var ipData = new(location.IpLocationData)
|
||||
if validate.IsPublicIp(clientIp) {
|
||||
ipData, err := location.GetLocation(ctx, clientIp)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "location.GetLocation err:%+v", err)
|
||||
}
|
||||
if ipData == nil {
|
||||
ipData = new(location.IpLocationData)
|
||||
}
|
||||
ipData, err := location.GetLocation(ctx, clientIp)
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "location.GetLocation err:%+v", err)
|
||||
}
|
||||
if ipData == nil {
|
||||
ipData = new(location.IpLocationData)
|
||||
}
|
||||
|
||||
data = entity.SysLog{
|
||||
@@ -233,30 +231,26 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
||||
|
||||
// View 获取指定字典类型信息
|
||||
func (s *sSysLog) View(ctx context.Context, in sysin.LogViewInp) (res *sysin.LogViewModel, err error) {
|
||||
|
||||
if err = dao.SysLog.Ctx(ctx).Hook(hook.CityLabel).Where("id", in.Id).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
return
|
||||
}
|
||||
|
||||
isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false)
|
||||
if isDemo.Bool() {
|
||||
// res.HeaderData = `{
|
||||
// "none": [
|
||||
// "` + consts.DemoTips + `"
|
||||
// ]
|
||||
//}`
|
||||
res.HeaderData = gjson.New(`{
|
||||
"none": [
|
||||
"` + consts.DemoTips + `"
|
||||
]
|
||||
}`)
|
||||
}
|
||||
return res, nil
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除
|
||||
func (s *sSysLog) Delete(ctx context.Context, in sysin.LogDeleteInp) error {
|
||||
if _, err := dao.SysLog.Ctx(ctx).Where("id", in.Id).Delete(); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
func (s *sSysLog) Delete(ctx context.Context, in sysin.LogDeleteInp) (err error) {
|
||||
_, err = dao.SysLog.Ctx(ctx).Where("id", in.Id).Delete()
|
||||
return
|
||||
}
|
||||
|
||||
// List 列表
|
||||
@@ -361,11 +355,11 @@ func (s *sSysLog) List(ctx context.Context, in sysin.LogListInp) (list []*sysin.
|
||||
}
|
||||
|
||||
if isDemo.Bool() {
|
||||
// list[i].HeaderData = `{
|
||||
// "none": [
|
||||
// "` + consts.DemoTips + `"
|
||||
// ]
|
||||
//}`
|
||||
list[i].HeaderData = gjson.New(`{
|
||||
"none": [
|
||||
"` + consts.DemoTips + `"
|
||||
]
|
||||
}`)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
@@ -252,7 +252,7 @@ func (s *sSysProvinces) UniqueId(ctx context.Context, in sysin.ProvincesUniqueId
|
||||
return
|
||||
}
|
||||
|
||||
if err = hgorm.IsUnique(ctx, dao.SysProvinces, g.Map{dao.Test.Columns().Id: in.NewId}, "", in.OldId); err != nil {
|
||||
if err = hgorm.IsUnique(ctx, dao.SysProvinces, g.Map{dao.SysProvinces.Columns().Id: in.NewId}, "", in.OldId); err != nil {
|
||||
res.IsUnique = false
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package view
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package view
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user