mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 05:12:32 +08:00
发布代码生成、更新20+表单组件,优化数据字典,gf版本更新到2.3.1
This commit is contained in:
@@ -16,8 +16,8 @@ import (
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/format"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sSysAttachment struct{}
|
||||
@@ -82,7 +82,7 @@ func (s *sSysAttachment) Status(ctx context.Context, in sysin.AttachmentStatusIn
|
||||
return err
|
||||
}
|
||||
|
||||
if !convert.InSliceInt(consts.StatusMap, in.Status) {
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (s *sSysAttachment) View(ctx context.Context, in sysin.AttachmentViewInp) (
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysAttachment) List(ctx context.Context, in sysin.AttachmentListInp) (list []*sysin.AttachmentListModel, totalCount int64, err error) {
|
||||
func (s *sSysAttachment) List(ctx context.Context, in sysin.AttachmentListInp) (list []*sysin.AttachmentListModel, totalCount int, err error) {
|
||||
mod := dao.SysAttachment.Ctx(ctx)
|
||||
|
||||
// 访问路径
|
||||
@@ -152,14 +152,18 @@ func (s *sSysAttachment) List(ctx context.Context, in sysin.AttachmentListInp) (
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("updated_at desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
conf, err := service.SysConfig().GetUpload(ctx)
|
||||
if err != nil {
|
||||
return list, totalCount, err
|
||||
}
|
||||
for _, v := range list {
|
||||
v.SizeFormat = format.FileSize(v.Size)
|
||||
v.FileUrl = service.CommonUpload().LastUrl(ctx, v.FileUrl, consts.UploadDriveLocal)
|
||||
v.FileUrl = service.CommonUpload().LastUrl(ctx, conf, v.FileUrl, v.Drive)
|
||||
}
|
||||
|
||||
return list, totalCount, err
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sSysBlacklist struct{}
|
||||
@@ -79,7 +79,7 @@ func (s *sSysBlacklist) Status(ctx context.Context, in sysin.BlacklistStatusInp)
|
||||
return err
|
||||
}
|
||||
|
||||
if !convert.InSliceInt(consts.StatusMap, in.Status) {
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
@@ -118,7 +118,7 @@ func (s *sSysBlacklist) View(ctx context.Context, in sysin.BlacklistViewInp) (re
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysBlacklist) List(ctx context.Context, in sysin.BlacklistListInp) (list []*sysin.BlacklistListModel, totalCount int64, err error) {
|
||||
func (s *sSysBlacklist) List(ctx context.Context, in sysin.BlacklistListInp) (list []*sysin.BlacklistListModel, totalCount int, err error) {
|
||||
mod := dao.SysBlacklist.Ctx(ctx)
|
||||
|
||||
// 访问路径
|
||||
@@ -141,7 +141,7 @@ func (s *sSysBlacklist) List(ctx context.Context, in sysin.BlacklistListInp) (li
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
@@ -32,6 +32,55 @@ func init() {
|
||||
service.RegisterSysConfig(NewSysConfig())
|
||||
}
|
||||
|
||||
// GetLoadGenerate 获取本地生成配置
|
||||
func (s *sSysConfig) GetLoadGenerate(ctx context.Context) (conf *model.GenerateConfig, err error) {
|
||||
generate := g.Cfg().MustGet(ctx, "hggen")
|
||||
if err = gconv.Struct(generate, &conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetSms 获取短信配置
|
||||
func (s *sSysConfig) GetSms(ctx context.Context) (conf *model.SmsConfig, err error) {
|
||||
models, err := s.GetConfigByGroup(ctx, sysin.GetConfigInp{Group: "sms"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = gconv.Struct(models.List, &conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetGeo 获取地理配置
|
||||
func (s *sSysConfig) GetGeo(ctx context.Context) (conf *model.GeoConfig, err error) {
|
||||
models, err := s.GetConfigByGroup(ctx, sysin.GetConfigInp{Group: "geo"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = gconv.Struct(models.List, &conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetUpload 获取上传配置
|
||||
func (s *sSysConfig) GetUpload(ctx context.Context) (conf *model.UploadConfig, err error) {
|
||||
models, err := s.GetConfigByGroup(ctx, sysin.GetConfigInp{Group: "upload"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = gconv.Struct(models.List, &conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetSmtp 获取邮件配置
|
||||
func (s *sSysConfig) GetSmtp(ctx context.Context) (conf *model.EmailConfig, err error) {
|
||||
models, err := s.GetConfigByGroup(ctx, sysin.GetConfigInp{Group: "smtp"})
|
||||
@@ -47,6 +96,22 @@ func (s *sSysConfig) GetSmtp(ctx context.Context) (conf *model.EmailConfig, err
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetLoadSSL 获取本地日志配置
|
||||
func (s *sSysConfig) GetLoadSSL(ctx context.Context) (conf *model.SSLConfig, err error) {
|
||||
if err = g.Cfg().MustGet(ctx, "hotgo.ssl").Struct(&conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetLoadLog 获取本地日志配置
|
||||
func (s *sSysConfig) GetLoadLog(ctx context.Context) (conf *model.LogConfig, err error) {
|
||||
if err = g.Cfg().MustGet(ctx, "hotgo.log").Struct(&conf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// GetConfigByGroup 获取指定分组的配置
|
||||
func (s *sSysConfig) GetConfigByGroup(ctx context.Context, in sysin.GetConfigInp) (*sysin.GetConfigModel, error) {
|
||||
if in.Group == "" {
|
||||
@@ -60,7 +125,7 @@ func (s *sSysConfig) GetConfigByGroup(ctx context.Context, in sysin.GetConfigInp
|
||||
if err := mod.Fields("key", "value", "type").Where("group", in.Group).Scan(&models); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
isDemo, _ := g.Cfg().Get(ctx, "hotgo.isDemo", false)
|
||||
isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false)
|
||||
|
||||
if len(models) > 0 {
|
||||
res.List = make(g.Map, len(models))
|
||||
@@ -84,19 +149,7 @@ func (s *sSysConfig) ConversionType(ctx context.Context, models *entity.SysConfi
|
||||
if models == nil {
|
||||
return nil, gerror.New("数据不存在")
|
||||
}
|
||||
|
||||
switch models.Type {
|
||||
case consts.ConfigTypeInt:
|
||||
value = gconv.Int64(models.Value)
|
||||
return
|
||||
case consts.ConfigTypeBool:
|
||||
value = gconv.Bool(models.Value)
|
||||
return
|
||||
default:
|
||||
value = gconv.String(models.Value)
|
||||
}
|
||||
|
||||
return value, nil
|
||||
return consts.ConvType(models.Value, models.Type), nil
|
||||
}
|
||||
|
||||
// UpdateConfigByGroup 更新指定分组的配置
|
||||
@@ -112,7 +165,7 @@ func (s *sSysConfig) UpdateConfigByGroup(ctx context.Context, in sysin.UpdateCon
|
||||
return err
|
||||
}
|
||||
|
||||
err := dao.SysConfig.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
|
||||
err := dao.SysConfig.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
for k, v := range in.List {
|
||||
row := s.getConfigByKey(k, models)
|
||||
// 新增
|
||||
|
@@ -17,7 +17,7 @@ import (
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sSysCron struct{}
|
||||
@@ -103,7 +103,7 @@ func (s *sSysCron) Status(ctx context.Context, in sysin.CronStatusInp) (err erro
|
||||
return err
|
||||
}
|
||||
|
||||
if !convert.InSliceInt(consts.StatusMap, in.Status) {
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func (s *sSysCron) View(ctx context.Context, in sysin.CronViewInp) (res *sysin.C
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysCron) List(ctx context.Context, in sysin.CronListInp) (list []*sysin.CronListModel, totalCount int64, err error) {
|
||||
func (s *sSysCron) List(ctx context.Context, in sysin.CronListInp) (list []*sysin.CronListModel, totalCount int, err error) {
|
||||
mod := dao.SysCron.Ctx(ctx)
|
||||
|
||||
// 访问路径
|
||||
@@ -170,7 +170,7 @@ func (s *sSysCron) List(ctx context.Context, in sysin.CronListInp) (list []*sysi
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ import (
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/tree"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sSysCronGroup struct{}
|
||||
@@ -82,7 +82,7 @@ func (s *sSysCronGroup) Status(ctx context.Context, in sysin.CronGroupStatusInp)
|
||||
return err
|
||||
}
|
||||
|
||||
if !convert.InSliceInt(consts.StatusMap, in.Status) {
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (s *sSysCronGroup) View(ctx context.Context, in sysin.CronGroupViewInp) (re
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysCronGroup) List(ctx context.Context, in sysin.CronGroupListInp) (list []*sysin.CronGroupListModel, totalCount int64, err error) {
|
||||
func (s *sSysCronGroup) List(ctx context.Context, in sysin.CronGroupListInp) (list []*sysin.CronGroupListModel, totalCount int, err error) {
|
||||
mod := dao.SysCronGroup.Ctx(ctx)
|
||||
|
||||
// 访问路径
|
||||
@@ -148,7 +148,7 @@ func (s *sSysCronGroup) List(ctx context.Context, in sysin.CronGroupListInp) (li
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
242
server/internal/logic/sys/curd_demo.go
Normal file
242
server/internal/logic/sys/curd_demo.go
Normal file
@@ -0,0 +1,242 @@
|
||||
// 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
|
||||
// @AutoGenerate Version 2.1.0
|
||||
// @AutoGenerate Date 2023-01-18 15:19:42
|
||||
//
|
||||
package sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/hgorm"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/excel"
|
||||
"hotgo/utility/validate"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
type sSysCurdDemo struct{}
|
||||
|
||||
func NewSysCurdDemo() *sSysCurdDemo {
|
||||
return &sSysCurdDemo{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysCurdDemo(NewSysCurdDemo())
|
||||
}
|
||||
|
||||
// Model 生成演示Orm模型
|
||||
func (s *sSysCurdDemo) Model(ctx context.Context) *gdb.Model {
|
||||
return dao.SysGenCurdDemo.Ctx(ctx)
|
||||
}
|
||||
|
||||
// List 获取生成演示列表
|
||||
func (s *sSysCurdDemo) List(ctx context.Context, in sysin.CurdDemoListInp) (list []*sysin.CurdDemoListModel, totalCount int, err error) {
|
||||
mod := dao.SysGenCurdDemo.Ctx(ctx)
|
||||
|
||||
// 查询ID
|
||||
if in.Id > 0 {
|
||||
mod = mod.Where(dao.SysGenCurdDemo.Columns().Id, in.Id)
|
||||
}
|
||||
|
||||
// 查询状态
|
||||
if in.Status > 0 {
|
||||
mod = mod.Where(dao.SysGenCurdDemo.Columns().Status, in.Status)
|
||||
}
|
||||
|
||||
// 查询创建时间
|
||||
if len(in.CreatedAt) == 2 {
|
||||
mod = mod.WhereBetween(dao.SysGenCurdDemo.Columns().CreatedAt, in.CreatedAt[0], in.CreatedAt[1])
|
||||
}
|
||||
|
||||
// 查询分类名称
|
||||
if in.TestCategoryName != "" {
|
||||
mod = mod.WhereLike(dao.TestCategory.Columns().Name, in.TestCategoryName)
|
||||
}
|
||||
|
||||
// 关联表testCategory
|
||||
mod = mod.LeftJoin(hgorm.GenJoinOnRelation(
|
||||
dao.SysGenCurdDemo.Table(), dao.SysGenCurdDemo.Columns().CategoryId, // 主表表名,关联条件
|
||||
dao.TestCategory.Table(), "testCategory", dao.TestCategory.Columns().Id, // 关联表表名,别名,关联条件
|
||||
)...)
|
||||
|
||||
totalCount, err = mod.Clone().Count(1)
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
if totalCount == 0 {
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
//关联表select
|
||||
fields, err := hgorm.GenJoinSelect(ctx, sysin.CurdDemoListModel{}, dao.SysGenCurdDemo, []*hgorm.Join{
|
||||
{Dao: dao.TestCategory, Alias: "testCategory"},
|
||||
})
|
||||
if err = mod.Fields(fields).Handler(hgorm.HandlerFilterAuth).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 list, totalCount, err
|
||||
}
|
||||
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
// Export 导出生成演示
|
||||
func (s *sSysCurdDemo) Export(ctx context.Context, in sysin.CurdDemoListInp) (err error) {
|
||||
list, totalCount, err := s.List(ctx, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...}
|
||||
tags, err := convert.GetEntityDescTags(sysin.CurdDemoExportModel{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
fileName = "导出生成演示-" + gctx.CtxId(ctx) + ".xlsx"
|
||||
sheetName = fmt.Sprintf("索引条件共%v行,共%v页,当前导出是第%v页,本页共%v行", totalCount, form.CalPageCount(totalCount, in.PerPage), in.Page, len(list))
|
||||
exports []sysin.CurdDemoExportModel
|
||||
)
|
||||
|
||||
err = gconv.Scan(list, &exports)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 修改/新增生成演示
|
||||
func (s *sSysCurdDemo) Edit(ctx context.Context, in sysin.CurdDemoEditInp) (err error) {
|
||||
// 修改
|
||||
if in.Id > 0 {
|
||||
in.UpdatedBy = contexts.GetUserId(ctx)
|
||||
_, err = dao.SysGenCurdDemo.Ctx(ctx).
|
||||
FieldsEx(
|
||||
dao.SysGenCurdDemo.Columns().Id,
|
||||
dao.SysGenCurdDemo.Columns().CreatedBy,
|
||||
dao.SysGenCurdDemo.Columns().CreatedAt,
|
||||
dao.SysGenCurdDemo.Columns().DeletedAt,
|
||||
).
|
||||
Where(dao.SysGenCurdDemo.Columns().Id, in.Id).Data(in).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 新增
|
||||
in.CreatedBy = contexts.GetUserId(ctx)
|
||||
_, err = dao.SysGenCurdDemo.Ctx(ctx).
|
||||
FieldsEx(
|
||||
dao.SysGenCurdDemo.Columns().Id,
|
||||
dao.SysGenCurdDemo.Columns().UpdatedBy,
|
||||
dao.SysGenCurdDemo.Columns().DeletedAt,
|
||||
).
|
||||
Data(in).Insert()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除生成演示
|
||||
func (s *sSysCurdDemo) Delete(ctx context.Context, in sysin.CurdDemoDeleteInp) (err error) {
|
||||
_, err = dao.SysGenCurdDemo.Ctx(ctx).Where(dao.SysGenCurdDemo.Columns().Id, in.Id).Delete()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 nil, err
|
||||
}
|
||||
|
||||
res.Sort = res.Sort + g.Cfg().MustGet(ctx, "hotgo.admin.maxSortIncrement").Int()
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// View 获取生成演示指定信息
|
||||
func (s *sSysCurdDemo) View(ctx context.Context, in sysin.CurdDemoViewInp) (res *sysin.CurdDemoViewModel, err error) {
|
||||
if err = dao.SysGenCurdDemo.Ctx(ctx).Where(dao.SysGenCurdDemo.Columns().Id, in.Id).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Status 更新生成演示状态
|
||||
func (s *sSysCurdDemo) Status(ctx context.Context, in sysin.CurdDemoStatusInp) (err error) {
|
||||
if in.Id <= 0 {
|
||||
err = gerror.New("ID不能为空")
|
||||
return err
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return err
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = dao.SysGenCurdDemo.Ctx(ctx).Where(dao.SysGenCurdDemo.Columns().Id, in.Id).Data(dao.SysGenCurdDemo.Columns().Status, in.Status).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Switch 更新生成演示开关
|
||||
func (s *sSysCurdDemo) Switch(ctx context.Context, in sysin.CurdDemoSwitchInp) (err error) {
|
||||
var fields = []string{
|
||||
dao.SysGenCurdDemo.Columns().Switch,
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
if !validate.InSliceString(fields, in.Key) {
|
||||
err = gerror.New("开关键名不在白名单")
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = dao.SysGenCurdDemo.Ctx(ctx).Where(dao.SysGenCurdDemo.Columns().Id, in.Id).Data(in.Key, in.Value).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@@ -82,7 +82,7 @@ func (s *sSysDictData) Edit(ctx context.Context, in sysin.DictDataEditInp) (err
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysDictData) List(ctx context.Context, in sysin.DictDataListInp) (list []*sysin.DictDataListModel, totalCount int64, err error) {
|
||||
func (s *sSysDictData) List(ctx context.Context, in sysin.DictDataListInp) (list []*sysin.DictDataListModel, totalCount int, err error) {
|
||||
mod := dao.SysDictData.Ctx(ctx)
|
||||
// 类型ID
|
||||
if in.TypeID > 0 {
|
||||
@@ -117,7 +117,7 @@ func (s *sSysDictData) List(ctx context.Context, in sysin.DictDataListInp) (list
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("sort asc,id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
@@ -128,3 +128,22 @@ func (s *sSysDictData) List(ctx context.Context, in sysin.DictDataListInp) (list
|
||||
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
// Select 获取列表
|
||||
func (s *sSysDictData) Select(ctx context.Context, in sysin.DataSelectInp) (list sysin.DataSelectModel, err error) {
|
||||
mod := dao.SysDictData.Ctx(ctx).Where("type", in.Type)
|
||||
if in.Type != "" {
|
||||
mod = mod.Where("type", in.Type)
|
||||
}
|
||||
|
||||
if err = mod.Order("sort asc,id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, err
|
||||
}
|
||||
|
||||
for k, v := range list {
|
||||
list[k].Value = consts.ConvType(v.Value, v.ValueType)
|
||||
list[k].Key = list[k].Value
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
|
@@ -171,3 +171,40 @@ func (s *sSysDictType) Select(ctx context.Context, in sysin.DictTypeSelectInp) (
|
||||
|
||||
return tree.GenTree(typeList), nil
|
||||
}
|
||||
|
||||
// TreeSelect 获取类型关系树选项
|
||||
func (s *sSysDictType) TreeSelect(ctx context.Context, in sysin.DictTreeSelectInp) (list sysin.DictTreeSelectModel, err error) {
|
||||
var (
|
||||
mod = dao.SysDictType.Ctx(ctx)
|
||||
models []*entity.SysDictType
|
||||
typeList []g.Map
|
||||
)
|
||||
|
||||
if err = mod.Order("pid asc,sort asc").Scan(&models); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, err
|
||||
}
|
||||
|
||||
for i := 0; i < len(models); i++ {
|
||||
typeList = append(typeList, g.Map{
|
||||
"index": models[i].Id,
|
||||
"key": models[i].Id,
|
||||
"label": models[i].Name,
|
||||
"id": models[i].Id,
|
||||
"pid": models[i].Pid,
|
||||
"name": models[i].Name,
|
||||
"sort": models[i].Sort,
|
||||
"created_at": models[i].CreatedAt,
|
||||
"status": models[i].Status,
|
||||
})
|
||||
}
|
||||
|
||||
maps := tree.GenTree(typeList)
|
||||
for _, v := range maps {
|
||||
// 父类一律禁止选中
|
||||
if _, ok := v["children"]; ok {
|
||||
v["disabled"] = true
|
||||
}
|
||||
}
|
||||
return tree.GenTree(typeList), nil
|
||||
}
|
||||
|
259
server/internal/logic/sys/gen_codes.go
Normal file
259
server/internal/logic/sys/gen_codes.go
Normal file
@@ -0,0 +1,259 @@
|
||||
// Package sys
|
||||
// @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 sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"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/library/hggen"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sSysGenCodes struct{}
|
||||
|
||||
func NewSysGenCodes() *sSysGenCodes {
|
||||
return &sSysGenCodes{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysGenCodes(NewSysGenCodes())
|
||||
}
|
||||
|
||||
// Delete 删除
|
||||
func (s *sSysGenCodes) Delete(ctx context.Context, in sysin.GenCodesDeleteInp) error {
|
||||
_, err := dao.SysGenCodes.Ctx(ctx).Where("id", in.Id).Delete()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Edit 修改/新增
|
||||
func (s *sSysGenCodes) Edit(ctx context.Context, in sysin.GenCodesEditInp) (res *sysin.GenCodesEditModel, err error) {
|
||||
if in.GenType == 0 {
|
||||
err = gerror.New("生成类型不能为空")
|
||||
return nil, err
|
||||
}
|
||||
if in.VarName == "" {
|
||||
err = gerror.New("实体名称不能为空")
|
||||
return nil, err
|
||||
}
|
||||
// 修改
|
||||
in.UpdatedAt = gtime.Now()
|
||||
if in.Id > 0 {
|
||||
_, err = dao.SysGenCodes.Ctx(ctx).Where("id", in.Id).Data(in).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
return &sysin.GenCodesEditModel{SysGenCodes: in.SysGenCodes}, nil
|
||||
}
|
||||
|
||||
// 新增
|
||||
if in.Options.IsNil() {
|
||||
in.Options = gjson.New(consts.NilJsonToString)
|
||||
}
|
||||
|
||||
in.MasterColumns = gjson.New("[]")
|
||||
in.Status = consts.GenCodesStatusWait
|
||||
in.CreatedAt = gtime.Now()
|
||||
id, err := dao.SysGenCodes.Ctx(ctx).Data(in).InsertAndGetId()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
in.Id = id
|
||||
return &sysin.GenCodesEditModel{SysGenCodes: in.SysGenCodes}, nil
|
||||
}
|
||||
|
||||
// Status 更新部门状态
|
||||
func (s *sSysGenCodes) Status(ctx context.Context, in sysin.GenCodesStatusInp) (err error) {
|
||||
if in.Id <= 0 {
|
||||
err = gerror.New("ID不能为空")
|
||||
return err
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return err
|
||||
}
|
||||
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
|
||||
// 修改
|
||||
_, err = dao.SysGenCodes.Ctx(ctx).Where("id", in.Id).Data("status", in.Status).Update()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MaxSort 最大排序
|
||||
func (s *sSysGenCodes) MaxSort(ctx context.Context, in sysin.GenCodesMaxSortInp) (*sysin.GenCodesMaxSortModel, error) {
|
||||
var res sysin.GenCodesMaxSortModel
|
||||
if in.Id > 0 {
|
||||
if err := dao.SysGenCodes.Ctx(ctx).Where("id", in.Id).Order("sort desc").Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
res.Sort = res.Sort + 10
|
||||
return &res, nil
|
||||
}
|
||||
|
||||
// View 获取指定字典类型信息
|
||||
func (s *sSysGenCodes) View(ctx context.Context, in sysin.GenCodesViewInp) (res *sysin.GenCodesViewModel, err error) {
|
||||
if err = dao.SysGenCodes.Ctx(ctx).Where("id", in.Id).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysGenCodes) List(ctx context.Context, in sysin.GenCodesListInp) (list []*sysin.GenCodesListModel, totalCount int, err error) {
|
||||
mod := dao.SysGenCodes.Ctx(ctx)
|
||||
|
||||
if in.GenType > 0 {
|
||||
mod = mod.Where("gen_type", in.GenType)
|
||||
}
|
||||
|
||||
if in.VarName != "" {
|
||||
mod = mod.Where("var_name", in.VarName)
|
||||
}
|
||||
|
||||
if in.Status > 0 {
|
||||
mod = mod.Where("status", in.Status)
|
||||
}
|
||||
|
||||
totalCount, err = mod.Count()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
if totalCount == 0 {
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
// Selects 选项
|
||||
func (s *sSysGenCodes) Selects(ctx context.Context, in sysin.GenCodesSelectsInp) (res *sysin.GenCodesSelectsModel, err error) {
|
||||
return hggen.TableSelects(ctx, in)
|
||||
}
|
||||
|
||||
// TableSelect 表选项
|
||||
func (s *sSysGenCodes) TableSelect(ctx context.Context, in sysin.GenCodesTableSelectInp) (res []*sysin.GenCodesTableSelectModel, err error) {
|
||||
var (
|
||||
sql = "SELECT TABLE_NAME as value, TABLE_COMMENT as label FROM information_schema.`TABLES` WHERE TABLE_SCHEMA = '%s'"
|
||||
config = g.DB(in.Name).GetConfig()
|
||||
disableTables = g.Cfg().MustGet(ctx, "hggen.disableTables").Strings()
|
||||
lists []*sysin.GenCodesTableSelectModel
|
||||
)
|
||||
|
||||
err = g.DB(in.Name).Ctx(ctx).Raw(fmt.Sprintf(sql, config.Name)).Scan(&lists)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range lists {
|
||||
if gstr.InArray(disableTables, v.Value) {
|
||||
continue
|
||||
}
|
||||
|
||||
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.DefAlias = gstr.CaseCamelLower(gstr.SubStrFromEx(v.Value, config.Prefix))
|
||||
row.Name = fmt.Sprintf("%s (%s)", v.Value, v.Label)
|
||||
row.Label = row.Name
|
||||
res = append(res, row)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ColumnSelect 表字段选项
|
||||
func (s *sSysGenCodes) ColumnSelect(ctx context.Context, in sysin.GenCodesColumnSelectInp) (res []*sysin.GenCodesColumnSelectModel, err error) {
|
||||
var (
|
||||
sql = "select COLUMN_NAME as value,COLUMN_COMMENT as label from information_schema.COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'"
|
||||
config = g.DB(in.Name).GetConfig()
|
||||
)
|
||||
|
||||
err = g.DB(in.Name).Ctx(ctx).Raw(fmt.Sprintf(sql, config.Name, in.Table)).Scan(&res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
return nil, gerror.Newf("table does not exist:%v", in.Table)
|
||||
}
|
||||
|
||||
for k, v := range res {
|
||||
res[k].Name = fmt.Sprintf("%s (%s)", v.Value, v.Label)
|
||||
res[k].Label = res[k].Name
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ColumnList 表字段列表
|
||||
func (s *sSysGenCodes) ColumnList(ctx context.Context, in sysin.GenCodesColumnListInp) (res []*sysin.GenCodesColumnListModel, err error) {
|
||||
return hggen.TableColumns(ctx, in)
|
||||
}
|
||||
|
||||
// Preview 生成预览
|
||||
func (s *sSysGenCodes) Preview(ctx context.Context, in sysin.GenCodesPreviewInp) (res *sysin.GenCodesPreviewModel, err error) {
|
||||
return hggen.Preview(ctx, in)
|
||||
}
|
||||
|
||||
// Build 提交生成
|
||||
func (s *sSysGenCodes) Build(ctx context.Context, in sysin.GenCodesBuildInp) (err error) {
|
||||
// 先保存配置
|
||||
_, err = s.Edit(ctx, sysin.GenCodesEditInp{SysGenCodes: in.SysGenCodes})
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.Status(ctx, sysin.GenCodesStatusInp{Id: in.Id, Status: consts.GenCodesStatusOk})
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = hggen.Build(ctx, in); err != nil {
|
||||
_ = s.Status(ctx, sysin.GenCodesStatusInp{Id: in.Id, Status: consts.GenCodesStatusFail})
|
||||
return err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@@ -9,6 +9,7 @@ package sys
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
@@ -21,13 +22,11 @@ import (
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/location"
|
||||
"hotgo/internal/library/queue"
|
||||
"hotgo/internal/model"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/excel"
|
||||
"hotgo/utility/validate"
|
||||
"time"
|
||||
)
|
||||
|
||||
type sSysLog struct{}
|
||||
@@ -90,23 +89,10 @@ func (s *sSysLog) Export(ctx context.Context, in sysin.LogListInp) (err error) {
|
||||
exportList = append(exportList, row)
|
||||
}
|
||||
|
||||
// 强转类型
|
||||
writer := ghttp.RequestFromCtx(ctx).Response.Writer
|
||||
w, _ := interface{}(writer).(*ghttp.ResponseWriter)
|
||||
|
||||
if err = excel.ExportByStruct(w, titleList, gconv.Interfaces(exportList), fileName, sheetName); err != nil {
|
||||
err = gerror.Wrap(err, "ExportByStruct:")
|
||||
if err = excel.ExportByStructs(ctx, titleList, exportList, fileName, sheetName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 加入到上下文
|
||||
contexts.SetResponse(ctx, &model.Response{
|
||||
Code: consts.CodeOK,
|
||||
Message: "导出成功",
|
||||
Timestamp: time.Now().Unix(),
|
||||
TraceID: gctx.CtxId(ctx),
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -116,60 +102,42 @@ func (s *sSysLog) RealWrite(ctx context.Context, commonLog entity.SysLog) error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := result.LastInsertId(); err != nil {
|
||||
if _, err = result.LastInsertId(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AutoLog 根据配置自动记录请求日志
|
||||
func (s *sSysLog) AutoLog(ctx context.Context) (err error) {
|
||||
// 日志开关
|
||||
logSwitch, _ := g.Cfg().Get(ctx, "hotgo.log.switch", true)
|
||||
if !logSwitch.Bool() {
|
||||
config, err := service.SysConfig().GetLoadLog(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !config.Switch {
|
||||
return nil
|
||||
}
|
||||
|
||||
data := s.AnalysisLog(ctx)
|
||||
|
||||
// 判断模块是否需要记录
|
||||
module, _ := g.Cfg().Get(ctx, "hotgo.log.module", nil)
|
||||
if module == nil {
|
||||
return nil
|
||||
}
|
||||
if exist := validate.InSliceExistStr(module.Strings(), data.Module); !exist {
|
||||
if ok := validate.InSliceExistStr(config.Module, data.Module); !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 判断状态码是否需要记录
|
||||
code, _ := g.Cfg().Get(ctx, "hotgo.log.skipCode", nil)
|
||||
if code != nil {
|
||||
if exist := validate.InSliceExistStr(code.Strings(), gconv.String(data.ErrorCode)); exist {
|
||||
return nil
|
||||
}
|
||||
if ok := validate.InSliceExistStr(config.SkipCode, gconv.String(data.ErrorCode)); ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 是否开启队列
|
||||
queueSwitch, _ := g.Cfg().Get(ctx, "hotgo.log.queue", true)
|
||||
if queueSwitch.Bool() {
|
||||
// 获取生产者实例
|
||||
queueInstance, err := queue.InstanceProducer()
|
||||
if config.Queue {
|
||||
q, err := queue.InstanceProducer()
|
||||
if err != nil {
|
||||
queue.FatalLog(ctx, "InstanceProducer异常", err)
|
||||
queue.FatalLog(ctx, "queue.InstanceProducer err:%+v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 生产消息
|
||||
mqMsg, err := queueInstance.SendMsg(consts.QueueLogTopic, gconv.String(data))
|
||||
|
||||
// 记录生产日志
|
||||
mqMsg, err := q.SendMsg(consts.QueueLogTopic, gconv.String(data))
|
||||
queue.ProducerLog(ctx, consts.QueueLogTopic, mqMsg.MsgId, err)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return s.RealWrite(ctx, data)
|
||||
}
|
||||
|
||||
@@ -185,7 +153,6 @@ func (s *sSysLog) QueueJob(ctx context.Context, mqMsg queue.MqMsg) (err error) {
|
||||
|
||||
// AnalysisLog 解析日志数据
|
||||
func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
||||
|
||||
var (
|
||||
modelContext = contexts.Get(ctx)
|
||||
response = modelContext.Response
|
||||
@@ -193,15 +160,14 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
||||
request = ghttp.RequestFromCtx(ctx)
|
||||
module = modelContext.Module
|
||||
clientIp = request.GetClientIp()
|
||||
locationData = location.GetLocation(ctx, clientIp)
|
||||
postData = "{}"
|
||||
getData = "{}"
|
||||
headerData = "{}"
|
||||
postData = gjson.New(consts.NilJsonToString)
|
||||
getData = gjson.New(consts.NilJsonToString)
|
||||
headerData = gjson.New(consts.NilJsonToString)
|
||||
data = entity.SysLog{}
|
||||
memberId int64 = 0
|
||||
errorCode = 0
|
||||
errorMsg = ""
|
||||
errorData = "{}"
|
||||
errorData = gjson.New(consts.NilJsonToString)
|
||||
traceID = ""
|
||||
timestamp int64 = 0
|
||||
appId = ""
|
||||
@@ -214,23 +180,27 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
||||
traceID = response.TraceID
|
||||
timestamp = response.Timestamp
|
||||
if len(gconv.String(response.Error)) > 0 {
|
||||
errorData = gconv.String(response.Error)
|
||||
errorData = gjson.New(response.Error)
|
||||
}
|
||||
}
|
||||
|
||||
// 请求头
|
||||
if reqHeadersBytes, _ := json.Marshal(request.Header); len(gconv.String(reqHeadersBytes)) > 0 {
|
||||
headerData = gconv.String(reqHeadersBytes)
|
||||
headerData = gjson.New(reqHeadersBytes)
|
||||
}
|
||||
|
||||
// post参数
|
||||
if gconv.String(request.PostForm) != "" {
|
||||
postData = gconv.String(request.PostForm)
|
||||
postData = gjson.New(gconv.String(request.PostForm))
|
||||
}
|
||||
|
||||
if postData.IsNil() {
|
||||
postData = gjson.New(request.GetBodyString())
|
||||
}
|
||||
|
||||
// get参数
|
||||
if len(request.URL.Query()) > 0 {
|
||||
getData = gconv.String(request.URL.Query())
|
||||
getData = gjson.New(request.URL.Query())
|
||||
}
|
||||
|
||||
// 当前登录用户
|
||||
@@ -239,6 +209,25 @@ 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{
|
||||
AppId: appId,
|
||||
MerchantId: 0,
|
||||
@@ -250,8 +239,8 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
|
||||
PostData: postData,
|
||||
HeaderData: headerData,
|
||||
Ip: clientIp,
|
||||
ProvinceId: locationData.ProvinceCode,
|
||||
CityId: locationData.CityCode,
|
||||
ProvinceId: ipData.ProvinceCode,
|
||||
CityId: ipData.CityCode,
|
||||
ErrorCode: errorCode,
|
||||
ErrorMsg: errorMsg,
|
||||
ErrorData: errorData,
|
||||
@@ -271,13 +260,13 @@ func (s *sSysLog) View(ctx context.Context, in sysin.LogViewInp) (res *sysin.Log
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return nil, err
|
||||
}
|
||||
isDemo, _ := g.Cfg().Get(ctx, "hotgo.isDemo", false)
|
||||
isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false)
|
||||
if isDemo.Bool() {
|
||||
res.HeaderData = `{
|
||||
"none": [
|
||||
"` + consts.DemoTips + `"
|
||||
]
|
||||
}`
|
||||
// res.HeaderData = `{
|
||||
// "none": [
|
||||
// "` + consts.DemoTips + `"
|
||||
// ]
|
||||
//}`
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -293,7 +282,7 @@ func (s *sSysLog) Delete(ctx context.Context, in sysin.LogDeleteInp) error {
|
||||
}
|
||||
|
||||
// List 列表
|
||||
func (s *sSysLog) List(ctx context.Context, in sysin.LogListInp) (list []*sysin.LogListModel, totalCount int64, err error) {
|
||||
func (s *sSysLog) List(ctx context.Context, in sysin.LogListInp) (list []*sysin.LogListModel, totalCount int, err error) {
|
||||
mod := dao.SysLog.Ctx(ctx)
|
||||
|
||||
// 访问路径
|
||||
@@ -353,11 +342,11 @@ func (s *sSysLog) List(ctx context.Context, in sysin.LogListInp) (list []*sysin.
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
isDemo, _ := g.Cfg().Get(ctx, "hotgo.isDemo", false)
|
||||
isDemo := g.Cfg().MustGet(ctx, "hotgo.isDemo", false)
|
||||
for i := 0; i < len(list); i++ {
|
||||
// 管理员
|
||||
if list[i].AppId == consts.AppAdmin {
|
||||
@@ -394,11 +383,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 = `{
|
||||
// "none": [
|
||||
// "` + consts.DemoTips + `"
|
||||
// ]
|
||||
//}`
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ import (
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/validate"
|
||||
)
|
||||
|
||||
type sSysProvinces struct{}
|
||||
@@ -80,7 +80,7 @@ func (s *sSysProvinces) Status(ctx context.Context, in sysin.ProvincesStatusInp)
|
||||
return err
|
||||
}
|
||||
|
||||
if !convert.InSliceInt(consts.StatusMap, in.Status) {
|
||||
if !validate.InSliceInt(consts.StatusMap, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return err
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (s *sSysProvinces) View(ctx context.Context, in sysin.ProvincesViewInp) (re
|
||||
}
|
||||
|
||||
// List 获取列表
|
||||
func (s *sSysProvinces) List(ctx context.Context, in sysin.ProvincesListInp) (list []*sysin.ProvincesListModel, totalCount int64, err error) {
|
||||
func (s *sSysProvinces) List(ctx context.Context, in sysin.ProvincesListInp) (list []*sysin.ProvincesListModel, totalCount int, err error) {
|
||||
mod := dao.SysProvinces.Ctx(ctx)
|
||||
|
||||
// 访问路径
|
||||
@@ -146,7 +146,7 @@ func (s *sSysProvinces) List(ctx context.Context, in sysin.ProvincesListInp) (li
|
||||
return list, totalCount, nil
|
||||
}
|
||||
|
||||
if err = mod.Page(int(in.Page), int(in.PerPage)).Order("id desc").Scan(&list); err != nil {
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
return list, totalCount, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user