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> <parent>
<groupId>com.unionmed</groupId> <groupId>com.unionmed</groupId>
<artifactId>unionmed-framework</artifactId> <artifactId>unionmed-framework</artifactId>
<version>0.0.19</version> <version>0.0.21</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

@ -15,11 +15,11 @@ import java.io.IOException;
public class CrossFilter extends OncePerRequestFilter { public class CrossFilter extends OncePerRequestFilter {
@Override @Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Origin", "*");
httpServletResponse.setHeader("Access-Control-Allow-Headers", "*"); response.setHeader("Access-Control-Allow-Headers", "*");
httpServletResponse.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Max-Age", "3600");
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,PUT"); response.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,PUT");
filterChain.doFilter(httpServletRequest, httpServletResponse); chain.doFilter(request, response);
} }
} }

@ -1,6 +1,7 @@
package com.unionmed.framework.spring.mvc.response; package com.unionmed.framework.spring.mvc.response;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.unionmed.framework.crypto.AES; import com.unionmed.framework.crypto.AES;
import com.unionmed.framework.util.Converter; import com.unionmed.framework.util.Converter;
@ -34,7 +35,7 @@ public final class BodyCryptUtils {
} }
public static String encrypt(String sk, String iv, Object body) { 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) { public static String decrypt(String sk, String body) {

@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
/** /**
* 身份证工具类 * 身份证工具类
@ -19,14 +20,20 @@ public class IdCardUtils {
private Integer gender; // 性别(1-男,2-女) private Integer gender; // 性别(1-男,2-女)
private Integer age; // 年龄(0:未满一年的婴儿) private Integer age; // 年龄(0:未满一年的婴儿)
private Timestamp birthday; // 出生日期 private Timestamp birthday; // 出生日期
private boolean onYearBthOver; // 同年生日是否已过
private boolean babyFlag; // 是否婴儿标识(T-是,F-否) private boolean babyFlag; // 是否婴儿标识(T-是,F-否)
// 以下默认值为-1,如果 !=-1 则表示已经计算过值了,不需要重新计算浪费CPU资源 // 以下默认值为-1,如果 !=-1 则表示已经计算过值了,不需要重新计算
private int babyBirthMth = -1; // 宝宝出生余几个月(主要针对新生儿?如:0岁5个月 或 1岁3个月) private int birthMth = -1; // 出生余几个月(如:0岁5个月 或 1岁3个月)
private int babyBirthDayOfMth = -1; // 宝宝出生余几天(主要针对新生儿?如:0岁2月零3天) private int birthDayOfMth = -1; // 出生余几天(如:0岁2月零3天)
private int babyBirthWeek = -1; // 宝宝出生余几周(主要针对新生儿?如:0岁3周) private int birthWeek = -1; // 出生余几周(如:0岁3周)
private int babyBirthDayOfWeek = -1; // 宝宝出生余N天(主要针对新生儿:3周零2天) private int birthDayOfWeek = -1; // 出生余N天(如:3周零2天)
/**
* 性别(1-,2-)
*
* @return
*/
public int getGender() { public int getGender() {
return gender; return gender;
} }
@ -71,7 +78,12 @@ public class IdCardUtils {
return birthday == null ? null : DateUtils.toString(birthday, format); return birthday == null ? null : DateUtils.toString(birthday, format);
} }
public boolean isBabyFlag() { /**
* 是否婴儿true: 未满一周岁
*
* @return
*/
public boolean isBaby() {
return babyFlag; return babyFlag;
} }
@ -80,18 +92,19 @@ public class IdCardUtils {
* *
* @return N月 * @return N月
*/ */
public int getBabyBirthMth() { public int getBirthMth() {
if (babyBirthMth != -1) { if (birthMth != -1) {
return babyBirthMth; return birthMth;
} }
LocalDate bth = birthday.toLocalDateTime().toLocalDate(); LocalDate bth = birthday.toLocalDateTime().toLocalDate();
LocalDate ld = LocalDate.now(); LocalDate ld = LocalDate.now();
babyBirthMth = ld.getMonthValue() - bth.getMonthValue();
if (babyBirthMth > 0 && ld.getDayOfMonth() < bth.getDayOfMonth()) { birthMth = ld.getMonthValue() - bth.getMonthValue();
babyBirthMth--; if (birthMth < 0) {
birthMth = 12 + birthMth;
} }
return babyBirthMth; return birthMth;
} }
/** /**
@ -99,12 +112,11 @@ public class IdCardUtils {
* *
* @return N周 * @return N周
*/ */
public int getBabyBirthWeekOfYear() { public int getBirthWeekOfYear() {
if (babyBirthWeek != -1) { if (birthWeek < 0) {
return babyBirthWeek; 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 birthWeek;
return babyBirthWeek;
} }
/** /**
@ -112,8 +124,8 @@ public class IdCardUtils {
* *
* @return N周 * @return N周
*/ */
public int getBabyBirthWeekOfMth() { public int getBirthWeekOfMth() {
return (int) ((DateUtils.toMillis(LocalDate.now()) - DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBabyBirthMth()).toLocalDate())) / DateUtils.getWeekMillis()); 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天 * @return N天
*/ */
public int getBabyBirthDayOfMonth() { public int getBirthDayOfMonth() {
if (babyBirthDayOfMth != -1) { if (birthDayOfMth != -1) {
return babyBirthDayOfMth; return birthDayOfMth;
} }
LocalDate ld = LocalDate.now(); LocalDate ld = LocalDate.now();
LocalDate mth = birthday.toLocalDateTime().plusYears(age).plusMonths(getBabyBirthMth()).toLocalDate(); if (onYearBthOver) {
int i = 1; LocalDateTime dateTime = birthday.toLocalDateTime();
for (; mth.plusDays(i).isBefore(ld); i++) ; 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天 * @return N天
*/ */
public int getBabyBirthDayOfWeek() { public int getBirthDayOfWeek() {
if (babyBirthDayOfWeek != -1) return babyBirthDayOfWeek; if (birthDayOfWeek != -1) return birthDayOfWeek;
long bthMills = DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBabyBirthMth()).plusWeeks(getBabyBirthWeekOfMth())); long bthMills = DateUtils.toMillis(birthday.toLocalDateTime().plusYears(age).plusMonths(getBirthMth()).plusWeeks(getBirthWeekOfMth()));
babyBirthDayOfWeek = (int) ((DateUtils.toMillis(LocalDate.now()) - bthMills) / DateUtils.getDayMillis()); birthDayOfWeek = (int) ((DateUtils.toMillis(LocalDate.now()) - bthMills) / DateUtils.getDayMillis());
if (babyBirthDayOfWeek > 0) babyBirthDayOfWeek++; if (birthDayOfWeek > 0) birthDayOfWeek++;
return babyBirthDayOfWeek; return birthDayOfWeek;
} }
} }
@ -178,23 +197,22 @@ public class IdCardUtils {
idCard.gender = Integer.valueOf(chars[genderIdx] + "") % 2 == 0 ? 2 : 1; idCard.gender = Integer.valueOf(chars[genderIdx] + "") % 2 == 0 ? 2 : 1;
LocalDate today = DateUtils.now().toLocalDateTime().toLocalDate(); LocalDate today = DateUtils.now().toLocalDateTime().toLocalDate();
int todayYear = today.getYear(); int onYear = today.getYear();
idCard.age = todayYear - bth.getYear(); idCard.age = onYear - bth.getYear();
if (idCard.age > 0) { if (idCard.age > 0) {
LocalDate dateTime = bth.withYear(todayYear); if (idCard.onYearBthOver = today.compareTo(bth.withYear(onYear)) < 0) {
if (today.compareTo(dateTime) < 0) {
idCard.age--; // 生日未到,年龄减一 idCard.age--; // 生日未到,年龄减一
} }
} else { } else {
idCard.babyFlag = true; idCard.babyFlag = true;
idCard.babyBirthMth = today.getMonthValue() - bth.getMonthValue(); idCard.birthMth = today.getMonthValue() - bth.getMonthValue();
if (idCard.babyBirthMth > 0 && today.getDayOfMonth() > bth.getDayOfMonth()) { if (idCard.birthMth > 0 && today.getDayOfMonth() > bth.getDayOfMonth()) {
idCard.babyBirthMth--; idCard.birthMth--;
} }
LocalDate mth = bth.withMonth(idCard.babyBirthMth); LocalDate mth = bth.withMonth(idCard.birthMth);
int i = 1; int i = 1;
for (; mth.plusDays(i).isBefore(today); i++) ; for (; mth.plusDays(i).isBefore(today); i++) ;
idCard.babyBirthDayOfMth = i; idCard.birthDayOfMth = i;
} }
return idCard; return idCard;

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

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

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

Loading…
Cancel
Save