This commit is contained in:
fengjignqi
2026-05-16 16:19:39 +08:00
commit 1b1575eb8a
1632 changed files with 242221 additions and 0 deletions

View File

@@ -0,0 +1,168 @@
package com.ckkj.water.utils.helper;
import java.util.HashMap;
import java.util.Map;
public class FiveElementsHelper {
// 五行颜色值
private static final String COLOR_METAL = "#FFAA00"; // 金
private static final String COLOR_WOOD = "#4CAE50"; // 木
private static final String COLOR_WATER = "#2196F3"; // 水
private static final String COLOR_FIRE = "#E54E4E"; // 火
private static final String COLOR_EARTH = "#B9653D"; // 土
// 天干映射表
private static final Map<String, String> celestialStems = new HashMap<>();
// 地支映射表
private static final Map<String, String> terrestrialBranches = new HashMap<>();
// 藏干映射表
private static final Map<String, String[]> hiddenStems = new HashMap<>();
// 五行颜色映射
private static final Map<String, String> elementColors = new HashMap<>();
static {
// 初始化天干五行
celestialStems.put("甲", "木");
celestialStems.put("乙", "木");
celestialStems.put("丙", "火");
celestialStems.put("丁", "火");
celestialStems.put("戊", "土");
celestialStems.put("己", "土");
celestialStems.put("庚", "金");
celestialStems.put("辛", "金");
celestialStems.put("壬", "水");
celestialStems.put("癸", "水");
// 初始化地支五行
terrestrialBranches.put("子", "水");
terrestrialBranches.put("丑", "土");
terrestrialBranches.put("寅", "木");
terrestrialBranches.put("卯", "木");
terrestrialBranches.put("辰", "土");
terrestrialBranches.put("巳", "火");
terrestrialBranches.put("午", "火");
terrestrialBranches.put("未", "土");
terrestrialBranches.put("申", "金");
terrestrialBranches.put("酉", "金");
terrestrialBranches.put("戌", "土");
terrestrialBranches.put("亥", "水");
// 初始化藏干
hiddenStems.put("子", new String[]{"癸"});
hiddenStems.put("丑", new String[]{"己", "癸", "辛"});
hiddenStems.put("寅", new String[]{"甲", "丙", "戊"});
hiddenStems.put("卯", new String[]{"乙"});
hiddenStems.put("辰", new String[]{"戊", "乙", "癸"});
hiddenStems.put("巳", new String[]{"丙", "戊", "庚"});
hiddenStems.put("午", new String[]{"丁", "己"});
hiddenStems.put("未", new String[]{"己", "丁", "乙"});
hiddenStems.put("申", new String[]{"庚", "壬", "戊"});
hiddenStems.put("酉", new String[]{"辛"});
hiddenStems.put("戌", new String[]{"戊", "辛", "丁"});
hiddenStems.put("亥", new String[]{"壬", "甲"});
// 初始化五行颜色
elementColors.put("金", COLOR_METAL);
elementColors.put("木", COLOR_WOOD);
elementColors.put("水", COLOR_WATER);
elementColors.put("火", COLOR_FIRE);
elementColors.put("土", COLOR_EARTH);
}
/**
* 获取五行属性信息
*
* @param element 天干、地支或藏干
* @return 包含五行名称和颜色值的Map,如果未找到返回null
*/
public static Map<String, String> getElementInfo(String element) {
String elementType = null;
// 1. 检查是否为天干
if (celestialStems.containsKey(element)) {
elementType = celestialStems.get(element);
}
// 2. 检查是否为地支
else if (terrestrialBranches.containsKey(element)) {
elementType = terrestrialBranches.get(element);
}
// 3. 检查是否为藏干(需要遍历所有地支的藏干)
else {
for (String[] stems : hiddenStems.values()) {
for (String stem : stems) {
if (stem.equals(element)) {
elementType = celestialStems.get(stem);
break;
}
}
if (elementType != null) break;
}
}
// 未找到匹配项
if (elementType == null) return null;
// 返回结果
Map<String, String> result = new HashMap<>();
result.put("element", elementType);
result.put("color", elementColors.get(elementType));
return result;
}
/**
* 获取所有天干
*/
public static String[] getAllCelestialStems() {
return celestialStems.keySet().toArray(new String[0]);
}
/**
* 获取所有地支
*/
public static String[] getAllTerrestrialBranches() {
return terrestrialBranches.keySet().toArray(new String[0]);
}
/**
* 获取指定地支的藏干
*
* @param branch 地支
* @return 藏干数组,如果地支不存在返回null
*/
public static String[] getHiddenStems(String branch) {
return hiddenStems.get(branch);
}
/**
* 获取天干的阴阳属性
*
* @param stem 天干
* @return "阳"或"阴",无效输入返回null
*/
public static String getYinYang(String stem) {
// 阳干:甲、丙、戊、庚、壬
// 阴干:乙、丁、己、辛、癸
if ("甲丙戊庚壬".contains(stem)) return "阳";
if ("乙丁己辛癸".contains(stem)) return "阴";
return null;
}
/**
* 获取地支的阴阳属性
*
* @param branch 地支
* @return "阳"或"阴",无效输入返回null
*/
public static String getBranchYinYang(String branch) {
// 阳支:子、寅、辰、午、申、戌
// 阴支:丑、卯、巳、未、酉、亥
if ("子寅辰午申戌".contains(branch)) return "阳";
if ("丑卯巳未酉亥".contains(branch)) return "阴";
return null;
}
}

View File

@@ -0,0 +1,31 @@
package com.ckkj.water.utils.helper;
public class ShiShen {
private String fullName; // 十神全称(如"正官")
private String shortName; // 十神简称(如"官")
private String relation; // 生克关系(如"克我")
private String yinYang; // 阴阳关系(如"阳克阴")
public ShiShen(String fullName, String shortName, String relation, String yinYang) {
this.fullName = fullName;
this.shortName = shortName;
this.relation = relation;
this.yinYang = yinYang;
}
// Getters
public String getFullName() { return fullName; }
public String getShortName() { return shortName; }
public String getRelation() { return relation; }
public String getYinYang() { return yinYang; }
@Override
public String toString() {
return "ShiShen{" +
"全称='" + fullName + '\'' +
", 简称='" + shortName + '\'' +
", 关系='" + relation + '\'' +
", 阴阳='" + yinYang + '\'' +
'}';
}
}

View File

@@ -0,0 +1,156 @@
package com.ckkj.water.utils.helper;
import java.util.HashMap;
import java.util.Map;
public class ShiShenCalculator {
// 十神全称到简称的映射表
private static final Map<String, String> SHEN_SHORT_FORM = new HashMap<>();
static {
SHEN_SHORT_FORM.put("比肩", "比");
SHEN_SHORT_FORM.put("劫财", "劫");
SHEN_SHORT_FORM.put("食神", "食");
SHEN_SHORT_FORM.put("伤官", "伤");
SHEN_SHORT_FORM.put("偏财", "才");
SHEN_SHORT_FORM.put("正财", "财");
SHEN_SHORT_FORM.put("偏印", "枭");
SHEN_SHORT_FORM.put("正印", "印");
SHEN_SHORT_FORM.put("七杀", "杀");
SHEN_SHORT_FORM.put("正官", "官");
}
/**
* 根据十神全称获取简称
*
* @param fullName 十神全称(如"比肩")
* @return 十神简称(如"比"),未找到时返回null
*/
public static String getAbbreviation(String fullName) {
return SHEN_SHORT_FORM.get(fullName);
}
// 天干阴阳属性映射
private static final Map<String, String> stemYinYang = new HashMap<>();
static {
// 阳干:甲、丙、戊、庚、壬
// 阴干:乙、丁、己、辛、癸
stemYinYang.put("甲", "阳");
stemYinYang.put("乙", "阴");
stemYinYang.put("丙", "阳");
stemYinYang.put("丁", "阴");
stemYinYang.put("戊", "阳");
stemYinYang.put("己", "阴");
stemYinYang.put("庚", "阳");
stemYinYang.put("辛", "阴");
stemYinYang.put("壬", "阳");
stemYinYang.put("癸", "阴");
}
// 十神映射表
private static final Map<String, ShiShen> SHI_SHEN_MAP = new HashMap<>();
static {
// 生克关系 + 阴阳组合 -> 十神对象
SHI_SHEN_MAP.put("同阳", new ShiShen("比肩", "比", "同我", "阳同阳"));
SHI_SHEN_MAP.put("同阴", new ShiShen("比肩", "比", "同我", "阴同阴"));
SHI_SHEN_MAP.put("同阴阳", new ShiShen("劫财", "劫", "同我", "阴阳异"));
SHI_SHEN_MAP.put("生阳阳", new ShiShen("食神", "食", "我生", "阳生阳"));
SHI_SHEN_MAP.put("生阳阴", new ShiShen("伤官", "伤", "我生", "阳生阴"));
SHI_SHEN_MAP.put("生阴阳", new ShiShen("伤官", "伤", "我生", "阴生阳"));
SHI_SHEN_MAP.put("生阴阴", new ShiShen("食神", "食", "我生", "阴生阴"));
SHI_SHEN_MAP.put("克阳阳", new ShiShen("偏财", "才", "我克", "阳克阳"));
SHI_SHEN_MAP.put("克阳阴", new ShiShen("正财", "财", "我克", "阳克阴"));
SHI_SHEN_MAP.put("克阴阳", new ShiShen("正财", "财", "我克", "阴克阳"));
SHI_SHEN_MAP.put("克阴阴", new ShiShen("偏财", "才", "我克", "阴克阴"));
SHI_SHEN_MAP.put("被生阳阳", new ShiShen("偏印", "枭", "生我", "阳生阳"));
SHI_SHEN_MAP.put("被生阳阴", new ShiShen("正印", "印", "生我", "阴生阳"));
SHI_SHEN_MAP.put("被生阴阳", new ShiShen("正印", "印", "生我", "阳生阴"));
SHI_SHEN_MAP.put("被生阴阴", new ShiShen("偏印", "枭", "生我", "阴生阴"));
SHI_SHEN_MAP.put("被克阳阳", new ShiShen("七杀", "杀", "克我", "阳克阳"));
SHI_SHEN_MAP.put("被克阳阴", new ShiShen("正官", "官", "克我", "阴克阳"));
SHI_SHEN_MAP.put("被克阴阳", new ShiShen("正官", "官", "克我", "阳克阴"));
SHI_SHEN_MAP.put("被克阴阴", new ShiShen("七杀", "杀", "克我", "阴克阴"));
}
/**
* 计算十神关系
*
* @param dayStem 日干(如"己")
* @param targetStem 目标天干(如"癸")
* @return 十神对象,如果输入无效返回null
*/
public static ShiShen calculate(String dayStem, String targetStem) {
// 验证输入
if (!isValidStem(dayStem) || !isValidStem(targetStem)) {
return null;
}
// 1. 获取五行属性
String dayElement = FiveElementsHelper.getElementInfo(dayStem).get("element");
String targetElement = FiveElementsHelper.getElementInfo(targetStem).get("element");
// 2. 获取阴阳属性
String dayYY = stemYinYang.get(dayStem);
String targetYY = stemYinYang.get(targetStem);
// 3. 确定生克关系
String relationKey = getElementRelation(dayElement, targetElement);
String yyKey = dayYY + targetYY;
// 4. 组合最终key
String finalKey = relationKey + yyKey;
// 特殊处理同五行情况
if ("同".equals(relationKey)) {
if (dayYY.equals(targetYY)) {
finalKey = "同" + dayYY; // 同阳或同阴
} else {
finalKey = "同阴阳";
}
}
return SHI_SHEN_MAP.get(finalKey);
}
/**
* 判断是否为有效天干
*/
private static boolean isValidStem(String stem) {
return stemYinYang.containsKey(stem);
}
/**
* 获取五行生克关系
*/
private static String getElementRelation(String e1, String e2) {
if (e1.equals(e2)) return "同";
// 五行生克规则
Map<String, String> sheng = new HashMap<>();
sheng.put("木", "火");
sheng.put("火", "土");
sheng.put("土", "金");
sheng.put("金", "水");
sheng.put("水", "木");
Map<String, String> ke = new HashMap<>();
ke.put("木", "土");
ke.put("土", "水");
ke.put("水", "火");
ke.put("火", "金");
ke.put("金", "木");
if (sheng.get(e1).equals(e2)) return "生";
if (ke.get(e1).equals(e2)) return "克";
if (sheng.get(e2).equals(e1)) return "被生";
if (ke.get(e2).equals(e1)) return "被克";
return null; // 理论上不会发生
}
}