refactor(商城): 代码优化

master
wayn 4 years ago
parent cbd25a774d
commit 2347eeb508

@ -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;
}

@ -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;
}

@ -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() {

@ -25,7 +25,7 @@
<result column="content" property="content"/>
<result column="admin_content" property="adminContent"/>
<result column="user_id" property="userId"/>
<result column="username" property="username"/>
<result column="nickname" property="username"/>
<result column="avatar" property="avatar"/>
<result column="has_picture" property="hasPicture"/>
<result column="pic_urls" property="picUrls"
@ -61,7 +61,7 @@
c.star,
c.create_time,
c.update_time,
m.username,
m.nickname,
m.avatar
from shop_comment c
left join shop_member m on c.user_id = m.id

@ -5,7 +5,6 @@
<!-- 通用查询映射结果 -->
<resultMap id="ShopMemberResult" type="com.wayn.common.core.domain.shop.Member">
<result column="id" property="id" />
<result column="username" property="username" />
<result column="password" property="password" />
<result column="gender" property="gender" />
<result column="birthday" property="birthday"/>
@ -27,7 +26,7 @@
<!-- 通用查询结果列 -->
<sql id="selectMemberVo">
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
</sql>
@ -38,9 +37,6 @@
<if test="member.id != null">
AND id like concat('%', #{member.id}, '%')
</if>
<if test="member.username != null and member.username != ''">
AND username like concat('%', #{member.username}, '%')
</if>
<if test="member.status != null">
AND status = #{member.status}
</if>

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

Loading…
Cancel
Save