|
|
@@ -0,0 +1,66 @@
|
|
|
+package com.etotem.cfc.service;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class NumSoulCalculator {
|
|
|
+
|
|
|
+ /** 主数(大师数),不化简 */
|
|
|
+ private static final int[] MASTER_NUMBERS = {11, 22, 33};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生命灵数:年月日所有数字相加直至个位(主数11/22/33保留)
|
|
|
+ */
|
|
|
+ public static int calcLifePath(int year, int month, int day) {
|
|
|
+ int sum = digitSum(year) + digitSum(month) + digitSum(day);
|
|
|
+ return reduceToSingleOrMaster(sum);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 天赋数:年化简、月+日合并化简,返回两个两位数
|
|
|
+ * 例: 1990-05-15 -> 年=19, 日+月=5+6=11 -> [19, 11]
|
|
|
+ */
|
|
|
+ public static int[] calcTalent(int year, int month, int day) {
|
|
|
+ int yearNum = digitSum(year);
|
|
|
+ int monthDayNum = digitSum(month) + digitSum(day);
|
|
|
+ return new int[]{yearNum, monthDayNum};
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生日数:出生日化简至个位
|
|
|
+ */
|
|
|
+ public static int calcBirthday(int day) {
|
|
|
+ return reduceToSingleOrMaster(day);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 命运数(简化版,不含姓名):出生年月日总和化简
|
|
|
+ */
|
|
|
+ public static int calcDestiny(int year, int month, int day) {
|
|
|
+ int sum = digitSum(year) + digitSum(month) + digitSum(day);
|
|
|
+ return reduceToSingleOrMaster(sum);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int digitSum(int n) {
|
|
|
+ int sum = 0;
|
|
|
+ while (n > 0) {
|
|
|
+ sum += n % 10;
|
|
|
+ n /= 10;
|
|
|
+ }
|
|
|
+ return sum;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int reduceToSingleOrMaster(int n) {
|
|
|
+ while (n >= 10 && !isMasterNumber(n)) {
|
|
|
+ n = digitSum(n);
|
|
|
+ }
|
|
|
+ return n;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean isMasterNumber(int n) {
|
|
|
+ for (int m : MASTER_NUMBERS) {
|
|
|
+ if (m == n) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|