/**
* 八字数据库
* 提供天干地支、五行、十神等基础数据和查询功能
*/
class BaziDatabase {
constructor() {
this.heavenlyStems = this.initializeHeavenlyStems();
this.earthlyBranches = this.initializeEarthlyBranches();
this.fiveElements = this.initializeFiveElements();
this.tenGods = this.initializeTenGods();
this.nayin = this.initializeNayin();
this.spirits = this.initializeSpirits();
this.patterns = this.initializePatterns();
}
/**
* 初始化天干数据
*/
initializeHeavenlyStems() {
return {
'甲': {
index: 0,
element: '木',
polarity: '阳',
season: '春',
direction: '东',
color: '青',
nature: '生发',
personality: ['仁慈', '正直', '进取', '创新'],
body_parts: ['头', '胆', '毛发'],
animals: ['虎', '龙'],
plants: ['松', '柏', '梧桐'],
meanings: ['首领', '栋梁', '大树', '森林']
},
'乙': {
index: 1,
element: '木',
polarity: '阴',
season: '春',
direction: '东',
color: '绿',
nature: '柔顺',
personality: ['温和', '灵活', '适应', '细腻'],
body_parts: ['肝', '颈', '手足'],
animals: ['兔', '蛇'],
plants: ['花草', '藤蔓', '竹子'],
meanings: ['花草', '藤蔓', '柔木', '绿叶']
},
'丙': {
index: 2,
element: '火',
polarity: '阳',
season: '夏',
direction: '南',
color: '红',
nature: '炎热',
personality: ['热情', '积极', '光明', '外向'],
body_parts: ['心', '眼', '血液'],
animals: ['马', '猴'],
plants: ['向日葵', '红花'],
meanings: ['太阳', '火焰', '光明', '热情']
},
'丁': {
index: 3,
element: '火',
polarity: '阴',
season: '夏',
direction: '南',
color: '紫',
nature: '温暖',
personality: ['文雅', '细致', '内敛', '智慧'],
body_parts: ['心', '舌', '血管'],
animals: ['鸡', '羊'],
plants: ['灯芯草', '蜡烛'],
meanings: ['灯火', '星光', '文明', '智慧']
},
'戊': {
index: 4,
element: '土',
polarity: '阳',
season: '长夏',
direction: '中',
color: '黄',
nature: '厚重',
personality: ['稳重', '诚实', '包容', '务实'],
body_parts: ['脾', '胃', '肌肉'],
animals: ['牛', '狗'],
plants: ['大树', '高山'],
meanings: ['高山', '城墙', '大地', '堤坝']
},
'己': {
index: 5,
element: '土',
polarity: '阴',
season: '长夏',
direction: '中',
color: '黄',
nature: '滋养',
personality: ['温和', '细心', '保守', '踏实'],
body_parts: ['脾', '腹', '皮肤'],
animals: ['牛', '羊'],
plants: ['田园', '农作物'],
meanings: ['田园', '平原', '沃土', '农田']
},
'庚': {
index: 6,
element: '金',
polarity: '阳',
season: '秋',
direction: '西',
color: '白',
nature: '刚硬',
personality: ['果断', '刚毅', '正义', '锐利'],
body_parts: ['肺', '骨', '大肠'],
animals: ['虎', '猴'],
plants: ['金属', '矿物'],
meanings: ['刀剑', '金属', '矿石', '兵器']
},
'辛': {
index: 7,
element: '金',
polarity: '阴',
season: '秋',
direction: '西',
color: '白',
nature: '精致',
personality: ['精细', '敏感', '美丽', '高雅'],
body_parts: ['肺', '皮毛', '牙齿'],
animals: ['鸡', '兔'],
plants: ['珠宝', '首饰'],
meanings: ['珠宝', '首饰', '精金', '美玉']
},
'壬': {
index: 8,
element: '水',
polarity: '阳',
season: '冬',
direction: '北',
color: '黑',
nature: '流动',
personality: ['智慧', '灵活', '包容', '深沉'],
body_parts: ['肾', '膀胱', '血液'],
animals: ['鼠', '猪'],
plants: ['江河', '大海'],
meanings: ['江河', '大海', '雨露', '洪水']
},
'癸': {
index: 9,
element: '水',
polarity: '阴',
season: '冬',
direction: '北',
color: '黑',
nature: '滋润',
personality: ['温柔', '细腻', '内向', '神秘'],
body_parts: ['肾', '足', '生殖'],
animals: ['鱼', '龟'],
plants: ['露水', '泉水'],
meanings: ['雨露', '泉水', '小溪', '甘露']
}
};
}
/**
* 初始化地支数据
*/
initializeEarthlyBranches() {
return {
'子': {
index: 0,
element: '水',
polarity: '阳',
season: '冬',
month: 11,
time: '23-1时',
direction: '北',
animal: '鼠',
hidden_stems: ['癸'],
personality: ['机智', '灵活', '适应性强'],
body_parts: ['耳', '膀胱', '生殖系统'],
meanings: ['种子', '开始', '潜藏', '智慧']
},
'丑': {
index: 1,
element: '土',
polarity: '阴',
season: '冬',
month: 12,
time: '1-3时',
direction: '东北',
animal: '牛',
hidden_stems: ['己', '癸', '辛'],
personality: ['勤劳', '踏实', '保守'],
body_parts: ['脾', '胃', '腹部'],
meanings: ['田园', '勤劳', '积累', '基础']
},
'寅': {
index: 2,
element: '木',
polarity: '阳',
season: '春',
month: 1,
time: '3-5时',
direction: '东北',
animal: '虎',
hidden_stems: ['甲', '丙', '戊'],
personality: ['勇敢', '冲动', '领导力'],
body_parts: ['胆', '手', '毛发'],
meanings: ['森林', '权威', '勇猛', '生机']
},
'卯': {
index: 3,
element: '木',
polarity: '阴',
season: '春',
month: 2,
time: '5-7时',
direction: '东',
animal: '兔',
hidden_stems: ['乙'],
personality: ['温和', '敏感', '艺术性'],
body_parts: ['肝', '手指', '神经'],
meanings: ['花草', '温和', '美丽', '春意']
},
'辰': {
index: 4,
element: '土',
polarity: '阳',
season: '春',
month: 3,
time: '7-9时',
direction: '东南',
animal: '龙',
hidden_stems: ['戊', '乙', '癸'],
personality: ['变化', '神秘', '权威'],
body_parts: ['脾', '胃', '皮肤'],
meanings: ['水库', '变化', '神龙', '权威']
},
'巳': {
index: 5,
element: '火',
polarity: '阴',
season: '夏',
month: 4,
time: '9-11时',
direction: '东南',
animal: '蛇',
hidden_stems: ['丙', '戊', '庚'],
personality: ['智慧', '神秘', '直觉'],
body_parts: ['心', '眼', '血管'],
meanings: ['文明', '智慧', '变化', '神秘']
},
'午': {
index: 6,
element: '火',
polarity: '阳',
season: '夏',
month: 5,
time: '11-13时',
direction: '南',
animal: '马',
hidden_stems: ['丁', '己'],
personality: ['热情', '积极', '外向'],
body_parts: ['心', '舌', '血液'],
meanings: ['太阳', '光明', '热情', '奔放']
},
'未': {
index: 7,
element: '土',
polarity: '阴',
season: '夏',
month: 6,
time: '13-15时',
direction: '西南',
animal: '羊',
hidden_stems: ['己', '丁', '乙'],
personality: ['温和', '艺术', '感性'],
body_parts: ['脾', '胃', '口'],
meanings: ['花园', '艺术', '美丽', '温和']
},
'申': {
index: 8,
element: '金',
polarity: '阳',
season: '秋',
month: 7,
time: '15-17时',
direction: '西南',
animal: '猴',
hidden_stems: ['庚', '壬', '戊'],
personality: ['机智', '活跃', '变化'],
body_parts: ['肺', '大肠', '骨骼'],
meanings: ['金属', '变化', '机智', '传达']
},
'酉': {
index: 9,
element: '金',
polarity: '阴',
season: '秋',
month: 8,
time: '17-19时',
direction: '西',
animal: '鸡',
hidden_stems: ['辛'],
personality: ['精细', '完美', '挑剔'],
body_parts: ['肺', '皮肤', '毛发'],
meanings: ['珠宝', '精致', '美丽', '完美']
},
'戌': {
index: 10,
element: '土',
polarity: '阳',
season: '秋',
month: 9,
time: '19-21时',
direction: '西北',
animal: '狗',
hidden_stems: ['戊', '辛', '丁'],
personality: ['忠诚', '正义', '保护'],
body_parts: ['脾', '胃', '腿'],
meanings: ['山岗', '忠诚', '守护', '正义']
},
'亥': {
index: 11,
element: '水',
polarity: '阴',
season: '冬',
month: 10,
time: '21-23时',
direction: '西北',
animal: '猪',
hidden_stems: ['壬', '甲'],
personality: ['诚实', '善良', '包容'],
body_parts: ['肾', '头', '血液'],
meanings: ['江河', '包容', '善良', '结束']
}
};
}
/**
* 初始化五行数据
*/
initializeFiveElements() {
return {
'木': {
nature: '生发',
season: '春',
direction: '东',
color: ['青', '绿'],
emotion: '怒',
organ: '肝',
sense: '目',
taste: '酸',
generates: '火',
destroys: '土',
generated_by: '水',
destroyed_by: '金',
personality: ['仁慈', '正直', '进取', '创新'],
career: ['教育', '文化', '林业', '纺织'],
body_parts: ['肝', '胆', '眼', '筋', '指甲']
},
'火': {
nature: '炎上',
season: '夏',
direction: '南',
color: ['红', '紫'],
emotion: '喜',
organ: '心',
sense: '舌',
taste: '苦',
generates: '土',
destroys: '金',
generated_by: '木',
destroyed_by: '水',
personality: ['热情', '积极', '光明', '礼貌'],
career: ['能源', '电子', '娱乐', '餐饮'],
body_parts: ['心', '小肠', '舌', '血管', '面部']
},
'土': {
nature: '稼穑',
season: '长夏',
direction: '中',
color: ['黄', '棕'],
emotion: '思',
organ: '脾',
sense: '口',
taste: '甘',
generates: '金',
destroys: '水',
generated_by: '火',
destroyed_by: '木',
personality: ['诚信', '稳重', '包容', '务实'],
career: ['农业', '房地产', '建筑', '陶瓷'],
body_parts: ['脾', '胃', '口', '肌肉', '皮肤']
},
'金': {
nature: '从革',
season: '秋',
direction: '西',
color: ['白', '金'],
emotion: '悲',
organ: '肺',
sense: '鼻',
taste: '辛',
generates: '水',
destroys: '木',
generated_by: '土',
destroyed_by: '火',
personality: ['义气', '果断', '刚毅', '正直'],
career: ['金融', '机械', '军警', '珠宝'],
body_parts: ['肺', '大肠', '鼻', '皮毛', '骨骼']
},
'水': {
nature: '润下',
season: '冬',
direction: '北',
color: ['黑', '蓝'],
emotion: '恐',
organ: '肾',
sense: '耳',
taste: '咸',
generates: '木',
destroys: '火',
generated_by: '金',
destroyed_by: '土',
personality: ['智慧', '灵活', '包容', '深沉'],
career: ['水利', '运输', '贸易', '信息'],
body_parts: ['肾', '膀胱', '耳', '骨髓', '生殖']
}
};
}
/**
* 初始化十神数据
*/
initializeTenGods() {
return {
'比肩': {
relationship: '同性同类',
nature: '自我',
positive: ['独立', '自主', '坚持', '自信'],
negative: ['固执', '自私', '孤立', '争斗'],
represents: ['兄弟姐妹', '朋友', '同事', '竞争对手'],
career: ['合伙', '团队', '竞争', '独立'],
wealth: ['平分', '共享', '竞争', '劫财'],
relationship: ['同性朋友', '兄弟姐妹', '合作伙伴']
},
'劫财': {
relationship: '异性同类',
nature: '争夺',
positive: ['果断', '行动', '勇敢', '直接'],
negative: ['冲动', '争夺', '破财', '冲突'],
represents: ['异性兄弟', '竞争者', '劫夺者'],
career: ['竞争', '冒险', '投机', '变动'],
wealth: ['破财', '投机', '风险', '变动'],
relationship: ['异性朋友', '竞争对手', '合作冲突']
},
'食神': {
relationship: '同性所生',
nature: '表达',
positive: ['才华', '表达', '享受', '乐观'],
negative: ['放纵', '懒散', '挥霍', '不实'],
represents: ['才华', '子女', '学生', '作品'],
career: ['艺术', '娱乐', '教育', '服务'],
wealth: ['稳定', '享受', '消费', '投资'],
relationship: ['子女', '学生', '晚辈', '作品']
},
'伤官': {
relationship: '异性所生',
nature: '反叛',
positive: ['创新', '才华', '变革', '敏锐'],
negative: ['反叛', '伤害', '不稳', '冲动'],
represents: ['才华', '创新', '反叛', '变化'],
career: ['创新', '艺术', '技术', '变革'],
wealth: ['变动', '投机', '创新', '风险'],
relationship: ['异性子女', '创新伙伴', '反叛者']
},
'偏财': {
relationship: '同性所克',
nature: '机遇',
positive: ['机遇', '灵活', '外财', '人缘'],
negative: ['不稳', '投机', '花心', '浮躁'],
represents: ['外财', '机遇', '异性', '投资'],
career: ['投资', '贸易', '服务', '机遇'],
wealth: ['外财', '投资', '机遇', '变动'],
relationship: ['异性', '情人', '投资伙伴']
},
'正财': {
relationship: '异性所克',
nature: '稳定',
positive: ['稳定', '务实', '节俭', '责任'],
negative: ['保守', '小气', '固执', '压力'],
represents: ['正财', '妻子', '稳定', '责任'],
career: ['稳定', '管理', '财务', '实业'],
wealth: ['正财', '稳定', '积累', '节俭'],
relationship: ['配偶', '稳定关系', '责任伙伴']
},
'七杀': {
relationship: '同性所克',
nature: '压力',
positive: ['权威', '果断', '勇敢', '突破'],
negative: ['压力', '冲动', '暴躁', '危险'],
represents: ['权威', '压力', '挑战', '敌人'],
career: ['权威', '军警', '竞争', '挑战'],
wealth: ['压力', '风险', '突破', '变动'],
relationship: ['权威人士', '压力来源', '挑战者']
},
'正官': {
relationship: '异性所克',
nature: '责任',
positive: ['责任', '正义', '稳重', '名誉'],
negative: ['压抑', '保守', '束缚', '压力'],
represents: ['官职', '责任', '名誉', '约束'],
career: ['公职', '管理', '法律', '教育'],
wealth: ['稳定', '正当', '名誉', '责任'],
relationship: ['上司', '长辈', '权威', '丈夫']
},
'偏印': {
relationship: '同性所生',
nature: '偏门',
positive: ['直觉', '创新', '独特', '深度'],
negative: ['偏执', '孤僻', '不实', '变化'],
represents: ['偏门', '直觉', '宗教', '玄学'],
career: ['研究', '宗教', '艺术', '玄学'],
wealth: ['偏门', '不稳', '直觉', '变化'],
relationship: ['继母', '偏门师长', '宗教人士']
},
'正印': {
relationship: '异性所生',
nature: '保护',
positive: ['智慧', '学习', '保护', '慈爱'],
negative: ['依赖', '保守', '懒惰', '固执'],
represents: ['母亲', '老师', '保护', '学习'],
career: ['教育', '文化', '学术', '服务'],
wealth: ['稳定', '保守', '依赖', '传统'],
relationship: ['母亲', '老师', '保护者', '长辈']
}
};
}
/**
* 初始化纳音数据
*/
initializeNayin() {
return {
'甲子': '海中金', '乙丑': '海中金',
'丙寅': '炉中火', '丁卯': '炉中火',
'戊辰': '大林木', '己巳': '大林木',
'庚午': '路旁土', '辛未': '路旁土',
'壬申': '剑锋金', '癸酉': '剑锋金',
'甲戌': '山头火', '乙亥': '山头火',
'丙子': '涧下水', '丁丑': '涧下水',
'戊寅': '城头土', '己卯': '城头土',
'庚辰': '白蜡金', '辛巳': '白蜡金',
'壬午': '杨柳木', '癸未': '杨柳木',
'甲申': '泉中水', '乙酉': '泉中水',
'丙戌': '屋上土', '丁亥': '屋上土',
'戊子': '霹雳火', '己丑': '霹雳火',
'庚寅': '松柏木', '辛卯': '松柏木',
'壬辰': '长流水', '癸巳': '长流水',
'甲午': '砂中金', '乙未': '砂中金',
'丙申': '山下火', '丁酉': '山下火',
'戊戌': '平地木', '己亥': '平地木',
'庚子': '壁上土', '辛丑': '壁上土',
'壬寅': '金箔金', '癸卯': '金箔金',
'甲辰': '覆灯火', '乙巳': '覆灯火',
'丙午': '天河水', '丁未': '天河水',
'戊申': '大驿土', '己酉': '大驿土',
'庚戌': '钗钏金', '辛亥': '钗钏金',
'壬子': '桑柘木', '癸丑': '桑柘木',
'甲寅': '大溪水', '乙卯': '大溪水',
'丙辰': '沙中土', '丁巳': '沙中土',
'戊午': '天上火', '己未': '天上火',
'庚申': '石榴木', '辛酉': '石榴木',
'壬戌': '大海水', '癸亥': '大海水'
};
}
/**
* 初始化神煞数据
*/
initializeSpirits() {
return {
'天乙贵人': {
nature: '吉',
meaning: '贵人相助,逢凶化吉',
effects: ['贵人运', '化解灾难', '提升地位'],
查法: '甲戊见牛羊,乙己鼠猴乡,丙丁猪鸡位,壬癸兔蛇藏,庚辛逢虎马,此是贵人方'
},
'太极贵人': {
nature: '吉',
meaning: '聪明好学,喜神秘文化',
effects: ['智慧', '学习能力', '神秘文化'],
查法: '甲乙生人子午中,丙丁鸡兔定亨通,戊己两干临四季,庚辛寅亥禄丰隆,壬癸巳申偏喜美,值此应当福气钟'
},
'文昌贵人': {
nature: '吉',
meaning: '文采出众,利于考试',
effects: ['文采', '考试运', '学业'],
查法: '甲乙巳午报君知,丙戊申宫丁己鸡,庚猪辛鼠壬逢虎,癸人见卯入云梯'
},
'华盖': {
nature: '半吉半凶',
meaning: '孤高清雅,喜神秘文化',
effects: ['艺术天赋', '孤独', '神秘文化'],
查法: '寅午戌见戌,亥卯未见未,申子辰见辰,巳酉丑见丑'
},
'桃花': {
nature: '半吉半凶',
meaning: '异性缘佳,感情丰富',
effects: ['异性缘', '感情', '艺术'],
查法: '寅午戌见卯,亥卯未见子,申子辰见酉,巳酉丑见午'
},
'驿马': {
nature: '动',
meaning: '奔波变动,利于发展',
effects: ['变动', '旅行', '发展'],
查法: '寅午戌马在申,申子辰马在寅,巳酉丑马在亥,亥卯未马在巳'
},
'羊刃': {
nature: '凶',
meaning: '性格刚烈,易有灾祸',
effects: ['刚烈', '灾祸', '手术'],
查法: '甲羊刃在卯,乙羊刃在寅,丙戊羊刃在午,丁己羊刃在未,庚羊刃在酉,辛羊刃在申,壬羊刃在子,癸羊刃在亥'
},
'劫煞': {
nature: '凶',
meaning: '破财劫夺,小人是非',
effects: ['破财', '小人', '是非'],
查法: '寅午戌劫在亥,申子辰劫在巳,巳酉丑劫在寅,亥卯未劫在申'
},
'灾煞': {
nature: '凶',
meaning: '意外灾祸,血光之灾',
effects: ['意外', '灾祸', '血光'],
查法: '寅午戌灾在丑,申子辰灾在未,巳酉丑灾在戌,亥卯未灾在辰'
},
'孤辰': {
nature: '凶',
meaning: '孤独无依,六亲缘薄',
effects: ['孤独', '六亲缘薄'],
查法: '亥子丑人见寅,寅卯辰人见巳,巳午未人见申,申酉戌人见亥'
},
'寡宿': {
nature: '凶',
meaning: '孤独寡居,婚姻不利',
effects: ['孤独', '婚姻不利'],
查法: '亥子丑人见戌,寅卯辰人见丑,巳午未人见辰,申酉戌人见未'
}
};
}
/**
* 初始化格局数据
*/
initializePatterns() {
return {
'正官格': {
condition: '月令正官透干',
characteristics: ['正直', '责任心', '适合公职'],
喜用神: ['印绶', '比劫'],
忌神: ['伤官', '七杀'],
career: ['公务员', '管理', '法律', '教育'],
personality: ['正直', '有责任心', '保守稳重']
},
'七杀格': {
condition: '月令七杀透干',
characteristics: ['果断', '有魄力', '适合竞争'],
喜用神: ['印绶', '食神'],
忌神: ['财星', '比劫'],
career: ['军警', '竞争性行业', '企业家'],
personality: ['果断', '有魄力', '不服输']
},
'正财格': {
condition: '月令正财透干',
characteristics: ['务实', '节俭', '善理财'],
喜用神: ['比劫', '印绶'],
忌神: ['劫财', '伤官'],
career: ['财务', '银行', '实业', '贸易'],
personality: ['务实', '节俭', '有责任心']
},
'偏财格': {
condition: '月令偏财透干',
characteristics: ['灵活', '善交际', '机遇多'],
喜用神: ['比劫', '印绶'],
忌神: ['劫财', '伤官'],
career: ['投资', '贸易', '服务业', '娱乐'],
personality: ['灵活', '善交际', '重义气']
},
'食神格': {
condition: '月令食神透干',
characteristics: ['才华横溢', '乐观', '享受生活'],
喜用神: ['财星', '比劫'],
忌神: ['偏印', '七杀'],
career: ['艺术', '娱乐', '餐饮', '教育'],
personality: ['乐观', '有才华', '享受生活']
},
'伤官格': {
condition: '月令伤官透干',
characteristics: ['聪明', '有才华', '叛逆'],
喜用神: ['财星', '印绶'],
忌神: ['正官', '七杀'],
career: ['艺术', '技术', '创新', '自由职业'],
personality: ['聪明', '有才华', '不拘一格']
},
'正印格': {
condition: '月令正印透干',
characteristics: ['仁慈', '好学', '有智慧'],
喜用神: ['官杀', '比劫'],
忌神: ['财星', '食伤'],
career: ['教育', '文化', '宗教', '慈善'],
personality: ['仁慈', '好学', '有智慧']
},
'偏印格': {
condition: '月令偏印透干',
characteristics: ['聪明', '直觉强', '喜神秘'],
喜用神: ['官杀', '比劫'],
忌神: ['财星', '食神'],
career: ['研究', '玄学', '艺术', '医学'],
personality: ['聪明', '直觉强', '有些孤僻']
},
'比肩格': {
condition: '月令比肩透干',
characteristics: ['独立', '自主', '有主见'],
喜用神: ['食伤', '官杀'],
忌神: ['财星', '比劫'],
career: ['自由职业', '合伙', '竞争性行业'],
personality: ['独立', '自主', '有主见']
},
'劫财格': {
condition: '月令劫财透干',
characteristics: ['果断', '行动力强', '冲动'],
喜用神: ['食伤', '官杀'],
忌神: ['财星', '比劫'],
career: ['投机', '冒险', '变动性行业'],
personality: ['果断', '行动力强', '有些冲动']
}
};
}
/**
* 根据天干名称获取天干信息
* @param {string} stem - 天干名称
* @returns {Object|null} 天干信息
*/
getHeavenlyStem(stem) {
return this.heavenlyStems[stem] || null;
}
/**
* 根据地支名称获取地支信息
* @param {string} branch - 地支名称
* @returns {Object|null} 地支信息
*/
getEarthlyBranch(branch) {
return this.earthlyBranches[branch] || null;
}
/**
* 根据五行名称获取五行信息
* @param {string} element - 五行名称
* @returns {Object|null} 五行信息
*/
getFiveElement(element) {
return this.fiveElements[element] || null;
}
/**
* 根据十神名称获取十神信息
* @param {string} god - 十神名称
* @returns {Object|null} 十神信息
*/
getTenGod(god) {
return this.tenGods[god] || null;
}
/**
* 根据干支组合获取纳音
* @param {string} stem - 天干
* @param {string} branch - 地支
* @returns {string|null} 纳音
*/
getNayin(stem, branch) {
return this.nayin[stem + branch] || null;
}
/**
* 根据神煞名称获取神煞信息
* @param {string} spirit - 神煞名称
* @returns {Object|null} 神煞信息
*/
getSpirit(spirit) {
return this.spirits[spirit] || null;
}
/**
* 根据格局名称获取格局信息
* @param {string} pattern - 格局名称
* @returns {Object|null} 格局信息
*/
getPattern(pattern) {
return this.patterns[pattern] || null;
}
/**
* 获取所有天干列表
* @returns {Array} 天干列表
*/
getAllHeavenlyStems() {
return Object.keys(this.heavenlyStems);
}
/**
* 获取所有地支列表
* @returns {Array} 地支列表
*/
getAllEarthlyBranches() {
return Object.keys(this.earthlyBranches);
}
/**
* 获取所有五行列表
* @returns {Array} 五行列表
*/
getAllFiveElements() {
return Object.keys(this.fiveElements);
}
/**
* 获取所有十神列表
* @returns {Array} 十神列表
*/
getAllTenGods() {
return Object.keys(this.tenGods);
}
/**
* 获取所有格局列表
* @returns {Array} 格局列表
*/
getAllPatterns() {
return Object.keys(this.patterns);
}
/**
* 计算天干地支的五行关系
* @param {string} element1 - 五行1
* @param {string} element2 - 五行2
* @returns {string} 五行关系
*/
getFiveElementRelationship(element1, element2) {
const el1 = this.fiveElements[element1];
const el2 = this.fiveElements[element2];
if (!el1 || !el2) return '未知';
if (el1.generates === element2) return '相生';
if (el1.destroys === element2) return '相克';
if (el2.generates === element1) return '被生';
if (el2.destroys === element1) return '被克';
if (element1 === element2) return '比和';
return '无关';
}
/**
* 根据日干和其他干支计算十神
* @param {string} dayStem - 日干
* @param {string} targetStem - 目标天干
* @returns {string} 十神名称
*/
calculateTenGod(dayStem, targetStem) {
const dayInfo = this.heavenlyStems[dayStem];
const targetInfo = this.heavenlyStems[targetStem];
if (!dayInfo || !targetInfo) return '未知';
const dayElement = dayInfo.element;
const targetElement = targetInfo.element;
const dayPolarity = dayInfo.polarity;
const targetPolarity = targetInfo.polarity;
// 同类关系
if (dayElement === targetElement) {
return dayPolarity === targetPolarity ? '比肩' : '劫财';
}
// 我生关系
if (this.fiveElements[dayElement].generates === targetElement) {
return dayPolarity === targetPolarity ? '食神' : '伤官';
}
// 我克关系
if (this.fiveElements[dayElement].destroys === targetElement) {
return dayPolarity === targetPolarity ? '偏财' : '正财';
}
// 克我关系
if (this.fiveElements[targetElement].destroys === dayElement) {
return dayPolarity === targetPolarity ? '七杀' : '正官';
}
// 生我关系
if (this.fiveElements[targetElement].generates === dayElement) {
return dayPolarity === targetPolarity ? '偏印' : '正印';
}
return '未知';
}
/**
* 检查神煞
* @param {Object} bazi - 八字信息
* @param {string} spiritName - 神煞名称
* @returns {boolean} 是否有此神煞
*/
checkSpirit(bazi, spiritName) {
// 这里需要根据具体的神煞查法来实现
// 简化实现,实际应该根据各种神煞的查法来判断
return false;
}
/**
* 分析八字格局
* @param {Object} bazi - 八字信息
* @returns {Object} 格局分析结果
*/
analyzePattern(bazi) {
// 简化实现,实际应该根据月令和透干情况来判断格局
const monthBranch = bazi.month.branch;
const monthStem = bazi.month.stem;
const dayStem = bazi.day.stem;
// 计算月令藏干的十神
const monthBranchInfo = this.earthlyBranches[monthBranch];
if (!monthBranchInfo) return { pattern: '未知格局', strength: '中等' };
const hiddenStems = monthBranchInfo.hidden_stems;
const mainHiddenStem = hiddenStems[0]; // 主气
const tenGod = this.calculateTenGod(dayStem, mainHiddenStem);
const patternName = tenGod + '格';
const pattern = this.patterns[patternName];
if (pattern) {
return {
pattern: patternName,
description: pattern.characteristics.join('、'),
career_suggestions: pattern.career,
personality_traits: pattern.personality,
favorable_gods: pattern.喜用神,
unfavorable_gods: pattern.忌神
};
}
return {
pattern: '普通格局',
description: '无特殊格局',
career_suggestions: ['根据具体情况分析'],
personality_traits: ['需要综合分析'],
favorable_gods: ['需要具体分析'],
unfavorable_gods: ['需要具体分析']
};
}
/**
* 搜索相关信息
* @param {string} keyword - 关键词
* @param {string} category - 搜索类别
* @returns {Array} 搜索结果
*/
search(keyword, category = 'all') {
const results = [];
const lowerKeyword = keyword.toLowerCase();
if (category === 'all' || category === 'stems') {
Object.entries(this.heavenlyStems).forEach(([name, info]) => {
if (name.includes(keyword) ||
info.element.includes(keyword) ||
info.personality.some(p => p.includes(keyword))) {
results.push({ type: '天干', name, ...info });
}
});
}
if (category === 'all' || category === 'branches') {
Object.entries(this.earthlyBranches).forEach(([name, info]) => {
if (name.includes(keyword) ||
info.element.includes(keyword) ||
info.animal.includes(keyword)) {
results.push({ type: '地支', name, ...info });
}
});
}
if (category === 'all' || category === 'elements') {
Object.entries(this.fiveElements).forEach(([name, info]) => {
if (name.includes(keyword) ||
info.personality.some(p => p.includes(keyword)) ||
info.career.some(c => c.includes(keyword))) {
results.push({ type: '五行', name, ...info });
}
});
}
if (category === 'all' || category === 'gods') {
Object.entries(this.tenGods).forEach(([name, info]) => {
if (name.includes(keyword) ||
info.positive.some(p => p.includes(keyword)) ||
info.negative.some(n => n.includes(keyword))) {
results.push({ type: '十神', name, ...info });
}
});
}
return results;
}
}
module.exports = BaziDatabase;