|
|
@@ -46,6 +46,7 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.time.Duration;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
@@ -175,7 +176,8 @@ public class SmsbDeviceServiceImpl implements ISmsbDeviceService {
|
|
|
validEntityBeforeSave(add);
|
|
|
|
|
|
// identifier
|
|
|
- String identifier = getHashString(add.getSerialNumber());
|
|
|
+ // String identifier = getHashString(add.getSerialNumber());
|
|
|
+ String identifier = encryptMac(add.getMac().toLowerCase(Locale.ROOT));
|
|
|
add.setIdentifier(identifier);
|
|
|
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
@@ -186,6 +188,42 @@ public class SmsbDeviceServiceImpl implements ISmsbDeviceService {
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ private String encryptMac(String mac) {
|
|
|
+ // Step 1: 去除冒号
|
|
|
+ String step1 = mac.replaceAll(":", "");
|
|
|
+
|
|
|
+ // Step 2: 每位转换为双位数十进制
|
|
|
+ StringBuilder step2 = new StringBuilder();
|
|
|
+ for (char c : step1.toCharArray()) {
|
|
|
+ int value = Character.digit(c, 16);
|
|
|
+ step2.append(String.format("%02d", value));
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step 3: 每两位换位
|
|
|
+ String step2Str = step2.toString();
|
|
|
+ StringBuilder step3 = new StringBuilder();
|
|
|
+ for (int i = 0; i < step2Str.length(); i += 2) {
|
|
|
+ if (i + 1 < step2Str.length()) {
|
|
|
+ step3.append(step2Str.charAt(i + 1));
|
|
|
+ step3.append(step2Str.charAt(i));
|
|
|
+ } else {
|
|
|
+ step3.append(step2Str.charAt(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Step 4: 前两位和后两位颠倒
|
|
|
+ String step3Str = step3.toString();
|
|
|
+ if (step3Str.length() < 2) {
|
|
|
+ return step3Str;
|
|
|
+ }
|
|
|
+ String firstTwo = step3Str.substring(0, 2);
|
|
|
+ String lastTwo = step3Str.substring(step3Str.length() - 2);
|
|
|
+ String middle = step3Str.length() > 4 ? step3Str.substring(2, step3Str.length() - 2) : "";
|
|
|
+
|
|
|
+ return lastTwo + middle + firstTwo;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改设备
|
|
|
*
|
|
|
@@ -196,6 +234,8 @@ public class SmsbDeviceServiceImpl implements ISmsbDeviceService {
|
|
|
@CacheEvict(cacheNames = "global:msr:device:identifier", allEntries = true)
|
|
|
public Boolean updateByBo(SmsbDeviceBo bo) {
|
|
|
SmsbDevice update = MapstructUtils.convert(bo, SmsbDevice.class);
|
|
|
+ String identifier = encryptMac(update.getMac().toLowerCase(Locale.ROOT));
|
|
|
+ update.setIdentifier(identifier);
|
|
|
// validEntityBeforeSave(update);
|
|
|
refreshCacheById();
|
|
|
return baseMapper.updateById(update) > 0;
|