兼容多场景
This commit is contained in:
parent
e9dad7c9c8
commit
ef5ba847d5
|
|
@ -7,10 +7,13 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Period;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @use:定时同步人员年龄、工龄、司龄
|
||||
|
|
@ -51,42 +54,98 @@ public class SynEmployeeAgeGlSlInfoAction implements EsbServerlessRpcRemoteInter
|
|||
//判断调动生效日期是否为当天或者当天之前
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
for (Map<String, Object> employee : list) {
|
||||
String birthDateString = (String) employee.get("birthDate");
|
||||
String birthDateString = (String) employee.get("birthday");
|
||||
String firstWorkDateString = (String) employee.get("first_work_date");
|
||||
String joinDateString = (String) employee.get("hiredate");
|
||||
log.error("updateEmployeesInfo.birthDateString:{},firstWorkDateString:{},joinDateString:{}",birthDateString,firstWorkDateString,joinDateString);
|
||||
long birthDate_time =0L;
|
||||
long firstWorkDate_time =0L;
|
||||
long joinDate_time =0L;
|
||||
if (birthDateString != null && !birthDateString.isEmpty()) {
|
||||
LocalDate birthDate = LocalDate.parse(birthDateString, formatter);
|
||||
int age = calculateFullYears(birthDate, currentDate);
|
||||
employee.put("age", age);
|
||||
if(!birthDateString.contains("-")){
|
||||
birthDate_time = Long.parseLong(birthDateString);
|
||||
Date date = new Date(birthDate_time);
|
||||
birthDateString = sdf.format(date);
|
||||
LocalDate birthDate = LocalDate.parse(birthDateString, formatter2);
|
||||
int age = calculateFullYears(birthDate, currentDate);
|
||||
employee.put("age", age);
|
||||
}else{
|
||||
if(isDateOnlyFormat(birthDateString)){
|
||||
LocalDate birthDate = LocalDate.parse(birthDateString, formatter);
|
||||
int age = calculateFullYears(birthDate, currentDate);
|
||||
employee.put("age", age);
|
||||
}
|
||||
if(isDateTimeFormat(birthDateString)){
|
||||
LocalDate birthDate = LocalDate.parse(birthDateString, formatter2);
|
||||
int age = calculateFullYears(birthDate, currentDate);
|
||||
employee.put("age", age);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
employee.put("age", null); // 或者可以选择不放入 Map 中
|
||||
}
|
||||
|
||||
if (firstWorkDateString != null && !firstWorkDateString.isEmpty()) {
|
||||
LocalDate firstWorkDate = LocalDate.parse(firstWorkDateString, formatter);
|
||||
Double workYears = calculateYears(firstWorkDate, currentDate);
|
||||
employee.put("work_year", workYears);
|
||||
if(!firstWorkDateString.contains("-")){
|
||||
firstWorkDate_time = Long.parseLong(firstWorkDateString);
|
||||
Date date = new Date(firstWorkDate_time);
|
||||
firstWorkDateString = sdf.format(date);
|
||||
LocalDate firstWorkDate = LocalDate.parse(firstWorkDateString, formatter2);
|
||||
Double workYears = calculateYears(firstWorkDate, currentDate);
|
||||
employee.put("work_year", workYears);
|
||||
}else {
|
||||
if(isDateOnlyFormat(firstWorkDateString)){
|
||||
LocalDate firstWorkDate = LocalDate.parse(firstWorkDateString, formatter);
|
||||
Double workYears = calculateYears(firstWorkDate, currentDate);
|
||||
employee.put("work_year", workYears);
|
||||
}
|
||||
if(isDateTimeFormat(firstWorkDateString)){
|
||||
LocalDate firstWorkDate = LocalDate.parse(firstWorkDateString, formatter2);
|
||||
Double workYears = calculateYears(firstWorkDate, currentDate);
|
||||
employee.put("work_year", workYears);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
employee.put("work_year", null); // 或者可以选择不放入 Map 中
|
||||
}
|
||||
|
||||
if (joinDateString != null && !joinDateString.isEmpty()) {
|
||||
LocalDate joinDate = LocalDate.parse(joinDateString, formatter);
|
||||
Double companyYears = calculateYears(joinDate, currentDate);
|
||||
employee.put("sl", companyYears);
|
||||
if(!joinDateString.contains("-")){
|
||||
joinDate_time = Long.parseLong(joinDateString);
|
||||
Date date = new Date(joinDate_time);
|
||||
joinDateString = sdf.format(date);
|
||||
LocalDate joinDate = LocalDate.parse(joinDateString, formatter2);
|
||||
Double companyYears = calculateYears(joinDate, currentDate);
|
||||
employee.put("sl", companyYears);
|
||||
}else{
|
||||
if(isDateOnlyFormat(joinDateString)){
|
||||
LocalDate joinDate = LocalDate.parse(joinDateString, formatter);
|
||||
Double companyYears = calculateYears(joinDate, currentDate);
|
||||
employee.put("sl", companyYears);
|
||||
}
|
||||
if(isDateTimeFormat(joinDateString)){
|
||||
LocalDate joinDate = LocalDate.parse(joinDateString, formatter2);
|
||||
Double companyYears = calculateYears(joinDate, currentDate);
|
||||
employee.put("sl", companyYears);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
employee.put("sl", null); // 或者可以选择不放入 Map 中
|
||||
}
|
||||
log.error("updateEmployeesInfo.employee:{}", employee);
|
||||
}
|
||||
//再全量更新
|
||||
for (Map<String, Object> objectMap : list) {
|
||||
String id = (String) objectMap.get("id");
|
||||
String birthDateString = (String) objectMap.get("age");
|
||||
String firstWorkDateString = (String) objectMap.get("work_year");
|
||||
String joinDateString = (String) objectMap.get("sl");
|
||||
String sql = "update uf_jcl_employee_information set age = '" + birthDateString + "',work_year = '" + firstWorkDateString + "',sl = '" + joinDateString + "'" +
|
||||
String id = String.valueOf(objectMap.get("id"));
|
||||
String birthDateString = objectMap.get("age")!=null?String.valueOf(objectMap.get("age")):null;
|
||||
String firstWorkDateString = objectMap.get("work_year")!=null?String.valueOf(objectMap.get("work_year")):null;
|
||||
String joinDateString = objectMap.get("sl")!=null?String.valueOf(objectMap.get("sl")):null;
|
||||
String sql = "update uf_jcl_employee_information set age = " + birthDateString + ",work_year = " + firstWorkDateString + ",sl = " + joinDateString + " " +
|
||||
" where id = '" + id + "' and delete_type=0 ";
|
||||
log.error("updateEmployeesInfo.sql:{}", sql);
|
||||
rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
||||
|
|
@ -104,5 +163,21 @@ public class SynEmployeeAgeGlSlInfoAction implements EsbServerlessRpcRemoteInter
|
|||
return Math.round(years * 100.0) / 100.0; // 保留两位小数
|
||||
}
|
||||
|
||||
// 检查是否是日期格式 yyyy-MM-dd
|
||||
public static boolean isDateOnlyFormat(String dateStr) {
|
||||
String datePattern = "^\\d{4}-\\d{2}-\\d{2}$";
|
||||
Pattern pattern = Pattern.compile(datePattern);
|
||||
Matcher matcher = pattern.matcher(dateStr);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
// 检查是否是日期时间格式 yyyy-MM-dd HH:mm:ss
|
||||
public static boolean isDateTimeFormat(String dateStr) {
|
||||
String dateTimePattern = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$";
|
||||
Pattern pattern = Pattern.compile(dateTimePattern);
|
||||
Matcher matcher = pattern.matcher(dateStr);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.weaver.seconddev.jcl.organization.esb;
|
||||
|
||||
import cn.com.infosec.netsign.base.TransUtil;
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
|
|
|
|||
Loading…
Reference in New Issue