feat(可回溯): 回溯视频
增加appKey生成
This commit is contained in:
+3
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.wabestway.commons.http.Paging;
|
import com.wabestway.commons.http.Paging;
|
||||||
import com.wabestway.commons.http.ResObj;
|
import com.wabestway.commons.http.ResObj;
|
||||||
import com.wabestway.recall.util.HeaderDataUtil;
|
import com.wabestway.recall.util.HeaderDataUtil;
|
||||||
|
import com.wabestway.recall.util.ShortAppKeyGenerator;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import com.wabestway.ins.utils.UUIDUtil;
|
import com.wabestway.ins.utils.UUIDUtil;
|
||||||
@@ -47,6 +48,7 @@ public class RecallApiApiServiceImpl implements RecallApiApiService {
|
|||||||
BeanUtils.copyProperties(paramReq, recallApi);
|
BeanUtils.copyProperties(paramReq, recallApi);
|
||||||
|
|
||||||
recallApi.setId(UUIDUtil.generate());//赋值id
|
recallApi.setId(UUIDUtil.generate());//赋值id
|
||||||
|
recallApi.setAppKey(ShortAppKeyGenerator.generate());
|
||||||
recallApi.setTenantId(HeaderDataUtil.getTenantId());
|
recallApi.setTenantId(HeaderDataUtil.getTenantId());
|
||||||
recallApi.setCreateBy(HeaderDataUtil.getUserId());//创建人
|
recallApi.setCreateBy(HeaderDataUtil.getUserId());//创建人
|
||||||
recallApi.setCreateTime(System.currentTimeMillis());//创建时间
|
recallApi.setCreateTime(System.currentTimeMillis());//创建时间
|
||||||
@@ -61,6 +63,7 @@ public class RecallApiApiServiceImpl implements RecallApiApiService {
|
|||||||
@Override
|
@Override
|
||||||
public ResObj updateRecallApi(RecallApiDTO paramReq) {
|
public ResObj updateRecallApi(RecallApiDTO paramReq) {
|
||||||
RecallApiEntity recallApi = new RecallApiEntity();
|
RecallApiEntity recallApi = new RecallApiEntity();
|
||||||
|
paramReq.setAppKey(null);
|
||||||
BeanUtils.copyProperties(paramReq, recallApi);
|
BeanUtils.copyProperties(paramReq, recallApi);
|
||||||
recallApi.setUpdateBy(HeaderDataUtil.getUserId());//更新人
|
recallApi.setUpdateBy(HeaderDataUtil.getUserId());//更新人
|
||||||
recallApi.setUpdateTime(System.currentTimeMillis());//更新时间
|
recallApi.setUpdateTime(System.currentTimeMillis());//更新时间
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.wabestway.recall.util;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ShortAppKeyGenerator {
|
||||||
|
private static final char[] BASE62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||||
|
|
||||||
|
public static String generate() {
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
long mostSigBits = uuid.getMostSignificantBits();
|
||||||
|
long leastSigBits = uuid.getLeastSignificantBits();
|
||||||
|
byte[] bytes = new byte[16];
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
bytes[i] = (byte) (mostSigBits >>> (8 * (7 - i)));
|
||||||
|
bytes[i + 8] = (byte) (leastSigBits >>> (8 * (7 - i)));
|
||||||
|
}
|
||||||
|
return toBase62(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String toBase62(byte[] bytes) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
long num = toLong(bytes);
|
||||||
|
while (num > 0) {
|
||||||
|
int remainder = (int) (num % 62);
|
||||||
|
sb.append(BASE62_CHARS[remainder]);
|
||||||
|
num /= 62;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long toLong(byte[] bytes) {
|
||||||
|
long result = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
result <<= 8;
|
||||||
|
result |= (bytes[i] & 0xFF);
|
||||||
|
}
|
||||||
|
for (int i = 8; i < 16; i++) {
|
||||||
|
result <<= 8;
|
||||||
|
result |= (bytes[i] & 0xFF);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user