病人信息
This commit is contained in:
@@ -569,4 +569,21 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
|||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拼接多个字符串,忽略null值。
|
||||||
|
* @param parts 可变参数,可以传入任意数量的字符串
|
||||||
|
* @return 拼接后的完整字符串
|
||||||
|
*/
|
||||||
|
public static String joinStrings(String... parts) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (String part : parts) {
|
||||||
|
if (part != null) { // 忽略null值
|
||||||
|
result.append(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -106,6 +106,8 @@ public class SecurityConfig {
|
|||||||
.permitAll()
|
.permitAll()
|
||||||
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**")
|
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**")
|
||||||
.permitAll()
|
.permitAll()
|
||||||
|
.antMatchers("/patientmanage/information/**")
|
||||||
|
.permitAll()
|
||||||
// 除上面外的所有请求全部需要鉴权认证
|
// 除上面外的所有请求全部需要鉴权认证
|
||||||
.anyRequest().authenticated();
|
.anyRequest().authenticated();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package com.openhis.web.patientmanage.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.core.common.core.domain.R;
|
||||||
|
import com.core.common.enums.AssignSeqEnum;
|
||||||
|
import com.core.common.utils.AssignSeqUtil;
|
||||||
|
import com.core.common.utils.ChineseConvertUtils;
|
||||||
|
import com.core.common.utils.MessageUtils;
|
||||||
|
import com.core.common.utils.StringUtils;
|
||||||
|
import com.core.common.utils.bean.BeanUtils;
|
||||||
|
import com.openhis.administration.domain.Patient;
|
||||||
|
import com.openhis.administration.service.IPatientService;
|
||||||
|
import com.openhis.common.constant.PromptMsgConstant;
|
||||||
|
import com.openhis.web.patientmanage.dto.PatientInformationDto;
|
||||||
|
import com.openhis.web.patientmanage.mapper.PatientManageMapper;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病人管理——病人信息
|
||||||
|
*
|
||||||
|
* @author liuhr
|
||||||
|
* @date 2025/2/22
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/patientmanage/information")
|
||||||
|
@Slf4j
|
||||||
|
public class PatientInformationController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IPatientService patientService;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
private AssignSeqUtil assignSeqUtil;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
PatientManageMapper patientManageMapper;
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
StringUtils stringUtils;
|
||||||
|
|
||||||
|
// todo 暂且机构ID写死,后续从登录里取得
|
||||||
|
private final Long organizationId = 91L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加病人信息
|
||||||
|
*
|
||||||
|
* @param patientInformationDto 病人信息
|
||||||
|
*/
|
||||||
|
@PostMapping("/patient-information")
|
||||||
|
public R<?> addPatient(@Validated @RequestBody PatientInformationDto patientInformationDto) {
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
BeanUtils.copyProperties(patientInformationDto, patient);
|
||||||
|
|
||||||
|
// 使用基础采番,设置病人ID
|
||||||
|
String code = assignSeqUtil.getSeq(AssignSeqEnum.PATIENT_NUM.getPrefix());
|
||||||
|
patient.setBusNo(code);
|
||||||
|
// 设置生日
|
||||||
|
patient.setBirthDate(patientService.extractBirthday(patient.getIdCard()));
|
||||||
|
// 设置机构ID
|
||||||
|
patient.setOrganizationId(organizationId);
|
||||||
|
// 设置拼音首拼
|
||||||
|
patient.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(patient.getName()));
|
||||||
|
// 设置五笔首拼
|
||||||
|
patient.setWbStr(ChineseConvertUtils.toWBFirstLetter(patient.getName()));
|
||||||
|
// 设置地址
|
||||||
|
String fullAddress = stringUtils.joinStrings(patient.getAddressProvince(), patient.getAddressCity(),
|
||||||
|
patient.getAddressDistrict(), patient.getAddressStreet());
|
||||||
|
patient.setAddress(fullAddress);
|
||||||
|
|
||||||
|
// 调用服务层保存病人信息
|
||||||
|
boolean savePatientSuccess = patientService.save(patient);
|
||||||
|
|
||||||
|
if (!savePatientSuccess) {
|
||||||
|
return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00003, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00001, new Object[] {"病人信息"}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改病人信息
|
||||||
|
*
|
||||||
|
* @param patientInformationDto 病人信息
|
||||||
|
*/
|
||||||
|
@PutMapping("/patient-information")
|
||||||
|
public R<?> editPatient(@Validated @RequestBody PatientInformationDto patientInformationDto) {
|
||||||
|
|
||||||
|
Patient patient = new Patient();
|
||||||
|
BeanUtils.copyProperties(patientInformationDto, patient);
|
||||||
|
|
||||||
|
// 设置生日
|
||||||
|
patient.setBirthDate(patientService.extractBirthday(patient.getIdCard()));
|
||||||
|
// 设置拼音首拼
|
||||||
|
patient.setPyStr(ChineseConvertUtils.toPinyinFirstLetter(patient.getName()));
|
||||||
|
// 设置五笔首拼
|
||||||
|
patient.setWbStr(ChineseConvertUtils.toWBFirstLetter(patient.getName()));
|
||||||
|
// 设置地址
|
||||||
|
String fullAddress = stringUtils.joinStrings(patient.getAddressProvince(), patient.getAddressCity(),
|
||||||
|
patient.getAddressDistrict(), patient.getAddressStreet());
|
||||||
|
patient.setAddress(fullAddress);
|
||||||
|
|
||||||
|
// 调用服务层更新病人信息
|
||||||
|
boolean updateSuccess = patientService.updateById(patient);
|
||||||
|
|
||||||
|
if (!updateSuccess) {
|
||||||
|
return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002, new Object[] {"病人信息"}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除病人信息
|
||||||
|
*
|
||||||
|
* @param id 主表id
|
||||||
|
*/
|
||||||
|
// todo 删除需要么?或者逻辑删除后续再改
|
||||||
|
@DeleteMapping("/patient-information")
|
||||||
|
public R<?> deletePatient(@RequestParam Long id) {
|
||||||
|
|
||||||
|
boolean deleteSuccess = patientService.removeById(id);
|
||||||
|
|
||||||
|
if (!deleteSuccess) {
|
||||||
|
return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00007, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00005, new Object[] {"病人信息"}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询病人信息,可选条件
|
||||||
|
*
|
||||||
|
* @param busNo 病人ID(可选)
|
||||||
|
* @param name 病人姓名(可选)
|
||||||
|
* @param pageNo 页码(默认为1)
|
||||||
|
* @param pageSize 每页大小(默认为10)
|
||||||
|
*/
|
||||||
|
@GetMapping("/patient-information-page")
|
||||||
|
public R<?> getPatient(@RequestParam(required = false) String busNo, @RequestParam(required = false) String name,
|
||||||
|
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
|
||||||
|
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||||
|
|
||||||
|
// 跳过的记录数
|
||||||
|
Integer offset = (pageNo - 1) * pageSize;
|
||||||
|
// 连表查询患者信息
|
||||||
|
List<PatientInformationDto> listPatients = patientManageMapper.getPatientPage(busNo, name, pageSize, offset);
|
||||||
|
// 查询总记录数
|
||||||
|
long total = patientManageMapper.countPatients(busNo, name);
|
||||||
|
// 创建Page对象并设置属性
|
||||||
|
Page<PatientInformationDto> patientInformationPage = new Page<>(pageNo, pageSize, total);
|
||||||
|
patientInformationPage.setRecords(listPatients);
|
||||||
|
|
||||||
|
if (patientInformationPage == null || patientInformationPage.getRecords().isEmpty()) {
|
||||||
|
return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00006, null));
|
||||||
|
}
|
||||||
|
return R.ok(patientInformationPage,
|
||||||
|
MessageUtils.createMessage(PromptMsgConstant.Common.M00009, new Object[] {"病人信息"}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package com.openhis.web.patientmanage.dto;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import com.openhis.common.enums.AdministrativeGender;
|
||||||
|
import com.openhis.common.enums.MaritalStatus;
|
||||||
|
import com.openhis.common.enums.OccupationType;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病人信息Dto
|
||||||
|
*
|
||||||
|
* @author liuhr
|
||||||
|
* @date 2025/2/22
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PatientInformationDto {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 活动标记 */
|
||||||
|
private Integer activeFlag;
|
||||||
|
|
||||||
|
/** 临时标识 */
|
||||||
|
private Integer tempFlag;
|
||||||
|
|
||||||
|
/** 患者姓名 */
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/** 患者其他名称 */
|
||||||
|
private String nameJson;
|
||||||
|
|
||||||
|
/** 患者院内编码/病历号 */
|
||||||
|
private String busNo;
|
||||||
|
|
||||||
|
/** 性别编码 */
|
||||||
|
private AdministrativeGender genderEnum;
|
||||||
|
|
||||||
|
/** 生日 */
|
||||||
|
private Date birthDate;
|
||||||
|
|
||||||
|
/** 死亡时间 */
|
||||||
|
private Date deceasedDate;
|
||||||
|
|
||||||
|
/** 婚姻状态 */
|
||||||
|
private MaritalStatus maritalStatusEnum;
|
||||||
|
|
||||||
|
/** 职业编码 */
|
||||||
|
private OccupationType prfsEnum;
|
||||||
|
|
||||||
|
/** 电话 */
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/** 地址 */
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
/** 地址省 */
|
||||||
|
private String addressProvince;
|
||||||
|
|
||||||
|
/** 地址市 */
|
||||||
|
private String addressCity;
|
||||||
|
|
||||||
|
/** 地址区 */
|
||||||
|
private String addressDistrict;
|
||||||
|
|
||||||
|
/** 地址街道 */
|
||||||
|
private String addressStreet;
|
||||||
|
|
||||||
|
/** 患者其他地址 */
|
||||||
|
private String addressJson;
|
||||||
|
|
||||||
|
/** 民族 */
|
||||||
|
private String nationalityCode;
|
||||||
|
|
||||||
|
/** 身份证号 */
|
||||||
|
private String idCard;
|
||||||
|
|
||||||
|
/** 拼音码 */
|
||||||
|
private String pyStr;
|
||||||
|
|
||||||
|
/** 五笔码 */
|
||||||
|
private String wbStr;
|
||||||
|
|
||||||
|
/** 血型ABO */
|
||||||
|
private String bloodAbo;
|
||||||
|
|
||||||
|
/** 血型RH */
|
||||||
|
private String bloodRh;
|
||||||
|
|
||||||
|
/** 工作单位 */
|
||||||
|
private String workCompany;
|
||||||
|
|
||||||
|
/** 籍贯 */
|
||||||
|
private String nativePlace;
|
||||||
|
|
||||||
|
/** 国家编码 */
|
||||||
|
private String countryCode;
|
||||||
|
|
||||||
|
/** 联系人 */
|
||||||
|
private String linkName;
|
||||||
|
|
||||||
|
/** 联系人关系 */
|
||||||
|
private Integer linkRelationCode;
|
||||||
|
|
||||||
|
/** 联系人电话 */
|
||||||
|
private String linkTelcom;
|
||||||
|
|
||||||
|
/** 其他联系人 */
|
||||||
|
private String linkJsons;
|
||||||
|
|
||||||
|
/** 机构Id */
|
||||||
|
private Long organizationId;
|
||||||
|
|
||||||
|
/** 机构名 */
|
||||||
|
private String organizationName;
|
||||||
|
|
||||||
|
/** 创建时间 */
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/** 删除标识 */
|
||||||
|
// 0 为未删除,1 为删除
|
||||||
|
private String deleteFlag;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.openhis.web.patientmanage.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.openhis.administration.domain.Patient;
|
||||||
|
import com.openhis.web.patientmanage.dto.PatientInformationDto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病人信息管理
|
||||||
|
*
|
||||||
|
* @author Wuser
|
||||||
|
* @date 2025/2/25
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface PatientManageMapper extends BaseMapper<Patient> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病人信息分页查询
|
||||||
|
*
|
||||||
|
* @param busNo 病人ID
|
||||||
|
* @param name 病人姓名
|
||||||
|
* @param pageSize 页面大小
|
||||||
|
* @param offset 跳过条数
|
||||||
|
* @return 分页查询
|
||||||
|
*/
|
||||||
|
List<PatientInformationDto> getPatientPage(@Param("busNo") String busNo, @Param("name") String name,
|
||||||
|
@Param("pageSize") Integer pageSize, @Param("offset") Integer offset);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计总记录数的方法
|
||||||
|
*
|
||||||
|
* @param busNo 病人ID
|
||||||
|
* @param name 病人姓名
|
||||||
|
* @return 分页查询
|
||||||
|
*/
|
||||||
|
long countPatients(@Param("busNo") String busNo, @Param("name") String name);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.openhis.web.patientmanage.mapper.PatientManageMapper">
|
||||||
|
<select id="getPatientPage" resultType="com.openhis.web.patientmanage.dto.PatientInformationDto">
|
||||||
|
SELECT
|
||||||
|
pt.id,
|
||||||
|
pt.active_flag,
|
||||||
|
pt.temp_flag,
|
||||||
|
pt.name,
|
||||||
|
pt.name_json,
|
||||||
|
pt.bus_no,
|
||||||
|
pt.gender_enum,
|
||||||
|
pt.birth_date,
|
||||||
|
pt.deceased_date,
|
||||||
|
pt.marital_status_enum,
|
||||||
|
pt.prfs_enum,
|
||||||
|
pt.phone,
|
||||||
|
pt.address,
|
||||||
|
pt.address_province,
|
||||||
|
pt.address_city,
|
||||||
|
pt.address_district,
|
||||||
|
pt.address_street,
|
||||||
|
pt.address_json,
|
||||||
|
pt.nationality_code,
|
||||||
|
pt.id_card,
|
||||||
|
pt.py_str,
|
||||||
|
pt.wb_str,
|
||||||
|
pt.blood_abo,
|
||||||
|
pt.blood_rh,
|
||||||
|
pt.work_company,
|
||||||
|
pt.native_place,
|
||||||
|
pt.country_code,
|
||||||
|
pt.link_name,
|
||||||
|
pt.link_relation_code,
|
||||||
|
pt.link_telcom,
|
||||||
|
pt.link_jsons,
|
||||||
|
pt.organization_id,
|
||||||
|
pt.create_time
|
||||||
|
FROM adm_patient pt
|
||||||
|
<!-- 类型不一致,把organization_id转换成字符串类型-->
|
||||||
|
LEFT JOIN adm_organization ogt ON CAST(pt.organization_id AS VARCHAR) = ogt.bus_no
|
||||||
|
<where>
|
||||||
|
<!-- 如果传入busNo参数,且不为空 -->
|
||||||
|
<if test="busNo != null and busNo != ''">
|
||||||
|
AND busNo LIKE CONCAT(#{busNo}, '%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<!-- 如果传入name参数,且不为空 -->
|
||||||
|
<if test="name != null and name != ''">
|
||||||
|
AND name LIKE CONCAT(#{name}, '%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY pt.bus_no
|
||||||
|
LIMIT #{pageSize} OFFSET #{offset}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="countPatients" resultType="long">
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM adm_patient pt
|
||||||
|
<!-- 类型不一致,把organization_id转换成字符串类型-->
|
||||||
|
LEFT JOIN adm_organization ogt ON CAST(pt.organization_id AS VARCHAR) = ogt.bus_no
|
||||||
|
<where>
|
||||||
|
<!-- 如果传入busNo参数,且不为空 -->
|
||||||
|
<if test="busNo != null and busNo != ''">
|
||||||
|
AND busNo LIKE CONCAT(#{busNo}, '%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<!-- 如果传入name参数,且不为空 -->
|
||||||
|
<if test="name != null and name != ''">
|
||||||
|
AND name LIKE CONCAT(#{name}, '%')
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.openhis.administration.service;
|
package com.openhis.administration.service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.openhis.administration.domain.Patient;
|
import com.openhis.administration.domain.Patient;
|
||||||
|
|
||||||
@@ -11,4 +13,11 @@ import com.openhis.administration.domain.Patient;
|
|||||||
*/
|
*/
|
||||||
public interface IPatientService extends IService<Patient> {
|
public interface IPatientService extends IService<Patient> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从身份证号码中提取生日
|
||||||
|
*
|
||||||
|
* @param idCard 身份证号
|
||||||
|
* @return 出生日
|
||||||
|
*/
|
||||||
|
Date extractBirthday(String idCard);
|
||||||
}
|
}
|
||||||
@@ -54,14 +54,14 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Org
|
|||||||
/**
|
/**
|
||||||
* 通过机构ID查询机构名称
|
* 通过机构ID查询机构名称
|
||||||
*
|
*
|
||||||
* @param code 机构ID
|
* @param busNo 机构ID
|
||||||
* @return 机构名称
|
* @return 机构名称
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Organization getByCode(String code) {
|
public Organization getByBusNo(String busNo) {
|
||||||
QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
|
||||||
// 设置查询条件为机构Id code
|
// 设置查询条件为机构Id code
|
||||||
queryWrapper.eq("code", code);
|
queryWrapper.eq("bus_no", busNo);
|
||||||
return organizationMapper.selectOne(queryWrapper);
|
return organizationMapper.selectOne(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package com.openhis.administration.service.impl;
|
package com.openhis.administration.service.impl;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -16,4 +22,25 @@ import com.openhis.administration.service.IPatientService;
|
|||||||
@Service
|
@Service
|
||||||
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements IPatientService {
|
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements IPatientService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从身份证号码中提取生日
|
||||||
|
*
|
||||||
|
* @param idCard 身份证号
|
||||||
|
* @return 出生日
|
||||||
|
*/
|
||||||
|
public Date extractBirthday(String idCard) {
|
||||||
|
if (idCard == null) {
|
||||||
|
// 身份证号码为空
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取第7到14位作为生日字符串
|
||||||
|
String birthdayStr = idCard.substring(6, 14);
|
||||||
|
// 将生日字符串转换为 LocalDate
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||||
|
LocalDate date = LocalDate.parse(birthdayStr, formatter);
|
||||||
|
// 使用系统默认时区,将 LocalDate 转换为 Date
|
||||||
|
return Date.from(Instant.from(date.atStartOfDay(ZoneId.systemDefault())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user