feat: 增加登录日志接口
Esse commit está contido em:
pai
3a91f8b8fe
commit
c0f460e1e4
@ -0,0 +1,65 @@
|
||||
package com.cnbm.admin.controller;
|
||||
|
||||
import com.cnbm.admin.annotation.LogOperation;
|
||||
import com.cnbm.admin.dto.SysLogLoginDTO;
|
||||
import com.cnbm.admin.execl.SysLogLoginExcel;
|
||||
import com.cnbm.admin.service.SysLogLoginService;
|
||||
import com.cnbm.common.constant.Constant;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.utils.ExcelUtils;
|
||||
import com.cnbm.common.utils.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("sys/log/login")
|
||||
@Api(tags="登录日志")
|
||||
public class SysLogLoginController {
|
||||
@Autowired
|
||||
private SysLogLoginService sysLogLoginService;
|
||||
|
||||
@GetMapping("page")
|
||||
@ApiOperation("分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataTypeClass=Integer.class) ,
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataTypeClass=Integer.class) ,
|
||||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataTypeClass=String.class) ,
|
||||
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataTypeClass=String.class) ,
|
||||
@ApiImplicitParam(name = "status", value = "状态 0:失败 1:成功 2:账号已锁定", paramType = "query", dataTypeClass=Integer.class),
|
||||
@ApiImplicitParam(name = "creatorName", value = "用户名", paramType = "query", dataTypeClass=String.class)
|
||||
})
|
||||
@PreAuthorize("@ex.hasAuthority('sys:log:login')")
|
||||
public Result<PageData<SysLogLoginDTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
||||
PageData<SysLogLoginDTO> page = sysLogLoginService.page(params);
|
||||
|
||||
return new Result<PageData<SysLogLoginDTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("export")
|
||||
@ApiOperation("导出")
|
||||
@LogOperation("导出")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "status", value = "状态 0:失败 1:成功 2:账号已锁定", paramType = "query", dataTypeClass=Integer.class),
|
||||
@ApiImplicitParam(name = "creatorName", value = "用户名", paramType = "query", dataTypeClass=String.class)
|
||||
})
|
||||
@PreAuthorize("@ex.hasAuthority('sys:log:login')")
|
||||
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
||||
List<SysLogLoginDTO> list = sysLogLoginService.list(params);
|
||||
|
||||
ExcelUtils.exportExcelToTarget(response, null, list, SysLogLoginExcel.class);
|
||||
}
|
||||
|
||||
}
|
10
ym-admin/src/main/java/com/cnbm/admin/dao/SysLogLoginDao.java
Arquivo normal
10
ym-admin/src/main/java/com/cnbm/admin/dao/SysLogLoginDao.java
Arquivo normal
@ -0,0 +1,10 @@
|
||||
package com.cnbm.admin.dao;
|
||||
|
||||
import com.cnbm.admin.entity.SysLogLoginEntity;
|
||||
import com.cnbm.common.dao.BaseDao;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysLogLoginDao extends BaseDao<SysLogLoginEntity> {
|
||||
|
||||
}
|
36
ym-admin/src/main/java/com/cnbm/admin/dto/SysLogLoginDTO.java
Arquivo normal
36
ym-admin/src/main/java/com/cnbm/admin/dto/SysLogLoginDTO.java
Arquivo normal
@ -0,0 +1,36 @@
|
||||
package com.cnbm.admin.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@ApiModel(value = "登录日志")
|
||||
public class SysLogLoginDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "id")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "用户操作 0:用户登录 1:用户退出")
|
||||
private Integer operation;
|
||||
|
||||
@ApiModelProperty(value = "状态 0:失败 1:成功 2:账号已锁定")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "用户代理")
|
||||
private String userAgent;
|
||||
|
||||
@ApiModelProperty(value = "操作IP")
|
||||
private String ip;
|
||||
|
||||
@ApiModelProperty(value = "用户名")
|
||||
private String creatorName;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createDate;
|
||||
|
||||
}
|
35
ym-admin/src/main/java/com/cnbm/admin/entity/SysLogLoginEntity.java
Arquivo normal
35
ym-admin/src/main/java/com/cnbm/admin/entity/SysLogLoginEntity.java
Arquivo normal
@ -0,0 +1,35 @@
|
||||
package com.cnbm.admin.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cnbm.common.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@TableName("sys_log_login")
|
||||
public class SysLogLoginEntity extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户操作 0:用户登录 1:用户退出
|
||||
*/
|
||||
private Integer operation;
|
||||
/**
|
||||
* 状态 0:失败 1:成功 2:账号已锁定
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 用户代理
|
||||
*/
|
||||
private String userAgent;
|
||||
/**
|
||||
* 操作IP
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String creatorName;
|
||||
|
||||
}
|
24
ym-admin/src/main/java/com/cnbm/admin/execl/SysLogLoginExcel.java
Arquivo normal
24
ym-admin/src/main/java/com/cnbm/admin/execl/SysLogLoginExcel.java
Arquivo normal
@ -0,0 +1,24 @@
|
||||
package com.cnbm.admin.execl;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class SysLogLoginExcel {
|
||||
@Excel(name = "用户操作")
|
||||
private String operation;
|
||||
@Excel(name = "状态", replace = {"失败_0", "成功_1", "账号已锁定_1"})
|
||||
private Integer status;
|
||||
@Excel(name = "User-Agent")
|
||||
private String userAgent;
|
||||
@Excel(name = "操作IP")
|
||||
private String ip;
|
||||
@Excel(name = "用户名")
|
||||
private String creatorName;
|
||||
@Excel(name = "创建时间", format = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createDate;
|
||||
|
||||
}
|
||||
|
18
ym-admin/src/main/java/com/cnbm/admin/service/SysLogLoginService.java
Arquivo normal
18
ym-admin/src/main/java/com/cnbm/admin/service/SysLogLoginService.java
Arquivo normal
@ -0,0 +1,18 @@
|
||||
package com.cnbm.admin.service;
|
||||
|
||||
import com.cnbm.admin.dto.SysLogLoginDTO;
|
||||
import com.cnbm.admin.entity.SysLogLoginEntity;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.service.BaseService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface SysLogLoginService extends BaseService<SysLogLoginEntity> {
|
||||
|
||||
PageData<SysLogLoginDTO> page(Map<String, Object> params);
|
||||
|
||||
List<SysLogLoginDTO> list(Map<String, Object> params);
|
||||
|
||||
void save(SysLogLoginEntity entity);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.cnbm.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cnbm.admin.dao.SysLogLoginDao;
|
||||
import com.cnbm.admin.dto.SysLogLoginDTO;
|
||||
import com.cnbm.admin.entity.SysLogLoginEntity;
|
||||
import com.cnbm.admin.service.SysLogLoginService;
|
||||
import com.cnbm.common.constant.Constant;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.service.impl.BaseServiceImpl;
|
||||
import com.cnbm.common.utils.ConvertUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SysLogLoginServiceImpl extends BaseServiceImpl<SysLogLoginDao, SysLogLoginEntity> implements SysLogLoginService {
|
||||
|
||||
@Override
|
||||
public PageData<SysLogLoginDTO> page(Map<String, Object> params) {
|
||||
IPage<SysLogLoginEntity> page = baseDao.selectPage(
|
||||
getPage(params, Constant.CREATE_DATE, false),
|
||||
getWrapper(params)
|
||||
);
|
||||
|
||||
return getPageData(page, SysLogLoginDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysLogLoginDTO> list(Map<String, Object> params) {
|
||||
List<SysLogLoginEntity> entityList = baseDao.selectList(getWrapper(params));
|
||||
|
||||
return ConvertUtils.sourceToTarget(entityList, SysLogLoginDTO.class);
|
||||
}
|
||||
|
||||
private QueryWrapper<SysLogLoginEntity> getWrapper(Map<String, Object> params){
|
||||
String status = (String) params.get("status");
|
||||
String creatorName = (String) params.get("creatorName");
|
||||
|
||||
QueryWrapper<SysLogLoginEntity> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(StringUtils.isNotBlank(status), "status", status);
|
||||
wrapper.like(StringUtils.isNotBlank(creatorName), "creator_name", creatorName);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(SysLogLoginEntity entity) {
|
||||
insert(entity);
|
||||
}
|
||||
|
||||
}
|
6
ym-admin/src/main/resources/mapper/SysLogLoginDao.xml
Arquivo normal
6
ym-admin/src/main/resources/mapper/SysLogLoginDao.xml
Arquivo normal
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="com.cnbm.admin.dao.SysLogLoginDao">
|
||||
|
||||
</mapper>
|
Carregando…
Referência em uma nova issue
Block a user