增加任务自动流转
Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
parent
959a2e04e4
commit
19fd911b1b
@ -37,9 +37,7 @@ class Task
|
|||||||
{
|
{
|
||||||
Log::init(['path' => 'log/task']);
|
Log::init(['path' => 'log/task']);
|
||||||
$isRobot = (isset($data['data']) && isset($data['data']['is_robot']) && $data['data']['is_robot']) ? 1 : 0;
|
$isRobot = (isset($data['data']) && isset($data['data']['is_robot']) && $data['data']['is_robot']) ? 1 : 0;
|
||||||
logRecord($isRobot,'robot');
|
|
||||||
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['taskCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectLog'), 'action_type' => 'task', 'is_robot' => $isRobot];
|
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['taskCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectLog'), 'action_type' => 'task', 'is_robot' => $isRobot];
|
||||||
logRecord($data);
|
|
||||||
$task = \app\common\Model\Task::where(['code' => $data['taskCode']])->find();
|
$task = \app\common\Model\Task::where(['code' => $data['taskCode']])->find();
|
||||||
$logData['project_code'] = $task['project_code'];
|
$logData['project_code'] = $task['project_code'];
|
||||||
$toMember = [];
|
$toMember = [];
|
||||||
@ -187,33 +185,34 @@ class Task
|
|||||||
}
|
}
|
||||||
ProjectLog::create($logData);
|
ProjectLog::create($logData);
|
||||||
//工作流事件
|
//工作流事件
|
||||||
|
if (!$isRobot) {
|
||||||
$workflowActions = ['create', 'move', 'done', 'redo', 'assign', 'setEndTime', 'pri'];
|
$workflowActions = ['create', 'move', 'done', 'redo', 'assign', 'setEndTime', 'pri'];
|
||||||
if (in_array($data['type'], $workflowActions)) {
|
if (in_array($data['type'], $workflowActions)) {
|
||||||
$taskStageCode = $task['stage_code'];
|
$taskStageCode = $task['stage_code'];
|
||||||
$action = TaskWorkflowRule::getActionByTaskType($data['type']);
|
$action = TaskWorkflowRule::getActionByTaskType($data['type']);
|
||||||
$taskWorkflowRule = TaskWorkflowRule::where(['object_code' => $taskStageCode, 'sort' => 1])->order('id asc')->find();
|
$taskWorkflowRule = TaskWorkflowRule::where(['object_code' => $taskStageCode, 'sort' => 1])->order('id asc')->find();
|
||||||
if ($taskWorkflowRule) {
|
if ($taskWorkflowRule) {
|
||||||
$taskWorkflowRuleList = TaskWorkflowRule::where(['workflow_code' => $taskWorkflowRule['workflow_code']])->order('sort asc')->select();
|
$nextTaskWorkflowRule = TaskWorkflowRule::where(['workflow_code' => $taskWorkflowRule['workflow_code'], 'sort' => 2])->find();
|
||||||
if ($taskWorkflowRuleList) {
|
if ($nextTaskWorkflowRule) {
|
||||||
$condition = $taskWorkflowRuleList[1];
|
if ($nextTaskWorkflowRule['action'] == $action) {
|
||||||
if ($condition['action'] == $action) {
|
|
||||||
$goon = true;
|
$goon = true;
|
||||||
if ($action == 3) {
|
if ($action == 3) {
|
||||||
//设置执行人
|
//设置执行人
|
||||||
$toMemberCode = $toMember['code'];
|
$toMemberCode = $toMember['code'];
|
||||||
if ($toMemberCode != $condition['object_code']) {
|
if ($toMemberCode != $nextTaskWorkflowRule['object_code']) {
|
||||||
$goon = false;
|
$goon = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($goon) {
|
if ($goon) {
|
||||||
$do = $taskWorkflowRuleList[2];
|
$doTaskWorkflowRule = TaskWorkflowRule::where(['workflow_code' => $taskWorkflowRule['workflow_code'], 'sort' => 3])->find();
|
||||||
TaskWorkflowRule::doAction($task, $do);
|
$doTaskWorkflowRule && TaskWorkflowRule::doAction($task, $doTaskWorkflowRule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//触发推送的事件
|
//触发推送的事件
|
||||||
$notifyActions = ['done', 'redo', 'assign'];
|
$notifyActions = ['done', 'redo', 'assign'];
|
||||||
if (in_array($data['type'], $notifyActions)) {
|
if (in_array($data['type'], $notifyActions)) {
|
||||||
|
112
application/project/controller/TaskWorkflow.php
Normal file
112
application/project/controller/TaskWorkflow.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\project\controller;
|
||||||
|
|
||||||
|
use controller\BasicApi;
|
||||||
|
use think\facade\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
class TaskWorkflow extends BasicApi
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
if (!$this->model) {
|
||||||
|
$this->model = new \app\common\Model\TaskWorkflow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示资源规则
|
||||||
|
* @return void
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$where = [];
|
||||||
|
$code = Request::post('projectCode');
|
||||||
|
if (!$code) {
|
||||||
|
$this->error("请选择一个项目");
|
||||||
|
}
|
||||||
|
$where[] = ['project_code', '=', $code];
|
||||||
|
$list = $this->model->where($where)->select();
|
||||||
|
if ($list) {
|
||||||
|
foreach ($list as &$item) {
|
||||||
|
unset($item['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->success('', $list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
* @param Request $request
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function save(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request::only('name,projectCode');
|
||||||
|
if (!$request::post('name')) {
|
||||||
|
$this->error("请填写规则名称");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$result = $this->model->createStage($data['name'], $data['projectCode']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error($e->getMessage(), $e->getCode());;
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
$this->success('添加成功', $result);
|
||||||
|
}
|
||||||
|
$this->error("操作失败,请稍候再试!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存
|
||||||
|
* @param Request $request
|
||||||
|
* @return void
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function edit(Request $request)
|
||||||
|
{
|
||||||
|
$data = $request::only('name,stageCode');
|
||||||
|
if (!$request::post('name')) {
|
||||||
|
$this->error("请填写规则名称");
|
||||||
|
}
|
||||||
|
if (!$data['stageCode']) {
|
||||||
|
$this->error("请选择一个规则");
|
||||||
|
}
|
||||||
|
$template = $this->model->where(['code' => $data['stageCode']])->field('id')->find();
|
||||||
|
if (!$template) {
|
||||||
|
$this->error("该规则已失效");
|
||||||
|
}
|
||||||
|
$result = $this->model->_edit(['name' => $data['name']], ['code' => $data['stageCode']]);
|
||||||
|
if ($result) {
|
||||||
|
$this->success('');
|
||||||
|
}
|
||||||
|
$this->error("操作失败,请稍候再试!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除规则
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$code = Request::post('code');
|
||||||
|
if (!$code) {
|
||||||
|
$this->error("请选择一个规则");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$result = $this->model->deleteStage($code);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->error($e->getMessage(), $e->getCode());;
|
||||||
|
}
|
||||||
|
if ($result) {
|
||||||
|
$this->success('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user