demand: tms/app-运单录入、运单批量录入-运单号增加校验,仅支持字母+数字+“-”横杠的组合

committer: heyu
This commit is contained in:
aike 2025-10-27 14:50:43 +08:00
parent 0f50014ed1
commit 75a464ed76

View File

@ -3163,6 +3163,34 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
}
/**
* 校验运单号格式
* 只允许包含数字、字母、"-"横杠三种类型
* 横杠只允许在中间,不能在两端,且不能连续有多个横杠
* @param billCode 运单号
* @throws EmisBizError 格式不符合要求时抛出异常
*/
private void validateBillCodeFormat(String billCode) throws EmisBizError {
if (StringUtils.isEmpty(billCode)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运单号不能为空");
}
// 检查是否只包含数字、字母、横杠
if (!billCode.matches("^[0-9a-zA-Z\\-]+$")) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运单号只能包含数字、字母和横杠");
}
// 检查横杠是否在两端
if (billCode.startsWith("-") || billCode.endsWith("-")) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运单号横杠不能在两端");
}
// 检查是否有连续的横杠
if (billCode.contains("--")) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运单号不能有连续的横杠");
}
}
/**
* 新开单
* @param emisWaybillSave
@ -3172,6 +3200,9 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
// 当寄件国家为0095或0855时,去除billCode和billCodeSub中的第一个T
// modifyBillCode(emisWaybillSave);
// 校验运单号格式
validateBillCodeFormat(emisWaybillSave.getBillCode());
// 获取运单号,判断是不是子单已存在
boolean isExists = checkWaybillIsExists(emisWaybillSave.getBillCode());
if(isExists){