dos 2 mesi fa
parent
commit
89cd96ac87

+ 13 - 8
game-business/src/main/java/com/game/business/service/impl/AppUserServiceImpl.java

@@ -183,9 +183,11 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
         int finRes = 0;
         RLock rLock = redisson.getLock("app_user_amount_".concat(String.valueOf(finTranRecord.getUid())));
         boolean tryLock = false;
+        boolean hasLock = false;
         try {
             tryLock = rLock.tryLock(10L,10L, TimeUnit.SECONDS); //等待10秒 最多持有锁10秒
             if(tryLock){
+                hasLock = true;
                 AppUser appUser = appUserMapper.selectAppUserByUserid(finTranRecord.getUid());
                 if(null != appUser){
                     AppUser updateAppUser = new AppUser();
@@ -223,17 +225,19 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
                     }
                 }
             }else{
-                log.info("用户{}钱包更新失败:{}",finTranRecord.getUid(),tryLock);
+                //获取锁失败则递归再次调用
+                log.info("更新钱包等待超时,再次重试");
+                updateUserAmount(finTranRecord,withdrawAble,coinCashFlag);
             }
         } catch (InterruptedException e) {
             log.info("用户{}钱包更新失败:{}",finTranRecord.getUid(),e);
         } finally {
-            if(finRes < 1){
+            if(finRes < 1 && hasLock){
                 String params = "";
                 if(null != finTranRecord){
                     params = JSONObject.toJSONString(finTranRecord);
                 }
-                log.info("res:{},finRes:{},更新失败:{}",res,finRes,params);
+                log.info("res:{},finRes:{},更新失败:{},hasLock",res,finRes,params,hasLock);
                 throw new ServiceException("更新失败");
             }
             rLock.unlock();
@@ -269,16 +273,17 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
             if(tryLock){
                 AppUser appUser = selectAppUserByUserid(userId);
                 return appUser;
+            }else{
+                return getUserAsset(userId);
             }
-            rLock.unlock();
         }catch (Exception e){
             log.info("获取用户资产出错:{}",e);
             return null;
+        }finally {
+            if(null != rLock){
+                rLock.unlock();
+            }
         }
-        if(null != rLock){
-            rLock.unlock();
-        }
-        return null;
     }
 
     @Override