mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update 日常校验 统一重构到 StringUtils 便于维护扩展
This commit is contained in:
@ -150,7 +150,7 @@ public class GenTableColumn implements Serializable {
|
||||
private Map<String, Object> params = new HashMap<>();
|
||||
|
||||
public String getCapJavaField() {
|
||||
return StringUtils.upperFirst(javaField);
|
||||
return StringUtils.uncapitalize(javaField);
|
||||
}
|
||||
|
||||
public boolean isPk() {
|
||||
@ -231,7 +231,7 @@ public class GenTableColumn implements Serializable {
|
||||
}
|
||||
|
||||
public String readConverterExp() {
|
||||
String remarks = StringUtils.subBetween(this.columnComment, "(", ")");
|
||||
String remarks = StringUtils.substringBetween(this.columnComment, "(", ")");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (StringUtils.isNotEmpty(remarks)) {
|
||||
for (String value : remarks.split(" ")) {
|
||||
|
@ -2,7 +2,6 @@ package com.ruoyi.generator.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
@ -260,7 +259,7 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
// 获取模板列表
|
||||
List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
|
||||
for (String template : templates) {
|
||||
if (!StringUtils.containsAny("sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm", template)) {
|
||||
if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
|
||||
// 渲染模板
|
||||
StringWriter sw = new StringWriter();
|
||||
Template tpl = Velocity.getTemplate(template, Constants.UTF8);
|
||||
@ -284,7 +283,7 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
||||
|
||||
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
|
||||
if (Validator.isEmpty(dbTableColumns)) {
|
||||
if (StringUtils.isEmpty(dbTableColumns)) {
|
||||
throw new CustomException("同步数据失败,原表结构不存在");
|
||||
}
|
||||
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
|
||||
@ -364,16 +363,16 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
public void validateEdit(GenTable genTable) {
|
||||
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
|
||||
Map<String, Object> paramsObj = genTable.getParams();
|
||||
if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) {
|
||||
if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) {
|
||||
throw new CustomException("树编码字段不能为空");
|
||||
} else if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) {
|
||||
} else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) {
|
||||
throw new CustomException("树父编码字段不能为空");
|
||||
} else if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) {
|
||||
} else if (StringUtils.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) {
|
||||
throw new CustomException("树名称字段不能为空");
|
||||
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
|
||||
if (Validator.isEmpty(genTable.getSubTableName())) {
|
||||
if (StringUtils.isEmpty(genTable.getSubTableName())) {
|
||||
throw new CustomException("关联子表的表名不能为空");
|
||||
} else if (Validator.isEmpty(genTable.getSubTableFkName())) {
|
||||
} else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
|
||||
throw new CustomException("子表关联的外键名不能为空");
|
||||
}
|
||||
}
|
||||
@ -392,7 +391,7 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Validator.isNull(table.getPkColumn())) {
|
||||
if (StringUtils.isNull(table.getPkColumn())) {
|
||||
table.setPkColumn(table.getColumns().get(0));
|
||||
}
|
||||
if (GenConstants.TPL_SUB.equals(table.getTplCategory())) {
|
||||
@ -402,7 +401,7 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (Validator.isNull(table.getSubTable().getPkColumn())) {
|
||||
if (StringUtils.isNull(table.getSubTable().getPkColumn())) {
|
||||
table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
|
||||
}
|
||||
}
|
||||
@ -415,7 +414,7 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
*/
|
||||
public void setSubTable(GenTable table) {
|
||||
String subTableName = table.getSubTableName();
|
||||
if (Validator.isNotEmpty(subTableName)) {
|
||||
if (StringUtils.isNotEmpty(subTableName)) {
|
||||
table.setSubTable(baseMapper.selectGenTableByName(subTableName));
|
||||
}
|
||||
}
|
||||
@ -427,7 +426,7 @@ public class GenTableServiceImpl extends ServicePlusImpl<GenTableMapper, GenTabl
|
||||
*/
|
||||
public void setTableFromOptions(GenTable genTable) {
|
||||
Map<String, Object> paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
if (Validator.isNotNull(paramsObj)) {
|
||||
if (StringUtils.isNotNull(paramsObj)) {
|
||||
String treeCode = Convert.toStr(paramsObj.get(GenConstants.TREE_CODE));
|
||||
String treeParentCode = Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE));
|
||||
String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME));
|
||||
|
@ -61,7 +61,7 @@ public class GenUtils
|
||||
column.setHtmlType(GenConstants.HTML_INPUT);
|
||||
|
||||
// 如果是浮点型 统一用BigDecimal
|
||||
String[] str = StringUtils.splitToArray(StringUtils.subBetween(column.getColumnType(), "(", ")"), ",");
|
||||
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
|
||||
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0)
|
||||
{
|
||||
column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
|
||||
@ -98,33 +98,33 @@ public class GenUtils
|
||||
}
|
||||
|
||||
// 查询字段类型
|
||||
if (StringUtils.endWithIgnoreCase(columnName, "name"))
|
||||
if (StringUtils.endsWithIgnoreCase(columnName, "name"))
|
||||
{
|
||||
column.setQueryType(GenConstants.QUERY_LIKE);
|
||||
}
|
||||
// 状态字段设置单选框
|
||||
if (StringUtils.endWithIgnoreCase(columnName, "status"))
|
||||
if (StringUtils.endsWithIgnoreCase(columnName, "status"))
|
||||
{
|
||||
column.setHtmlType(GenConstants.HTML_RADIO);
|
||||
}
|
||||
// 类型&性别字段设置下拉框
|
||||
else if (StringUtils.endWithIgnoreCase(columnName, "type")
|
||||
|| StringUtils.endWithIgnoreCase(columnName, "sex"))
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|
||||
|| StringUtils.endsWithIgnoreCase(columnName, "sex"))
|
||||
{
|
||||
column.setHtmlType(GenConstants.HTML_SELECT);
|
||||
}
|
||||
// 图片字段设置图片上传控件
|
||||
else if (StringUtils.endWithIgnoreCase(columnName, "image"))
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
|
||||
{
|
||||
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
|
||||
}
|
||||
// 文件字段设置文件上传控件
|
||||
else if (StringUtils.endWithIgnoreCase(columnName, "file"))
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
|
||||
{
|
||||
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
|
||||
}
|
||||
// 内容字段设置富文本控件
|
||||
else if (StringUtils.endWithIgnoreCase(columnName, "content"))
|
||||
else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
|
||||
{
|
||||
column.setHtmlType(GenConstants.HTML_EDITOR);
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class GenUtils
|
||||
{
|
||||
int lastIndex = packageName.lastIndexOf(".");
|
||||
int nameLength = packageName.length();
|
||||
String moduleName = StringUtils.sub(packageName, lastIndex + 1, nameLength);
|
||||
String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength);
|
||||
return moduleName;
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ public class GenUtils
|
||||
{
|
||||
int lastIndex = tableName.lastIndexOf("_");
|
||||
int nameLength = tableName.length();
|
||||
String businessName = StringUtils.sub(tableName, lastIndex + 1, nameLength);
|
||||
String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength);
|
||||
return businessName;
|
||||
}
|
||||
|
||||
@ -182,10 +182,10 @@ public class GenUtils
|
||||
String tablePrefix = GenConfig.getTablePrefix();
|
||||
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix))
|
||||
{
|
||||
String[] searchList = StringUtils.splitToArray(tablePrefix, ",");
|
||||
String[] searchList = StringUtils.split(tablePrefix, ",");
|
||||
tableName = replaceFirst(tableName, searchList);
|
||||
}
|
||||
return StringUtils.upperFirst(StringUtils.toCamelCase(tableName));
|
||||
return StringUtils.convertToCamelCase(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,7 +230,7 @@ public class GenUtils
|
||||
{
|
||||
if (StringUtils.indexOf(columnType, '(') > 0)
|
||||
{
|
||||
return StringUtils.subBefore(columnType, "(",false);
|
||||
return StringUtils.substringBefore(columnType, "(");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -248,7 +248,7 @@ public class GenUtils
|
||||
{
|
||||
if (StringUtils.indexOf(columnType, '(') > 0)
|
||||
{
|
||||
String length = StringUtils.subBetween(columnType, "(", ")");
|
||||
String length = StringUtils.substringBetween(columnType, "(", ")");
|
||||
return Integer.valueOf(length);
|
||||
}
|
||||
else
|
||||
|
@ -1,11 +1,10 @@
|
||||
package com.ruoyi.generator.util;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.constant.GenConstants;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.JsonUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.generator.domain.GenTable;
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
@ -49,9 +48,9 @@ public class VelocityUtils
|
||||
velocityContext.put("tableName", genTable.getTableName());
|
||||
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
|
||||
velocityContext.put("ClassName", genTable.getClassName());
|
||||
velocityContext.put("className", StringUtils.lowerFirst(genTable.getClassName()));
|
||||
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
|
||||
velocityContext.put("moduleName", genTable.getModuleName());
|
||||
velocityContext.put("BusinessName", StringUtils.upperFirst(genTable.getBusinessName()));
|
||||
velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName()));
|
||||
velocityContext.put("businessName", genTable.getBusinessName());
|
||||
velocityContext.put("basePackage", getPackagePrefix(packageName));
|
||||
velocityContext.put("packageName", packageName);
|
||||
@ -110,15 +109,15 @@ public class VelocityUtils
|
||||
String subTableName = genTable.getSubTableName();
|
||||
String subTableFkName = genTable.getSubTableFkName();
|
||||
String subClassName = genTable.getSubTable().getClassName();
|
||||
String subTableFkClassName = StringUtils.toCamelCase(subTableFkName);
|
||||
String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName);
|
||||
|
||||
context.put("subTable", subTable);
|
||||
context.put("subTableName", subTableName);
|
||||
context.put("subTableFkName", subTableFkName);
|
||||
context.put("subTableFkClassName", subTableFkClassName);
|
||||
context.put("subTableFkclassName", StringUtils.lowerFirst(subTableFkClassName));
|
||||
context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName));
|
||||
context.put("subClassName", subClassName);
|
||||
context.put("subclassName", StringUtils.lowerFirst(subClassName));
|
||||
context.put("subclassName", StringUtils.uncapitalize(subClassName));
|
||||
context.put("subImportList", getImportList(genTable.getSubTable()));
|
||||
}
|
||||
|
||||
@ -240,7 +239,7 @@ public class VelocityUtils
|
||||
public static String getPackagePrefix(String packageName)
|
||||
{
|
||||
int lastIndex = packageName.lastIndexOf(".");
|
||||
String basePackage = StringUtils.sub(packageName, 0, lastIndex);
|
||||
String basePackage = StringUtils.substring(packageName, 0, lastIndex);
|
||||
return basePackage;
|
||||
}
|
||||
|
||||
@ -255,7 +254,7 @@ public class VelocityUtils
|
||||
List<GenTableColumn> columns = genTable.getColumns();
|
||||
GenTable subGenTable = genTable.getSubTable();
|
||||
HashSet<String> importList = new HashSet<String>();
|
||||
if (Validator.isNotNull(subGenTable))
|
||||
if (StringUtils.isNotNull(subGenTable))
|
||||
{
|
||||
importList.add("java.util.List");
|
||||
}
|
||||
@ -294,7 +293,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getParentMenuId(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)
|
||||
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));
|
||||
@ -310,7 +309,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getTreecode(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE))
|
||||
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE))
|
||||
{
|
||||
return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)));
|
||||
}
|
||||
@ -325,7 +324,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getTreeParentCode(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
|
||||
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
|
||||
{
|
||||
return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE)));
|
||||
}
|
||||
@ -340,7 +339,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getTreeName(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME))
|
||||
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME))
|
||||
{
|
||||
return StringUtils.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user