Преглед на файлове

完善同步客户信息表的定时任务逻辑

cgp преди 2 дни
родител
ревизия
55c0351ab4

+ 1 - 0
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -2555,6 +2555,7 @@ public class Task {
      * */
     public void pullWxPaymentRecord(){
         QwCompany qwCompany=new QwCompany();
+        qwCompany.setStatus(1L);
         //获取所有启用的微信企业列表
         List<QwCompany> qwCompanyList = qwCompanyService.selectQwCompanyList(qwCompany);
         // 当前时间(东八区)

+ 1 - 1
fs-service/src/main/java/com/fs/his/mapper/FsImportMemberMapper.java

@@ -74,7 +74,7 @@ public interface FsImportMemberMapper extends BaseMapper<FsImportMember>{
      * @param importMemberIds 导入会员ID集合
      * @return 修改数量
      */
-    int completionStatus(@Param("importMemberIds") List<Long> importMemberIds);
+    int batchUpdateCompletionStatus(@Param("importMemberIds") List<Long> importMemberIds);
 
     /**
      * 根据口袋助理会员ID查询导入会员

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

@@ -5,6 +5,7 @@ import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import com.alibaba.excel.EasyExcel;
@@ -12,6 +13,7 @@ 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 lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import com.fs.qw.mapper.FsCompanyCustomerMapper;
 import org.apache.commons.collections4.CollectionUtils;
@@ -30,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
  * @author fs
  * @date 2026-05-25
  */
+@Slf4j
 @Service
 public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper, FsImportMember> implements IFsImportMemberService {
 
@@ -150,8 +153,8 @@ public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper,
             return 0;
         }
         Date nowDate = DateUtils.getNowDate();
-        // 2. 将导入会员转换为销售客户对象(如果新增了额外属性,记得改一下批量新增的mapper.xml语句)
-        List<FsCompanyCustomer> companyCustomers = fsImportMembers.stream().map(member -> {
+        // 2. 将导入会员转换为销售客户对象,并初始化 claimStatus = 0(未认领)
+        List<FsCompanyCustomer> importCustomers = fsImportMembers.stream().map(member -> {
             FsCompanyCustomer customer = new FsCompanyCustomer();
             customer.setCustomerName(member.getMemberName());
             customer.setPhone(member.getMemberPhone());
@@ -161,26 +164,55 @@ public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper,
             customer.setPresentIllness(member.getPresentIllness());
             customer.setCurrentMedication(member.getCurrentMedication());
             customer.setAllergyHistory(member.getAllergyHistory());
-            customer.setClaimStatus(BigDecimal.ZERO.intValue());// 认领状态0:未认领,1:已认领
+            customer.setClaimStatus(0);  //未认领状态
             return customer;
         }).collect(Collectors.toList());
 
-        // 3. 分批插入,并统计实际成功插入的数量
+        // 3. 查询已存在的 import_member_id
+        FsCompanyCustomer queryCondition = new FsCompanyCustomer();
+        List<FsCompanyCustomer> originCustomerList = fsCompanyCustomerMapper.selectImportFsCompanyCustomerList(queryCondition);
+        Set<Long> existedImportIds = originCustomerList.stream()
+                .map(FsCompanyCustomer::getImportMemberId)
+                .collect(Collectors.toSet());
+
+        // 待更新:import_member_id 已存在
+        List<FsCompanyCustomer> existCustomerList = importCustomers.stream()
+                .filter(item -> existedImportIds.contains(item.getImportMemberId()))
+                .collect(Collectors.toList());
+
+        // 待新增:import_member_id 不存在
+        List<FsCompanyCustomer> willAddCustomers = importCustomers.stream()
+                .filter(item -> !existedImportIds.contains(item.getImportMemberId()))
+                .collect(Collectors.toList());
+
+        // 执行更新
+        int batchUpdateSize = 500;
+        int totalUpdateCount = 0; // 记录总共成功更新了多少条
+        for (int i = 0; i < existCustomerList.size(); i += batchUpdateSize) {
+            int end = Math.min(i + batchUpdateSize, existCustomerList.size());
+            List<FsCompanyCustomer> subList = existCustomerList.subList(i, end);
+            // updateBatchFsCompanyCustomer 批量更新返回该批次实际影响的行数(已存在的客户表信息数据不需要更新认领状态)
+            int updatedInBatch = fsCompanyCustomerMapper.updateBatchFsCompanyCustomer(subList);
+            totalUpdateCount += updatedInBatch;
+        }
+        log.info("定时同步会员信息表,批量更新了{}条数据", totalUpdateCount);
+        // 执行新增
         int batchSize = 500;
-        int totalInsertedCount = 0; // 记录总共成功插入了多少条
+        int totalAddCount = 0; // 记录总共成功新增了多少条
 
-        for (int i = 0; i < companyCustomers.size(); i += batchSize) {
-            int end = Math.min(i + batchSize, companyCustomers.size());
-            List<FsCompanyCustomer> subList = companyCustomers.subList(i, end);
+        for (int i = 0; i < willAddCustomers.size(); i += batchSize) {
+            int end = Math.min(i + batchSize, willAddCustomers.size());
+            List<FsCompanyCustomer> subList = willAddCustomers.subList(i, end);
             // insertBatchFsCompanyCustomer 返回该批次实际影响的行数
             int insertedInBatch = fsCompanyCustomerMapper.insertBatchFsCompanyCustomer(subList);
-            totalInsertedCount += insertedInBatch;
+            totalAddCount += insertedInBatch;
         }
+        log.info("定时同步会员信息表,批量新增了{}条数据", totalAddCount);
         // 4. 合并需要更新状态的ID
         List<Long> allProcessedIds = fsImportMembers.stream()
                 .map(FsImportMember::getId)
                 .collect(Collectors.toList());
         // 6. 批量修改导入会员状态
-        return baseMapper.completionStatus(allProcessedIds);
+        return baseMapper.batchUpdateCompletionStatus(allProcessedIds);
     }
 }

+ 10 - 0
fs-service/src/main/java/com/fs/qw/mapper/FsCompanyCustomerMapper.java

@@ -23,6 +23,11 @@ public interface FsCompanyCustomerMapper {
      */
     public List<FsCompanyCustomer> selectFsCompanyCustomerList(FsCompanyCustomer fsCompanyCustomer);
 
+    /**
+     * 查询导入客户信息列表
+     */
+    public List<FsCompanyCustomer> selectImportFsCompanyCustomerList(FsCompanyCustomer fsCompanyCustomer);
+
     /**
      * 新增客户信息
      */
@@ -62,6 +67,11 @@ public interface FsCompanyCustomerMapper {
      * */
     int insertBatchFsCompanyCustomer(@Param("companyCustomers") List<FsCompanyCustomer> companyCustomers);
 
+    /**
+     *  批量更新客户信息
+     * */
+    int updateBatchFsCompanyCustomer(@Param("companyCustomers") List<FsCompanyCustomer> companyCustomers);
+
     /**
      *  查询客户信息并加锁
      * */

+ 1 - 1
fs-service/src/main/resources/mapper/his/FsImportMemberMapper.xml

@@ -99,7 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </update>
 
-    <update id="completionStatus">
+    <update id="batchUpdateCompletionStatus">
         update fs_import_member set status = 1 where id in
         <foreach item="id" collection="importMemberIds" open="(" separator="," close=")">
             #{id}

+ 79 - 15
fs-service/src/main/resources/mapper/qw/FsCompanyCustomerMapper.xml

@@ -91,6 +91,55 @@
         order by filing_time desc
     </select>
 
+    <select id="selectImportFsCompanyCustomerList" parameterType="com.fs.qw.domain.FsCompanyCustomer"
+            resultMap="FsCompanyCustomerResult">
+        <include refid="selectFsCompanyCustomerVo"/>
+        where del_flag = '0' and import_member_id is not null
+        <if test="customerName != null and customerName != ''">
+            and customer_name like concat('%', #{customerName}, '%')
+        </if>
+        <if test="phone != null and phone != ''">
+            and phone like concat('%', #{phone}, '%')
+        </if>
+        <if test="companyUserName != null and companyUserName != ''">
+            and company_user_name like concat('%', #{companyUserName}, '%')
+        </if>
+        <if test="companyUserId != null">
+            and company_user_id = #{companyUserId}
+        </if>
+        <if test="claimStatus != null">
+            and claim_status = #{claimStatus}
+        </if>
+        <if test="beginTime != null and beginTime != ''">
+            and filing_time &gt;= #{beginTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            and filing_time &lt;= #{endTime}
+        </if>
+        <if test="beginCreateTime != null and beginCreateTime != ''">
+            and create_time &gt;= #{beginCreateTime}
+        </if>
+        <if test="endCreateTime != null and endCreateTime != ''">
+            and create_time &lt;= #{endCreateTime}
+        </if>
+        <if test="purchased != null and purchased == true">
+            and buy_count > 0
+        </if>
+        <if test="minBuyCount != null">
+            and buy_count &gt;= #{minBuyCount}
+        </if>
+        <if test="maxBuyCount != null">
+            and buy_count &lt;= #{maxBuyCount}
+        </if>
+        <if test="importMemberId != null">
+            and import_member_id = #{importMemberId}
+        </if>
+        <if test="completeStatus != null">
+            and complete_status = #{completeStatus}
+        </if>
+        order by filing_time desc
+    </select>
+
     <select id="selectFsCompanyCustomerById" parameterType="Long" resultMap="FsCompanyCustomerResult">
         <include refid="selectFsCompanyCustomerVo"/>
         where id = #{id} and del_flag = '0'
@@ -179,24 +228,14 @@
     <!-- 批量新增-->
     <insert id="insertBatchFsCompanyCustomer" parameterType="list">
         INSERT IGNORE INTO fs_company_customer (
-        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, remark,
-        import_member_id, buy_count, claim_status,
-        complete_status, dept_id, dept_name,
-        create_time
+        customer_name, phone, address, create_time,
+        import_member_id, present_illness, current_medication, allergy_history, claim_status
         ) VALUES
         <foreach collection="companyCustomers" item="item" separator=",">
             (
-            #{item.customerName}, #{item.sex}, #{item.age}, #{item.address},
-            #{item.phone}, #{item.filingTime}, #{item.companyUserId},
-            #{item.companyUserName}, #{item.appointmentTime}, #{item.doctorId},
-            #{item.doctorName}, #{item.presentIllness}, #{item.currentMedication},
-            #{item.allergyHistory}, #{item.createBy}, #{item.remark},
-            #{item.importMemberId}, #{item.buyCount}, #{item.claimStatus},
-            #{item.completeStatus}, #{item.deptId}, #{item.deptName},
-            #{item.createTime}
+            #{item.customerName}, #{item.phone}, #{item.address}, #{item.createTime},
+            #{item.importMemberId}, #{item.presentIllness}, #{item.currentMedication},
+            #{item.allergyHistory}, #{item.claimStatus}
             )
         </foreach>
     </insert>
@@ -254,4 +293,29 @@
         </foreach>
     </update>
 
+    <update id="updateBatchFsCompanyCustomer">
+        UPDATE fs_company_customer
+        <trim prefix="SET" suffixOverrides=",">
+            <trim prefix="present_illness = CASE" suffix="END,">
+                <foreach collection="companyCustomers" item="item">
+                    WHEN id = #{item.id} THEN #{item.presentIllness}
+                </foreach>
+            </trim>
+            <trim prefix="current_medication = CASE" suffix="END,">
+                <foreach collection="companyCustomers" item="item">
+                    WHEN id = #{item.id} THEN #{item.currentMedication}
+                </foreach>
+            </trim>
+            <trim prefix="allergy_history = CASE" suffix="END,">
+                <foreach collection="companyCustomers" item="item">
+                    WHEN id = #{item.id} THEN #{item.allergyHistory}
+                </foreach>
+            </trim>
+        </trim>
+        WHERE id IN
+        <foreach collection="companyCustomers" item="item" open="(" separator="," close=")">
+            #{item.id}
+        </foreach>
+    </update>
+
 </mapper>