Browse Source

+bi服务,互动反馈,整体管理,医疗知识管理系统框架

gaodm 6 years atrás
parent
commit
a1718e110d
100 changed files with 4543 additions and 1 deletions
  1. 74 0
      bi-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java
  2. 25 0
      bi-service/src/main/java/com/diagbot/client/UserServiceClient.java
  3. 23 0
      bi-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java
  4. 15 0
      bi-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java
  5. 47 0
      bi-service/src/main/java/com/diagbot/config/JwtConfiguration.java
  6. 41 0
      bi-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  7. 38 0
      bi-service/src/main/java/com/diagbot/config/RabbitConfig.java
  8. 42 0
      bi-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java
  9. 67 0
      bi-service/src/main/java/com/diagbot/config/SwaggerConfig.java
  10. 103 0
      bi-service/src/main/java/com/diagbot/entity/SysLog.java
  11. 37 0
      bi-service/src/main/java/com/diagbot/entity/User.java
  12. 30 0
      bi-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java
  13. 13 0
      bi-service/src/main/java/com/diagbot/facade/SysLogFacade.java
  14. 16 0
      bi-service/src/main/java/com/diagbot/mapper/SysLogMapper.java
  15. 18 0
      bi-service/src/main/java/com/diagbot/service/SysLogService.java
  16. 31 0
      bi-service/src/main/java/com/diagbot/service/impl/SysLogServiceImpl.java
  17. 51 0
      bi-service/src/main/java/com/diagbot/util/BeanUtil.java
  18. 92 0
      bi-service/src/main/java/com/diagbot/util/EntityUtil.java
  19. 97 0
      bi-service/src/main/java/com/diagbot/util/HttpUtils.java
  20. 81 0
      bi-service/src/main/java/com/diagbot/util/UserUtils.java
  21. 21 0
      bi-service/src/main/java/com/diagbot/vo/SysLogVo.java
  22. 89 0
      bi-service/src/main/java/com/diagbot/web/SysLogController.java
  23. 9 0
      bi-service/src/main/resources/bootstrap.yml
  24. 16 0
      bi-service/src/main/resources/mapper/SysLogMapper.xml
  25. 9 0
      bi-service/src/main/resources/public.cert
  26. 81 0
      bi-service/src/test/java/com/diagbot/CodeGeneration.java
  27. 101 0
      config-server/src/main/resources/shared/bi-service-dev.yml
  28. 101 0
      config-server/src/main/resources/shared/diagbotman-service-dev.yml
  29. 101 0
      config-server/src/main/resources/shared/feedback-service-dev.yml
  30. 21 1
      config-server/src/main/resources/shared/gateway-service-dev.yml
  31. 101 0
      config-server/src/main/resources/shared/knowledge-service-dev.yml
  32. 74 0
      diagbotman-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java
  33. 25 0
      diagbotman-service/src/main/java/com/diagbot/client/UserServiceClient.java
  34. 23 0
      diagbotman-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java
  35. 15 0
      diagbotman-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java
  36. 47 0
      diagbotman-service/src/main/java/com/diagbot/config/JwtConfiguration.java
  37. 41 0
      diagbotman-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  38. 38 0
      diagbotman-service/src/main/java/com/diagbot/config/RabbitConfig.java
  39. 42 0
      diagbotman-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java
  40. 67 0
      diagbotman-service/src/main/java/com/diagbot/config/SwaggerConfig.java
  41. 103 0
      diagbotman-service/src/main/java/com/diagbot/entity/SysLog.java
  42. 37 0
      diagbotman-service/src/main/java/com/diagbot/entity/User.java
  43. 30 0
      diagbotman-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java
  44. 13 0
      diagbotman-service/src/main/java/com/diagbot/facade/SysLogFacade.java
  45. 16 0
      diagbotman-service/src/main/java/com/diagbot/mapper/SysLogMapper.java
  46. 18 0
      diagbotman-service/src/main/java/com/diagbot/service/SysLogService.java
  47. 31 0
      diagbotman-service/src/main/java/com/diagbot/service/impl/SysLogServiceImpl.java
  48. 51 0
      diagbotman-service/src/main/java/com/diagbot/util/BeanUtil.java
  49. 92 0
      diagbotman-service/src/main/java/com/diagbot/util/EntityUtil.java
  50. 97 0
      diagbotman-service/src/main/java/com/diagbot/util/HttpUtils.java
  51. 81 0
      diagbotman-service/src/main/java/com/diagbot/util/UserUtils.java
  52. 21 0
      diagbotman-service/src/main/java/com/diagbot/vo/SysLogVo.java
  53. 89 0
      diagbotman-service/src/main/java/com/diagbot/web/SysLogController.java
  54. 9 0
      diagbotman-service/src/main/resources/bootstrap.yml
  55. 16 0
      diagbotman-service/src/main/resources/mapper/SysLogMapper.xml
  56. 9 0
      diagbotman-service/src/main/resources/public.cert
  57. 81 0
      diagbotman-service/src/test/java/com/diagbot/CodeGeneration.java
  58. 74 0
      feedback-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java
  59. 25 0
      feedback-service/src/main/java/com/diagbot/client/UserServiceClient.java
  60. 23 0
      feedback-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java
  61. 15 0
      feedback-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java
  62. 47 0
      feedback-service/src/main/java/com/diagbot/config/JwtConfiguration.java
  63. 41 0
      feedback-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  64. 38 0
      feedback-service/src/main/java/com/diagbot/config/RabbitConfig.java
  65. 42 0
      feedback-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java
  66. 67 0
      feedback-service/src/main/java/com/diagbot/config/SwaggerConfig.java
  67. 103 0
      feedback-service/src/main/java/com/diagbot/entity/SysLog.java
  68. 37 0
      feedback-service/src/main/java/com/diagbot/entity/User.java
  69. 30 0
      feedback-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java
  70. 13 0
      feedback-service/src/main/java/com/diagbot/facade/SysLogFacade.java
  71. 16 0
      feedback-service/src/main/java/com/diagbot/mapper/SysLogMapper.java
  72. 18 0
      feedback-service/src/main/java/com/diagbot/service/SysLogService.java
  73. 31 0
      feedback-service/src/main/java/com/diagbot/service/impl/SysLogServiceImpl.java
  74. 51 0
      feedback-service/src/main/java/com/diagbot/util/BeanUtil.java
  75. 92 0
      feedback-service/src/main/java/com/diagbot/util/EntityUtil.java
  76. 97 0
      feedback-service/src/main/java/com/diagbot/util/HttpUtils.java
  77. 81 0
      feedback-service/src/main/java/com/diagbot/util/UserUtils.java
  78. 21 0
      feedback-service/src/main/java/com/diagbot/vo/SysLogVo.java
  79. 89 0
      feedback-service/src/main/java/com/diagbot/web/SysLogController.java
  80. 9 0
      feedback-service/src/main/resources/bootstrap.yml
  81. 16 0
      feedback-service/src/main/resources/mapper/SysLogMapper.xml
  82. 9 0
      feedback-service/src/main/resources/public.cert
  83. 81 0
      feedback-service/src/test/java/com/diagbot/CodeGeneration.java
  84. 74 0
      knowledge-service/src/main/java/com/diagbot/aop/SysLoggerAspect.java
  85. 25 0
      knowledge-service/src/main/java/com/diagbot/client/UserServiceClient.java
  86. 23 0
      knowledge-service/src/main/java/com/diagbot/client/hystrix/UserServiceHystrix.java
  87. 15 0
      knowledge-service/src/main/java/com/diagbot/config/GlobalMethodSecurityConfiguration.java
  88. 47 0
      knowledge-service/src/main/java/com/diagbot/config/JwtConfiguration.java
  89. 41 0
      knowledge-service/src/main/java/com/diagbot/config/MybatisPlusConfig.java
  90. 38 0
      knowledge-service/src/main/java/com/diagbot/config/RabbitConfig.java
  91. 42 0
      knowledge-service/src/main/java/com/diagbot/config/ResourceServerConfiguration.java
  92. 67 0
      knowledge-service/src/main/java/com/diagbot/config/SwaggerConfig.java
  93. 103 0
      knowledge-service/src/main/java/com/diagbot/entity/SysLog.java
  94. 37 0
      knowledge-service/src/main/java/com/diagbot/entity/User.java
  95. 30 0
      knowledge-service/src/main/java/com/diagbot/exception/CommonExceptionHandler.java
  96. 13 0
      knowledge-service/src/main/java/com/diagbot/facade/SysLogFacade.java
  97. 16 0
      knowledge-service/src/main/java/com/diagbot/mapper/SysLogMapper.java
  98. 18 0
      knowledge-service/src/main/java/com/diagbot/service/SysLogService.java
  99. 31 0
      knowledge-service/src/main/java/com/diagbot/service/impl/SysLogServiceImpl.java
  100. 0 0
      knowledge-service/src/main/java/com/diagbot/util/BeanUtil.java

+ 74 - 0
bi-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
bi-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
bi-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
bi-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
bi-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
bi-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
bi-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
bi-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
bi-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(" bi-service api ")
+                .description("bi-service 微服务")
+                .termsOfServiceUrl("")
+                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

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

@@ -0,0 +1,103 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+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
bi-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;
+    }
+}

+ 30 - 0
bi-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);
+    }
+
+}

+ 13 - 0
bi-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
bi-service/src/main/java/com/diagbot/mapper/SysLogMapper.java

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

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

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

+ 31 - 0
bi-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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.config.RabbitConfig;
+import com.diagbot.entity.SysLog;
+import com.diagbot.mapper.SysLogMapper;
+import com.diagbot.service.SysLogService;
+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
bi-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
bi-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
bi-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
bi-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
bi-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
bi-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
bi-service/src/main/resources/bootstrap.yml

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

+ 16 - 0
bi-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
bi-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
bi-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//biservice");
+        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();
+
+    }
+}

+ 101 - 0
config-server/src/main/resources/shared/bi-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
+
+server:
+  port: 8841
+
+# 驱动配置信息
+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

+ 101 - 0
config-server/src/main/resources/shared/diagbotman-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
+
+server:
+  port: 8811
+
+# 驱动配置信息
+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

+ 101 - 0
config-server/src/main/resources/shared/feedback-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
+
+server:
+  port: 8831
+
+# 驱动配置信息
+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

+ 21 - 1
config-server/src/main/resources/shared/gateway-service-dev.yml

@@ -21,11 +21,31 @@ zuul:
       serviceId: user-service
       sensitiveHeaders:
 
-    blog-service:
+    logger-service:
       path: /logapi/**
       serviceId: logger-service
       sensitiveHeaders:
 
+    bi-service:
+      path: /biapi/**
+      serviceId: bi-service
+      sensitiveHeaders:
+
+    diagbotman-service:
+      path: /diagbotmanapi/**
+      serviceId: diagbotman-service
+      sensitiveHeaders:
+
+    feedback-service:
+      path: /feedbackapi/**
+      serviceId: feedback-service
+      sensitiveHeaders:
+
+    knowledge-service:
+      path: /knowledgeapi/**
+      serviceId: knowledge-service
+      sensitiveHeaders:
+
 server:
   port: 5000
 

+ 101 - 0
config-server/src/main/resources/shared/knowledge-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
+
+server:
+  port: 8821
+
+# 驱动配置信息
+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

+ 74 - 0
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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(" diagbotman-service api ")
+                .description("diagbotman-service 微服务")
+                .termsOfServiceUrl("")
+                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

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

@@ -0,0 +1,103 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+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
diagbotman-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;
+    }
+}

+ 30 - 0
diagbotman-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);
+    }
+
+}

+ 13 - 0
diagbotman-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
diagbotman-service/src/main/java/com/diagbot/mapper/SysLogMapper.java

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

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

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

+ 31 - 0
diagbotman-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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.config.RabbitConfig;
+import com.diagbot.entity.SysLog;
+import com.diagbot.mapper.SysLogMapper;
+import com.diagbot.service.SysLogService;
+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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-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
diagbotman-service/src/main/resources/bootstrap.yml

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

+ 16 - 0
diagbotman-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
diagbotman-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
diagbotman-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//diagbotmanservice");
+        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();
+
+    }
+}

+ 74 - 0
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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(" feedback-service api ")
+                .description("feedback-service 微服务")
+                .termsOfServiceUrl("")
+                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

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

@@ -0,0 +1,103 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+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
feedback-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;
+    }
+}

+ 30 - 0
feedback-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);
+    }
+
+}

+ 13 - 0
feedback-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
feedback-service/src/main/java/com/diagbot/mapper/SysLogMapper.java

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

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

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

+ 31 - 0
feedback-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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.config.RabbitConfig;
+import com.diagbot.entity.SysLog;
+import com.diagbot.mapper.SysLogMapper;
+import com.diagbot.service.SysLogService;
+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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-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
feedback-service/src/main/resources/bootstrap.yml

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

+ 16 - 0
feedback-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
feedback-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
feedback-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//feedbackservice");
+        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();
+
+    }
+}

+ 74 - 0
knowledge-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
knowledge-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
knowledge-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
knowledge-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
knowledge-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
knowledge-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
knowledge-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
knowledge-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
knowledge-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("knowledge-service api ")
+                .description("knowledge-service 微服务")
+                .termsOfServiceUrl("")
+                .contact("diagbot")
+                .version("1.0")
+                .build();
+    }
+
+}

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

@@ -0,0 +1,103 @@
+package com.diagbot.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+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
knowledge-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;
+    }
+}

+ 30 - 0
knowledge-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);
+    }
+
+}

+ 13 - 0
knowledge-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
knowledge-service/src/main/java/com/diagbot/mapper/SysLogMapper.java

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

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

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

+ 31 - 0
knowledge-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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.config.RabbitConfig;
+import com.diagbot.entity.SysLog;
+import com.diagbot.mapper.SysLogMapper;
+import com.diagbot.service.SysLogService;
+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));
+    }
+}

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


Some files were not shown because too many files changed in this diff