|
@@ -0,0 +1,553 @@
|
|
|
+package org.bfkj.services;
|
|
|
+
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import jakarta.annotation.Nullable;
|
|
|
+import org.bfkj.domain.*;
|
|
|
+import org.bfkj.services.cache.CodeCacheService;
|
|
|
+import org.bfkj.utils.CommonUtil;
|
|
|
+import org.bfkj.utils.RandomGraphic;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class SecurityService {
|
|
|
+
|
|
|
+
|
|
|
+ private DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ private final static Map<String, List<String>> alias = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ alias.put("appid", List.of("appid", "app_id", "appId", "APPID"));
|
|
|
+ alias.put("appsecret", List.of("appSecret", "app_secret", "APP_SECRET", "appsecret", "APPSECRET"));
|
|
|
+ alias.put("sessionid", List.of("sessionId", "sessionid"));
|
|
|
+ alias.put("requestip", List.of("requestIp", "requestip"));
|
|
|
+ alias.put("username", List.of("username"));
|
|
|
+ alias.put("password", List.of("password"));
|
|
|
+ alias.put("version", List.of("version"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private final ApplicationService applicationService;
|
|
|
+ private final ApplicationconnectlogService applicationconnectlogService;
|
|
|
+ private final UserloginlogService userloginlogService;
|
|
|
+ private final PermissionsService permissionsService;
|
|
|
+ private final UserinfoService userinfoService;
|
|
|
+ private final CodeCacheService codeCacheService;
|
|
|
+
|
|
|
+ public SecurityService(ApplicationService applicationService, ApplicationconnectlogService applicationconnectlogService, UserloginlogService userloginlogService, PermissionsService permissionsService, UserinfoService userinfoService, CodeCacheService codeCacheService) {
|
|
|
+ this.applicationService = applicationService;
|
|
|
+ this.applicationconnectlogService = applicationconnectlogService;
|
|
|
+ this.userloginlogService = userloginlogService;
|
|
|
+ this.permissionsService = permissionsService;
|
|
|
+ this.userinfoService = userinfoService;
|
|
|
+ this.codeCacheService = codeCacheService;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> getToken(Map<String, Object> requestData) throws JsonProcessingException {
|
|
|
+ Optional<String> appid = getValue("appid", requestData);
|
|
|
+ Optional<String> appSecret = getValue("appsecret", requestData);
|
|
|
+ Optional<String> requestIp = getValue("requestip", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (appid.isPresent() && appSecret.isPresent()) {
|
|
|
+
|
|
|
+ applicationconnectlogService.removeExpiresData();
|
|
|
+ result.putAll(getAppToken(appid.get(), appSecret.get(), requestIp.get(), sessionId.get()));
|
|
|
+ } else {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "appid 或者 appSecret 错误");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> getAppToken(String appid, String appSecret, String requestIp, String sessionId) throws JsonProcessingException {
|
|
|
+ Application application = applicationService.findByAppId(appid);
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (appSecret.equals(application.getAppsecret())) {
|
|
|
+
|
|
|
+ String md5Token = CommonUtil.toMD5("%s:%s".formatted(LocalDateTime.now(), sessionId));
|
|
|
+
|
|
|
+ Long apptokeneffective = application.getApptokeneffective();
|
|
|
+
|
|
|
+ LocalDateTime expiresTime = LocalDateTime.now().plusSeconds(apptokeneffective);
|
|
|
+
|
|
|
+ Appconnectlog applicationconnectlog = new Appconnectlog();
|
|
|
+
|
|
|
+ applicationconnectlog.setAppid(appid);
|
|
|
+ applicationconnectlog.setExpiretime(expiresTime);
|
|
|
+ applicationconnectlog.setApptoken(md5Token);
|
|
|
+ applicationconnectlog.setRequestip(requestIp);
|
|
|
+ applicationconnectlog.setRequesttime(LocalDateTime.now());
|
|
|
+ applicationconnectlog.setLasttime(LocalDateTime.now());
|
|
|
+ applicationconnectlogService.save(applicationconnectlog);
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("token", md5Token);
|
|
|
+ data.put("expirestime", expiresTime.format(dateTimeFormatter));
|
|
|
+ data.put("appname", application.getAppname());
|
|
|
+ data.put("appenname", application.getAppengname());
|
|
|
+ data.put("logo", application.getApplogo());
|
|
|
+ data.put("background", application.getBackgroundimage());
|
|
|
+ result.put("returnData", data);
|
|
|
+ result.put("code", "0");
|
|
|
+ result.put("message", null);
|
|
|
+ } else {
|
|
|
+ result.put("message", "用户或密码错误");
|
|
|
+ result.put("code", "-1");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> getUserToken(@Nullable String appToken, @Nullable String userName, @Nullable String password, @Nullable String code, @Nullable String requestIp, String sessionId, Boolean checkCode) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Appconnectlog applicationconnectlog = applicationconnectlogService.findByTokenAndRequestIp(appToken, requestIp);
|
|
|
+ if (Objects.isNull(applicationconnectlog)) {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "apptoken 错误");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Application application = applicationService.findByAppId(applicationconnectlog.getAppid());
|
|
|
+
|
|
|
+ if (checkCode && Objects.nonNull(application.getSecuritycoderule()) && !codeCacheService.check(code, sessionId)) {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "验证码错误");
|
|
|
+ } else {
|
|
|
+ Integer multilogin = application.getMultilogin();
|
|
|
+ Userinfo user = userinfoService.findByUsername(userName);
|
|
|
+ List<Userloginlog> userloginlogs = userloginlogService.findByUserId(user.getUserid());
|
|
|
+ if (!userloginlogs.isEmpty()) {
|
|
|
+ result.put("code", "0");
|
|
|
+ if (multilogin == 1) {
|
|
|
+ userloginlogService.expiresByUserid(user.getUserid());
|
|
|
+ }
|
|
|
+ userloginlogService.insertUserLoginLog(requestIp, sessionId, user.getUserid(), null, appToken, application.getAppid());
|
|
|
+ result.put("returnData", new HashMap<>() {{
|
|
|
+ put("userstatus", 1);
|
|
|
+ }});
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ result.put("code", "0");
|
|
|
+ result.put("returnData", new HashMap<>() {{
|
|
|
+ put("userstatus", 0);
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ userloginlogService.insertUserLoginLog(requestIp, sessionId, user.getUserid(), null, appToken, application.getAppid());
|
|
|
+
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> verifyToken(Map<String, Object> requestData) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Optional<String> token = getValue("token", requestData);
|
|
|
+
|
|
|
+ Optional<String> requestIp = getValue("requestip", requestData);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (token.isEmpty()) {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "token错误");
|
|
|
+ } else {
|
|
|
+ Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
|
|
|
+ if (LocalDateTime.now().isAfter(applicationLog.getExpiretime())) {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "token已过期");
|
|
|
+ } else {
|
|
|
+ result.put("code", "0");
|
|
|
+ result.put("message", "token校验通过");
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("validstatus", true);
|
|
|
+ result.put("returnData", data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> refreshToken(Map<String, Object> requestData) throws JsonProcessingException {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> resultData = new HashMap<>();
|
|
|
+ Map<String, Object> map = verifyToken(requestData);
|
|
|
+ Optional<String> version = getValue("version", requestData);
|
|
|
+
|
|
|
+ if (map.get("code").equals("0")) {
|
|
|
+ Optional<String> requestIp = getValue("requestIp", requestData);
|
|
|
+ Optional<String> token = getValue("token", requestData);
|
|
|
+
|
|
|
+ Appconnectlog applicationconnectlog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
|
|
|
+ Application application = applicationService.findByAppId(applicationconnectlog.getAppid());
|
|
|
+ LocalDateTime expiresTime = LocalDateTime.now().plusMinutes(application.getApptokeneffective());
|
|
|
+ applicationconnectlogService.updateApplicationLogTokenExpiresTime(applicationconnectlog.getAppid(), token.get(), expiresTime);
|
|
|
+ resultData.put("code", "0");
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("expirestime", expiresTime.format(dateTimeFormatter));
|
|
|
+ if ("1".equals(version.orElse("1"))) {
|
|
|
+ resultData.put("returnData", data);
|
|
|
+ } else {
|
|
|
+ resultData.put("data", data);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resultData.putAll(map);
|
|
|
+ }
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> verifyCode(Map<String, Object> requestData) {
|
|
|
+ Map<String, Object> resultData = new HashMap<>();
|
|
|
+ Optional<String> token = getValue("token", requestData);
|
|
|
+ Optional<String> ip = getValue("requestip", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Map<String, Object> testToken = verifyToken(requestData);
|
|
|
+ if ("0".equals(testToken.get("code"))) {
|
|
|
+ Appconnectlog applicationLog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), ip.get());
|
|
|
+ String appid = applicationLog.getAppid();
|
|
|
+ Application application = applicationService.findByAppId(appid);
|
|
|
+ String securitycoderule = application.getSecuritycoderule();
|
|
|
+ Long securitycodeeffective = application.getSecuritycodeeffective();
|
|
|
+ Integer securitycoderulelength = application.getSecuritycoderulelength();
|
|
|
+ Map<String, Object> codeMap = RandomGraphic.generateVerifyCode(securitycoderulelength, securitycoderule);
|
|
|
+
|
|
|
+ String code = codeMap.get("verifyCode").toString();
|
|
|
+ String verifyCodeImage = codeMap.get("verifyCodeImage").toString();
|
|
|
+ codeCacheService.addCode(code, sessionId.get(), securitycodeeffective);
|
|
|
+ resultData.put("code", "0");
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("verifyCodeImage", verifyCodeImage);
|
|
|
+ resultData.put("returnData", data);
|
|
|
+ } else {
|
|
|
+ resultData.put("code", "-1");
|
|
|
+ resultData.put("message", "token已经过期");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> login(Map<String, Object> requestData) {
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> testToken = verifyToken(requestData);
|
|
|
+ Map<String, Object> resultData = new HashMap<>();
|
|
|
+ if (testToken.get("code").equals("0")) {
|
|
|
+
|
|
|
+ Optional<String> username = getValue("username", requestData);
|
|
|
+ Optional<String> password = getValue("password", requestData);
|
|
|
+ Optional<String> code = getValue("verifycode", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Optional<String> requestIp = getValue("requestip", requestData);
|
|
|
+ Optional<String> token = getValue("token", requestData);
|
|
|
+ resultData.putAll(getUserToken(token.get(), username.get(), password.get(), code.get(), requestIp.get(), sessionId.get(), true));
|
|
|
+ } else {
|
|
|
+ resultData.put("code", "-1");
|
|
|
+ resultData.put("message", "token已经过期");
|
|
|
+ }
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> forceLogin(Map<String, Object> requestData) {
|
|
|
+
|
|
|
+ Map<String, Object> verifyTokenResult = verifyToken(requestData);
|
|
|
+ if (!verifyTokenResult.get("code").equals("0")) {
|
|
|
+ return verifyTokenResult;
|
|
|
+ }
|
|
|
+ Optional<String> token = getValue("token", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Optional<String> requestIp = getValue("requestip", requestData);
|
|
|
+ Userloginlog userloginlog = userloginlogService.findByAppToken(token.get(), sessionId.get());
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ if (Objects.isNull(userloginlog)) {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "登录失败");
|
|
|
+ } else {
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ Appconnectlog appconnectlog = applicationconnectlogService.findByTokenAndRequestIp(token.get(), requestIp.get());
|
|
|
+ if (Objects.nonNull(appconnectlog)) {
|
|
|
+ String appid = appconnectlog.getAppid();
|
|
|
+ Application application = applicationService.findByAppId(appid);
|
|
|
+ if (Objects.nonNull(application)) {
|
|
|
+ result.put("code", "0");
|
|
|
+ data.put("userid", userloginlog.getUserid());
|
|
|
+ Long apptokeneffective = application.getApptokeneffective();
|
|
|
+ data.put("expirestime", LocalDateTime.now().plusSeconds(apptokeneffective).format(dateTimeFormatter));
|
|
|
+ String userToken = CommonUtil.toMD5("%s:%s".formatted(sessionId.get(), LocalDateTime.now()));
|
|
|
+ data.put("usertoken", userToken);
|
|
|
+ userloginlogService.removeUserLoginAppToken(sessionId.get(), userloginlog.getUserid(), userToken);
|
|
|
+ } else {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "应用配置没有找到");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.put("code", "-1");
|
|
|
+ result.put("message", "应用token没有找到");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> checkUserToken(Map<String, Object> requestData) {
|
|
|
+ Optional<String> userToken = getValue("usertoken", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
|
|
|
+
|
|
|
+ String appid = userloginlog.getAppid();
|
|
|
+ Application application = applicationService.findByAppId(appid);
|
|
|
+ if (userloginlog.getLastheartbeat().plusSeconds(application.getApptokeneffective()).isBefore(LocalDateTime.now())) {
|
|
|
+ return new HashMap<>() {{
|
|
|
+ put("code", "1");
|
|
|
+ put("message", "用户token已过期");
|
|
|
+ }};
|
|
|
+ } else {
|
|
|
+ return new HashMap<>() {{
|
|
|
+ put("code", "0");
|
|
|
+ }};
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> logOut(Map<String, Object> requestData) {
|
|
|
+ Map<String, Object> resultData = checkUserToken(requestData);
|
|
|
+ if (!"0".equals(resultData.get("code"))) {
|
|
|
+ return resultData;
|
|
|
+ } else {
|
|
|
+ resultData = new HashMap<>();
|
|
|
+
|
|
|
+ Optional<String> userToken = getValue("usertoken", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
|
|
|
+
|
|
|
+ userloginlogService.removeUserLoginLogByUserId(userloginlog.getUserid());
|
|
|
+ permissionsService.removePermissions(userloginlog.getUserid());
|
|
|
+ resultData.put("code", "0");
|
|
|
+ resultData.put("message", "成功");
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> permission(Map<String, Object> requestData) {
|
|
|
+
|
|
|
+ Map<String, Object> resultData = checkUserToken(requestData);
|
|
|
+ if (!"0".equals(resultData.get("code"))) {
|
|
|
+ return resultData;
|
|
|
+ } else {
|
|
|
+ Optional<String> userToken = getValue("usertoken", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
|
|
|
+ List<Permissions> ps = permissionsService.getPermissions(userloginlog.getUserid().toString());
|
|
|
+ resultData = new HashMap<>();
|
|
|
+ resultData.put("code", "0");
|
|
|
+ resultData.put("returnData", ps);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> changePassword(Map<String, Object> requestData) {
|
|
|
+
|
|
|
+ Map<String, Object> resultData = checkUserToken(requestData);
|
|
|
+ if (!"0".equals(resultData.get("code"))) {
|
|
|
+ return resultData;
|
|
|
+ } else {
|
|
|
+ Optional<String> usertoken = getValue("usertoken", requestData);
|
|
|
+ Optional<String> oldPassword = getValue("oldpassword", requestData);
|
|
|
+ Optional<String> password = getValue("password", requestData);
|
|
|
+
|
|
|
+ Optional<String> userToken = getValue("usertoken", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Userloginlog userloginlog = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
|
|
|
+ Integer userId = userloginlog.getUserid();
|
|
|
+ Userinfo userinfo = userinfoService.findByUserId(userId);
|
|
|
+ if (Objects.nonNull(userinfo)) {
|
|
|
+ String userpassword = userinfo.getUserpassword();
|
|
|
+ if (!userpassword.equals(oldPassword.get())) {
|
|
|
+ resultData.put("message", "密码错误");
|
|
|
+ resultData.put("code", "-1");
|
|
|
+ return resultData;
|
|
|
+ } else {
|
|
|
+ userinfoService.updateUserPassword(userId, password.get());
|
|
|
+ }
|
|
|
+ resultData = new HashMap<>();
|
|
|
+ resultData.put("code", "0");
|
|
|
+ resultData.put("message", "修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map<String, Object> userHeartbeat(Map<String, Object> requestData) {
|
|
|
+ Map<String, Object> resultData = checkUserToken(requestData);
|
|
|
+ if (!"0".equals(resultData.get("code"))) {
|
|
|
+ return resultData;
|
|
|
+ } else {
|
|
|
+ resultData = new HashMap<>();
|
|
|
+ Optional<String> userToken = getValue("usertoken", requestData);
|
|
|
+ Optional<String> sessionId = getValue("sessionid", requestData);
|
|
|
+ Userloginlog userloginlog1 = userloginlogService.findByUserToken(userToken.get(), sessionId.get());
|
|
|
+ if (Objects.nonNull(userloginlog1)) {
|
|
|
+ List<Userloginlog> userloginlogs = userloginlogService.findByUserId(userloginlog1.getUserid());
|
|
|
+
|
|
|
+ if (Objects.nonNull(userloginlogs) && !userloginlogs.isEmpty()) {
|
|
|
+ for (Userloginlog userloginlog : userloginlogs) {
|
|
|
+
|
|
|
+ userloginlogService.updateLoginLogUserLastTimeById(userloginlog.getLoginid(), sessionId.get());
|
|
|
+
|
|
|
+ resultData.put("code", "0");
|
|
|
+ resultData.put("message", "用户在线");
|
|
|
+
|
|
|
+ }
|
|
|
+ if (resultData.isEmpty()) {
|
|
|
+ resultData.put("code", "-1");
|
|
|
+ resultData.put("message", "查询失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ resultData.put("code", "-1");
|
|
|
+ resultData.put("message", "查询失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private Optional<String> getValue(String key, Map<String, Object> data) {
|
|
|
+ return alias.getOrDefault(key, Collections.singletonList(key)).stream().map(data::get).filter(Objects::nonNull).map(Object::toString).findAny();
|
|
|
+ }
|
|
|
+}
|