diff --git a/framework-core/pom.xml b/framework-core/pom.xml index 2ad3cb9..f456278 100644 --- a/framework-core/pom.xml +++ b/framework-core/pom.xml @@ -5,7 +5,7 @@ com.unionmed unionmed-framework - 0.0.19 + 0.0.21 4.0.0 diff --git a/framework-core/src/main/java/com/unionmed/framework/spring/mvc/filter/CrossFilter.java b/framework-core/src/main/java/com/unionmed/framework/spring/mvc/filter/CrossFilter.java index c930a4a..d39e118 100644 --- a/framework-core/src/main/java/com/unionmed/framework/spring/mvc/filter/CrossFilter.java +++ b/framework-core/src/main/java/com/unionmed/framework/spring/mvc/filter/CrossFilter.java @@ -15,11 +15,11 @@ import java.io.IOException; public class CrossFilter extends OncePerRequestFilter { @Override - protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { - httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); - httpServletResponse.setHeader("Access-Control-Allow-Headers", "*"); - httpServletResponse.setHeader("Access-Control-Max-Age", "3600"); - httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,PUT"); - filterChain.doFilter(httpServletRequest, httpServletResponse); + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { + response.setHeader("Access-Control-Allow-Origin", "*"); + response.setHeader("Access-Control-Allow-Headers", "*"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,PUT"); + chain.doFilter(request, response); } } diff --git a/framework-core/src/main/java/com/unionmed/framework/spring/mvc/response/BodyCryptUtils.java b/framework-core/src/main/java/com/unionmed/framework/spring/mvc/response/BodyCryptUtils.java index 0825edf..c068ff1 100644 --- a/framework-core/src/main/java/com/unionmed/framework/spring/mvc/response/BodyCryptUtils.java +++ b/framework-core/src/main/java/com/unionmed/framework/spring/mvc/response/BodyCryptUtils.java @@ -1,6 +1,7 @@ package com.unionmed.framework.spring.mvc.response; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; import com.unionmed.framework.crypto.AES; import com.unionmed.framework.util.Converter; @@ -34,7 +35,7 @@ public final class BodyCryptUtils { } public static String encrypt(String sk, String iv, Object body) { - return iv + AES.encryptBase64String(sk, iv, isBasicType(body.getClass()) ? Converter.toString(body) : JSON.toJSONString(body)); + return iv + AES.encryptBase64String(sk, iv, isBasicType(body.getClass()) ? Converter.toString(body) : JSON.toJSONString(body, SerializerFeature.DisableCircularReferenceDetect)); } public static String decrypt(String sk, String body) { diff --git a/framework-core/src/main/java/com/unionmed/framework/util/IdCardUtils.java b/framework-core/src/main/java/com/unionmed/framework/util/IdCardUtils.java index df1ceb0..6859212 100644 --- a/framework-core/src/main/java/com/unionmed/framework/util/IdCardUtils.java +++ b/framework-core/src/main/java/com/unionmed/framework/util/IdCardUtils.java @@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; import java.sql.Timestamp; import java.time.LocalDate; +import java.time.LocalDateTime; /** * 身份证工具类 @@ -19,14 +20,20 @@ public class IdCardUtils { private Integer gender; // 性别(1-男,2-女) private Integer age; // 年龄(0:未满一年的婴儿) private Timestamp birthday; // 出生日期 + private boolean onYearBthOver; // 同年生日是否已过 private boolean babyFlag; // 是否婴儿标识(T-是,F-否) - // 以下默认值为-1,如果 !=-1 则表示已经计算过值了,不需要重新计算浪费CPU资源 - private int babyBirthMth = -1; // 宝宝出生余几个月(主要针对新生儿?如:0岁5个月 或 1岁3个月) - private int babyBirthDayOfMth = -1; // 宝宝出生余几天(主要针对新生儿?如:0岁2月零3天) - private int babyBirthWeek = -1; // 宝宝出生余几周(主要针对新生儿?如:0岁3周) - private int babyBirthDayOfWeek = -1; // 宝宝出生余N天(主要针对新生儿如?:3周零2天) + // 以下默认值为-1,如果 !=-1 则表示已经计算过值了,不需要重新计算 + private int birthMth = -1; // 出生余几个月(如:0岁5个月 或 1岁3个月) + private int birthDayOfMth = -1; // 出生余几天(如:0岁2月零3天) + private int birthWeek = -1; // 出生余几周(如:0岁3周) + private int birthDayOfWeek = -1; // 出生余N天(如:3周零2天) + /** + * 性别(1-男,2-女) + * + * @return + */ public int getGender() { return gender; } @@ -71,7 +78,12 @@ public class IdCardUtils { return birthday == null ? null : DateUtils.toString(birthday, format); } - public boolean isBabyFlag() { + /** + * 是否婴儿(true: 未满一周岁) + * + * @return + */ + public boolean isBaby() { return babyFlag; } @@ -80,18 +92,19 @@ public class IdCardUtils { * * @return N月 */ - public int getBabyBirthMth() { - if (babyBirthMth != -1) { - return babyBirthMth; + public int getBirthMth() { + if (birthMth != -1) { + return birthMth; } LocalDate bth = birthday.toLocalDateTime().toLocalDate(); LocalDate ld = LocalDate.now(); - babyBirthMth = ld.getMonthValue() - bth.getMonthValue(); - if (babyBirthMth > 0 && ld.getDayOfMonth() < bth.getDayOfMonth()) { - babyBirthMth--; + + birthMth = ld.getMonthValue() - bth.getMonthValue(); + if (birthMth < 0) { + birthMth = 12 + birthMth; } - return babyBirthMth; + return birthMth; } /** @@ -99,12 +112,11 @@ public class IdCardUtils { * * @return N周 */ - public int getBabyBirthWeekOfYear() { - if (babyBirthWeek != -1) { - return babyBirthWeek; + public int getBirthWeekOfYear() { + if (birthWeek < 0) { + birthWeek = (int) ((DateUtils.toMillis(LocalDate.now()) - DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).toLocalDate())) / DateUtils.getWeekMillis()); } - babyBirthWeek = (int) ((DateUtils.toMillis(LocalDate.now()) - DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).toLocalDate())) / DateUtils.getWeekMillis()); - return babyBirthWeek; + return birthWeek; } /** @@ -112,8 +124,8 @@ public class IdCardUtils { * * @return N周 */ - public int getBabyBirthWeekOfMth() { - return (int) ((DateUtils.toMillis(LocalDate.now()) - DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBabyBirthMth()).toLocalDate())) / DateUtils.getWeekMillis()); + public int getBirthWeekOfMth() { + return (int) ((DateUtils.toMillis(LocalDate.now()) - DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBirthMth()).toLocalDate())) / DateUtils.getWeekMillis()); } /** @@ -121,17 +133,24 @@ public class IdCardUtils { * * @return N天 */ - public int getBabyBirthDayOfMonth() { - if (babyBirthDayOfMth != -1) { - return babyBirthDayOfMth; + public int getBirthDayOfMonth() { + if (birthDayOfMth != -1) { + return birthDayOfMth; } LocalDate ld = LocalDate.now(); - LocalDate mth = birthday.toLocalDateTime().plusYears(age).plusMonths(getBabyBirthMth()).toLocalDate(); - int i = 1; - for (; mth.plusDays(i).isBefore(ld); i++) ; + if (onYearBthOver) { + LocalDateTime dateTime = birthday.toLocalDateTime(); + if (ld.getMonthValue() == dateTime.getMonthValue()) { + birthDayOfMth = ld.getDayOfMonth() - dateTime.getDayOfMonth(); + } + } + + if (birthDayOfMth < 0) { + birthDayOfMth = ld.getDayOfMonth(); + } - return babyBirthDayOfMth = i; + return birthDayOfMth; } /** @@ -139,12 +158,12 @@ public class IdCardUtils { * * @return N天 */ - public int getBabyBirthDayOfWeek() { - if (babyBirthDayOfWeek != -1) return babyBirthDayOfWeek; - long bthMills = DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBabyBirthMth()).plusWeeks(getBabyBirthWeekOfMth())); - babyBirthDayOfWeek = (int) ((DateUtils.toMillis(LocalDate.now()) - bthMills) / DateUtils.getDayMillis()); - if (babyBirthDayOfWeek > 0) babyBirthDayOfWeek++; - return babyBirthDayOfWeek; + public int getBirthDayOfWeek() { + if (birthDayOfWeek != -1) return birthDayOfWeek; + long bthMills = DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBirthMth()).plusWeeks(getBirthWeekOfMth())); + birthDayOfWeek = (int) ((DateUtils.toMillis(LocalDate.now()) - bthMills) / DateUtils.getDayMillis()); + if (birthDayOfWeek > 0) birthDayOfWeek++; + return birthDayOfWeek; } } @@ -178,23 +197,22 @@ public class IdCardUtils { idCard.gender = Integer.valueOf(chars[genderIdx] + "") % 2 == 0 ? 2 : 1; LocalDate today = DateUtils.now().toLocalDateTime().toLocalDate(); - int todayYear = today.getYear(); - idCard.age = todayYear - bth.getYear(); + int onYear = today.getYear(); + idCard.age = onYear - bth.getYear(); if (idCard.age > 0) { - LocalDate dateTime = bth.withYear(todayYear); - if (today.compareTo(dateTime) < 0) { + if (idCard.onYearBthOver = today.compareTo(bth.withYear(onYear)) < 0) { idCard.age--; // 生日未到,年龄减一 } } else { idCard.babyFlag = true; - idCard.babyBirthMth = today.getMonthValue() - bth.getMonthValue(); - if (idCard.babyBirthMth > 0 && today.getDayOfMonth() > bth.getDayOfMonth()) { - idCard.babyBirthMth--; + idCard.birthMth = today.getMonthValue() - bth.getMonthValue(); + if (idCard.birthMth > 0 && today.getDayOfMonth() > bth.getDayOfMonth()) { + idCard.birthMth--; } - LocalDate mth = bth.withMonth(idCard.babyBirthMth); + LocalDate mth = bth.withMonth(idCard.birthMth); int i = 1; for (; mth.plusDays(i).isBefore(today); i++) ; - idCard.babyBirthDayOfMth = i; + idCard.birthDayOfMth = i; } return idCard; diff --git a/framework-orm/pom.xml b/framework-orm/pom.xml index 843c178..26c85fa 100644 --- a/framework-orm/pom.xml +++ b/framework-orm/pom.xml @@ -5,7 +5,7 @@ unionmed-framework com.unionmed - 0.0.19 + 0.0.21 4.0.0 diff --git a/framework-test/pom.xml b/framework-test/pom.xml index 8d9c114..3fb9ba0 100644 --- a/framework-test/pom.xml +++ b/framework-test/pom.xml @@ -5,7 +5,7 @@ com.unionmed unionmed-framework - 0.0.19 + 0.0.21 4.0.0 diff --git a/pom.xml b/pom.xml index 7e259bd..236b897 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 com.unionmed unionmed-framework - 0.0.19 + 0.0.21 pom unionmed-framework