Browse Source

fix : 玩家渠道列表记录数据修正

bilingfeng 5 tháng trước cách đây
mục cha
commit
0469dbb979

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (梦回发送玩家弹窗消息, 新增二维码和获客链接字段・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (玩家渠道列表记录数据修正・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 10 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/AgentController.java

@@ -8,6 +8,7 @@ import com.zanxiang.game.module.manage.pojo.params.AgentAddParam;
 import com.zanxiang.game.module.manage.pojo.params.AgentListParam;
 import com.zanxiang.game.module.manage.pojo.vo.AgentVO;
 import com.zanxiang.game.module.manage.service.IAgentService;
+import com.zanxiang.game.module.manage.service.IUserAgentLogService;
 import com.zanxiang.game.module.mybatis.entity.Agent;
 import com.zanxiang.module.util.exception.BaseException;
 import com.zanxiang.module.util.pojo.ResultVO;
@@ -27,6 +28,9 @@ public class AgentController {
     @Autowired
     private IAgentService agentService;
 
+    @Autowired
+    private IUserAgentLogService userAgentLogService;
+
     @PreAuthorize(permissionKey = "manage:agent:list")
     @PostMapping("/list")
     public ResultVO<IPage<AgentVO>> listOfPage(@Validated @RequestBody AgentListParam dto) {
@@ -89,4 +93,10 @@ public class AgentController {
     public ResultVO<Boolean> configBackPolicy(@PathVariable("agentIds") List<Long> agentIds, @PathVariable(value = "backPolicyId", required = false) Long backPolicyId) {
         return ResultVO.ok(agentService.configBackPolicy(agentIds, backPolicyId));
     }
+
+    @PutMapping("/user/agent/log/update")
+    public ResultVO<Void> userAgentLogUpdate(@RequestParam Boolean isRunUpdate) {
+        userAgentLogService.userAgentLogUpdate(isRunUpdate);
+        return ResultVO.ok();
+    }
 }

+ 7 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IUserAgentLogService.java

@@ -11,6 +11,13 @@ import com.zanxiang.game.module.mybatis.entity.UserAgentLog;
  */
 public interface IUserAgentLogService extends IService<UserAgentLog> {
 
+    /**
+     * 数据修正
+     *
+     * @param isRunUpdate : 是否执行修正
+     */
+    void userAgentLogUpdate(boolean isRunUpdate);
+
     /**
      * 注册代理日志
      *

+ 50 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/UserAgentLogServiceImpl.java

@@ -1,5 +1,6 @@
 package com.zanxiang.game.module.manage.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zanxiang.game.module.manage.service.IUserAgentLogService;
 import com.zanxiang.game.module.mybatis.entity.Agent;
@@ -7,9 +8,13 @@ import com.zanxiang.game.module.mybatis.entity.User;
 import com.zanxiang.game.module.mybatis.entity.UserAgentLog;
 import com.zanxiang.game.module.mybatis.mapper.UserAgentLogMapper;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Objects;
+
 /**
  * @author : lingfeng
  * @time : 2023-07-20
@@ -19,6 +24,51 @@ import org.springframework.stereotype.Service;
 @Service
 public class UserAgentLogServiceImpl extends ServiceImpl<UserAgentLogMapper, UserAgentLog> implements IUserAgentLogService {
 
+    @Override
+    public void userAgentLogUpdate(boolean isRunUpdate) {
+        List<UserAgentLog> errorList = super.list(new LambdaQueryWrapper<UserAgentLog>()
+                .isNotNull(UserAgentLog::getOldAgentId)
+                .isNotNull(UserAgentLog::getNewAgentId)
+                .apply("old_agent_id=new_agent_id"));
+        if (CollectionUtils.isEmpty(errorList)) {
+            log.error("查询到可修正的数据列表为空!!!");
+            return;
+        }
+        log.error("查询到数据 count : {}", errorList.size());
+        if (!isRunUpdate) {
+            return;
+        }
+        int count = 0;
+        for (UserAgentLog userAgentLog : errorList) {
+            this.agentLogUpdate(userAgentLog);
+            count++;
+            log.error("第 count : {} 条数据, id : {} 修正", count, userAgentLog.getId());
+        }
+        log.error("=========== 全部修正完成 ===========");
+    }
+
+    private void agentLogUpdate(UserAgentLog userAgentLog) {
+        //不是错误数据
+        if (!Objects.equals(userAgentLog.getOldAgentId(), userAgentLog.getNewAgentId())) {
+            return;
+        }
+        //根据 userId 和 createTime 查询上一条数据
+        UserAgentLog beforeLog = super.getOne(new LambdaQueryWrapper<UserAgentLog>()
+                .eq(UserAgentLog::getUserId, userAgentLog.getUserId())
+                .lt(UserAgentLog::getCreateTime, userAgentLog.getCreateTime())
+                .orderByDesc(UserAgentLog::getCreateTime)
+                .last("limit 1"));
+        //未查询到上一条记录, 不做修正
+        if (beforeLog == null) {
+            log.error("查询上一条记录结果为空-------!!!!!!, logId : {}", userAgentLog.getId());
+            return;
+        }
+        //数据修正
+        userAgentLog.setOldAgentId(beforeLog.getNewAgentId());
+        userAgentLog.setOldChannel(beforeLog.getNewChannel());
+        super.updateById(userAgentLog);
+    }
+
     @Override
     public boolean regAgentLog(User user) {
         if (Agent.DEFAULT_AGENT.equals(user.getAgentId()) || Strings.isBlank(user.getChannel())) {