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
package com.vci.frameworkcore.compatibility.impl;
 
import com.vci.client.common.excel.ExcelDocumentUtils;
import com.vci.common.exception.VciException;
import com.vci.common.locale.LocaleDisplay;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.FuncOperationInfo;
import com.vci.corba.framework.data.FunctionInfo;
import com.vci.corba.framework.data.OperateInfo;
import com.vci.frameworkcore.compatibility.SmHMSysModConfigServiceI;
import com.vci.pagemodel.MenuVO;
import com.vci.client.common.excel.SheetDataSet;
import com.vci.starter.poi.bo.WriteExcelData;
import com.vci.starter.poi.bo.WriteExcelOption;
import com.vci.starter.poi.util.ExcelUtil;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.WebThreadLocalUtil;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
 
/**
 * 首页系统模块配置添加按钮、添加操作类型等接口服务
 * @author ludc
 * @date 2024/8/19 12:42
 */
@Service
public class SmHMSysModConfigServiceImpl implements SmHMSysModConfigServiceI {
 
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    private List<FunctionInfo> fileFunctionDatas = new ArrayList<FunctionInfo>();
 
    private int count = 0;
 
    private static FunctionOperateDelegate foDelegate;
 
    {
        if(Func.isEmpty(foDelegate)){
            foDelegate = new FunctionOperateDelegate();
        }
    }
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 添加模块
     * @param menuVO
     * @return
     */
    @Override
    public MenuVO addModule(MenuVO menuVO) throws VciBaseException {
        VciBaseUtil.alertNotNull(menuVO,"新增的模块对象");
        try {
            //往数据库里插入新建模块数据
            String puid = foDelegate.saveModule(menuVO);
            /**
             * 返回值:1,表示模块名称重复
             *            2,表示模块标识重复
             *         3, 模板别名存在重复
             */
            if(puid.equals("1")){
                throw new VciBaseException("模块名称重复,请修改!");
            }else if(puid.equals("2")){
                throw new VciBaseException("模块标识重复,请修改!");
            }else if(puid.equals("3")) {
                throw new VciBaseException("模块别名重复,请修改!");
            }
            menuVO.setId(puid);
            return menuVO;
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
    }
 
    /**
     * 修改模块
     * @param menuVO
     * @return
     */
    @Override
    public MenuVO updateModule(MenuVO menuVO) throws VciBaseException {
        VciBaseUtil.alertNotNull(menuVO,"修改的模块对象");
        try {
            String res = "";
            //更新数据库
            res = foDelegate.updateMod(menuVO);
            /**
             * 返回:1表示模块名重复。
             *       2表示模块标识重复。
             *       3标示模块别名重复。
             */
            if(res.equals("1")){
                throw new VciBaseException("模块名称重复,请修改!");
            }else if(res.equals("2")){
                throw new VciBaseException("模块标识重复,请修改!");
            }else if(res.equals("3")) {
                throw new VciBaseException("模块别名重复,请修改!");
            }/* else if (res.equals("4")) {
                throw new VciBaseException("模块编号重复,请修改!");
            }*/
            return menuVO;
        } catch (VciBaseException e) {
            e.printStackTrace();
            String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
    }
 
    /**
     * 删除模块
     * @param menuVO
     * @return
     */
    @Override
    public boolean delModule(MenuVO menuVO) {
        VciBaseUtil.alertNotNull(menuVO,"添加操作类型的列表");
        String res = "";
        try {
            String puid = "";
            if("FunctionObject".equals(menuVO.getModeType())) {
                puid = menuVO.getId();
            }else if("modelManagmentNode".equals(menuVO.getId())) {
                puid = "modelManagmentNode";
            }else if("systemManagmentNode".equals(menuVO.getId())) {
                puid = "systemManagmentNode";
            }
            if(Func.isBlank(puid)){
                throw new VciBaseException("未找到要删除的模块!");
            }
            res = foDelegate.deleteModule(puid);
            /**
             * 返回值:1表示模块在权限模块已经有授权信息,无法删除
             */
            if(res.equals("1")){
               throw new VciBaseException("当前模块(或下级模块)已经存在授权信息,无法删除。");
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
    }
 
    /**
     * 增加操作类型
     * @return
     */
    @Override
    public boolean addOperationType(List<MenuVO> menuVOList) {
        VciBaseUtil.alertNotNull(menuVOList,"添加操作类型的列表");
        List<FuncOperationInfo> objs = new ArrayList<>();
        //将操作类型组装成需要存储的对象
        menuVOList.stream().forEach(menuVO -> {
            FuncOperationInfo info = new FuncOperationInfo();
            //info.id = menuVO.getId() == null ? "" : menuVO.getId();
            info.funcId = menuVO.getParentId() == null ? "" : menuVO.getParentId();
            info.operId = menuVO.getId() == null ? "" : menuVO.getId();
            info.operName = menuVO.getName() == null ? "" : menuVO.getName();
            //info.operIndentify = menuVO.getOperIndentify() == null ? "" : menuVO.getOperIndentify();
            info.operAlias = menuVO.getAlias() == null ? "" : menuVO.getAlias();
            info.operDesc = menuVO.getRemark() == null ? "" : menuVO.getRemark();
            info.number = -1;
            info.isValid = true;
            /*VCIBaseTreeNode node = (VCIBaseTreeNode)treePaths[i].getLastPathComponent();
            OperateObject operateObject = (OperateObject) node.getObj();
            obj.setFuncId(funcObj.getId());
            obj.setOperId(operateObject.getId());
            obj.setOperName(operateObject.getName());
            obj.setOperIndentify(operateObject.getIdentify());
            obj.setOperAlias(operateObject.getAlias());
            obj.setNumber(-1);
            obj.setIsValid(true);*/
            objs.add(info);
        });
 
        //执行保存
        boolean res = true;
        try {
            res = this.saveFuncOperation(objs.toArray(new FuncOperationInfo[objs.size()]));
        } catch (Exception e) {
            res = false;
            e.printStackTrace();
            String exceptionMessage = "增加操作类型失败,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
        return res;
    }
 
    /**
     * 删除非系统模块
     * @return
     */
    @Override
    public boolean delNonsysModule() {
        try {
            if(platformClientUtil.getFrameworkService().deleteModules("nonsys")){
                return true;
            }
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = "删除非系统模块失败,原因:"+VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
        return false;
    }
 
    /**
     * 删除业务模块
     * @return
     */
    @Override
    public boolean delBusinessModule() {
        try {
            if(platformClientUtil.getFrameworkService().deleteModules("business")){
                return true;
            }
        } catch (PLException e) {
            e.printStackTrace();
            String exceptionMessage = "删除业务模块失败,原因:"+VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            throw new VciBaseException(exceptionMessage);
        }
        return false;
    }
 
    /**
     * 导出sql
     * @return
     */
    @Override
    public File exportFunctionSql(HttpServletResponse response,String exportPath,boolean isFunction) throws PLException {
        String dir = Func.isBlank(exportPath) ?  LocalFileUtil.getDefaultTempFolder():exportPath;
        String[][] allDatas;
        int size;
        if(isFunction){
            size = (int)platformClientUtil.getFrameworkService().getAllModelManagementNum();
            allDatas = this.getAllDatas(size);
        }else{
            size = (int)platformClientUtil.getFrameworkService().getAllOperitionsNum();
            allDatas = this.getAllOperitions(size);
        }
        File file = expData(dir,isFunction, allDatas);
        return file;
    }
 
    /**
     * 导出
     * @return
     */
    @Override
    public String exportModule(HttpServletResponse response) throws IOException {
        String defaultTempFolder = LocalFileUtil.getDefaultTempFolder();
        //写excel
        String excelPath = defaultTempFolder + File.separator + "module.xls";
        final List<String> columns = new ArrayList<String>(Arrays.asList("PLNAME","PLRESOURCEC","PLSUFFIXC","PLRESOURCEB",
                "PLSUFFIXB","PLMODULENO","PLDESC","PLISVALID","PLIMAGE","PLMODULESEQUENCE","PLALIASNAME",
                "PLMODULENAME","PLRESOURCEDOTNET","PLRESOURCEMOBIL","级别","别名","PLNO","PLISVALID",
                "PLNAME","PLUNIQUEFLAG","PLDESC","PLALIAS","PLSEQUENCE"));// 设置表单列名
        //int count = transmitTreeObject.getCurrentTreeNode().getChildCount();
        new File(excelPath).createNewFile();
        //设置列
        List<WriteExcelData> excelDataList = new ArrayList<>(10000);
        //设置列头
        for (int index = 0; index < columns.size(); index++) {
            excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
        }
        //查询要导出的数据
        String[][] firstLevel = new String[3000][23];
        try {
            firstLevel = this.checkLevel();
        } catch (VciBaseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String[][] datas = new String[10000][columns.size()];
        for(int i=0;i<firstLevel.length;i++){
            datas[i] =firstLevel[i];
        }
        if(Func.isEmpty(datas)){
            excelDataList.add(new WriteExcelData(1,1, "导出的列表为空,请刷新后尝试重新导出!"));
        }else{
            for (int i = 0; i < firstLevel.length; i++) {
                int row = i + 1;
                excelDataList.add(new WriteExcelData(row,0, ""+datas[i][0]));
                excelDataList.add(new WriteExcelData(row,1, ""+datas[i][1]));
                excelDataList.add(new WriteExcelData(row,2, ""+datas[i][2]));
                excelDataList.add(new WriteExcelData(row,3, ""+datas[i][3]));
                excelDataList.add(new WriteExcelData(row,4, ""+datas[i][4]));
                excelDataList.add(new WriteExcelData(row,5, ""+datas[i][5]));
                excelDataList.add(new WriteExcelData(row,6, ""+datas[i][6]));
                excelDataList.add(new WriteExcelData(row,7, ""+datas[i][7]));
                excelDataList.add(new WriteExcelData(row,8, ""+datas[i][8]));
                excelDataList.add(new WriteExcelData(row,9, ""+datas[i][9]));
                excelDataList.add(new WriteExcelData(row,10,""+datas[i][10]));
                excelDataList.add(new WriteExcelData(row,11,""+datas[i][11]));
                excelDataList.add(new WriteExcelData(row,12,""+datas[i][12]));
                excelDataList.add(new WriteExcelData(row,13,""+datas[i][13]));
                excelDataList.add(new WriteExcelData(row,14,""+datas[i][14]));
                excelDataList.add(new WriteExcelData(row,15,""+datas[i][15]));
                excelDataList.add(new WriteExcelData(row,16,""+datas[i][16]));
                excelDataList.add(new WriteExcelData(row,17,""+datas[i][17]));
                excelDataList.add(new WriteExcelData(row,18,""+datas[i][18]));
                excelDataList.add(new WriteExcelData(row,19,""+datas[i][19]));
                excelDataList.add(new WriteExcelData(row,20,""+datas[i][20]));
                excelDataList.add(new WriteExcelData(row,21,""+datas[i][21]));
                excelDataList.add(new WriteExcelData(row,22,""+datas[i][22]));
            }
        }
        WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
        ExcelUtil.writeDataToFile(excelPath, excelOption);
        return excelPath;
    }
 
    /**
     * 导入
     * @param files
     * @return
     * @throws PLException
     */
    @Override
    public BaseResult importModule(LinkedList<File> files) throws PLException, IOException {
        logger.info("正在收集表单数据......");
        boolean isSuccess = collectionDatas(files);
        logger.info("正在导入表单人员信息......");
        logger.info("count==="+count);
        boolean resBoolean = false;
        if(isSuccess == false){
            resBoolean = importExcelData(count);
        }
        return resBoolean ? BaseResult.success("导入成功!"):BaseResult.fail("导入失败!");
    }
 
    /**
     * 管理功能模块、业务功能模块下的叶子节点—修改操作别名接口
     * @return
     */
    @Override
    public boolean updateAlias(MenuVO menuVO) throws VciException {
        String alias = menuVO.getAlias();
        if ("".equals(alias)){
            throw new VciBaseException("请填写操作别名!");
        }
        boolean isValid = menuVO.getIsValid();
        String id = menuVO.getId();
        return foDelegate.updateFuncOperation(id , alias, isValid);
    }
 
    @Override
    public List<Object> getSysConfTree() {
        return null;
    }
 
    @Override
    public boolean addSysConf() {
        return false;
    }
 
    @Override
    public boolean updateSysConf() {
        return false;
    }
 
    @Override
    public boolean delSysConf() {
        return false;
    }
 
    @Override
    public String exportSysConf(HttpServletResponse response) {
        return null;
    }
 
    /**
     * 收集表单信息。
     * @param files
     * @return
     * @throws PLException
     * @throws IOException
     */
    private boolean collectionDatas(LinkedList<File> files) throws PLException, IOException{
        boolean b=false;
        for (File f : files) {
            List<SheetDataSet> sheetDataSets = this.getFileList(f);
            if (sheetDataSets != null && !sheetDataSets.isEmpty()) {
                for (SheetDataSet sheet : sheetDataSets) {
                    // sheet不能为空并且必须有出表头外的一条数据
                    if (sheet != null && sheet.getDataSet() != null && sheet.getDataSet().size() > 1) {
                        List<String[]> dataSet = sheet.getDataSet();
                        String fParentId=""; //第一级的id(第二级的parentid)
                        boolean boo=true;
                        boolean first=false;
                        String[] pd=new String[100];
                        int jibie=2;
                        for (int i = 1; i < dataSet.size(); i++) {
                            //fileDatas = new ArrayList<FunctionObject>();
                            String[] oneData = dataSet.get(i);
                            String id = ObjectUtility.getNewObjectID36();
 
                            FunctionInfo funObj=new FunctionInfo();
                            boolean onebl=false;
                            boolean twobl=false;
                            boolean same=false;
                            String plName=oneData[0];
                            //TODO: 这里绝对会出问题,导出的第一层的级别都是0,都不会存在等于1的,所以平台这儿等于1应该是不对的
                            if(oneData[14].equals("0")) {
                                try {
                                    onebl = foDelegate.firstLevel(plName);
                                } catch (VciException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                //如果第一级重名
                                if(onebl == true) {//第一级重名后覆盖第一级
                                    fuzhi(funObj,oneData);
                                    try {
                                        fParentId = foDelegate.changeFirstLevel(funObj,plName);
                                        pd[2]=fParentId;
                                    } catch (VciException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                    funObj.id = fParentId;
                                    fileFunctionDatas.add(funObj);
                                    first=true;
 
 
                                } else {
                                    funObj.id = id;
                                    funObj.parentId = "modelManagmentNode";
                                    fuzhi(funObj,oneData);
                                    fileFunctionDatas.add(funObj);
                                    first=false;
                                }
 
                                b=false;
                            }
                            //#########################     合并     #########################
                            for(jibie=2;jibie<100;jibie++){
                                if(oneData[14].equals(String.valueOf(jibie))){
                                    if(first == true && boo == true){
                                        try {
                                            if(pd[jibie]==null){
                                                pd[jibie]="";
                                            }
                                            twobl=foDelegate.secondLevel(plName,pd[jibie]);
                                        } catch (VciException e) {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                        }
                                        if(twobl==true) {//重名后覆盖
                                            fuzhi(funObj,oneData);
                                            try {
                                                fParentId=foDelegate.changeSecondLevel(funObj,plName,pd[jibie]);
                                                pd[jibie+1]=fParentId;
                                            } catch (VciException e) {
                                                // TODO Auto-generated catch block
                                                e.printStackTrace();
                                            }
                                            //funObj.setId(fParentId);
                                            funObj.id = pd[jibie+1];
                                            fileFunctionDatas.add(funObj);
                                            boo = true;
 
                                        }
                                    } else {
                                        funObj.id = id;
                                        b = false;
                                    }
                                }
                            }
 
                            if(oneData[14].equals("-1")) {
                                importExcelData(count);
                                FuncOperationInfo foObj = new FuncOperationInfo();
                                int len=fileFunctionDatas.size();
                                //**************同一节点下不能有相同的操作类型********************
                                String dataOperName=oneData[18];
                                String plFuncOid=fileFunctionDatas.get(len-1).id;
                                try {
                                    same = foDelegate.selSameOper(dataOperName,plFuncOid);
                                } catch (VciBaseException e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                                //******************************************************
                                if(same == false) {
                                    foObj.id = id;
                                    foObj.funcId = fileFunctionDatas.get(len-1).id;
                                    try {
                                        OperateInfo operObj = foDelegate.fetchOperateTypeByName(oneData[18]);
                                        foObj.operId = operObj.id;
                                    } catch (VciException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                    foObj.number = Integer.parseInt(oneData[16]);
                                    foObj.operAlias = oneData[15];
                                    foObj.isValid = Integer.parseInt(oneData[17]) != 0;
                                    try {
                                        foDelegate.saveFuncOperation2(foObj);
                                    } catch (VciException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
 
                                } else {
                                    foObj.number = Integer.parseInt(oneData[16]);
                                    foObj.operAlias = oneData[15];
                                    foObj.isValid = Integer.parseInt(oneData[17]) != 0;
                                    try {
                                        foDelegate.updateOperation(foObj,dataOperName,plFuncOid);
                                    } catch (VciException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }
                                count=fileFunctionDatas.size();
                                b=true;
                            }
                        }
                    }
                }
            }
        }
        return b;
    }
 
    /**
     * 导入表单数据
     * @throws VciException
     */
    private boolean importExcelData(int count) throws PLException {
        boolean b=false;
        try {
            b=    foDelegate.importModules(fileFunctionDatas.toArray(new FunctionInfo[]{}),count);
        } catch (VciBaseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return b;
    }
 
    /**
     * 获取表单数据
     * @param f
     * @return
     * @throws IOException
     * @throws PLException
     * @autor caicong
     * @data 2014-3-11
     */
    private List<SheetDataSet> getFileList(File f) throws PLException, IOException {
        // 获取流
        BufferedInputStream fileInputStream = new BufferedInputStream(
                new FileInputStream(f));
        String name = f.getName();
        // 获取表list
        List<SheetDataSet> sheetDataSets = ExcelDocumentUtils
                .readExcelDocument(name, fileInputStream);
        return sheetDataSets;
    }
 
    /**
     * 查询"功能模块管理"整个树结构并导出
     * add by caill start
     * */
    private String[][] checkLevel() throws VciBaseException{
        String[][] res = new String[3000][23];
        try{
            res = platformClientUtil.getFrameworkService().checkLevel();
        }catch (PLException e) {
            e.printStackTrace();
            throw new VciBaseException(String.valueOf(e.code), e.messages);
        }
        return res;
    }
 
    /**
     * 将查询出的数据转换成sql并写入指定路径下
     * @param dir
     * @param plDatas
     * @return
     */
    private File expData(String dir,boolean isFunction/*是否是导出管理功能模块sql*/, String[][] plDatas){
        new File(dir).mkdir();
        File file = new File(dir + (isFunction ? "/plfuncoperation.sql":"/ploperation.sql"));
        try {
            FileWriter w = new FileWriter(file);
            BufferedWriter bw = new BufferedWriter(w);
            System.out.println("长度为:"+plDatas.length);
            for(int i=0;i<plDatas.length;i++){
                if(isFunction){
                    if(!plDatas[i][16].trim().equals("") && plDatas[i][16]!=null && !plDatas[i][16].equals("-1")){
                        bw.write("insert into plfunction values('"+plDatas[i][0]+"','"+plDatas[i][1]+"',"+"'"+plDatas[i][2]+"',"+"'"+plDatas[i][3]+"',"+"'"+plDatas[i][4]+"',"
                                +"'"+plDatas[i][5]+"',"+"'"+plDatas[i][6]+"',"+"'"+plDatas[i][7]+"',"+"'"+plDatas[i][8]+"',"+"'"+plDatas[i][9]+"',"+"'"+plDatas[i][10]+"',"+"'"+plDatas[i][11]+"',"
                                +"'"+plDatas[i][12]+"',"+"'"+plDatas[i][13]+"',"+"'"+plDatas[i][14]+"',"+"'"+plDatas[i][15]+"');");
                        bw.write("\r\n");
                    }
                    if(!plDatas[i][16].trim().equals("") && plDatas[i][16]!=null && plDatas[i][16].equals("-1")){
                        bw.write("insert into plfuncoperation values('"+plDatas[i][17]+"','"+plDatas[i][18]+"',"+"'"+plDatas[i][19]+"',"+"'"+plDatas[i][20]+"',"+"'"+plDatas[i][21]+"',"
                                +"'"+plDatas[i][22]+"');");
                        bw.write("\r\n");
                    }
                }else{
                    bw.write("insert into ploperation values('"+plDatas[i][0]+"','"+plDatas[i][1]+"',"+"'"+plDatas[i][2]+"',"+"'"+plDatas[i][3]+"',"+"'"+plDatas[i][4]+"',"
                            +"'"+plDatas[i][5]+"');");
                    bw.write("\r\n");
                }
            }
 
            bw.flush();
            bw.close();
            return file;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     * 保存模块下的操作
     * @param funcOperationObjs
     * @return
     * @throws VciException
     */
    public boolean saveFuncOperation(FuncOperationInfo[] funcOperationObjs) throws VciException {
        if(funcOperationObjs == null || funcOperationObjs.length < 0){
            return false;
        }
        boolean res = true;
        try{
            res = platformClientUtil.getFrameworkService().saveFuncOperation(funcOperationObjs, foDelegate.getUserEntityInfo());
        }catch (PLException e) {
            e.printStackTrace();
            throw new VciException(String.valueOf(e.code),e.messages);
        }
        return res;
    }
 
    /**
     * 查询"功能模块管理"整个树结构并导出sql
     * @return
     * @throws PLException
     */
    public String[][] getAllDatas(int size) throws PLException {
        String[][] res = new String[size][23];
        try{
            res = platformClientUtil.getFrameworkService().getAllDatas(size);
        }catch (PLException e) {
            e.printStackTrace();
            throw new PLException(String.valueOf(e.code), e.messages);
        }
        return res;
    }
 
    /**
     * 获得所有的操作类型并导出到.sql文件中
     * add by caill start 2015.12.11
     * */
    private String[][] getAllOperitions(int size) throws VciBaseException{
        String[][] res = new String[size][6];
        try{
            res = platformClientUtil.getFrameworkService().getAllOperitions(size);
        }catch (PLException e) {
            e.printStackTrace();
            throw new VciBaseException(String.valueOf(e.code), e.messages);
        }
        return res;
    }
 
    public void fuzhi(FunctionInfo functionInfo,String[] oneData){
        functionInfo.name = oneData[0];
        functionInfo.resourceC = oneData[1];
        functionInfo.suffixC = oneData[2];
        functionInfo.desc = oneData[6];
        functionInfo.resourceB = oneData[3];
        functionInfo.suffixB = oneData[4];
        functionInfo.seq = Integer.parseInt(oneData[9]);
        //funObj.setModuleNo(Integer.parseInt(oneData[5]));
        functionInfo.image = oneData[8];
        functionInfo.isValid = Integer.parseInt(oneData[7]) != 0;
        functionInfo.aliasName = oneData[10];
        functionInfo.resourceDotNet = oneData[12];
        functionInfo.resourceMobile = oneData[13];
    }
 
    /**
     * 包含保存模块方法等操作类
     */
    private class FunctionOperateDelegate {
 
        /**
         * 判断第一级数据有没有重名的
         * @param plName
         * @return
         * @throws VciException
         */
        public boolean firstLevel(String plName) throws VciException{
            try{
                return platformClientUtil.getFrameworkService().firstLevel(plName);
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciException(String.valueOf(e.code), e.messages);
            }
        }
 
        /**
         * 覆盖重名的第一级数据
         * add by caill
         * */
        public String changeFirstLevel(FunctionInfo functionInfo,String plName) throws VciException{
            String fParentId="";
            try {
                fParentId= platformClientUtil.getFrameworkService().changeFirstLevel(functionInfo, plName);
            } catch (PLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
 
            return fParentId;
        }
 
        /**
         * 判断第二级数据有没有重名的
         * add by caill
         * */
        public boolean secondLevel(String plName,String fParentId) throws VciException{
            try{
                return platformClientUtil.getFrameworkService().secondLevel(plName,fParentId);
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciException(String.valueOf(e.code), e.messages);
            }
        }
 
        /**
         * 覆盖重名的第二级数据
         * add by caill
         * */
        public String changeSecondLevel(FunctionInfo functionInfo,String plName,String fParentId) throws VciException{
            String sParentId="";
            try {
                sParentId= platformClientUtil.getFrameworkService().changeSecondLevel(functionInfo, plName,fParentId);
            } catch (PLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return sParentId;
        }
 
        /**
         * 保存模块
         * @param object
         * @return
         * @throws VciException
         */
        public String saveModule(MenuVO object) throws VciBaseException {
            String res = "";
            try{
                res = platformClientUtil.getFrameworkService().saveModule(this.check(object,"add"),this.getUserEntityInfo());
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciBaseException(String.valueOf(e.code), e.messages);
            }
            return res;
        }
 
        /**
         * 修改模块
         * @param object
         * @return
         * @throws VciException
         */
        public String updateMod(MenuVO object) throws VciBaseException {
            String res = "";
            try{
                res = platformClientUtil.getFrameworkService().updateModule(this.check(object,"update"),this.getUserEntityInfo());
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciBaseException(String.valueOf(e.code), e.messages);
            }
            return res;
        }
 
        /**
         * 删除模块
         * @param puid
         * @return
         * @throws VciException
         */
        public String deleteModule(String puid) throws VciBaseException{
            String res = "";
            try{
                res = platformClientUtil.getFrameworkService().deleteModule(puid,this.getUserEntityInfo());
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciBaseException(String.valueOf(e.code), e.messages);
            }
            return res;
        }
 
        /**
         * VO转DO对象
         * @return
         */
        public FunctionInfo menuVO2FunctionInfo(MenuVO object){
            FunctionInfo info = new FunctionInfo();
            info.id = object.getId() == null ? "" : object.getId();
            //info.layer = object.getLayer();
            info.name = object.getName() == null ? "" : object.getName();
            info.parentId = object.getParentId() == null ? "" : object.getParentId();
            info.resourceC = object.getPathC() == null ? "" : object.getPathC();
            //info.suffixC = object.getSuffixC() == null ? "" : object.getSuffixC();
            info.resourceB = object.getPath() == null ? "" : object.getPath();
            //info.suffixB = object.getSuffixB() == null ? "" : object.getSuffixB();
            info.desc = object.getRemark() == null ? "" : object.getRemark();
            info.seq = object.getSort();
            //info.moduleNo = object.getModuleNo();
            info.image = object.getSource() == null ? "" : object.getSource();
            info.isValid = object.getIsValid();
            info.aliasName = object.getAlias() == null ? "" : object.getAlias();
            info.resourceDotNet = object.getResourceDotNet() == null ? "" : object.getResourceDotNet();
            info.resourceMobile = object.getResourceMobile() == null ? "" : object.getResourceMobile();
            info.desc = object.getRemark();
            return info;
        }
 
        /**
         * <p>Description: 页面输入的校验</p>
         *
         *@author xf
         *@time 2012-5-15
         *@return FunctionObject
         * @return
         */
        private FunctionInfo check(MenuVO menuVO,String type) {
            FunctionInfo obj = new FunctionInfo();
 
            //获取表单输入的值
            String modelName = menuVO.getName();
            String csIdentity = menuVO.getPathC();
            String bsIdentity = menuVO.getPath();
            String aliasName = menuVO.getAlias();
            String resDotNet = menuVO.getResourceDotNet();
            String resMobile = menuVO.getResourceMobile();
 
            //int moduleNo = transferStringToNum(moduleNoTxt.getText());
            int sequence = menuVO.getSort();
            String description = menuVO.getRemark();
 
            if("".equals(modelName) || "null".equals(modelName) || modelName == null) {
                throw new VciBaseException("模块名不能为空!");
            }else if(modelName.length() > 128) {
                throw new VciBaseException("模块名长度不能超过128!");
            }else if(description.length() > 255) {
                throw new VciBaseException("描述长度不能超过255!");
            }else if(csIdentity != null && !"".equals(csIdentity) && csIdentity.length() > 255) {
                throw new VciBaseException("C/S标识长度不能超过255!");
            } else if(resDotNet != null && !"".equals(resDotNet) && resDotNet.length() > 255) {
                throw new VciBaseException(".NET标识长度不能超过255!");
            }else if(resMobile != null && !"".equals(resMobile) && resMobile.length() > 255) {
                throw new VciBaseException("Mobile标识长度不能超过255!");
            } else if (sequence < 0) {
                throw new VciBaseException("序号不能小于0!");
            }
            if(type.equals("add")){
                //给object对象赋值
                String parentId = "";
                if(menuVO.getModeType().equals("FunctionObject")) {
                    parentId = menuVO.getParentId();
                }else if("modelManagmentNode".equals(menuVO.getParentId())) {
                    parentId = "modelManagmentNode";
                }else if("systemManagmentNode".equals(menuVO.getParentId())) {
                    parentId = "systemManagmentNode";
                }
                obj.parentId = parentId;
            }else{
                obj.id = menuVO.getId();
                obj.parentId = menuVO.getParentId();
            }
            obj.name = modelName;
            obj.resourceC = csIdentity;
            obj.desc = description;
            obj.resourceB = bsIdentity;
            obj.suffixC = "";
            obj.suffixB = "";
            obj.seq = sequence;
            obj.image = menuVO.getSource();
            obj.isValid = menuVO.getValid();//1有效0无效
            obj.aliasName = aliasName;
            obj.resourceDotNet = resDotNet;
            obj.resourceMobile = resMobile;
            return obj;
        }
 
        /**
         * 获取UserEntityInfo对象
         * @return
         */
        public UserEntityInfo getUserEntityInfo(){
            SessionInfo sessionInfo = WebThreadLocalUtil.getCurrentUserSessionInfoInThread();
            UserEntityInfo userEntityInfo = new UserEntityInfo(sessionInfo.getUserId(), "");
            return userEntityInfo;
        }
 
        /**
         * 导入模块对象
         * add by caill
         * */
        public boolean importModules(FunctionInfo[] funObject,int count) throws VciBaseException{
            boolean b=false;
            int len = funObject.length;
            List<FunctionInfo> funInfoList = new ArrayList<FunctionInfo>();
            for(int i = count ; i<len ; i++){
                if(funObject[i].parentId!=null){
                    FunctionInfo funInfo = funObject[i];
                    funInfoList.add(funInfo);
                }
            }
            FunctionInfo[] funInfos = new FunctionInfo[funInfoList.size()];
            for(int j=0;j<funInfoList.size();j++){
                funInfos[j] = funInfoList.get(j);
            }
 
            try {
                b = platformClientUtil.getFrameworkService().importModules(funInfos,this.getUserEntityInfo());
            } catch (PLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
 
            return b;
        }
 
        /**
         * 查询同一模块中是否已经存在相同的操作类型
         * add by caill
         * */
        public boolean selSameOper(String dataOperName,String plFuncOid) throws VciBaseException{
            boolean same=false;
            try {
                same = platformClientUtil.getFrameworkService().selSameOper(dataOperName,plFuncOid);
            } catch (PLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return same;
        }
 
        public OperateInfo fetchOperateTypeByName(String name) throws VciException {
            try{
                OperateInfo info =  platformClientUtil.getFrameworkService().fetchOperateTypeByName(name);
                return info;
            }catch (PLException e) {
                e.printStackTrace();
                throw new VciBaseException(String.valueOf(e.code),e.messages);
            }
        }
 
        /**
         * 保存操作类型
         * add by caill
         * */
        public boolean saveFuncOperation2(FuncOperationInfo funcOperationInfo) throws VciException{
            try {
                platformClientUtil.getFrameworkService().saveFuncOperation2(funcOperationInfo,this.getUserEntityInfo());
            } catch (PLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return true;
        }
 
        /**
         * 覆盖操作类型
         * add by caill
         * */
        public String updateOperation(FuncOperationInfo funcOperationInfo,String dataOperName,String plFuncOid) throws VciException{
            try {
                platformClientUtil.getFrameworkService().updateOperation(funcOperationInfo,this.getUserEntityInfo(),dataOperName,plFuncOid);
            } catch (PLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
 
        public boolean updateFuncOperation(String id , String alias, boolean isSelected) throws VciException {
            boolean res = false;
            try{
                res = platformClientUtil.getFrameworkService().updateFuncOperation(id, alias, isSelected, this.getUserEntityInfo());
            }catch(PLException e){
                throw new VciException(String.valueOf(e.code), e.messages);
            }
            return res;
        }
 
    }
 
 
}