| | |
| | | import java.util.ArrayList;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import org.apache.velocity.VelocityContext;
|
| | | import com.alibaba.fastjson.JSONObject;
|
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.alibaba.fastjson2.JSONObject;
|
| | | import com.ruoyi.common.constant.GenConstants;
|
| | | import com.ruoyi.common.utils.DateUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | |
| | |
|
| | | /**
|
| | | * 设置模板变量信息
|
| | | * |
| | | *
|
| | | * @return 模板列表
|
| | | */
|
| | | public static VelocityContext prepareContext(GenTable genTable)
|
| | |
| | | public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
|
| | | {
|
| | | String options = genTable.getOptions();
|
| | | JSONObject paramsObj = JSONObject.parseObject(options);
|
| | | JSONObject paramsObj = JSON.parseObject(options);
|
| | | String parentMenuId = getParentMenuId(paramsObj);
|
| | | context.put("parentMenuId", parentMenuId);
|
| | | }
|
| | |
| | | public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
|
| | | {
|
| | | String options = genTable.getOptions();
|
| | | JSONObject paramsObj = JSONObject.parseObject(options);
|
| | | JSONObject paramsObj = JSON.parseObject(options);
|
| | | String treeCode = getTreecode(paramsObj);
|
| | | String treeParentCode = getTreeParentCode(paramsObj);
|
| | | String treeName = getTreeName(paramsObj);
|
| | |
| | | context.put("subclassName", StringUtils.uncapitalize(subClassName));
|
| | | context.put("subImportList", getImportList(genTable.getSubTable()));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取模板信息
|
| | | * |
| | | * @param tplCategory 生成的模板
|
| | | * @param tplWebType 前端类型
|
| | | * @return 模板列表
|
| | | */
|
| | | public static List<String> getTemplateList(String tplCategory)
|
| | | public static List<String> getTemplateList(String tplCategory, String tplWebType)
|
| | | {
|
| | | String useWebType = "vm/vue";
|
| | | if ("element-plus".equals(tplWebType))
|
| | | {
|
| | | useWebType = "vm/vue/v3";
|
| | | }
|
| | | List<String> templates = new ArrayList<String>();
|
| | | templates.add("vm/java/domain.java.vm");
|
| | | templates.add("vm/java/mapper.java.vm");
|
| | |
| | | templates.add("vm/js/api.js.vm");
|
| | | if (GenConstants.TPL_CRUD.equals(tplCategory))
|
| | | {
|
| | | templates.add("vm/vue/index.vue.vm");
|
| | | templates.add(useWebType + "/index.vue.vm");
|
| | | }
|
| | | else if (GenConstants.TPL_TREE.equals(tplCategory))
|
| | | {
|
| | | templates.add("vm/vue/index-tree.vue.vm");
|
| | | templates.add(useWebType + "/index-tree.vue.vm");
|
| | | }
|
| | | else if (GenConstants.TPL_SUB.equals(tplCategory))
|
| | | {
|
| | | templates.add("vm/vue/index.vue.vm");
|
| | | templates.add(useWebType + "/index.vue.vm");
|
| | | templates.add("vm/java/sub-domain.java.vm");
|
| | | }
|
| | | return templates;
|
| | |
| | |
|
| | | /**
|
| | | * 获取包前缀
|
| | | * |
| | | *
|
| | | * @param packageName 包名称
|
| | | * @return 包前缀名称
|
| | | */
|
| | | 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);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public static String getDicts(GenTable genTable)
|
| | | {
|
| | | List<GenTableColumn> columns = genTable.getColumns();
|
| | | List<String> dicts = new ArrayList<String>();
|
| | | Set<String> dicts = new HashSet<String>();
|
| | | addDicts(dicts, columns);
|
| | | if (StringUtils.isNotNull(genTable.getSubTable()))
|
| | | {
|
| | | List<GenTableColumn> subColumns = genTable.getSubTable().getColumns();
|
| | | addDicts(dicts, subColumns);
|
| | | }
|
| | | return StringUtils.join(dicts, ", ");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加字典列表
|
| | | * |
| | | * @param dicts 字典列表
|
| | | * @param columns 列集合
|
| | | */
|
| | | public static void addDicts(Set<String> dicts, List<GenTableColumn> columns)
|
| | | {
|
| | | for (GenTableColumn column : columns)
|
| | | {
|
| | | if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny(
|
| | |
| | | dicts.add("'" + column.getDictType() + "'");
|
| | | }
|
| | | }
|
| | | return StringUtils.join(dicts, ", ");
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取权限前缀
|
| | | * |
| | | *
|
| | | * @param moduleName 模块名称
|
| | | * @param businessName 业务名称
|
| | | * @return 返回权限前缀
|
| | |
| | |
|
| | | /**
|
| | | * 获取上级菜单ID字段
|
| | | * |
| | | * @param options 生成其他选项
|
| | | *
|
| | | * @param paramsObj 生成其他选项
|
| | | * @return 上级菜单ID字段
|
| | | */
|
| | | public static String getParentMenuId(JSONObject paramsObj)
|
| | |
| | |
|
| | | /**
|
| | | * 获取树编码
|
| | | * |
| | | * @param options 生成其他选项
|
| | | *
|
| | | * @param paramsObj 生成其他选项
|
| | | * @return 树编码
|
| | | */
|
| | | public static String getTreecode(JSONObject paramsObj)
|
| | |
| | |
|
| | | /**
|
| | | * 获取树父编码
|
| | | * |
| | | * @param options 生成其他选项
|
| | | *
|
| | | * @param paramsObj 生成其他选项
|
| | | * @return 树父编码
|
| | | */
|
| | | public static String getTreeParentCode(JSONObject paramsObj)
|
| | |
| | |
|
| | | /**
|
| | | * 获取树名称
|
| | | * |
| | | * @param options 生成其他选项
|
| | | *
|
| | | * @param paramsObj 生成其他选项
|
| | | * @return 树名称
|
| | | */
|
| | | public static String getTreeName(JSONObject paramsObj)
|
| | |
| | |
|
| | | /**
|
| | | * 获取需要在哪一列上面显示展开按钮
|
| | | * |
| | | *
|
| | | * @param genTable 业务表对象
|
| | | * @return 展开按钮列序号
|
| | | */
|
| | | public static int getExpandColumn(GenTable genTable)
|
| | | {
|
| | | String options = genTable.getOptions();
|
| | | JSONObject paramsObj = JSONObject.parseObject(options);
|
| | | JSONObject paramsObj = JSON.parseObject(options);
|
| | | String treeName = paramsObj.getString(GenConstants.TREE_NAME);
|
| | | int num = 0;
|
| | | for (GenTableColumn column : genTable.getColumns())
|
| | |
| | | }
|
| | | return num;
|
| | | }
|
| | | } |
| | | }
|