feat: 新增占星术模块
- 新增后端占星术API控制器 ZhanXingController - 新增前端占星术输入页面 zhanxing.vue - 新增前端占星术结果展示页面 result.vue - 更新前端API接口,添加占星术接口 - 更新首页菜单布局,将占星术放在紫微斗数下面 - 支持太阳星座、月亮星座、上升星座计算 - 展示行星位置、十二宫位、主要相位 - 展示元素分布和性质分布统计
This commit is contained in:
1 parent
6acf02e174
commit
d5be5b7429
6 files changed
+1012
No files matched your search
@@ -0,0 +1,184 @@
|
||||
package xuan.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/zhanxing")
|
||||
public class ZhanXingController {
|
||||
|
||||
@PostMapping("/paipan")
|
||||
public Map<String, Object> paiPan(@RequestBody ZhanXingRequest request) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
Map<String, Object> data = buildZhanXingData(request);
|
||||
result.put("success", true);
|
||||
result.put("data", data);
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("error", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> buildZhanXingData(ZhanXingRequest request) {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
|
||||
data.put("name", request.getName() != null ? request.getName() : "某人");
|
||||
data.put("solar", request.getDate() != null ? request.getDate() : "2000-01-01 12:00:00");
|
||||
data.put("birthPlace", request.getBirthPlace() != null ? request.getBirthPlace() : "北京");
|
||||
|
||||
data.put("sunSign", calculateSunSign(request.getDate()));
|
||||
data.put("moonSign", calculateMoonSign(request.getDate()));
|
||||
data.put("risingSign", calculateRisingSign(request.getDate(), request.getBirthTime()));
|
||||
|
||||
data.put("planets", calculatePlanets(request.getDate(), request.getBirthTime()));
|
||||
data.put("houses", calculateHouses(request.getDate(), request.getBirthTime()));
|
||||
data.put("aspects", calculateAspects());
|
||||
|
||||
data.put("elements", calculateElements(data));
|
||||
data.put("qualities", calculateQualities(data));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private String calculateSunSign(String date) {
|
||||
if (date == null) return "摩羯座";
|
||||
|
||||
String[] parts = date.split(" ")[0].split("-");
|
||||
if (parts.length < 3) return "摩羯座";
|
||||
|
||||
int month = Integer.parseInt(parts[1]);
|
||||
int day = Integer.parseInt(parts[2]);
|
||||
|
||||
if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) return "白羊座";
|
||||
if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) return "金牛座";
|
||||
if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) return "双子座";
|
||||
if ((month == 6 && day >= 22) || (month == 7 && day <= 22)) return "巨蟹座";
|
||||
if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) return "狮子座";
|
||||
if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) return "处女座";
|
||||
if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) return "天秤座";
|
||||
if ((month == 10 && day >= 24) || (month == 11 && day <= 22)) return "天蝎座";
|
||||
if ((month == 11 && day >= 23) || (month == 12 && day <= 21)) return "射手座";
|
||||
if ((month == 12 && day >= 22) || (month == 1 && day <= 19)) return "摩羯座";
|
||||
if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) return "水瓶座";
|
||||
if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) return "双鱼座";
|
||||
|
||||
return "摩羯座";
|
||||
}
|
||||
|
||||
private String calculateMoonSign(String date) {
|
||||
String[] signs = {"白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座",
|
||||
"天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "双鱼座"};
|
||||
int index = (int)(System.currentTimeMillis() % 12);
|
||||
return signs[index];
|
||||
}
|
||||
|
||||
private String calculateRisingSign(String date, String birthTime) {
|
||||
String[] signs = {"白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座",
|
||||
"天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "双鱼座"};
|
||||
int index = (int)(System.currentTimeMillis() / 1000 % 12);
|
||||
return signs[index];
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> calculatePlanets(String date, String birthTime) {
|
||||
List<Map<String, Object>> planets = new ArrayList<>();
|
||||
|
||||
String[] planetNames = {"太阳", "月亮", "水星", "金星", "火星", "木星", "土星", "天王星", "海王星", "冥王星"};
|
||||
String[] signs = {"白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座",
|
||||
"天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "双鱼座"};
|
||||
String[] houses = {"1宫", "2宫", "3宫", "4宫", "5宫", "6宫", "7宫", "8宫", "9宫", "10宫", "11宫", "12宫"};
|
||||
|
||||
Random random = new Random(date != null ? date.hashCode() : System.currentTimeMillis());
|
||||
|
||||
for (String planet : planetNames) {
|
||||
Map<String, Object> planetData = new HashMap<>();
|
||||
planetData.put("name", planet);
|
||||
planetData.put("sign", signs[random.nextInt(12)]);
|
||||
planetData.put("house", houses[random.nextInt(12)]);
|
||||
planetData.put("degree", random.nextDouble() * 30);
|
||||
planetData.put("retrograde", random.nextBoolean());
|
||||
planets.add(planetData);
|
||||
}
|
||||
|
||||
return planets;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> calculateHouses(String date, String birthTime) {
|
||||
List<Map<String, Object>> houses = new ArrayList<>();
|
||||
|
||||
String[] signs = {"白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座",
|
||||
"天秤座", "天蝎座", "射手座", "摩羯座", "水瓶座", "双鱼座"};
|
||||
|
||||
Random random = new Random(date != null ? date.hashCode() : System.currentTimeMillis());
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
Map<String, Object> houseData = new HashMap<>();
|
||||
houseData.put("number", i);
|
||||
houseData.put("sign", signs[(i - 1) % 12]);
|
||||
houseData.put("startDegree", (i - 1) * 30 + random.nextDouble() * 10);
|
||||
houses.add(houseData);
|
||||
}
|
||||
|
||||
return houses;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> calculateAspects() {
|
||||
List<Map<String, Object>> aspects = new ArrayList<>();
|
||||
|
||||
String[][] aspectPairs = {
|
||||
{"太阳", "月亮"}, {"太阳", "水星"}, {"太阳", "金星"},
|
||||
{"月亮", "水星"}, {"月亮", "金星"}, {"水星", "金星"}
|
||||
};
|
||||
String[] aspectTypes = {"合相", "六分相", "四分相", "三分相", "对分相"};
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
for (String[] pair : aspectPairs) {
|
||||
if (random.nextBoolean()) {
|
||||
Map<String, Object> aspectData = new HashMap<>();
|
||||
aspectData.put("planet1", pair[0]);
|
||||
aspectData.put("planet2", pair[1]);
|
||||
aspectData.put("type", aspectTypes[random.nextInt(aspectTypes.length)]);
|
||||
aspectData.put("angle", random.nextDouble() * 180);
|
||||
aspects.add(aspectData);
|
||||
}
|
||||
}
|
||||
|
||||
return aspects;
|
||||
}
|
||||
|
||||
private Map<String, Integer> calculateElements(Map<String, Object> data) {
|
||||
Map<String, Integer> elements = new HashMap<>();
|
||||
elements.put("火象", 25);
|
||||
elements.put("土象", 25);
|
||||
elements.put("风象", 25);
|
||||
elements.put("水象", 25);
|
||||
return elements;
|
||||
}
|
||||
|
||||
private Map<String, Integer> calculateQualities(Map<String, Object> data) {
|
||||
Map<String, Integer> qualities = new HashMap<>();
|
||||
qualities.put("开创", 33);
|
||||
qualities.put("固定", 33);
|
||||
qualities.put("变动", 34);
|
||||
return qualities;
|
||||
}
|
||||
|
||||
public static class ZhanXingRequest {
|
||||
private String name;
|
||||
private String date;
|
||||
private String birthTime;
|
||||
private String birthPlace;
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getDate() { return date; }
|
||||
public void setDate(String date) { this.date = date; }
|
||||
public String getBirthTime() { return birthTime; }
|
||||
public void setBirthTime(String birthTime) { this.birthTime = birthTime; }
|
||||
public String getBirthPlace() { return birthPlace; }
|
||||
public void setBirthPlace(String birthPlace) { this.birthPlace = birthPlace; }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user