ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.base.util.common;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.builder.CustomFile;
import jnpf.base.PrintApi;
import jnpf.base.entity.SysConfigEntity;
import jnpf.base.entity.VisualdevEntity;
import jnpf.base.model.ColumnDataModel;
import jnpf.base.model.DownloadCodeForm;
import jnpf.base.model.Template6.ColumnListField;
import jnpf.base.model.Template7.Template7Model;
import jnpf.base.model.print.PrintOption;
import jnpf.constant.FileTypeConstant;
import jnpf.constant.GenerateConstant;
import jnpf.constant.JnpfConst;
import jnpf.database.model.superQuery.SuperJsonModel;
import jnpf.database.model.superQuery.SuperQueryJsonModel;
import jnpf.file.FileApi;
import jnpf.model.generater.GenerConfig;
import jnpf.model.generater.GenerField;
import jnpf.model.visualJson.FieLdsModel;
import jnpf.model.visualJson.TemplateJsonModel;
import jnpf.model.visualJson.analysis.FormAllModel;
import jnpf.model.visualJson.analysis.FormColumnModel;
import jnpf.model.visualJson.analysis.FormEnum;
import jnpf.model.visualJson.config.HeaderModel;
import jnpf.util.*;
import jnpf.util.context.SpringContext;
import jnpf.util.visiual.JnpfKeyConsts;
import lombok.Cleanup;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author JNPF开发平台组
 * @version V3.5.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2021/5/31
 */
public class GenerateCommon {
    public static final String IS_CLOUD = "cloud" ;
 
    private static PrintApi printDevService = SpringContext.getBean(PrintApi.class);
 
    private static FileApi fileApi = SpringContext.getBean(FileApi.class);
 
    public static String getLocalBasePath() {
        return fileApi.getLocalBasePath();
    }
 
    public static String getPath(String type) {
        return fileApi.getPath(type);
    }
 
    public static List<PrintOption> getList(List<String> ids) {
        return printDevService.getList(ids);
    }
    /**
     * 获取代码生成基础信息
     *
     * @return
     */
    public static Template7Model getTemplate7Model(List<SysConfigEntity> list) {
        String author = "";
        String copyright = "";
        String version = "";
        for (SysConfigEntity item : list) {
            if ("companyName".equals(item.getFkey())) {
                author = item.getValue();
            }
            if ("copyright".equals(item.getFkey())) {
                copyright = item.getValue();
            }
            if ("sysVersion".equals(item.getFkey())) {
                version = item.getValue();
            }
        }
        Template7Model temModel = new Template7Model();
        temModel.setServiceDirectory(GenerateCommon.getLocalBasePath() + GenerateCommon.getPath(FileTypeConstant.CODETEMP));
        temModel.setCreateDate(DateUtil.daFormat(new Date()));
        temModel.setCreateUser(StringUtil.isNotEmpty(author) ? author : GenerateConstant.AUTHOR);
        temModel.setCopyright(StringUtil.isNotEmpty(copyright) ? copyright : GenerateConstant.COPYRIGHT);
        temModel.setVersion(StringUtil.isNotEmpty(version) ? version : GenerateConstant.VERSION);
        temModel.setDescription(GenerateConstant.DESCRIPTION);
        return temModel;
    }
 
    /**
     * 获取自定义文件(模板和生成路径)
     *
     * @param generateParamModel
     * @return
     */
    public static List<CustomFile> getCustomFileList(GenerateParamModel generateParamModel) {
        Template7Model template7Model = generateParamModel.getTemplate7Model();
        String path = template7Model.getServiceDirectory() + generateParamModel.getFileName() + File.separator;
        DownloadCodeForm downloadCodeForm = generateParamModel.getDownloadCodeForm();
        ArrayList<CustomFile> custFileList = new ArrayList<>();
        if (generateParamModel.isMainTable()) {
            custFileList.add(new CustomFile.Builder().templatePath("java/Controller.java.vm").formatNameFunction(tableInfo -> tableInfo.getControllerName())
                    .fileName(StringPool.DOT_JAVA).filePath(getCustomFilePath(path, OutputFile.controller.name(), downloadCodeForm)).enableFileOverride().build());
        }
        custFileList.add(new CustomFile.Builder().templatePath("java/Entity.java.vm").formatNameFunction(tableInfo -> tableInfo.getEntityName())
                .fileName(StringPool.DOT_JAVA).filePath(getCustomFilePath(path, OutputFile.entity.name(), downloadCodeForm)).enableFileOverride().build());
        custFileList.add(new CustomFile.Builder().templatePath("java/Mapper.java.vm").formatNameFunction(tableInfo -> tableInfo.getMapperName())
                .fileName(StringPool.DOT_JAVA).filePath(getCustomFilePath(path, OutputFile.mapper.name(), downloadCodeForm)).enableFileOverride().build());
        custFileList.add(new CustomFile.Builder().templatePath("java/Service.java.vm").formatNameFunction(tableInfo -> tableInfo.getServiceName())
                .fileName(StringPool.DOT_JAVA).filePath(getCustomFilePath(path, OutputFile.service.name(), downloadCodeForm)).enableFileOverride().build());
        custFileList.add(new CustomFile.Builder().templatePath("java/ServiceImpl.java.vm").formatNameFunction(tableInfo ->
                        tableInfo.getServiceImplName())
                .fileName(StringPool.DOT_JAVA).filePath(getCustomFilePath(path, OutputFile.serviceImpl.name(), downloadCodeForm)).enableFileOverride().build());
        custFileList.add(new CustomFile.Builder().templatePath("java/Mapper.xml.vm").formatNameFunction(tableInfo -> tableInfo.getXmlName())
                .fileName(StringPool.DOT_XML).filePath(getCustomFilePath(path, OutputFile.xml.name(), downloadCodeForm)).enableFileOverride().build());
        return custFileList;
    }
 
    /**
     * 根据模板名称获取生成文件路径
     *
     * @param path
     * @param codeName
     * @param downloadCodeForm
     * @return
     */
    public static String getCustomFilePath(String path, String codeName, DownloadCodeForm downloadCodeForm) {
        String eachName = "";
        String frontName = "";
        String modulName = downloadCodeForm.getModule();
        String framePath = downloadCodeForm.getModulePackageName();
        switch (codeName) {
            case "controller":
                framePath = getCloudPath("-controller", downloadCodeForm);
                break;
            case "entity":
                framePath = getCloudPath("-entity", downloadCodeForm);
                break;
            case "mapper":
                framePath = getCloudPath("-biz", downloadCodeForm);
                break;
            case "xml":
                if ("cloud".equals(GenerateCommon.IS_CLOUD)) {
                    String fileFront = "jnpf-" + modulName + File.separator + "jnpf-" + modulName + "-biz" + File.separator;
                    if ("form".equals(modulName)) {
                        fileFront = "jnpf-workflow" + File.separator + "jnpf-workflow-form" + File.separator + "jnpf-workflow-form-biz" + File.separator;
                    }
                    framePath = fileFront + "src" + File.separator + "main" + File.separator + "resources";
                    return path + File.separator + "java" + File.separator + framePath + File.separator + "mapper"
                            + File.separator;
                }
                return path + File.separator + "resources" + File.separator + "mapper"
                        + File.separator;
            case "service":
                framePath = getCloudPath("-biz", downloadCodeForm);
                break;
            case "serviceImpl":
                codeName = "impl";
                frontName = "service" + File.separator;
                framePath = getCloudPath("-biz", downloadCodeForm);
            default:
                break;
        }
        return path + File.separator + "java" + File.separator + framePath + File.separator + frontName + codeName
                + File.separator;
    }
 
    /**
     * 获取微服务框架路径
     *
     * @param
     * @return
     * @copyright 引迈信息技术有限公司
     * @date 2023/3/22
     */
    public static String getCloudPath(String houzui, DownloadCodeForm downloadCodeForm) {
        //发起表单
        if ("form".equals(downloadCodeForm.getModule())) {
            return "jnpf-workflow" + File.separator + "jnpf-workflow-form" + File.separator + "jnpf-workflow-" + downloadCodeForm.getModule() + houzui + File.separator
                    + "src" + File.separator + "main" + File.separator + "java" + File.separator + "jnpf" + File.separator + "form";
        }
        String framePath = "jnpf-" + downloadCodeForm.getModule() + File.separator + "jnpf-" + downloadCodeForm.getModule() + houzui + File.separator
                + "src" + File.separator + "main" + File.separator + "java" + File.separator + downloadCodeForm.getModulePackageName();
        return framePath;
    }
 
    /**
     * 获取导出字段
     *
     * @param columnList
     * @return
     */
    public static List<ColumnListField> getExpotColumn(List<ColumnListField> columnList) {
        List<ColumnListField> listOptions = new ArrayList<>();
        columnList.forEach(item -> {
            ColumnListField columnListField = new ColumnListField();
            BeanUtil.copyProperties(item, columnListField);
            if (item.getVModel().toLowerCase().startsWith(JnpfKeyConsts.CHILD_TABLE_PREFIX)) {
                columnListField.setTableType(2);
                columnListField.setVModel(item.getVModel().split("-")[1]);
            } else if (item.getVModel().toLowerCase().contains(JnpfConst.SIDE_MARK)) {
                columnListField.setTableType(1);
                columnListField.setVModel(item.getVModel().split(JnpfConst.SIDE_MARK)[1]);
            } else {
                columnListField.setTableType(0);
            }
            if ("static".equals(item.getConfig().getDataType())) {
                columnListField.setOptions(JsonUtil.getObjectToString(item.getOptions()));
                if (item.getJnpfKey().equals(JnpfKeyConsts.CHECKBOX)) {
                    columnListField.setMultiple(true);
                }
            }
            listOptions.add(columnListField);
        });
        return listOptions;
    }
 
    /**
     * 合计千分位字段列表
     *
     * @param mast      主表字段
     * @param mastTable 副表字段
     * @param type      列表类型 4-行内编辑
     * @return
     */
    public static List<String> getSummaryThousandList(List<FormAllModel> mast, List<FormAllModel> mastTable, Integer type) {
        String suffix = "_name";
        if (type == 4) {
            suffix = "";
        }
        List<String> thousandsField = new ArrayList<>();
        for (FormAllModel f : mast) {
            FieLdsModel fm = f.getFormColumnModel().getFieLdsModel();
            if (fm.isThousands()) {
                thousandsField.add(fm.getVModel() + suffix);
            }
        }
        for (FormAllModel f : mastTable) {
            FieLdsModel fm = f.getFormMastTableModel().getMastTable().getFieLdsModel();
            if (fm.isThousands()) {
                thousandsField.add(f.getFormMastTableModel().getTable() + "." + fm.getVModel() + suffix);
            }
        }
        return thousandsField;
    }
 
    /**
     * 复杂表头 对象生成。
     *
     * @param path
     * @param generateParamModel
     * @param entity
     * @param downloadCodeForm
     * @param objectAll
     */
    public static void createComplexHeaderExcelVo(String path, GenerateParamModel generateParamModel, VisualdevEntity entity,
                                                  DownloadCodeForm downloadCodeForm, Map<String, Object> objectAll) {
        ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class);
        JsonUtil.getListToJsonArray(columnDataModel.getComplexHeaderList());
        List<HeaderModel> complexHeaderList = columnDataModel.getComplexHeaderList();
        String templateName = File.separator + "java" + File.separator + "ExcelVO.java.vm";
        VelocityContext context = new VelocityContext();
        Map<String, Object> object = new HashMap<>();
        object.put("genInfo", generateParamModel.getTemplate7Model());
        object.put("package", generateParamModel.getDownloadCodeForm().getModulePackageName());
        object.put("module", downloadCodeForm.getModule());
        object.put("isMain", true);
        object.put("isComplexVo", true);
        object.put("importFields", objectAll.get("importFields"));
        for (HeaderModel item : complexHeaderList) {
            if (item.getChildColumns().size() > 0) {
                String className = "Complex" + item.getId();
                object.put("complexList", JsonUtil.getListToJsonArray(item.getChildColumns()));
                object.put("className", className);
                context.put("context", object);
                String fileNames = GenerateCommon.getFileName(path, templateName, className, downloadCodeForm);
                GenerateCommon.velocityWriterFile(context, templateName, fileNames);
            }
        }
    }
 
    /**
     * 渲染html模板
     *
     * @param path         路径
     * @param object       模板数据
     * @param templatePath 模板路径
     */
    public static void htmlTemplates(String path, Map<String, Object> object, String templatePath, int type, boolean hasImport,
                                     DownloadCodeForm downloadCodeForm, GenerateInterface codeUtil) throws Exception {
        //获取模板列表
        List<String> templates = codeUtil.getTemplates(templatePath, type, hasImport);
        templates.add(File.separator + "java" + File.separator + "Json.json.vm" );
        //界面模板
        VelocityContext context = new VelocityContext();
        context.put("context", object);
        for (String template : templates) {
            String className = object.get("className").toString();
            String fileNames = GenerateCommon.getFileName(path, template, className, downloadCodeForm);
            GenerateCommon.velocityWriterFile(context, template, fileNames);
        }
    }
 
    /**
     * 根据模板 获取文件名
     *
     * @param path      路径
     * @param template  模板名称
     * @param className 文件名称
     * @return
     */
    public static String getFileName(String path, String template, String className, DownloadCodeForm downloadCodeForm) {
        String framePath = GenerateCommon.getCloudPath("-entity", downloadCodeForm);
        String modelfolder = downloadCodeForm.getMainClassName();
        String modelPath = XSSEscape.escapePath(path + File.separator + "java" + File.separator + framePath + File.separator + "model"
                + File.separator + modelfolder.toLowerCase());
        String htmlPath = XSSEscape.escapePath(path + File.separator + "html" + File.separator + "web" + File.separator + modelfolder.toLowerCase());
        File htmlfile = new File(htmlPath);
        File modelfile = new File(modelPath);
        if (!htmlfile.exists()) {
            htmlfile.mkdirs();
        }
        if (!modelfile.exists()) {
            modelfile.mkdirs();
        }
 
        if (template.contains("extraForm.vue.vm") || template.contains("ExtraForm.vue.vm")) {
            return htmlPath + File.separator + "ExtraForm.vue";
        }
        if (template.contains("Form.vue.vm")) {
            return htmlPath + File.separator + "Form.vue";
        }
        if (template.contains("FormPopup.vue.vm")) {
            return htmlPath + File.separator + "FormPopup.vue";
        }
        if (template.contains("index.vue.vm")) {
            return htmlPath + File.separator + "index.vue";
        }
        if (template.contains("indexEdit.vue.vm")) {
            return htmlPath + File.separator + "index.vue";
        }
        if (template.contains("Detail.vue.vm")) {
            return htmlPath + File.separator + "Detail.vue";
        }
        if (template.contains("api.ts.vm")) {
            //vue3生成ts文件夹
            String htmlTSPath = XSSEscape.escapePath(path + File.separator + "html" + File.separator + "web" + File.separator
                    + modelfolder.toLowerCase() + File.separator + "helper");
            File htmlJSfile = new File(htmlTSPath);
            if (!htmlJSfile.exists() && !"form".equals(downloadCodeForm.getModule())) {
                htmlJSfile.mkdirs();
            }
 
            return htmlPath + File.separator + "helper" + File.separator + "api.ts";
        }
        //后端代码
        if (template.contains("InfoVO.java.vm")) {
            return modelPath + File.separator + className + "InfoVO.java";
        }
        if (template.contains("Form.java.vm")) {
            return modelPath + File.separator + className + "Form.java";
        }
        if (template.contains("ListVO.java.vm")) {
            return modelPath + File.separator + className + "ListVO.java";
        }
        if (template.contains("GroupVO.java.vm")) {
            return modelPath + File.separator + className + "GroupVO.java";
        }
        if (template.contains("Pagination.java.vm")) {
            return modelPath + File.separator + className + "Pagination.java";
        }
        if (template.contains("ExcelVO.java.vm")) {
            return modelPath + File.separator + className + "ExcelVO.java";
        }
        if (template.contains("ExcelErrorVO.java.vm")) {
            return modelPath + File.separator + className + "ExcelErrorVO.java";
        }
        if (template.contains("Model.java.vm")) {
            return modelPath + File.separator + className + "Model.java";
        }
        if (template.contains("ListVO.java.vm")) {
            return modelPath + File.separator + className + "ListVO.java";
        }
        if (template.contains("Constant.java.vm")) {
            return modelPath + File.separator + className + "Constant.java";
        }
        if (template.contains("Json.json.vm")) {
            return modelPath + File.separator + className + "Json.json";
        }
        if (template.contains("Json.json.vm")) {
            return modelPath + File.separator + className + "Json.json";
        }
        return null;
    }
 
    /**
     * 生成代码
     *
     * @param context
     * @param template
     * @param fileNames
     */
    public static void velocityWriterFile(VelocityContext context, String template, String fileNames) {
        try {
            // 渲染模板
            @Cleanup StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate(template, Constants.UTF_8);
            tpl.merge(context, sw);
            if (fileNames != null) {
                File file = new File(XSSEscape.escapePath(fileNames));
                if (!file.exists()) {
                    file.createNewFile();
                }
                @Cleanup FileOutputStream fos = new FileOutputStream(file);
                IOUtils.write(sw.toString(), fos, Constants.UTF_8);
                IOUtils.closeQuietly(sw);
                IOUtils.closeQuietly(fos);
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("渲染模板失败,表名:" + e);
        }
    }
 
    /**
     * 获取接口参数配置,templatejson
     *
     * @param allModels
     * @return
     */
    public static Map<String, Object> getInterTemplateJson(List<FormAllModel> allModels, Map<String, String> childTableKey) {
        Map<String, Object> map = new HashMap<>();
        for (FormAllModel item : allModels) {
            if (FormEnum.mast.getMessage().equals(item.getJnpfKey())) {
                FieLdsModel fieLdsModel = BeanUtil.copyProperties(item.getFormColumnModel().getFieLdsModel(), FieLdsModel.class);
                if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
                    map.put(fieLdsModel.getVModel(), getTemJsonModel(fieLdsModel, childTableKey));
                }
            }
            if (FormEnum.mastTable.getMessage().equals(item.getJnpfKey())) {
                FieLdsModel fieLdsModel = BeanUtil.copyProperties(item.getFormMastTableModel().getMastTable().getFieLdsModel(), FieLdsModel.class);
                if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
                    map.put(item.getFormMastTableModel().getVModel(), getTemJsonModel(fieLdsModel, childTableKey));
                }
            }
            if (FormEnum.table.getMessage().equals(item.getJnpfKey())) {
                List<FormColumnModel> childList = item.getChildList().getChildList();
                for (FormColumnModel columnModel : childList) {
                    FieLdsModel fieLdsModel = BeanUtil.copyProperties(columnModel.getFieLdsModel(), FieLdsModel.class);
                    if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
                        HashMap<String, String> childTableMap = new HashMap<>();
                        childTableMap.put(item.getChildList().getTableModel(), item.getChildList().getAliasLowName());
                        map.put(item.getChildList().getAliasLowName() + fieLdsModel.getVModel(), getTemJsonModel(fieLdsModel, childTableMap));
                    }
                }
            }
        }
        return map;
    }
 
    private static List<TemplateJsonModel> getTemJsonModel(FieLdsModel fieLdsModel, Map<String, String> childTableKey) {
        List<TemplateJsonModel> templateJson = fieLdsModel.getConfig().getTemplateJson();
        List<TemplateJsonModel> json = templateJson.size() > 0 ? templateJson :
                JsonUtil.getJsonToList(fieLdsModel.getTemplateJson(), TemplateJsonModel.class);
        for (TemplateJsonModel t : json) {
            if (t.getRelationField() != null && t.getRelationField().contains("-") && Objects.equals(t.getSourceType(), 1)) {
                String[] split = t.getRelationField().split("-");
                t.setRelationField(childTableKey.get(split[0]) + "List-" + split[1]);
            }
        }
        return json;
    }
 
    /**
     * 获取非系统控件字段
     *
     * @return
     */
    public static List<String> getNotSystemFields(List<FormAllModel> mast, List<FormAllModel> mastTable, List<FormAllModel> childTable,
                                                  GenerateParamModel generateParamModel) {
        List<String> list = new ArrayList<>();
        String table = generateParamModel.getTable();
        boolean mainTable = generateParamModel.isMainTable();
        List<FormColumnModel> fields = new ArrayList<>();
        for (FormAllModel fam : mast) {
            if (mainTable) {
                fields.add(fam.getFormColumnModel());
            }
        }
        for (FormAllModel fam : mastTable) {
            if (table.equals(fam.getFormMastTableModel().getTable())) {
                fields.add(fam.getFormMastTableModel().getMastTable());
            }
        }
        for (FormAllModel fam : childTable) {
            if (table.equals(fam.getChildList().getTableName())) {
                fields.addAll(fam.getChildList().getChildList());
            }
        }
        for (FormColumnModel fcm : fields) {
            if (!JnpfKeyConsts.getSystemKey().contains(fcm.getFieLdsModel().getConfig().getJnpfKey())
                    && StringUtil.isNotEmpty(fcm.getFieLdsModel().getFieldAlias())) {
                list.add(fcm.getFieLdsModel().getFieldAlias().toUpperCase());
            }
        }
        return list;
    }
 
 
    /**
     * 移除对象内的json字符串
     *
     * @param str
     * @return
     */
    public static String objRemoveJson(String str) {
        JSONObject object = JSONObject.parseObject(str);
 
        JSONArray columnList = object.getJSONArray("columnList");
        removeJson(columnList);
        object.put("columnList", columnList);
 
        JSONArray searchList = object.getJSONArray("searchList");
        removeJson(searchList);
        object.put("searchList", searchList);
 
        JSONObject ruleList = object.getJSONObject("ruleList");
        ruleRemoveJson(ruleList);
        object.put("ruleList", ruleList);
 
        JSONObject ruleListApp = object.getJSONObject("ruleListApp");
        ruleRemoveJson(ruleListApp);
        object.put("ruleListApp", ruleListApp);
 
        JSONArray columnOptions = object.getJSONArray("columnOptions");
        removeJson(columnOptions);
        object.put("columnOptions", columnOptions);
 
        JSONArray defaultColumnList = object.getJSONArray("defaultColumnList");
        removeJson(defaultColumnList);
        object.put("defaultColumnList", defaultColumnList);
 
        JSONArray sortList = object.getJSONArray("sortList");
        removeJson(sortList);
        object.put("sortList", sortList);
 
        JSONArray fields = object.getJSONArray("fields");
        removeJson(fields);
        object.put("fields", fields);
 
        object.remove("funcs");
        return JSONObject.toJSONString(object, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
    }
 
    private static void ruleRemoveJson(JSONObject ruleList) {
        if (ruleList != null) {
            JSONArray conditionList = ruleList.getJSONArray("conditionList");
            if (conditionList != null) {
                for (Object o : conditionList) {
                    JSONObject obj = (JSONObject) o;
                    JSONArray groups = obj.getJSONArray("groups");
                    removeJson(groups);
                    obj.put("groups", groups);
                }
                ruleList.put("conditionList", conditionList);
            }
        }
    }
 
    /**
     * 递归移除对应属性
     *
     * @param jsonArray
     */
    public static void removeJson(JSONArray jsonArray) {
        if (jsonArray == null || jsonArray.size() == 0) {
            return;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = (JSONObject) jsonArray.get(i);
            String jnpfkey = jsonObject.getJSONObject("__config__").getString("jnpfKey");
            List<String> childrenListAll = new ArrayList() {{
                add(FormEnum.card.getMessage());
                add(FormEnum.row.getMessage());
                add(FormEnum.tab.getMessage());
                add(FormEnum.collapse.getMessage());
                add(FormEnum.collapseItem.getMessage());
                add(FormEnum.tabItem.getMessage());
                add(FormEnum.tableGrid.getMessage());
                add(FormEnum.tableGridTr.getMessage());
                add(FormEnum.tableGridTd.getMessage());
                add(FormEnum.STEPS.getMessage());
                add(FormEnum.STEP_ITEM.getMessage());
            }};
            if (childrenListAll.contains(jnpfkey) || StringUtil.isEmpty(jnpfkey)) {
                JSONObject config = jsonObject.getJSONObject("__config__");
                config.remove("on");
                JSONArray childArray = config.getJSONArray("children");
                removeJson(childArray);
                config.put("children", childArray);
                jsonObject.put("__config__", config);
            } else if (FormEnum.table.getMessage().equals(jnpfkey)) {
                JSONObject configA = jsonObject.getJSONObject("__config__");
                configA.remove("on");
                JSONArray children = configA.getJSONArray("children");
                for (int k = 0; k < children.size(); k++) {
                    JSONObject childrenObject = (JSONObject) children.get(k);
                    childrenObject.remove("on");
                    JSONObject config = childrenObject.getJSONObject("__config__");
                    config.remove("on");
                    if (!"static".equals(config.get("dataType"))) {
                        childrenObject.remove("options");
                        config.remove("options");
                    }
                    childrenObject.put("__config__", config);
                }
                configA.put("children", children);
                if (!"static".equals(configA.get("dataType"))) {
                    jsonObject.remove("options");
                    configA.remove("options");
                }
                jsonObject.put("__config__", configA);
            }
            jsonObject.remove("on");
            JSONObject config = jsonObject.getJSONObject("__config__");
            config.remove("on");
            if (!"static".equals(config.get("dataType"))) {
                jsonObject.remove("options");
                config.remove("options");
            }
            jsonObject.put("__config__", config);
        }
    }
 
    /**
     * 移除代码生成不支持的对象
     *
     * @param obj
     * @return
     */
    public static String delNotSupport(Object obj) {
        if (obj instanceof JSONArray) {
            List<Object> collect = JsonUtil.getJsonToJsonArray(JsonUtil.getObjectToString(obj)).stream()
                    .filter(t -> !"calculate".equals(JsonUtil.entityToMap(t).get("jnpfKey"))).collect(Collectors.toList());
            return JSONObject.toJSONString(collect, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
        }
        return JSONObject.toJSONString(obj, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
    }
 
    /**
     * 简化前端json
     *
     * @param obj
     * @param columnTtype 列表类型(4行内编辑)
     * @param jsType      js对象类型1-列表,2-查询,3-高级查询
     * @return
     */
    public static String simplifyJson(Object obj, Integer columnTtype, Integer jsType) {
        boolean inlineEdit = columnTtype == 4;//行内编辑
        if (obj instanceof JSONArray) {
            JSONArray jsonArray = new JSONArray();
            for (Object item : JsonUtil.getJsonToJsonArray(JsonUtil.getObjectToString(obj))) {
                JSONObject jsonObject = JSONObject.parseObject(JsonUtil.getObjectToString(item));
                if (!"calculate".equals(jsonObject.getString("jnpfKey"))) {
                    jsonObject.remove("on");
                    jsonObject.remove("style");
                    if (jsType != 1) {
                        jsonObject.remove("placeholder");
                    }
                    if (jsType == 1 && !inlineEdit) {
                        JSONObject config = jsonObject.getJSONObject("__config__");
                        JSONObject newConfig = new JSONObject();
                        newConfig.put("jnpfKey", config.get("jnpfKey"));
                        newConfig.put("label", config.get("label"));
                        newConfig.put("labelI18nCode", config.get("labelI18nCode"));
                        jsonObject.put("__config__", newConfig);
                    } else {
                        JSONObject config = jsonObject.getJSONObject("__config__");
                        JSONObject newConfig = new JSONObject();
                        newConfig.put("jnpfKey", config.get("jnpfKey"));
                        newConfig.put("label", config.get("label"));
                        newConfig.put("propsUrl", config.get("propsUrl"));
                        newConfig.put("dictionaryType", config.get("dictionaryType"));
                        newConfig.put("templateJson", config.get("templateJson"));
                        newConfig.put("dataType", config.getString("dataType"));
                        if (jsType == 2 || jsType == 1) {
                            newConfig.put("labelI18nCode", config.get("labelI18nCode"));
                            newConfig.put("defaultValue", config.getString("defaultValue"));
                        }
                        if(jsType == 3){
                            newConfig.put("tableName", config.get("tableName"));
                            newConfig.put("relationTable", config.getString("relationTable"));
                        }
                        jsonObject.put("__config__", newConfig);
                    }
                    jsonArray.add(jsonObject);
                }
            }
            return JSONObject.toJSONString(jsonArray, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
        }
        return JSONObject.toJSONString(obj, SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
    }
 
    public static String swapRuleFields(SuperJsonModel superJsonModel){
        SuperJsonModel  model= new SuperJsonModel();
        JSONObject obj = JSONObject.parseObject(JsonUtil.getObjectToString(model));
        if(superJsonModel!=null){
            List<SuperQueryJsonModel> conditionList = superJsonModel.getConditionList();
            JSONArray arr = new JSONArray();
            if(CollectionUtil.isNotEmpty(conditionList)){
                for (SuperQueryJsonModel superQueryJsonModel : conditionList) {
                    JSONObject item = JSONObject.parseObject(JsonUtil.getObjectToString(superQueryJsonModel));
                    List<FieLdsModel> groups = superQueryJsonModel.getGroups();
                    List<GenerField> newGroups = new ArrayList<>();
                    if(CollectionUtil.isNotEmpty(groups)){
                        for (FieLdsModel group : groups) {
                            GenerField generField = JsonUtil.getJsonToBean(group, GenerField.class);
                            generField.setOptions(null);
                            generField.setTemplateJson(null);
                            generField.setProps(null);
                            GenerConfig config = new GenerConfig();
                            config.setJnpfKey(group.getConfig().getJnpfKey());
                            config.setTableName(group.getConfig().getTableName());
                            config.setRelationTable(group.getConfig().getRelationTable());
                            generField.setConfig(config);
                            newGroups.add(generField);
                        }
                    }
                    item.put("groups", newGroups);
                    arr.add(item);
                }
                obj.put("conditionList", arr);
            }
        }
        return obj.toJSONString();
    }
}