许鹏程
2023-07-03 ea158bfd765843dee1c088910124b2d247ce29df
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
package com.product.module.data.service;
 
 
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.product.common.collect.SetUtils;
import com.product.common.excel.EasyExcelUtil;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.Global;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.file.service.FileManagerService;
import com.product.module.data.config.CmnCode;
import com.product.module.data.config.CmnConst;
import com.product.module.data.service.idel.ISystemDataUpLoadService;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
 
@Service
public class SystemDataUpLoadService extends AbstractBaseService implements ISystemDataUpLoadService {
    @Autowired
    private BaseDao baseDao;
    @Autowired
    private FileManagerService fileManagerService;
    @Autowired
    private QueryFilterService queryFilterService;
 
    @Autowired
    private PermissionService permissionService;
 
    public List<Map<String, Object>> getPrompt() throws BaseException {
        StringBuilder sql = new StringBuilder();
        sql.append(" select prompt_name `value` ,prompt_name `label` ,'prompt' type FROM product_sys_prompt ");
        sql.append(" union all ");
        sql.append(" select concat('《',dict_name,'》') dict_name,dict_name,'dict' type FROM product_sys_dict where is_used=1 group by dict_name ");
        FieldSetEntity f = new FieldSetEntity();
        f.setTableName("x");
        f.setValue("desc", "高级参照,普通参照");
        DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{});
        List<Map<String, Object>> result = Lists.newArrayList();
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            List<Map<String, Object>> promptList = Lists.newArrayList();
            List<Map<String, Object>> dictList = Lists.newArrayList();
            Map<String, Object> item;
            for (int i = 0; i < dt.getRows(); i++) {
                String type = dt.getString(i, "type");
                String value = dt.getString(i, "value");
                String label = dt.getString(i, "label");
                item = Maps.newHashMap();
                item.put("value", value);
                item.put("label", label);
                if ("prompt".equals(type)) {
                    promptList.add(item);
                } else {
                    dictList.add(item);
                }
            }
            item = Maps.newHashMap();
            item.put("label", "高级参照");
            item.put("children", promptList);
            item.put("value", "~高级参照~");
            result.add(item);
            item = Maps.newHashMap();
            item.put("label", "普通参照");
            item.put("children", dictList);
            item.put("value", "~普通参照~");
            result.add(item);
        }
        return result;
    }
 
 
    /**
     * 模板上传
     *
     * @param rpe
     * @return
     */
    @Override
    @Transactional
    public JSONObject uploadTemplate(RequestParameterEntity rpe) {
        FieldSetEntity paramFse = rpe.getFormData();
        String sourceFileName = paramFse.getString(CmnConst.FIELD_TEMPLATE_INFO);
        if (StringUtils.isEmpty(sourceFileName) || !sourceFileName.endsWith(".xlsx")) {
            throw new BaseException(CmnCode.UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT.getValue(), CmnCode.UPLOAD_TEMPLATE_NOT_ALLOWED_FORMAT.getText());
        }
 
        FieldSetEntity fse = fileManagerService.uploadFile(rpe);
        JSONObject resultObj = new JSONObject();
        resultObj.put(CmnConst.FIELD_TEMPLATE_INFO, fse.getString(CmnConst.FIELD_TEMPLATE_INFO));
        return resultObj;
    }
 
    /**
     * 解析模板,获取Excel表头信息
     *
     * @param fse
     * @return
     */
    public JSONObject analysisTemplate(FieldSetEntity fse) {
        String attachmentUUID = fse.getString(CmnConst.FIELD_TEMPLATE_INFO);
        DataTableEntity modelDte = null;
 
        String modelUUID = fse.getUUID();
        boolean needAnalysisFlag = true;
        if (!StringUtils.isEmpty(modelUUID)) {
            FieldSetEntity preModelFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, modelUUID, true);
            String preAttachmentUUID = preModelFse.getString(CmnConst.FIELD_TEMPLATE_INFO);
            modelDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{preModelFse.getString(CmnConst.FIELD_UPLOAD_SIGN)}, null, null, Integer.MAX_VALUE, 1, true);
            if (preAttachmentUUID.equals(attachmentUUID)) {
                // 同样的文件,不需要重新解析
                needAnalysisFlag = false;
            }
        }
 
        FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, attachmentUUID, false);
        if (needAnalysisFlag) {
            // 需要重新解析
            String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL);
            String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE);
            String path = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName;
            File templateFile = new File(path);
            // 创建文件流操作对象
            try (InputStream inputStream = new FileInputStream(templateFile)) {
                Map<String, List<List<String>>> map = EasyExcelUtil.readExcelByStringFromInputStream(inputStream, null);
                DataTableEntity subDte;
                Map<String, FieldSetEntity> subMap;
                FieldSetEntity mainFse;
                FieldSetEntity subFse;
                List<List<String>> list;
                int index = 0;
                for (Map.Entry<String, List<List<String>>> entry : map.entrySet()) {
                    list = entry.getValue();
                    if (list.isEmpty()) {
                        continue;
                    }
                    subDte = new DataTableEntity();
                    mainFse = null;
                    for (String excelHeader : list.get(list.size() - 1)) {
                        if (StringUtils.isEmpty(excelHeader)) {
                            throw new BaseException(CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getValue(), CmnCode.UPLOAD_TEMPLATE_EXISTS_EMPTY_COL.getText());
                        }
                        subFse = null;
                        if (modelDte != null && modelDte.getRows() > index) {
                            mainFse = modelDte.getFieldSetEntity(index);
                            subMap = dte2Map(mainFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER);
                            if (subMap.containsKey(excelHeader)) {
                                // 原有的字段
                                subFse = subMap.get(excelHeader);
                            }
                        }
                        if (subFse == null) {
                            // 本身没有的字段
                            subFse = new FieldSetEntity();
                            subFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB);
                            subFse.setValue(CmnConst.FIELD_EXCEL_HEADER, excelHeader);
                        }
                        subDte.addFieldSetEntity(subFse);
                    }
                    if (mainFse == null) {
                        mainFse = new FieldSetEntity();
                        mainFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
                        if (modelDte == null) {
                            modelDte = new DataTableEntity();
                        }
                        modelDte.addFieldSetEntity(mainFse);
                    } else {
                        mainFse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB);
                    }
                    mainFse.setValue("start_row_index", list.size() - 1);
                    mainFse.addSubDataTable(subDte);
                    index++;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_INFO_FAIL.getText());
            }
        }
 
        JSONObject resultObj = new JSONObject();
        resultObj.put("sheet_info", BaseUtil.dataTableEntityToJson(modelDte));
        resultObj.put(CmnConst.FIELD_UPLOAD_SIGN, SpringMVCContextHolder.getCurrentUser().getClient_uuid() + "_" + attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE) + "_" + System.currentTimeMillis());
        return resultObj;
    }
 
    /**
     * 保存
     *
     * @param fse
     */
    @Override
    @Transactional
    public void saveTemplate(FieldSetEntity fse) {
        if (StringUtils.isEmpty(fse.getUUID())) {
            addTemplate(fse);
        } else {
            updateTemplate(fse);
        }
    }
 
    /**
     * 新增模板
     *
     * @param fse
     */
    private void addTemplate(FieldSetEntity fse) {
        SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
        String orgLevelUUID = curUser.getOrg_level_uuid();
        String clientUUID = curUser.getClient_uuid();
        String attachmentUUID = fse.getString(CmnConst.FIELD_TEMPLATE_INFO);
        FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, attachmentUUID, false);
        String uploadSign = clientUUID + "_" + attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE) + "_" + System.currentTimeMillis();
        int sheetOrder = 1;
        fse.setValue(CmnConst.FIELD_SHEET_ORDER, sheetOrder);
        fse.setValue(CmnConst.FIELD_UPLOAD_SIGN, uploadSign);
        // 保存数据导入模板信息
        DataTableEntity modelDte = fse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
        if (!BaseUtil.dataTableIsEmpty(modelDte)) {
            FieldSetEntity tempFse;
            for (int i = 0; i < modelDte.getRows(); i++) {
                tempFse = modelDte.getFieldSetEntity(i);
                tempFse.setValue(CmnConst.FIELD_UPLOAD_SIGN, uploadSign);
                tempFse.setValue(CmnConst.FIELD_SHEET_ORDER, ++sheetOrder);
                BaseUtil.addOrgLeveLUUID(tempFse, Collections.singletonList(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), orgLevelUUID, curUser);
                baseDao.saveFieldSetEntity(tempFse);
            }
            fse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
        }
        BaseUtil.addOrgLeveLUUID(fse, Collections.singletonList(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), orgLevelUUID, curUser);
        baseDao.saveFieldSetEntity(fse);
 
        String mvcUUID = fse.getString(CmnConst.FIELD_FUNCTION_UUID);
        String buttonTitle = fse.getString(CmnConst.FILED_BUTTON_TITLE);
        // todo 待测试,创建mvc相关内容
        dealMvcInfo(mvcUUID, buttonTitle, uploadSign);
    }
 
    /**
     * 处理mvc中导入配置信息
     *
     * @param mvcUUID
     * @param buttonTitle
     */
    private void dealMvcInfo(String mvcUUID, String buttonTitle, String uploadSign) {
        FieldSetEntity firstPageFse = getFirstPageFse(mvcUUID);
        if (firstPageFse == null) {
            throw new BaseException(CmnCode.GET_MVC_FIRST_PAGE_INFO_FAIL.getValue(), CmnCode.GET_MVC_FIRST_PAGE_INFO_FAIL.getText());
        }
        FieldSetEntity preImportButtonFse = getImportButtonFse(firstPageFse, mvcUUID);
 
        SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
        if (preImportButtonFse == null) {
            // 本身没有导入按钮,自动创建 todo
 
            // 按钮
            FieldSetEntity importButtonFse = new FieldSetEntity();
            importButtonFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_BUTTONS);
            importButtonFse.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
            importButtonFse.setValue(CmnConst.FILED_BUTTON_NAME, "default_import");
            importButtonFse.setValue(CmnConst.FILED_BUTTON_TITLE, buttonTitle);
            importButtonFse.setValue(CmnConst.FILED_STATUS_UUID, 1);
            importButtonFse.setValue(CmnConst.FILED_CATEGORY_UUID, "import");
            importButtonFse.setValue(CmnConst.FILED_CLIENT_TYPE_UUID, "Web");
            importButtonFse.setValue(CmnConst.FILED_ROUTE_NAME, BaseUtil.getPageCode());
            importButtonFse.setValue("params", "{\"upload_sign\":\"" + uploadSign + "\"}");
            importButtonFse.setValue("button_category_uuid", "import");
            importButtonFse.setValue("button_type", 2);
            importButtonFse.setValue("is_main", 0);
            BaseUtil.createCreatorAndCreationTime(curUser, importButtonFse);
            baseDao.saveFieldSetEntity(importButtonFse);
 
//            // 页面
//            FieldSetEntity importPageFse = new FieldSetEntity();
//            importPageFse.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_PAGE);
//            importPageFse.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
//            importPageFse.setValue(CmnConst.FIELD_PAGE_NAME, "默认导入页面");
//            importPageFse.setValue(CmnConst.FIELD_PAGE_TYPE, 2);
//            importPageFse.setValue(CmnConst.FIELD_PAGE_TYPE, 2);
//            BaseUtil.createCreatorAndCreationTime(curUser, importPageFse);
//            baseDao.saveFieldSetEntity(importPageFse);
 
            // 连线-列表界面-导入按钮
            FieldSetEntity importLinkFse1 = new FieldSetEntity();
            importLinkFse1.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK);
            importLinkFse1.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
            importLinkFse1.setValue(CmnConst.FIELD_LINK_TYPE, 0);
            importLinkFse1.setValue(CmnConst.FIELD_LINE_FROM, firstPageFse.getUUID());
            importLinkFse1.setValue(CmnConst.FIELD_FROM_TYPE, 2);
            importLinkFse1.setValue(CmnConst.FIELD_LINE_TO, importButtonFse.getUUID());
            importLinkFse1.setValue(CmnConst.FIELD_TO_TYPE, 1);
            BaseUtil.createCreatorAndCreationTime(curUser, importLinkFse1);
            baseDao.saveFieldSetEntity(importLinkFse1);
//            // 连线-导入按钮-导入页面
//            FieldSetEntity importLinkFse2 = new FieldSetEntity();
//            importLinkFse2.setTableName(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK);
//            importLinkFse2.setValue(CmnConst.FILED_FUNCTION_UUID, mvcUUID);
//            importLinkFse2.setValue(CmnConst.FIELD_LINK_TYPE, 0);
//            importLinkFse2.setValue(CmnConst.FIELD_LINE_FROM, importButtonFse.getUUID());
//            importLinkFse2.setValue(CmnConst.FIELD_FROM_TYPE, 1);
//            importLinkFse2.setValue(CmnConst.FIELD_LINE_TO, importPageFse.getUUID());
//            importLinkFse2.setValue(CmnConst.FIELD_TO_TYPE, 2);
//            BaseUtil.createCreatorAndCreationTime(curUser, importLinkFse2);
//            baseDao.saveFieldSetEntity(importLinkFse2);
        } else {
            // 本身存在导入按钮,直接替换相应的数据 todo
            preImportButtonFse.setValue("", "");
            BaseUtil.updatedRegeneratorAndUpdateTime(curUser, preImportButtonFse);
            baseDao.saveFieldSetEntity(preImportButtonFse);
        }
    }
 
    /**
     * 提取指定mvc中【入口】后第一个页面
     *
     * @param mvcUUID
     * @return
     */
    private FieldSetEntity getFirstPageFse(String mvcUUID) {
        StringBuilder sql = new StringBuilder(256);
        sql.append("select p.* from (")
                .append("\n    select * FROM product_sys_function_buttons where is_main=1 and function_uuid=?")
                .append("\n) b")
                .append("\ninner join product_sys_link l on b.uuid=l.line_from")
                .append("\ninner join product_sys_mvc_page p on l.line_to=p.uuid");
        FieldSetEntity firstPageFse = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{mvcUUID}, false);
        return firstPageFse;
    }
 
    /**
     * 入口后第一个页面之后的导入
     *
     * @param firstPageFse
     * @param mvcUUID
     * @return
     */
    private FieldSetEntity getImportButtonFse(FieldSetEntity firstPageFse, String mvcUUID) {
        StringBuilder sql = new StringBuilder(256);
        sql.append("select b.* from (")
                .append("\n    select * FROM product_sys_mvc_page where uuid=?")
                .append("\n) p")
                .append("\ninner join product_sys_link l on p.uuid=l.line_to")
                .append("\ninner join (")
                .append("\n    select * FROM product_sys_function_buttons where function_uuid=? and button_category_uuid='import'")
                .append("\n) b on l.line_from=b.uuid");
        FieldSetEntity preImportButtonFse = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{firstPageFse.getUUID(), mvcUUID}, false);
        return preImportButtonFse;
    }
 
    /**
     * 修改模板
     *
     * @param fse
     */
    private void updateTemplate(FieldSetEntity fse) {
        SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
 
        // 保存数据导入模板信息
        DataTableEntity modelDte = fse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
        if (!BaseUtil.dataTableIsEmpty(modelDte)) {
            FieldSetEntity tempFse;
            for (int i = 0; i < modelDte.getRows(); i++) {
                tempFse = modelDte.getFieldSetEntity(i);
                BaseUtil.updatedRegeneratorAndUpdateTime(curUser, tempFse);
                baseDao.saveFieldSetEntity(tempFse);
            }
        }
        fse.removeSubData(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
        BaseUtil.updatedRegeneratorAndUpdateTime(curUser, fse);
        baseDao.saveFieldSetEntity(fse);
    }
 
    /**
     * 查询模板配置详情
     *
     * @param fse
     * @return
     */
    public FieldSetEntity findTemplate(FieldSetEntity fse) {
        String uploadSign = fse.getString(CmnConst.FIELD_UPLOAD_SIGN);
        DataTableEntity dt = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{uploadSign}, null, "sheet_order", Integer.MAX_VALUE, 1, true);
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            FieldSetEntity fs = new FieldSetEntity();
            fs.setTableName(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL);
            DataTableEntity sub = new DataTableEntity();
            for (int i = 0; i < dt.getRows(); i++) {
                if (i == 0) {
                    fs.setValue(CmnConst.FIELD_TITLE, dt.getString(0, CmnConst.FIELD_TITLE));
                    fs.setValue(CmnConst.FIELD_FUNCTION_UUID, dt.getString(0, CmnConst.FIELD_FUNCTION_UUID));
                    fs.setValue(CmnConst.FILED_BUTTON_TITLE, dt.getString(0, CmnConst.FILED_BUTTON_TITLE));
                    fs.setValue(CmnConst.UUID, dt.getString(0, CmnConst.UUID));
                    fs.setValue(CmnConst.FIELD_UPLOAD_SIGN, dt.getString(0, CmnConst.FIELD_UPLOAD_SIGN));
                    fs.setValue(CmnConst.FIELD_TEMPLATE_INFO, dt.getString(0, CmnConst.FIELD_TEMPLATE_INFO));
                }
                String before_func = dt.getString(i, CmnConst.FIELD_BEFORE_FUNC);
                String after_func = dt.getString(i, CmnConst.FIELD_AFTER_FUNC);
                String table_name = dt.getString(i, CmnConst.TABLE_NAME);
                String startRowIndex = dt.getString(i, "start_row_index");
                FieldSetEntity f = new FieldSetEntity();
                f.setTableName("sheet_info");
                f.setValue(CmnConst.FIELD_BEFORE_FUNC, before_func);
                f.setValue(CmnConst.FIELD_AFTER_FUNC, after_func);
                f.setValue(CmnConst.UUID, dt.getString(i, CmnConst.UUID));
                f.setValue(CmnConst.TABLE_NAME, table_name);
                f.setValue("start_row_index", startRowIndex);
                f.setSubData(dt.getFieldSetEntity(i).getSubData());
                sub.addFieldSetEntity(f);
            }
            fs.addSubDataTable(sub);
            return fs;
        }
        return null;
    }
 
    /**
     * 模板台账-左边树结构
     *
     * @param fse
     * @return
     */
    public DataTableEntity listTemplate(FieldSetEntity fse) {
        int pageSize = fse.getInteger(CmnConst.PAGESIZE) == null ? Integer.MAX_VALUE : fse.getInteger(CmnConst.PAGESIZE);
        int curPage = fse.getInteger(CmnConst.CPAGE) == null ? 1 : fse.getInteger(CmnConst.CPAGE);
        SystemUser user = SpringMVCContextHolder.getCurrentUser();
        StringBuilder filter = new StringBuilder(128);
        filter.append("org_level_uuid=? and length(title)>0");
        String queryFilter = queryFilterService.getQueryFilter(fse);
        if (!StringUtils.isEmpty(queryFilter)) {
            filter.append(" and ").append(queryFilter);
        }
        List<Object> paramList = Lists.newArrayList();
        paramList.add(user.getOrg_level_uuid());
        String[] filterParamArr = !StringUtils.isEmpty(fse.getString("~select_params~")) ? fse.getString("~select_params~").split(",") : null;
        if (filterParamArr != null) {
            Collections.addAll(paramList, filterParamArr);
        }
        return baseDao.listTable(fse.getTableName(), filter.toString(), paramList.toArray(), null, fse.getString(""), pageSize, curPage);
    }
 
    /**
     * 数据上传模板删除
     *
     * @param fse
     * @throws BaseException
     */
    @Override
    @Transactional
    public void deleteModel(FieldSetEntity fse) throws BaseException {
        String uploadSign = fse.getString(CmnConst.FIELD_UPLOAD_SIGN);
        DataTableEntity modelDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{uploadSign});
        if (BaseUtil.dataTableIsEmpty(modelDte)) {
            throw new BaseException(CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_DELETE_FAIL.getText());
        }
        FieldSetEntity mainModelFse = null;
        FieldSetEntity tempFse;
        List<String> uuidParamList = Lists.newArrayList();
        for (int i = 0; i < modelDte.getRows(); i++) {
            tempFse = modelDte.getFieldSetEntity(i);
            uuidParamList.add(tempFse.getUUID());
            if (!StringUtils.isEmpty(tempFse.getString(CmnConst.FIELD_FUNCTION_UUID))) {
                mainModelFse = tempFse;
            }
        }
        if (mainModelFse == null) {
            throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_MAIN_INFO_FAIL.getText());
        }
 
        // 删除mvc相关的表信息
        String mvcUUID = mainModelFse.getString(CmnConst.FIELD_FUNCTION_UUID);
        FieldSetEntity firstPageFse = getFirstPageFse(mvcUUID);
        // 导入按钮
        FieldSetEntity importButtonFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_BUTTONS, "function_uuid=? and button_name='default_import'", new Object[]{mvcUUID}, false);
        if (importButtonFse != null) {
            // 连线-导入按钮-导入页面
//            FieldSetEntity secondLinkFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=1 and line_from=?", new Object[]{mvcUUID, importButtonFse.getUUID()}, false);
            // 删除-导入页面
//            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_PAGE, new Object[]{secondLinkFse.getString(CmnConst.FIELD_LINE_TO)});
            // 删除-连线-导入按钮-导入页面
//            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=1 and line_from=?", new Object[]{mvcUUID, importButtonFse.getUUID()});
            // 删除-连线-列表界面-导入按钮
            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_MVC_LINK, "function_uuid=? and link_type=0 and from_type=2 and to_type=1 and line_from=? and line_to=?", new Object[]{mvcUUID, firstPageFse.getUUID(), importButtonFse.getUUID()});
            // 删除-导入按钮
            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_BUTTONS, new Object[]{importButtonFse.getUUID()});
 
        }
        // 删除附件
        FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, mainModelFse.getString(CmnConst.FIELD_TEMPLATE_INFO), false);
        if (attachmentFse != null) {
            String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL);
            String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE);
            String path = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName;
            File templateFile = new File(path);
            templateFile.delete();
            // 删除附件表
            baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, new Object[]{attachmentFse.getUUID()});
        }
        // 删除模板子表
        String filter = BaseUtil.buildQuestionMarkFilter(CmnConst.FIELD_MODEL_UUID, uuidParamList.size(), true);
        baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB, filter, uuidParamList.toArray());
        // 删除模板主表
        baseDao.delete(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, uuidParamList.toArray());
    }
 
    /**
     * 模板下载
     *
     * @param fse
     * @param response
     * @throws IOException
     */
    public void downloadTemplate(FieldSetEntity fse, HttpServletResponse response) throws IOException {
        String upload_sign = fse.getString("upload_sign");
        FieldSetEntity templateFse = baseDao.getFieldSetEntityByFilter(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=? AND length(title)>0", new Object[]{upload_sign}, false);
        String attachmentUUID = templateFse.getString(CmnConst.FIELD_TEMPLATE_INFO);
        fse.setValue(CmnConst.UUID, attachmentUUID);
        fileManagerService.getFileContent(fse, response);
    }
 
    /**
     * 业务功能导入-上传文件
     *
     * @param rpe
     * @return
     */
    @Override
    @Transactional
    public String recordDataImport(RequestParameterEntity rpe) {
        FieldSetEntity ff = fileManagerService.uploadFile(rpe);
        FieldSetEntity fse = rpe.getFormData();
        fse.setValue(CmnConst.FIELD_IS_SUCCESS, 0);
        SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
        fse.setValue(CmnConst.FIELD_ORG_LEVEL_UUID, curUser.getOrg_level_uuid());
        BaseUtil.createCreatorAndCreationTime(curUser, fse);
        fse.setValue("import_info", ff.getString("import_info"));
        baseDao.saveFieldSetEntity(fse);
        return fse.getUUID();
    }
 
    /**
     * 业务功能导入-解析并保存到数据库
     *
     * @param fse
     * @return
     */
    @Override
    @Transactional
    public void recordDataSave(FieldSetEntity fse) {
        SystemUser curUser = SpringMVCContextHolder.getCurrentUser();
 
        FieldSetEntity logFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_RECORD, fse.getUUID(), false);
        if (logFse == null) {
            throw new BaseException(CmnCode.UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_GET_UPLOAD_RECORD_FAIL.getText());
        }
 
        // 获取模板信息
        DataTableEntity templateDte = baseDao.listTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL, "upload_sign=?", new Object[]{logFse.getString(CmnConst.FIELD_UPLOAD_SIGN)}, null, "sheet_order", Integer.MAX_VALUE, 1, true);
 
        // 获取导入文件信息
        FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.TABLE_PRODUCT_SYS_ATTACHMENT, logFse.getString(CmnConst.FIELD_IMPORT_INFO), false);
        String relativePath = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_URL);
        String templateName = attachmentFse.getString(CmnConst.FIELD_ATTACHMENT_TITLE);
        Map<String, List<List<String>>> dataMap = new HashMap<>();
        try {
            String filePath = Global.getSystemConfig("local.dir", "") + File.separator + relativePath + File.separator + templateName;
            dataMap = EasyExcelUtil.readExcelByString(filePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 封装到dte中
        List<DataTableEntity> beforeSaveDataList = Lists.newArrayList();
        List<String> titleList;
        List<List<String>> dataList;
        List<String> rowList;
        String singleValue;// 单元格内的值
        int index = 0;
        FieldSetEntity curTemplateFse;
        Map<String, FieldSetEntity> curSubMap;
        List<List<List<String>>> headerDataList = Lists.newArrayList();
        List<Map<String, FieldSetEntity>> fieldInfoList = Lists.newArrayList();
        FieldSetEntity curFieldFse;
        FieldSetEntity recordFse;// 业务表fse
        DataTableEntity recordDte;// 业务表dte
        for (Map.Entry<String, List<List<String>>> entry : dataMap.entrySet()) {
            dataList = entry.getValue();
            if (dataList.isEmpty()) {
                continue;
            }
 
            recordDte = new DataTableEntity();
            curTemplateFse = templateDte.getFieldSetEntity(index);
            curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_EXCEL_HEADER);
            fieldInfoList.add(curSubMap);
            // 字段对应的excel 表头索引
            Map<String, String> fieldIndex = Maps.newHashMap();
            //表头开始行 cheng update 2023年6月30日15:48:22 多行头时,表头开始行不一定是第一行
            int startRowIndex = 1;
            if (!StringUtils.isEmpty(curTemplateFse.getString("start_row_index")) && NumberUtil.isNumber(curTemplateFse.getString("start_row_index"))) {
                startRowIndex = Integer.parseInt(curTemplateFse.getString("start_row_index")) + 1;
                if (startRowIndex < 1) {
                    startRowIndex = 1;
                }
            }
 
            titleList = dataList.get(startRowIndex);
            if (startRowIndex > 0) {
                headerDataList.add(dataList.subList(0, startRowIndex));
            } else {
                headerDataList.add(new ArrayList<>());
            }
            for (int i = startRowIndex; i < dataList.size(); i++) {
                rowList = dataList.get(i);
                recordFse = new FieldSetEntity();
                recordFse.setTableName(curTemplateFse.getString(CmnConst.FIELD_TABLE_NAME));
                //字段对应的列
                int j = 0;
                for (; j < titleList.size(); j++) {
                    if (rowList.size() < (j + 1)) {
                        singleValue = null;
                    } else {
                        singleValue = rowList.get(j);
                    }
                    curFieldFse = curSubMap.get(titleList.get(j));
                    recordFse.setValue(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), singleValue);
                    if (i == 1 || rowList.size() > fieldIndex.size()) {
                        fieldIndex.put(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), String.valueOf(j));
                    }
                }
                recordFse.setValue("~colName~", titleList);
                recordFse.setValue("~fieldIndex~", fieldIndex);
                // fieldSet 对应的行
                recordFse.setValue("~row~", i);
                recordDte.addFieldSetEntity(recordFse);
            }
            beforeSaveDataList.add(recordDte);
            index++;
        }
 
        // 数据解析保存
        String orgLevelUUID = curUser.getOrg_level_uuid();
        String actualValue;
        FieldMetaEntity meta;
        Object[] fieldArr;
        DataTableEntity tempDte;
        String fieldName;
        for (int i = 0; i < beforeSaveDataList.size(); i++) {
            tempDte = beforeSaveDataList.get(i);
 
            // 保存前处理
            try {
                tempDte = spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_BEFORE_FUNC), tempDte, headerDataList.get(i));
                if (BaseUtil.dataTableIsEmpty(tempDte)) {
                    throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_NO_DATA.getText());
                }
            } catch (BaseException e) {
                throw e;
            } catch (Exception e) {
                e.printStackTrace();
                throw new BaseException(CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_BEFORE_FUNC_EXEC_FAIL.getText());
            }
 
            meta = tempDte.getMeta();
            fieldArr = meta.getFields();
 
            curTemplateFse = templateDte.getFieldSetEntity(i);
            curSubMap = dte2Map(curTemplateFse.getSubDataTable(CmnConst.TABLE_PRODUCT_SYS_DATA_UPLOAD_MODEL_SUB), CmnConst.FIELD_FIELD_NAME);
            boolean isMultiFlag;
            StringBuilder errorMsg = new StringBuilder(8);
            for (int j = 0; j < tempDte.getRows(); j++) {
                recordFse = tempDte.getFieldSetEntity(j);
                for (Object fieldNameObj : fieldArr) {
                    if (fieldNameObj == null) {
                        continue;
                    }
                    fieldName = fieldNameObj.toString();
                    singleValue = recordFse.getString(fieldName);
 
                    curFieldFse = curSubMap.get(fieldName);
                    if (curFieldFse != null) {
                        // 提取真实值
                        if (!StringUtils.isEmpty(curFieldFse.getString(CmnConst.FIELD_PROMPT_NAME))) {
                            isMultiFlag = curFieldFse.getString(CmnConst.FIELD_IS_MULTI) == null ? false : "1".equals(curFieldFse.getString(CmnConst.FIELD_IS_MULTI));
                            // 根据参照名称,参照类型,显示域的值,获取隐藏域的值
                            actualValue = getRealValue(curFieldFse.getString(CmnConst.FIELD_PROMPT_NAME), singleValue, isMultiFlag);
                        } else {
                            actualValue = singleValue;
                        }
                        recordFse.setValue(curFieldFse.getString(CmnConst.FIELD_FIELD_NAME), actualValue);
                    }
                }
                try {
                    BaseUtil.createCreatorAndCreationTime(curUser, recordFse);
                    baseDao.saveFieldSetEntity(recordFse);
                } catch (BaseException e) {
                    e.printStackTrace();
//                    errorMsg.append("导入数据错误:\n\t");
                    errorMsg.append(String.format("第%s个sheet,第%s行,%s", i + 1, j + 1, e.getMessageInfo() != null ? e.getMessageInfo() : "")).append("\n");
//                    throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), String.format("%s: 第%s个sheet,第%s行", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1), e);
                } catch (Exception e) {
                    errorMsg.append(String.format("第%s个sheet,第%s行,%s", i + 1, j + 1, e.getMessage() != null ? e.getMessage() : "")).append("\n");
//                    throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), String.format("%s: 第%s个sheet,第%s行", CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getText(), i + 1, j + 1));
                }
            }
            if (errorMsg.length() > 0) {
                throw new BaseException(CmnCode.UPLOAD_TEMPLATE_IMPORT_DATA_FAIL.getValue(), errorMsg.toString());
            }
 
            // 保存后处理
            try {
                spDeal(templateDte.getFieldSetEntity(i).getString(CmnConst.FIELD_AFTER_FUNC), tempDte, headerDataList.get(i));
            } catch (BaseException e) {
                SpringMVCContextHolder.getSystemLogger().error(e);
            } catch (Exception e) {
                throw new BaseException(CmnCode.UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL.getValue(), CmnCode.UPLOAD_TEMPLATE_AFTER_FUNC_EXEC_FAIL.getText());
            }
        }
 
        // 更新记录表情况
        logFse.setValue(CmnConst.FIELD_IS_SUCCESS, 1);
        BaseUtil.updatedRegeneratorAndUpdateTime(curUser, fse);
        baseDao.saveFieldSetEntity(logFse);
    }
 
    /**
     * dte按照指定fse中的值作为key转换为map
     *
     * @param dte
     * @param keyFieldName
     * @return
     */
    private Map<String, FieldSetEntity> dte2Map(DataTableEntity dte, String keyFieldName) {
        Map<String, FieldSetEntity> resultMap = Maps.newHashMap();
        FieldSetEntity tempFse;
        for (int i = 0; i < dte.getRows(); i++) {
            tempFse = dte.getFieldSetEntity(i);
            resultMap.put(tempFse.getString(keyFieldName), tempFse);
        }
        return resultMap;
    }
 
    /**
     * 事件前或者事件后调用逻辑方法的特殊处理
     *
     * @param functionContent
     * @param dte
     * @param headerDataList
     * @return
     */
    private DataTableEntity spDeal(String functionContent, DataTableEntity dte, List<List<String>> headerDataList) throws BaseException {
        if (functionContent == null) {
            return dte;
        }
        functionContent = functionContent.trim();
        if (StringUtils.isEmpty(functionContent)) {
            return dte;
        }
        String className = functionContent.substring(0, functionContent.indexOf("."));
        String methodName = functionContent.substring(functionContent.indexOf(".") + 1, functionContent.indexOf("("));
        //根据className获取类
        Object bean = SpringUtil.getBean(className);
        //使用huTool的反射工具类获取方法,方法的参数类型为DataTableEntity、List<List<String>>
        Method method = ReflectUtil.getMethod(bean.getClass(), methodName, DataTableEntity.class, List.class);
        if (method != null) {
            //判断method返回值为DataTableEntity
            boolean isBackDataTable = !method.getReturnType().equals(DataTableEntity.class);
            //判断第二个参数的泛型类型
            Type[] types = method.getGenericParameterTypes();
            Type type = types[1];
            //判断类型是否为List<List<String>>,如果是则调用方法
            if (isBackDataTable && type.getTypeName().equals("java.util.List<java.util.List<java.lang.String>>")) {
                return ReflectUtil.invoke(bean, methodName, dte, headerDataList);
            }
        }
 
        return ReflectUtil.invoke(bean, methodName, dte);
    }
 
    /**
     * 获取真实值
     *
     * @param promptName
     * @param showValue
     * @return
     */
    private String getRealValue(String promptName, String showValue, boolean isMultiFlag) {
        String realValue = showValue;
        DataTableEntity promptDte;
        FieldSetEntity promptFse;
        if (promptName.startsWith("《")) {
            // 普通参照
            promptName = promptName.replace("《", "").replace("》", "");
            promptDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_COMMON_PROMPT, new String[]{promptName});
            if (!BaseUtil.dataTableIsEmpty(promptDte)) {
                Set<String> showSet = SetUtils.string2Set(showValue, ",");
                Set<String> realSet = Sets.newLinkedHashSet();
                for (int i = 0; i < promptDte.getRows(); i++) {
                    promptFse = promptDte.getFieldSetEntity(i);
                    if (isMultiFlag) {
                        if (showSet.contains(promptFse.getString(CmnConst.FIELD_DICT_LABEL))) {
                            realSet.add(promptFse.getString(CmnConst.FIELD_DICT_VALUE));
                        }
                    } else {
                        if (showValue.equals(promptFse.getString(CmnConst.FIELD_DICT_LABEL))) {
                            realValue = promptFse.getString(CmnConst.FIELD_DICT_VALUE);
                            break;
                        }
                    }
                }
                if (!realSet.isEmpty()) {
                    realValue = SetUtils.set2String(realSet, ",");
                }
            }
        } else {
            // 高级参照
            promptFse = BaseUtil.getSingleInfoByCache(CmnConst.CACHE_ADVANCED_PROMPT, new String[]{promptName});
            String sourceTableName = promptFse.getString(CmnConst.FILED_SOURCE_TABLE);
            String filter = promptFse.getString(CmnConst.FILED_FILTER);
            String showFieldName = promptFse.getString(CmnConst.FILED_VIEW_FIELD);
            Set<String> showSet = SetUtils.string2Set(showValue, ",");
            String promptFilter = BaseUtil.buildQuestionMarkFilter(showFieldName, isMultiFlag ? showSet.size() : 1, true);
            StringBuilder sql = new StringBuilder(256);
            String realFieldName = promptFse.getString(CmnConst.FILED_VALUE_FIELD);
            sql.append("select GROUP_CONCAT(").append(realFieldName).append(") real_value from ").append(sourceTableName).append(" where ").append(promptFilter);
            if (!StringUtils.isEmpty(filter)) {
                filter = SystemParamReplace.systemParamsReplace(filter);
                sql.append(" and ").append(filter);
            }
            // 补充特定字段数据过滤
            if (!StringUtils.isEmpty(promptFse.getString("org_filter_field")) || !StringUtils.isEmpty(promptFse.getString("user_filter_field"))) {
                String dataFilter = permissionService.getDataFilter(sourceTableName,
                        promptFse.getString("user_filter_field"), promptFse.getString("org_filter_field"));
                if (!StringUtils.isEmpty(dataFilter)) {
                    sql.append(" and ").append(dataFilter);
                }
            }
            FieldSetEntity sourceFse = baseDao.getFieldSetEntityBySQL(sql.toString(), showSet.toArray(), false);
            if (sourceFse != null) {
                realValue = sourceFse.getString("real_value");
            }
        }
        return realValue;
    }
}