jbpm的智能選擇審批人及人工任務分配的實現思路

一、jbpm中審批人的概念


在工作流中每一個人工任務的辦理者被稱作審批人,在原生的jbpm定義中,我們可以看到assignee和assignmentHandler這兩個標籤。

1
2
3
4
5
6
7
8
< task  name = "review"  g = "96,16,127,52" >  
     < assignment-handler  class = "org.jbpm.examples.task.assignmenthandler.AssignTask" >  
       < field  name = "assignee" >  
         < string  value = "chao.gao"  />  
       </ field >  
     </ assignment-handler >  
     < transition  to = "wait"  />  
   </ task >

assignee如果是單用戶,可以是字符串;如果是多用戶,則是列表或數組;另外也可以使用類似jsp中的正則表達式,進行動態審批人的指定

如果有assignee,而沒有分配處理器標籤,則引擎自動將該人工任務分配給所有assignee。如有assignmentHandler會按照默認或定製的分配處理器制定的規則進行審批人的智能篩選以及對任務進行動態的指派。

在會籤人方案一文中,提到了關於使用assignmentHandler生成會籤子任務的實例,在決策裏也提到了DefaultDecisionHandler,jbpm使用監聽器模式對不同的處理類進行調用。

1
2
3
4
5
6
7
8
9
10
11
12
13
/**  
      * @author Tom Baeyens  
      */  
     public  class  AssignTask  implements  AssignmentHandler {   
          
       private  static  final  long  serialVersionUID = 1L;   
       
       String assignee;   
       
       public  void  assign(Assignable assignable, OpenExecution execution) {   
         assignable.setAssignee(assignee);   
       }   
     }

以上是jbpm審批人的原生概念以及如何將指定或動態指定的用戶與人工任務相綁定的理論知識。

下面闡述我們的審批人選擇以及分配任務的思路

二、智能選擇審批人

  審批人設置表結構

wKioL1TcQijD8TvnAAIRX6WIKV4987.jpg


    數據列表如下

wKiom1TcQj2y4m74AAUDqSVCszA605.jpg

  頁面設置:

wKiom1TcXYPicv0YAAF46tJqBao488.jpg

一般情況下,商用工作流都提供基於組織架構、彙報關係、角色的審批人選擇方法,OA中也提供了相應功能。基於組織架構上下級關係,主要有當前部門、當前部門之上級部門、當前部門上級部門之上級部門,基於組織架構的層級關係,主要有一級部門、二級部門、三級部門、子公司等。以上兩種規則,除當前部門外還可以通過表單數據指定部門的編碼。基於組織架構的成員,可以將本架構內所有成員全部納入審批人列表。

代碼如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
private  Set<String> getAssigneeByAssignSetting(FlowRunTime flowRunTimeInfo,
             UserAssignEntity assignSetting) {
         Set<String> candidateUserIdList =  new  HashSet<String>();
 
         if ( "Y" .equals(assignSetting.getIsForm())){
             String fieldValue = getFiledValueByAssignSetting(assignSetting, flowRunTimeInfo);
             if (StringUtils.isNotEmpty(fieldValue) && assignSetting.getFieldName().contains( "," )){
                 String[] staffIds = fieldValue.split( "[,]" );
                 for (String staffId : staffIds){
                     if (StringUtils.isNotEmpty(staffId)){
                         StaffinfoEntity staffinfoEntity = staffInfoService.queryStaffInfoByStaffId(staffId);
                         if (staffinfoEntity !=  null  && StringUtils.isNotEmpty(staffinfoEntity.getStaffCode())){
                             candidateUserIdList.add(staffinfoEntity.getStaffCode());
                         } else  {
                             throw  new  UserAssignException( "通過表單選人出現錯誤,請檢查!" );
                         }
                     }
                 }
             } else   {
                 StaffinfoEntity staffinfoEntity = staffInfoService.queryStaffInfoByStaffId(fieldValue);
                 if (StringUtils.isEmpty(fieldValue)){
                     throw  new  UserAssignException( "通過表單選人出現錯誤,請檢查!" );
                 }
                  OrgEntity org = orgService.queryOrgByCode(fieldValue);
                  if (! "ShanghaiHQ" .equals(fieldValue)){
                      List<HrbpEntity> hrbpEntityList = hrbpService.queryHrbpByDqCode(fieldValue);
                      if (!CollectionUtils.isEmpty(hrbpEntityList)){
                          for (HrbpEntity hrbp : hrbpEntityList){
                              String staffCode = staffInfoService.queryStaffByStaffId(hrbp.getHrbpId()).getStaffCode();
                              if (StringUtils.isNotEmpty(staffCode) && !candidateUserIdList.contains(staffCode)){
                                  candidateUserIdList.add(staffCode);
                              }                       
                          }
                      }
                  }
                 if (staffinfoEntity !=  null ){
                     if  (UserAssignConstants.USERASSIGN_LEADER_OF_LASTSTEP.equals(assignSetting.getChooseRule()) || 
                         UserAssignConstants.USERASSIGN_LEADER_OF_STARTASSIGNEE.equals(assignSetting.getChooseRule())) {
                         String directleaderCode = staffInfoService.queryLeader(fieldValue).getDirectLeaderCode();
                         if (StringUtils.isNotEmpty(directleaderCode)){
                         StaffinfoEntity directLeader = staffInfoService.queryStaffInfoByStaffId(directleaderCode);
                             if  (directLeader !=  null ) {
                                 candidateUserIdList.add(directLeader.getStaffCode());  
                             }
                        
                     } else  if (UserAssignConstants.USERASSIGN_LEADER_OF_LEADER.equals(assignSetting.getChooseRule())){
                         String indirectleaderCode = staffInfoService.queryLeader(fieldValue).getLeapfrogLeaderCode();  
                         StaffinfoEntity indirectLeader = staffInfoService.queryStaffInfoByStaffId(indirectleaderCode);
                         if (indirectLeader !=  null ){
                             candidateUserIdList.add(indirectLeader.getStaffCode());
                         }
                     else  if (UserAssignConstants.USERASSIGN_LEADER_OF_LEADER_OF_LEADER.equals(assignSetting.getChooseRule())){
                         String indirectleaderCode = staffInfoService.queryLeader(fieldValue).getLeapfrogLeaderCode();   //越級主管
                         if (StringUtils.isNotEmpty(indirectleaderCode)){
                             StaffinfoEntity indirectLeader = staffInfoService.queryStaffInfoByStaffId(indirectleaderCode);
                             if (indirectLeader !=  null ){
                                 String inIndirectLeaderStaffId = staffInfoService.queryLeader(indirectLeader.getStaffId()).getDirectLeaderCode();
                                 if (StringUtils.isNotEmpty(inIndirectLeaderStaffId)){
                                     StaffinfoEntity inIndirectLeader = staffInfoService.queryStaffInfoByStaffId(inIndirectLeaderStaffId);
                                     if (inIndirectLeader !=  null ){
                                         candidateUserIdList.add(inIndirectLeader.getStaffCode());
                                     }
                                 }
                             }
                         }
                     }
                     if (UserAssignConstants.USERASSIGN_STARTER.equals(assignSetting.getChooseRule())){
                             candidateUserIdList.add(staffinfoEntity.getStaffCode());
                     }
       
                 }
                if (org !=  null ){
                     if (UserAssignConstants.USERASSIGN_LEADER_OF_ORG.equals(assignSetting.getChooseRule())){ //當前部門的領導:
                         if  (org !=  null  && !StringUtils.isBlank(org.getManagerCode())) {
                             String managerCode = org.getManagerCode();
                             candidateUserIdList.add(managerCode);
                         }
                     else  if (UserAssignConstants.USERASSIGN_LEADER_OF_LEADER_OF_ORG.equals(assignSetting.getChooseRule())){ //申請部門的上級領導:
                         if  (org !=  null  && !StringUtils.isBlank(org.getParentCode())) {
                             OrgEntity orgParent  = orgService.queryOrgByCode(org.getParentCode());
                             if  (orgParent!= null  && !StringUtils.isBlank(orgParent.getManagerCode())) {
                                 String managerCode = orgParent.getManagerCode();
                                 candidateUserIdList.add(managerCode);
                             }
                         }
                     else  if (UserAssignConstants.USERASSIGN_LEADER_OF_LEADER_OF_LEADER_OF_ORG.equals(assignSetting.getChooseRule())){ //申請部門的上級之上級領導:
                          if  (org !=  null  && !StringUtils.isBlank(org.getParentCode())) {
                              OrgEntity orgtwo  = orgService.queryOrgByCode(org.getParentCode());
                              if  (orgtwo!= null  && !StringUtils.isBlank(orgtwo.getManagerCode())) {
                                  OrgEntity orgParent = orgService.queryOrgByCode(orgtwo.getParentCode());
                                  if  (orgParent!= null  && !StringUtils.isBlank(orgParent.getManagerCode())) {
                                      String managerCode = orgParent.getManagerCode();
                                      candidateUserIdList.add(managerCode);
                                 }
                              }
                          }
                     else  if (UserAssignConstants.USERASSIGN_LEADER_OF_PLATFORM_OR_COMPANY.equals(assignSetting.getChooseRule())){ //申請部門的子公司領導:子公司領導
                         OrgEntity orgPlatform = orgService.queryPlatformEntityByDepCode(fieldValue);
candidateUserIdList.add(managerCode);
                                 }
                              }
                          }
                     else  if (UserAssignConstants.USERASSIGN_LEADER_OF_PLATFORM_OR_COMPANY.equals(assignSetting.getChooseRule())){ //申請部門的子公司領導:子公司領導
                         OrgEntity orgPlatform = orgService.queryPlatformEntityByDepCode(fieldValue);
                         if  (orgPlatform !=  null  && !StringUtils.isBlank(orgPlatform.getManagerCode())) {
                             String managerCode = orgPlatform.getManagerCode();
                             candidateUserIdList.add(managerCode);
                         }
相關文章
相關標籤/搜索