mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
数据动态查找以及动态赋值方法变更
This commit is contained in:
@@ -228,12 +228,12 @@ func GetMyNeed(c *gin.Context) {
|
||||
func GetWorkflowMoveByID(c *gin.Context) {
|
||||
var req request.GetById
|
||||
_ = c.ShouldBindQuery(&req)
|
||||
err, move, moves := service.GetWorkflowMoveByID(req.Id)
|
||||
err, move, moves, business := service.GetWorkflowMoveByID(req.Id)
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
global.GVA_LOG.Error(errStr)
|
||||
response.FailWithMessage(errStr, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{"move": move, "moves": moves}, c)
|
||||
response.OkWithData(gin.H{"move": move, "moves": moves, "business": business}, c)
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ func initWkModel() {
|
||||
}
|
||||
|
||||
func initWkTable() {
|
||||
|
||||
model.WorkflowBusinessTable = make(map[string]string)
|
||||
model.WorkflowBusinessTable["leave"] = "exa_wf_leaves"
|
||||
model.WorkflowBusinessTable = make(map[string]func() interface{})
|
||||
model.WorkflowBusinessTable["leave"] = func() interface{} {
|
||||
return new(model.ExaWfLeave)
|
||||
}
|
||||
}
|
||||
|
||||
func InitWkMode() {
|
||||
initWkModel()
|
||||
initWkTable()
|
||||
|
||||
}
|
||||
|
||||
@@ -19,3 +19,7 @@ type ExaWfLeaveWorkflow struct {
|
||||
WorkflowBase `json:"wf"`
|
||||
ExaWfLeave `json:"business"`
|
||||
}
|
||||
|
||||
func (e ExaWfLeave) TableName() string {
|
||||
return "exa_wf_leaves"
|
||||
}
|
||||
|
||||
@@ -7,10 +7,9 @@ import (
|
||||
)
|
||||
|
||||
var WorkflowBusinessStruct map[string]func() GVA_Workflow
|
||||
var WorkflowBusinessTable map[string]string
|
||||
var WorkflowBusinessTable map[string]func() interface{}
|
||||
|
||||
type GVA_Workflow interface {
|
||||
GetTableName() string
|
||||
CreateWorkflowMove() *WorkflowMove
|
||||
GetBusinessType() string
|
||||
GetWorkflowBase() WorkflowBase
|
||||
@@ -47,10 +46,6 @@ func (w WorkflowBase) GetWorkflowBase() (workflowBase WorkflowBase) {
|
||||
return w
|
||||
}
|
||||
|
||||
func (w WorkflowBase) GetTableName() string {
|
||||
return WorkflowBusinessTable[w.BusinessType]
|
||||
}
|
||||
|
||||
//定义clazz常量
|
||||
|
||||
const (
|
||||
|
||||
@@ -7,9 +7,14 @@ import (
|
||||
"gin-vue-admin/model"
|
||||
"gin-vue-admin/model/request"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/schema"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func getTable(businessType string) interface{} {
|
||||
return model.WorkflowBusinessTable[businessType]()
|
||||
}
|
||||
|
||||
//@author: [piexlmax](https://github.com/piexlmax)
|
||||
//@function: CreateWorkflowProcess
|
||||
//@description: 创建工作流相关信息
|
||||
@@ -166,7 +171,8 @@ func GetWorkflowProcessInfoList(info request.WorkflowProcessSearch) (err error,
|
||||
func StartWorkflow(wfInterface model.GVA_Workflow) (err error) {
|
||||
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
var txErr error
|
||||
txErr = tx.Table(wfInterface.GetTableName()).Create(wfInterface).Error
|
||||
tableName := getTable(wfInterface.GetBusinessType()).(schema.Tabler).TableName()
|
||||
txErr = tx.Table(tableName).Create(wfInterface).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
@@ -288,7 +294,8 @@ func GetMyNeed(userID uint, AuthorityID string) (err error, wfms []model.Workflo
|
||||
return err, wfms
|
||||
}
|
||||
|
||||
func GetWorkflowMoveByID(id float64) (err error, move model.WorkflowMove, moves []model.WorkflowMove) {
|
||||
func GetWorkflowMoveByID(id float64) (err error, move model.WorkflowMove, moves []model.WorkflowMove, business interface{}) {
|
||||
var result interface{}
|
||||
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
|
||||
var txErr error
|
||||
txErr = tx.Preload("Promoter").Preload("Operator").Preload("WorkflowNode").Preload("WorkflowProcess").First(&move, "id = ?", id).Error
|
||||
@@ -296,11 +303,16 @@ func GetWorkflowMoveByID(id float64) (err error, move model.WorkflowMove, moves
|
||||
return txErr
|
||||
}
|
||||
txErr = tx.Preload("Promoter").Preload("Operator").Preload("WorkflowNode").Preload("WorkflowProcess").Find(&moves, "business_id = ? AND business_type = ?", move.BusinessID, move.BusinessType).Error
|
||||
fmt.Println(moves)
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
result = getTable(move.BusinessType)
|
||||
fmt.Println(result)
|
||||
txErr = tx.First(result, "id = ?", move.BusinessID).Error
|
||||
if txErr != nil {
|
||||
return txErr
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err, move, moves
|
||||
return err, move, moves, result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user