diff --git a/.gitignore b/.gitignore index b1dce2e..62aefc4 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ nbdist/ .nb-gradle/ node_modules/* +# 忽略.vscode文件夹(核心规则) +.vscode/ + ###################################################################### # Others *.log diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml index fc5c513..0c623a5 100644 --- a/ruoyi-admin/src/main/resources/application-druid.yml +++ b/ruoyi-admin/src/main/resources/application-druid.yml @@ -6,8 +6,8 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 -# url: jdbc:mysql://192.168.0.222:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 +# url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://192.168.0.222:3306/ry_refactor0118?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: root password: 1qazse42W3 # 从库数据源 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index b08a9d0..ac23a28 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -61,14 +61,14 @@ spring: enabled: true # redis 配置 redis: - # 地址 - host: localhost - # 端口,默认为6379 - port: 6379 # # 地址 -# host: 192.168.0.222 +# host: localhost # # 端口,默认为6379 -# port: 6380 +# port: 6379 + # 地址 + host: 192.168.0.222 + # 端口,默认为6379 + port: 6380 # 数据库索引 database: 0 # 密码 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index 45c23a6..0d26b1a 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -280,18 +280,32 @@ public class ExcelUtil } else { - //再进行模糊匹配,模糊匹配再失败了,才是真的失败了 - //或者在注解里添加模糊匹配规则 - // attr 为java中的注解 + // 增强的模糊匹配逻辑 + String attrName = attr.name(); + String normalizedAttrName = normalizeString(attrName); + + // 遍历所有表头,寻找最佳匹配 for (Map.Entry entry : cellMap.entrySet()) { String name = entry.getKey(); - String attrName = attr.name(); - if(name.contains(attrName)) + if (name != null) { - column = cellMap.get(name); - fieldsMap.put(column, objects); - break; + String normalizedName = normalizeString(name); + + // 检查表头是否包含注解名称(大小写不敏感,去除空格和特殊字符) + if (normalizedName.contains(normalizedAttrName)) + { + column = entry.getValue(); + fieldsMap.put(column, objects); + break; + } + // 检查注解名称是否包含表头(双向匹配) + else if (normalizedAttrName.contains(normalizedName)) + { + column = entry.getValue(); + fieldsMap.put(column, objects); + break; + } } } } @@ -1191,7 +1205,7 @@ public class ExcelUtil if (field.isAnnotationPresent(Excel.class)) { Excel attr = field.getAnnotation(Excel.class); - if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) + if (attr != null && (attr.type() == Type.ALL || (type != null && attr.type() == type))) { field.setAccessible(true); fields.add(new Object[] { field, attr }); @@ -1205,7 +1219,7 @@ public class ExcelUtil Excel[] excels = attrs.value(); for (Excel attr : excels) { - if (attr != null && (attr.type() == Type.ALL || attr.type() == type)) + if (attr != null && (attr.type() == Type.ALL || (type != null && attr.type() == type))) { field.setAccessible(true); fields.add(new Object[] { field, attr }); @@ -1230,6 +1244,26 @@ public class ExcelUtil return (short) (maxHeight * 20); } + /** + * 标准化字符串,用于模糊匹配 + * @param str 原始字符串 + * @return 标准化后的字符串 + */ + private String normalizeString(String str) + { + if (str == null) + { + return ""; + } + // 转换为小写 + str = str.toLowerCase(); + // 去除空格 + str = str.replaceAll("\\s+", ""); + // 去除特殊字符(使用更安全的正则表达式) + str = str.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5]", ""); + return str; + } + /** * 创建一个工作簿 */ diff --git a/stock-system/src/main/resources/mapper/stocksystem/StocksMapper.xml b/stock-system/src/main/resources/mapper/stocksystem/StocksMapper.xml index dbc9ae1..fc71ee9 100644 --- a/stock-system/src/main/resources/mapper/stocksystem/StocksMapper.xml +++ b/stock-system/src/main/resources/mapper/stocksystem/StocksMapper.xml @@ -337,7 +337,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"