08ea5fbe98
添加用户管理视图、API和状态管理文件
1030 lines
36 KiB
Markdown
1030 lines
36 KiB
Markdown
# 紫微斗数数据模型设计
|
||
|
||
## 目录
|
||
|
||
- [一、现有数据模型分析](#一现有数据模型分析)
|
||
- [二、数据模型优化方案](#二数据模型优化方案)
|
||
- [三、核心数据结构设计](#三核心数据结构设计)
|
||
- [四、枚举定义](#四枚举定义)
|
||
- [五、数据模型实现](#五数据模型实现)
|
||
- [六、算法流程设计](#六算法流程设计)
|
||
|
||
---
|
||
|
||
## 一、现有数据模型分析
|
||
|
||
### 1.1 现有模型结构
|
||
|
||
#### 1.1.1 ZiweiChart(命盘主类)
|
||
|
||
```java
|
||
public class ZiweiChart {
|
||
private BirthInfo birthInfo;
|
||
private List<Palace> palaces;
|
||
private HeavenlyStem yearStem;
|
||
private EarthlyBranch mingGongBranch;
|
||
private EarthlyBranch shenGongBranch;
|
||
private String summary;
|
||
private String overallLuck;
|
||
}
|
||
```
|
||
|
||
**优点**:
|
||
|
||
- 结构清晰,包含基本信息
|
||
- 支持通过宫位类型和地支查询宫位
|
||
|
||
**缺点**:
|
||
|
||
- 缺少大限、流年、流月、流日、流时信息
|
||
- 缺少四化星的详细信息
|
||
- 缺少星曜格局信息
|
||
- 缺少三方四正关系信息
|
||
|
||
#### 1.1.2 Palace(宫位类)
|
||
|
||
```java
|
||
public class Palace {
|
||
private PalaceType palaceType;
|
||
private EarthlyBranch earthlyBranch;
|
||
private List<StarInfo> majorStars;
|
||
private List<String> minorStars;
|
||
private String analysis;
|
||
private int score;
|
||
}
|
||
```
|
||
|
||
**优点**:
|
||
|
||
- 包含宫位基本信息
|
||
- 支持主星和辅星
|
||
|
||
**缺点**:
|
||
|
||
- minorStars 使用 String 类型,不够类型安全
|
||
- 缺少宫位的三方四正关系
|
||
- 缺少宫位的四化信息
|
||
- 缺少宫位的星曜格局信息
|
||
|
||
#### 1.1.3 StarInfo(星星信息类)
|
||
|
||
```java
|
||
public class StarInfo {
|
||
private MajorStar star;
|
||
private StarNature nature;
|
||
private TransformationType transformation;
|
||
private int brightness;
|
||
private String description;
|
||
}
|
||
```
|
||
|
||
**优点**:
|
||
|
||
- 包含星星的基本信息
|
||
- 支持四化
|
||
|
||
**缺点**:
|
||
|
||
- 缺少星星的宫位信息
|
||
- 缺少星星的亮度计算逻辑
|
||
- 缺少星星的相互作用信息
|
||
|
||
### 1.2 现有枚举问题
|
||
|
||
#### 1.2.1 MajorStar 枚举问题
|
||
|
||
```java
|
||
public enum MajorStar {
|
||
ZIWEI("紫微", 1, StarNature.AUSPICIOUS, "帝星", "领导、权威、尊贵"),
|
||
TIANJI("天机", 2, StarNature.AUSPICIOUS, "智星", "智慧、谋略、变通"),
|
||
TAIYANG("太阳", 3, StarNature.AUSPICIOUS, "贵星", "光明、热情、慷慨"),
|
||
WUQU("武曲", 4, StarNature.NEUTRAL, "财星", "刚毅、务实、财帛"),
|
||
TIANXING("天同", 5, StarNature.AUSPICIOUS, "福星", "温和、福气、享受"),
|
||
LIANCHEN("廉贞", 6, StarNature.INAUSPICIOUS, "情星", "感情、才华、是非"),
|
||
TIANFU("天府", 7, StarNature.AUSPICIOUS, "库星", "稳重、保守、财富"),
|
||
TAIYIN("太阴", 8, StarNature.NEUTRAL, "母星", "温柔、内敛、母性"),
|
||
TANLANG("贪狼", 9, StarNature.INAUSPICIOUS, "欲星", "欲望、魅力、桃花"),
|
||
JUMEN("巨门", 10, StarNature.INAUSPICIOUS, "口星", "口才、是非、沟通"),
|
||
TIANXIANG("天相", 11, StarNature.AUSPICIOUS, "印星", "辅佐、稳重、贵人"),
|
||
TIANLIANG("天梁", 12, StarNature.NEUTRAL, "荫星", "恩泽、稳重、长辈"),
|
||
QISHA("七杀", 13, StarNature.INAUSPICIOUS, "将星", "威猛、果断、开创"),
|
||
POJUN("破军", 14, StarNature.INAUSPICIOUS, "耗星", "破旧立新、变动、消耗");
|
||
|
||
private final String name;
|
||
private final int index;
|
||
private final StarNature nature;
|
||
private final String alias;
|
||
private final String description;
|
||
|
||
MajorStar(String name, int index, StarNature nature, String alias, String description) {
|
||
this.name = name;
|
||
this.index = index;
|
||
this.nature = nature;
|
||
this.alias = alias;
|
||
this.description = description;
|
||
}
|
||
|
||
public String getName() {
|
||
return name;
|
||
}
|
||
|
||
public int getIndex() {
|
||
return index;
|
||
}
|
||
|
||
public StarNature getNature() {
|
||
return nature;
|
||
}
|
||
|
||
public String getAlias() {
|
||
return alias;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
}
|
||
```
|
||
|
||
**问题**:
|
||
|
||
- 包含了辅星(天魁、天钺、禄存)
|
||
- 缺少天府星
|
||
- 主星数量不正确(应该是 14 颗)
|
||
|
||
#### 1.2.2 MinorStar 枚举问题
|
||
|
||
```java
|
||
public enum MinorStar {
|
||
WENCHANG("文昌"),
|
||
WENQU("文曲"),
|
||
LUCHUN("禄存"), // 重复:禄存在MajorStar中也存在
|
||
QINGYANG("擎羊"),
|
||
// ...
|
||
}
|
||
```
|
||
|
||
**问题**:
|
||
|
||
- 与 MajorStar 重复(禄存)
|
||
- 缺少很多重要的辅星
|
||
- 分类不清晰(六吉星、六煞星、其他辅星)
|
||
|
||
---
|
||
|
||
## 二、数据模型优化方案
|
||
|
||
### 2.1 优化目标
|
||
|
||
1. **完整性**:包含紫微斗数所有核心要素
|
||
2. **准确性**:正确区分主星和辅星
|
||
3. **扩展性**:支持大限、流年、流月、流日、流时
|
||
4. **类型安全**:使用强类型而非 String
|
||
5. **可计算性**:支持三方四正、星曜格局等计算
|
||
6. **可持久化**:支持数据库存储和查询
|
||
|
||
### 2.2 优化策略
|
||
|
||
#### 2.2.1 分层设计
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ ZiweiChart(命盘) │
|
||
│ ├─ BirthInfo(出生信息) │
|
||
│ ├─ TrueSolarTime(真太阳时) │
|
||
│ ├─ PalaceList(宫位列表) │
|
||
│ ├─ MajorLimitList(大限列表) │
|
||
│ ├─ CurrentYear(流年) │
|
||
│ ├─ CurrentMonth(流月) │
|
||
│ ├─ CurrentDay(流日) │
|
||
│ └─ StarPatternList(星曜格局) │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
#### 2.2.2 宫位扩展
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ Palace(宫位) │
|
||
│ ├─ PalaceType(宫位类型) │
|
||
│ ├─ EarthlyBranch(地支) │
|
||
│ ├─ HeavenlyStem(天干) │
|
||
│ ├─ MajorStarList(主星列表) │
|
||
│ ├─ MinorStarList(辅星列表) │
|
||
│ ├─ TransformationList(四化列表) │
|
||
│ ├─ ThreeSidesFourDirections(三方四正)│
|
||
│ ├─ PalaceFortune(宫位运势) │
|
||
│ └─ PalaceScore(宫位评分) │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
#### 2.2.3 星星扩展
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ StarInfo(星星信息) │
|
||
│ ├─ StarType(星星类型) │
|
||
│ ├─ StarNature(星性) │
|
||
│ ├─ StarBrightness(亮度) │
|
||
│ ├─ StarTransformation(四化) │
|
||
│ ├─ StarPalace(所在宫位) │
|
||
│ ├─ StarDescription(描述) │
|
||
│ └─ StarInteraction(相互作用) │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
---
|
||
|
||
## 三、核心数据结构设计
|
||
|
||
### 3.1 命盘数据结构(ZiweiChart)
|
||
|
||
```java
|
||
public class ZiweiChart {
|
||
private BirthInfo birthInfo;
|
||
private TrueSolarTime trueSolarTime;
|
||
private List<Palace> palaces;
|
||
private List<Palace> majorLimits;
|
||
private Palace currentYear;
|
||
private Palace currentMonth;
|
||
private Palace currentDay;
|
||
private Palace currentHour;
|
||
private List<StarPattern> starPatterns;
|
||
private HeavenlyStem yearStem;
|
||
private EarthlyBranch mingGongBranch;
|
||
private EarthlyBranch shenGongBranch;
|
||
private String summary;
|
||
private String overallLuck;
|
||
private int overallScore;
|
||
}
|
||
```
|
||
|
||
### 3.2 宫位数据结构(Palace)
|
||
|
||
```java
|
||
public class Palace {
|
||
private PalaceType palaceType;
|
||
private EarthlyBranch earthlyBranch;
|
||
private HeavenlyStem heavenlyStem;
|
||
private List<MajorStarInfo> majorStars;
|
||
private List<MinorStarInfo> minorStars;
|
||
private List<Transformation> transformations;
|
||
private ThreeSidesFourDirections threeSidesFourDirections;
|
||
private PalaceFortune fortune;
|
||
private int score;
|
||
private String analysis;
|
||
}
|
||
```
|
||
|
||
### 3.3 主星信息结构(MajorStarInfo)
|
||
|
||
```java
|
||
public class MajorStarInfo {
|
||
private MajorStar star;
|
||
private StarNature nature;
|
||
private StarBrightness brightness;
|
||
private Transformation transformation;
|
||
private Palace palace;
|
||
private String description;
|
||
private int influenceScore;
|
||
}
|
||
```
|
||
|
||
### 3.4 辅星信息结构(MinorStarInfo)
|
||
|
||
```java
|
||
public class MinorStarInfo {
|
||
private MinorStar star;
|
||
private StarNature nature;
|
||
private StarBrightness brightness;
|
||
private Palace palace;
|
||
private String description;
|
||
private int influenceScore;
|
||
}
|
||
```
|
||
|
||
### 3.5 四化信息结构(Transformation)
|
||
|
||
```java
|
||
public class Transformation {
|
||
private HeavenlyStem stem;
|
||
private MajorStar star;
|
||
private TransformationType type;
|
||
private Palace palace;
|
||
private String effect;
|
||
}
|
||
```
|
||
|
||
### 3.6 三方四正结构(ThreeSidesFourDirections)
|
||
|
||
```java
|
||
public class ThreeSidesFourDirections {
|
||
private Palace mainPalace;
|
||
private Palace oppositePalace;
|
||
private Palace leftPalace;
|
||
private Palace rightPalace;
|
||
private List<Palace> allPalaces;
|
||
}
|
||
```
|
||
|
||
### 3.7 星曜格局结构(StarPattern)
|
||
|
||
```java
|
||
public class StarPattern {
|
||
private String patternName;
|
||
private List<MajorStar> stars;
|
||
private List<Palace> palaces;
|
||
private String description;
|
||
private String effect;
|
||
private int patternScore;
|
||
}
|
||
```
|
||
|
||
### 3.8 宫位运势结构(PalaceFortune)
|
||
|
||
```java
|
||
public class PalaceFortune {
|
||
private PalaceType palaceType;
|
||
private int score;
|
||
private String luckLevel;
|
||
private String analysis;
|
||
private String advice;
|
||
private String luckyColor;
|
||
private String luckyDirection;
|
||
private String luckyNumber;
|
||
}
|
||
```
|
||
|
||
### 3.9 真太阳时结构(TrueSolarTime)
|
||
|
||
```java
|
||
public class TrueSolarTime {
|
||
private LocalTime beijingTime;
|
||
private double longitude;
|
||
private LocalTime trueSolarTime;
|
||
private String shichen;
|
||
private int timeDiffMinutes;
|
||
}
|
||
```
|
||
|
||
### 3.10 大限结构(MajorLimit)
|
||
|
||
```java
|
||
public static class MajorLimit {
|
||
private int limitNumber; // 大限序号(1-12)
|
||
private EarthlyBranch branch; // 大限地支
|
||
private int startAge; // 起始年龄
|
||
private int endAge; // 结束年龄
|
||
private Palace palace; // 对应宫位
|
||
private String luckDescription; // 运势描述
|
||
|
||
public MajorLimit(int limitNumber, EarthlyBranch branch,
|
||
int startAge, int endAge) {
|
||
this.limitNumber = limitNumber;
|
||
this.branch = branch;
|
||
this.startAge = startAge;
|
||
this.endAge = endAge;
|
||
}
|
||
|
||
public boolean isAgeInRange(int age) {
|
||
return age >= startAge && age <= endAge;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 3.11 流年结构(CurrentYear)
|
||
|
||
```java
|
||
public static class CurrentYear {
|
||
private int year; // 年份
|
||
private EarthlyBranch branch; // 流年地支
|
||
private Palace mingGong; // 流年命宫
|
||
private String luckDescription; // 运势描述
|
||
|
||
public CurrentYear(int year, EarthlyBranch branch) {
|
||
this.year = year;
|
||
this.branch = branch;
|
||
}
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 四、枚举定义
|
||
|
||
### 4.1 主星枚举(MajorStar)
|
||
|
||
```java
|
||
public enum MajorStar {
|
||
ZIWEI("紫微", 1, StarNature.AUSPICIOUS, "帝星", "领导、权威、尊贵"),
|
||
TIANJI("天机", 2, StarNature.AUSPICIOUS, "智星", "智慧、谋略、变通"),
|
||
TAIYANG("太阳", 3, StarNature.AUSPICIOUS, "贵星", "光明、热情、慷慨"),
|
||
WUQU("武曲", 4, StarNature.NEUTRAL, "财星", "刚毅、务实、财帛"),
|
||
TIANXING("天同", 5, StarNature.AUSPICIOUS, "福星", "温和、福气、享受"),
|
||
LIANCHEN("廉贞", 6, StarNature.INAUSPICIOUS, "情星", "感情、才华、是非"),
|
||
TIANFU("天府", 7, StarNature.AUSPICIOUS, "库星", "稳重、保守、财富"),
|
||
TAIYIN("太阴", 8, StarNature.NEUTRAL, "母星", "温柔、内敛、母性"),
|
||
TANLANG("贪狼", 9, StarNature.INAUSPICIOUS, "欲星", "欲望、魅力、桃花"),
|
||
JUMEN("巨门", 10, StarNature.INAUSPICIOUS, "口星", "口才、是非、沟通"),
|
||
TIANXIANG("天相", 11, StarNature.AUSPICIOUS, "印星", "辅佐、稳重、贵人"),
|
||
TIANLIANG("天梁", 12, StarNature.NEUTRAL, "荫星", "恩泽、稳重、长辈"),
|
||
QISHA("七杀", 13, StarNature.INAUSPICIOUS, "将星", "威猛、果断、开创"),
|
||
POJUN("破军", 14, StarNature.INAUSPICIOUS, "耗星", "破旧立新、变动、消耗");
|
||
|
||
private final String name;
|
||
private final int index;
|
||
private final StarNature nature;
|
||
private final String alias;
|
||
private final String description;
|
||
|
||
MajorStar(String name, int index, StarNature nature, String alias, String description) {
|
||
this.name = name;
|
||
this.index = index;
|
||
this.nature = nature;
|
||
this.alias = alias;
|
||
this.description = description;
|
||
}
|
||
|
||
public String getName() {
|
||
return name;
|
||
}
|
||
|
||
public int getIndex() {
|
||
return index;
|
||
}
|
||
|
||
public StarNature getNature() {
|
||
return nature;
|
||
}
|
||
|
||
public String getAlias() {
|
||
return alias;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4.2 辅星枚举(MinorStar)
|
||
|
||
```java
|
||
public enum MinorStar {
|
||
WENCHANG("文昌", MinorStarType.LUCKY, "文昌星", "主科名、文采、学业"),
|
||
WENQU("文曲", MinorStarType.LUCKY, "文曲星", "主口才、艺术、才华"),
|
||
ZUOFU("左辅", MinorStarType.LUCKY, "左辅星", "主辅佐、助力、贵人"),
|
||
YOUBI("右弼", MinorStarType.LUCKY, "右弼星", "主辅佐、助力、贵人"),
|
||
TIANKUI("天魁", MinorStarType.LUCKY, "天魁星", "主贵人、助力、机遇"),
|
||
TIANYUE("天钺", MinorStarType.LUCKY, "天钺星", "主贵人、助力、机遇"),
|
||
QINGYANG("擎羊", MinorStarType.EVIL, "羊刃星", "主刑伤、是非、血光"),
|
||
TUOLUO("陀罗", MinorStarType.EVIL, "陀罗星", "主拖延、迟滞、纠结"),
|
||
HUOXING("火星", MinorStarType.EVIL, "火星", "主急躁、突发、灾难"),
|
||
LINGXING("铃星", MinorStarType.EVIL, "铃星", "主突发、灾难、变动"),
|
||
DIKONG("地空", MinorStarType.EVIL, "地空星", "主空亡、损失、虚耗"),
|
||
DIJIE("地劫", MinorStarType.EVIL, "地劫星", "主劫夺、损失、破财"),
|
||
TIANMA("天马", MinorStarType.OTHER, "天马星", "主迁移、奔波、变动"),
|
||
TIANKU("天哭", MinorStarType.OTHER, "天哭星", "主悲伤、忧虑、情绪低落"),
|
||
TIANXU("天虚", MinorStarType.OTHER, "天虚星", "主虚耗、损失、空亡"),
|
||
LONGCHI("龙池", MinorStarType.OTHER, "龙池星", "主才华、艺术、文采"),
|
||
FENGGU("凤阁", MinorStarType.OTHER, "凤阁星", "主才华、艺术、文采"),
|
||
HONGLUAN("红鸾", MinorStarType.OTHER, "红鸾星", "主桃花、婚姻、感情"),
|
||
TIANXI("天喜", MinorStarType.OTHER, "天喜星", "主桃花、婚姻、感情"),
|
||
GUCHEN("孤辰", MinorStarType.OTHER, "孤辰星", "主孤独、寂寞、寡居"),
|
||
GUAKU("寡宿", MinorStarType.OTHER, "寡宿星", "主孤独、寂寞、寡居"),
|
||
FEILING("飞铃", MinorStarType.OTHER, "飞铃星", "主变动、奔波"),
|
||
BAIHU("白虎", MinorStarType.OTHER, "白虎星", "主凶险、血光"),
|
||
FEIXING("飞星", MinorStarType.OTHER, "飞星星", "主变动、奔波"),
|
||
LUCUN("禄存", MinorStarType.OTHER, "禄存星", "主财帛、福气");
|
||
|
||
private final String name;
|
||
private final MinorStarType type;
|
||
private final String alias;
|
||
private final String description;
|
||
|
||
MinorStar(String name, MinorStarType type, String alias, String description) {
|
||
this.name = name;
|
||
this.type = type;
|
||
this.alias = alias;
|
||
this.description = description;
|
||
}
|
||
|
||
public String getName() {
|
||
return name;
|
||
}
|
||
|
||
public MinorStarType getType() {
|
||
return type;
|
||
}
|
||
|
||
public String getAlias() {
|
||
return alias;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4.3 辅星类型枚举(MinorStarType)
|
||
|
||
```java
|
||
public enum MinorStarType {
|
||
LUCKY("吉星"),
|
||
EVIL("煞星"),
|
||
OTHER("其他");
|
||
|
||
private final String description;
|
||
|
||
MinorStarType(String description) {
|
||
this.description = description;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4.4 星性枚举(StarNature)
|
||
|
||
```java
|
||
public enum StarNature {
|
||
AUSPICIOUS("吉星"),
|
||
NEUTRAL("中性"),
|
||
INAUSPICIOUS("凶星");
|
||
|
||
private final String description;
|
||
|
||
StarNature(String description) {
|
||
this.description = description;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4.5 星亮度枚举(StarBrightness)
|
||
|
||
```java
|
||
public enum StarBrightness {
|
||
BRIGHT("庙", 100),
|
||
VERY_BRIGHT("旺", 90),
|
||
BRIGHT_MODERATE("得地", 80),
|
||
MODERATE("平和", 70),
|
||
DIM("陷", 60),
|
||
VERY_DIM("落陷", 50);
|
||
|
||
private final String name;
|
||
private final int score;
|
||
|
||
StarBrightness(String name, int score) {
|
||
this.name = name;
|
||
this.score = score;
|
||
}
|
||
|
||
public String getName() {
|
||
return name;
|
||
}
|
||
|
||
public int getScore() {
|
||
return score;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4.6 四化类型枚举(TransformationType)
|
||
|
||
```java
|
||
public enum TransformationType {
|
||
LU("禄", "福气、钱财、好运、增幅"),
|
||
QUAN("权", "权力、竞争、强势、掌控"),
|
||
KE("科", "科名、名声、地位、才华"),
|
||
JI("忌", "波折、损失、是非");
|
||
|
||
private final String name;
|
||
private final String description;
|
||
|
||
TransformationType(String name, String description) {
|
||
this.name = name;
|
||
this.description = description;
|
||
}
|
||
|
||
public String getName() {
|
||
return name;
|
||
}
|
||
|
||
public String getDescription() {
|
||
return description;
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4.7 四化星映射表
|
||
|
||
根据紫微斗数权威标准,天干四化映射关系如下:
|
||
|
||
| 天干 | 化禄 | 化权 | 化科 | 化忌 |
|
||
| ---- | ---- | ---- | ---- | ---- |
|
||
| 甲 | 廉贞 | 破军 | 武曲 | 太阳 |
|
||
| 乙 | 天机 | 天梁 | 紫微 | 太阴 |
|
||
| 丙 | 天同 | 天机 | 文昌 | 廉贞 |
|
||
| 丁 | 太阴 | 天同 | 天机 | 巨门 |
|
||
| 戊 | 贪狼 | 太阴 | 右弼 | 天机 |
|
||
| 己 | 武曲 | 贪狼 | 天梁 | 文曲 |
|
||
| 庚 | 太阳 | 武曲 | 太阴 | 天同 |
|
||
| 辛 | 巨门 | 太阳 | 文曲 | 天相 |
|
||
| 壬 | 天梁 | 紫微 | 武曲 | 破军 |
|
||
| 癸 | 破军 | 巨门 | 太阴 | 贪狼 |
|
||
|
||
**四化星映射数据结构**:
|
||
|
||
```java
|
||
public class TransformationMapping {
|
||
private HeavenlyStem stem;
|
||
private MajorStar luStar;
|
||
private MajorStar quanStar;
|
||
private MajorStar keStar;
|
||
private MajorStar jiStar;
|
||
|
||
public TransformationMapping(HeavenlyStem stem, MajorStar luStar,
|
||
MajorStar quanStar, MajorStar keStar,
|
||
MajorStar jiStar) {
|
||
this.stem = stem;
|
||
this.luStar = luStar;
|
||
this.quanStar = quanStar;
|
||
this.keStar = keStar;
|
||
this.jiStar = jiStar;
|
||
}
|
||
|
||
public MajorStar getTransformationStar(TransformationType type) {
|
||
switch (type) {
|
||
case LU: return luStar;
|
||
case QUAN: return quanStar;
|
||
case KE: return keStar;
|
||
case JI: return jiStar;
|
||
default: return null;
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
**四化星映射常量**:
|
||
|
||
```java
|
||
public class TransformationMappings {
|
||
public static final Map<HeavenlyStem, TransformationMapping> MAPPINGS;
|
||
|
||
static {
|
||
MAPPINGS = new HashMap<>();
|
||
MAPPINGS.put(HeavenlyStem.JIA, new TransformationMapping(
|
||
HeavenlyStem.JIA, MajorStar.LIANCHEN, MajorStar.POJUN,
|
||
MajorStar.WUQU, MajorStar.TAIYANG));
|
||
MAPPINGS.put(HeavenlyStem.YI, new TransformationMapping(
|
||
HeavenlyStem.YI, MajorStar.TIANJI, MajorStar.TIANLIANG,
|
||
MajorStar.ZIWEI, MajorStar.TAIYIN));
|
||
MAPPINGS.put(HeavenlyStem.BING, new TransformationMapping(
|
||
HeavenlyStem.BING, MajorStar.TIANXING, MajorStar.TIANJI,
|
||
MinorStar.WENCHANG, MajorStar.LIANCHEN));
|
||
MAPPINGS.put(HeavenlyStem.DING, new TransformationMapping(
|
||
HeavenlyStem.DING, MajorStar.TAIYIN, MajorStar.TIANXING,
|
||
MajorStar.TIANJI, MajorStar.JUMEN));
|
||
MAPPINGS.put(HeavenlyStem.WU, new TransformationMapping(
|
||
HeavenlyStem.WU, MajorStar.TANLANG, MajorStar.TAIYIN,
|
||
MinorStar.YOUBI, MajorStar.TIANJI));
|
||
MAPPINGS.put(HeavenlyStem.JI, new TransformationMapping(
|
||
HeavenlyStem.JI, MajorStar.WUQU, MajorStar.TANLANG,
|
||
MajorStar.TIANLIANG, MinorStar.WENQU));
|
||
MAPPINGS.put(HeavenlyStem.GENG, new TransformationMapping(
|
||
HeavenlyStem.GENG, MajorStar.TAIYANG, MajorStar.WUQU,
|
||
MajorStar.TAIYIN, MajorStar.TIANXING));
|
||
MAPPINGS.put(HeavenlyStem.XIN, new TransformationMapping(
|
||
HeavenlyStem.XIN, MajorStar.JUMEN, MajorStar.TAIYANG,
|
||
MinorStar.WENQU, MajorStar.TIANXIANG));
|
||
MAPPINGS.put(HeavenlyStem.REN, new TransformationMapping(
|
||
HeavenlyStem.REN, MajorStar.TIANLIANG, MajorStar.ZIWEI,
|
||
MajorStar.WUQU, MajorStar.POJUN));
|
||
MAPPINGS.put(HeavenlyStem.GUI, new TransformationMapping(
|
||
HeavenlyStem.GUI, MajorStar.POJUN, MajorStar.JUMEN,
|
||
MajorStar.TAIYIN, MajorStar.TANLANG));
|
||
}
|
||
|
||
public static TransformationMapping getMapping(HeavenlyStem stem) {
|
||
return MAPPINGS.get(stem);
|
||
}
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## 五、数据模型实现
|
||
|
||
### 5.1 实现优先级
|
||
|
||
1. **高优先级**:
|
||
|
||
- 修正 MajorStar 枚举
|
||
- 修正 MinorStar 枚举
|
||
- 创建新的枚举类型
|
||
- 实现真太阳时计算
|
||
- 实现三方四正计算
|
||
|
||
2. **中优先级**:
|
||
|
||
- 扩展 Palace 类
|
||
- 扩展 StarInfo 类
|
||
- 实现星曜格局识别
|
||
- 实现大限流年计算
|
||
|
||
3. **低优先级**:
|
||
- 实现流月流日流时
|
||
- 实现星曜相互作用
|
||
- 实现高级分析功能
|
||
|
||
### 5.2 实现步骤
|
||
|
||
```
|
||
步骤1:修正枚举定义
|
||
├─ 修正MajorStar枚举
|
||
├─ 修正MinorStar枚举
|
||
├─ 创建MinorStarType枚举
|
||
└─ 创建StarBrightness枚举
|
||
|
||
步骤2:实现真太阳时计算
|
||
├─ 创建TrueSolarTime类
|
||
├─ 实现真太阳时计算方法
|
||
└─ 实现时辰确定方法
|
||
|
||
步骤3:扩展数据模型
|
||
├─ 扩展Palace类
|
||
├─ 扩展StarInfo类
|
||
├─ 创建MajorStarInfo类
|
||
├─ 创建MinorStarInfo类
|
||
└─ 创建Transformation类
|
||
|
||
步骤4:实现三方四正计算
|
||
├─ 创建ThreeSidesFourDirections类
|
||
├─ 实现三方四正计算方法
|
||
└─ 实现宫位关系查询
|
||
|
||
步骤5:实现星曜格局识别
|
||
├─ 创建StarPattern类
|
||
├─ 实现星曜格局识别方法
|
||
└─ 实现格局评分
|
||
|
||
步骤6:实现大限流年计算
|
||
├─ 实现大限计算方法
|
||
├─ 实现流年计算方法
|
||
└─ 实现流月流日流时计算
|
||
```
|
||
|
||
---
|
||
|
||
## 六、算法流程设计
|
||
|
||
### 6.1 排盘算法流程
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ 1. 输入出生信息 │
|
||
│ ├─ 出生日期(公历) │
|
||
│ ├─ 出生时间 │
|
||
│ ├─ 出生地(经纬度) │
|
||
│ └─ 性别 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 2. 计算真太阳时 │
|
||
│ ├─ 获取出生地经度 │
|
||
│ ├─ 计算经度差 │
|
||
│ ├─ 转换为时间差 │
|
||
│ └─ 得到真太阳时 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 3. 确定命宫位置 │
|
||
│ ├─ 根据出生月、日、时计算 │
|
||
│ └─ 确定命宫地支 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 4. 安紫微星 │
|
||
│ ├─ 根据出生日、时查表 │
|
||
│ └─ 确定紫微星所在宫位 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 5. 安十四主星 │
|
||
│ ├─ 根据紫微星位置和安星口诀 │
|
||
│ └─ 安放其他十三颗主星 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 6. 安十二宫位 │
|
||
│ ├─ 从命宫开始 │
|
||
│ ├─ 逆时针方向排列十二宫 │
|
||
│ └─ 确定各宫位地支 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 7. 安辅星 │
|
||
│ ├─ 安六吉星 │
|
||
│ ├─ 安六煞星 │
|
||
│ └─ 安其他辅星 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 8. 定四化 │
|
||
│ ├─ 根据出生年天干 │
|
||
│ └─ 确定四化星及其位置 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 9. 计算三方四正 │
|
||
│ ├─ 计算每个宫位的三方四正 │
|
||
│ └─ 建立宫位关系 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 10. 识别星曜格局 │
|
||
│ ├─ 识别十四主星格局 │
|
||
│ ├─ 识别辅星格局 │
|
||
│ └─ 计算格局评分 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 11. 安大限 │
|
||
│ ├─ 根据命宫位置 │
|
||
│ ├─ 顺时针方向排列大限 │
|
||
│ └─ 确定各年龄段的大限宫位 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 12. 生成命盘 │
|
||
│ └─ 返回完整命盘 │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
### 6.2 真太阳时计算流程
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ 1. 输入北京时间 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 2. 输入出生地经度 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 3. 计算经度差 │
|
||
│ 经度差 = 当地经度 - 120° │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 4. 转换为时间差 │
|
||
│ 时间差 = 经度差 × 4分钟 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 5. 计算真太阳时 │
|
||
│ 真太阳时 = 北京时间 + 时间差 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 6. 确定时辰 │
|
||
│ 根据真太阳时确定时辰 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 7. 返回真太阳时信息 │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
### 6.3 三方四正计算流程
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ 1. 输入宫位 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 2. 确定对冲宫位 │
|
||
│ 对冲宫位 = (宫位序号 + 6) mod 12 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 3. 确定左隔二宫位 │
|
||
│ 左隔二宫位 = (宫位序号 + 4) mod 12│
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 4. 确定右隔二宫位 │
|
||
│ 右隔二宫位 = (宫位序号 + 8) mod 12│
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 5. 返回三方四正 │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
### 6.4 星曜格局识别流程
|
||
|
||
```
|
||
┌─────────────────────────────────────┐
|
||
│ 1. 遍历所有宫位 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 2. 检查宫位主星组合 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 3. 检查三方四正主星组合 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 4. 匹配已知格局 │
|
||
│ ├─ 紫府同宫 │
|
||
│ ├─ 日月同宫 │
|
||
│ ├─ 机月同梁 │
|
||
│ ├─ 杀破狼 │
|
||
│ └─ 其他格局 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 5. 计算格局评分 │
|
||
└─────────────────────────────────────┘
|
||
↓
|
||
┌─────────────────────────────────────┐
|
||
│ 6. 返回星曜格局 │
|
||
└─────────────────────────────────────┘
|
||
```
|
||
|
||
---
|
||
|
||
## 附录
|
||
|
||
### A. 数据模型关系图
|
||
|
||
```
|
||
ZiweiChart
|
||
├─ BirthInfo
|
||
├─ TrueSolarTime
|
||
├─ List<Palace>
|
||
│ ├─ PalaceType
|
||
│ ├─ EarthlyBranch
|
||
│ ├─ HeavenlyStem
|
||
│ ├─ List<MajorStarInfo>
|
||
│ │ ├─ MajorStar
|
||
│ │ ├─ StarNature
|
||
│ │ ├─ StarBrightness
|
||
│ │ └─ Transformation
|
||
│ ├─ List<MinorStarInfo>
|
||
│ │ ├─ MinorStar
|
||
│ │ ├─ MinorStarType
|
||
│ │ └─ StarBrightness
|
||
│ ├─ List<Transformation>
|
||
│ ├─ ThreeSidesFourDirections
|
||
│ └─ PalaceFortune
|
||
├─ List<MajorLimit>
|
||
│ ├─ limitNumber
|
||
│ ├─ branch
|
||
│ ├─ startAge
|
||
│ ├─ endAge
|
||
│ ├─ palace
|
||
│ └─ luckDescription
|
||
├─ CurrentYear
|
||
│ ├─ year
|
||
│ ├─ branch
|
||
│ ├─ mingGong
|
||
│ └─ luckDescription
|
||
├─ Palace (CurrentMonth)
|
||
├─ Palace (CurrentDay)
|
||
├─ Palace (CurrentHour)
|
||
└─ List<StarPattern>
|
||
```
|
||
|
||
### B. 术语对照表
|
||
|
||
| 中文 | 英文 | 说明 |
|
||
| -------- | --------------------------- | ---------------------- |
|
||
| 命盘 | Chart | 紫微斗数排盘结果 |
|
||
| 宫位 | Palace | 命盘中的十二宫 |
|
||
| 主星 | Major Star | 十四颗主星 |
|
||
| 辅星 | Minor Star | 辅助星曜 |
|
||
| 四化 | Transformation | 化禄、化权、化科、化忌 |
|
||
| 真太阳时 | True Solar Time | 以太阳位置为基准的时间 |
|
||
| 三方四正 | Three Sides Four Directions | 命盘分析的重要方法 |
|
||
| 星曜格局 | Star Pattern | 星曜组合形成的特殊格局 |
|
||
| 大限 | Major Limit | 十年运势周期 |
|
||
| 流年 | Current Year | 年度运势 |
|
||
|
||
---
|
||
|
||
_文档版本:v1.0_
|
||
_最后更新:2025 年 12 月 29 日_
|