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);