Commit a249971a authored by fangxinjiang's avatar fangxinjiang

代码优化-fxj

parent a305dc3e
...@@ -148,7 +148,17 @@ public class Common { ...@@ -148,7 +148,17 @@ public class Common {
Matcher match = pattern.matcher(str); Matcher match = pattern.matcher(str);
return match.matches() != false; return match.matches() != false;
} }
// 字符串为数字 可以带N位小数点
private static final Pattern NUMBER_PATTERN = compile("^-?\\d+(\\.\\d+)?$");
public static boolean isNumberStr(String str) {
// 判断字符串为数字 可以带N位小数点的正则表达式
if (str == null || str.isEmpty()) {
return false;
}
Matcher match = NUMBER_PATTERN.matcher(str);
return match.matches();
}
/** /**
* 允许上传的文件类型 * 允许上传的文件类型
* *
...@@ -793,10 +803,8 @@ public class Common { ...@@ -793,10 +803,8 @@ public class Common {
return false; return false;
} }
// 使用正则表达式匹配格式 // 使用正则表达式匹配格式 10.01,10;12,13 ,数字最多两位小数
// 格式要求: 数字(可带小数),数字(可带小数);数字(可带小数),数字(可带小数);... return str.matches("\\d+(\\.\\d{1,2})?,\\d+(\\.\\d{1,2})?(;\\d+(\\.\\d{1,2})?,\\d+(\\.\\d{1,2})?)*");
// 其中数字为一个或多个数字字符,可能包含小数点
return str.matches("\\d+(\\.\\d+)?,\\d+(\\.\\d+)?(;\\d+(\\.\\d+)?,\\d+(\\.\\d+)?)*");
} }
/** /**
* 校验字符串是否符合格式 2025-11 或 2025/11 或202511 * 校验字符串是否符合格式 2025-11 或 2025/11 或202511
......
...@@ -697,6 +697,11 @@ public class ExcelUtil <T> implements Serializable { ...@@ -697,6 +697,11 @@ public class ExcelUtil <T> implements Serializable {
} }
//最大值校验 //最大值校验
if (Common.isNotNull(attr.max()) && !CommonConstants.ZERO_STRING.equals(attr.max())) { if (Common.isNotNull(attr.max()) && !CommonConstants.ZERO_STRING.equals(attr.max())) {
//先判断是否为科学计数的数,然后转换成非科学计数的字符串
if (c.indexOf("E+") >= 0 && Common.isNumberStr(c.replace("E+", ""))){
//如果金额科学计数,转出正常值 如 c = 1.23456789E+9 转换成 c = 1234567890
c = new BigDecimal(c).toPlainString();
}
if (Common.isNumber(c)) { if (Common.isNumber(c)) {
if (attr.isDouble() && Double.doubleToLongBits(Double.valueOf(c).doubleValue()) > Double.valueOf(attr.max()).doubleValue()){ if (attr.isDouble() && Double.doubleToLongBits(Double.valueOf(c).doubleValue()) > Double.valueOf(attr.max()).doubleValue()){
return errorInfo(attr, "_超出最大值", i); return errorInfo(attr, "_超出最大值", i);
...@@ -708,12 +713,17 @@ public class ExcelUtil <T> implements Serializable { ...@@ -708,12 +713,17 @@ public class ExcelUtil <T> implements Serializable {
return errorInfo(attr, "_超出最大值", i); return errorInfo(attr, "_超出最大值", i);
} }
} }
} else { }else {
return errorInfo(attr, "_必须为数字且最多两位小数", i); return errorInfo(attr, "_必须为数字且最多两位小数", i);
} }
} }
//最小值校验 //最小值校验
if (attr.min() > 0) { if (attr.min() > 0) {
//先判断是否为科学计数的数,然后转换成非科学计数的字符串
if (c.indexOf("E+") >= 0 && Common.isNumberStr(c.replace("E+", ""))){
//如果金额科学计数,转出正常值 如 c = 1.23456789E+9 转换成 c = 1234567890
c = new BigDecimal(c).toPlainString();
}
if (Common.isNumber(c)) { if (Common.isNumber(c)) {
if (attr.isFloat()){ if (attr.isFloat()){
if (Float.valueOf(c).compareTo(attr.min()) < CommonConstants.ZERO_INT) { if (Float.valueOf(c).compareTo(attr.min()) < CommonConstants.ZERO_INT) {
......
...@@ -906,15 +906,7 @@ public class SysBaseSetInfoServiceImpl extends ServiceImpl<SysBaseSetInfoMapper, ...@@ -906,15 +906,7 @@ public class SysBaseSetInfoServiceImpl extends ServiceImpl<SysBaseSetInfoMapper,
infoVo.setUpBig(excel.getUpBig()); infoVo.setUpBig(excel.getUpBig());
infoVo.setLowerBig(excel.getLowerBig()); infoVo.setLowerBig(excel.getLowerBig());
} }
//大病缴纳周期为按月缴纳方式为按比例需要填写比例无值提示
if (null == excel.getPayCompanyPro()
|| null == excel.getPayPersonalPro()
|| excel.getPayPersonalPro().compareTo(BigDecimal.ZERO) < 0
|| excel.getPayPersonalPro().compareTo(BigDecimal.ZERO) < 0){
errorMsg = new ErrorMessage(excel.getRowIndex(),"大病是否收取为是时,大病缴纳周期为“按月”的,单位或个人大病比例字段必填,且填写正确比例即可,请修改后重新提交",excel);
errorMessageList.add(errorMsg);
continue;
}
infoVo.setPayCompanyPro(excel.getPayCompanyPro()); infoVo.setPayCompanyPro(excel.getPayCompanyPro());
infoVo.setPayPersonalPro(excel.getPayPersonalPro()); infoVo.setPayPersonalPro(excel.getPayPersonalPro());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment