Commit bcd4b02e by 叶立庆

Merge remote-tracking branch 'origin/v5.6.0'

2 parents b01e249b f1cabaf4
......@@ -34,6 +34,7 @@ import cn.com.glsx.merchants.service.beisen.EmployeeMappingService;
import cn.com.glsx.merchants.service.beisen.EmployeeRole;
import cn.com.glsx.merchants.service.beisen.EmployeeRoleService;
import cn.com.glsx.merchants.service.beisen.ExecutorFactory;
import cn.com.glsx.merchants.util.NumberUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
......@@ -741,16 +742,19 @@ public class BeiSenService {
}
if (customProperties!= null) {
String s1 = customProperties.get(beiSenProperty.getTrialBasicSalary());
if (StringUtils.isEmpty(s1)) {
log.info("北森员工{},trialBasicSalary空", employeeInfo.getName());
BigDecimal trialSalary = NumberUtils.safeParseBigDecimal(s1);
if (trialSalary == null) {
log.info("北森员工{}, trialBasicSalary 为空或非数字: '{}'", employeeInfo.getName(), s1);
} else {
beisenEmployeeInfonew.setTrialBasicSalary(new BigDecimal(s1));
beisenEmployeeInfonew.setTrialBasicSalary(trialSalary);
}
String s2 = customProperties.get(beiSenProperty.getFormalBasicSalary());
if (StringUtils.isEmpty(s2)) {
log.info("北森员工{},formalBasicSalary空", employeeInfo.getName());
BigDecimal formalSalary = NumberUtils.safeParseBigDecimal(s2);
if (formalSalary == null) {
log.info("北森员工{}, formalBasicSalary 为空或非数字: '{}'", employeeInfo.getName(), s2);
} else {
beisenEmployeeInfonew.setFormalBasicSalary(new BigDecimal(s2));
beisenEmployeeInfonew.setFormalBasicSalary(formalSalary);
}
String s3 = customProperties.get(beiSenProperty.getMerchantName());
if (StringUtils.isEmpty(s3)) {
......@@ -818,4 +822,5 @@ public class BeiSenService {
return beisenEmployeeInfoDTO;
}).collect(Collectors.toList());
}
}
package cn.com.glsx.merchants.util;
import java.math.BigDecimal;
import java.util.regex.Pattern;
public class NumberUtils {
// 可选:预编译正则(性能更好)
private static final Pattern NUMBER_PATTERN = Pattern.compile(
"^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"
);
/**
* 安全地将字符串解析为 BigDecimal
* @param str 输入字符串
* @return 有效的 BigDecimal,或 null(如果无效)
*/
public static BigDecimal safeParseBigDecimal(String str) {
if (str == null || str.trim().isEmpty()) {
return null;
}
try {
// 可选1:先用正则快速过滤明显非法格式(提升性能,避免异常开销)
if (!NUMBER_PATTERN.matcher(str.trim()).matches()) {
return null;
}
// 可选2:直接尝试 new BigDecimal(更严格,支持科学计数法等)
return new BigDecimal(str.trim());
} catch (NumberFormatException e) {
return null;
}
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!