mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 01:46:47 +08:00
提交修改生成
This commit is contained in:
@@ -8,9 +8,12 @@ import java.util.Enumeration;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.xboe.common.utils.IDGenerator;
|
||||
import com.xboe.common.utils.MD5Util;
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.module.idconfig.entity.IPMapping;
|
||||
import com.xboe.module.idconfig.service.IIPMappingService;
|
||||
|
||||
@@ -31,8 +34,15 @@ public class IdGeneratorAutoConfig {
|
||||
public void init() throws Exception{
|
||||
|
||||
String ip=getLinuxLocalIp();
|
||||
String appName=SysConstant.getConfigValue("spring.application.name");
|
||||
if(StringUtils.isBlank(appName)) {
|
||||
appName=IDGenerator.randomString(8);//随机生成8位字符串
|
||||
}
|
||||
log.info("读取的应用名称:"+appName);
|
||||
String md5=MD5Util.MD5Encode(ip+appName);
|
||||
IPMapping ipm = ipMappingService.get(md5);
|
||||
|
||||
|
||||
IPMapping ipm = ipMappingService.findByIP(ip);
|
||||
Integer workServerId=null;
|
||||
Integer dataCenterId=null;
|
||||
if(ipm!=null) {
|
||||
@@ -43,9 +53,11 @@ public class IdGeneratorAutoConfig {
|
||||
workServerId=RandomUtils.nextInt(0,31);
|
||||
dataCenterId=RandomUtils.nextInt(0,31);
|
||||
ipm=new IPMapping();
|
||||
ipm.setId(md5);
|
||||
ipm.setIp(ip);
|
||||
ipm.setDcNum(dataCenterId);
|
||||
ipm.setWorkNum(workServerId);
|
||||
ipm.setAppName(appName);
|
||||
ipMappingService.save(ipm);
|
||||
}
|
||||
IDGenerator.init(workServerId,dataCenterId);
|
||||
|
||||
@@ -15,9 +15,15 @@ import lombok.Data;
|
||||
public class IPMapping {
|
||||
|
||||
@Id
|
||||
@Column(name = "id", length = 32)
|
||||
private String id;
|
||||
|
||||
@Column(name = "ip", length = 40)
|
||||
private String ip;
|
||||
|
||||
@Column(name = "app_name", length = 50)
|
||||
private String appName;
|
||||
|
||||
@Column(name = "work_num", length = 2)
|
||||
private Integer workNum;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.List;
|
||||
import com.xboe.module.idconfig.entity.IPMapping;
|
||||
|
||||
public interface IIPMappingService {
|
||||
|
||||
IPMapping findByIP(String ip);
|
||||
|
||||
IPMapping get(String id);
|
||||
|
||||
void save(IPMapping ipm);
|
||||
|
||||
|
||||
@@ -17,10 +17,6 @@ public class IPMappingServiceImpl implements IIPMappingService{
|
||||
@Autowired
|
||||
IPMappingDao dao;
|
||||
|
||||
@Override
|
||||
public IPMapping findByIP(String ip) {
|
||||
return dao.get(ip);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -33,5 +29,10 @@ public class IPMappingServiceImpl implements IIPMappingService{
|
||||
public List<IPMapping> getAll() {
|
||||
return dao.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPMapping get(String id) {
|
||||
return dao.get(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user