|
@ -62,7 +62,11 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.io.*; |
|
|
import java.io.*; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Path; |
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
|
import java.time.Period; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -79,6 +83,10 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
public static final List<String> controlGroup1 = Arrays.asList("input", "textarea", "datepicker", "daterange"); |
|
|
public static final List<String> controlGroup1 = Arrays.asList("input", "textarea", "datepicker", "daterange"); |
|
|
public static final List<String> controlGroup2 = Arrays.asList("select", "radio"); |
|
|
public static final List<String> controlGroup2 = Arrays.asList("select", "radio"); |
|
|
|
|
|
|
|
|
|
|
|
// 身份证号的正则表达式
|
|
|
|
|
|
private final Pattern PATTERN_15_ID = Pattern.compile("^\\d{6}(?<year>\\d{2})(?<month>0[1-9]|1[0-2])(?<day>[0-2][0-9]|3[0-1])\\d{2}(?<sex>\\d)$"); |
|
|
|
|
|
private final Pattern PATTERN_18_ID = Pattern.compile("^\\d{6}(?<year>\\d{4})(?<month>0[1-9]|1[0-2])(?<day>[0-2][0-9]|3[0-1])\\d{2}(?<sex>\\d)[0-9a-xA-X]$"); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 身份证号列序号 |
|
|
* 身份证号列序号 |
|
|
*/ |
|
|
*/ |
|
@ -433,16 +441,17 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
try { |
|
|
try { |
|
|
convertColumnWrappers2Map4Persist(itemIdAndColumnWrapper, row, currUserAgencyId, checkBoxOptionColumnIdxAndLabel, columnAndValues, true); |
|
|
convertColumnWrappers2Map4Persist(itemIdAndColumnWrapper, row, currUserAgencyId, checkBoxOptionColumnIdxAndLabel, columnAndValues, true); |
|
|
|
|
|
|
|
|
// 执行指定的检查
|
|
|
// 执行指定的检查以及数据补充
|
|
|
specifiedCheck(columnAndValues); |
|
|
execSpecifiedCheckAndFill(columnAndValues); |
|
|
|
|
|
|
|
|
String idCard = columnAndValues.get("ID_CARD"); |
|
|
String idCard = columnAndValues.get("ID_CARD"); |
|
|
Map<String, String> existingResiMap = icResiUserDao.selectResiInfoMap(idCard, null); |
|
|
Map<String, String> existingResiMap = icResiUserDao.selectResiInfoMap(idCard, null); |
|
|
|
|
|
|
|
|
if (existingResiMap == null) { |
|
|
if (existingResiMap == null) { |
|
|
// 新导入的居民,因为还没有读取子sheet,所以这些居民类别没有办法获取,先默认设置成0,后面读取子sheet的时候再更新
|
|
|
// 新导入的居民,因为还没有读取子sheet,所以这些居民类别没有办法获取,先默认设置成0,后面读取子sheet的时候再更新
|
|
|
|
|
|
// 注释掉的代码:根据已存在的必填信息,能解析出来该字段,所以不再赋值
|
|
|
columnAndValues.put("IS_ENSURE_HOUSE", "0"); |
|
|
columnAndValues.put("IS_ENSURE_HOUSE", "0"); |
|
|
columnAndValues.put("IS_OLD_PEOPLE", "0"); |
|
|
//columnAndValues.put("IS_OLD_PEOPLE", "0");
|
|
|
columnAndValues.put("IS_PARTY", "0"); |
|
|
columnAndValues.put("IS_PARTY", "0"); |
|
|
columnAndValues.put("IS_SPECIAL", "0"); |
|
|
columnAndValues.put("IS_SPECIAL", "0"); |
|
|
columnAndValues.put("IS_UNEMPLOYED", "0"); |
|
|
columnAndValues.put("IS_UNEMPLOYED", "0"); |
|
@ -464,7 +473,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
} else { |
|
|
} else { |
|
|
// 该居民已存在,要做更新操作,因为还没有读取子sheet,所以这些居民最新类别没有办法获取,先设置上旧的数据
|
|
|
// 该居民已存在,要做更新操作,因为还没有读取子sheet,所以这些居民最新类别没有办法获取,先设置上旧的数据
|
|
|
columnAndValues.put("IS_ENSURE_HOUSE", existingResiMap.get("IS_ENSURE_HOUSE")); |
|
|
columnAndValues.put("IS_ENSURE_HOUSE", existingResiMap.get("IS_ENSURE_HOUSE")); |
|
|
columnAndValues.put("IS_OLD_PEOPLE", existingResiMap.get("IS_OLD_PEOPLE")); |
|
|
//columnAndValues.put("IS_OLD_PEOPLE", existingResiMap.get("IS_OLD_PEOPLE"));
|
|
|
columnAndValues.put("IS_PARTY", existingResiMap.get("IS_PARTY")); |
|
|
columnAndValues.put("IS_PARTY", existingResiMap.get("IS_PARTY")); |
|
|
columnAndValues.put("IS_SPECIAL", existingResiMap.get("IS_SPECIAL")); |
|
|
columnAndValues.put("IS_SPECIAL", existingResiMap.get("IS_SPECIAL")); |
|
|
columnAndValues.put("IS_UNEMPLOYED", existingResiMap.get("IS_UNEMPLOYED")); |
|
|
columnAndValues.put("IS_UNEMPLOYED", existingResiMap.get("IS_UNEMPLOYED")); |
|
@ -544,16 +553,17 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 执行指定的检查 |
|
|
* 执行指定的检查以及数据的补充 |
|
|
* @param columnAndValues |
|
|
* @param columnAndValues |
|
|
*/ |
|
|
*/ |
|
|
private void specifiedCheck(LinkedHashMap<String, String> columnAndValues) { |
|
|
private void execSpecifiedCheckAndFill(LinkedHashMap<String, String> columnAndValues) { |
|
|
String idCard = columnAndValues.get("ID_CARD"); |
|
|
String idCard = columnAndValues.get("ID_CARD"); |
|
|
String mobile = columnAndValues.get("MOBILE"); |
|
|
String mobile = columnAndValues.get("MOBILE"); |
|
|
String name = columnAndValues.get("NAME"); |
|
|
String name = columnAndValues.get("NAME"); |
|
|
|
|
|
|
|
|
List<String> errors = new ArrayList<>(); |
|
|
List<String> errors = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
// 执行检查
|
|
|
if (StringUtils.isBlank(idCard)) { |
|
|
if (StringUtils.isBlank(idCard)) { |
|
|
log.debug("【居民信息导入】specifiedCheck身份证号为空的:{},{}", mobile, name); |
|
|
log.debug("【居民信息导入】specifiedCheck身份证号为空的:{},{}", mobile, name); |
|
|
|
|
|
|
|
@ -561,14 +571,12 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (idCard.length() > 18) { |
|
|
if (idCard.length() != 18 && idCard.length() != 15) { |
|
|
// 身份证号超长了哦,不可以的
|
|
|
errors.add("身份证号长度错误"); |
|
|
errors.add("身份证号过长"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(mobile) && mobile.length() > 15) { |
|
|
if (StringUtils.isNotBlank(mobile) && mobile.length() > 15) { |
|
|
// 手机号超长也是不可以的
|
|
|
errors.add("手机号长度错误"); |
|
|
errors.add("手机号过长"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (errors.size() > 0) { |
|
|
if (errors.size() > 0) { |
|
@ -576,6 +584,50 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res |
|
|
String errorMsg = String.join(";", errors); |
|
|
String errorMsg = String.join(";", errors); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ================== 数据补充 ===================
|
|
|
|
|
|
String year; |
|
|
|
|
|
String month; |
|
|
|
|
|
String day; |
|
|
|
|
|
String sex; |
|
|
|
|
|
|
|
|
|
|
|
if (idCard.length() == 15) { |
|
|
|
|
|
Matcher matcher = PATTERN_15_ID.matcher(idCard); |
|
|
|
|
|
if (matcher.matches()) { |
|
|
|
|
|
year = "19".concat(matcher.group("year")); |
|
|
|
|
|
month = matcher.group("month"); |
|
|
|
|
|
day = matcher.group("day"); |
|
|
|
|
|
sex = matcher.group("sex"); |
|
|
|
|
|
} else { |
|
|
|
|
|
String s = "身份证号解析错误"; |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (idCard.length() == 18) { |
|
|
|
|
|
Matcher matcher = PATTERN_18_ID.matcher(idCard); |
|
|
|
|
|
if (matcher.matches()) { |
|
|
|
|
|
year = matcher.group("year"); |
|
|
|
|
|
month = matcher.group("month"); |
|
|
|
|
|
day = matcher.group("day"); |
|
|
|
|
|
sex = matcher.group("sex"); |
|
|
|
|
|
} else { |
|
|
|
|
|
String s = "身份证号解析错误"; |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
String s = "身份证号位数错误"; |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), s, s); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 出生日期 & 年龄
|
|
|
|
|
|
LocalDate birthday = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day)); |
|
|
|
|
|
int age = Period.between(birthday, LocalDate.now()).getYears(); |
|
|
|
|
|
|
|
|
|
|
|
// 性别 & 生日 & 老年人
|
|
|
|
|
|
Boolean isMale = (Integer.parseInt(sex) % 2) == 1; |
|
|
|
|
|
columnAndValues.put("BIRTHDAY", String.join("-", Arrays.asList(year, month,day))); |
|
|
|
|
|
columnAndValues.put("GENDER", isMale ? "1" : "2"); |
|
|
|
|
|
columnAndValues.put("IS_OLD_PEOPLE", age > 60 ? "1" : "0"); |
|
|
|
|
|
System.out.println(6); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|