package xuan.controller; import org.springframework.web.bind.annotation.*; import xuan.core.bazi.BaZi; import xuan.core.bazi.settings.BaZiJiChuSetting; import xuan.core.bazi.settings.BaZiShenShaSetting; import xuan.core.bazi.settings.BaZiGanZhiLiuYiSetting; import java.util.HashMap; import java.util.Map; @RestController @RequestMapping("/api/bazi") public class BaZiController { @PostMapping("/paipan") public Map paiPan(@RequestBody BaZiRequest request) { Map result = new HashMap<>(); try { BaZiJiChuSetting setting = new BaZiJiChuSetting(); setting.setName(request.getName() != null ? request.getName() : "某人"); setting.setOccupy(request.getOccupy() != null ? request.getOccupy() : "某事"); setting.setSex(request.getSex() != null ? request.getSex() : 1); setting.setDate(request.getDate() != null ? request.getDate() : "2024-01-01 00:00:00"); setting.setDateType(request.getDateType() != null ? request.getDateType() : 0); setting.setLeapMonthType(request.getLeapMonthType() != null ? request.getLeapMonthType() : 0); setting.setXuShiSuiType(request.getXuShiSuiType() != null ? request.getXuShiSuiType() : 0); setting.setJieQiType(request.getJieQiType() != null ? request.getJieQiType() : 1); setting.setQiYunLiuPaiType(request.getQiYunLiuPaiType() != null ? request.getQiYunLiuPaiType() : 0); setting.setRenYuanType(request.getRenYuanType() != null ? request.getRenYuanType() : 0); setting.setDaYunLunShu(request.getDaYunLunShu() != null ? request.getDaYunLunShu() : 10); setting.setYearGanZhiType(request.getYearGanZhiType() != null ? request.getYearGanZhiType() : 2); setting.setMonthGanZhiType(request.getMonthGanZhiType() != null ? request.getMonthGanZhiType() : 1); setting.setDayGanZhiType(request.getDayGanZhiType() != null ? request.getDayGanZhiType() : 0); BaZi baZi = new BaZi(setting); baZi.baZiShenShaSetting(new BaZiShenShaSetting()); baZi.baZiGanZhiLiuYiSetting(new BaZiGanZhiLiuYiSetting()); result.put("success", true); result.put("data", buildBaZiData(baZi)); } catch (Exception e) { result.put("success", false); result.put("error", e.getMessage()); } return result; } private Map buildBaZiData(BaZi baZi) { Map data = new HashMap<>(); data.put("name", baZi.getName()); data.put("sex", baZi.getSex()); data.put("age", baZi.getAge()); data.put("solar", baZi.getSolarStr2()); data.put("lunar", baZi.getLunarStr2()); data.put("xingQi", baZi.getXingQi()); data.put("jiJie", baZi.getJiJie()); data.put("shengXiao", baZi.getShengXiao()); data.put("xingZuo", baZi.getXingZuo()); data.put("baZi", baZi.getBaZi()); data.put("baZiWuXing", baZi.getBaZiWuXing()); data.put("baZiNaYin", baZi.getBaZiNaYin()); data.put("baZiKongWang", baZi.getBaZiKongWang()); data.put("yearGanZhi", baZi.getYearGanZhi()); data.put("monthGanZhi", baZi.getMonthGanZhi()); data.put("dayGanZhi", baZi.getDayGanZhi()); data.put("hourGanZhi", baZi.getHourGanZhi()); data.put("taiYuanGanZhi", baZi.getTaiYuanGanZhi()); data.put("taiXiGanZhi", baZi.getTaiXiGanZhi()); data.put("mingGongGanZhi", baZi.getMingGongGanZhi()); data.put("shenGongGanZhi", baZi.getShenGongGanZhi()); data.put("wuXingWangShuai", baZi.getWuXingWangShuai()); data.put("wuXingQueShi", baZi.getWuXingQueShi()); data.put("xiYongShen", baZi.getXiYongShen()); data.put("tianGanLiuYi", baZi.getTianGanLiuYi()); data.put("diZhiLiuYi", baZi.getDiZhiLiuYi()); data.put("yearGanZhiShenSha", baZi.getYearGanZhiShenSha()); data.put("monthGanZhiShenSha", baZi.getMonthGanZhiShenSha()); data.put("dayGanZhiShenSha", baZi.getDayGanZhiShenSha()); data.put("hourGanZhiShenSha", baZi.getHourGanZhiShenSha()); return data; } public static class BaZiRequest { private String name; private String occupy; private Integer sex; private String date; private Integer dateType; private Integer leapMonthType; private Integer xuShiSuiType; private Integer jieQiType; private Integer qiYunLiuPaiType; private Integer renYuanType; private Integer daYunLunShu; private Integer yearGanZhiType; private Integer monthGanZhiType; private Integer dayGanZhiType; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getOccupy() { return occupy; } public void setOccupy(String occupy) { this.occupy = occupy; } public Integer getSex() { return sex; } public void setSex(Integer sex) { this.sex = sex; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public Integer getDateType() { return dateType; } public void setDateType(Integer dateType) { this.dateType = dateType; } public Integer getLeapMonthType() { return leapMonthType; } public void setLeapMonthType(Integer leapMonthType) { this.leapMonthType = leapMonthType; } public Integer getXuShiSuiType() { return xuShiSuiType; } public void setXuShiSuiType(Integer xuShiSuiType) { this.xuShiSuiType = xuShiSuiType; } public Integer getJieQiType() { return jieQiType; } public void setJieQiType(Integer jieQiType) { this.jieQiType = jieQiType; } public Integer getQiYunLiuPaiType() { return qiYunLiuPaiType; } public void setQiYunLiuPaiType(Integer qiYunLiuPaiType) { this.qiYunLiuPaiType = qiYunLiuPaiType; } public Integer getRenYuanType() { return renYuanType; } public void setRenYuanType(Integer renYuanType) { this.renYuanType = renYuanType; } public Integer getDaYunLunShu() { return daYunLunShu; } public void setDaYunLunShu(Integer daYunLunShu) { this.daYunLunShu = daYunLunShu; } public Integer getYearGanZhiType() { return yearGanZhiType; } public void setYearGanZhiType(Integer yearGanZhiType) { this.yearGanZhiType = yearGanZhiType; } public Integer getMonthGanZhiType() { return monthGanZhiType; } public void setMonthGanZhiType(Integer monthGanZhiType) { this.monthGanZhiType = monthGanZhiType; } public Integer getDayGanZhiType() { return dayGanZhiType; } public void setDayGanZhiType(Integer dayGanZhiType) { this.dayGanZhiType = dayGanZhiType; } } }