From 7b9300be4c957459aaf6c56126da916291bcba0f Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Fri, 6 May 2022 14:02:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B1=85=E6=B0=91=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?datapicker=E5=92=8Cdatarange=E7=A9=BA=E9=97=B4=E7=9A=84?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=BF=9B=E8=A1=8C=E6=AD=A3=E5=88=99=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=88=A4=E6=96=AD=EF=BC=8C=E5=92=8C=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/IcResiUserImportServiceImpl.java | 82 ++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java index d530aa9f34..c3ec181ef2 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserImportServiceImpl.java @@ -85,10 +85,24 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res public static final List controlGroup1 = Arrays.asList("input", "textarea", "datepicker", "daterange"); public static final List controlGroup2 = Arrays.asList("select", "radio"); - // 身份证号的正则表达式 + /** + * 15位身份证号的正则表达式 + */ private final Pattern PATTERN_15_ID = Pattern.compile("^\\d{6}(?\\d{2})(?0[1-9]|1[0-2])(?[0-2][0-9]|3[0-1])\\d{2}(?\\d)$"); + /** + * 18位身份证号的正则表达式 + */ private final Pattern PATTERN_18_ID = Pattern.compile("^\\d{6}(?\\d{4})(?0[1-9]|1[0-2])(?[0-2][0-9]|3[0-1])\\d{2}(?\\d)[0-9a-xA-X]$"); + /** + * 日期解析,不含时间 + */ + private final Pattern PATTERN_DATE_PICKER = Pattern.compile("^(\\d{4})[-/](0?[1-9]|1[0-2])[-/](3[0-1]|[0-2]?\\d).*$"); + /** + * daterange的解析:1992-01-20,1992-01-30 + */ + private final Pattern PATTERN_DATE_RANGE = Pattern.compile("^(\\d{4})[-/](0?[1-9]|1[0-2])[-/](3[0-1]|[0-2]?\\d).*,(\\d{4})[-/](0?[1-9]|1[0-2])[-/](3[0-1]|[0-2]?\\d).*$"); + /** * 身份证号列序号 */ @@ -149,7 +163,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res private OssFeignClient ossFeignClient; /** - * 字表中不需要的列 + * 子表中不需要的列。因为主表中需要身份证号,网格等信息,但子表中不需要这些列必填,只要有身份证号即可,因此字表判断的时候需要排除这些列 */ private List subTableNeedlessColumns = Arrays.asList("GRID_ID", "VILLAGE_ID", "BUILD_ID", "UNIT_ID", "HOME_ID", "IS_BDHJ", "NAME", "MOBILE", "GENDER", "ID_CARD", @@ -621,7 +635,6 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res 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); } /** @@ -695,7 +708,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res } catch (Exception e) { String errorMsg; - if (e instanceof RenException) { + if (e instanceof RenException || e instanceof EpmetException) { errorMsg = e.getMessage(); } else { errorMsg = "未知系统错误"; @@ -792,6 +805,7 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res String notFoundColumnName = null; List emptyColumnNames = new ArrayList<>(); + List patternErrorColumnNames = new ArrayList<>(); // 这两列要提前放进去,因为有的列未填写的话,会抛异常出去,需要用这两列来做描述 target2Insert.put("ID_CARD", row.get(ID_CARD_COLUMN_NO)); @@ -823,6 +837,13 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res continue; } + // 日期控件的数据校验和清晰 + boolean dateError = dateTypeCheckAndWash(columnWrapper, patternErrorColumnNames); + if (dateError) { + hasError = dateError; + continue; + } + // "select", "radio" } else if (controlGroup2.contains(columnWrapper.getItemType())){ @@ -916,10 +937,63 @@ public class IcResiUserImportServiceImpl implements IcResiUserImportService, Res sb.append(notFoundColumnName).append("填写的值在系统中未找到"); } + if (CollectionUtils.isNotEmpty(patternErrorColumnNames)) { + sb.append(String.join(",", patternErrorColumnNames)).append("的值格式错误"); + } + throw new EpmetException(sb.toString()); } } + /** + * 处理一下日期类型的数据 + * @param columnWrapper + * @param patternErrorColumnNames + * @return true:有错误,false,没错误 + */ + private boolean dateTypeCheckAndWash(ColumnWrapper columnWrapper, List patternErrorColumnNames) { + // 日期格式不对的检查 + String cellContent = columnWrapper.getCellContent(); + if (StringUtils.isBlank(cellContent)) { + return false; + } + + if ("datepicker".equals(columnWrapper.getItemType())) { + Matcher matcher = PATTERN_DATE_PICKER.matcher(cellContent); + if (matcher.matches()) { + String year = matcher.group(1); + String month = matcher.group(2); + String day = matcher.group(3); + + cellContent = String.format("%s-%02d-%02d", year, Integer.parseInt(month), Integer.parseInt(day)); + columnWrapper.setCellContent(cellContent); + columnWrapper.setColValue(cellContent); + } else { + patternErrorColumnNames.add(columnWrapper.getCombinedLabel()); + return true; + } + } else if ("daterange".equals(columnWrapper.getItemType())) { + Matcher matcher = PATTERN_DATE_RANGE.matcher(cellContent); + if (matcher.matches()) { + String year = matcher.group(1); + String month = matcher.group(2); + String day = matcher.group(3); + String yearEnd = matcher.group(4); + String monthEnd = matcher.group(5); + String dayEnd = matcher.group(6); + + cellContent = String.format("%s-%02d-%02d,%s-%02d-%02d", year, Integer.parseInt(month), Integer.parseInt(day), yearEnd, Integer.parseInt(monthEnd), Integer.parseInt(dayEnd)); + columnWrapper.setCellContent(cellContent); + columnWrapper.setColValue(cellContent); + } else { + patternErrorColumnNames.add(columnWrapper.getCombinedLabel()); + return true; + } + } + + return false; + } + /** * 必填,但是用户没填的,放到list中 * @param isPrimaryTable 是否是主表。true:是主表,false:从表 From cd81ac7b6aa2878c116d37d72d9a7d362402a5ce Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Fri, 6 May 2022 14:15:01 +0800 Subject: [PATCH 2/2] url --- .../main/java/com/epmet/feign/EpmetUserOpenFeignClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java index 0029c42100..07bf76bfa5 100644 --- a/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java @@ -23,8 +23,8 @@ import java.util.Set; * @author yinzuomei@elink-cn.com * @date 2020/6/4 13:09 */ - @FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallbackFactory = EpmetUserOpenFeignClientFallbackFactory.class, url = "localhost:8087") -//@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallbackFactory = EpmetUserOpenFeignClientFallbackFactory.class) +// @FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallbackFactory = EpmetUserOpenFeignClientFallbackFactory.class, url = "localhost:8087") +@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallbackFactory = EpmetUserOpenFeignClientFallbackFactory.class) public interface EpmetUserOpenFeignClient { /**