|
@@ -1,43 +1,89 @@
|
|
|
package com.dragon.tj.portal.auth.controller;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.dragon.tj.portal.auth.model.LoginUser;
|
|
|
+import com.dragon.tj.portal.auth.service.TokenService;
|
|
|
import com.dragon.tj.portal.auth.util.SecurityUtils;
|
|
|
import com.dragon.tj.portal.auth.web.entity.SysUser;
|
|
|
import com.dragon.tj.portal.auth.web.service.SysUserService;
|
|
|
import com.dragon.tj.portal.common.base.R;
|
|
|
+import com.dragon.tj.portal.common.constants.DateTimeFormatterConstant;
|
|
|
+import com.dragon.tj.portal.common.enums.log.ModuleEnum;
|
|
|
+import com.dragon.tj.portal.component.redis.StringCacheUtil;
|
|
|
import com.dragon.tj.portal.entity.PageParam;
|
|
|
+import com.dragon.tj.portal.entity.SysLog;
|
|
|
+import com.dragon.tj.portal.service.SysLogService;
|
|
|
import com.dragonsoft.encrypt.EncryptFactory;
|
|
|
import com.dragonsoft.encrypt.EncryptHandler;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/user")
|
|
|
public class UserController {
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
|
|
|
+
|
|
|
+ @Value("${external.esou.url}")
|
|
|
+ private String esouUrl;
|
|
|
+ @Value("${external.dcuc.url}")
|
|
|
+ private String dcucUrl;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
private SysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ private SysLogService sysLogService;
|
|
|
+ @Autowired
|
|
|
+ private StringCacheUtil stringCacheUtil;
|
|
|
|
|
|
@GetMapping("/info")
|
|
|
public R<Map<String, Object>> info(HttpServletRequest request) {
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
- Map<String, Object> data = new HashMap<>(3);
|
|
|
- data.put("name", loginUser.getUsername());
|
|
|
- data.put("deptCode", loginUser.getOrgCode());
|
|
|
- data.put("deptName", loginUser.getUser().getOrgName());
|
|
|
- data.put("idCard", loginUser.getIdCard());
|
|
|
+
|
|
|
+ Map<String, String> userInfo = new HashMap<>();
|
|
|
+ userInfo.put("name", loginUser.getUsername());
|
|
|
+ userInfo.put("deptCode", loginUser.getOrgCode());
|
|
|
+ userInfo.put("deptName", loginUser.getUser().getOrgName());
|
|
|
+ userInfo.put("idCard", loginUser.getIdCard());
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 获取当前在线人数
|
|
|
+ Set<String> keys = stringCacheUtil.keys(TokenService.LOGIN_TOKEN_KEY + "*");
|
|
|
+ userInfo.put("loginUserNum", String.valueOf(keys.size()));
|
|
|
+
|
|
|
+ // 获取上次登录信息
|
|
|
+ List<SysLog> sysLogs = sysLogService.list(
|
|
|
+ Wrappers.<SysLog>query().lambda()
|
|
|
+ .eq(SysLog::getCreateBy, loginUser.getIdCard())
|
|
|
+ .eq(SysLog::getModuleType, ModuleEnum.LOGIN.getCode())
|
|
|
+ .orderByDesc(SysLog::getCreateTime)
|
|
|
+ .last("LIMIT 2")
|
|
|
+ );
|
|
|
+ if (Objects.nonNull(sysLogs) && sysLogs.size() == 2) {
|
|
|
+ userInfo.put("lastLoginTime", DateTimeFormatterConstant.FORMATTER0.format(sysLogs.get(1).getCreateTime()));
|
|
|
+ userInfo.put("lastLoginIp", sysLogs.get(1).getRemoteAddr());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("获取用户[{}]上次登录信息失败", loginUser.getIdCard(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, String> links = new HashMap<>();
|
|
|
EncryptHandler encryptHandler = EncryptFactory.getInstance();
|
|
|
- data.put("encryptIdCard", encryptHandler.encapsulateString(loginUser.getIdCard()));
|
|
|
+ String encryptIdCard = encryptHandler.encapsulateString(loginUser.getIdCard());
|
|
|
+ links.put("esouUrl", esouUrl.replace("{USER_IDCARD}", encryptIdCard));
|
|
|
+ links.put("dcucUrl", dcucUrl);
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>(2);
|
|
|
data.put("roles", loginUser.getPermissions());
|
|
|
+ data.put("userInfo", userInfo);
|
|
|
+ data.put("links", links);
|
|
|
return R.ok(data);
|
|
|
}
|
|
|
|