cy
2022-06-27 150ced737ad5d16d476df143c7e4238fc6b8b998
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
package cn.ksource.core.workflow;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import cn.ksource.beans.*;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.dao.SqlParameter;
import cn.ksource.web.Constants;
 
@Service
public class WorkflowBusinessServiceImpl implements WorkflowBusinessService {
    @Autowired
    private BaseDao baseDao;
    
    @Autowired
    private WorkflowCoreService workflowCoreService;
    
    
    public void toNode(WORKFLOW_BASE base,String node_template_id,NodeDealEntity entity){
        workflowCoreService.toNode(base, node_template_id, entity);
    }
    
    @Override
    public List<Map> getBackTemplateNodeList(
            String nodeInstanceId) {
        StringBuilder sql = new StringBuilder();
        sql.append("select tn.* ");
        sql.append("from workflow_template_node tn ");
        sql.append("where tn.ID in (select ROLEBACKNODEID from workflow_roleback_node where  ");
        sql.append("NODETEMPLEID in (select NODE_TEMPLATE_ID from workflow_node where ID=:id))");
        
        return baseDao.queryForList(sql.toString(), new SqlParameter().addValue("id", nodeInstanceId));
    }
 
 
    @Override
    public WORKFLOW_BASE toBack(String workflowInstanceId,
            String nodeInstanceId, String userId,
            Integer result, String note, String backNodeTemplateId) {
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setBackNodeId(backNodeTemplateId);
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        workflowCoreService.toBack(entity, new HashMap());
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    @Override
    public WORKFLOW_BASE toNext(String workflowInstanceId,
            String nodeInstanceId, String userId,
            Integer result, String note) {
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        //上一环节指定人员时,主要负责人可以推动流程到下一节点,其他负责人只能更新本节点状态
        WORKFLOW_NODE node = new WORKFLOW_NODE(nodeInstanceId).getInstanceById();
        if (node.getDeal_type() - Constants.WORKFLOW_TEMPLATE_NODE_DEALER_TYPE_ASSIGN == 0 && !isAdminWorkflowNode(workflowInstanceId, nodeInstanceId, userId)) {
            workflowCoreService.toNextByPartner(entity, new HashMap());
        } else {
            workflowCoreService.toNext(entity, new HashMap());
        }
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    @Override
    public WORKFLOW_BASE toNext(String workflowInstanceId,
            String nodeInstanceId, String userId,
            Integer result, String note, List<WorkflowDutyerEntity> dutyers) {
        
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        //上一环节指定人员时,主要负责人可以推动流程到下一节点,其他负责人只能更新本节点状态
        WORKFLOW_NODE node = new WORKFLOW_NODE(nodeInstanceId).getInstanceById();
        if (node.getDeal_type() - Constants.WORKFLOW_TEMPLATE_NODE_DEALER_TYPE_ASSIGN == 0 && !isAdminWorkflowNode(workflowInstanceId, nodeInstanceId, userId)) {
            workflowCoreService.toNextByPartner(entity, new HashMap());
        } else {
            workflowCoreService.toNext(entity, dutyers, new HashMap());
        }
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
 
    @Override
    public WORKFLOW_BASE closeWorkflow(String workflowInstanceId,
            String nodeInstanceId, String userId, Integer result, String note) {
        
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        workflowCoreService.handCloseWorkflow(entity, new HashMap());
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    @Override
    public WORKFLOW_BASE finishWorkflow(String workflowInstanceId,
            String nodeInstanceId, String userId, Integer result, String note) {
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        workflowCoreService.handFinishWorkflow(entity, new HashMap());
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    @Override
    public boolean isAdminWorkflowNode(String flowId, String nodeId, String userId) {
        
        StringBuilder sql = new StringBuilder();
        sql.append("select count(u.ID) ");
        sql.append("from workflow_template_node_user u ");
        sql.append("where u.NODE_ID=(select NODE_TEMPLATE_ID from workflow_node where ID=:id) ");
        sql.append("and u.USER_ID=:user_id ");
        sql.append("and u.IS_ADMIN=1 ");
        sql.append("and u.FLOW_INSTANCE_ID=:flow_instance_id ");
        
        SqlParameter param = new SqlParameter();
        param.addValue("id", nodeId);
        param.addValue("user_id", userId);
        param.addValue("flow_instance_id", flowId);
        
        return baseDao.queryForInteger(sql.toString(), param) > 0 ? true : false;
    }
 
    @Override
    public WORKFLOW_BASE updateWorkflowState(String workflowInstanceId,
            Integer wfstate) {
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById()
        .setWfstate(wfstate)
        .update();
    }
    
    /**
     * 获取报修设备信息
     * @param businessId
     * @return
     */
    private List<Map> queryCiRepairDetail(String businessId) {
        String sql = "select CI_ID,CI_NAME from sc_workflow_ci_repair_ci where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
        
        return baseDao.queryForList(sql, param);
        
    }
 
    /**
     * 获取变更设备信息
     * @param businessId
     * @return
     */
    private List<Map> queryCiChangeDetail(String businessId) {
        String sql = "select CI_ID,CI_NAME from sc_workflow_ci_change_ci where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
        
        return baseDao.queryForList(sql, param);
        
    }
    
    /**
     * 获取新增、变更、报废设备信息
     * @param businessId
     * @return
     */
    private List<Map> queryCiReferDetail(String businessId, int referType) {
        String sql = "select CI_ID,CI_NAME from sc_workflow_ci_refer where BUSINESS_ID=:business_id and REFER_TYPE=:refer_type ";
        
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
        param.addValue("refer_type", referType);
        
        return baseDao.queryForList(sql, param);
        
    }
    
    
    @Override
    public WORKFLOW_BASE startCIRemindWorkflow(String businessId) {
        //获取提醒申请信息
        SC_WORKFLOW_CI_REMIND remind = new SC_WORKFLOW_CI_REMIND().setId(businessId).queryForBean();
        if (remind == null) {
            return null;
        }
        
        //启动智能提醒流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_CI_REMIND);
        startEntity.setCustomerId(remind.getCustomer_id());
        startEntity.setFlowName(remind.getName());
        startEntity.setOrderCode(remind.getOrder_code());
        startEntity.setCustomerName(remind.getCustomer_name());
        startEntity.setUserName("系统定时任务");
        //服务内容说明
        startEntity.setWfNote(remind.getService_content());
        startEntity.setSubCustomerId(remind.getSub_customer_id());
        startEntity.setSubCustomerName(remind.getSub_customer_name());
        
        //客户加盟商信息
        SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO().setId(remind.getCustomer_id()).queryForBean();
        if (customer != null) {
            
        }
        //获取智能提醒设备
        //List<Map> ciList = this.queryCiRemindCi(businessId);
        //startEntity.setCiList(ciList);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, new HashMap());
        //反写智能提醒表中流程编号
        if (work_base != null) {
            remind.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    
    /**
     * 获取智能提醒设备信息
     * @param businessId
     * @return
     */
    private List<Map> queryCiRemindCi(String businessId) {
        String sql = "select CI_ID,CI_NAME from sc_workflow_ci_remind_ci where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
        
        return baseDao.queryForList(sql, param);
        
    }
    
    @Override
    public WORKFLOW_BASE startCIHealthWorkflow(String businessId) {
        //获取体检申请信息
        SC_WORKFLOW_CI_HEALTH health = new SC_WORKFLOW_CI_HEALTH(businessId).getInstanceById();
        if (health == null) {
            return null;
        }
        
        //启动健康检查流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_CI_HEALTH);
        startEntity.setCustomerId(health.getCustomer_id());
        startEntity.setCustomerName(health.getCustomer_name());
        startEntity.setFlowName(health.getName());
        
        startEntity.setSubCustomerId(health.getSub_customer_id());
        startEntity.setSubCustomerName(health.getSub_customer_name());
        
        startEntity.setOrderCode(health.getOrder_code());
        //申请人指定为客户
        startEntity.setUserId("");
        startEntity.setUserName("系统定时任务");
        
        //获取健康体检设备
        //List<Map> ciList = this.queryCiHealthCi(businessId);
        //startEntity.setCiList(ciList);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, new HashMap());
        
        //反写健康检查申请表中流程编号
        if (work_base != null) {
            health.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
 
    @Override
    public WORKFLOW_BASE toLast(String workflowInstanceId,
            String nodeInstanceId, String userId, Integer result, String note) {
 
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        workflowCoreService.toLast(entity, new HashMap());
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
    
    /**
     * 获取健康检查设备信息
     * @param businessId
     * @return
     */
    private List<Map> queryCiHealthCi(String businessId) {
        String sql = "select CI_ID,CI_NAME from sc_workflow_ci_health_ci where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
        
        return baseDao.queryForList(sql, param);
    }
 
    @Override
    public WORKFLOW_NODE getLastWorkflowNode(String flowId, String nodeId) {
        String sql = "select * from workflow_node where FLOWID=:flowid and ID<>:id and FLOWSTATE=3 order by CREATETIME desc limit 0,1 ";
        SqlParameter param = new SqlParameter();
        param.addValue("flowid", flowId);
        param.addValue("id", nodeId);
        
        return baseDao.queryForBean(sql, param, new WORKFLOW_NODE());
    }
 
    @Override
    public WORKFLOW_BASE toNode(int nodeNum, String workflowInstanceId,
            String nodeInstanceId, String userId, Integer result, String note,
            List<WorkflowDutyerEntity> dutyers) {
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        workflowCoreService.toNode(nodeNum, entity, dutyers, new HashMap());
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    @Override
    public WORKFLOW_BASE startIncidentWorkflow(String businessId,String bz) {
        //获取事件申请信息
        SC_WORKFLOW_INCIDENT incident = new SC_WORKFLOW_INCIDENT(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动事件流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT);
        startEntity.setCustomerId(incident.getCustomer_id());
        startEntity.setCustomerName(incident.getCustomer_name());
        startEntity.setFlowName(incident.getFlow_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_user_id());
        startEntity.setUserName(incident.getCreate_user_name());
        startEntity.setWfNote(incident.getDescrip());
        startEntity.setSubCustomerId(incident.getSub_customer_id());
        startEntity.setSubCustomerName(incident.getSub_customer_name());
        startEntity.setNote(incident.getDescrip());
        
        //获取关联设备
        /*List<Map> ciList = this.queryIncidentCi(businessId);
        startEntity.setCiList(ciList);*/
        
        Map map = new HashMap();
        map.put("bz", bz);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    /**
     * 入库流程
     */
    @Override
    public WORKFLOW_BASE startStockWorkflow(String businessId,String bz) {
        //获取事件申请信息
        SPARE_PART_STORAGE incident = new SPARE_PART_STORAGE(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动事件流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_STOCK);
        startEntity.setFlowName(incident.getOrder_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_id());
        startEntity.setUserName(incident.getCreate_name());
        startEntity.setWfNote(incident.getStorage_reason());
        Map map = new HashMap();
        map.put("bz", bz);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    /**
     * 备件申领流程
     */
    @Override
    public WORKFLOW_BASE startSpareWorkflow(String businessId,String bz) {
        //获取事件申请信息
        SPARE_PART_APPLY incident = new SPARE_PART_APPLY(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动事件流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_SPARE);
        startEntity.setFlowName(incident.getOrder_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_id());
        startEntity.setUserName(incident.getCreate_name());
        startEntity.setWfNote(incident.getApply_reason());
        Map map = new HashMap();
        map.put("bz", bz);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    
    /**
     * 出库申请流程
     */
    @Override
    public WORKFLOW_BASE startDeliveryWorkflow(String businessId,String bz) {
        //获取事件申请信息
        SPARE_PART_DELIVERY incident = new SPARE_PART_DELIVERY(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动事件流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_CKLC);
        startEntity.setFlowName(incident.getOrder_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_id());
        startEntity.setUserName(incident.getCreate_name());
        startEntity.setWfNote(incident.getDelivery_reason());
        Map map = new HashMap();
        map.put("bz", bz);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    
    /**
     * 报损报溢流程
     */
    @Override
    public WORKFLOW_BASE startOverageLossWorkflow(String businessId,String bz) {
        //获取事件申请信息
        OVERAGE_LOSS incident = new OVERAGE_LOSS(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动事件流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_BSBY);
        startEntity.setFlowName(incident.getOrder_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_id());
        startEntity.setUserName(incident.getCreate_name());
        startEntity.setWfNote(incident.getNote());
        Map map = new HashMap();
        map.put("bz", bz);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    @Override
    public WORKFLOW_BASE startInventoryWorkflow(String businessId,String bz) {
        //获取事件申请信息
        STOCK_INVENTORY stockInventory = new STOCK_INVENTORY(businessId).getInstanceById();
        if (stockInventory == null) {
            return null;
        }
        //启动库存盘点
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_KCPD);
        startEntity.setFlowName(stockInventory.getOrder_name());
        startEntity.setOrderCode(stockInventory.getOrder_code());
        startEntity.setUserId(stockInventory.getCreate_id());
        startEntity.setUserName(stockInventory.getCreate_name());
        startEntity.setWfNote(stockInventory.getNote());
        Map map = new HashMap();
        map.put("bz", bz);
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
 
        if (work_base != null) {
            stockInventory.setFlow_id(work_base.getId()).update();
        }
        return work_base;
    }
 
    public WORKFLOW_BASE startIncident_LocalWorkflow(String businessId, String bz){
        //获取事件申请信息
        SC_WORKFLOW_INCIDENT_LOCAL incident = new SC_WORKFLOW_INCIDENT_LOCAL(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动事件流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_INCIDENT_LOCAL);
        startEntity.setCustomerId(incident.getCustomer_id());
        startEntity.setCustomerName(incident.getCustomer_name());
        startEntity.setFlowName(incident.getFlow_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_user_id());
        startEntity.setUserName(incident.getCreate_user_name());
        startEntity.setWfNote(incident.getDescrip());
        startEntity.setSubCustomerId(incident.getSub_customer_id());
        startEntity.setSubCustomerName(incident.getSub_customer_name());;
        
        //获取关联设备
        /*String sql = "select CI_ID,CI_NAME from SC_WORKFLOW_INCIDENT_LOCAL_CI where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();  
        param.addValue("business_id", businessId);  
        
        List<Map> ciList = baseDao.queryForList(sql, param);  
        
        startEntity.setCiList(ciList);   */
        
        
        Map map = new HashMap();
        map.put("bz", bz);
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        //反写健康检查申请表中流程编号
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    
    
    public WORKFLOW_BASE startQuestionWorkflow(String businessId,String bz){
        
        //获取问题信息
        SC_WORKFLOW_QUESTION incident = new SC_WORKFLOW_QUESTION(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
        
        //启动问题流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_QUESTION);
        startEntity.setCustomerId(incident.getCustomer_id());
        startEntity.setCustomerName(incident.getCustomer_name());
        startEntity.setFlowName(incident.getFlow_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_user_id());
        startEntity.setUserName(incident.getCreate_user_name());
        startEntity.setWfNote(incident.getDescrip());
        startEntity.setSubCustomerId(incident.getSub_customer_id());
        startEntity.setSubCustomerName(incident.getSub_customer_name());
        startEntity.setNote(bz);
        Map map = new HashMap();
        map.put("bz", bz);
        //获取关联设备
        /*String sql = "select CI_ID,CI_NAME from SC_WORKFLOW_INCIDENT_LOCAL_CI where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();  
        param.addValue("business_id", businessId);  
        
        List<Map> ciList = baseDao.queryForList(sql, param);  
        
        startEntity.setCiList(ciList);  */ 
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, map);
        
        //反写健康检查申请表中流程编号
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
            .update();
        }
        return work_base;
    }
    
    
    
    
    
    private List<Map> queryIncidentCi(String businessId) {
        String sql = "select CI_ID,CI_NAME from sc_workflow_incident_ci where BUSINESS_ID=:business_id ";
        
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
        
        return baseDao.queryForList(sql, param);
    }
 
    @Override
    public WORKFLOW_BASE resetNodeDealer(String workflowInstanceId,
            String nodeInstanceId, String userId, String userName) {
        
        //更新节点处理人,角色置空
        new WORKFLOW_NODE().setId(nodeInstanceId)
        .setCurrent_dealer_id(userId)
        .setCurrent_dealer_name(userName)
        .setCurrent_deal_roleida("")
        .setCurrent_deal_rolename("")
        .update();
        
        //更新流程处理人
        new WORKFLOW_BASE().setId(workflowInstanceId)
        .setCurrent_dealer_id(userId)
        .setCurrent_dealer_name(userName)
        .setCurrent_deal_roleida("")
        .setCurrent_deal_rolename("")
        .update();
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    @Override
    public WORKFLOW_BASE deleteWorkflow(String workflowInstanceId,
            String nodeInstanceId, String userId, Integer result, String note) {
        GG_USER user = new GG_USER(userId).getInstanceById();
        String userName = user != null ? user.getZsxm() : "";
        
        WorkflowDealEntity entity = new WorkflowDealEntity();
        entity.setNodeInstanceId(nodeInstanceId);
        entity.setNote(note);
        entity.setResult(result);
        entity.setUserId(userId);
        entity.setUserName(userName);
        entity.setWfInstanceId(workflowInstanceId);
        
        workflowCoreService.handDeleteWorkflow(entity, new HashMap());
        
        return new WORKFLOW_BASE(workflowInstanceId).getInstanceById();
    }
 
    public WORKFLOW_BASE startChangeWorkflow(String businessId){
 
        //获取问题信息
        SC_WORKFLOW_CHANGE incident = new SC_WORKFLOW_CHANGE(businessId).getInstanceById();
        if (incident == null) {
            return null;
        }
 
        //启动问题流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_CI_CHANGE);
        startEntity.setCustomerId(incident.getCustomer_id());
        startEntity.setCustomerName(incident.getCustomer_name());
        startEntity.setFlowName(incident.getFlow_name());
        startEntity.setOrderCode(incident.getOrder_code());
        startEntity.setUserId(incident.getCreate_user_id());
        startEntity.setUserName(incident.getCreate_user_name());
        startEntity.setWfNote(incident.getDescrip());
        startEntity.setProjectId(incident.getProject_id());
        startEntity.setProjectName(incident.getProject_name());
        startEntity.setSubCustomerId(incident.getSub_customer_id());
        startEntity.setSubCustomerName(incident.getSub_customer_name());
 
        //客户加盟商信息
        SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO().setId(incident.getCustomer_id()).queryForBean();
 
        //获取关联设备
        /*String sql = "select CI_ID,CI_NAME from SC_WORKFLOW_INCIDENT_LOCAL_CI where BUSINESS_ID=:business_id ";
 
        SqlParameter param = new SqlParameter();
        param.addValue("business_id", businessId);
 
        List<Map> ciList = baseDao.queryForList(sql, param);
 
        startEntity.setCiList(ciList);  */
 
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, new HashMap());
 
        //反写健康检查申请表中流程编号
        if (work_base != null) {
            incident.setFlow_id(work_base.getId())
                    .update();
        }
        return work_base;
    }
    
    @Override
    public WORKFLOW_BASE startReleaseWorkflow(String businessId,String note) {
        //获取新增申请信息
        SC_WORKFLOW_RELEASE release = new SC_WORKFLOW_RELEASE().setId(businessId).getInstanceById();
        if (release == null) {
            return null;
        }
        
        //启动新增流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_RELEASE);
        startEntity.setCustomerId(release.getCustomer_id());
        startEntity.setCustomerName(release.getCustomer_name());
        //startEntity.setFlowName("发布管理-"+release.getOrder_code());
        startEntity.setFlowName(release.getName());
        startEntity.setOrderCode(release.getOrder_code());
        startEntity.setUserId(release.getRelease_user_id());
        startEntity.setUserName(release.getRelease_user_name());
        startEntity.setProjectId(release.getProject_id());
        startEntity.setProjectName(release.getProject_name());
        startEntity.setSubCustomerId(release.getSub_customer_id());
        startEntity.setSubCustomerName(release.getSub_customer_name());
        startEntity.setNote(note);
        //客户加盟商信息
        SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO().setId(release.getCustomer_id()).queryForBean();
        /*if (customer != null) {
            startEntity.setPartnerId(customer.getPartner_id());
            startEntity.setPartnerName(customer.getPartner_name());
        }*/
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, new HashMap());
        
        //反写新增申请表中流程编号
        if (work_base != null) {
            release.setFlow_id(work_base.getId())
            .update();
        }
        
        return work_base;
    }
    
    @Override
    public WORKFLOW_BASE startCIAddWorkflow(String businessId) {
        //获取新增申请信息
        SC_WORKFLOW_CI_ADD add = new SC_WORKFLOW_CI_ADD().setId(businessId).getInstanceById();
        if (add == null) {
            return null;
        }
        
        //启动新增流程
        WorkflowStartEntity startEntity = new WorkflowStartEntity();
        startEntity.setBusinessId(businessId);
        startEntity.setBusinessType(Constants.WORKFLOW_BASE_BUSINESS_TYPE_CI_ADD);
        startEntity.setCustomerId(add.getCustomer_id());
        startEntity.setCustomerName(add.getCustomer_name());
        startEntity.setFlowName(add.getFlow_name());
        startEntity.setOrderCode(add.getOrder_code());
        startEntity.setUserId(add.getApply_user_id());
        startEntity.setUserName(add.getApply_user_name());
        startEntity.setNote(add.getApply_reason());
        
        /*//客户加盟商信息
        SC_PARTNER_CUSTOMER_INFO customer = new SC_PARTNER_CUSTOMER_INFO().setId(add.getCustomer_id()).queryForBean();
        if (customer != null) {
            startEntity.setPartnerId(customer.getPartner_id());
            startEntity.setPartnerName(customer.getPartner_name());
        }*/
        
        WORKFLOW_BASE work_base = workflowCoreService.startWorkflow(startEntity, new HashMap());
        
        //反写新增申请表中流程编号
        if (work_base != null) {
            add.setFlow_id(work_base.getId())
            .update();
        }
        
        return work_base;
    }
 
}