Browse Source

电话号码导出

xdd 1 month ago
parent
commit
1035809fee

+ 5 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsExportTaskServiceImpl.java

@@ -22,6 +22,7 @@ import com.fs.his.vo.FsStoreOrderExcelVO;
 import com.fs.his.vo.FsStoreOrderExportVO;
 import com.fs.his.vo.FsStorePaymentExcelVO;
 import com.fs.system.service.ISysMenuService;
+import com.hc.openapi.tool.codec.Base64;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -188,7 +189,10 @@ public class FsExportTaskServiceImpl implements IFsExportTaskService
 
                 // 处理手机号
                 if (vo.getUserPhone() != null) {
-                    String decryptedPhone = PhoneUtil.decryptPhone(vo.getUserPhone());
+                    String decryptedPhone = vo.getUserPhone();
+                    if(Base64.isBase64(vo.getUserPhone())) {
+                        decryptedPhone = PhoneUtil.decryptPhoneNew(vo.getUserPhone());
+                    }
                     if (hasPhonePermission) {
                         vo.setUserPhone(decryptedPhone);
                     } else {

+ 51 - 1
fs-service/src/main/java/com/fs/his/utils/PhoneUtil.java

@@ -1,11 +1,12 @@
 package com.fs.his.utils;
 
 import com.fs.common.utils.ParseUtils;
+import lombok.extern.slf4j.Slf4j;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 import java.util.Base64;
-
+@Slf4j
 public class PhoneUtil {
 
     public static String encryptPhone(String text) {
@@ -38,6 +39,55 @@ public class PhoneUtil {
         }
         return text;
     }
+
+
+    /**
+     * 智能解密手机号 - 可处理加密、掩码和明文三种格式
+     * @param phoneText 可能是加密、掩码或明文的电话号码
+     * @return 解密后的手机号或原文
+     */
+    public static String decryptPhoneNew(String phoneText) {
+        // 参数校验
+        if (phoneText == null || phoneText.isEmpty()) {
+            return phoneText;
+        }
+
+        // 检查是否是明文电话号码格式 (纯数字)
+        if (phoneText.matches("^\\d+$")) {
+            return phoneText; // 已经是明文,直接返回
+        }
+
+        // 检查是否是掩码电话号码格式 (包含*)
+        if (phoneText.contains("*")) {
+            return phoneText; // 掩码格式,直接返回
+        }
+
+        // 尝试作为加密电话号码解密
+        try {
+
+            SecretKeySpec secretKey = new SecretKeySpec("AESAabCdeREssREA".getBytes(), "AES");
+            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+            cipher.init(Cipher.DECRYPT_MODE, secretKey);
+
+            byte[] decodedBytes = Base64.getDecoder().decode(phoneText);
+            byte[] decryptedBytes = cipher.doFinal(decodedBytes);
+            String decryptedPhone = new String(decryptedBytes);
+
+            // 验证解密结果是否为有效电话号码
+            if (decryptedPhone.matches("^\\d{5,20}$")) { // 简单验证是5-20位数字
+                return decryptedPhone;
+            } else {
+                // 解密结果不像有效电话号码
+                System.out.println("解密结果不是有效电话号码: " + decryptedPhone);
+                return phoneText;
+            }
+
+        } catch (Exception e) {
+            // 记录异常,但不影响程序流程
+            log.error("Phone decryption failed for: {}",phoneText,e);
+            return phoneText; // 解密失败返回原文
+        }
+    }
     /**
     * 解密加*
     */