|
@@ -0,0 +1,155 @@
|
|
|
+package com.zanxiang.game.module.manage.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.github.sd4324530.jtuple.Tuple3;
|
|
|
+import com.zanxiang.erp.base.ErpServer;
|
|
|
+import com.zanxiang.erp.base.pojo.vo.SysIpv4RpcVO;
|
|
|
+import com.zanxiang.erp.base.rpc.ISysIpv4Rpc;
|
|
|
+import com.zanxiang.game.module.manage.service.IGameService;
|
|
|
+import com.zanxiang.game.module.manage.service.IIpDataAssayService;
|
|
|
+import com.zanxiang.game.module.manage.service.IUserLoginLogService;
|
|
|
+import com.zanxiang.game.module.manage.service.IUserService;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.Game;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.User;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.UserLoginLog;
|
|
|
+import com.zanxiang.module.util.JsonUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author : lingfeng
|
|
|
+ * @time : 2025-01-15
|
|
|
+ * @description : ip数据解析
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class IpDataAssayServiceImpl implements IIpDataAssayService {
|
|
|
+
|
|
|
+ @DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
|
|
|
+ private ISysIpv4Rpc sysIpv4Rpc;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameService gameService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserLoginLogService userLoginLogService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void userHandle(long supperGameId) {
|
|
|
+ long page = 1L;
|
|
|
+ long pageSize = 5000L;
|
|
|
+ long totalPage;
|
|
|
+ List<Long> gameIdList = gameService.list(new LambdaQueryWrapper<Game>()
|
|
|
+ .select(Game::getId)
|
|
|
+ .eq(Game::getSuperGameId, supperGameId)
|
|
|
+ ).stream().map(Game::getId).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(gameIdList)) {
|
|
|
+ log.error("查询游戏列表列表为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ do {
|
|
|
+ Page<User> pageUser = userService.page(new Page<>(page, pageSize), new LambdaQueryWrapper<User>()
|
|
|
+ .select(User::getId, User::getIp, User::getIpData)
|
|
|
+ .in(User::getGameId, gameIdList)
|
|
|
+ .orderByDesc(User::getCreateTime));
|
|
|
+ totalPage = pageUser.getPages();
|
|
|
+ List<User> userList = pageUser.getRecords();
|
|
|
+ log.error("当前执行页, page : {}, total : {}, size : {}", page, totalPage, userList.size());
|
|
|
+ userList.forEach(user -> {
|
|
|
+ if (Strings.isNotBlank(user.getIpData())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String ipData = this.ipAssay(user.getIp());
|
|
|
+ if (Strings.isBlank(ipData)) {
|
|
|
+ log.error("IP解析结果返回为空, ip : {}", user.getIp());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ userService.update(new LambdaUpdateWrapper<User>()
|
|
|
+ .set(User::getIpData, ipData)
|
|
|
+ .eq(User::getId, user.getId()));
|
|
|
+ });
|
|
|
+ } while (++page <= totalPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void userLoginLogHandle() {
|
|
|
+ long page = 1L;
|
|
|
+ long pageSize = 5000L;
|
|
|
+ long totalPage;
|
|
|
+ do {
|
|
|
+ Page<UserLoginLog> pageUserLoginLog = userLoginLogService.page(new Page<>(page, pageSize),
|
|
|
+ new LambdaQueryWrapper<UserLoginLog>()
|
|
|
+ .select(UserLoginLog::getId, UserLoginLog::getIp, UserLoginLog::getIpData)
|
|
|
+ .ge(UserLoginLog::getCreateTime, LocalDateTime.now().minusMonths(2))
|
|
|
+ .orderByDesc(UserLoginLog::getCreateTime));
|
|
|
+ totalPage = pageUserLoginLog.getPages();
|
|
|
+ List<UserLoginLog> userLoginLogList = pageUserLoginLog.getRecords();
|
|
|
+ userLoginLogList.forEach(userLoginLog -> {
|
|
|
+ if (Strings.isNotBlank(userLoginLog.getIpData())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String ipData = this.ipAssay(userLoginLog.getIp());
|
|
|
+ if (Strings.isBlank(ipData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ userLoginLogService.update(new LambdaUpdateWrapper<UserLoginLog>()
|
|
|
+ .set(UserLoginLog::getIpData, ipData)
|
|
|
+ .eq(UserLoginLog::getId, userLoginLog.getId()));
|
|
|
+ });
|
|
|
+ } while (++page <= totalPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void ipDataHandle(List<String> msgList) {
|
|
|
+ msgList.forEach(msg -> {
|
|
|
+ String[] array = msg.split(":");
|
|
|
+ //消息类型(注册还是登录), 数据主键, ip地址
|
|
|
+ Tuple3<String, String, String> tuple3 = Tuple3.with(array[0], array[1], array[2]);
|
|
|
+ String ipData = this.ipAssay(tuple3.third);
|
|
|
+ if (Strings.isBlank(ipData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //注册用户, t_user表
|
|
|
+ if (Objects.equals(tuple3.first, "REG")) {
|
|
|
+ userService.update(new LambdaUpdateWrapper<User>()
|
|
|
+ .set(User::getIpData, ipData)
|
|
|
+ .eq(User::getId, Long.parseLong(tuple3.second))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //登录日志, t_user_login_log表
|
|
|
+ if (Objects.equals(tuple3.first, "LOGIN")) {
|
|
|
+ userLoginLogService.update(new LambdaUpdateWrapper<UserLoginLog>()
|
|
|
+ .set(UserLoginLog::getIpData, ipData)
|
|
|
+ .eq(UserLoginLog::getId, Long.parseLong(tuple3.second))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private String ipAssay(String ip) {
|
|
|
+ if (Strings.isBlank(ip)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ SysIpv4RpcVO data = null;
|
|
|
+ try {
|
|
|
+ data = sysIpv4Rpc.getIpDetail(ip).getData();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用erp解析IP异常, ip : {}, e : {}", ip, e.getMessage());
|
|
|
+ }
|
|
|
+ return JsonUtil.toString(data);
|
|
|
+ }
|
|
|
+}
|