|
@@ -30,7 +30,9 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
|
|
+import java.time.Period;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.time.format.DateTimeParseException;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -100,6 +102,8 @@ public class PatientController extends AppBaseController {
|
|
|
if(0 != idCardVerificationResponse.getResult()){
|
|
if(0 != idCardVerificationResponse.getResult()){
|
|
|
throw new CustomException(idCardVerificationResponse.getDescription());
|
|
throw new CustomException(idCardVerificationResponse.getDescription());
|
|
|
}
|
|
}
|
|
|
|
|
+ // 校验出生年月与身份证是否一致 + 年龄满18周岁
|
|
|
|
|
+ validateBirthdayAndAge(idCardNumber, param.getBirthday());
|
|
|
}
|
|
}
|
|
|
FsPatient patient=new FsPatient();
|
|
FsPatient patient=new FsPatient();
|
|
|
BeanUtil.copyProperties(param, patient);
|
|
BeanUtil.copyProperties(param, patient);
|
|
@@ -126,6 +130,8 @@ public class PatientController extends AppBaseController {
|
|
|
if(0 != idCardVerificationResponse.getResult()){
|
|
if(0 != idCardVerificationResponse.getResult()){
|
|
|
throw new CustomException(idCardVerificationResponse.getDescription());
|
|
throw new CustomException(idCardVerificationResponse.getDescription());
|
|
|
}
|
|
}
|
|
|
|
|
+ // 校验出生年月与身份证是否一致 + 年龄满18周岁
|
|
|
|
|
+ validateBirthdayAndAge(idCardNumber, param.getBirthday());
|
|
|
}
|
|
}
|
|
|
FsPatient patient=new FsPatient();
|
|
FsPatient patient=new FsPatient();
|
|
|
BeanUtil.copyProperties(param, patient);
|
|
BeanUtil.copyProperties(param, patient);
|
|
@@ -141,5 +147,35 @@ public class PatientController extends AppBaseController {
|
|
|
return R.ok("操作成功");
|
|
return R.ok("操作成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验出生年月与身份证号是否一致,以及年龄是否满18周岁
|
|
|
|
|
+ * @param idCard 身份证号
|
|
|
|
|
+ * @param birthday 出生年月
|
|
|
|
|
+ */
|
|
|
|
|
+ private void validateBirthdayAndAge(String idCard, Date birthday) {
|
|
|
|
|
+ if (StringUtils.isBlank(idCard) || birthday == null) {
|
|
|
|
|
+ throw new CustomException("身份证和出生年月为必填项");
|
|
|
|
|
+ }
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
+ // 从身份证提取出生日期(第7-14位:yyyyMMdd)
|
|
|
|
|
+ String idCardBirthday = idCard.substring(6, 14);
|
|
|
|
|
+ String birthdayStr = sdf.format(birthday);
|
|
|
|
|
+ // 比较出生年月是否一致
|
|
|
|
|
+ if (!idCardBirthday.equals(birthdayStr)) {
|
|
|
|
|
+ throw new CustomException("出生年月与身份证不一致请核对");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 校验年龄是否满18周岁(差一天也不行)
|
|
|
|
|
+ try {
|
|
|
|
|
+ LocalDate birthDate = LocalDate.parse(idCardBirthday, DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
|
|
+ Period period = Period.between(birthDate, now);
|
|
|
|
|
+ if (period.getYears() < 18) {
|
|
|
|
|
+ throw new CustomException("检测到您为未成年人,禁止独立购买处方药,请由监护人登录账号下单");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (DateTimeParseException e) {
|
|
|
|
|
+ throw new CustomException("出生日期格式不正确");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|