提交 58ecca14 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

数据动态查找以及动态赋值方法变更

上级 468483ee
......@@ -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
}
......@@ -161,4 +161,20 @@ export const getMyNeed = () => {
url: "/workflowProcess/getMyNeed",
method: 'get',
})
}
// @Tags WorkflowProcess
// @Summary 根据id获取当前节点详情和历史
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "根据id获取当前节点详情和过往"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /workflowProcess/getWorkflowMoveByID [get]
export const getWorkflowMoveByID = (params) => {
return service({
url: "/workflowProcess/getWorkflowMoveByID",
method: 'get',
params
})
}
\ No newline at end of file
......@@ -44,6 +44,10 @@ export default {
name: "ExaWfLeave",
mixins: [infoList],
props:{
business:{
type:Object,
default:function(){return null}
},
wf:{
type:Object,
default:function(){return{}}
......@@ -51,7 +55,8 @@ export default {
},
data() {
return {
type: "",formData: {
type: "",
formData: {
cause:"",
startTime:new Date(),
endTime:new Date(),
......@@ -72,6 +77,7 @@ export default {
workflowProcessID:this.wf.workflowProcessID,
workflowNodeID:this.wf.id,
promoterID:this.userInfo.ID,
operatorID:this.userInfo.ID,
action:"create",
param:""
}
......@@ -89,7 +95,9 @@ export default {
},
async created() {
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if(this.business){
this.formData = this.business
}
}
};
</script>
......
......@@ -164,8 +164,7 @@ export default {
this.$router.push({
name: "workflowUse",
query: {
workflowId: row.id,
activeId:0,
workflowId: row.id
}
});
},
......
<template>
<div class="workflow-use">
<WorkflowInfo v-if="done" :wf="this.node"/>
<WorkflowInfo v-if="done" :wf="this.node" :business="business"/>
</div>
</template>
<script>
import {findWorkflowStep} from "@/api/workflowProcess.js"
import {findWorkflowStep,getWorkflowMoveByID} from "@/api/workflowProcess.js"
export default {
name:"WorklowUse",
data(){
return{
done:false
done:false,
business:null,
node:null
}
},
async created(){
const workflowId = this.$route.query.workflowId
const actionId = this.$route.query.actionId
const businessId = this.$route.query.businessId
const wfmId = this.$route.query.wfmId
if(workflowId){
const res = await findWorkflowStep({id:workflowId})
if(res.code == 0){
......@@ -24,6 +24,13 @@ export default {
this.node = res.data.workflow.nodes[0]
this.done = true
}
}else if(wfmId){
const res = await getWorkflowMoveByID({id:wfmId})
if(res.code == 0){
this.business = res.data.business
this.node = res.data.move.workflowNode
this.done = true
}
}
},
beforeCreate(){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册