mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	迁移登陆日志的代码
This commit is contained in:
		| @@ -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<PageResult<SysLoginLogRespVO>> getLoginLogPage(@Validated SysLoginLogPageReqVO reqVO) { | ||||
|         PageResult<SysLoginLogDO> 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<SysLogininfor> list = logininforService.selectLogininforList(logininfor); | ||||
| //        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class); | ||||
| //        return util.exportExcel(list, "登录日志"); | ||||
| //    } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -8,7 +8,7 @@ import lombok.ToString; | ||||
|  | ||||
| import java.util.Date; | ||||
|  | ||||
| @ApiModel("操作日志 Response VO") | ||||
| @ApiModel("登陆日志 Response VO") | ||||
| @Data | ||||
| @EqualsAndHashCode(callSuper = true) | ||||
| @ToString(callSuper = true) | ||||
|   | ||||
| @@ -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<SysLoginLogRespVO> convertPage(PageResult<SysLoginLogDO> page); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<SysLoginLogDO> { | ||||
|  | ||||
|     default PageResult<SysLoginLogDO> selectPage(SysLoginLogPageReqVO reqVO) { | ||||
|         QueryWrapperX<SysLoginLogDO> query = new QueryWrapperX<SysLoginLogDO>() | ||||
|                 .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); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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), // 验证码不正确 | ||||
|  | ||||
|   | ||||
| @@ -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<SysLoginLogDO> getLoginLogPage(SysLoginLogPageReqVO reqVO); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -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<SysLoginLogDO> getLoginLogPage(SysLoginLogPageReqVO reqVO) { | ||||
|         return loginLogMapper.selectPage(reqVO); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV