Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I run the workflow , such as: flow.Run(), flow.netStep() ? When I have run [ Documents.New ] and [ Documents.setState ] , there is not data in tabale [wf_documents_001] . #101

Closed
yuedefeng opened this issue Nov 21, 2018 · 14 comments
Assignees
Labels

Comments

@yuedefeng
Copy link

How can I Use it , can you give me a demo ?

@yuedefeng
Copy link
Author

When I have run [ Documents.New ] and [ Documents.setState ] , there is not data in tabale [wf_documents_001] .

How can I run the workflow , such as: flow.Run(), flow.netStep() ?


func (this *WFApi) WorkflowsCreate() {

tx, _ := db.Begin()
defer tx.Rollback()

docType1, err = DocTypes.New(tx, "EXAM:COMMON")

//////
docState1, err = DocStates.New(tx, "Init") //初始化
docState2, err = DocStates.New(tx, "EntrustCreate") //委托创建
docState3, err = DocStates.New(tx, "EntrustApproved") //委托审核
docState4, err = DocStates.New(tx, "SampleHandon") //样本交接
docState5, err = DocStates.New(tx, "PrepareFinish") //制备完成
DocStates.New(tx, "PrepareApproved") //制备审核
DocStates.New(tx, "TaskAssign") //任务分配
DocStates.New(tx, "DataApproved") //数据录入审核
DocStates.New(tx, "ReportGen") //报告生成
DocStates.New(tx, "ReportApproved") //报告审核

/////
docActionID1, _ := DocActions.New(tx, "CreateEntrust", false) //创建委托
docActionID2, _ := DocActions.New(tx, "ApproveEntrust", false) //审核委托
docActionID3, _ := DocActions.New(tx, "HandonSample", false) //提交样本
docActionID4, _ := DocActions.New(tx, "FinishPrepare", true) //完成制备
docActionID5, _ := DocActions.New(tx, "ApprovePrepare", true) //审核制备
docActionID6, _ := DocActions.New(tx, "AssignTask", false) //分配任务
docActionID7, _ := DocActions.New(tx, "ApproveData", false) //审核数据
docActionID8, _ := DocActions.New(tx, "GenReport", false) //生成报告
docActionID9, _ := DocActions.New(tx, "ApproveReport", true) //审核报告

workflowId, _ := Workflows.New(tx, "Examination", docType1, docState1)
Workflows.SetActive(tx, workflowId, true)

//创建Docments
contextId, _ := AccessContexts.New(tx, "Context")
groupId, _ := Groups.New(tx, "Examination", "exam")

resUser, _ := tx.Exec(`INSERT INTO users_master(first_name, last_name, email, active)
		VALUES('admin', 'dashoo', 'admin@dashoo.com', 1)`)
uid, _ := resUser.LastInsertId()
userID1 := UserID(uid)

Groups.AddUser(tx, groupId, userID1)
roleID1, _ := Roles.New(tx, "administrator")
Roles.AddPermissions(tx, roleID1, docType1, []DocActionID{docActionID1, docActionID2,
	docActionID3, docActionID4, docActionID5, docActionID6, docActionID7, docActionID8, docActionID9})

docNewInput := DocumentsNewInput {
	DocTypeID: docType1,
	AccessContextID: contextId,
	GroupID: groupId,
	Title: "entrust flow",
	Data: "eid: 111, entrustNo: 2222",
}
Documents.New(tx, &docNewInput)

documentID1, _ := Documents.New(tx, &docNewInput)
Documents.setState(tx, docType1, documentID1, docState2, contextId)


tx.Commit()

}

@js-ojus
Copy link
Owner

js-ojus commented Nov 21, 2018

Thanks for your interest @yuedefeng !

I am travelling currently. Please allow me until tomorrow to respond.

@yuedefeng yuedefeng changed the title How can I Use it , can you give me a demo ? How can I run the workflow , such as: flow.Run(), flow.netStep() ? When I have run [ Documents.New ] and [ Documents.setState ] , there is not data in tabale [wf_documents_001] . Nov 22, 2018
@yuedefeng
Copy link
Author

Thanks for your support, waiting for you

@js-ojus
Copy link
Owner

js-ojus commented Nov 22, 2018

A quick note: Documents.setState should not be called directly. The comment says:

// This method is not exported.  It is used internally by `Workflow`
// to move the document along the workflow, into a new document state.

A Node each has to be defined for each document state of the workflow, except the final state. Please look at _Workflows.AddNode.

A DocEvent has to be constructed to signal to the workflow that a DocAction has been performed by either the user or a system event. Document states are changed by Workflow.ApplyEvent, to which this event has to be fed. In turn, the workflow loads the node corresponding to the document state specified in the event, and applies the event to the node with the specified document.

The node applies the given document action to transition the document into the target state of the action. These transitions are defined for document types. Please see Transition and TransitionMap in the file doctype.go.

@js-ojus
Copy link
Owner

js-ojus commented Nov 22, 2018

Please print the value of q2 before line 236 of document.go, and let me know the constructed query.

Also, in:

documentID1, _ := Documents.New(tx, &docNewInput)

don't discard the error. Please see if there is any error reported, and let me know.

@js-ojus js-ojus self-assigned this Nov 23, 2018
@js-ojus
Copy link
Owner

js-ojus commented Nov 24, 2018

@yuedefeng : ping!!

@yuedefeng
Copy link
Author

yuedefeng commented Nov 24, 2018

Documents.New has no error. But when I run the DocEvents.New, the error [sql: Scan error on column index 4, name 'ctime':unsupported Scan, storing driver.Value type []uint8] .

the following is my code:

func (this *WFApi) WorkflowsNext() {

tx, _ := db.Begin()
defer tx.Rollback()

/*docNewInput := DocumentsNewInput {
	DocTypeID: docType1,
	AccessContextID: contextId,
	GroupID: groupId,
	Title: "entrust flow",
	Data: "eid: 111, entrustNo: 2222",
}
documentID1, err := Documents.New(tx, &docNewInput)
fmt.Println("documentID1=", documentID1, err)*/

docEventInput := DocEventsNewInput{
	DocTypeID: DocTypeID(1),
	DocumentID: DocumentID(1),
	DocStateID: DocStateID(2),
	DocActionID: DocActionID(2),
	GroupID: GroupID(1),
	Text: "开始审批",
}
groupIds := []GroupID{GroupID(1)}
myWorkflow, err := Workflows.Get(WorkflowID(1))
docEvent1, err := DocEvents.New(tx, &docEventInput)
myDocEvent, err := DocEvents.Get(docEvent1)
newDocStateId, err := myWorkflow.ApplyEvent(tx, myDocEvent, groupIds)
fmt.Println("newDocStateId=", newDocStateId, err)


tx.Commit()

}

@yuedefeng
Copy link
Author

There is a bug, workflow.go[line: 371], less a '?'
q := INSERT INTO wf_workflow_nodes(doctype_id, docstate_id, ac_id, workflow_id, name, type) VALUES(?, ?, ?, ?, ?)

@yuedefeng
Copy link
Author

All of the 'ctime' has the same error, I have change the sql:

/q := SELECT id, doctype_id, doc_id, docstate_id, docaction_id, group_id, data, ctime, status FROM wf_docevents WHERE id = ?/
q := SELECT id, doctype_id, doc_id, docstate_id, docaction_id, group_id, data, status FROM wf_docevents WHERE id = ?
row := db.QueryRow(q, eid)
//err := row.Scan(&elem.ID, &elem.DocType, &elem.DocID, &elem.State, &elem.Action, &elem.Group, &text, &elem.Ctime, &dstatus)
err := row.Scan(&elem.ID, &elem.DocType, &elem.DocID, &elem.State, &elem.Action, &elem.Group, &text, &dstatus)
if err != nil {
return nil, err
}

@js-ojus
Copy link
Owner

js-ojus commented Nov 24, 2018

Documents.New has no error. But when I run the DocEvents.New, the error [sql: Scan error on column index 4, name 'ctime':unsupported Scan, storing driver.Value type []uint8] .

As per the documentation at https://github.com/go-sql-driver/mysql/#timetime-support:

However, many want to scan MySQL DATE and DATETIME values into time.Time variables, which is the logical opposite in Go to DATE and DATETIME in MySQL. You can do that by changing the internal output type from []byte to time.Time with the DSN parameter parseTime=true.

Please append ?parseTime=true to the database connection string.

@js-ojus
Copy link
Owner

js-ojus commented Nov 24, 2018

There is a bug, workflow.go[line: 371], less a '?'
q := INSERT INTO wf_workflow_nodes(doctype_id, docstate_id, ac_id, workflow_id, name, type) VALUES(?, ?, ?, ?, ?)

Ouch! I see that I have not merged a few ad hoc fixes back. Thanks for spotting this!

I shall do a diff on the local copy, and review these ad hoc changes.

@yuedefeng
Copy link
Author

How can I add data to datatable [wf_docstate_transitions] ?
When I call myWorkflow.ApplyEvent, received the error ErrWorkflowInvalidAction ?


tstate, ok := ts[event.Action]
if !ok {
return 0, ErrWorkflowInvalidAction
}

@yuedefeng
Copy link
Author

where is the step history of the workflow ?

@js-ojus
Copy link
Owner

js-ojus commented Nov 24, 2018

Please open new issues for additional bugs/questions.

@js-ojus js-ojus closed this as completed Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants