From 031b7da19894c8539ff9fd6a7d4b5246f8a66b7d Mon Sep 17 00:00:00 2001 From: ageerle <32251822+ageerle@users.noreply.github.com> Date: 星期五, 16 五月 2025 16:29:21 +0800 Subject: [PATCH] Merge pull request #84 from janzhou123/main --- ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/util/VelocityUtils.java | 718 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 359 insertions(+), 359 deletions(-) diff --git a/ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/util/VelocityUtils.java b/ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/util/VelocityUtils.java index 6d0e68a..65ab7ea 100644 --- a/ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/util/VelocityUtils.java +++ b/ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/util/VelocityUtils.java @@ -25,386 +25,386 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class VelocityUtils { - /** - * 椤圭洰绌洪棿璺緞 - */ - private static final String PROJECT_PATH = "main/java"; + /** + * 椤圭洰绌洪棿璺緞 + */ + private static final String PROJECT_PATH = "main/java"; - /** - * mybatis绌洪棿璺緞 - */ - private static final String MYBATIS_PATH = "main/resources/mapper"; + /** + * mybatis绌洪棿璺緞 + */ + private static final String MYBATIS_PATH = "main/resources/mapper"; - /** - * 榛樿涓婄骇鑿滃崟锛岀郴缁熷伐鍏� - */ - private static final String DEFAULT_PARENT_MENU_ID = "3"; + /** + * 榛樿涓婄骇鑿滃崟锛岀郴缁熷伐鍏� + */ + private static final String DEFAULT_PARENT_MENU_ID = "3"; - /** - * 璁剧疆妯℃澘鍙橀噺淇℃伅 - * - * @return 妯℃澘鍒楄〃 - */ - public static VelocityContext prepareContext(GenTable genTable) { - String moduleName = genTable.getModuleName(); - String businessName = genTable.getBusinessName(); - String packageName = genTable.getPackageName(); - String tplCategory = genTable.getTplCategory(); - String functionName = genTable.getFunctionName(); + /** + * 璁剧疆妯℃澘鍙橀噺淇℃伅 + * + * @return 妯℃澘鍒楄〃 + */ + public static VelocityContext prepareContext(GenTable genTable) { + String moduleName = genTable.getModuleName(); + String businessName = genTable.getBusinessName(); + String packageName = genTable.getPackageName(); + String tplCategory = genTable.getTplCategory(); + String functionName = genTable.getFunctionName(); - VelocityContext velocityContext = new VelocityContext(); - velocityContext.put("tplCategory", genTable.getTplCategory()); - velocityContext.put("tableName", genTable.getTableName()); - velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "銆愯濉啓鍔熻兘鍚嶇О銆�"); - velocityContext.put("ClassName", genTable.getClassName()); - velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); - velocityContext.put("moduleName", genTable.getModuleName()); - velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); - velocityContext.put("businessName", genTable.getBusinessName()); - velocityContext.put("basePackage", getPackagePrefix(packageName)); - velocityContext.put("packageName", packageName); - velocityContext.put("author", genTable.getFunctionAuthor()); - velocityContext.put("datetime", DateUtils.getDate()); - velocityContext.put("pkColumn", genTable.getPkColumn()); - velocityContext.put("importList", getImportList(genTable)); - velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); - velocityContext.put("columns", genTable.getColumns()); - velocityContext.put("table", genTable); - velocityContext.put("dicts", getDicts(genTable)); - setMenuVelocityContext(velocityContext, genTable); - if (GenConstants.TPL_TREE.equals(tplCategory)) { - setTreeVelocityContext(velocityContext, genTable); - } - // 鍒ゆ柇鏄痬odal杩樻槸drawer - Dict paramsObj = JsonUtils.parseMap(genTable.getOptions()); - if (ObjectUtil.isNotNull(paramsObj)) { - String popupComponent = Optional - .ofNullable(paramsObj.getStr("popupComponent")) - .orElse("modal"); - velocityContext.put("popupComponent", popupComponent); - velocityContext.put("PopupComponent", StringUtils.capitalize(popupComponent)); - } else { - velocityContext.put("popupComponent", "modal"); - velocityContext.put("PopupComponent", "Modal"); - } - // 鍒ゆ柇鏄師鐢焌ntd琛ㄥ崟杩樻槸useForm琛ㄥ崟 - // native 鍘熺敓antd琛ㄥ崟 - // useForm useVbenForm - if (ObjectUtil.isNotNull(paramsObj)) { - String formComponent = Optional - .ofNullable(paramsObj.getStr("formComponent")) - .orElse("useForm"); - velocityContext.put("formComponent", formComponent); - } - return velocityContext; + VelocityContext velocityContext = new VelocityContext(); + velocityContext.put("tplCategory", genTable.getTplCategory()); + velocityContext.put("tableName", genTable.getTableName()); + velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "銆愯濉啓鍔熻兘鍚嶇О銆�"); + velocityContext.put("ClassName", genTable.getClassName()); + velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); + velocityContext.put("moduleName", genTable.getModuleName()); + velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); + velocityContext.put("businessName", genTable.getBusinessName()); + velocityContext.put("basePackage", getPackagePrefix(packageName)); + velocityContext.put("packageName", packageName); + velocityContext.put("author", genTable.getFunctionAuthor()); + velocityContext.put("datetime", DateUtils.getDate()); + velocityContext.put("pkColumn", genTable.getPkColumn()); + velocityContext.put("importList", getImportList(genTable)); + velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); + velocityContext.put("columns", genTable.getColumns()); + velocityContext.put("table", genTable); + velocityContext.put("dicts", getDicts(genTable)); + setMenuVelocityContext(velocityContext, genTable); + if (GenConstants.TPL_TREE.equals(tplCategory)) { + setTreeVelocityContext(velocityContext, genTable); } - - public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { - String options = genTable.getOptions(); - Dict paramsObj = JsonUtils.parseMap(options); - String parentMenuId = getParentMenuId(paramsObj); - context.put("parentMenuId", parentMenuId); + // 鍒ゆ柇鏄痬odal杩樻槸drawer + Dict paramsObj = JsonUtils.parseMap(genTable.getOptions()); + if (ObjectUtil.isNotNull(paramsObj)) { + String popupComponent = Optional + .ofNullable(paramsObj.getStr("popupComponent")) + .orElse("modal"); + velocityContext.put("popupComponent", popupComponent); + velocityContext.put("PopupComponent", StringUtils.capitalize(popupComponent)); + } else { + velocityContext.put("popupComponent", "modal"); + velocityContext.put("PopupComponent", "Modal"); } + // 鍒ゆ柇鏄師鐢焌ntd琛ㄥ崟杩樻槸useForm琛ㄥ崟 + // native 鍘熺敓antd琛ㄥ崟 + // useForm useVbenForm + if (ObjectUtil.isNotNull(paramsObj)) { + String formComponent = Optional + .ofNullable(paramsObj.getStr("formComponent")) + .orElse("useForm"); + velocityContext.put("formComponent", formComponent); + } + return velocityContext; + } - public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { - String options = genTable.getOptions(); - Dict paramsObj = JsonUtils.parseMap(options); - String treeCode = getTreecode(paramsObj); - String treeParentCode = getTreeParentCode(paramsObj); - String treeName = getTreeName(paramsObj); + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable) { + String options = genTable.getOptions(); + Dict paramsObj = JsonUtils.parseMap(options); + String parentMenuId = getParentMenuId(paramsObj); + context.put("parentMenuId", parentMenuId); + } - context.put("treeCode", treeCode); - context.put("treeParentCode", treeParentCode); - context.put("treeName", treeName); - context.put("expandColumn", getExpandColumn(genTable)); - if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { - context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE)); - } - if (paramsObj.containsKey(GenConstants.TREE_NAME)) { - context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME)); - } + public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) { + String options = genTable.getOptions(); + Dict paramsObj = JsonUtils.parseMap(options); + String treeCode = getTreecode(paramsObj); + String treeParentCode = getTreeParentCode(paramsObj); + String treeName = getTreeName(paramsObj); + + context.put("treeCode", treeCode); + context.put("treeParentCode", treeParentCode); + context.put("treeName", treeName); + context.put("expandColumn", getExpandColumn(genTable)); + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) { + context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE)); + } + if (paramsObj.containsKey(GenConstants.TREE_NAME)) { + context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME)); + } + } + + /** + * 鑾峰彇妯℃澘淇℃伅 + * + * @return 妯℃澘鍒楄〃 + */ + public static List<String> getTemplateList(String tplCategory) { + List<String> templates = new ArrayList<>(); + templates.add("vm/java/domain.java.vm"); + templates.add("vm/java/vo.java.vm"); + templates.add("vm/java/bo.java.vm"); + templates.add("vm/java/mapper.java.vm"); + templates.add("vm/java/service.java.vm"); + templates.add("vm/java/serviceImpl.java.vm"); + templates.add("vm/java/controller.java.vm"); + templates.add("vm/xml/mapper.xml.vm"); + if (DataBaseHelper.isOracle()) { + templates.add("vm/sql/oracle/sql.vm"); + } else if (DataBaseHelper.isPostgerSql()) { + templates.add("vm/sql/postgres/sql.vm"); + } else if (DataBaseHelper.isSqlServer()) { + templates.add("vm/sql/sqlserver/sql.vm"); + } else { + templates.add("vm/sql/sql.vm"); + } + templates.add("vm/ts/api.ts.vm"); + templates.add("vm/ts/types.ts.vm"); + if (GenConstants.TPL_CRUD.equals(tplCategory)) { + templates.add("vm/vue/index.vue.vm"); + } else if (GenConstants.TPL_TREE.equals(tplCategory)) { + templates.add("vm/vue/index-tree.vue.vm"); } /** - * 鑾峰彇妯℃澘淇℃伅 - * - * @return 妯℃澘鍒楄〃 + * 娣诲姞vben5 */ - public static List<String> getTemplateList(String tplCategory) { - List<String> templates = new ArrayList<>(); - templates.add("vm/java/domain.java.vm"); - templates.add("vm/java/vo.java.vm"); - templates.add("vm/java/bo.java.vm"); - templates.add("vm/java/mapper.java.vm"); - templates.add("vm/java/service.java.vm"); - templates.add("vm/java/serviceImpl.java.vm"); - templates.add("vm/java/controller.java.vm"); - templates.add("vm/xml/mapper.xml.vm"); - if (DataBaseHelper.isOracle()) { - templates.add("vm/sql/oracle/sql.vm"); - } else if (DataBaseHelper.isPostgerSql()) { - templates.add("vm/sql/postgres/sql.vm"); - } else if (DataBaseHelper.isSqlServer()) { - templates.add("vm/sql/sqlserver/sql.vm"); - } else { - templates.add("vm/sql/sql.vm"); - } - templates.add("vm/ts/api.ts.vm"); - templates.add("vm/ts/types.ts.vm"); - if (GenConstants.TPL_CRUD.equals(tplCategory)) { - templates.add("vm/vue/index.vue.vm"); - } else if (GenConstants.TPL_TREE.equals(tplCategory)) { - templates.add("vm/vue/index-tree.vue.vm"); - } - - /** - * 娣诲姞vben5 - */ - templates.add("vm/vben5/api/index.ts.vm"); - templates.add("vm/vben5/api/model.d.ts.vm"); - templates.add("vm/vben5/views/data.ts.vm"); - if (GenConstants.TPL_CRUD.equals(tplCategory)) { - templates.add("vm/vben5/views/index_vben.vue.vm"); - templates.add("vm/vben5/views/popup.vue.vm"); - } else if (GenConstants.TPL_TREE.equals(tplCategory)) { - templates.add("vm/vben5/views/index_vben_tree.vue.vm"); - templates.add("vm/vben5/views/popup_tree.vue.vm"); - } - - return templates; + templates.add("vm/vben5/api/index.ts.vm"); + templates.add("vm/vben5/api/model.d.ts.vm"); + templates.add("vm/vben5/views/data.ts.vm"); + if (GenConstants.TPL_CRUD.equals(tplCategory)) { + templates.add("vm/vben5/views/index_vben.vue.vm"); + templates.add("vm/vben5/views/popup.vue.vm"); + } else if (GenConstants.TPL_TREE.equals(tplCategory)) { + templates.add("vm/vben5/views/index_vben_tree.vue.vm"); + templates.add("vm/vben5/views/popup_tree.vue.vm"); } - /** - * 鑾峰彇鏂囦欢鍚� - */ - public static String getFileName(String template, GenTable genTable) { - // 鏂囦欢鍚嶇О - String fileName = ""; - // 鍖呰矾寰� - String packageName = genTable.getPackageName(); - // 妯″潡鍚� - String moduleName = genTable.getModuleName(); - // 澶у啓绫诲悕 - String className = genTable.getClassName(); - // 涓氬姟鍚嶇О - String businessName = genTable.getBusinessName(); + return templates; + } - String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); - String mybatisPath = MYBATIS_PATH + "/" + moduleName; - String vuePath = "vue"; + /** + * 鑾峰彇鏂囦欢鍚� + */ + public static String getFileName(String template, GenTable genTable) { + // 鏂囦欢鍚嶇О + String fileName = ""; + // 鍖呰矾寰� + String packageName = genTable.getPackageName(); + // 妯″潡鍚� + String moduleName = genTable.getModuleName(); + // 澶у啓绫诲悕 + String className = genTable.getClassName(); + // 涓氬姟鍚嶇О + String businessName = genTable.getBusinessName(); - if (template.contains("domain.java.vm")) { - fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); - } - if (template.contains("vo.java.vm")) { - fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className); - } - if (template.contains("bo.java.vm")) { - fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className); - } - if (template.contains("mapper.java.vm")) { - fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); - } else if (template.contains("service.java.vm")) { - fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); - } else if (template.contains("serviceImpl.java.vm")) { - fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); - } else if (template.contains("controller.java.vm")) { - fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); - } else if (template.contains("mapper.xml.vm")) { - fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); - } else if (template.contains("sql.vm")) { - fileName = businessName + "Menu.sql"; - } else if (template.contains("api.ts.vm")) { - fileName = StringUtils.format("{}/api/{}/{}/index.ts", vuePath, moduleName, businessName); - } else if (template.contains("types.ts.vm")) { - fileName = StringUtils.format("{}/api/{}/{}/types.ts", vuePath, moduleName, businessName); - } else if (template.contains("index.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); - } else if (template.contains("index-tree.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); - } + String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); + String mybatisPath = MYBATIS_PATH + "/" + moduleName; + String vuePath = "vue"; - // 鍒ゆ柇鏄痬odal杩樻槸drawer - Dict paramsObj = JsonUtils.parseMap(genTable.getOptions()); - String popupComponent = "modal"; - if (ObjectUtil.isNotNull(paramsObj)) { - popupComponent = Optional - .ofNullable(paramsObj.getStr("popupComponent")) - .orElse("modal"); - } - String vben5Path = "vben5"; - if (template.contains("vm/vben5/api/index.ts.vm")) { - fileName = StringUtils.format("{}/api/{}/{}/index.ts", vben5Path, moduleName, businessName); - } - if (template.contains("vm/vben5/api/model.d.ts.vm")) { - fileName = StringUtils.format("{}/api/{}/{}/model.d.ts", vben5Path, moduleName, businessName); - } - if (template.contains("vm/vben5/views/index_vben.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName); - } - if (template.contains("vm/vben5/views/index_vben_tree.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName); - } - if (template.contains("vm/vben5/views/data.ts.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/data.ts", vben5Path, moduleName, businessName); - } - if (template.contains("vm/vben5/views/popup.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent); - } - if (template.contains("vm/vben5/views/popup_tree.vue.vm")) { - fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent); - } - - return fileName; + if (template.contains("domain.java.vm")) { + fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); + } + if (template.contains("vo.java.vm")) { + fileName = StringUtils.format("{}/domain/vo/{}Vo.java", javaPath, className); + } + if (template.contains("bo.java.vm")) { + fileName = StringUtils.format("{}/domain/bo/{}Bo.java", javaPath, className); + } + if (template.contains("mapper.java.vm")) { + fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); + } else if (template.contains("service.java.vm")) { + fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); + } else if (template.contains("serviceImpl.java.vm")) { + fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); + } else if (template.contains("controller.java.vm")) { + fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); + } else if (template.contains("mapper.xml.vm")) { + fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); + } else if (template.contains("sql.vm")) { + fileName = businessName + "Menu.sql"; + } else if (template.contains("api.ts.vm")) { + fileName = StringUtils.format("{}/api/{}/{}/index.ts", vuePath, moduleName, businessName); + } else if (template.contains("types.ts.vm")) { + fileName = StringUtils.format("{}/api/{}/{}/types.ts", vuePath, moduleName, businessName); + } else if (template.contains("index.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); + } else if (template.contains("index-tree.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); } - /** - * 鑾峰彇鍖呭墠缂� - * - * @param packageName 鍖呭悕绉� - * @return 鍖呭墠缂�鍚嶇О - */ - public static String getPackagePrefix(String packageName) { - int lastIndex = packageName.lastIndexOf("."); - return StringUtils.substring(packageName, 0, lastIndex); + // 鍒ゆ柇鏄痬odal杩樻槸drawer + Dict paramsObj = JsonUtils.parseMap(genTable.getOptions()); + String popupComponent = "modal"; + if (ObjectUtil.isNotNull(paramsObj)) { + popupComponent = Optional + .ofNullable(paramsObj.getStr("popupComponent")) + .orElse("modal"); + } + String vben5Path = "vben5"; + if (template.contains("vm/vben5/api/index.ts.vm")) { + fileName = StringUtils.format("{}/api/{}/{}/index.ts", vben5Path, moduleName, businessName); + } + if (template.contains("vm/vben5/api/model.d.ts.vm")) { + fileName = StringUtils.format("{}/api/{}/{}/model.d.ts", vben5Path, moduleName, businessName); + } + if (template.contains("vm/vben5/views/index_vben.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName); + } + if (template.contains("vm/vben5/views/index_vben_tree.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vben5Path, moduleName, businessName); + } + if (template.contains("vm/vben5/views/data.ts.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/data.ts", vben5Path, moduleName, businessName); + } + if (template.contains("vm/vben5/views/popup.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent); + } + if (template.contains("vm/vben5/views/popup_tree.vue.vm")) { + fileName = StringUtils.format("{}/views/{}/{}/{}-{}.vue", vben5Path, moduleName, businessName, businessName, popupComponent); } - /** - * 鏍规嵁鍒楃被鍨嬭幏鍙栧鍏ュ寘 - * - * @param genTable 涓氬姟琛ㄥ璞� - * @return 杩斿洖闇�瑕佸鍏ョ殑鍖呭垪琛� - */ - public static HashSet<String> getImportList(GenTable genTable) { - List<GenTableColumn> columns = genTable.getColumns(); - HashSet<String> importList = new HashSet<>(); - for (GenTableColumn column : columns) { - if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { - importList.add("java.util.Date"); - importList.add("com.fasterxml.jackson.annotation.JsonFormat"); - } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { - importList.add("java.math.BigDecimal"); - } else if (!column.isSuperColumn() && "imageUpload".equals(column.getHtmlType())) { - importList.add("org.dromara.common.translation.annotation.Translation"); - importList.add("org.dromara.common.translation.constant.TransConstant"); - } + return fileName; + } + + /** + * 鑾峰彇鍖呭墠缂� + * + * @param packageName 鍖呭悕绉� + * @return 鍖呭墠缂�鍚嶇О + */ + public static String getPackagePrefix(String packageName) { + int lastIndex = packageName.lastIndexOf("."); + return StringUtils.substring(packageName, 0, lastIndex); + } + + /** + * 鏍规嵁鍒楃被鍨嬭幏鍙栧鍏ュ寘 + * + * @param genTable 涓氬姟琛ㄥ璞� + * @return 杩斿洖闇�瑕佸鍏ョ殑鍖呭垪琛� + */ + public static HashSet<String> getImportList(GenTable genTable) { + List<GenTableColumn> columns = genTable.getColumns(); + HashSet<String> importList = new HashSet<>(); + for (GenTableColumn column : columns) { + if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) { + importList.add("java.util.Date"); + importList.add("com.fasterxml.jackson.annotation.JsonFormat"); + } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) { + importList.add("java.math.BigDecimal"); + } else if (!column.isSuperColumn() && "imageUpload".equals(column.getHtmlType())) { + importList.add("org.dromara.common.translation.annotation.Translation"); + importList.add("org.dromara.common.translation.constant.TransConstant"); + } + } + return importList; + } + + /** + * 鏍规嵁鍒楃被鍨嬭幏鍙栧瓧鍏哥粍 + * + * @param genTable 涓氬姟琛ㄥ璞� + * @return 杩斿洖瀛楀吀缁� + */ + public static String getDicts(GenTable genTable) { + List<GenTableColumn> columns = genTable.getColumns(); + Set<String> dicts = new HashSet<>(); + addDicts(dicts, columns); + 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( + column.getHtmlType(), + new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) { + dicts.add("'" + column.getDictType() + "'"); + } + } + } + + /** + * 鑾峰彇鏉冮檺鍓嶇紑 + * + * @param moduleName 妯″潡鍚嶇О + * @param businessName 涓氬姟鍚嶇О + * @return 杩斿洖鏉冮檺鍓嶇紑 + */ + public static String getPermissionPrefix(String moduleName, String businessName) { + return StringUtils.format("{}:{}", moduleName, businessName); + } + + /** + * 鑾峰彇涓婄骇鑿滃崟ID瀛楁 + * + * @param paramsObj 鐢熸垚鍏朵粬閫夐」 + * @return 涓婄骇鑿滃崟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; + } + + /** + * 鑾峰彇鏍戠紪鐮� + * + * @param paramsObj 鐢熸垚鍏朵粬閫夐」 + * @return 鏍戠紪鐮� + */ + public static String getTreecode(Map<String, Object> paramsObj) { + 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(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(Dict paramsObj) { + if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { + return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME)); + } + return StringUtils.EMPTY; + } + + /** + * 鑾峰彇闇�瑕佸湪鍝竴鍒椾笂闈㈡樉绀哄睍寮�鎸夐挳 + * + * @param genTable 涓氬姟琛ㄥ璞� + * @return 灞曞紑鎸夐挳鍒楀簭鍙� + */ + public static int getExpandColumn(GenTable genTable) { + String options = genTable.getOptions(); + Dict paramsObj = JsonUtils.parseMap(options); + String treeName = paramsObj.getStr(GenConstants.TREE_NAME); + int num = 0; + for (GenTableColumn column : genTable.getColumns()) { + if (column.isList()) { + num++; + String columnName = column.getColumnName(); + if (columnName.equals(treeName)) { + break; } - return importList; + } } - - /** - * 鏍规嵁鍒楃被鍨嬭幏鍙栧瓧鍏哥粍 - * - * @param genTable 涓氬姟琛ㄥ璞� - * @return 杩斿洖瀛楀吀缁� - */ - public static String getDicts(GenTable genTable) { - List<GenTableColumn> columns = genTable.getColumns(); - Set<String> dicts = new HashSet<>(); - addDicts(dicts, columns); - 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( - column.getHtmlType(), - new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO, GenConstants.HTML_CHECKBOX })) { - dicts.add("'" + column.getDictType() + "'"); - } - } - } - - /** - * 鑾峰彇鏉冮檺鍓嶇紑 - * - * @param moduleName 妯″潡鍚嶇О - * @param businessName 涓氬姟鍚嶇О - * @return 杩斿洖鏉冮檺鍓嶇紑 - */ - public static String getPermissionPrefix(String moduleName, String businessName) { - return StringUtils.format("{}:{}", moduleName, businessName); - } - - /** - * 鑾峰彇涓婄骇鑿滃崟ID瀛楁 - * - * @param paramsObj 鐢熸垚鍏朵粬閫夐」 - * @return 涓婄骇鑿滃崟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; - } - - /** - * 鑾峰彇鏍戠紪鐮� - * - * @param paramsObj 鐢熸垚鍏朵粬閫夐」 - * @return 鏍戠紪鐮� - */ - public static String getTreecode(Map<String, Object> paramsObj) { - 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(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(Dict paramsObj) { - if (CollUtil.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME)) { - return StringUtils.toCamelCase(paramsObj.getStr(GenConstants.TREE_NAME)); - } - return StringUtils.EMPTY; - } - - /** - * 鑾峰彇闇�瑕佸湪鍝竴鍒椾笂闈㈡樉绀哄睍寮�鎸夐挳 - * - * @param genTable 涓氬姟琛ㄥ璞� - * @return 灞曞紑鎸夐挳鍒楀簭鍙� - */ - public static int getExpandColumn(GenTable genTable) { - String options = genTable.getOptions(); - Dict paramsObj = JsonUtils.parseMap(options); - String treeName = paramsObj.getStr(GenConstants.TREE_NAME); - int num = 0; - for (GenTableColumn column : genTable.getColumns()) { - if (column.isList()) { - num++; - String columnName = column.getColumnName(); - if (columnName.equals(treeName)) { - break; - } - } - } - return num; - } + return num; + } } -- Gitblit v1.9.3