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; + + + } + /** * 校验福利核算的账单月份输入格式是否正确 */