增加失败码功能

This commit is contained in:
wuweihua
2026-09-28 11:07:09 +08:00
parent 0408b6c35e
commit cc802d1292
13 changed files with 247 additions and 31 deletions
@@ -0,0 +1,143 @@
package com.bms.price.enums;
import com.bms.common.utils.StringUtils;
/**
* Stable fail codes for prc_billing_task.fail_code (search / ops).
* Resolved from exception message when task writeback is FAILED.
*/
public enum BillTaskFailCode
{
NO_CUSTOMER_PACKAGE("NO_CUSTOMER_PACKAGE"),
NO_ACTIVE_PACKAGE_VERSION("NO_ACTIVE_PACKAGE_VERSION"),
ALREADY_IN_AR_BILL("ALREADY_IN_AR_BILL"),
PRODUCT_ARCHIVE_MISSING("PRODUCT_ARCHIVE_MISSING"),
PRICE_NOT_HIT("PRICE_NOT_HIT"),
ZONE_PRICE_NOT_HIT("ZONE_PRICE_NOT_HIT"),
POSTCODE_REQUIRED("POSTCODE_REQUIRED"),
POSTCODE_ZONE_NOT_FOUND("POSTCODE_ZONE_NOT_FOUND"),
ORACLE_ORDER_NOT_FOUND("ORACLE_ORDER_NOT_FOUND"),
ORACLE_ORDERNO_EMPTY("ORACLE_ORDERNO_EMPTY"),
ORACLE_CUSTOMER_EMPTY("ORACLE_CUSTOMER_EMPTY"),
ORACLE_PRODUCT_EMPTY("ORACLE_PRODUCT_EMPTY"),
ORACLE_WEIGHT_INVALID("ORACLE_WEIGHT_INVALID"),
BILL_TIME_EMPTY("BILL_TIME_EMPTY"),
REFUND_ORDER_UNRESOLVED("REFUND_ORDER_UNRESOLVED"),
CUSTOMER_CODE_REQUIRED("CUSTOMER_CODE_REQUIRED"),
CUSTOMER_DISABLED("CUSTOMER_DISABLED"),
FREIGHT_MISSING("FREIGHT_MISSING"),
UNKNOWN("UNKNOWN");
private final String code;
BillTaskFailCode(String code)
{
this.code = code;
}
public String getCode()
{
return code;
}
/**
* Map free-text error message to a stable fail code for search.
*/
public static String resolveCode(String errorMessage)
{
if (StringUtils.isEmpty(errorMessage))
{
return null;
}
String msg = errorMessage.trim();
if (containsAny(msg, "\u672a\u7ed1\u5b9a\u5957\u9910", "noCustomerPackage", "NO_CUSTOMER_PACKAGE"))
{
return NO_CUSTOMER_PACKAGE.code;
}
if (containsAny(msg, "\u65e0\u751f\u6548\u5957\u9910\u7248\u672c", "noActivePackageVersion", "NO_ACTIVE_PACKAGE_VERSION"))
{
return NO_ACTIVE_PACKAGE_VERSION.code;
}
if (containsAny(msg, "\u5df2\u751f\u6210\u5e94\u6536\u8d26\u5355", "alreadyInArBill", "ALREADY_IN_AR_BILL"))
{
return ALREADY_IN_AR_BILL.code;
}
if (containsAny(msg, "\u672a\u627e\u5230\u6709\u6548\u4ea7\u54c1\u6863\u6848", "PRODUCT_ARCHIVE_MISSING"))
{
return PRODUCT_ARCHIVE_MISSING.code;
}
if (containsAny(msg, "\u8be5\u5206\u533a\u65e0\u5bf9\u5e94\u4ea7\u54c1\u91cd\u91cf\u6bb5", "zonePriceNotHit", "ZONE_PRICE_NOT_HIT"))
{
return ZONE_PRICE_NOT_HIT.code;
}
if (containsAny(msg, "\u6ca1\u6709\u4ea7\u54c1/\u56fd\u5bb6/\u91cd\u91cf\u6bb5", "priceNotHit", "PRICE_NOT_HIT"))
{
return PRICE_NOT_HIT.code;
}
if (containsAny(msg, "\u8bf7\u586b\u5199\u76ee\u7684\u90ae\u7f16", "postcodeRequired", "POSTCODE_REQUIRED"))
{
return POSTCODE_REQUIRED.code;
}
if (containsAny(msg, "\u90ae\u7f16\u672a\u5339\u914d\u5230\u5206\u533a", "postcodeZoneNotFound", "POSTCODE_ZONE_NOT_FOUND"))
{
return POSTCODE_ZONE_NOT_FOUND.code;
}
if (containsAny(msg, "Oracle main order not found", "ORACLE_ORDER_NOT_FOUND"))
{
return ORACLE_ORDER_NOT_FOUND.code;
}
if (containsAny(msg, "mapped orderNo empty", "ORACLE_ORDERNO_EMPTY"))
{
return ORACLE_ORDERNO_EMPTY.code;
}
if (containsAny(msg, "mapped customerCode empty", "ORACLE_CUSTOMER_EMPTY"))
{
return ORACLE_CUSTOMER_EMPTY.code;
}
if (containsAny(msg, "mapped productCode empty", "ORACLE_PRODUCT_EMPTY"))
{
return ORACLE_PRODUCT_EMPTY.code;
}
if (containsAny(msg, "mapped weight invalid", "ORACLE_WEIGHT_INVALID"))
{
return ORACLE_WEIGHT_INVALID.code;
}
if (containsAny(msg, "billTime empty", "billTime required", "BILL_TIME_EMPTY"))
{
return BILL_TIME_EMPTY.code;
}
if (containsAny(msg, "\u9000\u8d39\u8ba2\u5355\u53f7\u65e0\u6cd5\u89e3\u6790", "REFUND_ORDER_UNRESOLVED"))
{
return REFUND_ORDER_UNRESOLVED.code;
}
if (containsAny(msg, "\u5ba2\u6237\u4ee3\u7801\u4e0d\u80fd\u4e3a\u7a7a", "customerCodeRequired", "CUSTOMER_CODE_REQUIRED"))
{
return CUSTOMER_CODE_REQUIRED.code;
}
if (containsAny(msg, "\u5ba2\u6237\u5df2\u505c\u7528", "customerDisabled", "CUSTOMER_DISABLED"))
{
return CUSTOMER_DISABLED.code;
}
if (containsAny(msg, "\u8fd0\u8d39\u4e3a\u7a7a", "freightMissing", "FREIGHT_MISSING"))
{
return FREIGHT_MISSING.code;
}
return UNKNOWN.code;
}
private static boolean containsAny(String msg, String... markers)
{
if (msg == null || markers == null)
{
return false;
}
for (String marker : markers)
{
if (StringUtils.isNotEmpty(marker) && msg.indexOf(marker) >= 0)
{
return true;
}
}
return false;
}
}