소스 검색

Merge branch 'release/1.5.2'

tianyunperfect 5 년 전
부모
커밋
168a9b5f1a
7개의 변경된 파일161개의 추가작업 그리고 183개의 파일을 삭제
  1. 2 1
      README.md
  2. 5 2
      app/Dockerfile
  3. 0 133
      app/bin/boot.sh
  4. 1 28
      app/bin/docker-build
  5. 4 6
      common/pom.xml
  6. 96 0
      common/src/main/java/com/alvin/common/util/DateUtil.java
  7. 53 13
      common/src/main/java/com/alvin/common/util/JsonUtil.java

+ 2 - 1
README.md

@@ -10,7 +10,8 @@ springboot-web常用功能整合,包含常用功能。
 工具类
 - json工具类
 - 分布式Id生成器(雪花算法,利用hostName和Ip自动分配,系统多于32个的时候,请使用redis或者mysql来分配。)
-
+- 日期工具类
+- 爬虫工具类
 
 ## 怎么使用
 

+ 5 - 2
app/Dockerfile

@@ -1,8 +1,11 @@
-FROM hub.c.163.com/library/openjdk:8-jdk
+FROM hub.c.163.com/library/java:8-alpine
 VOLUME /tmp
 ADD target/*.jar app.jar
 
 # 抛出端口,起标记作用
 EXPOSE 8080
 
-ENTRYPOINT ["java","-jar","/app.jar"]
+#启动命令
+ENTRYPOINT exec java -jar app.jar
+# 默认参数
+#CMD [""]

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 133
app/bin/boot.sh


+ 1 - 28
app/bin/docker-build

@@ -1,28 +1 @@
-#!/bin/bash
-
-cd `dirname $0`
-cd ..
-
-# 定义应用组名
-group_name='springboot-parent'
-# 定义应用名称
-app_name='app'
-# 定义应用版本
-app_version='1.0-SNAPSHOT'
-# 定义应用环境
-profile_active='docker'
-echo '----copy jar----'
-docker stop ${app_name}
-echo '----stop container----'
-docker rm ${app_name}
-echo '----rm container----'
-docker rmi ${group_name}/${app_name}:${app_version}
-echo '----rm image----'
-# 打包编译docker镜像
-docker build -t ${group_name}/${app_name}:${app_version} .
-echo '----build image----'
-docker run -p 8080:8080 --name ${app_name} \
--e 'spring.profiles.active'=${profile_active} \
--e TZ="Asia/Shanghai" \
--d ${group_name}/${app_name}:${app_version}
-echo '----start container----'
+#!/bin/bash

cd `dirname $0`
cd ..

# 定义应用组名
group_name='springboot-parent'
# 定义应用名称
app_name='app'
# 定义应用版本
app_version='1.0-SNAPSHOT'
# 定义应用环境
profile_active='dev'
echo '----copy jar----'
docker stop ${app_name}
echo '----stop container----'
docker rm ${app_name}
echo '----rm container----'
docker rmi ${group_name}/${app_name}:${app_version}
echo '----rm image----'
# 打包编译docker镜像
docker build -t ${group_name}/${app_name}:${app_version} .
echo '----build image----'
docker run -p 8080:8080 --name ${app_name} \
-e 'spring.profiles.active'=${profile_active} \
-d ${group_name}/${app_name}:${app_version}
echo '----start container----'

+ 4 - 6
common/pom.xml

@@ -18,12 +18,6 @@
             <artifactId>lombok</artifactId>
             <version>1.18.4</version>
         </dependency>
-        <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
-        <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>fastjson</artifactId>
-            <version>1.2.56</version>
-        </dependency>
         <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
         <dependency>
             <groupId>com.google.code.gson</groupId>
@@ -54,5 +48,9 @@
             <artifactId>javax.mail</artifactId>
             <version>1.6.2</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-core</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 96 - 0
common/src/main/java/com/alvin/common/util/DateUtil.java

@@ -0,0 +1,96 @@
+package com.alvin.common.util;
+
+import org.springframework.util.Assert;
+
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
+
+/**
+ * 日期工具类
+ * 日期大小比较
+ * 日期加减
+ * 时间戳转换
+ *
+ * @author tianyunperfect
+ * @date 2020/05/28
+ */
+public class DateUtil {
+
+    /**
+     * 当前秒
+     *
+     * @return {@link Long}
+     */
+    public static Long getEpochMilli() {
+        return Instant.now().toEpochMilli();
+    }
+
+    /**
+     * 当前秒
+     *
+     * @return {@link Long}
+     */
+    public static Long getEpochSecond() {
+        return Instant.now().getEpochSecond();
+    }
+
+    /**
+     * 将Long类型的时间戳转换成String 类型的时间格式,时间格式为:yyyy-MM-dd HH:mm:ss
+     */
+    public static String convertTimeToString(Long time) {
+        Assert.notNull(time, "time is null");
+        DateTimeFormatter ftf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        return ftf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
+    }
+
+    /**
+     * 将字符串转日期成Long类型的时间戳,格式为:yyyy-MM-dd HH:mm:ss
+     */
+    public static Long convertTimeToLong(String time) {
+        Assert.notNull(time, "time is null");
+        DateTimeFormatter ftf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime parse = LocalDateTime.parse("2018-05-29 13:52:50", ftf);
+        return LocalDateTime.from(parse).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+    }
+
+    /**
+     * 取本月第一天
+     */
+    public static LocalDate firstDayOfThisMonth() {
+        LocalDate today = LocalDate.now();
+        return today.with(TemporalAdjusters.firstDayOfMonth());
+    }
+
+    /**
+     * 取本月第N天
+     */
+    public static LocalDate dayOfThisMonth(int n) {
+        LocalDate today = LocalDate.now();
+        return today.withDayOfMonth(n);
+    }
+
+    /**
+     * 取本月最后一天
+     */
+    public static LocalDate lastDayOfThisMonth() {
+        LocalDate today = LocalDate.now();
+        return today.with(TemporalAdjusters.lastDayOfMonth());
+    }
+
+    /**
+     * 取本月第一天的开始时间
+     */
+    public static LocalDateTime startOfThisMonth() {
+        return LocalDateTime.of(firstDayOfThisMonth(), LocalTime.MIN);
+    }
+
+
+    /**
+     * 取本月最后一天的结束时间
+     */
+    public static LocalDateTime endOfThisMonth() {
+        return LocalDateTime.of(lastDayOfThisMonth(), LocalTime.MAX);
+    }
+
+}

+ 53 - 13
common/src/main/java/com/alvin/common/util/JsonUtil.java

@@ -1,22 +1,27 @@
 package com.alvin.common.util;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.TypeReference;
 import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+import java.util.List;
+import java.util.Map;
 
 
 /**
  * json工具类
  * https://www.yuque.com/tianyunperfect/ygzsw4/bv1mlg
  * <p>
- * JsonUtil.toObject(str,JsonHello.class)
- * JsonUtil.toObject(str2, new TypeReference<List<MyDay>>(){})
- * JsonUtil.toObject(str2, new TypeReference<JsonHello<Hello>>(){})
+ * JsonUtil.getObject(str,JsonHello.class)
  *
  * @author tianyunperfect
  * @date 2020/05/20
  */
 public class JsonUtil {
+    private static final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();;
+
+    public JsonUtil() {
+    }
 
     /**
      * 转换为json字符串
@@ -25,7 +30,7 @@ public class JsonUtil {
      * @return {@link String}
      */
     public static String toJsonStr(Object object) {
-        return new Gson().toJson(object);
+        return gson.toJson(object);
     }
 
 
@@ -36,18 +41,53 @@ public class JsonUtil {
      * @param clazz   clazz
      * @return {@link T}
      */
-    public static <T> T toObject(String jsonStr, Class<T> clazz) {
-        return JSON.parseObject(jsonStr, clazz);
+    public static <T> T getObject(String jsonStr, Class<T> clazz) {
+        return gson.fromJson(jsonStr, clazz);
     }
 
     /**
-     * 将json字符串 转换为 泛型类、集合等
+     * 支持泛型等复杂类型
+     * new TypeToken<Result<List<Integer>>>(){}
+     * new TypeToken<List<Map<String, T>>>() {}
      *
-     * @param jsonStr        json str
-     * @param tTypeReference t型参考
+     * @param jsonString json字符串
+     * @param typeToken  令牌类型
      * @return {@link T}
      */
-    public static <T> T toObject(String jsonStr, TypeReference<T> tTypeReference) {
-        return JSON.parseObject(jsonStr, tTypeReference);
+    public static <T> T getObject(String jsonString, TypeToken typeToken) {
+
+        return gson.fromJson(jsonString, typeToken.getType());
+    }
+
+    /**
+     * 转为数组
+     * @param jsonString
+     * @param tClass
+     * @param <T>
+     * @return
+     */
+    public static <T> T[] getArray(String jsonString, Class<T> tClass) {
+        return gson.fromJson(jsonString, TypeToken.getArray(tClass).getType());
+    }
+
+    /**
+     * 转为list
+     * @param jsonString
+     * @param tClass
+     * @param <T>
+     * @return
+     */
+    public static <T> List<T> getList(String jsonString, Class<T> tClass) {
+        return gson.fromJson(jsonString, new TypeToken<List<T>>() {}.getType());
+    }
+
+    /**
+     * json字符串转成map的
+     *
+     * @param gsonString
+     * @return
+     */
+    public static <T> Map<String, T> getMap(String gsonString) {
+        return gson.fromJson(gsonString, new TypeToken<Map<String, T>>() {}.getType());
     }
 }

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.