This commit is contained in:
@@ -17,9 +17,8 @@ import org.redkale.source.*;
|
|||||||
public class LoginUserRecord extends BaseEntity {
|
public class LoginUserRecord extends BaseEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@Column(comment = "记录ID; 值=userid+'-'+UUID")
|
||||||
@Column(comment = "UUID")
|
private String seqid = ""; //记录ID; 值=userid+'-'+UUID
|
||||||
private String seqid = ""; //UUID
|
|
||||||
|
|
||||||
@Column(updatable = false, comment = "C端用户ID")
|
@Column(updatable = false, comment = "C端用户ID")
|
||||||
private long userid; //C端用户ID
|
private long userid; //C端用户ID
|
||||||
@@ -79,8 +78,9 @@ public class LoginUserRecord extends BaseEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTable(String table, Serializable userid) {
|
public String getTable(String table, Serializable primary) {
|
||||||
return getHashTable(table, (int) (((Long) userid) % 100));
|
String id = (String) primary;
|
||||||
|
return getHashTable(table, (int) (Long.parseLong(id.substring(0, id.indexOf('-'))) % 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHashTable(String table, int hash) {
|
private String getHashTable(String table, int hash) {
|
||||||
|
|||||||
@@ -17,6 +17,32 @@ import org.redkale.source.*;
|
|||||||
@DistributeTable(strategy = UserDetail.TableStrategy.class)
|
@DistributeTable(strategy = UserDetail.TableStrategy.class)
|
||||||
public class UserDetail extends BaseEntity {
|
public class UserDetail extends BaseEntity {
|
||||||
|
|
||||||
|
public static class TableStrategy implements DistributeTableStrategy<UserDetail> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTable(String table, UserDetail bean) {
|
||||||
|
return getTable(table, bean.getUserid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTable(String table, FilterNode node) {
|
||||||
|
Serializable id = node.findValue("userid");
|
||||||
|
if (id != null) return getTable(table, id);
|
||||||
|
return getHashTable(table, (Integer) node.findValue("#hash"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTable(String table, Serializable userid) {
|
||||||
|
return getHashTable(table, (int) (((Long) userid) % 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getHashTable(String table, int hash) {
|
||||||
|
int pos = table.indexOf('.');
|
||||||
|
return "platf_user." + table.substring(pos + 1) + "_" + (hash > 9 ? hash : ("0" + hash));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private long userid; //用户ID
|
private long userid; //用户ID
|
||||||
|
|
||||||
@@ -84,30 +110,4 @@ public class UserDetail extends BaseEntity {
|
|||||||
public void setCreatetime(long createtime) {
|
public void setCreatetime(long createtime) {
|
||||||
this.createtime = createtime;
|
this.createtime = createtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TableStrategy implements DistributeTableStrategy<UserDetail> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTable(String table, UserDetail bean) {
|
|
||||||
return getTable(table, bean.getUserid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTable(String table, FilterNode node) {
|
|
||||||
Serializable id = node.findValue("userid");
|
|
||||||
if (id != null) return getTable(table, id);
|
|
||||||
return getHashTable(table, (Integer) node.findValue("#hash"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTable(String table, Serializable userid) {
|
|
||||||
return getHashTable(table, (int) (((Long) userid) % 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getHashTable(String table, int hash) {
|
|
||||||
int pos = table.indexOf('.');
|
|
||||||
return "platf_user." + table.substring(pos + 1) + "_" + (hash > 9 ? hash : ("0" + hash));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user