优化
This commit is contained in:
+14
-1
@@ -366,7 +366,20 @@ public class FinancePhase1OperationService {
|
||||
private String json(Object value) { try { return objectMapper.writeValueAsString(value); } catch (Exception e) { throw error("FIN-DATA-500", "财务数据序列化失败"); } }
|
||||
private String hash(Object value) { try { return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(json(value).getBytes(StandardCharsets.UTF_8))); } catch (Exception e) { throw error("FIN-DATA-500", "幂等请求哈希失败"); } }
|
||||
private static String text(JsonNode node, String field) { JsonNode value = node.path(field); return value.isMissingNode() || value.isNull() ? null : value.asText(); }
|
||||
private static Long jsonLong(JsonNode node, String field) { JsonNode value = node.path(field); return value.isIntegralNumber() && value.asLong() > 0 ? value.asLong() : null; }
|
||||
private static Long jsonLong(JsonNode node, String field) {
|
||||
JsonNode value = node.path(field);
|
||||
if (value.isIntegralNumber() && value.canConvertToLong()) {
|
||||
long parsed = value.longValue();
|
||||
return parsed > 0 ? parsed : null;
|
||||
}
|
||||
if (!value.isTextual()) return null;
|
||||
try {
|
||||
long parsed = Long.parseLong(value.textValue());
|
||||
return parsed > 0 ? parsed : null;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private static Long firstLong(Long first, Long second) { return first != null ? first : second; }
|
||||
private static String firstText(String first, String second) { return StringUtils.hasText(first) ? first : second; }
|
||||
private static String defaultText(JsonNode node, String field, String fallback) { String value = text(node, field); return value == null || value.isBlank() ? fallback : value; }
|
||||
|
||||
@@ -462,7 +462,9 @@ public class FinanceSettlementService {
|
||||
BigDecimal unitPrice = quantity == null || quantity.signum() == 0 ? null
|
||||
: amount.divide(quantity, 6, java.math.RoundingMode.HALF_UP);
|
||||
Long supplierId = jsonLong(snapshot, "supplierId");
|
||||
if (supplierId == null) throw error("FIN_409", "应付结算缺少供应商快照");
|
||||
if ("PAYABLE".equals(text(row, "direction")) && supplierId == null) {
|
||||
throw error("FIN_409", "应付结算缺少供应商快照");
|
||||
}
|
||||
return new SettlementLine(number(row, "fee_source_id").longValue(), text(row, "source_type"),
|
||||
number(row, "source_fee_id").longValue(), number(row, "source_fee_version").intValue(),
|
||||
text(row, "direction"), number(row, "customer_id").longValue(), jsonText(snapshot, "customerName"),
|
||||
@@ -594,7 +596,17 @@ public class FinanceSettlementService {
|
||||
}
|
||||
private static Long jsonLong(JsonNode node, String key) {
|
||||
JsonNode value = node.path(key);
|
||||
return value.isIntegralNumber() ? value.longValue() : null;
|
||||
if (value.isIntegralNumber() && value.canConvertToLong()) {
|
||||
long parsed = value.longValue();
|
||||
return parsed > 0 ? parsed : null;
|
||||
}
|
||||
if (!value.isTextual()) return null;
|
||||
try {
|
||||
long parsed = Long.parseLong(value.textValue());
|
||||
return parsed > 0 ? parsed : null;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private static LocalDate jsonDate(JsonNode node, String key) {
|
||||
String value = jsonText(node, key);
|
||||
|
||||
Reference in New Issue
Block a user