wei 5 년 전
부모
커밋
d8180e2ef9
31개의 변경된 파일590개의 추가작업 그리고 307개의 파일을 삭제
  1. 10 0
      .idea/.gitignore
  2. 1 1
      base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/FeignConfigure.java
  3. 59 0
      base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/RibbonConfig.java
  4. 18 0
      base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/RibbonProperties.java
  5. 22 0
      base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/vo/EagerLoad.java
  6. 3 1
      base-springframework/base-springframework-cloud/src/main/resources/META-INF/spring.factories
  7. 11 2
      base-springframework/base-springframework-cloud/src/main/resources/application-cloud.yml
  8. 0 38
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/FastJsonConverter.java
  9. 48 0
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/MappingJacksonConverter.java
  10. 0 37
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/ParameterFilter.java
  11. 0 198
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/ParameterRequestWrapper.java
  12. 28 0
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/StringWithoutSpaceDeserializer.java
  13. 16 3
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/log/config/LogProperty.java
  14. 9 1
      base-springframework/base-springframework-core/src/main/resources/application-common.yml
  15. 1 1
      base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/config/MybatisPlusConfig.java
  16. 3 3
      base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/constants/GeneratorParam.java
  17. 1 1
      base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/env/InitializeCustomConfiguration.java
  18. 5 4
      base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/generator/Generator.java
  19. 1 1
      base-springframework/base-springframework-mysql/src/main/resources/META-INF/spring.factories
  20. 1 1
      base-springframework/base-springframework-mysql/src/main/resources/application-mysql.yml
  21. 53 0
      base-springframework/base-springframework-redis/pom.xml
  22. 45 0
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/config/RedisConfig.java
  23. 85 0
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/env/InitializeCustomConfiguration.java
  24. 57 0
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/utils/RedisLock.java
  25. 5 0
      base-springframework/base-springframework-redis/src/main/resources/META-INF/spring.factories
  26. 16 0
      base-springframework/base-springframework-redis/src/main/resources/application-redis.yml
  27. 1 6
      base-springframework/pom.xml
  28. 8 2
      wei-user/wei-user-app/pom.xml
  29. 17 5
      wei-user/wei-user-app/src/main/java/com/wei/user/controller/UserController.java
  30. 59 0
      wei-user/wei-user-app/src/main/java/com/wei/user/vo/UserVO.java
  31. 7 2
      wei-user/wei-user-app/src/main/resources/bootstrap.yml

+ 10 - 0
.idea/.gitignore

@@ -0,0 +1,10 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+/compiler.xml
+/encodings.xml

+ 1 - 1
base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/FeignConfigure.java

@@ -5,8 +5,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Configuration;
 
 
 @Data
 @Data
-@ConfigurationProperties(prefix = "spring.cloud.feign")
 @Configuration
 @Configuration
+@ConfigurationProperties(prefix = "spring.cloud.feign")
 public class FeignConfigure {
 public class FeignConfigure {
 
 
     /**
     /**

+ 59 - 0
base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/RibbonConfig.java

@@ -0,0 +1,59 @@
+package com.wei.base.springframework.cloud.config;
+
+import com.google.common.collect.Lists;
+import com.wei.base.springframework.cloud.vo.EagerLoad;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.cloud.client.ServiceInstance;
+import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient;
+import org.springframework.cloud.netflix.ribbon.RibbonEagerLoadProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.util.List;
+
+@Configuration
+public class RibbonConfig {
+
+    @Autowired
+    private ConsulDiscoveryClient consulDiscoveryClient;
+
+    @Autowired
+    private RibbonEagerLoadProperties ribbonEagerLoadProperties;
+
+    @Autowired
+    private RibbonProperties ribbonProperties;
+
+    @Bean
+    @ConditionalOnProperty("ribbon.eager-load.enabled")
+    public void autoEagerLoad() {
+        //判断是否需要自动加载
+        EagerLoad eagerLoad = ribbonProperties.getEagerLoad();
+        if (!eagerLoad.getAutoEnabled()) {
+            return;
+        }
+
+
+        List<ServiceInstance> serviceInstances = consulDiscoveryClient.getAllInstances();
+        List<String> clients = Lists.newArrayListWithCapacity(serviceInstances.size());
+
+        List<String> excludes = Lists.newArrayList();
+        if (eagerLoad != null) {
+            excludes = eagerLoad.getExcludes();
+        }
+
+        for (ServiceInstance serviceInstance : serviceInstances) {
+            String serviceId = serviceInstance.getServiceId();
+            if (CollectionUtils.isNotEmpty(excludes)) {
+                if (excludes.contains(serviceId)) {
+                    continue;
+                }
+            }
+
+            clients.add(serviceId);
+        }
+
+        ribbonEagerLoadProperties.setClients(clients);
+    }
+}

+ 18 - 0
base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/RibbonProperties.java

@@ -0,0 +1,18 @@
+package com.wei.base.springframework.cloud.config;
+
+import com.wei.base.springframework.cloud.vo.EagerLoad;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.Serializable;
+
+@Data
+@Configuration
+@ConfigurationProperties(prefix = "ribbon")
+public class RibbonProperties implements Serializable {
+
+    private static final long serialVersionUID = -2085296475361063649L;
+
+    private EagerLoad eagerLoad;
+}

+ 22 - 0
base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/vo/EagerLoad.java

@@ -0,0 +1,22 @@
+package com.wei.base.springframework.cloud.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+public class EagerLoad implements Serializable {
+
+    private static final long serialVersionUID = 6222379748331032436L;
+
+    /**
+     * 需要排除的服务
+     */
+    private Boolean autoEnabled = Boolean.FALSE;
+
+    /**
+     * 需要排除的服务
+     */
+    private List<String> excludes;
+}

+ 3 - 1
base-springframework/base-springframework-cloud/src/main/resources/META-INF/spring.factories

@@ -1,7 +1,9 @@
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
     com.wei.base.springframework.cloud.config.FeignConfigure,\
     com.wei.base.springframework.cloud.config.FeignConfigure,\
     com.wei.base.springframework.cloud.feign.FeignInterceptor,\
     com.wei.base.springframework.cloud.feign.FeignInterceptor,\
-    com.wei.base.springframework.cloud.feign.FeignDecoder
+    com.wei.base.springframework.cloud.feign.FeignDecoder,\
+    com.wei.base.springframework.cloud.config.RibbonConfig,\
+    com.wei.base.springframework.cloud.config.RibbonProperties
 
 
 org.springframework.boot.env.EnvironmentPostProcessor=\
 org.springframework.boot.env.EnvironmentPostProcessor=\
     com.wei.base.springframework.cloud.env.InitializeCustomConfiguration
     com.wei.base.springframework.cloud.env.InitializeCustomConfiguration

+ 11 - 2
base-springframework/base-springframework-cloud/src/main/resources/application-cloud.yml

@@ -6,7 +6,16 @@ spring:
         enabled: true
         enabled: true
         # 表示consul上面文件的格式 有四种 yaml properties key_value files
         # 表示consul上面文件的格式 有四种 yaml properties key_value files
         format: yaml
         format: yaml
-        prefix: config/${spring.profiles.active}
+        prefix: config/${spring.profiles.active:}
         data-key: application
         data-key: application
       discovery:
       discovery:
-        prefer-ip-address: true
+        prefer-ip-address: true
+        health-check-path: ${server.servlet.context-path:}/actuator/health
+
+ribbon:
+  eager-load:
+    enabled: true
+    # 是否自动加载
+    autoEnabled: true
+    # 需要过滤加载的服务
+    excludes: consul

+ 0 - 38
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/FastJsonConverter.java

@@ -1,38 +0,0 @@
-package com.wei.base.springframework.core.http.converter;
-
-import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.alibaba.fastjson.support.config.FastJsonConfig;
-import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.wei.base.springframework.core.web.config.ResponseHandlerConfigure;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.MediaType;
-
-@Configuration
-public class FastJsonConverter {
-
-    @Autowired
-    private ResponseHandlerConfigure responseHandlerConfigure;
-
-    @Bean
-    public HttpMessageConverters configureMessageConverters() {
-        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
-
-        FastJsonConfig fastJsonConfig = new FastJsonConfig();
-        fastJsonConfig.setCharset(Charsets.UTF_8);
-        fastJsonConfig.setDateFormat(responseHandlerConfigure.getDateFormat());
-
-        // null值是否返回,默认为不返回
-        if (responseHandlerConfigure.getIsWriteMapNullValue()) {
-            fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
-        }
-
-        fastConverter.setFastJsonConfig(fastJsonConfig);
-        fastConverter.setSupportedMediaTypes(Lists.newArrayList(MediaType.APPLICATION_JSON));
-        return new HttpMessageConverters(fastConverter);
-    }
-}

+ 48 - 0
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/MappingJacksonConverter.java

@@ -0,0 +1,48 @@
+package com.wei.base.springframework.core.http.converter;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import com.wei.base.springframework.core.web.config.ResponseHandlerConfigure;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+
+import java.text.SimpleDateFormat;
+
+@Configuration
+public class MappingJacksonConverter {
+
+    @Autowired
+    private ResponseHandlerConfigure responseHandlerConfigure;
+
+    @Bean
+    public MappingJackson2HttpMessageConverter configureMessageConverters() {
+        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
+        //设置日期格式
+        ObjectMapper objectMapper = new ObjectMapper();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(responseHandlerConfigure.getDateFormat());
+        objectMapper.setDateFormat(simpleDateFormat);
+
+        // null值是否返回,默认为不返回
+        if (responseHandlerConfigure.getIsWriteMapNullValue()) {
+            objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+        }
+
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(String.class, new StringWithoutSpaceDeserializer(String.class));
+        objectMapper.registerModule(module);
+
+        //在反序列化时忽略在 json 中存在但 Java 对象不存在的属性
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        mappingJackson2HttpMessageConverter.setObjectMapper(objectMapper);
+        mappingJackson2HttpMessageConverter.setDefaultCharset(Charsets.UTF_8);
+        mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Lists.newArrayList(MediaType.APPLICATION_JSON));
+        return mappingJackson2HttpMessageConverter;
+    }
+}

+ 0 - 37
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/ParameterFilter.java

@@ -1,37 +0,0 @@
-package com.wei.base.springframework.core.http.converter;
-
-import org.springframework.stereotype.Component;
-
-import javax.servlet.*;
-import javax.servlet.annotation.WebFilter;
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-
-/**
- * 入参拦截器
- *
- * @author : weierming
- * @date : 2020/7/14
- */
-@Component
-@WebFilter(urlPatterns = "/**", filterName = "ParamsFilter", dispatcherTypes = DispatcherType.REQUEST)
-public class ParameterFilter implements Filter {
-
-    @Override
-    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
-            throws IOException, ServletException {
-        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
-        ParameterRequestWrapper parmsRequest = new ParameterRequestWrapper(httpServletRequest);
-        filterChain.doFilter(parmsRequest, response);
-    }
-
-    @Override
-    public void destroy() {
-
-    }
-
-    @Override
-    public void init(FilterConfig arg0) throws ServletException {
-
-    }
-}

+ 0 - 198
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/ParameterRequestWrapper.java

@@ -1,198 +0,0 @@
-package com.wei.base.springframework.core.http.converter;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.google.common.base.Charsets;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.wei.base.springframework.util.StringUtil;
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.io.IOUtils;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-
-import javax.servlet.ReadListener;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * 请求参数处理器
- *
- * @author : weierming
- * @date : 2020/7/14
- */
-public class ParameterRequestWrapper extends HttpServletRequestWrapper {
-
-    private Map<String, String[]> params = Maps.newHashMap();
-
-    private static final String CHARSET_NAME = Charsets.UTF_8.name();
-
-    public ParameterRequestWrapper(HttpServletRequest request) {
-        // 将request交给父类,以便于调用对应方法的时候,将其输出,其实父亲类的实现方式和第一种new的方式类似
-        super(request);
-        // 将参数表,赋予给当前的Map以便于持有request中的参数
-        Map<String, String[]> requestMap = request.getParameterMap();
-        params.putAll(requestMap);
-        //
-        modifyParameterValues();
-    }
-
-    /**
-     * 重写getInputStream方法 post类型的请求参数必须通过流才能获取到值
-     */
-    @Override
-    public ServletInputStream getInputStream() throws IOException {
-        // 非json类型,直接返回
-        try {
-            if (!super.getHeader(HttpHeaders.CONTENT_TYPE).equalsIgnoreCase(MediaType.APPLICATION_JSON_VALUE)) {
-                return super.getInputStream();
-            }
-
-            // 为空,直接返回
-            String json = IOUtils.toString(super.getInputStream(), CHARSET_NAME);
-            if (StringUtil.isEmpty(json)) {
-                return super.getInputStream();
-            }
-
-            ByteArrayInputStream bis = null;
-            try {
-                Map<String, Object> map = JSON.parseObject(json);
-                mapTrim(map);
-
-                bis = new ByteArrayInputStream(JSON.toJSONString(map).getBytes(CHARSET_NAME));
-            } catch (Exception e) {
-                JSONArray jsonArray = JSON.parseArray(json);
-                if (jsonArray.isEmpty()) {
-                    bis = new ByteArrayInputStream(JSON.toJSONString(jsonArray).getBytes(CHARSET_NAME));
-                    return new MyServletInputStream(bis);
-                }
-
-                List<Map<String, Object>> list = Lists.newArrayListWithCapacity(jsonArray.size());
-                jsonArray.stream().forEach(vo -> {
-                    Map<String, Object> map = (Map<String, Object>) vo;
-                    mapTrim(map);
-
-                    list.add(map);
-                });
-
-                bis = new ByteArrayInputStream(JSON.toJSONString(list).getBytes(CHARSET_NAME));
-            }
-
-            return new MyServletInputStream(bis);
-        } catch (Exception e) {
-            return super.getInputStream();
-        }
-    }
-
-    /**
-     * map value去空格
-     *
-     * @param map
-     */
-    private void mapTrim(Map<String, Object> map) {
-        if (MapUtils.isEmpty(map)) {
-            return;
-        }
-
-        Set<String> set = map.keySet();
-        Iterator<String> it = set.iterator();
-
-        while (it.hasNext()) {
-            String key = it.next();
-            Object values = map.get(key);
-            if (values instanceof String) {
-                values = StringUtil.trim((String) values);
-            } else if (values instanceof JSONArray) {
-                // 如果是数组且不为空则循环将value中的空格去除
-                JSONArray jsonArray = (JSONArray) values;
-                if (!jsonArray.isEmpty()) {
-                    List<Map<String, Object>> list = Lists.newArrayListWithExpectedSize(jsonArray.size());
-                    jsonArray.stream().forEach(json -> {
-                        Map<String, Object> jsonMap = (Map<String, Object>) json;
-                        mapTrim(jsonMap);
-
-                        list.add(jsonMap);
-                    });
-
-                    values = list;
-                }
-            } else if (values instanceof JSONObject) {
-                Map<String, Object> jsonMap = (Map<String, Object>) values;
-                mapTrim(jsonMap);
-                values = jsonMap;
-            }
-
-            map.put(key, values);
-        }
-    }
-
-    /**
-     * 将parameter的值去除空格后重写回去
-     */
-    public void modifyParameterValues() {
-        Set<String> set = params.keySet();
-        Iterator<String> it = set.iterator();
-        while (it.hasNext()) {
-            String key = (String) it.next();
-            String[] values = params.get(key);
-            values[0] = values[0].trim();
-            params.put(key, values);
-        }
-    }
-
-    /**
-     * 重写getParameter 参数从当前类中的map获取
-     */
-    @Override
-    public String getParameter(String name) {
-        String[] values = params.get(name);
-        if (values == null || values.length == 0) {
-            return null;
-        }
-        return values[0];
-    }
-
-    /**
-     * 重写getParameterValues
-     */
-    @Override
-    public String[] getParameterValues(String name) {// 同上
-        return params.get(name);
-    }
-
-    class MyServletInputStream extends ServletInputStream {
-        private ByteArrayInputStream bis;
-
-        public MyServletInputStream(ByteArrayInputStream bis) {
-            this.bis = bis;
-        }
-
-        @Override
-        public boolean isFinished() {
-            return true;
-        }
-
-        @Override
-        public boolean isReady() {
-            return true;
-        }
-
-        @Override
-        public void setReadListener(ReadListener listener) {
-
-        }
-
-        @Override
-        public int read() throws IOException {
-            return bis.read();
-        }
-    }
-}

+ 28 - 0
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/http/converter/StringWithoutSpaceDeserializer.java

@@ -0,0 +1,28 @@
+package com.wei.base.springframework.core.http.converter;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import com.wei.base.springframework.util.StringUtil;
+
+import java.io.IOException;
+
+/**
+ * 序列化时将字符串前后空格过滤
+ *
+ * @author : weierming
+ * @date : 2020/9/4
+ */
+public class StringWithoutSpaceDeserializer extends StdDeserializer<String> {
+
+    private static final long serialVersionUID = -1291306222073325805L;
+
+    public StringWithoutSpaceDeserializer(Class<String> vc) {
+        super(vc);
+    }
+
+    @Override
+    public String deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException {
+        return StringUtil.trim(jsonParser.getText());
+    }
+}

+ 16 - 3
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/log/config/LogProperty.java

@@ -1,7 +1,6 @@
 package com.wei.base.springframework.core.log.config;
 package com.wei.base.springframework.core.log.config;
 
 
 import ch.qos.logback.core.PropertyDefinerBase;
 import ch.qos.logback.core.PropertyDefinerBase;
-import com.wei.base.springframework.util.StringUtil;
 
 
 /**
 /**
  * 日志配置文件 由于日志会在spring之前先进行加载没办法通过spring来配置动态化
  * 日志配置文件 由于日志会在spring之前先进行加载没办法通过spring来配置动态化
@@ -11,10 +10,24 @@ import com.wei.base.springframework.util.StringUtil;
  */
  */
 public class LogProperty extends PropertyDefinerBase {
 public class LogProperty extends PropertyDefinerBase {
 
 
-    private static final String LOG_PATH = System.getProperty("user.dir");
+    //系统变量配置
+    private static final String OS_NAME = "os.name";
+
+    //系统变量配置
+    private static final String LINUX = "linux";
+
+    //linux日志目录
+    private static final String LOG_PATH = "logs";
+
+    //其他系统日志目录
+    private static final String OTHER_LOG_PATH = "target";
 
 
     @Override
     @Override
     public String getPropertyValue() {
     public String getPropertyValue() {
-        return StringUtil.substringAfterLast(LOG_PATH, "/");
+        if (System.getProperty(OS_NAME).toLowerCase().indexOf(LINUX) >= 0) {
+            return LOG_PATH;
+        }
+
+        return OTHER_LOG_PATH;
     }
     }
 }
 }

+ 9 - 1
base-springframework/base-springframework-core/src/main/resources/application-common.yml

@@ -1,5 +1,13 @@
+spring:
+  mvc:
+    servlet:
+      #启动时加载所有servlet 避免访问后在加载会延长第一次的请求时间
+      load-on-startup: 0
+
 #公共配置 减少各个项目中的配置
 #公共配置 减少各个项目中的配置
-service:
+server:
+  servlet:
+    context-path: /${spring.application.name}
   undertow:
   undertow:
     threads:
     threads:
       # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
       # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程

+ 1 - 1
base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/mysql/config/MybatisPlusConfig.java → base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/config/MybatisPlusConfig.java

@@ -1,4 +1,4 @@
-package com.wei.base.springframework.mysql.config;
+package com.wei.base.springframework.redis.config;
 
 
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
 import org.mybatis.spring.annotation.MapperScan;
 import org.mybatis.spring.annotation.MapperScan;

+ 3 - 3
base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/mysql/constants/GeneratorParam.java → base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/constants/GeneratorParam.java

@@ -1,4 +1,4 @@
-package com.wei.base.springframework.mysql.constants;
+package com.wei.base.springframework.redis.constants;
 
 
 import lombok.Data;
 import lombok.Data;
 
 
@@ -18,7 +18,7 @@ public class GeneratorParam {
     /**
     /**
      * 驱动连接的URL
      * 驱动连接的URL
      */
      */
-    private String dataSourceUrl = "jdbc:mysql://gz-cdb-mrzurxn3.sql.tencentcdb.com:60057/wei_user?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT";
+    private String dataSourceUrl = "jdbc:mysql://192.168.11.128:3306/wei_user?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT";
 
 
     /**
     /**
      * 数据库连接用户名
      * 数据库连接用户名
@@ -28,7 +28,7 @@ public class GeneratorParam {
     /**
     /**
      * 数据库连接密码
      * 数据库连接密码
      */
      */
-    private String dataSourcePassWord = "Leven1234@";
+    private String dataSourcePassWord = "123456";
 
 
     /**
     /**
      * 需要生成的表
      * 需要生成的表

+ 1 - 1
base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/mysql/env/InitializeCustomConfiguration.java → base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/env/InitializeCustomConfiguration.java

@@ -1,4 +1,4 @@
-package com.wei.base.springframework.mysql.env;
+package com.wei.base.springframework.redis.env;
 
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;

+ 5 - 4
base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/mysql/generator/Generator.java → base-springframework/base-springframework-mysql/src/main/java/com/wei/base/springframework/redis/generator/Generator.java

@@ -1,4 +1,4 @@
-package com.wei.base.springframework.mysql.generator;
+package com.wei.base.springframework.redis.generator;
 
 
 import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.annotation.DbType;
 import com.baomidou.mybatisplus.generator.AutoGenerator;
 import com.baomidou.mybatisplus.generator.AutoGenerator;
@@ -10,7 +10,7 @@ import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
 import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
 import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Maps;
-import com.wei.base.springframework.mysql.constants.GeneratorParam;
+import com.wei.base.springframework.redis.constants.GeneratorParam;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 
 
 import java.util.List;
 import java.util.List;
@@ -69,7 +69,7 @@ public class Generator {
 
 
         cfg.setFileOutConfigList(focList);
         cfg.setFileOutConfigList(focList);
         mpg.setCfg(cfg);
         mpg.setCfg(cfg);
-        
+
 //        // 关闭默认 xml 生成,调整生成 至 根目录
 //        // 关闭默认 xml 生成,调整生成 至 根目录
 //        TemplateConfig tc = new TemplateConfig();
 //        TemplateConfig tc = new TemplateConfig();
 //        tc.setXml(null);
 //        tc.setXml(null);
@@ -103,7 +103,8 @@ public class Generator {
         gc.setEnableCache(false);// XML 二级缓存
         gc.setEnableCache(false);// XML 二级缓存
         gc.setBaseResultMap(true);// XML ResultMap
         gc.setBaseResultMap(true);// XML ResultMap
         gc.setBaseColumnList(false);// XML columList
         gc.setBaseColumnList(false);// XML columList
-        gc.setDateType(DateType.ONLY_DATE);
+        //设置日期类型
+        gc.setDateType(DateType.TIME_PACK);
         gc.setServiceName("%sService");
         gc.setServiceName("%sService");
 
 
         return gc;
         return gc;

+ 1 - 1
base-springframework/base-springframework-mysql/src/main/resources/META-INF/spring.factories

@@ -1,4 +1,4 @@
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-  com.wei.base.springframework.mysql.config.MybatisPlusConfig
+  com.wei.base.springframework.redis.config.MybatisPlusConfig
 org.springframework.boot.env.EnvironmentPostProcessor=\
 org.springframework.boot.env.EnvironmentPostProcessor=\
   com.wei.base.springframework.core.env.InitializeCustomConfiguration
   com.wei.base.springframework.core.env.InitializeCustomConfiguration

+ 1 - 1
base-springframework/base-springframework-mysql/src/main/resources/application-mysql.yml

@@ -1,5 +1,5 @@
 #公共配置 减少各个项目中的配置
 #公共配置 减少各个项目中的配置
-service:
+spring:
   datasource:
   datasource:
     driver: com.mysql.cj.jdbc.Driver
     driver: com.mysql.cj.jdbc.Driver
 
 

+ 53 - 0
base-springframework/base-springframework-redis/pom.xml

@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+         xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.wei</groupId>
+        <artifactId>base-springframework</artifactId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>base-springframework-redis</artifactId>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.wei</groupId>
+            <artifactId>base-springframework-util</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+            <version>${spring-boot-starter.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-maven-plugin</artifactId>
+                    <version>${spring-boot-maven-plugin.version}</version>
+                    <executions>
+                        <execution>
+                            <goals>
+                                <goal>repackage</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+    </build>
+</project>

+ 45 - 0
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/config/RedisConfig.java

@@ -0,0 +1,45 @@
+package com.wei.base.springframework.redis.config;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+@Configuration
+public class RedisConfig {
+
+    @Bean
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
+        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
+
+        redisTemplate.setConnectionFactory(factory);
+
+        Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
+
+        ObjectMapper objectMapper = new ObjectMapper();
+
+        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+        jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
+
+        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
+
+        // key采用String的序列化方式
+        redisTemplate.setKeySerializer(stringRedisSerializer);
+        // hash的key也采用String的序列化方式
+        redisTemplate.setHashKeySerializer(stringRedisSerializer);
+
+        // value序列化方式采用jackson
+        redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
+
+        // hash的value序列化方式采用jackson
+        redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
+
+        redisTemplate.afterPropertiesSet();
+        return redisTemplate;
+    }
+}

+ 85 - 0
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/env/InitializeCustomConfiguration.java

@@ -0,0 +1,85 @@
+package com.wei.base.springframework.redis.env;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.env.EnvironmentPostProcessor;
+import org.springframework.boot.env.YamlPropertySourceLoader;
+import org.springframework.core.env.ConfigurableEnvironment;
+import org.springframework.core.env.MutablePropertySources;
+import org.springframework.core.env.PropertiesPropertySource;
+import org.springframework.core.env.PropertySource;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * 加载自定义配置文件
+ *
+ * @author : weierming
+ * @date : 2020/7/13
+ */
+public class InitializeCustomConfiguration implements EnvironmentPostProcessor {
+
+    //自定义配置文件地址
+    private static final List<String> PROFILES = Lists.newArrayList("application-redis.yml");
+
+    @Override
+    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
+        PROFILES.stream().forEach(profile -> {
+            //从classpath路径下面查找文件
+            Resource resource = new ClassPathResource(profile);
+            if (resource == null || !resource.exists()) {
+                throw new IllegalArgumentException("资源" + resource + "不存在");
+            }
+
+            MutablePropertySources mutablePropertySources = environment.getPropertySources();
+            //加载成PropertySource对象,并添加到Environment环境中
+            switch (StringUtils.substringAfterLast(profile, ".")) {
+                case "yml":
+                    List<PropertySource<?>> propertySources = loadYmlProfiles(resource);
+                    propertySources.stream().forEach(propertySource -> {
+                        mutablePropertySources.addLast(propertySource);
+                    });
+                    break;
+                default:
+                    mutablePropertySources.addLast(loadProfiles(resource));
+                    break;
+            }
+        });
+    }
+
+    /**
+     * 加载单个配置文件
+     *
+     * @param resource
+     * @return
+     */
+    private PropertiesPropertySource loadProfiles(Resource resource) {
+        try {
+            Properties properties = new Properties();
+            properties.load(resource.getInputStream());
+            return new PropertiesPropertySource(resource.getFilename(), properties);
+        } catch (IOException ex) {
+            throw new IllegalStateException("加载配置文件失败" + resource, ex);
+        }
+    }
+
+    /**
+     * 加载yml格式配置文件
+     *
+     * @param resource
+     * @return
+     */
+    private List<PropertySource<?>> loadYmlProfiles(Resource resource) {
+        try {
+            YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader();
+            return yamlPropertySourceLoader.load(resource.getFilename(), resource);
+        } catch (IOException ex) {
+            throw new IllegalStateException("加载配置文件失败" + resource, ex);
+        }
+    }
+}

+ 57 - 0
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/utils/RedisLock.java

@@ -0,0 +1,57 @@
+package com.wei.base.springframework.redis.utils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+@Component
+public class RedisLock {
+
+    @Autowired
+    private RedisTemplate<String, Object> redisTemplate;
+
+    /**
+     * 加锁
+     *
+     * @param key
+     * @param value 当前时间+超时时间
+     * @return
+     */
+    public Boolean lock(String key, String value) {
+        redisTemplate.opsForValue();
+
+//        if (redisTemplate.opsForValue().setIfAbsent(key, value)) {//相当于SETNX,setIfAbsent方法设置了为true,没有设置为false
+//            return Boolean.TRUE;
+//        }
+//        redisTemplate.opsForValue().setIf
+//        //假设currentValue=A   接下来并发进来的两个线程的value都是B  其中一个线程拿到锁,除非从始至终所有都是在并发(实际上这中情况是不存在的),只要开始时有数据有先后顺序,则分布式锁就不会出现“多卖”的现象
+//        String currentValue = String.valueOf(redisTemplate.opsForValue().get(key));
+//        //如果锁过期  解决死锁
+//        if (!StringUtils.isEmpty(currentValue) && Long.parseLong(currentValue) < System.currentTimeMillis()) {
+//            //获取上一个锁的时间,锁过期后,GETSET将原来的锁替换成新锁
+//            String oldValue = String.valueOf(redisTemplate.opsForValue().getAndSet(key, value));
+//            if (!StringUtils.isEmpty(oldValue) && oldValue.equals(currentValue)) {
+//                return Boolean.TRUE;
+//            }
+//        }
+
+        return Boolean.FALSE;//拿到锁的就有执行权力,拿不到的只有重新再来,重新再来只得是让用户手动继续抢单
+    }
+
+    /**
+     * 解锁
+     *
+     * @param key
+     * @param value
+     */
+    public void unlock(String key, String value) {
+//        try {
+//            String currentValue = String.valueOf(redisTemplate.opsForValue().get(key));
+//            if (!StringUtils.isEmpty(currentValue) && currentValue.equals(value)) {
+//                redisTemplate.opsForValue().getOperations().delete(key);
+//            }
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+    }
+}

+ 5 - 0
base-springframework/base-springframework-redis/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,5 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+  com.wei.base.springframework.redis.config.RedisConfig,\
+  com.wei.base.springframework.redis.utils.RedisLock
+org.springframework.boot.env.EnvironmentPostProcessor=\
+  com.wei.base.springframework.core.env.InitializeCustomConfiguration

+ 16 - 0
base-springframework/base-springframework-redis/src/main/resources/application-redis.yml

@@ -0,0 +1,16 @@
+spring:
+  redis:
+    #默认端口
+    port: 6379
+    jedis:
+      pool:
+        # 连接池最大连接数(使用负值表示没有限制)
+        max-active: 200
+        # 连接池最大阻塞等待时间(使用负值表示没有限制)
+        max-wait: -1
+        # 连接池中的最小空闲连接
+        min-idle: 0
+        # 连接池中的最大空闲连接
+        max-idle: 10
+    # 连接超时时间(毫秒)
+    timeout: 1000

+ 1 - 6
base-springframework/pom.xml

@@ -12,6 +12,7 @@
         <module>base-springframework-util</module>
         <module>base-springframework-util</module>
         <module>base-springframework-core</module>
         <module>base-springframework-core</module>
         <module>base-springframework-mysql</module>
         <module>base-springframework-mysql</module>
+        <module>base-springframework-redis</module>
         <module>base-springframework-cloud</module>
         <module>base-springframework-cloud</module>
     </modules>
     </modules>
 
 
@@ -52,12 +53,6 @@
         </dependency>
         </dependency>
 
 
         <dependency>
         <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>fastjson</artifactId>
-            <version>${fastjson.version}</version>
-        </dependency>
-
-        <dependency>
             <groupId>com.google.guava</groupId>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
             <artifactId>guava</artifactId>
             <version>${guava.version}</version>
             <version>${guava.version}</version>

+ 8 - 2
wei-user/wei-user-app/pom.xml

@@ -13,14 +13,20 @@
     <dependencies>
     <dependencies>
         <dependency>
         <dependency>
             <groupId>com.wei</groupId>
             <groupId>com.wei</groupId>
+            <artifactId>wei-user-api</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.wei</groupId>
             <artifactId>base-springframework-mysql</artifactId>
             <artifactId>base-springframework-mysql</artifactId>
             <version>${project.version}</version>
             <version>${project.version}</version>
         </dependency>
         </dependency>
 
 
         <dependency>
         <dependency>
             <groupId>com.wei</groupId>
             <groupId>com.wei</groupId>
-            <artifactId>wei-user-api</artifactId>
-            <version>0.0.1-SNAPSHOT</version>
+            <artifactId>base-springframework-redis</artifactId>
+            <version>${project.version}</version>
         </dependency>
         </dependency>
     </dependencies>
     </dependencies>
 
 

+ 17 - 5
wei-user/wei-user-app/src/main/java/com/wei/user/controller/UserController.java

@@ -1,14 +1,14 @@
 package com.wei.user.controller;
 package com.wei.user.controller;
 
 
 import com.wei.base.springframework.constant.vo.RestfulVO;
 import com.wei.base.springframework.constant.vo.RestfulVO;
+import com.wei.base.springframework.redis.utils.RedisLock;
 import com.wei.user.entity.User;
 import com.wei.user.entity.User;
 import com.wei.user.service.UserService;
 import com.wei.user.service.UserService;
+import com.wei.user.vo.UserVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -26,15 +26,18 @@ public class UserController {
     @Autowired
     @Autowired
     private UserService userService;
     private UserService userService;
 
 
+    @Autowired
+    private RedisLock redisLock;
+
     @ApiOperation("分页查询所有数据")
     @ApiOperation("分页查询所有数据")
     @GetMapping("/test")
     @GetMapping("/test")
-    public User test() {
+    public User test(User user) {
         return userService.getById(1);
         return userService.getById(1);
     }
     }
 
 
     @ApiOperation("分页查询所有数据")
     @ApiOperation("分页查询所有数据")
     @GetMapping("/test2")
     @GetMapping("/test2")
-    public RestfulVO<User> test2() {
+    public RestfulVO<User> test2(@RequestParam(value = "test") String test) {
         return new RestfulVO(userService.getById(1));
         return new RestfulVO(userService.getById(1));
     }
     }
 
 
@@ -43,4 +46,13 @@ public class UserController {
     public RestfulVO<String> test1() {
     public RestfulVO<String> test1() {
         return new RestfulVO("1111");
         return new RestfulVO("1111");
     }
     }
+
+    @ApiOperation("分页查询所有数据")
+    @PostMapping("/test3")
+    public void test1(@RequestBody UserVO user) {
+        redisLock.lock("test", "1111");
+        System.err.println(11111);
+//        redisLock.unlock("test", "1111");
+        return;
+    }
 }
 }

+ 59 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/vo/UserVO.java

@@ -0,0 +1,59 @@
+package com.wei.user.vo;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * <p>
+ * 用户信息表
+ * </p>
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class UserVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private Long id;
+
+    /**
+     * 用户名称
+     */
+    private String name;
+
+    /**
+     * 用户手机号
+     */
+    private String mobilePhone;
+
+    /**
+     * 用户邮箱
+     */
+    private String email;
+
+    /**
+     * 密码
+     */
+    private String password;
+
+    /**
+     * 用户头像地址
+     */
+    private String pictureUrl;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    List<UserVO> user;
+
+    List<String> list;
+}

+ 7 - 2
wei-user/wei-user-app/src/main/resources/bootstrap.yml

@@ -1,7 +1,5 @@
 server:
 server:
   port: 8201
   port: 8201
-  servlet:
-    context-path: /wei-user
 
 
 spring:
 spring:
   application:
   application:
@@ -16,3 +14,10 @@ spring:
   profiles:
   profiles:
     active: dev
     active: dev
 
 
+  datasource:
+    url: jdbc:mysql://192.168.11.128:3306/wei_user?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT
+    username: root
+    password: 123456
+  redis:
+    host: 192.168.11.128
+    port: 6379