feat: 完成工具菜单所有功能

- 后端ToolController实现6个工具API
- 前端创建6个工具页面
- 修改pages.json注册页面
- 修改api.js添加工具API
- 修改tools.vue添加跳转逻辑
This commit is contained in:
H1d3rOne committed 2026-03-08 01:06:24 +08:00
1 parent c85c819008
commit e021ce5bc9
10 files changed
+2292 -14

No files matched your search

@@ -0,0 +1,402 @@
package xuan.controller;
import com.nlf.calendar.Lunar;
import com.nlf.calendar.Solar;
import com.nlf.calendar.LunarYear;
import com.nlf.calendar.LunarMonth;
import org.springframework.web.bind.annotation.*;
import xuan.core.bazi.BaZi;
import xuan.core.bazi.settings.BaZiJiChuSetting;
import java.util.*;
@RestController
@RequestMapping("/api/tools")
public class ToolController {
@PostMapping("/lunar")
public Map<String, Object> lunarQuery(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
String date = params.get("date").toString();
int type = params.containsKey("type") ? Integer.parseInt(params.get("type").toString()) : 0;
Map<String, Object> data = new HashMap<>();
if (type == 0) {
Solar solar = Solar.fromYmdHms(
Integer.parseInt(date.substring(0, 4)),
Integer.parseInt(date.substring(5, 7)),
Integer.parseInt(date.substring(8, 10)),
params.containsKey("hour") ? Integer.parseInt(params.get("hour").toString()) : 0,
params.containsKey("minute") ? Integer.parseInt(params.get("minute").toString()) : 0,
0
);
Lunar lunar = solar.getLunar();
data.put("solar", solar.toString());
data.put("lunar", lunar.toString());
data.put("lunarYear", lunar.getYearInGanZhi());
data.put("lunarMonth", lunar.getMonthInGanZhi());
data.put("lunarDay", lunar.getDayInGanZhi());
data.put("lunarYearName", lunar.getYearShengXiao() + "年");
data.put("lunarMonthName", lunar.getMonthName());
data.put("lunarDayName", lunar.getDayName());
data.put("festival", lunar.getFestivals());
data.put("jieQi", lunar.getJieQi());
data.put("week", solar.getWeekInChinese());
data.put("constellation", solar.getXingZuo());
} else {
int year = Integer.parseInt(params.get("lunarYear").toString());
int month = Integer.parseInt(params.get("lunarMonth").toString());
int day = Integer.parseInt(params.get("lunarDay").toString());
boolean isLeap = params.containsKey("isLeap") && Boolean.parseBoolean(params.get("isLeap").toString());
Lunar lunar = Lunar.fromYmd(year, month, day, isLeap ? 1 : 0);
Solar solar = lunar.getSolar();
data.put("lunar", lunar.toString());
data.put("solar", solar.toString());
data.put("solarYear", solar.getYear());
data.put("solarMonth", solar.getMonth());
data.put("solarDay", solar.getDay());
}
result.put("success", true);
result.put("data", data);
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
@PostMapping("/ganzhi")
public Map<String, Object> ganZhiQuery(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
String date = params.get("date").toString();
int hour = params.containsKey("hour") ? Integer.parseInt(params.get("hour").toString()) : 0;
Solar solar = Solar.fromYmdHms(
Integer.parseInt(date.substring(0, 4)),
Integer.parseInt(date.substring(5, 7)),
Integer.parseInt(date.substring(8, 10)),
hour, 0, 0
);
Lunar lunar = solar.getLunar();
Map<String, Object> data = new HashMap<>();
data.put("yearGanZhi", lunar.getYearInGanZhi());
data.put("monthGanZhi", lunar.getMonthInGanZhi());
data.put("dayGanZhi", lunar.getDayInGanZhi());
data.put("hourGanZhi", lunar.getTimeInGanZhi());
data.put("yearGan", lunar.getYearGan());
data.put("yearZhi", lunar.getYearZhi());
data.put("monthGan", lunar.getMonthGan());
data.put("monthZhi", lunar.getMonthZhi());
data.put("dayGan", lunar.getDayGan());
data.put("dayZhi", lunar.getDayZhi());
data.put("hourGan", lunar.getTimeGan());
data.put("hourZhi", lunar.getTimeZhi());
result.put("success", true);
result.put("data", data);
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
@PostMapping("/shengxiao")
public Map<String, Object> shengXiaoQuery(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
int year = Integer.parseInt(params.get("year").toString());
Solar solar = Solar.fromYmd(year, 1, 1);
Lunar lunar = solar.getLunar();
String shengXiao = lunar.getYearShengXiao();
Map<String, Object> data = new HashMap<>();
data.put("year", year);
data.put("shengXiao", shengXiao);
String[] shengXiaoOrder = {"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"};
Map<String, String> shengXiaoInfo = new HashMap<>();
shengXiaoInfo.put("鼠", "子鼠,五行属水,聪明机智,适应力强");
shengXiaoInfo.put("牛", "丑牛,五行属土,勤劳踏实,责任心强");
shengXiaoInfo.put("虎", "寅虎,五行属木,勇敢自信,领导力强");
shengXiaoInfo.put("兔", "卯兔,五行属木,温柔善良,心思细腻");
shengXiaoInfo.put("龙", "辰龙,五行属土,气宇轩昂,有远大理想");
shengXiaoInfo.put("蛇", "巳蛇,五行属火,智慧深沉,洞察力强");
shengXiaoInfo.put("马", "午马,五行属火,热情奔放,行动力强");
shengXiaoInfo.put("羊", "未羊,五行属土,温文尔雅,富有同情心");
shengXiaoInfo.put("猴", "申猴,五行属金,聪明伶俐,多才多艺");
shengXiaoInfo.put("鸡", "酉鸡,五行属金,精明能干,善于表达");
shengXiaoInfo.put("狗", "戌狗,五行属土,忠诚可靠,正义感强");
shengXiaoInfo.put("猪", "亥猪,五行属水,善良宽厚,乐观豁达");
data.put("info", shengXiaoInfo.getOrDefault(shengXiao, "未知生肖"));
String ganZhi = lunar.getYearInGanZhi();
data.put("ganZhi", ganZhi);
result.put("success", true);
result.put("data", data);
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
@PostMapping("/xingzuo")
public Map<String, Object> xingZuoQuery(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
int month = Integer.parseInt(params.get("month").toString());
int day = Integer.parseInt(params.get("day").toString());
Solar solar = Solar.fromYmd(2000, month, day);
String xingZuo = solar.getXingZuo();
Map<String, Object> data = new HashMap<>();
data.put("month", month);
data.put("day", day);
data.put("xingZuo", xingZuo);
Map<String, Map<String, String>> xingZuoInfo = new HashMap<>();
xingZuoInfo.put("白羊座", Map.of(
"dateRange", "3月21日-4月19日",
"element", "火象星座",
"character", "热情、冲动、自信",
"desc", "白羊座是黄道十二宫的第一宫,代表着新的开始和生命力。白羊座的人充满活力,勇于冒险,具有领导才能。"
));
xingZuoInfo.put("金牛座", Map.of(
"dateRange", "4月20日-5月20日",
"element", "土象星座",
"character", "稳重、务实、固执",
"desc", "金牛座是黄道十二宫的第二宫,代表着物质和财富。金牛座的人踏实可靠,追求稳定,有很强的耐心。"
));
xingZuoInfo.put("双子座", Map.of(
"dateRange", "5月21日-6月21日",
"element", "风象星座",
"character", "聪明、善变、好奇",
"desc", "双子座是黄道十二宫的第三宫,代表着沟通和交流。双子座的人思维敏捷,善于表达,兴趣广泛。"
));
xingZuoInfo.put("巨蟹座", Map.of(
"dateRange", "6月22日-7月22日",
"element", "水象星座",
"character", "敏感、顾家、情绪化",
"desc", "巨蟹座是黄道十二宫的第四宫,代表着家庭和情感。巨蟹座的人重视家庭,情感丰富,有很强的保护欲。"
));
xingZuoInfo.put("狮子座", Map.of(
"dateRange", "7月23日-8月22日",
"element", "火象星座",
"character", "自信、慷慨、霸道",
"desc", "狮子座是黄道十二宫的第五宫,代表着创造力和自我表达。狮子座的人自信大方,有领导才能,喜欢成为焦点。"
));
xingZuoInfo.put("处女座", Map.of(
"dateRange", "8月23日-9月22日",
"element", "土象星座",
"character", "细心、完美主义、挑剔",
"desc", "处女座是黄道十二宫的第六宫,代表着分析和服务。处女座的人注重细节,追求完美,有很强的分析能力。"
));
xingZuoInfo.put("天秤座", Map.of(
"dateRange", "9月23日-10月23日",
"element", "风象星座",
"character", "优雅、公正、犹豫",
"desc", "天秤座是黄道十二宫的第七宫,代表着平衡和和谐。天秤座的人追求公正,善于社交,有很强的审美能力。"
));
xingZuoInfo.put("天蝎座", Map.of(
"dateRange", "10月24日-11月22日",
"element", "水象星座",
"character", "神秘、执着、多疑",
"desc", "天蝎座是黄道十二宫的第八宫,代表着转化和重生。天蝎座的人意志坚定,洞察力强,有很强的直觉。"
));
xingZuoInfo.put("射手座", Map.of(
"dateRange", "11月23日-12月21日",
"element", "火象星座",
"character", "乐观、自由、粗心",
"desc", "射手座是黄道十二宫的第九宫,代表着探索和哲学。射手座的人热爱自由,乐观开朗,有很强的冒险精神。"
));
xingZuoInfo.put("摩羯座", Map.of(
"dateRange", "12月22日-1月19日",
"element", "土象星座",
"character", "务实、有责任感、悲观",
"desc", "摩羯座是黄道十二宫的第十宫,代表着成就和责任。摩羯座的人有很强的责任感,追求成功,脚踏实地。"
));
xingZuoInfo.put("水瓶座", Map.of(
"dateRange", "1月20日-2月18日",
"element", "风象星座",
"character", "独立、创新、叛逆",
"desc", "水瓶座是黄道十二宫的第十一宫,代表着创新和人道主义。水瓶座的人思想前卫,独立自主,有很强的创造力。"
));
xingZuoInfo.put("双鱼座", Map.of(
"dateRange", "2月19日-3月20日",
"element", "水象星座",
"character", "浪漫、敏感、优柔寡断",
"desc", "双鱼座是黄道十二宫的最后一宫,代表着灵性和直觉。双鱼座的人富有想象力,感情丰富,有很强的同理心。"
));
Map<String, String> info = xingZuoInfo.getOrDefault(xingZuo, Map.of("desc", "未知星座"));
data.put("dateRange", info.get("dateRange"));
data.put("element", info.get("element"));
data.put("character", info.get("character"));
data.put("desc", info.get("desc"));
result.put("success", true);
result.put("data", data);
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
@PostMapping("/wuxing")
public Map<String, Object> wuXingQuery(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
String date = params.get("date").toString();
int hour = params.containsKey("hour") ? Integer.parseInt(params.get("hour").toString()) : 0;
Solar solar = Solar.fromYmdHms(
Integer.parseInt(date.substring(0, 4)),
Integer.parseInt(date.substring(5, 7)),
Integer.parseInt(date.substring(8, 10)),
hour, 0, 0
);
Lunar lunar = solar.getLunar();
String yearGan = lunar.getYearGan();
String monthGan = lunar.getMonthGan();
String dayGan = lunar.getDayGan();
String hourGan = lunar.getTimeGan();
Map<String, String> ganWuXing = new HashMap<>();
ganWuXing.put("甲", "木"); ganWuXing.put("乙", "木");
ganWuXing.put("丙", "火"); ganWuXing.put("丁", "火");
ganWuXing.put("戊", "土"); ganWuXing.put("己", "土");
ganWuXing.put("庚", "金"); ganWuXing.put("辛", "金");
ganWuXing.put("壬", "水"); ganWuXing.put("癸", "水");
Map<String, Object> data = new HashMap<>();
data.put("yearGan", yearGan);
data.put("yearWuXing", ganWuXing.get(yearGan));
data.put("monthGan", monthGan);
data.put("monthWuXing", ganWuXing.get(monthGan));
data.put("dayGan", dayGan);
data.put("dayWuXing", ganWuXing.get(dayGan));
data.put("hourGan", hourGan);
data.put("hourWuXing", ganWuXing.get(hourGan));
Map<String, Integer> wuXingCount = new HashMap<>();
wuXingCount.put("金", 0);
wuXingCount.put("木", 0);
wuXingCount.put("水", 0);
wuXingCount.put("火", 0);
wuXingCount.put("土", 0);
for (String gan : Arrays.asList(yearGan, monthGan, dayGan, hourGan)) {
String wx = ganWuXing.get(gan);
wuXingCount.put(wx, wuXingCount.get(wx) + 1);
}
String[] zhiList = {lunar.getYearZhi(), lunar.getMonthZhi(), lunar.getDayZhi(), lunar.getTimeZhi()};
Map<String, String> zhiWuXing = new HashMap<>();
zhiWuXing.put("子", "水"); zhiWuXing.put("丑", "土");
zhiWuXing.put("寅", "木"); zhiWuXing.put("卯", "木");
zhiWuXing.put("辰", "土"); zhiWuXing.put("巳", "火");
zhiWuXing.put("午", "火"); zhiWuXing.put("未", "土");
zhiWuXing.put("申", "金"); zhiWuXing.put("酉", "金");
zhiWuXing.put("戌", "土"); zhiWuXing.put("亥", "水");
for (String zhi : zhiList) {
String wx = zhiWuXing.get(zhi);
wuXingCount.put(wx, wuXingCount.get(wx) + 1);
}
data.put("wuXingCount", wuXingCount);
List<String> missing = new ArrayList<>();
for (Map.Entry<String, Integer> entry : wuXingCount.entrySet()) {
if (entry.getValue() == 0) {
missing.add(entry.getKey());
}
}
data.put("missing", missing);
Map<String, String> wuXingInfo = new HashMap<>();
wuXingInfo.put("金", "金主义,其性刚,其情烈。金盛之人骨肉相称,面方白净,眉高眼深。");
wuXingInfo.put("木", "木主仁,其性直,其情和。木盛之人丰姿秀丽,骨骼修长,手足细腻。");
wuXingInfo.put("水", "水主智,其性聪,其情善。水盛之人面黑有采,语言清和,为人深思熟虑。");
wuXingInfo.put("火", "火主礼,其性急,其情恭。火盛之人头小脚长,上尖下阔,浓眉小耳。");
wuXingInfo.put("土", "土主信,其性重,其情厚。土盛之人圆腰廓鼻,眉清目秀,口才声重。");
data.put("wuXingInfo", wuXingInfo);
result.put("success", true);
result.put("data", data);
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
@PostMapping("/jiri")
public Map<String, Object> jiRiQuery(@RequestBody Map<String, Object> params) {
Map<String, Object> result = new HashMap<>();
try {
String date = params.get("date").toString();
Solar solar = Solar.fromYmd(
Integer.parseInt(date.substring(0, 4)),
Integer.parseInt(date.substring(5, 7)),
Integer.parseInt(date.substring(8, 10))
);
Lunar lunar = solar.getLunar();
Map<String, Object> data = new HashMap<>();
data.put("solar", solar.toString());
data.put("lunar", lunar.toString());
data.put("ganZhi", lunar.getDayInGanZhi());
data.put("xingZuo", solar.getXingZuo());
data.put("week", solar.getWeekInChinese());
List<String> yi = lunar.getDayYi();
List<String> ji = lunar.getDayJi();
data.put("yi", yi);
data.put("ji", ji);
String[] chong = lunar.getDayChong().split(" ");
data.put("chong", chong.length > 0 ? chong[0] : "");
data.put("chongGan", lunar.getDayChongGan());
data.put("chongZhi", lunar.getDayChongZhi());
data.put("sha", lunar.getDaySha());
String jieQi = lunar.getJieQi();
data.put("jieQi", jieQi != null ? jieQi : "无");
List<String> festivals = lunar.getFestivals();
data.put("festivals", festivals);
List<String> solarFestivals = solar.getFestivals();
data.put("solarFestivals", solarFestivals);
boolean isGoodDay = yi.size() > ji.size();
data.put("isGoodDay", isGoodDay);
data.put("suggestion", isGoodDay ? "今日宜多行善事,适合办理重要事务" : "今日宜静不宜动,适合修身养性");
result.put("success", true);
result.put("data", data);
} catch (Exception e) {
result.put("success", false);
result.put("error", e.getMessage());
}
return result;
}
}