mirror of
https://github.com/thousmile/molly-multi-tenant.git
synced 2025-12-30 12:42:26 +00:00
添加 登录日志和操作日志
This commit is contained in:
@@ -10,7 +10,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* spring boot jpa 多租户 启动类
|
||||
* spring boot mybatis-plus 多租户 启动类
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
|
||||
@@ -11,6 +11,7 @@ import lombok.experimental.Accessors;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -108,6 +109,11 @@ public class JwtLoginUser implements UserDetails, Principal {
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 过期时间 为空就是永久
|
||||
*/
|
||||
private LocalDateTime expired;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
@@ -139,7 +145,10 @@ public class JwtLoginUser implements UserDetails, Principal {
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
if (expired == null) {
|
||||
return true;
|
||||
}
|
||||
return LocalDateTime.now().isBefore(expired);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,14 +18,15 @@ import static com.xaaef.molly.core.auth.consts.LoginConst.CAPTCHA_CODE_KEY;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* 验证码
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen<932560435@qq.com>
|
||||
* @version 1.0
|
||||
* @version 1.0.1
|
||||
* @createTime 2020/3/5 0005 11:32
|
||||
*/
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xaaef.molly.common.domain.CustomRequestInfo;
|
||||
import com.xaaef.molly.common.util.ServletUtils;
|
||||
import com.xaaef.molly.core.auth.enums.AdminFlag;
|
||||
import com.xaaef.molly.core.auth.enums.GrantType;
|
||||
@@ -17,6 +18,7 @@ import com.xaaef.molly.core.auth.po.LoginFormPO;
|
||||
import com.xaaef.molly.core.auth.service.JwtTokenService;
|
||||
import com.xaaef.molly.core.auth.service.LineCaptchaService;
|
||||
import com.xaaef.molly.core.auth.service.UserLoginService;
|
||||
import com.xaaef.molly.core.log.domain.LoginLog;
|
||||
import com.xaaef.molly.core.log.service.LogStorageService;
|
||||
import com.xaaef.molly.core.tenant.service.MultiTenantManager;
|
||||
import com.xaaef.molly.core.tenant.util.TenantUtils;
|
||||
@@ -24,7 +26,6 @@ import com.xaaef.molly.core.tenant.util.TenantUtils;
|
||||
import com.xaaef.molly.perms.entity.PmsRoleProxy;
|
||||
import com.xaaef.molly.perms.mapper.PmsRoleMapper;
|
||||
import com.xaaef.molly.system.entity.SysMenu;
|
||||
import com.xaaef.molly.system.entity.SysTenant;
|
||||
import com.xaaef.molly.system.enums.MenuTargetEnum;
|
||||
import com.xaaef.molly.system.mapper.SysMenuMapper;
|
||||
import com.xaaef.molly.system.mapper.SysTenantMapper;
|
||||
@@ -45,6 +46,16 @@ import java.util.stream.Collectors;
|
||||
import static com.xaaef.molly.common.util.JsonUtils.DEFAULT_DATE_TIME_PATTERN;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户登录
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen<932560435@qq.com>
|
||||
* @version 1.0.1
|
||||
* @createTime 2020/3/5 0005 11:32
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@@ -93,7 +104,6 @@ public class UserLoginServiceImpl implements UserLoginService {
|
||||
var format = LocalDateTimeUtil.format(currentTenant.getExpired(), DEFAULT_DATE_TIME_PATTERN);
|
||||
throw new JwtAuthException(StrUtil.format("租户 {} 已经在 {} 过期了!", currentTenant.getName(), format));
|
||||
}
|
||||
|
||||
// 把表单提交的 username password 封装到 UsernamePasswordAuthenticationToken中
|
||||
var authResult = authManager.authenticate(
|
||||
new UsernamePasswordAuthenticationToken(
|
||||
@@ -124,7 +134,7 @@ public class UserLoginServiceImpl implements UserLoginService {
|
||||
tokenService.setLoginUser(target);
|
||||
|
||||
// 保存登录日志到数据库中
|
||||
logStorageService.asyncLoginSave(target, ServletUtils.getRequestInfo(request));
|
||||
asyncLoginLogSave(target, ServletUtils.getRequestInfo(request));
|
||||
|
||||
// 删除 redis 中的 验证码
|
||||
captchaService.delete(po.getCodeKey());
|
||||
@@ -189,4 +199,30 @@ public class UserLoginServiceImpl implements UserLoginService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存 登录日志
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @date 2023/2/6 15:56
|
||||
*/
|
||||
private void asyncLoginLogSave(JwtLoginUser loginUser, CustomRequestInfo request) {
|
||||
var loginLog = new LoginLog();
|
||||
loginLog.setRequestUrl(request.getRequestUrl());
|
||||
loginLog.setRequestIp(request.getIp());
|
||||
loginLog.setAddress(request.getAddress());
|
||||
loginLog.setOsName(request.getOsName());
|
||||
loginLog.setBrowser(request.getBrowser());
|
||||
loginLog.setAvatar(loginUser.getAvatar());
|
||||
loginLog.setNickname(loginUser.getNickname());
|
||||
loginLog.setUsername(loginUser.getUsername());
|
||||
loginLog.setUserId(loginUser.getUserId());
|
||||
loginLog.setTenantId(loginUser.getTenantId());
|
||||
loginLog.setCreateTime(loginUser.getLoginTime());
|
||||
loginLog.setGrantType(loginUser.getGrantType().getCode());
|
||||
loginLog.setId(IdUtil.getSnowflakeNextId());
|
||||
logStorageService.asyncLoginSave(loginLog);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.xaaef.molly.core.log.service;
|
||||
|
||||
import com.xaaef.molly.common.domain.CustomRequestInfo;
|
||||
import com.xaaef.molly.core.auth.jwt.JwtLoginUser;
|
||||
import com.xaaef.molly.core.log.domain.LoginLog;
|
||||
import com.xaaef.molly.core.log.domain.OperLog;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
@@ -21,11 +22,11 @@ public interface LogStorageService {
|
||||
/**
|
||||
* 异步保存 登录日志 到 ES 中
|
||||
*
|
||||
* @param loginUser
|
||||
* @param loginLog
|
||||
* @author Wang Chen Chen
|
||||
* @date 2021/8/11 15:30
|
||||
*/
|
||||
void asyncLoginSave(JwtLoginUser loginUser, CustomRequestInfo request);
|
||||
void asyncLoginSave(LoginLog loginLog);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.xaaef.molly.core.log.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.xaaef.molly.common.domain.CustomRequestInfo;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
import com.xaaef.molly.core.auth.jwt.JwtLoginUser;
|
||||
import com.xaaef.molly.core.log.domain.LoginLog;
|
||||
import com.xaaef.molly.core.log.domain.OperLog;
|
||||
import com.xaaef.molly.core.log.service.LogStorageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 操作日志
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen
|
||||
* @version 1.0.1
|
||||
* @date 2021/8/17 16:18
|
||||
*/
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LogStorageServiceAdapter implements LogStorageService {
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void asyncLoginSave(JwtLoginUser loginUser, CustomRequestInfo request) {
|
||||
var loginLog = new LoginLog();
|
||||
loginLog.setRequestUrl(request.getRequestUrl());
|
||||
loginLog.setRequestIp(request.getIp());
|
||||
loginLog.setAddress(request.getAddress());
|
||||
loginLog.setOsName(request.getOsName());
|
||||
loginLog.setBrowser(request.getBrowser());
|
||||
loginLog.setAvatar(loginUser.getAvatar());
|
||||
loginLog.setNickname(loginUser.getNickname());
|
||||
loginLog.setUsername(loginUser.getUsername());
|
||||
loginLog.setUserId(loginUser.getUserId());
|
||||
loginLog.setTenantId(loginUser.getTenantId());
|
||||
loginLog.setCreateTime(loginUser.getLoginTime());
|
||||
loginLog.setGrantType(loginUser.getGrantType().getCode());
|
||||
loginLog.setId(IdUtil.getSnowflakeNextId());
|
||||
log.info("登录日志: \n{}", JsonUtils.toFormatJson(loginLog));
|
||||
}
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void asyncOperateSave(OperLog operLog) {
|
||||
log.info("操作日志: \n{}", JsonUtils.toFormatJson(operLog));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.xaaef.molly.monitor.controller;
|
||||
|
||||
import com.xaaef.molly.common.domain.Pagination;
|
||||
import com.xaaef.molly.common.po.SearchPO;
|
||||
import com.xaaef.molly.common.util.JsonResult;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
import com.xaaef.molly.monitor.service.LmsLoginLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 监控 登录日志
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @version 3.0
|
||||
*/
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/lms/lgoin")
|
||||
@Tag(name = "[ 监控 ] 登录日志")
|
||||
@AllArgsConstructor
|
||||
public class LmsLoginLogController {
|
||||
|
||||
private final LmsLoginLogService baseService;
|
||||
|
||||
|
||||
@Operation(summary = "分页", description = "分页 查询所有")
|
||||
@GetMapping("/query")
|
||||
public JsonResult<Pagination<LmsLoginLog>> pageQuery(SearchPO params) {
|
||||
var page = baseService.pageKeywords(params);
|
||||
return JsonResult.success(page.getTotal(), page.getRecords());
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "批量删除", description = "只需要id即可")
|
||||
@PostMapping()
|
||||
public JsonResult<Boolean> delete(@RequestBody Set<Long> ids) {
|
||||
boolean b = baseService.removeBatchByIds(ids);
|
||||
return JsonResult.success(b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.xaaef.molly.monitor.controller;
|
||||
|
||||
import com.xaaef.molly.common.domain.Pagination;
|
||||
import com.xaaef.molly.common.po.SearchPO;
|
||||
import com.xaaef.molly.common.util.JsonResult;
|
||||
import com.xaaef.molly.monitor.entity.LmsOperLog;
|
||||
import com.xaaef.molly.monitor.service.LmsOperLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 监控 操作日志
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen <932560435@qq.com>
|
||||
* @version 3.0
|
||||
*/
|
||||
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/lms/oper")
|
||||
@Tag(name = "[ 监控 ] 操作日志")
|
||||
@AllArgsConstructor
|
||||
public class LmsOperLogController {
|
||||
|
||||
private final LmsOperLogService baseService;
|
||||
|
||||
|
||||
@Operation(summary = "分页", description = "分页 查询所有")
|
||||
@GetMapping("/query")
|
||||
public JsonResult<Pagination<LmsOperLog>> pageQuery(SearchPO params) {
|
||||
var page = baseService.pageKeywords(params);
|
||||
return JsonResult.success(page.getTotal(), page.getRecords());
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "批量删除", description = "只需要id即可")
|
||||
@PostMapping()
|
||||
public JsonResult<Boolean> delete(@RequestBody Set<Long> ids) {
|
||||
boolean b = baseService.removeBatchByIds(ids);
|
||||
return JsonResult.success(b);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
package com.xaaef.molly.system.controller;
|
||||
package com.xaaef.molly.monitor.controller;
|
||||
|
||||
import com.xaaef.molly.common.util.JsonResult;
|
||||
import com.xaaef.molly.system.entity.ServerInfo;
|
||||
import com.xaaef.molly.monitor.entity.ServerInfo;
|
||||
import com.xaaef.molly.system.service.SysConfigService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.xaaef.molly.monitor.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:27
|
||||
*/
|
||||
|
||||
@TableName("lms_login_log")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LmsLoginLog implements java.io.Serializable {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 授权类型
|
||||
*/
|
||||
private String grantType;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* 请求IP
|
||||
*/
|
||||
private String requestIp;
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 操作系统
|
||||
*/
|
||||
private String osName;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
protected LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.xaaef.molly.monitor.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 操作日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:27
|
||||
*/
|
||||
|
||||
@TableName("lms_oper_log")
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class LmsOperLog implements java.io.Serializable {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 服务名称
|
||||
*/
|
||||
private String serviceName;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 方法
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 方法参数
|
||||
*/
|
||||
private String methodArgs;
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*/
|
||||
private String requestMethod;
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* 请求IP
|
||||
*/
|
||||
private String requestIp;
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 请求响应
|
||||
*/
|
||||
private String responseResult;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 错误日志
|
||||
*/
|
||||
private String errorLog;
|
||||
|
||||
/**
|
||||
* 耗时(毫秒)
|
||||
*/
|
||||
private Long timeCost;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
protected LocalDateTime createTime;
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.xaaef.molly.system.entity;
|
||||
package com.xaaef.molly.monitor.entity;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.xaaef.molly.common.util.ArithUtils;
|
||||
import com.xaaef.molly.common.util.IpUtils;
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
@@ -17,13 +16,10 @@ import oshi.software.os.OperatingSystem;
|
||||
import oshi.util.Util;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.UnknownHostException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.Period;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.xaaef.molly.monitor.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:28
|
||||
*/
|
||||
|
||||
public interface LmsLoginLogMapper extends BaseMapper<LmsLoginLog> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.xaaef.molly.monitor.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
import com.xaaef.molly.monitor.entity.LmsOperLog;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 操作日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:28
|
||||
*/
|
||||
|
||||
public interface LmsOperLogMapper extends BaseMapper<LmsOperLog> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.xaaef.molly.monitor.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xaaef.molly.common.po.SearchPO;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:28
|
||||
*/
|
||||
|
||||
public interface LmsLoginLogService extends IService<LmsLoginLog> {
|
||||
|
||||
IPage<LmsLoginLog> pageKeywords(SearchPO params);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.xaaef.molly.monitor.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.xaaef.molly.common.po.SearchPO;
|
||||
import com.xaaef.molly.monitor.entity.LmsOperLog;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 操作日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:28
|
||||
*/
|
||||
|
||||
public interface LmsOperLogService extends IService<LmsOperLog> {
|
||||
|
||||
IPage<LmsOperLog> pageKeywords(SearchPO params);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.xaaef.molly.monitor.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xaaef.molly.common.po.SearchPO;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
import com.xaaef.molly.monitor.mapper.LmsLoginLogMapper;
|
||||
import com.xaaef.molly.monitor.service.LmsLoginLogService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import static com.xaaef.molly.core.tenant.consts.MbpConst.CREATE_TIME;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:28
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class LmsLoginLogServiceImpl extends ServiceImpl<LmsLoginLogMapper, LmsLoginLog> implements LmsLoginLogService {
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<LmsLoginLog> pageKeywords(SearchPO params) {
|
||||
Page<LmsLoginLog> pageRequest = Page.of(params.getPageIndex(), params.getPageSize());
|
||||
var wrapper = new LambdaQueryWrapper<LmsLoginLog>();
|
||||
// 开始时间是否为空
|
||||
if (ObjectUtils.isNotEmpty(params.getStartDate())) {
|
||||
// 如果结束时间是否为空
|
||||
if (ObjectUtils.isNotEmpty(params.getEndDate())) {
|
||||
wrapper.between(LmsLoginLog::getCreateTime, params.getStartDate(), params.getEndDate());
|
||||
} else {
|
||||
wrapper.between(LmsLoginLog::getCreateTime, params.getStartDate(), LocalDate.now());
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(params.getKeywords())) {
|
||||
wrapper.like(LmsLoginLog::getCreateTime, params.getKeywords());
|
||||
}
|
||||
return super.page(pageRequest, wrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.xaaef.molly.monitor.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.xaaef.molly.common.po.SearchPO;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
import com.xaaef.molly.monitor.entity.LmsOperLog;
|
||||
import com.xaaef.molly.monitor.mapper.LmsOperLogMapper;
|
||||
import com.xaaef.molly.monitor.service.LmsOperLogService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 操作日志
|
||||
* </p>
|
||||
*
|
||||
* @author WangChenChen
|
||||
* @version 1.1
|
||||
* @date 2023/2/6 15:28
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class LmsOperLogServiceImpl extends ServiceImpl<LmsOperLogMapper, LmsOperLog> implements LmsOperLogService {
|
||||
|
||||
|
||||
@Override
|
||||
public IPage<LmsOperLog> pageKeywords(SearchPO params) {
|
||||
Page<LmsOperLog> pageRequest = Page.of(params.getPageIndex(), params.getPageSize());
|
||||
var wrapper = new LambdaQueryWrapper<LmsOperLog>();
|
||||
// 开始时间是否为空
|
||||
if (ObjectUtils.isNotEmpty(params.getStartDate())) {
|
||||
// 如果结束时间是否为空
|
||||
if (ObjectUtils.isNotEmpty(params.getEndDate())) {
|
||||
wrapper.between(LmsOperLog::getCreateTime, params.getStartDate(), params.getEndDate());
|
||||
} else {
|
||||
wrapper.between(LmsOperLog::getCreateTime, params.getStartDate(), LocalDate.now());
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(params.getKeywords())) {
|
||||
wrapper.like(LmsOperLog::getCreateTime, params.getKeywords());
|
||||
}
|
||||
return super.page(pageRequest, wrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.xaaef.molly.monitor.service.impl;
|
||||
|
||||
import com.xaaef.molly.common.util.JsonUtils;
|
||||
import com.xaaef.molly.core.log.domain.LoginLog;
|
||||
import com.xaaef.molly.core.log.domain.OperLog;
|
||||
import com.xaaef.molly.core.log.service.LogStorageService;
|
||||
import com.xaaef.molly.monitor.entity.LmsLoginLog;
|
||||
import com.xaaef.molly.monitor.entity.LmsOperLog;
|
||||
import com.xaaef.molly.monitor.mapper.LmsLoginLogMapper;
|
||||
import com.xaaef.molly.monitor.mapper.LmsOperLogMapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 日志
|
||||
* </p>
|
||||
*
|
||||
* @author Wang Chen Chen
|
||||
* @version 1.0.1
|
||||
* @date 2021/8/17 16:18
|
||||
*/
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class LogStorageServiceImpl implements LogStorageService {
|
||||
|
||||
private final LmsLoginLogMapper loginLogMapper;
|
||||
|
||||
private final LmsOperLogMapper operLogMapper;
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void asyncLoginSave(LoginLog loginLog) {
|
||||
var target = new LmsLoginLog();
|
||||
BeanUtils.copyProperties(loginLog, target);
|
||||
loginLogMapper.insert(target);
|
||||
// log.info("登录日志: \n{}", JsonUtils.toFormatJson(target));
|
||||
}
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void asyncOperateSave(OperLog operLog) {
|
||||
var target = new LmsOperLog();
|
||||
BeanUtils.copyProperties(operLog, target);
|
||||
target.setResponseResult(JsonUtils.toJson(operLog.getResponseResult()));
|
||||
target.setMethodArgs(JsonUtils.toJson(operLog.getMethodArgs()));
|
||||
operLogMapper.insert(target);
|
||||
// log.info("操作日志: \n{}", JsonUtils.toFormatJson(target));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,14 +5,13 @@
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
|
||||
<include file="db/changelog/sys.xml"/>
|
||||
|
||||
<include file="db/changelog/lms.xml"/>
|
||||
|
||||
<include file="db/changelog/pms.xml"/>
|
||||
|
||||
|
||||
|
||||
<!-- 初始化 租户,权限模板 -->
|
||||
<changeSet id="1671072286-1" author="WangChenChen (generated)">
|
||||
<sqlFile path="db/changelog/sql/tenant_init.sql"/>
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
<include file="db/changelog/pms.xml"/>
|
||||
<include file="db/changelog/lms.xml"/>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
||||
59
server/src/main/resources/db/changelog/lms.xml
Normal file
59
server/src/main/resources/db/changelog/lms.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
|
||||
<!-- [ 日志 ] 操作日志 -->
|
||||
<changeSet id="1675663013-1" author="WangChenChen (generated)">
|
||||
<sql splitStatements="true">
|
||||
CREATE TABLE `lms_oper_log`
|
||||
(
|
||||
`id` bigint(20) NOT NULL COMMENT 'ID',
|
||||
`title` varchar(255) NOT NULL COMMENT '标题',
|
||||
`description` varchar(255) NOT NULL COMMENT '描述',
|
||||
`service_name` varchar(255) NOT NULL COMMENT '服务名称',
|
||||
`user_id` bigint(20) COMMENT '用户ID',
|
||||
`method` varchar(255) NOT NULL COMMENT '方法',
|
||||
`method_args` text COMMENT '方法参数',
|
||||
`request_method` varchar(255) COMMENT '请求类型',
|
||||
`request_url` varchar(255) COMMENT '请求地址',
|
||||
`request_ip` varchar(255) COMMENT '请求IP',
|
||||
`address` varchar(255) COMMENT '请求地址',
|
||||
`response_result` text COMMENT '请求响应',
|
||||
`status` int(11) NOT NULL COMMENT '状态',
|
||||
`error_log` text COMMENT '错误日志',
|
||||
`time_cost` bigint(20) NOT NULL COMMENT '耗时(毫秒)',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='[ 日志 ] 操作日志';
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
|
||||
<!-- [ 日志 ] 登录日志 -->
|
||||
<changeSet id="1675663115-1" author="WangChenChen (generated)">
|
||||
<sql splitStatements="true">
|
||||
CREATE TABLE `lms_login_log`
|
||||
(
|
||||
`id` bigint(20) NOT NULL COMMENT 'ID',
|
||||
`grant_type` varchar(255) NOT NULL COMMENT '授权类型',
|
||||
`user_id` bigint(20) NOT NULL COMMENT '用户ID',
|
||||
`nickname` varchar(255) NOT NULL COMMENT '用户昵称',
|
||||
`username` varchar(255) NOT NULL COMMENT '用户名',
|
||||
`avatar` varchar(255) NOT NULL COMMENT '头像',
|
||||
`request_url` varchar(255) NOT NULL COMMENT '请求地址',
|
||||
`request_ip` varchar(255) NOT NULL COMMENT '请求IP',
|
||||
`address` varchar(255) NOT NULL COMMENT '请求地址',
|
||||
`os_name` varchar(255) COMMENT '操作系统',
|
||||
`browser` varchar(255) COMMENT '浏览器',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='[ 日志 ] 登录日志';
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
|
||||
</databaseChangeLog>
|
||||
@@ -41,7 +41,6 @@ INSERT INTO `sys_menu` VALUES (10018, '视图', 10004, 'pre_user:view', '#', '',
|
||||
INSERT INTO `sys_menu` VALUES (10019, '修改', 10004, 'pre_user:update', '#', '', '', 3, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10020, '删除', 10004, 'pre_user:delete', '#', '', '', 4, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10021, '重置密码', 10004, 'pre_user:reset:password', '#', '', '', 5, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10022, '修改角色', 10004, 'pre_user:update:roles', '#', '', '', 6, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10023, '视图', 10005, 'pre_role:view', '#', '', '', 1, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10024, '新增', 10005, 'pre_role:create', '#', '', '', 2, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10025, '修改', 10005, 'pre_role:update', '#', '', '', 3, 1, 1, 2, '2022-06-25 15:03:42', 19980817, '2022-06-25 15:03:42', 19980817);
|
||||
@@ -56,7 +55,6 @@ INSERT INTO `sys_menu` VALUES (10033, '新增', 10006, 'pre_menu:create', '#', '
|
||||
INSERT INTO `sys_menu` VALUES (10034, '修改', 10006, 'pre_menu:update', '#', '', '', 3, 1, 1, 1, '2022-06-25 15:03:42', 19980817, '2022-06-27 20:39:53', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10035, '删除', 10006, 'pre_menu:delete', '#', '', '', 4, 1, 1, 1, '2022-06-25 15:03:42', 19980817, '2022-06-27 20:39:25', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10036, '字典数据', 10001, 'sys:dict:data', 'sys/dict/dictData', '#', '/sys/dict/data', 7, 0, 0, 1, '2022-06-27 20:36:39', 19980817, '2022-06-30 12:10:50', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10037, '新增租户', 10016, 'sys:tenant:create:link', 'sys/tenant/createTenant', 'sys', '/sys/tenant/create', 1, 0, 0, 1, '2022-06-27 21:28:41', 19980817, '2022-06-27 21:28:41', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10038, '数据统计', 0, 'statistics', 'Layout', 'statistics', '/statistics', 1, 0, 1, 2, '2022-07-30 18:17:42', 19980817, '2022-07-30 18:17:42', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10039, '能耗统计', 10038, 'statistics:energy', 'statistics/energy/index', 'statistics_energy', '/statistics/energy', 5, 0, 1, 2, '2022-07-30 18:18:27', 19980817, '2022-07-30 18:18:27', 19980817);
|
||||
INSERT INTO `sys_menu` VALUES (10040, '趋势分析', 10038, 'statistics:trend', 'statistics/trend/index', 'statistics_trend', '/statistics/trend', 10, 0, 1, 2, '2022-07-30 18:19:12', 19980817, '2022-07-30 18:19:12', 19980817);
|
||||
|
||||
@@ -243,4 +243,5 @@
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
|
||||
</databaseChangeLog>
|
||||
|
||||
Reference in New Issue
Block a user