一级节点 -> 二级节点
 节点一  :   节点任务一 、 节点任务二 、 节点任务三
 节点二  :   节点任务一 、 节点任务二 、 节点任务三 、 节点任务四 、 节点任务五 、 节点任务六
 节点三  :   节点任务一 、 节点任务二
 节点四  :   节点任务一
 节点五  :   节点任务一 、 节点任务二 、 节点任务三 、 节点任务四业务模式是这样的:节点分为两级,一级节点下设有多个并联的二级节点(二级节点数量不定)
每一个业务都要按照一级节点顺序来走,每个节点都必须走,每个节点中的任务也是必须走的,但是可以不按顺序,也就是说二级节点的所有任务可以并发执行,该节点下的所有任务都执行完了就可以跳到下一个节点以前的设计是只有一级节点,其中关于业务的许多报表不能统计
现在想升级一下换个模式,但不知如何设计数据库结构比较合理?

解决方案 »

  1.   


    --参考一下Oracle树型查找的例子:drop table test_tree;
    create  table   test_tree   
      (   
          userid number(8) not null primary key,   
          username varchar2(18) not null,   
          p_username varchar2(18),   
          num number(10,2)   
      );   
        
      insert   into   test_tree   values(1,'1000',null,null);   
      insert   into   test_tree   values(2,'1100','1000',null);   
      insert   into   test_tree   values(3,'1200','1000',null);   
      insert   into   test_tree   values(4,'1101','1100',100);   
      insert   into   test_tree   values(5,'1102','1100',200);   
      insert   into   test_tree   values(6,'1104','1100',250);   
      insert   into   test_tree   values(7,'1201','1200',150);   
      insert   into   test_tree   values(8,'1205','1200',200);   
      insert   into   test_tree   values(9,'1207','1200',150);   
      commit;   select * from test_tree;
        
    select b.username,
           b.p_username,
           (select distinct sum(nvl(a.num, 0))
              from test_tree a
             start with a.username = b.username
            connect by a.p_username = prior a.username) sum
      from test_tree b
     start with username = '1000'
    connect by p_username = prior username;
      

  2.   


    --楼主是不是这个意思?SQL> select * from test_tree;   USERID USERNAME           P_USERNAME                  NUM
    --------- ------------------ ------------------ ------------
            1 1000                                  
            2 1100               1000               
            3 1200               1000               
            4 1101               1100                     100.00
            5 1102               1100                     200.00
            6 1104               1100                     250.00
            7 1201               1200                     150.00
            8 1205               1200                     200.00
            9 1207               1200                     150.009 rows selectedSQL> 
    SQL> select b.username,
      2         b.p_username,
      3         (select distinct sum(nvl(a.num, 0))
      4            from test_tree a
      5           start with a.username = b.username
      6          connect by a.p_username = prior a.username) sum
      7    from test_tree b
      8   start with username = '1000'
      9  connect by p_username = prior username;USERNAME           P_USERNAME                SUM
    ------------------ ------------------ ----------
    1000                                        1050
    1100               1000                      550
    1101               1100                      100
    1102               1100                      200
    1104               1100                      250
    1200               1000                      500
    1201               1200                      150
    1205               1200                      200
    1207               1200                      1509 rows selectedSQL> 
      

  3.   


    实际业务就是这样的,只不过在每个节点再附带一些业务信息而已
    保存业务的每个节点提交信息以前的思路是这样的:流程表(以前只有一级节点):
    ID,顺序编号
    yName,节点名称
    yOrder,节点顺序业务表
    ID,自动编号
    yName,所处节点
    ...,各种业务信息每条业务记录都会按照流程表中的节点顺序把所有节点走完,不过节点只有一级
    现在想再细化一下每个节点的任务,就是增加二级节点
    不知道这个表怎么设计比较合适
      

  4.   

    分两个表,一个主表,存储节点信息(id(本节点编号),pid(上级节点编号)),一个从表,存储任务信息(id(任务编号),nid(节点编号)).
      

  5.   

    只要存任务信息就可以了呀,通过任务表可以查到是哪个节点(nid(节点编号))
      

  6.   

    还是这个思路,刚刚拿EXCEL试试
    应该说业务节点只有一级节点,所有的任务可以被称为二级节点
    这样的话,是不是那个从表就不用了?!
      

  7.   


    id(本节点)  pid(父节点)
    1                    0
    2                    1
    3                    1
    4                    1
    5                    0
    6                    5
    7                    5
    ......节点与任务节点的区别是
    节点的父节点是NULL 或 0 ;
    任务节点的父节点是具体值