Commit 2027385afa85a8370caad6a369e9f7f5600b4e55

Authored by yangfei
1 parent ff58bcc045

儿保身高曲线图

Showing 2 changed files with 209 additions and 184 deletions

platform-common/src/main/java/com/lyms/platform/common/utils/DateUtil.java View file @ 2027385
... ... @@ -9,20 +9,20 @@
9 9 import java.util.concurrent.locks.ReentrantLock;
10 10  
11 11 public class DateUtil {
12   - private static Lock lock = new ReentrantLock();
  12 + private static Lock lock = new ReentrantLock();
13 13 public static SimpleDateFormat dd = new SimpleDateFormat("dd");
14 14 public static SimpleDateFormat yyyy = new SimpleDateFormat("yyyy");
15 15 public static SimpleDateFormat ymd = new SimpleDateFormat("yyyyMMdd");
16 16 public static SimpleDateFormat y_m_d = new SimpleDateFormat("yyyy-MM-dd");
17 17 public static SimpleDateFormat y_m = new SimpleDateFormat("yyyy年MM月");
18 18  
19   - public static SimpleDateFormat y_m_d1= new SimpleDateFormat("yyyy年MM月dd日");
  19 + public static SimpleDateFormat y_m_d1 = new SimpleDateFormat("yyyy年MM月dd日");
20 20 public static SimpleDateFormat md = new SimpleDateFormat("MM-dd");
21 21 public static SimpleDateFormat m_d = new SimpleDateFormat("MM/dd");
22 22 public static SimpleDateFormat y_m_d_h_m_s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
23 23 public static SimpleDateFormat y_m_d_h_m1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
24   - public static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
25   - "yyyy/MM/dd HH:mm" };
  24 + public static String[] parsePatterns = {"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
  25 + "yyyy/MM/dd HH:mm"};
26 26  
27 27 public static SimpleDateFormat y_m_d_h_m = new SimpleDateFormat("yyyyMMddHHmm");
28 28 public static SimpleDateFormat yyyyMMddHHmmssSSS = new SimpleDateFormat("yyyyMMddHHmmssSSS");
29 29  
30 30  
... ... @@ -67,13 +67,14 @@
67 67  
68 68 /**
69 69 * 获取传入日期 相加xx月后的第xx天
  70 + *
70 71 * @param date
71   - * @param addMonth 添加的月份数 当前月=0, 下月=1,上月=-1
72   - * @param day 第一天传1, 第二天传2,....... 最后一天传0
  72 + * @param addMonth 添加的月份数 当前月=0, 下月=1,上月=-1
  73 + * @param day 第一天传1, 第二天传2,....... 最后一天传0
73 74 * @return
74 75 */
75 76 public static Date getMonthDay(Date date, Integer addMonth, Integer day) {
76   - if(date != null && addMonth != null && day != null) {
  77 + if (date != null && addMonth != null && day != null) {
77 78 Calendar calendar = Calendar.getInstance();
78 79 calendar.setTime(date);
79 80 calendar.add(Calendar.MONTH, day == 0 ? addMonth + 1 : addMonth);
... ... @@ -89,7 +90,7 @@
89 90 */
90 91 public static Date getQuartDay(Date date, Integer addQuart, Integer day) {
91 92 Integer quart = getQuart(date);
92   - if(quart != null && addQuart != null && day != null) {
  93 + if (quart != null && addQuart != null && day != null) {
93 94 Calendar calendar = Calendar.getInstance();
94 95 calendar.setTime(date);
95 96 calendar.set(Calendar.MONTH, day == 0 ? (quart + addQuart) * 3 : (quart - 1 + addQuart) * 3);
... ... @@ -103,8 +104,8 @@
103 104 * 获取半年的时间
104 105 */
105 106 public static Date getHalfDay(Date date, Integer addHalt, Integer day) {
106   - if(date != null) {
107   - if(getMonth(date) > 6) {
  107 + if (date != null) {
  108 + if (getMonth(date) > 6) {
108 109 Calendar calendar = Calendar.getInstance();
109 110 calendar.setTime(date);
110 111 calendar.set(Calendar.MONTH, day == 0 ? 6 + (addHalt + 1) * 6 : 6 + addHalt * 6);
... ... @@ -119,7 +120,7 @@
119 120 * 获取一年的时间
120 121 */
121 122 public static Date getYear(Date date, Integer addYear, Integer day) {
122   - if(date != null) {
  123 + if (date != null) {
123 124 Calendar calendar = Calendar.getInstance();
124 125 calendar.setTime(date);
125 126 calendar.add(Calendar.YEAR, addYear);
126 127  
127 128  
128 129  
129 130  
130 131  
131 132  
... ... @@ -133,26 +134,27 @@
133 134 /**
134 135 * 1月~3月 4~6 7~9 10~11
135 136 * 获取当前时间属于哪个季度
  137 + *
136 138 * @param date
137 139 * @return
138 140 */
139 141 public static Integer getQuart(Date date) {
140   - if(date != null) {
  142 + if (date != null) {
141 143 Integer month = getMonth(date);
142   - if(month >= 1 && month <= 3) {
  144 + if (month >= 1 && month <= 3) {
143 145 return 1;
144   - } else if(month >= 4 && month <= 6) {
  146 + } else if (month >= 4 && month <= 6) {
145 147 return 2;
146   - } else if(month >= 7 && month <= 9) {
  148 + } else if (month >= 7 && month <= 9) {
147 149 return 3;
148   - } else if(month >= 10 && month <= 12) {
  150 + } else if (month >= 10 && month <= 12) {
149 151 return 4;
150 152 }
151 153 }
152 154 return null;
153 155 }
154 156  
155   - public static Date getYmdDate(Date date){
  157 + public static Date getYmdDate(Date date) {
156 158 try {
157 159 date.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(y_m_d.format(date)).getTime());
158 160 } catch (Exception e) {
159 161  
... ... @@ -169,11 +171,11 @@
169 171 }
170 172  
171 173 public static Integer getAge(Date birth) {
172   - if(null==birth){
  174 + if (null == birth) {
173 175 return null;
174 176 }
175   - java.util.Calendar calendar= Calendar.getInstance();
176   - Date date=new Date();
  177 + java.util.Calendar calendar = Calendar.getInstance();
  178 + Date date = new Date();
177 179 calendar.setTime(date);
178 180  
179 181 Calendar c1 = Calendar.getInstance();
... ... @@ -185,7 +187,7 @@
185 187  
186 188 int mouth1 = c1.get(Calendar.MONTH);//0当前
187 189 int mouth2 = c2.get(Calendar.MONTH);//4
188   - int i=0;
  190 + int i = 0;
189 191 /* if(mouth2-mouth1>=0){
190 192 int days1 = c1.get(Calendar.DAY_OF_MONTH);//当前10
191 193 int days2 = c2.get(Calendar.DAY_OF_MONTH);//1
192 194  
193 195  
... ... @@ -197,16 +199,16 @@
197 199 i=i-1;
198 200 }*/
199 201  
200   - if(mouth2==mouth1){
  202 + if (mouth2 == mouth1) {
201 203 int days1 = c1.get(Calendar.DAY_OF_MONTH);//当前10
202 204 int days2 = c2.get(Calendar.DAY_OF_MONTH);//1
203   - if(days1<days2){
204   - i=i-1;
205   - }else if(days1>days2){
  205 + if (days1 < days2) {
  206 + i = i - 1;
  207 + } else if (days1 > days2) {
206 208 // i=i-1;
207 209 }
208   - }else if(mouth2>mouth1){
209   - i=i-1;
  210 + } else if (mouth2 > mouth1) {
  211 + i = i - 1;
210 212 }
211 213  
212 214  
213 215  
... ... @@ -217,10 +219,11 @@
217 219 // long m = now.getTime() - birth.getTime();
218 220 // Long age = m / 31536000000L;
219 221 // return age.intValue();
220   - return (Math.abs(year1 - year2)+i);
  222 + return (Math.abs(year1 - year2) + i);
221 223 }
222   - public static Integer getAge(Date birth,Date fmDate) {
223   - if (birth == null ||null==fmDate) {
  224 +
  225 + public static Integer getAge(Date birth, Date fmDate) {
  226 + if (birth == null || null == fmDate) {
224 227 return null;
225 228 }
226 229 long m = fmDate.getTime() - birth.getTime();
227 230  
... ... @@ -321,15 +324,14 @@
321 324 }
322 325 }
323 326  
324   - public static Date getYear()
325   - {
  327 + public static Date getYear() {
326 328 lock.lock();
327 329 try {
328 330 String year = yyyy.format(new Date());
329 331 return yyyy.parse(year);
330 332 } catch (Exception e) {
331 333 return null;
332   - }finally {
  334 + } finally {
333 335 lock.unlock();
334 336 }
335 337 }
... ... @@ -407,7 +409,7 @@
407 409 return y_m_d.parse(s);
408 410 } catch (Exception e) {
409 411 return null;
410   - }finally {
  412 + } finally {
411 413 lock.unlock();
412 414 }
413 415 }
... ... @@ -423,7 +425,7 @@
423 425 return ymd.parse(s);
424 426 } catch (Exception e) {
425 427 return null;
426   - }finally {
  428 + } finally {
427 429 lock.unlock();
428 430 }
429 431 }
... ... @@ -477,7 +479,7 @@
477 479 return y_m_d.format(d);
478 480 } catch (Exception e) {
479 481 return null;
480   - }finally {
  482 + } finally {
481 483 lock.unlock();
482 484 }
483 485 }
... ... @@ -658,7 +660,7 @@
658 660 rightNow.setTime(srcDate);
659 661 rightNow.add(Calendar.DAY_OF_YEAR, days);
660 662 return rightNow.getTime();
661   - }finally {
  663 + } finally {
662 664 lock.unlock();
663 665 }
664 666 }
... ... @@ -670,7 +672,7 @@
670 672 rightNow.setTime(srcDate);
671 673 rightNow.add(Calendar.MONTH, month);
672 674 return rightNow.getTime();
673   - }finally {
  675 + } finally {
674 676 lock.unlock();
675 677 }
676 678 }
... ... @@ -682,7 +684,7 @@
682 684 rightNow.setTime(srcDate);
683 685 rightNow.add(Calendar.YEAR, year);
684 686 return rightNow.getTime();
685   - }finally {
  687 + } finally {
686 688 lock.unlock();
687 689 }
688 690 }
689 691  
... ... @@ -694,13 +696,12 @@
694 696 rightNow.setTime(srcDate);
695 697 rightNow.add(Calendar.WEEK_OF_YEAR, weak);
696 698 return rightNow.getTime();
697   - }finally {
  699 + } finally {
698 700 lock.unlock();
699 701 }
700 702 }
701 703  
702 704  
703   -
704 705 /**
705 706 * 获取当天还剩多少秒
706 707 *
707 708  
708 709  
709 710  
710 711  
711 712  
712 713  
713 714  
714 715  
715 716  
716 717  
717 718  
718 719  
719 720  
720 721  
721 722  
... ... @@ -718,73 +719,67 @@
718 719  
719 720 /**
720 721 * 计算儿童的月龄
  722 + *
721 723 * @param birth
722 724 * @param checkDate
723 725 * @return
724 726 */
725   - public static String getBabyMonthAge(Date birth, Date checkDate)
726   - {
727   - if(birth == null){
  727 + public static String getBabyMonthAge(Date birth, Date checkDate) {
  728 + if (birth == null) {
728 729 return "";
729 730 }
730 731 Calendar rightNow = Calendar.getInstance();
731 732 rightNow.setTime(checkDate);
732   - rightNow.add(Calendar.MONTH,-1);
733   - if (birth.getTime() > rightNow.getTime().getTime())
734   - {
735   - int day = daysBetween(birth,checkDate);
736   - return day+"天";
  733 + rightNow.add(Calendar.MONTH, -1);
  734 + if (birth.getTime() > rightNow.getTime().getTime()) {
  735 + int day = daysBetween(birth, checkDate);
  736 + return day + "天";
737 737 }
738 738 Calendar rightNow1 = Calendar.getInstance();
739 739 rightNow1.setTime(checkDate);
740   - rightNow1.add(Calendar.YEAR,-1);
  740 + rightNow1.add(Calendar.YEAR, -1);
741 741  
742 742  
743   - if (birth.getTime() > rightNow1.getTime().getTime())
744   - {
745   - int month = getMonthSpace(birth,checkDate);
  743 + if (birth.getTime() > rightNow1.getTime().getTime()) {
  744 + int month = getMonthSpace(birth, checkDate);
746 745 Calendar yearNow = Calendar.getInstance();
747 746 yearNow.setTime(birth);
748   - yearNow.add(Calendar.MONTH,month);
  747 + yearNow.add(Calendar.MONTH, month);
749 748  
750   - int day = daysBetween(yearNow.getTime(),checkDate);
  749 + int day = daysBetween(yearNow.getTime(), checkDate);
751 750 String dstr = "";
752   - if (day != 0)
753   - {
754   - dstr=day+"天";
  751 + if (day != 0) {
  752 + dstr = day + "天";
755 753 }
756 754 String ms = "";
757   - if (month != 0)
758   - {
759   - ms = month+"月龄";
  755 + if (month != 0) {
  756 + ms = month + "月龄";
760 757 }
761   - return ms+dstr;
  758 + return ms + dstr;
762 759 }
763 760 int year = getYearSpace(birth, checkDate);
764 761 rightNow.setTime(checkDate);
765   - rightNow.add(Calendar.YEAR,year);
  762 + rightNow.add(Calendar.YEAR, year);
766 763  
767 764 int month = getMonthSpace1(birth, rightNow.getTime());
768 765  
769   - return year+"岁"+ (month == 0 ? "" : month+"月龄");
  766 + return year + "岁" + (month == 0 ? "" : month + "月龄");
770 767 }
771 768  
772   - public static int daysBetween(Date smdate,Date bdate)
773   - {
774   - if (smdate == null || bdate == null)
775   - {
  769 + public static int daysBetween(Date smdate, Date bdate) {
  770 + if (smdate == null || bdate == null) {
776 771 return -1;
777 772 }
778   - SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
  773 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
779 774 try {
780   - smdate=sdf.parse(sdf.format(smdate));
781   - bdate=sdf.parse(sdf.format(bdate));
  775 + smdate = sdf.parse(sdf.format(smdate));
  776 + bdate = sdf.parse(sdf.format(bdate));
782 777 Calendar cal = Calendar.getInstance();
783 778 cal.setTime(smdate);
784 779 long time1 = cal.getTimeInMillis();
785 780 cal.setTime(bdate);
786 781 long time2 = cal.getTimeInMillis();
787   - long between_days=(time2-time1)/(1000*3600*24);
  782 + long between_days = (time2 - time1) / (1000 * 3600 * 24);
788 783 return Integer.parseInt(String.valueOf(between_days));
789 784 } catch (ParseException e) {
790 785 e.printStackTrace();
791 786  
792 787  
793 788  
... ... @@ -805,22 +800,21 @@
805 800 c2.setTime(date2);
806 801  
807 802 result = c2.get(Calendar.MONDAY) - c1.get(Calendar.MONTH);
808   - if (result <= 0)
809   - {
  803 + if (result <= 0) {
810 804 result = 12 - Math.abs(result);
811 805 }
812 806  
813 807 // result = result == 0 ? 1 : Math.abs(result);
814   - if (Integer.parseInt(getDD(date1)) > Integer.parseInt(getDD(date2)))
815   - {
816   - result = result -1;
  808 + if (Integer.parseInt(getDD(date1)) > Integer.parseInt(getDD(date2))) {
  809 + result = result - 1;
817 810 }
818 811  
819 812 return result;
820 813  
821 814 }
822   - public static int countMonths(Date date1,Date date2) throws ParseException{
823 815  
  816 + public static int countMonths(Date date1, Date date2) throws ParseException {
  817 +
824 818 /* Calendar c1=Calendar.getInstance();
825 819 Calendar c2=Calendar.getInstance();
826 820  
827 821  
828 822  
829 823  
830 824  
831 825  
832 826  
833 827  
834 828  
... ... @@ -836,40 +830,38 @@
836 830 }*/
837 831  
838 832 // return year*12+c2.get(Calendar.MONTH)-c1.get(Calendar.MONTH);
839   - return 0;
  833 + return 0;
840 834  
841 835  
842 836 }
843   - public static int getBabyMonthAge1(Date birth, Date checkDate)
844   - {
  837 +
  838 + public static int getBabyMonthAge1(Date birth, Date checkDate) {
845 839 Calendar rightNow = Calendar.getInstance();
846 840 rightNow.setTime(checkDate);
847   - rightNow.add(Calendar.MONTH,-1);
848   - if (birth.getTime() > rightNow.getTime().getTime())
849   - {
  841 + rightNow.add(Calendar.MONTH, -1);
  842 + if (birth.getTime() > rightNow.getTime().getTime()) {
850 843 return 0;
851 844 }
852 845 Calendar rightNow1 = Calendar.getInstance();
853 846 rightNow1.setTime(checkDate);
854   - rightNow1.add(Calendar.YEAR,-1);
  847 + rightNow1.add(Calendar.YEAR, -1);
855 848  
856 849  
857   - if (birth.getTime() > rightNow1.getTime().getTime())
858   - {
  850 + if (birth.getTime() > rightNow1.getTime().getTime()) {
859 851  
860   - int month = getMonthSpace(birth,checkDate);
  852 + int month = getMonthSpace(birth, checkDate);
861 853 Calendar yearNow = Calendar.getInstance();
862 854 yearNow.setTime(birth);
863   - yearNow.add(Calendar.MONTH,month);
  855 + yearNow.add(Calendar.MONTH, month);
864 856 return month;
865 857 }
866 858 int year = getYearSpace(birth, checkDate);
867 859 rightNow.setTime(checkDate);
868   - rightNow.add(Calendar.YEAR,year);
  860 + rightNow.add(Calendar.YEAR, year);
869 861  
870 862 int month = getMonthSpace1(birth, rightNow.getTime());
871 863  
872   - return year*12+month;
  864 + return year * 12 + month;
873 865 }
874 866  
875 867 public static int getMonthSpace1(Date date1, Date date2) {
876 868  
... ... @@ -883,14 +875,12 @@
883 875 c2.setTime(date2);
884 876  
885 877 result = c2.get(Calendar.MONDAY) - c1.get(Calendar.MONTH);
886   - if (result < 0)
887   - {
  878 + if (result < 0) {
888 879 result = 12 - Math.abs(result);
889 880 }
890 881  
891   - if (Integer.parseInt(getDD(date1)) > Integer.parseInt(getDD(date2)))
892   - {
893   - result = result -1;
  882 + if (Integer.parseInt(getDD(date1)) > Integer.parseInt(getDD(date2))) {
  883 + result = result - 1;
894 884 }
895 885  
896 886 return result;
... ... @@ -898,7 +888,6 @@
898 888 }
899 889  
900 890  
901   -
902 891 public static int getYearSpace(Date date1, Date date2) {
903 892 int result = 0;
904 893  
905 894  
906 895  
... ... @@ -909,28 +898,32 @@
909 898 c2.setTime(date2);
910 899  
911 900 result = c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR);
912   - if (Integer.parseInt(getMMdd(date1).split("-")[0]) > Integer.parseInt(getMMdd(date2).split("-")[0]))
913   - {
914   - result = result -1;
  901 + if (Integer.parseInt(getMMdd(date1).split("-")[0]) > Integer.parseInt(getMMdd(date2).split("-")[0])) {
  902 + result = result - 1;
915 903 }
916 904 return result == 0 ? 1 : Math.abs(result);
917 905  
918 906 }
919 907  
920 908  
921   -
922   -
923   - public static int getBabyAgeMonth(Date d1,Date d2){
924   - int months=0;//相差月份
925   - int y1=d1.getYear();
926   - int y2=d2.getYear();
927   - int dd1=d1.getDate(); //起始日期天
928   - int dd2=d2.getDate(); //结束日期天
929   - if(d1.getTime()<d2.getTime()){
930   - months=d2.getMonth()-d1.getMonth()+(y2-y1)*12;
931   - if(dd2<dd1){
932   - months=months-1;
  909 + public static int getBabyAgeMonth(Date d1, Date d2) {
  910 + int months = 0;//相差月份
  911 + try {
  912 + lock.lock();
  913 + int y1 = d1.getYear();
  914 + int y2 = d2.getYear();
  915 + int dd1 = d1.getDate(); //起始日期天
  916 + int dd2 = d2.getDate(); //结束日期天
  917 + if (d1.getTime() < d2.getTime()) {
  918 + months = d2.getMonth() - d1.getMonth() + (y2 - y1) * 12;
  919 + if (dd2 < dd1) {
  920 + months = months - 1;
  921 + }
933 922 }
  923 + }catch (Exception e){
  924 + e.printStackTrace();
  925 + }finally {
  926 + lock.unlock();
934 927 }
935 928 return months;
936 929 }
937 930  
938 931  
939 932  
940 933  
941 934  
942 935  
943 936  
944 937  
945 938  
946 939  
... ... @@ -951,55 +944,53 @@
951 944 w = 0;
952 945 return weekDays[w];
953 946 }
954   - public static Date getRangeDate(Date initDate,int num,String type,int delayDay){
955 947  
  948 + public static Date getRangeDate(Date initDate, int num, String type, int delayDay) {
  949 +
956 950 Calendar rightNow = Calendar.getInstance();
957 951 rightNow.setTime(initDate);
958   - if(type == null)return null;
959   - if(type.equals("年".trim())){
960   - rightNow.add(Calendar.YEAR,num);
  952 + if (type == null) return null;
  953 + if (type.equals("年".trim())) {
  954 + rightNow.add(Calendar.YEAR, num);
961 955  
962   - }else if(type.equals("月".trim())){
  956 + } else if (type.equals("月".trim())) {
963 957  
964   - rightNow.add(Calendar.MONTH,num);
965   - }else if(type.equals("周".trim())){
  958 + rightNow.add(Calendar.MONTH, num);
  959 + } else if (type.equals("周".trim())) {
966 960 rightNow.add(Calendar.WEEK_OF_YEAR, num);
967   - }else if(type.equals("天".trim())){
968   - rightNow.add(Calendar.DAY_OF_YEAR,num);
  961 + } else if (type.equals("天".trim())) {
  962 + rightNow.add(Calendar.DAY_OF_YEAR, num);
969 963 }
970 964 rightNow.add(Calendar.DAY_OF_YEAR, delayDay);
971 965 return rightNow.getTime();
972 966 }
973 967  
974   - public static Date getNewDate(int num,String type,int day){
  968 + public static Date getNewDate(int num, String type, int day) {
975 969 Date dt = new Date();
976 970  
977 971 Calendar rightNow = Calendar.getInstance();
978 972 rightNow.setTime(dt);
979   - if(type == null)return null;
980   - if(type.trim().equals("年")){
981   - rightNow.add(Calendar.YEAR,num);
982   - }else if(type.trim().equals("月")){
983   - rightNow.add(Calendar.MONTH,num);
984   - }else if(type.trim().equals("周")){
  973 + if (type == null) return null;
  974 + if (type.trim().equals("年")) {
  975 + rightNow.add(Calendar.YEAR, num);
  976 + } else if (type.trim().equals("月")) {
  977 + rightNow.add(Calendar.MONTH, num);
  978 + } else if (type.trim().equals("周")) {
985 979 rightNow.add(Calendar.WEEK_OF_YEAR, num);
986   - }else if(type.trim().equals("天")){
987   - rightNow.add(Calendar.DAY_OF_YEAR,num);
  980 + } else if (type.trim().equals("天")) {
  981 + rightNow.add(Calendar.DAY_OF_YEAR, num);
988 982 }
989 983 rightNow.add(Calendar.DAY_OF_YEAR, day);
990 984 return rightNow.getTime();
991 985 }
992 986  
993   - public static Date formatDate(Date date)
994   - {
995   - String time = y_m_d.format(date);
  987 + public static Date formatDate(Date date) {
  988 + String time = y_m_d.format(date);
996 989 return parseYMD(time);
997 990 }
998 991  
999   - public static String formatSimpleDate(Date date)
1000   - {
1001   - if (date == null)
1002   - {
  992 + public static String formatSimpleDate(Date date) {
  993 + if (date == null) {
1003 994 return "";
1004 995 }
1005 996 SimpleDateFormat md = new SimpleDateFormat("M-d");
... ... @@ -1007,8 +998,6 @@
1007 998 }
1008 999  
1009 1000  
1010   -
1011   -
1012 1001 /**
1013 1002 * @auther HuJiaqi
1014 1003 * @createTime 2016年11月29日 11时30分
... ... @@ -1050,7 +1039,7 @@
1050 1039 /**
1051 1040 * 日期型字符串转化为日期 格式
1052 1041 * { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
1053   - * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" }
  1042 + * "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm" }
1054 1043 */
1055 1044 public static Date parseDate(Object str) {
1056 1045 if (str == null) {
1057 1046  
1058 1047  
... ... @@ -1066,18 +1055,19 @@
1066 1055 /**
1067 1056 * 判断第一个时间 是否大于或等于第二个时间
1068 1057 * 只对比年月日 相同也返回true
  1058 + *
1069 1059 * @param date1
1070 1060 * @param date2
1071 1061 * @return
1072 1062 */
1073 1063 public static boolean isGtOrEq(Date date1, Date date2) {
1074 1064 try {
1075   - date1 = ymd.parse(ymd.format(date1));
1076   - date2 = ymd.parse(ymd.format(date2));
1077   - if(org.apache.commons.lang3.time.DateUtils.isSameDay(date1, date2) || date1.after(date2)) {
  1065 + date1 = ymd.parse(ymd.format(date1));
  1066 + date2 = ymd.parse(ymd.format(date2));
  1067 + if (org.apache.commons.lang3.time.DateUtils.isSameDay(date1, date2) || date1.after(date2)) {
1078 1068 return true;
1079 1069 }
1080   - } catch (Exception e){
  1070 + } catch (Exception e) {
1081 1071 e.printStackTrace();
1082 1072 }
1083 1073 return false;
... ... @@ -1086,6 +1076,7 @@
1086 1076 /**
1087 1077 * 判断第一个时间 是否小于或等于第二个时间
1088 1078 * 只对比年月日 相同也返回true
  1079 + *
1089 1080 * @param date1
1090 1081 * @param date2
1091 1082 * @return
... ... @@ -1097,6 +1088,7 @@
1097 1088 /**
1098 1089 * 判断date是否包含于 start 和 end 之间
1099 1090 * 只对比年月日 包含相同天数
  1091 + *
1100 1092 * @param date
1101 1093 * @param start
1102 1094 * @param end
1103 1095  
1104 1096  
... ... @@ -1111,18 +1103,19 @@
1111 1103  
1112 1104 /**
1113 1105 * 把一段时间 拼成 孕?周+?天
  1106 + *
1114 1107 * @param start
1115 1108 * @param end
1116 1109 * @return
1117 1110 */
1118   - public static String getWeekDesc(Date start, Date end) {
1119   - if(start == null || end == null) {
  1111 + public static String getWeekDesc(Date start, Date end) {
  1112 + if (start == null || end == null) {
1120 1113 return "孕0周+0天";
1121 1114 }
1122 1115 Integer betweenDay = DateUtil.getDays(start, end);
1123 1116 Integer week = betweenDay / 7;
1124 1117 Integer day = betweenDay % 7;
1125   - if(week >= 42) {
  1118 + if (week >= 42) {
1126 1119 return "已分娩";
1127 1120 }
1128 1121 return "孕" + week + "周" + (day > 0 ? "+" + day + "天" : "");
1129 1122  
... ... @@ -1131,12 +1124,13 @@
1131 1124 /**
1132 1125 * 获取孕周
1133 1126 * 上面写的有bug 有时候会多一周!!!
  1127 + *
1134 1128 * @param start
1135 1129 * @param end
1136 1130 * @return
1137 1131 */
1138 1132 public static Integer getWeek2(Date start, Date end) {
1139   - if(start == null || end == null) {
  1133 + if (start == null || end == null) {
1140 1134 return null;
1141 1135 }
1142 1136 Integer betweenDay = DateUtil.getDays(start, end);
... ... @@ -1146,6 +1140,7 @@
1146 1140  
1147 1141 /**
1148 1142 * 获取两个日期相差几个月
  1143 + *
1149 1144 * @param start
1150 1145 * @param end
1151 1146 * @return
... ... @@ -1159,7 +1154,7 @@
1159 1154 c2.setTime(end);
1160 1155 result = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH);
1161 1156 result += 12 * (c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR));
1162   - if(c2.get(Calendar.DAY_OF_MONTH) - c1.get(Calendar.DAY_OF_MONTH) < 0 && result > 0) {
  1157 + if (c2.get(Calendar.DAY_OF_MONTH) - c1.get(Calendar.DAY_OF_MONTH) < 0 && result > 0) {
1163 1158 result -= 1;
1164 1159 }
1165 1160 } catch (Exception e) {
... ... @@ -1171,6 +1166,7 @@
1171 1166 /**
1172 1167 * 获取两个日期直接的天数(只算最后的天数)
1173 1168 * 比如 2017-10-10 2017-11-20 返回 10
  1169 + *
1174 1170 * @param start
1175 1171 * @param end
1176 1172 * @return
1177 1173  
... ... @@ -1185,10 +1181,10 @@
1185 1181  
1186 1182 int endDay = c2.get(Calendar.DAY_OF_MONTH);
1187 1183 int startDay = c1.get(Calendar.DAY_OF_MONTH);
1188   - if(endDay >= startDay) {
  1184 + if (endDay >= startDay) {
1189 1185 result = endDay - startDay;
1190 1186 } else { /** 获取上个月天数 + endDate天数 - startDate天数 */
1191   - c2.add(Calendar.MONTH,-1);/** 得到上个月的月份 */
  1187 + c2.add(Calendar.MONTH, -1);/** 得到上个月的月份 */
1192 1188 result = c2.getActualMaximum(Calendar.DAY_OF_MONTH) + endDay - startDay;
1193 1189 }
1194 1190  
1195 1191  
1196 1192  
... ... @@ -1199,15 +1195,15 @@
1199 1195 }
1200 1196  
1201 1197  
1202   -
1203 1198 /**
1204 1199 * 获取月龄描述信息 优惠券使用时间 - 分娩时间
  1200 + *
1205 1201 * @param start
1206 1202 * @param end
1207 1203 * @return
1208 1204 */
1209 1205 public static String getMonthDesc(Date start, Date end) {
1210   - if(start == null || end == null) {
  1206 + if (start == null || end == null) {
1211 1207 return "0月龄+0天";
1212 1208 }
1213 1209 int month = getMonth(start, end);
... ... @@ -1217,6 +1213,7 @@
1217 1213  
1218 1214 /**
1219 1215 * 获取传入日期的月份
  1216 + *
1220 1217 * @param date
1221 1218 * @return
1222 1219 */
1223 1220  
... ... @@ -1228,9 +1225,10 @@
1228 1225  
1229 1226 /**
1230 1227 * 返回当前时间 只包括年月日
  1228 + *
1231 1229 * @return
1232 1230 */
1233   - public static Date getYMDTime(){
  1231 + public static Date getYMDTime() {
1234 1232 try {
1235 1233 Date now = new SimpleDateFormat("yyyy-MM-dd").parse(getymd());
1236 1234 return now;
1237 1235  
... ... @@ -1242,10 +1240,11 @@
1242 1240  
1243 1241 /**
1244 1242 * 把传入的时间 格式化为 只有年月日的时间
  1243 + *
1245 1244 * @param date
1246 1245 * @return
1247 1246 */
1248   - public static void formatYmd(Date date){
  1247 + public static void formatYmd(Date date) {
1249 1248 try {
1250 1249 date.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(y_m_d.format(date)).getTime());
1251 1250 } catch (Exception e) {
... ... @@ -1255,6 +1254,7 @@
1255 1254  
1256 1255 /**
1257 1256 * 获取当前时间加上多少周的时间
  1257 + *
1258 1258 * @param week
1259 1259 * @return
1260 1260 */
... ... @@ -1274,6 +1274,7 @@
1274 1274  
1275 1275 /**
1276 1276 * 获取当前时间加上xx月后的年月日时间
  1277 + *
1277 1278 * @param month
1278 1279 * @return
1279 1280 */
1280 1281  
1281 1282  
1282 1283  
1283 1284  
1284 1285  
1285 1286  
1286 1287  
... ... @@ -1291,44 +1292,47 @@
1291 1292  
1292 1293 /**
1293 1294 * 用于月龄查询
  1295 + * <p>
  1296 + * Date start = DateUtil.getBirthStart(endMonth);
  1297 + * Date end = DateUtil.getBirthEnd(startMonth);
  1298 + * criteria.and("birth").gte(start).lt(end);
1294 1299 *
1295   - * Date start = DateUtil.getBirthStart(endMonth);
1296   - * Date end = DateUtil.getBirthEnd(startMonth);
1297   - * criteria.and("birth").gte(start).lt(end);
1298   - *
1299 1300 * @param end
1300 1301 * @return
1301 1302 */
1302 1303 public static Date getBirthStart(Integer end) {
1303 1304 return getMonth(-end - 1);
1304 1305 }
  1306 +
1305 1307 public static Date getBirthEnd(Integer start) {
1306 1308 return addDay(getMonth(-start), 1);
1307 1309 }
1308 1310  
1309 1311 /**
1310 1312 * 用于孕周查询
  1313 + * <p>
  1314 + * Date start = DateUtil.getBirthStart(endMonth);
  1315 + * Date end = DateUtil.getBirthEnd(startMonth);
  1316 + * criteria.and("birth").gte(start).lt(end);
1311 1317 *
1312   - * Date start = DateUtil.getBirthStart(endMonth);
1313   - * Date end = DateUtil.getBirthEnd(startMonth);
1314   - * criteria.and("birth").gte(start).lt(end);
1315   - *
1316 1318 * @param end
1317 1319 * @return
1318 1320 */
1319 1321 public static Date getWeekStart(Integer end) {
1320 1322 return getWeek(-end - 1);
1321 1323 }
  1324 +
1322 1325 public static Date getWeekEnd(Integer start) {
1323 1326 return getWeek(-start);
1324 1327 }
1325 1328  
1326 1329 /**
1327 1330 * 获取xx周的日期
  1331 + *
1328 1332 * @param week
1329 1333 * @return
1330 1334 */
1331   - public static Date getWeek(Integer week) {
  1335 + public static Date getWeek(Integer week) {
1332 1336 Calendar calendar = Calendar.getInstance();
1333 1337 calendar.setTime(new Date());
1334 1338 calendar.add(Calendar.WEEK_OF_MONTH, week);
... ... @@ -1343,9 +1347,10 @@
1343 1347 /**
1344 1348 * 获取几年之前的日期
1345 1349 * 主要用于年龄查询
1346   - * Date start = DateUtil.getBeforeAge(age);
1347   - Date end = DateUtil.getBeforeAge(age + 1);
1348   - pCriteria.and("birth").gt(end).lte(start);
  1350 + * Date start = DateUtil.getBeforeAge(age);
  1351 + * Date end = DateUtil.getBeforeAge(age + 1);
  1352 + * pCriteria.and("birth").gt(end).lte(start);
  1353 + *
1349 1354 * @param age
1350 1355 * @return
1351 1356 */
1352 1357  
... ... @@ -1359,12 +1364,12 @@
1359 1364  
1360 1365 public static List<Map<String, Date>> getRange(Date start, Date end) {
1361 1366 List<Map<String, Date>> restList = new ArrayList<>();
1362   - if(start != null && end != null) {
  1367 + if (start != null && end != null) {
1363 1368 List<Date> dates = getMonthBetween(start, end);
1364 1369 for (int i = 0; i < dates.size(); i++) {
1365 1370 Map<String, Date> temp = new HashMap<>();
1366 1371 temp.put("cname", dates.get(i));
1367   - if(i == 0) {
  1372 + if (i == 0) {
1368 1373 temp.put("start", start);
1369 1374 temp.put("end", dates.size() > 1 ? addDay(dates.get(1), -1) : end);
1370 1375 } else if (i == dates.size() - 1) {
... ... @@ -1382,6 +1387,7 @@
1382 1387  
1383 1388 /**
1384 1389 * 把传进来的日期 设置为当天的最后一秒
  1390 + *
1385 1391 * @param date
1386 1392 */
1387 1393 public static Date getDayLastSecond(Date date) {
... ... @@ -1405,7 +1411,7 @@
1405 1411 Calendar curr = min;
1406 1412 while (curr.before(max)) {
1407 1413 result.add(curr.getTime());
1408   - curr.add(Calendar.MONTH, 1);
  1414 + curr.add(Calendar.MONTH, 1);
1409 1415 }
1410 1416 return result;
1411 1417 }
... ... @@ -1442,6 +1448,7 @@
1442 1448  
1443 1449 /**
1444 1450 * 获取昨天五点的时间
  1451 + *
1445 1452 * @return
1446 1453 */
1447 1454 public static Date getYesterday() {
1448 1455  
... ... @@ -1452,10 +1459,10 @@
1452 1459  
1453 1460 public static void main(String[] args) {
1454 1461  
1455   - int i = DateUtil.daysBetween(DateUtil.parseYMD("2018-02-20"),new Date());
  1462 + int i = DateUtil.daysBetween(DateUtil.parseYMD("2018-02-20"), new Date());
1456 1463 System.out.println(i);
1457 1464  
1458   - int week = DateUtil.getWeek2(parseYMD("2017-10-12"),new Date());
  1465 + int week = DateUtil.getWeek2(parseYMD("2017-10-12"), new Date());
1459 1466 System.out.println(week);
1460 1467 // System.out.println(getDayLastSecond(new Date()).toLocaleString());
1461 1468 // List<Map<String, Date>> monthBetween = getRange(parseYMD("2017-1-11"), parseYMD("2017-12-29"));
platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BabyCheckFacade.java View file @ 2027385
... ... @@ -38,7 +38,10 @@
38 38 @Autowired
39 39 private BabyBookbuildingService babyBookbuildingService;
40 40  
  41 + @Autowired
  42 + private BabyService babyService;
41 43  
  44 +
42 45 @Autowired
43 46 private BasicConfigService basicConfigService;
44 47  
45 48  
46 49  
47 50  
48 51  
... ... @@ -1675,19 +1678,22 @@
1675 1678  
1676 1679 Map<String,Object> map = new HashMap<>();
1677 1680  
1678   - List<String> weightTitles = new LinkedList<>();
  1681 + List<Integer> weightTitles = new LinkedList<>();
1679 1682 List<String> weightValues = new LinkedList<>();
1680 1683  
1681   - List<String> heightTitles = new LinkedList<>();
  1684 + List<Integer> heightTitles = new LinkedList<>();
1682 1685 List<String> heightValues = new LinkedList<>();
1683 1686  
1684   - List<Map<String,String>> tables = new LinkedList<>();
  1687 + List<Map<String,Object>> tables = new LinkedList<>();
1685 1688  
  1689 + BabyModel babyModel = babyService.getOneBabyById(babyId);
  1690 +
1686 1691 BabyCheckModelQuery query = new BabyCheckModelQuery();
1687 1692 query.setYn(YnEnums.YES.getId());
1688 1693 query.setBuildId(babyId);
1689 1694 //查询儿童的检查记录
1690 1695 List<BabyCheckModel> checkModels = babyCheckService.queryBabyCheckRecord(query, "checkDate,created", Sort.Direction.ASC);
  1696 +
1691 1697 if (CollectionUtils.isNotEmpty(checkModels))
1692 1698 {
1693 1699 for (BabyCheckModel checkModel : checkModels)
1694 1700  
1695 1701  
... ... @@ -1696,15 +1702,21 @@
1696 1702 {
1697 1703 if (org.apache.commons.lang.StringUtils.isNotEmpty(checkModel.getHeight()) || org.apache.commons.lang.StringUtils.isNotEmpty(checkModel.getWeight()))
1698 1704 {
1699   - Map<String,String> heightMap = new HashMap<>();
  1705 + int month = DateUtil.getBabyAgeMonth(babyModel.getBirth(),checkModel.getCheckDate());
  1706 + Map<String,Object> heightMap = new HashMap<>();
  1707 + heightMap.put("time",month);
1700 1708 if (org.apache.commons.lang.StringUtils.isNotEmpty(checkModel.getHeight()))
1701 1709 {
1702 1710 if (org.apache.commons.lang.StringUtils.isNumeric(checkModel.getHeight()) || Pattern.compile("^[-\\+]?[.\\d]*$").matcher(checkModel.getHeight()).matches())
1703 1711 {
1704   - heightTitles.add(DateUtil.getyyyy_MM_dd(checkModel.getCheckDate()));
1705   - heightValues.add(checkModel.getHeight());
  1712 + if(heightTitles.contains(month)){
  1713 + int index = heightTitles.indexOf(month);
  1714 + heightValues.set(index,checkModel.getHeight());
  1715 + }else {
  1716 + heightTitles.add(month);
  1717 + heightValues.add(checkModel.getHeight());
  1718 + }
1706 1719 }
1707   - heightMap.put("time",DateUtil.getyyyy_MM_dd(checkModel.getCheckDate()));
1708 1720 heightMap.put("height", checkModel.getHeight());
1709 1721 }
1710 1722 else
1711 1723  
1712 1724  
... ... @@ -1716,17 +1728,21 @@
1716 1728 {
1717 1729 if (org.apache.commons.lang.StringUtils.isNumeric(checkModel.getWeight()) || Pattern.compile("^[-\\+]?[.\\d]*$").matcher(checkModel.getWeight()).matches())
1718 1730 {
1719   - weightTitles.add(DateUtil.getyyyy_MM_dd(checkModel.getCheckDate()));
1720   - weightValues.add(checkModel.getWeight());
  1731 +
  1732 + if(weightTitles.contains(month)){//如果存在月的数据则更新对应索引的值
  1733 + int index = weightTitles.indexOf(month);
  1734 + weightValues.set(index,checkModel.getWeight());
  1735 + }else {
  1736 + weightTitles.add(month);
  1737 + weightValues.add(checkModel.getWeight());
  1738 + }
1721 1739 }
1722   - heightMap.put("time", DateUtil.getyyyy_MM_dd(checkModel.getCheckDate()));
1723 1740 heightMap.put("weight",checkModel.getWeight());
1724 1741 }
1725 1742 else
1726 1743 {
1727 1744 heightMap.put("weight", "--");
1728 1745 }
1729   -
1730 1746 tables.add(heightMap);
1731 1747 }
1732 1748 }
... ... @@ -1739,7 +1755,9 @@
1739 1755 map.put("heightValues",heightValues);
1740 1756  
1741 1757 map.put("tables",tables);
1742   -
  1758 + if(babyModel!=null){
  1759 + map.put("sex",babyModel.getSex());
  1760 + }
1743 1761 return new BaseObjectResponse().setData(map).setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功");
1744 1762 }
1745 1763 }