1821349743@qq.com
2023-02-20 059154a3b7d812b3bb4b89ecfa4d94f9b905f7e0
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
package com.product.server.report.service;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.product.admin.service.CodeService;
import com.product.common.collect.ListUtils;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
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.server.report.config.CmnConst;
import com.product.server.report.config.ReportCode;
import com.product.server.report.service.idel.IGenerateEChartService;
import com.product.util.BaseUtil;
import com.product.util.SystemParamReplace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.List;
 
/**
 * @author : lx
 * @Description: 图表Echart封装
 * @date :
 */
@Component
public class GenerateEChartService extends AbstractBaseService implements IGenerateEChartService{
 
    @Autowired
    public BaseDao baseDao;
    public BaseDao getBaseDao() {
        return baseDao;
    }
    public void setBaseDao(BaseDao baseDao) {
        this.baseDao = baseDao;
    }
 
    @Autowired
    CodeService codeService;
    @Autowired
    public DataListReportService dataListReportService;
    @Autowired
    QueryFilterService queryFilterService;
    @Override
    public JSONArray generatePieEChartMaster(FieldSetEntity fse) throws BaseException {
        String uuid = fse.getString(CmnConst.UUID);
        //查询报表配置表  .PRODUCT_SYS_report_config_attribute子表
        FieldSetEntity configField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, uuid,false);
        //查询画布表
        DataTableEntity chartsDataTable = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_CHARTS," report_config_uuid = ? ", new String[]{uuid});
        if(!BaseUtil.dataTableIsEmpty(chartsDataTable)) {
            JSONArray array = new JSONArray();
            for (int i = 0; i < chartsDataTable.getRows(); i++) {
                FieldSetEntity fieldSetEntity = chartsDataTable.getFieldSetEntity(i);
                array.add(this.generatePieEChart(fieldSetEntity));
            }
            return array;
        }else {
            throw new BaseException(ReportCode.GET_CHART_NULL_FAIL.getValue(), ReportCode.GET_CHART_NULL_FAIL.getText(), this.getClass(), "generatePieEChartMaster");
        }
    }
 
    /**
     *     单个图形报表
     *     通过配置表获取关联的属性表和属性值表,再递归拼接出上级属性返回至页面。
     * @param fse 配置图表
     * @return
     */
    @Override
    public JSONObject generatePieEChart(FieldSetEntity fse) throws BaseException {
 
        //数据源uuid
        String report_datasource_uuid = fse.getString(CmnConst.REPORT_DATASOURCE_UUID);
        //类型uuid
        String report_type_config_uuid = fse.getString(CmnConst.REPORT_TYPE_CONFIG_UUID);
        if(BaseUtil.strIsNull(report_datasource_uuid) || BaseUtil.strIsNull(report_type_config_uuid)){
            return BaseUtil.fieldSetEntityToJson(fse);
        }
        //查询类型表
        FieldSetEntity typeField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_CONFIG, report_type_config_uuid,false);
 
        //获取配置报表数据源data数据表 .PRODUCT_SYS_report_datasource_config子表
        FieldSetEntity datasourceField = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_DATASOURCE_CONFIG,report_datasource_uuid,true);
        //获取查询的数据sql
        String sql_text = datasourceField.getString(CmnConst.SQL_TEXT);
        //解析SQL里面的系统参数
        sql_text = SystemParamReplace.systemParamsReplace(sql_text);
        String type_group = typeField.getString(CmnConst.TYPE_GROUP);
 
        //为关系图
        if("relationCharts".equals(type_group)){
            JSONObject obj = this.chooseRelationship(sql_text);
            String typeGroup = typeField.getString(CmnConst.TYPE_GROUP);
            JSONObject object = new JSONObject();
            object.put(CmnConst.TYPE_GROUP,typeGroup);
            object.put(CmnConst.OPTION,obj);
//            object.put("function",this.functionArray(uuid));
            return object;
        }
        DataTableEntity valueData = baseDao.listTable(sql_text,new Object[]{});
        //获取报表配置属性表  加echarts配置属性
        //只能查询到关联属性值的属性表,如果父级属性下有多个相同子属性。通过grouping分组。
        DataTableEntity attributeData = baseDao.listTable("SELECT a.field_name,a.report_type_attr_value,a.uuid,a.grouping ,b.* FROM product_sys_report_config_attribute a LEFT JOIN product_sys_report_type_attribute b on a.report_type_attr = b.uuid WHERE a.report_config_uuid = ? ORDER BY a.grouping,b.parentAttributeUuid " ,new Object[]{fse.getString(CmnConst.UUID)});
        JSONObject allProperties = new JSONObject();
        if(attributeData.getRows() > 0){
            JSONObject propertyObject = new JSONObject();
            String parenUuid1 = attributeData.getString(0,"parentAttributeUuid");
            String grouping1 = attributeData.getString(0,"grouping");
            for (int i = 0,length = attributeData.getRows(); i < length; i++) {
                FieldSetEntity fieldSet = attributeData.getFieldSetEntity(i);
                //上级uuid
                String parenUuid2 = fieldSet.getString("parentAttributeUuid");
                //上级name
                String parenName = fieldSet.getString("parentAttributeName");
                //图表属性值
                String attr_value = fieldSet.getString("report_type_attr_value");
                //为空传默认值
                if(BaseUtil.strIsNull(attr_value)){
                    attr_value = fieldSet.getString("default_value");
                }
                //图表属
                String attribute_name = fieldSet.getString("attribute_name");
                //通过数据库插入数据
                String fieldName = fieldSet.getString(CmnConst.FIELD_NAME);
                //通过数据库插入数据
                String grouping2 = fieldSet.getString("grouping");
                //普通属性都有上级属性, 特殊的颜色风格属性无上级属性,本身就是顶级属性。
                if(!BaseUtil.strIsNull(parenUuid2)) {
                    //之前上级uuid为空
                    if(BaseUtil.strIsNull(parenUuid1)) {
                        parenUuid1 = parenUuid2;
                        //有不同的属性,先把之前同样的属性封装。
                    }else if (!BaseUtil.strIsNull(parenUuid1) && !parenUuid2.equals(parenUuid1)) {
                        //封装之前的json数据
                        this.getAllProperties(parenUuid1, propertyObject, allProperties);
                        parenUuid1 = parenUuid2;
                    } else if ((parenUuid2.equals(parenUuid1) && !BaseUtil.strIsNull(grouping2))) {
                        if (!grouping2.equals(grouping1)) {
                            this.getAllProperties(parenUuid1, propertyObject, allProperties);
                        }
                    }
                }else{
                    //上级属性为option,说明他为最大属性没有上级  直接添加进allProperties
                    if("option".equals(parenName)){
                        allProperties.put(attribute_name,changeDataFormat(attr_value)[0]);
                        continue;
                    }
                }
                grouping1 = grouping2;
                //饼状图插入数据同属一个父元素  多个元素和对应的数据需全部找出来一起封装json
                if(!BaseUtil.strIsNull(fieldName)){
                    String parentAttributeName = fieldSet.getString("parentAttributeName");
                    //下级为对象还是数组
                    String type = fieldSet.getString("subordinateElementType");
                    List<String> keys = ListUtils.newArrayList();
                    List<String> keys2 = ListUtils.newArrayList();
                    keys.add(fieldName);
                    keys2.add(attribute_name);
                    //为最后一位
                    while (i < length-1) {
                        FieldSetEntity fieldSet2 = attributeData.getFieldSetEntity(i+1);
                        String parenUuid3 = fieldSet2.getString("parentAttributeUuid");
                        String fieldName3 = fieldSet2.getString(CmnConst.FIELD_NAME);
                        if(parenUuid2.equals(parenUuid3) && !BaseUtil.strIsNull(fieldName3)){
                            keys.add(fieldName3);
                            keys2.add(fieldSet2.getString("attribute_name"));
                        }else {
                            break;
                        }
                        i++;
                    }
                    if("1".equals(type)) {
                        propertyObject.put(keys2.get(0), this.attributesAndValues(valueData, keys, keys2, type));
                    }else {
                        propertyObject.put(parentAttributeName, this.attributesAndValues(valueData, keys, keys2, type));
                    }
                }else {
                    propertyObject.put(attribute_name,changeDataFormat(attr_value)[0]);
                }
                if(i == (length - 1)){
                    //封装最后一组数据
                    this.getAllProperties(parenUuid1,propertyObject,allProperties);
                }
            }
        }
        JSONObject s=new JSONObject();
        //图表边距
//        s.put("bottom",30);
//        s.put("left",30);
//        s.put("right",0);
//        allProperties.put("grid",s);
        String typeGroup = typeField.getString(CmnConst.TYPE_GROUP);
        JSONObject object = BaseUtil.fieldSetEntityToJson(fse);
        object.put(CmnConst.TYPE,typeGroup);
        object.put(CmnConst.OPTION,allProperties);
//        object.put("function",this.functionArray(uuid));
        return object;
    }
 
    /**
     * 获取上级数据并递归拼装上级属性
     * @param superiorUuid 上级uuid
     * @param obj
     * @return
     * @throws BaseException
     */
    @Override
    public void getAllProperties(String superiorUuid,JSONObject obj,JSONObject allProperties) throws BaseException {
        FieldSetEntity fieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_TYPE_ATTRIBUTE,superiorUuid,false);
        String attribute_name = fieldSet.getString("attribute_name");
        JSONObject superiorObj = new JSONObject();
        JSONArray objSubArray = obj.getJSONArray(attribute_name);
        //确定他的子属性时(1)array 还是(0)object
//        if(objSubArray == null){
            if ("1".equals(fieldSet.getString("subordinateElementType"))) {
                JSONArray array = new JSONArray();
                array.add(obj);
                superiorObj.put(attribute_name, array);
            } else {
                superiorObj.put(attribute_name, obj);
            }
//        }else if(objSubArray != null){
//            superiorObj = obj;
//        }
        //上级属性name
        superiorUuid = fieldSet.getString("parentAttributeUuid");
        //上级名称
        String parentAttributeName = fieldSet.getString("parentAttributeName");
        //如果父元素uuid为空
        if(BaseUtil.strIsNull(superiorUuid)){
            JSONArray allSubProperties = allProperties.getJSONArray(attribute_name);
            if(allSubProperties != null){
                JSONObject subObj = JSONObject.parseObject(obj.toJSONString());
                if(allSubProperties.size() > 0){
                    //是扩充当前子元素  还是同级新增一个子元素
                    Boolean is_extend = true;
                    JSONObject subPropertiesJSONObject = allSubProperties.getJSONObject(0);
                    //break bak1  结束了所有循环
                    bak1:
                    for (String key1 : subPropertiesJSONObject.keySet()) {
                        for (String key2 : subObj.keySet()) {
                            if(key1.equals(key2)){
                                is_extend = false;
                                break bak1;
                            }
                        }
                    }
                    //每个元素都不一样
                    if(is_extend){
                        for (String key :subObj.keySet()) {
                            subPropertiesJSONObject.put(key, subObj.get(key));
                        }
                        obj.clear();
                        return;
                    }
                    }
                allSubProperties.add(subObj);
                obj.clear();
                return;
            }
            //克隆json
            JSONObject copy;
            Object o = superiorObj.get(attribute_name);
            if(o instanceof JSONArray){
                JSONArray oar = (JSONArray) o;
                JSONArray arr = JSONObject.parseArray(oar.toJSONString());
                allProperties.put(attribute_name,arr);
            }else {
                copy = JSONObject.parseObject(superiorObj.toJSONString());
                allProperties.put(attribute_name,copy.getJSONObject(attribute_name));
            }
        }else {
            //查询有无同父类的元素
            Object o = allProperties.get(parentAttributeName);
            if(o == null){
                Object a = superiorObj.get(attribute_name);
                JSONObject newObj = JSONObject.parseObject(superiorObj.toJSONString());
                if(a != null) {
                    if(a instanceof JSONArray) {
                        JSONArray array = (JSONArray)a;
                        if (array != null && array.size() == 1) {
                            JSONObject object = array.getJSONObject(0);
                            JSONArray aa = object.getJSONArray(attribute_name);
                            if (aa != null) {
                                newObj = JSONObject.parseObject(object.toJSONString());
                            }
                        }
                    }
                }
                 this.getAllProperties(superiorUuid,newObj,allProperties);
            }else {
                JSONObject currentProperty = null;
                if(o instanceof JSONArray) {
                    JSONArray arrays = (JSONArray)o;
                    currentProperty  = arrays.getJSONObject(arrays.size()-1);
                } else if(o instanceof JSONObject) {
                    currentProperty = (JSONObject)o;
                }
                if(currentProperty != null){
                    Object o2 = superiorObj.get(attribute_name);
                    if(o2 instanceof JSONArray){
                        JSONArray oar = (JSONArray) o2;
                        JSONObject subObj = oar.getJSONObject(oar.size()-1);
                        JSONArray subArray = subObj.getJSONArray(attribute_name);
                        JSONArray arr = new JSONArray();
                        if(subArray != null){
                            arr = JSONObject.parseArray(subArray.toJSONString());
                        }else {
                            JSONObject copyObj = JSONObject.parseObject(subObj.toJSONString());
                            arr.add(copyObj);
                        }
                        JSONArray theOriginalData = currentProperty.getJSONArray(attribute_name);
                        if(theOriginalData == null){
                            currentProperty.put(attribute_name,arr);
                        }else {
                            theOriginalData.add(arr.getJSONObject(arr.size()-1));
                        }
 
                    }else {
                        JSONObject copy = JSONObject.parseObject(superiorObj.getJSONObject(attribute_name).toJSONString());
                        JSONObject o3 = currentProperty.getJSONObject(attribute_name);
                        if(o3 == null){
                            currentProperty.put(attribute_name,copy);
                        }else {
                            for (String key: copy.keySet()) {
                                //可以以Object的类型存入
                                o3.put(key, copy.get(key));
                            }
                        }
                    }
                }
            }
        }
        obj.clear();
    }
 
    /**
     * 图表数据源集合封装至EChart属性
     * @param valueData 数据值data
     * @param
     * @return
     * @throws BaseException
     */
    @Override
    public JSONArray attributesAndValues(DataTableEntity valueData,List<String> keys,List<String> keys2,String type) throws BaseException {
        JSONArray array = new JSONArray();
        if("1".equals(type)) {
            for (int j = 0, length = valueData.getRows(); j < length; j++) {
                FieldSetEntity valueSet = valueData.getFieldSetEntity(j);
                    array.add(valueSet.getString(keys.get(0)));
            }
        }else {
            for (int j = 0, length = valueData.getRows(); j < length; j++) {
                JSONObject object = new JSONObject();
                FieldSetEntity valueSet = valueData.getFieldSetEntity(j);
                for (int i = 0, len = keys.size(); i < len; i++) {
                    object.put(keys2.get(i), valueSet.getString(keys.get(i)));
                }
                array.add(object);
            }
        }
        return array;
    }
 
    /**
     * 改变数据格式
     * @param attr_value 获取的数据值
     * @param
     * @return
     * @throws BaseException
     */
    @Override
    public Object[] changeDataFormat(String attr_value) throws BaseException {
        Object[] oArray = new Object[1];
        if(BaseUtil.strIsNull(attr_value)){
            oArray[0] = attr_value;
         //如果是数字
        }else if(attr_value.matches("^-?[0-9]\\d*$")){
            oArray[0] = Integer.parseInt(attr_value);
        }else if("false".equals(attr_value)){
            oArray[0] = false;
        }else if("true".equals(attr_value)){
            oArray[0] = true;
        //二维数组
        }else if(attr_value.indexOf("~~") != -1){
            String[] array2 = attr_value.split("~~");
            if(array2.length > 0){
                JSONArray array = new JSONArray();
                for (int i = 0,length = array2.length; i < length; i++) {
                    if(array2[i].indexOf("~") != -1){
                        array.add(array2[i].split("~"));
                    }else {
                        array.add(array2[i]);
                    }
                }
                oArray[0] = array;
            }
            //一维数组
        }else if(attr_value.indexOf("~") != -1){
            if(attr_value.length() == 1){
                oArray[0] = new JSONObject();
            }else {
                oArray[0] = attr_value.split("~");
                String[] value = attr_value.split("~");
                Integer len = value.length;
                Object[] subObj = new Object[len];
                //matches() 方法用于检测字符串是否匹配给定的正则表达式。
                for (int i = 0; i < len; i++) {
                    if(value[i].matches("^-?[1-9]\\d*$")){
                        subObj[i] =  Integer.parseInt(value[i]);
                    }else {
                        subObj[i] =  value[i];
                    }
                }
                oArray[0] = subObj;
            }
        }else {
            oArray[0] = attr_value;
        }
        return oArray;
    }
 
 
    /**
     * 关系图封装数据源
     * @param sql
     * @return
     * @throws BaseException
     */
    @Override
    public JSONObject chooseRelationship(String sql) throws BaseException {
        JSONArray links = new JSONArray();
        JSONArray nodes = new JSONArray();
        JSONArray categories = new JSONArray();
        String[] sqlArray = sql.split("~");
        Integer maxValue = 0;
        for (int i = 0; i < sqlArray.length; i++) {
            String s = sqlArray[i];
            DataTableEntity dataTableEntity = baseDao.listTable(s,new Object[]{});
            for (int j = 0; j < dataTableEntity.getRows(); j++) {
                FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(j);
                if(s.lastIndexOf("links") != -1){
                    String source = fieldSetEntity.getString("source");
                    String target = fieldSetEntity.getString("target");
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("source", ((Integer) changeDataFormat(source)[0])-1);
                    jsonObject.put("target",((Integer) changeDataFormat(target)[0])-1);
                    links.add(jsonObject);
                }
                if(s.lastIndexOf("nodes") != -1){
                    String id = fieldSetEntity.getString("id");
                    String name = fieldSetEntity.getString("name");
                    String modularity_class = fieldSetEntity.getString("modularity_class");
                    Integer value = fieldSetEntity.getInteger("value");
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id",((Integer)changeDataFormat(id)[0])-1);
                    jsonObject.put("name",name);
                    if(value > maxValue){
                        maxValue = value;
                    }
                    jsonObject.put("value",value);
                    JSONObject subObj = new JSONObject();
                    subObj.put("modularity_class",((Integer)changeDataFormat(modularity_class)[0])-1);
                    jsonObject.put("attributes",subObj);
                    nodes.add(jsonObject);
                }
                if(s.lastIndexOf("categories") != -1){
                    String id = fieldSetEntity.getString("id");
                    String name = fieldSetEntity.getString("name");
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id",((Integer)changeDataFormat(id)[0])-1);
                    jsonObject.put("name",name);
                    categories.add(jsonObject);
                }
            }
 
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("links",links);
        jsonObject.put("nodes",nodes);
 
        Integer place = 1;
        while ((maxValue/place) > 200){
            place = place * 2;
        }
        for (int i = 0,length = nodes.size(); i < length; i++) {
            Integer value = nodes.getJSONObject(i).getInteger("value");
            nodes.getJSONObject(i).put("symbolSize", (value/place));
        }
        jsonObject.put("categories",categories);
        return jsonObject;
    }
 
    /**
     * 通过配置表uuid获取js方法
     * @param uuid 配置表uuid
     * @param
     * @return
     * @throws BaseException
     */
    @Override
    public JSONArray functionArray(String uuid)throws BaseException{
            //获取图表方法
            DataTableEntity functionData = baseDao.listTable("SELECT * FROM product_sys_report_function where is_execute = 1 and report_config_uuid = ?", new String[]{uuid});
            JSONArray functionArray = new JSONArray();
            for (int i = 0,length = functionData.getRows(); i < length; i++) {
                FieldSetEntity functionField = functionData.getFieldSetEntity(i);
                JSONObject funObject = new JSONObject();
                funObject.put("function",functionField.getString("function"));
                funObject.put("event_type",functionField.getString("event_type"));
                functionArray.add(funObject);
            }
            return functionArray;
        }
 
    /**
     *     图表发布
     * @param fse
     * @return
     */
    @Transactional
    @Override
    public List<String> releaseConfig(FieldSetEntity fse, String module_uuid, String parentCode) {
 
        FieldSetEntity fseReport=baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, fse.getUUID(), false);
 
        //创建MVCC保存对象
        FieldSetEntity fseFunction=new FieldSetEntity();
        fseFunction.setTableName(CmnConst.PRODUCT_SYS_FUNCTIONS);
        //1.创建MVC(系统MVC目录下)
        //生成功能编码
        codeService.createCode(fseFunction,CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, parentCode);
        String function_tricode=fseFunction.getString(CmnConst.TRICODE);
        fseFunction.setTableName(CmnConst.PRODUCT_SYS_FUNCTIONS);
        fseFunction.setValue(CmnConst.TRICODE, function_tricode);        //功能编码
        fseFunction.setValue(CmnConst.MODULE_UUID, module_uuid);    //所属模块UUID
        fseFunction.setValue(CmnConst.TABLE_UUID, CmnConst.PRODUCT_SYS_REPORT_CONFIG);            //功能关联表
        fseFunction.setValue(CmnConst.FUNCTION_NAME, fseReport.getString(CmnConst.REPORT_NAME));    //功能名称
        fseFunction.setValue(CmnConst.FUNCTION_DESCRIPTION, fseReport.getString(CmnConst.REPORT_NAME));    //功能描述
        fseFunction.setValue(CmnConst.STATUS_UUID, 1);            //是否启用
        fseFunction.setValue(CmnConst.FUNCTION_TYPE_UUID, 1);    //功能类型-业务功能
        fseFunction.setValue(CmnConst.CLIENT_TYPE_UUID, "web");        //客户端类型
        fseFunction.setValue(CmnConst.VERSION_UUID, "001"); //版本uuid
        fseFunction.setValue(CmnConst.TRICODE_PARENT, parentCode);
        fseFunction.setValue("data_type", 1); //类型  1为功能
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fseFunction);
 
        //创建按钮保存对象
        DataTableEntity dtButton=new DataTableEntity();
        FieldSetEntity fseButton=new FieldSetEntity();
        fseButton.setTableName(CmnConst.PRODUCT_SYS_FUNCTION_BUTTONS);
        fseButton.setValue(CmnConst.IS_MAIN, 1);        //是否入口
        fseButton.setValue(CmnConst.STATUS_UUID, 1);    //是否启用
        fseButton.setValue(CmnConst.CLIENT_TYPE_UUID, "Web");    //客户端类型
        fseButton.setValue(CmnConst.BUTTON_NAME, "入口");    //按钮名称
        fseButton.setValue(CmnConst.BUTTON_TITLE, "entrance");    //按钮标题
        fseButton.setValue(CmnConst.BUTTON_TYPE, 1);            //按钮类型
        fseButton.setValue(CmnConst.BUTTON_CATEGORY_UUID, "main");    //按钮分类
        fseButton.setValue(CmnConst.ROUTE_NAME, BaseUtil.getPageCode());    //路由名称
        fseButton.setValue(CmnConst.UPLOAD_API_URL, CmnConst.ADDRESS_INIT_CHART);// 入口接口地址
        JSONObject paramObj = new JSONObject();
        paramObj.put(CmnConst.UUID, fse.getUUID());
        fseButton.setValue(CmnConst.PARAMS, paramObj.toString());// 接口参数
        fseButton.setValue(CmnConst.TOP_LOCATION, "100px");
        fseButton.setValue(CmnConst.LEFT_LOCATION, "100px");
        fseButton.setValue("terminal_type", 1); //客户端类型
        dtButton.setMeta(fseButton.getMeta());
        dtButton.addFieldSetEntity(fseButton);
 
        //创建页面保存对象
        DataTableEntity dtPage=new DataTableEntity();
        FieldSetEntity fsePage=new FieldSetEntity();
        fsePage.setTableName(CmnConst.PRODUCT_SYS_MVC_PAGE);
        fsePage.setValue(CmnConst.PAGE_NAME, "图表展示");
        fsePage.setValue(CmnConst.PAGE_TYPE, 2);
        fsePage.setValue(CmnConst.PAGE_URL, CmnConst.ADDRESS_CHART_VIEW);
        fsePage.setValue(CmnConst.TOP_LOCATION, "300px");
        fsePage.setValue(CmnConst.LEFT_LOCATION, "100px");
        fsePage.setValue(CmnConst.PAGE_OPEN_WITH, 0);
        fsePage.setValue("terminal_type", 1); //客户端类型
        dtPage.addFieldSetEntity(fsePage);
 
        fseFunction.addSubDataTable(dtButton);
        fseFunction.addSubDataTable(dtPage);
 
        String functionUUID = baseDao.add(fseFunction);
 
        //创建连线保存对象
        FieldSetEntity fseLink=new FieldSetEntity();
        fseLink.setTableName(CmnConst.PRODUCT_SYS_LINK);
        fseLink.setValue(CmnConst.LINK_TYPE, 0);        //连线类型
        fseLink.setValue(CmnConst.FUNCTION_UUID, functionUUID);    //所属功能UUID
        fseLink.setValue(CmnConst.LINE_FROM, fseButton.getUUID());    //起始端
        fseLink.setValue(CmnConst.FROM_TYPE, 0);                    //起始端类型
        fseLink.setValue(CmnConst.LINE_TO, fsePage.getUUID());        //结束端
        fseLink.setValue(CmnConst.TO_TYPE, 2);                        //结束端类型
        fseLink.setValue("terminal_type", 1);//客户端类型
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fseLink);
 
        baseDao.add(fseLink);
 
        // 提取发布的角色相关数据
        List<String> roleUUIDList = Lists.newArrayList();
        List<String> clientUUIDList = Lists.newArrayList();
        String[] singleRoleInfoArr;
        for (String singleRoleInfo : fse.getString(CmnConst.ROLE_UUID).split("#")) {
            singleRoleInfoArr = singleRoleInfo.split(",");
            roleUUIDList.add(singleRoleInfoArr[2]);
            clientUUIDList.add(singleRoleInfoArr[0]);
        }
 
        // 2.绑定角色(给某一角色赋予该功能)
        for (String roleUUID : roleUUIDList) {
            FieldSetEntity fseFunctionButton=new FieldSetEntity();
            fseFunctionButton.setTableName(CmnConst.PRODUCT_SYS_FUNCTION_PERMISSION);
            fseFunctionButton.setValue(CmnConst.FUNCTION_UUID, functionUUID);// 所属功能UUID
            fseFunctionButton.setValue(CmnConst.BUTTON_UUID, fseButton.getUUID());// 按钮UUID
            fseFunctionButton.setValue(CmnConst.ROLE_UUID, roleUUID);// 所属角色UUID
            baseDao.add(fseFunctionButton);
        }
 
        // 3.绑定客户角色(给某一客户角色赋予该功能)
        for (String clientUUID : clientUUIDList) {
            DataTableEntity clientDte = DataPoolCacheImpl.getInstance().getCacheData("客户信息", new String[]{clientUUID});
            if (BaseUtil.dataTableIsEmpty(clientDte)) {
                continue;
            }
            FieldSetEntity clientFse = clientDte.getFieldSetEntity(0);
            FieldSetEntity fseClientFunctionButton = new FieldSetEntity();
            fseClientFunctionButton.setTableName(CmnConst.PRODUCT_SYS_FUNCTION_PERMISSION);
            fseClientFunctionButton.setValue(CmnConst.FUNCTION_UUID, functionUUID);// 所属功能UUID
            fseClientFunctionButton.setValue(CmnConst.BUTTON_UUID, fseButton.getUUID());// 按钮UUID
            fseClientFunctionButton.setValue(CmnConst.ROLE_UUID, clientFse.getString(CmnConst.ROLE_UUID));// 所属角色UUID
            baseDao.add(fseClientFunctionButton);
        }
 
        //4.创建菜单(根据前端所选父级菜单)
        FieldSetEntity fseMenu=new FieldSetEntity();
        fseMenu.setTableName(CmnConst.PRODUCT_SYS_MENUS);
        codeService.createCode(fseMenu,CmnConst.PRODUCT_SYS_MENUS, CmnConst.TRICODE, fse.getString(CmnConst.TRICODE_PARENT));
        fseMenu.setValue(CmnConst.TRICODE_PARENT, fse.getString(CmnConst.TRICODE_PARENT));
        fseMenu.setValue(CmnConst.MENU_NAME, fse.getString(CmnConst.MENU_NAME));
        fseMenu.setValue(CmnConst.FUNCTION_UUID, functionUUID);
        fseMenu.setValue(CmnConst.SEQUENCE, 0);
        fseMenu.setValue(CmnConst.IS_CATALOG, 0);
        fseMenu.setValue(CmnConst.IS_SHOW, 1);
        fseMenu.setValue(CmnConst.MENU_ICON, fse.getString(CmnConst.MENU_ICON));
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fseMenu);
 
        baseDao.add(fseMenu);
 
        //数据回写
        fseReport.setValue(CmnConst.FUNCTION_UUID, functionUUID);
 
        boolean result = baseDao.update(fseReport);
 
        return roleUUIDList;
    }
 
    /**
     * 获取已发布列表
     * @param fieldSetEntity
     * @return
     */
    public DataTableEntity releasedListChartConfig(FieldSetEntity fieldSetEntity){
        Integer curPage = fieldSetEntity.getInteger(CmnConst.CPAGE);
        Integer pageSize = fieldSetEntity.getInteger(CmnConst.PAGE_SIZE);
        StringBuffer sql = new StringBuffer();
//        sql.append(" select * from ( ")
        sql.append(" select rc.uuid,rc.report_name,'图表' type_name,t1.role_info,mp.menu_name tricode_parent,m.menu_icon,m.menu_name,rc.function_uuid ")
                .append(" FROM product_sys_report_config rc ")
                .append(" inner join ( ")
                .append(" select function_uuid,group_concat(role_info separator ',') role_info ")
                .append(" from ( ")
                .append(" select function_uuid,concat(c.client_name,'/',o.org_level_name,'/',role_name) role_info ")
                .append(" FROM product_sys_clients c ")
                .append(" inner join product_sys_org_levels o on o.client_uuid=c.uuid ")
                .append(" inner join ( ")
                .append(" select function_uuid,org_level_uuid,uuid role_uuid,role_name ")
                .append(" FROM product_sys_role r ")
                .append(" inner join ( ")
                .append(" select function_uuid,role_uuid FROM product_sys_function_permission ")
                .append(" ) p on r.uuid=p.role_uuid ")
                .append(" ) r1 on o.uuid=r1.org_level_uuid ")
                .append(" ) t ")
                .append(" group by function_uuid ")
                .append(" ) t1 on rc.function_uuid=t1.function_uuid ")
                .append(" inner join product_sys_menus m on rc.function_uuid=m.function_uuid ")
                .append(" inner join product_sys_menus mp on m.tricode_parent=mp.tricode ")
                .append(" WHERE datasource_uuid is null ");
//                .append(" ) product_sys_report_config ");
                if (!BaseUtil.dataTableIsEmpty(fieldSetEntity.getSubDataTable("systemSeniorQueryString"))) {
                    sql.append(" AND " + queryFilterService.getQueryFilter(fieldSetEntity));
                }
        return baseDao.listTable(sql.toString(), new Object[]{}, pageSize == null ? Integer.MAX_VALUE : pageSize, curPage == null ? 1: curPage);
    }
 
 
    /**
     *     取消报表发布
     * @param fse
     * @return
     */
    @Transactional
    @Override
    public Boolean cancelRelease(FieldSetEntity fse) {
        //缓存里面取FUNCTION_UUID
//        DataTableEntity reportConfigDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_REPORT_CONFIG, new String[]{fse.getUUID()});
//        if (BaseUtil.dataTableIsEmpty(reportConfigDte)) {
//            throw new BaseException(ReportCode.GET_REPORT_CONFIG_FIAL.getValue(), ReportCode.GET_REPORT_CONFIG_FIAL.getText());
//        }
//        FieldSetEntity reportConfigFse = reportConfigDte.getFieldSetEntity(0);
        String uuid = fse.getString(CmnConst.UUID);
        FieldSetEntity fieldSet = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, uuid, false);
        String functionUUID = fieldSet.getString(CmnConst.FUNCTION_UUID);
        if (StringUtils.isEmpty(functionUUID)) {
            return false;
        }
        //从角色权限中移除
        baseDao.delete(CmnConst.PRODUCT_SYS_FUNCTION_PERMISSION, "function_uuid=?", new Object[] {functionUUID});
        //删除连线
        baseDao.delete(CmnConst.PRODUCT_SYS_LINK, "function_uuid=?", new Object[] {functionUUID});
        //删除按钮
        baseDao.delete(CmnConst.PRODUCT_SYS_FUNCTION_BUTTONS, "function_uuid=?", new Object[] {functionUUID});
        //删除页面
        baseDao.delete(CmnConst.PRODUCT_SYS_MVC_PAGE, "function_uuid=?", new Object[] {functionUUID});
 
        //删除菜单
        baseDao.delete(CmnConst.PRODUCT_SYS_MENUS, "function_uuid=?", new Object[] {functionUUID});
        //删除功能
        baseDao.delete(CmnConst.PRODUCT_SYS_FUNCTIONS, "uuid = ?", new Object[] {functionUUID});
        //数据回写
        fieldSet.setValue(CmnConst.FUNCTION_UUID, "");
 
//        DataPoolRefreshCache.getInstance().put(.PRODUCT_SYS_page_button_v");
 
        return baseDao.update(fieldSet);
    }
}