diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/annotation/Log.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/annotation/Log.java new file mode 100644 index 00000000..f52cfb17 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/annotation/Log.java @@ -0,0 +1,42 @@ +package com.daqing.financial.hrauth.annotation; + + +import com.daqing.financial.hrauth.enums.OperationType; +import com.daqing.financial.hrauth.enums.OperationUnit; + +import java.lang.annotation.*; + +/** + * @author Rogers + * 操作日志注解 + * @create 2020-07-03 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Log { + + /** + * 方法描述,可使用占位符获取参数:{{tel}} + */ + String detail() default ""; + + /** + * 日志等级:自己定,此处分为1-9 + */ + int level() default 0; + + /** + * 操作类型(enum):主要是select,insert,update,delete + */ + OperationType operationType() default OperationType.UNKNOWN; + + /** + * 被操作的对象(此处使用enum):可以是任何对象,如表名(user),或者是工具(redis) + */ + OperationUnit operationUnit() default OperationUnit.UNKNOWN; + + +} + + diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/aspect/Operation.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/aspect/Operation.java new file mode 100644 index 00000000..3ffb2533 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/aspect/Operation.java @@ -0,0 +1,124 @@ +package com.daqing.financial.hrauth.aspect; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.daqing.financial.hrauth.annotation.Log; +import com.daqing.financial.hrauth.dao.SystemLogMapper; +import com.daqing.financial.hrauth.service.TokenService; +import com.daqing.financial.hrauth.service.UserLoginService; +import com.daqing.financial.hrauth.util.IpUtils; +import com.daqing.framework.domain.hrms.SystemLog; +import com.daqing.framework.domain.hrms.Token; +import com.daqing.framework.domain.hrms.UserEntity; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @ClassName Operation + * @Description 操作日志类 + * @Date 2020/9/29 10:06 + * @Version 1.0 + */ +@Slf4j +@Component +public class Operation { + + @Resource + private SystemLogMapper systemLogMapper; + @Autowired + private TokenService tokenService; + @Autowired + private UserLoginService userLoginService; + @Async + public void addOperationLog(JoinPoint joinPoint, Object res, long time, UserEntity systemUser) { +// synchronized (SysLogAspect.class) {//获得登录用户信息 +// User systemUser = (User) SecurityUtils.getSubject().getPrincipal(); + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + SystemLog operationLog = new SystemLog(); + //获取内网地址IpUtils.intranetIp() + //获取外网地址IpUtils.internetIp() +// operationLog.setIpAddressLan(""); +// operationLog.setIpAddressWan(""); + operationLog.setIpAddressLan(IpUtils.intranetIp()); + //获取不到外网IP设置内网IP + if (StringUtils.isBlank(IpUtils.internetIp())) { + operationLog.setIpAddressWan(IpUtils.intranetIp()); + } else { + operationLog.setIpAddressWan(IpUtils.internetIp()); + } +// operationLog.setRunTime(time); + //operationLog.setRunTime(0L); + operationLog.setReturnValue(JSONObject.toJSONString(res)); + operationLog.setId(UUID.randomUUID().toString()); + operationLog.setArgs(JSONObject.toJSONString(joinPoint.getArgs())); + operationLog.setCreateTime(new Date()); + operationLog.setMethod(signature.getDeclaringTypeName() + "." + signature.getName()); + operationLog.setUserId(systemUser.getId() + ""); + operationLog.setUserName(systemUser.getAccount()); + Log annotation = signature.getMethod().getAnnotation(Log.class); + if (annotation != null) { + operationLog.setLogLevel(annotation.level()); + operationLog.setLogDescribe(getDetail(((MethodSignature) joinPoint.getSignature()).getParameterNames(), joinPoint.getArgs(), annotation)); + operationLog.setOperationType(annotation.operationType().getValue()); + operationLog.setOperationUnit(annotation.operationUnit().getValue()); + } + + //这里保存日志 +// log.info("######记录日志:{}######", operationLog.toString()); + int b = systemLogMapper.insert(operationLog); + log.info("######记录日志:{}######", operationLog.toString()); + if (b<= 0) { + log.error("#####新增###记录日志失败:{}####", operationLog); + } +// } + } + + /** + * 对当前登录用户和占位符处理 + * + * @param argNames 方法参数名称数组 + * @param args 方法参数数组 + * @param annotation 注解信息 + * @return 返回处理后的描述 + */ + private String getDetail(String[] argNames, Object[] args, Log annotation) { + //获得登录用户信息 + //User systemUser = (User) SecurityUtils.getSubject().getPrincipal(); + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + String token = request.getHeader("token"); + Token userToken = tokenService.getOne(new QueryWrapper().eq("token", token)); + UserEntity systemUser = userLoginService.getOne(new QueryWrapper().eq("id",userToken.getUserId())); + + Map map = new HashMap<>(4); + for (int i = 0; i < argNames.length; i++) { + map.put(argNames[i], args[i]); + } + + String detail = annotation.detail(); + try { + detail = "'" + systemUser.getAccount() + "'=》" + annotation.detail(); + for (Map.Entry entry : map.entrySet()) { + Object k = entry.getKey(); + Object v = entry.getValue(); + detail = detail.replace("{{" + k + "}}", JSONObject.toJSONString(v)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return detail; + } +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/aspect/SysLogAspect.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/aspect/SysLogAspect.java new file mode 100644 index 00000000..4601ad31 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/aspect/SysLogAspect.java @@ -0,0 +1,178 @@ +package com.daqing.financial.hrauth.aspect; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.daqing.financial.hrauth.annotation.Log; +import com.daqing.financial.hrauth.service.TokenService; +import com.daqing.financial.hrauth.service.UserLoginService; +import com.daqing.framework.domain.hrms.Token; +import com.daqing.framework.domain.hrms.UserEntity; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName actionLogAspect + * @Description 操作日志切面 + * @Author Rogers + * @Date 2020/7/3 23:24 + * @Version 1.0 + */ +@Slf4j +@Aspect +@Component +public class SysLogAspect { +/* @Resource + private ISystemLogService logService; + @Resource + private SystemLogMapper systemLogMapper;*/ + + @Resource + private Operation operation; + @Autowired + private TokenService tokenService; + @Autowired + private UserLoginService userLoginService; + /** + * 此处的切点是注解的方式,也可以用包名的方式达到相同的效果 + * '@Pointcut("execution(* com.wwj.springboot.service.impl.*.*(..))")' + */ + @Pointcut("@annotation(com.daqing.financial.hrauth.annotation.Log)") + public void operationLog() { + } + + + /** + * 环绕增强,相当于MethodInterceptor + */ + @Around("operationLog()") + public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { + Object res = null; + long time = System.currentTimeMillis(); + try { + res = joinPoint.proceed(); + time = System.currentTimeMillis() - time; + return res; + } finally { + try { + //User systemUser = (User) SecurityUtils.getSubject().getPrincipal(); + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + String token = request.getHeader("token"); + Token userToken = tokenService.getOne(new QueryWrapper().eq("token", token)); + UserEntity systemUser = userLoginService.getOne(new QueryWrapper().eq("id",userToken.getUserId())); + operation.addOperationLog(joinPoint,res,time,systemUser); + //方法执行完成后增加日志 +// addOperationLog(joinPoint, res, time); + } catch (Exception e) { + log.error("LogAspect 操作失败:" + e.getMessage()); + e.printStackTrace(); + } + } + } + + + /** + * 对当前登录用户和占位符处理 + * + * @param argNames 方法参数名称数组 + * @param args 方法参数数组 + * @param annotation 注解信息 + * @return 返回处理后的描述 + */ + private String getDetail(String[] argNames, Object[] args, Log annotation) { + //获得登录用户信息 + //User systemUser = (User) SecurityUtils.getSubject().getPrincipal(); + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + UserEntity systemUser = (UserEntity) request.getUserPrincipal(); + + Map map = new HashMap<>(4); + for (int i = 0; i < argNames.length; i++) { + map.put(argNames[i], args[i]); + } + + String detail = annotation.detail(); + try { + detail = "'" + systemUser.getAccount() + "'=》" + annotation.detail(); + for (Map.Entry entry : map.entrySet()) { + Object k = entry.getKey(); + Object v = entry.getValue(); + detail = detail.replace("{{" + k + "}}", JSONObject.toJSONString(v)); + } + } catch (Exception e) { + e.printStackTrace(); + } + return detail; + } + + @Before("operationLog()") + public void doBeforeAdvice(JoinPoint joinPoint) { +// System.out.println("进入方法前执行....."); + } + + /** + * 处理完请求,返回内容 + * + * @param ret + */ + @AfterReturning(returning = "ret", pointcut = "operationLog()") + public void doAfterReturning(Object ret) { +// System.out.println("方法的返回值 : " + ret); + } + + /** + * 后置异常通知 + */ + @AfterThrowing("operationLog()") + public void throwss(JoinPoint jp) { +// System.out.println("方法异常时执行....."); + } + + + /** + * 后置最终通知,final增强,不管是抛出异常或者正常退出都会执行 + */ + @After("operationLog()") + public void after(JoinPoint jp) { +// System.out.println("方法最后执行....."); + } + + + /** + * 获取客户端ip地址 + * + * @param request + * @return + */ + public static String getClientIp(HttpServletRequest request) { + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.trim() == "" || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.trim() == "" || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.trim() == "" || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + // 多个路由时,取第一个非unknown的ip + final String[] arr = ip.split(","); + for (final String str : arr) { + if (!"unknown".equalsIgnoreCase(str)) { + ip = str; + break; + } + } + return ip; + } + +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java index 195035db..6d907167 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/UserLoginController.java @@ -53,6 +53,7 @@ public class UserLoginController implements UserLoginControllerApi { @PostMapping(value = "/login") @ApiOperation(value = "用户登录") + /*@SysLog(MODULE = "登录日志", REMARK = "登录日志")*/ public ResponseResult login( @RequestBody LoginRequest loginRequest /* @RequestParam("password") String password, @RequestParam("phone") String phone, diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/SystemLogMapper.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/SystemLogMapper.java new file mode 100644 index 00000000..6a7c9e30 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/SystemLogMapper.java @@ -0,0 +1,18 @@ +package com.daqing.financial.hrauth.dao; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.daqing.framework.domain.hrms.SystemLog; +import org.apache.ibatis.annotations.Mapper; + +/** + * @ClassName UserActionMapper + * @Description 用户动作记录 + * @Author Rogers + * @Date 2020/7/3 22:08 + * @Version 1.0 + */ +@Mapper +public interface SystemLogMapper extends BaseMapper { +} + diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/BusinessType.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/BusinessType.java new file mode 100644 index 00000000..d93e0528 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/BusinessType.java @@ -0,0 +1,66 @@ +package com.daqing.financial.hrauth.enums; + +/** + * 日志操作类型 + */ +public enum BusinessType +{ + /** + * 其它 + */ + OTHER, + /** + * 新增 + */ + INSERT, + /** + * 修改 + */ + UPDATE, + /** + * 删除 + */ + DELETE, + /** + * 查询 + */ + SELECT, + /** + * 导出 + */ + EXPORT, + /** + * 导入 + */ + IMPORT; + + public static String getMsg(BusinessType type){ + String result = null; + switch (type) { + case INSERT: + result = "新增"; + break; + case UPDATE: + result = "修改"; + break; + case DELETE: + result = "删除"; + break; + case SELECT: + result = "查询"; + break; + case EXPORT: + result = "导出"; + break; + case IMPORT: + result = "导入"; + break; + case OTHER: + result = "其它"; + break; + default: + break; + } + return result; + } +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/OperationType.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/OperationType.java new file mode 100644 index 00000000..0444d8a5 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/OperationType.java @@ -0,0 +1,52 @@ +package com.daqing.financial.hrauth.enums; + +public enum OperationType { + + /** + * 操作类型 + */ + UNKNOWN("UNKNOWN"), + DELETE("DELETE"), + SELECT("SELECT"), + UPDATE("UPDATE"), + INSERT("INSERT"); + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + OperationType(String s) { + this.value = s; + } + + + public static String getMsg(BusinessType type){ + String result = null; + switch (type) { + case INSERT: + result = "新增"; + break; + case UPDATE: + result = "修改"; + break; + case DELETE: + result = "删除"; + break; + case SELECT: + result = "查询"; + break; + case OTHER: + result = "其它"; + break; + default: + break; + } + return result; + } +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/OperationUnit.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/OperationUnit.java new file mode 100644 index 00000000..ab911055 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/enums/OperationUnit.java @@ -0,0 +1,37 @@ +package com.daqing.financial.hrauth.enums; + +public enum OperationUnit { + /** + * 被操作的单元 + */ + UNKNOWN("unknown"), + USER("user"), + LOG("log"), + PERMISSION("permission"), + ROLE("role"), + DEVICE("device"), + WITHDRAW("withdraw"), + ATRUSER("atrUser"), + ASSERT("ASSERT"), + COIN("coin"), + NOTICE("notice"), + DATASTATISTIC("datastatistic"), + BlockGroup("blockGroup"), + C2C("c2c"), + USERROLE("userRole"); + + private String value; + + OperationUnit(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/IpUtils.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/IpUtils.java new file mode 100644 index 00000000..f663abee --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/util/IpUtils.java @@ -0,0 +1,68 @@ +package com.daqing.financial.hrauth.util; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; + +/** + * @ClassName IpUtils + * @Description Ip工具类,获取ip + * @Author Rogers + * @Date 2020/7/4 14:36 + * @Version 1.0 + */ +public class IpUtils { + /*** + * 获取外网IP + * @return + */ + public static String internetIp() { + try { + + Enumeration networks = NetworkInterface.getNetworkInterfaces(); + InetAddress inetAddress = null; + Enumeration inetAddresses = null; + while (networks.hasMoreElements()) { + inetAddresses = networks.nextElement().getInetAddresses(); + while (inetAddresses.hasMoreElements()) { + inetAddress = inetAddresses.nextElement(); + if (inetAddress != null + && inetAddress instanceof Inet4Address + && !inetAddress.isSiteLocalAddress() + && !inetAddress.isLoopbackAddress() + && inetAddress.getHostAddress().indexOf(":") == -1) { + return inetAddress.getHostAddress(); + } + } + } + + return null; + + } catch (Exception e) { + + throw new RuntimeException(e); + } + } + + /** + * 获取内网IP + * + * @return + */ + public static String intranetIp() { + try { + return InetAddress.getLocalHost().getHostAddress(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * 获取服务启动host + * @return + */ + public static String getHost(){ + return internetIp()==null?intranetIp():internetIp(); + } +} diff --git a/dq-financial-hrms/pom.xml b/dq-financial-hrms/pom.xml index 5543ca6f..cc81ef92 100644 --- a/dq-financial-hrms/pom.xml +++ b/dq-financial-hrms/pom.xml @@ -62,11 +62,17 @@ - + + + com.daqing.financial + dq-financial-hrms-auth + 0.0.1-SNAPSHOT + compile diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java index a4f13137..5e02d068 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java @@ -1,5 +1,8 @@ package com.daqing.financial.hrms.controller; +import com.daqing.financial.hrauth.annotation.Log; +import com.daqing.financial.hrauth.enums.OperationType; +import com.daqing.financial.hrauth.enums.OperationUnit; import com.daqing.financial.hrms.EmployeeControllerApi; import com.daqing.financial.hrms.service.EmployeeService; import com.daqing.framework.domain.hrms.EmployeeEntity; @@ -30,6 +33,7 @@ public class EmployeeController implements EmployeeControllerApi { private EmployeeService employeeService; @GetMapping("/list") + @Log(detail = "员工列表",level = 3,operationUnit = OperationUnit.ROLE,operationType = OperationType.INSERT) //@RequiresPermissions("hrms:employee:info") public ResponseResult list(@RequestParam("page") Integer page, @RequestParam("size") Integer size, diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java index a2545da2..a1a82215 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/UserController.java @@ -5,9 +5,6 @@ import com.daqing.framework.domain.hrms.UserEntity; import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.Authentication; -import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; import org.springframework.web.bind.annotation.*; import java.util.Arrays; @@ -88,7 +85,7 @@ public class UserController { * @param authentication * @return */ - @GetMapping(value = "get") +/* @GetMapping(value = "get") @PreAuthorize("hasAnyRole('ROLE_ADMIN')") public Object get(Authentication authentication){ //Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); @@ -96,5 +93,5 @@ public class UserController { OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)authentication.getDetails(); String token = details.getTokenValue(); return token; - } + }*/ } diff --git a/dq-financial-hrms/src/main/resources/application.yml b/dq-financial-hrms/src/main/resources/application.yml new file mode 100644 index 00000000..30e77ef2 --- /dev/null +++ b/dq-financial-hrms/src/main/resources/application.yml @@ -0,0 +1,12 @@ +#security: +# oauth2: +# client: +# client-id: user-client +# client-secret: user-secret-8888 +# user-authorization-uri: http://localhost:7000/oauth/authorize +# access-token-uri: http://localhost:7000/oauth/token +# resource: +# id: user-client +# user-info-uri: user-info +# authorization: +# check-token-access: http://localhost:7000/oauth/check_token \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/bootstrap.properties b/dq-financial-hrms/src/main/resources/bootstrap.properties index d1c6bdec..b5a7eb56 100644 --- a/dq-financial-hrms/src/main/resources/bootstrap.properties +++ b/dq-financial-hrms/src/main/resources/bootstrap.properties @@ -15,4 +15,14 @@ spring.cloud.nacos.config.ext-config[1].refresh=true spring.cloud.nacos.config.ext-config[2].data-id=other.yml spring.cloud.nacos.config.ext-config[2].group=dev -spring.cloud.nacos.config.ext-config[2].refresh=true \ No newline at end of file +spring.cloud.nacos.config.ext-config[2].refresh=true + +#spring.redis.host=127.0.0.1 +#spring.redis.port=6379 +#spring.redis.password=123456 +#spring.redis.database=0 +#spring.redis.timeout=30000 +#spring.redis.jedis.pool.max-active=8 +#spring.redis.jedis.pool.max-wait=-1 +#spring.redis.jedis.pool.max-idle=8 +#spring.redis.jedis.pool.min-idle=0 \ No newline at end of file diff --git a/dq-framework-common/pom.xml b/dq-framework-common/pom.xml index 9d7931c5..92927a4f 100644 --- a/dq-framework-common/pom.xml +++ b/dq-framework-common/pom.xml @@ -143,6 +143,7 @@ 1.1.0 + diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/SystemLog.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/SystemLog.java new file mode 100644 index 00000000..db75a110 --- /dev/null +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/SystemLog.java @@ -0,0 +1,102 @@ +package com.daqing.framework.domain.hrms; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +/** + * @ClassName SystemLog + * @Description 操作日志 + * @Date 2020/9/29 14:30 + * @Version 1.0 + */ + +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Data +@TableName("sys_action_log") +@ApiModel("操作日志") +public class SystemLog { + @TableId(value = "id", type = IdType.UUID) + private String id; + /** + * 创建时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") +// @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") +// @TableField(fill = FieldFill.INSERT_UPDATE) + @ApiModelProperty("创建时间") + private Date createTime; + /** + * 日志等级 + */ + @ApiModelProperty("日志等级") + private Integer logLevel; + /** + * 被操作的对象 + */ + @ApiModelProperty("被操作的对象") + private String operationUnit; + /** + * 方法名 + */ + @ApiModelProperty("method") + private String method; + /** + * 参数 + */ + @ApiModelProperty("参数") + private String args; + /** + * 操作人id + */ + @ApiModelProperty("操作人id") + private String userId; + /** + * 操作人 + */ + @ApiModelProperty("操作人") + private String userName; + /** + * 日志描述 + */ + @ApiModelProperty("日志描述") + private String logDescribe; + /** + * 操作类型 + */ + @ApiModelProperty("操作类型") + private String operationType; + /** + * 方法运行时间 + */ + @ApiModelProperty("方法运行时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Long runTime; + /** + * 方法返回值 + */ + @ApiModelProperty("方法返回值") + private String returnValue; + /** + * 内网IP地址 + */ + @ApiModelProperty("内网IP地址") + private String ipAddressLan; + + /** + * 外网IP地址 + */ + @ApiModelProperty("外网IP地址") + private String ipAddressWan; +} diff --git a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java index 1c03c1da..c7d68e2c 100644 --- a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java +++ b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java @@ -2,7 +2,6 @@ package com.daqing.financial.gateway.config; import com.alibaba.fastjson.JSONObject; import com.daqing.framework.util.JwtUtils; -import com.daqing.framework.util.RedisUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.filter.GatewayFilterChain; @@ -85,10 +84,10 @@ public class ApiGlobalFilter implements GlobalFilter, Ordered { * @return userPhone */ private Boolean verifyJWT(String token){ - String id = RedisUtil.get("dq:token:"+token); +/* String id = RedisUtil.get("dq:token:"+token); if(id == null || "".equals(id)){ return false; - } + }*/ return JwtUtils.validateJWT(token); //return Long.parseLong(id); } diff --git a/dq-govern-gateway/src/main/resources/application.yml b/dq-govern-gateway/src/main/resources/application.yml index 6ea9f3a1..e53aa09b 100644 --- a/dq-govern-gateway/src/main/resources/application.yml +++ b/dq-govern-gateway/src/main/resources/application.yml @@ -13,7 +13,7 @@ spring: # - Query=url,qq # - id: hrms_route - uri: lb://dq-financial-hrms + uri: http://localhost:7000/dq-financial-hrms #lb://dq-financial-hrms predicates: - Path=/api/** filters: diff --git a/dq-govern-gateway/src/main/resources/bootstrap.properties b/dq-govern-gateway/src/main/resources/bootstrap.properties index 5d6a98ae..4e867f1c 100644 --- a/dq-govern-gateway/src/main/resources/bootstrap.properties +++ b/dq-govern-gateway/src/main/resources/bootstrap.properties @@ -6,4 +6,14 @@ spring.cloud.nacos.config.namespace=772e2607-b929-4246-9671-ee5a36d74d25 spring.cloud.nacos.config.ext-config[0].data-id=dq-govern-gateway.yml spring.cloud.nacos.config.ext-config[0].group=dev -spring.cloud.nacos.config.ext-config[0].refresh=true \ No newline at end of file +spring.cloud.nacos.config.ext-config[0].refresh=true + +spring.redis.host=127.0.0.1 +spring.redis.port=6379 +spring.redis.password=123456 +spring.redis.database=0 +spring.redis.timeout=30000 +spring.redis.jedis.pool.max-active=8 +spring.redis.jedis.pool.max-wait=-1 +spring.redis.jedis.pool.max-idle=8 +spring.redis.jedis.pool.min-idle=0 \ No newline at end of file