码迷,mamicode.com
首页 > 其他好文 > 详细

流程设计

时间:2016-05-13 11:49:29      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

最近在弄公司的OA系统,整理一下相关思路和方法

OA系统其实说白了就两大块,流程处理和节点权限

 

流程处理即该谁处理,其中涉及到该流程有多少个节点和节点的处理人都有谁、节点与节点之间的关系,A节点过后是B节点还是C节点,怎样判断一个流程是否结束,整理了一下自己的思路分为下面几步

1、配置固定的流程和流程节点

2、设置好每个节点的处理人

3、寻找当前节点的下一步处理人

由于相关情况,这其中遇到了一些问题

1、节点退回时,不固定节点而是选择人退回,这就要找出处理过该条数据的相关人员和对应节点,但是有可能一个人存在于这条数据的两个节点,那么就没有办法确定到底该人员到底是属于哪个节点的,当时跟我们公司相关人员沟通后的结果是选择最近的节点(0_0),最后采用的方法是在流程节点配置的时候按照正常的先后顺序排个序,找到最新处理的那个人的节点

2、有些节点处理的时候可能会交给以前处理过该条数据的某个人员,则在流程节点中添加一个字段在指明到底是跳转到那个节点,再在处理过该条数据的记录中找个最新的那个人

3、相同流程有些数据在C节点已经结束,但是有些数据则在D节点才结束,针对这种情况在流程节点创建一个虚拟结束节点

解决了以上问题差不一个流程处理就OK了,当然还有很多需要改进的地方。。。

 

关于节点权限,采用的思路是每个public方法都新建一个节点,把节点id赋予到user上面,写一个基类每次加载页面都检查一下该user是否该权限,但是,但是,他们改了我们的前端架子,居然用了两层iframe,真的是一下我就不知道该说什么了,所以在这方面做得不是很好,尤其是在数据处理后的列表刷新,算了吧,反正都这样了,主要是现在的公司就这调调

贴一下自己的两个主要代码

这个是关于流程的一些主要方法

<?php
/**
 *
 * 流程主控制器
 * User: Red
 * Date: 2016/1/20
 * Time: 17:03
 */



class main extends AWS_CONTROLLER
{
    public function index()
    {
        if ($_GET[‘op‘] == ‘grid‘) {
            $list = $this->model(‘base‘, ‘flow_case‘)->get_list_json();
            echo $list;
        } else {
            TPL::output(‘flow/index‘);
        }
    }

    /**
     * 流程发起
     * @author Red
     * @date 2016年1月20日17:13:27
     */
    public function add_action()
    {
        $flow = $this->model(‘base‘,‘flow‘)->get_all();

        TPL::assign(‘flow_list‘,$flow);
        TPL::output(‘flow/add‘);
    }

    /**
     * 获取下一节点处理人
     * @author Red
     * @date
     */
    public function get_next_uid_action()
    {
        $status = trim($_POST[‘choose_status‘]);
        $nid    = intval($_POST[‘choose_nid‘]);
        $tid    = intval($_POST[‘choose_tid‘]);
        $isBack = intval($_POST[‘isBack‘]);
        //是否为终节点
        $node_info = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘id‘ => $nid));
        if($status==-2){
            echo json_encode(array(‘is_end_node‘ => -2));
            exit;
        }
        if ($node_info[‘is_end_node‘] == 1 && $status > 0 ) {
            echo json_encode(array(‘is_end_node‘ => 1));
            exit;
        }

        //如果为退回,则是选人退回
        if($isBack==1) {
            $back_info = $this->model(‘trans‘)->get_back_info($tid,$nid);
            echo json_encode($back_info);exit;
        }
        $next_node     = $this->model(‘trans‘)->get_next_flow_node($nid, $status, $_POST);

        //是否是指定节点 在日志表中找出最新的那条记录
        if($node_info[‘is_appoint_node‘]){
            $appoint_info = $this->model(‘trans‘)->get_appoint_info($tid,$node_info[‘appoint_node‘],$next_node[‘id‘]);
            echo json_encode($appoint_info);exit;
        }

        $next_uid_info = $this->model(‘trans‘)->get_next_uid($next_node[‘id‘], $tid);

        echo json_encode($next_uid_info);
    }

    /**
     * 流程发起时获取url
     * @author Red
     * @date
     */
    public function get_start_url_action()
    {
        $fid       = intval($_POST[‘fid‘]);
        $node_info = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘fid‘ => $fid, ‘is_start_node‘ => 1, ‘status‘ => 1));
        $flow_info = $this->model(‘base‘, ‘flow‘)->get_one(array(‘id‘ => $fid));
        if ($node_info && $flow_info) {
            $arr           = explode(":", $node_info[‘template_id‘]);
            $data[‘url‘]   = ‘case/‘ . $arr[0] . ‘/‘ . $arr[1] . ‘/‘;
            $data[‘title‘] = ‘发起‘ . $flow_info[‘name‘];
            echo json_encode($data);
            exit;
        }
        echo json_encode(array());
    }

    /**
     * 流程跳转处理,获取url
     * @author Red
     * @date 2016年1月28日15:32:47
     */
    public function get_flow_url_action()
    {
        $nid       = intval($_POST[‘nid‘]);
        $fid       = intval($_POST[‘fid‘]);
        $node_info = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘id‘ => $nid));
        $flow_info = $this->model(‘base‘, ‘flow‘)->get_one(array(‘id‘ => $fid));
        if ($node_info[‘template_id‘] && $flow_info) {
            $arr                     = explode(":", $node_info[‘template_id‘]);
            $data[‘other‘]           = ‘case‘;
            $data[‘case_controller‘] = trim($arr[0]);
            $data[‘case_function‘]   = trim($arr[1]);
            $data[‘flow_name‘]       = trim($flow_info[‘name‘]);
            $data[‘node_id‘]         = $nid;
            echo json_encode($data);
            exit;
        }
        echo json_encode(array());
    }

    /**
     * 历史记录
     * @author Red
     * @date
     */
    public function show_history_action()
    {
        $fid = intval($_GET[‘fid‘]);
        $tid = intval($_GET[‘tid‘]);

        $join[]   = array(‘fn‘ => ‘oa_flow_nodes‘, ‘on‘ => ‘fn.id=oa_flow_trans_log.nid‘, array(‘node_name‘ => ‘fn.name‘));
        $log_list = $this->model(‘base‘, ‘flow_trans_log‘)->get_join_list(array(‘tid‘ => $tid), $join, ‘*‘, ‘end_time asc‘);
        $list     = array();

        foreach ($log_list as $value) {
            $result = array(
                ‘operator_name‘ => $value[‘operator_name‘],
                ‘leave_word‘    => $value[‘leave_word‘],
                ‘end_time‘      => $value[‘end_time‘],
                ‘node_status‘   => ‘完成 ‘ . $value[‘node_name‘],
                ‘result‘        => $value[‘result‘],
                ‘endpoint‘      => ‘0‘
            );
            $list[] = $result;
        }
        //写入当前节点
        $join1[]      = array(‘fn‘ => ‘oa_flow_nodes‘, ‘on‘ => ‘fn.id=oa_flow_trans_operator.nid‘, array(‘node_name‘ => ‘fn.name‘));
        $join1[]      = array(‘u‘ => ‘oa_users‘, ‘on‘ => ‘u.uid=oa_flow_trans_operator.uid‘, array(‘user_name‘ => ‘u.user_name‘));
        $join1[]      = array(‘t‘ => ‘oa_flow_trans‘, ‘on‘ => ‘t.id=oa_flow_trans_operator.tid‘, array(‘current_nid‘ => ‘t.current_nid‘, ‘t_status‘ => ‘t.status‘));
        $current_node = $this->model(‘base‘, ‘flow_trans_operator‘)->get_join_list(array(‘tid‘ => $tid), $join1);
        $is_end       = ($current_node[‘0‘][‘t_status‘] == 1 && $current_node[‘0‘][‘current_nid‘] == 0) ? 1 : 0;
        $is_delete    = ($current_node[‘0‘][‘t_status‘] == -1 && $current_node[‘0‘][‘current_nid‘] == 0) ? 1 : 0;
        $list[]       = array(
            ‘operator_name‘ => $current_node[‘0‘][‘user_name‘],
            ‘node_status‘   => ‘等待  ‘ . $current_node[‘0‘][‘node_name‘],
            ‘endpoint‘      => ‘1‘,
            ‘is_end‘        => $is_end,
            ‘is_delete‘     => $is_delete
        );
        TPL::assign(‘list‘, $list);
        TPL::output(‘flow/show_history‘);
    }

    /**
     * 删除流程
     * @author Red
     * @date 2016年2月2日11:21:32
     */
    public function delete_flow_action()
    {
        $tid        = intval($_POST[‘tid‘]);
        $leave_word = trim($_POST[‘leave_word‘]);
        start_trans();
        //业务表状态更改
        $trans_info = $this->model(‘base‘, ‘flow_trans‘)->get_one(array(‘id‘ => $tid));
        $res        = $this->model(‘base‘, $trans_info[‘case_table‘])->update_data(array(‘status‘ => -1), array(‘id‘ => $trans_info[‘case_id‘]));
        if ($res === false) {
            back_trans(‘业务表状态更改失败‘);
        }
        //流程表更改
        $res = $this->model(‘base‘, ‘flow_trans‘)->update_data(array(‘current_nid‘ => 0, ‘status‘ => -1), array(‘id‘ => $tid));
        if ($res === false) {
            back_trans(‘流程表状态更改失败‘);
        }
        $user_info = get_user_info();
        //添加日志
        $data                   = array();
        $data [‘tid‘]           = $tid;
        $data [‘operator_name‘] = $user_info[‘user_name‘];
        $data [‘operator_id‘]   = $user_info[‘uid‘];
        $data [‘receive_time‘]  = $trans_info [‘current_node_time‘] ? $trans_info [‘current_node_time‘] : time();
        $data [‘end_time‘]      = time();
        $data [‘nid‘]           = $trans_info[‘current_nid‘];
        $data [‘result‘]        = -1;
        $data [‘leave_word‘]    = $leave_word;
        $res                    = $this->model(‘base‘, ‘flow_trans_log‘)->insert_data($data);
        if ($res === false) {
            back_trans(‘流程表状态更改失败‘);
        }
        $table = substr($trans_info[‘case_table‘],5);
        commit_trans(json_encode(array(‘msg‘=>‘ok‘,‘table‘=>$table)));
    }
}

这个是关于流程处理的方法

<?php
/**
 * 流程控制层 用于流程自动跳转
 * User: Red
 * Date: 2016/1/20
 * Time: 09:37
 */
if (!defined(‘IN_ANWSION‘)) {
    die;
}

class trans_class extends AWS_MODEL
{
    /**
     * 流程处理主入口
     * @author Red
     * @date 2016年1月20日16:47:06
     * @param $property
     * @return bool|int
     * @throws Exception
     */
    public $trans_id;//流程id

    public function trans($property = array())
    {
        $fid = intval($_POST[‘choose_fid‘]);
        if ($fid < 1) {
            writeLog(‘流程id必须‘, ‘trans/error‘);

            return false;

        }
        $tid        = intval($_POST[‘choose_tid‘]);
        $nid        = isset($property[‘nid‘]) ? (int)$property[‘nid‘] : intval($_POST[‘choose_nid‘]);
        $status     = $_POST[‘choose_status‘];
        $msg        = $property[‘msg‘] ? ‘,‘ . trim($property[‘msg‘]) : ‘‘;
        $leave_word = trim($_POST[‘leave_word‘]) . $msg;

        $next_uid = intval($_POST[‘nextHandler‘]);

        $result = self::trans_handle($fid, $nid, $tid, $status, $leave_word, $next_uid, $property, $_POST);

        if ($result) {
            return $result;
        } else {
            return false;
        }

    }


    /**
     * 流程处理
     * @author Red
     * @date  2016年1月20日16:47:55
     * @param $fid
     * @param $tid
     * @param $nid
     * @param $status
     * @param $leave_word
     * @param $next_uid
     * @param $property
     * @param $post
     * @return bool
     * @throws Exception
     */
    private function trans_handle($fid, $nid, $tid, $status, $leave_word, $next_uid, $property, $post)
    {
        if (intval($fid) < 1 || (intval($next_uid) < 1 && !$post[‘choose_is_end_node‘] = 1000)) {
            writeLog(‘参数错误,fid=>‘ . $fid . ‘POST数据=>‘ . print_r($post), ‘trans/error‘);

            return false;
        }
        // 如果tid参数为空,默认处理为发起节点
        if (intval($tid) < 1) {
            $node_info = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘fid‘ => $fid, ‘is_start_node‘ => 1, ‘status‘ => 1));

            $case_id    = $property[‘case_id‘];
            $case_table = $property[‘case_table‘];
            if ($case_id < 1 || empty($case_table)) {
                writeLog(‘发起流程时业务id或业务表未传,property=>‘ . $property, ‘trans/error‘);

                return false;
            }
        } else {
            $node_info = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘id‘ => $nid));
        }

        $nid = $node_info [‘id‘];

        if (!$node_info) {
            writeLog(‘节点不存在,nid=>‘ . $nid, ‘trans/error‘);

            return false;
        }

        $user_info = get_user_info();
        $uid       = $user_info[‘uid‘];
        // ***流程处理开始***
        $trans_info = $this->model(‘base‘, ‘flow_trans‘)->get_one(array(‘id‘ => $tid));

        // 判断是否开始节点
        if ($node_info [‘is_start_node‘] == 1 && $tid < 1) {

            $data [‘current_nid‘]       = $nid;
            $data [‘fid‘]               = $fid;
            $data [‘create_time‘]       = time();
            $data [‘create_uid‘]        = $uid;
            $data [‘current_node_time‘] = time();
            $data ["case_id"]           = $case_id;
            $data ["case_table"]        = $case_table;
            $this->trans_id             = $tid = $this->model(‘base‘, ‘flow_trans‘)->insert_data($data);
            if ($tid === false) {
                writeLog(‘添加流程事务表出错,data=>‘ . $data, ‘trans/errot‘);

                return false;
            }
            // 当前用户作为流程开始节点的启动者
            $operator [‘tid‘] = $tid;
            $operator [‘uid‘] = $uid;
            $operator [‘nid‘] = $nid;
            if ($this->model(‘base‘, ‘flow_trans_operator‘) === false) {
                writeLog(‘设置当前用户作为流程开始节点的启动者出错,operator=>‘ . $operator, ‘trans/error‘);

                return false;
            }
        } else {
            //检查是否是自己的事务
            $join[]    = array(‘ft‘ => ‘oa_flow_trans‘, ‘on‘ => ‘oa_flow_trans_operator.nid=ft.current_nid‘);
            $operators = $this->model(‘base‘, ‘flow_trans_operator‘)->get_join_list(array(‘tid‘ => $tid, ‘uid‘ => $uid, ‘nid‘ => $nid));
            if ($operators < 1) {
                writeLog(‘非自己的事务,无权操作,uid=>‘ . $uid, ‘trans/error‘);

                return false;
            }
        }
        $next_node = self::get_next_flow_node($nid, $status, $post);

        if (($node_info [‘is_end_node‘] == 1 && $status == 1) || ($next_node[‘is_virtual_node‘] == 1 && $status == 1)) {
            //虚拟结束节点处理  手动把当前流程结束

            // 终结同意流程
            $data                 = array();
            $data [‘current_nid‘] = 0;
            $data [‘end_time‘]    = time();
            $data [‘status‘]      = 1;

            $res = $this->model(‘base‘, ‘flow_trans‘)->update_data($data, array(‘id‘ => $tid));
            if ($res === false) {
                writeLog(‘操作结束节点时更新事务表(oa_flow_trans)出错‘, ‘trans/error‘);

                return false;
            }
            //业务表状态更改
            $res = $this->model(‘base‘, $trans_info[‘case_table‘])->update_data(array(‘status‘ => 1), array(‘id‘ => $trans_info[‘case_id‘]));
            if ($res === false) {
                writeLog(‘借宿流程:业务表状态更改出错‘, ‘trans/endFlow‘);

                return false;
            }
        } else if ($status == -2) {
            // 终结拒绝流程
            $data                 = array();
            $data [‘current_nid‘] = 0;
            $data [‘end_time‘]    = time();
            $data [‘status‘]      = -2;

            //业务表状态更改
            $res = $this->model(‘base‘, $trans_info[‘case_table‘])->update_data(array(‘status‘ => -2), array(‘id‘ => $trans_info[‘case_id‘]));
            if ($res === false) {
                writeLog(‘取消流程:业务表状态更改出错‘, ‘trans/cancelFlow‘);

                return false;
            }
            $res = $this->model(‘base‘, ‘flow_trans‘)->update_data($data, array(‘id‘ => $tid));
            if ($res === false) {
                writeLog(‘操作结束节点时更新事务表(oa_flow_trans)出错‘, ‘trans/cancelFlow‘);

                return false;
            }

        } else {

            if ($post[‘isBack‘] == 1) {
                //退回的时候是固定节点不需要再去找一次
                $next_nid           = $nid;
                $next_node[‘value‘] = 0;
                $nid                = $_POST[‘choose_current_nid‘];//流程本身节点
            } else {
                // 正常流程
                $next_node = self::get_next_flow_node($nid, $status, $post);


                if (is_null($next_node) || $next_node === false) {
                    writeLog(‘当前节点不是结束节点并且下1个节点为空‘, ‘trans/error‘);

                    return false;
                }
                $next_nid = $next_node[‘next_nid‘];
            }
            $data                       = array();
            $data [‘status‘]            = 0;
            $data [‘current_nid‘]       = $next_nid;
            $data [‘current_uid‘]       = $next_uid;
            $data [‘current_node_time‘] = time();
            $res                        = $this->model(‘base‘, ‘flow_trans‘)->update_data($data, array(‘id‘ => $tid));
            if ($res === false) {
                writeLog(‘操作非结束节点时更新事务表(oa_flow_trans)出错!data=>‘ . $data, ‘trans/error‘);

                return false;
            }
            $exist_operator = $this->model(‘base‘, ‘flow_trans_operator‘)->get_one(array(‘tid‘ => $tid));

            if ($exist_operator) {

                $res = $this->model(‘base‘, ‘flow_trans_operator‘)->update_data(array(‘nid‘ => $next_nid, ‘uid‘ => $next_uid), array(‘tid‘ => $tid));
            } else {
                //下一节点
                $operator        = array();
                $operator[‘uid‘] = $next_uid;
                $operator[‘tid‘] = $tid;
                $operator[‘nid‘] = $next_nid;
                $res             = $this->model(‘base‘, ‘flow_trans_operator‘)->insert_data($operator);
            }
            if ($res === false) {
                writeLog(‘节点处理人添加失败‘, ‘trans/error‘);

            }
        }
        // ***流程处理结束***

        // 记录处理结果和日志
        $data                   = array();
        $data [‘tid‘]           = $tid;
        $data [‘operator_name‘] = $user_info[‘user_name‘];
        $data [‘operator_id‘]   = $uid;
        $data [‘receive_time‘]  = $trans_info [‘current_node_time‘] ? $trans_info [‘current_node_time‘] : time();
        $data [‘end_time‘]      = time();
        $data [‘nid‘]           = $nid;
        $data [‘result‘]        = ($node_info [‘is_end_node‘] == 1 && $status == 1) ? 1 : (($status == -2) ? -2 : $next_node[‘value‘]);
        $data [‘leave_word‘]    = $leave_word;

        $res = $this->model(‘base‘, ‘flow_trans_log‘)->insert_data($data);
        if ($res === false) {
            writeLog(‘写入操作日志(oa_flow_trans_log)时出错‘, ‘trans/error‘);

            return false;
        }

        return $tid;
    }

    /**
     * 获取当前流程的下一节点
     * @author Red
     * @date  2016年1月20日16:48:48
     * @param $nid
     * @param $val
     * @param $post
     * @return bool
     * @throws Exception
     */
    public function get_next_flow_node($nid, $val, $post)
    {
        $node_info = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘id‘ => $nid));
        if ($node_info [‘fun_name‘] && $node_info[‘form_type‘] == 2) {
            //函数路径
            $fun_file_path = AWS_PATH . ‘fun/‘ . trim($node_info [‘fun_name‘]) . ".php";
            writeLog(‘函数错误,$fun_file_path=>‘ . ($fun_file_path), ‘tt‘);
            if (file_exists($fun_file_path)) {
                include_once $fun_file_path;
                $value = call_user_func_array(‘flow_fun‘, array($post));
            } else {
                writeLog(‘函数错误,$fun_file_path=>‘ . $fun_file_path, ‘trans/error‘);

                return false;
            }
        } else {
            $value = $val;
        }
        $where[‘nid‘]   = $nid;
        $where[‘value‘] = $value;
        $join[]         = array(‘fn‘ => ‘oa_flow_nodes‘, ‘on‘ => ‘fn.id=oa_flow_next_nodes.next_nid‘, ‘fn.*‘);
        $next_node_info = $this->model(‘base‘, ‘flow_next_nodes‘)->get_join_list($where, $join, ‘*‘, ‘‘, 1);
        if (!$next_node_info) {
            writeLog(‘something wrong‘, ‘trans/error‘);

            return false;
        }

        return $next_node_info[0];
    }

    /**
     * 获取下一处理人
     * @author Red
     * @date 2016年1月26日13:47:00
     * @param $nid
     * @param int $tid
     * @return array|bool
     * @throws Exception
     */
    public function get_next_uid($nid, $tid = 0)
    {

        $flow_node    = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘id‘ => $nid));
        $next_handler = array();
        if (!$flow_node) {
            writeLog(‘节点不存在,nid=‘ . $nid, ‘trans/choose_next_uid‘);

            return false;
        }
        //虚拟终节点
        if ($flow_node[‘is_virtual_node‘] == 1) {
            return array(‘is_end_node‘ => 1);
        }

        $join[]    = array(‘no‘ => ‘oa_flow_node_operator‘, ‘on‘ => ‘no.nid=oa_flow_nodes.id‘);
        $join[]    = array(‘ug‘ => ‘oa_flow_group‘, ‘on‘ => ‘ug.id=no.group_id‘, array(‘uids‘ => ‘ug.uids‘));
        $operators = $this->model(‘base‘, ‘flow_nodes‘)->get_join_list(array(‘oa_flow_nodes.id‘ => $nid), $join);

        if (count($operators) < 1) {
            $next_handler [] = array(
                ‘uid‘            => -1000,
                ‘name‘           => ‘请配置节点处理人‘,
                ‘selected‘       => ‘selected‘,
                ‘next_nid‘       => $flow_node[‘id‘],
                ‘next_node_name‘ => $flow_node[‘name‘],
            );

            return $next_handler;
        }
        //默认选择项
        //退回的
        $back_log = $this->model(‘base‘, ‘flow_trans_log‘)->get_list(array(‘nid‘ => $nid, ‘tid‘ => $tid, ‘result‘ => 0), ‘end_time desc‘, 1);
        if ($back_log) {
            $operator_id = $back_log[‘operator_id‘];
        }
        //找人
        $users = $this->model(‘base‘, ‘users‘)->get_all(array(‘status‘ => 1, ‘uid‘ => array(‘in‘ => $operators[0][‘uids‘])));

        foreach ($users as $item) {
            // 不是自己的处理人加入列表
            //if ($item [‘uid‘] != $uid) {

            $next_handler [] = array(
                ‘uid‘            => $item[‘uid‘],
                ‘name‘           => $item[‘dept_name‘] ? $item[‘true_name‘] . ‘【‘ . $item[‘dept_name‘] . ‘】‘ : $item[‘true_name‘],
                ‘selected‘       => $operator_id == $item [‘uid‘] ? ‘selected‘ : ‘‘,
                ‘next_nid‘       => $flow_node[‘id‘],
                ‘next_node_name‘ => $flow_node[‘name‘],
            );
            // }
        }

        return $next_handler;
    }

    /**
     * 退回时选择人,这些人从translog中去找,曾经处理过该条数据的人,
     *              如果这个人隶属于两个节点,这把这人归属于最后一个节点(confirmed by 菊姐 2016年4月21日15:51:21)
     * @author Red
     * @date 2016年4月21日16:34:52
     * @param $tid
     * @param $nid
     * @return array
     */
    public function get_back_info($tid, $nid)
    {
        //没有具体的方法来判断节点的先后关系,所以在配置流程节点时请注意严格按照流程的先后顺序来设置流程节点
        //想了一下可以根据结束时间来判断,因为就算有退回的那么它的的结束时间也应该是最后的 red 2016年4月22日09:33:11
        //又想了一下发现还是不行,最后在每个流程节点添加一个sort字段用于节点的先后排序 2016年4月22日11:18:39

        //1.找到最近的那条日志关联flow_nodes找出sort
        //2.找到这条数据的所有日志(排除比sort大的,排除nid相同的)
        //3.最后去重,找到nid

        $join[]      = array(‘u‘ => ‘oa_users‘, ‘on‘ => ‘u.uid=oa_flow_trans_log.operator_id‘, array(‘dName‘ => ‘u.dept_name‘, ‘tName‘ => ‘true_name‘));
        $join[]      = array(‘fn‘ => ‘oa_flow_nodes‘, ‘on‘ => "fn.id=oa_flow_trans_log.nid", array(‘sort‘ => ‘fn.sort‘), ‘joinType‘ => ‘left‘);
        $current_log = $this->model(‘base‘, ‘flow_trans_log‘)->get_join_list(array(‘tid‘ => $tid), $join, ‘*‘, ‘id desc‘, 1);


        $log_list = $this->model(‘base‘, ‘flow_trans_log‘)->get_join_list(array(‘tid‘ => $tid, ‘oa_flow_trans_log.result‘ => 1, ‘fn.sort‘ => array(‘lte‘ => $current_log[0][‘sort‘]), ‘nid‘ => array(‘neq‘ => $nid)), $join);

        //去掉重复的人
        foreach ($log_list as $value) {
            $user_list[$value[‘operator_id‘]] = $value;
        }

        //寻找nid
        foreach ($log_list as $value) {
            foreach ($user_list as $k => $val) {
                if ($value[‘operator_id‘] == $val[‘operator_id‘] && $value[‘tid‘] == $val[‘tid‘]) {

                    if ($value[‘sort‘] < $val[‘sort‘]) {
                        $val[‘t_nid‘] = $value[‘nid‘];
                    } else {
                        $val[‘t_nid‘] = $value[‘nid‘];
                    }
                    $user_lists[$k] = $val;
                }

            }
        }

        foreach ($user_lists as $item) {

            $next_handler [] = array(
                ‘uid‘      => $item[‘operator_id‘],
                ‘name‘     => $item[‘dName‘] ? $item[‘tName‘] . ‘【‘ . $item[‘dName‘] . ‘】‘ : $item[‘tName‘],
                ‘selected‘ => ‘‘,
                ‘next_nid‘ => $item[‘t_nid‘],
            );
        }

        return $next_handler;
    }

    /**
     * 指定节点找人
     * @author Red
     * @date 2016年5月10日15:22:55
     * @param $tid
     * @param $appoint_nid
     * @param $next_nid
     * @return array
     */
    public function get_appoint_info($tid, $appoint_nid,$next_nid)
    {
        $flow_node   = $this->model(‘base‘, ‘flow_nodes‘)->get_one(array(‘id‘ => $next_nid));
        $join[]      = array(‘u‘ => ‘oa_users‘, ‘on‘ => ‘u.uid=oa_flow_trans_log.operator_id‘, array(‘dName‘ => ‘u.dept_name‘, ‘tName‘ => ‘true_name‘));
        $join[]      = array(‘fn‘ => ‘oa_flow_nodes‘, ‘on‘ => "fn.id=oa_flow_trans_log.nid", array(‘node_name‘ => ‘fn.name‘), ‘joinType‘ => ‘left‘);
        $appoint_log = $this->model(‘base‘, ‘flow_trans_log‘)->get_join_list(array(‘nid‘ => $appoint_nid, ‘tid‘ => $tid, ‘oa_flow_trans_log.result‘ => 1), $join, ‘*‘, ‘id desc‘, 1);

        $next_handler [] = array(
            ‘uid‘            => $appoint_log[0][‘operator_id‘],
            ‘name‘           => $appoint_log[0][‘dName‘] ? $appoint_log[0][‘tName‘] . ‘【‘ . $appoint_log[0][‘dName‘] . ‘】‘ : $appoint_log[0][‘tName‘],
            ‘selected‘       => ‘‘,
            ‘next_nid‘       => $next_nid,
            ‘next_node_name‘ => $flow_node[‘name‘],
        );

        return $next_handler;
    }
}

 

流程设计

标签:

原文地址:http://www.cnblogs.com/red-j/p/5486576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!