韦二铭 il y a 5 ans
Parent
commit
4253bde9d9
42 fichiers modifiés avec 965 ajouts et 178 suppressions
  1. 1 1
      base-springframework/base-springframework-cloud/pom.xml
  2. 1 2
      base-springframework/base-springframework-cloud/src/main/java/com/wei/base/springframework/cloud/config/RibbonConfig.java
  3. 2 4
      base-springframework/base-springframework-cloud/src/main/resources/application-cloud.yml
  4. 31 0
      base-springframework/base-springframework-constant/src/main/java/com/wei/base/springframework/constant/vo/PageRequest.java
  5. 0 7
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/CoreConfiguration.java
  6. 3 1
      base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/swagger/Swagger3ServiceModelToOpenApiMapperImpl.java
  7. 7 1
      base-springframework/base-springframework-core/src/main/resources/META-INF/spring.factories
  8. 2 4
      base-springframework/base-springframework-core/src/main/resources/logback-spring.xml
  9. 78 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/controller/BaseExport.java
  10. 126 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/controller/BaseExportLogic.java
  11. 21 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/enums/EsayExcelExceptionEnum.java
  12. 50 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/enums/ExportFileTypeEnum.java
  13. 4 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/util/ExcelUtil.java
  14. 35 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/vo/ExportParam.java
  15. 30 0
      base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/vo/ExportRequest.java
  16. 1 1
      base-springframework/base-springframework-mysql/pom.xml
  17. 0 29
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/config/RedisProperties.java
  18. 12 0
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/constant/RedisConstant.java
  19. 25 64
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/utils/RedisLock.java
  20. 0 21
      base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/vo/LockContent.java
  21. 2 2
      base-springframework/base-springframework-redis/src/main/resources/META-INF/spring.factories
  22. 1 5
      base-springframework/base-springframework-redis/src/main/resources/application-redis.yml
  23. 183 0
      base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/BeanUtil.java
  24. 22 0
      base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/HttpServletUtil.java
  25. 39 0
      base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/PageUtil.java
  26. 37 0
      base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/ReflectionUtil.java
  27. 68 0
      base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/SpringBeanUtil.java
  28. 2 2
      base-springframework/base-springframework-util/src/main/resources/META-INF/spring.factories
  29. 3 2
      base-springframework/pom.xml
  30. 9 3
      consul/README.md
  31. 1 1
      wei-user/wei-user-api/src/main/java/com/wei/user/api/ApiService.java
  32. 1 1
      wei-user/wei-user-app/pom.xml
  33. 15 0
      wei-user/wei-user-app/src/main/java/com/wei/user/controller/Test.java
  34. 44 8
      wei-user/wei-user-app/src/main/java/com/wei/user/controller/UserController.java
  35. 5 2
      wei-user/wei-user-app/src/main/java/com/wei/user/entity/User.java
  36. 68 0
      wei-user/wei-user-app/src/main/java/com/wei/user/excelEntity/UserExcel.java
  37. 4 1
      wei-user/wei-user-app/src/main/java/com/wei/user/mapper/UserMapper.java
  38. 10 5
      wei-user/wei-user-app/src/main/java/com/wei/user/mapstruct/UserMapstruct.java
  39. 4 1
      wei-user/wei-user-app/src/main/java/com/wei/user/service/UserService.java
  40. 7 1
      wei-user/wei-user-app/src/main/java/com/wei/user/service/impl/UserServiceImpl.java
  41. 4 2
      wei-user/wei-user-app/src/main/java/com/wei/user/vo/UserVO.java
  42. 7 7
      wei-user/wei-user-app/src/main/resources/bootstrap.yml

+ 1 - 1
base-springframework/base-springframework-cloud/pom.xml

@@ -20,7 +20,7 @@
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <spring-boot-maven-plugin.version>2.3.1.RELEASE</spring-boot-maven-plugin.version>
-        <spring-cloud.version>2.2.3.RELEASE</spring-cloud.version>
+        <spring-cloud.version>2.2.4.RELEASE</spring-cloud.version>
         <feign-httpclient.version>10.11</feign-httpclient.version>
     </properties>
 

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

@@ -33,8 +33,7 @@ public class RibbonConfig {
         if (!eagerLoad.getAutoEnabled()) {
             return;
         }
-
-
+        
         List<ServiceInstance> serviceInstances = consulDiscoveryClient.getAllInstances();
         List<String> clients = Lists.newArrayListWithCapacity(serviceInstances.size());
 

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

@@ -2,12 +2,10 @@ spring:
   cloud:
     consul:
       config:
-        #是否启用配置中心 默认为true启用
-        enabled: true
         # 表示consul上面文件的格式 有四种 yaml properties key_value files
         format: yaml
-        prefix: config/${spring.profiles.active:}
-        data-key: application
+        prefix: config
+        data-key: application.yml
       discovery:
         prefer-ip-address: true
         health-check-path: ${server.servlet.context-path:}/actuator/health

+ 31 - 0
base-springframework/base-springframework-constant/src/main/java/com/wei/base/springframework/constant/vo/PageRequest.java

@@ -0,0 +1,31 @@
+package com.wei.base.springframework.constant.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 分页入参
+ *
+ * @author : weierming
+ * @date : 2020/9/22
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class PageRequest implements Serializable {
+
+    private static final long serialVersionUID = 2270218228565313137L;
+
+    /**
+     * 每页显示条数,默认 10
+     */
+    protected Integer size = 10;
+
+    /**
+     * 当前页
+     */
+    protected Integer current = 1;
+}

+ 0 - 7
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/CoreConfiguration.java

@@ -1,7 +0,0 @@
-package com.wei.base.springframework.core;
-
-import org.springframework.context.annotation.ComponentScan;
-
-@ComponentScan
-public class CoreConfiguration {
-}

+ 3 - 1
base-springframework/base-springframework-core/src/main/java/com/wei/base/springframework/core/swagger/Swagger3ServiceModelToOpenApiMapperImpl.java

@@ -66,6 +66,7 @@ public class Swagger3ServiceModelToOpenApiMapperImpl extends ServiceModelToOpenA
 
         Map<String, String> map = Maps.newHashMapWithExpectedSize(schemas.size());
         String restfulVOName = responseHandlerConfigure.getRestfulVOName();
+        Map<String, Schema> newSchemas = Maps.newHashMapWithExpectedSize(schemas.size());
         for (Map.Entry<String, Schema> entry : schemas.entrySet()) {
             Schema schema = entry.getValue();
             // 判断返回对象是否已经包含默认包装类格式
@@ -83,9 +84,10 @@ public class Swagger3ServiceModelToOpenApiMapperImpl extends ServiceModelToOpenA
             }
 
             Schema restfulSchema = getRestfulSchema(schema, restfulClass);
-            schemas.put(restfulSchemaName, restfulSchema);
+            newSchemas.put(restfulSchemaName, restfulSchema);
         }
 
+        schemas.putAll(newSchemas);
         return map;
     }
 

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

@@ -1,4 +1,10 @@
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-	com.wei.base.springframework.core.CoreConfiguration
+  com.wei.base.springframework.core.http.converter.MappingJacksonConverter,\
+  com.wei.base.springframework.core.swagger.Swagger3Config,\
+  com.wei.base.springframework.core.swagger.Swagger3ServiceModelToOpenApiMapperImpl,\
+  com.wei.base.springframework.core.web.config.ResponseHandlerConfigure,\
+  com.wei.base.springframework.core.web.handler.BaseExceptionHandler,\
+  com.wei.base.springframework.core.web.handler.ResponseHandler
+
 org.springframework.boot.env.EnvironmentPostProcessor=\
   com.wei.base.springframework.core.env.InitializeCustomConfiguration

+ 2 - 4
base-springframework/base-springframework-core/src/main/resources/logback-spring.xml

@@ -13,10 +13,8 @@
     <!-- 彩色日志 -->
     <!-- 彩色日志依赖的渲染类 -->
     <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
-    <conversionRule conversionWord="wex"
-                    converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
-    <conversionRule conversionWord="wEx"
-                    converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
+    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
+    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
     <!-- 彩色日志格式 -->
     <property name="CONSOLE_LOG_PATTERN"
               value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>

+ 78 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/controller/BaseExport.java

@@ -0,0 +1,78 @@
+package com.wei.base.springframework.easyexcel.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.wei.base.springframework.constant.exception.ServiceException;
+import com.wei.base.springframework.easyexcel.enums.EsayExcelExceptionEnum;
+import com.wei.base.springframework.easyexcel.vo.ExportParam;
+import com.wei.base.springframework.easyexcel.vo.ExportRequest;
+import com.wei.base.springframework.util.HttpServletUtil;
+import com.wei.base.springframework.util.ReflectionUtil;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * 公共导出
+ *
+ * @param <T> 查询分页数据实体类
+ * @param <E> excel实体对象
+ * @author : weierming
+ * @date : 2020/9/22
+ */
+public interface BaseExport<T, E> {
+
+    Logger log = LoggerFactory.getLogger(BaseExport.class);
+
+    /**
+     * 导出
+     *
+     * @param exportRequest
+     * @throws Exception
+     */
+    @ResponseBody
+    @GetMapping(value = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+    @ApiOperation(value = "导出", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
+    default Object export(@Validated ExportRequest exportRequest) {
+        ExportParam exportParam = BaseExportLogic.checkParameter(exportRequest);
+        Class<? extends BaseExport> subClass = getClass();
+        exportParam.setSubClass(subClass);
+
+        // 通过反射获取子类上的泛型集合
+        List<Class<?>> list = ReflectionUtil.getSuperGenericityClass(subClass);
+        exportParam.setSuperGenericityClass(list.size() >= 1 ? list.get(0) : null);
+        exportParam.setExcelEntityClass(list.size() >= 2 ? list.get(1) : null);
+
+        HttpServletResponse httpServletResponse = HttpServletUtil.getHttpServletResponse();
+        httpServletResponse.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
+        try (OutputStream outputStream = httpServletResponse.getOutputStream()) {
+            httpServletResponse.addHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment;fileName=%s",
+                    URLEncoder.encode(exportRequest.getFileName() + exportParam.getFileType().getExcelTypeEnum().getValue(),
+                            String.valueOf(StandardCharsets.UTF_8))));
+            BaseExportLogic.excelWriter(outputStream, exportParam);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            throw new ServiceException(EsayExcelExceptionEnum.GENERATE_FILE_FAIL);
+        }
+
+        return null;
+    }
+
+    /**
+     * 获取导出数据
+     *
+     * @param t 查询条件 实体里必须包含size current 这两个参数 不要一次性查出所有数据
+     * @return 分页参数
+     */
+    Page<?> getExportData(T t);
+}

+ 126 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/controller/BaseExportLogic.java

@@ -0,0 +1,126 @@
+package com.wei.base.springframework.easyexcel.controller;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.metadata.WriteWorkbook;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.wei.base.springframework.constant.exception.ServiceException;
+import com.wei.base.springframework.easyexcel.enums.EsayExcelExceptionEnum;
+import com.wei.base.springframework.easyexcel.enums.ExportFileTypeEnum;
+import com.wei.base.springframework.easyexcel.vo.ExportParam;
+import com.wei.base.springframework.easyexcel.vo.ExportRequest;
+import com.wei.base.springframework.util.BeanUtil;
+import com.wei.base.springframework.util.PageUtil;
+import com.wei.base.springframework.util.SpringBeanUtil;
+import com.wei.base.springframework.util.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+
+import java.io.OutputStream;
+
+/**
+ * 导出公共逻辑实现
+ *
+ * @author : weierming
+ * @date : 2020/9/30
+ */
+@Slf4j
+public class BaseExportLogic {
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    /**
+     * 每页大小
+     */
+    private static final Integer SIZE = 5000;
+
+    /**
+     * 校验导出参数
+     *
+     * @param exportRequest 导出入参
+     * @return 转换后的导出入参
+     */
+    public static ExportParam checkParameter(ExportRequest exportRequest) {
+        String parameter = exportRequest.getParameter();
+        ExportParam exportParam = new ExportParam();
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        if (StringUtil.isNotBlank(parameter)) {
+            try {
+                // 校验查询参数是否是json字符串
+                objectNode = (ObjectNode) objectMapper.readTree(parameter);
+                if (!objectNode.isObject()) {
+                    throw new ServiceException(EsayExcelExceptionEnum.EXPORT_PARAMETER_ERROR);
+                }
+            } catch (JsonProcessingException e) {
+                log.error(e.getMessage(), e);
+                throw new ServiceException(EsayExcelExceptionEnum.EXPORT_PARAMETER_ERROR);
+            }
+        }
+
+        exportParam.setParam(objectNode);
+        exportParam.setFileType(ObjectUtils.defaultIfNull(exportRequest.getFileType(), ExportFileTypeEnum.XLSX));
+        return exportParam;
+    }
+
+    /**
+     * excel写入逻辑
+     *
+     * @param outputStream 输出流
+     * @param exportParam  转换后的导出入参
+     */
+    public static void excelWriter(OutputStream outputStream, ExportParam exportParam) {
+        WriteWorkbook writeWorkbook = new WriteWorkbook();
+        writeWorkbook.setOutputStream(outputStream);
+        // excel类型
+        writeWorkbook.setExcelType(exportParam.getFileType().getExcelTypeEnum());
+        // 导出excel实体
+        writeWorkbook.setClazz(exportParam.getExcelEntityClass());
+        ExcelWriter excelWriter = new ExcelWriter(writeWorkbook);
+        WriteSheet writeSheet = EasyExcel.writerSheet().build();
+
+        Integer pageCount = excelWriteLogic(excelWriter, writeSheet, exportParam.getParam(), 1, exportParam.getSubClass(),
+                exportParam.getSuperGenericityClass(), exportParam.getExcelEntityClass());
+        if (pageCount > 1) {
+            for (int i = 2; i <= pageCount; i++) {
+                excelWriteLogic(excelWriter, writeSheet, exportParam.getParam(), i, exportParam.getSubClass(),
+                        exportParam.getSuperGenericityClass(), exportParam.getExcelEntityClass());
+            }
+        }
+
+        excelWriter.finish();
+    }
+
+    /**
+     * 将查询出来的数据存入excel中
+     *
+     * @param excelWriter          ExcelWriter对象
+     * @param writeSheet           excelSheet对象
+     * @param param                查询参数
+     * @param current              页码
+     * @param subClass             实现导出类的实体
+     * @param superGenericityClass 查询数据接口实体类
+     * @param excelEntityClass     excel实体类
+     * @return 总页数
+     */
+    private static Integer excelWriteLogic(ExcelWriter excelWriter, WriteSheet writeSheet, ObjectNode param,
+                                           Integer current, Class<?> subClass,
+                                           Class<?> superGenericityClass, Class<?> excelEntityClass) {
+        param.put("size", SIZE);
+        param.put("current", current);
+
+        BaseExport baseExport = SpringBeanUtil.getBean(subClass);
+        Object exportDataParam = objectMapper.convertValue(param, superGenericityClass);
+        Page<Object> exportData = baseExport.getExportData(exportDataParam);
+        if (exportData == null) {
+            exportData = new Page<>();
+        }
+
+        excelWriter.write(BeanUtil.copy(exportData.getRecords(), excelEntityClass), writeSheet);
+        Integer pageCount = PageUtil.getPageCount(exportData.getTotal(), SIZE);
+        return pageCount;
+    }
+}

+ 21 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/enums/EsayExcelExceptionEnum.java

@@ -0,0 +1,21 @@
+package com.wei.base.springframework.easyexcel.enums;
+
+import com.wei.base.springframework.constant.exception.BaseException;
+import lombok.Getter;
+
+@Getter
+public enum EsayExcelExceptionEnum implements BaseException {
+
+    COMMENT_SERVICE_EXCEPTION(1000, "%s"),
+    EXPORT_PARAMETER_ERROR(1001, "导出查询参数错误!"),
+    GENERATE_FILE_FAIL(1002, "生成导出文件失败!"),
+    ;
+
+    private Integer code;
+    private String msg;
+
+    EsayExcelExceptionEnum(Integer code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+}

+ 50 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/enums/ExportFileTypeEnum.java

@@ -0,0 +1,50 @@
+/**
+ * Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.wei.base.springframework.easyexcel.enums;
+
+import com.alibaba.excel.support.ExcelTypeEnum;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+/**
+ * 导出文件类型
+ *
+ * @author : weierming
+ * @date : 2020/9/24
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Getter
+public enum ExportFileTypeEnum {
+
+    XLS(1, ExcelTypeEnum.XLS),
+    XLSX(2, ExcelTypeEnum.XLSX),
+    ;
+
+    private Integer code;
+    private ExcelTypeEnum excelTypeEnum;
+
+    public static ExportFileTypeEnum getEnumByCode(Integer code) {
+        for (ExportFileTypeEnum result : ExportFileTypeEnum.values()) {
+            if (result.getCode().equals(code)) {
+                return result;
+            }
+        }
+
+        return null;
+    }
+}

+ 4 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/util/ExcelUtil.java

@@ -0,0 +1,4 @@
+package com.wei.base.springframework.easyexcel.util;
+
+public class ExcelUtil {
+}

+ 35 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/vo/ExportParam.java

@@ -0,0 +1,35 @@
+package com.wei.base.springframework.easyexcel.vo;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.wei.base.springframework.easyexcel.enums.ExportFileTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ExportParam implements Serializable {
+
+    private static final long serialVersionUID = -7105868777500886435L;
+
+    @ApiModelProperty(value = "导出文件名!")
+    private String fileName;
+
+    @ApiModelProperty(value = "导出查询条件,json串格式")
+    private ObjectNode param;
+
+    @ApiModelProperty(value = "时间类型(不传默认:yyyy-MM-dd HH:mm:ss)")
+    private String dateType = "yyyy-MM-dd HH:mm:ss";
+
+    @ApiModelProperty(value = "导出文件格式 (1:XLS, 2:XLSX, 3:CSV  不传默认1)")
+    private ExportFileTypeEnum fileType;
+
+    @ApiModelProperty(value = "查询数据接口实体类")
+    private Class<?> superGenericityClass;
+
+    @ApiModelProperty(value = "导出文件实体类")
+    private Class<?> excelEntityClass;
+
+    @ApiModelProperty(value = "实现BaseExport实体类")
+    private Class<?> subClass;
+}

+ 30 - 0
base-springframework/base-springframework-easyexcel/src/main/java/com/wei/base/springframework/easyexcel/vo/ExportRequest.java

@@ -0,0 +1,30 @@
+package com.wei.base.springframework.easyexcel.vo;
+
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.wei.base.springframework.easyexcel.enums.ExportFileTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ExportRequest implements Serializable {
+
+    private static final long serialVersionUID = -7105868777500886435L;
+
+    @ApiModelProperty(value = "导出文件名!")
+    private String fileName = IdWorker.getIdStr();
+
+    @ApiModelProperty(value = "导出查询条件,json串格式")
+    private String parameter;
+
+    @ApiModelProperty(value = "时间类型(不传默认:yyyy-MM-dd HH:mm:ss)")
+    private String dateType = "yyyy-MM-dd HH:mm:ss";
+
+    @ApiModelProperty(value = "导出文件格式 (1:XLS, 2:XLSX, 3:CSV  不传默认1)")
+    private Integer fileType = ExportFileTypeEnum.XLSX.getCode();
+
+    public ExportFileTypeEnum getFileType() {
+        return ExportFileTypeEnum.getEnumByCode(fileType);
+    }
+}

+ 1 - 1
base-springframework/base-springframework-mysql/pom.xml

@@ -16,7 +16,7 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <java.version>1.8</java.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <spring-boot-maven-plugin.version>2.3.1.RELEASE</spring-boot-maven-plugin.version>
+        <spring-boot-maven-plugin.version>2.3.4.RELEASE</spring-boot-maven-plugin.version>
         <mysql-connector-java.version>8.0.21</mysql-connector-java.version>
         <mybatis-plus.version>3.3.2</mybatis-plus.version>
         <freemarker.version>2.3.30</freemarker.version>

+ 0 - 29
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/config/RedisProperties.java

@@ -1,29 +0,0 @@
-package com.wei.base.springframework.redis.config;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-import java.io.Serializable;
-
-@Data
-@Configuration
-@ConfigurationProperties(prefix = "spring.redis")
-public class RedisProperties implements Serializable {
-
-    private static final long serialVersionUID = -4633090811506861386L;
-    /**
-     * redis锁key值
-     */
-    String lockKey;
-
-    /**
-     * redis锁默认过期时间
-     */
-    Long expirationTime;
-
-    /**
-     * redis锁等待时间
-     */
-    Long waitTime;
-}

+ 12 - 0
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/constant/RedisConstant.java

@@ -0,0 +1,12 @@
+package com.wei.base.springframework.redis.constant;
+
+public interface RedisConstant {
+
+    String LOCK_KEY = "LOCK:";
+
+    String FAIR_LOCK = "FAIR_LOCK:";
+
+    String READ_WRITE_LOCK = "READ_WRITE_LOCK:";
+
+    String COUNT_DOWN_LATCH = "COUNT_DOWN_LATCH:";
+}

+ 25 - 64
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/utils/RedisLock.java

@@ -1,101 +1,62 @@
 package com.wei.base.springframework.redis.utils;
 
-import com.wei.base.springframework.redis.config.RedisProperties;
+import com.wei.base.springframework.redis.constant.RedisConstant;
+import com.wei.base.springframework.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.redisson.api.RCountDownLatch;
 import org.redisson.api.RLock;
+import org.redisson.api.RReadWriteLock;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.concurrent.TimeUnit;
-
 @Slf4j
 @Component
 public class RedisLock<T> {
 
     @Autowired
-    RedissonClient redissonClient;
-
-    @Autowired
-    private RedisProperties redisProperties;
+    private RedissonClient redissonClient;
 
     /**
      * 可重入锁
      *
-     * @param key            锁key值
-     * @param expirationTime 过期时间
-     * @param timeUnit       时间单位
-     * @return 锁对象, 解锁方式  RLock.unlock()
-     */
-    public RLock lock(String key, long expirationTime, TimeUnit timeUnit) {
-        RLock rLock = redissonClient.getLock(redisProperties.getLockKey() + key);
-        rLock.lock(expirationTime, timeUnit);
-        return rLock;
-    }
-
-    /**
-     * 可重入锁(过期时间30秒)
-     *
      * @param key 锁key值
-     * @return 锁对象, 解锁方式  RLock.unlock()
+     * @return 锁对象
      */
     public RLock lock(String key) {
-        return lock(key, redisProperties.getExpirationTime(), TimeUnit.SECONDS);
+        return redissonClient.getLock(RedisConstant.LOCK_KEY + StringUtil.upperCase(key));
     }
 
     /**
-     * 可重入
+     * 公平锁
      *
-     * @param key            锁key值
-     * @param expirationTime 过期时间(单位:秒)
-     * @return 锁对象, 解锁方式  RLock.unlock()
+     * @param key 锁key值
+     * @return 锁对象
      */
-    public RLock lock(String key, long expirationTime) {
-        return lock(key, expirationTime, TimeUnit.SECONDS);
+    public RLock fairLock(String key) {
+        return redissonClient.getFairLock(RedisConstant.FAIR_LOCK + StringUtil.upperCase(key));
     }
 
     /**
-     * 尝试获取锁
-     * <p>
-     * try {
-     * if(tryLock(key)) {
-     * <p>
-     * }
-     * } catch (Exception e) {
-     * } finally {
-     * // 无论如何, 最后都要解锁
-     * unlock();
-     * }
+     * 读写锁 分布式可重入读写锁允许同时有多个读锁和一个写锁处于加锁状态。
      *
-     * @param rLock     当前锁对象
-     * @param waitTime  等待时间
-     * @param leaseTime 过期时间
-     * @param unit      时间单位
-     * @return true获取成功, false获取失败
-     * @throws InterruptedException 如果线程中断
+     * @param key 锁key值
+     * @return 锁对象
      */
-    public Boolean tryLock(RLock rLock, long waitTime, long leaseTime, TimeUnit unit) throws InterruptedException {
-        return rLock.tryLock(waitTime, leaseTime, unit);
+    public RReadWriteLock readWriteLock(String key) {
+        return redissonClient.getReadWriteLock(RedisConstant.READ_WRITE_LOCK + StringUtil.upperCase(key));
     }
 
     /**
-     * 尝试获取锁
-     * <p>
-     * try {
-     * if(tryLock(key)) {
-     * <p>
-     * }
-     * } catch (Exception e) {
-     * } finally {
-     * // 无论如何, 最后都要解锁
-     * unlock();
-     * }
+     * 闭锁
+     * 通过trySetCount设置大小
+     * 通过在其他线程或者MQ里只想countDown()执行-1操作
+     * 当设置的trySetCount大小等于0时代表已经解锁
      *
-     * @param rLock 当前锁对象
-     * @return true获取成功, false获取失败
-     * @throws InterruptedException 如果线程中断
+     * @param key 锁key值
+     * @return 锁对象
      */
-    public Boolean tryLock(RLock rLock) throws InterruptedException {
-        return tryLock(rLock, redisProperties.getWaitTime(), redisProperties.getExpirationTime(), TimeUnit.SECONDS);
+    public RCountDownLatch countDownLatch(String key) {
+        return redissonClient.getCountDownLatch(RedisConstant.COUNT_DOWN_LATCH + StringUtil.upperCase(key));
     }
 }

+ 0 - 21
base-springframework/base-springframework-redis/src/main/java/com/wei/base/springframework/redis/vo/LockContent.java

@@ -1,21 +0,0 @@
-package com.wei.base.springframework.redis.vo;
-
-import lombok.Data;
-
-import java.io.Serializable;
-
-@Data
-public class LockContent implements Serializable {
-
-    private static final long serialVersionUID = 1923389751075205531L;
-
-    /**
-     * 锁Id
-     */
-    private String lockId;
-
-    /**
-     * 锁超时时间
-     */
-    private Long lockExpirationTime;
-}

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

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

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

@@ -13,8 +13,4 @@ spring:
         # 连接池中的最大空闲连接
         max-idle: 10
     # 连接超时时间(毫秒)
-    timeout: 3000
-    # redis锁key值
-    lockKey: "REDIS_LOCK:"
-    # redis锁默认过期时间
-    expirationTime: 30
+    timeout: 3000

+ 183 - 0
base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/BeanUtil.java

@@ -0,0 +1,183 @@
+package com.wei.base.springframework.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cglib.beans.BeanCopier;
+import org.springframework.cglib.beans.BeanMap;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+
+@Slf4j
+public class BeanUtil {
+
+    /**
+     * Map<source class,<target class , BeanCopier>>
+     */
+    private static final ConcurrentHashMap<Class<?>, ConcurrentHashMap<Class<?>, BeanCopier>> cache = new ConcurrentHashMap<>();
+
+    private static final ObjectMapper objectMapper = new ObjectMapper();
+
+    static {
+        // 转换为格式化的json
+        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
+
+        // 如果json中有新增的字段并且是实体类类中不存在的,不报错
+        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+    }
+
+    /**
+     * 浅拷贝,对象属性都是基本类型时使用, 性能最优
+     */
+    public static <T> T copy(Object source, Class<T> targetClass) {
+
+        ConcurrentHashMap<Class<?>, BeanCopier> map = cache.get(source.getClass());
+        if (map == null) {
+            cache.putIfAbsent(source.getClass(), new ConcurrentHashMap<>());
+            map = cache.get(source.getClass());
+        }
+        BeanCopier copier = map.get(targetClass);
+        if (copier == null) {
+            map.putIfAbsent(targetClass, BeanCopier.create(source.getClass(), targetClass, false));
+            copier = map.get(targetClass);
+        }
+        T targetObj;
+        try {
+            targetObj = targetClass.newInstance();
+            copier.copy(source, targetObj, null);
+            return targetObj;
+        } catch (InstantiationException | IllegalAccessException e) {
+            throw new IllegalArgumentException(targetClass.getName() + " could not initial ! ", e);
+        }
+    }
+
+
+    /**
+     * 列表,浅拷贝, 参数对象没有其他复杂数据类型时使用 , 性能比deepCopy高
+     *
+     * @param source      ,可以是单个对象或者是列表,如果是列表则返回List
+     * @param targetClass ,返回的对象类型
+     * @return 空列表或者是List(类型为targetClass)
+     */
+    public static <T, E> List<T> copy(List<E> source, Class<T> targetClass) {
+        if (CollectionUtils.isEmpty(source)) {
+            return Collections.emptyList();
+        }
+        return source.stream().map(sourceObj -> copy(sourceObj, targetClass)).collect(Collectors.toList());
+
+    }
+
+
+    /**
+     * 深拷贝,对象存在其它引用时候使用
+     *
+     * @param source      ,源对象
+     * @param targetClass ,返回的对象类型
+     * @return null 或者 targetClass
+     */
+    public static <T> T deepCopy(Object source, Class<T> targetClass) throws JsonProcessingException {
+        if (source == null) {
+            return null;
+        }
+
+        return objectMapper.readValue(objectMapper.writeValueAsString(source), targetClass);
+    }
+
+
+    /**
+     * 深拷贝,对象存在其它引用时候使用
+     *
+     * @param source      ,源对象列表
+     * @param targetClass ,返回的对象类型
+     * @return 空列表 或者是List(类型为targetClass)
+     */
+    public static <T, E> List<T> deepCopy(List<E> source, Class<T> targetClass) throws JsonProcessingException {
+        if (CollectionUtils.isEmpty(source)) {
+            return Collections.emptyList();
+        }
+
+        JavaType javaType = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, targetClass);
+        return objectMapper.readValue(objectMapper.writeValueAsString(source), javaType);
+    }
+
+    /**
+     * 将对象转换成Map
+     *
+     * @param bean
+     * @return map ,key为属性名,如果属性为复杂类型,则为嵌套map
+     */
+    public static Map<String, Object> bean2Map(Object bean) {
+        Map<String, Object> map = new HashMap<>(1);
+        BeanMap beanMap = BeanMap.create(bean);
+        Set<?> set = beanMap.keySet();
+        for (Object key : set) {
+            Object value = beanMap.get(key);
+            bean2MapRecursion(map, value, key.toString());
+        }
+
+        return map;
+    }
+
+
+    private static void bean2MapRecursion(Map<String, Object> map, Object bean, String propertyName) {
+        if (bean != null) {
+            try {
+                if (isPrimitive(bean.getClass())) {
+                    map.put(propertyName, bean);
+                } else if (Object[].class.isInstance(bean)) {
+                    List<Map<String, Object>> list = new ArrayList<>();
+                    for (Object item : (Object[]) bean) {
+                        list.add(bean2Map(item));
+                    }
+                    map.put(propertyName, list);
+                } else if (Collection.class.isInstance(bean)) {
+                    List<Map<String, Object>> list = new ArrayList<>();
+                    for (Object item : (Collection<?>) bean) {
+                        list.add(bean2Map(item));
+                    }
+                    map.put(propertyName, list);
+                } else if (Map.class.isInstance(bean)) {
+                    Map<String, Object> subMap = new HashMap<>();
+                    for (Map.Entry<?, ?> entry : ((Map<?, ?>) bean).entrySet()) {
+                        bean2MapRecursion(subMap, entry.getValue(), entry.getKey().toString());
+                    }
+                    map.put(propertyName, subMap);
+                } else {
+                    Map<String, Object> subMap = new HashMap<>();
+                    BeanMap beanMap = BeanMap.create(bean);
+                    Set<?> set = beanMap.keySet();
+                    for (Object key : set) {
+                        Object value = beanMap.get(key);
+                        bean2MapRecursion(subMap, value, key.toString());
+                    }
+                    map.put(propertyName, subMap);
+                }
+            } catch (RuntimeException e) {
+                log.error("propertyName = {} , value = ", propertyName, bean);
+                throw e;
+            }
+        }
+    }
+
+    /**
+     * 是否基本类型
+     *
+     * @param cls
+     * @return
+     */
+    public static boolean isPrimitive(Class<?> cls) {
+        if (cls.isArray()) {
+            return isPrimitive(cls.getComponentType());
+        }
+
+        return cls.isPrimitive() || cls == Class.class || cls == String.class || cls == Boolean.class || cls == Character.class || Number.class.isAssignableFrom(cls)
+                || Date.class.isAssignableFrom(cls);
+    }
+}

+ 22 - 0
base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/HttpServletUtil.java

@@ -0,0 +1,22 @@
+package com.wei.base.springframework.util;
+
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class HttpServletUtil {
+
+    public static ServletRequestAttributes getServletRequestAttributes() {
+        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+    }
+
+    public static HttpServletRequest getHttpServletRequest() {
+        return getServletRequestAttributes().getRequest();
+    }
+
+    public static HttpServletResponse getHttpServletResponse() {
+        return getServletRequestAttributes().getResponse();
+    }
+}

+ 39 - 0
base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/PageUtil.java

@@ -0,0 +1,39 @@
+package com.wei.base.springframework.util;
+
+import java.math.BigDecimal;
+
+/**
+ * 分页工具类
+ *
+ * @author admin
+ */
+public class PageUtil {
+
+    /**
+     * 根据总条数获取每页大小
+     *
+     * @param total
+     * @param pageSize
+     * @return
+     */
+    public static Integer getPageCount(Integer total, Integer pageSize) {
+        BigDecimal totalB = new BigDecimal(total);
+        BigDecimal pageSizeB = new BigDecimal(pageSize);
+
+        return totalB.divide(pageSizeB, 0, BigDecimal.ROUND_UP).intValue();
+    }
+
+    public static Integer getPageCount(Long total, Integer pageSize) {
+        BigDecimal totalB = new BigDecimal(total);
+        BigDecimal pageSizeB = new BigDecimal(pageSize);
+
+        return totalB.divide(pageSizeB, 0, BigDecimal.ROUND_UP).intValue();
+    }
+
+    public static Integer getPageCount(Long total, Long pageSize) {
+        BigDecimal totalB = new BigDecimal(total);
+        BigDecimal pageSizeB = new BigDecimal(pageSize);
+
+        return totalB.divide(pageSizeB, 0, BigDecimal.ROUND_UP).intValue();
+    }
+}

+ 37 - 0
base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/ReflectionUtil.java

@@ -0,0 +1,37 @@
+package com.wei.base.springframework.util;
+
+import com.google.common.collect.Lists;
+import org.springframework.util.ReflectionUtils;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.List;
+
+public class ReflectionUtil extends ReflectionUtils {
+
+    /**
+     * 获取继承类中的泛型
+     *
+     * @param clazz 需要获取类的class
+     * @return 泛型class
+     */
+    public static List<Class<?>> getSuperGenericityClass(Class<?> clazz) {
+        Type[] genericInterfaces = clazz.getGenericInterfaces();
+        if (genericInterfaces.length == 0) {
+            return null;
+        }
+
+        Type genericInterface = genericInterfaces[0];
+        if (!ParameterizedType.class.isAssignableFrom(genericInterface.getClass())) {
+            return null;
+        }
+
+        Type[] actualTypeArguments = ((ParameterizedType) genericInterface).getActualTypeArguments();
+        List<Class<?>> list = Lists.newArrayListWithExpectedSize(actualTypeArguments.length);
+        for (Type actualTypeArgument : actualTypeArguments) {
+            list.add((Class<?>) actualTypeArgument);
+        }
+
+        return list;
+    }
+}

+ 68 - 0
base-springframework/base-springframework-util/src/main/java/com/wei/base/springframework/util/SpringBeanUtil.java

@@ -0,0 +1,68 @@
+package com.wei.base.springframework.util;
+
+import com.google.common.collect.Lists;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+public class SpringBeanUtil implements ApplicationContextAware {
+
+    /**
+     * Spring应用上下文环境
+     */
+    private static ApplicationContext applicationContext;
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        // 初始化applicationContext
+        SpringBeanUtil.applicationContext = applicationContext;
+    }
+
+    /**
+     * 通过类获取
+     *
+     * @param clazz 注入的类
+     * @param <T>   返回类型
+     * @return 返回这个bean
+     * @throws BeansException bean异常
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T getBean(Class<?> clazz) throws BeansException {
+        return (T) applicationContext.getBean(clazz);
+    }
+
+    /**
+     * 通过名字获取
+     *
+     * @param name 名字
+     * @param <T>  返回类型
+     * @return 返回这个bean
+     * @throws BeansException bean异常
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T getBean(String name) throws BeansException {
+        return (T) applicationContext.getBean(name);
+    }
+
+    /**
+     * 给实例化的类注入需要的bean (@Autowired) 如果不注入,被@Autowired注解的变量会报空指针
+     *
+     * @param t
+     */
+    public static <T> void autowireBean(T t) {
+        applicationContext.getAutowireCapableBeanFactory().autowireBean(t);
+    }
+
+    public static List<String> getActiveProfile() {
+        String[] profiles = applicationContext.getEnvironment().getActiveProfiles();
+        if (profiles != null) {
+            return Lists.newArrayList(profiles);
+        }
+
+        return Lists.newArrayList();
+    }
+}

+ 2 - 2
base-springframework/base-springframework-util/src/main/resources/META-INF/spring.factories

@@ -1,5 +1,5 @@
-#org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-#	com.wei.base.springframework.util.UtilConfiguration
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+	com.wei.base.springframework.util.SpringBeanUtil
 	
 #org.springframework.boot.env.EnvironmentPostProcessor=\
 #	org.springframework.core.web.config.Test

+ 3 - 2
base-springframework/pom.xml

@@ -14,6 +14,7 @@
         <module>base-springframework-mysql</module>
         <module>base-springframework-redis</module>
         <module>base-springframework-cloud</module>
+        <module>base-springframework-easyexcel</module>
     </modules>
 
     <properties>
@@ -24,8 +25,8 @@
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
         <lombok.version>1.18.12</lombok.version>
-        <spring-boot-starter.version>2.3.1.RELEASE</spring-boot-starter.version>
-        <spring-boot-starter-web.version>2.3.1.RELEASE</spring-boot-starter-web.version>
+        <spring-boot-starter.version>2.3.4.RELEASE</spring-boot-starter.version>
+        <spring-boot-starter-web.version>2.3.4.RELEASE</spring-boot-starter-web.version>
         <fastjson.version>1.2.73</fastjson.version>
         <guava.version>29.0-jre</guava.version>
         <commons-lang3.version>3.10</commons-lang3.version>

+ 9 - 3
consul/README.md

@@ -11,9 +11,15 @@ sudo nohup ./consul agent -dev -ui -client 0.0.0.0 &
 ```
 访问 ip:8500 界面显示表明运行成功
 
+###通过docker安装
+```
+docker pull consul
+docker run -d --name consul -p 8500:8500 consul agent -dev -client 0.0.0.0 -ui
+```
+
 ##git2consul安装
 ```
-curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash
+curl --silent --location https://rpm.nodesource.com/setup_14.x | sudo -E bash -
 sudo yum -y install nodejs
 ```
 如果yum下载失败的话执行以下代码后在重试
@@ -31,8 +37,8 @@ npm install -g git2consul --registry=https://registry.npm.taobao.org
 ```
 下载成功后创建git2consul的配置文件
 ```
-mkdir /user/local/gitconsul
-cd /user/local/gitconsul
+mkdir /usr/local/gitconsul
+cd /usr/local/gitconsul
 vi git2consul.json
 ```
 将以下内容复制进去并做修改

+ 1 - 1
wei-user/wei-user-api/src/main/java/com/wei/user/api/ApiService.java

@@ -1,4 +1,4 @@
-package com.wei.cloud.api;
+package com.wei.user.api;
 
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;

+ 1 - 1
wei-user/wei-user-app/pom.xml

@@ -25,7 +25,7 @@
 
         <dependency>
             <groupId>com.wei</groupId>
-            <artifactId>base-springframework-redis</artifactId>
+            <artifactId>base-springframework-easyexcel</artifactId>
             <version>${project.version}</version>
         </dependency>
     </dependencies>

+ 15 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/controller/Test.java

@@ -0,0 +1,15 @@
+package com.wei.user.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.wei.base.springframework.easyexcel.controller.BaseExport;
+import com.wei.user.excelEntity.UserExcel;
+import com.wei.user.vo.UserVO;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class Test implements BaseExport<UserVO, UserExcel> {
+    @Override
+    public Page<UserExcel> getExportData(UserVO userVO) {
+        return null;
+    }
+}

+ 44 - 8
wei-user/wei-user-app/src/main/java/com/wei/user/controller/UserController.java

@@ -1,9 +1,13 @@
 package com.wei.user.controller;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.wei.base.springframework.constant.vo.RestfulVO;
-import com.wei.base.springframework.redis.utils.RedisLock;
+import com.wei.base.springframework.easyexcel.controller.BaseExport;
 import com.wei.user.entity.User;
+import com.wei.user.excelEntity.UserExcel;
+import com.wei.user.mapstruct.UserMapstruct;
 import com.wei.user.service.UserService;
 import com.wei.user.vo.UserVO;
 import io.swagger.annotations.Api;
@@ -11,6 +15,8 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  * <p>
  * 用户信息表 前端控制器
@@ -22,13 +28,13 @@ import org.springframework.web.bind.annotation.*;
 @Api(tags = "test")
 @RestController
 @RequestMapping("/user")
-public class UserController {
+public class UserController implements BaseExport<UserVO, UserExcel> {
 
     @Autowired
     private UserService userService;
 
     @Autowired
-    private RedisLock redisLock;
+    private UserMapstruct userMapstruct;
 
     @ApiOperation("分页查询所有数据")
     @GetMapping("/test")
@@ -38,8 +44,10 @@ public class UserController {
 
     @ApiOperation("分页查询所有数据")
     @GetMapping("/test2")
-    public RestfulVO<User> test2(@RequestParam(value = "test") String test) {
-        return new RestfulVO(userService.getById(1));
+    public boolean test2(@RequestParam(value = "test") String test) {
+        UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.lambda().set(User::getEmail, "11111");
+        return userService.update(updateWrapper);
     }
 
     @ApiOperation("分页查询所有数据")
@@ -51,16 +59,44 @@ public class UserController {
     @ApiOperation("分页查询所有数据")
     @PostMapping("/test3")
     public void test1(@RequestBody UserVO user) {
-        System.err.println(redisLock.lock("test"));
         System.err.println(11111);
-        System.err.println(redisLock.unlock("test"));
+        return;
+    }
+
+    @ApiOperation("分页查询所有数据")
+    @PutMapping("/put")
+    public void put(@RequestBody UserVO user) {
+        System.err.println(11111);
         return;
     }
 
     @ApiOperation("分页查询所有数据")
     @GetMapping("/test4")
     public void test1(Object object) throws JsonProcessingException {
-        System.err.println(object.toString());
         return;
     }
+
+    @ApiOperation("批量插入")
+    @PostMapping("/insertBatchSomeColumn")
+    public Integer insertBatchSomeColumn(@RequestBody List<User> list) {
+        return userService.insertBatchSomeColumn(list);
+    }
+
+    @ApiOperation("查询")
+    @PostMapping("/getById")
+    public User getById(@RequestBody List<User> list) {
+        return userService.getById(1);
+    }
+
+    @ApiOperation("查询")
+    @PostMapping("/getPage")
+    public Page<User> getPage(UserVO userVO) {
+        Page page = new Page(userVO.getCurrent(), userVO.getSize());
+        return userService.page(page);
+    }
+
+    @Override
+    public Page<?> getExportData(UserVO userVO) {
+        return getPage(userVO);
+    }
 }

+ 5 - 2
wei-user/wei-user-app/src/main/java/com/wei/user/entity/User.java

@@ -1,10 +1,12 @@
 package com.wei.user.entity;
 
-import java.util.Date;
-import java.io.Serializable;
+import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
+import java.io.Serializable;
+import java.util.Date;
+
 /**
  * <p>
  * 用户信息表
@@ -19,6 +21,7 @@ public class User implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    @TableId
     private Long id;
 
     /**

+ 68 - 0
wei-user/wei-user-app/src/main/java/com/wei/user/excelEntity/UserExcel.java

@@ -0,0 +1,68 @@
+package com.wei.user.excelEntity;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+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 UserExcel implements Serializable {
+
+
+    private static final long serialVersionUID = 1072879095890203450L;
+
+    @ExcelProperty(value = "id", index = 0)
+    private Long id;
+
+    /**
+     * 用户名称
+     */
+    @ExcelProperty(value = "用户名称", index = 1)
+    private String name;
+
+    /**
+     * 用户手机号
+     */
+    @ExcelProperty(value = "用户手机号", index = 2)
+    private String mobilePhone;
+
+    /**
+     * 用户邮箱
+     */
+    @ExcelProperty(value = "用户邮箱", index = 3)
+    private String email;
+
+    /**
+     * 密码
+     */
+    @ExcelProperty(value = "密码", index = 4)
+    private String password;
+
+    /**
+     * 用户头像地址
+     */
+    @ExcelProperty(value = "用户头像地址", index = 5)
+    private String pictureUrl;
+
+    /**
+     * 创建时间
+     */
+    @ExcelProperty(value = "创建时间", index = 6)
+    private Date createTime;
+
+    List<UserExcel> user;
+
+    List<String> list;
+}

+ 4 - 1
wei-user/wei-user-app/src/main/java/com/wei/user/mapper/UserMapper.java

@@ -1,7 +1,9 @@
 package com.wei.user.mapper;
 
-import com.wei.user.entity.User;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.wei.user.entity.User;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface UserMapper extends BaseMapper<User> {
 
+    int insertBatchSomeColumn(List<User> entityList);
 }

+ 10 - 5
wei-user/wei-user-app/src/main/java/com/wei/user/mapstruct/UserMapstruct.java

@@ -1,14 +1,19 @@
 package com.wei.user.mapstruct;
 
+import com.wei.user.entity.User;
+import com.wei.user.excelEntity.UserExcel;
 import org.mapstruct.Mapper;
 
+import java.util.List;
+
 /**
-* 用户信息表 服务类型实体转换
-*
-* @author wei
-* @since 2020-08-13
-*/
+ * 用户信息表 服务类型实体转换
+ *
+ * @author wei
+ * @since 2020-08-13
+ */
 @Mapper(componentModel = "spring")
 public interface UserMapstruct {
 
+    List<UserExcel> userToUserExcel(List<User> user);
 }

+ 4 - 1
wei-user/wei-user-app/src/main/java/com/wei/user/service/UserService.java

@@ -1,7 +1,9 @@
 package com.wei.user.service;
 
-import com.wei.user.entity.User;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.wei.user.entity.User;
+
+import java.util.List;
 
 /**
  * <p>
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface UserService extends IService<User> {
 
+    Integer insertBatchSomeColumn(List<User> list);
 }

+ 7 - 1
wei-user/wei-user-app/src/main/java/com/wei/user/service/impl/UserServiceImpl.java

@@ -7,6 +7,8 @@ import com.wei.user.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 用户信息表 服务实现类
@@ -20,5 +22,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 
     @Autowired
     private UserMapper userMapper;
-    
+
+    @Override
+    public Integer insertBatchSomeColumn(List<User> list) {
+        return userMapper.insertBatchSomeColumn(list);
+    }
 }

+ 4 - 2
wei-user/wei-user-app/src/main/java/com/wei/user/vo/UserVO.java

@@ -1,5 +1,6 @@
 package com.wei.user.vo;
 
+import com.wei.base.springframework.constant.vo.PageRequest;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -17,9 +18,10 @@ import java.util.List;
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
-public class UserVO implements Serializable {
+public class UserVO extends PageRequest implements Serializable {
 
-    private static final long serialVersionUID = 1L;
+
+    private static final long serialVersionUID = 1072879095890203450L;
 
     private Long id;
 

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

@@ -2,7 +2,6 @@ server:
   port: 8201
 
 spring:
-
   application:
     name: wei-user
   cloud:
@@ -12,13 +11,14 @@ spring:
       # consul启动端口
       port: 8500
 
-  profiles:
-    active: ttt
 
-  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
+  #  profiles:
+#    active: dev
+
+#  datasource:
+#    url: jdbc:p6spy: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