linxk vor 3 Wochen
Ursprung
Commit
abf952451a

+ 7 - 0
cif-service/src/main/java/com/txz/cif/dao/AccountMapper.java

@@ -9,8 +9,15 @@ import java.math.BigDecimal;
 public interface AccountMapper extends Mapper<Account> {
     int dealWithDayCut(@Param("accountId")Long accountId, @Param("amount")BigDecimal amount);
 
+    int dealWithDayCutHasTotal(@Param("accountId")Long accountId, @Param("amount")BigDecimal amount);
+
+
     int deal(@Param("accountId")Long accountId, @Param("amount")BigDecimal amount);
 
+    int dealHasTotal(@Param("accountId")Long accountId, @Param("amount")BigDecimal amount);
+
+
+
     void dealFreeze(@Param("accountId")Long accountId, @Param("amount") BigDecimal amount);
 
     BigDecimal sumTodayInit(@Param("aliases")String aliases);

+ 24 - 6
cif-service/src/main/java/com/txz/cif/service/impl/AccountServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.lang.generator.SnowflakeGenerator;
 import cn.hutool.core.util.StrUtil;
 import com.txz.cif.constants.MyConstants;
 import com.txz.cif.dao.AccountMapper;
+import com.txz.cif.enums.BizTypeEnum;
 import com.txz.cif.model.Account;
 import com.txz.cif.model.AccountFlow;
 import com.txz.cif.model.Flow;
@@ -54,15 +55,32 @@ public class AccountServiceImpl extends AbstractService<Account> implements Acco
             //解冻
             cAccountMapper.dealFreeze(accountFlow.getAccountId(),accountFlow.getAmount().negate());
         } else {
+
             if (accountFlow.getType() == 1){
-                int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(),accountFlow.getAmount().negate());
-                if (i == 0){
-                    cAccountMapper.deal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
+                if (BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.WITHDRAW
+                  || BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.RECHARGE){
+                    int i = cAccountMapper.dealWithDayCutHasTotal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
+                    if (i == 0){
+                        cAccountMapper.dealHasTotal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
+                    }
+                } else {
+                    int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(),accountFlow.getAmount().negate());
+                    if (i == 0){
+                        cAccountMapper.deal(accountFlow.getAccountId(),accountFlow.getAmount().negate());
+                    }
                 }
             } else {
-                int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(),accountFlow.getAmount());
-                if (i == 0){
-                    cAccountMapper.deal(accountFlow.getAccountId(),accountFlow.getAmount());
+                if (BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.WITHDRAW
+                        || BizTypeEnum.getByKey(accountFlow.getBizType()) == BizTypeEnum.RECHARGE){
+                    int i = cAccountMapper.dealWithDayCutHasTotal(accountFlow.getAccountId(),accountFlow.getAmount());
+                    if (i == 0){
+                        cAccountMapper.dealHasTotal(accountFlow.getAccountId(),accountFlow.getAmount());
+                    }
+                } else {
+                    int i = cAccountMapper.dealWithDayCut(accountFlow.getAccountId(),accountFlow.getAmount());
+                    if (i == 0){
+                        cAccountMapper.deal(accountFlow.getAccountId(),accountFlow.getAmount());
+                    }
                 }
             }
         }

+ 37 - 8
cif-service/src/main/resources/mapper/AccountMapper.xml

@@ -52,14 +52,6 @@
           ,before_day_time = CURRENT_DATE
           ,before_day_init_balance = before_day_balance
           ,before_day_balance = balance
-      ,total_in_amount = total_in_amount + CASE
-      WHEN #{amount} > 0 THEN #{amount}
-      ELSE 0
-      END,
-      total_out_amount = total_out_amount + CASE
-      WHEN 0 > #{amount}  THEN -#{amount}
-      ELSE 0
-      END
         where id =  #{accountId}
           <if test="accountId != 5">
             and balance + #{amount} >= 0
@@ -67,7 +59,44 @@
           and DATE_FORMAT( before_day_time, '%Y-%m-%d' ) != CURRENT_DATE
     </update>
 
+  <update id="dealWithDayCutHasTotal"  >
+    update c_account
+    set balance = balance + #{amount}
+    ,before_day_time = CURRENT_DATE
+    ,before_day_init_balance = before_day_balance
+    ,before_day_balance = balance
+    ,total_in_amount = total_in_amount + CASE
+    WHEN #{amount} > 0   THEN #{amount}
+    ELSE 0
+    END,
+    total_out_amount = total_out_amount + CASE
+    WHEN 0 > #{amount}  THEN -#{amount}
+    ELSE 0
+    END
+    where id =  #{accountId}
+    <if test="accountId != 5">
+      and balance + #{amount} >= 0
+    </if>
+    and DATE_FORMAT( before_day_time, '%Y-%m-%d' ) != CURRENT_DATE
+  </update>
+
   <update id="deal">
+    UPDATE c_account
+    SET balance = balance + #{amount}
+    WHERE id = #{accountId}
+    <choose>
+      <when test="accountId != 5">
+        AND balance + #{amount} >= 0
+      </when>
+      <otherwise>
+        <!-- 账户ID为5时的特殊处理 -->
+        AND 1=1
+      </otherwise>
+    </choose>
+  </update>
+
+
+  <update id="dealHasTotal">
     UPDATE c_account
     SET balance = balance + #{amount},
     total_in_amount = total_in_amount + CASE