1. 代码更新

master
陈峰 1 year ago
parent f7f4a43821
commit f514a5703f
  1. 2
      framework-core/pom.xml
  2. 12
      framework-core/src/main/java/com/unionmed/framework/spring/mvc/filter/CrossFilter.java
  3. 3
      framework-core/src/main/java/com/unionmed/framework/spring/mvc/response/BodyCryptUtils.java
  4. 102
      framework-core/src/main/java/com/unionmed/framework/util/IdCardUtils.java
  5. 2
      framework-orm/pom.xml
  6. 2
      framework-test/pom.xml
  7. 2
      pom.xml

@ -5,7 +5,7 @@
<parent>
<groupId>com.unionmed</groupId>
<artifactId>unionmed-framework</artifactId>
<version>0.0.19</version>
<version>0.0.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -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);
}
}

@ -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) {

@ -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;

@ -5,7 +5,7 @@
<parent>
<artifactId>unionmed-framework</artifactId>
<groupId>com.unionmed</groupId>
<version>0.0.19</version>
<version>0.0.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent>
<groupId>com.unionmed</groupId>
<artifactId>unionmed-framework</artifactId>
<version>0.0.19</version>
<version>0.0.21</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -9,7 +9,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.unionmed</groupId>
<artifactId>unionmed-framework</artifactId>
<version>0.0.19</version>
<version>0.0.21</version>
<packaging>pom</packaging>
<name>unionmed-framework</name>

Loading…
Cancel
Save