diff --git a/src/main/java/com/peanut/config/TGDZ.java b/src/main/java/com/peanut/config/TGDZ.java index d8fe5f60..259a637b 100644 --- a/src/main/java/com/peanut/config/TGDZ.java +++ b/src/main/java/com/peanut/config/TGDZ.java @@ -8,5 +8,36 @@ public class TGDZ { public static final String[] dzz = {"子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"}; + public static final String[] wx = {"木","火","土","金","水"}; + public static final String[] dzr = {"甲子","乙丑","丙寅","丁卯","戊辰","己巳","庚午","辛未","壬申","癸酉","甲戌","乙亥","丙子","丁丑","戊寅","己卯","庚辰","辛巳","壬午","癸未","甲申","乙酉","丙戌","丁亥","戊子","己丑","庚寅","辛卯","壬辰","癸巳","甲午","乙未","丙申","丁酉","戊戌","己亥","庚子","辛丑","壬寅","癸卯","甲辰","乙巳","丙午","丁未","戊申","己酉","庚戌","辛亥","壬子","癸丑","甲寅","乙卯","丙辰","丁巳","戊午","己未","庚申","辛酉","壬戌","癸亥"}; + + public static final String[] lq = {"厥阴","少阴","太阴","少阳","阳明","太阳"}; + + + public static final String[] tianfu = {"己丑","己未","戊寅","戊申","戊子","戊午","乙卯","乙酉","丁巳","丁亥","丙辰","丙戍"}; + + public static final String[] suihui = {"甲辰","甲戍","己丑","己未","乙酉","丁卯","戊午","丙子"}; + + public static final String[] tongtianfu = {"甲辰","甲戍","庚子","庚午","壬寅","壬申"}; + + public static final String[] tongsuihui = {"辛未","辛丑","癸卯","癸酉","癸巳","癸亥"}; + + public static final String[] taiyitianfu = {"己丑","己未","乙酉","戊午"}; + + public static final double D = 0.2422; + // "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", + // "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", + // "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至" + // 定义数组,存储的是20世纪和21世纪的节气C值 + + public static final double[] S20 = { 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 }; + + public static final double[] S21 = { 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 }; + + + + } diff --git a/src/main/java/com/peanut/modules/book/controller/MyUserController.java b/src/main/java/com/peanut/modules/book/controller/MyUserController.java index 15da37de..e32ea3f9 100644 --- a/src/main/java/com/peanut/modules/book/controller/MyUserController.java +++ b/src/main/java/com/peanut/modules/book/controller/MyUserController.java @@ -166,8 +166,15 @@ public class MyUserController { * 常规注册 发短信验证码 */ @RequestMapping("/sms/sendcode") - public R registerSms(@RequestParam("phone") String phone,@RequestParam Integer areaCode) throws Exception { + public R registerSms(@RequestParam("phone") String phone,@RequestParam(required = false) String areaCode) throws Exception { + int areacode=0; + if(areaCode==null||areaCode.equals("")){ + areacode=0; + }else{ + areacode = Integer.valueOf(areaCode); + } + System.out.println(areacode); //验证一分钟内是否已经发过 String redisCode = redisTemplate.opsForValue().get("RegistCode" + phone); if (!StringUtils.isEmpty(redisCode)) { @@ -192,7 +199,7 @@ public class MyUserController { redisTemplate.opsForValue().set("RegistCode"+phone,code,5, TimeUnit.MINUTES); //发送 - userService.sendCodeForRegister(phone,code,areaCode); + userService.sendCodeForRegister(phone,code,areacode); return R.ok(); } diff --git a/src/main/java/com/peanut/modules/book/controller/PointController.java b/src/main/java/com/peanut/modules/book/controller/PointController.java index 054280fb..7765433d 100644 --- a/src/main/java/com/peanut/modules/book/controller/PointController.java +++ b/src/main/java/com/peanut/modules/book/controller/PointController.java @@ -180,7 +180,7 @@ public class PointController { Date parse = simpleDateFormat.parse(date); - Map stringStringMap = pointService.TGDZForDate(parse); + Map stringStringMap = pointService.TGDZForDate(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 ecb38841..275c3dd7 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); - Map TGDZForDate(Date date); + Map TGDZForDate(Date date); } 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 bb399cd3..c38fbbe1 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 @@ -17,6 +17,7 @@ import com.peanut.modules.book.service.PointService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.text.SimpleDateFormat; import java.util.*; @Service("pointService") @@ -66,7 +67,7 @@ public class PointServiceImpl extends ServiceImpl impleme } @Override - public Map TGDZForDate(Date date) { + public Map TGDZForDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Integer year = calendar.get(Calendar.YEAR); @@ -74,17 +75,11 @@ public class PointServiceImpl extends ServiceImpl impleme 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 ct = myCalendar.getCT(); - System.out.println(ct); 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; @@ -103,8 +98,7 @@ public class PointServiceImpl extends ServiceImpl impleme //月份天干地支 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 flagMap = new HashMap<>(); + HashMap flagMap = new HashMap<>(); flagMap.put("year",c_year); flagMap.put("month",c_month); @@ -134,9 +128,173 @@ public class PointServiceImpl extends ServiceImpl impleme dcc = dd-1; } flagMap.put("hour",tg[dcc]+dzz[s_d-1]); + + //获取五运相关 + boolean check_dh; + if(month==1&&getSolarTerm(year, 1, 2)>day){ + check_dh = false; + }else { + check_dh = true; + } + + Map yearWY = getYearWY(check_dh?year:year-1); + flagMap.put("wy",yearWY); + + //获取六气相关 + Map yearLQ = getYearLQ(check_dh?year:year-1); + flagMap.put("lq",yearLQ); + + return flagMap; } + + private Map getYearLQ(Integer year){ + String[] dz = TGDZ.dz; + Integer d = (year+7)%12; + if(d==0){ + d=12; + } + String c_year_d = dz[d - 1]; + + HashMap flag = new HashMap<>(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String dh = year.toString() + "-01-" + getSolarTerm(year, 1, 2);//大寒日期 + Integer n_year = year+1; + String ndh = n_year.toString() + "-01-" + getSolarTerm(n_year, 1, 2);//大寒日期 + Calendar chunFen = Calendar.getInstance(); + chunFen.set(year,2,getSolarTerm(year,3,2)); + String erqi = simpleDateFormat.format(chunFen.getTime()); + Calendar xiaoMan = Calendar.getInstance(); + xiaoMan.set(year,4,getSolarTerm(year,5,2)); + String sanqi = simpleDateFormat.format(xiaoMan.getTime()); + Calendar daShu = Calendar.getInstance(); + daShu.set(year,6,getSolarTerm(year,7,2)); + String siqi = simpleDateFormat.format(daShu.getTime()); + Calendar qiufen = Calendar.getInstance(); + qiufen.set(year,8,getSolarTerm(year,9,2)); + String wuqi = simpleDateFormat.format(qiufen.getTime()); + Calendar xiaoxue = Calendar.getInstance(); + xiaoxue.set(year,10,getSolarTerm(year,11,2)); + String liuqi = simpleDateFormat.format(xiaoxue.getTime()); + List time = new ArrayList<>(); + time.add(dh);time.add(erqi);time.add(sanqi);time.add(siqi);time.add(wuqi);time.add(liuqi);time.add(ndh); + flag.put("time",time); + String[] zhuqi = {"厥阴","少阴","少阳","太阴","阳明","太阳"}; + flag.put("zhuqi",zhuqi); + String[] lq = TGDZ.lq; + String sitian; + if(c_year_d=="子"||c_year_d=="午"){ + sitian = "少阴"; + } else if (c_year_d=="丑"||c_year_d=="未") { + sitian = "太阴"; + } else if (c_year_d=="寅"||c_year_d=="申") { + sitian = "少阳"; + } else if (c_year_d=="卯"||c_year_d=="酉") { + sitian = "阳明"; + } else if (c_year_d=="辰"||c_year_d=="戌") { + sitian = "太阳"; + }else { + sitian = "厥阴"; + } + List lq_list = Arrays.asList(lq); + int i = lq_list.indexOf(sitian); + List keqi = new ArrayList<>(); + keqi.add(myAddLQ(i-2));keqi.add(myAddLQ(i-1));keqi.add(myAddLQ(i));keqi.add(myAddLQ(i+1));keqi.add(myAddLQ(i+2));keqi.add(myAddLQ(i+3)); + flag.put("keqi",keqi); + + return flag; + + } + + private String myAddLQ(int i){ + String[] lq = TGDZ.lq; + if(i<0){ + return lq[i+6]; + } else if (i>5) { + return lq[i-6]; + }else { + return lq[i]; + } + } + + /** + * 获取一年的全部五运分布 + * @param year 年2013 + * @return + */ + private Map getYearWY(Integer year){ + String[] tg = TGDZ.tg; + Integer ty_c = year%10; + Integer ty = ty_c<=3?ty_c+10-3:ty_c-3; + String c_year_t = tg[ty-1]; + + HashMap flag = new HashMap<>(); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String dh = year.toString() + "-01-" + getSolarTerm(year, 1, 2);//大寒日期 + Integer next_year = year+1; + String dh_n = next_year.toString()+ "-01-" + getSolarTerm(next_year, 1, 2);//次年大寒日期 + Calendar chunFen = Calendar.getInstance(); + chunFen.set(year,2,getSolarTerm(year, 3, 2)); + chunFen.add(Calendar.DAY_OF_MONTH,15); + String erYun = simpleDateFormat.format(chunFen.getTime()); + Calendar mangZhong = Calendar.getInstance(); + mangZhong.set(year,5,getSolarTerm(year,6,1)); + mangZhong.add(Calendar.DAY_OF_MONTH,10); + String sanYun = simpleDateFormat.format(mangZhong.getTime()); + Calendar chuShu = Calendar.getInstance(); + chuShu.set(year,7,getSolarTerm(year,8,2)); + chuShu.add(Calendar.DAY_OF_MONTH,7); + String siYun = simpleDateFormat.format(chuShu.getTime()); + Calendar liDong = Calendar.getInstance(); + liDong.set(year,10,getSolarTerm(year,11,1)); + liDong.add(Calendar.DAY_OF_MONTH,4); + String zhongYun = simpleDateFormat.format(liDong.getTime()); + ArrayList time = new ArrayList<>(); + time.add(dh); + time.add(erYun); + time.add(sanYun); + time.add(siYun); + time.add(zhongYun); + time.add(dh_n); + flag.put("time",time); + String nianYun; + if(c_year_t=="甲"||c_year_t=="己"){ + nianYun = "土"; + } else if (c_year_t=="乙"||c_year_t=="庚") { + nianYun = "金"; + } else if (c_year_t=="丙"||c_year_t=="辛") { + nianYun = "水"; + } else if (c_year_t=="丁"||c_year_t=="壬") { + nianYun = "木"; + }else { + nianYun = "火"; + } + String[] wx = TGDZ.wx; + flag.put("nianYun",nianYun); + flag.put("zhuYun",wx); + List list = Arrays.asList(wx); + int i = list.indexOf(nianYun); + ArrayList kwx = new ArrayList<>(); + for (int jk =0;jk<5;jk++){ + kwx.add(mygetWx(i)); + i++; + } + flag.put("keYun",kwx); + + + return flag; + } + + private String mygetWx(int i){ + String[] wx = TGDZ.wx; + if(i>=5){ + return wx[i-5]; + }else{ + return wx[i]; + } + } + private void createIds(Integer id, List list){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(PointCategoryEntity::getPid,id); @@ -168,4 +326,33 @@ public class PointServiceImpl extends ServiceImpl impleme return dzr[c]; } } + + /** + * 饭后某年某月的第几个节日的日 + * @param year + * @param month + * @param num 1/2 + * @return + */ + private int getSolarTerm(Integer year,Integer month,Integer num){ + double D = TGDZ.D; + double[] s20 = TGDZ.S20; + double[] s21 = TGDZ.S21; + double[] sc = null; + if (year >= 1901 && year <= 2000) {// 20世纪 + sc =s20; + } else if (year >= 2001 && year <= 2100) {// 21世纪 + sc =s21; + } + double C=num==1?sc[(month) * 2 - 1 - 1]:sc[month * 2 - 1]; + int Y = year % 100; + int L = (Y) / 4; + if (num==1&&year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { + // 注意:凡闰年3月1日前闰年数要减一,即:L=[(Y-1)/4],因为小寒、大寒、立春、雨水这两个节气都小于3月1日 + if (C == 5.4055 || C == 3.87) { + L = (Y - 1) / 4; + } + } + return (int) ((Y * D + C) - L); + } }