Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master' into master

bluebirds 4 жил өмнө
parent
commit
9904de8179

+ 154 - 0
src/main/java/com/migao/config/aop/LogAspect.java

@@ -0,0 +1,154 @@
+package com.migao.config.aop;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.migao.config.authority.AuthenticationProperties;
+import com.migao.config.authority.LoginUtils;
+import com.migao.config.constant.LogType;
+import com.migao.config.log.LogAnnotation;
+import com.migao.entity.vo.req.LogHistoryInsertReq;
+import com.migao.service.LogHistoryService;
+import com.migao.util.UrlMatcherUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.CodeSignature;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.context.annotation.Configuration;
+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.lang.reflect.Method;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration
+@Slf4j
+@Aspect
+@Component
+public class LogAspect {
+
+    @Resource
+    private LogHistoryService logHistoryService;
+    @Resource
+    private AuthenticationProperties authenticationProperties;
+
+    private final ThreadLocal<LocalDateTime> currentThread = new ThreadLocal<>();
+
+    @Pointcut("execution(public * com.migao.controller..*.*(..)))")
+    public void logAspect() {
+
+    }
+
+    //    @Before("logAspect()"+
+//            "&& @annotation(cn.jiheng.ypd.config.log.LogAnnotation)")
+    @Before("logAspect()")
+    public void doBeforeGame() {
+        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        if (servletRequestAttributes != null) {
+            String uri = servletRequestAttributes.getRequest().getRequestURI();
+            log.info("接收请求:{}", uri);
+            currentThread.set(LocalDateTime.now());
+        }
+    }
+
+    @After("logAspect()")
+    public void doAfterReturningGame(JoinPoint joinPoint) {
+        if (currentThread.get() != null) {
+            ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+            if (servletRequestAttributes != null) {
+                String uri = servletRequestAttributes.getRequest().getRequestURI();
+                log.info("请求地址:{},耗时:{}毫秒", uri, Duration.between(currentThread.get(), LocalDateTime.now()).toMillis());
+                Integer millis = Math.toIntExact(Duration.between(currentThread.get(), LocalDateTime.now()).toMillis());
+                // 获取方法注解的权限
+                MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
+                Method method = methodSignature.getMethod();
+                // 获取日志操作类型
+                LogAnnotation annotation = method.getAnnotation(LogAnnotation.class);
+                String typeName = "";
+                String tableName = "";
+                if (annotation == null) {
+                    return;
+                }
+                    LogType type = annotation.operationType();
+                    typeName = type.name();
+                    tableName = annotation.describe();
+
+                //获取请求参数
+                Map<String, Object> param = new HashMap<>();
+                Object[] paramValues = joinPoint.getArgs();
+                String[] paramNames = ((CodeSignature) joinPoint.getSignature()).getParameterNames();
+                //忽略参数uri
+                if (!UrlMatcherUtil.matches(authenticationProperties.getLogIgnoreParamList(), uri)) {
+                    for (int i = 0; i < paramNames.length; i++) {
+                        param.put(paramNames[i], paramValues[i]);
+                    }
+                }
+                //记录日志
+                ServletRequestAttributes requestAttributes =
+                        (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+                if (requestAttributes == null) {
+                    return;
+                }
+                String string = null;
+                if (annotation != null) {
+                    if (annotation.isParameters().equals("是")) {
+                        string = JSONObject.toJSONString(param);
+                    }
+                }
+                HttpServletRequest request =
+                        requestAttributes.getRequest();
+                Long userId = null;
+                if (StringUtils.isNotBlank(request.getHeader(authenticationProperties.getHeaderName()))) {
+                    if (!uri.contains("login")) {
+                        userId = LoginUtils.getLoginUserId();
+                    }
+                }
+                logHistoryService.insert(
+                        LogHistoryInsertReq
+                                .builder()
+                                .deleted(0)
+                                .type(typeName)
+                                .tableName(tableName)
+                                .requestTime(currentThread.get())
+                                .uri(uri)
+                                .params(string)
+                                .duration(millis)
+                                .userId(userId)
+                                .ip(getRemoteHost(request))
+                                .build()
+                );
+                currentThread.remove();
+            }
+        }
+    }
+
+    /**
+     * 获取目标主机的ip
+     *
+     * @param request request
+     * @return ip
+     */
+    private String getRemoteHost(HttpServletRequest request) {
+        String ip = request.getHeader("x-forwarded-for");
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("Proxy-Client-IP");
+        }
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getHeader("WL-Proxy-Client-IP");
+        }
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            ip = request.getRemoteAddr();
+        }
+        return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : ip;
+    }
+}

+ 25 - 0
src/main/java/com/migao/config/constant/LogType.java

@@ -0,0 +1,25 @@
+package com.migao.config.constant;
+
+import lombok.Getter;
+
+/**
+ * Created by IntelliJ IDEA.
+ * @author: lcl
+ * @Created: 2020/4/13 11:39
+ */
+@Getter
+public enum LogType {
+    /**
+     * Operation type
+     */
+    INSERT("新增"),
+    UPDATE("修改"),
+    DELETE("删除"),
+    SELECT("查看"),
+    ;
+
+    private String value;
+    LogType(String value){
+        this.value = value;
+    }
+}

+ 39 - 0
src/main/java/com/migao/config/log/LogAnnotation.java

@@ -0,0 +1,39 @@
+package com.migao.config.log;
+
+
+
+import com.migao.config.constant.LogType;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+* Created by IntelliJ IDEA.
+* @author: lcl
+* @Created: 2020/4/13 11:39
+*/
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD})
+public @interface LogAnnotation {
+    /**
+     *  描述
+     */
+    String describe();
+
+    /**
+     *  操作类型
+     */
+    LogType operationType();
+
+    /**
+     *  操作表名
+     */
+    String tableName();
+
+    /**
+     *  是否读取参数
+     */
+    String isParameters();
+}

+ 28 - 0
src/main/java/com/migao/config/mybatis/AutoFillObjectHandler.java

@@ -0,0 +1,28 @@
+package com.migao.config.mybatis;
+
+import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
+import com.migao.config.authority.LoginUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.reflection.MetaObject;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+
+@Slf4j
+@Component
+public class AutoFillObjectHandler implements MetaObjectHandler {
+    @Override
+    public void insertFill(MetaObject metaObject) {
+        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
+        this.strictInsertFill(metaObject, "deleted", Integer.class,0);
+        if (LoginUtils.isLogin()){
+            this.strictInsertFill(metaObject, "createUserId", Long.class, LoginUtils.getUser().getId());
+        }
+    }
+
+    @Override
+    public void updateFill(MetaObject metaObject) {
+        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
+        this.strictUpdateFill(metaObject, "updateUserId", Long.class, LoginUtils.getUser().getId());
+    }
+}

+ 3 - 0
src/main/java/com/migao/controller/UserController.java

@@ -1,5 +1,7 @@
 package com.migao.controller;
 
+import com.migao.config.constant.LogType;
+import com.migao.config.log.LogAnnotation;
 import com.migao.config.properties.SystemProperties;
 import com.migao.config.response.ResponseBean;
 import com.migao.config.validation.Insert;
@@ -30,6 +32,7 @@ public class UserController {
 
     @ApiOperation("新增用户")
     @PostMapping(value = "/insert")
+    @LogAnnotation(describe = "新增用户",isParameters = "是", operationType = LogType.INSERT, tableName = "t_courts")
     public ResponseBean<?> insert(
             @Validated(value = {Insert.class}) @RequestBody UserInsertReq userInsertReq
     ) {

+ 52 - 0
src/main/java/com/migao/entity/po/Department.java

@@ -0,0 +1,52 @@
+package com.migao.entity.po;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+import java.time.LocalDateTime;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Entity
+@Table(name = "t_department")
+@org.hibernate.annotations.Table(appliesTo = "t_department", comment = "部门表")
+@TableName("t_department")
+public class Department {
+
+    @Id
+    @TableId(type = IdType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", columnDefinition = "int COMMENT '主键'")
+    private Integer id;
+
+    @Column(name = "parent_id", columnDefinition = "bigint(20) comment '父id'")
+    private Integer parentId;
+
+    @Column(name = "name", columnDefinition = "varchar(255) comment '权限名称'")
+    private String name;
+
+    @Column(name = "description", columnDefinition = "varchar(255) comment '备注'")
+    private String description;
+
+    @Column(name = "sort", columnDefinition = "int(11) comment '排序'")
+    private Integer sort;
+
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    @Column(name = "deleted", columnDefinition = "tinyint(4) comment '逻辑删除 0未删除 1已删除'")
+    private Integer deleted;
+
+    @Column(name = "create_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '创建时间'")
+    private LocalDateTime createTime;
+
+    @JoinColumn(name = "create_user_id", columnDefinition = "bigint(20) comment '新增人'")
+    private Integer createUserId;
+}

+ 4 - 5
src/main/java/com/migao/entity/po/FileInfo.java

@@ -26,11 +26,10 @@ import javax.persistence.*;
 public class FileInfo {
 
     @Id
-    @TableId(type = IdType.ASSIGN_ID)
-    @GeneratedValue(generator = "snowFlake")
-    @GenericGenerator(name = "snowFlake", strategy = "com.migao.config.jpa.SnowIdentityGenerator")
-    @Column(name = "id", columnDefinition = "bigint(20) comment '主键'")
-    private Long id;
+    @TableId(type = IdType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", columnDefinition = "int COMMENT '主键'")
+    private Integer id;
 
     @Column(name = "name", columnDefinition = "varchar(255) comment '文件名称'")
     private String name;

+ 66 - 0
src/main/java/com/migao/entity/po/LogHistory.java

@@ -0,0 +1,66 @@
+package com.migao.entity.po;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+import java.time.LocalDateTime;
+
+/**
+ * @version 1.0
+ * @Author mwh
+ * @Date 2020/4/10 9:27
+ */
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Entity
+@Table(name = "t_log_history")
+@org.hibernate.annotations.Table(appliesTo = "t_log_history", comment = "日志记录表")
+@TableName("t_log_history")
+public class LogHistory {
+
+    @Id
+    @TableId(type = IdType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", columnDefinition = "int COMMENT '主键'")
+    private Integer id;
+
+    @Column(name = "table_name", columnDefinition = "varchar(255) comment '操作名称'")
+    private String tableName;
+
+    @Column(name = "uri", columnDefinition = "varchar(255) comment '访问地址'")
+    private String uri;
+
+    @Column(name = "params", columnDefinition = "varchar(255) comment '携带参数(json)'")
+    private String params;
+
+    @JoinColumn(name = "user_id", columnDefinition = "bigint(20) comment '操作名称'")
+    private Integer userId;
+
+    @Column(name = "request_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '请求时间'")
+    private LocalDateTime requestTime;
+
+    @Column(name = "duration", columnDefinition = "int(11) comment '请求持续时间(毫秒)'")
+    private Integer duration;
+
+    @Column(name = "type", columnDefinition = "varchar(255) comment '操作类型'")
+    private String type;
+
+    @Column(name = "deleted", columnDefinition = "tinyint(4) comment '逻辑删除 0未删除 1已删除'")
+    private Integer deleted;
+
+    @Column(name = "ip", columnDefinition = "varchar(255) COMMENT '请求地址'")
+    private String ip;
+
+
+
+}

+ 56 - 0
src/main/java/com/migao/entity/po/Permission.java

@@ -0,0 +1,56 @@
+package com.migao.entity.po;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Entity
+@Table(name = "t_permission")
+@TableName("t_permission")
+@org.hibernate.annotations.Table(appliesTo = "t_permission", comment = "权限")
+public class Permission implements Serializable {
+
+    @Id
+    @TableId(type = IdType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", columnDefinition = "int COMMENT '主键'")
+    private Integer id;
+
+    @Column(name = "name", columnDefinition = "varchar(255) comment '权限名称'")
+    private String name;
+
+    @Column(name = "url", columnDefinition = "varchar(255) comment '接口地址'")
+    private String url;
+
+    @Column(name = "module", columnDefinition = "varchar(255) comment '模块'")
+    private String module;
+
+    @Column(name = "parent_id", columnDefinition = "bigint(20) comment '主键'")
+    private String parentId;
+
+
+    @Column(name = "description", columnDefinition = "varchar(255) comment '备注'")
+    private String description;
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    @Column(name = "deleted", columnDefinition = "tinyint(4) comment '逻辑删除 0未删除 1已删除'")
+    private Integer deleted;
+
+    @Column(name = "create_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '创建时间'")
+    private LocalDateTime createTime;
+
+    @JoinColumn(name = "create_user_id", columnDefinition = "bigint(20) comment '新增人'")
+    private Integer createUserId;
+}

+ 53 - 0
src/main/java/com/migao/entity/po/Role.java

@@ -0,0 +1,53 @@
+package com.migao.entity.po;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Entity
+@Table(name = "t_role")
+@TableName("t_role")
+@org.hibernate.annotations.Table(appliesTo = "t_role", comment = "权限")
+public class Role implements Serializable {
+
+    @Id
+    @TableId(type = IdType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", columnDefinition = "int COMMENT '主键'")
+    private Integer id;
+
+    @Column(name = "parent_id", columnDefinition = "bigint(20)  comment '父角色'")
+    private Integer parentId;
+
+    @Column(name = "name", columnDefinition = "varchar(255) comment '角色名称'")
+    private String name;
+
+    @Column(name = "security_name", columnDefinition = "varchar(255) comment '角色英文名称'")
+    private String securityName;
+
+    @Column(name = "description", columnDefinition = "varchar(255) comment '备注'")
+    private String description;
+
+
+    @TableField(fill = FieldFill.INSERT_UPDATE)
+    @Column(name = "deleted", columnDefinition = "tinyint(4) comment '逻辑删除 0未删除 1已删除'")
+    private Integer deleted;
+
+    @Column(name = "create_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '创建时间'")
+    private LocalDateTime createTime;
+
+    @JoinColumn(name = "create_user_id", columnDefinition = "bigint(20) comment '新增人'")
+    private Integer createUserId;
+}

+ 8 - 23
src/main/java/com/migao/entity/po/User.java

@@ -11,10 +11,7 @@ import javax.persistence.*;
 import java.io.Serializable;
 import java.time.LocalDateTime;
 
-/**
- * @author : lcl
- * @date : 2020/4/15 8:50
- */
+
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
@@ -24,16 +21,14 @@ import java.time.LocalDateTime;
 @org.hibernate.annotations.Table(appliesTo = "t_user", comment = "用户")
 @TableName("t_user")
 public class User implements Serializable {
-
     @Id
-    @TableId(type = IdType.ASSIGN_ID)
-    @GeneratedValue(generator = "snowFlake")
-    @GenericGenerator(name = "snowFlake", strategy = "com.migao.config.jpa.SnowIdentityGenerator")
-    @Column(name = "id", columnDefinition = "bigint(20) comment '主键'")
-    private Long id;
+    @TableId(type = IdType.AUTO)
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", columnDefinition = "int COMMENT '主键'")
+    private Integer id;
 
     @Column(name = "department_id", columnDefinition = "bigint(20) comment '部门id'")
-    private Long departmentId;
+    private Integer departmentId;
 
     @Column(name = "name", columnDefinition = "varchar(255) comment '姓名'")
     private String name;
@@ -59,20 +54,10 @@ public class User implements Serializable {
     @TableField(fill = FieldFill.INSERT_UPDATE)
     @Column(name = "deleted", columnDefinition = "tinyint(4) comment '逻辑删除 0未删除 1已删除'")
     private Integer deleted;
-    @TableField(fill = FieldFill.UPDATE)
-    @Column(name = "update_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '修改时间'")
-    private LocalDateTime updateTime;
-    @TableField(fill = FieldFill.UPDATE)
-    @JoinColumn(name = "update_user_id", columnDefinition = "bigint(20) comment '最后修改人'")
-    private Long updateUserId;
-    @Column(name = "delete_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '删除时间'")
-    private LocalDateTime deleteTime;
-    @JoinColumn(name = "delete_user_id", columnDefinition = "bigint(20) comment '删除人'")
-    private Long deleteUserId;
-    @TableField(fill = FieldFill.INSERT)
+
     @Column(name = "create_time", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP comment '创建时间'")
     private LocalDateTime createTime;
 
     @JoinColumn(name = "create_user_id", columnDefinition = "bigint(20) comment '新增人'")
-    private Long createUserId;
+    private Integer createUserId;
 }

+ 62 - 0
src/main/java/com/migao/entity/vo/req/LogHistoryInsertReq.java

@@ -0,0 +1,62 @@
+package com.migao.entity.vo.req;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.time.LocalDateTime;
+
+
+/**
+ * @version 1.0
+ * @Author mwh
+ * @Date 2020/4/10 14:20
+ */
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+@Data
+public class LogHistoryInsertReq {
+
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    @ApiModelProperty(value = "逻辑删除 0未删除 1已删除")
+    @NotNull(message = "逻辑删除 0未删除 1已删除不能为空")
+    private Integer deleted;
+
+    @ApiModelProperty(value = "请求持续时间(毫秒)")
+    @NotNull(message = "请求持续时间(毫秒)不能为空")
+    private Integer duration;
+
+    @ApiModelProperty(value = "携带参数(json)")
+    @NotEmpty(message = "携带参数(json)不能为空")
+    private String params;
+
+    @ApiModelProperty(value = "请求时间")
+    @NotNull(message = "请求时间不能为空")
+    private LocalDateTime requestTime;
+
+    @ApiModelProperty(value = "操作名称")
+    @NotEmpty(message = "操作名称不能为空")
+    private String tableName;
+
+    @ApiModelProperty(value = "访问地址")
+    @NotEmpty(message = "访问地址不能为空")
+    private String uri;
+
+    @ApiModelProperty(value = "操作类型")
+    @NotNull(message = "操作类型不能为空")
+    private String type;
+
+    @ApiModelProperty(value = "操作名称")
+    @NotNull(message = "操作名称不能为空")
+    private Long userId;
+
+    private String ip;
+
+}

+ 1 - 1
src/main/java/com/migao/entity/vo/req/UserInsertReq.java

@@ -38,7 +38,7 @@ public class UserInsertReq {
     @ApiModelProperty(value = "部门id")
     @NotEmpty(message = "部门不能为空")
     @JsonSerialize(using=ToStringSerializer.class)
-    private Long departmentId;
+    private Integer departmentId;
 
     @ApiModelProperty(value = "角色id")
     @NotEmpty(message = "角色不能为空")

+ 1 - 1
src/main/java/com/migao/entity/vo/res/UserLoginRes.java

@@ -21,7 +21,7 @@ import java.util.Set;
 public class UserLoginRes implements Serializable {
 
     @JsonSerialize(using= ToStringSerializer.class)
-    private Long id;
+    private Integer id;
 
     @ApiModelProperty(value = "用户")
     private String username;

+ 14 - 0
src/main/java/com/migao/mapper/LogHistoryMapper.java

@@ -0,0 +1,14 @@
+package com.migao.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.migao.entity.po.LogHistory;
+
+/**
+ * @version 1.0
+ * @Author mwh
+ * @Date 2020/4/10 11:00
+ */
+
+public interface LogHistoryMapper extends BaseMapper<LogHistory> {
+
+}

+ 14 - 0
src/main/java/com/migao/service/LogHistoryService.java

@@ -0,0 +1,14 @@
+package com.migao.service;
+
+import com.migao.config.response.ResponseBean;
+import com.migao.entity.vo.req.LogHistoryInsertReq;
+
+public interface LogHistoryService {
+    /**
+     * 增
+     *
+     * @param logHistoryInsertReq logHistoryInsertReq
+     * @return ?
+     */
+    ResponseBean<?> insert(LogHistoryInsertReq logHistoryInsertReq);
+}

+ 27 - 0
src/main/java/com/migao/service/impl/LogHistoryServiceImpl.java

@@ -0,0 +1,27 @@
+package com.migao.service.impl;
+
+import com.migao.config.response.ResponseBean;
+import com.migao.config.response.ResponseBuilder;
+import com.migao.entity.po.LogHistory;
+import com.migao.entity.vo.req.LogHistoryInsertReq;
+import com.migao.mapper.LogHistoryMapper;
+import com.migao.service.LogHistoryService;
+import com.migao.util.EntityUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@Service
+@Transactional(rollbackFor = {Exception.class})
+public class LogHistoryServiceImpl implements LogHistoryService {
+    @Resource
+    private LogHistoryMapper logHistoryMapper;
+
+    @Override
+    public ResponseBean<?> insert(LogHistoryInsertReq logHistoryInsertReq) {
+        return ResponseBuilder.ok(logHistoryMapper.insert(EntityUtils.copyProperties(logHistoryInsertReq, LogHistory.class)));
+    }
+}

+ 1 - 1
src/main/java/com/migao/service/impl/UserServiceImpl.java

@@ -50,7 +50,7 @@ public class UserServiceImpl implements UserService {
         if (!checkPassword) {
             return ResponseEntity.ok().body(ResponseBuilder.fail("用户名或密码错误"));
         }
-        String sign = JWTUtil.sign(user.getId());
+        String sign = JWTUtil.sign(user.getId().longValue());
         sign = StringUtils.join(authenticationProperties.getTokenPrefix(), SystemConstant.BLANK_STRING, sign);
         userLoginRes.setToken(sign);
         if (StringUtils.isBlank(user.getHead())) {

+ 20 - 0
src/main/java/com/migao/util/UrlMatcherUtil.java

@@ -0,0 +1,20 @@
+package com.migao.util;
+
+import org.springframework.util.AntPathMatcher;
+
+import java.util.List;
+
+/**
+ * @version 1.0
+ * @Author mwh
+ * @Date 2020/4/15 8:45
+ */
+public class UrlMatcherUtil {
+
+    public static final AntPathMatcher MATCHER = new AntPathMatcher();
+
+    public static boolean matches(List<String> list, String path) {
+        return list.stream().anyMatch(i->MATCHER.match(i, path));
+    }
+
+}