lym 6 日 前
コミット
28e72718aa
25 ファイル変更3146 行追加0 行削除
  1. 101 0
      forest-common/pom.xml
  2. 86 0
      forest-common/src/main/java/com/hwrj/cloud/common/api/CommonPage.java
  3. 150 0
      forest-common/src/main/java/com/hwrj/cloud/common/api/CommonResult.java
  4. 11 0
      forest-common/src/main/java/com/hwrj/cloud/common/api/IErrorCode.java
  5. 29 0
      forest-common/src/main/java/com/hwrj/cloud/common/api/ResultCode.java
  6. 14 0
      forest-common/src/main/java/com/hwrj/cloud/common/entity/BaseForm.java
  7. 68 0
      forest-common/src/main/java/com/hwrj/cloud/common/entity/NoteInfo.java
  8. 33 0
      forest-common/src/main/java/com/hwrj/cloud/common/exception/ApiException.java
  9. 18 0
      forest-common/src/main/java/com/hwrj/cloud/common/exception/Asserts.java
  10. 36 0
      forest-common/src/main/java/com/hwrj/cloud/common/exception/GlobalException.java
  11. 75 0
      forest-common/src/main/java/com/hwrj/cloud/common/exception/GlobalExceptionHandler.java
  12. 22 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/CompanyInfo.java
  13. 1478 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/DateCommonUtil.java
  14. 35 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/DateUtil.java
  15. 31 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/FileUtil.java
  16. 265 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/HttpUtils.java
  17. 51 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/InvitationCodeUtil.java
  18. 64 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/JsonUtils.java
  19. 74 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/LogKit.java
  20. 156 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/ResultEnum.java
  21. 40 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/SMSEnum.java
  22. 86 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/SMSUtil.java
  23. 83 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/ShareCodeUtil.java
  24. 134 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/StrKit.java
  25. 6 0
      forest-common/src/main/java/com/hwrj/cloud/common/util/StringUtil.java

+ 101 - 0
forest-common/pom.xml

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>forest-mall-cloud</artifactId>
+        <groupId>com.hwrj.cloud</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.hwrj.cloud.common</groupId>
+    <artifactId>forest-common</artifactId>
+    <version>${forest.version}</version>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper-spring-boot-starter</artifactId>
+        </dependency>
+
+
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>2.10.8</version>
+        </dependency>
+
+        <!-- commons-lang3 -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.11</version>
+        </dependency>
+
+
+
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-commons</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.jsonwebtoken</groupId>
+            <artifactId>jjwt</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-jdbc</artifactId>
+        </dependency>
+
+        <!--短信服务-->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>aliyun-java-sdk-core</artifactId>
+            <version>4.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
+            <version>5.2.8.RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.73</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat.embed</groupId>
+            <artifactId>tomcat-embed-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.security</groupId>
+            <artifactId>spring-security-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.security</groupId>
+            <artifactId>spring-security-core</artifactId>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 86 - 0
forest-common/src/main/java/com/hwrj/cloud/common/api/CommonPage.java

@@ -0,0 +1,86 @@
+package com.hwrj.cloud.common.api;
+
+import com.github.pagehelper.PageInfo;
+import org.springframework.data.domain.Page;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 分页数据封装类
+ * Created by macro on 2019/4/19.
+ */
+public class CommonPage<T> {
+    private Integer pageNum;
+    private Integer pageSize;
+    private Integer totalPage;
+    private Long total;
+    private List<T> list=new ArrayList<>();
+
+    /**
+     * 将PageHelper分页后的list转为分页信息
+     */
+    public static <T> CommonPage<T> restPage(List<T> list) {
+        CommonPage<T> result = new CommonPage<T>();
+        PageInfo<T> pageInfo = new PageInfo<T>(list);
+        result.setTotalPage(pageInfo.getPages());
+        result.setPageNum(pageInfo.getPageNum());
+        result.setPageSize(pageInfo.getPageSize());
+        result.setTotal(pageInfo.getTotal());
+        result.setList(pageInfo.getList());
+        return result;
+    }
+
+    /**
+     * 将SpringData分页后的list转为分页信息
+     */
+    public static <T> CommonPage<T> restPage(Page<T> pageInfo) {
+        CommonPage<T> result = new CommonPage<T>();
+        result.setTotalPage(pageInfo.getTotalPages());
+        result.setPageNum(pageInfo.getNumber());
+        result.setPageSize(pageInfo.getSize());
+        result.setTotal(pageInfo.getTotalElements());
+        result.setList(pageInfo.getContent());
+        return result;
+    }
+
+    public Integer getPageNum() {
+        return pageNum;
+    }
+
+    public void setPageNum(Integer pageNum) {
+        this.pageNum = pageNum;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public Integer getTotalPage() {
+        return totalPage;
+    }
+
+    public void setTotalPage(Integer totalPage) {
+        this.totalPage = totalPage;
+    }
+
+    public List<T> getList() {
+        return list;
+    }
+
+    public void setList(List<T> list) {
+        this.list = list;
+    }
+
+    public Long getTotal() {
+        return total;
+    }
+
+    public void setTotal(Long total) {
+        this.total = total;
+    }
+}

+ 150 - 0
forest-common/src/main/java/com/hwrj/cloud/common/api/CommonResult.java

@@ -0,0 +1,150 @@
+package com.hwrj.cloud.common.api;
+
+import io.swagger.annotations.ApiModel;
+
+/**
+ * 通用返回对象
+ * Created by macro on 2019/4/19.
+ */
+@ApiModel("公共返回类")
+public class CommonResult<T> {
+
+    private long code;
+    private String message;
+    private T data;
+
+    protected CommonResult() {
+    }
+
+    protected CommonResult(long code, String message, T data) {
+        this.code = code;
+        this.message = message;
+        this.data = data;
+    }
+
+    protected CommonResult(long code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    /**
+     * 成功返回结果
+     *
+     * @param data 获取的数据
+     */
+    public static <T> CommonResult<T> success(T data) {
+        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
+    }
+    /**
+     * 成功返回结果
+     *
+     * @param data 获取的数据
+     */
+    public static <T> CommonResult<T> success() {
+        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
+    }
+
+    /**
+     * 成功返回结果
+     *
+     * @param data 获取的数据
+     * @param  message 提示信息
+     */
+    public static <T> CommonResult<T> success(T data, String message) {
+        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
+    }
+
+    /**
+     * 失败返回结果
+     * @param errorCode 错误码
+     */
+    public static <T> CommonResult<T> failed(IErrorCode errorCode) {
+        return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
+    }
+
+    /**
+     * 失败返回结果
+     * @param errorCode 错误码
+     * @param message 错误信息
+     */
+    public static <T> CommonResult<T> failed(IErrorCode errorCode,String message) {
+        return new CommonResult<T>(errorCode.getCode(), message, null);
+    }
+
+    /**
+     * 失败返回结果
+     * @param errorCode 错误码
+     * @param message 错误信息
+     */
+    public static <T> CommonResult<T> failed(long errorCode,String message) {
+        return new CommonResult<T>(errorCode, message, null);
+    }
+
+    /**
+     * 失败返回结果
+     * @param message 提示信息
+     */
+    public static <T> CommonResult<T> failed(String message) {
+        return new CommonResult<T>(ResultCode.FAILED.getCode(), message, null);
+    }
+
+    /**
+     * 失败返回结果
+     */
+    public static <T> CommonResult<T> failed() {
+        return failed(ResultCode.FAILED);
+    }
+
+    /**
+     * 参数验证失败返回结果
+     */
+    public static <T> CommonResult<T> validateFailed() {
+        return failed(ResultCode.VALIDATE_FAILED);
+    }
+
+    /**
+     * 参数验证失败返回结果
+     * @param message 提示信息
+     */
+    public static <T> CommonResult<T> validateFailed(String message) {
+        return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message, null);
+    }
+
+    /**
+     * 未登录返回结果
+     */
+    public static <T> CommonResult<T> unauthorized(T data) {
+        return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
+    }
+
+    /**
+     * 未授权返回结果
+     */
+    public static <T> CommonResult<T> forbidden(T data) {
+        return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
+    }
+
+    public long getCode() {
+        return code;
+    }
+
+    public void setCode(long code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+}

+ 11 - 0
forest-common/src/main/java/com/hwrj/cloud/common/api/IErrorCode.java

@@ -0,0 +1,11 @@
+package com.hwrj.cloud.common.api;
+
+/**
+ * 封装API的错误码
+ * Created by macro on 2019/4/19.
+ */
+public interface IErrorCode {
+    long getCode();
+
+    String getMessage();
+}

+ 29 - 0
forest-common/src/main/java/com/hwrj/cloud/common/api/ResultCode.java

@@ -0,0 +1,29 @@
+package com.hwrj.cloud.common.api;
+
+/**
+ * 枚举了一些常用API操作码
+ * Created by macro on 2019/4/19.
+ */
+public enum ResultCode implements IErrorCode {
+    SUCCESS(200, "操作成功"),
+    FAILED(500, "操作失败"),
+    VALIDATE_FAILED(404, "参数检验失败"),
+    UNAUTHORIZED(401, "暂未登录或token已经过期"),
+    FORBIDDEN(403, "没有相关权限");
+    private long code;
+    private String message;
+
+    private ResultCode(long code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    @Override
+    public long getCode() {
+        return code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+}

+ 14 - 0
forest-common/src/main/java/com/hwrj/cloud/common/entity/BaseForm.java

@@ -0,0 +1,14 @@
+package com.hwrj.cloud.common.entity;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+@ApiModel(value = "基础请求类")
+@Data
+public class BaseForm {
+    private int pageSize=10;
+
+    private int pageNo=1;
+
+
+}

+ 68 - 0
forest-common/src/main/java/com/hwrj/cloud/common/entity/NoteInfo.java

@@ -0,0 +1,68 @@
+package com.hwrj.cloud.common.entity;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.io.Serializable;
+
+/***
+ * 短信信息
+ * @Author : vic
+ */
+public class NoteInfo implements Serializable {
+
+    /**
+     * 请求ID
+     */
+    @JsonProperty("RequestId")
+    private String requestId;
+
+    /**
+     * 状态码
+     */
+    @JsonProperty("Code")
+    private String code;
+
+    /**
+     * 状态码的描述
+     */
+    @JsonProperty("Message")
+    private String message;
+
+    /**
+     * 发送回执ID
+     */
+    @JsonProperty("BizId")
+    private String bizId;
+
+    public String getRequestId() {
+        return requestId;
+    }
+
+    public void setRequestId(String requestId) {
+        this.requestId = requestId;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public String getBizId() {
+        return bizId;
+    }
+
+    public void setBizId(String bizId) {
+        this.bizId = bizId;
+    }
+}

+ 33 - 0
forest-common/src/main/java/com/hwrj/cloud/common/exception/ApiException.java

@@ -0,0 +1,33 @@
+package com.hwrj.cloud.common.exception;
+
+
+import com.hwrj.cloud.common.api.IErrorCode;
+
+/**
+ * 自定义API异常
+ * Created by macro on 2020/2/27.
+ */
+public class ApiException extends RuntimeException {
+    private IErrorCode errorCode;
+
+    public ApiException(IErrorCode errorCode) {
+        super(errorCode.getMessage());
+        this.errorCode = errorCode;
+    }
+
+    public ApiException(String message) {
+        super(message);
+    }
+
+    public ApiException(Throwable cause) {
+        super(cause);
+    }
+
+    public ApiException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IErrorCode getErrorCode() {
+        return errorCode;
+    }
+}

+ 18 - 0
forest-common/src/main/java/com/hwrj/cloud/common/exception/Asserts.java

@@ -0,0 +1,18 @@
+package com.hwrj.cloud.common.exception;
+
+
+import com.hwrj.cloud.common.api.IErrorCode;
+
+/**
+ * 断言处理类,用于抛出各种API异常
+ * Created by macro on 2020/2/27.
+ */
+public class Asserts {
+    public static void fail(String message) {
+        throw new ApiException(message);
+    }
+
+    public static void fail(IErrorCode errorCode) {
+        throw new ApiException(errorCode);
+    }
+}

+ 36 - 0
forest-common/src/main/java/com/hwrj/cloud/common/exception/GlobalException.java

@@ -0,0 +1,36 @@
+package com.hwrj.cloud.common.exception;
+
+
+import com.hwrj.cloud.common.util.ResultEnum;
+
+/**
+ * @author qiubo
+ */
+public class GlobalException extends RuntimeException {
+
+
+    private Integer code;
+
+    public GlobalException(String errorMessage) {
+        super(errorMessage);
+    }
+
+    public GlobalException(Integer code, String msg) {
+        this(msg);
+        this.setCode(code);
+    }
+
+    public GlobalException(ResultEnum resultEnum) {
+        this(resultEnum.getMsg());
+        this.setCode(resultEnum.getCode());
+    }
+
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+}

+ 75 - 0
forest-common/src/main/java/com/hwrj/cloud/common/exception/GlobalExceptionHandler.java

@@ -0,0 +1,75 @@
+package com.hwrj.cloud.common.exception;
+
+
+import com.hwrj.cloud.common.api.CommonResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.validation.BindException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+/**
+ * 全局异常处理
+ * Created by macro on 2020/2/27.
+ */
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
+
+    @ExceptionHandler(value = ApiException.class)
+    public CommonResult handle(ApiException e) {
+        if (e.getErrorCode() != null) {
+            return CommonResult.failed(e.getErrorCode());
+        }
+        return CommonResult.failed(e.getMessage());
+    }
+
+    /**
+     * 自定义验证异常
+     */
+    @ExceptionHandler(BindException.class)
+    public CommonResult validatedBindException(BindException e){
+        log.error(e.getMessage(), e);
+        String message = e.getAllErrors().get(0).getDefaultMessage();
+        return CommonResult.failed(message);
+    }
+
+    /**
+     * 自定义验证异常
+     */
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    public Object validExceptionHandler(MethodArgumentNotValidException e){
+        log.error(e.getMessage(), e);
+        String message = e.getBindingResult().getFieldError().getDefaultMessage();
+        return CommonResult.failed(message);
+    }
+
+    /**
+     * 业务异常
+     */
+    @ExceptionHandler(GlobalException.class)
+    public CommonResult businessException(GlobalException e){
+         return CommonResult.failed(e.getMessage());
+    }
+    /**
+     * 处理自定义异常
+     * @param ex
+     * @return
+     */
+    @ExceptionHandler(RuntimeException.class)
+    @ResponseBody
+    public CommonResult handleOrderException(RuntimeException ex) {
+        return CommonResult.failed(500 ,ex.getMessage());
+    }
+
+    @ExceptionHandler(UsernameNotFoundException.class)
+    @ResponseBody
+    public CommonResult usernameNotFoundException(UsernameNotFoundException ex) {
+        return CommonResult.failed(400 ,ex.getMessage());
+    }
+
+}

+ 22 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/CompanyInfo.java

@@ -0,0 +1,22 @@
+package com.hwrj.cloud.common.util;
+
+public class CompanyInfo {
+    private Long id;
+    private String compName;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getCompName() {
+        return compName;
+    }
+
+    public void setCompName(String compName) {
+        this.compName = compName;
+    }
+}

+ 1478 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/DateCommonUtil.java

@@ -0,0 +1,1478 @@
+package com.hwrj.cloud.common.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+
+public class DateCommonUtil {
+    // 默认日期格式
+    public static final String DATE_DEFAULT_FORMAT = "yyyy-MM-dd";
+
+    // 默认时间格式
+    public static final String DATETIME_DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+    // 默认时间格式
+    public static final String DATETIME_NOSECOND_FORMAT = "yyyy-MM-dd HH:mm";
+
+    public static final String DATETIME_HOUR_FORMAT = "yyyy-MM-dd HH";
+
+    public static final String TIME_DEFAULT_FORMAT = "HH:mm:ss";
+
+    public static final String TIME_HOUSER_FORMAT = "HH:mm";
+
+    public static final String TIME_MONTH_DAY_FORMAT = "MM.dd";
+
+    public static final ThreadLocal<DateFormat> DATE_FORMATTER = new ThreadLocal<DateFormat>() {
+        @Override
+        protected DateFormat initialValue() {
+            return new SimpleDateFormat("yyyy-MM-dd");
+        }
+    };
+
+    public static final DateTimeFormatter YMD_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+
+    public static final String DATE_YEAR_MONTH_FORMAT = "yyyy-MM";
+
+    public static final String DATE_DEFAULT_FORMAT_NO_SPACE = "yyyyMMdd";
+
+    /**
+     * 获取当前日期(yyyy-MM-dd)
+     *
+     * @return Date
+     */
+    public static Date getNowDate() {
+        return new DateTime().toDate();
+    }
+
+    /**
+     * 获取当前日期(yyyy-MM-dd)
+     *
+     * @return Date
+     */
+    public static String getNowDateToString() {
+        return new DateTime().toString(DATE_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 获取当前日期时间戳
+     *
+     * @return
+     */
+    public static Long getNowTimestamp() {
+        return getNowDateTime().getTime();
+    }
+
+    /**
+     * 获取指定日期时间戳
+     *
+     * @return
+     */
+    public static Long getDateTimestamp(Date date) {
+        return getDate(date).getTime();
+    }
+
+    /**
+     * 获取指定日期时间戳
+     *
+     * @return
+     */
+    public static Long getDateTimestamp(String date) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return getDate(date).getTime();
+    }
+
+    /**
+     * 获取当前日期(yyyy-MM-dd)
+     *
+     * @return
+     */
+    public static Date getNowDateTime() {
+        return getDate(new Date());
+    }
+
+    /**
+     * 获取当前日期(yyyy-MM-dd)
+     *
+     * @return
+     */
+    public static String getNowDateTimeToString() {
+        return new DateTime().toString(DATE_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 日期格式化yyyy-MM-dd
+     *
+     * @param date
+     * @return DATE
+     */
+    public static Date getDate(Date date) {
+        try {
+            return new DateTime(getDateToString(date)).toDate();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 日期格式化
+     *
+     * @param date
+     * @return
+     */
+    public static Date getDate(String date) {
+        try {
+            date = date.replace(" ", "T");//把空格替换成T
+            return new DateTime(date).toDate();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 时间戳转日期
+     *
+     * @param timeStamp
+     * @return
+     */
+    public static Date getDate(long timeStamp) {
+        return new Date(timeStamp);
+    }
+
+
+    /**
+     * 日期格式化yyyy-MM-dd
+     *
+     * @param date
+     * @return String
+     */
+    public static String getDateToString(Date date) {
+        return new DateTime(date).toString(DATE_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 日期格式化yyyy-MM-dd
+     *
+     * @param date
+     * @return String
+     */
+    public static String getDateToStringEx(Date date) {
+        if (null == date) {
+            return null;
+        }
+        return new DateTime(date).toString(DATE_DEFAULT_FORMAT);
+    }
+
+    public static String getDateToStringhour(Date date) {
+        if (null == date) {
+            return null;
+        }
+        return new DateTime(date).toString(TIME_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 日期格式化yyyy-MM-dd hh:MM:ss
+     *
+     * @param date
+     * @return String
+     */
+    public static String getDateToStrings(Date date) {
+        return new DateTime(date).toString(DATETIME_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 日期格式化yyyy-MM-dd
+     *
+     * @param date
+     * @return String
+     */
+    public static String getDateToString(String date) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).toString(DATE_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 日期格式化
+     *
+     * @param date
+     * @param formatStr
+     * @return
+     */
+    public static String getDateFormatToString(Date date, String formatStr) {
+        if (StringUtils.isNotBlank(formatStr)) {
+            return new DateTime(date).toString(formatStr);
+        }
+        return null;
+    }
+
+    /**
+     * 日期格式化
+     *
+     * @param date
+     * @param formatStr
+     * @return
+     */
+    public static String getDateFormatToString(String date, String formatStr) {
+        if (StringUtils.isNotBlank(formatStr)) {
+            date = date.replace(" ", "T");//把空格替换成T
+            return new DateTime(date).toString(formatStr);
+        }
+        return null;
+    }
+
+    /**
+     * 日期格式化
+     *
+     * @param date
+     * @param formatStr
+     * @return
+     */
+    public static Date getDateFormat(Date date, String formatStr) {
+        if (StringUtils.isNotBlank(formatStr)) {
+            return new DateTime(new DateTime(date).toString(formatStr)).toDate();
+        }
+        return null;
+    }
+
+    /**
+     * 日期格式化
+     *
+     * @param date
+     * @param formatStr
+     * @return
+     */
+    public static Date getDateFormat(String date, String formatStr) {
+        if (StringUtils.isNotBlank(formatStr)) {
+            date = date.replace(" ", "T");//把空格替换成T
+            return new DateTime(new DateTime(date).toString(formatStr)).toDate();
+        }
+        return null;
+    }
+    //-----------------
+
+    /**
+     * 日期格式化 yyyy-MM-dd HH:mm:ss
+     *
+     * @param date
+     * @return DATE
+     */
+    public static Date getDateTime(Date date) {
+        try {
+            return new DateTime(date).toDate();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 日期格式化 yyyy-MM-dd HH:mm:ss
+     *
+     * @param date
+     * @return DATE
+     */
+    public static Date getDateTime(String date) {
+        try {
+            date = date.replace(" ", "T");//把空格替换成T
+            return new DateTime(date).toDate();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 日期格式化 yyyy-MM-dd HH:mm:ss
+     *
+     * @param date
+     * @return String
+     */
+    public static String getDateTimeToString(Date date) {
+        return new DateTime(date).toString(DATETIME_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 日期格式化 yyyy-MM-dd HH:mm:ss
+     *
+     * @param date
+     * @return String
+     */
+    public static String getDateTimeToString(String date) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).toString(DATETIME_DEFAULT_FORMAT);
+    }
+
+    /**
+     * 获取指定日期年份
+     *
+     * @param date
+     * @return
+     */
+    public static int geYear(Date date) {
+        return new DateTime(date).getYear();
+    }
+
+    /**
+     * 获取指定日期年份
+     *
+     * @param date
+     * @return
+     */
+    public static int getYear(String date) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).getYear();
+    }
+
+    /**
+     * 获取指定日期年份
+     *
+     * @param date
+     * @return
+     */
+    public static int getYear(Date date) {
+        return new DateTime(date).getYear();
+    }
+
+    /**
+     * 获取指定日期月份
+     *
+     * @param date
+     * @return
+     */
+    public static int getMonth(Date date) {
+        return new DateTime(date).getMonthOfYear();
+    }
+
+    /**
+     * 获取指定日期月份
+     *
+     * @param date
+     * @return
+     */
+    public static int getMonth(String date) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).getMonthOfYear();
+    }
+
+    /**
+     * 获取指定日期天数(号)
+     *
+     * @param date
+     * @return
+     */
+    public static int getDay(Date date) {
+        return new DateTime(date).getDayOfMonth();
+    }
+
+    /**
+     * 获取指定日期天数(号)
+     *
+     * @param date
+     * @return
+     */
+    public static int getDay(String date) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).getDayOfMonth();
+    }
+
+
+    /**
+     * 获取当前年
+     *
+     * @return
+     */
+    public static int getNowYear() {
+        Calendar d = Calendar.getInstance();
+        return d.get(Calendar.YEAR);
+    }
+
+    /**
+     * 获取当前月份
+     *
+     * @return
+     */
+    public static int getNowMonth() {
+        Calendar d = Calendar.getInstance();
+        return d.get(Calendar.MONTH) + 1;
+    }
+
+    /**
+     * 获取当月天数
+     *
+     * @return
+     */
+    public static int getNowMonthDay() {
+        Calendar d = Calendar.getInstance();
+        return d.getActualMaximum(Calendar.DATE);
+    }
+
+    /**
+     * 比较两日期大小
+     *
+     * @param date      日期字符串
+     * @param otherDate 另一个日期字符串
+     * @return 比较两日期大小。如果date>otherDate则返回true,否则false
+     */
+    public static Boolean whenGT(String date, String otherDate) {
+        date = date.replace(" ", "T");//把空格替换成T
+        otherDate = otherDate.replace(" ", "T");//把空格替换成T
+        return whenGT(getDate(date), getDate(otherDate));
+    }
+
+    /**
+     * 比较两日期大小
+     *
+     * @param date      日期
+     * @param otherDate 另一个日期
+     * @return 比较两日期大小。如果date>otherDate则返回true,否则false
+     */
+    public static Boolean whenGT(Date date, Date otherDate) {
+        Boolean flag = false;
+        Date dateTmp = getDateTime(date);
+        Date otherDateTmp = getDateTime(otherDate);
+        if (dateTmp != null && otherDateTmp != null) {
+            long time = dateTmp.getTime() - otherDateTmp.getTime();
+            if (time > 0) {
+                flag = true;
+            }
+        }
+        return flag;
+    }
+
+    /**
+     * 比较两日期是否相等
+     *
+     * @param date      日期字符串
+     * @param otherDate 另一个日期字符串
+     * @return 比较两日期大小。如果date==otherDate则返回true,否则false
+     */
+    public static Boolean whenEQ(String date, String otherDate) {
+        date = date.replace(" ", "T");//把空格替换成T
+        otherDate = otherDate.replace(" ", "T");//把空格替换成T
+        return whenEQ(getDate(date), getDate(otherDate));
+    }
+
+    /**
+     * 比较两日期是否相等
+     *
+     * @param date      日期
+     * @param otherDate 另一个日期
+     * @return 比较两日期大小。如果date==otherDate则返回true,否则false
+     */
+    public static Boolean whenEQ(Date date, Date otherDate) {
+        Boolean flag = false;
+        Date dateTmp = getDateTime(date);
+        Date otherDateTmp = getDateTime(otherDate);
+        if (dateTmp != null && otherDateTmp != null) {
+            long time = dateTmp.getTime() - otherDateTmp.getTime();
+            if (time == 0) {
+                flag = true;
+            }
+        }
+        return flag;
+    }
+
+    /**
+     * 比较两日期是否在同一天
+     *
+     * @param date      日期字符串
+     * @param otherDate 另一个日期字符串
+     * @return 比较两日期大小。如果date==otherDate则返回true,否则false
+     */
+    public static Boolean whenEQDay(String date, String otherDate) {
+        date = date.replace(" ", "T");//把空格替换成T
+        otherDate = otherDate.replace(" ", "T");//把空格替换成T
+        return whenEQ(getDate(date), getDate(otherDate));
+    }
+
+    /**
+     * 比较两日期是否在同一天
+     *
+     * @param date      日期
+     * @param otherDate 另一个日期
+     * @return 比较两日期大小。如果date==otherDate则返回true,否则false
+     */
+    public static Boolean whenEQDay(Date date, Date otherDate) {
+        Boolean flag = false;
+        Date dateTmp = getDate(date);
+        Date otherDateTmp = getDate(otherDate);
+        if (dateTmp != null && otherDateTmp != null) {
+            long time = dateTmp.getTime() - otherDateTmp.getTime();
+            if (time == 0) {
+                flag = true;
+            }
+        }
+        return flag;
+    }
+
+    /**
+     * 获取提前多少个月
+     *
+     * @param monty
+     * @return
+     */
+    public static Date getFirstMonth(int monty) {
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -monty);
+        return c.getTime();
+    }
+
+    /**
+     * 获取两日期差,返回年月日差值
+     *
+     * @param date1
+     * @param date2
+     * @return
+     */
+    public static List<Integer> getDiffDates(String date1, String date2) {
+        String dates = "";
+        List<Integer> diffList = new ArrayList<Integer>();
+        try {
+            Date startDate = getDate(date1);
+            Date endDate = getDate(date2);
+            Calendar calS = Calendar.getInstance();
+            // 开始时间
+            calS.setTime(startDate);
+            int startY = calS.get(Calendar.YEAR);
+            int startM = calS.get(Calendar.MONTH);
+            int startD = calS.get(Calendar.DATE);
+            int startDayOfMonth = calS.getActualMaximum(Calendar.DAY_OF_MONTH);
+            // 结束时间
+            calS.setTime(endDate);
+            int endY = calS.get(Calendar.YEAR);
+            int endM = calS.get(Calendar.MONTH);
+            // 处理起止日期为同一天,默认服务为一天 示例:2016-01-01 至 2016-01-01
+            int endD = calS.get(Calendar.DATE) + 1;
+            int endDayOfMonth = calS.getActualMaximum(Calendar.DAY_OF_MONTH);
+            int lday = endD - startD;
+            // 每月按照30天计算
+            if (endD < startD) {
+                endM = endM - 1;
+                lday = 30 - startD + endD;
+            }
+            /*
+             * 按照正常日期计算 if (lday<0) { endM = endM -1; lday = startDayOfMonth+
+             * lday; }
+             */
+            // 处理服务天数问题,示例:2016-01-01 到 2017-12-31 实际上是1年
+            if (lday == endDayOfMonth) {
+                endM = endM + 1;
+                lday = 0;
+            }
+            int mos = (endY - startY) * 12 + (endM - startM);
+            int lyear = mos / 12;
+            int lmonth = mos % 12;
+            diffList.add(lyear);
+            diffList.add(lmonth);
+            diffList.add(lday);
+            dates = lyear + "年" + lmonth + "个月" + lday + "天";
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return diffList;
+    }
+    /**
+     * 获取两日期差,返回年月日差值
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static List<Integer> getDiffDates(Date startDate, Date endDate) {
+        String dates = "";
+        List<Integer> diffList = new ArrayList<Integer>();
+        try {
+            Calendar calS = Calendar.getInstance();
+            // 开始时间
+            calS.setTime(startDate);
+            int startY = calS.get(Calendar.YEAR);
+            int startM = calS.get(Calendar.MONTH);
+            int startD = calS.get(Calendar.DATE);
+            int startDayOfMonth = calS.getActualMaximum(Calendar.DAY_OF_MONTH);
+            // 结束时间
+            calS.setTime(endDate);
+            int endY = calS.get(Calendar.YEAR);
+            int endM = calS.get(Calendar.MONTH);
+            // 处理起止日期为同一天,默认服务为一天 示例:2016-01-01 至 2016-01-01
+            int endD = calS.get(Calendar.DATE) + 1;
+            int endDayOfMonth = calS.getActualMaximum(Calendar.DAY_OF_MONTH);
+            int lday = endD - startD;
+            // 每月按照30天计算
+            if (endD < startD) {
+                endM = endM - 1;
+                lday = 30 - startD + endD;
+            }
+            /*
+             * 按照正常日期计算 if (lday<0) { endM = endM -1; lday = startDayOfMonth+
+             * lday; }
+             */
+            // 处理服务天数问题,示例:2016-01-01 到 2017-12-31 实际上是1年
+            if (lday == endDayOfMonth) {
+                endM = endM + 1;
+                lday = 0;
+            }
+            int mos = (endY - startY) * 12 + (endM - startM);
+            int lyear = mos / 12;
+            int lmonth = mos % 12;
+            diffList.add(lyear);
+            diffList.add(lmonth);
+            diffList.add(lday);
+            dates = lyear + "年" + lmonth + "个月" + lday + "天";
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return diffList;
+    }
+    /**
+     * 获取两日期相差的天数
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static Integer getDiffDays(Date startDate, Date endDate) {
+        if (StringUtil.isEmpty(startDate) || StringUtil.isEmpty(endDate)) {
+            return 0;
+        }
+        return (int) ((endDate.getTime() - startDate.getTime()) / (1000 * 3600 * 24));
+    }
+    /**
+     * @Description: 计算两个日期相隔多少天
+     * @Param: [start, end]
+     * @return: int
+     * @Author: cx
+     * @Date: 2018/6/28
+     */
+    public static int daysApart(Date start, Date end) {
+        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+        try {
+            Date StartDate = df.parse(df.format(start));
+            Date endDate = df.parse(df.format(end));
+            return (int) ((endDate.getTime() - StartDate.getTime()) / (24 * 60 * 60 * 1000L));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return 0;
+    }
+    /**
+     * 增加日期的年份。失败返回null。
+     *
+     * @param date       日期
+     * @param yearAmount 增加数量。可为负数
+     * @return String 增加年份后的日期字符串
+     */
+    public static String addYear(String date, int yearAmount) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).plusMonths(yearAmount).toString();
+    }
+    /**
+     * 增加日期的年份。失败返回null。
+     *
+     * @param date       日期
+     * @param yearAmount 增加数量。可为负数
+     * @return 增加年份后的日期
+     */
+    public static Date addYear(Date date, int yearAmount) {
+        return new DateTime(date).plusMonths(yearAmount).toDate();
+    }
+    /**
+     * 增加日期的月份。失败返回null
+     *
+     * @param date        日期
+     * @param monthAmount 增加数量。可为负数
+     * @return String 增加月份后的日期字符串
+     */
+    public static String addMonth(String date, int monthAmount) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).plusMonths(monthAmount).toString();
+    }
+    /**
+     * 增加日期的月份。失败返回null。
+     *
+     * @param date        日期
+     * @param monthAmount 增加数量。可为负数
+     * @return 增加月份后的日期
+     */
+    public static Date addMonth(Date date, int monthAmount) {
+        return new DateTime(date).plusMonths(monthAmount).toDate();
+    }
+    /**
+     * 增加日期的天数。失败返回null。
+     *
+     * @param date      日期字符串
+     * @param dayAmount 增加数量。可为负数
+     * @return 增加天数后的日期字符串
+     */
+    public static String addDay(String date, int dayAmount) {
+        date = date.replace(" ", "T");//把空格替换成T
+        return new DateTime(date).plusDays(dayAmount).toString();
+    }
+    /**
+     * 增加日期的天数。失败返回null。
+     *
+     * @param date      日期
+     * @param dayAmount 增加数量。可为负数
+     * @return 增加天数后的日期
+     */
+    public static Date addDay(Date date, int dayAmount) {
+        return new DateTime(date).plusDays(dayAmount).toDate();
+    }
+    /**
+     * 设置指定日期(天)。失败返回null。
+     *
+     * @param date      日期
+     * @param dayAmount 增加数量。可为负数
+     * @return 增加天数后的日期
+     */
+    public static Date setDay(Date date, int dayAmount) {
+        DateTime dateTime = new DateTime(date);
+        return new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dayAmount, dateTime.getHourOfDay(), dateTime.getMillisOfDay()).toDate();
+    }
+    /**
+     * 设置指定日期(天)。失败返回null。
+     *
+     * @param date      日期
+     * @param dayAmount 增加数量。可为负数
+     * @return 增加天数后的日期
+     */
+    public static Date setDay(String date, int dayAmount) {
+        date = date.replace(" ", "T");//把空格替换成T
+        DateTime dateTime = new DateTime(date);
+        return new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dayAmount, dateTime.getHourOfDay(), dateTime.getMillisOfDay()).toDate();
+    }
+    /**
+     * 设置固定日期,如果输入数字大于该月最大日期那么默认为当月最大日期
+     *
+     * @param date
+     * @param dayAmount
+     * @return
+     */
+    public static Date setDayPlus(String date, int dayAmount) {
+        date = date.replace(" ", "T");//把空格替换成T
+        DateTime dateTime = new DateTime(date);
+        if (dayAmount >= 29) {
+            Date[] dates = DateCommonUtil.computeMonthFirstAndLastDay(DateCommonUtil.getDate(date), 0);
+            String dateStr = DateCommonUtil.getDateToString(dates[1]);
+            String dayStr = dateStr.substring(dateStr.length() - 2);
+            Integer day = Integer.valueOf(dayStr);
+            if (dayAmount > day) {
+                {
+                    dayAmount = day;
+                }
+            }
+        }
+        return new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dayAmount, dateTime.getHourOfDay(), dateTime.getMillisOfDay()).toDate();
+    }
+
+    /**
+     * 获取日期是一周中的第几天 每周从周一开始
+     *
+     * @param date
+     * @return
+     */
+    public static int getDateInWeekFewDay(Date date) {
+        SimpleDateFormat sdf = new SimpleDateFormat("E");
+        String key = sdf.format(getDateFormat(date, DATE_DEFAULT_FORMAT));
+        if ("星期一".equals(key) || "Mon".equals(key) || "MON".equals(key)) {
+            return 1;
+        } else if ("星期二".equals(key) || "Tue".equals(key) || "TUE".equals(key)) {
+            return 2;
+        } else if ("星期三".equals(key) || "Wed".equals(key) || "WED".equals(key)) {
+            return 3;
+        } else if ("星期四".equals(key) || "Thu".equals(key) || "THU".equals(key)) {
+            return 4;
+        } else if ("星期五".equals(key) || "Fri".equals(key) || "FRI".equals(key)) {
+            return 5;
+        } else if ("星期六".equals(key) || "Sat".equals(key) || "SAT".equals(key)) {
+            return 6;
+        }
+        return 7;
+    }
+
+    /**
+     * 计算得到日期区间的所有日期
+     * 例如:from=2017-06-25 to=2017-06-28 那么他们之间的日期就是 2017-06-26 2017-06-27
+     *
+     * @param from
+     * @param to
+     * @return
+     */
+    public static List<Date> computeDateRangeDate(Date from, Date to) {
+        List<Date> dateRange = new ArrayList<Date>();
+        from = DateCommonUtil.getDateFormat(from, DATE_DEFAULT_FORMAT);
+        to = DateCommonUtil.getDateFormat(to, DATE_DEFAULT_FORMAT);
+        Calendar startCal = Calendar.getInstance();
+        startCal.setTime(getDateFormat(from, DATE_DEFAULT_FORMAT));
+        startCal.add(Calendar.DAY_OF_YEAR, 1);
+        Calendar endCal = Calendar.getInstance();
+        endCal.setTime(getDateFormat(to, DATE_DEFAULT_FORMAT));
+        while (startCal.before(endCal)) {
+            dateRange.add(startCal.getTime());
+            startCal.add(Calendar.DAY_OF_YEAR, 1);
+        }
+        return dateRange;
+    }
+
+    /**
+     * 获取指定日期所在月总天数
+     *
+     * @param sourceDate
+     * @return
+     */
+    public static int getMonthDayCount(Date sourceDate) {
+        Calendar d = Calendar.getInstance();
+        d.setTime(sourceDate);
+        return d.getActualMaximum(Calendar.DATE);
+    }
+
+    /**
+     * Date转换为LocalDate
+     */
+    public static LocalDate dateToLocalDate(Date date) {
+        Instant instant = date.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+        return instant.atZone(zoneId).toLocalDate();
+    }
+
+    /**
+     * LocalDate转换为Date
+     */
+    public static Date localDateToDate(LocalDate localDate) {
+        ZoneId zoneId = ZoneId.systemDefault();
+        ZonedDateTime zdt = localDate.atStartOfDay(zoneId);
+        return Date.from(zdt.toInstant());
+    }
+
+    /**
+     * 计算某月一号和最后一天
+     *
+     * @param sourceDate    源日期
+     * @param monthInterval 目标月与当前月月差值(正负均可)
+     * @return
+     */
+    public static Date[] computeMonthFirstAndLastDay(Date sourceDate, int monthInterval) {
+        Date[] destDates = new Date[2];
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(sourceDate);
+        cal.add(Calendar.MONTH, monthInterval);
+        cal.set(Calendar.DAY_OF_MONTH, 1);
+        destDates[0] = DateCommonUtil.getDate(DATE_FORMATTER.get().format(cal.getTime()));
+        if (monthInterval < 0) {
+            cal.setTime(sourceDate);
+            if (monthInterval < -1) {
+                cal.add(Calendar.MONTH, monthInterval + 1);
+            }
+        }
+        if (monthInterval >= 0) {
+            cal.add(Calendar.MONTH, 1);
+        }
+        cal.set(Calendar.DAY_OF_MONTH, 0);
+        destDates[1] = DateCommonUtil.getDate(DATE_FORMATTER.get().format(cal.getTime()));
+
+        return destDates;
+    }
+
+    /**
+     * 获取当前日期的下一天
+     *
+     * @return
+     */
+    public static String getAfterDay(Date date) {
+        Calendar calendar = new GregorianCalendar();
+        calendar.setTime(date);
+        calendar.add(Calendar.DATE, 1);//把日期往后增加一天.整数往后推,负数往前移动
+        date = calendar.getTime();   //这个时间就是日期往后推一天的结果
+        return DateCommonUtil.getDateToString(date);
+    }
+
+    /**
+     * 获取当前日期的前一天
+     *
+     * @return
+     */
+    public static String getBeforeDay(Date date) {
+        Calendar calendar = new GregorianCalendar();
+        calendar.setTime(date);
+        calendar.add(Calendar.DATE, -1);//把日期往后增加一天.整数往后推,负数往前移动
+        date = calendar.getTime();   //这个时间就是日期往后推一天的结果
+        return DateCommonUtil.getDateToString(date);
+    }
+
+    /**
+     * 获取两日期相差的天数(格式转为YMD格式 消除HMS带来的误差)
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static Integer getDiffDaysEx(Date startDate, Date endDate) {
+        if (StringUtil.isEmpty(startDate) || StringUtil.isEmpty(endDate)) {
+            return 0;
+        }
+        try {
+            DateFormat df = DATE_FORMATTER.get();
+            startDate = df.parse(df.format(startDate));
+            endDate = df.parse(df.format(endDate));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return (int) ((endDate.getTime() - startDate.getTime()) / (1000 * 3600 * 24)) + 1;
+    }
+
+    /**
+     * 比较两日期大小
+     *
+     * @param date      日期
+     * @param otherDate 另一个日期
+     * @return 比较两日期大小。如果date>otherDate则返回true,否则false
+     */
+    public static Boolean whenGTOrEQ(Date date, Date otherDate) {
+        Boolean flag = false;
+        Date dateTmp = getDateTime(date);
+        Date otherDateTmp = getDateTime(otherDate);
+        if (dateTmp != null && otherDateTmp != null) {
+            long time = dateTmp.getTime() - otherDateTmp.getTime();
+            if (time >= 0) {
+                flag = true;
+            }
+        }
+        return flag;
+    }
+
+    /**
+     * 计算得到日期区间的所有日期(包含开始日期)
+     * 例如:from=2017-06-25 to=2017-06-28 那么他们之间的日期就是 2017-06-25 2017-06-26 2017-06-27
+     *
+     * @param from
+     * @param to
+     * @return
+     */
+    public static List<Date> computeDateRangeDateEx(Date from, Date to) {
+        List<Date> dateRange = new ArrayList<Date>();
+        from = DateCommonUtil.getDateFormat(from, DATE_DEFAULT_FORMAT);
+        to = DateCommonUtil.getDateFormat(to, DATE_DEFAULT_FORMAT);
+        dateRange.add(from);
+        Calendar startCal = Calendar.getInstance();
+        startCal.setTime(getDateFormat(from, DATE_DEFAULT_FORMAT));
+        startCal.add(Calendar.DAY_OF_YEAR, 1);
+        Calendar endCal = Calendar.getInstance();
+        endCal.setTime(getDateFormat(to, DATE_DEFAULT_FORMAT));
+        while (startCal.before(endCal)) {
+            dateRange.add(startCal.getTime());
+            startCal.add(Calendar.DAY_OF_YEAR, 1);
+        }
+        return dateRange;
+    }
+
+    /**
+     * 格式化日期 yyyy-MM
+     *
+     * @param date
+     * @return
+     */
+    public static Date getYearMonth(Date date) {
+        return getDate(new DateTime(date).toString(DATE_YEAR_MONTH_FORMAT));
+    }
+
+    /**
+     * 格式化日期 yyyy-MM 月份-1
+     *
+     * @param date
+     * @return
+     */
+    public static Date getPreYearMonth(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(Calendar.MONTH, -1);
+        return calendar.getTime();
+    }
+
+    public static int compareYearMonth(Date d1, Date d2) {
+
+        Calendar c1 = Calendar.getInstance();
+        c1.setTime(d1);
+        int y1 = c1.get(Calendar.YEAR);
+        int m1 = c1.get(Calendar.MONTH);
+
+        Calendar c2 = Calendar.getInstance();
+        c2.setTime(d2);
+        int y2 = c2.get(Calendar.YEAR);
+        int m2 = c2.get(Calendar.MONTH);
+        if (y1 == y2) {
+            return m1 - m2;
+        }
+        return y1 - y2;
+    }
+
+    public static int compareYearMonthDay(Date d1, Date d2) {
+        int compareYearMonth = compareYearMonth(d1, d2);
+        if (compareYearMonth == 0) {
+            Calendar c1 = Calendar.getInstance();
+            c1.setTime(d1);
+            int day1 = c1.get(Calendar.DAY_OF_MONTH);
+
+            Calendar c2 = Calendar.getInstance();
+            c2.setTime(d2);
+            int day2 = c2.get(Calendar.DAY_OF_MONTH);
+            return day1 - day2;
+        }
+        return compareYearMonth;
+    }
+
+    /**
+     * 给日期加上小时
+     *
+     * @param date yyyy-MM-dd格式的日期
+     * @param hour
+     * @return
+     */
+    public static Date addHour(Date date, int hour) {
+        //当前日期毫秒数
+        long currentTime = date.getTime();
+        //计算小时总计的毫秒数
+        long hourTime = hour * 60 * 60 * 1000;
+        //总的毫秒数
+        long totalTime = currentTime + hourTime;
+        return new Date(totalTime);
+    }
+
+
+    /**
+     * 判断两个日期区间是否存在交叉
+     *
+     * @param firstBeginDate
+     * @param firstEndDate
+     * @param secondBeginDate
+     * @param secondEndDate
+     * @return 如果有交叉返回true  否则返回false
+     */
+    public static boolean checkDateRangeCross(Date firstBeginDate, Date firstEndDate, Date secondBeginDate, Date secondEndDate) {
+        return ((firstBeginDate.getTime() >= secondBeginDate.getTime())
+                && firstBeginDate.getTime() < secondEndDate.getTime())
+                ||
+                ((firstBeginDate.getTime() > secondBeginDate.getTime())
+                        && firstBeginDate.getTime() <= secondEndDate.getTime())
+                ||
+                ((secondBeginDate.getTime() >= firstBeginDate.getTime())
+                        && secondBeginDate.getTime() < firstEndDate.getTime())
+                ||
+                ((secondBeginDate.getTime() > firstBeginDate.getTime())
+                        && secondBeginDate.getTime() <= firstEndDate.getTime());
+    }
+    /**
+     * 判断两个日期区间是否存在交叉
+     *
+     * @param firstBeginDate
+     * @param firstEndDate
+     * @param secondBeginDate
+     * @param secondEndDate
+     * @return 如果有交叉返回true  否则返回false
+     */
+    public static boolean checkDateRangeCross(long firstBeginDate, long firstEndDate, long secondBeginDate, long secondEndDate) {
+        return ((firstBeginDate >= secondBeginDate)
+                && firstBeginDate < secondEndDate)
+                ||
+                ((firstBeginDate > secondBeginDate)
+                        && firstBeginDate <= secondEndDate)
+                ||
+                ((secondBeginDate >= firstBeginDate)
+                        && secondBeginDate < firstEndDate)
+                ||
+                ((secondBeginDate > firstBeginDate)
+                        && secondBeginDate <= firstEndDate);
+    }
+    //小红点项目 获取开始显示红点的日期
+    public static Date getRedSpotDate() {
+        Date redSpotDate = DateCommonUtil.getDate("2018-2-21");
+        return redSpotDate;
+    }
+    /**
+     * 获得两个日期之间的所有月份
+     *
+     * @param minDate
+     * @param maxDate
+     * @return
+     * @throws Exception
+     */
+    public static List<String> getMonthBetween(String minDate, String maxDate) throws Exception {
+        ArrayList<String> result = new ArrayList<String>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
+        Calendar min = Calendar.getInstance();
+        Calendar max = Calendar.getInstance();
+        min.setTime(sdf.parse(minDate));
+        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
+        max.setTime(sdf.parse(maxDate));
+        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
+        Calendar curr = min;
+        while (curr.before(max)) {
+            result.add(sdf.format(curr.getTime()));
+            curr.add(Calendar.MONTH, 1);
+        }
+
+        return result;
+    }
+
+    /**
+     * 获得两个日期之间的所有日期
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     * @throws Exception
+     */
+    private static List<Date> dateSplit(Date startDate, Date endDate) throws Exception {
+        if (!startDate.before(endDate)) {
+            throw new Exception("开始时间应该在结束时间之后");
+        }
+        Long spi = endDate.getTime() - startDate.getTime();
+        Long step = spi / (24 * 60 * 60 * 1000);// 相隔天数
+        List<Date> dateList = new ArrayList<Date>();
+        dateList.add(endDate);
+        for (int i = 1; i <= step; i++) {
+            dateList.add(new Date(dateList.get(i - 1).getTime()
+                    - (24 * 60 * 60 * 1000)));// 比上一天减一
+        }
+        return dateList;
+    }
+    /**
+     * 获取某一时间段特定星期几的日期
+     *
+     * @param beginTime 开始时间
+     * @param endTime   结束时间
+     * @param weekDays  星期几
+     * @param dateTime  具体时间
+     *                  getDates("2013-04-01", "2014-04-14","星期一|星期二|星期日");
+     * @return 返回时间数组
+     */
+    public static List<Date> getDates(Date beginTime, Date endTime, String weekDays, Date dateTime) throws Exception {
+        String dateFrom = null;
+        String dateEnd = null;
+        long time = 1L;
+        long perDayMilSec = 24 * 60 * 60 * 1000;
+        List<Date> dateList = new ArrayList<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        SimpleDateFormat hms = new SimpleDateFormat("hh:mm:ss");
+        //需要查询的星期系数
+        String strWeekNumber = weekForNum(weekDays);
+        String houreTime = null;
+        if (dateTime != null) {
+            houreTime = hms.format(dateTime);
+        }
+        try {
+            dateFrom = sdf.format(beginTime.getTime() - perDayMilSec);
+            dateEnd = sdf.format(endTime);
+            while (true) {
+                time = sdf.parse(dateFrom).getTime();
+                time = time + perDayMilSec;
+                Date date = new Date(time);
+                dateFrom = sdf.format(date);
+                if (dateFrom.compareTo(dateEnd) <= 0) {
+                    //查询的某一时间的星期系数
+                    Integer weekDay = dayForWeek(date);
+                    //判断当期日期的星期系数是否是需要查询的
+                    if (strWeekNumber.indexOf(weekDay.toString()) != -1) {
+                        Date timeDate = sdf.parse(dateFrom + " " + houreTime);
+                        dateList.add(timeDate);
+                    }
+                } else {
+                    break;
+                }
+            }
+        } catch (ParseException e1) {
+            e1.printStackTrace();
+        }
+        return dateList;
+    }
+    //等到当期时间的周系数。星期日:1,星期一:2,星期二:3,星期三:4,星期四:5,星期五:6,星期六:7
+    public static Integer dayForWeek(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        return calendar.get(Calendar.DAY_OF_WEEK);
+    }
+    /**
+     * 得到对应星期的系数  星期日:1,星期一:2,星期二:3,星期三:4,星期四:5,星期五:6,星期六:7
+     *
+     * @param weekDays 星期格式  星期一|星期二
+     */
+    public static String weekForNum(String weekDays) {
+        //返回结果为组合的星期系数
+        String weekNumber = "";
+        //解析传入的星期
+        if (weekDays.indexOf("|") != -1) {//多个星期数
+            String[] strWeeks = weekDays.split("\\|");
+            for (int i = 0; i < strWeeks.length; i++) {
+                weekNumber = weekNumber + "" + getWeekNum(strWeeks[i]).toString();
+            }
+        } else {//一个星期数
+            weekNumber = getWeekNum(weekDays).toString();
+        }
+        return weekNumber;
+    }
+    /**
+     * 将星期转换为对应的系数  星期日:1,星期一:2,星期二:3,星期三:4,星期四:5,星期五:6,星期六:7
+     * @param strWeek
+     * @return
+     */
+    public static Integer getWeekNum(String strWeek) {
+        Integer number = 1;//默认为星期日
+        if ("星期日".equals(strWeek)) {
+            number = 1;
+        } else if ("星期一".equals(strWeek)) {
+            number = 2;
+        } else if ("星期二".equals(strWeek)) {
+            number = 3;
+        } else if ("星期三".equals(strWeek)) {
+            number = 4;
+        } else if ("星期四".equals(strWeek)) {
+            number = 5;
+        } else if ("星期五".equals(strWeek)) {
+            number = 6;
+        } else if ("星期六".equals(strWeek)) {
+            number = 7;
+        }
+        return number;
+    }
+    /**
+     * 获取当前日期是星期几<br>
+     *
+     * @param date
+     * @return 当前日期是星期几
+     */
+    public static String getWeekOfDate(Date date) {
+        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
+        if (w < 0) {
+            w = 0;
+        }
+        return weekDays[w];
+    }
+    /**
+     * 获取时间段内固定日期集合
+     *
+     * @param start
+     * @param end
+     * @param dayOfMonth
+     * @return
+     */
+    public static List<Date> getFixedDateList(Date start, Date end, int dayOfMonth) {
+        List<Date> dateList = new ArrayList<>();
+        List<Integer> diff = getDiffDates(start, end);
+//        int totalMonth = diff.get(0)*12 + diff.get(1) + (diff.get(2) > 0?1:0);
+        int totalMonth = diff.get(1);
+        //如果目标天小于开始日期的天那么从下月开始
+        if (DateCommonUtil.getDay(start) <= dayOfMonth) {
+            Date[] dates = DateCommonUtil.computeMonthFirstAndLastDay(DateCommonUtil.getDate(start), 0);
+            String dateStr = DateCommonUtil.getDateToString(dates[1]);
+            String dayStr = dateStr.substring(dateStr.length() - 2);
+            Integer day = Integer.valueOf(dayStr);
+            if (dayOfMonth <= day) {
+                String computeDate = dateStr.substring(0, dateStr.lastIndexOf("-") + 1);
+                Date targetDate = DateCommonUtil.getDate(computeDate + dayOfMonth);
+                dateList.add(targetDate);
+            }
+        }
+        //如果目标天大于结束日期的天那么只计算到结束日期的上个月
+        if (DateCommonUtil.getDay(end) < dayOfMonth) {
+            totalMonth--;
+        }
+        String sourceDate = DateCommonUtil.getDateToString(start);
+        for (int i = 0; i < totalMonth; i++) {
+            sourceDate = DateCommonUtil.getDateToString(DateCommonUtil.addMonth(sourceDate, 1));
+            String computeDate = sourceDate.substring(0, sourceDate.lastIndexOf("-") + 1);
+            Date[] dates = DateCommonUtil.computeMonthFirstAndLastDay(DateCommonUtil.getDate(sourceDate), 0);
+            String dateStr = DateCommonUtil.getDateToString(dates[1]);
+            String dayStr = dateStr.substring(dateStr.length() - 2);
+            Integer day = Integer.valueOf(dayStr);
+            if (dayOfMonth <= day) {
+                Date targetDate = DateCommonUtil.getDate(computeDate + dayOfMonth);
+                dateList.add(targetDate);
+            }
+        }
+        return dateList;
+    }
+    /**
+     * 获取时间段内固定日期时间集合
+     *
+     * @param start
+     * @param end
+     * @param dateTime
+     * @return
+     */
+    public static List<Date> getFixedDateTimeList(Date start, Date end, Date dateTime) {
+        List<Date> dateList = new ArrayList<>();
+        List<Integer> diff = getDiffDates(start, end);
+        String datetime = getDateFormatToString(dateTime, DATETIME_DEFAULT_FORMAT);
+        int dayOfMonth = Integer.parseInt(datetime.substring(8, 10));
+        String hms = datetime.substring(11, 19);
+//        int totalMonth = diff.get(0)*12 + diff.get(1) + (diff.get(2) > 0?1:0);
+        int totalMonth = diff.get(1);
+        //如果目标天小于开始日期的天那么从下月开始
+        if (DateCommonUtil.getDay(start) <= dayOfMonth) {
+            Date[] dates = DateCommonUtil.computeMonthFirstAndLastDay(DateCommonUtil.getDate(start), 0);
+            String dateStr = DateCommonUtil.getDateToString(dates[1]);
+            String dayStr = dateStr.substring(dateStr.length() - 2);
+            Integer day = Integer.valueOf(dayStr);
+            if (dayOfMonth <= day) {
+                String computeDate = dateStr.substring(0, dateStr.lastIndexOf("-") + 1);
+                computeDate = computeDate + dayOfMonth + " " + hms;
+                Date targetDate = DateCommonUtil.getDate(computeDate);
+                dateList.add(targetDate);
+            }
+        }
+        //如果目标天大于结束日期的天那么只计算到结束日期的上个月
+        if (DateCommonUtil.getDay(end) < dayOfMonth) {
+            totalMonth--;
+        }
+        String sourceDate = DateCommonUtil.getDateToString(start);
+        for (int i = 0; i < totalMonth; i++) {
+            sourceDate = DateCommonUtil.getDateToString(DateCommonUtil.addMonth(sourceDate, 1));
+            String computeDate = sourceDate.substring(0, sourceDate.lastIndexOf("-") + 1);
+            Date[] dates = DateCommonUtil.computeMonthFirstAndLastDay(DateCommonUtil.getDate(sourceDate), 0);
+            String dateStr = DateCommonUtil.getDateToString(dates[1]);
+            String dayStr = dateStr.substring(dateStr.length() - 2);
+            Integer day = Integer.valueOf(dayStr);
+            if (dayOfMonth <= day) {
+                computeDate = computeDate + dayOfMonth + " " + hms;
+                Date targetDate = DateCommonUtil.getDate(computeDate);
+                dateList.add(targetDate);
+            }
+        }
+        return dateList;
+    }
+    /**
+     * 获取固定日期
+     *
+     * @param begin
+     * @param end
+     * @return
+     */
+    public static List<Date> getData(Date begin, Date end, int day) {
+        Calendar l_begin = Calendar.getInstance();
+        l_begin.clear();
+        l_begin.setTime(begin);
+
+        Calendar l_end = Calendar.getInstance();
+        l_end.clear();
+        l_end.setTime(end);
+        List<Date> list = new ArrayList<Date>();
+        boolean ifOk = true;
+        if (day == l_begin.get(Calendar.DATE)) {
+            list.add(new Date(l_begin.getTimeInMillis()));
+        }
+        do {
+            l_begin.add(Calendar.DATE, 1);
+            if (day == l_begin.get(Calendar.DATE) && l_begin.compareTo(l_end) == -1) {
+                list.add(new Date(l_begin.getTimeInMillis()));
+            }
+            if (l_begin.compareTo(l_end) == 1) {
+                ifOk = false;
+            }
+        } while (ifOk);
+        return list;
+    }
+
+    /**
+     * 开始时间--结束时间拼凑字符串
+     * @param start
+     * @param end
+     * @return
+     */
+    public static String getStringTime(Date start, Date end) {
+        String startTime = getDateFormatToString(start, DATE_DEFAULT_FORMAT);
+        String endTime = getDateFormatToString(end, DATE_DEFAULT_FORMAT);
+        if (startTime != null && endTime != null) {
+            return startTime + "~" + endTime;
+        }
+        return "暂无~暂无";
+    }
+
+    /**
+     * @Description: yyyyMMddHHmmss字符串转化为日期
+     * @Param: [time]
+     * @return: java.util.Date
+     * @Author: cx
+     * @Date: 2018/5/17
+     */
+    public static Date getStringTimeToDate(String time, String pattern) {
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
+        Date date = null;
+        try {
+            date = simpleDateFormat.parse(time);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return date;
+    }
+
+    /**
+     * @Description: yyyyMMddHHmmss字符串转化为日期
+     * @Param: [time]
+     * @return: java.util.Date
+     * @Author: cx
+     * @Date: 2018/5/17
+     */
+    public static boolean dateEqInMinute(Date date, Date otherDate) {
+        String dateStr = getDateFormatToString(date, "yyyyMMddHHmm");
+        String otherDateStr = getDateFormatToString(otherDate, "yyyyMMddHHmm");
+        if (dateStr != null && otherDateStr != null) {
+            return dateStr.equals(otherDateStr);
+        }
+        return false;
+    }
+
+    /**
+     * 清空时分秒
+     *
+     * @param date
+     * @return
+     */
+    public static void clearHHMMSS(Date date) {
+        if (date == null) {
+            return;
+        }
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        // 将时分秒,毫秒域清零
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        date.setTime(cal.getTime().getTime());
+    }
+
+
+    /**
+     * 获取格式 年-月-日  上午/下午
+     *
+     * @param date
+     * @return
+     */
+    public static String getDateWU(Date date) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd a");
+        String format = sdf.format(new Date());
+        return format;
+    }
+
+    public static void main(String[] args) {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd a");
+        String format = sdf.format(new Date());
+        System.out.println(format);
+
+    }
+
+
+}

+ 35 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/DateUtil.java

@@ -0,0 +1,35 @@
+package com.hwrj.cloud.common.util;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * 日期工具类
+ * Created by macro on 2019/1/29.
+ */
+public class DateUtil {
+
+    /**
+     * 从Date类型的时间中提取日期部分
+     */
+    public static Date getDate(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.SECOND, 0);
+        return calendar.getTime();
+    }
+
+    /**
+     * 从Date类型的时间中提取时间部分
+     */
+    public static Date getTime(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.YEAR, 1970);
+        calendar.set(Calendar.MONTH, 0);
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        return calendar.getTime();
+    }
+}

+ 31 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/FileUtil.java

@@ -0,0 +1,31 @@
+package com.hwrj.cloud.common.util;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class FileUtil {
+    /**
+     * @Author:
+     * @Description:获取某个目录下所有直接下级文件,不包括目录下的子目录的下的文件,所以不用递归获取
+     * @Date:
+     */
+    public static List<String> getFiles(String path) {
+        List<String> files = new ArrayList<String>();
+        File file = new File(path);
+        File[] tempList = file.listFiles();
+
+        for (int i = 0; i < tempList.length; i++) {
+            if (tempList[i].isFile()) {
+                files.add(tempList[i].toString());
+                //文件名,不包含路径
+                //String fileName = tempList[i].getName();
+            }
+            if (tempList[i].isDirectory()) {
+                //这里就不递归了,
+                FileUtil.getFiles(tempList[i].getPath());
+            }
+        }
+        return files;
+    }
+}

+ 265 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/HttpUtils.java

@@ -0,0 +1,265 @@
+package com.hwrj.cloud.common.util;
+
+import javax.net.ssl.*;
+import javax.servlet.http.HttpServletRequest;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.Map;
+
+public class HttpUtils {
+    private HttpUtils() {
+    }
+
+
+    /**
+     * https 域名校验
+     */
+    private static class TrustAnyHostnameVerifier implements HostnameVerifier {
+        public boolean verify(String hostname, SSLSession session) {
+            return true;
+        }
+    }
+
+    /**
+     * https 证书管理
+     */
+    private static class TrustAnyTrustManager implements X509TrustManager {
+        public X509Certificate[] getAcceptedIssuers() {
+            return null;
+        }
+
+        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+        }
+
+        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+        }
+    }
+
+    private static final String GET = "GET";
+    private static final String POST = "POST";
+    private static String CHARSET = "UTF-8";
+
+    private static final SSLSocketFactory sslSocketFactory = initSSLSocketFactory();
+    private static final TrustAnyHostnameVerifier trustAnyHostnameVerifier = new TrustAnyHostnameVerifier();
+
+    private static SSLSocketFactory initSSLSocketFactory() {
+        try {
+            TrustManager[] tm = {new TrustAnyTrustManager()};
+            SSLContext sslContext = SSLContext.getInstance("TLS");    // ("TLS", "SunJSSE");
+            sslContext.init(null, tm, new java.security.SecureRandom());
+            return sslContext.getSocketFactory();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static void setCharSet(String charSet) {
+        if (StrKit.isBlank(charSet)) {
+            throw new IllegalArgumentException("charSet can not be blank.");
+        }
+        HttpUtils.CHARSET = charSet;
+    }
+
+    private static HttpURLConnection getHttpConnection(String url, String method, Map<String, String> headers) throws IOException, NoSuchAlgorithmException, NoSuchProviderException, KeyManagementException {
+        URL _url = new URL(url);
+        HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
+        if (conn instanceof HttpsURLConnection) {
+            ((HttpsURLConnection) conn).setSSLSocketFactory(sslSocketFactory);
+            ((HttpsURLConnection) conn).setHostnameVerifier(trustAnyHostnameVerifier);
+        }
+
+        conn.setRequestMethod(method);
+        conn.setDoOutput(true);
+        conn.setDoInput(true);
+
+        conn.setConnectTimeout(19000);
+        conn.setReadTimeout(19000);
+
+        conn.setRequestProperty("Content-Type", "application/json");
+        conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36");
+
+        if (headers != null && !headers.isEmpty()) {
+            for (Map.Entry<String, String> entry : headers.entrySet()) {
+                conn.setRequestProperty(entry.getKey(), entry.getValue());
+            }
+        }
+
+        return conn;
+    }
+
+    /**
+     * Send GET request
+     */
+    public static String get(String url, Map<String, String> queryParas, Map<String, String> headers) {
+        HttpURLConnection conn = null;
+        try {
+            conn = getHttpConnection(buildUrlWithQueryString(url, queryParas), GET, headers);
+            conn.connect();
+            return readResponseString(conn);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (conn != null) {
+                conn.disconnect();
+            }
+        }
+    }
+
+    public static String get(String url, Map<String, String> queryParas) {
+        return get(url, queryParas, null);
+    }
+
+    public static String get(String url) {
+        return get(url, null, null);
+    }
+
+    /**
+     * Send POST request
+     */
+    public static String post(String url, Map<String, String> queryParas, String data, Map<String, String> headers) {
+        HttpURLConnection conn = null;
+        try {
+            conn = getHttpConnection(buildUrlWithQueryString(url, queryParas), POST, headers);
+            conn.connect();
+
+            if (data != null) {
+                OutputStream out = conn.getOutputStream();
+                out.write(data.getBytes(CHARSET));
+                out.flush();
+                out.close();
+            }
+
+            return readResponseString(conn);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (conn != null) {
+                conn.disconnect();
+            }
+        }
+    }
+
+    public static String post(String url, Map<String, String> queryParas, String data) {
+        return post(url, queryParas, data, null);
+    }
+
+    public static String post(String url, String data, Map<String, String> headers) {
+        return post(url, null, data, headers);
+    }
+
+    public static String post(String url, String data) {
+        return post(url, null, data, null);
+    }
+
+    private static String readResponseString(HttpURLConnection conn) {
+        BufferedReader reader = null;
+        try {
+            StringBuilder ret;
+            reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), CHARSET));
+            String line = reader.readLine();
+            if (line != null) {
+                ret = new StringBuilder();
+                ret.append(line);
+            } else {
+                return "";
+            }
+
+            while ((line = reader.readLine()) != null) {
+                ret.append('\n').append(line);
+            }
+            return ret.toString();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    LogKit.error(e.getMessage(), e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Build queryString of the url
+     */
+    private static String buildUrlWithQueryString(String url, Map<String, String> queryParas) {
+        if (queryParas == null || queryParas.isEmpty()) {
+            return url;
+        }
+
+        StringBuilder sb = new StringBuilder(url);
+        boolean isFirst;
+        if (url.indexOf('?') == -1) {
+            isFirst = true;
+            sb.append('?');
+        } else {
+            isFirst = false;
+        }
+
+        for (Map.Entry<String, String> entry : queryParas.entrySet()) {
+            if (isFirst) {
+                isFirst = false;
+            } else {
+                sb.append('&');
+            }
+
+            String key = entry.getKey();
+            String value = entry.getValue();
+            if (StrKit.notBlank(value)) {
+                try {
+                    value = URLEncoder.encode(value, CHARSET);
+                } catch (UnsupportedEncodingException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            sb.append(key).append('=').append(value);
+        }
+        return sb.toString();
+    }
+
+    public static String readData(HttpServletRequest request) {
+        BufferedReader br = null;
+        try {
+            StringBuilder ret;
+            br = request.getReader();
+
+            String line = br.readLine();
+            if (line != null) {
+                ret = new StringBuilder();
+                ret.append(line);
+            } else {
+                return "";
+            }
+
+            while ((line = br.readLine()) != null) {
+                ret.append('\n').append(line);
+            }
+
+            return ret.toString();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (br != null) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    LogKit.error(e.getMessage(), e);
+                }
+            }
+        }
+    }
+
+    @Deprecated
+    public static String readIncommingRequestData(HttpServletRequest request) {
+        return readData(request);
+    }
+}

+ 51 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/InvitationCodeUtil.java

@@ -0,0 +1,51 @@
+package com.hwrj.cloud.common.util;
+
+import org.apache.catalina.User;
+
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Random;
+
+public class InvitationCodeUtil {
+
+    private static final String[] storeInvitationChars={"a","c","b","d","f","e","h","i","j","k","l","m","n","o","p"
+            ,"q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"};
+    /**
+     * @author liushuaic
+     * @date 2015/11/18 14:53
+     * @desc  生成邀请码
+     * 格式: 15(年)+01(月)+18(日)+id
+     * */
+    public static Integer generateInvitationCode(CompanyInfo companyInfo){
+        Date date= Calendar.getInstance().getTime();
+        SimpleDateFormat sdf2=new SimpleDateFormat("YYMMdd");
+        String dateStr= sdf2.format(date);
+        return Integer.valueOf(dateStr+companyInfo.getId().toString());
+    }
+    /**
+     * @author liushuaic
+     * @date 2015/11/26 18:01
+     * @desc  生成邀请码
+     * 格式: abcd12
+     * */
+    public static String generateInvitationCodeTwo(CompanyInfo user){
+        String userIdStr=user.getId().toString();
+        int forSize=5-userIdStr.length();
+        String randomStr="";
+        for(int i=0;i<forSize;i++){
+            Random random=new Random();
+            int randomIndex=random.nextInt(35);
+            randomStr=randomStr+storeInvitationChars[randomIndex];
+        }
+        return randomStr+userIdStr;
+    }
+    public static void main(String[] args) {
+        //System.out.println(storeInvitationChars.length);
+        CompanyInfo user=new CompanyInfo();
+        user.setId(23l);
+        String invitationCode=InvitationCodeUtil.generateInvitationCodeTwo(user);
+        System.out.println(invitationCode);
+    }
+}

+ 64 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/JsonUtils.java

@@ -0,0 +1,64 @@
+package com.hwrj.cloud.common.util;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.util.List;
+
+/**
+ * @author Binary Wang(https://github.com/binarywang)
+ */
+public class JsonUtils {
+
+    // 定义jackson对象
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
+    public static String toJson(Object obj) {
+
+        String o = JSONObject.toJSONString(obj);
+        return o;
+    }
+
+    /**
+     * 将对象转换成json字符串。
+     */
+    public static String objectToJson(Object data) {
+        try {
+            String string = MAPPER.writeValueAsString(data);
+            return string;
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 将json结果集转化为对象
+     */
+    public static <T> T jsonToPojo(String jsonData, Class<T> beanType) {
+        try {
+            T t = MAPPER.readValue(jsonData, beanType);
+            return t;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 将json数据转换成pojo对象list
+     */
+    public static <T> List<T> jsonToList(String jsonData, Class<T> beanType) {
+        JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
+        try {
+            List<T> list = MAPPER.readValue(jsonData, javaType);
+            return list;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+}

+ 74 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/LogKit.java

@@ -0,0 +1,74 @@
+package com.hwrj.cloud.common.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LogKit {
+    private static class Holder {
+        private static Logger log = LoggerFactory.getLogger(LogKit.class);
+    }
+
+    /**
+     * 当通过 Constants.setLogFactory(...) 或者
+     * LogManager.me().setDefaultLogFacotyr(...)
+     * 指定默认日志工厂以后,重置一下内部 Log 对象,以便使内部日志实现与系统保持一致
+     */
+    public static void synchronizeLog() {
+        Holder.log = LoggerFactory.getLogger(LogKit.class);
+    }
+
+    /**
+     * Do nothing.
+     */
+    public static void logNothing(Throwable t) {
+
+    }
+
+    public static void debug(String message) {
+        Holder.log.debug(message);
+    }
+
+    public static void debug(String message, Throwable t) {
+        Holder.log.debug(message, t);
+    }
+
+    public static void info(String message) {
+        Holder.log.info(message);
+    }
+
+    public static void info(String message, Throwable t) {
+        Holder.log.info(message, t);
+    }
+
+    public static void warn(String message) {
+        Holder.log.warn(message);
+    }
+
+    public static void warn(String message, Throwable t) {
+        Holder.log.warn(message, t);
+    }
+
+    public static void error(String message) {
+        Holder.log.error(message);
+    }
+
+    public static void error(String message, Throwable t) {
+        Holder.log.error(message, t);
+    }
+
+    public static boolean isDebugEnabled() {
+        return Holder.log.isDebugEnabled();
+    }
+
+    public static boolean isInfoEnabled() {
+        return Holder.log.isInfoEnabled();
+    }
+
+    public static boolean isWarnEnabled() {
+        return Holder.log.isWarnEnabled();
+    }
+
+    public static boolean isErrorEnabled() {
+        return Holder.log.isErrorEnabled();
+    }
+}

+ 156 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/ResultEnum.java

@@ -0,0 +1,156 @@
+package com.hwrj.cloud.common.util;
+
+
+
+
+/**
+ * 服务接口返回状态信息枚举定义
+ *
+ * @author qiubo
+ */
+public enum ResultEnum {
+
+    SUCCESS(0, "操作成功"),
+    FAILURE(1, "操作失败"),
+    FAILED(-1, "非法用户,请输入正确的accessToken"),
+    SYS_ERROR(500, "系统开小差了,请稍后再试"),
+    SYS_BREAK_ERROR(501, "系统服务中断,请稍后再试"),
+    SYS_PASSWD_ERROR(502, "旧密码验证错误,请重试"),
+    PERMISSION_DENIED(403, "没有权限"),
+    ACCOUNT_ALREADY_LOGIN(404, "该账号已经在其他设备上登录"),
+    NOT_LOGIN(401, "请先登录"),
+    RELOGIN(402, "请重新登录"),
+    LOGIN_ACCOUNT_MISS(407, "账号有错误,请检查账号信息"),
+    LOGIN_PWD_MISS(408, "密码有误,请重新输入"),
+    LOGIN_FORBIDED(406, "用户被禁用,请联系管理员"),
+    TOKEN_EXPIRED(405, "登录已过期,请重新登录"),
+    CODE_EXPIRED(409, "验证码不正确,请重新输入"),
+    FAIL_LOGIN_LOGIN_NAME(600, "用户账号或密码不正确"),
+    LOGINING_USER(601, "用户正在登陆系统,不能删除"),
+    ASSAY_APPLIED(602, "请勿重复提交检验申请"),
+    USER_IS_NOT(603, "用户已存在,请登录"),
+    WECHAT_USER_NOT_EXIST(604, "投诉用户不存在"),
+    ENCRYPTION_ERROR(605, "加密操作失败"),
+    PARAMETER_NOT_NULL(606, "参数不能为空"),
+    PARAMETER_INPUT_ERROR(620, "错误的输入参数!"),
+    FILE_NOT_FOUND(607, "文件不存在"),
+    USER_IS_HAVA(608, "用户登陆错误"),
+    WRONG_PHONE(609, "手机号相关错误"),
+    FORM_VALIDATION(610, "表单验证相关错误"),
+    CODE_ERROR(611, "验证码错误或已过期"),
+    FAILED_AUTHORIZE_LOGIN(612, "授权登录失败"),
+    LOGIN_FAILED(613, "登录失败"),
+    USER_IS_NUll(614, "用户数据不存在"),
+    USER_IS_BINDING(615, "该手机号已被使用"),
+    PAYORDER_ADD_ERROR(616, "支付订单新增失败"),
+    PAYORDER_UPDATE_ERROR(617, "支付订单更新失败"),
+    ORG_IS_NOT(618, "企业编码重复!"),
+    CODE_DEL_DUPLICATE(619, "溯源码重复废弃!"),
+    CODE_BATCH_DUPLICATE(621, "产品批次码重复!"),
+    ORDER_PAY_DUPLICATE(622, "订单已支付,请勿重复支付!"),
+    ORDER_PAY_COMPLETE(623, "订单已完成,请勿再次支付!"),
+    GOODS_BUY_AUTH(624, "该用户购买商品超出购买权限!"),
+    WX_AUTH_INFO_SUCCESS(625, "微信认证信息检测成功!"),
+    WX_AUTH_INFO_FAIL(626, "微信认证信息检测失败!"),
+    SIGNATURE_OK(718, "签名成功"),
+    SIGNATURE_ERROR(719, "签名失败"),
+    FILE_UPLOAD_ERROR(720, "文件上传失败!"),
+    
+    /** 基础管理错误信息 */
+    ORG_EXIST(800, "部门重复!"),
+    
+    /** 店铺管理错误信息 */
+    STORE_EXIST(830,"店铺已存在!"),
+    STORE_LINKPHONE_EXIST(831,"店铺联系电话已存在!"),
+    ROLE_NAME_EXIST(832,"职位重复!"),
+    ROLE_CODE_EXIST(833,"职位编码重复!"),
+    STORE_PERSON_EXIST(834,"职员联系电话已存在!"),
+    STORE_NOT_DEL(835,"职位有关联职员,需要解除以后才能进行删除"),
+    
+    WAREHOUSE_NAME_EXIST(837,"仓库名称已存在!"),
+    
+    CUSTOMER_CODE_EXIST(840,"客户编码已存在!"),
+    CUSTOMER_LINKPHONE_EXIST(841,"客户联系电话已存在!"),
+    
+    PROVIDER_CODE_EXIST(845,"供应商编码已存在!"),
+    PROVIDER_LINKPHONE_EXIST(846,"供应商联系电话已存在!"),
+    
+    GOODS_NAME_EXIST(850,"规格型号商品已存在!"),
+    GOODS_REGISTERCODE_EXIST(851,"商品登记证号已存在!"),
+    GOODS_NOT_DEL(852,"商品有交易订单,该商品不能删除"),
+    ORDER_CODE_DUPLICATE(869,"订单编号重复"),
+    
+    /** 库存管理错误信息  **/
+    INVENTORYRECORD_STOCKPILEGUID_NULL(860,"库存id不能为空"),
+    INVENTORYRECORD_GOODSGUID_NULL(861,"商品id不能为空"),
+    INVENTORYRECORD_WAREHOUSEGUID_NULL(862,"仓库id不能为空"),
+    INVENTORYRECORD_GOODSNAME_NULL(863,"商品名称不能为空"),
+    INVENTORYRECORD_INITCOUNT_NULL(864,"盘点前库存数量不能为空"),
+    INVENTORYRECORD_INVENTORYCOUNT_NULL(865,"盘存数量不能为空"),
+    INVENTORYRECORD_DIFFCOUNT_NULL(866,"盘存差额不能为空"),
+    INVENTORYRECORD_WAREHOUSENAME_NULL(867,"仓库名称不能为空"),
+    INVENTORYRECORD_REMARK_NULL(868,"备注不能为空"),
+
+
+    /** 参数设置管理模块错误信息  */
+    DICT_TYPE_FOUND(900,"字典类型已经存在"),
+    DICT_CODE_FOUND(901,"字典编码已经存在"),
+    DICT_TYPE_USED(902,"字典类型被下级数据引用,请先删除关联的下级数据"),
+    DICT_VALUE_FOUND(903,"字典值已经存在"),
+    DICT_SEQ_FOUND(904,"字典序列号已经存在"),
+    DICT_NOT_DEL(905,"基础字典类型不能删除"),
+    DICT_CODE_NOTEDIT(906,"基础字典编码不能修改"),
+    
+    SELLER_ALREADY_EXIST(720, "该档口已经存在管理员,请选择其他档口");
+
+
+    private Integer code;
+
+    private String msg;
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public void setCode(Integer code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    ResultEnum(Integer code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    /**
+     * 通过枚举code获取枚举msg
+     */
+    public static String getMsgByCode(Integer code) {
+        for (ResultEnum resultEnum : ResultEnum.values()) {
+            if (code.equals(resultEnum.getCode())) {
+                return resultEnum.getMsg();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 通过枚举code获取枚举对象
+     */
+    public static ResultEnum getResultEnumByCode(Integer code) {
+        for (ResultEnum resultEnum : ResultEnum.values()) {
+            if (code.equals(resultEnum.getCode())) {
+                return resultEnum;
+            }
+        }
+        return null;
+    }
+
+}

+ 40 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/SMSEnum.java

@@ -0,0 +1,40 @@
+package com.hwrj.cloud.common.util;
+
+/**
+ * 模板id
+ */
+public enum SMSEnum {
+
+    AUTHENTICATION("身份验证", "SMS_157230327"),
+
+    LOGIN_CONFIRMATION("登录确认", "SMS_157230326"),
+
+    ABNORMAL_LOGIN("登录异常", "SMS_157230325"),
+
+    USER_REGISTRATION("用户注册", "SMS_157230324"),
+
+    CHANGE_PASSWORD("修改密码", "SMS_157230323"),
+
+    INFORMATION_CHANGE("信息变更", "SSMS_157230322");
+    /**
+     * 名称
+     */
+    private String name;
+    /**
+     * 编码
+     */
+    private String code;
+
+    SMSEnum(String name, String code) {
+        this.name = name;
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public String getCode() {
+        return code;
+    }
+}

+ 86 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/SMSUtil.java

@@ -0,0 +1,86 @@
+package com.hwrj.cloud.common.util;
+
+
+import com.aliyuncs.CommonRequest;
+import com.aliyuncs.CommonResponse;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.profile.DefaultProfile;
+import com.hwrj.cloud.common.entity.NoteInfo;
+import com.hwrj.cloud.common.exception.GlobalException;
+
+
+/**
+ * 发送短信方法
+ *
+ * @author vic
+ */
+
+public class SMSUtil {
+
+    private String accessKeyId;
+
+    private String accessKeySecret;
+
+    private String signName;
+
+    private static final String VERSION = "2017-05-25";
+
+    private static final String DOMIAN = "dysmsapi.aliyuncs.com";
+
+    private static final String ACTION = "SendSms";
+
+    public SMSUtil(String accessKeyId, String accessKeySecret, String signName) {
+        this.accessKeyId = accessKeyId;
+        this.accessKeySecret = accessKeySecret;
+        this.signName = signName;
+    }
+
+    public NoteInfo sendNote(String phoneNumbers, String templateCode, String code) {
+        DefaultProfile profile = DefaultProfile.getProfile("default", accessKeyId, accessKeySecret);
+        IAcsClient client = new DefaultAcsClient(profile);
+        CommonRequest request = new CommonRequest();
+        request.setMethod(MethodType.POST);
+        request.setDomain(DOMIAN);
+        request.setVersion(VERSION);
+        request.setAction(ACTION);
+        request.putQueryParameter("PhoneNumbers", phoneNumbers);
+        request.putQueryParameter("TemplateCode", templateCode);
+        request.putQueryParameter("SignName", signName);
+        request.putQueryParameter("TemplateParam",
+                "{\"code\":\"" + code + "\",\"product\":\"hywa\"}");
+        NoteInfo result = null;
+
+        try {
+            CommonResponse response = client.getCommonResponse(request);
+            result = JsonUtils.jsonToPojo(response.getData(), NoteInfo.class);
+            String recode = result.getCode();
+            getNoteInfo(recode);
+            return result;
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
+
+        return result;
+
+    }
+
+    private void getNoteInfo(String recode) {
+        if ("isv.MOBILE_NUMBER_ILLEGAL".equals(recode)) {
+            throw new GlobalException(ResultEnum.FAILURE.getCode(), "非法手机号");
+        } else if ("isv.DAY_LIMIT_CONTROL".equals(recode) || "isv.BUSINESS_LIMIT_CONTROL".equals(recode)) {
+            throw new GlobalException(ResultEnum.FAILURE.getCode(), "手机号日发送数超限");
+        } else if ("isv.AMOUNT_NOT_ENOUGH".equals(recode) || "isv.OUT_OF_SERVICE".equals(recode)) {
+            throw new GlobalException(ResultEnum.FAILURE.getCode(), "服务商短信服务停止");
+        } else if ("isp.SYSTEM_ERROR".equals(recode)) {
+            throw new GlobalException(ResultEnum.FAILURE.getCode(), "短信服务错误重新发送");
+        } else if ("isv.MOBILE_NUMBER_ILLEGAL".equals(recode)) {
+            throw new GlobalException(ResultEnum.FAILURE.getCode(), "非国内手机号");
+        }
+    }
+
+}
+
+

+ 83 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/ShareCodeUtil.java

@@ -0,0 +1,83 @@
+package com.hwrj.cloud.common.util;
+
+import java.util.Random;
+
+/**
+ * 邀请码生成器,算法原理:<br/>
+ * 1) 获取id: 1127738 <br/>
+ * 2) 使用自定义进制转为:gpm6 <br/>
+ * 3) 转为字符串,并在后面加'o'字符:gpm6o <br/>
+ * 4)在后面随机产生若干个随机数字字符:gpm6o7 <br/>
+ * 转为自定义进制后就不会出现o这个字符,然后在后面加个'o',这样就能确定唯一性。最后在后面产生一些随机字符进行补全。<br/>
+ * @author jiayu.qiu
+ */
+public class ShareCodeUtil {
+
+    /** 自定义进制(0,1没有加入,容易与o,l混淆) */
+    private static final char[] r=new char[]{'q', 'w', 'e', '8', 'a', 's', '2', 'd', 'z', 'x', '9', 'c', '7', 'p', '5', 'i', 'k', '3', 'm', 'j', 'u', 'f', 'r', '4', 'v', 'y', 'l', 't', 'n', '6', 'b', 'g', 'h'};
+
+    /** (不能与自定义进制有重复) */
+    private static final char b='o';
+
+    /** 进制长度 */
+    private static final int binLen=r.length;
+
+    /** 序列最小长度 */
+    private static final int s=10;
+
+    /**
+     * 根据ID生成六位随机码
+     * @param id ID
+     * @return 随机码
+     */
+    public static String toSerialCode(long id) {
+        char[] buf=new char[32];
+        int charPos=32;
+
+        while((id / binLen) > 0) {
+            int ind=(int)(id % binLen);
+            // System.out.println(num + "-->" + ind);
+            buf[--charPos]=r[ind];
+            id /= binLen;
+        }
+        buf[--charPos]=r[(int)(id % binLen)];
+        // System.out.println(num + "-->" + num % binLen);
+        String str=new String(buf, charPos, (32 - charPos));
+        // 不够长度的自动随机补全
+        if(str.length() < s) {
+            StringBuilder sb=new StringBuilder();
+            sb.append(b);
+            Random rnd=new Random();
+            for(int i=1; i < s - str.length(); i++) {
+                sb.append(r[rnd.nextInt(binLen)]);
+            }
+            str+=sb.toString();
+        }
+        return str;
+    }
+
+    public static long codeToId(String code) {
+        char chs[]=code.toCharArray();
+        long res=0L;
+        for(int i=0; i < chs.length; i++) {
+            int ind=0;
+            for(int j=0; j < binLen; j++) {
+                if(chs[i] == r[j]) {
+                    ind=j;
+                    break;
+                }
+            }
+            if(chs[i] == b) {
+                break;
+            }
+            if(i > 0) {
+                res=res * binLen + ind;
+            } else {
+                res=ind;
+            }
+            // System.out.println(ind + "-->" + res);
+        }
+        return res;
+    }
+
+}

+ 134 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/StrKit.java

@@ -0,0 +1,134 @@
+package com.hwrj.cloud.common.util;
+
+public class StrKit {
+    /**
+     * 首字母变小写
+     */
+    public static String firstCharToLowerCase(String str) {
+        char firstChar = str.charAt(0);
+        if (firstChar >= 'A' && firstChar <= 'Z') {
+            char[] arr = str.toCharArray();
+            arr[0] += ('a' - 'A');
+            return new String(arr);
+        }
+        return str;
+    }
+
+    /**
+     * 首字母变大写
+     */
+    public static String firstCharToUpperCase(String str) {
+        char firstChar = str.charAt(0);
+        if (firstChar >= 'a' && firstChar <= 'z') {
+            char[] arr = str.toCharArray();
+            arr[0] -= ('a' - 'A');
+            return new String(arr);
+        }
+        return str;
+    }
+
+    /**
+     * 字符串为 null 或者内部字符全部为 ' ' '\t' '\n' '\r' 这四类字符时返回 true
+     */
+    public static boolean isBlank(String str) {
+        if (str == null) {
+            return true;
+        }
+        int len = str.length();
+        if (len == 0) {
+            return true;
+        }
+        for (int i = 0; i < len; i++) {
+            switch (str.charAt(i)) {
+                case ' ':
+                case '\t':
+                case '\n':
+                case '\r':
+                    // case '\b':
+                    // case '\f':
+                    break;
+                default:
+                    return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean notBlank(String str) {
+        return !isBlank(str);
+    }
+
+    public static boolean notBlank(String... strings) {
+        if (strings == null || strings.length == 0) {
+            return false;
+        }
+        for (String str : strings) {
+            if (isBlank(str)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean notNull(Object... paras) {
+        if (paras == null) {
+            return false;
+        }
+        for (Object obj : paras) {
+            if (obj == null) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static String toCamelCase(String stringWithUnderline) {
+        if (stringWithUnderline.indexOf('_') == -1) {
+            return stringWithUnderline;
+        }
+
+        stringWithUnderline = stringWithUnderline.toLowerCase();
+        char[] fromArray = stringWithUnderline.toCharArray();
+        char[] toArray = new char[fromArray.length];
+        int j = 0;
+        for (int i = 0; i < fromArray.length; i++) {
+            if (fromArray[i] == '_') {
+                // 当前字符为下划线时,将指针后移一位,将紧随下划线后面一个字符转成大写并存放
+                i++;
+                if (i < fromArray.length) {
+                    toArray[j++] = Character.toUpperCase(fromArray[i]);
+                }
+            } else {
+                toArray[j++] = fromArray[i];
+            }
+        }
+        return new String(toArray, 0, j);
+    }
+
+    public static String join(String[] stringArray) {
+        StringBuilder sb = new StringBuilder();
+        for (String s : stringArray) {
+            sb.append(s);
+        }
+        return sb.toString();
+    }
+
+    public static String join(String[] stringArray, String separator) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < stringArray.length; i++) {
+            if (i > 0) {
+                sb.append(separator);
+            }
+            sb.append(stringArray[i]);
+        }
+        return sb.toString();
+    }
+
+    public static boolean equals(String a, String b) {
+        return a == null ? b == null : a.equals(b);
+    }
+
+    public static String getRandomUUID() {
+        return java.util.UUID.randomUUID().toString().replace("-", "");
+    }
+}

+ 6 - 0
forest-common/src/main/java/com/hwrj/cloud/common/util/StringUtil.java

@@ -0,0 +1,6 @@
+package com.hwrj.cloud.common.util;
+
+import org.springframework.util.StringUtils;
+
+public class StringUtil extends StringUtils {
+}