在下面模块生成基本配置策略枚举和对外接口
创建id生成策略枚举类
```package org.qiyu.live.id.generate.enums;
/**
- @Author idea
- @Date: Created in 17:55 2023/6/13
@Description
*/
public enum IdTypeEnum {USER_ID(1,"用户id生成策略");
int code;
String desc;IdTypeEnum(int code, String desc) {
this.code = code; this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
```生成对外接口方法
```package org.qiyu.live.id.generate.interfaces;
/**
- @Author idea
- @Date: Created in 19:45 2023/5/25
@Description
/
public interface IdGenerateRpc {
/*- 获取有序id
* - @param id
@return
*/
Long getSeqId(Integer id);/**
- 获取无序id
* - @param id
- @return
*/
Long getUnSeqId(Integer id);
- 获取有序id
}
### 接下来在id生成模块实现
![image.png](https://ucc.alicdn.com/pic/developer-ecology/f5tatfcr46lrm_7b0eef0e7c93486a9e77982a29fa726c.png)
###创建数据库po类(这里就是数据库id配置策略表)
```package com.laoyang.id.dao.po;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
/**
* @Author idea
* @Date: Created in 19:59 2023/5/23
* @Description
*/
@TableName("t_id_gengrate_config")
public class IdGeneratePO {
@TableId(type = IdType.AUTO)
private Integer id;
/**
* id备注描述
*/
private String remark;
/**
* 初始化值
*/
private long initNum;
/**
* 步长
*/
private int step;
/**
* 是否是有序的id
*/
private int isSeq;
/**
* 当前id所在阶段的开始值
*/
private long currentStart;
/**
* 当前id所在阶段的阈值
*/
private long nextThreshold;
/**
* 业务代码前缀
*/
private String idPrefix;
/**
* 乐观锁版本号
*/
private int version;
private Date createTime;
private Date updateTime;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public long getInitNum() {
return initNum;
}
public void setInitNum(long initNum) {
this.initNum = initNum;
}
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public long getCurrentStart() {
return currentStart;
}
public void setCurrentStart(long currentStart) {
this.currentStart = currentStart;
}
public long getNextThreshold() {
return nextThreshold;
}
public void setNextThreshold(long nextThreshold) {
this.nextThreshold = nextThreshold;
}
public String getIdPrefix() {
return idPrefix;
}
public void setIdPrefix(String idPrefix) {
this.idPrefix = idPrefix;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public int getIsSeq() {
return isSeq;
}
public void setIsSeq(int isSeq) {
this.isSeq = isSeq;
}
@Override
public String toString() {
return "IdGeneratePO{" +
"id=" + id +
", remark='" + remark + '\'' +
", initNum=" + initNum +
", step=" + step +
", isSeq=" + isSeq +
", currentStart=" + currentStart +
", nextThreshold=" + nextThreshold +
", idPrefix='" + idPrefix + '\'' +
", version=" + version +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
}
}