diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java deleted file mode 100644 index 6146f34ad..000000000 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysLogininforController.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.ruoyi.web.controller.monitor; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -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.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.system.domain.SysLogininfor; -import com.ruoyi.system.service.ISysLogininforService; - -/** - * 系统访问记录 - * - * @author ruoyi - */ -@RestController -@RequestMapping("/monitor/logininfor") -public class SysLogininforController extends BaseController { - - @Autowired - private ISysLogininforService logininforService; - - @PreAuthorize("@ss.hasPermi('monitor:logininfor:list')") - @GetMapping("/list") - public TableDataInfo list(SysLogininfor logininfor) { - startPage(); - List list = logininforService.selectLogininforList(logininfor); - return getDataTable(list); - } - - @Log(title = "登录日志", businessType = BusinessType.EXPORT) - @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')") - @GetMapping("/export") - public AjaxResult export(SysLogininfor logininfor) { - List list = logininforService.selectLogininforList(logininfor); - ExcelUtil util = new ExcelUtil(SysLogininfor.class); - return util.exportExcel(list, "登录日志"); - } - -} diff --git a/ruoyi-ui/src/api/monitor/logininfor.js b/ruoyi-ui/src/api/monitor/logininfor.js deleted file mode 100644 index 0b89cdc6e..000000000 --- a/ruoyi-ui/src/api/monitor/logininfor.js +++ /dev/null @@ -1,35 +0,0 @@ -import request from '@/utils/request' - -// 查询登录日志列表 -export function list(query) { - return request({ - url: '/monitor/logininfor/list', - method: 'get', - params: query - }) -} - -// 删除登录日志 -export function delLogininfor(infoId) { - return request({ - url: '/monitor/logininfor/' + infoId, - method: 'delete' - }) -} - -// 清空登录日志 -export function cleanLogininfor() { - return request({ - url: '/monitor/logininfor/clean', - method: 'delete' - }) -} - -// 导出登录日志 -export function exportLogininfor(query) { - return request({ - url: '/monitor/logininfor/export', - method: 'get', - params: query - }) -} \ No newline at end of file diff --git a/ruoyi-ui/src/api/system/loginlog.js b/ruoyi-ui/src/api/system/loginlog.js new file mode 100644 index 000000000..41aba1fe1 --- /dev/null +++ b/ruoyi-ui/src/api/system/loginlog.js @@ -0,0 +1,20 @@ +import request from '@/utils/request' + +// 查询登录日志列表 +export function list(query) { + return request({ + url: '/system/login-log/page', + method: 'get', + params: query + }) +} + +// 导出登录日志 +export function exportLoginLog(query) { + return request({ + url: '/system/login-log/export', + method: 'get', + params: query, + responseType: 'blob' + }) +} diff --git a/ruoyi-ui/src/utils/dict.js b/ruoyi-ui/src/utils/dict.js index 00f74aefe..af1bcd836 100644 --- a/ruoyi-ui/src/utils/dict.js +++ b/ruoyi-ui/src/utils/dict.js @@ -12,7 +12,8 @@ export const DICT_TYPE = { SYS_DATA_SCOPE: 'sys_data_scope', SYS_USER_SEX: 'sys_user_sex', SYS_NOTICE_TYPE: 'sys_notice_type', - SYS_OPERATE_TYPE: 'sys_operate_type' + SYS_OPERATE_TYPE: 'sys_operate_type', + SYS_LOGIN_RESULT: 'sys_login_result' } /** diff --git a/ruoyi-ui/src/views/monitor/logininfor/index.vue b/ruoyi-ui/src/views/system/loginlog/index.vue similarity index 50% rename from ruoyi-ui/src/views/monitor/logininfor/index.vue rename to ruoyi-ui/src/views/system/loginlog/index.vue index 90d321f3e..601c9420f 100644 --- a/ruoyi-ui/src/views/monitor/logininfor/index.vue +++ b/ruoyi-ui/src/views/system/loginlog/index.vue @@ -1,230 +1,185 @@ - - - - + + + + diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysLoginLogController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysLoginLogController.java index 65fba768d..88638b64e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysLoginLogController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/SysLoginLogController.java @@ -1,4 +1,44 @@ package cn.iocoder.dashboard.modules.system.controller.logger; +import cn.iocoder.dashboard.common.pojo.CommonResult; +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; +import cn.iocoder.dashboard.modules.system.convert.logger.SysLoginLogConvert; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysLoginLogDO; +import cn.iocoder.dashboard.modules.system.service.logger.SysLoginLogService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +@Api(tags = "登陆日志 API") +@RestController +@RequestMapping("/system/login-log") public class SysLoginLogController { + + @Resource + private SysLoginLogService loginLogService; + + @ApiOperation("获得登陆日志分页列表") + @GetMapping("/page") +// @PreAuthorize("@ss.hasPermi('system:login-log:query')") + public CommonResult> getLoginLogPage(@Validated SysLoginLogPageReqVO reqVO) { + PageResult page = loginLogService.getLoginLogPage(reqVO); + return CommonResult.success(SysLoginLogConvert.INSTANCE.convertPage(page)); + } + +// @GetMapping("/export") +//// @Log(title = "登录日志", businessType = BusinessType.EXPORT) +//// @PreAuthorize("@ss.hasPermi('monitor:logininfor:export')") +// public void exportLoginLog(SysLogininfor logininfor) { +// List list = logininforService.selectLogininforList(logininfor); +// ExcelUtil util = new ExcelUtil(SysLogininfor.class); +// return util.exportExcel(list, "登录日志"); +// } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java new file mode 100644 index 000000000..c90bfff0b --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java @@ -0,0 +1,36 @@ +package cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog; + +import cn.iocoder.dashboard.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@ApiModel("登陆日志分页列表 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class SysLoginLogPageReqVO extends PageParam { + + @ApiModelProperty(value = "用户 IP", example = "127.0.0.1", notes = "模拟匹配") + private String userIp; + + @ApiModelProperty(value = "用户账号", example = "芋道", notes = "模拟匹配") + private String username; + + @ApiModelProperty(value = "操作状态", example = "true") + private Boolean status; + + @ApiModelProperty(value = "开始时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date beginTime; + + @ApiModelProperty(value = "结束时间", example = "2020-10-24") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private Date endTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java index e3e3f9de1..f9e2664f8 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java @@ -8,7 +8,7 @@ import lombok.ToString; import java.util.Date; -@ApiModel("操作日志 Response VO") +@ApiModel("登陆日志 Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysLoginLogConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysLoginLogConvert.java index 301fff469..71a7e5093 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysLoginLogConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/logger/SysLoginLogConvert.java @@ -1,6 +1,8 @@ package cn.iocoder.dashboard.modules.system.convert.logger; +import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogRespVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysLoginLogDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -12,4 +14,6 @@ public interface SysLoginLogConvert { SysLoginLogDO convert(SysLoginLogCreateReqVO bean); + PageResult convertPage(PageResult page); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysLoginLogMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysLoginLogMapper.java index 5f0b0904c..8d7b0a944 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysLoginLogMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/logger/SysLoginLogMapper.java @@ -1,9 +1,28 @@ package cn.iocoder.dashboard.modules.system.dal.mysql.dao.logger; +import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysLoginLogDO; +import cn.iocoder.dashboard.modules.system.enums.logger.SysLoginResultEnum; import org.apache.ibatis.annotations.Mapper; @Mapper public interface SysLoginLogMapper extends BaseMapperX { + + default PageResult selectPage(SysLoginLogPageReqVO reqVO) { + QueryWrapperX query = new QueryWrapperX() + .likeIfPresent("user_ip", reqVO.getUserIp()) + .likeIfPresent("username", reqVO.getUsername()) + .betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()); + if (Boolean.TRUE.equals(reqVO.getStatus())) { + query.eq("result", SysLoginResultEnum.SUCCESS.getResult()); + } else if (Boolean.FALSE.equals(reqVO.getStatus())) { + query.gt("result", SysLoginResultEnum.SUCCESS.getResult()); + } + query.orderByDesc("id"); // 降序 + return selectPage(reqVO, query); + } + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysLoginResultEnum.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysLoginResultEnum.java index 4a26a7243..96887fb7e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysLoginResultEnum.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/logger/SysLoginResultEnum.java @@ -12,7 +12,7 @@ public enum SysLoginResultEnum { SUCCESS(0), // 成功 BAD_CREDENTIALS(10), // 账号或密码不正确 - USER_DISABLED(20), // 账号或密码不正确 + USER_DISABLED(20), // 用户被禁用 CAPTCHA_NOT_FOUND(30), // 验证码不存在 CAPTCHA_CODE_ERROR(31), // 验证码不正确 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysLoginLogService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysLoginLogService.java index adda74456..d6c67569f 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysLoginLogService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/SysLoginLogService.java @@ -1,6 +1,9 @@ package cn.iocoder.dashboard.modules.system.service.logger; +import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysLoginLogDO; /** * 登陆日志 Service 接口 @@ -14,4 +17,12 @@ public interface SysLoginLogService { */ void createLoginLog(SysLoginLogCreateReqVO reqVO); + /** + * 获得登陆日志分页 + * + * @param reqVO 分页条件 + * @return 登陆日志分页 + */ + PageResult getLoginLogPage(SysLoginLogPageReqVO reqVO); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysLoginLogServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysLoginLogServiceImpl.java index 36c41e31a..9f55354d1 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysLoginLogServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/logger/impl/SysLoginLogServiceImpl.java @@ -1,13 +1,22 @@ package cn.iocoder.dashboard.modules.system.service.logger.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; +import cn.iocoder.dashboard.modules.system.controller.logger.vo.loginlog.SysLoginLogPageReqVO; import cn.iocoder.dashboard.modules.system.convert.logger.SysLoginLogConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.logger.SysLoginLogMapper; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.logger.SysLoginLogDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; import cn.iocoder.dashboard.modules.system.service.logger.SysLoginLogService; +import cn.iocoder.dashboard.modules.system.service.user.SysUserService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.Collection; + +import static cn.iocoder.dashboard.util.collection.CollectionUtils.convertSet; /** * 登陆日志 Service 实现 @@ -18,10 +27,18 @@ public class SysLoginLogServiceImpl implements SysLoginLogService { @Resource private SysLoginLogMapper loginLogMapper; + @Resource + private SysUserService userService; + @Override public void createLoginLog(SysLoginLogCreateReqVO reqVO) { SysLoginLogDO loginLog = SysLoginLogConvert.INSTANCE.convert(reqVO); loginLogMapper.insert(loginLog); } + @Override + public PageResult getLoginLogPage(SysLoginLogPageReqVO reqVO) { + return loginLogMapper.selectPage(reqVO); + } + }