Selaa lähdekoodia

fix : 数据库慢sql优化, 代码修改

bilingfeng 5 kuukautta sitten
vanhempi
commit
80c3ccc90e

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <解决玩家被重复买量, AgentLog数据错误的问题> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <数据库慢sql优化, 代码修改> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 4 - 8
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IPerformOrderService.java

@@ -22,31 +22,27 @@ public interface IPerformOrderService {
      * 检查订单是否为首单(账号首充)
      *
      * @param platformOrderDTO 平台订单dto
-     * @return {@link Boolean}
      */
-    Boolean checkIsFirstRecharge(PlatformOrderDTO platformOrderDTO);
+    void checkIsFirstRecharge(PlatformOrderDTO platformOrderDTO);
 
     /**
      * 更新游戏玩家充值统计
      *
      * @param platformOrderDTO 平台订单dto
-     * @return {@link Boolean}
      */
-    Boolean userRechargeTotal(PlatformOrderDTO platformOrderDTO);
+    void userRechargeTotal(PlatformOrderDTO platformOrderDTO);
 
     /**
      * 更新商户号统计
      *
      * @param platformOrderDTO 平台订单dto
-     * @return {@link Boolean}
      */
-    Boolean payMerchantTotal(PlatformOrderDTO platformOrderDTO);
+    void payMerchantTotal(PlatformOrderDTO platformOrderDTO);
 
     /**
      * 米大师收款统计
      *
      * @param platformOrderDTO 平台订单dto
-     * @return {@link Boolean}
      */
-    Boolean miPayTotal(PlatformOrderDTO platformOrderDTO);
+    void miPayTotal(PlatformOrderDTO platformOrderDTO);
 }

+ 20 - 50
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/PerformOrderServiceImpl.java

@@ -2,7 +2,6 @@ package com.zanxiang.game.module.sdk.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.zanxiang.game.module.base.pojo.enums.CpStatusEnum;
 import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
 import com.zanxiang.game.module.base.util.DateUtils;
@@ -176,85 +175,63 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
 
     @Override
     @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
-    public Boolean checkIsFirstRecharge(PlatformOrderDTO platformOrderDTO) {
-        log.info("订单:{} 检查更新用户是否为首充 ----------start---------", platformOrderDTO.getOrderId());
+    public void checkIsFirstRecharge(PlatformOrderDTO platformOrderDTO) {
         try {
-            int count = orderService.count(new LambdaQueryWrapper<Order>()
+            if (orderService.count(new LambdaQueryWrapper<Order>()
                     .eq(Order::getUserId, platformOrderDTO.getUserId())
                     .eq(Order::getStatus, OrderStateEnum.SUCCESS_PAY.getCode())
-                    .ne(Order::getOrderId, platformOrderDTO.getOrderId()));
-            if (count <= 0) {
+                    .ne(Order::getOrderId, platformOrderDTO.getOrderId())
+            ) <= 0) {
                 orderService.update(new LambdaUpdateWrapper<Order>()
                         .set(Order::getIsFirstRecharge, 1)
                         .eq(Order::getOrderId, platformOrderDTO.getOrderId()));
-                log.info("订单:{} 验证订单是否为首充成功", platformOrderDTO.getOrderId());
-                return Boolean.TRUE;
             }
-            log.info("订单:{} 检查更新用户是否为首充 ----------end---------", platformOrderDTO.getOrderId());
         } catch (Exception e) {
-            log.error("订单:{} 验证订单是否为首充失败 e:{}", platformOrderDTO.getOrderId(), e);
+            log.error("验证订单是否为首充异常, orderId : {}, e : {}", platformOrderDTO.getOrderId(), e.getMessage());
         }
-        return Boolean.FALSE;
     }
 
     @Override
     @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
-    public Boolean userRechargeTotal(PlatformOrderDTO platformOrderDTO) {
-        log.info("订单:{} 更新用户充值统计 ----------start---------", platformOrderDTO.getOrderId());
+    public void userRechargeTotal(PlatformOrderDTO platformOrderDTO) {
         try {
             //订单取消情况 做减法
             float amount = platformOrderDTO.getAmount().floatValue();
             int num = 1;
             //游戏用户角色统计更新
             if (Strings.isNotBlank(platformOrderDTO.getRoleId()) && !"0".equals(platformOrderDTO.getRoleId())) {
-                GameUserRole gameUserRole = new GameUserRole();
-                gameUserRole.setRoleId(platformOrderDTO.getRoleId());
-                gameUserRoleService.update(gameUserRole, new UpdateWrapper<GameUserRole>().lambda()
+                gameUserRoleService.update(new LambdaUpdateWrapper<GameUserRole>()
                         .set(GameUserRole::getLastRechargeTime, platformOrderDTO.getPayTime())
                         .setSql("recharge_count=recharge_count+" + num)
                         .setSql("recharge_money=recharge_money+" + amount)
-                        .setEntity(gameUserRole));
-            } else {
-                log.info("订单:{} 用户玩家角色RoleId为空,不进行gameUserRole充值统计汇总", platformOrderDTO.getOrderId());
+                        .eq(GameUserRole::getGameId, platformOrderDTO.getGameId())
+                        .eq(GameUserRole::getRoleId, platformOrderDTO.getRoleId())
+                        .eq(GameUserRole::getUserId, platformOrderDTO.getUserId()));
             }
             //游戏用户统计更新
             if (platformOrderDTO.getMgUserId() != null) {
-                GameUser gameUser = new GameUser();
-                gameUser.setId(platformOrderDTO.getMgUserId());
-                gameUserService.update(gameUser, new UpdateWrapper<GameUser>().lambda()
+                gameUserService.update(new LambdaUpdateWrapper<GameUser>()
                         .set(GameUser::getLastRechargeTime, platformOrderDTO.getPayTime())
                         .setSql("recharge_count=recharge_count+" + num)
                         .setSql("recharge_money=recharge_money+" + amount)
-                        .setEntity(gameUser)
-                );
-            } else {
-                log.info("订单:{} 用户玩家MgUserId为空,不进行gameUser充值统计汇总", platformOrderDTO.getOrderId());
+                        .eq(GameUser::getId, platformOrderDTO.getMgUserId()));
             }
             //用户统计更新
             if (platformOrderDTO.getUserId() != null) {
-                User user = new User();
-                user.setId(platformOrderDTO.getUserId());
-                userService.update(user, new UpdateWrapper<User>().lambda()
+                userService.update(new LambdaUpdateWrapper<User>()
                         .set(User::getLastRechargeTime, platformOrderDTO.getPayTime())
                         .setSql("recharge_count=recharge_count+" + num)
                         .setSql("recharge_money=recharge_money+" + amount)
-                        .setEntity(user)
-                );
-            } else {
-                log.info("订单:{} 用户UserId为空,不进行User充值统计汇总", platformOrderDTO.getOrderId());
+                        .eq(User::getId, platformOrderDTO.getUserId()));
             }
-            log.info("订单:{} 更新用户充值统计 ----------end---------", platformOrderDTO.getOrderId());
-            return Boolean.TRUE;
         } catch (Exception e) {
-            log.error("订单:{} 用户充值统计逻辑操作失败 e:{}", platformOrderDTO.getOrderId(), e);
+            log.error("用户充值统计逻辑操作异常, orderId : {}, e : {}", platformOrderDTO.getOrderId(), e.getMessage(), e);
         }
-        return Boolean.FALSE;
     }
 
     @Override
     @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
-    public Boolean payMerchantTotal(PlatformOrderDTO platformOrderDTO) {
-        log.info("订单:{} 更新商户号统计 ----------start---------", platformOrderDTO.getOrderId());
+    public void payMerchantTotal(PlatformOrderDTO platformOrderDTO) {
         try {
             //根据订单中的商户id获取商户信息
             PayMerchantDTO payMerchantInfo = payMerchantService.getByMerchantNo(platformOrderDTO.getMerchantNo());
@@ -291,25 +268,21 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
                     .setSql(dayPayAmount)
                     .eq(PayMerchant::getMerchantNo, platformOrderDTO.getMerchantNo())
             );
-            log.info("订单:{} 更新商户号统计 ----------end---------", platformOrderDTO.getOrderId());
-            return Boolean.TRUE;
         } catch (Exception e) {
-            log.error("订单:{} 更新商户号统计异常 e:{}", platformOrderDTO.getOrderId(), e);
+            log.error("更新商户号统计异常, orderId : {}, e : {}", platformOrderDTO.getOrderId(), e.getMessage());
         }
-        return Boolean.FALSE;
     }
 
     @Override
     @Transactional(rollbackFor = {RuntimeException.class, Exception.class})
-    public Boolean miPayTotal(PlatformOrderDTO platformOrderDTO) {
-        log.info("订单:{} 更新米大师统计 ----------start---------", platformOrderDTO.getOrderId());
+    public void miPayTotal(PlatformOrderDTO platformOrderDTO) {
         try {
             //获取米大师统计信息
             GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(platformOrderDTO.getGameId());
             GameAppletDTO.MiPayConfigBean miPayConfigBean = gameAppletDTO.getMiPayConfigBean();
             if (miPayConfigBean == null) {
                 log.error("米大师支付统计失败, 米大师配置信息不存在");
-                return Boolean.FALSE;
+                return;
             }
             MiPaySum miPaySum = miPaySumService.getOne(new LambdaQueryWrapper<MiPaySum>()
                     .eq(MiPaySum::getGameId, gameAppletDTO.getGameId())
@@ -349,11 +322,8 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
                     .eq(MiPaySum::getGameId, gameAppletDTO.getGameId())
                     .eq(MiPaySum::getAppId, gameAppletDTO.getAppId())
                     .eq(MiPaySum::getMiPayAppId, miPayConfigBean.getAppId()));
-            log.info("订单:{} 更新米大师统计 ----------end---------", platformOrderDTO.getOrderId());
-            return Boolean.TRUE;
         } catch (Exception e) {
-            log.error("订单:{} 更新米大师统计异常 e:{}", platformOrderDTO.getOrderId(), e);
+            log.error("更新米大师统计异常, orderId : {}, e : {}", platformOrderDTO.getOrderId(), e.getMessage());
         }
-        return Boolean.FALSE;
     }
 }