解决开源漏洞问题。
This commit is contained in:
parent
6dd0c2939a
commit
1198ea8d02
|
|
@ -12,7 +12,7 @@ import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
||||||
import com.electromagnetic.industry.software.common.pojo.AccessSuccessInfo;
|
import com.electromagnetic.industry.software.common.pojo.AccessSuccessInfo;
|
||||||
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import com.electromagnetic.industry.software.common.util.TokenUtil;
|
import com.electromagnetic.industry.software.common.util.TokenUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.TokenMapper;
|
import com.electromagnetic.industry.software.manage.mapper.TokenMapper;
|
||||||
|
|
@ -183,7 +183,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||||
if (CollUtil.isEmpty(successInfoList)) {
|
if (CollUtil.isEmpty(successInfoList)) {
|
||||||
ElectromagneticResult res = user.getResult();
|
ElectromagneticResult res = user.getResult();
|
||||||
UserAccessLog userAccessLog = new UserAccessLog()
|
UserAccessLog userAccessLog = new UserAccessLog()
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
.setId(EleIdCreator.createSnowflakeId())
|
||||||
.setUserId(user.getUserId())
|
.setUserId(user.getUserId())
|
||||||
.setAccessStartTime(DateUtil.date(accessStartTime))
|
.setAccessStartTime(DateUtil.date(accessStartTime))
|
||||||
.setAccessEndTime(DateUtil.date(accessEndTime))
|
.setAccessEndTime(DateUtil.date(accessEndTime))
|
||||||
|
|
@ -209,7 +209,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||||
} else {
|
} else {
|
||||||
for (AccessSuccessInfo accessSuccessInfo : successInfoList) {
|
for (AccessSuccessInfo accessSuccessInfo : successInfoList) {
|
||||||
UserAccessLog userAccessLog = new UserAccessLog()
|
UserAccessLog userAccessLog = new UserAccessLog()
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
.setId(EleIdCreator.createSnowflakeId())
|
||||||
.setUserId(user.getUserId())
|
.setUserId(user.getUserId())
|
||||||
.setAccessStartTime(DateUtil.date(accessStartTime))
|
.setAccessStartTime(DateUtil.date(accessStartTime))
|
||||||
.setAccessEndTime(DateUtil.date(accessEndTime))
|
.setAccessEndTime(DateUtil.date(accessEndTime))
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -23,6 +23,6 @@ public class EdFileFavorite extends BaseModel {
|
||||||
private String fileId;
|
private String fileId;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
@ -127,7 +127,7 @@ public class EdFileInfo extends BaseModel {
|
||||||
private String templateCode;
|
private String templateCode;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
String newFileDbId = EleIdCreator.createSnowflakeId();
|
||||||
String fileTime = EleCommonUtil.getNowTimeStr();
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
||||||
this.setId(newFileDbId);
|
this.setId(newFileDbId);
|
||||||
this.setFileTime(fileTime);
|
this.setFileTime(fileTime);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -31,6 +31,6 @@ public class EdFileRelation extends BaseModel {
|
||||||
private String relationship;
|
private String relationship;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ public class EdTagLibrary extends BaseModel {
|
||||||
private Integer isPublished; // 是否已发布(0: 未发布, 1: 已发布)
|
private Integer isPublished; // 是否已发布(0: 未发布, 1: 已发布)
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setTagId(IdWorker.getSnowFlakeIdString());
|
this.setTagId(EleIdCreator.createSnowflakeId());
|
||||||
this.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); //默认未发布
|
this.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); //默认未发布
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.models;
|
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -15,6 +15,6 @@ public class FileTagRelation extends BaseModel {
|
||||||
private String tagId;
|
private String tagId;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ public class Role extends BaseModel {
|
||||||
private String roleDesc;
|
private String roleDesc;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -35,6 +35,6 @@ public class RolePermission extends BaseModel {
|
||||||
private String permissionCode;
|
private String permissionCode;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import cn.hutool.core.util.RandomUtil;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
import com.electromagnetic.industry.software.common.cons.UserConstants;
|
||||||
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.SignUtils;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -92,9 +92,9 @@ public class User extends BaseModel {
|
||||||
private String salt;
|
private String salt;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
this.setSalt(RandomUtil.randomString(16));
|
this.setSalt(RandomUtil.randomString(16));
|
||||||
this.setUserPwd(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD + this.getSalt()));
|
this.setUserPwd(EleCommonUtil.getStrMd5(UserConstants.DEFAULT_PASSWORD + this.getSalt()));
|
||||||
this.setIsPublished(UserConstants.DEFAULT_PUBLISH_STATUS);
|
this.setIsPublished(UserConstants.DEFAULT_PUBLISH_STATUS);
|
||||||
this.setIsActivated(UserConstants.DEFAULT_ACTIVE_STATUS);
|
this.setIsActivated(UserConstants.DEFAULT_ACTIVE_STATUS);
|
||||||
this.setAdminType(AdminTypeEnum.NORMAL.getValue());
|
this.setAdminType(AdminTypeEnum.NORMAL.getValue());
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
|
@ -29,6 +29,6 @@ public class UserRole extends BaseModel {
|
||||||
private String roleId;
|
private String roleId;
|
||||||
|
|
||||||
public void newInit() {
|
public void newInit() {
|
||||||
this.setId(IdWorker.getSnowFlakeIdString());
|
this.setId(EleIdCreator.createSnowflakeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import com.electromagnetic.industry.software.common.pojo.PageFile;
|
||||||
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import com.electromagnetic.industry.software.common.util.OfficeFileUtil;
|
import com.electromagnetic.industry.software.common.util.OfficeFileUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
|
|
@ -149,7 +149,7 @@ public class ChatService {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (Document document : documents) {
|
for (Document document : documents) {
|
||||||
Map<String, Object> metadata = Map.of("fileName", file.getOriginalFilename(), "fileMd5", fileMd5);
|
Map<String, Object> metadata = Map.of("fileName", file.getOriginalFilename(), "fileMd5", fileMd5);
|
||||||
newDocuments.add(new Document(IdWorker.getSnowFlakeIdString(), Objects.requireNonNull(document.getText()), metadata));
|
newDocuments.add(new Document(EleIdCreator.createSnowflakeId(), Objects.requireNonNull(document.getText()), metadata));
|
||||||
stringBuilder.append(document.getText());
|
stringBuilder.append(document.getText());
|
||||||
}
|
}
|
||||||
FileUtil.writeString(stringBuilder.toString(), elePropertyConfig.getAiFileUploadStoreDir() + File.separator + fileMd5, Charset.defaultCharset());
|
FileUtil.writeString(stringBuilder.toString(), elePropertyConfig.getAiFileUploadStoreDir() + File.separator + fileMd5, Charset.defaultCharset());
|
||||||
|
|
@ -158,7 +158,7 @@ public class ChatService {
|
||||||
vectorStore.write(newDocuments);
|
vectorStore.write(newDocuments);
|
||||||
for (Document document : newDocuments) {
|
for (Document document : newDocuments) {
|
||||||
aiFileUploadRecordMapper.insert(new AiFileUploadRecord()
|
aiFileUploadRecordMapper.insert(new AiFileUploadRecord()
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
.setId(EleIdCreator.createSnowflakeId())
|
||||||
.setVectorId(document.getId())
|
.setVectorId(document.getId())
|
||||||
.setFileSize(file.getSize())
|
.setFileSize(file.getSize())
|
||||||
.setFileMd5(fileMd5)
|
.setFileMd5(fileMd5)
|
||||||
|
|
@ -170,7 +170,7 @@ public class ChatService {
|
||||||
public Flux<String> chatStreamStr(QueryDTO queryDTO) {
|
public Flux<String> chatStreamStr(QueryDTO queryDTO) {
|
||||||
AiQuestionRecord record = new AiQuestionRecord()
|
AiQuestionRecord record = new AiQuestionRecord()
|
||||||
.setQuestion(queryDTO.getMsg())
|
.setQuestion(queryDTO.getMsg())
|
||||||
.setId(IdWorker.getSnowFlakeIdString());
|
.setId(EleIdCreator.createSnowflakeId());
|
||||||
UserLoginInfo userLoginInfo = new UserLoginInfo();
|
UserLoginInfo userLoginInfo = new UserLoginInfo();
|
||||||
userLoginInfo.setUserId(queryDTO.getUserId());
|
userLoginInfo.setUserId(queryDTO.getUserId());
|
||||||
UserThreadLocal.set(userLoginInfo);
|
UserThreadLocal.set(userLoginInfo);
|
||||||
|
|
@ -202,7 +202,7 @@ public class ChatService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flux<ChatResponse> chatStreamResponse(QueryDTO queryDTO) {
|
public Flux<ChatResponse> chatStreamResponse(QueryDTO queryDTO) {
|
||||||
AiQuestionRecord record = new AiQuestionRecord().setQuestion(queryDTO.getMsg()).setId(IdWorker.getSnowFlakeIdString());
|
AiQuestionRecord record = new AiQuestionRecord().setQuestion(queryDTO.getMsg()).setId(EleIdCreator.createSnowflakeId());
|
||||||
UserLoginInfo userLoginInfo = new UserLoginInfo();
|
UserLoginInfo userLoginInfo = new UserLoginInfo();
|
||||||
userLoginInfo.setUserId(queryDTO.getUserId());
|
userLoginInfo.setUserId(queryDTO.getUserId());
|
||||||
UserThreadLocal.set(userLoginInfo);
|
UserThreadLocal.set(userLoginInfo);
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
@Override
|
@Override
|
||||||
public ElectromagneticResult<?> createFolder(CreateFolderDTO createFolderDTO, int dataOwnCode) {
|
public ElectromagneticResult<?> createFolder(CreateFolderDTO createFolderDTO, int dataOwnCode) {
|
||||||
Assert.isTrue(EleCommonUtil.isFileNameValid(createFolderDTO.getNewFolderName()), NAME_VALID_MSG);
|
Assert.isTrue(EleCommonUtil.isFileNameValid(createFolderDTO.getNewFolderName()), NAME_VALID_MSG);
|
||||||
String folderId = IdWorker.getSnowFlakeIdString();
|
String folderId = EleIdCreator.createSnowflakeId();
|
||||||
|
|
||||||
if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
|
if (DataOwnEnum.isSysCode(dataOwnCode) || DataOwnEnum.isRepoCode(dataOwnCode)) {
|
||||||
List<String> accessibleTree = permissionService.getAccessibleTree();
|
List<String> accessibleTree = permissionService.getAccessibleTree();
|
||||||
|
|
@ -1034,7 +1034,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
.eq(EdFileInfo::getFileName, srcFileInfo.getFileName())
|
||||||
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()));
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType()));
|
||||||
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
||||||
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
String newFileDbId = EleIdCreator.createSnowflakeId();
|
||||||
String fileTime = EleCommonUtil.getNowTimeStr();
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
||||||
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
||||||
String fileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
String fileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
||||||
|
|
@ -1218,7 +1218,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType());
|
.eq(EdFileInfo::getFileType, srcFileInfo.getFileType());
|
||||||
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(queryWrapper);
|
List<EdFileInfo> sameFileInfos = this.baseMapper.selectList(queryWrapper);
|
||||||
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
Integer maxFileVersion = Collections.max(sameFileInfos, Comparator.comparing(EdFileInfo::getFileVersion)).getFileVersion();
|
||||||
String newFileDbId = IdWorker.getSnowFlakeIdString();
|
String newFileDbId = EleIdCreator.createSnowflakeId();
|
||||||
String fileTime = EleCommonUtil.getNowTimeStr();
|
String fileTime = EleCommonUtil.getNowTimeStr();
|
||||||
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
String codePathByDbPath = commonService.getCodePathByDbPath(destFolderInfo.getFilePath());
|
||||||
String fileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
String fileCode = commonService.createFileCode(codePathByDbPath, srcFileInfo.getFileType(), maxFileVersion + 1, fileTime);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import cn.hutool.core.text.StrFormatter;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.FileFormatMapper;
|
import com.electromagnetic.industry.software.manage.mapper.FileFormatMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.FileFormat;
|
import com.electromagnetic.industry.software.manage.pojo.models.FileFormat;
|
||||||
|
|
@ -39,7 +39,7 @@ public class FileFormatServiceImpl extends ServiceImpl<FileFormatMapper, FileFor
|
||||||
FileFormat fileFormat = new FileFormat();
|
FileFormat fileFormat = new FileFormat();
|
||||||
fileFormat.setSuffixName(suffixName);
|
fileFormat.setSuffixName(suffixName);
|
||||||
fileFormat.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
fileFormat.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||||
fileFormat.setId(IdWorker.getSnowFlakeIdString());
|
fileFormat.setId(EleIdCreator.createSnowflakeId());
|
||||||
fileFormat.setSuffixNo(createFileFormatNo(fileFormats.size()));
|
fileFormat.setSuffixNo(createFileFormatNo(fileFormats.size()));
|
||||||
fileFormat.setCreatedBy(UserThreadLocal.getUserId());
|
fileFormat.setCreatedBy(UserThreadLocal.getUserId());
|
||||||
this.baseMapper.insert(fileFormat);
|
this.baseMapper.insert(fileFormat);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import com.electromagnetic.industry.software.common.enums.EleDataTypeEnum;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.pojo.RespPageVO;
|
import com.electromagnetic.industry.software.common.pojo.RespPageVO;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.ImportPrjInfoMapper;
|
import com.electromagnetic.industry.software.manage.mapper.ImportPrjInfoMapper;
|
||||||
|
|
@ -91,7 +91,7 @@ public class ImportPrjServiceImpl extends ServiceImpl<ImportPrjInfoMapper, Impor
|
||||||
// 如果是目录且不是最后一个元素
|
// 如果是目录且不是最后一个元素
|
||||||
boolean isDirectory = i < pathParts.length - 1 || entry.isDirectory();
|
boolean isDirectory = i < pathParts.length - 1 || entry.isDirectory();
|
||||||
if (!pathIdMap.containsKey(currentPath)) {
|
if (!pathIdMap.containsKey(currentPath)) {
|
||||||
String newId = IdWorker.getSnowFlakeIdString();
|
String newId = EleIdCreator.createSnowflakeId();
|
||||||
pathIdMap.put(currentPath, newId);
|
pathIdMap.put(currentPath, newId);
|
||||||
String findIdPath = findIdPath(parentId, itemIdMap);
|
String findIdPath = findIdPath(parentId, itemIdMap);
|
||||||
String filePath = StrUtil.isEmpty(findIdPath) ? newId : findIdPath + ElectromagneticConstants.MYSQL_FILE_PATH_SPLIT + newId;
|
String filePath = StrUtil.isEmpty(findIdPath) ? newId : findIdPath + ElectromagneticConstants.MYSQL_FILE_PATH_SPLIT + newId;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import com.electromagnetic.industry.software.common.pojo.RespPageVO;
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.ImportTableDataMapper;
|
import com.electromagnetic.industry.software.manage.mapper.ImportTableDataMapper;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.ImportTableInfoMapper;
|
import com.electromagnetic.industry.software.manage.mapper.ImportTableInfoMapper;
|
||||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportTableData;
|
import com.electromagnetic.industry.software.manage.pojo.models.ImportTableData;
|
||||||
|
|
@ -45,7 +45,7 @@ public class ImportTableServiceImpl implements ImportTableService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String addTableInfo(String relatedId, Map<Integer, Object> tableHeader) {
|
public String addTableInfo(String relatedId, Map<Integer, Object> tableHeader) {
|
||||||
String id = IdWorker.getSnowFlakeIdString();
|
String id = EleIdCreator.createSnowflakeId();
|
||||||
ImportTableInfo importTableInfo = new ImportTableInfo()
|
ImportTableInfo importTableInfo = new ImportTableInfo()
|
||||||
.setId(id)
|
.setId(id)
|
||||||
.setTableHeader(JSONUtil.toJsonStr(tableHeader))
|
.setTableHeader(JSONUtil.toJsonStr(tableHeader))
|
||||||
|
|
@ -107,7 +107,7 @@ public class ImportTableServiceImpl implements ImportTableService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String addTableData(String tableInfoId, String tableData) {
|
public String addTableData(String tableInfoId, String tableData) {
|
||||||
String id = IdWorker.getSnowFlakeIdString();
|
String id = EleIdCreator.createSnowflakeId();
|
||||||
ImportTableData importTableData = new ImportTableData().setId(id).setTableInfoId(tableInfoId).setData(tableData);
|
ImportTableData importTableData = new ImportTableData().setId(id).setTableInfoId(tableInfoId).setData(tableData);
|
||||||
importTableDataMapper.insert(importTableData);
|
importTableDataMapper.insert(importTableData);
|
||||||
return id;
|
return id;
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
|
|
||||||
public Boolean matchPassword(User user, String password) {
|
public Boolean matchPassword(User user, String password) {
|
||||||
String salt = user.getSalt();
|
String salt = user.getSalt();
|
||||||
String encodePwd = SignUtils.MD5(password + salt);
|
String encodePwd = EleCommonUtil.getStrMd5(password + salt);
|
||||||
return user.getUserPwd().equals(encodePwd);
|
return user.getUserPwd().equals(encodePwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
singleUserResponse.setRoleList(roleList);
|
singleUserResponse.setRoleList(roleList);
|
||||||
|
|
||||||
// 检查密码是否和初始密码相同
|
// 检查密码是否和初始密码相同
|
||||||
if (user.getUserPwd().equals(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD + user.getSalt()))) {
|
if (user.getUserPwd().equals(EleCommonUtil.getStrMd5(UserConstants.DEFAULT_PASSWORD + user.getSalt()))) {
|
||||||
singleUserResponse.setIsDefaultPwd(1);
|
singleUserResponse.setIsDefaultPwd(1);
|
||||||
} else {
|
} else {
|
||||||
singleUserResponse.setIsDefaultPwd(0);
|
singleUserResponse.setIsDefaultPwd(0);
|
||||||
|
|
@ -327,7 +327,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
|
|
||||||
Assert.isTrue(!decodeNewPwd.contains(user.getUserAccount()), "密码最小长度为8,必须至少包含一个大写字母、一个小写字母、一个特殊字符、数字、不可包含账号");
|
Assert.isTrue(!decodeNewPwd.contains(user.getUserAccount()), "密码最小长度为8,必须至少包含一个大写字母、一个小写字母、一个特殊字符、数字、不可包含账号");
|
||||||
Assert.isTrue(EleCommonUtil.isPwdValid(decodeNewPwd), "密码最小长度为8,必须至少包含一个大写字母、一个小写字母、一个特殊字符、数字、不可包含账号");
|
Assert.isTrue(EleCommonUtil.isPwdValid(decodeNewPwd), "密码最小长度为8,必须至少包含一个大写字母、一个小写字母、一个特殊字符、数字、不可包含账号");
|
||||||
user.setUserPwd(SignUtils.MD5(decodeNewPwd + user.getSalt()));
|
user.setUserPwd(EleCommonUtil.getStrMd5(decodeNewPwd + user.getSalt()));
|
||||||
boolean success = this.updateById(user);
|
boolean success = this.updateById(user);
|
||||||
UserThreadLocal.setSuccessInfo("", userId, StrFormatter.format("修改了用户密码"));
|
UserThreadLocal.setSuccessInfo("", userId, StrFormatter.format("修改了用户密码"));
|
||||||
return ElectromagneticResultUtil.success(success);
|
return ElectromagneticResultUtil.success(success);
|
||||||
|
|
@ -344,7 +344,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||||
User user = this.getById(userId);
|
User user = this.getById(userId);
|
||||||
Assert.notNull(user, StrFormatter.format("用户ID {} 无效", userId));
|
Assert.notNull(user, StrFormatter.format("用户ID {} 无效", userId));
|
||||||
|
|
||||||
user.setUserPwd(SignUtils.MD5(UserConstants.DEFAULT_PASSWORD + user.getSalt()));
|
user.setUserPwd(EleCommonUtil.getStrMd5(UserConstants.DEFAULT_PASSWORD + user.getSalt()));
|
||||||
boolean success = this.updateById(user);
|
boolean success = this.updateById(user);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnu
|
||||||
import com.electromagnetic.industry.software.common.pojo.BackupFileResLog;
|
import com.electromagnetic.industry.software.common.pojo.BackupFileResLog;
|
||||||
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
|
||||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
import com.electromagnetic.industry.software.common.util.EleIdCreator;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||||
|
|
@ -109,7 +109,7 @@ public class BackupTask {
|
||||||
BackupFileResLog resLog = backupHandler.backupFiles(fileSysPath);
|
BackupFileResLog resLog = backupHandler.backupFiles(fileSysPath);
|
||||||
long endTime = System.currentTimeMillis();
|
long endTime = System.currentTimeMillis();
|
||||||
FileBackupLog backupLog = new FileBackupLog()
|
FileBackupLog backupLog = new FileBackupLog()
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
.setId(EleIdCreator.createSnowflakeId())
|
||||||
.setFileId(edFileInfo.getId())
|
.setFileId(edFileInfo.getId())
|
||||||
.setFileCode(edFileInfo.getFileCode())
|
.setFileCode(edFileInfo.getFileCode())
|
||||||
.setBackupSuccess(resLog.getBackupSuccess())
|
.setBackupSuccess(resLog.getBackupSuccess())
|
||||||
|
|
@ -154,7 +154,7 @@ public class BackupTask {
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
fileSystemService.deleteFile(file.getAbsolutePath());
|
fileSystemService.deleteFile(file.getAbsolutePath());
|
||||||
UserAccessLog userAccessLog = new UserAccessLog()
|
UserAccessLog userAccessLog = new UserAccessLog()
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
.setId(EleIdCreator.createSnowflakeId())
|
||||||
.setUserId("")
|
.setUserId("")
|
||||||
.setAccessStartTime(new Date())
|
.setAccessStartTime(new Date())
|
||||||
.setAccessEndTime(new Date())
|
.setAccessEndTime(new Date())
|
||||||
|
|
@ -212,7 +212,7 @@ public class BackupTask {
|
||||||
List<FileBackupLog> failBacks = fileBackupLogs.stream().filter(FileBackupLog::isBackupSuccess).toList();
|
List<FileBackupLog> failBacks = fileBackupLogs.stream().filter(FileBackupLog::isBackupSuccess).toList();
|
||||||
if (CollUtil.isEmpty(failBacks)) {
|
if (CollUtil.isEmpty(failBacks)) {
|
||||||
FileBackupLog backupLog = new FileBackupLog()
|
FileBackupLog backupLog = new FileBackupLog()
|
||||||
.setId(IdWorker.getSnowFlakeIdString())
|
.setId(EleIdCreator.createSnowflakeId())
|
||||||
.setFileId(Base64.encode(fileName))
|
.setFileId(Base64.encode(fileName))
|
||||||
.setFileCode(Base64.encode(fileName))
|
.setFileCode(Base64.encode(fileName))
|
||||||
.setBackupSuccess(resLog.getBackupSuccess())
|
.setBackupSuccess(resLog.getBackupSuccess())
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package com.electromagnetic.industry.software.common.util;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.util.HexUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
import cn.hutool.crypto.symmetric.AES;
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
import com.electromagnetic.industry.software.common.parse.*;
|
import com.electromagnetic.industry.software.common.parse.*;
|
||||||
|
|
@ -184,4 +186,9 @@ public final class EleCommonUtil {
|
||||||
return startValid && endValid && orderValid;
|
return startValid && endValid && orderValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getStrMd5(String str) {
|
||||||
|
byte[] md5Bytes = DigestUtil.md5(str);
|
||||||
|
return HexUtil.encodeHexStr(md5Bytes);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.electromagnetic.industry.software.common.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
|
||||||
|
public class EleIdCreator {
|
||||||
|
|
||||||
|
public static String createSnowflakeId() {
|
||||||
|
return createSnowflakeIdNum() + "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long createSnowflakeIdNum() {
|
||||||
|
return IdUtil.getSnowflake(1, 1).nextId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,152 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.common.util;
|
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
|
|
||||||
public class IdWorker {
|
|
||||||
|
|
||||||
// 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
|
|
||||||
private final static long twepoch = 1288834974657L;
|
|
||||||
// 机器标识位数
|
|
||||||
private final static long workerIdBits = 5L;
|
|
||||||
// 数据中心标识位数
|
|
||||||
private final static long datacenterIdBits = 5L;
|
|
||||||
// 机器ID最大值
|
|
||||||
private final static long maxWorkerId = -1L ^ (-1L << workerIdBits);
|
|
||||||
// 数据中心ID最大值
|
|
||||||
private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
|
|
||||||
// 毫秒内自增位
|
|
||||||
private final static long sequenceBits = 12L;
|
|
||||||
// 机器ID偏左移12位
|
|
||||||
private final static long workerIdShift = sequenceBits;
|
|
||||||
// 数据中心ID左移17位
|
|
||||||
private final static long datacenterIdShift = sequenceBits + workerIdBits;
|
|
||||||
// 时间毫秒左移22位
|
|
||||||
private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
|
|
||||||
private final static long sequenceMask = -1L ^ (-1L << sequenceBits);
|
|
||||||
private static final IdWorker idWorker = new IdWorker();
|
|
||||||
/* 上次生产id时间戳 */
|
|
||||||
private static long lastTimestamp = -1L;
|
|
||||||
private final long workerId;
|
|
||||||
// 数据标识id部分
|
|
||||||
private final long datacenterId;
|
|
||||||
// 0,并发控制
|
|
||||||
private long sequence = 0L;
|
|
||||||
|
|
||||||
public IdWorker() {
|
|
||||||
this.datacenterId = getDatacenterId(maxDatacenterId);
|
|
||||||
this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param workerId 工作机器ID
|
|
||||||
* @param datacenterId 序列号
|
|
||||||
*/
|
|
||||||
public IdWorker(long workerId, long datacenterId) {
|
|
||||||
if (workerId > maxWorkerId || workerId < 0) {
|
|
||||||
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
|
|
||||||
}
|
|
||||||
if (datacenterId > maxDatacenterId || datacenterId < 0) {
|
|
||||||
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
|
|
||||||
}
|
|
||||||
this.workerId = workerId;
|
|
||||||
this.datacenterId = datacenterId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 获取 maxWorkerId
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
|
|
||||||
StringBuffer mpid = new StringBuffer();
|
|
||||||
mpid.append(datacenterId);
|
|
||||||
String name = ManagementFactory.getRuntimeMXBean().getName();
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
/*
|
|
||||||
* GET jvmPid
|
|
||||||
*/
|
|
||||||
mpid.append(name.split("@")[0]);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* MAC + PID 的 hashcode 获取16个低位
|
|
||||||
*/
|
|
||||||
return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 数据标识id部分
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
protected static long getDatacenterId(long maxDatacenterId) {
|
|
||||||
long id = 0L;
|
|
||||||
try {
|
|
||||||
InetAddress ip = InetAddress.getLocalHost();
|
|
||||||
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
|
|
||||||
if (network == null) {
|
|
||||||
id = 1L;
|
|
||||||
} else {
|
|
||||||
byte[] mac = network.getHardwareAddress();
|
|
||||||
id = ((0x000000FF & (long) mac[mac.length - 1])
|
|
||||||
| (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
|
|
||||||
id = id % (maxDatacenterId + 1);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println(" getDatacenterId: " + e.getMessage());
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getSnowFlakeId() {
|
|
||||||
return idWorker.nextId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSnowFlakeIdString() {
|
|
||||||
return String.valueOf(getSnowFlakeId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取下一个ID
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public synchronized long nextId() {
|
|
||||||
long timestamp = timeGen();
|
|
||||||
if (timestamp < lastTimestamp) {
|
|
||||||
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastTimestamp == timestamp) {
|
|
||||||
// 当前毫秒内,则+1
|
|
||||||
sequence = (sequence + 1) & sequenceMask;
|
|
||||||
if (sequence == 0) {
|
|
||||||
// 当前毫秒内计数满了,则等待下一秒
|
|
||||||
timestamp = tilNextMillis(lastTimestamp);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sequence = 0L;
|
|
||||||
}
|
|
||||||
lastTimestamp = timestamp;
|
|
||||||
// ID偏移组合生成最终的ID,并返回ID
|
|
||||||
long nextId = ((timestamp - twepoch) << timestampLeftShift)
|
|
||||||
| (datacenterId << datacenterIdShift)
|
|
||||||
| (workerId << workerIdShift) | sequence;
|
|
||||||
|
|
||||||
return nextId;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long tilNextMillis(final long lastTimestamp) {
|
|
||||||
long timestamp = this.timeGen();
|
|
||||||
while (timestamp <= lastTimestamp) {
|
|
||||||
timestamp = this.timeGen();
|
|
||||||
}
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long timeGen() {
|
|
||||||
return System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
package com.electromagnetic.industry.software.common.util;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class SignUtils {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取MD5加密后的字符串
|
|
||||||
*
|
|
||||||
* @param str 加密前的字符串
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String MD5(String str) {
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
md.reset();
|
|
||||||
md.update(str.getBytes(StandardCharsets.UTF_8));
|
|
||||||
byte[] byteArray = md.digest();
|
|
||||||
StringBuffer md5StrBuff = new StringBuffer();
|
|
||||||
for (int i = 0; i < byteArray.length; i++) {
|
|
||||||
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) {
|
|
||||||
md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
|
|
||||||
} else {
|
|
||||||
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return md5StrBuff.toString();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue