From 0b7bcf0a7f3be4919721f9c32c2b68a529adea8c Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期四, 21 八月 2025 16:26:48 +0800
Subject: [PATCH] feat:开发

---
 FlexJobApi.Core/Utils/StringUtils/StringUtils.cs |   66 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs b/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs
index a303260..1a0cf08 100644
--- a/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs
+++ b/FlexJobApi.Core/Utils/StringUtils/StringUtils.cs
@@ -1,4 +1,5 @@
-锘縰sing Furion.FriendlyException;
+锘縰sing Furion.DataValidation;
+using Furion.FriendlyException;
 using Mapster.Utils;
 using System;
 using System.Collections.Generic;
@@ -77,5 +78,68 @@
                 return singularName + "s";
             }
         }
+
+        public static bool CheckIsIdentityNumber18(this string identity)
+        {
+            return identity.IsNotNull() && identity.TryValidate(EnumValidationTypes.ValiIdentity).IsValid && identity.Length == 18;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鎬у埆
+        /// </summary>
+        /// <param name="identity"></param>
+        /// <returns></returns>
+        public static EnumUserGender? GetGender(this string identity)
+        {
+            if (identity.CheckIsIdentityNumber18())
+            {
+                return identity[16] % 2 == 0
+                    ? EnumUserGender.Female
+                    : EnumUserGender.Male;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇鐢熸棩
+        /// </summary>
+        /// <param name="identity"></param>
+        /// <returns></returns>
+        public static DateTime? GetBirthday(this string identity)
+        {
+            if (identity.CheckIsIdentityNumber18())
+            {
+                return new DateTime(
+                    identity.Substring(6, 4).ToInt()!.Value,
+                    identity.Substring(10, 2).ToInt()!.Value,
+                    identity.Substring(12, 2).ToInt()!.Value);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇骞撮緞
+        /// </summary>
+        /// <param name="identity"></param>
+        /// <returns></returns>
+        public static int? GetAge(this string identity)
+        {
+            if (identity.CheckIsIdentityNumber18())
+            {
+                var birthday = identity.GetBirthday();
+                return birthday.GetAge();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
     }
 }

--
Gitblit v1.9.1