Commit face4a4e by Future

雪花id生成调整

parent 837f1616
......@@ -12,6 +12,7 @@ import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientLoginService;
import com.wecloud.im.service.ImClientService;
import com.wecloud.im.vo.TokenVo;
import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.config.properties.JwtProperties;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
......@@ -91,7 +92,7 @@ public class ImClientLoginServiceImpl implements ImClientLoginService {
if (imClient == null) {
log.info("client不存在,先走注册流程");
imClient = new ImClient();
imClient.setId(new Snowflake(1L, 1L).nextId());
imClient.setId(SnowflakeUtil.getId());
imClient.setFkAppid(imApplication.getId());
imClient.setClientId(imTokenVerify.getClientId());
imClientService.save(imClient);
......
......@@ -33,7 +33,7 @@ public class SnowflakeUtil {
if (SNOWFLAKE == null) {
synchronized (SnowflakeUtil.class) {
if (SNOWFLAKE == null) {
SNOWFLAKE = new Snowflake(SnowflakeUtil.getWorkId(), SnowflakeUtil.getDataCenterId());
SNOWFLAKE = new Snowflake(SnowflakeUtil.getWorkId(), 1L);
}
}
}
......@@ -59,13 +59,4 @@ public class SnowflakeUtil {
}
}
private static Long getDataCenterId(){
int[] ints = StringUtils.toCodePoints(SystemUtils.getHostName());
int sums = 0;
for (int i: ints) {
sums += i;
}
return (long)(sums % 32);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment