diff --git a/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogLoginController.java b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogLoginController.java new file mode 100644 index 0000000..95cf2a1 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/controller/SysLogLoginController.java @@ -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> page(@ApiIgnore @RequestParam Map params){ + PageData page = sysLogLoginService.page(params); + + return new Result>().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 params, HttpServletResponse response) throws Exception { + List list = sysLogLoginService.list(params); + + ExcelUtils.exportExcelToTarget(response, null, list, SysLogLoginExcel.class); + } + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogLoginDao.java b/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogLoginDao.java new file mode 100644 index 0000000..c4a9ddb --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dao/SysLogLoginDao.java @@ -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 { + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogLoginDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogLoginDTO.java new file mode 100644 index 0000000..c52d0c4 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/SysLogLoginDTO.java @@ -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; + +} diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogLoginEntity.java b/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogLoginEntity.java new file mode 100644 index 0000000..45b6848 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/SysLogLoginEntity.java @@ -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; + +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogLoginExcel.java b/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogLoginExcel.java new file mode 100644 index 0000000..8230aa2 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/execl/SysLogLoginExcel.java @@ -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; + +} + diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/SysLogLoginService.java b/ym-admin/src/main/java/com/cnbm/admin/service/SysLogLoginService.java new file mode 100644 index 0000000..2fec755 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/SysLogLoginService.java @@ -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 { + + PageData page(Map params); + + List list(Map params); + + void save(SysLogLoginEntity entity); +} \ No newline at end of file diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogLoginServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogLoginServiceImpl.java new file mode 100644 index 0000000..21db772 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/SysLogLoginServiceImpl.java @@ -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 implements SysLogLoginService { + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, Constant.CREATE_DATE, false), + getWrapper(params) + ); + + return getPageData(page, SysLogLoginDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.selectList(getWrapper(params)); + + return ConvertUtils.sourceToTarget(entityList, SysLogLoginDTO.class); + } + + private QueryWrapper getWrapper(Map params){ + String status = (String) params.get("status"); + String creatorName = (String) params.get("creatorName"); + + QueryWrapper 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); + } + +} diff --git a/ym-admin/src/main/resources/mapper/SysLogLoginDao.xml b/ym-admin/src/main/resources/mapper/SysLogLoginDao.xml new file mode 100644 index 0000000..587044e --- /dev/null +++ b/ym-admin/src/main/resources/mapper/SysLogLoginDao.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file