diff --git a/bms-back/bms-system/src/main/java/com/bms/price/search/EsBillSearchStore.java b/bms-back/bms-system/src/main/java/com/bms/price/search/EsBillSearchStore.java index 52f99f25..ed6e0398 100644 --- a/bms-back/bms-system/src/main/java/com/bms/price/search/EsBillSearchStore.java +++ b/bms-back/bms-system/src/main/java/com/bms/price/search/EsBillSearchStore.java @@ -69,8 +69,8 @@ public class EsBillSearchStore implements IBillSearchStore doc.put("bizId", bizId.trim()); doc.put("status", StringUtils.isEmpty(status) ? EsBizLogSupport.STATUS_SUCCESS : status.trim()); doc.put("error", StringUtils.isEmpty(errorMessage) ? null : errorMessage); - doc.put("request", parseOrRaw(requestJson)); - // Normalize response.ok boolean -> 1/0: index mapping typed response.ok as long. + // Index dynamic mapping is strict on a few fields; coerce before PUT. + doc.put("request", normalizeRequestForEs(parseOrRaw(requestJson))); doc.put("response", normalizeResponseForEs(parseOrRaw(responseJson))); String ts = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(now); doc.put("updatedAt", ts); @@ -86,7 +86,26 @@ public class EsBillSearchStore implements IBillSearchStore } } - /** Index historically mapped response.ok as long; coerce boolean to 1/0. */ + /** + * request.bizDate is mapped as date (ISO / epoch only); bill writes "yyyy-MM-dd HH:mm:ss". + * request.taskId is mapped as long; UUID strings must not stay under taskId. + */ + private Object normalizeRequestForEs(Object request) + { + if (!(request instanceof JSONObject)) + { + return request; + } + JSONObject obj = (JSONObject) request; + normalizeBizDateField(obj); + relocateNonNumericTaskId(obj); + return obj; + } + + /** + * response.ok mapped as long; response.success as boolean; response.taskId as long. + * Local rebill DONE used UUID taskId + numeric success and was rejected by ES. + */ private Object normalizeResponseForEs(Object response) { if (!(response instanceof JSONObject)) @@ -99,9 +118,54 @@ public class EsBillSearchStore implements IBillSearchStore { obj.put("ok", Boolean.TRUE.equals(ok) ? Integer.valueOf(1) : Integer.valueOf(0)); } + Object success = obj.get("success"); + if (success instanceof Number) + { + obj.put("success", Boolean.valueOf(((Number) success).intValue() != 0)); + } + relocateNonNumericTaskId(obj); return obj; } + private void normalizeBizDateField(JSONObject obj) + { + Object raw = obj.get("bizDate"); + if (!(raw instanceof String)) + { + return; + } + String bizDate = ((String) raw).trim(); + // "yyyy-MM-dd HH:mm:ss" -> ISO-local so ES date mapper accepts it. + if (bizDate.length() >= 19 && bizDate.charAt(10) == ' ') + { + obj.put("bizDate", bizDate.substring(0, 10) + "T" + bizDate.substring(11)); + } + } + + private void relocateNonNumericTaskId(JSONObject obj) + { + Object taskId = obj.get("taskId"); + if (!(taskId instanceof String)) + { + return; + } + String text = ((String) taskId).trim(); + if (text.isEmpty()) + { + obj.remove("taskId"); + return; + } + try + { + obj.put("taskId", Long.valueOf(Long.parseLong(text))); + } + catch (NumberFormatException e) + { + obj.remove("taskId"); + obj.put("taskIdStr", text); + } + } + @Override public BillSyncSnapshot get(String logType, String bizId) {