1821349743@qq.com
2023-04-03 3df221b0a98cde4562471727a6ad41ffafbe39a8
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
package com.product.server.report.service;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.product.admin.service.CodeService;
import com.product.admin.service.UpdateLoginUserInfoService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.CoreConst;
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.IReportConfigService;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.xml.crypto.Data;
import java.util.*;
 
@Component
public class ReportConfigService extends AbstractBaseService implements IReportConfigService {
    @Autowired
    BaseDao baseDao;
    @Autowired
    CodeService codeService;
    @Autowired
    public QueryFilterService queryFilterService;
    @Autowired
    public DataListReportService dataListReportService;
 
    /**
     * 报表列表
     *
     * @param cpage
     * @param pageSize
     * @return
     */
    public DataTableEntity listReportConfig(Integer cpage, Integer pageSize, FieldSetEntity fse) {
        cpage = cpage == null ? 1 : cpage;
        pageSize = pageSize == null ? 20 : pageSize;
 
        List<Object> paramList = Lists.newArrayList();
        StringBuilder sql = new StringBuilder(512);
        sql.append("\nSELECT a.uuid,a.type_uuid,a.is_valid,a.org_level_uuid,a.report_name,b.type_name,b.type_group")
                .append("\nFROM product_sys_report_config a")
                .append("\nLEFT JOIN product_sys_report_type_config b ON a.type_uuid = b.uuid")
                .append("\nwhere (function_uuid is null or function_uuid='') ");
        if (!StringUtils.isEmpty(fse.getString(CmnConst.TYPE_UUID))) {
            sql.append("\nand b.type_group=?");
            paramList.add(fse.getString(CmnConst.TYPE_UUID));
        }
        return baseDao.listTable(sql.toString(), paramList.toArray(), pageSize, cpage);
    }
 
    /**
     * 报表详情
     *
     * @param uuid
     * @return
     */
    public FieldSetEntity findReportConfig(String uuid) {
        StringBuilder sql = new StringBuilder(256);
        sql.append("\nselect report_area,cell_position_y,cell_position_x,attribute_name,report_type_attr_value")
                .append("\nfrom (")
                .append("\n    select report_area,cell_position_y,cell_position_x,report_type_attr_value,report_type_attr FROM product_sys_report_config_attribute ca")
                .append("\n    where report_config_uuid=?")
                .append("\n) ca")
                .append("\nleft join (")
                .append("\n    select uuid,attribute_name FROM product_sys_report_type_attribute where type_group='DataList'")
                .append("\n) ta on ca.report_type_attr=ta.uuid")
                .append("\nwhere attribute_name is not null ")
                .append("\norder by report_area,cell_position_y,cell_position_x");
        DataTableEntity tempDte = baseDao.listTable(sql.toString(), new Object[]{uuid});
        DataTableEntity reportConfigAttrDte = new DataTableEntity();
        FieldSetEntity tempFse;
        FieldSetEntity reportConfigAttrFse = new FieldSetEntity();
        String curReportArea;
        String curX;
        String curY;
        String preReportArea = "";
        String preX = "";
        String preY = "";
        for (int i = 0; i < tempDte.getRows(); i++) {
            tempFse = tempDte.getFieldSetEntity(i);
            curReportArea = tempFse.getString(CmnConst.ATTR_REPORT_AREA);
            curX = tempFse.getString(CmnConst.CELL_POSITION_X);
            curY = tempFse.getString(CmnConst.CELL_POSITION_Y);
            if (curReportArea == null || curX == null || curY == null) {
                continue;
            }
            if (!preReportArea.equals(curReportArea) || !preX.equals(curX) || !preY.equals(curY)) {
                reportConfigAttrFse = new FieldSetEntity();
                reportConfigAttrDte.addFieldSetEntity(reportConfigAttrFse);
                reportConfigAttrFse.setTableName(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
                reportConfigAttrFse.setValue(CmnConst.ATTR_X, curX);
                reportConfigAttrFse.setValue(CmnConst.ATTR_Y, curY);
                reportConfigAttrFse.setValue(CmnConst.ATTR_REPORT_AREA, curReportArea);
            }
            reportConfigAttrFse.setValue(tempFse.getString(CmnConst.ATTRIBUTE_NAME), tempFse.getString(CmnConst.REPORT_TYPE_ATTR_VALUE));
            preReportArea = curReportArea;
            preX = curX;
            preY = curY;
        }
 
        FieldSetEntity reportConfigFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, uuid, false);
        reportConfigFse.addSubDataTable(reportConfigAttrDte);
 
        return reportConfigFse;
    }
 
    /**
     * 报表新增
     *
     * @param fse
     * @return
     */
    @Transactional
    public String addReportConfig(FieldSetEntity fse) {
        fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUserId());
        fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
        fse.setValue(CmnConst.IS_VALID, 1);
 
        replaceAttrName2UUID(fse);
 
        if (StringUtils.isEmpty(fse.getString(CmnConst.PAGE_SIZE))) {
            fse.setValue(CmnConst.PAGE_SIZE, null);
        }
        System.out.println(System.currentTimeMillis());
        String uuid = baseDao.add(fse);
        System.out.println(System.currentTimeMillis());
 
        if ("1".equals(fse.getString(CmnConst.RELATE_FLAG))) {
            // 重新设置缓存
            dataListReportService.setConfig(fse.getUUID());
        }
 
        return uuid;
    }
 
    /**
     * 报表修改
     *
     * @param fse
     * @return
     */
    @Transactional
    public boolean updateReportConfig(FieldSetEntity fse) {
        fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUserId());
        fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
 
        replaceAttrName2UUID(fse);
 
        if (StringUtils.isEmpty(fse.getString(CmnConst.PAGE_SIZE))) {
            fse.setValue(CmnConst.PAGE_SIZE, null);
        }
 
        boolean result = baseDao.update(fse);
 
        if ("1".equals(fse.getString(CmnConst.RELATE_FLAG)) || !StringUtils.isEmpty(fse.getString(CmnConst.FUNCTION_UUID))) {
            // 重新设置缓存
            dataListReportService.setConfig(fse.getUUID());
        }
 
        return result;
    }
 
    /**
     * 替换属性名称为uuid
     *
     * @param fse
     */
    private void replaceAttrName2UUID(FieldSetEntity fse) {
        DataTableEntity reportTypeAttrDte = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_TYPE_ATTRIBUTE, "type_group='DataList'", new Object[]{}, new Object[]{CmnConst.ATTRIBUTE_NAME, CmnConst.UUID});
        if (!BaseUtil.dataTableIsEmpty(reportTypeAttrDte)) {
            Map<String, String> reportTypeAttrMap = Maps.newHashMap();
            FieldSetEntity tempFse;
            for (int i = 0; i < reportTypeAttrDte.getRows(); i++) {
                tempFse = reportTypeAttrDte.getFieldSetEntity(i);
                reportTypeAttrMap.put(tempFse.getString(CmnConst.ATTRIBUTE_NAME), tempFse.getUUID());
            }
            DataTableEntity preReportAttrDte = baseDao.listTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE, "report_config_uuid=?", new Object[]{fse.getUUID()});
            Map<JSONObject, String> preReportAttrMap = Maps.newHashMap();
            JSONObject tempObj;
            if (!BaseUtil.dataTableIsEmpty(preReportAttrDte)) {
                for (int i = 0; i < preReportAttrDte.getRows(); i++) {
                    tempFse = preReportAttrDte.getFieldSetEntity(i);
                    tempObj = new JSONObject();
                    tempObj.put(CmnConst.ATTR_REPORT_AREA, tempFse.getString(CmnConst.ATTR_REPORT_AREA));
                    tempObj.put(CmnConst.CELL_POSITION_X, tempFse.getString(CmnConst.CELL_POSITION_X));
                    tempObj.put(CmnConst.CELL_POSITION_Y, tempFse.getString(CmnConst.CELL_POSITION_Y));
                    tempObj.put(CmnConst.REPORT_TYPE_ATTR, tempFse.getString(CmnConst.REPORT_TYPE_ATTR));
                    preReportAttrMap.put(tempObj, tempFse.getUUID());
                }
            }
            DataTableEntity reportAttrDte = fse.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
            if (!BaseUtil.dataTableIsEmpty(reportAttrDte)) {
                String tempUUID;
                for (int i = 0; i < reportAttrDte.getRows(); i++) {
                    tempFse = reportAttrDte.getFieldSetEntity(i);
                    tempFse.setValue("report_type_attr_show_name", tempFse.getString(CmnConst.REPORT_TYPE_ATTR));
                    tempFse.setValue(CmnConst.REPORT_TYPE_ATTR, reportTypeAttrMap.get(tempFse.getString(CmnConst.REPORT_TYPE_ATTR)));
                    tempFse.setValue(CmnConst.CELL_POSITION_X, tempFse.getString(CmnConst.ATTR_X));
                    tempFse.setValue(CmnConst.CELL_POSITION_Y, tempFse.getString(CmnConst.ATTR_Y));
                    String x = tempFse.getString(CmnConst.ATTR_X);
                    tempObj = new JSONObject();
                    tempObj.put(CmnConst.ATTR_REPORT_AREA, tempFse.getString(CmnConst.ATTR_REPORT_AREA));
                    tempObj.put(CmnConst.CELL_POSITION_X, tempFse.getString(CmnConst.CELL_POSITION_X));
                    tempObj.put(CmnConst.CELL_POSITION_Y, tempFse.getString(CmnConst.CELL_POSITION_Y));
                    tempObj.put(CmnConst.REPORT_TYPE_ATTR, tempFse.getString(CmnConst.REPORT_TYPE_ATTR));
 
                    tempUUID = preReportAttrMap.get(tempObj);
                    if (!StringUtils.isEmpty(tempUUID)) {
                        tempFse.setValue(CmnConst.UUID, tempUUID);
                    }
                    if (StringUtils.isEmpty(tempFse.getString(CmnConst.REPORT_TYPE_ATTR_VALUE))) {
                        //属性值是否为空
                        if (StringUtils.isEmpty(tempFse.getUUID())) {
                            //没有保存过的属性
                            reportAttrDte.removeFieldSetEntity(i);
                            i--;
                        } else {
                            //标记为删除
                            tempFse.setValue(CoreConst.SYSTEM_DATA_OPERATE_TYPE, "del");
                        }
                        continue;
                    }
                }
            }
        }
    }
 
    /**
     * 报表删除
     *
     * @param uuid
     * @return
     */
    @Transactional
    public boolean deleteReportConfig(String uuid) {
        return baseDao.delete(CmnConst.PRODUCT_SYS_REPORT_CONFIG, "uuid=?", new Object[]{uuid});
    }
 
    @Autowired
    UpdateLoginUserInfoService updateLoginUserInfoService;
 
    /**
     * 取消报表发布
     *
     * @param fse
     * @return
     */
    @Transactional
    public boolean cancelRelease(FieldSetEntity fse) {
        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 functionUUID = reportConfigFse.getString(CmnConst.FUNCTION_UUID);
        if (StringUtils.isEmpty(functionUUID)) {
            return false;
        }
 
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_FUNCTION_PERMISSION, "function_uuid=?", new Object[]{functionUUID}, new Object[]{"role_uuid uuid"});
        //从角色权限中移除
        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});
 
        //数据回写
        fse.setValue(CmnConst.FUNCTION_UUID, "");
 
        if (!DataTableEntity.isEmpty(dt)) {
            updateLoginUserInfoService.updateUserInfoByUpdateRole(dt.getUuids(), true);
        }
        return baseDao.update(fse);
    }
 
    /**
     * 报表发布
     *
     * @param fse
     * @return
     */
    @Transactional
    public boolean releaseConfig(FieldSetEntity fse) {
 
        FieldSetEntity fseReport = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, fse.getUUID(), false);
 
        //创建MVCC保存对象
        FieldSetEntity fseFunction = new FieldSetEntity();
        //1.创建MVC(系统MVC目录下)
        //生成功能编码
        String defaultCode = "001-005";
        fseFunction.setTableName(CmnConst.PRODUCT_SYS_FUNCTIONS);
        codeService.createCode(fseFunction, CmnConst.PRODUCT_SYS_FUNCTIONS, CmnConst.TRICODE, defaultCode);
        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");
        fseFunction.setValue(CmnConst.DATA_TYPE, 1);// 数据类型
        fseFunction.setValue(CmnConst.TRICODE_PARENT, defaultCode);// 上级模块code
        fseFunction.setValue("terminal_type", 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_INTERFENCE);// 入口接口地址
        fseButton.setValue("terminal_type", 1);
        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");
        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_NAME, fse.getString(CmnConst.MENU_NAME));
        fsePage.setValue(CmnConst.PAGE_TYPE, 2);
        fsePage.setValue(CmnConst.PAGE_URL, CmnConst.ADDRESS_REPORT_SHOW);
        fsePage.setValue(CmnConst.TOP_LOCATION, "300px");
        fsePage.setValue(CmnConst.LEFT_LOCATION, "100px");
        fsePage.setValue(CmnConst.PAGE_OPEN_WITH, 0);
        fsePage.setValue(CmnConst.PAGE_TYPE, 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, fse.getString(CmnConst.SEQUENCE));
        fseMenu.setValue(CmnConst.IS_CATALOG, 0);
        fseMenu.setValue(CmnConst.IS_SHOW, StringUtils.isEmpty(fse.getString(CmnConst.IS_SHOW)) ? 1 : fse.getString(CmnConst.IS_SHOW));
        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);
 
        // 重新设置缓存
        dataListReportService.setConfig(fseReport.getUUID());
 
        return result;
    }
 
    /**
     * 报表copy
     *
     * @param uuid
     * @return
     */
    public String copyConfig(String uuid) {
        FieldSetEntity fse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_REPORT_CONFIG, uuid, true);
        FieldSetEntity fseCopy = fse;
        fseCopy.remove(CmnConst.ID);
        fseCopy.remove(CmnConst.UUID);
        DataTableEntity dtSub = fseCopy.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
        if (dtSub != null && dtSub.getRows() > 0) {
            for (int i = 0; i < dtSub.getRows(); i++) {
                FieldSetEntity fseSub = dtSub.getFieldSetEntity(i);
                fseSub.remove(CmnConst.ID);
                fseSub.remove(CmnConst.UUID);
            }
        }
        return baseDao.add(fseCopy, true);
    }
 
    /**
     * 配置报表-引用
     *
     * @param fse
     * @return
     */
    public FieldSetEntity quoteReportConfig(FieldSetEntity fse) {
        FieldSetEntity sourceFse = findReportConfig(fse.getUUID());
        sourceFse.setValue(CmnConst.DATASOURCE_UUID, fse.getString(CmnConst.DATASOURCE_UUID));
        sourceFse.remove(new String[]{CmnConst.ID, CmnConst.UUID, CmnConst.CREATED_BY, CmnConst.CREATED_UTC_DATETIME, CmnConst.UPDATED_BY, CmnConst.CREATED_UTC_DATETIME, CmnConst.REPORT_NAME});
        DataTableEntity subDte = sourceFse.getSubDataTable(CmnConst.PRODUCT_SYS_REPORT_CONFIG_ATTRIBUTE);
        FieldSetEntity subFse;
        for (int i = 0; i < subDte.getRows(); i++) {
            subFse = subDte.getFieldSetEntity(i);
            subFse.remove(new String[]{CmnConst.ID, CmnConst.UUID, CmnConst.CREATED_BY, CmnConst.CREATED_UTC_DATETIME, CmnConst.UPDATED_BY, CmnConst.CREATED_UTC_DATETIME});
        }
        return sourceFse;
    }
 
    /**
     * 获取报表发布信息-发布
     *
     * @return
     */
    public JSONArray getReportReleaseInfo() {
        StringBuilder sql = new StringBuilder(256);
        DataTableEntity aimDte = new DataTableEntity();
        DataTableEntity dte;
        Object[] arr;
        String filter;
        sql.append("select distinct null pid,uuid sid,client_name name FROM product_sys_clients c")
                .append("\ninner join (")
                .append("\n    select client_uuid pid,uuid sid,org_level_name FROM product_sys_org_levels where org_level_status=0 order by org_level_code")
                .append("\n) o on o.pid=c.uuid")
                .append("\ninner join (")
                .append("\n    select org_level_uuid pid,uuid sid,role_name FROM product_sys_role where is_used=1")
                .append("\n) r on r.pid=o.sid");
        // 去掉admin所属客户
//                .append("\nwhere c.uuid!='4d4679ed-c4c3-41b8-abfe-451a66fd4043'");
        dte = baseDao.listTable(sql.toString(), new Object[]{});
 
        aimDte.addFieldSetEntity(dte);
 
        arr = dte.getFieldAllValues("sid");
        filter = BaseUtil.buildQuestionMarkFilter("client_uuid", arr.length, true);
        sql.setLength(0);
        sql.append("\nselect distinct o.* from (")
                .append("\n    select client_uuid pid,uuid sid,org_level_name name FROM product_sys_org_levels where org_level_status=0")
                .append("\n    and ").append(filter)
                .append("\n    order by org_level_code")
                .append("\n) o")
                .append("\ninner join (")
                .append("\n    select org_level_uuid pid,uuid sid,role_name FROM product_sys_role where is_used=1")
                .append("\n) r on r.pid=o.sid");
        dte = baseDao.listTable(sql.toString(), arr);
        aimDte.addFieldSetEntity(dte);
 
        arr = dte.getFieldAllValues("sid");
        filter = BaseUtil.buildQuestionMarkFilter("org_level_uuid", arr.length, true);
        sql.setLength(0);
        sql.append("\nselect org_level_uuid pid,uuid sid,role_name name FROM product_sys_role where is_used=1").append(" and ").append(filter);
        dte = baseDao.listTable(sql.toString(), arr);
        aimDte.addFieldSetEntity(dte);
 
        return BaseUtil.dataTableToTreeData(aimDte, "sid", "pid", null, false);
    }
 
    /**
     * 获取报表发布信息-发布后查看信息
     *
     * @return
     */
    public JSONObject viewReportReleaseInfo(FieldSetEntity fse) {
        DataTableEntity reportConfigDte = DataPoolCacheImpl.getInstance().getCacheData(CmnConst.CACHE_REPORT_CONFIG, new String[]{fse.getUUID()});
        if (BaseUtil.dataTableIsEmpty(reportConfigDte)) {
            throw new BaseException(ReportCode.GET_REPORT_RELEASE_INFO_FAIL.getValue(), ReportCode.GET_REPORT_RELEASE_INFO_FAIL.getText());
        }
        FieldSetEntity reportConfigFse = reportConfigDte.getFieldSetEntity(0);
        StringBuilder sql = new StringBuilder(256);
        sql.append("\nselect group_concat(single_role_uuid separator '#') role_uuid")
                .append("\nfrom (")
                .append("\n    select concat(client_uuid,',',uuid,',',role_uuid) single_role_uuid")
                .append("\n    FROM product_sys_org_levels o")
                .append("\n    inner join (")
                .append("\n        select org_level_uuid,uuid role_uuid,role_name")
                .append("\n        FROM product_sys_role r")
                .append("\n        inner join (")
                .append("\n            select role_uuid FROM product_sys_function_permission where function_uuid=?")
                .append("\n        ) p on r.uuid=p.role_uuid")
                .append("\n    ) r1 on o.uuid=r1.org_level_uuid")
                .append("\n) t");
        String functionUUID = reportConfigFse.getString(CmnConst.FUNCTION_UUID);
        DataTableEntity dte = baseDao.listTable(sql.toString(), new Object[]{functionUUID});
 
        FieldSetEntity menuFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_MENUS, "function_uuid=?", new Object[]{functionUUID}, false);
 
        JSONObject resultObj = new JSONObject();
        resultObj.put(CmnConst.UUID, fse.getUUID());
        resultObj.put(CmnConst.ROLE_UUID, dte.getFieldSetEntity(0).getString(CmnConst.ROLE_UUID));
        resultObj.put(CmnConst.TRICODE_PARENT, menuFse.getString(CmnConst.TRICODE_PARENT));
        resultObj.put(CmnConst.MENU_ICON, menuFse.getString(CmnConst.MENU_ICON));
        resultObj.put(CmnConst.MENU_NAME, menuFse.getString(CmnConst.MENU_NAME));
 
        return resultObj;
    }
 
    /**
     * 已发布列表界面
     *
     * @param fse
     * @return
     */
    public DataTableEntity releasedListReportConfig(FieldSetEntity fse) {
        String filter = queryFilterService.getQueryFilter(fse);
        StringBuilder sql = new StringBuilder(256);
//        sql.append("select * from ( ");
        sql.append("\n    select rc.uuid,rc.report_name,rtc.type_name,t1.role_info,mp.menu_name tricode_parent,m.menu_icon,m.menu_name ");
        sql.append("\n    FROM product_sys_report_config rc ");
        sql.append("\n    inner join ( ");
        sql.append("\n        select function_uuid,group_concat(role_info separator ',') role_info ");
        sql.append("\n        from ( ");
        sql.append("\n            select function_uuid,concat(c.client_name,'/',o.org_level_name,'/',role_name) role_info ");
        sql.append("\n                        FROM product_sys_clients c ");
        sql.append("\n                        inner join product_sys_org_levels o on o.client_uuid=c.uuid ");
        sql.append("\n                        inner join ( ");
        sql.append("\n                                select function_uuid,org_level_uuid,uuid role_uuid,role_name ");
        sql.append("\n                                FROM product_sys_role r ");
        sql.append("\n                                inner join ( ");
        sql.append("\n                                        select function_uuid,role_uuid FROM product_sys_function_permission ");
        sql.append("\n                                ) p on r.uuid=p.role_uuid ");
        sql.append("\n                        ) r1 on o.uuid=r1.org_level_uuid ");
        sql.append("\n        ) t ");
        sql.append("\n        group by function_uuid ");
        sql.append("\n    ) t1 on rc.function_uuid=t1.function_uuid ");
        sql.append("\n    inner join product_sys_menus m on rc.function_uuid=m.function_uuid ");
        sql.append("\n    inner join product_sys_report_type_config rtc on rc.type_uuid=rtc.uuid ");
        sql.append("\n    inner join product_sys_menus mp on m.tricode_parent=mp.tricode ");
//        sql.append("\n) t2 ");
        if (!StringUtils.isEmpty(filter)) {
            sql.append(" WHERE " + filter);
        }
        Integer curPage = fse.getInteger(CmnConst.CPAGE);
        Integer pageSize = fse.getInteger(CmnConst.PAGESIZE);
        return baseDao.listTable(sql.toString(), new Object[]{}, pageSize == null ? Integer.MAX_VALUE : pageSize, curPage == null ? 1 : curPage);
    }
}