|
@@ -1,24 +1,40 @@
|
|
|
package cn.tycoding.langchat.auth.endpoint;
|
|
|
|
|
|
+import static cn.tycoding.langchat.common.constant.CacheConst.AUTH_SESSION_PREFIX;
|
|
|
+
|
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.Dict;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.tycoding.langchat.auth.service.TokenInfo;
|
|
|
import cn.tycoding.langchat.common.constant.CacheConst;
|
|
|
import cn.tycoding.langchat.common.exception.ServiceException;
|
|
|
import cn.tycoding.langchat.common.properties.AuthProps;
|
|
|
+import cn.tycoding.langchat.common.utils.MybatisUtil;
|
|
|
import cn.tycoding.langchat.common.utils.QueryPage;
|
|
|
import cn.tycoding.langchat.common.utils.R;
|
|
|
import cn.tycoding.langchat.upms.dto.UserInfo;
|
|
|
import cn.tycoding.langchat.upms.service.SysUserService;
|
|
|
import cn.tycoding.langchat.upms.utils.AuthUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+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;
|
|
|
|
|
|
/**
|
|
|
* @author tycoding
|
|
@@ -72,15 +88,36 @@ public class AuthEndpoint {
|
|
|
|
|
|
@GetMapping("/token/page")
|
|
|
public R tokenPage(QueryPage queryPage) {
|
|
|
- List<String> list = StpUtil.searchTokenValue("", queryPage.getPage(), queryPage.getLimit(), true);
|
|
|
+ List<String> list = StpUtil.searchTokenValue("", queryPage.getPage() - 1, queryPage.getLimit(), true);
|
|
|
List ids = redisTemplate.opsForValue().multiGet(list);
|
|
|
+ Set<String> keys = redisTemplate.keys(AUTH_SESSION_PREFIX + "*");
|
|
|
+
|
|
|
+ List<Object> result = new ArrayList<>();
|
|
|
ids.forEach(id -> {
|
|
|
+ Dict data = Dict.create();
|
|
|
Map<String, Object> dataMap = StpUtil.getSessionByLoginId(id).getDataMap();
|
|
|
UserInfo userInfo = (UserInfo)dataMap.get(CacheConst.AUTH_USER_INFO_KEY);
|
|
|
SaTokenInfo tokenInfo = (SaTokenInfo)dataMap.get(CacheConst.AUTH_TOKEN_INFO_KEY);
|
|
|
+ data.set("token", tokenInfo.tokenValue);
|
|
|
+ data.set("perms", userInfo.getPerms());
|
|
|
+ data.set("roles", userInfo.getRoles());
|
|
|
+ data.set("email", userInfo.getEmail());
|
|
|
+ data.set("id", userInfo.getId());
|
|
|
+ data.set("username", userInfo.getUsername());
|
|
|
+ data.set("realName", userInfo.getRealName());
|
|
|
+
|
|
|
+ long expiration = StpUtil.getTokenTimeout();
|
|
|
+ Date targetDate = new Date(System.currentTimeMillis() + expiration);
|
|
|
+ String formattedDate = DateUtil.format(targetDate, DatePattern.NORM_DATETIME_PATTERN);
|
|
|
+ data.set("expiration", formattedDate);
|
|
|
+
|
|
|
+ result.add(data);
|
|
|
});
|
|
|
|
|
|
- return R.ok(list);
|
|
|
+ IPage page = new Page(queryPage.getPage(), queryPage.getLimit());
|
|
|
+ page.setRecords(result);
|
|
|
+ page.setTotal(keys == null ? 0 : keys.size());
|
|
|
+ return R.ok(MybatisUtil.getData(page));
|
|
|
}
|
|
|
|
|
|
}
|