This commit is contained in:
2026-03-18 10:19:42 +08:00
parent 2526ad4414
commit e58dd3529d
267 changed files with 25279 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
/*
* @desc:缓存相关
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/9 11:25
*/
package consts
const (
// CachePrefix 应用缓存数据前缀
CachePrefix = "APP:"
CacheModelMem = "memory"
CacheModelRedis = "redis"
CacheModelDist = "dist"
// CacheSysDict 字典缓存菜单KEY
CacheSysDict = CachePrefix + "sysDict"
// CacheSysDictTag 字典缓存标签
CacheSysDictTag = CachePrefix + "sysDictTag"
// CacheSysConfigTag 系统参数配置
CacheSysConfigTag = CachePrefix + "sysConfigTag"
)

View File

@@ -0,0 +1,8 @@
/*
* @desc:常量
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/30 11:54
*/
package consts

View File

@@ -0,0 +1,11 @@
package consts
const (
UploadPath = "upload_file"
ImgTypeKey = "sys.uploadFile.imageType"
ImgSizeKey = "sys.uploadFile.imageSize"
FileTypeKey = "sys.uploadFile.fileType"
FileSizeKey = "sys.uploadFile.fileSize"
CheckFileTypeImg = "img" // 文件类型(图片)
CheckFileTypeFile = "file" // 文件类型(任意)
)

View File

@@ -0,0 +1,19 @@
/*
* @desc:
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/4 18:19
*/
package controller
import (
"github.com/gogf/gf/v2/net/ghttp"
)
type BaseController struct {
}
// Init 自动执行的初始化方法
func (c *BaseController) Init(r *ghttp.Request) {
}

View File

@@ -0,0 +1,32 @@
/*
* @desc:验证码获取
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/2 17:45
*/
package controller
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/common"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
)
var Captcha = captchaController{}
type captchaController struct {
}
// Get 获取验证码
func (c *captchaController) Get(ctx context.Context, req *common.CaptchaReq) (res *common.CaptchaRes, err error) {
var (
idKeyC, base64stringC string
)
idKeyC, base64stringC, err = service.Captcha().GetVerifyImgString(ctx)
res = &common.CaptchaRes{
Key: idKeyC,
Img: base64stringC,
}
return
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/common/dao/internal"
)
// casbinRuleDao is the data access object for table casbin_rule.
// You can define custom methods on it to extend its functionality as you wish.
type casbinRuleDao struct {
*internal.CasbinRuleDao
}
var (
// CasbinRule is globally public accessible object for table casbin_rule operations.
CasbinRule = casbinRuleDao{
internal.NewCasbinRuleDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,84 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// CasbinRuleDao is the data access object for table casbin_rule.
type CasbinRuleDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns CasbinRuleColumns // columns contains all the column names of Table for convenient usage.
}
// CasbinRuleColumns defines and stores column names for table casbin_rule.
type CasbinRuleColumns struct {
Ptype string //
V0 string //
V1 string //
V2 string //
V3 string //
V4 string //
V5 string //
}
// casbinRuleColumns holds the columns for table casbin_rule.
var casbinRuleColumns = CasbinRuleColumns{
Ptype: "ptype",
V0: "v0",
V1: "v1",
V2: "v2",
V3: "v3",
V4: "v4",
V5: "v5",
}
// NewCasbinRuleDao creates and returns a new DAO object for table data access.
func NewCasbinRuleDao() *CasbinRuleDao {
return &CasbinRuleDao{
group: "default",
table: "casbin_rule",
columns: casbinRuleColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *CasbinRuleDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *CasbinRuleDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *CasbinRuleDao) Columns() CasbinRuleColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *CasbinRuleDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *CasbinRuleDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *CasbinRuleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,90 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-18 21:09:17
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysConfigDao is the data access object for table sys_config.
type SysConfigDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysConfigColumns // columns contains all the column names of Table for convenient usage.
}
// SysConfigColumns defines and stores column names for table sys_config.
type SysConfigColumns struct {
ConfigId string // 参数主键
ConfigName string // 参数名称
ConfigKey string // 参数键名
ConfigValue string // 参数键值
ConfigType string // 系统内置Y是 N否
CreateBy string // 创建者
UpdateBy string // 更新者
Remark string // 备注
CreatedAt string // 创建时间
UpdatedAt string // 修改时间
}
// sysConfigColumns holds the columns for table sys_config.
var sysConfigColumns = SysConfigColumns{
ConfigId: "config_id",
ConfigName: "config_name",
ConfigKey: "config_key",
ConfigValue: "config_value",
ConfigType: "config_type",
CreateBy: "create_by",
UpdateBy: "update_by",
Remark: "remark",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewSysConfigDao creates and returns a new DAO object for table data access.
func NewSysConfigDao() *SysConfigDao {
return &SysConfigDao{
group: "default",
table: "sys_config",
columns: sysConfigColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysConfigDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysConfigDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysConfigDao) Columns() SysConfigColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysConfigDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysConfigDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysConfigDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,98 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-16 16:32:52
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysDictDataDao is the data access object for table sys_dict_data.
type SysDictDataDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysDictDataColumns // columns contains all the column names of Table for convenient usage.
}
// SysDictDataColumns defines and stores column names for table sys_dict_data.
type SysDictDataColumns struct {
DictCode string // 字典编码
DictSort string // 字典排序
DictLabel string // 字典标签
DictValue string // 字典键值
DictType string // 字典类型
CssClass string // 样式属性(其他样式扩展)
ListClass string // 表格回显样式
IsDefault string // 是否默认1是 0否
Status string // 状态0正常 1停用
CreateBy string // 创建者
UpdateBy string // 更新者
Remark string // 备注
CreatedAt string // 创建时间
UpdatedAt string // 修改时间
}
// sysDictDataColumns holds the columns for table sys_dict_data.
var sysDictDataColumns = SysDictDataColumns{
DictCode: "dict_code",
DictSort: "dict_sort",
DictLabel: "dict_label",
DictValue: "dict_value",
DictType: "dict_type",
CssClass: "css_class",
ListClass: "list_class",
IsDefault: "is_default",
Status: "status",
CreateBy: "create_by",
UpdateBy: "update_by",
Remark: "remark",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewSysDictDataDao creates and returns a new DAO object for table data access.
func NewSysDictDataDao() *SysDictDataDao {
return &SysDictDataDao{
group: "default",
table: "sys_dict_data",
columns: sysDictDataColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysDictDataDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysDictDataDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysDictDataDao) Columns() SysDictDataColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysDictDataDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysDictDataDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysDictDataDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,88 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-16 16:32:52
// ==========================================================================
package internal
import (
"context"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
)
// SysDictTypeDao is the data access object for table sys_dict_type.
type SysDictTypeDao struct {
table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of current DAO.
columns SysDictTypeColumns // columns contains all the column names of Table for convenient usage.
}
// SysDictTypeColumns defines and stores column names for table sys_dict_type.
type SysDictTypeColumns struct {
DictId string // 字典主键
DictName string // 字典名称
DictType string // 字典类型
Status string // 状态0正常 1停用
CreateBy string // 创建者
UpdateBy string // 更新者
Remark string // 备注
CreatedAt string // 创建日期
UpdatedAt string // 修改日期
}
// sysDictTypeColumns holds the columns for table sys_dict_type.
var sysDictTypeColumns = SysDictTypeColumns{
DictId: "dict_id",
DictName: "dict_name",
DictType: "dict_type",
Status: "status",
CreateBy: "create_by",
UpdateBy: "update_by",
Remark: "remark",
CreatedAt: "created_at",
UpdatedAt: "updated_at",
}
// NewSysDictTypeDao creates and returns a new DAO object for table data access.
func NewSysDictTypeDao() *SysDictTypeDao {
return &SysDictTypeDao{
group: "default",
table: "sys_dict_type",
columns: sysDictTypeColumns,
}
}
// DB retrieves and returns the underlying raw database management object of current DAO.
func (dao *SysDictTypeDao) DB() gdb.DB {
return g.DB(dao.group)
}
// Table returns the table name of current dao.
func (dao *SysDictTypeDao) Table() string {
return dao.table
}
// Columns returns all column names of current dao.
func (dao *SysDictTypeDao) Columns() SysDictTypeColumns {
return dao.columns
}
// Group returns the configuration group name of database of current dao.
func (dao *SysDictTypeDao) Group() string {
return dao.group
}
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
func (dao *SysDictTypeDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
}
// Transaction wraps the transaction logic using function f.
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
// It commits the transaction and returns nil if function f returns nil.
//
// Note that, you should not Commit or Rollback the transaction in function f
// as it is automatically handled by this function.
func (dao *SysDictTypeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
return dao.Ctx(ctx).Transaction(ctx, f)
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/common/dao/internal"
)
// sysConfigDao is the data access object for table sys_config.
// You can define custom methods on it to extend its functionality as you wish.
type sysConfigDao struct {
*internal.SysConfigDao
}
var (
// SysConfig is globally public accessible object for table sys_config operations.
SysConfig = sysConfigDao{
internal.NewSysConfigDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/common/dao/internal"
)
// sysDictDataDao is the data access object for table sys_dict_data.
// You can define custom methods on it to extend its functionality as you wish.
type sysDictDataDao struct {
*internal.SysDictDataDao
}
var (
// SysDictData is globally public accessible object for table sys_dict_data operations.
SysDictData = sysDictDataDao{
internal.NewSysDictDataDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,24 @@
// =================================================================================
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
// =================================================================================
package dao
import (
"github.com/tiger1103/gfast/v3/internal/app/common/dao/internal"
)
// sysDictTypeDao is the data access object for table sys_dict_type.
// You can define custom methods on it to extend its functionality as you wish.
type sysDictTypeDao struct {
*internal.SysDictTypeDao
}
var (
// SysDictType is globally public accessible object for table sys_dict_type operations.
SysDictType = sysDictTypeDao{
internal.NewSysDictTypeDao(),
}
)
// Fill with you ideas below.

View File

@@ -0,0 +1,45 @@
/*
* @desc:缓存处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/27 16:33
*/
package cache
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/tiger1103/gfast-cache/cache"
"github.com/tiger1103/gfast/v3/internal/app/common/consts"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
)
func init() {
service.RegisterCache(New())
}
func New() *sCache {
var (
ctx = gctx.New()
cacheContainer *cache.GfCache
)
prefix := g.Cfg().MustGet(ctx, "system.cache.prefix").String()
model := g.Cfg().MustGet(ctx, "system.cache.model").String()
if model == consts.CacheModelRedis {
// redis
cacheContainer = cache.NewRedis(prefix)
} else {
// memory
cacheContainer = cache.New(prefix)
}
return &sCache{
GfCache: cacheContainer,
prefix: prefix,
}
}
type sCache struct {
*cache.GfCache
prefix string
}

View File

@@ -0,0 +1,69 @@
/*
* @desc:验证码处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/28 9:01
*/
package captcha
import (
"context"
"github.com/gogf/gf/v2/text/gstr"
"github.com/mojocn/base64Captcha"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
)
func init() {
service.RegisterCaptcha(New())
}
func New() *sCaptcha {
return &sCaptcha{
driver: &base64Captcha.DriverString{
Height: 80,
Width: 240,
NoiseCount: 50,
ShowLineOptions: 20,
Length: 4,
Source: "abcdefghjkmnpqrstuvwxyz23456789",
Fonts: []string{"chromohv.ttf"},
},
store: base64Captcha.DefaultMemStore,
}
}
type sCaptcha struct {
driver *base64Captcha.DriverString
store base64Captcha.Store
}
var (
captcha = sCaptcha{
driver: &base64Captcha.DriverString{
Height: 80,
Width: 240,
NoiseCount: 50,
ShowLineOptions: 20,
Length: 4,
Source: "abcdefghjkmnpqrstuvwxyz23456789",
Fonts: []string{"chromohv.ttf"},
},
store: base64Captcha.DefaultMemStore,
}
)
// GetVerifyImgString 获取字母数字混合验证码
func (s *sCaptcha) GetVerifyImgString(ctx context.Context) (idKeyC string, base64stringC string, err error) {
driver := s.driver.ConvertFonts()
c := base64Captcha.NewCaptcha(driver, s.store)
idKeyC, base64stringC, _, err = c.Generate()
return
}
// VerifyString 验证输入的验证码是否正确
func (s *sCaptcha) VerifyString(id, answer string) bool {
c := base64Captcha.NewCaptcha(s.driver, s.store)
answer = gstr.ToLower(answer)
return c.Verify(id, answer, true)
}

View File

@@ -0,0 +1,17 @@
/**
* @Company: 云南奇讯科技有限公司
* @Author: yxf
* @Description:
* @Date: 2024/1/25 16:22
*/
package eventBus
import (
"github.com/asaskevich/EventBus"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
)
func init() {
service.RegisterEventBus(EventBus.New())
}

View File

@@ -0,0 +1,15 @@
// ==========================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// ==========================================================================
package logic
import (
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/cache"
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/captcha"
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/eventBus"
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/middleware"
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysConfig"
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysDictData"
_ "github.com/tiger1103/gfast/v3/internal/app/common/logic/sysDictType"
)

View File

@@ -0,0 +1,31 @@
/*
* @desc:中间件处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/28 9:08
*/
package middleware
import (
"github.com/gogf/gf/v2/net/ghttp"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
)
func init() {
service.RegisterMiddleware(New())
}
func New() *sMiddleware {
return &sMiddleware{}
}
type sMiddleware struct{}
func (s *sMiddleware) MiddlewareCORS(r *ghttp.Request) {
corsOptions := r.Response.DefaultCORSOptions()
// you can set options
//corsOptions.AllowDomain = []string{"goframe.org", "baidu.com"}
r.Response.CORS(corsOptions)
r.Middleware.Next()
}

View File

@@ -0,0 +1,178 @@
/*
* @desc:配置参数管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/28 9:13
*/
package sysConfig
import (
"context"
"errors"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/common/consts"
"github.com/tiger1103/gfast/v3/internal/app/common/dao"
"github.com/tiger1103/gfast/v3/internal/app/common/model/do"
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
systemConsts "github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysConfig(New())
}
func New() *sSysConfig {
return &sSysConfig{}
}
type sSysConfig struct {
}
// List 系统参数列表
func (s *sSysConfig) List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error) {
res = new(system.ConfigSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysConfig.Ctx(ctx)
if req != nil {
if req.ConfigName != "" {
m = m.Where("config_name like ?", "%"+req.ConfigName+"%")
}
if req.ConfigType != "" {
m = m.Where("config_type = ", gconv.Int(req.ConfigType))
}
if req.ConfigKey != "" {
m = m.Where("config_key like ?", "%"+req.ConfigKey+"%")
}
if len(req.DateRange) > 0 {
m = m.Where("created_at >= ? AND created_at<=?", req.DateRange[0], req.DateRange[1])
}
}
res.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取数据失败")
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = systemConsts.PageSize
}
err = m.Page(req.PageNum, req.PageSize).Order("config_id asc").Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取数据失败")
})
return
}
func (s *sSysConfig) Add(ctx context.Context, req *system.ConfigAddReq, userId uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = s.CheckConfigKeyUnique(ctx, req.ConfigKey)
liberr.ErrIsNil(ctx, err)
_, err = dao.SysConfig.Ctx(ctx).Insert(do.SysConfig{
ConfigName: req.ConfigName,
ConfigKey: req.ConfigKey,
ConfigValue: req.ConfigValue,
ConfigType: req.ConfigType,
CreateBy: userId,
Remark: req.Remark,
})
liberr.ErrIsNil(ctx, err, "添加系统参数失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysConfigTag)
})
return
}
// CheckConfigKeyUnique 验证参数键名是否存在
func (s *sSysConfig) CheckConfigKeyUnique(ctx context.Context, configKey string, configId ...int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
data := (*entity.SysConfig)(nil)
m := dao.SysConfig.Ctx(ctx).Fields(dao.SysConfig.Columns().ConfigId).Where(dao.SysConfig.Columns().ConfigKey, configKey)
if len(configId) > 0 {
m = m.Where(dao.SysConfig.Columns().ConfigId+" != ?", configId[0])
}
err = m.Scan(&data)
liberr.ErrIsNil(ctx, err, "校验失败")
if data != nil {
liberr.ErrIsNil(ctx, errors.New("参数键名重复"))
}
})
return
}
// Get 获取系统参数
func (s *sSysConfig) Get(ctx context.Context, id int) (res *system.ConfigGetRes, err error) {
res = new(system.ConfigGetRes)
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysConfig.Ctx(ctx).WherePri(id).Scan(&res.Data)
liberr.ErrIsNil(ctx, err, "获取系统参数失败")
})
return
}
// Edit 修改系统参数
func (s *sSysConfig) Edit(ctx context.Context, req *system.ConfigEditReq, userId uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = s.CheckConfigKeyUnique(ctx, req.ConfigKey, req.ConfigId)
liberr.ErrIsNil(ctx, err)
_, err = dao.SysConfig.Ctx(ctx).WherePri(req.ConfigId).Update(do.SysConfig{
ConfigName: req.ConfigName,
ConfigKey: req.ConfigKey,
ConfigValue: req.ConfigValue,
ConfigType: req.ConfigType,
UpdateBy: userId,
Remark: req.Remark,
})
liberr.ErrIsNil(ctx, err, "修改系统参数失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysConfigTag)
})
return
}
// Delete 删除系统参数
func (s *sSysConfig) Delete(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysConfig.Ctx(ctx).Delete(dao.SysConfig.Columns().ConfigId+" in (?)", ids)
liberr.ErrIsNil(ctx, err, "删除失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysConfigTag)
})
return
}
// GetConfigByKey 通过key获取参数从缓存获取
func (s *sSysConfig) GetConfigByKey(ctx context.Context, key string) (config *entity.SysConfig, err error) {
if key == "" {
err = gerror.New("参数key不能为空")
return
}
cache := service.Cache()
cf := cache.Get(ctx, consts.CacheSysConfigTag+key)
if cf != nil && !cf.IsEmpty() {
err = gconv.Struct(cf, &config)
return
}
config, err = s.GetByKey(ctx, key)
if err != nil {
return
}
if config != nil {
cache.Set(ctx, consts.CacheSysConfigTag+key, config, 0, consts.CacheSysConfigTag)
}
return
}
// GetByKey 通过key获取参数从数据库获取
func (s *sSysConfig) GetByKey(ctx context.Context, key string) (config *entity.SysConfig, err error) {
err = dao.SysConfig.Ctx(ctx).Where("config_key", key).Scan(&config)
if err != nil {
g.Log().Error(ctx, err)
err = gerror.New("获取配置失败")
}
return
}

View File

@@ -0,0 +1,279 @@
/*
* @desc:字典数据管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/28 9:22
*/
package sysDictData
import (
"context"
"errors"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/common/consts"
"github.com/tiger1103/gfast/v3/internal/app/common/dao"
"github.com/tiger1103/gfast/v3/internal/app/common/model"
"github.com/tiger1103/gfast/v3/internal/app/common/model/do"
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
systemConsts "github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysDictData(New())
}
func New() *sSysDictData {
return &sSysDictData{}
}
type sSysDictData struct {
}
// GetDictDataTree 根据备注查询返回树形结构
func (s *sSysDictData) GetDictDataTree(ctx context.Context, remark string) (res *system.GetDictTreeRes, err error) {
cache := service.Cache()
cacheKey := consts.CacheSysDict + "_" + remark
//从缓存获取
iDict := cache.GetOrSetFuncLock(ctx, cacheKey, func(ctx context.Context) (value interface{}, err error) {
err = g.Try(ctx, func(ctx context.Context) {
//从数据库获取
var list []*entity.SysDictType
//获取类型数据
err = dao.SysDictType.Ctx(ctx).Where(dao.SysDictType.Columns().Remark, remark).
Where(dao.SysDictType.Columns().Status, 1).Fields(model.DictTypeRes{}).Scan(&list)
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
if len(list) == 0 {
return
}
dict := &system.GetDictRes{}
err = dao.SysDictData.Ctx(ctx).Fields(model.DictDataRes{}).
Where(dao.SysDictData.Columns().Remark, remark).
Where(dao.SysDictData.Columns().Status, 1).
Order(dao.SysDictData.Columns().DictSort + " asc," +
dao.SysDictData.Columns().DictCode + " asc").
Scan(&dict.Values)
liberr.ErrIsNil(ctx, err, "获取字典数据失败")
// 构建树形结构
res = new(system.GetDictTreeRes)
for _, category := range list {
tree := new(system.GetDictRes)
dictType := &model.DictTypeRes{
DictName: category.DictName,
DictType: category.DictType,
Remark: category.Remark,
}
for _, v := range dict.Values {
if category.DictType == v.DictType {
dictData := &model.DictDataRes{
DictValue: v.DictValue,
DictLabel: v.DictLabel,
DictType: v.DictType,
Remark: v.Remark,
IsDefault: v.IsDefault,
}
tree.Values = append(tree.Values, dictData)
}
}
tree.Info = dictType
res.List = append(res.List, tree)
}
})
return
}, 0, consts.CacheSysDictTag)
if !iDict.IsEmpty() {
err = gconv.Struct(iDict, &res)
if err != nil {
return
}
}
return
}
// GetDictWithDataByType 通过字典键类型获取选项
func (s *sSysDictData) GetDictWithDataByType(ctx context.Context, req *system.GetDictReq) (dict *system.GetDictRes,
err error) {
dictType := req.DictType
defaultValue := req.DefaultValue
cache := service.Cache()
cacheKey := consts.CacheSysDict + "_" + dictType
//从缓存获取
iDict := cache.GetOrSetFuncLock(ctx, cacheKey, func(ctx context.Context) (value interface{}, err error) {
err = g.Try(ctx, func(ctx context.Context) {
//从数据库获取
dict = &system.GetDictRes{}
//获取类型数据
err = dao.SysDictType.Ctx(ctx).Where(dao.SysDictType.Columns().DictType, dictType).
Where(dao.SysDictType.Columns().Status, 1).Fields(model.DictTypeRes{}).Scan(&dict.Info)
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
if dict.Info == nil {
return
}
err = dao.SysDictData.Ctx(ctx).Fields(model.DictDataRes{}).
Where(dao.SysDictData.Columns().DictType, dictType).
Where(dao.SysDictData.Columns().Status, 1).
Order(dao.SysDictData.Columns().DictSort + " asc," +
dao.SysDictData.Columns().DictCode + " asc").
Scan(&dict.Values)
liberr.ErrIsNil(ctx, err, "获取字典数据失败")
})
value = dict
return
}, 0, consts.CacheSysDictTag)
if !iDict.IsEmpty() {
err = gconv.Struct(iDict, &dict)
if err != nil {
return
}
}
//设置给定的默认值
for _, v := range dict.Values {
if defaultValue != "" {
if gstr.Equal(defaultValue, v.DictValue) {
v.IsDefault = 1
} else {
v.IsDefault = 0
}
}
}
return
}
// List 获取字典数据
func (s *sSysDictData) List(ctx context.Context, req *system.DictDataSearchReq) (res *system.DictDataSearchRes, err error) {
res = new(system.DictDataSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysDictData.Ctx(ctx)
if req != nil {
if req.DictLabel != "" {
m = m.Where(dao.SysDictData.Columns().DictLabel+" like ?", "%"+req.DictLabel+"%")
}
if req.Status != "" {
m = m.Where(dao.SysDictData.Columns().Status+" = ", gconv.Int(req.Status))
}
if req.DictType != "" {
m = m.Where(dao.SysDictData.Columns().DictType+" = ?", req.DictType)
}
res.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取字典数据失败")
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
}
if req.PageSize == 0 {
req.PageSize = systemConsts.PageSize
}
err = m.Page(req.PageNum, req.PageSize).Order(dao.SysDictData.Columns().DictSort + " asc," +
dao.SysDictData.Columns().DictCode + " asc").Scan(&res.List)
liberr.ErrIsNil(ctx, err, "获取字典数据失败")
})
return
}
// IsExists 判断同一类型下字典名次和字典键值是否存在
func (s *sSysDictData) IsExists(ctx context.Context, dictType, dictLabel, dictValue string, dictCode ...int64) error {
return g.Try(ctx, func(ctx context.Context) {
var dictData []*entity.SysDictData
err := dao.SysDictData.Ctx(ctx).Where(dao.SysDictData.Columns().DictType, dictType).
Fields(dao.SysDictData.Columns().DictCode, dao.SysDictData.Columns().DictLabel, dao.SysDictData.Columns().DictValue).
Scan(&dictData)
liberr.ErrIsNil(ctx, err, "获取字典数据失败")
if dictData == nil {
return
}
if len(dictCode) > 0 {
for _, v := range dictData {
if v.DictLabel == gstr.Trim(dictLabel) && v.DictCode != dictCode[0] {
liberr.ErrIsNil(ctx, errors.New("字典名称已存在"))
}
if v.DictValue == dictValue && v.DictCode != dictCode[0] {
liberr.ErrIsNil(ctx, errors.New("字典键值已存在"))
}
}
} else {
for _, v := range dictData {
if v.DictLabel == gstr.Trim(dictLabel) {
liberr.ErrIsNil(ctx, errors.New("字典名称已存在"))
}
if v.DictValue == dictValue {
liberr.ErrIsNil(ctx, errors.New("字典键值已存在"))
}
}
}
})
}
func (s *sSysDictData) Add(ctx context.Context, req *system.DictDataAddReq, userId uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = s.IsExists(ctx, req.DictType, req.DictLabel, req.DictValue)
liberr.ErrIsNil(ctx, err)
_, err = dao.SysDictData.Ctx(ctx).Insert(do.SysDictData{
DictSort: req.DictSort,
DictLabel: gstr.Trim(req.DictLabel),
DictValue: gstr.Trim(req.DictValue),
DictType: req.DictType,
CssClass: req.CssClass,
ListClass: req.ListClass,
IsDefault: req.IsDefault,
Status: req.Status,
CreateBy: userId,
Remark: req.Remark,
})
liberr.ErrIsNil(ctx, err, "添加字典数据失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysDictTag)
})
return
}
// Get 获取字典数据
func (s *sSysDictData) Get(ctx context.Context, dictCode uint) (res *system.DictDataGetRes, err error) {
res = new(system.DictDataGetRes)
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysDictData.Ctx(ctx).WherePri(dictCode).Scan(&res.Dict)
liberr.ErrIsNil(ctx, err, "获取字典数据失败")
})
return
}
// Edit 修改字典数据
func (s *sSysDictData) Edit(ctx context.Context, req *system.DictDataEditReq, userId uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = s.IsExists(ctx, req.DictType, req.DictLabel, req.DictValue, req.DictCode)
liberr.ErrIsNil(ctx, err)
_, err = dao.SysDictData.Ctx(ctx).WherePri(req.DictCode).Update(do.SysDictData{
DictSort: req.DictSort,
DictLabel: gstr.Trim(req.DictLabel),
DictValue: gstr.Trim(req.DictValue),
DictType: req.DictType,
CssClass: req.CssClass,
ListClass: req.ListClass,
IsDefault: req.IsDefault,
Status: req.Status,
UpdateBy: userId,
Remark: req.Remark,
})
liberr.ErrIsNil(ctx, err, "修改字典数据失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysDictTag)
})
return
}
// Delete 删除字典数据
func (s *sSysDictData) Delete(ctx context.Context, ids []int) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
_, err = dao.SysDictData.Ctx(ctx).Where(dao.SysDictData.Columns().DictCode+" in(?)", ids).Delete()
liberr.ErrIsNil(ctx, err, "删除字典数据失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysDictTag)
})
return
}

View File

@@ -0,0 +1,186 @@
/*
* @desc:字典类型管理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/9/28 9:26
*/
package sysDictType
import (
"context"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/common/consts"
"github.com/tiger1103/gfast/v3/internal/app/common/dao"
"github.com/tiger1103/gfast/v3/internal/app/common/model"
"github.com/tiger1103/gfast/v3/internal/app/common/model/do"
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
"github.com/tiger1103/gfast/v3/internal/app/common/service"
systemConsts "github.com/tiger1103/gfast/v3/internal/app/system/consts"
"github.com/tiger1103/gfast/v3/library/liberr"
)
func init() {
service.RegisterSysDictType(New())
}
func New() *sSysDictType {
return &sSysDictType{}
}
type sSysDictType struct {
}
// List 字典类型列表
func (s *sSysDictType) List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error) {
res = new(system.DictTypeSearchRes)
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysDictType.Ctx(ctx)
if req.DictName != "" {
m = m.Where(dao.SysDictType.Columns().DictName+" like ?", "%"+req.DictName+"%")
}
if req.DictType != "" {
m = m.Where(dao.SysDictType.Columns().DictType+" like ?", "%"+req.DictType+"%")
}
if req.Status != "" {
m = m.Where(dao.SysDictType.Columns().Status+" = ", gconv.Int(req.Status))
}
res.Total, err = m.Count()
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
if req.PageNum == 0 {
req.PageNum = 1
}
res.CurrentPage = req.PageNum
if req.PageSize == 0 {
req.PageSize = systemConsts.PageSize
}
err = m.Fields(model.SysDictTypeInfoRes{}).Page(req.PageNum, req.PageSize).
Order(dao.SysDictType.Columns().DictId + " asc").Scan(&res.DictTypeList)
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
})
return
}
// Add 添加字典类型
func (s *sSysDictType) Add(ctx context.Context, req *system.DictTypeAddReq, userId uint64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = s.ExistsDictType(ctx, req.DictType)
liberr.ErrIsNil(ctx, err)
_, err = dao.SysDictType.Ctx(ctx).Insert(do.SysDictType{
DictName: req.DictName,
DictType: req.DictType,
Status: req.Status,
CreateBy: userId,
Remark: req.Remark,
})
liberr.ErrIsNil(ctx, err, "添加字典类型失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysDictTag)
})
return
}
// Edit 修改字典类型
func (s *sSysDictType) Edit(ctx context.Context, req *system.DictTypeEditReq, userId uint64) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
err = s.ExistsDictType(ctx, req.DictType, req.DictId)
liberr.ErrIsNil(ctx, err)
dictType := (*entity.SysDictType)(nil)
e := dao.SysDictType.Ctx(ctx).Fields(dao.SysDictType.Columns().DictType).WherePri(req.DictId).Scan(&dictType)
liberr.ErrIsNil(ctx, e, "获取字典类型失败")
liberr.ValueIsNil(dictType, "字典类型不存在")
//修改字典类型
_, e = dao.SysDictType.Ctx(ctx).TX(tx).WherePri(req.DictId).Update(do.SysDictType{
DictName: req.DictName,
DictType: req.DictType,
Status: req.Status,
UpdateBy: userId,
Remark: req.Remark,
})
liberr.ErrIsNil(ctx, e, "修改字典类型失败")
//修改字典数据
_, e = dao.SysDictData.Ctx(ctx).TX(tx).Data(do.SysDictData{DictType: req.DictType}).
Where(dao.SysDictData.Columns().DictType, dictType.DictType).Update()
liberr.ErrIsNil(ctx, e, "修改字典数据失败")
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysDictTag)
})
return err
})
return
}
func (s *sSysDictType) Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error) {
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysDictType.Ctx(ctx).Where(dao.SysDictType.Columns().DictId, req.DictId).Scan(&dictType)
liberr.ErrIsNil(ctx, err, "获取字典类型失败")
})
return
}
// ExistsDictType 检查类型是否已经存在
func (s *sSysDictType) ExistsDictType(ctx context.Context, dictType string, dictId ...int64) (err error) {
err = g.Try(ctx, func(ctx context.Context) {
m := dao.SysDictType.Ctx(ctx).Fields(dao.SysDictType.Columns().DictId).
Where(dao.SysDictType.Columns().DictType, dictType)
if len(dictId) > 0 {
m = m.Where(dao.SysDictType.Columns().DictId+" !=? ", dictId[0])
}
res, e := m.One()
liberr.ErrIsNil(ctx, e, "sql err")
if !res.IsEmpty() {
liberr.ErrIsNil(ctx, gerror.New("字典类型已存在"))
}
})
return
}
// Delete 删除字典类型
func (s *sSysDictType) Delete(ctx context.Context, dictIds []int) (err error) {
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err = g.Try(ctx, func(ctx context.Context) {
discs := ([]*entity.SysDictType)(nil)
err = dao.SysDictType.Ctx(ctx).Fields(dao.SysDictType.Columns().DictType).
Where(dao.SysDictType.Columns().DictId+" in (?) ", dictIds).Scan(&discs)
liberr.ErrIsNil(ctx, err, "删除失败")
types := garray.NewStrArray()
for _, dt := range discs {
types.Append(dt.DictType)
}
if types.Len() > 0 {
_, err = dao.SysDictType.Ctx(ctx).TX(tx).Delete(dao.SysDictType.Columns().DictId+" in (?) ", dictIds)
liberr.ErrIsNil(ctx, err, "删除类型失败")
_, err = dao.SysDictData.Ctx(ctx).TX(tx).Delete(dao.SysDictData.Columns().DictType+" in (?) ", types.Slice())
liberr.ErrIsNil(ctx, err, "删除字典数据失败")
}
//清除缓存
service.Cache().RemoveByTag(ctx, consts.CacheSysDictTag)
})
return err
})
return
}
// GetAllDictType 获取所有正常状态下的字典类型
func (s *sSysDictType) GetAllDictType(ctx context.Context) (list []*entity.SysDictType, err error) {
cache := service.Cache()
//从缓存获取
data := cache.Get(ctx, consts.CacheSysDict+"_dict_type_all")
if !data.IsNil() {
err = data.Structs(&list)
return
}
err = g.Try(ctx, func(ctx context.Context) {
err = dao.SysDictType.Ctx(ctx).Where("status", 1).Order("dict_id ASC").Scan(&list)
liberr.ErrIsNil(ctx, err, "获取字典类型数据出错")
//缓存
cache.Set(ctx, consts.CacheSysDict+"_dict_type_all", list, 0, consts.CacheSysDictTag)
})
return
}

View File

@@ -0,0 +1,22 @@
/*
* @desc:公用model
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2023/5/11 22:43
*/
package model
// PageReq 公共请求参数
type PageReq struct {
DateRange []string `p:"dateRange"` //日期范围
PageNum int `p:"pageNum"` //当前页码
PageSize int `p:"pageSize"` //每页数
OrderBy string `p:"orderBy" v:"regex:^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?\\s+(asc|desc|ASC|DESC)(?:\\s*,\\s*[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?\\s+(asc|desc|ASC|DESC))*$#排序参数不合法"` // 排序方式
}
// ListRes 列表公共返回
type ListRes struct {
CurrentPage int `json:"currentPage"`
Total interface{} `json:"total"`
}

View File

@@ -0,0 +1,21 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
)
// CasbinRule is the golang structure of table casbin_rule for DAO operations like Where/Data.
type CasbinRule struct {
g.Meta `orm:"table:casbin_rule, do:true"`
Ptype interface{} //
V0 interface{} //
V1 interface{} //
V2 interface{} //
V3 interface{} //
V4 interface{} //
V5 interface{} //
}

View File

@@ -0,0 +1,25 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-18 21:09:17
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysConfig is the golang structure of table sys_config for DAO operations like Where/Data.
type SysConfig struct {
g.Meta `orm:"table:sys_config, do:true"`
ConfigId interface{} // 参数主键
ConfigName interface{} // 参数名称
ConfigKey interface{} // 参数键名
ConfigValue interface{} // 参数键值
ConfigType interface{} // 系统内置Y是 N否
CreateBy interface{} // 创建者
UpdateBy interface{} // 更新者
Remark interface{} // 备注
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 修改时间
}

View File

@@ -0,0 +1,29 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-16 16:32:52
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysDictData is the golang structure of table sys_dict_data for DAO operations like Where/Data.
type SysDictData struct {
g.Meta `orm:"table:sys_dict_data, do:true"`
DictCode interface{} // 字典编码
DictSort interface{} // 字典排序
DictLabel interface{} // 字典标签
DictValue interface{} // 字典键值
DictType interface{} // 字典类型
CssClass interface{} // 样式属性(其他样式扩展)
ListClass interface{} // 表格回显样式
IsDefault interface{} // 是否默认1是 0否
Status interface{} // 状态0正常 1停用
CreateBy interface{} // 创建者
UpdateBy interface{} // 更新者
Remark interface{} // 备注
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 修改时间
}

View File

@@ -0,0 +1,24 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-16 16:32:52
// =================================================================================
package do
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
// SysDictType is the golang structure of table sys_dict_type for DAO operations like Where/Data.
type SysDictType struct {
g.Meta `orm:"table:sys_dict_type, do:true"`
DictId interface{} // 字典主键
DictName interface{} // 字典名称
DictType interface{} // 字典类型
Status interface{} // 状态0正常 1停用
CreateBy interface{} // 创建者
UpdateBy interface{} // 更新者
Remark interface{} // 备注
CreatedAt *gtime.Time // 创建日期
UpdatedAt *gtime.Time // 修改日期
}

View File

@@ -0,0 +1,16 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// =================================================================================
package entity
// CasbinRule is the golang structure for table casbin_rule.
type CasbinRule struct {
Ptype string `json:"ptype" description:""`
V0 string `json:"v0" description:""`
V1 string `json:"v1" description:""`
V2 string `json:"v2" description:""`
V3 string `json:"v3" description:""`
V4 string `json:"v4" description:""`
V5 string `json:"v5" description:""`
}

View File

@@ -0,0 +1,23 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-18 21:09:17
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysConfig is the golang structure for table sys_config.
type SysConfig struct {
ConfigId uint `json:"configId" description:"参数主键"`
ConfigName string `json:"configName" description:"参数名称"`
ConfigKey string `json:"configKey" description:"参数键名"`
ConfigValue string `json:"configValue" description:"参数键值"`
ConfigType int `json:"configType" description:"系统内置Y是 N否"`
CreateBy uint `json:"createBy" description:"创建者"`
UpdateBy uint `json:"updateBy" description:"更新者"`
Remark string `json:"remark" description:"备注"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改时间"`
}

View File

@@ -0,0 +1,27 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-16 16:32:52
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysDictData is the golang structure for table sys_dict_data.
type SysDictData struct {
DictCode int64 `json:"dictCode" description:"字典编码"`
DictSort int `json:"dictSort" description:"字典排序"`
DictLabel string `json:"dictLabel" description:"字典标签"`
DictValue string `json:"dictValue" description:"字典键值"`
DictType string `json:"dictType" description:"字典类型"`
CssClass string `json:"cssClass" description:"样式属性(其他样式扩展)"`
ListClass string `json:"listClass" description:"表格回显样式"`
IsDefault int `json:"isDefault" description:"是否默认1是 0否"`
Status int `json:"status" description:"状态0正常 1停用"`
CreateBy uint64 `json:"createBy" description:"创建者"`
UpdateBy uint64 `json:"updateBy" description:"更新者"`
Remark string `json:"remark" description:"备注"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建时间"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改时间"`
}

View File

@@ -0,0 +1,22 @@
// =================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at 2022-04-16 16:32:52
// =================================================================================
package entity
import (
"github.com/gogf/gf/v2/os/gtime"
)
// SysDictType is the golang structure for table sys_dict_type.
type SysDictType struct {
DictId uint64 `json:"dictId" description:"字典主键"`
DictName string `json:"dictName" description:"字典名称"`
DictType string `json:"dictType" description:"字典类型"`
Status uint `json:"status" description:"状态0正常 1停用"`
CreateBy uint `json:"createBy" description:"创建者"`
UpdateBy uint `json:"updateBy" description:"更新者"`
Remark string `json:"remark" description:"备注"`
CreatedAt *gtime.Time `json:"createdAt" description:"创建日期"`
UpdatedAt *gtime.Time `json:"updatedAt" description:"修改日期"`
}

View File

@@ -0,0 +1,8 @@
/*
* @desc:xxxx功能描述
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/18 11:56
*/
package model

View File

@@ -0,0 +1,23 @@
/*
* @desc:字典数据
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/18 11:56
*/
package model
type DictTypeRes struct {
DictName string `json:"name"`
DictType string `json:"type"`
Remark string `json:"remark"`
}
// DictDataRes 字典数据
type DictDataRes struct {
DictValue string `json:"key"`
DictLabel string `json:"value"`
DictType string `json:"type"`
IsDefault int `json:"isDefault"`
Remark string `json:"remark"`
}

View File

@@ -0,0 +1,19 @@
/*
* @desc:字典类型
* @company:云南奇讯科技有限公司
* @Author: yixiaohu<yxh669@qq.com>
* @Date: 2022/3/18 11:56
*/
package model
import "github.com/gogf/gf/v2/os/gtime"
type SysDictTypeInfoRes struct {
DictId uint64 `orm:"dict_id,primary" json:"dictId"` // 字典主键
DictName string `orm:"dict_name" json:"dictName"` // 字典名称
DictType string `orm:"dict_type,unique" json:"dictType"` // 字典类型
Status uint `orm:"status" json:"status"` // 状态0正常 1停用
Remark string `orm:"remark" json:"remark"` // 备注
CreatedAt *gtime.Time `orm:"created_at" json:"createdAt"` // 创建日期
}

View File

@@ -0,0 +1,32 @@
/*
* @desc:token options
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/8 16:02
*/
package model
import (
"github.com/gogf/gf/v2/frame/g"
)
type TokenOptions struct {
// server name
ServerName string `json:"serverName"`
// 缓存key (每创建一个实例CacheKey必须不相同)
CacheKey string `json:"cacheKey"`
// 超时时间 默认10天
Timeout int64 `json:"timeout"`
// 缓存刷新时间 默认5天
// 处理携带token的请求时当前时间大于超时时间并小于缓存刷新时间时token将自动刷新即重置token存活时间
// MaxRefresh值为0时,token将不会自动刷新
MaxRefresh int64 `json:"maxRefresh"`
// 是否允许多点登录
MultiLogin bool `json:"multiLogin"`
// Token加密key 32位
EncryptKey []byte `json:"encryptKey"`
// 拦截排除地址
ExcludePaths g.SliceStr `json:"excludePaths"`
CacheModel string `json:"cacheModel"`
}

View File

@@ -0,0 +1,28 @@
/*
* @desc:后台路由
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/2/18 17:34
*/
package router
import (
"context"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/tiger1103/gfast/v3/internal/app/common/controller"
)
var R = new(Router)
type Router struct{}
func (router *Router) BindController(ctx context.Context, group *ghttp.RouterGroup) {
group.Group("/pub", func(group *ghttp.RouterGroup) {
group.Group("/captcha", func(group *ghttp.RouterGroup) {
group.Bind(
controller.Captcha,
)
})
})
}

View File

@@ -0,0 +1,29 @@
/*
* @desc:缓存处理
* @company:云南奇讯科技有限公司
* @Author: yixiaohu
* @Date: 2022/3/9 11:15
*/
package service
import (
"github.com/tiger1103/gfast-cache/cache"
)
type ICache interface {
cache.IGCache
}
var c ICache
func Cache() ICache {
if c == nil {
panic("implement not found for interface ICache, forgot register?")
}
return c
}
func RegisterCache(che ICache) {
c = che
}

View File

@@ -0,0 +1,28 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"context"
)
type ICaptcha interface {
GetVerifyImgString(ctx context.Context) (idKeyC string, base64stringC string, err error)
VerifyString(id, answer string) bool
}
var localCaptcha ICaptcha
func Captcha() ICaptcha {
if localCaptcha == nil {
panic("implement not found for interface ICaptcha, forgot register?")
}
return localCaptcha
}
func RegisterCaptcha(i ICaptcha) {
localCaptcha = i
}

View File

@@ -0,0 +1,238 @@
package service
import (
"context"
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
"github.com/casbin/casbin/v2/persist"
"github.com/gogf/gf/v2/frame/g"
"github.com/tiger1103/gfast/v3/internal/app/common/dao"
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
"sync"
)
type adapterCasbin struct {
Enforcer *casbin.SyncedEnforcer
EnforcerErr error
ctx context.Context
}
var (
once sync.Once
en *casbin.SyncedEnforcer
enErr error
)
// CasbinEnforcer 获取adapter单例对象
func CasbinEnforcer(ctx context.Context) (enforcer *casbin.SyncedEnforcer, err error) {
ac := newAdapter(ctx)
enforcer = ac.Enforcer
err = ac.EnforcerErr
return
}
// 初始化adapter操作
func newAdapter(ctx context.Context) (a *adapterCasbin) {
a = new(adapterCasbin)
a.ctx = ctx
once.Do(func() {
en, enErr = initPolicy(ctx, a)
})
if enErr == nil && en != nil {
en.SetAdapter(a)
}
a.Enforcer, a.EnforcerErr = en, enErr
return
}
func initPolicy(ctx context.Context, a *adapterCasbin) (e *casbin.SyncedEnforcer, err error) {
// Because the DB is empty at first,
// so we need to load the policy from the file adapter (.CSV) first.
e, err = casbin.NewSyncedEnforcer(g.Cfg().MustGet(ctx, "casbin.modelFile").String(), a)
return
}
// SavePolicy saves policy to database.
func (a *adapterCasbin) SavePolicy(model model.Model) (err error) {
err = a.dropTable()
if err != nil {
return
}
err = a.createTable()
if err != nil {
return
}
for ptype, ast := range model["p"] {
for _, rule := range ast.Policy {
line := savePolicyLine(ptype, rule)
_, err := dao.CasbinRule.Ctx(a.ctx).Data(line).Insert()
if err != nil {
return err
}
}
}
for ptype, ast := range model["g"] {
for _, rule := range ast.Policy {
line := savePolicyLine(ptype, rule)
_, err := dao.CasbinRule.Ctx(a.ctx).Data(line).Insert()
if err != nil {
return err
}
}
}
return
}
func (a *adapterCasbin) dropTable() (err error) {
return
}
func (a *adapterCasbin) createTable() (err error) {
return
}
// LoadPolicy loads policy from database.
func (a *adapterCasbin) LoadPolicy(model model.Model) error {
var lines []*entity.CasbinRule
if err := dao.CasbinRule.Ctx(a.ctx).Scan(&lines); err != nil {
return err
}
for _, line := range lines {
loadPolicyLine(line, model)
}
return nil
}
// AddPolicy adds a policy rule to the storage.
func (a *adapterCasbin) AddPolicy(sec string, ptype string, rule []string) error {
line := savePolicyLine(ptype, rule)
_, err := dao.CasbinRule.Ctx(a.ctx).Data(line).Insert()
return err
}
// RemovePolicy removes a policy rule from the storage.
func (a *adapterCasbin) RemovePolicy(sec string, ptype string, rule []string) error {
line := savePolicyLine(ptype, rule)
err := rawDelete(a, line)
return err
}
func (a *adapterCasbin) AddPolicies(sec string, ptype string, rules [][]string) error {
lines := make([]*entity.CasbinRule, len(rules))
for k, rule := range rules {
lines[k] = savePolicyLine(ptype, rule)
}
_, err := dao.CasbinRule.Ctx(a.ctx).Data(lines).Insert()
return err
}
// RemovePolicies removes policy rules from the storage.
// This is part of the Auto-Save feature.
func (a *adapterCasbin) RemovePolicies(sec string, ptype string, rules [][]string) error {
for _, rule := range rules {
err := a.RemovePolicy(sec, ptype, rule)
if err != nil {
return err
}
}
return nil
}
// RemoveFilteredPolicy removes policy rules that match the filter from the storage.
func (a *adapterCasbin) RemoveFilteredPolicy(sec string, ptype string,
fieldIndex int, fieldValues ...string) error {
line := &entity.CasbinRule{}
line.Ptype = ptype
if fieldIndex <= 0 && 0 < fieldIndex+len(fieldValues) {
line.V0 = fieldValues[0-fieldIndex]
}
if fieldIndex <= 1 && 1 < fieldIndex+len(fieldValues) {
line.V1 = fieldValues[1-fieldIndex]
}
if fieldIndex <= 2 && 2 < fieldIndex+len(fieldValues) {
line.V2 = fieldValues[2-fieldIndex]
}
if fieldIndex <= 3 && 3 < fieldIndex+len(fieldValues) {
line.V3 = fieldValues[3-fieldIndex]
}
if fieldIndex <= 4 && 4 < fieldIndex+len(fieldValues) {
line.V4 = fieldValues[4-fieldIndex]
}
if fieldIndex <= 5 && 5 < fieldIndex+len(fieldValues) {
line.V5 = fieldValues[5-fieldIndex]
}
err := rawDelete(a, line)
return err
}
func loadPolicyLine(line *entity.CasbinRule, model model.Model) {
lineText := line.Ptype
if line.V0 != "" {
lineText += ", " + line.V0
}
if line.V1 != "" {
lineText += ", " + line.V1
}
if line.V2 != "" {
lineText += ", " + line.V2
}
if line.V3 != "" {
lineText += ", " + line.V3
}
if line.V4 != "" {
lineText += ", " + line.V4
}
if line.V5 != "" {
lineText += ", " + line.V5
}
persist.LoadPolicyLine(lineText, model)
}
func savePolicyLine(ptype string, rule []string) *entity.CasbinRule {
line := &entity.CasbinRule{}
line.Ptype = ptype
if len(rule) > 0 {
line.V0 = rule[0]
}
if len(rule) > 1 {
line.V1 = rule[1]
}
if len(rule) > 2 {
line.V2 = rule[2]
}
if len(rule) > 3 {
line.V3 = rule[3]
}
if len(rule) > 4 {
line.V4 = rule[4]
}
if len(rule) > 5 {
line.V5 = rule[5]
}
return line
}
func rawDelete(a *adapterCasbin, line *entity.CasbinRule) error {
db := dao.CasbinRule.Ctx(a.ctx).Where("ptype = ?", line.Ptype)
if line.V0 != "" {
db = db.Where("v0 = ?", line.V0)
}
if line.V1 != "" {
db = db.Where("v1 = ?", line.V1)
}
if line.V2 != "" {
db = db.Where("v2 = ?", line.V2)
}
if line.V3 != "" {
db = db.Where("v3 = ?", line.V3)
}
if line.V4 != "" {
db = db.Where("v4 = ?", line.V4)
}
if line.V5 != "" {
db = db.Where("v5 = ?", line.V5)
}
_, err := db.Delete()
return err
}

View File

@@ -0,0 +1,23 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
eventBus "github.com/asaskevich/EventBus"
)
var localEventBus eventBus.Bus
func EventBus() eventBus.Bus {
if localEventBus == nil {
panic("implement not found for interface EventBus, forgot register?")
}
return localEventBus
}
func RegisterEventBus(i eventBus.Bus) {
localEventBus = i
}

View File

@@ -0,0 +1,27 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"github.com/gogf/gf/v2/net/ghttp"
)
type IMiddleware interface {
MiddlewareCORS(r *ghttp.Request)
}
var localMiddleware IMiddleware
func Middleware() IMiddleware {
if localMiddleware == nil {
panic("implement not found for interface IMiddleware, forgot register?")
}
return localMiddleware
}
func RegisterMiddleware(i IMiddleware) {
localMiddleware = i
}

View File

@@ -0,0 +1,37 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
)
type ISysConfig interface {
List(ctx context.Context, req *system.ConfigSearchReq) (res *system.ConfigSearchRes, err error)
Add(ctx context.Context, req *system.ConfigAddReq, userId uint64) (err error)
CheckConfigKeyUnique(ctx context.Context, configKey string, configId ...int64) (err error)
Get(ctx context.Context, id int) (res *system.ConfigGetRes, err error)
Edit(ctx context.Context, req *system.ConfigEditReq, userId uint64) (err error)
Delete(ctx context.Context, ids []int) (err error)
GetConfigByKey(ctx context.Context, key string) (config *entity.SysConfig, err error)
GetByKey(ctx context.Context, key string) (config *entity.SysConfig, err error)
}
var localSysConfig ISysConfig
func SysConfig() ISysConfig {
if localSysConfig == nil {
panic("implement not found for interface ISysConfig, forgot register?")
}
return localSysConfig
}
func RegisterSysConfig(i ISysConfig) {
localSysConfig = i
}

View File

@@ -0,0 +1,35 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
)
type ISysDictData interface {
GetDictDataTree(ctx context.Context, dictType string) (res *system.GetDictTreeRes, err error)
GetDictWithDataByType(ctx context.Context, req *system.GetDictReq) (dict *system.GetDictRes, err error)
List(ctx context.Context, req *system.DictDataSearchReq) (res *system.DictDataSearchRes, err error)
Add(ctx context.Context, req *system.DictDataAddReq, userId uint64) (err error)
Get(ctx context.Context, dictCode uint) (res *system.DictDataGetRes, err error)
Edit(ctx context.Context, req *system.DictDataEditReq, userId uint64) (err error)
Delete(ctx context.Context, ids []int) (err error)
}
var localSysDictData ISysDictData
func SysDictData() ISysDictData {
if localSysDictData == nil {
panic("implement not found for interface ISysDictData, forgot register?")
}
return localSysDictData
}
func RegisterSysDictData(i ISysDictData) {
localSysDictData = i
}

View File

@@ -0,0 +1,36 @@
// ================================================================================
// Code generated by GoFrame CLI tool. DO NOT EDIT.
// You can delete these comments if you wish manually maintain this interface file.
// ================================================================================
package service
import (
"context"
"github.com/tiger1103/gfast/v3/api/v1/system"
"github.com/tiger1103/gfast/v3/internal/app/common/model/entity"
)
type ISysDictType interface {
List(ctx context.Context, req *system.DictTypeSearchReq) (res *system.DictTypeSearchRes, err error)
Add(ctx context.Context, req *system.DictTypeAddReq, userId uint64) (err error)
Edit(ctx context.Context, req *system.DictTypeEditReq, userId uint64) (err error)
Get(ctx context.Context, req *system.DictTypeGetReq) (dictType *entity.SysDictType, err error)
ExistsDictType(ctx context.Context, dictType string, dictId ...int64) (err error)
Delete(ctx context.Context, dictIds []int) (err error)
GetAllDictType(ctx context.Context) (list []*entity.SysDictType, err error)
}
var localSysDictType ISysDictType
func SysDictType() ISysDictType {
if localSysDictType == nil {
panic("implement not found for interface ISysDictType, forgot register?")
}
return localSysDictType
}
func RegisterSysDictType(i ISysDictType) {
localSysDictType = i
}