消息id分表错误问题
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
package win.liyufan.im;
|
package win.liyufan.im;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class MessageShardingUtil {
|
public class MessageShardingUtil {
|
||||||
@@ -55,8 +56,10 @@ public class MessageShardingUtil {
|
|||||||
|
|
||||||
mid >>= (nodeIdWidth + rotateIdWidth);
|
mid >>= (nodeIdWidth + rotateIdWidth);
|
||||||
Date date = new Date(mid + T201801010000);
|
Date date = new Date(mid + T201801010000);
|
||||||
int month = date.getMonth();
|
Calendar calendar = Calendar.getInstance();
|
||||||
int year = date.getYear();
|
calendar.setTime(date);
|
||||||
|
int month = calendar.get(Calendar.MONTH);
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
year %= 3;
|
year %= 3;
|
||||||
return "t_messages_" + (year * 12 + month);
|
return "t_messages_" + (year * 12 + month);
|
||||||
}
|
}
|
||||||
@@ -68,13 +71,15 @@ public class MessageShardingUtil {
|
|||||||
|
|
||||||
mid >>= (nodeIdWidth + rotateIdWidth);
|
mid >>= (nodeIdWidth + rotateIdWidth);
|
||||||
Date date = new Date(mid + T201801010000);
|
Date date = new Date(mid + T201801010000);
|
||||||
int month = date.getMonth();
|
Calendar calendar = Calendar.getInstance();
|
||||||
int year = date.getYear();
|
calendar.setTime(date);
|
||||||
|
int month = calendar.get(Calendar.MONTH);
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
year %= 3;
|
year %= 3;
|
||||||
month = month + 1;
|
month = month - 1;
|
||||||
if (month == 12) {
|
if (month == -1) {
|
||||||
month = 0;
|
month = 11;
|
||||||
year = (year + 3 -1)%3;
|
year = (year + 3 - 1)%3;
|
||||||
}
|
}
|
||||||
return "t_messages_" + (year * 12 + month);
|
return "t_messages_" + (year * 12 + month);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user