ソースを参照

患者信息表修改认领逻辑

cgp 1 週間 前
コミット
13d7e84938

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

@@ -61,4 +61,9 @@ public interface FsCompanyCustomerMapper {
      *  批量插入客户信息
      * */
     int insertBatchFsCompanyCustomer(@Param("companyCustomers") List<FsCompanyCustomer> companyCustomers);
+
+    /**
+     *  查询客户信息并加锁
+     * */
+    FsCompanyCustomer selectByIdForUpdate(Long id);
 }

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

@@ -123,7 +123,8 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
             //若提交的号码是脱敏的号码,则不需要更新号码
             fsCompanyCustomer.setPhone(null);
         }
-        FsCompanyCustomer oldCustomer = selectFsCompanyCustomerById(fsCompanyCustomer.getId());
+        // 使用行锁查询客户信息(阻塞直到获得锁)
+        FsCompanyCustomer oldCustomer = fsCompanyCustomerMapper.selectByIdForUpdate(fsCompanyCustomer.getId());
         if(oldCustomer.getCompanyUserId()!=null){
             throw new CustomException("客户已被其它销售认领!请刷新后重试");
         }

+ 4 - 0
fs-service/src/main/resources/mapper/qw/FsCompanyCustomerMapper.xml

@@ -114,6 +114,10 @@
         </where>
     </select>
 
+    <select id="selectByIdForUpdate" resultMap="FsCompanyCustomerResult">
+        SELECT * FROM fs_company_customer WHERE id = #{id} FOR UPDATE
+    </select>
+
     <insert id="insertFsCompanyCustomer" parameterType="com.fs.qw.domain.FsCompanyCustomer" useGeneratedKeys="true" keyProperty="id">
         insert into fs_company_customer
         <trim prefix="(" suffix=")" suffixOverrides=",">