This commit is contained in:
孟帅
2024-07-21 22:21:02 +08:00
parent 7d8330f72f
commit a37d088360
440 changed files with 6303 additions and 3339 deletions

View File

@@ -11,8 +11,10 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"hotgo/internal/dao"
"hotgo/internal/library/contexts"
"hotgo/internal/library/dict"
"hotgo/internal/library/hgorm/handler"
"hotgo/internal/library/storager"
"hotgo/internal/model"
"hotgo/internal/model/input/sysin"
"hotgo/internal/service"
"hotgo/utility/format"
@@ -26,6 +28,7 @@ func NewSysAttachment() *sSysAttachment {
func init() {
service.RegisterSysAttachment(NewSysAttachment())
dict.RegisterFunc("AttachmentKindOption", "上传类型选项", service.SysAttachment().AttachmentKindOption)
}
// Model ORM模型
@@ -111,3 +114,15 @@ func (s *sSysAttachment) ClearKind(ctx context.Context, in *sysin.AttachmentClea
}
return
}
// AttachmentKindOption 上传类型选项
func (s *sSysAttachment) AttachmentKindOption(ctx context.Context) (opts []*model.Option, err error) {
opts = append(opts, dict.GenDefaultOption("", "全部"))
opts = append(opts, dict.GenSuccessOption(storager.KindImg, "图片", "PictureOutlined"))
opts = append(opts, dict.GenPrimaryOption(storager.KindDoc, "文档", "FileWordOutlined"))
opts = append(opts, dict.GenSuccessOption(storager.KindAudio, "音频", "CustomerServiceOutlined"))
opts = append(opts, dict.GenSuccessOption(storager.KindVideo, "视频", "PlaySquareOutlined"))
opts = append(opts, dict.GenSuccessOption(storager.KindZip, "压缩包", "FileZipOutlined"))
opts = append(opts, dict.GenSuccessOption(storager.KindOther, "其他", "PlusOutlined"))
return
}

View File

@@ -3,7 +3,7 @@
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.13.1
// @AutoGenerate Version 2.15.1
package sys
import (
@@ -69,11 +69,6 @@ func (s *sSysCurdDemo) List(ctx context.Context, in *sysin.CurdDemoListInp) (lis
mod = mod.WhereLike(dao.SysGenCurdDemo.Columns().Description, "%"+in.Description+"%")
}
// 查询状态
if in.Status > 0 {
mod = mod.Where(dao.SysGenCurdDemo.Columns().Status, in.Status)
}
// 查询创建者
if in.CreatedBy != "" {
ids, err := service.AdminMember().GetIdsByKeyword(ctx, in.CreatedBy)
@@ -88,11 +83,6 @@ func (s *sSysCurdDemo) List(ctx context.Context, in *sysin.CurdDemoListInp) (lis
mod = mod.WhereBetween(dao.SysGenCurdDemo.Columns().CreatedAt, in.CreatedAt[0], in.CreatedAt[1])
}
// 查询测试分类
if in.CategoryId > 0 {
mod = mod.Where(dao.SysGenCurdDemo.Columns().CategoryId, in.CategoryId)
}
// 查询关联分类
if in.TestCategoryName != "" {
mod = mod.WherePrefix(dao.TestCategory.Table(), dao.TestCategory.Columns().Name, in.TestCategoryName)
@@ -145,6 +135,7 @@ func (s *sSysCurdDemo) Export(ctx context.Context, in *sysin.CurdDemoListInp) (e
// Edit 修改/新增CURD列表
func (s *sSysCurdDemo) Edit(ctx context.Context, in *sysin.CurdDemoEditInp) (err error) {
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
// 修改
if in.Id > 0 {
in.UpdatedBy = contexts.GetUserId(ctx)
@@ -169,6 +160,7 @@ func (s *sSysCurdDemo) Edit(ctx context.Context, in *sysin.CurdDemoEditInp) (err
// Delete 删除CURD列表
func (s *sSysCurdDemo) Delete(ctx context.Context, in *sysin.CurdDemoDeleteInp) (err error) {
if _, err = s.Model(ctx).WherePri(in.Id).Delete(); err != nil {
err = gerror.Wrap(err, "删除CURD列表失败请稍后重试")
return
@@ -200,6 +192,18 @@ func (s *sSysCurdDemo) View(ctx context.Context, in *sysin.CurdDemoViewInp) (res
return
}
// Status 更新CURD列表状态
func (s *sSysCurdDemo) Status(ctx context.Context, in *sysin.CurdDemoStatusInp) (err error) {
if _, err = s.Model(ctx).WherePri(in.Id).Data(g.Map{
dao.SysGenCurdDemo.Columns().Status: in.Status,
dao.SysGenCurdDemo.Columns().UpdatedBy: contexts.GetUserId(ctx),
}).Update(); err != nil {
err = gerror.Wrap(err, "更新CURD列表状态失败请稍后重试")
return
}
return
}
// Switch 更新CURD列表开关
func (s *sSysCurdDemo) Switch(ctx context.Context, in *sysin.CurdDemoSwitchInp) (err error) {
var fields = []string{
@@ -220,4 +224,4 @@ func (s *sSysCurdDemo) Switch(ctx context.Context, in *sysin.CurdDemoSwitchInp)
return
}
return
}
}

View File

@@ -186,7 +186,7 @@ func (s *sSysEmsLog) Send(ctx context.Context, in *sysin.SendEmsInp) (err error)
data.Content = in.Content
data.Code = in.Code
data.Ip = location.GetClientIp(ghttp.RequestFromCtx(ctx))
data.Status = consts.EmsStatusNotUsed
data.Status = consts.CodeStatusNotUsed
data.CreatedAt = gtime.Now()
data.UpdatedAt = gtime.Now()
@@ -395,7 +395,7 @@ func (s *sSysEmsLog) VerifyCode(ctx context.Context, in *sysin.VerifyEmsCodeInp)
}
if in.Event != consts.EmsTemplateCode {
if models.Status == consts.EmsStatusUsed {
if models.Status == consts.CodeStatusUsed {
err = gerror.New("验证码已使用,请重新发送!")
return
}
@@ -414,7 +414,7 @@ func (s *sSysEmsLog) VerifyCode(ctx context.Context, in *sysin.VerifyEmsCodeInp)
_, err = dao.SysEmsLog.Ctx(ctx).Where("id", models.Id).Data(g.Map{
"times": models.Times + 1,
"status": consts.EmsStatusUsed,
"status": consts.CodeStatusUsed,
"updated_at": gtime.Now(),
}).Update()
return

View File

@@ -17,6 +17,7 @@ import (
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gmode"
"hotgo/internal/consts"
"hotgo/internal/dao"
"hotgo/internal/global"
@@ -226,7 +227,7 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
takeUpTime = tt
}
headerData.MustSet("qqq", request.EnterTime.String())
headerData.MustAppend("Enter-Time", request.EnterTime.String())
data = entity.SysLog{
AppId: appId,
@@ -237,7 +238,7 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
Url: request.URL.Path,
GetData: getData,
PostData: postData,
HeaderData: headerData,
HeaderData: s.SimplifyHeaderParams(headerData),
Ip: clientIp,
ProvinceId: ipData.ProvinceCode,
CityId: ipData.CityCode,
@@ -255,6 +256,21 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
return data
}
// SimplifyHeaderParams 过滤掉请求头中的大参数
func (s *sSysLog) SimplifyHeaderParams(data *gjson.Json) *gjson.Json {
if data == nil || data.IsNil() {
return data
}
var filters = []string{"Accept", "Authorization", "Cookie"}
for _, filter := range filters {
v := data.Get(filter)
if len(v.String()) > 128 {
data.MustRemove(filter)
}
}
return data
}
// View 获取指定请求日志信息
func (s *sSysLog) View(ctx context.Context, in *sysin.LogViewInp) (res *sysin.LogViewModel, err error) {
mod := s.Model(ctx)
@@ -350,7 +366,18 @@ func (s *sSysLog) List(ctx context.Context, in *sysin.LogListInp) (list []*sysin
// 请求耗时
if dict.HasOptionKey(consts.HTTPHandlerTimeOptions, in.TakeUpTime) {
mod = mod.Where(fmt.Sprintf("`take_up_time` %v", in.TakeUpTime))
mod = mod.Where(gdb.Raw(fmt.Sprintf("(`take_up_time` %v)", in.TakeUpTime)))
}
// 非生产环境,允许关键词查询日志
// 生成环境使用需谨慎,日志量大易产生慢日志
if !gmode.IsProduct() && in.Keyword != "" {
mod = mod.Where("(`get_data` LIKE '%" +
in.Keyword + "%' or `post_data` LIKE '%" +
in.Keyword + "%' or `header_data` LIKE '%" +
in.Keyword + "%' or `error_data` LIKE '%" +
in.Keyword + "%' or `error_msg` LIKE '%" +
in.Keyword + "%')")
}
totalCount, err = mod.Count()

View File

@@ -3,7 +3,7 @@
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.13.1
// @AutoGenerate Version 2.15.1
package sys
import (
@@ -173,4 +173,4 @@ func (s *sSysNormalTreeDemo) TreeOption(ctx context.Context) (nodes []tree.Node,
nodes[i] = v
}
return tree.ListToTree(0, nodes)
}
}

View File

@@ -3,7 +3,7 @@
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.13.1
// @AutoGenerate Version 2.15.1
package sys
import (
@@ -173,4 +173,4 @@ func (s *sSysOptionTreeDemo) TreeOption(ctx context.Context) (nodes []tree.Node,
nodes[i] = v
}
return tree.ListToTree(0, nodes)
}
}

View File

@@ -11,6 +11,7 @@ import (
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gmode"
"hotgo/internal/dao"
"hotgo/internal/library/hgorm"
"hotgo/internal/library/hgorm/handler"
@@ -46,6 +47,12 @@ func (s *sSysServeLog) List(ctx context.Context, in *sysin.ServeLogListInp) (lis
mod = mod.Where(dao.SysServeLog.Columns().TraceId, in.TraceId)
}
// 非生产环境,允许关键词查询日志
// 生成环境使用需谨慎,日志量大易产生慢日志
if !gmode.IsProduct() && in.Content != "" {
mod = mod.WhereLike(dao.SysServeLog.Columns().Content, "%"+in.Content+"%")
}
// 查询日志级别
if in.LevelFormat != "" {
mod = mod.WhereLike(dao.SysServeLog.Columns().LevelFormat, in.LevelFormat)

View File

@@ -134,7 +134,7 @@ func (s *sSysSmsLog) SendCode(ctx context.Context, in *sysin.SendCodeInp) (err e
data.Mobile = in.Mobile
data.Code = in.Code
data.Ip = location.GetClientIp(ghttp.RequestFromCtx(ctx))
data.Status = consts.SmsStatusNotUsed
data.Status = consts.CodeStatusNotUsed
data.CreatedAt = gtime.Now()
data.UpdatedAt = gtime.Now()
@@ -261,7 +261,7 @@ func (s *sSysSmsLog) VerifyCode(ctx context.Context, in *sysin.VerifyCodeInp) (e
}
if in.Event != consts.SmsTemplateCode {
if models.Status == consts.SmsStatusUsed {
if models.Status == consts.CodeStatusUsed {
err = gerror.New("验证码已使用,请重新发送!")
return
}
@@ -280,7 +280,7 @@ func (s *sSysSmsLog) VerifyCode(ctx context.Context, in *sysin.VerifyCodeInp) (e
_, err = dao.SysSmsLog.Ctx(ctx).WherePri(models.Id).Data(g.Map{
cols.Times: models.Times + 1,
cols.Status: consts.SmsStatusUsed,
cols.Status: consts.CodeStatusUsed,
cols.UpdatedAt: gtime.Now(),
}).Update()
return

View File

@@ -3,7 +3,7 @@
// @Copyright Copyright (c) 2024 HotGo CLI
// @Author Ms <133814250@qq.com>
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.13.1
// @AutoGenerate Version 2.15.1
package sys
import (
@@ -84,6 +84,7 @@ func (s *sSysTestCategory) List(ctx context.Context, in *sysin.TestCategoryListI
// Edit 修改/新增测试分类
func (s *sSysTestCategory) Edit(ctx context.Context, in *sysin.TestCategoryEditInp) (err error) {
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
// 修改
if in.Id > 0 {
if _, err = s.Model(ctx).
@@ -106,6 +107,7 @@ func (s *sSysTestCategory) Edit(ctx context.Context, in *sysin.TestCategoryEditI
// Delete 删除测试分类
func (s *sSysTestCategory) Delete(ctx context.Context, in *sysin.TestCategoryDeleteInp) (err error) {
if _, err = s.Model(ctx).WherePri(in.Id).Delete(); err != nil {
err = gerror.Wrap(err, "删除测试分类失败,请稍后重试!")
return
@@ -162,4 +164,4 @@ func (s *sSysTestCategory) Option(ctx context.Context) (opts []*model.Option, er
opts[k] = dict.GenHashOption(v.Id, gconv.String(v.Name))
}
return
}
}

View File

@@ -12,7 +12,7 @@ import (
// DefaultInterceptor 默认拦截器
func (s *sCronClient) DefaultInterceptor(ctx context.Context, msg *tcp.Message) (err error) {
// conn := tcp.ConnFromCtx(ctx)
// g.Log().Debugf(ctx, "DefaultInterceptor msg:%+v, conn:%+v", msg, gjson.New(conn).String())
//conn := tcp.ConnFromCtx(ctx)
//g.Log().Warningf(ctx, "DefaultInterceptor msg:%+v, conn:%+v", msg, gjson.New(conn).String())
return
}