mirror of
https://gitee.com/lakernote/easy-admin.git
synced 2026-09-03 05:33:47 +08:00
(新增)[后端](增加登录验证码校验)
This commit is contained in:
15
README.md
15
README.md
@@ -2,11 +2,11 @@
|
||||
|
||||
#### 介绍
|
||||
|
||||
**easy**,**easy**,**easy**,打造一个**简单**、**轻量级**的**后台管理系统脚手架**。目前使用的技术都是相对较轻量级、上手很容易的技术。例如:**Spring Boot**、**hutool-all**、**mybatis-plus** 、**knife4j** 、**sa-token**、**javamelody** 、**snakerflow** 等。**后续的发展方向也是把目标对准中小型项目**,**提炼简单高效架构**。
|
||||
**easy**,**easy**,**easy**,打造一款**简单**、**轻量级**的**后台管理系统脚手架**。目前使用的技术都是相对较轻量级、上手很容易的技术。例如:**Spring Boot**、**hutool-all**、**mybatis-plus** 、**knife4j** 、**sa-token**、**javamelody** 、**snakerflow** 等。**后续的发展方向也是把目标对准中小型项目**,**提炼简单高效架构**。
|
||||
|
||||
**适合场景:**`学生学习`、`前后端项目练手`、`接私活快速开发`、`中小型企业脚手架`、`Spring Boot深度扩展学习`等
|
||||
**适合场景:学生学习、前后端项目练手、私活快速开发、中小型企业脚手架、Spring Boot深度扩展学习**等
|
||||
|
||||
项目架构灵活多变,内置前后端代码生成,可前后端分离,也可以一体化开发。
|
||||
**项目架构灵活多变**,**内置前后端代码生成**,**开发模式**支持**前后端分离**和**不分离**模式,**部署模式支持多种方式**:**Fat.jar模式**、**Nginx反向代理**、**Nginx正向代理**。
|
||||
|
||||
**项目地址**:[https://gitee.com/lakernote/easy-admin](https://gitee.com/lakernote/easy-admin)
|
||||
|
||||
@@ -21,7 +21,11 @@
|
||||
|
||||
#### 在线演示
|
||||
|
||||
暂时无服务器。。。尬住了
|
||||
**地址**:[http://101.132.189.23/admin/login.html](http://101.132.189.23/admin/login.html)
|
||||
|
||||
**用户名/密码**:laker/lakernote
|
||||
|
||||
> 当前处于开发阶段,由于我前端技术小白水平,开发进度较慢,还有很多功能未开发完成,有想一起开发的小伙伴,请加vx【**lakernote**】联系我。
|
||||
|
||||
#### 软件架构
|
||||
|
||||
@@ -216,4 +220,5 @@ web
|
||||
----login.html
|
||||
```
|
||||
|
||||
浏览器访问`http://ip:port/admin`
|
||||
浏览器访问`http://ip:port/admin`
|
||||
|
||||
|
||||
1
pom.xml
1
pom.xml
@@ -11,6 +11,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>easy-admin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<!-- web -->
|
||||
|
||||
6
run.sh
6
run.sh
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
AppName=ruoyi.jar
|
||||
AppName=easy-admin-1.0.0.jar
|
||||
|
||||
#JVM参数
|
||||
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
|
||||
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms100M -Xmx100M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
|
||||
APP_HOME=`pwd`
|
||||
LOG_PATH=$APP_HOME/logs/$AppName.log
|
||||
|
||||
@@ -26,7 +26,7 @@ function start()
|
||||
if [ x"$PID" != x"" ]; then
|
||||
echo "$AppName is running..."
|
||||
else
|
||||
nohup java -jar $JVM_OPTS $AppName > /dev/null 2>&1 &
|
||||
nohup java -jar $JVM_OPTS $AppName &
|
||||
echo "Start $AppName success..."
|
||||
fi
|
||||
}
|
||||
|
||||
14
src/main/java/com/laker/admin/framework/aop/Metrics.java
Normal file
14
src/main/java/com/laker/admin/framework/aop/Metrics.java
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
package com.laker.admin.framework.aop;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* @author laker
|
||||
*/
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Metrics {
|
||||
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.laker.admin.framework.aop;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.laker.admin.module.ext.entity.ExtLog;
|
||||
import com.laker.admin.module.ext.service.IExtLogService;
|
||||
import com.laker.admin.utils.http.HttpServletRequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@@ -15,37 +19,59 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Bean的优先级设置为最高
|
||||
*/
|
||||
@Aspect
|
||||
//@Component
|
||||
@Component
|
||||
@Slf4j
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class MetricsAspect {
|
||||
@Autowired
|
||||
ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
IExtLogService extLogService;
|
||||
|
||||
@Pointcut("@within(org.springframework.web.bind.annotation.RestController)")
|
||||
public void withAnnotationRestController() {
|
||||
@Pointcut("@annotation(Metrics) || @within(Metrics)")
|
||||
public void withAnnotationMetrics() {
|
||||
}
|
||||
|
||||
@Around("withAnnotationRestController()")
|
||||
@Around("withAnnotationMetrics()")
|
||||
public Object metrics(ProceedingJoinPoint pjp) throws Throwable {
|
||||
MethodSignature signature = (MethodSignature) pjp.getSignature();
|
||||
String name = signature.toShortString();
|
||||
Object returnValue;
|
||||
Instant start = Instant.now();
|
||||
ExtLog logBean = new ExtLog();
|
||||
logBean.setIp(HttpServletRequestUtil.getRemoteAddress());
|
||||
logBean.setUri(HttpServletRequestUtil.getRequestURI());
|
||||
logBean.setUserId(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null);
|
||||
logBean.setClient(HttpServletRequestUtil.getRequestUserAgent());
|
||||
logBean.setRequest(objectMapper.writeValueAsString(pjp.getArgs()));
|
||||
logBean.setMethod(name);
|
||||
logBean.setStatus(true);
|
||||
try {
|
||||
returnValue = pjp.proceed();
|
||||
} catch (Exception ex) {
|
||||
log.info("method:{},fail,cost:{}ms,uri:{},param:{}", name, Duration.between(start, Instant.now()).toMillis(), HttpServletRequestUtil.getRequestURI(), objectMapper.writeValueAsString(pjp.getArgs()));
|
||||
logBean.setCost((int) Duration.between(start, Instant.now()).toMillis());
|
||||
logBean.setCreateTime(LocalDateTime.now());
|
||||
logBean.setStatus(false);
|
||||
extLogService.save(logBean);
|
||||
log.error(name, ex);
|
||||
throw ex;
|
||||
|
||||
}
|
||||
log.info("method:{},success,cost:{}ms,uri:{},param:{},return:{}", name, Duration.between(start, Instant.now()).toMillis(), HttpServletRequestUtil.getRequestURI(), objectMapper.writeValueAsString(pjp.getArgs()), objectMapper.writeValueAsString(returnValue));
|
||||
String response = objectMapper.writeValueAsString(returnValue);
|
||||
log.info("method:{},success,cost:{}ms,uri:{},param:{},return:{}", name, Duration.between(start, Instant.now()).toMillis(), HttpServletRequestUtil.getRequestURI(), objectMapper.writeValueAsString(pjp.getArgs()), response);
|
||||
logBean.setCost((int) Duration.between(start, Instant.now()).toMillis());
|
||||
logBean.setCreateTime(LocalDateTime.now());
|
||||
if (StrUtil.isNotBlank(response) && response.length() <= 500) {
|
||||
logBean.setResponse(response);
|
||||
}
|
||||
extLogService.save(logBean);
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.laker.admin.module.ext.controller;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.framework.PageResponse;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.module.ext.entity.ExtLog;
|
||||
import com.laker.admin.module.ext.service.IExtLogService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/ext/log")
|
||||
@Metrics
|
||||
public class ExtLogController {
|
||||
@Autowired
|
||||
IExtLogService extLogService;
|
||||
@@ -29,9 +32,14 @@ public class ExtLogController {
|
||||
@GetMapping
|
||||
@ApiOperation(value = "日志分页查询")
|
||||
public PageResponse pageAll(@RequestParam(required = false, defaultValue = "1") long page,
|
||||
@RequestParam(required = false, defaultValue = "10") long limit) {
|
||||
@RequestParam(required = false, defaultValue = "10") long limit,
|
||||
String keyWord) {
|
||||
Page roadPage = new Page<>(page, limit);
|
||||
LambdaQueryWrapper<ExtLog> queryWrapper = new QueryWrapper().lambda();
|
||||
if (StrUtil.isNotBlank(keyWord)) {
|
||||
queryWrapper.like(ExtLog::getRequest, keyWord);
|
||||
}
|
||||
queryWrapper.orderByDesc(ExtLog::getCreateTime);
|
||||
Page pageList = extLogService.page(roadPage, queryWrapper);
|
||||
return PageResponse.ok(pageList.getRecords(), pageList.getTotal());
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ package com.laker.admin.module.ext.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 日志
|
||||
@@ -41,6 +43,8 @@ public class ExtLog implements Serializable {
|
||||
* 浏览器或者app信息
|
||||
*/
|
||||
private String client;
|
||||
private String uri;
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 请求
|
||||
@@ -52,6 +56,8 @@ public class ExtLog implements Serializable {
|
||||
*/
|
||||
private String response;
|
||||
|
||||
private Boolean status;
|
||||
|
||||
/**
|
||||
* 耗时ms
|
||||
*/
|
||||
@@ -60,6 +66,7 @@ public class ExtLog implements Serializable {
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.laker.admin.framework.PageResponse;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -42,6 +43,7 @@ public class SnakerflowFacetsController {
|
||||
|
||||
@GetMapping("/process/modelJson")
|
||||
@ApiOperation(value = "根据流程定义名称获取流程定义json", tags = "流程引擎-流程")
|
||||
@Metrics
|
||||
public String getProcess(@RequestParam(required = false) String processId) {
|
||||
if (StrUtil.isBlank(processId)) {
|
||||
return "";
|
||||
@@ -80,6 +82,7 @@ public class SnakerflowFacetsController {
|
||||
*/
|
||||
@ApiOperation(value = "根据流程定义ID,删除流程定义", tags = "流程引擎-流程")
|
||||
@RequestMapping(value = "/process/delete/{id}", method = RequestMethod.GET)
|
||||
@Metrics
|
||||
public Response processDelete(@PathVariable("id") String id) {
|
||||
snakerEngineFacets.getEngine().process().undeploy(id);
|
||||
return Response.ok();
|
||||
@@ -121,6 +124,7 @@ public class SnakerflowFacetsController {
|
||||
|
||||
@ApiOperation(value = "流程定义+流程状态", tags = "流程引擎-流程")
|
||||
@RequestMapping(value = "/process/json", method = RequestMethod.GET)
|
||||
@Metrics
|
||||
public Object json(String processId, String orderId) {
|
||||
Process process = snakerEngineFacets.getEngine().process().getProcessById(processId);
|
||||
AssertHelper.notNull(process);
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.laker.admin.module.sys.controller;
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.framework.cache.ICache;
|
||||
import com.laker.admin.module.sys.entity.SysUser;
|
||||
import com.laker.admin.module.sys.service.ISysUserService;
|
||||
@@ -14,6 +16,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -23,6 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@ApiSupport(order = 2)
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Metrics
|
||||
public class LoginController {
|
||||
|
||||
@Autowired
|
||||
@@ -33,7 +37,7 @@ public class LoginController {
|
||||
@PostMapping("/api/v1/login")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "登录")
|
||||
public Response login(@RequestBody LoginDto loginDto) {
|
||||
public Response login(@Validated @RequestBody LoginDto loginDto) {
|
||||
log.info("login {}", loginDto);
|
||||
// 验证码是否正确
|
||||
String code = iCache.get(loginDto.getUid());
|
||||
@@ -43,7 +47,7 @@ public class LoginController {
|
||||
// 单机版:在map中创建了会话,token id等映射关系 // 写入cookie
|
||||
SysUser sysUser = sysUserService.getOne(Wrappers.<SysUser>lambdaQuery()
|
||||
.eq(SysUser::getUserName, loginDto.getUsername())
|
||||
.eq(SysUser::getPassword, loginDto.getPassword()));
|
||||
.eq(SysUser::getPassword, SecureUtil.sha256(loginDto.getPassword())));
|
||||
if (sysUser == null) {
|
||||
return Response.error("5001", "用户名或密码不正确");
|
||||
}
|
||||
|
||||
@@ -2,14 +2,19 @@ package com.laker.admin.module.sys.controller;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @author laker
|
||||
*/
|
||||
@Data
|
||||
public class LoginDto {
|
||||
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
private String username;
|
||||
@NotBlank(message = "密码不能为空")
|
||||
private String password;
|
||||
@NotBlank(message = "验证码不能为空")
|
||||
private String captchaCode;
|
||||
@NotBlank(message = "验证码Id不能为空")
|
||||
private String uid;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.ResultTable;
|
||||
import com.laker.admin.framework.ResultTree;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.module.sys.entity.SysDept;
|
||||
import com.laker.admin.module.sys.service.ISysDeptService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/dept")
|
||||
@Metrics
|
||||
public class SysDeptController {
|
||||
@Autowired
|
||||
ISysDeptService sysDeptService;
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.framework.PageResponse;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.module.sys.entity.SysDict;
|
||||
import com.laker.admin.module.sys.service.ISysDictService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -22,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/dict")
|
||||
@Metrics
|
||||
public class SysDictController {
|
||||
@Autowired
|
||||
ISysDictService sysDictService;
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.module.sys.entity.SysMenu;
|
||||
import com.laker.admin.module.sys.pojo.MenuVo;
|
||||
import com.laker.admin.module.sys.service.ISysMenuService;
|
||||
@@ -24,6 +25,7 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/menu")
|
||||
@Metrics
|
||||
public class SysMenuController {
|
||||
@Autowired
|
||||
ISysMenuService sysMenuService;
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.framework.PageResponse;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.ResultTree;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.module.sys.entity.SysMenu;
|
||||
import com.laker.admin.module.sys.entity.SysRole;
|
||||
import com.laker.admin.module.sys.entity.SysRolePower;
|
||||
@@ -31,6 +32,7 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/role")
|
||||
@Metrics
|
||||
public class SysRoleController {
|
||||
@Autowired
|
||||
ISysRoleService sysRoleService;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.laker.admin.module.sys.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.laker.admin.framework.PageResponse;
|
||||
import com.laker.admin.framework.Response;
|
||||
import com.laker.admin.framework.aop.Metrics;
|
||||
import com.laker.admin.module.sys.entity.SysRole;
|
||||
import com.laker.admin.module.sys.entity.SysUser;
|
||||
import com.laker.admin.module.sys.entity.SysUserRole;
|
||||
@@ -33,6 +36,7 @@ import java.util.List;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/user")
|
||||
@Metrics
|
||||
public class SysUserController {
|
||||
@Autowired
|
||||
ISysUserService sysUserService;
|
||||
@@ -64,6 +68,12 @@ public class SysUserController {
|
||||
public Response saveOrUpdate(@RequestBody SysUser param) {
|
||||
|
||||
if (param.getUserId() == null) {
|
||||
// 只有超级管理员才能创建用户
|
||||
if (StpUtil.getLoginIdAsLong() != 1L) {
|
||||
return Response.error("403", "只有超级管理员才能创建用户!");
|
||||
}
|
||||
String password = param.getPassword();
|
||||
param.setPassword(SecureUtil.sha256(password));
|
||||
param.setCreateTime(LocalDateTime.now());
|
||||
sysUserService.save(param);
|
||||
if (StrUtil.isNotBlank(param.getRoleIds())) {
|
||||
|
||||
@@ -9,10 +9,11 @@ import org.springframework.boot.logging.LoggerGroups;
|
||||
import org.springframework.boot.logging.LoggingSystem;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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 org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -24,7 +25,7 @@ import java.io.File;
|
||||
* @author laker
|
||||
* @since 2021-08-05
|
||||
*/
|
||||
@RestController
|
||||
@Controller
|
||||
@RequestMapping("/sys/weblog")
|
||||
public class WebLogController {
|
||||
@Autowired
|
||||
@@ -36,6 +37,7 @@ public class WebLogController {
|
||||
|
||||
|
||||
@GetMapping(value = "/file", produces = "text/plain; charset=UTF-8")
|
||||
@ResponseBody
|
||||
public Resource logFile(@RequestParam(required = false) String filePath) {
|
||||
String lookFilePath = lakerConfig.getLogFilePath();
|
||||
if (StrUtil.isNotBlank(filePath)) {
|
||||
@@ -49,6 +51,7 @@ public class WebLogController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/level") //动态设置日志级别
|
||||
@ResponseBody
|
||||
public String configureLogLevel(String name, LogLevel configuredLevel) {
|
||||
if (StrUtil.isBlank(name)) {
|
||||
return "请输入日志名称";
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
List<Long> roleIds = userRoles.stream().map(sysUserRole -> sysUserRole.getRoleId()).collect(Collectors.toList());
|
||||
List<SysRolePower> rolePowerLists = sysRolePowerService.list(Wrappers.<SysRolePower>lambdaQuery().in(SysRolePower::getRoleId, roleIds));
|
||||
List<Long> powerIds = rolePowerLists.stream().map(sysRolePower -> sysRolePower.getPowerId()).collect(Collectors.toList());
|
||||
return menuService.list(Wrappers.<SysMenu>lambdaQuery().in(SysMenu::getMenuId, powerIds).eq(SysMenu::getEnable, true).orderByDesc(SysMenu::getSort));
|
||||
return menuService.list(Wrappers.<SysMenu>lambdaQuery().in(SysMenu::getMenuId, powerIds).eq(SysMenu::getEnable, true).orderByAsc(SysMenu::getSort));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.laker.admin.utils.http;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -46,6 +49,18 @@ public class HttpServletRequestUtil {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取getRequestURI
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getRequestUserAgent() {
|
||||
HttpServletRequest request = getRequest();
|
||||
UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||
return JSONUtil.toJsonStr(userAgent);
|
||||
|
||||
}
|
||||
|
||||
public static String getRemoteAddress() {
|
||||
HttpServletRequest request = getRequest();
|
||||
if (request == null) {
|
||||
|
||||
@@ -22,12 +22,6 @@ spring:
|
||||
thread-name-prefix: laker-
|
||||
freemarker:
|
||||
suffix: .ftl
|
||||
logging:
|
||||
file:
|
||||
max-size: 10MB
|
||||
max-history: 50
|
||||
name: laker.log
|
||||
path: ./
|
||||
mybatis-plus:
|
||||
type-aliases-package: org.snaker.engine.entity
|
||||
knife4j:
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<property name="LOG_HOME" value="logs"/>
|
||||
<property name="encoding" value="UTF-8"/>
|
||||
<property name="ENCODING" value="UTF-8"/>
|
||||
|
||||
<appender name="DEFAULT" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<!-- 正在记录的日志文件的路径及文件名 -->
|
||||
<file>${LOG_HOME}/laker.log</file>
|
||||
<Append>true</Append>
|
||||
<prudent>false</prudent>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--日志打印的格式-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{50} %line - %m%n</pattern>
|
||||
<!--编码格式-->
|
||||
<charset>${ENCODING}</charset>
|
||||
</encoder>
|
||||
<!-- 按天回滚 daily -->
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!--归档日志文件名-->
|
||||
<FileNamePattern>${LOG_HOME}/test.log.%d{yyyy-MM-dd}</FileNamePattern>
|
||||
<!-- 最多保存15天历史文件 -->
|
||||
<!-- 每天日志归档路径以及格式 -->
|
||||
<FileNamePattern>${LOG_HOME}/laker-%d{yyyy-MM-dd}-%i.log</FileNamePattern>
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--日志量最大20GB-->
|
||||
<totalSizeCap>20GB</totalSizeCap>
|
||||
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||
<!--超过10MB就切分日志-->
|
||||
<maxFileSize>10MB</maxFileSize>
|
||||
</timeBasedFileNamingAndTriggeringPolicy>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
|
||||
11
src/test/java/com/laker/admin/service/Test.java
Normal file
11
src/test/java/com/laker/admin/service/Test.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.laker.admin.service;
|
||||
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String s = SecureUtil.sha256("lakernote");
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
@@ -68,49 +68,52 @@
|
||||
title: '用户id',
|
||||
field: 'userId',
|
||||
align: 'center',
|
||||
width: 120
|
||||
width: 80
|
||||
},
|
||||
{
|
||||
title: 'ip地址',
|
||||
title: '请求IP',
|
||||
field: 'ip',
|
||||
align: 'center',
|
||||
width: 120
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
title: '浏览器或者app信息',
|
||||
field: 'client',
|
||||
align: 'center',
|
||||
width: 120
|
||||
title: '请求方法',
|
||||
field: 'method',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '请求',
|
||||
title: '请求URI',
|
||||
field: 'uri',
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '请求内容',
|
||||
field: 'request',
|
||||
align: 'center',
|
||||
width: 120
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
title: '响应',
|
||||
title: '响应内容',
|
||||
field: 'response',
|
||||
align: 'center',
|
||||
width: 120
|
||||
width: 150
|
||||
},
|
||||
{
|
||||
title: '耗时ms',
|
||||
field: 'cost',
|
||||
align: 'center',
|
||||
width: 120
|
||||
width: 80
|
||||
},
|
||||
{
|
||||
title: 'Client信息',
|
||||
field: 'client',
|
||||
align: 'center',
|
||||
width: 80
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
field: 'createTime',
|
||||
align: 'center',
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
toolbar: '#record-toolbar',
|
||||
align: 'center',
|
||||
width: 180
|
||||
width: 150
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -121,7 +124,9 @@
|
||||
let uri = "/ext/" + module;
|
||||
easyAdmin.tableRender({
|
||||
url: uri,
|
||||
cols: cols
|
||||
cols: cols,
|
||||
toolbar: null,
|
||||
defaultToolbar: null
|
||||
});
|
||||
easyAdmin.TableTool(uri, module);
|
||||
easyAdmin.TableToolBar(uri, module);
|
||||
|
||||
@@ -31,13 +31,6 @@
|
||||
placeholder="请输入标题" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">密码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="password" value="*******" lay-verify="title" autocomplete="off"
|
||||
placeholder="请输入标题" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">电话</label>
|
||||
<div class="layui-input-block">
|
||||
|
||||
Reference in New Issue
Block a user