|
|
@@ -119,8 +119,35 @@ public class CompanyLoginService
|
|
|
}
|
|
|
}
|
|
|
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
+ //查询当前登录用户信息
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(loginUser.getUser().getUserId());
|
|
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginUser.getUser().getCompanyId(),username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
redisCache.setCacheObject("companyId:"+loginUser.getUser().getUserId(),loginUser.getUser().getCompanyId(),604800, TimeUnit.SECONDS);
|
|
|
+ String ipAddr = IpUtils.getIpAddr(ServletUtils.getRequest()).split(",")[0].trim();
|
|
|
+ log.info("销售用户{}正常登录获取到的ip地址{}", loginUser.getUser().getUserId(), ipAddr);
|
|
|
+
|
|
|
+ companyUser.setUserId(loginUser.getUser().getUserId());
|
|
|
+ String loginIp = companyUser.getLoginIp();
|
|
|
+ List<String> ipList = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(loginIp)) {
|
|
|
+ String[] ips = loginIp.split(",");
|
|
|
+ for (String ip : ips) {
|
|
|
+ ip = ip.trim(); // 去掉前后空格
|
|
|
+ if (!ip.isEmpty()) {
|
|
|
+ ipList.add(ip); // 先加入已有 IP
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ipList.add(ipAddr);
|
|
|
+ List<String> distinctList = ipList.stream()
|
|
|
+ .map(String::trim) // 再次确保去掉空格
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ companyUser.setLoginIp(String.join(",", distinctList));
|
|
|
+
|
|
|
+ companyUser.setLoginDate(new Date());
|
|
|
+ companyUserService.updateCompanyUser(companyUser);
|
|
|
// 生成token
|
|
|
return tokenService.createToken(loginUser);
|
|
|
}
|