解决条码查询报错的bug
This commit is contained in:
@@ -98,7 +98,7 @@ public interface MaterialMapperEx {
|
||||
|
||||
List<Material> getMaterialListByUnitIds(@Param("unitIds") String[] unitIds);
|
||||
|
||||
String getMaxBarCode();
|
||||
List<String> getBarCodeList();
|
||||
|
||||
List<MaterialVo4Unit> getMaterialByMeId(
|
||||
@Param("meId") Long meId);
|
||||
|
||||
@@ -1307,12 +1307,15 @@ public class MaterialService {
|
||||
}
|
||||
|
||||
public String getMaxBarCode() {
|
||||
String maxBarCodeOld = materialMapperEx.getMaxBarCode();
|
||||
if(StringUtil.isNotEmpty(maxBarCodeOld)) {
|
||||
return Long.parseLong(maxBarCodeOld)+"";
|
||||
} else {
|
||||
return "1000";
|
||||
}
|
||||
List<String> barCodeOldList = materialMapperEx.getBarCodeList();
|
||||
// 使用 Stream API 处理条码列表
|
||||
OptionalLong maxBarcode = barCodeOldList.stream()
|
||||
.filter(StringUtil::isNumeric) // 过滤掉非数字条码
|
||||
.mapToLong(Long::parseLong) // 将字符串转换为 Long 类型
|
||||
.max(); // 获取最大值
|
||||
// 如果存在最大值,返回它;否则返回 1000L
|
||||
Long maxBarCodeOld = maxBarcode.orElse(1000L);
|
||||
return maxBarCodeOld + "";
|
||||
}
|
||||
|
||||
public List<String> getMaterialNameList() {
|
||||
|
||||
@@ -444,4 +444,17 @@ public class StringUtil {
|
||||
return originStr.replaceAll("(?i)" + regex, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串是否为纯数字
|
||||
* @param str 输入的字符串
|
||||
* @return 如果字符串为纯数字,返回 true;否则返回 false
|
||||
*/
|
||||
public static boolean isNumeric(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// 使用正则表达式判断字符串是否为纯数字
|
||||
return str.matches("\\d+");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user