AppGenUtil.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. package jnpf.base.util.app;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.alibaba.fastjson.serializer.SerializerFeature;
  5. import com.baomidou.mybatisplus.core.toolkit.Constants;
  6. import com.google.common.collect.ImmutableList;
  7. import jnpf.base.entity.VisualdevEntity;
  8. import jnpf.base.model.ColumnDataModel;
  9. import jnpf.base.model.DownloadCodeForm;
  10. import jnpf.base.model.Template6.BtnData;
  11. import jnpf.base.model.Template6.ColumnListField;
  12. import jnpf.base.model.Template7.Template7Model;
  13. import jnpf.base.model.VisualWebTypeEnum;
  14. import jnpf.base.util.common.AliasModel;
  15. import jnpf.base.util.common.DataControlUtils;
  16. import jnpf.base.util.common.GenerateCommon;
  17. import jnpf.base.util.common.SuperQueryUtil;
  18. import jnpf.database.model.superQuery.SuperJsonModel;
  19. import jnpf.i18n.util.I18nUtil;
  20. import jnpf.model.visualJson.*;
  21. import jnpf.model.visualJson.analysis.*;
  22. import jnpf.model.visualJson.config.ConfigModel;
  23. import jnpf.model.visualJson.config.TabConfigModel;
  24. import jnpf.util.JsonUtil;
  25. import jnpf.util.StringUtil;
  26. import jnpf.util.XSSEscape;
  27. import jnpf.util.visiual.JnpfKeyConsts;
  28. import lombok.Cleanup;
  29. import org.apache.commons.io.IOUtils;
  30. import org.apache.velocity.Template;
  31. import org.apache.velocity.VelocityContext;
  32. import org.apache.velocity.app.Velocity;
  33. import java.io.File;
  34. import java.io.FileOutputStream;
  35. import java.io.IOException;
  36. import java.io.StringWriter;
  37. import java.math.BigDecimal;
  38. import java.util.*;
  39. import java.util.stream.Collectors;
  40. public class AppGenUtil {
  41. //+-----------------------------界面2021.8.13------------------------------------------------------------
  42. private List<String> noShow = ImmutableList.of(JnpfKeyConsts.CALCULATE);
  43. public void htmlTemplates(AppGenModel appGenModel) throws IOException {
  44. Map<String, Object> map = new HashMap<>(16);
  45. VisualdevEntity entity = appGenModel.getEntity();
  46. DownloadCodeForm downloadCodeForm = appGenModel.getDownloadCodeForm();
  47. List<FormAllModel> formAllModel = new ArrayList<>();
  48. boolean isView = isView(appGenModel);
  49. Map<String, String> tableNameAll = new HashMap<>();
  50. if (!isView) {
  51. tableNameAll.putAll(this.forDataMode(appGenModel, formAllModel));
  52. }
  53. FormDataModel model = appGenModel.getModel();
  54. List<FormAllModel> mast = this.mast(formAllModel);
  55. List<Map<String, Object>> child = new ArrayList<>();
  56. this.childModel(formAllModel, child, tableNameAll);
  57. this.mastTableModel(formAllModel, map, tableNameAll);
  58. this.templateJson(formAllModel);
  59. map.put("moduleId", appGenModel.getEntity().getId());
  60. map.put("children", child);
  61. map.put("groupTable", appGenModel.getGroupTable());
  62. map.put("type", appGenModel.getType());
  63. map.put("fields", mast);
  64. map.put("package", "jnpf");
  65. map.put("isModel", "true");
  66. map.put("labelSuffix", model.getLabelSuffix());
  67. map.put("flowEnCode", entity.getEnCode());
  68. map.put("flowId", entity.getId());
  69. map.put("webType", entity.getWebType());
  70. map.put("isFlow", Objects.equals(downloadCodeForm.getEnableFlow(), 1));
  71. map.put("module", model.getAreasName());
  72. map.put("className", DataControlUtils.captureName(model.getClassName()));
  73. this.formData(map, appGenModel, formAllModel);
  74. List<String> getTemplate = this.getTemplate(appGenModel);
  75. Template7Model templateModel = appGenModel.getTemplate7Model();
  76. String path = templateModel.getServiceDirectory() + appGenModel.getFileName();
  77. boolean type = this.isForm(appGenModel);
  78. this.htmlTemplates(map, getTemplate, path, DataControlUtils.initialLowercase(model.getClassName()), isView ? false : !type);
  79. }
  80. private void templateJson(List<FormAllModel> formAllModel) {
  81. for (FormAllModel model : formAllModel) {
  82. if (FormEnum.mast.getMessage().equals(model.getJnpfKey())) {
  83. List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
  84. templateJsonAll.addAll(model.getFormColumnModel().getFieLdsModel().getConfig().getTemplateJson());
  85. List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(model.getFormColumnModel().getFieLdsModel().getTemplateJson(), TemplateJsonModel.class);
  86. templateJsonAll.addAll(templateJsonModelList);
  87. model.getFormColumnModel().getFieLdsModel().getConfig().setTemplateJson(templateJsonAll);
  88. }
  89. if (FormEnum.mastTable.getMessage().equals(model.getJnpfKey())) {
  90. List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
  91. templateJsonAll.addAll(model.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig().getTemplateJson());
  92. List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(model.getFormMastTableModel().getMastTable().getFieLdsModel().getTemplateJson(), TemplateJsonModel.class);
  93. templateJsonAll.addAll(templateJsonModelList);
  94. model.getFormMastTableModel().getMastTable().getFieLdsModel().getConfig().setTemplateJson(templateJsonAll);
  95. }
  96. }
  97. }
  98. /**
  99. * 获取模板
  100. *
  101. * @param appGenModel
  102. * @return
  103. */
  104. private List<String> getTemplate(AppGenModel appGenModel) {
  105. String template = this.tempPath(appGenModel);
  106. VisualdevEntity entity = appGenModel.getEntity();
  107. DownloadCodeForm downloadCodeForm = appGenModel.getDownloadCodeForm();
  108. boolean isView = isView(appGenModel);
  109. List<String> templates = new ArrayList<>();
  110. if (isView) {
  111. templates.add(template + File.separator + "app" + File.separator + "index.vue.vm");
  112. } else {
  113. boolean isType = !VisualWebTypeEnum.FORM.getType().equals(entity.getWebType());
  114. templates.add(template + File.separator + "app" + File.separator + "form.vue.vm");
  115. //模板2
  116. if (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType())) {
  117. ColumnDataModel appColumnDataModel = JsonUtil.getJsonToBean(entity.getColumnData(), ColumnDataModel.class);
  118. List<BtnData> columnBtnDataList = JsonUtil.getJsonToList(appColumnDataModel.getColumnBtnsList(), BtnData.class);
  119. boolean detail = columnBtnDataList.stream().filter(t -> "detail".equals(t.getValue())).count() > 0;
  120. if (downloadCodeForm.getEnableFlow() == 0 && isType && detail) {
  121. templates.add(template + File.separator + "app" + File.separator + "detail.vue.vm");
  122. }
  123. }
  124. //除了模板4,其他都有index的模板
  125. boolean index = !(VisualWebTypeEnum.FORM.getType().equals(entity.getWebType()) && downloadCodeForm.getEnableFlow() != 1);
  126. if (index) {
  127. templates.add(template + File.separator + "app" + File.separator + "index.vue.vm");
  128. }
  129. }
  130. return templates;
  131. }
  132. /**
  133. * 获取文件名
  134. *
  135. * @param path 路径
  136. * @param template 模板名称
  137. * @param className 文件名称
  138. * @return
  139. */
  140. private String getFileNames(String path, String template, String className, boolean isIndex) {
  141. path = XSSEscape.escapePath(path);
  142. className = XSSEscape.escapePath(className);
  143. String pathName = className.toLowerCase();
  144. if (template.contains("index.vue.vm") || template.contains("detail.vue.vm")) {
  145. String indexHtmlPath = path + File.separator + "html" + File.separator + "app";
  146. indexHtmlPath += isIndex ? File.separator + "index" + File.separator + pathName : File.separator + pathName;
  147. File indexfile = new File(indexHtmlPath);
  148. if (!indexfile.exists()) {
  149. indexfile.mkdirs();
  150. }
  151. className = template.contains("index.vue.vm") ? "index" : "detail";
  152. return indexHtmlPath + File.separator + className + ".vue";
  153. }
  154. if (template.contains("form.vue.vm")) {
  155. String formHtmlPath = path + File.separator + "html" + File.separator + "app";
  156. formHtmlPath += isIndex ? File.separator + "form" + File.separator + pathName : File.separator + pathName;
  157. File formfile = new File(formHtmlPath);
  158. if (!formfile.exists()) {
  159. formfile.mkdirs();
  160. }
  161. className = isIndex ? "index" : "form";
  162. return formHtmlPath + File.separator + className + ".vue";
  163. }
  164. return null;
  165. }
  166. /**
  167. * 渲染html模板
  168. *
  169. * @param path 路径
  170. * @param object 模板数据
  171. * @param path 模板路径
  172. */
  173. private void htmlTemplates(Object object, List<String> templates, String path, String className, boolean isIndex) {
  174. //界面模板
  175. VelocityContext context = new VelocityContext();
  176. context.put("context", object);
  177. for (String template : templates) {
  178. // 渲染模板
  179. try {
  180. @Cleanup StringWriter sw = new StringWriter();
  181. Template tpl = Velocity.getTemplate(template, Constants.UTF_8);
  182. tpl.merge(context, sw);
  183. String fileNames = getFileNames(path, template, className, isIndex);
  184. if (fileNames != null) {
  185. File file = new File(fileNames);
  186. if (!file.exists()) {
  187. file.createNewFile();
  188. }
  189. @Cleanup FileOutputStream fos = new FileOutputStream(file);
  190. IOUtils.write(sw.toString(), fos, Constants.UTF_8);
  191. IOUtils.closeQuietly(sw);
  192. IOUtils.closeQuietly(fos);
  193. }
  194. } catch (IOException e) {
  195. e.printStackTrace();
  196. System.out.println("渲染模板失败,表名:" + e);
  197. }
  198. }
  199. }
  200. /**
  201. * 封装主表数据
  202. */
  203. private List<FormAllModel> mast(List<FormAllModel> formAllModel) {
  204. List<FormAllModel> mast = formAllModel.stream().filter(t -> FormEnum.mast.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  205. //主表赋值
  206. for (int i = 0; i < mast.size(); i++) {
  207. FieLdsModel fieLdsModel = mast.get(i).getFormColumnModel().getFieLdsModel();
  208. this.model(fieLdsModel);
  209. String vmodel = fieLdsModel.getVModel();
  210. if (StringUtil.isEmpty(vmodel)) {
  211. mast.remove(i);
  212. i--;
  213. }
  214. }
  215. return mast;
  216. }
  217. /**
  218. * 封装mastTable数据
  219. */
  220. private Map<String, List<FormAllModel>> mastTableModel(List<FormAllModel> formAllModel, Map<String, Object> map, Map<String, String> tableNameAll) {
  221. List<FormAllModel> mastTable = formAllModel.stream().filter(t -> FormEnum.mastTable.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  222. Map<String, List<FormAllModel>> mastListAll = mastTable.stream().collect(Collectors.groupingBy(e -> e.getFormMastTableModel().getTable()));
  223. Map<String, String> mastTableNameAll = new HashMap<>();
  224. Map<String, List<FormAllModel>> mastTableList = new HashMap<>();
  225. //表单主表
  226. for (String mastkey : mastListAll.keySet()) {
  227. List<FormAllModel> mastList = mastListAll.get(mastkey);
  228. for (FormAllModel fieLdsList : mastList) {
  229. FieLdsModel fieLdsModel = fieLdsList.getFormMastTableModel().getMastTable().getFieLdsModel();
  230. this.model(fieLdsModel);
  231. }
  232. mastListAll.put(mastkey, mastList);
  233. String tableName = tableNameAll.get(mastkey);
  234. String name = tableName.substring(0, 1).toUpperCase() + tableName.substring(1);
  235. mastTableNameAll.put(mastkey, name);
  236. mastTableList.put(tableName.toLowerCase(), mastList);
  237. }
  238. map.put("mastTableName", mastTableNameAll);
  239. map.put("tableName", tableNameAll);
  240. map.put("mastTable", mastTableList);
  241. return mastListAll;
  242. }
  243. /**
  244. * 封装子表数据
  245. */
  246. private void childModel(List<FormAllModel> formAllModel, List<Map<String, Object>> child, Map<String, String> tableNameAll) {
  247. List<FormAllModel> table = formAllModel.stream().filter(t -> FormEnum.table.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  248. for (FormAllModel formModel : table) {
  249. FormColumnTableModel childList = formModel.getChildList();
  250. List<String> thousandsField = new ArrayList<>();
  251. List<String> summaryField = new ArrayList<>();
  252. Map<String, Object> summaryFieldName = new HashMap<>();
  253. String tableName = childList.getTableName();
  254. List<String> summaryFieldAll = JsonUtil.getJsonToList(childList.getSummaryField(), String.class);
  255. String name = tableNameAll.get(tableName);
  256. String className = name.substring(0, 1).toLowerCase() + name.substring(1);
  257. List<FormColumnModel> tableList = childList.getChildList();
  258. List<FormColumnModel> childFieldList = new ArrayList<>();
  259. for (int i = 0; i < tableList.size(); i++) {
  260. FormColumnModel columnModel = tableList.get(i);
  261. FieLdsModel fieLdsModel = columnModel.getFieLdsModel();
  262. ConfigModel config = fieLdsModel.getConfig();
  263. model(fieLdsModel);
  264. if (fieLdsModel.isThousands()) {
  265. thousandsField.add(fieLdsModel.getVModel());
  266. }
  267. if (!fieLdsModel.getConfig().getNoShow() && summaryFieldAll.contains(fieLdsModel.getVModel())) {
  268. summaryField.add(fieLdsModel.getVModel());
  269. summaryFieldName.put(fieLdsModel.getVModel(),config.getLabel());
  270. if(StringUtil.isNotEmpty(config.getLabelI18nCode())){
  271. summaryFieldName.put(fieLdsModel.getVModel() +"_i18n", config.getLabelI18nCode());
  272. }
  273. }
  274. List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
  275. templateJsonAll.addAll(fieLdsModel.getConfig().getTemplateJson());
  276. List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(fieLdsModel.getTemplateJson(), TemplateJsonModel.class);
  277. templateJsonAll.addAll(templateJsonModelList);
  278. for (TemplateJsonModel templateJsonModel : templateJsonAll) {
  279. if (StringUtil.isNotEmpty(templateJsonModel.getRelationField()) && Objects.equals(templateJsonModel.getSourceType(), 1)) {
  280. String[] fieldList = templateJsonModel.getRelationField().split("-");
  281. if (fieldList.length > 1) {
  282. templateJsonModel.setRelationField(className + "-" + fieldList[1]);
  283. }
  284. }
  285. }
  286. for (TemplateJsonModel templateJsonModel : templateJsonModelList) {
  287. if (StringUtil.isNotEmpty(templateJsonModel.getRelationField()) && Objects.equals(templateJsonModel.getSourceType(), 1)) {
  288. String[] fieldList = templateJsonModel.getRelationField().split("-");
  289. if (fieldList.length > 1) {
  290. templateJsonModel.setRelationField(className + "List-" + fieldList[1]);
  291. }
  292. }
  293. }
  294. fieLdsModel.setTemplateJson(JsonUtil.getObjectToString(templateJsonModelList));
  295. fieLdsModel.getConfig().setTemplateJson(templateJsonAll);
  296. //修改弹窗的子表默认数据
  297. FieLdsModel childField = JsonUtil.getJsonToBean(fieLdsModel, FieLdsModel.class);
  298. ConfigModel configModel = JsonUtil.getJsonToBean(config, ConfigModel.class);
  299. Object defaultValue = configModel.getDefaultValue();
  300. if (defaultValue instanceof String) {
  301. defaultValue = "";
  302. } else if (defaultValue instanceof BigDecimal) {
  303. defaultValue = 0;
  304. } else if (defaultValue instanceof List) {
  305. defaultValue = new ArrayList<>();
  306. }
  307. configModel.setDefaultValue(defaultValue);
  308. childField.setConfig(configModel);
  309. FormColumnModel childColumn = new FormColumnModel();
  310. childColumn.setFieLdsModel(childField);
  311. childFieldList.add(childColumn);
  312. }
  313. childList.setThousandsField(thousandsField);
  314. childList.setSummaryField(JsonUtil.getObjectToString(summaryField));
  315. childList.setSummaryFieldName(JsonUtil.getObjectToString(summaryFieldName));
  316. childList.setChildList(tableList);
  317. childList.setChildFieldList(childFieldList);
  318. Map<String, Object> childs = JsonUtil.entityToMap(childList);
  319. childs.put("className", className);
  320. childs.put("children", childList);
  321. child.add(childs);
  322. }
  323. }
  324. /**
  325. * 封装model数据
  326. */
  327. private void model(FieLdsModel fieLdsModel) {
  328. ConfigModel configModel = fieLdsModel.getConfig();
  329. String jnpfKey = configModel.getJnpfKey();
  330. if (configModel.getDefaultValue() instanceof String) {
  331. configModel.setValueType("String");
  332. }
  333. if (configModel.getDefaultValue() == null) {
  334. configModel.setValueType("undefined");
  335. if (JnpfKeyConsts.ADDRESS.equals(jnpfKey)) {
  336. configModel.setDefaultValue(new ArrayList<>());
  337. configModel.setValueType(null);
  338. }
  339. }
  340. if (JnpfKeyConsts.SWITCH.equals(jnpfKey)) {
  341. if (configModel.getDefaultValue() instanceof Boolean) {
  342. Boolean defaultValue = (Boolean) configModel.getDefaultValue();
  343. configModel.setDefaultValue(defaultValue ? 1 : 0);
  344. }
  345. }
  346. if (JnpfKeyConsts.TREESELECT.equals(jnpfKey)) {
  347. configModel.setValueType(fieLdsModel.getMultiple() ? configModel.getValueType() : "undefined");
  348. }
  349. fieLdsModel.setConfig(configModel);
  350. }
  351. /**
  352. * 封装页面数据
  353. */
  354. private void formData(Map<String, Object> map, AppGenModel appGenModel, List<FormAllModel> formAllModel) throws IOException {
  355. FormDataModel model = appGenModel.getModel();
  356. //界面
  357. map.put("formRef", model.getFormRef());
  358. map.put("hasConfirmAndAddBtn", false);
  359. map.put("formModel", model.getFormModel());
  360. map.put("size", model.getSize());
  361. map.put("labelPosition", model.getLabelPosition());
  362. map.put("labelWidth", model.getLabelWidth());
  363. map.put("formRules", model.getFormRules());
  364. map.put("gutter", model.getGutter());
  365. map.put("disabled", model.getDisabled());
  366. map.put("span", model.getSpan());
  367. map.put("formBtns", model.getFormBtns());
  368. map.put("idGlobal", model.getIdGlobal());
  369. map.put("popupType", model.getPopupType());
  370. map.put("form", formAllModel);
  371. //列表
  372. boolean isPage = this.isPage(appGenModel);
  373. boolean type = this.isForm(appGenModel);
  374. boolean isView = this.isView(appGenModel);
  375. if (isPage) {
  376. List<BtnData> columnList = new ArrayList<>();
  377. String page = "1";
  378. String sort = "";
  379. String defaultSidx = "";
  380. int pageSize = 20;
  381. boolean thousands = false;
  382. SuperJsonModel ruleQueryJson = new SuperJsonModel();
  383. VisualdevEntity entity = appGenModel.getEntity();
  384. if (StringUtil.isNotEmpty(entity.getColumnData())) {
  385. String columnData = entity.getColumnData();
  386. ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData, ColumnDataModel.class);
  387. page = columnDataModel.getHasPage() ? "0" : "1";
  388. sort = columnDataModel.getSort();
  389. pageSize = columnDataModel.getPageSize();
  390. defaultSidx = columnDataModel.getDefaultSidx();
  391. thousands = columnDataModel.isThousands();
  392. this.columnData(formAllModel, columnDataModel, map);
  393. List<BtnData> btns = StringUtil.isNotEmpty(columnDataModel.getBtnsList()) ? JsonUtil.getJsonToList(columnDataModel.getBtnsList(), BtnData.class) : new ArrayList<>();
  394. btns.addAll(StringUtil.isNotEmpty(columnDataModel.getColumnBtnsList()) ? JsonUtil.getJsonToList(columnDataModel.getColumnBtnsList(), BtnData.class) : new ArrayList<>());
  395. columnList.addAll(btns.stream().filter(t -> t.isShow()).collect(Collectors.toList()));
  396. ruleQueryJson = columnDataModel.getRuleListApp();
  397. Template7Model templateModel = appGenModel.getTemplate7Model();
  398. String path = templateModel.getServiceDirectory() + appGenModel.getFileName();
  399. boolean index = isView ? false : !type;
  400. String columnPath = path + File.separator + "html" + File.separator + "app" + File.separator + (index ? "index" + File.separator : "") + model.getClassName().toLowerCase() + File.separator;
  401. File indexfile = new File(columnPath);
  402. if (!indexfile.exists()) {
  403. indexfile.mkdirs();
  404. }
  405. String jsonString = JSONObject.toJSONString(JsonUtil.getJsonToJsonArray(columnDataModel.getColumnList()), SerializerFeature.WriteMapNullValue, SerializerFeature.PrettyFormat);
  406. SuperQueryUtil.CreateJsFile(jsonString, columnPath + "columnList.js", "columnList");
  407. }
  408. //合计千分位
  409. List<FormAllModel> mast = formAllModel.stream().filter(t -> FormEnum.mast.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  410. List<FormAllModel> mastTable = formAllModel.stream().filter(t -> FormEnum.mastTable.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  411. List<String> thousandsField = GenerateCommon.getSummaryThousandList(mast, mastTable, 4);
  412. map.put("page", page);
  413. map.put("sort", sort);
  414. map.put("defaultSidx", defaultSidx);
  415. map.put("pageSize", pageSize);
  416. map.put("columnBtnsList", columnList);
  417. map.put("thousands", thousands);
  418. map.put("thousandsField", JsonUtil.getObjectToString(thousandsField));
  419. map.put("ruleQueryJson", JSONObject.toJSONString(ruleQueryJson));
  420. }
  421. //共用
  422. String pKeyName = appGenModel.getPKeyName();
  423. map.put("pKeyName", pKeyName);
  424. }
  425. /**
  426. * 封装列表数据
  427. */
  428. private void columnData(List<FormAllModel> formAllModel, ColumnDataModel columnDataModel, Map<String, Object> map) {
  429. List<FormAllModel> mast = formAllModel.stream().filter(t -> FormEnum.mast.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  430. List<FormAllModel> mastTable = formAllModel.stream().filter(t -> FormEnum.mastTable.getMessage().equals(t.getJnpfKey())).collect(Collectors.toList());
  431. //显示数据
  432. List<ColumnListField> columnListAll = JsonUtil.getJsonToList(columnDataModel.getColumnList(), ColumnListField.class);
  433. Map<String, List<FormAllModel>> mastTableList = new HashMap<>();
  434. Map<String, List<ColumnListField>> childColumnList = new HashMap<>();
  435. List<ColumnListField> columnMastList = new ArrayList<>();
  436. for (ColumnListField columnList : columnListAll) {
  437. String prop = columnList.getProp();
  438. FormAllModel model = mastTable.stream().filter(t -> t.getFormMastTableModel().getVModel().equals(prop)).findFirst().orElse(null);
  439. if (model == null) {
  440. String[] split = prop.split("-");
  441. if (split.length == 1) {
  442. columnMastList.add(columnList);
  443. } else {
  444. List<ColumnListField> childList = childColumnList.get(split[0]) != null ? childColumnList.get(split[0]) : new ArrayList<>();
  445. String vModel = split[1];
  446. columnList.setVModel(vModel);
  447. childList.add(columnList);
  448. childColumnList.put(split[0], childList);
  449. }
  450. } else {
  451. FormMastTableModel formMastTableModel = model.getFormMastTableModel();
  452. String tableName = formMastTableModel.getTable();
  453. List<FormAllModel> columnListList = mastTableList.get(tableName) != null ? mastTableList.get(tableName) : new ArrayList<>();
  454. model.setFormMastTableModel(formMastTableModel);
  455. columnListList.add(model);
  456. mastTableList.put(tableName, columnListList);
  457. }
  458. }
  459. map.put("childColumnList", childColumnList);
  460. map.put("columnList", columnMastList);
  461. map.put("columnMastList", mastTableList);
  462. map.put("AppColumnList", columnDataModel.getColumnList());
  463. //排序
  464. List<ColumnListField> sortListAll = columnListAll.stream().filter(t -> t.getSortable()).collect(Collectors.toList());
  465. List<ColumnListField> sortList = new ArrayList<>();
  466. for (int i = 0; i < sortListAll.size(); i++) {
  467. ColumnListField field = sortListAll.get(i);
  468. if (!noShow.contains(field.getJnpfKey())) {
  469. sortList.add(field);
  470. }
  471. }
  472. map.put("sortList", sortList);
  473. map.put("defaultSortConfig", columnDataModel.getDefaultSortConfig());
  474. //搜索
  475. List<FieLdsModel> searchVOListAll = JsonUtil.getJsonToList(columnDataModel.getSearchList(), FieLdsModel.class);
  476. List<FieLdsModel> searchVOList = new ArrayList<>();
  477. List<FieLdsModel> mastTableSearch = new ArrayList<>();
  478. List<FieLdsModel> childSearch = new ArrayList<>();
  479. List<FieLdsModel> mastSearch = new ArrayList<>();
  480. List<Map<String, Object>> searchAll = new LinkedList<>();
  481. List<Map<String, Object>> tabSearch = new LinkedList<>();
  482. int isTab = 0;
  483. for (FieLdsModel columnSearch : searchVOListAll) {
  484. List<TemplateJsonModel> templateJsonAll = new ArrayList<>();
  485. ConfigModel config = columnSearch.getConfig();
  486. templateJsonAll.addAll(config.getTemplateJson());
  487. List<TemplateJsonModel> templateJsonModelList = JsonUtil.getJsonToList(columnSearch.getTemplateJson(), TemplateJsonModel.class);
  488. templateJsonAll.addAll(templateJsonModelList);
  489. config.setTemplateJson(templateJsonAll);
  490. Map<String, Object> column = new HashMap<>();
  491. String vmodel = columnSearch.getId();
  492. boolean isMast = mast.stream().filter(t -> vmodel.equals(t.getFormColumnModel().getFieLdsModel().getVModel())).count() > 0;
  493. boolean isMastTable = mastTable.stream().filter(t -> vmodel.equals(t.getFormMastTableModel().getVModel())).count() > 0;
  494. Object value = columnSearch.getValue();
  495. if (value instanceof String) {
  496. config.setValueType("String");
  497. }
  498. if (isMast) {
  499. column.put("key", "mastSearch");
  500. mastSearch.add(columnSearch);
  501. } else if (isMastTable) {
  502. column.put("key", "mastTableSearch");
  503. mastTableSearch.add(columnSearch);
  504. } else {
  505. columnSearch.setVModel(vmodel.replaceAll("-", "_"));
  506. column.put("key", "childSearch");
  507. childSearch.add(columnSearch);
  508. }
  509. column.put("html", columnSearch);
  510. if (!noShow.contains(config.getJnpfKey())) {
  511. searchVOList.add(columnSearch);
  512. searchAll.add(column);
  513. }
  514. }
  515. TabConfigModel tabConfig = ObjectUtil.isNotEmpty(columnDataModel.getTabConfig()) ? columnDataModel.getTabConfig() : new TabConfigModel();
  516. String fieldsModel = tabConfig.getRelationField();
  517. if (tabConfig.isOn() && StringUtil.isNotEmpty(fieldsModel)) {
  518. for (FormAllModel item : mast) {
  519. FieLdsModel fieLdsModel = item.getFormColumnModel().getFieLdsModel();
  520. if (fieLdsModel.getVModel().equals(fieldsModel)) {
  521. Map<String, Object> column = new HashMap<>();
  522. column.put("key", "tab");
  523. column.put("html", fieLdsModel);
  524. tabSearch.add(column);
  525. isTab++;
  526. }
  527. }
  528. for (FormAllModel item : mastTable) {
  529. FieLdsModel mastTableModel = item.getFormMastTableModel().getMastTable().getFieLdsModel();
  530. if (mastTableModel.getVModel().equals(fieldsModel)) {
  531. Map<String, Object> column = new HashMap<>();
  532. column.put("key", "tab");
  533. column.put("html", mastTableModel);
  534. tabSearch.add(column);
  535. isTab++;
  536. }
  537. }
  538. }
  539. map.put("tabSearch", tabSearch);
  540. map.put("hasAllTab", isTab > 0 ? tabConfig.isHasAllTab() : false);
  541. map.put("isTab", isTab > 0);
  542. //关键词搜索
  543. map.put("isKeyword", searchVOList.stream().filter(t -> t.getIsKeyword()).count() > 0);
  544. map.put("searchAll", searchAll);
  545. map.put("searchList", mastTableSearch);
  546. map.put("childSearch", childSearch);
  547. map.put("mastsearchList", mastSearch);
  548. map.put("useDataPermission", columnDataModel.getUseDataPermission() != null ? columnDataModel.getUseDataPermission() : false);
  549. map.put("useBtnPermission", columnDataModel.getUseBtnPermission() != null ? columnDataModel.getUseBtnPermission() : false);
  550. map.put("useFormPermission", columnDataModel.getUseFormPermission() != null ? columnDataModel.getUseFormPermission() : false);
  551. map.put("useColumnPermission", columnDataModel.getUseColumnPermission() != null ? columnDataModel.getUseColumnPermission() : false);
  552. }
  553. //----------------------------代码-------------------------------------------------------
  554. /**
  555. * 封装数据
  556. *
  557. * @param formAllModel
  558. */
  559. private Map<String, String> forDataMode(AppGenModel appGenModel, List<FormAllModel> formAllModel) {
  560. VisualdevEntity entity = appGenModel.getEntity();
  561. //formTempJson
  562. FormDataModel formData = JsonUtil.getJsonToBean(entity.getFormData(), FormDataModel.class);
  563. List<FieLdsModel> list = JsonUtil.getJsonToList(formData.getFields(), FieLdsModel.class);
  564. List<TableModel> tableModelList = JsonUtil.getJsonToList(entity.getVisualTables(), TableModel.class);
  565. RecursionForm recursionForm = new RecursionForm(list, tableModelList);
  566. List<FormAllModel> formAllModelAll = new ArrayList<>();
  567. FormCloumnUtil.recursionFormGen(recursionForm, formAllModelAll);
  568. for (FormAllModel allModel : formAllModelAll) {
  569. boolean add = true;
  570. if (FormEnum.mast.getMessage().equals(allModel.getJnpfKey())) {
  571. FieLdsModel fieLdsModel = allModel.getFormColumnModel().getFieLdsModel();
  572. add = !noShow.contains(fieLdsModel.getConfig().getJnpfKey());
  573. if (ObjectUtil.isNotEmpty(fieLdsModel.getConfig().getTipLabel())) {
  574. String tipLabel = fieLdsModel.getConfig().getTipLabel().replaceAll("\n", " ");
  575. fieLdsModel.getConfig().setTipLabel(tipLabel);
  576. }
  577. }
  578. if (FormEnum.mastTable.getMessage().equals(allModel.getJnpfKey())) {
  579. FieLdsModel fieLdsModel = allModel.getFormMastTableModel().getMastTable().getFieLdsModel();
  580. add = !noShow.contains(fieLdsModel.getConfig().getJnpfKey());
  581. if (ObjectUtil.isNotEmpty(fieLdsModel.getConfig().getTipLabel())) {
  582. String tipLabel = fieLdsModel.getConfig().getTipLabel().replaceAll("\n", " ");
  583. fieLdsModel.getConfig().setTipLabel(tipLabel);
  584. }
  585. }
  586. if (FormEnum.table.getMessage().equals(allModel.getJnpfKey())) {
  587. List<FormColumnModel> childListAll = allModel.getChildList().getChildList();
  588. List<FormColumnModel> childList = new ArrayList<>();
  589. for (int k = 0; k < childListAll.size(); k++) {
  590. FormColumnModel formColumnModel = childListAll.get(k);
  591. FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
  592. if (ObjectUtil.isNotEmpty(fieLdsModel.getConfig().getTipLabel())) {
  593. String tipLabel = fieLdsModel.getConfig().getTipLabel().replaceAll("\n", " ");
  594. fieLdsModel.getConfig().setTipLabel(tipLabel);
  595. }
  596. if (!noShow.contains(fieLdsModel.getConfig().getJnpfKey())) {
  597. childList.add(formColumnModel);
  598. }
  599. }
  600. allModel.getChildList().setChildList(childList);
  601. }
  602. if (add) {
  603. formAllModel.add(allModel);
  604. }
  605. }
  606. Map<String, String> tableNameAll = new HashMap<>();
  607. Map<String, AliasModel> tableAliseMap = appGenModel.getTableAliseMap();
  608. for (String key : tableAliseMap.keySet()) {
  609. tableNameAll.put(key, tableAliseMap.get(key).getAliasName());
  610. }
  611. return tableNameAll;
  612. }
  613. private String tempPath(AppGenModel appGenModel) {
  614. String tempPath = appGenModel.getTemplatePath();
  615. VisualdevEntity entity = appGenModel.getEntity();
  616. DownloadCodeForm downloadCodeForm = appGenModel.getDownloadCodeForm();
  617. boolean isView = isView(appGenModel);
  618. if (isView) {
  619. tempPath = "TemplateCode2";
  620. } else {
  621. if (VisualWebTypeEnum.FORM.getType().equals(entity.getWebType())) {
  622. tempPath = downloadCodeForm.getEnableFlow() == 1 ? "TemplateCode5" : "TemplateCode4";
  623. } else if (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType())) {
  624. tempPath = downloadCodeForm.getEnableFlow() == 1 ? "TemplateCode3" : "TemplateCode2";
  625. }
  626. }
  627. return tempPath;
  628. }
  629. private boolean isPage(AppGenModel appGenModel) {
  630. VisualdevEntity entity = appGenModel.getEntity();
  631. boolean type = !VisualWebTypeEnum.FORM.getType().equals(entity.getWebType());
  632. return type;
  633. }
  634. private boolean isForm(AppGenModel appGenModel) {
  635. VisualdevEntity entity = appGenModel.getEntity();
  636. boolean type = (VisualWebTypeEnum.FORM_LIST.getType().equals(entity.getWebType()) && appGenModel.getDownloadCodeForm().getEnableFlow() == 0);
  637. return type;
  638. }
  639. private boolean isView(AppGenModel appGenModel) {
  640. VisualdevEntity entity = appGenModel.getEntity();
  641. boolean type = VisualWebTypeEnum.DATA_VIEW.getType().equals(entity.getWebType());
  642. return type;
  643. }
  644. }