dzhcore

package module
v1.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 26 Imported by: 6

README

dzhcore

基于 cooladmin 二开版本 这里要感谢作者李栋

依赖

go get -u github.com/gzdzh-cn/dzhcore

Documentation

https://pkg.go.dev/github.com/gzdzh-cn/dzhcore

更新日志

v1.1.7

  • 更改依赖顺序

v1.1.6 2024年8月29日

  • 更新工具函数

v1.1.5

  • 增加工具函数
  • 接口查询,id转换为数字
  • service的PageQueryOp和ListQueryOp增加As参数

v1.1.4

  • 自增id改为雪花ID

v1.1.3

  • 修改bug

v1.1.0

  • 修改ok返回自定义msg
  • 修改FillInitData的逻辑
  • 增加版本号打印
  • service数据库调用改为model封装DBM

v1.0.1

  • 加入了 mysql,本地上传驱动,oss驱动
  • 修改为gf最新的dao层方式调用

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version           = "v1.1.6"
	Config            = coreconfig.Config            // 配置中的core节相关配置
	GetCfgWithDefault = coreconfig.GetCfgWithDefault // GetCfgWithDefault 获取配置,如果配置不存在,则使用默认值
)
View Source
var (
	GormDBS       = make(map[string]*gorm.DB) // 定义全局gorm.DB对象集合 仅供内部使用
	CacheEPS      = gcache.New()              // 定义全局缓存对象	供EPS使用
	CacheManager  = common.CacheManager       // 定义全局缓存对象	供其他业务使用
	ProcessFlag   = guid.S()                  // 定义全局进程标识
	RunMode       = "dev"                     // 定义全局运行模式
	IsRedisMode   = false                     // 定义全局是否为redis模式
	I18n          = gi18n.New()               // 定义全局国际化对象
	Versions      = common.Versions           // 全部版本
	NodeSnowflake *snowflake.Node
)
View Source
var (
	File = corefile.NewFile // File 文件上传操作
)
View Source
var FuncMap = make(map[string]coreFunc)

FuncMap 函数列表

View Source
var ModelInfo = make(map[string][]*ColumnInfo)

ModelInfo 路由perfix 对应的model信息

Functions

func ClusterRunFunc

func ClusterRunFunc(ctx g.Ctx, funcstring string) (err error)

ClusterRunFunc 集群运行函数,如果是单机模式, 则直接运行函数

func CreateSnowflake added in v1.1.6

func CreateSnowflake(ctx context.Context) *snowflake.Node

雪花

func CreateTable

func CreateTable(model IModel) error

CreateTable 根据entity结构体创建表

func DBM

func DBM(m IModel) *gdb.Model

DBM 根据model获取 *gdb.Model

func FillInitData

func FillInitData(ctx g.Ctx, moduleName string, model IModel)

FillInitData 数据库填充初始数据

func GDBM

func GDBM(m IModel) *gdb.Model

Deprecated 请使用 core.DBM 替代

func GetFunc

func GetFunc(name string) coreFunc

GetFunc 获取函数

func GetVersions

func GetVersions(name string) interface{}

获取版本

func InitDB

func InitDB(group string) (*gorm.DB, error)

InitDB 初始化数据库连接供gorm使用

func ListenFunc

func ListenFunc(ctx g.Ctx)

ListenFunc 监听函数

func MiddlewareHandlerResponse

func MiddlewareHandlerResponse(r *ghttp.Request)

MiddlewareHandlerResponse is the default middleware handling handler response object and its error.

func RegisterController

func RegisterController(c IController)

RegisterController 注册控制器到路由

func RegisterControllerSimple

func RegisterControllerSimple(c IControllerSimple)

注册不带crud的路由

func RegisterFunc

func RegisterFunc(name string, f coreFunc)

RegisterFunc 注册函数

func RunFunc

func RunFunc(ctx g.Ctx, funcstring string) (err error)

RunFunc 运行函数

func SetVersions

func SetVersions(name string, v string)

存储版本

Types

type AddReq

type AddReq struct {
	g.Meta `path:"/add" method:"POST"`
}

type BaseRes

type BaseRes struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

BaseRes core.OK 正常返回

func Fail

func Fail(message string) *BaseRes

Fail 失败返回结果

func Ok

func Ok(data interface{}, message ...string) *BaseRes

Ok 返回正常结果

type Claims

type Claims struct {
	IsRefresh       bool     `json:"isRefresh"`
	RoleIds         []string `json:"roleIds"`
	Username        string   `json:"username"`
	UserId          string   `json:"userId"`
	PasswordVersion *int32   `json:"passwordVersion"`
	jwt.RegisteredClaims
}

type ColumnInfo

type ColumnInfo struct {
	Comment      string `json:"comment"`
	Length       string `json:"length"`
	Nullable     bool   `json:"nullable"`
	PropertyName string `json:"propertyName"`
	Type         string `json:"type"`
}

ColumnInfo 表字段信息

type Controller

type Controller struct {
	Prefix  string     `json:"prefix"`
	Api     g.ArrayStr `json:"api"`
	Service IService   `json:"service"`
}

func (*Controller) Add

func (c *Controller) Add(ctx context.Context, req *AddReq) (res *BaseRes, err error)

func (*Controller) Delete

func (c *Controller) Delete(ctx context.Context, req *DeleteReq) (res *BaseRes, err error)

func (*Controller) Info

func (c *Controller) Info(ctx context.Context, req *InfoReq) (res *BaseRes, err error)

func (*Controller) List

func (c *Controller) List(ctx context.Context, req *ListReq) (res *BaseRes, err error)

func (*Controller) Page

func (c *Controller) Page(ctx context.Context, req *PageReq) (res *BaseRes, err error)

func (*Controller) Update

func (c *Controller) Update(ctx context.Context, req *UpdateReq) (res *BaseRes, err error)

type ControllerSimple

type ControllerSimple struct {
	Prefix string
}

type DefaultHandlerResponse

type DefaultHandlerResponse struct {
	Code    int         `json:"code"    dc:"Error code"`
	Message string      `json:"message" dc:"Error message"`
	Data    interface{} `json:"data,omitempty"    dc:"Result data for certain request according API definition"`
}

DefaultHandlerResponse is the default implementation of HandlerResponse.

type DeleteReq

type DeleteReq struct {
	g.Meta `path:"/delete" method:"POST"`
	Ids    []int `json:"ids" v:"required#请选择要删除的数据"`
}

type IController

type IController interface {
	Add(ctx context.Context, req *AddReq) (res *BaseRes, err error)
	Delete(ctx context.Context, req *DeleteReq) (res *BaseRes, err error)
	Update(ctx context.Context, req *UpdateReq) (res *BaseRes, err error)
	Info(ctx context.Context, req *InfoReq) (res *BaseRes, err error)
	List(ctx context.Context, req *ListReq) (res *BaseRes, err error)
	Page(ctx context.Context, req *PageReq) (res *BaseRes, err error)
}

type IControllerSimple

type IControllerSimple interface {
}

type IDao

type IDao interface {
	DB() gdb.DB
	Table() string
	Group() string
	Ctx(ctx context.Context) *gdb.Model
	//Columns()
	Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error)
}

type IModel

type IModel interface {
	TableName() string
	GroupName() string
}

type IService

type IService interface {
	ServiceAdd(ctx context.Context, req *AddReq) (data interface{}, err error)       // 新增
	ServiceDelete(ctx context.Context, req *DeleteReq) (data interface{}, err error) // 删除
	ServiceUpdate(ctx context.Context, req *UpdateReq) (data interface{}, err error) // 修改
	ServiceInfo(ctx context.Context, req *InfoReq) (data interface{}, err error)     // 详情
	ServiceList(ctx context.Context, req *ListReq) (data interface{}, err error)     // 列表
	ServicePage(ctx context.Context, req *PageReq) (data interface{}, err error)     // 分页
	ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error)  // 新增|删除|修改前的操作
	ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error)   // 新增|删除|修改后的操作
	GetModel() IModel
	GetDao() IDao
}

type InfoReq

type InfoReq struct {
	g.Meta `path:"/info" method:"GET"`
	Id     int `json:"id" v:"integer|required#请选择要查询的数据"`
}

type JoinOp

type JoinOp struct {
	Dao       IDao
	Model     IModel   // 关联的model
	Alias     string   // 别名
	Condition string   // 关联条件
	Type      JoinType // 关联类型  LeftJoin RightJoin InnerJoin
}

关联查询

type JoinType

type JoinType string

关联类型

const (
	LeftJoin  JoinType = "LeftJoin"
	RightJoin JoinType = "RightJoin"
	InnerJoin JoinType = "InnerJoin"
)

Join 类型

type ListReq

type ListReq struct {
	g.Meta `path:"/list" method:"POST"`
	Order  string `json:"order"`
	Sort   string `json:"sort"`
}

type Model

type Model struct {
	ID         string    `gorm:"primaryKey;autoIncrement:false;varchar(255);index" json:"id"`
	CreateTime time.Time `gorm:"column:createTime;not null;index,priority:1;autoCreateTime:nano;comment:创建时间" json:"createTime"` // 创建时间
	UpdateTime time.Time `gorm:"column:updateTime;not null;index,priority:1;autoUpdateTime:nano;comment:更新时间" json:"updateTime"` // 更新时间
	DeletedAt  time.Time `gorm:"index" json:"deletedAt"`
}

func NewModel

func NewModel() *Model

func (*Model) GroupName

func (m *Model) GroupName() string

返回分组名

func (*Model) TableName

func (m *Model) TableName() string

返回表名

type PageReq

type PageReq struct {
	g.Meta         `path:"/page" method:"POST"`
	Page           int    `d:"1" json:"page"`     // 页码
	Size           int    `d:"15" json:"size"`    //每页条数
	Order          string `json:"order"`          // 排序字段
	Sort           string `json:"sort"`           // 排序方式 asc desc
	IsExport       bool   `json:"isExport"`       // 是否导出
	MaxExportLimit int    `json:"maxExportLimit"` // 最大导出条数,不传或者小于等于0则不限制
}

type QueryOp

type QueryOp struct {
	FieldEQ      []string                                      // 字段等于
	KeyWordField []string                                      // 模糊搜索匹配的数据库字段
	AddOrderby   g.MapStrStr                                   // 添加排序
	Where        func(ctx context.Context) []g.Array           // 自定义条件
	Select       string                                        // 查询字段,多个字段用逗号隔开 如: id,name  或  a.id,a.name,b.name AS bname
	As           string                                        //主表别名
	Join         []*JoinOp                                     // 关联查询
	Extend       func(ctx g.Ctx, m *gdb.Model) *gdb.Model      // 追加其他条件
	ModifyResult func(ctx g.Ctx, data interface{}) interface{} // 修改结果
}

List/Add接口条件配置

type Service

type Service struct {
	Dao                IDao
	Model              IModel
	ListQueryOp        *QueryOp
	PageQueryOp        *QueryOp
	InsertParam        func(ctx context.Context) g.MapStrAny // Add时插入参数
	Before             func(ctx context.Context) (err error) // CRUD前的操作
	InfoIgnoreProperty string                                // Info时忽略的字段,多个字段用逗号隔开
	UniqueKey          g.MapStrStr                           // 唯一键 key:字段名 value:错误信息
	NotNullKey         g.MapStrStr                           // 非空键 key:字段名 value:错误信息
}

func NewDaoService

func NewDaoService(dao IDao) *Service

func NewModelService

func NewModelService(model IModel) *Service

func (*Service) GetDao

func (s *Service) GetDao() IDao

获取dao

func (*Service) GetModel

func (s *Service) GetModel() IModel

获取model

func (*Service) ModifyAfter

func (s *Service) ModifyAfter(ctx context.Context, method string, param g.MapStrAny) (err error)

新增|删除|修改后的操作

func (*Service) ModifyBefore

func (s *Service) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error)

新增|删除|修改前的操作

func (*Service) ServiceAdd

func (s *Service) ServiceAdd(ctx context.Context, req *AddReq) (data interface{}, err error)

新增

func (*Service) ServiceDelete

func (s *Service) ServiceDelete(ctx context.Context, req *DeleteReq) (data interface{}, err error)

删除

func (*Service) ServiceInfo

func (s *Service) ServiceInfo(ctx context.Context, req *InfoReq) (data interface{}, err error)

查询

func (*Service) ServiceList

func (s *Service) ServiceList(ctx context.Context, req *ListReq) (data interface{}, err error)

列表

func (*Service) ServicePage

func (s *Service) ServicePage(ctx context.Context, req *PageReq) (data interface{}, err error)

分页列表

func (*Service) ServiceUpdate

func (s *Service) ServiceUpdate(ctx context.Context, req *UpdateReq) (data interface{}, err error)

修改

type UpdateReq

type UpdateReq struct {
	g.Meta `path:"/update" method:"POST"`
}

func (UpdateReq) Deadline

func (u UpdateReq) Deadline() (deadline time.Time, ok bool)

func (UpdateReq) Done

func (u UpdateReq) Done() <-chan struct{}

func (UpdateReq) Err

func (u UpdateReq) Err() error

func (UpdateReq) Value

func (u UpdateReq) Value(key any) any

Directories

Path Synopsis
contrib
drivers/mysql
Package mysql 扩展了 GoFrame 的 mysql 包,集成了 gorm相关功能.
Package mysql 扩展了 GoFrame 的 mysql 包,集成了 gorm相关功能.
files/local
Package local 提供本地文件上传支持
Package local 提供本地文件上传支持
utility

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL