From f5e6133809c553cfd9fb28ee61019927c547c374 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 08 Dec 2021 15:58:33 +0800
Subject: [PATCH] 20211208  fish

---
 src/main/java/com/xcong/excoin/rabbit/consumer/FishHitConsumer.java |   28 ++++++++++++++++++++++++----
 1 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/rabbit/consumer/FishHitConsumer.java b/src/main/java/com/xcong/excoin/rabbit/consumer/FishHitConsumer.java
index 2bab670..15b44eb 100644
--- a/src/main/java/com/xcong/excoin/rabbit/consumer/FishHitConsumer.java
+++ b/src/main/java/com/xcong/excoin/rabbit/consumer/FishHitConsumer.java
@@ -1,8 +1,12 @@
 package com.xcong.excoin.rabbit.consumer;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.xcong.excoin.configurations.RabbitMqConfig;
+import com.xcong.excoin.modules.fish.dao.CannonOwnRecordDao;
 import com.xcong.excoin.modules.fish.dao.MemberAccountGoldDao;
+import com.xcong.excoin.modules.fish.entity.CannonOwnRecord;
 import com.xcong.excoin.modules.fish.entity.MemberAccountGold;
 import com.xcong.excoin.websocket.fish.model.MsgModel;
 import lombok.extern.slf4j.Slf4j;
@@ -12,6 +16,7 @@
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * @author wzy
@@ -25,21 +30,36 @@
     @Autowired
     private MemberAccountGoldDao memberAccountGoldDao;
 
+    @Autowired
+    private CannonOwnRecordDao cannonOwnRecordDao;
+
     @RabbitListener(queues = RabbitMqConfig.QUEUE_FISH_HIT)
     public void fishHit(String content) {
-        log.info("收到打渔消息:{}", content);
         MsgModel msg = JSONObject.parseObject(content, MsgModel.class);
 
         synchronized (this) {
+            List<CannonOwnRecord> forts = cannonOwnRecordDao.selectCannonOwnRecordsByMemberIdAndCannonCode(msg.getMemberId(), msg.getFortCode());
+            if (CollUtil.isEmpty(forts)) {
+                log.info("未拥有该炮台:{}", content);
+                return;
+            }
+
             MemberAccountGold accountGold = memberAccountGoldDao.selectByMemberIdForLock(msg.getMemberId());
             BigDecimal available = accountGold.getAvailableBalance();
 
-            BigDecimal gold = BigDecimal.valueOf(msg.getObtain()).subtract(msg.getConsume());
+            BigDecimal gold;
+            // 由于前端打渔实现逻辑为,点击炮台发射子弹时触发一次,打中鱼再触发一次,所以,扣减和增加分开算
+            if (msg.getObtain() == 0) {
+                gold = msg.getConsume().negate();
+            } else {
+                gold = BigDecimal.valueOf(msg.getObtain());
+            }
 
-            if (gold.compareTo(BigDecimal.ZERO) < 0 && gold.abs().compareTo(available) > 0) {
-                log.info("余额不足");
+            if (msg.getConsume().compareTo(available) > 0) {
+                log.info("余额不足:{}", content);
                 return;
             }
+
             memberAccountGoldDao.updateTotalBalanceAndAvailableBalance(accountGold.getId(), gold, gold, BigDecimal.ZERO);
         }
     }

--
Gitblit v1.9.1