dangsn
2024-12-03 d0ae279ff3b83358d1c07f4481a041c4ad335026
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
package com.vci.web.dao.impl;
 
import com.vci.common.utility.ObjectUtility;
import com.vci.constant.WFVariablesKeyConstant;
import com.vci.corba.common.PLException;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.workflow.WorkflowServicePrx;
import com.vci.corba.workflow.data.*;
import com.vci.dto.ProcessTemplateVO;
import com.vci.model.ProcessInstance;
import com.vci.model.ProcessTask;
import com.vci.model.WFProcessClassifyDO;
import com.vci.model.WFProcessTemplateDO;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.*;
import com.vci.starter.web.constant.QueryOptionConstant;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.PageHelper;
import com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.starter.web.util.BeanUtilForVCI;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.dao.WebProcessDaoI;
import com.vci.web.service.SmUserQueryServiceI;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.service.WebLifeCycleServiceI;
import com.vci.web.service.WebLoServiceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
 
 
/**
 * 流程的数据层
 * @author weidy
 */
@Repository
public class WebProcessDaoImpl implements WebProcessDaoI {
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 多语言的前缀
     */
    private final String msgCodePrefix = "com.vci.web.flow.";
 
    @Resource
    private WebBoServiceI boService;
    
    @Resource
    private WebLoServiceI loService;
 
    @Resource
    private WebLifeCycleServiceI lifeCycleService;
 
    /**
     * 用户查询服务
     */
    @Autowired
    private SmUserQueryServiceI userQueryService;
 
    /**
     * 平台的流程服务
     */
    private WorkflowServicePrx workService = null;
 
    /**
     * 平台调用客户端
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
    /***
     * 流程分类主键和类型的映射
     */
    private Map<String/*类型*/,String/*主键*/> categoryMap = new HashMap<String, String>();
    
    private final String workitemBtmType = "workitem";
    
    private final String workIntanceBtmType = "workflowinstance";
    
    private final String processDataLink ="input";
    
    private final String taskDataLink = "input";
 
    
    /**
     * 获取流程分类的映射
     * @throws VciBaseException
     */
    private void getCategory() throws VciBaseException {
        try {
            ProcessCategoryInfo[] pcia = getWorkService().getProcessCategories("root");
            if(pcia!=null&&pcia.length>0){
                for(ProcessCategoryInfo pci : pcia){
                    categoryMap.put(pci.name.toLowerCase(), pci.id);
                }
            }
        } catch (PLException e) {
            WebUtil.getVciBaseException(e);
        }
    }
    
    /**
     * 获取某个分类下的所有流程模版
     * @param type 分类信息
     * @param filterTemplate 指定模板
     * @param showAll 是否显示所有版本的
     * @return 
     * @throws 
     */
    @Override
    public List<ProcessTemplateVO> getTemplatesByType(String type, String filterTemplate, boolean showAll)
            throws VciBaseException {
        WebUtil.alertNotNull(type,"模板分类");
        ProcessDefinitionInfo[] allFlowInType = null;
        if(StringUtils.isBlank(filterTemplate)) {
            //无指定模板情况下,获取模板分类下的所有模板
            type = type.toLowerCase();
            if (categoryMap.isEmpty() || !categoryMap.containsKey(type)) {
                getCategory();
            }
            String typeOid = "" ;
            if (categoryMap.containsKey(type)) {
                typeOid = categoryMap.get(type);
            } else {
                throw new VciBaseException(msgCodePrefix + "typeNotExist", new String[]{type});
            }
            try {
                allFlowInType = getWorkService().getProcessDefinitions(typeOid);
            } catch (PLException e) {
                throw WebUtil.getVciBaseException(e);
            }
        }else{
            List<ProcessDefinitionInfo> infoList = new ArrayList<>();
            List<String> templateList = VciBaseUtil.str2List(filterTemplate);
            if(!CollectionUtils.isEmpty(templateList)){
                templateList.forEach(name->{
                    try {
                        String nameUnRev = name;
                        String revision = "";
                        if(name.contains("-")){
                            nameUnRev = name.substring(0,name.lastIndexOf("-"));
                            revision = name.substring(name.lastIndexOf("-")+1);
                        }
                        ProcessDefinitionInfo[] definition = getWorkService().getProcessDefinitionByProcessDefinitionName(nameUnRev, "");
                        if(definition!=null){
                            if(StringUtils.isBlank(revision)) {
                                Collections.addAll(infoList, definition);
                            }else{
                                //过滤版本
                                String finalRevision = revision;
                                infoList.addAll(Arrays.stream(definition).filter(s -> finalRevision.equalsIgnoreCase(String.valueOf(s.version))).collect(Collectors.toList()));
                            }
                        }
                    } catch (PLException e) {
                        throw WebUtil.getVciBaseException(e);
                    }
                });
            }
            allFlowInType = infoList.toArray(new ProcessDefinitionInfo[0]);
        }
        return swapProcessTemplate(allFlowInType, type, showAll);
    }
 
    /**
     * 根据部署主键,获取流程模板对象
     * @param deployId 部署主键
     * @return
     * @throws VciBaseException
     */
    @Override
    public ProcessTemplateVO getTemplateByDeployId(String deployId) throws VciBaseException {
        WebUtil.alertNotNull(deployId,"流程部署主键");
        ProcessDefinitionInfo pdi = null;
        try {
            pdi = getWorkService().getProcessDefinitionByDeployId(deployId.trim());
        } catch (PLException e) {
            throw new VciBaseException(msgCodePrefix + "deployIdNotExist", new String[]{deployId});
        }
        List<ProcessTemplateVO> proTemplates = swapProcessTemplate(new ProcessDefinitionInfo[]{pdi},"",false);
        if(proTemplates == null || proTemplates.size() == 0){
            throw new VciBaseException(msgCodePrefix + "deployIdNotExist", new String[]{deployId});
        }
        return proTemplates.get(0);
    }
    
    private List<ProcessTemplateVO> swapProcessTemplate(ProcessDefinitionInfo[] allFlowInType, String type, boolean showAll){
        List<ProcessTemplateVO> allTemplate = new ArrayList<ProcessTemplateVO>();
        if(allFlowInType!=null&&allFlowInType.length>0){
            for(ProcessDefinitionInfo pd : allFlowInType){
                //status = 0 表示停用, status = 1表示启用
                if("1".equalsIgnoreCase(pd.status) || showAll){
                    ProcessTemplateVO pt = new ProcessTemplateVO();
                    pt.setOid(pd.id);
                    pt.setCategroyOid(pd.categroyId);
                    pt.setDeploymentId(pd.jbpmDeploymentId);
                    pt.setKey(pd.key);
                    pt.setName(pd.name);
                    pt.setStatus(pd.status);
                    pt.setTaskType(type);
                    pt.setVersion((int) pd.version);
                    allTemplate.add(pt);
                }
            }
        }
        return allTemplate;
    }
 
    /**
     * 获取流程的所有节点
     * @param processOid
     */
    @Override
    public List<ProcessNodeVO> getAllProcessNode(String processOid)
            throws VciBaseException{
        WebUtil.alertNotNull(processOid,"流程主键");
        String deploymentId = getJbpmDeploymentId(processOid);
        if(StringUtils.isBlank(deploymentId)){
            throw new VciBaseException(msgCodePrefix + "processTemplateNotExist",new String[]{processOid});
        }
        String[] allTaskNames = getAllProcessNodeNameByDeploy(deploymentId);
        List<ProcessNodeVO> allNode = new ArrayList<ProcessNodeVO>();
        for(String taskName :  allTaskNames){
            ProcessNodeVO pn = getNodePresideUsersByDeploy(deploymentId, taskName);
            allNode.add(pn);
        }
        return allNode;
    }
 
    /**
     * 获取流程中的第一个节点的名称
     * @param deployId 部署主键
     * @return
     * @throws VciBaseException
     */
    @Override
    public String getFirstNodeName(String deployId) throws VciBaseException {
        WebUtil.alertNotNull(deployId,"部署主键");
        try {
            ProcessTaskInfo firstProcessTask = getWorkService().getFirstProcessTask(deployId);
            if(firstProcessTask!=null){
                return firstProcessTask.taskName;
            }
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        return null;
    }
 
    /**
     * 获取流程的所有节点名称
     * @param processOid
     */
    @Override
    public String[] getAllProcessNodeName(String processOid) throws VciBaseException{
        if(StringUtils.isEmpty(processOid)){
            WebUtil.alertNotNull(processOid);
        }
        String deploymentId = getJbpmDeploymentId(processOid);
        if(StringUtils.isEmpty(deploymentId)){
            throw new VciBaseException(msgCodePrefix + "processTemplateNotExist",new String[]{processOid});
        }
        return getAllProcessNodeNameByDeploy(deploymentId);
    }
    
    /**
     * 获取流程中的所有节点名称
     * @param deploymentId 流程引擎中的部署id
     * @return
     * @throws VciBaseException
     */
    @Override
    public String[] getAllProcessNodeNameByDeploy(String deploymentId) throws VciBaseException{
        String[] allTaskNames = null;
        try {
            allTaskNames = getWorkService().getAllTaskNames(deploymentId);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        return allTaskNames;
    }
 
    /**
     * 获取流程模板在流程引擎中的部署主键
     * @param processOid
     */
    @Override
    public String getJbpmDeploymentId(String processOid) throws VciBaseException{
        WebUtil.alertNotNull(processOid,"流程模板主键");
        return getWorkService().getDeploymentID(processOid);
    }
 
    /**
     * 获取流程模板对应的引擎里的部署主键
     * @param executionId
     * @return
     * @throws VciBaseException
     */
    @Override
    public String getJbpmDeploymentIdByExecutionId(String executionId) throws VciBaseException{
        WebUtil.alertNotNull(executionId,"流程执行主键");
        try {
            return getWorkService().getDeploymentIdByExecutionId(executionId);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 获取模板中节点设置的负责人
     * @param deploymentId 引擎中的部署主键
     * @param taskName 任务节点名称
     * @return
     * @throws VciBaseException
     */
    @Override
    public ProcessNodeVO getNodePresideUsersByDeploy(String deploymentId, String taskName) throws VciBaseException{
        WebUtil.alertNotNull(taskName,"流程任务名称",deploymentId,"流程引擎中的部署主键");
        ProcessNodeVO pn = new ProcessNodeVO();
        pn.setName(taskName);
        try {
            String[] nodePresideUsers = getWorkService().getCurCandidates(deploymentId, taskName, "", "");
            if(nodePresideUsers!=null&& nodePresideUsers.length>0){
                for(String preUsers : nodePresideUsers){
                    //平台存储的方式是用户;角色;部门;自定义....
                    if(StringUtils.isNotEmpty(preUsers)){
                        String[] preUsersSplit = preUsers.split("\\;");
                        if(preUsersSplit!=null && preUsersSplit.length>0){
                            if(StringUtils.isNotEmpty(preUsersSplit[0])){
                                pn.setUsers(preUsersSplit[0]);
                            }
                            if(preUsersSplit.length>1 && StringUtils.isNotEmpty(preUsersSplit[1])){
                                pn.setRoles(preUsersSplit[1]);
                            }
                            if(preUsersSplit.length>2 && StringUtils.isNotEmpty(preUsersSplit[2])){
                                pn.setDepts(preUsersSplit[2]);
                            }
                            if(preUsersSplit.length>3 && StringUtils.isNotEmpty(preUsersSplit[3])){
                                pn.setCustomClass(preUsersSplit[3]);
                            }
                        }
                    }
                }
            }
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        return pn;
    }
    
    
    /**
     * 获取流程模板中某个节点的处理人
     * @param processOid
     * @param taskName
     * @return
     * @throws VciBaseException
     */
    @Override
    public ProcessNodeVO getNodePresideUsers(String processOid, String taskName) throws VciBaseException{
        WebUtil.alertNotNull(taskName,"流程任务节点名称",processOid,"流程主键");
        String deploymentId = getJbpmDeploymentId(processOid);
        if(StringUtils.isEmpty(deploymentId)){
            throw new VciBaseException(msgCodePrefix + "processTemplateNotExist",new String[]{processOid});
        }
        return getNodePresideUsersByDeploy(deploymentId,taskName);
    }
 
    /**
     * 获取任务的处理人
     * @param executionid 执行主键
     * @param taskName 任务名称
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<ProcessUserVO> getNodePresideUsersByTask(String executionid, String taskName)
            throws VciBaseException{
        WebUtil.alertNotNull(executionid,"流程执行任务",taskName,"任务名称");
        if("结束".equalsIgnoreCase(taskName)){
            return null;
        }
        //不能使用workitem去查询,因为可能任务还没到
        String users = getWorkService().getNextTaskAssigner(executionid, taskName);
        List<ProcessUserVO> allProUser = new ArrayList<ProcessUserVO>();
        if(StringUtils.isNotEmpty(users)){
            String userIds = users.replace("user:", "");//现在只支持设置用户
            List<SmUserVO> allUser = userQueryService.listUserByUserIds(WebUtil.str2List(userIds));
            if(allUser!=null && allUser.size()>0){
                for(SmUserVO user : allUser){
                    ProcessUserVO pu = new ProcessUserVO();
                    BeanUtils.copyProperties(user, pu);
                    pu.setType("user");
                    allProUser.add(pu);
                }
            }
        }
        return allProUser;
    }
 
    /**
     * 查询待办任务
     */
    @Override
    public DataGrid getUndoTask(
            Map<String, String> conditionMap, PageHelper ph, String userId)
            throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,1);
    }
 
    /**
     * 使用流程实例获取所有的待办信息
     * @param processInstanceId 流程的实例主键
     * @return 待办的任务
     */
    @Override
    public DataGrid getUndoTaskByInstanceId(String processInstanceId, long mill){
        Map<String,String> conditionMap = new HashMap<>();
        conditionMap.put("executionid",processInstanceId+"*");
        if(mill>0) {
            conditionMap.put("ts", QueryOptionConstant.MORETHAN + VciDateUtil.date2Str(new Date(mill), VciDateUtil.DateTimeMillFormat));
        }
        return getProcessTask(conditionMap,new PageHelper(-1),null,8);
    }
 
    /**
     * 查询流程任务
     * @param conditionMap 查询条件
     * @param ph 分页信息,没有排序
     * @param userId 用户名
     * @param doTaskType 用户类型,1-待办任务,2-已办任务
     * @return
     * @throws VciBaseException
     */
    private DataGrid getProcessTask(Map<String, String> conditionMap, PageHelper ph, String userId,int doTaskType) throws  VciBaseException,VciBaseException{
        if(conditionMap == null) {
            conditionMap = new HashMap<String, String>();
        }
        String btmType = "";
        if(doTaskType== 1){//待办任务
            WebUtil.alertNotNull(userId,"用户名");
            conditionMap.put("businesstype", "5");//本项目没有实际的意义
            conditionMap.put("principal", userId);
            conditionMap.put("lcstatus", "Executing");
            btmType = workitemBtmType;
            //ph.addSort("createtime",ph.desc);
        }else if(doTaskType == 2){//已办任务
            WebUtil.alertNotNull(userId,"用户名");
            conditionMap.put("taskoid", QueryOptionConstant.IN +" ( select ht.DBID_ FROM JBPM4_HIST_TASK ht left join PLFLOWAPPROVEOPINION op on ht.DBID_ = op.PLTASKID where DECODE(op.plassgin, null, ht.ASSIGNEE_, op.plassgin) = '" + userId + "') ");
            conditionMap.put("lcstatus","Completed");
            btmType = workitemBtmType;
        }else if(doTaskType == 3){//完成的流程
            if(StringUtils.isNotEmpty(userId)) {//为空表示查询所有的
                conditionMap.put("creator", userId);
            }
            conditionMap.put("lcstatus", "Completed");
            btmType = workIntanceBtmType;
        }else if(doTaskType == 4){//被终止的流程
            if(StringUtils.isNotEmpty(userId)) {
                conditionMap.put("creator", userId);
            }
            conditionMap.put("lcstatus", "Obsoleted");
            btmType = workIntanceBtmType;
        }else if(doTaskType ==5){//被挂起的流程
            if(StringUtils.isNotEmpty(userId)) {
                conditionMap.put("creator", userId);
            }
            conditionMap.put("lcstatus", "Suspended");
            btmType = workIntanceBtmType;
        }else if(doTaskType == 6){//执行中的流程
            if(StringUtils.isNotEmpty(userId)) {
                conditionMap.put("creator", userId);
            }
            conditionMap.put("lcstatus", "Executing");
            btmType = workIntanceBtmType;
        }else if(doTaskType ==7){
            WebUtil.alertNotNull(userId,"用户名");
            conditionMap.put("creator", userId);
        }else if(doTaskType ==8){
            //流程获取所有待处理的任务
            conditionMap.put("lcstatus", "Executing");
            btmType = workitemBtmType;
        }else{
            throw new VciBaseException(msgCodePrefix+"doTaskTypeError",new String[]{doTaskType+""});
        }
        List<String> causeList = new ArrayList<String>();
        causeList.add("*");
        causeList.add("creator_name");
        if(doTaskType!= 1){
            ph.addSort("ts",ph.desc);
        }
        ph.addSort("createtime",ph.desc);
        return boService.queryGridByBo(btmType, conditionMap, ph,causeList);
        
    }
 
    @Override
    public DataGrid getDoneProcess(Map<String, String> conditionMap, PageHelper ph, String userId) throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,2);
    }
 
    @Override
    public DataGrid getCompletedProcess(Map<String, String> conditionMap, PageHelper ph, String userId) throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,3);
    }
 
    @Override
    public DataGrid getObsoledtedProcess(Map<String, String> conditionMap,
            PageHelper ph, String userId) throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,4);
    }
 
    @Override
    public DataGrid getSuspendedProcess(Map<String, String> conditionMap,
            PageHelper ph, String userId) throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,5);
    }
 
    @Override
    public DataGrid getExecutingProcess(Map<String, String> conditionMap,
            PageHelper ph, String userId) throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,6);
    }
 
    @Override
    public DataGrid getCreateProcess(Map<String, String> conditionMap,
            PageHelper ph, String userId) throws VciBaseException {
        return getProcessTask(conditionMap,ph,userId,7);
    }
    
    @Override
    public List<ProcessTaskVO>  getTaskByOid(String oid) throws VciBaseException{
        WebUtil.alertNotNull(oid,"待办任务主键");
        List<ProcessTask> tasks = boService.selectByOidCollection(VciBaseUtil.str2List(oid),ProcessTask.class);
        return processTaskDO2VOs(tasks);
    }
 
    /**
     * 还有任务的主键获取任务CBO对象
     * @param oid 主键
     * @return CBO对象
     * @throws VciBaseException 查询出错会抛出异常
     */
    @Override
    public List<Map> getTaskCBOByOid(String oid) throws VciBaseException{
        WebUtil.alertNotNull(oid,"待办任务主键");
        return (boService.cbos2Map(boService.selectCBOByOidCollection(VciBaseUtil.str2List(oid),getWorkitemBtmType())));
    }
 
    /**
     * 任务的对象转换为显示对象
     * @param tasks 任务的对象
     * @return 任务的显示对象
     */
    private List<ProcessTaskVO> processTaskDO2VOs(Collection<ProcessTask> tasks){
        List<ProcessTaskVO> taskVOList = new ArrayList<>();
        Optional.ofNullable(tasks).orElseGet(()->new ArrayList<>()).stream().forEach(task->{
            ProcessTaskVO taskVO = new ProcessTaskVO();
            BeanUtilForVCI.convert(task,taskVO);
            taskVOList.add(taskVO);
        });
        return taskVOList;
    }
    
    @Override
    public ProcessInstanceVO getProcessByOid(String oid) throws VciBaseException{
        WebUtil.alertNotNull(oid,"流程实例主键");
        ProcessInstance process = boService.selectByOid(oid,ProcessInstance.class);
        ProcessInstanceVO processInstanceVO = new ProcessInstanceVO();
        if(process == null || StringUtils.isBlank(process.getOid())){
            throw new VciBaseException(DATA_OID_NOT_EXIST);
        }
        BeanUtilForVCI.convert(process,processInstanceVO);
        return processInstanceVO;
    }
 
    /**
     * 获取流程中的变量,平台只支持字符串.....
     * @param executionId
     * @param key
     * @return
     * @throws VciBaseException
     */
    @Override
    public String getVariablesInProcess(String executionId,String key) throws VciBaseException{
        WebUtil.alertNotNull(executionId,"流程执行主键",key,"参数Key");
        UserEntityInfo ueo = new UserEntityInfo();
        SessionInfo si = WebUtil.getCurrentUserSessionInfo();
        ueo.modules = "流程";
        ueo.userName = si.getUserId();
        while(StringUtils.countMatches(executionId,".")>1){
            //说明是子任务,用父任务获取一下变量
            executionId = executionId.substring(0,executionId.lastIndexOf("."));
        }
        try {
            return getWorkService().getProcessVariable(executionId, key, ueo);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 获取流程中关联的数据
     * @param taskOid 任务的主键
     * @param processOid 流程的主键
     * @param referColumns 引用的列
     * @return
     * @throws VciBaseException
     */
    @Override
    public DataGrid getDataByTask(String taskOid,String processOid,String referColumns) throws VciBaseException {
        if(StringUtils.isBlank(taskOid) && StringUtils.isBlank(processOid)){
            throw new VciBaseException(msgCodePrefix + "taskOidOrProcessOidNotNull");
        }
        Map<String,String> conditionMap = new HashMap<String, String>();
        if(StringUtils.isNotBlank(taskOid)) {
            conditionMap.put("f_oid", taskOid.trim());
            conditionMap.put("f_btwname", workitemBtmType);
        }else if(StringUtils.isNotBlank(processOid)){
            //实际上传递的是executionid
            conditionMap.put("f_oid", "\\IN(select oid from platformbtm_" + workIntanceBtmType + " where executionid = '" + processOid.trim() + "')");
            conditionMap.put("f_btwname", workIntanceBtmType);
        }
        return getData(taskDataLink,conditionMap,referColumns);
    }
 
    /**
     * 获取流程关联的业务数据的里阿杰类型
     * @param taskOid 任务主键
     * @param executionid 流程执行主键
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<LinkObject> getDataCloInTask(String taskOid, String executionid) throws VciBaseException {
        Map<String,String> conditionMap = new HashMap<String, String>();
        if(StringUtils.isNotBlank(taskOid)) {
            conditionMap.put("f_oid", taskOid.trim());
            conditionMap.put("f_btwname", getWorkitemBtmType());
        }else if(StringUtils.isNotBlank(executionid)){
            conditionMap.put("f_oid", "\\IN(select oid from platformbtm_" + getWorkIntanceBtmType() + " where executionid = '" + executionid.trim() + "')");
            conditionMap.put("f_btwname", getWorkIntanceBtmType());
        }
        return loService.queryCLO(taskDataLink, conditionMap);
    }
    
    private DataGrid getData(String linkType,Map<String,String> conditionMap,String referColumns) throws VciBaseException{
        List<LinkObject> clos = loService.queryCLO(taskDataLink, conditionMap);
        Map<String,List<String>> btmOidMap = new HashMap<String, List<String>>();
        if(clos!=null&&clos.size()>0){
            for(LinkObject clo : clos){
                List<String> oids = null;
                String btm = clo.toBTName.toLowerCase();
                if(btmOidMap.containsKey(btm)){
                    oids = btmOidMap.get(btm);
                }else{
                    oids = new ArrayList<String>();
                }
                oids.add(clo.toOid);
                btmOidMap.put(btm, oids);
            }
        }
        List<Map> data = new ArrayList<Map>();
        if(!btmOidMap.isEmpty()){
            Iterator<String> it = btmOidMap.keySet().iterator();
            while(it.hasNext()){
                String btm = it.next();
                List<String> oids  = btmOidMap.get(btm);
                conditionMap.clear();
                conditionMap.put("oid", QueryOptionConstant.IN + "(" + WebUtil.toInSql(oids.toArray(new String[0])) + ")");
                List<String> caluesList = new ArrayList<String>();
                if(StringUtils.isNotEmpty(referColumns)) {
                    caluesList = Arrays.asList(referColumns.split(","));
                }else {
                    caluesList.add("*");
                }
                List<BusinessObject> cbos = boService.queryCBO(btm, conditionMap,null,caluesList);
                data.addAll(boService.cbos2Map(cbos));
            }
        }
        DataGrid dg = new DataGrid();
        dg.setData(data);
        dg.setTotal(data.size());
        dg.setLimit(-1);
        dg.setPage(1);
        return dg;
    }
 
    @Override
    public DataGrid getDataByProcess(String executionId,String referColumns) throws VciBaseException{
        WebUtil.alertNotNull(executionId,"流程执行ID");
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("f_oid","\\IN(select oid from platformbtm_" +getWorkIntanceBtmType() + " where executionid='" + executionId.trim() + "')");
        conditionMap.put("f_btwname", getWorkIntanceBtmType());
        return getData(processDataLink,conditionMap,referColumns);
    }
 
    @Override
    public List<ProcessHistoryVO> getHistory(String executionId) throws VciBaseException{
        WebUtil.alertNotNull(executionId,"流程执行主键");
        List<ProcessHistoryVO> hisList = new ArrayList<ProcessHistoryVO>();
        FlowApproveHistoryInfo[] historyActivitys = null;
        try {
            historyActivitys = getWorkService().getHistoryActivityByProInsIdbyPLM(executionId);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        //需要去除未处理的重复项
        for (int i = 0; i < historyActivitys.length; i++) {
            FlowApproveHistoryInfo historyActivity = historyActivitys[i];
            ProcessHistoryVO his = new ProcessHistoryVO();
            his.setTaskName(historyActivity.taskName);
            his.setOpinin(historyActivity.opinion);//这个是处理方式,就是同意还是不同意
            his.setCreateTime(VciDateUtil.date2Str(VciDateUtil.long2Date(historyActivity.createTime), VciDateUtil.DateTimeFormat));
            his.setEndTime(VciDateUtil.date2Str(VciDateUtil.long2Date(historyActivity.endTime), VciDateUtil.DateTimeFormat));
            his.setNode(historyActivity.note);
            his.setAssignee(historyActivity.assignee);
            his.setExecutionId(historyActivity.executionId);
            String userIdString = historyActivity.assignee;
            if(StringUtils.contains(userIdString,":")) {
                userIdString = userIdString.substring(userIdString.indexOf(":") + 1);
            }
            String userShowInfoString = "";
            SmUserVO user = userQueryService.getUserByUserId(userIdString);
            if(user != null){
                userShowInfoString = user.getName() + "(" + user.getId() + ")";
            }else{
                userShowInfoString = historyActivity.assignee;
            }
            his.setAssigneeName(userShowInfoString);
            if(StringUtils.isNotBlank(his.getEndTime())) {
                hisList.add(his);
            }
            //如果endTime为空表示是待办的,但是服务端的接口中有个问题是,会把会签或者子流程中已经处理的和未处理的混合在一起
            //直接从待办任务里去查询
        }
 
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("businesstype", "5");//本项目没有实际的意义
        conditionMap.put("lcstatus", "Executing");
        if(StringUtils.countMatches(executionId,".")>1){
            String ex = executionId;
            while(StringUtils.countMatches(ex,".")>1){
                ex = ex.substring(0,ex.lastIndexOf("."));
            }
            conditionMap.put("executionid", ex + "*");
        }else {
            conditionMap.put("executionid", executionId + "*");
        }
        conditionMap.put(WebBoServiceI.QUERY_FILTER_SECRET,"false");
        conditionMap.put(WebBoServiceI.QUERY_FILTER_DATARIGHT,"false");
        PageHelper pageHelper = new PageHelper(-1);
        pageHelper.setSort("endTime");
        pageHelper.setOrder(pageHelper.asc);
        List<BusinessObject> undoTaskCbos= boService.queryCBO(workitemBtmType, conditionMap);
        if(undoTaskCbos != null && undoTaskCbos.size() > 0) {
            for(BusinessObject cbo : undoTaskCbos) {
                ProcessHistoryVO his = new ProcessHistoryVO();
                String taskName = cbo.name;
                if(StringUtils.contains(taskName,"-")) {
                    taskName = taskName.substring(taskName.lastIndexOf("-") + 1);
                }
                his.setTaskName(taskName);
                his.setCreateTime(String.valueOf(cbo.createTime));
                String userIdString = ObjectTool.getBOAttributeValue(cbo,"principal");
                if(StringUtils.contains(userIdString,":")) {
                    userIdString = userIdString.substring(userIdString.indexOf(":") + 1);
                }
                his.setAssignee(ObjectTool.getBOAttributeValue(cbo,"principal"));
                String userShowInfoString = "";
                SmUserVO user = userQueryService.getUserByUserId(userIdString);
                if(user != null){
                    userShowInfoString = user.getName() + "(" + user.getId() + ")";
                }else{
                    userShowInfoString = userIdString;
                }
                his.setAssigneeName(userShowInfoString);
                his.setExecutionId(ObjectTool.getBOAttributeValue(cbo,"executionid"));
                
                hisList.add(his);
            }
        }
        return hisList;
    }
 
    @Override
    public byte[] getProcessPicture(String executionId, String taskName)
            throws VciBaseException{
        WebUtil.alertNotNull(executionId,"流程执行主键",taskName,"流程任务名称");
        try {
            byte[] processChart =  getWorkService().getExecutionImageByExecutionId(executionId, taskName);
            return processChart;
        } catch (Throwable e) {
            String msg = "有可能这个任务关联的流程已经结束或者被终止,不能再查看其流程图了";
            logger.error(msg,e);
            throw new VciBaseException(msg);
        }
    }
 
    @Override
    public byte[] getProcessTemplatePicture(String executionId)
            throws VciBaseException{
        WebUtil.alertNotNull(executionId,"流程实例主键");
        try {
            byte[] processChart =  getWorkService().getFlowImageByDeployID(executionId);
            return processChart;
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 获取任务的路由
     * @param taskOid jbpm中的任务主键
     * @return
     * @throws VciBaseException
     */
    @Override
    public String[] getAllOutComes(String taskOid) throws VciBaseException{
        try {
            return getWorkService().getAllOutComes(taskOid);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 获取下一步的任务
     * @param executionid 流程执行主键
     * @param taskName 当前任务的名称
     * @param outCome 路由名称
     * @return 因为有分支的情况,所以下一步任务会有多个
     */
    @Override
    public String getNextTaskName(String executionid, String taskName, String outCome) throws VciBaseException{
        WebUtil.alertNotNull(executionid,"流程执行主键",taskName,"任务名称");
        String deployId = getJbpmDeploymentIdByExecutionId(executionid);
        try {
            return getWorkService().getNextTaskNameByJbpmId(deployId, taskName, outCome);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 获取平台的流程服务
     * @return
     */
    @Override
    public WorkflowServicePrx getWorkService() throws VciBaseException{
        if(workService == null){
            this.workService = platformClientUtil.getWorkflowService();
        }
        return workService;
    }
 
    @Override
    public String getTaskDataLink() {
        return taskDataLink;
    }
 
    @Override
    public String getWorkitemBtmType() {
        return workitemBtmType;
    }
 
    @Override
    public String getWorkIntanceBtmType(){
        return workIntanceBtmType;
    }
 
    /**
     * 开启流程代理------平台只支持添加一个代理用户
     */
    @Override
    public void beginProxy(String userId, Date startDate, Date endDate,
            boolean isNowEnable) throws VciBaseException {
        WebUtil.alertNotNull(userId,"代理人的用户名",startDate,"开始时间");
        TasksAssignedInfo taskAss = new TasksAssignedInfo();
        taskAss.id = new ObjectUtility().getNewObjectID36();
        SmUserVO user = userQueryService.getUserByUserId(userId);
        if(user!=null){
            taskAss.userName = user.getName();
        }else{
            taskAss.userName = "";
        }
        taskAss.TasksName = userId;
        taskAss.startTime = VciDateUtil.getTime(startDate);
        if(endDate == null){
            endDate = VciDateUtil.getDateAddDay(startDate, 30);//默认最多代理一个月
        }
        taskAss.endTime = VciDateUtil.getTime(endDate);
        taskAss.isTrue = isNowEnable?true:false;
        taskAss.fromUser =WebUtil.getCurrentUserSessionInfo().getUserId();
        try {
            getWorkService().saveOrUpdateTasksAssigned(taskAss, WebUtil.getUserEntityInfo("流程"));
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
    
    
 
    @Override
    public void endProxy()
            throws VciBaseException {
        //平台不支持停用启用代理信息..可以查询出来再重新添加。
        try {
            UserEntityInfo  uei = WebUtil.getUserEntityInfo( "流程");
            getWorkService().deleteTasksAssignedByUserName(new String[]{uei.userName}, uei);
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
    
    @Override
    public TasksAssignedInfo getProxy() throws VciBaseException{
        TasksAssignedInfo assign = null;
        try {
            assign = getWorkService().getTasksAssignedByUserName("", WebUtil.getUserEntityInfo( "流程"));
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
        return assign;
    }
 
    /**
     * 结束流程
     *
     * @param executionId 流程执行主键
     * @throws VciBaseException
     */
    @Override
    public void endProcess(String executionId) {
        try {
            DataGrid dataGrid  = getDataByProcess(executionId,null);
            //先获取一下
            UserEntityInfo userEntityInfo = WebUtil.getUserEntityInfo("流程");
            String resetStatus = null;
            try{
                resetStatus = getWorkService().getProcessVariable(executionId, WFVariablesKeyConstant.RESET_STATUS, userEntityInfo);
            }catch (Throwable e){
                logger.error("获取流程的变量出错",e);
            }
            getWorkService().endProcessInstanceByplatform(executionId,userEntityInfo);
            //平台没有自动将业务数据恢复到之前的状态
            if(StringUtils.isNotBlank(resetStatus)){
                resetLcStatusForBusinessData(dataGrid.getData(),resetStatus);
            }
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        } catch (Exception e) {
            throw new VciBaseException("结束流程失败!", new Object[]{}, e);
        }
    }
 
    private void  resetLcStatusForBusinessData(List<Map> bussinesDataList,String resetStatus) throws Exception{
        if(bussinesDataList!=null && bussinesDataList.size() > 0){
            String btmType = "";
            String lctId = "";
            List<String> oidList = new ArrayList<String>();
            //流程中的业务数据都是在同一个业务类型下的
            for(Map data : bussinesDataList){
                btmType = (String)data.get("btmname");
                String oid = (String)data.get("oid");
                lctId = (String)data.get("lctid");
                oidList.add(oid);
            }
            //转换成500长度的
            List<BusinessObject> cboList = new ArrayList<BusinessObject>();
            if(oidList.size()>500){
                List<List<String>> oidListForIn = WebUtil.switchListForOracleIn(oidList);
                for(List<String> oidListForInRecord : oidListForIn){
                    Map<String,String> conditionMap = new HashMap<String, String>();
                    conditionMap.put("oid",QueryOptionConstant.IN + "(" + WebUtil.toInSql(oidListForInRecord.toArray(new String[0])) + ")" );
                    List<BusinessObject> tempCbos = boService.queryCBO(btmType,conditionMap);
                    cboList.addAll(tempCbos);
                }
            }else{
                Map<String,String> conditionMap = new HashMap<String, String>();
                conditionMap.put("oid",QueryOptionConstant.IN + "(" + WebUtil.toInSql(oidList.toArray(new String[0])) + ")" );
                List<BusinessObject> tempCbos = boService.queryCBO(btmType,conditionMap);
                cboList.addAll(tempCbos);
            }
            //找到这个业务类型的起始状态
            lifeCycleService.transCboStatus(cboList,resetStatus);//执行重置
        }
    }
 
    /**
     * 根据业务类型查询正在执行的流程
     *
     * @param bussinessOid 业务类型数据
     * @param btmName      业务类型名称
     * @return
     * @throws VciBaseException
     */
    @Override
    public List<ProcessInstanceVO> listExecutingProcessByBussinessOid(String bussinessOid, String btmName) throws VciBaseException {
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("oid",QueryOptionConstant.IN + "(select f_oid from platformlt_" + getTaskDataLink() + " where f_btwname='" + getWorkIntanceBtmType() + "' " +
                                " and t_btwname='" + btmName + "' and t_oid = '" + bussinessOid + "' )");
        conditionMap.put("lcstatus","Executing");
        List<ProcessInstance> processInstances = boService.queryObject(ProcessInstance.class,conditionMap);
        List<ProcessInstanceVO> instanceVOS = new ArrayList<>();
        Optional.ofNullable(processInstances).orElseGet(()->new ArrayList<>()).stream().forEach(instance->{
            ProcessInstanceVO instanceVO = new ProcessInstanceVO();
            BeanUtilForVCI.convert(instance,instanceVO);
            instanceVOS.add(instanceVO);
        });
        return instanceVOS;
    }
 
    /**
     * 批量终止流程,
     *
     * @param executionIds  流程的执行主键
     * @param note          终止原因
     * @throws VciBaseException
     */
    @Override
    public void batchEndProcess(Collection<String> executionIds, String note) throws VciBaseException {
        WebUtil.alertNotNull(executionIds,"流程执行主键信息");
        for(String executionId : executionIds){
            endProcess(executionId);
        }
    }
 
    /**
     * 获取流程xml的二进制内容
     * @param jbpmDeploymentId
     * @return 流程的二进制内容
     * @throws VciBaseException  
     */
    @Override
    public byte[] getProcessXmlContent(String jbpmDeploymentId) throws VciBaseException {
        WebUtil.alertNotNull("流程执行主键信息",jbpmDeploymentId);
        try {
            return getWorkService().getProcessResource(jbpmDeploymentId,".xml");
        } catch (PLException e) {
            throw WebUtil.getVciBaseException(e);
        }
    }
 
    /**
     * 流程分类的数据对象转换为显示对象
     * @param doCollection 数据对象的集合
     * @return 显示对象
     */
    @Override
    public List<ProcessClassifyVO>  processClassifyDO2VOs(Collection<WFProcessClassifyDO> doCollection){
        List<ProcessClassifyVO> voList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(doCollection)){
            doCollection.stream().forEach(classifyDO->{
                ProcessClassifyVO classifyVO = processClassifyDO2VO(classifyDO);
                voList.add(classifyVO);
            });
        }
        return voList;
    }
 
    /**
     * 流程分类的数据对象转换为显示对象
     * @param classifyDO 数据对象
     * @return 显示对象
     */
    @Override
    public ProcessClassifyVO processClassifyDO2VO(WFProcessClassifyDO classifyDO){
        ProcessClassifyVO classifyVO = new ProcessClassifyVO();
        if(classifyVO!=null){
            BeanUtilForVCI.convert(classifyDO,classifyVO);
        }
        return classifyVO;
    }
 
    /**
     * 流程模板的数据对象转换为显示对象
     * @param doCollection 数据对象集合
     * @return 显示对象
     */
    @Override
    public List<ProcessTemplateVO> processTemplateDO2VOs(Collection<WFProcessTemplateDO> doCollection){
        List<ProcessTemplateVO> voList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(doCollection)){
            doCollection.stream().forEach(templateDO->{
                ProcessTemplateVO templateVO = processTemplateDO2VO(templateDO);
                voList.add(templateVO);
            });
        }
        return voList;
    }
 
    /**
     * 流程模板的数据对象转换为显示对象
     * @param templateDO 数据对象
     * @return 显示对象
     */
    @Override
    public ProcessTemplateVO processTemplateDO2VO(WFProcessTemplateDO templateDO){
        ProcessTemplateVO templateVO = new ProcessTemplateVO();
        if(templateVO!=null){
            BeanUtilForVCI.convert(templateDO,templateVO);
        }
        return templateVO;
    }
 
    /**
     * 使用用户名查询待办任务的个数
     *
     * @param username 用户名
     * @return 个数
     */
    @Override
    public int countUndoTaskByUsername(String username) {
        Map<String,String> conditionMap = new HashMap<String, String>();
        conditionMap.put("businesstype", "5");//本项目没有实际的意义
        conditionMap.put("principal", username);
        conditionMap.put("lcstatus", "Executing");
        return boService.queryCount(workitemBtmType,conditionMap);
    }
 
 
}