From e40264147af2a798e585c4e17c66e2055b071c70 Mon Sep 17 00:00:00 2001 From: wangjinlei <751475802@qq.com> Date: Fri, 10 Nov 2023 18:11:58 +0800 Subject: [PATCH] bug --- .../com/peanut/common/utils/MyCalendar.java | 121 +++++++++++++++++ .../book/controller/PointController.java | 4 +- .../modules/book/service/PointService.java | 2 +- .../book/service/impl/PointServiceImpl.java | 126 +++++------------- 4 files changed, 156 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/peanut/common/utils/MyCalendar.java b/src/main/java/com/peanut/common/utils/MyCalendar.java index ca56e61e..830dcc81 100644 --- a/src/main/java/com/peanut/common/utils/MyCalendar.java +++ b/src/main/java/com/peanut/common/utils/MyCalendar.java @@ -25,6 +25,77 @@ public class MyCalendar { private int chinesemonth;// 农历月份 private int chineseday;// 农历日 private boolean leap;// 判断闰月 + + private int tgchineseyear;//天干地支年份 + + private int tgchinesemonth;//天干地址月份 + + + public int getTgchineseyear() { + return tgchineseyear; + } + + public void setTgchineseyear(int tgchineseyear) { + this.tgchineseyear = tgchineseyear; + } + + public int getTgchinesemonth() { + return tgchinesemonth; + } + + public void setTgchinesemonth(int tgchinesemonth) { + this.tgchinesemonth = tgchinesemonth; + } + + public void setDate(Date date){ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + Integer year = calendar.get(Calendar.YEAR); + int kkk = calendar.get(Calendar.MONTH); + + Integer month = kkk + 1; + Integer day = calendar.get(Calendar.DAY_OF_MONTH); + this.setyear(year); + this.setmonth(month); + this.getfirstday(day); + } + + public Map getCT(){ + Integer c_year = Integer.valueOf(this.getChineseyear()); + Integer c_month = Integer.valueOf(this.getChinesemonth()); + Integer c_day = (Integer.valueOf(this.getChineseday()))+1; + Map stringIntegerMap = new HashMap<>(); + stringIntegerMap.put("year",c_year); + stringIntegerMap.put("month",c_month); + stringIntegerMap.put("day",c_day); + return stringIntegerMap; + } + + + public int getChineseyear() { + return chineseyear; + } + + public void setChineseyear(int chineseyear) { + this.chineseyear = chineseyear; + } + + public int getChinesemonth() { + return chinesemonth; + } + + public void setChinesemonth(int chinesemonth) { + this.chinesemonth = chinesemonth; + } + + public int getChineseday() { + return chineseday; + } + + public void setChineseday(int chineseday) { + this.chineseday = chineseday; + } + // 1-4: 表示当年有无闰年,有的话,为闰月的月份,没有的话,为0。 // 5-16:为除了闰月外的正常月份是大月还是小月,1为30天,0为29天。 // 注意:从1月到12月对应的是第16位到第5位。 @@ -174,6 +245,14 @@ public class MyCalendar { } this.chinesemonth = lmonth; this.chineseday = offset; + + //添加天干地支时间校正 + if(!checkLC()){ + setTgchineseyear(this.chineseyear-1); + }else{ + setTgchineseyear(this.chineseyear); + } + } // 返回日期数组的空数据个数,即1号所在行中有多少个空位置 @@ -342,6 +421,48 @@ public class MyCalendar { return days; } + //判断是否过了立春 + public boolean checkLC(){ + int getmonth = getmonth(); + if(getmonth<2){//立春在2月所以1月立春还没到 + return false; + } + if(getmonth>2){//2月以上立春肯定是过了 + return true; + } + double D = 0.2422; + // "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", + // "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", + // "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" + // 定义数组,存储的是20世纪和21世纪的节气C值 + double[] SolarTerms_C_20thcentury = { 6.11, 20.84, 4.6295, 19.4599, 6.3826, 21.4155, 5.59, 20.888, 6.318, 21.86, + 6.5, 22.2, 7.928, 23.65, 8.35, 23.95, 8.44, 23.822, 9.098, 24.218, 8.218, 23.08, 7.9, 22.6 }; + double[] SolarTerms_C_21stcentury = { 5.4055, 20.12, 3.87, 18.73, 5.63, 20.646, 4.81, 20.1, 5.52, 21.04, 5.678, + 21.37, 7.108, 22.83, 7.5, 23.13, 7.646, 23.042, 8.318, 23.438, 7.438, 22.36, 7.18, 21.94 }; + double[] SolarTerms_C = null; + if (year >= 1901 && year <= 2000) {// 20世纪 + SolarTerms_C = SolarTerms_C_20thcentury; + } else if (year >= 2001 && year <= 2100) {// 21世纪 + SolarTerms_C = SolarTerms_C_21stcentury; + } + double C1 = SolarTerms_C[(month) * 2 - 1 - 1]; + int Y = year % 100; + int L = (Y) / 4; + if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { + // 注意:凡闰年3月1日前闰年数要减一,即:L=[(Y-1)/4],因为小寒、大寒、立春、雨水这两个节气都小于3月1日 + if (C1 == 5.4055 || C1 == 3.87) { + L = (Y - 1) / 4; + } + } + int num1 = (int) ((Y * D + C1) - L); + if(month stringStringMap = pointService.TGDZForYear(parse); + return R.ok().put("tgdz",stringStringMap); } } diff --git a/src/main/java/com/peanut/modules/book/service/PointService.java b/src/main/java/com/peanut/modules/book/service/PointService.java index 7c4739d1..d7334519 100644 --- a/src/main/java/com/peanut/modules/book/service/PointService.java +++ b/src/main/java/com/peanut/modules/book/service/PointService.java @@ -17,5 +17,5 @@ public interface PointService extends IService { List searchPoint(String keywords); - String[] TGDZForYear(Date year); + Map TGDZForYear(Date year); } diff --git a/src/main/java/com/peanut/modules/book/service/impl/PointServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/PointServiceImpl.java index 38613f7d..c3a591d1 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/PointServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/PointServiceImpl.java @@ -66,103 +66,38 @@ public class PointServiceImpl extends ServiceImpl impleme } @Override - public String[] TGDZForYear(Date date) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - Integer year = calendar.get(Calendar.YEAR); - int kkk = calendar.get(Calendar.MONTH); - Integer month = kkk + 1; - Integer day = calendar.get(Calendar.DAY_OF_MONTH); - MyCalendar mc = new MyCalendar(); - mc.setyear(year); - mc.setmonth(month); - mc.getfirstday(day); - - System.out.println(mc.getChinaYearString()); - System.out.println(mc.getChinaMonthString()); - System.out.println(mc.getCalendar().toString()); - - -// String[] day = mc.getCalendar();// 阳历日期 -// String[] chineseday = mc.getchineseCalendar_festival_solarterms();// 农历日期 - - // 以下为输出 -// System.out.println(mc.getyear() + "年" + mc.getmonth() + "月"); -// System.out.println(); -// String[] week = {"日", "一", "二", "三", "四", "五", "六"}; -// for (String str : week) { -// System.out.printf("%-7s", " " + str); -// } -// System.out.println(); -// ArrayList listYl = new ArrayList<>(); -// ArrayList listNl = new ArrayList<>(); -// boolean bool = false; -// int n = 0; -// for (int i = 0; i < day.length; i++) { -// System.out.printf("%-5s", " " + day[i]); -// listYl.add(day[i]); -// n++; -// if (n == 7) { -// System.out.println(); -// int k = mc.getweekDay(); -// for (int j = 0; j < k; j++) { -// System.out.printf("%9s", ""); -// listNl.add(""); -// } -// for (int j = k; j < 7; j++) { -// System.out.printf("%4s", chineseday[j]); -// listNl.add(chineseday[j]); -// } -// System.out.println(); -// } -// -// -// if (n % 7 == 0 && n != 7) { -// System.out.println(); -// bool = true; -// } -// if (bool == true) { -// for (int j = (n - 7); j < n; j++) { -// System.out.printf("%4s", chineseday[j]); -// listNl.add(chineseday[j]); -// } -// if (n != day.length) { -// System.out.println(); -// } -// bool = false; -// } -// if (n == day.length && n % 7 != 0) { -// System.out.println(); -// for (int j = (n - n % 7); j < n; j++) { -// System.out.printf("%4s", chineseday[j]); -// listNl.add(chineseday[j]); -// } -// } -// } -// System.out.println(); -// System.out.println(listYl); -// System.out.println(listNl); -// ArrayList list = new ArrayList<>(); -// for (int k = 0; k < listYl.size(); k++) { -// JSONObject jsonObject = new JSONObject(); -// if (listYl.get(k) == "") { -// jsonObject.put("yl", ""); -// jsonObject.put("nl", ""); -// } else { -// jsonObject.put("yl", listYl.get(k)); -// jsonObject.put("nl", listNl.get(k)); -// } -// list.add(jsonObject); -// } -// System.out.println(list); + public Map TGDZForYear(Date date) { + MyCalendar myCalendar = new MyCalendar(); + myCalendar.setDate(date); + Map ct = myCalendar.getCT(); + System.out.println(ct); + System.out.println(Arrays.toString(myCalendar.getchineseCalendar_festival_solarterms())); + Integer year = ct.get("year"); + Integer month = ct.get("month"); + Integer day = ct.get("day"); - String[] strings = mc.getchineseCalendar_festival_solarterms(); - return strings; -// Integer day = calendar.get(Calendar.DAY_OF_MONTH); -// String[] tg = TGDZ.tg; -// String[] dz = TGDZ.dz; + String[] tg = TGDZ.tg; + String[] dz = TGDZ.dz; + + //年份天干地支 + String c_year = myCalendar.getChinaYearString(); + + //月份天干地支 + Integer ty_c = year%10; + Integer ty = ty_c<=3?ty_c+10-3:ty_c-3; + Integer tm = ((ty*2 +month)%10)==0?10:((ty*2 +month)%10); + String c_month = tg[tm-1]+dz[month-1]; + + HashMap flagMap = new HashMap<>(); + flagMap.put("year",c_year); + flagMap.put("month",c_month); + + + + return flagMap; + // Integer y = year % 10; // if(y<=3){ // y += 10; @@ -178,6 +113,9 @@ public class PointServiceImpl extends ServiceImpl impleme // String y_d = dz[month-1]; // // return s+s1+"年 "+y_s+y_d+"月 "; + + +// return null; } private void createIds(Integer id, List list){