Parcourir la source

问题修改:账户入账问题修改

liweifan il y a 3 ans
Parent
commit
376b228b40

+ 2 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserAccountService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.yonge.cooleshow.biz.dal.dto.UserAccountRecordDto;
 import com.yonge.cooleshow.biz.dal.dto.req.TotalReq;
 import com.yonge.cooleshow.biz.dal.entity.UserAccountRecord;
+import com.yonge.cooleshow.biz.dal.vo.UserAccountRecordVo;
 import com.yonge.cooleshow.biz.dal.vo.UserAccountVo;
 import com.yonge.cooleshow.biz.dal.dto.search.UserAccountSearch;
 import com.yonge.cooleshow.biz.dal.entity.UserAccount;
@@ -70,7 +71,7 @@ public interface UserAccountService extends IService<UserAccount>  {
      * @updateTime 2022/4/7 16:40
      * @return: java.lang.Integer
      */
-    HttpResponseResult<UserAccountRecord> accountChange(Long recordId, PostStatusEnum postStatus);
+    HttpResponseResult<UserAccountRecord> accountChange(UserAccountRecord record, PostStatusEnum postStatus);
     /***
      * 账户统计查询
      * @author liweifan

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/CourseScheduleServiceImpl.java

@@ -1779,7 +1779,7 @@ public class CourseScheduleServiceImpl extends ServiceImpl<CourseScheduleDao, Co
             for (UserAccountRecordDto dto : list) {
                 UserAccountRecordVo record = userAccountRecordService.detail(dto.getOrderNo(), dto.getBizType(), dto.getBizId());
                 if (null != record) {
-                    userAccountService.accountChange(record.getId(), PostStatusEnum.RECORDED);
+                    userAccountService.accountChange(record, PostStatusEnum.RECORDED);
                 }
             }
             Set<Long> bizIds = list.stream().map(UserAccountRecordDto::getBizId).collect(Collectors.toSet());

+ 1 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserAccountRecordServiceImpl.java

@@ -105,7 +105,7 @@ public class UserAccountRecordServiceImpl extends ServiceImpl<UserAccountRecordD
         paramNames.add(AccountBizTypeEnum.VIP_SHARE.getCode());
         List<UserAccountRecord> accountRecords = baseMapper.queryCanAccountByBizType(paramNames);
         for (UserAccountRecord accountRecord : accountRecords) {
-            userAccountService.accountChange(accountRecord.getId(), PostStatusEnum.RECORDED);
+            userAccountService.accountChange(accountRecord, PostStatusEnum.RECORDED);
         }
     }
 
@@ -115,7 +115,6 @@ public class UserAccountRecordServiceImpl extends ServiceImpl<UserAccountRecordD
         return detail;
     }
 
-
     @Override
     public IPage<UserAccountRecordVo> appSelectPage(IPage<UserAccountRecordVo> page, UserAccountRecordSearch query) {
         return page.setRecords(baseMapper.appSelectPage(page, query));

+ 26 - 29
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserAccountServiceImpl.java

@@ -211,67 +211,64 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
     }
 
     @Override
-    public HttpResponseResult<UserAccountRecord> accountChange(Long recordId, PostStatusEnum postStatus) {
-        if (null == postStatus || null == recordId
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResponseResult<UserAccountRecord> accountChange(UserAccountRecord record, PostStatusEnum postStatus) {
+        if (null == postStatus || null == record
                 || (!PostStatusEnum.RECORDED.equals(postStatus) && !PostStatusEnum.CANCEL.equals(postStatus))) {
-            throw new BizException("入账状态变更, 参数异常: recordId is {} postStatus is {}", recordId, postStatus.getCode());
-        }
-        UserAccountRecordVo detail = userAccountRecordService.detail(recordId);
-        if (null == detail) {
-            throw new BizException("入账状态变更, 未找到记录信息: recordId is {} postStatus is {}", recordId, postStatus.getCode());
+            throw new BizException("入账状态变更, 参数异常: record is {} postStatus is {}", JSONObject.toJSONString(record), postStatus.getCode());
         }
-        if (!PostStatusEnum.WAIT.equals(detail.getPostStatus())
-                && !PostStatusEnum.FROZEN.equals(detail.getPostStatus())) {
+        if (!PostStatusEnum.WAIT.equals(record.getPostStatus())
+                && !PostStatusEnum.FROZEN.equals(record.getPostStatus())) {
             return HttpResponseResult.succeed();
         }
-        detail.setPostStatus(postStatus);
+        record.setPostStatus(postStatus);
         HttpResponseResult<UserAccountRecord> res = DistributedLock.of(redissonClient)
-                .runIfLockToFunction(CacheNameEnum.LOCK_CHANGE_ACCOUNT.getRedisKey(recordId)
-                        , this::doAccountChange, detail, 10L);
+                .runIfLockToFunction(CacheNameEnum.LOCK_CHANGE_ACCOUNT.getRedisKey(record.getAccountId())
+                        , this::doAccountChange, record, 10L);
         if (null != res) {
             return res;
         } else {
-            throw new BizException("记录变更-账户记录变更失败: param is {}", JSONObject.toJSONString(detail));
+            throw new BizException("记录变更-账户记录变更失败: param is {}", JSONObject.toJSONString(record));
         }
     }
 
     @Transactional(rollbackFor = Exception.class)
     public HttpResponseResult<UserAccountRecord> doAccountChange(UserAccountRecord param) {
         //这里需要双重判断,这一次是锁内判断
-        UserAccountRecordVo detail = userAccountRecordService.detail(param.getId());
-        if (!PostStatusEnum.WAIT.equals(detail.getPostStatus())
-                && !PostStatusEnum.FROZEN.equals(detail.getPostStatus())) {
+        UserAccountRecord old = userAccountRecordService.getById(param.getId());
+        if (!PostStatusEnum.WAIT.equals(old.getPostStatus())
+                && !PostStatusEnum.FROZEN.equals(old.getPostStatus())) {
             return HttpResponseResult.succeed();
         }
-        detail.setPostStatus(detail.getPostStatus());
         //待入账
-        if (PostStatusEnum.WAIT.equals(detail.getPostStatus())) {
-            if (PostStatusEnum.RECORDED.equals(detail.getPostStatus())) {
+        if (PostStatusEnum.WAIT.equals(old.getPostStatus())) {
+            if (PostStatusEnum.RECORDED.equals(param.getPostStatus())) {
                 //正常入账
-                baseMapper.changeAccount(detail.getAccountId(), detail.getTransAmount(), detail.getInOrOut().getCode());
+                baseMapper.changeAccount(old.getAccountId(), old.getTransAmount(), old.getInOrOut().getCode());
             } else if (PostStatusEnum.CANCEL.equals(param.getPostStatus())) {
                 //取消入账
             }
-        } else if (PostStatusEnum.FROZEN.equals(detail.getPostStatus())) {
+        } else if (PostStatusEnum.FROZEN.equals(old.getPostStatus())) {
             if (PostStatusEnum.RECORDED.equals(param.getPostStatus())) {
                 //冻结后正常入账
-                baseMapper.frozenDeductChangeAccount(detail.getAccountId(), detail.getTransAmount(), detail.getInOrOut().getCode());
+                baseMapper.frozenDeductChangeAccount(old.getAccountId(), old.getTransAmount(), old.getInOrOut().getCode());
             } else if (PostStatusEnum.CANCEL.equals(param.getPostStatus())) {
                 //冻结后取消入账
-                baseMapper.frozenBackChangeAccount(detail.getAccountId(), detail.getTransAmount(), detail.getInOrOut().getCode());
+                baseMapper.frozenBackChangeAccount(old.getAccountId(), old.getTransAmount(), old.getInOrOut().getCode());
             }
         }
 
-        UserAccountVo accountVo = detail(detail.getAccountId());
+        UserAccountVo accountVo = detail(old.getAccountId());
         if (accountVo.getAmountTotal().doubleValue() < 0
                 || accountVo.getAmountUsable().doubleValue() < 0 || accountVo.getAmountFrozen().doubleValue() < 0) {
             throw new BizException("账户变更失败");
         }
         //插入账户变更记录
-        detail.setAccountBalance(accountVo.getAmountUsable());
-        detail.setUpdateTime(new Date());
-        userAccountRecordService.updateById(detail);
-        return HttpResponseResult.succeed(detail);
+        old.setPostStatus(param.getPostStatus());
+        old.setAccountBalance(accountVo.getAmountUsable());
+        old.setUpdateTime(new Date());
+        userAccountRecordService.updateById(old);
+        return HttpResponseResult.succeed(old);
     }
 
     @Override
@@ -432,7 +429,7 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco
             return;
         }
         for (UserAccountRecord userAccount : list) {
-            this.accountChange(userAccount.getId(),shareDto.getStatus());
+            this.accountChange(userAccount,shareDto.getStatus());
         }
     }
 

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserOrderRefundServiceImpl.java

@@ -534,7 +534,7 @@ public class UserOrderRefundServiceImpl extends ServiceImpl<UserOrderRefundDao,
         for (UserAccountRecord userAccountRecord : dataList) {
             if (PostStatusEnum.WAIT.equals(userAccountRecord.getPostStatus())
                     || PostStatusEnum.FROZEN.equals(userAccountRecord.getPostStatus())) {
-                userAccountService.accountChange(userAccountRecord.getId(), PostStatusEnum.CANCEL);
+                userAccountService.accountChange(userAccountRecord, PostStatusEnum.CANCEL);
             }
         }
         //处理平台入账

+ 4 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserWithdrawalServiceImpl.java

@@ -279,12 +279,12 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
                 res = HttpResponseResult.failed("结算" + authOperaReq.getId() + "失败,失败原因:" + withdraw.getMsg());
 
                 UserAccountRecordVo detail = accountRecordService.detail(null, AccountBizTypeEnum.WITHDRAWAL, Long.parseLong(authOperaReq.getId()));
-                userAccountService.accountChange(detail.getId(), PostStatusEnum.CANCEL);
+                userAccountService.accountChange(detail, PostStatusEnum.CANCEL);
             }
         } else {
             //审核不通过,账户解冻
             UserAccountRecordVo detail = accountRecordService.detail(null, AccountBizTypeEnum.WITHDRAWAL, Long.parseLong(authOperaReq.getId()));
-            userAccountService.accountChange(detail.getId(), PostStatusEnum.CANCEL);
+            userAccountService.accountChange(detail, PostStatusEnum.CANCEL);
 
             //发生审核未通过通知
             unpassSend(build.getUserId(), build.getPhone(), authOperaReq.getReason());
@@ -357,7 +357,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 
             //结算成功,账户解冻,入账户明细
             UserAccountRecordVo recordVo = accountRecordService.detail(null, AccountBizTypeEnum.WITHDRAWAL, detail.getId());
-            userAccountService.accountChange(recordVo.getId(), PostStatusEnum.RECORDED);
+            userAccountService.accountChange(recordVo, PostStatusEnum.RECORDED);
             //发生结算成功通知
             successSend(detail.getUserId(), detail.getPhone());
         } else if ("2".equals(callback.getStatus())) {
@@ -369,7 +369,7 @@ public class UserWithdrawalServiceImpl extends ServiceImpl<UserWithdrawalDao, Us
 
             //结算失败,账户解冻
             UserAccountRecordVo recordVo = accountRecordService.detail(null, AccountBizTypeEnum.WITHDRAWAL, detail.getId());
-            userAccountService.accountChange(recordVo.getId(), PostStatusEnum.CANCEL);
+            userAccountService.accountChange(recordVo, PostStatusEnum.CANCEL);
 
             //发生结算失败通知
             unpassSend(detail.getUserId(), detail.getPhone(), callback.getErrorMsg());