Files
yinyitong-zhongyuyuan-dll-hang/src/main/java/com/dpkj/modules/cardReader/utils/UserInfoVO.java

74 lines
2.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.dpkj.modules.cardReader.utils;
import com.dpkj.common.exception.RRException;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.function.Consumer;
@Data
public class UserInfoVO {
// 姓名
private String name;
// 性别
private String sex;
// 民族
private String nation;
// 出生年月
private String born;
// 地址
private String address;
// 身份证号
private String IDCardNo;
// 签发机关
private String grantDept;
// 有效期开始日期
private String userLifeBegin;
// 有效期过期时间
private String userLifeEnd;
@JsonIgnore
private CardReaderSdk cardReaderSdk;
public UserInfoVO(CardReaderSdk cardReaderSdk) {
if (cardReaderSdk == null) {
throw new RRException("sdk初始化失败");
}
this.cardReaderSdk = cardReaderSdk;
this.name = this.convert2Str(this.cardReaderSdk::GetName, "姓名转换失败");
this.sex = this.convert2Str(this.cardReaderSdk::GetSex, "性别转换失败");
this.nation = this.convert2Str(this.cardReaderSdk::GetNation, "民族转换失败");
this.born = this.convert2Str(this.cardReaderSdk::GetBirth, "出生日期转换失败");
this.address = this.convert2Str(this.cardReaderSdk::GetAddress, "住址转换失败");
this.IDCardNo = this.convert2Str(this.cardReaderSdk::GetCertNo, "身份证转换失败");
this.grantDept = this.convert2Str(this.cardReaderSdk::GetDepartemt, "签发机关转换失败");
this.userLifeBegin = this.convert2Str(this.cardReaderSdk::GetEffectDate, "有效期开始日期转换失败");
this.userLifeEnd = this.convert2Str(this.cardReaderSdk::GetExpireDate, "有效期截至日期转换失败");
}
private String convert2Str(Consumer<byte[]> function, String tip) {
byte[] param = new byte[256];
function.accept(param);
try {
return new String(param, "GBK").trim();
} catch (Exception e) {
throw new RRException(tip == null ? "参数转换失败" : tip);
}
}
private LocalDateTime str2LocalDateTime(String str) {
// 定义日期格式化器
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
// 将字符串解析为 LocalDate
LocalDate localDate = LocalDate.parse(str, formatter);
// 将 LocalDate 转换为 LocalDateTime设置时间为 00:00:00
return localDate.atStartOfDay();
}
}