|
|
@@ -13,6 +13,10 @@ import java.util.List;
|
|
|
/**
|
|
|
* 口袋助理JSON解析工具类
|
|
|
* 用于从JSON中提取加微状态、成交状态、通话状态
|
|
|
+ *
|
|
|
+ * 加微状态解析优先级:
|
|
|
+ * 1. 优先从 lbl_doc 标签中读取“是否加微”子标签(如果存在)
|
|
|
+ * 2. 若不存在或解析失败,则从 properties 自定义属性中读取“客户是否加微”的 checked 状态
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class KdzlJsonParser {
|
|
|
@@ -35,40 +39,113 @@ public class KdzlJsonParser {
|
|
|
// 反序列化为Custm对象
|
|
|
Custm custm = objectMapper.readValue(kdzlMemberJson, Custm.class);
|
|
|
if (custm == null) {
|
|
|
- log.warn("解析Custm对象为null, JSON可能为空对象,待同步importMemberId:{}",customer.getImportMemberId());
|
|
|
+ log.warn("解析Custm对象为null, JSON可能为空对象,待同步importMemberId:{}", customer.getImportMemberId());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 1. 解析加微状态
|
|
|
- Integer addWechatStatus = parseAddWechatStatus(custm.getProperties());
|
|
|
+ // 1. 解析加微状态(优先使用lbl_doc中的“是否加微”,再使用properties中的“客户是否加微”)
|
|
|
+ Integer addWechatStatus = parseAddWechatStatus(custm.getLbl_doc(), custm.getProperties());
|
|
|
if (addWechatStatus != null) {
|
|
|
customer.setKdzlAddWechatStatus(addWechatStatus);
|
|
|
}
|
|
|
|
|
|
- // 2. 解析成交状态
|
|
|
+ // 2. 解析成交状态(仅从properties中读取)
|
|
|
Integer makeStatus = parseMakeStatus(custm.getProperties());
|
|
|
if (makeStatus != null) {
|
|
|
customer.setKdzlMakeStatus(makeStatus);
|
|
|
}
|
|
|
|
|
|
- // 3. 解析通话状态(文本描述)
|
|
|
+ // 3. 解析通话状态(文本描述,仅从lbl_doc中读取)
|
|
|
String callStatus = parseCallStatus(custm.getLbl_doc());
|
|
|
if (StringUtils.isNotBlank(callStatus)) {
|
|
|
customer.setKdzlCallStatus(callStatus);
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
- log.error("待同步的importMemberId:{}",customer.getImportMemberId());
|
|
|
+ log.error("待同步的importMemberId:{}", customer.getImportMemberId());
|
|
|
log.error("解析口袋助理JSON失败, json={}", kdzlMemberJson, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 解析加微状态
|
|
|
+ * 解析加微状态(优先标签,其次自定义属性)
|
|
|
+ *
|
|
|
+ * @param lblDoc 标签文档(可能为null)
|
|
|
+ * @param properties 自定义属性列表(可能为null)
|
|
|
+ * @return 1-已加微, 0-未加微, null-未知
|
|
|
+ */
|
|
|
+ private static Integer parseAddWechatStatus(LblDoc lblDoc, List<Property> properties) {
|
|
|
+ // 1. 优先从 lbl_doc 解析“是否加微”
|
|
|
+ Integer fromLbl = parseAddWechatStatusFromLbl(lblDoc);
|
|
|
+ if (fromLbl != null) {
|
|
|
+ log.debug("从lbl_doc解析到加微状态: {}", fromLbl == 1 ? "已加微" : "未加微");
|
|
|
+ return fromLbl;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 如果lbl_doc中没有,再从 properties 解析“客户是否加微”
|
|
|
+ Integer fromProp = parseAddWechatStatusFromProperties(properties);
|
|
|
+ if (fromProp != null) {
|
|
|
+ log.debug("从properties解析到加微状态: {}", fromProp == 1 ? "已加微" : "未加微");
|
|
|
+ return fromProp;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("无法解析加微状态(lbl_doc和properties均无有效数据)");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从 lbl_doc 解析加微状态
|
|
|
+ * 规则:lbl_doc.clbls 中找到 lbl_name = "是否加微",取其 sub_lbls 第一个元素的 lbl_name
|
|
|
+ * 若 lbl_name 为"已加微"则返回1,为"未加微"则返回0
|
|
|
+ *
|
|
|
+ * @param lblDoc 标签文档
|
|
|
+ * @return 1-已加微, 0-未加微, null-未找到或解析失败
|
|
|
+ */
|
|
|
+ private static Integer parseAddWechatStatusFromLbl(LblDoc lblDoc) {
|
|
|
+ if (lblDoc == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<Clbl> clbls = lblDoc.getClbls();
|
|
|
+ if (CollectionUtils.isEmpty(clbls)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ for (Clbl clbl : clbls) {
|
|
|
+ if (clbl == null) continue;
|
|
|
+ Lbl clblLbl = clbl.getLbl();
|
|
|
+ if (clblLbl != null && "是否加微".equals(clblLbl.getLbl_name())) {
|
|
|
+ List<SubLbl> subLbls = clbl.getSub_lbls();
|
|
|
+ if (!CollectionUtils.isEmpty(subLbls)) {
|
|
|
+ SubLbl firstSub = subLbls.get(0);
|
|
|
+ if (firstSub != null && firstSub.getLbl() != null) {
|
|
|
+ String statusName = firstSub.getLbl().getLbl_name();
|
|
|
+ if ("已加微".equals(statusName)) {
|
|
|
+ return 1;
|
|
|
+ } else if ("未加微".equals(statusName)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 找到了“是否加微”标签但没有子标签,视为未知,不再继续查找其他标签
|
|
|
+ log.warn("存在'是否加微'标签但无有效子标签,无法确定加微状态");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("从lbl_doc解析加微状态异常", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从 properties 解析加微状态
|
|
|
* 规则:properties中找到 prop_name = "客户是否加微",解析其 prop_value(JSON数组),
|
|
|
- * 找到 checked=true 的项,若 name 包含"已加微"则返回1,否则返回0
|
|
|
+ * 找到 checked=true 的项,若 name 包含"已加微"则返回1,否则返回0
|
|
|
+ *
|
|
|
+ * @param properties 自定义属性列表
|
|
|
+ * @return 1-已加微, 0-未加微, null-未找到或解析失败
|
|
|
*/
|
|
|
- private static Integer parseAddWechatStatus(List<Property> properties) {
|
|
|
+ private static Integer parseAddWechatStatusFromProperties(List<Property> properties) {
|
|
|
if (CollectionUtils.isEmpty(properties)) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -82,7 +159,7 @@ public class KdzlJsonParser {
|
|
|
}
|
|
|
return parseCheckedStatus(target.getProp_value(), "已加微");
|
|
|
} catch (Exception e) {
|
|
|
- log.error("解析加微状态异常", e);
|
|
|
+ log.error("从properties解析加微状态异常", e);
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
@@ -90,7 +167,10 @@ public class KdzlJsonParser {
|
|
|
/**
|
|
|
* 解析成交状态
|
|
|
* 规则:properties中找到 prop_name = "客户是否成交",解析其 prop_value(JSON数组),
|
|
|
- * 找到 checked=true 的项,若 name 包含"已成交"则返回1,否则返回0
|
|
|
+ * 找到 checked=true 的项,若 name 包含"已成交"则返回1,否则返回0
|
|
|
+ *
|
|
|
+ * @param properties 自定义属性列表
|
|
|
+ * @return 1-已成交, 0-未成交, null-未找到或解析失败
|
|
|
*/
|
|
|
private static Integer parseMakeStatus(List<Property> properties) {
|
|
|
if (CollectionUtils.isEmpty(properties)) {
|
|
|
@@ -112,7 +192,7 @@ public class KdzlJsonParser {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 解析 checked 状态
|
|
|
+ * 解析 checked 状态(通用方法)
|
|
|
*
|
|
|
* @param propValue 类似 "[{\"id\":12052116,\"name\":\"已加微\"},{\"checked\":true,\"id\":12052115,\"name\":\"未加微\"}]"
|
|
|
* @param trueFlag 目标标志(如"已加微"或"已成交")
|
|
|
@@ -150,6 +230,9 @@ public class KdzlJsonParser {
|
|
|
/**
|
|
|
* 解析通话状态(文本)
|
|
|
* 规则:lbl_doc.clbls 中找到 lbl_name = "通话状态",取其 sub_lbls 第一个元素的 lbl_name
|
|
|
+ *
|
|
|
+ * @param lblDoc 标签文档
|
|
|
+ * @return 通话状态文本,如“已接听”“已拨打”,未找到返回null
|
|
|
*/
|
|
|
private static String parseCallStatus(LblDoc lblDoc) {
|
|
|
if (lblDoc == null) {
|