Просмотр исходного кода

fix:“修复管理id不唯一的情况"

soobin 11 месяцев назад
Родитель
Сommit
ea183f7fa3

+ 3 - 0
src/main/java/com/szwl/controller/IndexController.java

@@ -357,6 +357,9 @@ public class IndexController {
         equipmentApply.setManagerId(managerId);
         equipmentApply.setGtClientId(gtClientId);
         Long adminId = AdminUtils.decrypt(false, managerId);
+        if (adminId == null) {
+            return "找不到商家";
+        }
 
         TAdmin admin = adminService.getById(adminId);
         if (admin == null) {

+ 14 - 9
src/main/java/com/szwl/model/utils/AdminUtils.java

@@ -20,11 +20,11 @@ public final class AdminUtils {
     /**
      * 将id转成加密样式
      */
-    public static String encrypt(boolean isPrefix , Long id) {
+    public static String encrypt(boolean isPrefix, Long id) {
         id = id * base2 + base1;
-        if(isPrefix){
+        if (isPrefix) {
             return prefix + id.toString();
-        }else{
+        } else {
             return id.toString();
         }
 
@@ -34,16 +34,21 @@ public final class AdminUtils {
     /**
      * 解密id
      */
-    public static Long decrypt(boolean isPrefix , String uid) {
+    public static Long decrypt(boolean isPrefix, String uid) {
         try {
-            if(isPrefix){
+            if (isPrefix) {
                 uid = uid.substring(1, uid.length());
             }
 
             Long id = Long.valueOf(uid);
             id = id - base1;
-            id = id / base2;
-            return id;
+            long l = id % base2;
+            if (l == 0) {
+                id = id / base2;
+                return id;
+            } else {
+                return null;
+            }
         } catch (Exception e) {
             return null;
         }
@@ -51,7 +56,7 @@ public final class AdminUtils {
 
 
     public static void main(String[] args) {
-        System.out.println(encrypt(false, 3L));
-        System.out.println(decrypt(false, "2478"));
+        System.out.println(encrypt(false, 2958L));
+        System.out.println(decrypt(false, "40918"));
     }
 }