| | |
| | | package com.ruoyi.generator.util; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Dict; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.ruoyi.common.constant.GenConstants; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | |
| | | import com.ruoyi.generator.domain.GenTableColumn; |
| | | import org.apache.velocity.VelocityContext; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 模板处理工具类 |
| | |
| | | |
| | | public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { |
| | | String options = genTable.getOptions(); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(options); |
| | | Dict paramsObj = JsonUtils.parseMap(options); |
| | | String parentMenuId = getParentMenuId(paramsObj); |
| | | context.put("parentMenuId", parentMenuId); |
| | | } |
| | | |
| | | public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { |
| | | String options = genTable.getOptions(); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(options); |
| | | Dict paramsObj = JsonUtils.parseMap(options); |
| | | String treeCode = getTreecode(paramsObj); |
| | | String treeParentCode = getTreeParentCode(paramsObj); |
| | | String treeName = getTreeName(paramsObj); |
| | |
| | | */ |
| | | public static String getPackagePrefix(String packageName) { |
| | | int lastIndex = packageName.lastIndexOf("."); |
| | | String basePackage = StringUtils.substring(packageName, 0, lastIndex); |
| | | return basePackage; |
| | | return StringUtils.substring(packageName, 0, lastIndex); |
| | | } |
| | | |
| | | /** |
| | |
| | | List<GenTableColumn> columns = genTable.getColumns(); |
| | | GenTable subGenTable = genTable.getSubTable(); |
| | | HashSet<String> importList = new HashSet<String>(); |
| | | if (StringUtils.isNotNull(subGenTable)) { |
| | | if (ObjectUtil.isNotNull(subGenTable)) { |
| | | importList.add("java.util.List"); |
| | | } |
| | | for (GenTableColumn column : columns) { |
| | |
| | | */ |
| | | public static String getDicts(GenTable genTable) { |
| | | List<GenTableColumn> columns = genTable.getColumns(); |
| | | List<String> dicts = new ArrayList<String>(); |
| | | Set<String> dicts = new HashSet<String>(); |
| | | for (GenTableColumn column : columns) { |
| | | if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( |
| | | column.getHtmlType(), new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO})) { |
| | | column.getHtmlType(), |
| | | new String[]{GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX})) { |
| | | dicts.add("'" + column.getDictType() + "'"); |
| | | } |
| | | } |
| | |
| | | * @param paramsObj 生成其他选项 |
| | | * @return 上级菜单ID字段 |
| | | */ |
| | | public static String getParentMenuId(Map<String, Object> paramsObj) { |
| | | if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) |
| | | && StringUtils.isNotEmpty(Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)))) { |
| | | return Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID)); |
| | | public static String getParentMenuId(Dict paramsObj) { |
| | | if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID) |
| | | && StringUtils.isNotEmpty(paramsObj.getStr(GenConstants.PARENT_MENU_ID))) { |
| | | return paramsObj.getStr(GenConstants.PARENT_MENU_ID); |
| | | } |
| | | return DEFAULT_PARENT_MENU_ID; |
| | | } |
| | |
| | | * @return 树编码 |
| | | */ |
| | | public static String getTreecode(Map<String, Object> paramsObj) { |
| | | if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) { |
| | | if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE)) { |
| | | return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE))); |
| | | } |
| | | return StringUtils.EMPTY; |
| | |
| | | * @param paramsObj 生成其他选项 |
| | | * @return 树父编码 |
| | | */ |
| | | public static String getTreeParentCode(Map<String, Object> paramsObj) { |
| | | if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { |
| | | return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE))); |
| | | public static String getTreeParentCode(Dict paramsObj) { |
| | | if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { |
| | | return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_PARENT_CODE)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | } |
| | |
| | | * @param paramsObj 生成其他选项 |
| | | * @return 树名称 |
| | | */ |
| | | public static String getTreeName(Map<String, Object> paramsObj) { |
| | | if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { |
| | | return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME))); |
| | | public static String getTreeName(Dict paramsObj) { |
| | | if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { |
| | | return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME)); |
| | | } |
| | | return StringUtils.EMPTY; |
| | | } |
| | |
| | | */ |
| | | public static int getExpandColumn(GenTable genTable) { |
| | | String options = genTable.getOptions(); |
| | | Map<String, Object> paramsObj = JsonUtils.parseMap(options); |
| | | String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)); |
| | | Dict paramsObj = JsonUtils.parseMap(options); |
| | | String treeName = paramsObj.getStr(GenConstants.TREE_NAME); |
| | | int num = 0; |
| | | for (GenTableColumn column : genTable.getColumns()) { |
| | | if (column.isList()) { |