Просмотр исходного кода

患者信息表修改认领逻辑

cgp 17 часов назад
Родитель
Сommit
58ef0178c9

+ 18 - 0
fs-company/src/main/java/com/fs/company/controller/qw/FsCompanyCustomerController.java

@@ -5,6 +5,7 @@ import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.page.TableDataInfo;
 import com.fs.common.exception.CustomException;
 import com.fs.common.utils.poi.ExcelUtil;
+import com.fs.company.domain.CompanyUser;
 import com.fs.company.mapper.CompanyUserRoleMapper;
 import com.fs.company.service.ICompanyUserService;
 import com.fs.framework.security.LoginUser;
@@ -155,6 +156,23 @@ public class FsCompanyCustomerController extends BaseController {
         }
     }
 
+    /**
+     * 认领客户
+     */
+    @PutMapping("/claimCustomer")
+    public AjaxResult claimCustomer(@RequestBody FsCompanyCustomer fsCompanyCustomer) {
+        // 获取当前登录销售
+        CompanyUser companyUser = SecurityUtils.getLoginUser().getUser();
+        try {
+            return toAjax(fsCompanyCustomerService.claimCustomer(fsCompanyCustomer,companyUser));
+        } catch (DuplicateKeyException e) {
+            if (e.getMessage().contains("uk_phone")) {
+                return AjaxResult.error("电话号码已存在,请更换后再试");
+            }
+            return AjaxResult.error("数据冲突,请稍后重试");
+        }
+    }
+
     /**
      * 删除客户
      */

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

@@ -1,6 +1,7 @@
 package com.fs.his.service.impl;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -157,6 +158,7 @@ public class FsImportMemberServiceImpl extends ServiceImpl<FsImportMemberMapper,
             customer.setAddress(member.getAddress());
             customer.setCreateTime(nowDate);
             customer.setImportMemberId(member.getId());
+            customer.setClaimStatus(BigDecimal.ZERO.intValue());// 认领状态0:未认领,1:已认领
             return customer;
         }).collect(Collectors.toList());
 

+ 23 - 1
fs-service/src/main/java/com/fs/qw/domain/FsCompanyCustomer.java

@@ -83,10 +83,32 @@ public class FsCompanyCustomer extends BaseEntity {
     /** 导入会员id*/
     private Long importMemberId;
 
+    //购买次数
+    private Long buyCount;
+
+    //认领状态0:未认领,1:已认领
+    private int claimStatus;
+
+    //以下字段(非数据库字段,用于接收查询参数)
+
+    /** 创建时间开始 */
+    private String beginCreateTime;
+
+    /** 创建时间结束 */
+    private String endCreateTime;
+
+    /** 是否已购(true: buy_count>0) */
+    private Boolean purchased;
+
+    /** 最小购买次数 */
+    private Integer minBuyCount;
+
+    /** 最大购买次数 */
+    private Integer maxBuyCount;
     // 分页相关
     private Integer pageNum;
     private Integer pageSize;
 
-    /** 是否为自己客户(非数据库字段)true:自己的客户,false:其他人的客户 */
+    /** 是否为自己客户true:自己的客户,false:其他人的客户 */
     private Boolean myCustomerFlag;
 }

+ 3 - 0
fs-service/src/main/java/com/fs/qw/service/IFsCompanyCustomerService.java

@@ -1,5 +1,6 @@
 package com.fs.qw.service;
 
+import com.fs.company.domain.CompanyUser;
 import com.fs.qw.domain.FsCompanyCustomer;
 import com.fs.qw.param.TransferCustomerParam;
 
@@ -28,4 +29,6 @@ public interface IFsCompanyCustomerService {
     //执行转交销售客户信息
     int transferCustomer(TransferCustomerParam transferCustomerParam);
 
+    //执行认领销售客户信息
+    int claimCustomer(FsCompanyCustomer fsCompanyCustomer,CompanyUser companyUser);
 }

+ 38 - 2
fs-service/src/main/java/com/fs/qw/service/impl/FsCompanyCustomerServiceImpl.java

@@ -1,14 +1,20 @@
 package com.fs.qw.service.impl;
 
 import com.fs.common.exception.CustomException;
+import com.fs.company.domain.CompanyUser;
+import com.fs.his.domain.FsImportMember;
+import com.fs.his.mapper.FsImportMemberMapper;
 import com.fs.qw.domain.FsCompanyCustomer;
 import com.fs.qw.mapper.FsCompanyCustomerMapper;
 import com.fs.qw.param.TransferCustomerParam;
 import com.fs.qw.service.IFsCompanyCustomerService;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.Collections;
 import java.util.List;
 
@@ -18,11 +24,15 @@ import java.util.List;
  * @author yourname
  * @date 2026-04-30
  */
+@Slf4j
 @Service
 public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
     @Autowired
     private FsCompanyCustomerMapper fsCompanyCustomerMapper;
 
+    @Autowired
+    private FsImportMemberMapper importMemberMapper;
+
     @Override
     public FsCompanyCustomer selectFsCompanyCustomerById(Long id) {
         return fsCompanyCustomerMapper.selectFsCompanyCustomerById(id);
@@ -71,10 +81,10 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
             //若提交的号码是脱敏的号码,则不需要更新号码
             fsCompanyCustomer.setPhone(null);
         }
-        //更新之前查询一下(因为认领接口也走的这个逻辑)
+        //更新之前查询一下
         FsCompanyCustomer oldCustomer = selectFsCompanyCustomerById(fsCompanyCustomer.getId());
         if(oldCustomer.getCompanyUserId()!=null&&oldCustomer.getCompanyUserId()!=fsCompanyCustomer.getCompanyUserId()){
-            throw new CustomException("客户信息已被其它销售认领!");
+            throw new CustomException("网络繁忙!请稍后再试");
         }
         return fsCompanyCustomerMapper.updateFsCompanyCustomer(fsCompanyCustomer);
     }
@@ -104,4 +114,30 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
         //修改客户的归属销售id
         return fsCompanyCustomerMapper.updateCompanyUserIdByIds(param);
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int claimCustomer(FsCompanyCustomer fsCompanyCustomer, CompanyUser companyUser) {
+        if (fsCompanyCustomer.getPhone()!=null&&fsCompanyCustomer.getPhone().contains("*")){
+            //若提交的号码是脱敏的号码,则不需要更新号码
+            fsCompanyCustomer.setPhone(null);
+        }
+        FsCompanyCustomer oldCustomer = selectFsCompanyCustomerById(fsCompanyCustomer.getId());
+        if(oldCustomer.getCompanyUserId()!=null){
+            throw new CustomException("客户已被其它销售认领!请刷新后重试");
+        }
+
+        if (oldCustomer.getImportMemberId()==null){
+            log.error("销售认领客户数据异常,客户信息id:{}",oldCustomer.getId());
+            throw new CustomException("网络繁忙!请稍后再试");
+        }
+        FsImportMember fsImportMember=new FsImportMember();
+        fsImportMember.setId(oldCustomer.getImportMemberId());
+        fsImportMember.setCompanyId(companyUser.getCompanyId());
+        fsImportMember.setCompanyUserId(companyUser.getUserId());
+        //更新关联的导入会员表信息
+        importMemberMapper.updateFsImportMember(fsImportMember);
+        fsCompanyCustomer.setClaimStatus(BigDecimal.ONE.intValue());//已认领
+        return fsCompanyCustomerMapper.updateFsCompanyCustomer(fsCompanyCustomer);
+    }
 }

+ 36 - 7
fs-service/src/main/resources/mapper/qw/FsCompanyCustomerMapper.xml

@@ -25,14 +25,17 @@
         <result property="updateBy"          column="update_by"          />
         <result property="updateTime"        column="update_time"        />
         <result property="remark"            column="remark"             />
-        <result property="importMemberId"    column="import_member_id"             />
+        <result property="importMemberId"    column="import_member_id"   />
+        <result property="buyCount"          column="buy_count"          />
+        <result property="claimStatus"       column="claim_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
+               create_by, create_time, update_by, update_time, remark, del_flag, import_member_id,
+               buy_count,claim_status
         from fs_company_customer
     </sql>
 
@@ -51,12 +54,33 @@
         <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>
@@ -72,7 +96,6 @@
         <include refid="selectFsCompanyCustomerVo"/>
         <where>
             del_flag = '0'
-            <!-- 销售ID集合必传,不存在或为空时不生成任何条件(调用前必须确保有值) -->
             <if test="companyUserIds != null and companyUserIds.size() > 0">
                 and company_user_id IN
                 <foreach collection="companyUserIds" item="id" open="(" separator="," close=")">
@@ -111,6 +134,8 @@
             <if test="createBy != null">create_by,</if>
             <if test="remark != null">remark,</if>
             <if test="importMemberId != null">import_member_id,</if>
+            <if test="buyCount != null">buy_count,</if>
+            <if test="claimStatus != null">claim_status,</if>
             create_time
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -131,16 +156,18 @@
             <if test="createBy != null">#{createBy},</if>
             <if test="remark != null">#{remark},</if>
             <if test="importMemberId != null">#{importMemberId},</if>
+            <if test="buyCount != null">#{buyCount},</if>
+            <if test="claimStatus != null">#{claimStatus},</if>
             sysdate()
         </trim>
     </insert>
 
-    <!-- 遇到重复电话直接忽略,继续插入下一条 -->
+    <!-- 批量插入,支持 buy_count,若未传入则默认 0 -->
     <insert id="insertBatchFsCompanyCustomer">
-        INSERT IGNORE INTO fs_company_customer (customer_name, address, phone,create_time,import_member_id)
+        INSERT IGNORE INTO fs_company_customer (customer_name, address, phone, create_time, import_member_id,claim_status)
         VALUES
         <foreach collection="companyCustomers" item="item" separator=",">
-            (#{item.customerName}, #{item.address}, #{item.phone},#{item.createTime},#{item.importMemberId})
+            (#{item.customerName}, #{item.address}, #{item.phone}, #{item.createTime}, #{item.importMemberId}, #{item.claimStatus})
         </foreach>
     </insert>
 
@@ -163,6 +190,8 @@
             <if test="allergyHistory != null">allergy_history = #{allergyHistory},</if>
             <if test="remark != null">remark = #{remark},</if>
             <if test="importMemberId != null">import_member_id = #{importMemberId},</if>
+            <if test="buyCount != null">buy_count = #{buyCount},</if>
+            <if test="claimStatus != null">claim_status = #{claimStatus},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
             update_time = sysdate()
         </set>
@@ -184,7 +213,7 @@
         update fs_company_customer
         set company_user_id   = #{targetDoctorId},
         company_user_name = #{targetDoctorName},
-        update_time= sysdate()
+        update_time = sysdate()
         where del_flag = '0'
         and id in
         <foreach collection="customerIds" item="id" open="(" separator="," close=")">