♻️ Refactoring code. @Inner
This commit is contained in:
1 parent
70bc5100b3
commit
c8658f0fbd
6 files changed
+15
-67
No files matched your search
@@ -26,7 +26,7 @@ import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.PaginationConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import com.pig4cloud.pigx.common.security.annotation.Inner;
|
||||
import com.pig4cloud.pigx.common.security.service.PigxUser;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.cache.CacheManager;
|
||||
@@ -110,6 +110,7 @@ public class PigxTokenEndpoint {
|
||||
* @param token token
|
||||
* @return
|
||||
*/
|
||||
@Inner
|
||||
@DeleteMapping("/{token}")
|
||||
public R<Boolean> delToken(@PathVariable("token") String token) {
|
||||
return new R<>(redisTemplate.delete(PIGX_OAUTH_ACCESS + token));
|
||||
@@ -122,6 +123,7 @@ public class PigxTokenEndpoint {
|
||||
* @param params 分页参数
|
||||
* @return
|
||||
*/
|
||||
@Inner
|
||||
@PostMapping("/page")
|
||||
public R<Page> tokenList(@RequestBody Map<String, Object> params) {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
@@ -169,9 +171,6 @@ public class PigxTokenEndpoint {
|
||||
private boolean extractToken(Map<String, String> map, Object principal) {
|
||||
if (principal instanceof PigxUser) {
|
||||
PigxUser user = (PigxUser) principal;
|
||||
if (!user.getTenantId().equals(TenantContextHolder.getTenantId())) {
|
||||
return true;
|
||||
}
|
||||
map.put("user_id", user.getId() + "");
|
||||
map.put("user_name", user.getUsername() + "");
|
||||
}
|
||||
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
package com.pig4cloud.pigx.common.data.mybatis;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Mybatis Plus的参数填充器
|
||||
* @author lishangbu
|
||||
* @date 2018/12/28
|
||||
* 利用Mybatis Plus的参数填充器设置一些公共信息参数
|
||||
* setFieldValByName方法传入的字段名称是Java Bean的属性
|
||||
* 其接口默认方法会自行进行判空之类的预处理,因此不需要我们进一步操作
|
||||
* MP 3.0.7将会变更这个方法
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
|
||||
private static final String CREATE_USER = "createUser";
|
||||
private static final String UPDATE_USER = "updateUser";
|
||||
private static final String CREATE_TIME = "createTime";
|
||||
private static final String UPDATE_TIME = "updateTime";
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
this.setFieldValByName(CREATE_TIME, LocalDateTime.now(),metaObject);
|
||||
this.setFieldValByName(CREATE_USER,getUserName(),metaObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.setFieldValByName(UPDATE_TIME,LocalDateTime.now(),metaObject);
|
||||
this.setFieldValByName(UPDATE_USER,getUserName(),metaObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户名信息
|
||||
* 开启details属性的情况下,通过用户实体获取用户名
|
||||
* 反之直接获取用户名
|
||||
* @return
|
||||
*/
|
||||
private String getUserName(){
|
||||
return Optional.ofNullable(SecurityUtils.getUser().getUsername())
|
||||
.orElse(SecurityUtils.getUsername());
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.pig4cloud.pigx.common.data.cache.RedisCacheAutoConfiguration,\
|
||||
com.pig4cloud.pigx.common.data.tenant.TenantContextHolderFilter,\
|
||||
com.pig4cloud.pigx.common.data.tenant.PigxFeignTenantConfiguration,\
|
||||
com.pig4cloud.pigx.common.data.mybatis.MybatisPlusConfig,\
|
||||
com.pig4cloud.pigx.common.data.mybatis.MybatisPlusMetaObjectHandler
|
||||
com.pig4cloud.pigx.common.data.mybatis.MybatisPlusConfig
|
||||
+4
-6
@@ -19,13 +19,11 @@ package com.pig4cloud.pigx.admin.api.feign;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.feign.factory.RemoteTokenServiceFallbackFactory;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
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.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -42,7 +40,7 @@ public interface RemoteTokenService {
|
||||
* @return page
|
||||
*/
|
||||
@PostMapping("/token/page")
|
||||
R<Page> getTokenPage(@RequestBody Map<String, Object> params);
|
||||
R<Page> getTokenPage(@RequestBody Map<String, Object> params,@RequestHeader(SecurityConstants.FROM) String from);
|
||||
|
||||
/**
|
||||
* 删除token
|
||||
@@ -51,5 +49,5 @@ public interface RemoteTokenService {
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/token/{token}")
|
||||
R<Boolean> removeTokenById(@PathVariable("token") String token);
|
||||
R<Boolean> removeTokenById(@PathVariable("token") String token,@RequestHeader(SecurityConstants.FROM) String from);
|
||||
}
|
||||
+4
-2
@@ -41,10 +41,11 @@ public class RemoteTokenServiceFallbackImpl implements RemoteTokenService {
|
||||
* 分页查询token 信息
|
||||
*
|
||||
* @param params 分页参数
|
||||
* @param from 内部调用标志
|
||||
* @return page
|
||||
*/
|
||||
@Override
|
||||
public R<Page> getTokenPage(Map<String, Object> params) {
|
||||
public R<Page> getTokenPage(Map<String, Object> params, String from) {
|
||||
log.error("调用认证中心查询token 失败", cause);
|
||||
return null;
|
||||
}
|
||||
@@ -53,10 +54,11 @@ public class RemoteTokenServiceFallbackImpl implements RemoteTokenService {
|
||||
* 删除token
|
||||
*
|
||||
* @param token
|
||||
* @param from 内部调用标志
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R<Boolean> removeTokenById(String token) {
|
||||
public R<Boolean> removeTokenById(String token, String from) {
|
||||
log.error("删除token 失败 {}", token, cause);
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteTokenService;
|
||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -47,7 +48,7 @@ public class TokenController {
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R getTokenPage(@RequestParam Map<String, Object> params) {
|
||||
return remoteTokenService.getTokenPage(params);
|
||||
return remoteTokenService.getTokenPage(params, SecurityConstants.FROM_IN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,6 +61,6 @@ public class TokenController {
|
||||
@DeleteMapping("/{token}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_token_del')")
|
||||
public R removeById(@PathVariable String token) {
|
||||
return remoteTokenService.removeTokenById(token);
|
||||
return remoteTokenService.removeTokenById(token, SecurityConstants.FROM_IN);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user