You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

122 lines
4.3 KiB

<?php
/**
* User: u73376
* Date: 2018/9/8
* Time: 18:04
*/
class TaskManager
{
/**
* @param $formKey
* @param string $flowCode
* @param string $state
* @return array|void
*/
public static function getTask($formKey, $flowCode = "%", $taskType = "%", $state = "OPEN")
{
$result = DB::result("select * from workflow_task
where form_key='" . $formKey . "' and state='" . $state . "'
and flow_code like '" . $flowCode . "%'
and task_type like '" . $taskType . "%'");
$tasks = array();
foreach ($result as $row) {
$task = new NodeTask();
$task->setTaskId($row['task_id'])
->setFormKey($row['form_key'])
->setNecessary($row['necessary'])
->setTaskType($row['task_type'])
->setErrorInfo($row['error_info'])
->setRemark($row['remark'])
->setFlowCode($row['flow_code'])
->setCompletionCondition($row['completion_condition'])
->setState($row['state'])
->setCreator($row['creator'])
->setJoinRole($row['join_role'])
->setRoleType($row['role_type'])
->setTaskType($row['task_type'])
->setWfCondition($row['wf_condition'])
->setCreateCode($row['create_code']);
array_push($tasks, $task);
}
return $tasks;
}
public static function getTasks(NodeTask $task)
{
$taskClass = new ReflectionClass('NodeTask');
$props = $taskClass->getProperties();
$condition = array();
$sql = "select * From workflow_task where 1=1 ";
foreach ($props as $prop) {
$val = $prop->getValue($task);
$name = $prop->getName();
if (is_null($val) || empty($val) || $prop->isStatic()) continue;
$condition[$name] = $val;
$sql .= " and $name = '$val' ";
}
$tasks = array();
//return $tasks;
$result = DB::result($sql, true);
$tasks = array();
// var_dump( $result);
foreach ($result as $row) {
$task = new NodeTask();
$task->setTaskId($row['task_id'])
->setFormKey($row['form_key'])
->setNecessary($row['necessary'])
->setTaskType($row['task_type'])
->setErrorInfo($row['error_info'])
->setRemark($row['remark'])
->setFlowCode($row['flow_code'])
->setCompletionCondition($row['completion_condition'])
->setState($row['state'])
->setJoinRole($row['join_role'])
->setCreator($row['creator'])
->setRoleType($row['role_type'])
->setWfCondition($row['wf_condition'])
->setTaskType($row['task_type'])
->setCreateCode($row['create_code']);
array_push($tasks, $task);
}
return $tasks;
}
static function closeTaskByFormKey($formKey, $flowCode = "")
{
return null;
}
public static function insertTask(NodeTask $task)
{
$task_id = self::getNewTaskId();
//var_dump( $task_id);
DB::insert_table("workflow_task", array(
"task_id" => $task_id,
"form_key" => $task->getFormKey(),
"flow_code" => $task->getFlowCode(),
"task_type" => $task->getTaskType(),
"completion_condition" => $task->getCompletionCondition(),
"state" => $task->getState(),
"necessary" => $task->getNecessary(),
"error_info" => $task->getErrorInfo(),
"join_role" => $task->getJoinRole(),
"creator" => $task->getCreator(),
"role_type" => $task->getRoleType(),
"remark" => $task->getRemark(),
"phase" => $task->getPhase(),
"wf_condition" => $task->getWfCondition(),
'create_code' => $task->getCreateCode(),
));
return $task_id;
}
static function getNewTaskId()
{
list($msec, $sec) = explode(' ', microtime());
return date('YmdHis') . str_pad((sprintf("%0.4f", $msec) * 10000), 4, STR_PAD_LEFT);
}
}