ソースを参照

客户信息表同步增加客户成交状态、加微状态、通话状态

cgp 10 時間 前
コミット
6a1449d877

+ 10 - 0
fs-service/src/main/java/com/fs/his/service/impl/FsImportMemberServiceImpl.java

@@ -13,10 +13,12 @@ import com.fs.common.utils.DateUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.his.dto.MemberExcelDTO;
 import com.fs.his.listenner.MemberImportListener;
+import com.fs.his.utils.KdzlJsonParser;
 import com.fs.kdzl.dto.Custm;
 import com.fs.kdzl.dto.Property;
 import com.fs.kdzl.service.KdzlService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
@@ -177,6 +179,10 @@ public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper,
             customer.setCurrentMedication(member.getCurrentMedication());
             customer.setAllergyHistory(member.getAllergyHistory());
             customer.setClaimStatus(0);  //未认领状态
+            // 解析口袋助理JSON
+            if (StringUtils.isNotBlank(member.getKdzlMemberJson())) {
+                KdzlJsonParser.fillCustomerFromKdzlJson(customer, member.getKdzlMemberJson());
+            }
             return customer;
         }).collect(Collectors.toList());
 
@@ -228,6 +234,10 @@ public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper,
         return baseMapper.batchUpdateCompletionStatus(allProcessedIds);
     }
 
+    /**
+     * 解析每行json内容 获取客户加微状态、成交状态、通话状态
+     * */
+
     @Override
     @Async
     public void syncKdzlMemberInfo() {

+ 186 - 0
fs-service/src/main/java/com/fs/his/utils/KdzlJsonParser.java

@@ -0,0 +1,186 @@
+package com.fs.his.utils;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fs.kdzl.dto.*;
+import com.fs.qw.domain.FsCompanyCustomer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
+/**
+ * 口袋助理JSON解析工具类
+ * 用于从JSON中提取加微状态、成交状态、通话状态
+ */
+@Slf4j
+public class KdzlJsonParser {
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 解析口袋助理会员JSON,填充客户对象的加微状态、成交状态、通话状态
+     *
+     * @param customer       客户对象(会被修改)
+     * @param kdzlMemberJson 口袋助理会员JSON字符串
+     */
+    public static void fillCustomerFromKdzlJson(FsCompanyCustomer customer, String kdzlMemberJson) {
+        if (customer == null || StringUtils.isBlank(kdzlMemberJson)) {
+            log.warn("fillCustomerFromKdzlJson: customer为空或JSON为空");
+            return;
+        }
+
+        try {
+            // 反序列化为Custm对象
+            Custm custm = objectMapper.readValue(kdzlMemberJson, Custm.class);
+            if (custm == null) {
+                log.warn("解析Custm对象为null, JSON可能为空对象,待同步importMemberId:{}",customer.getImportMemberId());
+                return;
+            }
+
+            // 1. 解析加微状态
+            Integer addWechatStatus = parseAddWechatStatus(custm.getProperties());
+            if (addWechatStatus != null) {
+                customer.setKdzlAddWechatStatus(addWechatStatus);
+            }
+
+            // 2. 解析成交状态
+            Integer makeStatus = parseMakeStatus(custm.getProperties());
+            if (makeStatus != null) {
+                customer.setKdzlMakeStatus(makeStatus);
+            }
+
+            // 3. 解析通话状态(文本描述)
+            String callStatus = parseCallStatus(custm.getLbl_doc());
+            if (StringUtils.isNotBlank(callStatus)) {
+                customer.setKdzlCallStatus(callStatus);
+            }
+
+        } catch (Exception e) {
+            log.error("待同步的importMemberId:{}",customer.getImportMemberId());
+            log.error("解析口袋助理JSON失败, json={}", kdzlMemberJson, e);
+        }
+    }
+
+    /**
+     * 解析加微状态
+     * 规则:properties中找到 prop_name = "客户是否加微",解析其 prop_value(JSON数组),
+     * 找到 checked=true 的项,若 name 包含"已加微"则返回1,否则返回0
+     */
+    private static Integer parseAddWechatStatus(List<Property> properties) {
+        if (CollectionUtils.isEmpty(properties)) {
+            return null;
+        }
+        try {
+            Property target = properties.stream()
+                    .filter(p -> p != null && "客户是否加微".equals(p.getProp_name()))
+                    .findFirst()
+                    .orElse(null);
+            if (target == null || StringUtils.isBlank(target.getProp_value())) {
+                return null;
+            }
+            return parseCheckedStatus(target.getProp_value(), "已加微");
+        } catch (Exception e) {
+            log.error("解析加微状态异常", e);
+            return null;
+        }
+    }
+
+    /**
+     * 解析成交状态
+     * 规则:properties中找到 prop_name = "客户是否成交",解析其 prop_value(JSON数组),
+     * 找到 checked=true 的项,若 name 包含"已成交"则返回1,否则返回0
+     */
+    private static Integer parseMakeStatus(List<Property> properties) {
+        if (CollectionUtils.isEmpty(properties)) {
+            return null;
+        }
+        try {
+            Property target = properties.stream()
+                    .filter(p -> p != null && "客户是否成交".equals(p.getProp_name()))
+                    .findFirst()
+                    .orElse(null);
+            if (target == null || StringUtils.isBlank(target.getProp_value())) {
+                return null;
+            }
+            return parseCheckedStatus(target.getProp_value(), "已成交");
+        } catch (Exception e) {
+            log.error("解析成交状态异常", e);
+            return null;
+        }
+    }
+
+    /**
+     * 解析 checked 状态
+     *
+     * @param propValue 类似 "[{\"id\":12052116,\"name\":\"已加微\"},{\"checked\":true,\"id\":12052115,\"name\":\"未加微\"}]"
+     * @param trueFlag  目标标志(如"已加微"或"已成交")
+     * @return 1 表示匹配成功,0 表示匹配失败(即未加微/未成交),null表示解析失败或未找到
+     */
+    private static Integer parseCheckedStatus(String propValue, String trueFlag) {
+        if (StringUtils.isBlank(propValue) || StringUtils.isBlank(trueFlag)) {
+            return null;
+        }
+        try {
+            JsonNode arrayNode = objectMapper.readTree(propValue);
+            if (arrayNode == null || !arrayNode.isArray()) {
+                log.warn("parseCheckedStatus: 期望数组类型, 实际为 {}", propValue);
+                return null;
+            }
+            for (JsonNode item : arrayNode) {
+                if (item == null) continue;
+                JsonNode checkedNode = item.get("checked");
+                if (checkedNode != null && checkedNode.asBoolean()) {
+                    JsonNode nameNode = item.get("name");
+                    if (nameNode != null && nameNode.asText().contains(trueFlag)) {
+                        return 1;
+                    } else {
+                        return 0;
+                    }
+                }
+            }
+            log.debug("parseCheckedStatus: 未找到checked=true的项, propValue={}", propValue);
+        } catch (Exception e) {
+            log.error("解析checked状态失败, propValue={}, trueFlag={}", propValue, trueFlag, e);
+        }
+        return null;
+    }
+
+    /**
+     * 解析通话状态(文本)
+     * 规则:lbl_doc.clbls 中找到 lbl_name = "通话状态",取其 sub_lbls 第一个元素的 lbl_name
+     */
+    private static String parseCallStatus(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 (StringUtils.isNotBlank(statusName)) {
+                                return statusName;
+                            }
+                        }
+                    }
+                    // 找到了"通话状态"但没有有效子状态,跳出循环
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            log.error("解析通话状态异常", e);
+        }
+        return null;
+    }
+}

+ 9 - 0
fs-service/src/main/java/com/fs/qw/domain/FsCompanyCustomer.java

@@ -98,6 +98,15 @@ public class FsCompanyCustomer extends BaseEntity {
     //归属部门名称
     private String deptName;
 
+    //口袋助理-加微状态0:未加,1:已加
+    private Integer kdzlAddWechatStatus;
+
+    //口袋助理-成交状态0:未成交,1:已成交
+    private Integer kdzlMakeStatus;
+
+    //口袋助理-通话状态,第三方返回的纯文字描述
+    private String kdzlCallStatus;
+
     //以下字段(非数据库字段,用于接收查询参数)
 
     /*** 认领号码*/

+ 42 - 8
fs-service/src/main/resources/mapper/qw/FsCompanyCustomerMapper.xml

@@ -31,15 +31,20 @@
         <result property="completeStatus"    column="complete_status"    />
         <result property="deptId"            column="dept_id"            />
         <result property="deptName"          column="dept_name"          />
+        <!-- 口袋助理相关字段 -->
+        <result property="kdzlAddWechatStatus" column="kdzl_add_wechat_status" />
+        <result property="kdzlMakeStatus"      column="kdzl_make_status"      />
+        <result property="kdzlCallStatus"      column="kdzl_call_status"      />
     </resultMap>
 
     <sql id="selectFsCompanyCustomerVo">
         select id, customer_name, sex, age, address, phone, filing_time,
-        company_user_id, company_user_name, appointment_time, doctor_id, doctor_name,
-        present_illness, current_medication, allergy_history,
-        create_by, create_time, update_by, update_time, remark, del_flag, import_member_id,
-        buy_count, claim_status,
-        complete_status, dept_id, dept_name
+               company_user_id, company_user_name, appointment_time, doctor_id, doctor_name,
+               present_illness, current_medication, allergy_history,
+               create_by, create_time, update_by, update_time, remark, del_flag, import_member_id,
+               buy_count, claim_status,
+               complete_status, dept_id, dept_name,
+               kdzl_add_wechat_status, kdzl_make_status, kdzl_call_status
         from fs_company_customer
     </sql>
 
@@ -204,6 +209,10 @@
             <if test="completeStatus != null">complete_status,</if>
             <if test="deptId != null">dept_id,</if>
             <if test="deptName != null">dept_name,</if>
+            <!-- 口袋助理字段 -->
+            <if test="kdzlAddWechatStatus != null">kdzl_add_wechat_status,</if>
+            <if test="kdzlMakeStatus != null">kdzl_make_status,</if>
+            <if test="kdzlCallStatus != null">kdzl_call_status,</if>
             create_time
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -229,21 +238,27 @@
             <if test="completeStatus != null">#{completeStatus},</if>
             <if test="deptId != null">#{deptId},</if>
             <if test="deptName != null">#{deptName},</if>
+            <!-- 口袋助理字段值 -->
+            <if test="kdzlAddWechatStatus != null">#{kdzlAddWechatStatus},</if>
+            <if test="kdzlMakeStatus != null">#{kdzlMakeStatus},</if>
+            <if test="kdzlCallStatus != null">#{kdzlCallStatus},</if>
             sysdate()
         </trim>
     </insert>
 
-    <!-- 批量新增-->
+    <!-- 批量新增(保持原字段不变,新字段不在此处插入,如有需要可另行扩展) -->
     <insert id="insertBatchFsCompanyCustomer" parameterType="list">
         INSERT IGNORE INTO fs_company_customer (
         customer_name, phone, address, create_time,
-        import_member_id, present_illness, current_medication, allergy_history, claim_status
+        import_member_id, present_illness, current_medication, allergy_history, claim_status,
+        kdzl_add_wechat_status, kdzl_make_status, kdzl_call_status
         ) VALUES
         <foreach collection="companyCustomers" item="item" separator=",">
             (
             #{item.customerName}, #{item.phone}, #{item.address}, #{item.createTime},
             #{item.importMemberId}, #{item.presentIllness}, #{item.currentMedication},
-            #{item.allergyHistory}, #{item.claimStatus}
+            #{item.allergyHistory}, #{item.claimStatus},
+             #{item.kdzlAddWechatStatus}, #{item.kdzlMakeStatus}, #{item.kdzlCallStatus}
             )
         </foreach>
     </insert>
@@ -272,6 +287,10 @@
             <if test="completeStatus != null">complete_status = #{completeStatus},</if>
             <if test="deptId != null">dept_id = #{deptId},</if>
             <if test="deptName != null">dept_name = #{deptName},</if>
+            <!-- 口袋助理字段 -->
+            <if test="kdzlAddWechatStatus != null">kdzl_add_wechat_status = #{kdzlAddWechatStatus},</if>
+            <if test="kdzlMakeStatus != null">kdzl_make_status = #{kdzlMakeStatus},</if>
+            <if test="kdzlCallStatus != null">kdzl_call_status = #{kdzlCallStatus},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
             update_time = sysdate()
         </set>
@@ -319,6 +338,21 @@
                     WHEN import_member_id = #{item.importMemberId} THEN #{item.allergyHistory}
                 </foreach>
             </trim>
+            <trim prefix="kdzl_add_wechat_status = CASE" suffix="END,">
+                <foreach collection="companyCustomers" item="item">
+                    WHEN import_member_id = #{item.importMemberId} THEN #{item.kdzlAddWechatStatus}
+                </foreach>
+            </trim>
+            <trim prefix="kdzl_make_status = CASE" suffix="END,">
+                <foreach collection="companyCustomers" item="item">
+                    WHEN import_member_id = #{item.importMemberId} THEN #{item.kdzlMakeStatus}
+                </foreach>
+            </trim>
+            <trim prefix="kdzl_call_status = CASE" suffix="END,">
+                <foreach collection="companyCustomers" item="item">
+                    WHEN import_member_id = #{item.importMemberId} THEN #{item.kdzlCallStatus}
+                </foreach>
+            </trim>
         </trim>
         WHERE import_member_id IN
         <foreach collection="companyCustomers" item="item" open="(" separator="," close=")">