use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.
the class MyBatisPlusMetaObjectHandler method insertFill.
/**
* 新增填充
*
* @param metaObject {@link MetaObject}
*/
@Override
public void insertFill(MetaObject metaObject) {
User currentUser = SecurityUtils.getCurrentUser();
if (null != currentUser) {
this.fillStrategy(metaObject, "createUserId", currentUser.getId());
}
this.fillStrategy(metaObject, "createTime", LocalDateTime.now());
this.fillStrategy(metaObject, "version", 1);
}
use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.
the class MyBatisPlusMetaObjectHandler method updateFill.
/**
* 修改填充
*
* @param metaObject {@link MetaObject}
*/
@Override
public void updateFill(MetaObject metaObject) {
User currentUser = SecurityUtils.getCurrentUser();
if (null != currentUser) {
this.fillStrategy(metaObject, "updateUserId", currentUser.getId());
}
this.fillStrategy(metaObject, "updateTime", LocalDateTime.now());
}
use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.
the class LogAspectj method handleLog.
/**
* 日志处理
*/
void handleLog(final JoinPoint joinPoint, Object jsonResult, final Exception e) {
try {
Log log = getAnnotationLog(joinPoint);
if (check(joinPoint, log)) {
return;
}
// 当前用户
OperLogEntity entity = new OperLogEntity();
// 状态
entity.setStatus(StatusEnum.SUCCESS.getValue());
// 操作类型
entity.setOperType(log.businessType().getValue());
// 请求用户
User currentUser = SecurityUtils.getCurrentUser();
if (null != currentUser) {
entity.setUsername(currentUser.getUsername());
entity.setCreateUserId(currentUser.getId());
entity.setCreateTime(LocalDateTimeUtils.now());
}
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
if (null == attributes) {
return;
}
// 请求ip
String ip = "";
// 请求地址
String requestUrl = "";
// 请求方式
String requestMethod = "";
if (attributes instanceof ServletRequestAttributes) {
HttpServletRequest request = ((ServletRequestAttributes) attributes).getRequest();
ip = ServletUtil.getClientIP(request);
// 请求地址
requestUrl = request.getRequestURI();
requestMethod = request.getMethod();
}
entity.setOperIp(ip);
// 描述
// 类描述
String controllerDescription = "";
ClassDescribe classDescribe = joinPoint.getTarget().getClass().getAnnotation(ClassDescribe.class);
if (null != classDescribe) {
controllerDescription = classDescribe.value();
}
// 方法描述
String controllerMethodDescription = getDescribe(log);
if (log.controllerApiValue()) {
entity.setDescription(StringUtils.join(controllerDescription, controllerMethodDescription));
} else {
entity.setDescription(controllerMethodDescription);
}
// 请求地址
entity.setRequestUrl(requestUrl);
// 请求方式
entity.setRequestMethod(requestMethod);
// 操作方法
String className = joinPoint.getTarget().getClass().getName();
String methodName = joinPoint.getSignature().getName();
entity.setOperMethod(className + "." + methodName);
// 请求参数
if (log.request()) {
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
String requestParamsValue = getRequestValue(joinPoint, request, log.paramsName());
entity.setRequestParams(requestParamsValue);
}
// 返回参数
if (log.response()) {
String result = JsonUtils.objectToJson(null == jsonResult ? "" : jsonResult);
entity.setRequestResult(result);
}
if (null != e) {
if (log.requestByError()) {
String result = JsonUtils.objectToJson(null == jsonResult ? "" : jsonResult);
entity.setRequestResult(result);
String message = ExceptionUtils.getExceptionMessage(e);
entity.setErrorMessage(StringUtils.substring(message, 0, 2000));
entity.setStatus(StatusEnum.FAIL.getValue());
}
}
AsyncManager.me().execute(AsyncFactory.recordOperLog(entity));
} catch (Exception e1) {
e1.printStackTrace();
if (null != e) {
e.printStackTrace();
}
// 记录本地异常日志
LOGGER.error("==前置通知异常==");
LOGGER.error("异常信息:{}", e1.getMessage());
if (null != e) {
throw new BusinessException(e.getMessage());
} else {
throw new BusinessException(e1.getMessage());
}
}
}
use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.
the class MenuEventListener method findMenuByUser.
private List<TreeMenuDTO> findMenuByUser(UserDTO user) {
if (null == user) {
return null;
}
if (user.getIsAdmin() == 1) {
MenuParams params = new MenuParams();
params.setSortType(SortTypeEnum.ASC.getValue());
params.setSortColumn(Collections.singletonList(MenuEntity.SORT));
QueryWrapper<MenuEntity> query = QueryWrapperUtils.getQuery(params);
List<MenuEntity> entities = menuService.list(query);
return BeanUtil.copyToList(entities, TreeMenuDTO.class);
}
Collection<Long> permissionIds = user.getPermissionIds();
if (CollectionUtils.isEmpty(permissionIds)) {
return Lists.newArrayList();
}
LambdaQueryWrapper<PermissionEntity> queryWrapper = Wrappers.lambdaQuery(PermissionEntity.class).in(PermissionEntity::getId, permissionIds).select(PermissionEntity::getMenuId, PermissionEntity::getPermission);
// 权限
List<PermissionEntity> permissionEntities = ((UserInfoServiceImpl) userInfoService.getThis()).getPermissionService().list(queryWrapper);
if (CollectionUtils.isEmpty(permissionEntities)) {
return Lists.newArrayList();
}
Map<Long, List<String>> permissionMapping = permissionEntities.stream().collect(Collectors.groupingBy(PermissionEntity::getMenuId, Collectors.mapping(PermissionEntity::getPermission, Collectors.toList())));
// 菜单
List<Long> menuIds = permissionEntities.parallelStream().map(PermissionEntity::getMenuId).collect(Collectors.toList());
Set<MenuEntity> entities = Sets.newHashSet();
for (Long menuId : menuIds) {
entities.addAll(menuService.getSuperior(menuId, Lists.newArrayList()));
}
List<MenuEntity> menuEntities = entities.stream().sorted(Comparator.comparing(MenuEntity::getSort)).collect(Collectors.toList());
List<TreeMenuDTO> treeMenu = BeanUtil.copyToList(menuEntities, TreeMenuDTO.class);
for (TreeMenuDTO menu : treeMenu) {
menu.setAuthority(permissionMapping.get(menu.getId()));
}
return treeMenu;
}
use of com.hb0730.boot.admin.security.model.User in project boot-admin by hb0730.
the class MenuServiceImpl method updateCurrentMenu.
@Override
public boolean updateCurrentMenu() {
User currentUser = SecurityUtils.getCurrentUser();
if (null == currentUser) {
throw new LoginException(ResponseStatusEnum.USE_LOGIN_ERROR, "当前用户未登录,请登录后重试");
}
eventPublisher.publishEvent(new MenuEvent(this, currentUser.getId()));
return true;
}
Aggregations