1
2
3
4
5 package gboat2.approveflow.action;
6
7 import gboat2.approveflow.business.ApproveFlowConstant;
8 import gboat2.approveflow.business.IApproveflowBusiness;
9 import gboat2.approveflow.model.TVerifyDetail;
10 import gboat2.approveflow.model.TVerifyLevel;
11 import gboat2.approveflow.model.TVerifyLevelVO;
12 import gboat2.approveflow.service.IApproveFlowRegister;
13 import gboat2.base.core.annotation.Domain;
14 import gboat2.base.core.annotation.ListDomain;
15 import gboat2.base.core.annotation.Module;
16 import gboat2.base.core.annotation.Operation;
17 import gboat2.base.core.annotation.Operations;
18 import gboat2.base.core.annotation.Preference;
19 import gboat2.base.core.dao.Page;
20 import gboat2.base.core.dao.QuerySupport;
21 import gboat2.base.core.web.BaseActionSupport;
22 import gboat2.base.core.web.JsonResultSupport;
23 import gboat2.base.bridge.exception.DefaultGboatNestedException;
24 import gboat2.serviceflow.model.NodeInfo;
25 import gboat2.serviceflow.model.ProcessInfo;
26 import gboat2.web.model.Role;
27
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Map;
34
35 import org.apache.commons.lang3.StringUtils;
36 import org.apache.struts2.convention.annotation.ResultPath;
37 import org.springframework.beans.factory.annotation.Autowired;
38
39
40
41
42
43
44
45 @Domain(value = TVerifyLevel.class)
46 @ListDomain(value = TVerifyLevelVO.class)
47 @ResultPath("/content/approveflow")
48 @Preference("/系统配置/审批流配置")
49 @Module(name = "审批流管理", desc = "管理所有审批流")
50 @Operations(value = { @Operation(name = "新增审批流", code = "add", desc = "新增审批配置"),
51 @Operation(name = "编辑", code = "edit", desc = "编辑审批配置"),
52 @Operation(name = "查看", code = "view", desc = "查看审批配置"),
53 @Operation(name = "删除", code = "delete", desc = "删除审批配置")})
54 public class ApproveflowAction extends BaseActionSupport {
55
56 private static final long serialVersionUID = 1L;
57
58 @Autowired
59 private IApproveflowBusiness approveflowBusiness;
60
61 @Autowired
62 private IApproveFlowRegister approveflowRegister;
63
64
65 private List<ProcessInfo> processInfoList;
66
67
68 private List<NodeInfo> nodeInfoList;
69
70
71 private List<Role> roleList;
72
73 private String processId;
74
75 private String levelId;
76
77 private String bpmnDataJson;
78
79 private Map<String,String> nodeNameAssignerMap = new HashMap<String,String>();
80
81 private Map<String,ProcessInfo> processCache = new HashMap<String,ProcessInfo>();
82
83 @Override
84 protected void initList(Map<String, Object> params) {
85 params.put(QuerySupport.PARAM_ORDERBY, "processId,stepName");
86 processInfoList = approveflowBusiness.getAllProcessInfo();
87 }
88
89
90
91
92
93
94
95
96
97 @SuppressWarnings({ "unchecked", "rawtypes" })
98 @Override
99 protected void postList(Page pageinfo) {
100
101 Iterator<TVerifyLevelVO> it = pageinfo.getResult().iterator();
102
103 Map<String,String> roleCodeNameMap = approveflowBusiness.getRoleCodeNameMap();
104 while (it.hasNext()) {
105 TVerifyLevelVO verifyLevel = it.next();
106
107 if(verifyLevel.getVerifyType().equals("R")){
108 verifyLevel.setApproveFlow(getFlowDesc(verifyLevel,roleCodeNameMap));
109 }
110
111
112 if(verifyLevel.getVerifyType().equals("R")){
113 verifyLevel.setVerifyType("角色");
114 }else if(verifyLevel.getVerifyType().equals("N")){
115 verifyLevel.setVerifyType("不审核");
116 }else if(verifyLevel.getVerifyType().equals("P")){
117 verifyLevel.setVerifyType("人员");
118 }else if(verifyLevel.getVerifyType().equals("B")){
119 verifyLevel.setVerifyType("BPMN");
120 }else{
121 verifyLevel.setVerifyType("未识别");
122 }
123
124
125 ProcessInfo processInfo = getProcessInfo(verifyLevel.getProcessId());
126 if (processInfo != null) {
127
128 verifyLevel.setProcessName(processInfo.getProcessName());
129 if(verifyLevel.getStepName().equals(ApproveFlowConstant.PROCESS_DEFAULT_VALUE)){
130 verifyLevel.setStepName(ApproveFlowConstant.PROCESS_DEFAULT_NAME);
131 }else{
132
133 NodeInfo nodeInfo = processInfo.getNodeCode_node_map().get(verifyLevel.getStepName());
134 if (nodeInfo != null) {
135
136 verifyLevel.setStepName(nodeInfo.getNodeName());
137 }
138 }
139 }
140 }
141
142 }
143
144 private ProcessInfo getProcessInfo(String processId){
145 ProcessInfo process = null;
146 if(processCache.containsKey(processId)){
147 process = processCache.get(processId);
148 }else{
149 process = approveflowBusiness.getProcessInfoById(processId);
150 if(process!=null){
151 processCache.put(processId, process);
152 }
153 }
154
155 return process;
156 }
157
158
159 private String getFlowDesc(TVerifyLevel verify,Map<String,String> roleCodeNameMap){
160 StringBuffer desc = new StringBuffer();
161
162 if(!StringUtils.isEmpty(verify.getLevel1())){
163 desc.append(roleCodeNameMap.get(verify.getLevel1()));
164 }else{
165 return desc.toString();
166 }
167
168 if(!StringUtils.isEmpty(verify.getLevel2())){
169 desc.append(" -> "+roleCodeNameMap.get(verify.getLevel2()));
170 }else{
171 return desc.toString();
172 }
173
174 if(!StringUtils.isEmpty(verify.getLevel3())){
175 desc.append(" -> "+roleCodeNameMap.get(verify.getLevel3()));
176 }else{
177 return desc.toString();
178 }
179
180 if(!StringUtils.isEmpty(verify.getLevel4())){
181 desc.append(" -> "+roleCodeNameMap.get(verify.getLevel4()));
182 }else{
183 return desc.toString();
184 }
185
186 if(!StringUtils.isEmpty(verify.getLevel5())){
187 desc.append(" -> "+roleCodeNameMap.get(verify.getLevel5()));
188 }else{
189 return desc.toString();
190 }
191
192 if(!StringUtils.isEmpty(verify.getLevel6())){
193 desc.append(" -> "+roleCodeNameMap.get(verify.getLevel6()));
194 }else{
195 return desc.toString();
196 }
197
198 return desc.toString();
199 }
200
201
202
203
204
205
206
207 protected void initSave() {
208 TVerifyLevel verifyLevel = (TVerifyLevel) getModel();
209 Map<String,String> stepCodeNameMap = new HashMap<String,String>();
210 boolean isVerifyLevelExsit = false;
211 if(verifyLevel == null || verifyLevel.getLevelId() == null || verifyLevel.getLevelId().equals("")){
212 if(verifyLevel.getStepName().equals(ApproveFlowConstant.PROCESS_DEFAULT_NAME)){
213 verifyLevel.setStepName(ApproveFlowConstant.PROCESS_DEFAULT_VALUE);
214 }else{
215
216 stepCodeNameMap = approveflowBusiness.getStepCodeNameMap(verifyLevel.getProcessId());
217
218 verifyLevel.setStepName(stepCodeNameMap.get(verifyLevel.getStepName()));
219 }
220
221 isVerifyLevelExsit = approveflowBusiness.isVerifyLevelExsit(verifyLevel.getProcessId(), verifyLevel.getStepName());
222 }
223
224 if(isVerifyLevelExsit == true){
225 throw new DefaultGboatNestedException("此审批流记录已存在");
226 }
227
228 if(!"B".equals(verifyLevel.getVerifyType())){
229 while(
230 (StringUtils.isNotEmpty(verifyLevel.getLevel1())&&(verifyLevel.getLevel1().equals(verifyLevel.getLevel2())))
231 || (StringUtils.isNotEmpty(verifyLevel.getLevel2())&&(verifyLevel.getLevel2().equals(verifyLevel.getLevel3())))
232 || (StringUtils.isNotEmpty(verifyLevel.getLevel3())&&(verifyLevel.getLevel3().equals(verifyLevel.getLevel4())))
233 || (StringUtils.isNotEmpty(verifyLevel.getLevel4())&&(verifyLevel.getLevel4().equals(verifyLevel.getLevel5())))
234 || (StringUtils.isNotEmpty(verifyLevel.getLevel5())&&(verifyLevel.getLevel5().equals(verifyLevel.getLevel6())))
235 ){
236 if(!StringUtils.isEmpty(verifyLevel.getLevel2())&&verifyLevel.getLevel2().equals(verifyLevel.getLevel1())){
237 verifyLevel.setLevel2(verifyLevel.getLevel3());
238 verifyLevel.setLevel3(verifyLevel.getLevel4());
239 verifyLevel.setLevel4(verifyLevel.getLevel5());
240 verifyLevel.setLevel5(verifyLevel.getLevel6());
241 verifyLevel.setLevel6("");
242 }
243 if(!StringUtils.isEmpty(verifyLevel.getLevel3())&&verifyLevel.getLevel3().equals(verifyLevel.getLevel2())){
244 verifyLevel.setLevel3(verifyLevel.getLevel4());
245 verifyLevel.setLevel4(verifyLevel.getLevel5());
246 verifyLevel.setLevel5(verifyLevel.getLevel6());
247 verifyLevel.setLevel6("");
248 }
249 if(!StringUtils.isEmpty(verifyLevel.getLevel4())&&verifyLevel.getLevel4().equals(verifyLevel.getLevel3())){
250 verifyLevel.setLevel4(verifyLevel.getLevel5());
251 verifyLevel.setLevel5(verifyLevel.getLevel6());
252 verifyLevel.setLevel6("");
253 }
254 if(!StringUtils.isEmpty(verifyLevel.getLevel5())&&verifyLevel.getLevel5().equals(verifyLevel.getLevel4())){
255 verifyLevel.setLevel5(verifyLevel.getLevel6());
256 verifyLevel.setLevel6("");
257 }
258 }
259 }
260 }
261
262 @Override
263 protected void postSave() {
264 TVerifyLevel verifyLevel = (TVerifyLevel) getModel();
265 if("B".equals(verifyLevel.getVerifyType())){
266 approveflowBusiness.saveTVerifyDetail(this.bpmnDataJson, verifyLevel.getLevelId());
267 }
268 }
269
270
271
272
273
274
275 protected void initEdit() {
276 setDefaultInfo();
277
278 }
279 protected void initView() {
280 setDefaultInfo();
281 }
282
283 public void deleteApproveFlow(){
284 approveflowBusiness.deleteApproveFlow(this.levelId);
285 JsonResultSupport.outputSuccess();
286 }
287
288 private void setDefaultInfo(){
289 TVerifyLevel verifyLevel = (TVerifyLevel)getModel();
290
291 roleList = approveflowBusiness.getAllRoles();
292
293 if(verifyLevel != null && verifyLevel.getProcessId() != "" && verifyLevel.getProcessId() != null){
294 levelId = verifyLevel.getLevelId();
295 ProcessInfo processInfo = approveflowBusiness.getProcessInfoById(verifyLevel.getProcessId());
296
297 if(processInfo != null){
298 processInfoList = new ArrayList<ProcessInfo>();
299 processInfoList.add(processInfo);
300 nodeInfoList = processInfo.getNodeInfoList();
301 NodeInfo defaultSetting = new NodeInfo();
302 defaultSetting.setNodeName(ApproveFlowConstant.PROCESS_DEFAULT_NAME);
303 defaultSetting.setNodeCode(ApproveFlowConstant.PROCESS_DEFAULT_VALUE);
304 nodeInfoList.add(defaultSetting);
305 }
306
307 List<TVerifyDetail> detailList = approveflowBusiness.getDetailListByLevelId(levelId);
308 for(TVerifyDetail detail : detailList){
309 if(StringUtils.isNotEmpty(detail.getNodeName())){
310 nodeNameAssignerMap.put(detail.getNodeName(), detail.getAssigner());
311 }
312 }
313 }else{
314
315 processInfoList = approveflowBusiness.getAllProcessInfo();
316 }
317 }
318
319
320
321
322
323 public void getStepNames() {
324 try {
325 if (processId != "" && processId != null) {
326
327 String StepCodeNameStr = approveflowBusiness.getStepCodeNameStr(processId);
328
329 response.setCharacterEncoding("utf-8");
330 response.getWriter().write(StepCodeNameStr);
331 }
332 } catch (IOException e) {
333 e.printStackTrace();
334 }
335
336 }
337
338 public void getBpmnProcessInfo(){
339 JsonResultSupport.output(approveflowBusiness.getBpmnProcessInfo());
340 }
341
342 public void getNodeListByProcessId(){
343 JsonResultSupport.output(approveflowBusiness.getNodeListByProcessId(this.processId));
344 }
345
346 public void getProcessImgByProcessId(){
347 String url = approveflowRegister.getPathForDisplay(this.processId);
348 if(StringUtils.isEmpty(url)){
349 JsonResultSupport.outputFailure();
350 }
351 JsonResultSupport.output(request.getContextPath()+url);
352 }
353
354 public List<Role> getRoleList() {
355 return roleList;
356 }
357
358 public void setRoleList(List<Role> roleList) {
359 this.roleList = roleList;
360 }
361
362 public List<ProcessInfo> getProcessInfoList() {
363 return processInfoList;
364 }
365
366 public void setProcessInfoList(List<ProcessInfo> processInfoList) {
367 this.processInfoList = processInfoList;
368 }
369
370 public String getProcessId() {
371 return processId;
372 }
373
374 public void setProcessId(String processId) {
375 this.processId = processId;
376 }
377
378 public List<NodeInfo> getNodeInfoList() {
379 return nodeInfoList;
380 }
381
382 public void setNodeInfoList(List<NodeInfo> nodeInfoList) {
383 this.nodeInfoList = nodeInfoList;
384 }
385
386 public String getLevelId() {
387 return levelId;
388 }
389
390 public void setLevelId(String levelId) {
391 this.levelId = levelId;
392 }
393
394 public String getBpmnDataJson() {
395 return bpmnDataJson;
396 }
397
398 public void setBpmnDataJson(String bpmnDataJson) {
399 this.bpmnDataJson = bpmnDataJson;
400 }
401
402 public Map<String, String> getNodeNameAssignerMap() {
403 return nodeNameAssignerMap;
404 }
405
406 public void setNodeNameAssignerMap(Map<String, String> nodeNameAssignerMap) {
407 this.nodeNameAssignerMap = nodeNameAssignerMap;
408 }
409
410
411 }