diff --git a/src/com/engine/salary/service/impl/SalaryAcctEmployeeServiceImpl.java b/src/com/engine/salary/service/impl/SalaryAcctEmployeeServiceImpl.java index 13a5d502e..6a777042d 100644 --- a/src/com/engine/salary/service/impl/SalaryAcctEmployeeServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryAcctEmployeeServiceImpl.java @@ -323,7 +323,7 @@ public class SalaryAcctEmployeeServiceImpl extends Service implements SalaryAcct @Override public void batchSave(Collection salaryAcctEmployeePOS) { - if(CollectionUtils.isEmpty(salaryAcctEmployeePOS)){ + if (CollectionUtils.isEmpty(salaryAcctEmployeePOS)) { return; } List> partition = Lists.partition((List) salaryAcctEmployeePOS, 100); @@ -396,11 +396,13 @@ public class SalaryAcctEmployeeServiceImpl extends Service implements SalaryAcct SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salaryAcctRecordPO.getSalarySobId(), SalaryDateUtil.localDate2YearMonth(salaryAcctRecordPO.getSalaryMonth())); // 根据薪资账套的"核算人员范围"过滤入职日期大于薪资周期止的人员 salaryEmployees = salaryEmployees.stream() + .filter(salaryEmployee -> SalaryDateUtil.stringToDate(salaryEmployee.getCompanystartdate()) != null) .filter(salaryEmployee -> StringUtils.isBlank(salaryEmployee.getCompanystartdate()) || SalaryDateUtil.stringToDate(salaryEmployee.getCompanystartdate()).compareTo(salarySobCycleDTO.getSalaryCycle().getEndDate()) <= 0) .collect(Collectors.toList()); // 根据薪资账套的"核算人员范围"过滤离职日期小于薪资周期起的人员 salaryEmployees = salaryEmployees.stream() + .filter(salaryEmployee -> SalaryDateUtil.stringToDate(salaryEmployee.getCompanystartdate()) != null) .filter(salaryEmployee -> StringUtils.isBlank(salaryEmployee.getDismissdate()) || SalaryDateUtil.stringToDate(salaryEmployee.getDismissdate()).compareTo(salarySobCycleDTO.getSalaryCycle().getEndDate()) >= 0) .collect(Collectors.toList()); diff --git a/src/com/engine/salary/util/SalaryDateUtil.java b/src/com/engine/salary/util/SalaryDateUtil.java index 014a5d111..37536ed53 100644 --- a/src/com/engine/salary/util/SalaryDateUtil.java +++ b/src/com/engine/salary/util/SalaryDateUtil.java @@ -99,6 +99,7 @@ public class SalaryDateUtil { return StringUtils.EMPTY; } } + public static String getFormatLocalDate(LocalDate localDate) { if (localDate == null) { return StringUtils.EMPTY; @@ -165,6 +166,7 @@ public class SalaryDateUtil { ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault()); return Date.from(zonedDateTime.toInstant()); } + public static Date localDateTimeToDate(LocalDateTime localDateTime) { if (null == localDateTime) { return null; @@ -323,23 +325,23 @@ public class SalaryDateUtil { } - /** * LocalDate转YearMonth + * * @param localDate * @return */ - public static YearMonth toYearMonth(LocalDate localDate){ + public static YearMonth toYearMonth(LocalDate localDate) { Objects.requireNonNull(localDate, "localDate"); return YearMonth.of(localDate.getYear(), localDate.getMonthValue()); } - /** * YearMonth转Date * 注意dayOfMonth范围:1到31之间,最大值根据月份确定特殊情况,如2月闰年29,非闰年28 * 如果要转换为当月最后一天,可以使用下面方法:toDateEndOfMonth(YearMonth) + * * @param yearMonth * @param dayOfMonth * @return @@ -351,6 +353,7 @@ public class SalaryDateUtil { /** * YearMonth转Date,转换为当月第一天 + * * @param yearMonth * @return */ @@ -360,6 +363,7 @@ public class SalaryDateUtil { /** * YearMonth转Date,转换为当月最后一天 + * * @param yearMonth * @return */ @@ -373,6 +377,7 @@ public class SalaryDateUtil { * YearMonth转LocalDate * 注意dayOfMonth范围:1到31之间,最大值根据月份确定特殊情况,如2月闰年29,非闰年28 * 如果要转换为当月最后一天,可以使用下面方法:toLocalDateEndOfMonth(YearMonth) + * * @param yearMonth * @param dayOfMonth * @return @@ -384,6 +389,7 @@ public class SalaryDateUtil { /** * YearMonth转LocalDate,转换为当月第一天 + * * @param yearMonth * @return */ @@ -393,6 +399,7 @@ public class SalaryDateUtil { /** * YearMonth转LocalDate,转换为当月最后一天 + * * @param yearMonth * @return */ @@ -403,6 +410,7 @@ public class SalaryDateUtil { /** * String转Date + * * @param date * @return */ @@ -420,16 +428,7 @@ public class SalaryDateUtil { } public static Date stringToDate(String date) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date parse = null; - if (date != null) { - try { - parse = sdf.parse(date); - } catch (ParseException e) { - throw new RuntimeException(e); - } - } - return parse; + return dateStrToLocalDate(date); } //格式化日期 @@ -443,4 +442,25 @@ public class SalaryDateUtil { String str = new SimpleDateFormat("yyyy-MM").format(date);//再将时间转换为对应格式字符串 return str; } + + private static Date dateStrToLocalDate(String date) { + Date localDate = null; + try { + date = date.substring(0, 10); + if (date.contains("/")) { + SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); + localDate = format.parse(date); + } else if (date.contains("-")) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + localDate = format.parse(date); + } + } catch (Exception e) { + log.error("日期解析异常,{}", date); + localDate = null; + } + + return localDate; + } } + +