由于工作流的表结构中,几个主要实体之间存在外键关系。所以归档一条流程实例相应的活动和工作项等记录的时候需要按照其相应的顺序。
归档一个流程实例
相应的操作顺序如下:
1、根据processInstID将相应的1条记录从WFProcessInst表中插入 WF_H_ProcessInst表
2、根据processInstID将relateData字段从WFProcessInst表中更新到WF_H_ProcessInst表
3、根据processInstID将相应的1条记录从WFProcessInstAttr表中插入WF_H_ProcessInstAttr表
4、根据processInstID将procInstAttr字段从WFProcessInstAttr表中更新到WF_H_ProcessInstAttr表
5、根据processInstID将相应多条的记录从WFActivityInst表中插入WF_H_ActivityInst表
6、根据processInstID找到WFWorkItem中对应的workItemid列表
7、循环workItemid列表将相应多条的记录从WFWorkItem表中插入WF_H_WorkItem表
8、循环workItemid列表将相应多条的记录从WFWIParticipant表中插入WF_H_WIParticipant表
9、根据processInstID将相应的1条记录从WFTransition表中插入WF_H_Transition表
10、根据processInstID将相应的1条记录从WFTransCtrl表中插入WF_H_TransCtrl表
11、根据processInstID从WFWorkItem表中找到需要删除记录的workitemid
12、根据workitemid删除相应的WFWIParticipant记录
13、根据workitemid删除相应的WFWorkItem记录
14、根据processInstID删除相应的WFTransCtrl记录
15、根据processInstID删除相应的WFTransition记录
16、根据processInstID删除相应的WFActivityInst记录
17、根据processInstID删除相应的WFProcessInstAttr记录
18、根据processInstID删除相应的WFProcessInst记录
关于性能
由于操作的生产环境的数据库,如果数据库压力过大会影响业务的正常运转。建议操作时,查询出未被转历史的100条流程实例的processInstID,循环调用上面的操作,之后提交。如果数据库性能没有受到影响则可逐步加大每次操作的量。
关于容错性
流程结束后才会转历史,所以转历史出错后,不会影响运行库中流程的使用,需要讨论的是,业务表出错后,会不会对用户的使用有影响。
另外,如果转历史出错,可能回导致运行库和历史库里出现相同的记录。使用下面的sql语句可以查询出来。
select count(*)fromwfworkitem a,wf_h_workitem b where a.workitemid = b.workitemid;
。。。
关于验证
一个流程转历史之后,其下面相应的活动和工作项等记录都不在运行库了。所以用下面的sql语句如果返回是0,则可证明所有的流程都成功转历史。
1. select count(*)fromwfworkitemwhere processinstid =(select processinstid fromwfprocessinstwhere currentstate =7or currentstate=8)
2. select count(*)fromwfwiparticipant a,wfworkitem b,wfprocessinst c where a.workitemid = b.workitemid and b.processinstid = c.processinstid and(c.currentstate =7or c.currentstate=8)
3. select count(*)fromwfactivityinstwhere processinstid =(select processinstid fromwfprocessinstwhere currentstate =7or currentstate=8)
4. select count(*)fromwftransctrlwhere processinstid =(select processinstid fromwfprocessinstwhere currentstate =7or currentstate=8)
5. select count(*)fromWFTransitionwhere processinstid =(select processinstid fromwfprocessinstwhere currentstate =7or currentstate=8)
6. 关于实现
有2种实现方式:
1、 使用存储过程
2、 提供BL方法
在安徽移动的项目中,在512的基础上提供了一个转历史的BL方法。使用时候需要注意在调用的时候,要放在一个事务里面否则可能会出现运行库和历史库2边都有的问题。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14780828/viewspace-374520/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/14780828/viewspace-374520/