gaodm vor 6 Jahren
Commit
0b9dd1dfda
100 geänderte Dateien mit 4917 neuen und 0 gelöschten Zeilen
  1. 25 0
      .gitignore
  2. 25 0
      common/.gitignore
  3. 46 0
      common/pom.xml
  4. 19 0
      common/src/main/java/com/diagbot/annotation/SysLogger.java
  5. 31 0
      common/src/main/java/com/diagbot/dto/RespDTO.java
  6. 36 0
      common/src/main/java/com/diagbot/exception/CommonException.java
  7. 45 0
      common/src/main/java/com/diagbot/exception/ErrorCode.java
  8. 31 0
      common/src/main/java/com/diagbot/util/ArrayUtil.java
  9. 647 0
      common/src/main/java/com/diagbot/util/DateUtil.java
  10. 64 0
      common/src/main/java/com/diagbot/util/ListUtil.java
  11. 46 0
      common/src/main/java/com/diagbot/util/StringUtil.java
  12. 25 0
      config-server/.gitignore
  13. 60 0
      config-server/pom.xml
  14. 19 0
      config-server/src/main/java/com/diagbot/ConfigServerApplication.java
  15. 34 0
      config-server/src/main/resources/application.yml
  16. 38 0
      config-server/src/main/resources/shared/application.yml
  17. 31 0
      config-server/src/main/resources/shared/gateway-service-dev.yml
  18. 101 0
      config-server/src/main/resources/shared/logger-service-dev.yml
  19. 92 0
      config-server/src/main/resources/shared/uaa-service-dev.yml
  20. 104 0
      config-server/src/main/resources/shared/user-service-dev.yml
  21. 16 0
      config-server/src/test/java/com/diagbot/ConfigServerApplicationTests.java
  22. 25 0
      eureka-server/.gitignore
  23. 49 0
      eureka-server/pom.xml
  24. 19 0
      eureka-server/src/main/java/com/diagbot/EurekaServerApplication.java
  25. 8 0
      eureka-server/src/main/resources/application.yml
  26. 16 0
      eureka-server/src/test/java/com/diagbot/EurekaServerApplicationTests.java
  27. 25 0
      gateway-service/.gitignore
  28. 64 0
      gateway-service/pom.xml
  29. 21 0
      gateway-service/src/main/java/com/diagbot/GatewayServiceApplication.java
  30. 12 0
      gateway-service/src/main/resources/bootstrap.yml
  31. 16 0
      gateway-service/src/test/java/com/diagbot/GatewayServiceApplicationTests.java
  32. 25 0
      log-service/.gitignore
  33. 145 0
      log-service/pom.xml
  34. 19 0
      log-service/src/main/java/com/diagbot/LogServiceApplication.java
  35. 74 0
      log-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java
  36. 25 0
      log-service/src/main/java/com/diagbot/client/UserServiceClient.java
  37. 23 0
      log-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java
  38. 15 0
      log-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java
  39. 47 0
      log-service/src/main/java/com/diagbot/config/JwtConfiguration.java
  40. 41 0
      log-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  41. 57 0
      log-service/src/main/java/com/diagbot/config/RabbitConfig.java
  42. 42 0
      log-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java
  43. 67 0
      log-service/src/main/java/com/diagbot/config/SwaggerConfig.java
  44. 103 0
      log-service/src/main/java/com/diagbot/entity/SysLog.java
  45. 37 0
      log-service/src/main/java/com/diagbot/entity/User.java
  46. 13 0
      log-service/src/main/java/com/diagbot/facade/SysLogFacade.java
  47. 16 0
      log-service/src/main/java/com/diagbot/mapper/SysLogMapper.java
  48. 32 0
      log-service/src/main/java/com/diagbot/rabbit/Receiver.java
  49. 18 0
      log-service/src/main/java/com/diagbot/rabbit/Sender.java
  50. 41 0
      log-service/src/main/java/com/diagbot/rabbit/User.java
  51. 18 0
      log-service/src/main/java/com/diagbot/service/SysLogService.java
  52. 31 0
      log-service/src/main/java/com/diagbot/service/impl/SysLogServiceImpl.java
  53. 51 0
      log-service/src/main/java/com/diagbot/util/BeanUtil.java
  54. 92 0
      log-service/src/main/java/com/diagbot/util/EntityUtil.java
  55. 97 0
      log-service/src/main/java/com/diagbot/util/HttpUtils.java
  56. 81 0
      log-service/src/main/java/com/diagbot/util/UserUtils.java
  57. 21 0
      log-service/src/main/java/com/diagbot/vo/SysLogVo.java
  58. 89 0
      log-service/src/main/java/com/diagbot/web/SysLogController.java
  59. 9 0
      log-service/src/main/resources/bootstrap.yml
  60. 16 0
      log-service/src/main/resources/mapper/SysLogMapper.xml
  61. 9 0
      log-service/src/main/resources/public.cert
  62. 81 0
      log-service/src/test/java/com/diagbot/CodeGeneration.java
  63. 16 0
      log-service/src/test/java/com/diagbot/LogServiceApplicationTests.java
  64. 99 0
      pom.xml
  65. 36 0
      sql/sys-log.sql
  66. 50 0
      sql/sys-user.sql
  67. 25 0
      uaa-service/.gitignore
  68. 107 0
      uaa-service/pom.xml
  69. 14 0
      uaa-service/src/main/java/com/diagbot/UaaServiceApplication.java
  70. 41 0
      uaa-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  71. 58 0
      uaa-service/src/main/java/com/diagbot/config/OAuth2Config.java
  72. 70 0
      uaa-service/src/main/java/com/diagbot/config/WebSecurityConfig.java
  73. 52 0
      uaa-service/src/main/java/com/diagbot/entity/Role.java
  74. 100 0
      uaa-service/src/main/java/com/diagbot/entity/User.java
  75. 16 0
      uaa-service/src/main/java/com/diagbot/mapper/UserMapper.java
  76. 25 0
      uaa-service/src/main/java/com/diagbot/service/UserServiceDetail.java
  77. 12 0
      uaa-service/src/main/resources/bootstrap.yml
  78. BIN
      uaa-service/src/main/resources/diagbot-jwt.jks
  79. 6 0
      uaa-service/src/main/resources/logback-spring.xml
  80. 29 0
      uaa-service/src/main/resources/mapper/UserMapper.xml
  81. 81 0
      uaa-service/src/test/java/com/diagbot/CodeGeneration.java
  82. 16 0
      uaa-service/src/test/java/com/diagbot/UaaServiceApplicationTests.java
  83. 25 0
      user-service/.gitignore
  84. 145 0
      user-service/pom.xml
  85. 26 0
      user-service/src/main/java/com/diagbot/UserServiceApplication.java
  86. 75 0
      user-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java
  87. 25 0
      user-service/src/main/java/com/diagbot/client/AuthServiceClient.java
  88. 20 0
      user-service/src/main/java/com/diagbot/client/hystrix/AuthServiceHystrix.java
  89. 15 0
      user-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java
  90. 47 0
      user-service/src/main/java/com/diagbot/config/JwtConfiguration.java
  91. 41 0
      user-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  92. 38 0
      user-service/src/main/java/com/diagbot/config/RabbitConfig.java
  93. 42 0
      user-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java
  94. 67 0
      user-service/src/main/java/com/diagbot/config/SwaggerConfig.java
  95. 29 0
      user-service/src/main/java/com/diagbot/dto/LoginDTO.java
  96. 75 0
      user-service/src/main/java/com/diagbot/entity/JWT.java
  97. 82 0
      user-service/src/main/java/com/diagbot/entity/SysLog.java
  98. 57 0
      user-service/src/main/java/com/diagbot/entity/User.java
  99. 30 0
      user-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java
  100. 0 0
      user-service/src/main/java/com/diagbot/facade/LoggerFacade.java

+ 25 - 0
.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 25 - 0
common/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 46 - 0
common/pom.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>common</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>common</name>
+    <description>Common for Spring Boot</description>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <encoding>UTF-8</encoding>
+        <java.version>1.8</java.version>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.49</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.7</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>

+ 19 - 0
common/src/main/java/com/diagbot/annotation/SysLogger.java

@@ -0,0 +1,19 @@
+package com.diagbot.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * @Description: 日志注解拦截用
+ * @author: gaodm
+ * @time: 2018/8/1 14:54
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface SysLogger {
+    String value() default "";
+}

+ 31 - 0
common/src/main/java/com/diagbot/dto/RespDTO.java

@@ -0,0 +1,31 @@
+package com.diagbot.dto;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 通用返回格式
+ * @author: gaodm
+ * @time: 2018/8/1 14:55
+ */
+public class RespDTO<T> implements Serializable{
+
+
+    public int code = 0;
+    public String msg = "";
+    public T data;
+
+    public static RespDTO onSuc(Object data) {
+        RespDTO resp = new RespDTO();
+        resp.data = data;
+        return resp;
+    }
+
+    @Override
+    public String toString() {
+        return "RespDTO{" +
+                "code=" + code +
+                ", error='" + msg + '\'' +
+                ", data=" + data +
+                '}';
+    }
+}

+ 36 - 0
common/src/main/java/com/diagbot/exception/CommonException.java

@@ -0,0 +1,36 @@
+package com.diagbot.exception;
+
+
+/**
+ * @Description: 通用错误处理
+ * @author: gaodm
+ * @time: 2018/8/1 14:56
+ */
+public class CommonException extends RuntimeException {
+
+    private ErrorCode errorCode;
+
+    public CommonException(ErrorCode errorCode) {
+        super(errorCode.getMsg());
+        this.errorCode = errorCode;
+    }
+
+    public CommonException(ErrorCode errorCode, String msg) {
+        super(msg);
+        this.errorCode = errorCode;
+    }
+
+    public ErrorCode getErrorCode() {
+        return errorCode;
+    }
+
+
+    public int getCode() {
+        return errorCode.getCode();
+    }
+
+    public String getMsg() {
+        return errorCode.getMsg();
+    }
+
+}

+ 45 - 0
common/src/main/java/com/diagbot/exception/ErrorCode.java

@@ -0,0 +1,45 @@
+package com.diagbot.exception;
+
+/**
+ * @Description: 通用错误码
+ * @author: gaodm
+ * @time: 2018/8/1 14:56
+ */
+public enum ErrorCode {
+
+    OK(0, ""),
+    FAIL(-1, "操作失败"),
+    RPC_ERROR(-2,"远程调度失败"),
+    USER_NOT_FOUND(1000,"用户不存在"),
+    USER_PASSWORD_ERROR(1001,"密码错误"),
+    GET_TOKEN_FAIL(1002,"获取token失败"),
+    TOKEN_IS_NOT_MATCH_USER(1003,"请使用自己的token进行接口请求"),
+
+    LOG_IS_NOT_EXIST(9001,"该日志不存在");
+    private int code;
+    private String msg;
+
+
+    ErrorCode(int code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+
+    public int getCode() {
+        return code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public static ErrorCode codeOf(int code) {
+        for (ErrorCode state : values()) {
+            if (state.getCode() == code) {
+                return state;
+            }
+        }
+        return null;
+    }
+}

+ 31 - 0
common/src/main/java/com/diagbot/util/ArrayUtil.java

@@ -0,0 +1,31 @@
+package com.diagbot.util;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ * @Description:数组工具类
+ * @author: gaodaming
+ * @date: 2016/6/13 16:21
+ * @version: V1.0
+ */
+public class ArrayUtil {
+    /**
+     * 判断数组是否为空
+     * @param array 数组
+     * @return 是否为空
+     */
+    public static boolean isEmpty(Object[] array) {
+        return ArrayUtils.isEmpty(array);
+    }
+
+    /**
+     * 数组合并
+     * @param array 一个数组
+     * @param anotherArray 另外一个数组
+     * @param <T> 数组类型
+     * @return 合并后的数组
+     */
+    public static <T> T[] add(T[] array, T[] anotherArray) {
+        return ArrayUtils.addAll(array, anotherArray);
+    }
+}

+ 647 - 0
common/src/main/java/com/diagbot/util/DateUtil.java

@@ -0,0 +1,647 @@
+package com.diagbot.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @Description: 日期帮助类
+ * @author: gaodm
+ * @time: 2018/8/6 11:17
+ */
+public class DateUtil {
+
+    public static final long TEN_MINUTES = 10 * 60 * 1000;
+    public static final long ONE_DAY = 24 * 60 * 60 * 1000;
+
+    // Internal values for using in date/time calculations
+    public static final long MILLISECOND_OF_SECOND = 1000;
+    public static final long MILLISECOND_OF_MINUTE = MILLISECOND_OF_SECOND * 60;
+    public static final long MILLISECOND_OF_HOUR = MILLISECOND_OF_MINUTE * 60;
+    public static final long MILLISECOND_OF_DAY = MILLISECOND_OF_HOUR * 24;
+    public static final long MILLISECOND_OF_WEEK = MILLISECOND_OF_DAY * 7;
+
+    /** 日期格式:yyyy-MM-dd */
+    public static final String DATE_FORMAT = "yyyy-MM-dd";
+    /** 日期格式:yyyyMMdd */
+    public static final String DATE_FORMAT_NO_SPLIT = "yyyyMMdd";
+    /** 日期格式:yyyyMMddHHmmss */
+    public static final String DATE_TIME_FORMAT_NO_SPLIT = "yyyyMMddHHmmss";
+    /** 日期格式:yyyy-MM-dd HH:mm:ss */
+    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
+    /** 日期格式:yyyy-MM-dd HH:mm:ss.SSS */
+    public static final String DATE_TIME_MS_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+
+    public static final String FORMAT_TIME = "HH:mm:ss";
+
+    /**
+     * 精确到毫秒的完整时间    如:yyyy-MM-dd HH:mm:ss.S
+     */
+    public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
+
+    /**
+     * 中文简写  如:2010年12月01日
+     */
+    public static String FORMAT_SHORT_CN = "yyyy年MM月dd";
+
+    /**
+     * 中文全称  如:2010年12月01日  23时15分06秒
+     */
+    public static String FORMAT_LONG_CN = "yyyy年MM月dd日  HH时mm分ss秒";
+
+    /**
+     * 中文全称精确到分钟  如:2010年12月01日  23时15分
+     */
+    public static String FORMAT_LONG_CN_MI = "yyyy年MM月dd日  HH时mm分";
+
+    /**
+     * 精确到毫秒的完整中文时间
+     */
+    public static String FORMAT_FULL_CN = "yyyy年MM月dd日  HH时mm分ss秒SSS毫秒";
+
+
+    /**
+     * Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules. For
+     * example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:
+     * <p>
+     * <code>add(Calendar.DAY_OF_MONTH, -5)</code>.
+     *
+     * @param date
+     *            the date of before the changed.
+     * @param field
+     *            the calendar field.
+     * @param amount
+     *            the amount of date or time to be added to the field.
+     * @return
+     */
+    public static Date add(final Date date, Integer field, Integer amount) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+
+        calendar.add(field, amount);
+
+        return calendar.getTime();
+    }
+
+    /**
+     * 添加天数
+     * @param date
+     *           要操作的日期
+     * @param days
+     *            天数
+     * @return
+     */
+    public static Date addDate(final Date date, Integer days) {
+        return add(date, Calendar.DATE, days);
+    }
+
+    /**
+     * 按指定的格式,将日期转换成为字符
+     * @param date 日期
+     * @param format 格式
+     * @return 按指定的格式,将日期转换成为字符
+     */
+    public static String format(Date date, String format) {
+        if (date == null) {
+            return "";
+        }
+
+        if (isEmpty(format)) {
+            format = DATE_FORMAT;
+        }
+
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        return sdf.format(date);
+    }
+
+    /**
+     * 判断字符串是否为空
+     * @param str 要判断的字符串
+     * @return boolean
+     */
+    private static boolean isEmpty(String str) {
+        return str == null || str.trim().length() == 0;
+    }
+
+    /**
+     * 将日期转换成为字符(yyyy-MM-dd)
+     * @param date
+     * @return
+     */
+    public static String formatDate(Date date) {
+        return format(date, DATE_FORMAT);
+    }
+
+    /**
+     *  今天日期的字符(yyyy-MM-dd)
+     * @return  今天日期的字符(yyyy-MM-dd)
+     */
+    public static String today() {
+        return formatDate(new Date());
+    }
+
+    /**
+     * 将日期转换成为字符(yyyy-MM-dd HH:mm:ss)
+     * @param date
+     * @return
+     */
+    public static String formatDateTime(Date date) {
+        return format(date, DATE_TIME_FORMAT);
+    }
+
+    /**
+     * 当前时间的字符(yyyy-MM-dd HH:mm:ss)
+     * @return 当前时间的字符(yyyy-MM-dd HH:mm:ss)
+     */
+    public static String nowString() {
+        return formatDateTime(now());
+    }
+
+    /**
+     * 当前时间
+     * @return 当前时间
+     */
+    public static Date now() {
+        return new Date();
+    }
+
+    /**
+     * 将日期转换成为字符(yyyy-MM-dd HH:mm:ss.SSS)
+     *
+     * @param date 要格式化的数据
+     * @return 将日期转换成为字符(yyyy-MM-dd HH:mm:ss.SSS)
+     */
+    public static String formatDateTimeMs(Date date) {
+        return format(date, DATE_TIME_MS_FORMAT);
+    }
+
+    /**
+     * 生成日期
+     * @param object 要转换的数据
+     * @return 生成日期
+     */
+    public static Date getDateValue(Object object) {
+        return null == object ? null : (Date) object;
+    }
+
+    /**
+     * 按指定的格式,将字符转换为日期
+     * @param dateString 日期
+     * @param format 格式
+     * @return 按指定的格式,将字符转换为日期
+     */
+    public static Date parseDate(String dateString, String format) {
+        if (isEmpty(format)) {
+            return null;
+        }
+
+        try {
+            return new SimpleDateFormat(format).parse(dateString);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+
+
+    /**
+     * 获取昨天的日期格式化字符串 yyyy-MM-dd
+     * @return
+     */
+    public static String yesterdayFormate(){
+        Date  date = new Date();
+        Date dBefore = new Date();
+        Calendar calendar = Calendar.getInstance(); //得到日历
+        calendar.setTime(date);//把当前时间赋给日历
+        calendar.add(Calendar.DAY_OF_MONTH, -1);  //设置为前一天
+        dBefore = calendar.getTime();   //得到前一天的时间
+        return formatDate(dBefore);
+    }
+
+
+
+    /**
+     * 将字符(yyyy-MM-dd)转换为日期
+     * @param dateString
+     * @return 将字符(yyyy-MM-dd)转换为日期
+     */
+    public static Date parseDate(String dateString) {
+        return parseDate(dateString, DATE_FORMAT);
+    }
+
+    /**
+     * 将字符(yyyy-MM-dd HH:mm:ss)转换为日期
+     * @param dateString
+     * @return 将字符(yyyy-MM-dd HH:mm:ss)转换为日期
+     */
+    public static Date parseDateTime(String dateString) {
+        return parseDate(dateString, DATE_TIME_FORMAT);
+    }
+
+    /**
+     * milliseconds 转化为日期
+     *
+     * @param date
+     * @return  milliseconds 转化为日期
+     */
+    public static Date toDate(Long date) {
+        if (date == null) {
+            return null;
+        }
+        return new Date(date);
+    }
+
+    /**
+     * 获取当前时间 milliseconds
+     *
+     * @return 获取当前时间 milliseconds
+     */
+    public static long getCurrentTime() {
+        return new Date().getTime();
+    }
+
+    /**
+     * 获取当前时间字符串 默认格式:yyyy-MM-dd HH:mm:ss
+     *
+     * @param dateFormatPattern
+     *            日期转换格式
+     * @return 获取当前时间字符串 默认格式:yyyy-MM-dd HH:mm:ss
+     */
+    public static String getCurrentDateStr(String dateFormatPattern) {
+        if (isEmpty(dateFormatPattern)) {
+            dateFormatPattern = DATE_TIME_FORMAT;
+        }
+        return format(new Date(), dateFormatPattern);
+    }
+
+    public static Date getServerTime(String operateTimeStr) {
+        Date serverTime = new Date();
+        if (isEmpty(operateTimeStr)) {
+            return serverTime;
+        }
+
+        Date operateTime = parseDate(operateTimeStr, DATE_TIME_FORMAT);
+
+        if (operateTime == null) {
+            operateTime = parseDate(operateTimeStr, DATE_TIME_MS_FORMAT);
+        }
+
+        Long interval = operateTime.getTime() - serverTime.getTime();
+        if (operateTime.after(serverTime) && TEN_MINUTES < interval) {
+            return serverTime;
+        } else if (operateTime.before(serverTime) && ONE_DAY < Math.abs(interval)) {
+            return serverTime;
+        } else {
+            return operateTime;
+        }
+    }
+
+    /**
+     * 添加或减少月
+     * @param date 要操作的日期
+     * @param months 月
+     * @return操作过的日期
+     */
+    public static Date addMonth(Date date, int months) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.add(Calendar.MONTH, months);
+        return cal.getTime();
+    }
+
+    /**
+     * 添加或减少周
+     * @param date 要操作的日期
+     * @param weeks 周
+     * @return操作过的日期
+     */
+    public static Date addWeek(Date date, int weeks) {
+        if (date != null) {
+            return new Date(date.getTime() + weeks * MILLISECOND_OF_WEEK);
+        }
+        return date;
+    }
+
+    /**
+     * 添加或减少天数
+     * @param date 日期
+     * @param days 天数
+     * @return 操作过的日期
+     */
+    public static Date addDay(Date date, int days) {
+        if (date != null) {
+            return new Date(date.getTime() + days * MILLISECOND_OF_DAY);
+        }
+        return date;
+    }
+
+    /**
+     * 添加或减少小时
+     * @param date 要操作的日期
+     * @param hours 小时
+     * @return 操作过的日期
+     */
+    public static Date addHour(Date date, int hours) {
+        if (date != null) {
+            return new Date(date.getTime() + hours * MILLISECOND_OF_HOUR);
+        }
+        return date;
+    }
+
+    /**
+     *  添加或减少分钟
+     * @param date 要操作的日期
+     * @param minutes 分钟
+     * @return 操作过的日期
+     */
+    public static Date addMinutes(Date date, int minutes) {
+        if (date != null) {
+            return new Date(date.getTime() + minutes * MILLISECOND_OF_MINUTE);
+        }
+        return date;
+    }
+
+    /**
+     * 获得某个月的第一天0时0分0秒的时间
+     *
+     * @param year 年
+     * @param month 月
+     * @return java.util.Date
+     */
+    public static Date getFirstDateOfMonth(int year, int month) {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.YEAR, year);
+        cal.set(Calendar.MONTH, month - 1);
+        cal.set(Calendar.DAY_OF_MONTH, 1);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+
+        return cal.getTime();
+    }
+
+    /**
+     * 获取某一天的0时0分0秒的时间
+     *
+     * @param year 年
+     * @param month 月
+     * @param day 日
+     * @return 返回加上0点的时间
+     */
+    public static Date getFirstTimeOfDay(int year, int month, int day) {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.YEAR, year);
+        cal.set(Calendar.MONTH, month - 1);
+        cal.set(Calendar.DAY_OF_MONTH, day);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+
+        return cal.getTime();
+    }
+
+    /**
+     * 获取某一天的0时0分0秒的时间
+     *
+     * @param date 输入日期
+     * @return 返回加上0点的时间
+     */
+    public static Date getFirstTimeOfDay(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        return cal.getTime();
+    }
+
+    /**
+     * 获取某一天的23时59分59秒的时间
+     *
+     * @param date 日期
+     * @return 某一天的23时59分59秒的时间
+     */
+    public static Date getLastTimeOfDay(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        cal.set(Calendar.HOUR_OF_DAY, 23);
+        cal.set(Calendar.MINUTE, 59);
+        cal.set(Calendar.SECOND, 59);
+        return cal.getTime();
+    }
+
+    /**
+     * 获得Date型对象,根据时间点
+     *
+     * @param year  年
+     * @param month 月
+     * @param day 日
+     * @return 时间点
+     */
+    public static Date getDateFromTime(int year, int month, int day, int hour, int minute, int second) {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.YEAR, year);
+        cal.set(Calendar.MONTH, month - 1);
+        cal.set(Calendar.DAY_OF_MONTH, day);
+        cal.set(Calendar.HOUR_OF_DAY, hour);
+        cal.set(Calendar.MINUTE, minute);
+        cal.set(Calendar.SECOND, second);
+
+        return cal.getTime();
+    }
+
+
+    /**
+     * 将时间字符串进行相加后操作后格式化输出
+     * @param timeStr 格式<HH:mm:ss>
+     * @param hour 小时
+     * @param minute 分钟
+     * @param second 秒
+     * @return 格式<HH:mm>
+     */
+    public static String timeOperate(String timeStr, int hour, int minute, int second){
+        SimpleDateFormat df = new SimpleDateFormat(FORMAT_TIME);
+        String[] times = timeStr.trim().split(":");
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.HOUR_OF_DAY,Integer.valueOf(times[0]));
+        calendar.set(Calendar.MINUTE,Integer.valueOf(times[1]));
+        if(times.length==3){
+            calendar.set(Calendar.SECOND,Integer.valueOf(times[2]));
+        }
+        calendar.add(Calendar.HOUR_OF_DAY,hour);
+        calendar.add(Calendar.MINUTE,minute);
+        calendar.add(Calendar.SECOND,second);
+        return df.format(calendar.getTime());
+
+    }
+
+    /**
+     * 根据指定string生成当天时间
+     * @param timeStr 格式<HH:mm> or <HH:mm:ss>
+     * @return 当天时间
+     */
+    public static Date getCurrentDayTimeByStr(String timeStr) {
+        String[] times = timeStr.trim().split(":");
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0]));
+        calendar.set(Calendar.MINUTE, Integer.valueOf(times[1]));
+        if(times.length==3){
+            calendar.set(Calendar.SECOND,Integer.valueOf(times[2]));
+        }else {
+            calendar.set(Calendar.SECOND,0);
+        }
+        calendar.set(Calendar.MILLISECOND, 0);
+        return calendar.getTime();
+    }
+
+    /**
+     * 根据指定string生成指定日期时间
+     *
+     * @param timeStr 格式<HH:mm> or <HH:mm:ss>
+     * @param date 日期
+     * @return 日期时间
+     */
+    public static Date getSpecialDayTimeByStr(Date date, String timeStr) {
+        String[] times = timeStr.trim().split(":");
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0]));
+        calendar.set(Calendar.MINUTE, Integer.valueOf(times[1]));
+        if (times.length == 3) {
+            calendar.set(Calendar.SECOND, Integer.valueOf(times[2]));
+        }else {
+            calendar.set(Calendar.SECOND, 0);
+        }
+        calendar.set(Calendar.MILLISECOND, 0);
+        return calendar.getTime();
+    }
+
+    /**
+     * 获取两个日期间所跨0点次数
+     * @param d1 开始日期
+     * @param d2 结束日期
+     * @return 得到两个日期相差的天数
+     */
+    public static  Integer getDaysBetweenTwoDate(Date d1,Date d2) {
+        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
+        try {
+            Date d11 = sdf.parse(sdf.format(d1));
+            Date d21 = sdf.parse(sdf.format(d2));
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(d11);
+            long time1 = cal.getTimeInMillis();
+            cal.setTime(d21);
+            long time2 = cal.getTimeInMillis();
+            long between_days = Math.abs((time2 - time1) / (1000 * 3600 * 24));
+
+            return Integer.parseInt(String.valueOf(between_days));
+        } catch (ParseException e) {
+            return null;
+        }
+    }
+
+    public static boolean after(Date date1, Date date2) {
+        return date1.compareTo(date2) > 0;
+    }
+
+    public static boolean before(Date date1, Date date2) {
+        return date1.compareTo(date2) < 0;
+    }
+
+    /**
+     * 获取时间戳
+     */
+    public static String getTimeString() {
+        SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
+        Calendar calendar = Calendar.getInstance();
+        return df.format(calendar.getTime());
+    }
+
+    /**
+     * 获取日期年份
+     * @param date 日期
+     * @return
+     */
+    public static String getYear(Date date) {
+        SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
+        return df.format(date).substring(0, 4);
+    }
+    /**
+     * 功能描述:返回月
+     *
+     * @param date
+     *            Date 日期
+     * @return 返回月份
+     */
+    public static int getMonth(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.MONTH) + 1;
+    }
+
+    /**
+     * 功能描述:返回日
+     *
+     * @param date
+     *            Date 日期
+     * @return 返回日份
+     */
+    public static int getDay(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.DAY_OF_MONTH);
+    }
+
+    /**
+     * 功能描述:返回小
+     *
+     * @param date
+     *            日期
+     * @return 返回小时
+     */
+    public static int getHour(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.HOUR_OF_DAY);
+    }
+
+    /**
+     * 功能描述:返回分
+     *
+     * @param date
+     *            日期
+     * @return 返回分钟
+     */
+    public static int getMinute(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.MINUTE);
+    }
+
+    /**
+     * 返回秒钟
+     *
+     * @param date
+     *            Date 日期
+     * @return 返回秒钟
+     */
+    public static int getSecond(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.SECOND);
+    }
+
+    /**
+     * 功能描述:返回毫
+     *
+     * @param date
+     *            日期
+     * @return 返回毫
+     */
+    public static long getMillis(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.getTimeInMillis();
+    }
+}

+ 64 - 0
common/src/main/java/com/diagbot/util/ListUtil.java

@@ -0,0 +1,64 @@
+package com.diagbot.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Description: List 工具类
+ * @author: gaodm
+ * @date: 2017/12/28 15:36
+ * @version: V1.0
+ */
+public class ListUtil {
+    /**
+     * list的第一行
+     */
+    public static final int FIRST = 0;
+
+    private ListUtil() {
+
+    }
+
+    /**
+     * 创建List对象
+     *
+     * @param <E> 泛型,
+     * @return
+     */
+    public static <E> ArrayList<E> newArrayList() {
+        return new ArrayList<>();
+    }
+
+    /**
+     * 判断List是否为空
+     *
+     * @param list
+     * @return
+     */
+    public static boolean isEmpty(List list) {
+        if (null == list) {
+            return Boolean.TRUE;
+        }
+        if (list.isEmpty()) {
+            return Boolean.TRUE;
+        }
+        if (list.size() < 1) {
+            return Boolean.TRUE;
+        }
+        return Boolean.FALSE;
+    }
+
+    /**
+     * 获取List集合中第一个对象,前提是自己先判断这个list不会为空
+     *
+     * @param list
+     * @param <E>
+     * @return
+     */
+    public static <E> E firstEntity(List<E> list) {
+        if (isEmpty(list)) {
+            return null;
+        }
+        return list.get(FIRST);
+    }
+}

+ 46 - 0
common/src/main/java/com/diagbot/util/StringUtil.java

@@ -0,0 +1,46 @@
+package com.diagbot.util;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * @Description: 字符串有关帮助类 封装了第三方帮助类
+ * @author: gaodm
+ * @time: 2018/8/6 11:15
+ */
+public class StringUtil {
+    /**
+     * 判断某字符串是否为空或长度为0或由空白符(whitespace) 构成
+     * @param str 需要判断的字符串
+     * @return
+     */
+    public static boolean isBlank(String str){
+        return StringUtils.isBlank(str);
+    }
+
+    /**
+     * 判断某字符串是否不是为空或长度为0或由空白符(whitespace) 构成
+     * @param str 需要判断的字符串
+     * @return
+     */
+    public static boolean isNotBlank(String str){
+        return StringUtils.isNotBlank(str);
+    }
+
+    /**
+     * 判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0
+     * @param str 需要判断的字符串
+     * @return
+     */
+    public static boolean isEmpty(String str){
+        return StringUtils.isEmpty(str);
+    }
+
+    /**
+     * 判断某字符串是否不为空,为空的标准是 str==null 或 str.length()==0
+     * @param str 需要判断的字符串
+     * @return
+     */
+    public static boolean isNotEmpty(String str){
+        return StringUtils.isNotEmpty(str);
+    }
+}

+ 25 - 0
config-server/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 60 - 0
config-server/pom.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>config-server</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>config-server</name>
+    <description>Config Server for Spring Boot</description>
+
+    <parent>
+        <groupId>com.diagbot</groupId>
+        <artifactId>diagbotcloud</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-config-server</artifactId>
+        </dependency>
+        <!-- actuator-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
+        </dependency>
+
+
+
+        <dependency>
+            <groupId>org.springframework.retry</groupId>
+            <artifactId>spring-retry</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 19 - 0
config-server/src/main/java/com/diagbot/ConfigServerApplication.java

@@ -0,0 +1,19 @@
+package com.diagbot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.config.server.EnableConfigServer;
+
+/**
+ * @Description: 配置中心启动文件
+ * @author: gaodm
+ * @time: 2018/8/1 14:56
+ */
+@SpringBootApplication
+@EnableConfigServer
+public class ConfigServerApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(ConfigServerApplication.class, args);
+    }
+}

+ 34 - 0
config-server/src/main/resources/application.yml

@@ -0,0 +1,34 @@
+# remote git
+#spring:
+#  cloud:
+#    config:
+#      server:
+#        git:
+#          uri: https://git.coding.net/xiaoantimes/xiaoantimes-taichi
+#          searchPaths: backend/repo
+#          username: 124746406@qq.com
+#          password:
+#      label: master
+
+# ---native
+spring:
+  cloud:
+    config:
+      server:
+        native:
+          search-locations: classpath:/shared
+  profiles:
+     active: native
+  application:
+    name: config-server
+
+# port
+server:
+  port: 8769
+
+management:
+  security:
+    enabled: false
+
+
+

+ 38 - 0
config-server/src/main/resources/shared/application.yml

@@ -0,0 +1,38 @@
+#logging:
+#  level:
+#    org.springframework.security: INFO
+
+#hystrix:
+#  command:
+#    default:
+#      execution:
+#        isolation:
+#          thread:
+#            timeoutInMilliseconds: 10000
+
+eureka:
+  client:
+    serviceUrl:
+      defaultZone: http://localhost:8761/eureka/
+
+#endpoints:
+#  health:
+#    sensitive: false
+#    enabled: true
+#  actuator:
+#    enabled: true
+#    sensitive: false
+#  beans:
+#    sensitive: false
+#    enabled: true
+
+
+management:
+  security:
+    enabled: false
+
+feign:
+  hystrix:
+    enabled: true
+
+

+ 31 - 0
config-server/src/main/resources/shared/gateway-service-dev.yml

@@ -0,0 +1,31 @@
+hystrix:
+  command:
+    default:
+      execution:
+        isolation:
+          thread:
+            timeoutInMilliseconds: 20000
+
+ribbon:
+  ReadTimeout: 20000
+  ConnectTimeout: 20000
+
+zuul:
+  host:
+    connect-timeout-millis: 20000
+    socket-timeout-millis: 20000
+
+  routes:
+    user-service:
+      path: /userapi/**
+      serviceId: user-service
+      sensitiveHeaders:
+
+    blog-service:
+      path: /logapi/**
+      serviceId: logger-service
+      sensitiveHeaders:
+
+server:
+  port: 5000
+

+ 101 - 0
config-server/src/main/resources/shared/logger-service-dev.yml

@@ -0,0 +1,101 @@
+#spring:
+#  datasource:
+#    driver-class-name: com.mysql.jdbc.Driver
+#    url: jdbc:mysql://localhost:3306/sys-log?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+#    username: root
+#    password: root
+#  jpa:
+#    hibernate:
+#      ddl-auto: update
+#    show-sql: true
+
+# 驱动配置信息
+spring:
+  datasource:
+    druid:
+      driverClassName: com.mysql.jdbc.Driver
+      driver-class-name: com.mysql.jdbc.Driver
+      platform: mysql
+      url: jdbc:mysql://localhost:3306/sys-log?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+      username: root
+      password: root
+      # 连接池的配置信息
+      # 初始化大小,最小,最大
+      initialSize: 5
+      minIdle: 5
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      # 打开PSCache,并且指定每个连接上PSCache的大小
+      poolPreparedStatements: true
+      maxPoolPreparedStatementPerConnectionSize: 20
+      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+      filters.commons-log.connection-logger-name: stat,wall,log4j
+      filter.stat.log-slow-sql: true
+      filter.stat.slow-sql-millis: 2000
+#监控配置
+      web-stat-filter:
+        enabled: true
+        url-pattern: /*
+        exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*'
+
+# StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置
+      stat-view-servlet:
+        enabled: true
+        url-pattern: /druid/*
+        reset-enable: false
+        login-username: root
+        login-password: root
+
+  #mq
+  rabbitmq:
+    host: localhost
+    port: 5672
+    username: guest
+    password: guest
+    publisher-confirms: true
+    virtual-host: /
+
+#mybatis
+mybatis-plus:
+  mapper-locations: classpath:/mapper/*Mapper.xml
+  #实体扫描,多个package用逗号或者分号分隔
+  typeAliasesPackage: com.diagbot.entity
+  global-config:
+    #刷新mapper 调试神器
+    db-config:
+      #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+      id-type: id_worker
+      #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+      field-strategy: not_empty
+      #驼峰下划线转换
+      column-underline: true
+      #数据库大写下划线转换
+      #capital-mode: true
+      #刷新mapper 调试神器
+      refresh-mapper: true
+      #逻辑删除配置
+      logic-delete-value: 0
+      logic-not-delete-value: 1
+      #自定义填充策略接口实现
+      #meta-object-handler: com.baomidou.springboot.xxx
+      #自定义SQL注入器
+      #sql-injector: com.baomidou.springboot.xxx
+  configuration:
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+
+#logging
+logging:
+  level.com.diagbot: debug
+
+server:
+  port: 9997

+ 92 - 0
config-server/src/main/resources/shared/uaa-service-dev.yml

@@ -0,0 +1,92 @@
+#spring:
+#  datasource:
+#    driver-class-name: com.mysql.jdbc.Driver
+#    url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+#    username: root
+#    password: root
+#  jpa:
+#    hibernate:
+#      ddl-auto: update
+#    show-sql: true
+
+# 驱动配置信息
+spring:
+  datasource:
+    druid:
+      driverClassName: com.mysql.jdbc.Driver
+      driver-class-name: com.mysql.jdbc.Driver
+      platform: mysql
+      url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+      username: root
+      password: root
+      # 连接池的配置信息
+      # 初始化大小,最小,最大
+      initialSize: 5
+      minIdle: 5
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      # 打开PSCache,并且指定每个连接上PSCache的大小
+      poolPreparedStatements: true
+      maxPoolPreparedStatementPerConnectionSize: 20
+      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+      filters.commons-log.connection-logger-name: stat,wall,log4j
+      filter.stat.log-slow-sql: true
+      filter.stat.slow-sql-millis: 2000
+#监控配置
+      web-stat-filter:
+        enabled: true
+        url-pattern: /*
+        exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*'
+
+# StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置
+      stat-view-servlet:
+        enabled: true
+        url-pattern: /druid/*
+        reset-enable: false
+        login-username: root
+        login-password: root
+
+#mybatis
+mybatis-plus:
+  mapper-locations: classpath:/mapper/*Mapper.xml
+  #实体扫描,多个package用逗号或者分号分隔
+  typeAliasesPackage: com.diagbot.entity
+  global-config:
+    #刷新mapper 调试神器
+    db-config:
+      #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+      id-type: id_worker
+      #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+      field-strategy: not_empty
+      #驼峰下划线转换
+      column-underline: true
+      #数据库大写下划线转换
+      #capital-mode: true
+      #刷新mapper 调试神器
+      refresh-mapper: true
+      #逻辑删除配置
+      logic-delete-value: 0
+      logic-not-delete-value: 1
+      #自定义填充策略接口实现
+      #meta-object-handler: com.baomidou.springboot.xxx
+      #自定义SQL注入器
+      #sql-injector: com.baomidou.springboot.xxx
+  configuration:
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+
+#logging
+logging:
+  level.com.diagbot: debug
+
+server:
+  port: 9999

+ 104 - 0
config-server/src/main/resources/shared/user-service-dev.yml

@@ -0,0 +1,104 @@
+server:
+  port: 8762
+
+
+#spring:
+#  datasource:
+#    driver-class-name: com.mysql.jdbc.Driver
+#    url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+#    username: root
+#    password: root
+#  jpa:
+#    hibernate:
+#      ddl-auto: update
+#    show-sql: true
+
+# 驱动配置信息
+spring:
+  datasource:
+    druid:
+      driverClassName: com.mysql.jdbc.Driver
+      driver-class-name: com.mysql.jdbc.Driver
+      platform: mysql
+      url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+      username: root
+      password: root
+      # 连接池的配置信息
+      # 初始化大小,最小,最大
+      initialSize: 5
+      minIdle: 5
+      maxActive: 20
+      # 配置获取连接等待超时的时间
+      maxWait: 60000
+      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+      timeBetweenEvictionRunsMillis: 60000
+      # 配置一个连接在池中最小生存的时间,单位是毫秒
+      minEvictableIdleTimeMillis: 300000
+      validationQuery: SELECT 1 FROM DUAL
+      testWhileIdle: true
+      testOnBorrow: false
+      testOnReturn: false
+      # 打开PSCache,并且指定每个连接上PSCache的大小
+      poolPreparedStatements: true
+      maxPoolPreparedStatementPerConnectionSize: 20
+      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+      filters.commons-log.connection-logger-name: stat,wall,log4j
+      filter.stat.log-slow-sql: true
+      filter.stat.slow-sql-millis: 2000
+#监控配置
+      web-stat-filter:
+        enabled: true
+        url-pattern: /*
+        exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*'
+
+# StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置
+      stat-view-servlet:
+        enabled: true
+        url-pattern: /druid/*
+        reset-enable: false
+        login-username: root
+        login-password: root
+
+  #mq
+  rabbitmq:
+    host: localhost
+    port: 5672
+    username: guest
+    password: guest
+    publisher-confirms: true
+    virtual-host: /
+
+#mybatis
+mybatis-plus:
+  mapper-locations: classpath:/mapper/*Mapper.xml
+  #实体扫描,多个package用逗号或者分号分隔
+  typeAliasesPackage: com.diagbot.entity
+  global-config:
+    #刷新mapper 调试神器
+    db-config:
+      #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+      id-type: id_worker
+      #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+      field-strategy: not_empty
+      #驼峰下划线转换
+      column-underline: true
+      #数据库大写下划线转换
+      #capital-mode: true
+      #刷新mapper 调试神器
+      refresh-mapper: true
+      #逻辑删除配置
+      logic-delete-value: 0
+      logic-not-delete-value: 1
+      #自定义填充策略接口实现
+      #meta-object-handler: com.baomidou.springboot.xxx
+      #自定义SQL注入器
+      #sql-injector: com.baomidou.springboot.xxx
+  configuration:
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+
+#logging
+logging:
+  level.com.diagbot: debug
+
+foo: foo version 1

+ 16 - 0
config-server/src/test/java/com/diagbot/ConfigServerApplicationTests.java

@@ -0,0 +1,16 @@
+package com.diagbot;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ConfigServerApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}

+ 25 - 0
eureka-server/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 49 - 0
eureka-server/pom.xml

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>eureka-server</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>eureka-server</name>
+    <description>Eureka Server project for Spring Boot</description>
+
+    <parent>
+        <groupId>com.diagbot</groupId>
+        <artifactId>diagbotcloud</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <java.version>1.8</java.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>

+ 19 - 0
eureka-server/src/main/java/com/diagbot/EurekaServerApplication.java

@@ -0,0 +1,19 @@
+package com.diagbot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
+
+/**
+ * @Description: 注册中心启动文件
+ * @author: gaodm
+ * @time: 2018/8/1 14:57
+ */
+@SpringBootApplication
+@EnableEurekaServer
+public class EurekaServerApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(EurekaServerApplication.class, args);
+    }
+}

+ 8 - 0
eureka-server/src/main/resources/application.yml

@@ -0,0 +1,8 @@
+server:
+  port: 8761
+eureka:
+  client:
+    register-with-eureka: false
+    fetch-registry: false
+    serviceUrl:
+      defaultZone: http://localhost:${server.port}/eureka/

+ 16 - 0
eureka-server/src/test/java/com/diagbot/EurekaServerApplicationTests.java

@@ -0,0 +1,16 @@
+package com.diagbot;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class EurekaServerApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}

+ 25 - 0
gateway-service/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 64 - 0
gateway-service/pom.xml

@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>gateway-service</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>gateway-service</name>
+    <description>Gateway service project for Spring Boot</description>
+
+    <parent>
+        <groupId>com.diagbot</groupId>
+        <artifactId>diagbotcloud</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
+        </dependency>
+        <!-- 配置-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-config</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>

+ 21 - 0
gateway-service/src/main/java/com/diagbot/GatewayServiceApplication.java

@@ -0,0 +1,21 @@
+package com.diagbot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+
+/**
+ * @Description: 网关启动文件
+ * @author: gaodm
+ * @time: 2018/8/1 14:58
+ */
+@SpringBootApplication
+@EnableZuulProxy
+@EnableEurekaClient
+public class GatewayServiceApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(GatewayServiceApplication.class, args);
+    }
+}

+ 12 - 0
gateway-service/src/main/resources/bootstrap.yml

@@ -0,0 +1,12 @@
+spring:
+  application:
+    name: gateway-service
+  cloud:
+    config:
+      uri: http://localhost:8769
+      fail-fast: true
+  profiles:
+    active: dev
+
+
+

+ 16 - 0
gateway-service/src/test/java/com/diagbot/GatewayServiceApplicationTests.java

@@ -0,0 +1,16 @@
+package com.diagbot;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class GatewayServiceApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}

+ 25 - 0
log-service/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 145 - 0
log-service/pom.xml

@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>log-service</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>log-service</name>
+    <description>Log service for Spring Boot</description>
+
+    <parent>
+        <groupId>com.diagbot</groupId>
+        <artifactId>diagbotcloud</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.diagbot</groupId>
+            <artifactId>common</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+        </dependency>
+
+        <!-- 配置-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-config</artifactId>
+        </dependency>
+
+        <!-- 开启web-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <!-- 开启feign-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+        </dependency>
+
+        <!-- dashboard -->
+        <!-- actuator-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <!--hystrix-dashboard-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
+        </dependency>
+        <!--hystrix -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
+        </dependency>
+
+        <!-- zipkin-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-zipkin</artifactId>
+        </dependency>
+
+        <!--swagger-->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+        </dependency>
+        <!--database-->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <!--<dependency>-->
+        <!--<groupId>org.springframework.boot</groupId>-->
+        <!--<artifactId>spring-boot-starter-data-jpa</artifactId>-->
+        <!--</dependency>-->
+
+        <!--security-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+
+        <!-- mq -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <!-- mybatis-plus begin -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>${mybatis-plus-boot-starter.version}</version>
+        </dependency>
+        <!-- mybatis-plus end -->
+
+        <!-- 阿里巴巴druid数据库连接池 -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+        </dependency>
+
+        <!-- springboot整合mybatis(核心就这一个) -->
+        <!-- 注意顺序,这个一定要放在最下面 -->
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>${mybatis-spring-boot.version}</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>

+ 19 - 0
log-service/src/main/java/com/diagbot/LogServiceApplication.java

@@ -0,0 +1,19 @@
+package com.diagbot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+
+/**
+ * @Description: 日志服务启动文件
+ * @author: gaodm
+ * @time: 2018/8/1 15:00
+ */
+@SpringBootApplication
+@EnableEurekaClient
+public class LogServiceApplication {
+
+	public static void main(String[] args) {
+		SpringApplication.run(LogServiceApplication.class, args);
+	}
+}

+ 74 - 0
log-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java

@@ -0,0 +1,74 @@
+package com.diagbot.aop;
+
+import com.alibaba.fastjson.JSON;
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.entity.SysLog;
+import com.diagbot.facade.SysLogFacade;
+import com.diagbot.util.HttpUtils;
+import com.diagbot.util.UserUtils;
+import org.apache.commons.lang.StringUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+
+/**
+ * @Description: 日志拦截切面
+ * @author: gaodm
+ * @time: 2018/8/2 13:36
+ */
+@Aspect
+@Component
+public class SysLoggerAspect {
+    @Autowired
+    private SysLogFacade sysLogFacade;
+
+    @Pointcut("@annotation(com.diagbot.annotation.SysLogger)")
+    public void loggerPointCut() {
+
+    }
+
+    @Before("loggerPointCut()")
+    public void saveSysLog(JoinPoint joinPoint) {
+        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+        Method method = signature.getMethod();
+
+        SysLog sysLog = new SysLog();
+        SysLogger sysLogger = method.getAnnotation(SysLogger.class);
+        if(sysLogger != null){
+            //注解上的描述
+            sysLog.setOperation(sysLogger.value());
+        }
+        //请求的方法名
+        String className = joinPoint.getTarget().getClass().getName();
+        String methodName = signature.getName();
+        sysLog.setMethod(className + "." + methodName + "()");
+        //请求的参数
+        Object[] args = joinPoint.getArgs();
+        String params="";
+        for(Object o:args){
+            params+=JSON.toJSONString(o);
+        }
+        if(!StringUtils.isEmpty(params)) {
+            sysLog.setParams(params);
+        }
+        //设置IP地址
+        sysLog.setIp(HttpUtils.getIpAddress());
+        //用户名
+        String username = UserUtils.getCurrentPrinciple();
+        if(!StringUtils.isEmpty(username)) {
+            sysLog.setUsername(username);
+        }
+        sysLog.setCreateDate(new Date());
+        //保存系统日志
+        sysLogFacade.log(sysLog);
+    }
+
+}
+

+ 25 - 0
log-service/src/main/java/com/diagbot/client/UserServiceClient.java

@@ -0,0 +1,25 @@
+package com.diagbot.client;
+
+import com.diagbot.client.hystrix.UserServiceHystrix;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.User;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestHeader;
+
+
+/**
+ * @Description: 调用用户服务
+ * @author: gaodm
+ * @time: 2018/8/6 9:52
+ */
+@FeignClient(value = "user-service",fallback = UserServiceHystrix.class )
+public interface UserServiceClient {
+
+    @PostMapping(value = "/user/{username}")
+    RespDTO<User> getUser(@RequestHeader(value = "Authorization") String token, @PathVariable("username") String username);
+}
+
+
+

+ 23 - 0
log-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java

@@ -0,0 +1,23 @@
+package com.diagbot.client.hystrix;
+
+import com.diagbot.client.UserServiceClient;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.User;
+import org.springframework.stereotype.Component;
+
+
+/**
+ * @Description: 调用用户服务
+ * @author: gaodm
+ * @time: 2018/8/6 9:52
+ */
+@Component
+public class UserServiceHystrix implements UserServiceClient {
+
+    @Override
+    public RespDTO<User> getUser(String token, String username) {
+        System.out.println(token);
+        System.out.println(username);
+        return null;
+    }
+}

+ 15 - 0
log-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java

@@ -0,0 +1,15 @@
+package com.diagbot.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+
+/**
+ * @Description: 安全配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:38
+ */
+@Configuration
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+public class GlobalMethodSecurityConfiguration {
+
+}

+ 47 - 0
log-service/src/main/java/com/diagbot/config/JwtConfiguration.java

@@ -0,0 +1,47 @@
+package com.diagbot.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.security.oauth2.provider.token.TokenStore;
+import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
+import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
+import org.springframework.util.FileCopyUtils;
+
+import java.io.IOException;
+
+/**
+ * @Description: JWT配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:38
+ */
+@Configuration
+public class JwtConfiguration {
+    @Autowired
+    JwtAccessTokenConverter jwtAccessTokenConverter;
+
+    @Bean
+    @Qualifier("tokenStore")
+    public TokenStore tokenStore() {
+
+        System.out.println("Created JwtTokenStore");
+        return new JwtTokenStore(jwtAccessTokenConverter);
+    }
+
+    @Bean
+    protected JwtAccessTokenConverter jwtTokenEnhancer() {
+        JwtAccessTokenConverter converter =  new JwtAccessTokenConverter();
+        Resource resource = new ClassPathResource("public.cert");
+        String publicKey ;
+        try {
+            publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        converter.setVerifierKey(publicKey);
+        return converter;
+    }
+}

+ 41 - 0
log-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java

@@ -0,0 +1,41 @@
+package com.diagbot.config;
+
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import org.mybatis.spring.mapper.MapperScannerConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @Description: MybatisPlus配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:39
+ */
+@Configuration
+//@MapperScan("com.diagbot.mapper*")//这个注解,作用相当于下面的@Bean MapperScannerConfigurer,2者配置1份即可
+public class MybatisPlusConfig {
+
+    /**
+     * mybatis-plus分页插件<br>
+     * 文档:http://mp.baomidou.com<br>
+     */
+    @Bean
+    public PaginationInterceptor paginationInterceptor() {
+        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
+        // 开启 PageHelper 的支持
+        paginationInterceptor.setLocalPage(true);
+        return paginationInterceptor;
+    }
+
+    /**
+     * 相当于顶部的:
+     * {@code @MapperScan("com.diagbot.mapper*")}
+     * 这里可以扩展,比如使用配置文件来配置扫描Mapper的路径
+     */
+    @Bean
+    public MapperScannerConfigurer mapperScannerConfigurer() {
+        MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();
+        scannerConfigurer.setBasePackage("com.diagbot.mapper*");
+        return scannerConfigurer;
+    }
+
+}

+ 57 - 0
log-service/src/main/java/com/diagbot/config/RabbitConfig.java

@@ -0,0 +1,57 @@
+package com.diagbot.config;
+
+
+import com.diagbot.rabbit.Receiver;
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.core.TopicExchange;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
+import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @Description: 消息消费者配置
+ * @author: gaodm
+ * @time: 2018/8/1 14:59
+ */
+@Configuration
+public class RabbitConfig {
+
+
+  public   final static String queueName = "spring-boot";
+
+    @Bean
+    Queue queue() {
+        return new Queue(queueName, false);
+    }
+
+    @Bean
+    TopicExchange exchange() {
+        return new TopicExchange("spring-boot-exchange");
+    }
+
+    @Bean
+    Binding binding(Queue queue, TopicExchange exchange) {
+        return BindingBuilder.bind(queue).to(exchange).with(queueName);
+    }
+
+    @Bean
+    SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,
+                                             MessageListenerAdapter listenerAdapter) {
+        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
+        container.setConnectionFactory(connectionFactory);
+        container.setQueueNames(queueName);
+        container.setMessageListener(listenerAdapter);
+        return container;
+    }
+
+    @Bean
+    MessageListenerAdapter listenerAdapter(Receiver receiver) {
+        return new MessageListenerAdapter(receiver, "receiveMessage");
+    }
+
+
+}

+ 42 - 0
log-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java

@@ -0,0 +1,42 @@
+package com.diagbot.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
+import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
+import org.springframework.security.oauth2.provider.token.TokenStore;
+
+/**
+ * @Description: 权限资源配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:21
+ */
+@Configuration
+@EnableResourceServer
+public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
+    Logger log = LoggerFactory.getLogger(ResourceServerConfiguration.class);
+
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        http
+                .csrf().disable()
+                .authorizeRequests()
+                .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/druid.*").permitAll()
+                .antMatchers("/**").authenticated();
+//        .antMatchers("/**").permitAll();
+    }
+
+
+    @Override
+    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
+        log.info("Configuring ResourceServerSecurityConfigurer ");
+        resources.resourceId("user-service").tokenStore(tokenStore);
+    }
+
+    @Autowired
+    TokenStore tokenStore;
+}

+ 67 - 0
log-service/src/main/java/com/diagbot/config/SwaggerConfig.java

@@ -0,0 +1,67 @@
+package com.diagbot.config;
+
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * @Description: Swagger配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:21
+ */
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig {
+    /**
+     * 全局参数
+     *
+     * @return
+     */
+    private List<Parameter> parameter() {
+        List<Parameter> params = new ArrayList<>();
+        params.add(new ParameterBuilder().name("Authorization")
+                .description("Authorization Bearer token")
+                .modelRef(new ModelRef("string"))
+                .parameterType("header")
+                .required(false).build());
+        return params;
+    }
+
+
+    @Bean
+    public Docket sysApi() {
+        return new Docket(DocumentationType.SWAGGER_2)
+                .apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.diagbot.web"))
+                .paths(PathSelectors.any())
+                .build().globalOperationParameters(parameter());
+                //.securitySchemes(newArrayList(oauth()))
+               // .securityContexts(newArrayList(securityContext()));
+    }
+
+    private ApiInfo apiInfo() {
+        return new ApiInfoBuilder()
+                .title(" log-service api ")
+                .description("log-service 微服务")
+                .termsOfServiceUrl("")
+                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

+ 103 - 0
log-service/src/main/java/com/diagbot/entity/SysLog.java

@@ -0,0 +1,103 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+@TableName("sys_log")
+public class SysLog implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+    @TableField("create_date")
+    private Date createDate;
+    private String ip;
+    private String method;
+    private String operation;
+    private String params;
+    private String username;
+
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Date getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(Date createDate) {
+        this.createDate = createDate;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    public String getOperation() {
+        return operation;
+    }
+
+    public void setOperation(String operation) {
+        this.operation = operation;
+    }
+
+    public String getParams() {
+        return params;
+    }
+
+    public void setParams(String params) {
+        this.params = params;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    @Override
+    public String toString() {
+        return "SysLog{" +
+        ", id=" + id +
+        ", createDate=" + createDate +
+        ", ip=" + ip +
+        ", method=" + method +
+        ", operation=" + operation +
+        ", params=" + params +
+        ", username=" + username +
+        "}";
+    }
+}

+ 37 - 0
log-service/src/main/java/com/diagbot/entity/User.java

@@ -0,0 +1,37 @@
+package com.diagbot.entity;
+
+/**
+ * @Description: 用户实体类
+ * @author: gaodm
+ * @time: 2018/8/6 9:53
+ */
+public class User {
+
+    private Long id;
+    private String username;
+    private String password;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+}

+ 13 - 0
log-service/src/main/java/com/diagbot/facade/SysLogFacade.java

@@ -0,0 +1,13 @@
+package com.diagbot.facade;
+
+import com.diagbot.service.impl.SysLogServiceImpl;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: 用户日志业务层
+ * @author: gaodm
+ * @time: 2018/8/6 9:11
+ */
+@Component
+public class SysLogFacade extends SysLogServiceImpl {
+}

+ 16 - 0
log-service/src/main/java/com/diagbot/mapper/SysLogMapper.java

@@ -0,0 +1,16 @@
+package com.diagbot.mapper;
+
+import com.diagbot.entity.SysLog;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+public interface SysLogMapper extends BaseMapper<SysLog> {
+
+}

+ 32 - 0
log-service/src/main/java/com/diagbot/rabbit/Receiver.java

@@ -0,0 +1,32 @@
+package com.diagbot.rabbit;
+
+import com.alibaba.fastjson.JSON;
+import com.diagbot.entity.SysLog;
+import com.diagbot.facade.SysLogFacade;
+import com.diagbot.service.SysLogService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @Description: 消费者处理
+ * @author: gaodm
+ * @time: 2018/8/1 17:02
+ */
+@Component
+public class Receiver {
+
+    private CountDownLatch latch = new CountDownLatch(1);
+
+    @Autowired
+    SysLogFacade sysLogFacade;
+    public void receiveMessage(String message) {
+        System.out.println("Received <" + message + ">");
+        SysLog  sysLog=  JSON.parseObject(message,SysLog.class);
+        sysLogFacade.insert(sysLog);
+        latch.countDown();
+    }
+
+
+}

+ 18 - 0
log-service/src/main/java/com/diagbot/rabbit/Sender.java

@@ -0,0 +1,18 @@
+package com.diagbot.rabbit;
+
+///**
+// * Created by gaodm on 2018/8/1.
+// */
+//@Component
+//public class Sender {
+//
+//    @Autowired
+//    private AmqpTemplate rabbitTemplate;
+//
+//    public void send() {
+//        String context = "hello " + new Date();
+//        System.out.println("Sender : " + context);
+//        rabbitTemplate.convertAndSend(RabbitConfig.queueName, "Hello from RabbitMQ!");
+//    }
+//
+//}

+ 41 - 0
log-service/src/main/java/com/diagbot/rabbit/User.java

@@ -0,0 +1,41 @@
+package com.diagbot.rabbit;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2018/8/2 11:14
+ */
+public class User {
+    private String username;
+    private String password;
+
+
+    public User(String username, String password) {
+        this.username = username;
+        this.password = password;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    @Override
+    public String toString() {
+        return "User{" +
+                "username='" + username + '\'' +
+                ", password='" + password + '\'' +
+                '}';
+    }
+}

+ 18 - 0
log-service/src/main/java/com/diagbot/service/SysLogService.java

@@ -0,0 +1,18 @@
+package com.diagbot.service;
+
+import com.diagbot.entity.SysLog;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+public interface SysLogService extends IService<SysLog> {
+
+    void log(SysLog sysLog);
+
+}

+ 31 - 0
log-service/src/main/java/com/diagbot/service/impl/SysLogServiceImpl.java

@@ -0,0 +1,31 @@
+package com.diagbot.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.diagbot.config.RabbitConfig;
+import com.diagbot.entity.SysLog;
+import com.diagbot.mapper.SysLogMapper;
+import com.diagbot.service.SysLogService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+@Service
+public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
+
+    @Autowired
+    private AmqpTemplate rabbitTemplate;
+
+    @Override
+    public void log(SysLog sysLog){
+        rabbitTemplate.convertAndSend(RabbitConfig.queueName, JSON.toJSONString(sysLog));
+    }
+}

+ 51 - 0
log-service/src/main/java/com/diagbot/util/BeanUtil.java

@@ -0,0 +1,51 @@
+package com.diagbot.util;
+
+
+import org.springframework.beans.BeanUtils;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @Description: 对象转换工具类
+ * @author: gaodm
+ * @date: 2017/12/28 10:16
+ * @version: V1.0
+ */
+public class BeanUtil {
+    /**
+     * 把一个对象的属性值复制给另外一个对象的属性值
+     * @param source 源对象,被转换的对象
+     * @param target 目标对象,即转换后对象
+     */
+    public static void copyProperties(Object source, Object target){
+        BeanUtils.copyProperties(source,target);
+    }
+
+    /**
+     * 复制集合
+     * @param <E>
+     * @param source 转换前的列表
+     * @param destinationClass 转换后列表类
+     * @return 转换后列表
+     */
+    public static <E> List<E> listCopyTo(List<?> source, Class<E> destinationClass){
+        try{
+            if (source.size() == 0){
+                return Collections.emptyList();
+            }
+            List<E> res = new ArrayList<E>(source.size());
+            for (Object o : source) {
+                E e = destinationClass.newInstance();
+                BeanUtils.copyProperties(o, e);
+                res.add(e);
+            }
+            return res;
+        }catch (IllegalAccessException ex){
+            throw new RuntimeException(ex);
+        }catch (InstantiationException ex){
+            throw new RuntimeException(ex);
+        }
+    }
+}

+ 92 - 0
log-service/src/main/java/com/diagbot/util/EntityUtil.java

@@ -0,0 +1,92 @@
+package com.diagbot.util;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 实体对象工具类
+ * @author: gaodm
+ * @time: 2018/2/11 10:09
+ */
+@Slf4j
+public class EntityUtil {
+
+    /**
+     *
+     * 将list中的元素放到Map<K, V>以建立 key - value 索引<p>
+     *
+     * @param list  List<V> 元素列表
+     * @param keyFieldName String 元素的属性名称, 该属性的值作为索引key
+     * @param <K> key类型
+     * @param <V> value类型
+     * @return Map<K, V> key - value 索引
+     */
+    @SuppressWarnings("unchecked")
+    public static <K, V> Map<K, V> makeEntityMap(List<V> list, String keyFieldName) {
+        Map<K, V> map = new HashMap<>();
+        if(list == null || list.size() == 0) {
+            return map;
+        }
+        try {
+            Method getter = getMethod(list.get(0).getClass(), keyFieldName, "get");
+            for (V item : list) {
+                map.put((K) getter.invoke(item), item);
+            }
+        } catch (Exception e) {
+            log.error("makeEntityMap error list is " + list, e);
+            return map;
+        }
+        return map;
+    }
+
+    /**
+     *
+     * 将list中的元素放到Map<K, List<V>> 以建立 key - List<value> 索引<p>
+     *
+     * @param list  List<V> 元素列表
+     * @param keyFieldName String 元素的属性名称, 该属性的值作为索引key
+     * @param <K> key类型
+     * @param <V> value类型
+     * @return Map<K, V> key - value 索引
+     */
+    public static <K, V> Map<K, List<V>> makeEntityListMap(List<V> list, String keyFieldName) {
+        Map<K, List<V>> map = new LinkedHashMap<>();
+        if(list == null || list.size() == 0) {
+            return map;
+        }
+        try {
+            Method getter = getMethod(list.get(0).getClass(), keyFieldName, "get");
+            for (V item : list) {
+                @SuppressWarnings("unchecked")
+                K key = (K) getter.invoke(item);
+                List<V> groupList = map.get(key);
+                if (groupList == null) {
+                    groupList = new ArrayList<>();
+                    map.put(key, groupList);
+                }
+                groupList.add(item);
+            }
+        } catch (Exception e) {
+            log.error("makeEntityListMap error list is " + list, e);
+            return map;
+        }
+        return map;
+    }
+
+    /**
+     * 获取getter或setter
+     */
+    @SuppressWarnings("unchecked")
+    private static Method getMethod(@SuppressWarnings("rawtypes") Class clazz, String fieldName,
+                                    String methodPrefix) throws NoSuchMethodException {
+        String first = fieldName.substring(0, 1);
+        String getterName = methodPrefix + fieldName.replaceFirst(first, first.toUpperCase());
+        return clazz.getMethod(getterName);
+    }
+}

+ 97 - 0
log-service/src/main/java/com/diagbot/util/HttpUtils.java

@@ -0,0 +1,97 @@
+package com.diagbot.util;
+
+
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Enumeration;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @Description: http请求功能工具类
+ * @author: gaodm
+ * @time: 2018/8/3 17:45
+ */
+public class HttpUtils {
+
+
+    /**
+     * 尝试获取当前请求的HttpServletRequest实例
+     *
+     * @return HttpServletRequest
+     */
+    public static HttpServletRequest getHttpServletRequest() {
+        try {
+            return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+
+    public static Map<String, String> getHeaders(HttpServletRequest request) {
+        Map<String, String> map = new LinkedHashMap<>();
+        Enumeration<String> enumeration = request.getHeaderNames();
+        while (enumeration.hasMoreElements()) {
+            String key = enumeration.nextElement();
+            String value = request.getHeader(key);
+            map.put(key, value);
+        }
+        return map;
+    }
+
+    /**
+     * 获取请求客户端的真实ip地址
+     *
+     * @param request 请求对象
+     * @return ip地址
+     */
+    public static String getIpAddress(HttpServletRequest request) {
+
+        // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
+        String ip = request.getHeader("X-Forwarded-For");
+
+        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+            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.getHeader("HTTP_CLIENT_IP");
+            }
+            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+                ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+            }
+            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+                ip = request.getRemoteAddr();
+            }
+        } else if (ip.length() > 15) {
+            String[] ips = ip.split(",");
+            for (int index = 0; index < ips.length; index++) {
+                String strIp = (String) ips[index];
+                if (!("unknown".equalsIgnoreCase(strIp))) {
+                    ip = strIp;
+                    break;
+                }
+            }
+        }
+        return ip;
+    }
+
+    /**
+     * 获取请求客户端的真实ip地址
+     *
+     * @param
+     * @return ip地址
+     */
+    public static String getIpAddress() {
+        // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址
+        return getIpAddress(getHttpServletRequest());
+    }
+
+
+}

+ 81 - 0
log-service/src/main/java/com/diagbot/util/UserUtils.java

@@ -0,0 +1,81 @@
+package com.diagbot.util;
+
+
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import java.util.List;
+
+/**
+ * @Description: 用户工具类
+ * @author: gaodm
+ * @time: 2018/8/3 17:46
+ */
+public class UserUtils {
+
+    private static final String AUTHORIZATION = "authorization";
+
+    /**
+     * 获取当前请求的token
+     * @return
+     */
+    public static String getCurrentToken() {
+        return HttpUtils.getHeaders(HttpUtils.getHttpServletRequest()).get(AUTHORIZATION);
+    }
+
+    /**
+     * 获取当前请求的用户Id
+     * @return
+     */
+    public static String getCurrentPrinciple() {
+        return (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+    }
+
+    /**
+     * 判读当前token用户是否为接口所需的参数username
+     *
+     * @param username
+     * @return
+     */
+    public static boolean isMyself(String username) {
+        return username.equals(getCurrentPrinciple());
+    }
+
+    /**
+     * 获取当前请求Authentication
+     *
+     * @return
+     */
+    public static Authentication getCurrentAuthentication() {
+        return SecurityContextHolder.getContext().getAuthentication();
+    }
+
+    /**
+     * 获取当前请求的权限信息
+     * @return
+     */
+    public static List<SimpleGrantedAuthority> getCurrentAuthorities() {
+        return (List<SimpleGrantedAuthority>) SecurityContextHolder.getContext().getAuthentication().getAuthorities();
+    }
+
+    /**
+     * @param role
+     * @return
+     */
+    public static boolean hasRole(String role) {
+        if (!role.startsWith("ROLE_")) {
+            role = "ROLE_" + role;
+        }
+        boolean hasRole = false;
+        List<SimpleGrantedAuthority> list = getCurrentAuthorities();
+        for (SimpleGrantedAuthority s : list) {
+            if (role.equals(s.getAuthority())) {
+                hasRole = true;
+                break;
+            }
+        }
+        return hasRole;
+    }
+
+}

+ 21 - 0
log-service/src/main/java/com/diagbot/vo/SysLogVo.java

@@ -0,0 +1,21 @@
+package com.diagbot.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2018/8/6 10:16
+ */
+@Getter
+@Setter
+public class SysLogVo {
+    private Date createDate;
+    private String ip;
+    private String method;
+    private String operation;
+    private String params;
+}

+ 89 - 0
log-service/src/main/java/com/diagbot/web/SysLogController.java

@@ -0,0 +1,89 @@
+package com.diagbot.web;
+
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.entity.SysLog;
+import com.diagbot.facade.SysLogFacade;
+import com.diagbot.vo.SysLogVo;
+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.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+@RestController
+@RequestMapping("/log")
+public class SysLogController {
+
+    @Autowired
+    private SysLogFacade sysLogFacade;
+
+    @ApiOperation(value = "添加日志", notes = "添加日志")
+    @PreAuthorize("hasRole('USER')")
+    @PostMapping("/add")
+    @SysLogger("postLog")
+    public RespDTO add(@RequestBody SysLogVo sysLogVo){
+        SysLog sysLog = new SysLog();
+        sysLog.setCreateDate(new Date());
+        sysLog.setIp(sysLogVo.getIp());
+        sysLog.setMethod(sysLogVo.getMethod());
+        sysLog.setOperation(sysLogVo.getOperation());
+        sysLog.setParams(sysLogVo.getParams());
+        return RespDTO.onSuc(sysLogFacade.insert(sysLog)?"添加成功":"添加失败");
+    }
+
+    @ApiOperation(value = "删除日志", notes = "删除日志")
+    @PreAuthorize("hasRole('USER')")
+    @DeleteMapping("/delete/{id}")
+    @SysLogger("deleteLog")
+    public RespDTO delete(@PathVariable(value = "id") Integer id){
+        return RespDTO.onSuc(sysLogFacade.deleteById(id)?"删除成功":"删除失败");
+    }
+
+    @ApiOperation(value = "修改日志", notes = "修改日志")
+    @PreAuthorize("hasRole('USER')")
+    @PostMapping("/update")
+    @SysLogger("updateLog")
+    public RespDTO update(@RequestBody SysLog student){
+        return RespDTO.onSuc(sysLogFacade.updateById(student)?"修改成功":"修改失败");
+    }
+
+    @ApiOperation(value = "获取日志列表", notes = "获取日志列表")
+    @PreAuthorize("hasRole('USER')")
+    @GetMapping("/list")
+    @SysLogger("listLog")
+    public RespDTO list(){
+        Wrapper<SysLog> wrapper = new QueryWrapper<>();
+        return RespDTO.onSuc(sysLogFacade.selectList(wrapper));
+    }
+
+    @ApiOperation(value = "获取日志翻页信息", notes = "获取日志翻页信息")
+    @PreAuthorize("hasRole('USER')")
+    @GetMapping("/page")
+    @SysLogger("pageLog")
+    public RespDTO page() {
+        IPage<SysLog> wrapper = new Page<>();
+        return RespDTO.onSuc(sysLogFacade.selectPage(wrapper, null));
+    }
+}
+

+ 9 - 0
log-service/src/main/resources/bootstrap.yml

@@ -0,0 +1,9 @@
+spring:
+  application:
+    name: logger-service
+  cloud:
+    config:
+      uri: http://localhost:8769
+      fail-fast: true
+  profiles:
+    active: dev

+ 16 - 0
log-service/src/main/resources/mapper/SysLogMapper.xml

@@ -0,0 +1,16 @@
+<?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.diagbot.mapper.SysLogMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.diagbot.entity.SysLog">
+        <id column="id" property="id" />
+        <result column="create_date" property="createDate" />
+        <result column="ip" property="ip" />
+        <result column="method" property="method" />
+        <result column="operation" property="operation" />
+        <result column="params" property="params" />
+        <result column="username" property="username" />
+    </resultMap>
+
+</mapper>

+ 9 - 0
log-service/src/main/resources/public.cert

@@ -0,0 +1,9 @@
+-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxXZWH/WgxW9eTT6AmPRo
+GFY3T5V1+F1458dcQFw0EZejjHuGwEeHvxcgl4059Me2B1xXTs3FDXTWQ5z19EtP
+3ITYtnFTo2cxhwxiwqN8ZqFdpq5Uac0mzjlYKcyGp8x6t+Nc2cv3D3Ul2VIbGvbP
+sQOeKvt3WxWwdpQ+q3RXjRUFQGiygSD7yuXHIUpcOsm4ZWDlUkjfwX1q4pjiwFfA
+Mq5xgkzPwolUKnI0NFnom3Th3i4oFXzUg2s6cEj7jL7YU35c2/9kE7WQPbeYhoSi
+XH2OwWgBk/2Ki6+Q0Yq/eAsXSBjp1jqh337vvKBk5ocPG1Imi8uTLIgYQCMwzvg+
+VQIDAQAB
+-----END PUBLIC KEY-----

+ 81 - 0
log-service/src/test/java/com/diagbot/CodeGeneration.java

@@ -0,0 +1,81 @@
+package com.diagbot;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+/**
+ * @Description: 代码生成器
+ * @author: gaodm
+ * @time: 2018/8/2 10:15
+ */
+public class CodeGeneration {
+
+    /**
+     *
+     * @Title: main
+     * @Description: 生成
+     * @param args
+     */
+    public static void main(String[] args) {
+        AutoGenerator mpg = new AutoGenerator();
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        gc.setOutputDir("E://code//logservice");
+        gc.setFileOverride(true);
+        gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
+        gc.setEnableCache(false);// XML 二级缓存
+        gc.setBaseResultMap(true);// XML ResultMap
+        gc.setBaseColumnList(false);// XML columList
+        gc.setAuthor("gaodm");// 作者
+
+        // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        gc.setControllerName("%sController");
+        gc.setServiceName("%sService");
+        gc.setServiceImplName("%sServiceImpl");
+        gc.setMapperName("%sMapper");
+        gc.setXmlName("%sMapper");
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setDbType(DbType.MYSQL);
+        dsc.setDriverName("com.mysql.jdbc.Driver");
+        dsc.setUsername("root");
+        dsc.setPassword("root");
+        dsc.setUrl("jdbc:mysql://127.0.0.1:3306/sys-log?useUnicode=true&characterEncoding=utf-8");
+        mpg.setDataSource(dsc);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+//        strategy.setTablePrefix(new String[] { "sys_" });// 此处可以修改为您的表前缀
+        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
+        strategy.setInclude(new String[] { "sys_log" }); // 需要生成的表
+
+        strategy.setSuperServiceClass(null);
+        strategy.setSuperServiceImplClass(null);
+        strategy.setSuperMapperClass(null);
+
+        mpg.setStrategy(strategy);
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setParent("com.diagbot");
+        pc.setController("web");
+        pc.setService("service");
+        pc.setServiceImpl("service.impl");
+        pc.setMapper("mapper");
+        pc.setEntity("entity");
+        pc.setXml("resources.mapper");
+        mpg.setPackageInfo(pc);
+
+        // 执行生成
+        mpg.execute();
+
+    }
+}

+ 16 - 0
log-service/src/test/java/com/diagbot/LogServiceApplicationTests.java

@@ -0,0 +1,16 @@
+package com.diagbot;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class LogServiceApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}

+ 99 - 0
pom.xml

@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>diagbotcloud</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <modules>
+        <module>eureka-server</module>
+        <module>config-server</module>
+        <module>gateway-service</module>
+        <module>uaa-service</module>
+        <module>user-service</module>
+        <module>log-service</module>
+        <module>common</module>
+    </modules>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.0.4.RELEASE</version>
+        <relativePath/>
+    </parent>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <java.version>1.8</java.version>
+        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
+        <mybatis-plus-boot-starter.version>3.0-gamma</mybatis-plus-boot-starter.version>
+        <mybatis-spring-boot.version>1.3.2</mybatis-spring-boot.version>
+        <druid.version>1.1.9</druid.version>
+        <swagger.version>2.9.2</swagger.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jolokia</groupId>
+            <artifactId>jolokia-core</artifactId>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <!-- mybatis-plus begin -->
+            <dependency>
+                <groupId>com.baomidou</groupId>
+                <artifactId>mybatis-plus-boot-starter</artifactId>
+                <version>${mybatis-plus-boot-starter.version}</version>
+            </dependency>
+            <!-- mybatis-plus end -->
+
+            <!-- 阿里巴巴druid数据库连接池 -->
+            <dependency>
+                <groupId>com.alibaba</groupId>
+                <artifactId>druid-spring-boot-starter</artifactId>
+                <version>${druid.version}</version>
+            </dependency>
+
+            <!--swagger-->
+            <dependency>
+                <groupId>io.springfox</groupId>
+                <artifactId>springfox-swagger2</artifactId>
+                <version>${swagger.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>io.springfox</groupId>
+                <artifactId>springfox-swagger-ui</artifactId>
+                <version>${swagger.version}</version>
+            </dependency>
+
+            <!-- springboot整合mybatis(核心就这一个) -->
+            <!-- 注意顺序,这个一定要放在最下面 -->
+            <dependency>
+                <groupId>org.mybatis.spring.boot</groupId>
+                <artifactId>mybatis-spring-boot-starter</artifactId>
+                <version>${mybatis-spring-boot.version}</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+</project>

+ 36 - 0
sql/sys-log.sql

@@ -0,0 +1,36 @@
+
+CREATE DATABASE  `sys-log` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
+
+use `sys-log`;
+
+/*
+Navicat MySQL Data Transfer
+
+Source Server         : SSSS
+Source Server Version : 50717
+Source Host           : localhost:3306
+Source Database       : sys-log
+
+Target Server Type    : MYSQL
+Target Server Version : 50717
+File Encoding         : 65001
+
+Date: 2017-07-13 09:10:09
+*/
+
+SET FOREIGN_KEY_CHECKS=0;
+
+-- ----------------------------
+-- Table structure for sys_log
+-- ----------------------------
+DROP TABLE IF EXISTS `sys_log`;
+CREATE TABLE `sys_log` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `create_date` datetime DEFAULT NULL,
+  `ip` varchar(255) DEFAULT NULL,
+  `method` varchar(255) DEFAULT NULL,
+  `operation` varchar(255) DEFAULT NULL,
+  `params` varchar(255) DEFAULT NULL,
+  `username` varchar(255) DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=267 DEFAULT CHARSET=utf8;

+ 50 - 0
sql/sys-user.sql

@@ -0,0 +1,50 @@
+
+CREATE DATABASE  `sys-user` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
+
+use `sys-user`;
+
+-- ----------------------------
+-- Table structure for role
+-- ----------------------------
+DROP TABLE IF EXISTS `role`;
+CREATE TABLE `role` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `name` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+
+-- ----------------------------
+-- Table structure for user
+-- ----------------------------
+DROP TABLE IF EXISTS `user`;
+CREATE TABLE `user` (
+  `id` bigint(20) NOT NULL AUTO_INCREMENT,
+  `password` varchar(255) DEFAULT NULL,
+  `username` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `UK_sb8bbouer5wak8vyiiy4pf2bx` (`username`)
+) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
+
+-- ----------------------------
+-- Table structure for user_role
+-- ----------------------------
+DROP TABLE IF EXISTS `user_role`;
+CREATE TABLE `user_role` (
+  `user_id` bigint(20) NOT NULL,
+  `role_id` bigint(20) NOT NULL,
+  KEY `FKa68196081fvovjhkek5m97n3y` (`role_id`),
+  KEY `FK859n2jvi8ivhui0rl0esws6o` (`user_id`),
+  CONSTRAINT `FK859n2jvi8ivhui0rl0esws6o` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`),
+  CONSTRAINT `FKa68196081fvovjhkek5m97n3y` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+INSERT INTO `user` VALUES ('1', '$2a$10$rlM./Q4dh5qXYmxFxUqkRetMPf6JewV/Hj/s4qBg/6U1.mzcue2oK', 'fzp');
+
+
+INSERT INTO `role` VALUES ('1', 'ROLE_USER');
+INSERT INTO `role` VALUES ('2', 'ROLE_ADMIN');
+
+INSERT INTO `user_role` VALUES ('1', '1');
+INSERT INTO `user_role` VALUES ('1', '2');
+

+ 25 - 0
uaa-service/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 107 - 0
uaa-service/pom.xml

@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>uaa-service</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>uaa-service</name>
+    <description>Uaa Service for Spring Boot</description>
+
+    <parent>
+        <groupId>com.diagbot</groupId>
+        <artifactId>diagbotcloud</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <java.version>1.8</java.version>
+    </properties>
+
+    <dependencies>
+        <!-- 配置-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-config</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+        </dependency>
+
+        <!--<dependency>-->
+            <!--<groupId>org.springframework.boot</groupId>-->
+            <!--<artifactId>spring-boot-starter-data-jpa</artifactId>-->
+        <!--</dependency>-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <!-- mybatis-plus begin -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>${mybatis-plus-boot-starter.version}</version>
+        </dependency>
+        <!-- mybatis-plus end -->
+
+        <!-- 阿里巴巴druid数据库连接池 -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+        </dependency>
+
+        <!-- springboot整合mybatis(核心就这一个) -->
+        <!-- 注意顺序,这个一定要放在最下面 -->
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>${mybatis-spring-boot.version}</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <configuration>
+                    <nonFilteredFileExtensions>
+                        <nonFilteredFileExtension>cert</nonFilteredFileExtension>
+                        <nonFilteredFileExtension>jks</nonFilteredFileExtension>
+                    </nonFilteredFileExtensions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 14 - 0
uaa-service/src/main/java/com/diagbot/UaaServiceApplication.java

@@ -0,0 +1,14 @@
+package com.diagbot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+
+@SpringBootApplication
+@EnableEurekaClient
+public class UaaServiceApplication {
+
+	public static void main(String[] args) {
+		SpringApplication.run(UaaServiceApplication.class, args);
+	}
+}

+ 41 - 0
uaa-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java

@@ -0,0 +1,41 @@
+package com.diagbot.config;
+
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import org.mybatis.spring.mapper.MapperScannerConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @Description: MybatisPlus配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:39
+ */
+@Configuration
+//@MapperScan("com.diagbot.mapper*")//这个注解,作用相当于下面的@Bean MapperScannerConfigurer,2者配置1份即可
+public class MybatisPlusConfig {
+
+    /**
+     * mybatis-plus分页插件<br>
+     * 文档:http://mp.baomidou.com<br>
+     */
+    @Bean
+    public PaginationInterceptor paginationInterceptor() {
+        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
+        // 开启 PageHelper 的支持
+        paginationInterceptor.setLocalPage(true);
+        return paginationInterceptor;
+    }
+
+    /**
+     * 相当于顶部的:
+     * {@code @MapperScan("com.diagbot.mapper*")}
+     * 这里可以扩展,比如使用配置文件来配置扫描Mapper的路径
+     */
+    @Bean
+    public MapperScannerConfigurer mapperScannerConfigurer() {
+        MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();
+        scannerConfigurer.setBasePackage("com.diagbot.mapper*");
+        return scannerConfigurer;
+    }
+
+}

+ 58 - 0
uaa-service/src/main/java/com/diagbot/config/OAuth2Config.java

@@ -0,0 +1,58 @@
+package com.diagbot.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
+import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
+import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
+import org.springframework.security.oauth2.provider.token.TokenStore;
+import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
+import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
+import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
+
+/**
+ * @Description: OAuth2授权认证配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:24
+ */
+@Configuration
+@EnableAuthorizationServer
+public class OAuth2Config extends AuthorizationServerConfigurerAdapter {
+    @Override
+    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
+        clients.inMemory()
+                .withClient("uaa-service")
+                .secret("{noop}123456")
+                .scopes("service")
+                .autoApprove(true)
+                .authorizedGrantTypes("implicit","refresh_token", "password", "authorization_code")
+                .accessTokenValiditySeconds(24*3600);//24小时过期
+    }
+
+    @Override
+    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
+        endpoints.tokenStore(tokenStore()).tokenEnhancer(jwtTokenEnhancer()).authenticationManager(authenticationManager);
+    }
+
+    @Autowired
+    @Qualifier("authenticationManagerBean")
+    private AuthenticationManager authenticationManager;
+
+    @Bean
+    public TokenStore tokenStore() {
+        return new JwtTokenStore(jwtTokenEnhancer());
+    }
+
+    @Bean
+    protected JwtAccessTokenConverter jwtTokenEnhancer() {
+        KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("diagbot-jwt.jks"), "diagbot123456".toCharArray());
+        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
+        converter.setKeyPair(keyStoreKeyFactory.getKeyPair("diagbot-jwt"));
+        return converter;
+    }
+}

+ 70 - 0
uaa-service/src/main/java/com/diagbot/config/WebSecurityConfig.java

@@ -0,0 +1,70 @@
+package com.diagbot.config;
+
+
+import com.diagbot.service.UserServiceDetail;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.factory.PasswordEncoderFactories;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.AuthenticationEntryPoint;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * @Description: WebSecurity配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:24
+ */
+@Configuration
+class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+
+    @Override
+    @Bean
+    public AuthenticationManager authenticationManagerBean() throws Exception {
+        return super.authenticationManagerBean();
+    }
+
+    @Override
+    protected void configure(HttpSecurity http) throws Exception {
+        //CSRF:因为不再依赖于Cookie,所以你就不需要考虑对CSRF(跨站请求伪造)的防范。
+        http
+            .csrf().disable()
+                .exceptionHandling()
+               // .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED))
+                .authenticationEntryPoint(new AuthenticationEntryPoint() {
+                    @Override
+                    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
+                        httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+                    }
+                })
+                .and()
+                .authorizeRequests()
+                .antMatchers("/**").authenticated()
+            .and()
+                .httpBasic();
+    }
+
+    @Bean
+    UserDetailsService userServiceDetail() {
+        return new UserServiceDetail();
+    }
+
+    @Bean
+    public PasswordEncoder passwordEncoder() {
+        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
+    }
+
+    @Override
+    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+        auth.userDetailsService(userServiceDetail()).passwordEncoder(passwordEncoder());
+    }
+}

+ 52 - 0
uaa-service/src/main/java/com/diagbot/entity/Role.java

@@ -0,0 +1,52 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import org.springframework.security.core.GrantedAuthority;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+public class Role implements GrantedAuthority, Serializable {
+
+	@TableId(value = "id", type = IdType.AUTO)
+	private Long id;
+	private String name;
+
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	@Override
+	public String toString() {
+		return "Role{" +
+				", id=" + id +
+				", name=" + name +
+				"}";
+	}
+
+	@Override
+	public String getAuthority() {
+		return name;
+	}
+}

+ 100 - 0
uaa-service/src/main/java/com/diagbot/entity/User.java

@@ -0,0 +1,100 @@
+package com.diagbot.entity;
+
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+public class User implements UserDetails, Serializable {
+	private static final long serialVersionUID = 1L;
+
+	@TableId(value = "id", type = IdType.AUTO)
+	private Long id;
+	private String password;
+	private String username;
+
+	private List<Role> authorities;
+
+	@Override
+	public String toString() {
+		return "User{" +
+				", id=" + id +
+				", password=" + password +
+				", username=" + username +
+				"}";
+	}
+
+
+	public User() {
+	}
+
+	public Long getId() {
+		return id;
+	}
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	@Override
+	public Collection<? extends GrantedAuthority> getAuthorities() {
+		return authorities;
+	}
+
+	public void setAuthorities(List<Role> authorities) {
+		this.authorities = authorities;
+	}
+
+	@Override
+	public String getUsername() {
+		return username;
+	}
+
+	public void setUsername(String username) {
+		this.username = username;
+	}
+
+	@Override
+	public String getPassword() {
+		return password;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+	@Override
+	public boolean isAccountNonExpired() {
+		return true;
+	}
+
+	@Override
+	public boolean isAccountNonLocked() {
+		return true;
+	}
+
+	@Override
+	public boolean isCredentialsNonExpired() {
+		return true;
+	}
+
+	@Override
+	public boolean isEnabled() {
+		return true;
+	}
+
+
+}

+ 16 - 0
uaa-service/src/main/java/com/diagbot/mapper/UserMapper.java

@@ -0,0 +1,16 @@
+package com.diagbot.mapper;
+
+import com.diagbot.entity.User;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+public interface UserMapper extends BaseMapper<User> {
+    User findByUsername(String username);
+}

+ 25 - 0
uaa-service/src/main/java/com/diagbot/service/UserServiceDetail.java

@@ -0,0 +1,25 @@
+package com.diagbot.service;
+
+
+import com.diagbot.mapper.UserMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description: 实现用户详细信息
+ * @author: gaodm
+ * @time: 2018/8/2 16:47
+ */
+@Service
+public class UserServiceDetail implements UserDetailsService {
+
+    @Autowired
+    private UserMapper userMapper;
+    @Override
+    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+        return userMapper.findByUsername(username);
+    }
+}

+ 12 - 0
uaa-service/src/main/resources/bootstrap.yml

@@ -0,0 +1,12 @@
+spring:
+  application:
+    name: uaa-service
+  cloud:
+    config:
+      uri: http://localhost:8769
+      fail-fast: true
+  profiles:
+      active: dev
+management:
+  security:
+    enabled: false

BIN
uaa-service/src/main/resources/diagbot-jwt.jks


+ 6 - 0
uaa-service/src/main/resources/logback-spring.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <include resource="org/springframework/boot/logging/logback/base.xml" />
+    <logger name="org.springframework.web" level="INFO"/>
+
+</configuration>

+ 29 - 0
uaa-service/src/main/resources/mapper/UserMapper.xml

@@ -0,0 +1,29 @@
+<?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.diagbot.mapper.UserMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.diagbot.entity.User">
+        <id column="id" property="id" />
+        <result column="password" property="password" />
+        <result column="username" property="username" />
+    </resultMap>
+
+
+    <resultMap id="userMap" type="com.diagbot.entity.User">
+        <id column="id" property="id" />
+        <result column="password" property="password" />
+        <result column="username" property="username" />
+        <collection property="authorities" ofType="com.diagbot.entity.Role">
+            <result column="name" property="name"/>
+        </collection>
+    </resultMap>
+
+    <select id="findByUsername" parameterType="java.lang.String" resultMap="userMap">
+		select u.*,r.name
+		from user u
+        LEFT JOIN user_role ur on u.id= ur.user_id
+        LEFT JOIN role r on ur.role_id=r.id
+        where username= #{username}
+	</select>
+</mapper>

+ 81 - 0
uaa-service/src/test/java/com/diagbot/CodeGeneration.java

@@ -0,0 +1,81 @@
+package com.diagbot;
+
+import com.baomidou.mybatisplus.annotation.DbType;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
+import com.baomidou.mybatisplus.generator.config.GlobalConfig;
+import com.baomidou.mybatisplus.generator.config.PackageConfig;
+import com.baomidou.mybatisplus.generator.config.StrategyConfig;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+
+/**
+ * @Description: 代码生成器
+ * @author: gaodm
+ * @time: 2018/8/2 10:15
+ */
+public class CodeGeneration {
+
+    /**
+     *
+     * @Title: main
+     * @Description: 生成
+     * @param args
+     */
+    public static void main(String[] args) {
+        AutoGenerator mpg = new AutoGenerator();
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        gc.setOutputDir("E://code//uaaservice");
+        gc.setFileOverride(true);
+        gc.setActiveRecord(false);// 不需要ActiveRecord特性的请改为false
+        gc.setEnableCache(false);// XML 二级缓存
+        gc.setBaseResultMap(true);// XML ResultMap
+        gc.setBaseColumnList(false);// XML columList
+        gc.setAuthor("gaodm");// 作者
+
+        // 自定义文件命名,注意 %s 会自动填充表实体属性!
+        gc.setControllerName("%sController");
+        gc.setServiceName("%sService");
+        gc.setServiceImplName("%sServiceImpl");
+        gc.setMapperName("%sMapper");
+        gc.setXmlName("%sMapper");
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+        dsc.setDbType(DbType.MYSQL);
+        dsc.setDriverName("com.mysql.jdbc.Driver");
+        dsc.setUsername("root");
+        dsc.setPassword("root");
+        dsc.setUrl("jdbc:mysql://127.0.0.1:3306/sys-user?useUnicode=true&characterEncoding=utf-8");
+        mpg.setDataSource(dsc);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+//        strategy.setTablePrefix(new String[] { "sys_" });// 此处可以修改为您的表前缀
+        strategy.setNaming(NamingStrategy.underline_to_camel);// 表名生成策略
+        strategy.setInclude(new String[] { "user","role" }); // 需要生成的表
+
+        strategy.setSuperServiceClass(null);
+        strategy.setSuperServiceImplClass(null);
+        strategy.setSuperMapperClass(null);
+
+        mpg.setStrategy(strategy);
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+        pc.setParent("com.diagbot");
+        pc.setController("web");
+        pc.setService("service");
+        pc.setServiceImpl("service.impl");
+        pc.setMapper("mapper");
+        pc.setEntity("entity");
+        pc.setXml("resources.mapper");
+        mpg.setPackageInfo(pc);
+
+        // 执行生成
+        mpg.execute();
+
+    }
+}

+ 16 - 0
uaa-service/src/test/java/com/diagbot/UaaServiceApplicationTests.java

@@ -0,0 +1,16 @@
+package com.diagbot;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class UaaServiceApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}

+ 25 - 0
user-service/.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/build/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/

+ 145 - 0
user-service/pom.xml

@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.diagbot</groupId>
+    <artifactId>user-service</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>user-service</name>
+    <description>User service for Spring Boot</description>
+
+    <parent>
+        <groupId>com.diagbot</groupId>
+        <artifactId>diagbotcloud</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.diagbot</groupId>
+            <artifactId>common</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+        </dependency>
+
+        <!-- 配置-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-config</artifactId>
+        </dependency>
+
+        <!-- 开启web-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <!-- 开启feign-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
+        </dependency>
+
+        <!-- dashboard -->
+        <!-- actuator-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <!--hystrix-dashboard-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
+        </dependency>
+        <!--hystrix -->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
+        </dependency>
+
+        <!-- zipkin-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-zipkin</artifactId>
+        </dependency>
+
+        <!--swagger-->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+        </dependency>
+        <!--database-->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.springframework.boot</groupId>-->
+            <!--<artifactId>spring-boot-starter-data-jpa</artifactId>-->
+        <!--</dependency>-->
+
+        <!--security-->
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-oauth2</artifactId>
+        </dependency>
+
+        <!-- mq -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+
+        <!-- mybatis-plus begin -->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>${mybatis-plus-boot-starter.version}</version>
+        </dependency>
+        <!-- mybatis-plus end -->
+
+        <!-- 阿里巴巴druid数据库连接池 -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid-spring-boot-starter</artifactId>
+        </dependency>
+
+        <!-- springboot整合mybatis(核心就这一个) -->
+        <!-- 注意顺序,这个一定要放在最下面 -->
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>${mybatis-spring-boot.version}</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>

+ 26 - 0
user-service/src/main/java/com/diagbot/UserServiceApplication.java

@@ -0,0 +1,26 @@
+package com.diagbot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+import org.springframework.cloud.netflix.hystrix.EnableHystrix;
+import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @Description: 用户服务启动类
+ * @author: gaodm
+ * @time: 2018/8/3 17:47
+ */
+@SpringBootApplication
+@EnableEurekaClient
+@EnableFeignClients
+@EnableHystrixDashboard
+@EnableHystrix
+public class UserServiceApplication {
+
+	public static void main(String[] args) {
+		SpringApplication.run(UserServiceApplication.class, args);
+	}
+
+}

+ 75 - 0
user-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java

@@ -0,0 +1,75 @@
+package com.diagbot.aop;
+
+import com.alibaba.fastjson.JSON;
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.entity.SysLog;
+import com.diagbot.facade.LoggerFacade;
+import com.diagbot.service.LoggerService;
+import com.diagbot.util.HttpUtils;
+import com.diagbot.util.UserUtils;
+import org.apache.commons.lang.StringUtils;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+
+/**
+ * @Description: 日志拦截切面
+ * @author: gaodm
+ * @time: 2018/8/2 13:36
+ */
+@Aspect
+@Component
+public class SysLoggerAspect {
+    @Autowired
+    private LoggerFacade loggerFacade;
+
+    @Pointcut("@annotation(com.diagbot.annotation.SysLogger)")
+    public void loggerPointCut() {
+
+    }
+
+    @Before("loggerPointCut()")
+    public void saveSysLog(JoinPoint joinPoint) {
+        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+        Method method = signature.getMethod();
+
+        SysLog sysLog = new SysLog();
+        SysLogger sysLogger = method.getAnnotation(SysLogger.class);
+        if(sysLogger != null){
+            //注解上的描述
+            sysLog.setOperation(sysLogger.value());
+        }
+        //请求的方法名
+        String className = joinPoint.getTarget().getClass().getName();
+        String methodName = signature.getName();
+        sysLog.setMethod(className + "." + methodName + "()");
+        //请求的参数
+        Object[] args = joinPoint.getArgs();
+        String params="";
+        for(Object o:args){
+            params+=JSON.toJSONString(o);
+        }
+        if(!StringUtils.isEmpty(params)) {
+            sysLog.setParams(params);
+        }
+        //设置IP地址
+        sysLog.setIp(HttpUtils.getIpAddress());
+        //用户名
+        String username = UserUtils.getCurrentPrinciple();
+        if(!StringUtils.isEmpty(username)) {
+            sysLog.setUsername(username);
+        }
+        sysLog.setCreateDate(new Date());
+        //保存系统日志
+        loggerFacade.log(sysLog);
+    }
+
+}
+

+ 25 - 0
user-service/src/main/java/com/diagbot/client/AuthServiceClient.java

@@ -0,0 +1,25 @@
+package com.diagbot.client;
+
+import com.diagbot.client.hystrix.AuthServiceHystrix;
+import com.diagbot.entity.JWT;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RequestParam;
+
+
+/**
+ * @Description: 请求认证授权服务器客户端
+ * @author: gaodm
+ * @time: 2018/8/2 13:37
+ */
+@FeignClient(value = "uaa-service",fallback =AuthServiceHystrix.class )
+public interface AuthServiceClient {
+
+    @PostMapping(value = "/oauth/token")
+    JWT getToken(@RequestHeader(value = "Authorization") String authorization, @RequestParam("grant_type") String type,
+                 @RequestParam("username") String username, @RequestParam("password") String password);
+}
+
+
+

+ 20 - 0
user-service/src/main/java/com/diagbot/client/hystrix/AuthServiceHystrix.java

@@ -0,0 +1,20 @@
+package com.diagbot.client.hystrix;
+
+
+import com.diagbot.client.AuthServiceClient;
+import com.diagbot.entity.JWT;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description: 请求认证授权服务器客户端(请求失败熔断)
+ * @author: gaodm
+ * @time: 2018/8/2 13:37
+ */
+@Component
+public class AuthServiceHystrix implements AuthServiceClient {
+    @Override
+    public JWT getToken(String authorization, String type, String username, String password) {
+        System.out.println("--------opps getToken hystrix---------");
+        return null;
+    }
+}

+ 15 - 0
user-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java

@@ -0,0 +1,15 @@
+package com.diagbot.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
+
+/**
+ * @Description: 安全配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:38
+ */
+@Configuration
+@EnableGlobalMethodSecurity(prePostEnabled = true)
+public class GlobalMethodSecurityConfiguration {
+
+}

+ 47 - 0
user-service/src/main/java/com/diagbot/config/JwtConfiguration.java

@@ -0,0 +1,47 @@
+package com.diagbot.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.security.oauth2.provider.token.TokenStore;
+import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
+import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
+import org.springframework.util.FileCopyUtils;
+
+import java.io.IOException;
+
+/**
+ * @Description: JWT配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:38
+ */
+@Configuration
+public class JwtConfiguration {
+    @Autowired
+    JwtAccessTokenConverter jwtAccessTokenConverter;
+
+    @Bean
+    @Qualifier("tokenStore")
+    public TokenStore tokenStore() {
+
+        System.out.println("Created JwtTokenStore");
+        return new JwtTokenStore(jwtAccessTokenConverter);
+    }
+
+    @Bean
+    protected JwtAccessTokenConverter jwtTokenEnhancer() {
+        JwtAccessTokenConverter converter =  new JwtAccessTokenConverter();
+        Resource resource = new ClassPathResource("public.cert");
+        String publicKey ;
+        try {
+            publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        converter.setVerifierKey(publicKey);
+        return converter;
+    }
+}

+ 41 - 0
user-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java

@@ -0,0 +1,41 @@
+package com.diagbot.config;
+
+import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import org.mybatis.spring.mapper.MapperScannerConfigurer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @Description: MybatisPlus配置类
+ * @author: gaodm
+ * @time: 2018/8/2 13:39
+ */
+@Configuration
+//@MapperScan("com.diagbot.mapper*")//这个注解,作用相当于下面的@Bean MapperScannerConfigurer,2者配置1份即可
+public class MybatisPlusConfig {
+
+    /**
+     * mybatis-plus分页插件<br>
+     * 文档:http://mp.baomidou.com<br>
+     */
+    @Bean
+    public PaginationInterceptor paginationInterceptor() {
+        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
+        // 开启 PageHelper 的支持
+        paginationInterceptor.setLocalPage(true);
+        return paginationInterceptor;
+    }
+
+    /**
+     * 相当于顶部的:
+     * {@code @MapperScan("com.diagbot.mapper*")}
+     * 这里可以扩展,比如使用配置文件来配置扫描Mapper的路径
+     */
+    @Bean
+    public MapperScannerConfigurer mapperScannerConfigurer() {
+        MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();
+        scannerConfigurer.setBasePackage("com.diagbot.mapper*");
+        return scannerConfigurer;
+    }
+
+}

+ 38 - 0
user-service/src/main/java/com/diagbot/config/RabbitConfig.java

@@ -0,0 +1,38 @@
+package com.diagbot.config;
+
+
+import org.springframework.amqp.core.Binding;
+import org.springframework.amqp.core.BindingBuilder;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.core.TopicExchange;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @Description: 消息配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:21
+ */
+@Configuration
+public class RabbitConfig {
+
+
+  public   final static String queueName = "spring-boot";
+
+    @Bean
+    Queue queue() {
+        return new Queue(queueName, false);
+    }
+
+    @Bean
+    TopicExchange exchange() {
+        return new TopicExchange("spring-boot-exchange");
+    }
+
+    @Bean
+    Binding binding(Queue queue, TopicExchange exchange) {
+        return BindingBuilder.bind(queue).to(exchange).with(queueName);
+    }
+
+
+}

+ 42 - 0
user-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java

@@ -0,0 +1,42 @@
+package com.diagbot.config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
+import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
+import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
+import org.springframework.security.oauth2.provider.token.TokenStore;
+
+/**
+ * @Description: 权限资源配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:21
+ */
+@Configuration
+@EnableResourceServer
+public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
+    Logger log = LoggerFactory.getLogger(ResourceServerConfiguration.class);
+
+    @Override
+    public void configure(HttpSecurity http) throws Exception {
+        http
+                .csrf().disable()
+                .authorizeRequests()
+                .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/user/login.*","/user/registry.*","/user/test.*","/druid.*").permitAll()
+                .antMatchers("/**").authenticated();
+//        .antMatchers("/**").permitAll();
+    }
+
+
+    @Override
+    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
+        log.info("Configuring ResourceServerSecurityConfigurer ");
+        resources.resourceId("user-service").tokenStore(tokenStore);
+    }
+
+    @Autowired
+    TokenStore tokenStore;
+}

+ 67 - 0
user-service/src/main/java/com/diagbot/config/SwaggerConfig.java

@@ -0,0 +1,67 @@
+package com.diagbot.config;
+
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.ParameterBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * @Description: Swagger配置类
+ * @author: gaodm
+ * @time: 2018/8/2 14:21
+ */
+@Configuration
+@EnableSwagger2
+public class SwaggerConfig {
+    /**
+     * 全局参数
+     *
+     * @return
+     */
+    private List<Parameter> parameter() {
+        List<Parameter> params = new ArrayList<>();
+        params.add(new ParameterBuilder().name("Authorization")
+                .description("Authorization Bearer token")
+                .modelRef(new ModelRef("string"))
+                .parameterType("header")
+                .required(false).build());
+        return params;
+    }
+
+
+    @Bean
+    public Docket sysApi() {
+        return new Docket(DocumentationType.SWAGGER_2)
+                .apiInfo(apiInfo())
+                .select()
+                .apis(RequestHandlerSelectors.basePackage("com.diagbot.web"))
+                .paths(PathSelectors.any())
+                .build().globalOperationParameters(parameter());
+                //.securitySchemes(newArrayList(oauth()))
+               // .securityContexts(newArrayList(securityContext()));
+    }
+
+    private ApiInfo apiInfo() {
+        return new ApiInfoBuilder()
+                .title(" user-service api ")
+                .description("user-service 微服务")
+                .termsOfServiceUrl("")
+                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

+ 29 - 0
user-service/src/main/java/com/diagbot/dto/LoginDTO.java

@@ -0,0 +1,29 @@
+package com.diagbot.dto;
+
+import com.diagbot.entity.User;
+
+/**
+ * @Description: 登录输出类
+ * @author: gaodm
+ * @time: 2018/8/2 14:22
+ */
+public class LoginDTO {
+    private User user;
+    private String token;
+
+    public User getUser() {
+        return user;
+    }
+
+    public void setUser(User user) {
+        this.user = user;
+    }
+
+    public String getToken() {
+        return token;
+    }
+
+    public void setToken(String token) {
+        this.token = token;
+    }
+}

+ 75 - 0
user-service/src/main/java/com/diagbot/entity/JWT.java

@@ -0,0 +1,75 @@
+package com.diagbot.entity;
+
+/**
+ * @Description: JWT实体类
+ * @author: gaodm
+ * @time: 2018/8/2 13:53
+ */
+public class JWT {
+    private String access_token;
+    private String token_type;
+    private String refresh_token;
+    private int expires_in;
+    private String scope;
+    private String jti;
+
+    public String getAccess_token() {
+        return access_token;
+    }
+
+    public void setAccess_token(String access_token) {
+        this.access_token = access_token;
+    }
+
+    public String getToken_type() {
+        return token_type;
+    }
+
+    public void setToken_type(String token_type) {
+        this.token_type = token_type;
+    }
+
+    public String getRefresh_token() {
+        return refresh_token;
+    }
+
+    public void setRefresh_token(String refresh_token) {
+        this.refresh_token = refresh_token;
+    }
+
+    public int getExpires_in() {
+        return expires_in;
+    }
+
+    public void setExpires_in(int expires_in) {
+        this.expires_in = expires_in;
+    }
+
+    public String getScope() {
+        return scope;
+    }
+
+    public void setScope(String scope) {
+        this.scope = scope;
+    }
+
+    public String getJti() {
+        return jti;
+    }
+
+    public void setJti(String jti) {
+        this.jti = jti;
+    }
+
+    @Override
+    public String toString() {
+        return "JWT{" +
+                "access_token='" + access_token + '\'' +
+                ", token_type='" + token_type + '\'' +
+                ", refresh_token='" + refresh_token + '\'' +
+                ", expires_in=" + expires_in +
+                ", scope='" + scope + '\'' +
+                ", jti='" + jti + '\'' +
+                '}';
+    }
+}

+ 82 - 0
user-service/src/main/java/com/diagbot/entity/SysLog.java

@@ -0,0 +1,82 @@
+package com.diagbot.entity;
+
+import java.util.Date;
+
+/**
+ * @Description: 日志实体类
+ * @author: gaodm
+ * @time: 2018/8/2 13:35
+ */
+public class SysLog {
+
+    private Long id;
+    //用户名
+    private String username;
+    //用户操作
+    private String operation;
+    //请求方法
+    private String method;
+    //请求参数
+    private String params;
+    //IP地址
+    private String ip;
+    //创建时间
+    private Date createDate;
+
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    public String getOperation() {
+        return operation;
+    }
+
+    public void setOperation(String operation) {
+        this.operation = operation;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    public String getParams() {
+        return params;
+    }
+
+    public void setParams(String params) {
+        this.params = params;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public Date getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(Date createDate) {
+        this.createDate = createDate;
+    }
+}

+ 57 - 0
user-service/src/main/java/com/diagbot/entity/User.java

@@ -0,0 +1,57 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author gaodm
+ * @since 2018-08-02
+ */
+public class User implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+    private String password;
+    private String username;
+
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    @Override
+    public String toString() {
+        return "User{" +
+        ", id=" + id +
+        ", password=" + password +
+        ", username=" + username +
+        "}";
+    }
+}

+ 30 - 0
user-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java

@@ -0,0 +1,30 @@
+package com.diagbot.exception;
+
+import com.diagbot.dto.RespDTO;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+
+/**
+ * @Description: 错误通用处理
+ * @author: gaodm
+ * @time: 2018/8/2 14:22
+ */
+@ControllerAdvice
+@ResponseBody
+public class CommonExceptionHandler {
+
+    @ExceptionHandler(CommonException.class)
+    public ResponseEntity<RespDTO> handleException(Exception e) {
+        RespDTO resp = new RespDTO();
+        CommonException taiChiException = (CommonException) e;
+        resp.code = taiChiException.getCode();
+        resp.msg = e.getMessage();
+
+        return new ResponseEntity(resp, HttpStatus.OK);
+    }
+
+}

+ 0 - 0
user-service/src/main/java/com/diagbot/facade/LoggerFacade.java


Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.