flowservice

package
v0.0.0-...-7a729f8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConclusionGo            = 1
	ConclusionGoWithRisk    = 2
	ConclusionReject        = 3
	ConCLusionTransferOther = 100
	CurStepTblColName       = "cur_step"

	// 状态 1: 流程草稿   2: 流程流转中  3: 流程完成(被拒绝), 4: 流程完成(超时) 5: 流程完成(正常)
	FlowStateDraft   = 1
	FlowStateRunning = 2
	FlowStateFinish  = 3
	FlowStateReject  = 4
	FlowStateTimeOut = 5
)
View Source
const (
	UISettingTypeTable   = "tableInit"
	UISettingTypeAddForm = "add"
	UISettingTypeModForm = "mod"

	UIGroupTypeSlot = "slot"
)

Variables

This section is empty.

Functions

func Err2CustomErr

func Err2CustomErr(err error) customerror.CustomError

func GetRefValue

func GetRefValue(v reflect.Value) reflect.Value

获取可读取/可修改的反射值

func Register

func Register(serviceType string, service FlowService)

Register 注册新类型的服务

Types

type Action

type Action interface {
	Do(CRUDContext, *gin.Context) (ret interface{}, flowId uint, oplog string, err error)
}

更新字段接口

type ActionInf

type ActionInf interface {
	// 获取一个自定义动作
	GetAction(serviceId uint, actionType string) (action Action, err error)
}

type ActionObject

type ActionObject struct {
	Showbtn   bool                   `json:"showbtn"`
	Formrules map[string]interface{} `json:"formrules,omitempty"`
}

type CRUDContext

type CRUDContext struct {
	UserName    string
	ServiceName string
	ServiceId   uint
	Service     FlowService
	OperateLog  string
	Action      string

	// getall 参数
	Fields        []string
	Sortby        []string
	Order         []string
	QueryConditon []*common.QueryConditon
	Limit         int
	Offset        int
}

type CheckHandler

type CheckHandler struct {
	ID          uint   `gorm:"primary_key"  json:"id"`                                        // 自增主键
	User        string `gorm:"size:100;column:user;unique_index:onerecord"  json:"user"`      // 操作者的账户id
	Step        string `gorm:"size:20;column:step;unique_index:onerecord"  json:"step"`       // 步骤
	ServiceId   uint   `gorm:"column:service_id;unique_index:onerecord"  json:"serviceId"`    // FlowId
	ServiceName string `gorm:"size:50;column:service;unique_index:onerecord"  json:"service"` // FlowType
	Conclusion  int    `gorm:"column:conclusion"  json:"conclusion"`                          // 评审结论,0未评审,1 通过,2 风险通过 3 拒绝, 100 转他人处理
	Remark      string `gorm:"column:remark"  json:"remark"`                                  // 操作详情
	//Attach      string      `gorm:"size:1000;column:attach;index"  json:"attach"` // 附件
	CreatedAt     time.Time   `json:"created_at"` // 创建时间
	UpdatedAt     time.Time   `json:"updated_at"` // 最后更新时间
	TblName       string      `gorm:"-" json:"-"` // 表名
	Flow          FlowService `gorm:"-" json:"-"` // 关联的流程
	AttachKeys    []string    `gorm:"-" json:"-"` // 附件key列表
	IsPublicCheck bool        `gorm:"-" json:"-"` // 是否为公共审核,如果是不需要鉴权

	Pretreatment   func(CRUDContext, *gin.Context, *gorm.DB, *CheckHandler) (oplog string, err error)                `gorm:"-" json:"-"` // 预处理
	Aftertreatment func(CRUDContext, *gin.Context, *gorm.DB, *CheckHandler, []FlowHandler) (oplog string, err error) `gorm:"-" json:"-"` // 后处理

	PreStepHandlerIds []uint `gorm:"-" json:"preStepHandlerIds"` // 上一步需要重新审批的用户
}

func (*CheckHandler) Do

func (h *CheckHandler) Do(crudContext CRUDContext, c *gin.Context) (ret interface{}, oplog string, err error)

func (*CheckHandler) GetConclusion

func (h *CheckHandler) GetConclusion() bool

是否通过

func (*CheckHandler) IsFinish

func (h *CheckHandler) IsFinish() bool

是否完成审核

func (*CheckHandler) LoadInst

func (h *CheckHandler) LoadInst(flow FlowService, uname string, id uint) (ret FlowHandler, err error)

从数据库中加载数据,返回一个新实例

func (*CheckHandler) LoadStepHandlers

func (h *CheckHandler) LoadStepHandlers(tx *gorm.DB, flowId uint, stepKey string) (handlers []FlowHandler, err error)

加载handler

func (*CheckHandler) SetAttachKeys

func (h *CheckHandler) SetAttachKeys(keys []string)

非接口方法 设置附件keys,用于保存附件使用

func (*CheckHandler) TableName

func (h *CheckHandler) TableName() string

表名

type CommFlow

type CommFlow struct {
	ID      uint   `gorm:"primary_key" json:"id"`                          // 自增主键
	CurStep string `gorm:"size:20;column:cur_step;index"  json:"cur_step"` // 当前步骤
	State   int    `gorm:"column:state;index"  json:"state"`               // 状态 1: 流程草稿   2: 流程流转中  3: 流程完成  4: 流程完成(被拒绝), 5: 流程完成(超时)
	Creator string `gorm:"size:100;column:creator;index"  json:"creator"`  // 创建人

	CreatedAt time.Time `json:"created_at"` // 创建时间
	UpdatedAt time.Time `json:"updated_at"` // 最后更新时间
}

流程公共属性

func (*CommFlow) BaseGetAll

func (c *CommFlow) BaseGetAll(dbInst *gorm.DB, crudModel interface{}, ret interface{}, querys []*common.QueryConditon, fields []string, sortby []string, order []string,
	offset int, limit int) (ml interface{}, totalcount int64, err error)

分页查询 CRUD 对象 GetAll retrieves all oplogs matches certain condition. Returns empty list if no records exist

func (*CommFlow) BaseGetOne

func (c *CommFlow) BaseGetOne(dbInst *gorm.DB, crudModel interface{}, id int64) (ret interface{}, err error)

获取一个CRUD对象

func (*CommFlow) BaseQuery

func (c *CommFlow) BaseQuery(dbInst *gorm.DB, crudModel interface{}, querys []*common.QueryConditon,
	fields []string, sortby []string, order []string) (o *gorm.DB, err error)

基础方法 ---

func (*CommFlow) BaseUpdate

func (c *CommFlow) BaseUpdate(dbInst *gorm.DB, crudModel interface{}, fields []string, saveNil ...bool) (ret interface{}, err error)

更新一个CRUD 对象

func (*CommFlow) Create

func (c *CommFlow) Create(dbInst *gorm.DB, obj interface{}) (err error)

创建CRUD对象

func (*CommFlow) GetFlowName

func (s *CommFlow) GetFlowName() string

获取flowname

func (*CommFlow) GetID

func (f *CommFlow) GetID() uint

获取ID

func (*CommFlow) GetNextStep

func (f *CommFlow) GetNextStep(steps map[string]FlowStep, firstStep ...FlowStep) (step FlowStep, err error)

获取下一步

func (*CommFlow) GetPreStep

func (f *CommFlow) GetPreStep(steps map[string]FlowStep) (step FlowStep, err error)

获取上一步

func (*CommFlow) GetStepHandlers

func (f *CommFlow) GetStepHandlers(name, tblName, stepName string) (ret interface{}, err error)

获取上一步的handlerid,给部分退回时使用

func (*CommFlow) GetValue

func (f *CommFlow) GetValue(flow FlowService, attr string) reflect.Value

获取某个属性值(供step跳转使用)

func (*CommFlow) GoNext

func (x *CommFlow) GoNext(tx *gorm.DB, flow FlowService, tblName, serviceName string, remainingIds []uint) (curStepHandlers []FlowHandler, err error)

流程步骤(下一步/上一步)

func (*CommFlow) ImportData

func (c *CommFlow) ImportData(data [][]string, head []string, db *gorm.DB,
	getModel func() interface{}, getValue func(string, string) (interface{}, error)) (err error)

导入数据 data 需要导入的数据 head 属性表头 dataRowIndex 从第几行开始导入 db 数据连接 model 实例

func (*CommFlow) OpHistory

func (f *CommFlow) OpHistory(offset, limit int, name, tblName string) (ret interface{}, err error)

获取操作状态(含历史)

func (*CommFlow) OpLogHistory

func (f *CommFlow) OpLogHistory(offset, limit int, name, tblName string) (ret interface{}, err error)

获取下一步

func (*CommFlow) SetValue

func (f *CommFlow) SetValue(tx *gorm.DB, flow FlowService, attr string, refvalue reflect.Value) (err error)

更新属性信息(供step使用)

type CommStep

type CommStep struct {
	KeyId              string       // 标识
	Rate               int          // 通过率,默认 100
	Handler            FlowHandler  // 处理人
	HandlersInFlowAttr string       // handers 默认存储到flow到那个属性中
	Configs            []ConfigPage // 处理该步骤需要对参数对象
	LoadConfig         func(flow FlowService) []ConfigPage
	LoadJSONConfig     func(flow FlowService) interface{}                      // json生成的map嵌套对象
	CancelDo           func(tx *gorm.DB, flowId uint, flow string) (err error) // 返回当前部署时,清空数据
}

func (*CommStep) AddHandlers

func (s *CommStep) AddHandlers(tx *gorm.DB, handlers []FlowHandler) (err error)

handlers 入库

func (*CommStep) ClearHandlers

func (s *CommStep) ClearHandlers(tx *gorm.DB, flowId uint, flow string, steps []string, remainingIds []uint) (err error)

删除当前步骤和上一步的处理记录

func (*CommStep) GetConfigs

func (s *CommStep) GetConfigs(flow FlowService) (ret interface{})

获取处理当前步骤所需要对参数对象(供前端使用)

func (*CommStep) GetDefaultHandlers

func (s *CommStep) GetDefaultHandlers(flow FlowService) (handers string)

从flow属性中获取责任人信息,多个逗号分割,作为步骤初始化时创建handers

func (*CommStep) Hander

func (s *CommStep) Hander() (handler FlowHandler)

找到注册handle

func (*CommStep) Key

func (s *CommStep) Key() (stepKey string)

func (*CommStep) LoadHandlers

func (s *CommStep) LoadHandlers(tx *gorm.DB, flowId uint) (handlers []FlowHandler, err error)

流程步骤等操作信息

func (*CommStep) PassRate

func (s *CommStep) PassRate() (rate int)

通过标准,100 表示所有人结论都要是通过

type ConfigGroup

type ConfigGroup struct {
	Label  string        `json:"label"`            // 名称,需要资源化对标签
	Key    string        `json:"key"`              // 唯一标示,用来对应slot插槽
	Type   string        `json:"type"`             // 分组类型
	Cols   int           `json:"col"`              // form中item一行显示几个
	Items  []ConfigItem  `json:"items,omitempty"`  // 配置项集合
	Tables []ConfigTable `json:"tables,omitempty"` // 表类型配置项
}

分组

type ConfigItem

type ConfigItem struct {
	Label     string                   `json:"label"`              // 名称,需要资源化对标签
	Key       string                   `json:"key"`                // 需要传递给后台对form key
	Type      string                   `json:"type"`               // 类型:int,string,enum
	Value     interface{}              `json:"value"`              // 配置项的值
	ReadOnly  bool                     `json:"readOnly"`           // 是否只读
	Required  bool                     `json:"required"`           // 是否非必填
	Multiple  bool                     `json:"multiple"`           // 是否多选
	Clearable bool                     `json:"clearable"`          // 是否可以清空
	Columns   []map[string]interface{} `json:"columns"`            //
	Vkey      string                   `json:"vkey"`               //
	LabelKey  string                   `json:"labelkey"`           //
	Hidden    bool                     `json:"hidden"`             // 是否隐藏
	Lua       string                   `json:"lua"`                // lua脚本名,只针对enum类型有效
	RemoteUrl string                   `json:"remoteUrl"`          // 远程调用接口
	Validate  []map[string]interface{} `json:"validate,omitempty"` // 校验规则,正则表达式
	Options   []map[string]interface{} `json:"options,omitempty"`  // 可选结果
	Props     map[string]interface{}   `json:"props,omitempty"`    // 扩展属性(Key,value)
	Extra     Extra                    `json:"extra,omitempty"`    // 扩展属性,特定结构
	Control   []ItemControl            `json:"control,omitempty"`  // 联动控制
}

一个config item标示一个配置项

type ConfigPage

type ConfigPage struct {
	Type   string        `json:"type"`   // 定义使用对前端模版类型
	Label  string        `json:"label"`  // 名称,需要资源化对标签
	Groups []ConfigGroup `json:"groups"` // 分组
}

分页

type ConfigTable

type ConfigTable struct {
	Columns    []ConfigItem             `json:"columns"`       // 列类型
	Value      []map[string]interface{} `json:"value"`         // 值
	RowModAble bool                     `json:"rowModAble"`    // 表格是否允许添加和删除行
	Key        string                   `json:"key,omitempty"` // 唯一标示,和itemkey等都不能重复
}

type CurdTblData

type CurdTblData struct {
	DataUrl             string                 `json:"dataUrl"`
	ShowOperationColumn bool                   `json:"showOperationColumn"`
	Multidelete         bool                   `json:"multiDelete"`
	DeleteObject        map[string]interface{} `json:"deleteObject"`
	AddObject           ActionObject           `json:"addObject"`
	EditObject          ActionObject           `json:"editObject"`
	DetailObject        map[string]interface{} `json:"detailObject"`
	ImportAction        map[string]interface{} `json:"importAction"`
	ExportAction        string                 `json:"exportAction"`
	Columns             []TblColumn            `json:"columns"`
}

curd table init data 对象

type DeleteInf

type DeleteInf interface {
	// 删除一个对象
	Delete(CRUDContext, *gin.Context) (ret interface{}, oplog string, err error)
}

type Export

type Export interface {
	// 返回excel文件连接
	Export(CRUDContext, *gin.Context) (content io.ReadSeeker, oplog string, err error)
}

导出接口

type Extra

type Extra struct {
	Columns []map[string]interface{} `json:"columns,omitempty"`
}

type FlowHandler

type FlowHandler interface {
	// 保存用户的处理结果
	Do(CRUDContext, *gin.Context) (ret interface{}, oplog string, err error)
	// 从数据库中加载数据,返回一个新实例
	LoadInst(flow FlowService, uname string, id uint) (handler FlowHandler, err error)
	LoadStepHandlers(tx *gorm.DB, flowId uint, stepKey string) (handlers []FlowHandler, err error)
	GetConclusion() bool // 是否通过
	IsFinish() bool      // 是否完成审核
	TableName() string   // 表名
}

flow handler 接口

type FlowService

type FlowService interface {
	GetID() uint
	// 获取flowname
	GetFlowName() string
	// 新建流程
	New(c *gin.Context) (flowId uint, ret interface{}, oplog string, err error)
	// make新实例
	NewInst() (flowService FlowService)
	// 获取新实例(从数据库中加载初始值)
	LoadInst(CRUDContext, *gin.Context) (flowService FlowService, err error)
}

FlowService 流程接口,支持各种Service定制

func GetService

func GetService(serviceType string) (FlowService, customerror.CustomError)

GetService 获取Servie 对象

type FlowStep

type FlowStep interface {
	// 唯一标识
	Key() (stepKey string)
	// 通过标准,100 表示所有人结论都要是通过
	PassRate() (rate int)
	// 找到注册handle
	Hander() (handler FlowHandler)
	// 流程步骤等操作信息
	LoadHandlers(tx *gorm.DB, flowId uint) (handlers []FlowHandler, err error)
	// handlers 入库
	AddHandlers(tx *gorm.DB, handlers []FlowHandler) (err error)
	// 退回上一步,清理handlers
	ClearHandlers(tx *gorm.DB, flowId uint, flow string, steps []string, remainingIds []uint) (err error)
	// 从flow属性中获取责任人信息,多个逗号分割,作为步骤初始化时创建handers
	GetDefaultHandlers(flow FlowService) (handers string)
	// 获取处理当前步骤所需要对参数对象(供前端使用)
	GetConfigs(flow FlowService) (ret interface{})
}

flow step 接口

type GetAllInf

type GetAllInf interface {
	// 获取所有流程
	GetAll(CRUDContext, *gin.Context) (ret interface{}, count int64, oplog string, err error)
}

type GetConfigsInf

type GetConfigsInf interface {
	// 获取处理当前流程所需要对参数对象(供前端使用)
	GetConfigs(uname string, id uint, c *gin.Context) (ret interface{}, oplog string, err error)
}

type GetCurStepInf

type GetCurStepInf interface {
	// 获取当前步骤
	GetCurStep() (step FlowStep, err error)
}

type GetNextStepInf

type GetNextStepInf interface {
	// 获取下一步
	GetNextStep() (step FlowStep, err error)
}

type GetOneInf

type GetOneInf interface {
	// 获取一个对象详情
	GetOne(CRUDContext, *gin.Context) (ret interface{}, oplog string, err error)
}

type GetPreStepInf

type GetPreStepInf interface {
	// 获取上一步
	GetPreStep() (step FlowStep, err error)
}

type GetValueInf

type GetValueInf interface {
	// 获取某个属性值(供step使用)
	GetValue(attr string) reflect.Value
}

type GoNextInf

type GoNextInf interface {
	// 流程步骤(下一步/上一步), remainingIds:上一步需要重新处理的,默认全部需要
	GoNext(tx *gorm.DB, remainingIds []uint) (handlers []FlowHandler, err error)
}

type Import

type Import interface {
	// 导入操作
	Import(io.Reader, CRUDContext, *gin.Context) (ret interface{}, oplog string, err error)
}

导入接口

type ItemControl

type ItemControl struct {
	Value   interface{}  `json:"value,omitempty"`
	Append  string       `json:"append,omitempty"`
	Prepend string       `json:"prepend,omitempty"`
	Rule    []ConfigItem `json:"rule,omitempty"`
}

type MultiDeleteInf

type MultiDeleteInf interface {
	// 删除多个对象
	MultiDelete([]string, CRUDContext, *gin.Context) (ret interface{}, oplog string, err error)
}

type OpHistoryInf

type OpHistoryInf interface {
	// 获取操作状态
	GetOpHistory() (ret interface{}, oplog string, err error)
}

type OpLogHistoryInf

type OpLogHistoryInf interface {
	// 获取操作日志历表
	GetOpLogHistory() (ret interface{}, oplog string, err error)
}

type OplogModelInf

type OplogModelInf interface {
	// 返回操作日志记录对象(主要是确定表名)
	OplogModel(*gin.Context, CRUDContext) interface{}
}

日志表自定义接口

type PreHandlersInf

type PreHandlersInf interface {
	// 获取上一步操作者
	GetPreHandlers() (ret interface{}, oplog string, err error)
}

type SetValueInf

type SetValueInf interface {
	// 更新属性信息(供step使用)
	SetValue(tx *gorm.DB, attr string, refvalue reflect.Value) (err error)
}

type TblColumn

type TblColumn struct {
	Label         string                   `json:"label"`                   // 列标题
	FixedPosition string                   `json:"fixedPosition,omitempty"` // 对齐方式
	Prop          string                   `json:"prop"`                    // 列属性名
	Sortable      bool                     `json:"sortable,omitempty"`      // 是否支持排序
	Queryable     bool                     `json:"queryable,omitempty"`     // 是否支持查询
	Vmap          map[string]interface{}   `json:"vmap,omitempty"`          // 显示替换值map
	Filter        []map[string]interface{} `json:"filter,omitempty"`        // 过滤
	Type          string                   `json:"type,omitempty"`          // 类型
	Width         int                      `json:"width,omitempty"`         // 列宽
}

列属性(curd表的列)

type UpdateInf

type UpdateInf interface {
	// 更新对象
	Update(fc CRUDContext, c *gin.Context) (ret interface{}, oplog string, err error) // 刷新流程基础信息

}

Jump to

Keyboard shortcuts

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