解决条码查询报错的bug

This commit is contained in:
jishenghua 2025-03-03 19:14:36 +08:00
parent 182a8aed1e
commit 5a528d6855
4 changed files with 27 additions and 11 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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+");
}
}

View File

@ -524,10 +524,9 @@
and ifnull(delete_flag,'0') !='1'
</select>
<select id="getMaxBarCode" resultType="java.lang.String">
select max(CAST(me.bar_code AS SIGNED)) bar_code from jsh_material_extend me
where 1=1
and ifnull(me.delete_Flag,'0') !='1'
<select id="getBarCodeList" resultType="java.lang.String">
select me.bar_code from jsh_material_extend me
where ifnull(me.delete_Flag,'0') !='1'
</select>
<select id="getMaterialByMeId" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
@ -790,4 +789,5 @@
and ifnull(m.delete_flag,'0') !='1'
limit 0,1
</select>
</mapper>