zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
package cn.autoform.web.controller.workflow;
 
import cn.autoform.bean.FormSolidiFication;
import cn.autoform.bean.ProcessCon;
import cn.autoform.bean.ProcessState;
import cn.autoform.bean.system.UserInfo;
import cn.autoform.db.entity.ProcessApproval;
import cn.autoform.db.entity.ProcessInstance;
import cn.autoform.db.entity.ProcessTask;
import cn.autoform.db.exten.Process;
import cn.autoform.fw.exception.FormClientException;
import cn.autoform.fw.exception.IEMRuntimeException;
import cn.autoform.util.form.FormDataCodeToNameFilter;
import cn.autoform.util.thread.Keys;
import cn.autoform.util.thread.ThreadData;
import cn.autoform.util.tool.JSONTool;
import cn.autoform.util.tool.ObjectUtil;
import cn.autoform.web.client.CscApiService;
import cn.autoform.web.client.WorkflowClient;
import cn.autoform.web.client.impl.FormClientImpl;
import cn.autoform.web.client.util.WorkflowTool;
import cn.autoform.web.client.util.WorkflowTwe;
import cn.autoform.web.controller.resumable.util.FastDFSClient;
import cn.autoform.web.service.datamanagement.DataManagementService;
import cn.autoform.web.service.process.*;
import com.alibaba.fastjson.TypeReference;
import com.codingapi.tx.annotation.TxTransaction;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeoutException;
 
@Slf4j
@RestController
public class WorkflowController {
 
    @Autowired
    private FormClientImpl formClient;
    @Autowired
    private ProcessApprovalService processApp;
 
 
    @Autowired
    private ProcessInstanceService processInstance;
 
    @Autowired(required = false)
    private ProcessFilter processFilter;
 
    @Autowired
    private WorkflowClient workflowClient;
 
 
    @Resource(name = "processStateServiceImpl")
    private ProcessStateService process;
 
    @Value("${process-service-id}")
    private Integer processServiceId;
 
    @Resource
    private FastDFSClient fastDFSClient;
 
    /**
     * 流程logservice
     */
    @Resource(name = "processLogServiceImpl")
    private ProcessLogService processLogService;
 
    @Autowired
    private WorkflowTool workflowTool;
 
    @Autowired
    private WorkflowTwe workflowTwe;
 
    @Autowired
    private CscApiService cscApi;
 
    @Autowired
    private DataManagementService dataManagementService;
    public static final String Q = "[%s]:10";
 
    public static final String A = "[%s]:20";
 
    /**
     * 当前待办信息key
     */
    private static final String PROCESSINFORMATION = "processInformation";
 
    /**
     * 项目负责人
     */
    private static final String PROJECT_LEADER_PHONE = "projectLeaderPhone";
 
 
    /**
     * 删除流程定义
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processdefine01}", method = RequestMethod.POST)
    public Map<String, Object> defineDelete(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.defineDelete(process);
        return result;
    }
 
    /**
     * 部署流程定义
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processdefine02}", method = RequestMethod.POST)
    public Map<String, Object> definePeploy(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        jsonObject.remove("tenantID");
        jsonObject.remove("formID");
        //写死版本号
        jsonObject.put("version", "1.1.1");
        System.out.println("参数:" + JSONTool.toJson(jsonStr));
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.definePeploy(process);
        //修改数据库流程定义json信息
        processApp.definePeploy(result);
        System.out.println("结果:" + JSONTool.toJson(result));
        return result;
    }
 
    /**
     * 流程定义分页查询
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processdefine03}", method = RequestMethod.POST)
    public Map<String, Object> defineSeache(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.defineSeache(process);
        return result;
    }
 
    /**
     * 创建流程定义
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processdefine04}", method = RequestMethod.POST)
    public Map<String, Object> defineCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        //取出本地流程定义,没有则创建
        ProcessApproval pro = processApp.selectApp(jsonObject.getString("formID"));
        if (pro != null) {
            return JSONTool.toObj(JSONTool.toJson(pro), new TypeReference<Map<String, Object>>() {
            });
//            return RestResultGenerator.genBussinessSuccessResult(pro);
        }
        workflowTool.setRequest(request);
        //查询是否已经初始化过
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> flag = workflowClient.check(workflowTwe.getProcess(getRse(new JSONObject())));
        String flag1 = Objects.toString(flag.get("data"), "true");
        System.out.println("返回结果:" + JSONTool.toJson(flag));
        //若没有初始化过,进行初始化
        if (flag1.equals("false")) {
            Map<String, Object> o = workflowClient.initialization(workflowTwe.getProcess(getRse(new JSONObject())));
            System.out.println("初始化接口:" + JSONTool.toJson(o));
        }
        Map<String, Object> result = workflowClient.defineCreate(process);
        //新创建的定义添加到本端
        ProcessApproval proc = new ProcessApproval();
        //proc.setOrganizationId(jsonObject.getString("organizationId"));
        proc.setFormId(jsonObject.getString("formID"));
        processApp.addProcessApproval(result, proc);
        System.out.println("返回结果:" + JSONTool.toJson(result));
//        return RestResultGenerator.genBussinessSuccessResult(result.get("data"));
        return JSONTool.toObj(JSONTool.toJson(result.get("data")), new TypeReference<Map<String, Object>>() {
        });
    }
 
    public JSONObject getRse(JSONObject js) {
        js.put("tenantId", ThreadData.get(Keys.TENANT_ID));
        js.put("companyId", ThreadData.get(Keys.COMPANY_ID));
        js.put("serviceId", ThreadData.get(Keys.SERVICE_ID));
        return js;
    }
 
    /**
     * 退回流程实例
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     * @throws FormClientException
     */
    @RequestMapping(value = "${requset.processinst01}", method = RequestMethod.POST)
    public Map<String, String> instBack(@RequestBody Map<String, Object> jsonStr, HttpServletRequest request) throws TimeoutException, IOException, FormClientException {
        System.out.println("参数:" + JSONTool.toJson(jsonStr));
        //添加流程log
        processLogService.addProcessLog(jsonStr, "20", null);
        //重新构造参数
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put("activityInstId", jsonStr.get("activityInstId"));
        maps.put("activityDefId", jsonStr.get("activityDefId"));
        maps.put("processInstId", jsonStr.get("processInstId"));
        maps.put("data", jsonStr.get("data"));
        System.out.println("工作流参数:" + JSONTool.toJson(maps));
        JSONObject jsonObject = JSONObject.fromObject(JSONTool.toJson(maps));
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, String> result = workflowClient.instBack(process);
        System.out.println("返回结果:" + JSONTool.toJson(result));
//        if(result.get("data").equals("1")){
//        //添加退回Log
//        ProcessLog proLog = JSONTool.toObj(JSONTool.toJson(jsonStr),ProcessLog.class);
//        System.out.println(JSONTool.toJson(proLog));
//        processLogService.insertLog(proLog);
//        }
        //流程引擎执行失败,不进行表单状态的处理
        if(null != result && null != result.get("resCode") && result.get("resCode").contains("ErrCode")){
            return result;
        }
        if (true) {
            record(Objects.toString(jsonStr.get("processInstId"), ""), 1, jsonStr.get("activityDefId").toString());
        }
 
        if(workflowTool.isOne(Objects.toString(jsonStr.get("processInstId")))){
            processFilter.executeRollBack(
                    Objects.toString(jsonStr.get("formID"))
                    , Optional.ofNullable(jsonStr.get("dataRowNum")).map(Object::toString).map(Integer::valueOf).orElse(0)
                    , ThreadData.get(Keys.TENANT_ID));
        }
 
        return result;
    }
 
    /**
     * 设置代理
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst02}", method = RequestMethod.POST)
    public Map<String, Object> agentCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.agentCreat(process);
        return result;
    }
 
    @PostMapping("/test/html")
    public Object testHtml(@RequestBody String jsonStr) {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        String htmlUrl = uploadHtml(jsonObject.getString("html"));
        return htmlUrl;
    }
 
    @RequestMapping(value = "/set/html", method = RequestMethod.POST)
    public Map<String, Object> setHtml(@RequestBody String jsonStr) throws TimeoutException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        ProcessState ps = new ProcessState(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
        ps.setHtmlUrl(uploadHtml(jsonObject.getString("html")));
        this.process.updateState(ps);
        return new ModelMap("resCode", "000000");
    }
 
    /**
     * 创建流程实例
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "${requset.processinst03}", method = RequestMethod.POST)
    @TxTransaction(isStart = true)
    @Transactional
    public Map<String, Object> instCreat(@RequestBody String jsonStr, HttpServletRequest request) throws Exception {
        //添加流程办理中
        Integer dNum = null;
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        String formId = jsonObject.getString("formID");
        Integer dataRowNun = jsonObject.getInt("dataRowNum");
        String htmlUrl = uploadHtml(jsonObject.getString("html"));
        // 清除无用参数,参数超长问题
        jsonObject.remove("html");
 
        String tenantId = ThreadData.get(Keys.TENANT_ID);
        if (processFilter != null) {
            processFilter.executeBefor(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
        }
        //查看本条数据是否创建过流程
        ProcessApproval pro = null;
        ProcessInstance pros = new ProcessInstance();
        pros.setDataRowNum(jsonObject.getInt("dataRowNum"));
        pros.setFormID(jsonObject.getString("formID"));
        Map<String, Object> res = new HashMap<>();
        //判断是否已经创建流程实例,以创建返回
        //取出当前流程大状态
        ProcessInstance p = processInstance.selectInst(pros);
        ProcessState pse = process.selectState(new ProcessState(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID)));
        //验证操作人员
        checkData(pse);
        if (p != null) {
            ProcessState pgo = new ProcessState(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
            //取出当前流程大状态
            ProcessState ps = process.selectState(pgo);
            if (!ObjectUtil.empty(ps) && "10".equals(ps.getProcessState())) {
                //已有流程实例,并且状态为10,重新提交
                String i = instOne(htmlUrl, jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID), p.getProcessInstId(), p.getProcessDefId());
                if (i != null) {
 
                    if (processFilter != null) {
                        processFilter.executeCreate(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
                    }
 
                    res.put("resCode", "00000");
                    return res;
                } else {
 
                }
            }
            res.put("data", "2");
 
            if (processFilter != null) {
                processFilter.executeCreate(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
            }
            return res;
        }
        pro = processApp.selectApp(jsonObject.getString("formID"));
        if (pro == null) {
            res.put("data", "3");
            return res;
        }
 
        jsonObject.put("processDefName", pro.getProcessDefName());
        jsonObject.put("processDefId", pro.getProcessDefId());
        jsonObject.put("processInstName", pse.getNumber());
        jsonObject.put("params", processApp.getProcessParam(
                formId
                , tenantId
                , dataRowNun));
        setSearchParam(jsonObject, pse);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.autoFinish(process);
        //将流程实例添加在本端
        Object obj = result.get("data");
        if (ObjectUtil.empty(obj)) {
            throw new IEMRuntimeException("流程自动提交待办异常,自动提交失败");
        }
        StringBuffer tasks = new StringBuffer();
        ProcessInstance proInst = JSONTool.toObj(JSONTool.toJson(obj), ProcessInstance.class);
        try {
            //添加流程日志
            Map<String, Object> logMap = JSONTool.toObj(jsonStr, Map.class);
            logMap.put("processInstId", proInst.getProcessInstId());
 
            proInst.setFormID(formId);
            proInst.setTenantID(tenantId);
            proInst.setDataRowNum(dataRowNun);
 
            dNum = processLogService.addProcessLog(logMap, "30", null);
 
            ProcessState ps = new ProcessState(formId, dataRowNun, tenantId);
            ps.setProcessUser(ThreadData.get(Keys.OPEN_ID));
            ps.setProcessLog(null);
            ps.setHtmlUrl(htmlUrl);
 
            List<ProcessTask> list = proInst.getWorkItems();
            if (ObjectUtil.notEmpty(list)) {
                for (ProcessTask pr : list) {
                    tasks.append("[").append(pr.getParticipantId()).append("],");
//                    proInst.setActivityInstId(pr.getActivityDefId());
                }
                ps.setProcessTask(tasks.toString().replaceAll(",$", ""));
                ps.setOrderStatus("21");
                ps.setProcessState("20");
            } else {
                this.budgetDeduction(tenantId, formId, dataRowNun);
                ps.setOrderStatus("40");
                ps.setProcessState("30");
            }
            proInst.setActivityInstId(proInst.getOneActivityDefId());
            processInstance.addProcess(proInst);
 
            this.process.updateState(ps);
 
//            if (workflowTool.isOver(result)) {
//                if (processFilter != null) {
//                    processFilter.executeOver(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
//                }
//            }
 
            if (processFilter != null) {
                processFilter.executeAfter(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
            }
 
            if (processFilter != null) {
                processFilter.executeCreate(jsonObject.getString("formID"), jsonObject.getInt("dataRowNum"), ThreadData.get(Keys.TENANT_ID));
            }
        } catch (Exception e) {
            System.err.println("------------------------手动结束当前流程----------------");
            jsonObject.clear();
            jsonObject.put("processInstId", proInst.getProcessInstId());
            processLogService.delProcessLog(dNum);
            workflowClient.instOver(workflowTool.getProcess(jsonObject));
            log.error(e.getMessage(), e);
 
            res.put("resCode", "00018");
            return res;
        }
        return result;
    }
 
    public String uploadHtml(String html) {
//        log.debug("上传大小:{}", html.length());
        String url = fastDFSClient.uploadFile(html.getBytes(), "json");
//        log.debug("上传成功:{}", url);
        if (ObjectUtil.empty(url)) {
            throw new IEMRuntimeException("固化html失败!");
        }
        return url;
    }
 
    private void setSearchParam(JSONObject jsonObject, ProcessState pse) {
        log.debug("流程状态:{}", JSONTool.toJson(pse));
        Map<String, Object> name = new HashMap<>(pse.getMainInfo());
        FormDataCodeToNameFilter.accept(name);
        jsonObject.put("sourceSystem", "epc");
        if (StringUtils.isEmpty((String)pse.getMainInfo().get("reimburseMan"))
                || StringUtils.isEmpty((String)name.get("reimburseMan"))) {
            //todo set
            UserInfo userInfo = formClient.getUserInfo();
            jsonObject.put("search_1", userInfo.getUserCode());
            jsonObject.put("search_2", userInfo.getUserName());
        } else {
            jsonObject.put("search_1", pse.getMainInfo().get("reimburseMan"));
            jsonObject.put("search_2", name.get("reimburseMan"));
        }
        jsonObject.put("search_3", pse.getMainInfo().get("C_Type"));
        jsonObject.put("search_4", name.get("C_Type"));
        jsonObject.put("search_5", name.get("Remark"));
        log.debug("添加查询参数:{}", jsonObject.toString());
    }
//
//    @RequestMapping(value = "${requset.processinst03}", method = RequestMethod.POST)
//    public JSONObject setSearchParam1(@RequestBody String jsonStr) {
//        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
//        jsonObject.put("sourceSystem", "epc");
//            //todo set
//            UserInfo userInfo = formClient.getUserInfo();
//            jsonObject.put("search_1", userInfo.getUserCode());
//            jsonObject.put("search_2", userInfo.getUserName());
//        log.debug("添加查询参数:{}", jsonObject.toString());
//        return jsonObject;
//    }
 
 
    /**
     * 撤销流程实例
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     * @throws FormClientException
     */
    @RequestMapping(value = "${requset.processinst04}", method = RequestMethod.POST)
    public Map<String, Object> instDrawBack(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException, FormClientException {
//        System.out.println("撤回参数"+jsonStr);
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instDrawBack(process);
//        System.out.println(" 撤销返回结果:"+JSONTool.toJson(result));
        //修改流程大状态
        if (result != null && "00000".equals(result.get("resCode"))) {
            this.updateState(jsonObject.getString("processInstId"));
        }
        if(workflowTool.isOne(jsonObject.getString("processInstId"))){
            processFilter.executeRollBack(jsonObject.getString("formID"), jsonObject.getInt("datarowNum"), ThreadData.get(Keys.TENANT_ID));
        }
        return result;
    }
 
    /**
     * 结束流程实例
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst05}", method = RequestMethod.POST)
    public Map<String, Object> instOver(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instOver(process);
        System.out.println("返回参数:" + JSONTool.toJson(result));
        return result;
    }
 
    /**
     * 设置代办
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst06}", method = RequestMethod.POST)
    public Map<String, Object> chargeCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.chargeCreate(process);
        return result;
    }
 
    /**
     * 执行流程实例
     *
     * @param
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "${requset.processinst07}", method = RequestMethod.POST)
    @TxTransaction(isStart = true)
    @Transactional
    public Map<String, Object> instFinish(@RequestBody Map<String, Object> map, HttpServletRequest request) throws Exception {
        //添加流程log
        processLogService.addProcessLog(map, "10", null);
        String formId = Objects.toString(map.get("formID"), "");
        Integer dataRowNum = NumberUtils.createInteger(Objects.toString(map.get("dataRowNum"), "0"));
        String tenantId = Objects.toString(map.get("tenantID"), "");
        if (processFilter != null) {
            processFilter.executeBefor(formId, dataRowNum, tenantId);
        }
        Map<String, Object> workFlowParam = new HashMap<>();
        workFlowParam.put("processInstId", map.get("processInstId"));
        workFlowParam.put("activityInstId", map.get("activityInstId"));
        workFlowParam.put("data", map.get("data"));
        workFlowParam.put("formID", map.get("formID"));
        workFlowParam.put("dataRowNum", map.get("dataRowNum"));
        workFlowParam.put("tenantID", map.get("tenantID"));
        workFlowParam.put("userName", map.get("userName"));
        workFlowParam.put("params", processApp.getProcessParam(
                Objects.toString(map.get("formID"))
                , Objects.toString(map.get("tenantID"))
                , NumberUtils.createInteger(Objects.toString(map.get("dataRowNum"), "0"))));
        JSONObject jsonObject = JSONObject.fromObject(JSONTool.toJson(workFlowParam));
        //执行前判断是否是项目负责人审批
        setProjectleader(JSONTool.toObj(JSONTool.toJson(map.get(PROCESSINFORMATION)), ProcessTask.class)
                , new ProcessState(formId, dataRowNum, tenantId), jsonObject);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instFinish(process);
//        System.out.println("执行返回结果:"+JSONTool.toJson(result));
        if (workflowTool.isOver(result)) {
            this.budgetDeduction(tenantId, formId, dataRowNum);
        } else {
            record(Objects.toString(map.get("processInstId"), ""), 0, map.get("activityInstId").toString());//if(result.get("data") != null)
        }
        if (processFilter != null) {
            processFilter.executeAfter(formId, dataRowNum, tenantId);
        }
        return result;
    }
 
    /**
     * 查询流程待办
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst08}", method = RequestMethod.POST)
    public Map<String, Object> instSeacheHandle(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        jsonObject.put("appId", processServiceId);
        jsonObject.put("tenantId", ThreadData.get(Keys.TENANT_ID));
        jsonObject.put("compId", ThreadData.get(Keys.COMPANY_ID));
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instSeacheHandle(process);
        return result;
    }
 
    /**
     * 流程实例log
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst09}", method = RequestMethod.POST)
    public Map<String, Object> instLog(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        ProcessInstance pros = new ProcessInstance();
        pros.setDataRowNum(Integer.parseInt(jsonObject.getString("dataRowNum")));
        pros.setFormID(jsonObject.getString("formID"));
        ProcessInstance prop = processInstance.selectInst(pros);
        System.out.println("流程实例:" + JSONTool.toJson(prop));
        if (prop == null) {
            Map<String, Object> remap = new HashMap<>();
            remap.put("data", null);
            return remap;
        }
        jsonObject.put("processInstId", prop.getProcessInstId());
 
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instLog(process);
        //每次操作更新本端节点,暂时不操作
        //processNodeService.operation(result,jsonObject.get("processInstId").toString());
        System.out.println("流程Log:" + JSONTool.toJson(result));
        return result;
    }
 
    /**
     * 获取所有可退回项目
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst10}", method = RequestMethod.POST)
    public Map<String, Object> getBack(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.getBack(process);
        return result;
    }
 
    /**
     * 查询代理
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst11}", method = RequestMethod.POST)
    public Map<String, Object> instAgent(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instAgent(process);
        return result;
    }
 
    /**
     * 查询代理去除流程定义信息
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst12}", method = RequestMethod.POST)
    public Map<String, Object> instAgentDefMsg(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instAgentDefMsg(process);
        return result;
    }
 
    /**
     * 查询流程实例
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processinst13}", method = RequestMethod.POST)
    public Map<String, Object> instSeache(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.instSeache(process);
        return result;
    }
 
    /**
     * 租户注册系统
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "${requset.processapp01}", method = RequestMethod.POST)
    public Map<String, Object> appCreate(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        workflowTool.setRequest(request);
        Process process = workflowTool.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.appCreate(process);
        return result;
    }
 
    /**
     * 初始化租户接口
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "process/initialization", method = RequestMethod.POST)
    public Map<String, Object> initialization(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        Process process = workflowTwe.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.initialization(process);
        return result;
    }
 
 
    /**
     * 检查初始化
     *
     * @param jsonStr
     * @param request
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    @RequestMapping(value = "process/check", method = RequestMethod.POST)
    public Map<String, Object> check(@RequestBody String jsonStr, HttpServletRequest request) throws TimeoutException, IOException {
        JSONObject jsonObject = JSONObject.fromObject(jsonStr);
        Process process = workflowTwe.getProcess(jsonObject);
        Map<String, Object> result = workflowClient.check(process);
        return result;
    }
 
    public static final String unsubmitted = "20";
 
    /**
     * 提交流程时,添加表单大状态
     *
     * @throws TimeoutException
     * @throws FormClientException
     */
    public int updateState(String formId, Integer dataRowNun, String tenantId, String processIntsId) throws FormClientException, TimeoutException {
        ProcessState pro = new ProcessState();
        pro.setFormId(formId);
        /*10:未提交,20:审核中,30审核完成 */
        pro.setProcessState(unsubmitted);
        pro.setDataRowNum(dataRowNun);
        pro.setProcessTask(processIntsId);
        pro.setTenantId(tenantId);
        pro.setProcessUser(cscApi.getUserId(ThreadData.get(Keys.OPEN_ID)));
        process.updateState(pro);
        return process.updateState(pro);
    }
//    @Resource(name = "processStateServiceImpl")
//    ProcessStateService pros;
//    @PostMapping("/qwe")
//    public void dfds() throws TimeoutException, FormClientException{
////        pros.selectState(null);
////        pros.updateState(null);
//        ThreadData.set(Keys.COMPANY_ID, "17");
//        ThreadData.set(Keys.OPEN_ID, "7d65637b5d634dae");
//
//    }
 
    /**
     * 每次审批后修改表单大状态
     */
    public int instState() {
        return 1;
    }
 
 
    /**
     * 自动提交流程第一步
     *
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    public String instOne(String htmlUrl, String formId, Integer dataRowNun, String tenantId, String processIntsId, String processDefId) throws Exception {
        //查询待办
//        System.err.println("--------------------开始自动提交------------------------");
        JSONObject o = new JSONObject();
        o.put("processInstId", processIntsId);
        o.put("params", processApp.getProcessOneActivityParam(
                processIntsId
                , processDefId
                , formId
                , tenantId
                , dataRowNun));
        Map<String, Object> result = workflowClient.instSeacheHandle(workflowTool.getProcess(o));
        Map<String, Object> map = JSONTool.toObj(JSONTool.toJson(result.get("data")), Map.class);
        String arctiv = null;
        if (!ObjectUtil.empty(map.get("data"))) {
            List<ProcessTask> list = JSONTool.toList(JSONTool.toJson(map.get("data")), ProcessTask.class);
            if (!ObjectUtil.empty(list) && list.size() > 0) {
//                System.out.println("-----------------查询自动提交待办-------------------------");
                o.put("activityInstId", list.get(0).getActivityInstId());
                arctiv = list.get(0).getActivityDefId();
                //执行前判断是否是项目负责人审批
                setProjectleader(list.get(0)
                        , new ProcessState(formId, dataRowNun, tenantId), o);
            } else {
                throw new IEMRuntimeException("流程自动提交待办异常,无待办信息!!");
            }
        }
        o.getString("activityInstId");
        //自动审批第一步
        Map<String, Object> result1 = workflowClient.instFinish(workflowTool.getProcess(o));
        Object c = result1.get("data");
        ProcessState p = new ProcessState(formId, dataRowNun, tenantId);
        p.setProcessUser(ThreadData.get(Keys.OPEN_ID));
        String tasks = "";
        if (!ObjectUtil.empty(c)) {
            ProcessInstance pro = JSONTool.toObj(JSONTool.toJson(c), ProcessInstance.class);
            List<ProcessTask> list = pro.getWorkItems();
            if (list.size() > 0) {
                StringBuffer s = new StringBuffer();
                for (ProcessTask pr : list) {
//                    System.out.println("["+cscApi.getUserId(pr.getOpenId())+"]");
//                    s.append("["+cscApi.getUserId(pr.getOpenId())+"]");
                    s.append("[" + pr.getParticipantId() + "]");
                }
                tasks = s.toString().replaceAll(",$", "");
 
                p.setProcessTask(tasks);
                p.setOrderStatus("21");
                p.setProcessState("20");
            } else {
                this.budgetDeduction(tenantId, formId, dataRowNun);
                p.setOrderStatus("40");
                p.setProcessState("30");
//                return arctiv;
            }
        } else {
            throw new IEMRuntimeException("流程自动提交待办异常,自动提交失败");
        }
        //查询待办,把待办人存储到大状态中
        o.remove("activityInstId");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("processInstId", processIntsId);
        p.setProcessLog(null);
        p.setProcessTask(tasks);
        p.setHtmlUrl(htmlUrl);
        //单据状态改为审核中
        System.err.println("---------------------自动审批第一步----------------------");
        System.out.println("------------------------圆满结束--------------------------");
 
        process.updateState(p);
        return arctiv;
    }
 
    /**
     * 审批,退回后后记录已办,和下个节点待办
     *
     * @throws FormClientException
     * @throws TimeoutException
     */
    @SuppressWarnings("unchecked")
    public int record(String processIntsId, Integer flag, String activityInstId) throws TimeoutException, FormClientException {
        //取出表单id
        ProcessInstance pros = processInstance.selectInsts(processIntsId);
        System.out.println("当前流程:" + JSONTool.toJson(pros));
        ProcessState pro = new ProcessState(pros.getFormID(), pros.getDataRowNum(), pros.getTenantID());
        //取出当前流程大状态
        ProcessState p = process.selectState(pro);
        p.setDataRowNum(pros.getDataRowNum());
        p.setFormId(pros.getFormID());
        p.setTenantId(pros.getTenantID());
        System.out.println("当前流程大状态:" + JSONTool.toJson(p));
        //添加已办,已退回
        ProcessCon con = new ProcessCon();
        con.setRetired(p.getProcessLog());
        String z = null;
        if (flag == 0) {
            //添加已办
            con.getRetired().add(String.format(Q, cscApi.getUserId(ThreadData.get(Keys.OPEN_ID))));
            z = con.getLog();
        } else {
            //添加已退
            con.getRetired().add(String.format(A, cscApi.getUserId(ThreadData.get(Keys.OPEN_ID))));
            z = con.getLog();
            if (activityInstId.equals(pros.getActivityInstId())) {
                p.setProcessState("10");
                p.setOrderStatus(p.getOrderCode() != null && !p.getOrderCode().isEmpty() ? "15" : "20");
                z = "";
//                //修改流程log得状态
//                ProcessLog plog = new ProcessLog(pros.getFormID(),pros.getDataRowNum()
//                        ,pros.getTenantID(),processIntsId
//                        ,ThreadData.get(Keys.COMPANY_ID),ThreadData.get(Keys.OPEN_ID));
//                plog.setDataType("30");
//                processLogService.updateState(plog);
                //结束流程
//                this.processInstOver(processIntsId);
            }
        }
        p.setProcessLog(z);
        //添加新的待办--------------------------
        JSONObject o = new JSONObject();
        o.put("processInstId", processIntsId);
        Map<String, Object> result3 = workflowClient.instSeacheHandle(workflowTool.getProcess(o));
        Map<String, Object> map1 = JSONTool.toObj(JSONTool.toJson(result3.get("data")), Map.class);
        if (!ObjectUtil.empty(map1.get("data"))) {
            List<ProcessTask> list = JSONTool.toList(JSONTool.toJson(map1.get("data")), ProcessTask.class);
            if (list.size() > 0) {
                StringBuffer s = new StringBuffer();
                for (ProcessTask pr : list) {
                    s.append("[" + cscApi.getUserId(pr.getOpenId()) + "]");
                }
                p.setProcessTask(s.toString().replaceAll(",$", ""));
            }
        }
        //修改当表单大状态
        System.out.println("当前状态:" + JSONTool.toJson(p));
        process.updateState(p);
        return 1;
    }
 
    //判断是否撤回到了 提交活动步骤
    @SuppressWarnings("unchecked")
    public boolean updateState(String proId) throws TimeoutException, FormClientException {
        System.out.println("------------------判断是否撤销到提交活动------------------------");
        //取出当前流程实例
        ProcessInstance pro = processInstance.selectInsts(proId);
        System.out.println("当前流程实例:" + JSONTool.toJson(pro));
        //查询当前待办
        JSONObject o = new JSONObject();
        o.put("processInstId", pro.getProcessInstId());
        Map<String, Object> result = workflowClient.instSeacheHandle(workflowTool.getProcess(o));
        Map<String, Object> map1 = JSONTool.toObj(JSONTool.toJson(result.get("data")), Map.class);
        System.out.println("当前待办信息:" + JSONTool.toJson(map1));
        if (!ObjectUtil.empty(map1.get("data"))) {
            List<ProcessTask> list = JSONTool.toList(JSONTool.toJson(map1.get("data")), ProcessTask.class);
            ProcessState p = new ProcessState(pro.getFormID(), pro.getDataRowNum(), pro.getTenantID());
            //查询流程大状态
            ProcessState processState = process.selectState(p);
            StringBuffer s = new StringBuffer();
            for (ProcessTask pr : list) {
                s.append("[" + cscApi.getUserId(pr.getOpenId()) + "]");
            }
            p.setProcessTask(s.toString().replaceAll(",$", ""));
 
            System.out.println("修改流程大状态成功");
            //判断是否是撤销到第一节点
            if (pro.getActivityInstId().equals(list.get(0).getActivityDefId())) {
                //修改流程大状态为未提交
                p.setProcessState("10");
                p.setOrderStatus(processState.getOrderCode() != null
                        && !Objects.equals("", processState.getOrderCode()) ? "15" : "20");
                p.setProcessLog("");
                //结束流程
//                this.processInstOver(proId);
//                //修改流程log得状态
//                ProcessLog plog = new ProcessLog(pro.getFormID(),pro.getDataRowNum()
//                        ,pro.getTenantID(),proId
//                        ,ThreadData.get(Keys.COMPANY_ID),ThreadData.get(Keys.OPEN_ID));
//                plog.setDataType("30");
//                processLogService.updateState(plog);
            }
            process.updateState(p);
 
        }
        return true;
    }
 
    //流程结束后执行预算逻辑
    public void budgetDeduction(String tenantId, String formId, Integer dataRowNum) throws FormClientException, TimeoutException {
        if (this.processFilter != null) {
            this.processFilter.executeOver(formId, dataRowNum, tenantId);
        }
    }
 
//    //取出表单的自动生成编号
//    public String getNumber(pse, String formId,Integer dataRowNum,String tenantId) throws TimeoutException, FormClientException{
//        return getProcessState(formId, dataRowNum,tenantId).getNumber();
//    }
 
    public ProcessState getProcessState(String formId, Integer dataRowNum, String tenantId) throws TimeoutException, FormClientException {
        return process.selectState(new ProcessState(formId, dataRowNum, tenantId));
    }
 
    public FormSolidiFication formSolidiFication(String formId, Integer dataRowNum, String tenantId) throws TimeoutException {
        return dataManagementService.formSolidiFication(formId, dataRowNum, tenantId);
    }
 
    /**
     * 结束流程操作-1
     *
     * @throws TimeoutException
     */
    public int processStateOver(String proId) throws TimeoutException {
 
        return processInstance.updateProState(proId);
    }
 
 
    /**
     * 结束流程操作-2
     *
     * @throws TimeoutException
     */
    public int processInstOver(String proId) throws TimeoutException {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("processInstId", proId);
        workflowClient.instOver(workflowTool.getProcess(jsonObject));
        return 1;
    }
 
    public void checkData(ProcessState ps) {
        if (Objects.equals(ps.getCreateUser(), ThreadData.get(Keys.OPEN_ID))) {
            log.debug("当前数据操作人员通过验证");
        } else {
            throw new IEMRuntimeException("FORM_USER_AGREEMENT");
        }
    }
 
 
    //到账状态
    private static final String CONFORMINGSTATE = "conformingstate";
 
    //回执号
    private static final String VOUCHERNO = "voucherno";
 
    //未到账,常量
    private static final String WDZ = "T00001";
 
    //交易号
    private static final String TRADENUMBER = "tradeNumber";
 
    /**
     * 新接口 ,编辑并提交,编辑并退回
     */
    @RequestMapping(value = "${requset.processinst14}", method = RequestMethod.POST)
    public Map vouchernoWirte(@RequestBody Map<String, Object> map, HttpServletRequest request) throws Exception {
        String state = Objects.toString(map.get(CONFORMINGSTATE), null);
        String proInstId = Objects.toString(map.get("processInstId"));//当前流程实例id
        //修改表单数据
        ProcessState st = new ProcessState(Objects.toString(map.get("formID")), Integer.parseInt(map.get("dataRowNum").toString()), Objects.toString(map.get("tenantID")));
        st.setConformingstate(state);
        st.setTradeNumber(Objects.toString(map.get(TRADENUMBER), ""));
        st.setVoucherno(Objects.toString(map.get(VOUCHERNO), ""));
        process.updateState(st);
        //判断执行还是退回
        if (Objects.equals(WDZ, state)) {
            log.debug("进入退回");
            //获取可退回活动项
            Map<String, Object> ms = this.getBack(JSONTool.toJson(
                    new ModelMap("processInstId", proInstId)), request);
            Map<String, Object> m = ((List<Map>) ms.get("data")).get(0);
            m.put("formID", map.get("formID"));
            m.put("dataRowNum", map.get("dataRowNum"));
            m.put("tenantID", map.get("tenantID"));
            m.put("processInstId", proInstId);
            m.put("activityInstId", map.get("activityInstId"));
            return this.instBack(m, request);
        } else {
            log.debug("进入执行");
            map.remove(CONFORMINGSTATE);
            map.remove(VOUCHERNO);
            map.remove(TRADENUMBER);
            return this.instFinish(map, request);
        }
 
    }
 
 
    public void setProjectleader(ProcessTask processTask, ProcessState processState, JSONObject jsonObject) throws TimeoutException {
        log.debug("当前是否活动指派前:" + processTask.getAppointActivity());
        if (processTask.getAppointActivity() != null && processTask.getAppointActivity()) {
            ProcessState ps = process.selectState(processState);
            String phone = Objects.toString(ps.getMainInfo().get(PROJECT_LEADER_PHONE), null);
            if (phone != null && !Objects.equals(phone, "")) {
                String id = cscApi.getUserId(phone);
                log.debug("当前人员id:" + id);
                if (id != null && !Objects.equals(id, "")) {
                    jsonObject.put("wfpIds", Arrays.asList(id));
                    jsonObject.put("workItemId", processTask.getWorkItemId());
                }
            }
        }
    }
}