From a6028c51e72cc3fa0a896361699b995bb3c69da0 Mon Sep 17 00:00:00 2001 From: sy Date: Wed, 14 Sep 2022 14:36:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A6=8F=E5=88=A9=E6=A0=B8=E7=AE=97=E5=B9=B2?= =?UTF-8?q?=E9=A2=84=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96v2-=E9=92=88=E5=AF=B9=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E4=BF=9D=E9=99=A9=E7=A7=8D=E7=B1=BB=E7=9A=84=E6=95=B0=E5=80=BC?= =?UTF-8?q?=E6=9C=AA=E5=A1=AB=E5=80=BC=E6=97=B6=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=8F=96=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=AD=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E6=95=B0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/SIAccountServiceImpl.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java index 0a09ca9ea..3a8e3ce1b 100644 --- a/src/com/engine/salary/service/impl/SIAccountServiceImpl.java +++ b/src/com/engine/salary/service/impl/SIAccountServiceImpl.java @@ -63,6 +63,8 @@ import weaver.hrm.User; import java.io.InputStream; import java.math.BigDecimal; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import static com.engine.salary.util.excel.ExcelSupport.EXCEL_TYPE_XLSX; @@ -1377,15 +1379,44 @@ public class SIAccountServiceImpl extends Service implements SIAccountService { */ private Map checkJsonMap(Map newMap, String oldJson) { Map oldMap = JSON.parseObject(oldJson, HashMap.class); + + //校验newMap中的value值是否为整数或者小数 + for(Map.Entry newEntry : newMap.entrySet()) { + String newValue = newEntry.getValue(); + int l = newValue.length(); + + if (newValue.length() > 0 && !isNumeric(newValue)) { + throw new SalaryRunTimeException("请检查导入Excel中个人或单位对应的福利项数值是否为整数或小数!"); + } + } + //保留oldMap无变动数据,更新newMap已变动数据 for (Map.Entry oldEntry : oldMap.entrySet()) { - //保留无变动数据,更新已变动数据 if (!newMap.containsKey(oldEntry.getKey())) { newMap.put(oldEntry.getKey(), oldEntry.getValue()); + } else if (newMap.containsKey(oldEntry.getKey()) && "".equals(newMap.get(oldEntry.getKey()))) { + newMap.put(oldEntry.getKey(), oldEntry.getValue()); } } + + return newMap; } + /** + * 判断字符串是否为整数或者小数 + */ + public static boolean isNumeric(String str){ + + Pattern pattern = Pattern.compile("[0-9]*\\.?[0-9]+"); + Matcher isNum = pattern.matcher(str); + if (!isNum.matches()) { + return false; + } + return true; + + + } + /** * 校验福利核算的账单月份输入格式是否正确 */