| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- 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.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.base.service.PrintDevService;
- 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.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 = "single";
- private static PrintDevService printDevService = SpringContext.getBean(PrintDevService.class);
- public static String getLocalBasePath() {
- return FileUploadUtils.getLocalBasePath();
- }
- public static String getPath(String type) {
- return FilePathUtil.getFilePath(type);
- }
- public static List<PrintOption> getList(List<String> ids) {
- return printDevService.getPrintTemplateOptions(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";
- }
- 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);
- }
- 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();
- }
- }
|