天干地支
This commit is contained in:
@@ -180,7 +180,7 @@ public class PointController {
|
||||
Date parse = simpleDateFormat.parse(date);
|
||||
|
||||
|
||||
Map<String, String> stringStringMap = pointService.TGDZForYear(parse);
|
||||
Map<String, String> stringStringMap = pointService.TGDZForDate(parse);
|
||||
return R.ok().put("tgdz",stringStringMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@ public interface PointService extends IService<PointEntity> {
|
||||
|
||||
List<PointEntity> searchPoint(String keywords);
|
||||
|
||||
Map<String,String> TGDZForYear(Date year);
|
||||
Map<String,String> TGDZForDate(Date date);
|
||||
}
|
||||
|
||||
@@ -66,56 +66,75 @@ public class PointServiceImpl extends ServiceImpl<PointDao, PointEntity> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,String> TGDZForYear(Date date) {
|
||||
public Map<String,String> TGDZForDate(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);
|
||||
Integer hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
|
||||
System.out.println(hour);
|
||||
MyCalendar myCalendar = new MyCalendar();
|
||||
myCalendar.setDate(date);
|
||||
Map<String, Integer> 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");
|
||||
|
||||
Integer tg_year = ct.get("tg_year");
|
||||
Integer tg_month = ct.get("tg_month");
|
||||
// Integer day = ct.get("c_day");
|
||||
|
||||
|
||||
String[] tg = TGDZ.tg;
|
||||
String[] dz = TGDZ.dz;
|
||||
String[] dzz = TGDZ.dzz;
|
||||
|
||||
//年份天干地支
|
||||
String c_year = myCalendar.getChinaYearString();
|
||||
Integer ty_c = tg_year%10;
|
||||
Integer ty = ty_c<=3?ty_c+10-3:ty_c-3;
|
||||
String c_year_t = tg[ty-1];
|
||||
Integer d = (tg_year+7)%12;
|
||||
if(d==0){
|
||||
d=12;
|
||||
}
|
||||
String c_year_d = dz[d - 1];
|
||||
String c_year = c_year_t+c_year_d;
|
||||
|
||||
//月份天干地支
|
||||
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];
|
||||
Integer tm = ((ty*2 +tg_month)%10)==0?10:((ty*2 +tg_month)%10);
|
||||
String c_month = tg[tm-1]+dz[tg_month-1];
|
||||
|
||||
HashMap<String, String> flagMap = new HashMap<>();
|
||||
flagMap.put("year",c_year);
|
||||
flagMap.put("month",c_month);
|
||||
|
||||
//获取日干支
|
||||
String dayGZ = getDayGZ(year, month, day);
|
||||
flagMap.put("day",dayGZ);
|
||||
|
||||
|
||||
//获取时干支,时天干=日天干×2+时地支-2(因为天干有十个,所以计算出来的数字如果大于10,就要减去10)
|
||||
String substring = dayGZ.substring(0, 1);
|
||||
List<String> list = Arrays.asList(tg);
|
||||
int i = list.indexOf(substring);
|
||||
int s_d;
|
||||
if(hour==23){
|
||||
s_d = 1;
|
||||
}else{
|
||||
if(hour%2==0){
|
||||
s_d = (hour+2)/2;
|
||||
}else {
|
||||
s_d = (hour+3)/2;
|
||||
}
|
||||
}
|
||||
int dd = ((i+1)*2+s_d-2)%10;
|
||||
int dcc;
|
||||
if(dd==0){
|
||||
dcc=9;
|
||||
}else{
|
||||
dcc = dd-1;
|
||||
}
|
||||
flagMap.put("hour",tg[dcc]+dzz[s_d-1]);
|
||||
return flagMap;
|
||||
|
||||
// Integer y = year % 10;
|
||||
// if(y<=3){
|
||||
// y += 10;
|
||||
// }
|
||||
// String s = tg[y-3-1];
|
||||
// Integer d = (year+7)%12;
|
||||
// if(d==0){
|
||||
// d=12;
|
||||
// }
|
||||
// String s1 = dz[d - 1];
|
||||
// //月干
|
||||
// String y_s = tg[(((y - 3) * 2 + month)%10) - 1];
|
||||
// String y_d = dz[month-1];
|
||||
//
|
||||
// return s+s1+"年 "+y_s+y_d+"月 ";
|
||||
|
||||
|
||||
// return null;
|
||||
}
|
||||
|
||||
private void createIds(Integer id, List<Integer> list){
|
||||
@@ -128,4 +147,25 @@ public class PointServiceImpl extends ServiceImpl<PointDao, PointEntity> impleme
|
||||
}
|
||||
list.add(id);
|
||||
}
|
||||
|
||||
private String getDayGZ(int year,int month,int day){
|
||||
if(year==2024&&month==1&&day==1){
|
||||
return "甲子";
|
||||
}
|
||||
String[] dzr = TGDZ.dzr;
|
||||
Calendar basedate = Calendar.getInstance();
|
||||
basedate.set(2024, 1 - 1, 1);
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.set(year,month-1,day);
|
||||
if(year<2024){
|
||||
int offset = (int) ((basedate.getTimeInMillis() - now.getTimeInMillis()) / (1000 * 60 * 60 * 24));
|
||||
int c = offset%60;
|
||||
int cc = c==0?0:60-c;
|
||||
return dzr[cc];
|
||||
}else{
|
||||
int offset = (int) ((now.getTimeInMillis() - basedate.getTimeInMillis()) / (1000 * 60 * 60 * 24));
|
||||
int c = offset%60;
|
||||
return dzr[c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user