Helius
2021-11-26 882f5815e69bc9dc2270d8c9ecc94acbeecad4a3
fix fish hit
6 files modified
40 ■■■■ changed files
src/main/java/com/xcong/excoin/rabbit/consumer/FishHitConsumer.java 24 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/websocket/fish/HitFishWebSocket.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/websocket/fish/model/MsgModel.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/websocket/handler/FishHitWebSocketHandler.java 2 ●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 2 ●●● patch | view | raw | blame | history
src/main/resources/application.yml 2 ●●● patch | view | raw | blame | history
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("未拥有该炮台");
                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) {
            if (msg.getConsume().compareTo(available) > 0) {
                log.info("余额不足");
                return;
            }
            memberAccountGoldDao.updateTotalBalanceAndAvailableBalance(accountGold.getId(), gold, gold, BigDecimal.ZERO);
        }
    }
src/main/java/com/xcong/excoin/websocket/fish/HitFishWebSocket.java
@@ -107,7 +107,7 @@
        // 消耗金币
        BigDecimal consume = (BigDecimal) fortObj;
        MsgModel msg = new MsgModel(consume, fishGold, SID_MID.get(session.getId()));
        MsgModel msg = new MsgModel(consume, fishGold, SID_MID.get(session.getId()), fortId);
        // 发送打渔消息
        fishHitProducer.sendFishHitMsg(JSONObject.toJSONString(msg));
    }
src/main/java/com/xcong/excoin/websocket/fish/model/MsgModel.java
@@ -26,9 +26,15 @@
     */
    private Long memberId;
    public MsgModel(BigDecimal consume, int obtain, Long memberId) {
    /**
     * 大炮编码
     */
    private String fortCode;
    public MsgModel(BigDecimal consume, int obtain, Long memberId, String fortCode) {
        this.consume = consume;
        this.obtain = obtain;
        this.memberId = memberId;
        this.fortCode = fortCode;
    }
}
src/main/java/com/xcong/excoin/websocket/handler/FishHitWebSocketHandler.java
@@ -99,7 +99,7 @@
        // 消耗金币
        BigDecimal consume = (BigDecimal) fortObj;
        MsgModel msg = new MsgModel(consume, fishGold, SID_MID.get(session.getId()));
        MsgModel msg = new MsgModel(consume, fishGold, SID_MID.get(session.getId()), fortId);
        // 发送打渔消息
        fishHitProducer.sendFishHitMsg(JSONObject.toJSONString(msg));
    }
src/main/resources/application-test.yml
@@ -101,7 +101,7 @@
  loop-job: false
  rabbit-consumer: false
  block-job: true
  fish-hit: false
  fish-hit: true
aliyun:
  oss:
src/main/resources/application.yml
@@ -101,7 +101,7 @@
  loop-job: false
  rabbit-consumer: false
  block-job: false
  fish-hit: true
  fish-hit: false
aliyun:
  oss: