From 2347eeb5086479e7109bf88c37e1994921af734c Mon Sep 17 00:00:00 2001
From: wayn <1669738430@qq.com>
Date: Mon, 17 May 2021 10:46:18 +0800
Subject: [PATCH] =?UTF-8?q?refactor(=E5=95=86=E5=9F=8E):=20=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../wayn/common/core/domain/shop/Member.java | 6 ---
.../wayn/common/core/domain/vo/CommentVO.java | 2 +-
.../java/com/wayn/common/util/IdUtil.java | 47 +++++++++++--------
.../resources/mapper/shop/CommentMapper.xml | 4 +-
.../resources/mapper/shop/MemberMapper.xml | 6 +--
.../api/controller/LoginController.java | 1 -
6 files changed, 32 insertions(+), 34 deletions(-)
diff --git a/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/Member.java b/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/Member.java
index de78058..96498d5 100644
--- a/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/Member.java
+++ b/waynboot-common/src/main/java/com/wayn/common/core/domain/shop/Member.java
@@ -33,11 +33,6 @@ public class Member extends ShopBaseEntity implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
- /**
- * 用户名称
- */
- private String username;
-
/**
* 用户密码
*/
@@ -109,5 +104,4 @@ public class Member extends ShopBaseEntity implements Serializable {
*/
private Boolean delFlag;
-
}
diff --git a/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/CommentVO.java b/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/CommentVO.java
index 977c370..f048640 100644
--- a/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/CommentVO.java
+++ b/waynboot-common/src/main/java/com/wayn/common/core/domain/vo/CommentVO.java
@@ -68,6 +68,6 @@ public class CommentVO {
*/
private Integer star;
- @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+ @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private Date createTime;
}
diff --git a/waynboot-common/src/main/java/com/wayn/common/util/IdUtil.java b/waynboot-common/src/main/java/com/wayn/common/util/IdUtil.java
index 7e65b26..0be657c 100644
--- a/waynboot-common/src/main/java/com/wayn/common/util/IdUtil.java
+++ b/waynboot-common/src/main/java/com/wayn/common/util/IdUtil.java
@@ -6,19 +6,31 @@ import org.apache.commons.lang3.SystemUtils;
import java.net.Inet4Address;
import java.net.UnknownHostException;
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
+/**
+ * ID生成帮助类
+ */
public class IdUtil {
+
+ /**
+ * 生成UUID
+ *
+ * @return string
+ */
public static String getUid() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
- public static String getSnowFlakeId() {
- return null;
+ /**
+ * 生成分布式ID,依赖雪花算法
+ *
+ * @return long
+ */
+ public static long getSnowFlakeId() {
+ return new SnowFlake(SnowFlake.getDataCenterId(), SnowFlake.getMachineId()).nextId();
}
/**
@@ -51,14 +63,15 @@ public class IdUtil {
private final static long MACHINE_LEFT = SEQUENCE_BIT;
private final static long DATACENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT;
private final static long TIMESTAMP_LEFT = DATACENTER_LEFT + DATACENTER_BIT;
-
private final long datacenterId; // 数据中心
private final long machineId; // 机器标识
+
private final ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); // 线程安全的Random
- private final int clockBackOffset = 10; // 时钟回拨偏移量
+ private final int clockBackOffset = 10; // 可容忍的时钟回拨偏移量
private long sequence = 0L; // 序列号
private long lastStamp = -1L;// 上一次时间戳
+
public SnowFlake(long datacenterId, long machineId) {
if (datacenterId > MAX_DATACENTER_NUM || datacenterId < 0) {
throw new IllegalArgumentException("datacenterId can't be greater than MAX_DATACENTER_NUM or less than 0");
@@ -72,16 +85,12 @@ public class IdUtil {
public static void main(String[] args) {
SnowFlake snowFlake = new SnowFlake(getDataCenterId(), getMachineId());
- long l = snowFlake.nextId();
- System.out.println(l);
- System.out.println(Long.valueOf(l).toString().length());
- System.out.println(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
- // long start = System.currentTimeMillis();
- // for (int i = 0; i < 5000000; i++) {
- // System.out.println(snowFlake.nextId());
- // }
- //
- // System.out.println(System.currentTimeMillis() - start);
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < 5000000; i++) {
+ System.out.println(snowFlake.nextId());
+ }
+
+ System.out.println(System.currentTimeMillis() - start);
}
private static long getMachineId() {
@@ -151,9 +160,9 @@ public class IdUtil {
lastStamp = currStamp;
return (currStamp - START_STAMP) << TIMESTAMP_LEFT // 时间戳部分
- | datacenterId << DATACENTER_LEFT // 数据中心部分
- | machineId << MACHINE_LEFT // 机器标识部分
- | sequence; // 序列号部分
+ | datacenterId << DATACENTER_LEFT // 数据中心部分
+ | machineId << MACHINE_LEFT // 机器标识部分
+ | sequence; // 序列号部分
}
private long getNextMill() {
diff --git a/waynboot-common/src/main/resources/mapper/shop/CommentMapper.xml b/waynboot-common/src/main/resources/mapper/shop/CommentMapper.xml
index 0f7ed8e..4a0bd77 100644
--- a/waynboot-common/src/main/resources/mapper/shop/CommentMapper.xml
+++ b/waynboot-common/src/main/resources/mapper/shop/CommentMapper.xml
@@ -25,7 +25,7 @@
-
+
-
@@ -27,7 +26,7 @@
select id,
- username, password, gender, birthday, email, last_login_time, last_login_ip, user_level, nickname, mobile, avatar, weixin_openid, session_key, status, create_time, update_time, del_flag
+ password, gender, birthday, email, last_login_time, last_login_ip, user_level, nickname, mobile, avatar, weixin_openid, session_key, status, create_time, update_time, del_flag
from shop_member
@@ -38,9 +37,6 @@
AND id like concat('%', #{member.id}, '%')
-
- AND username like concat('%', #{member.username}, '%')
-
AND status = #{member.status}
diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java
index 10421a4..c09abb7 100644
--- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java
+++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/LoginController.java
@@ -74,7 +74,6 @@ public class LoginController {
// 删除验证码
redisCache.deleteObject(registryObj.getEmailKey());
Member member = new Member();
- member.setUsername("用户" + new Date().getTime() / 1000);
member.setNickname("昵称" + new Date().getTime() / 1000);
String avatar = "http://cdn.wayn.xin/091fffcf8e8c25ed8d2cb926be60a16a.png";
member.setAvatar(avatar);