|
|
|
@ -0,0 +1,111 @@
|
|
|
|
|
package com.weaver.seconddev.jcl.organization.esb;
|
|
|
|
|
|
|
|
|
|
import com.weaver.common.base.entity.result.WeaResult;
|
|
|
|
|
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
|
|
|
|
|
import com.weaver.seconddev.jcl.organization.util.DatabaseUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.Period;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @use:定时同步所有人员主表信息
|
|
|
|
|
* @date 2025年3月27日
|
|
|
|
|
* @author xuxy
|
|
|
|
|
*/
|
|
|
|
|
@Service("synAllEmployeeInfo_jcl")
|
|
|
|
|
public class SynAllEmployeeInfoAction implements EsbServerlessRpcRemoteInterface {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DatabaseUtils databaseUtils;
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(SynAllEmployeeInfoAction.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
|
|
|
|
|
Map<String, Object> rs =new HashMap<>();
|
|
|
|
|
//查询员工全量信息
|
|
|
|
|
List<Map<String, Object>> list = queryEmployeesInfo();
|
|
|
|
|
//遍历更新日期不为空的人员:年龄、工龄、司龄
|
|
|
|
|
Map<String, Object> result = updateEmployeesInfo(list);
|
|
|
|
|
log.error("SynEmployeeAgeGlSlInfoAction.flowV3:"+result);
|
|
|
|
|
rs.put("flowV3",result);
|
|
|
|
|
return WeaResult.success(rs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Map<String, Object>> queryEmployeesInfo() {
|
|
|
|
|
String sql=" SELECT id,birthDate,first_work_date,hiredate,age,work_year,sl from uf_jcl_employee_information where delete_type=0 and TENANT_KEY='t7n9jpeaoa' " ;
|
|
|
|
|
log.error("queryEmployeesInfo.sql:{}",sql);
|
|
|
|
|
Map<String, Object> rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
|
|
|
|
List<Map<String, Object>> recordList = databaseUtils.getDataSourceList(rs);
|
|
|
|
|
log.error("queryEmployeesInfo.recordList:{}",recordList);
|
|
|
|
|
return recordList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> updateEmployeesInfo(List<Map<String, Object>> list) {
|
|
|
|
|
Map<String, Object> rs = new HashMap<>();
|
|
|
|
|
//判断调动生效日期是否为当天或者当天之前
|
|
|
|
|
LocalDate currentDate = LocalDate.now();
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
for (Map<String, Object> employee : list) {
|
|
|
|
|
String birthDateString = (String) employee.get("birthDate");
|
|
|
|
|
String firstWorkDateString = (String) employee.get("first_work_date");
|
|
|
|
|
String joinDateString = (String) employee.get("hiredate");
|
|
|
|
|
log.error("updateEmployeesInfo.birthDateString:{},firstWorkDateString:{},joinDateString:{}",birthDateString,firstWorkDateString,joinDateString);
|
|
|
|
|
if (birthDateString != null && !birthDateString.isEmpty()) {
|
|
|
|
|
LocalDate birthDate = LocalDate.parse(birthDateString, formatter);
|
|
|
|
|
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);
|
|
|
|
|
} 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);
|
|
|
|
|
} else {
|
|
|
|
|
employee.put("sl", null); // 或者可以选择不放入 Map 中
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//再全量更新
|
|
|
|
|
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 + "'" +
|
|
|
|
|
" where id = '" + id + "' and TENANT_KEY = 't7n9jpeaoa' and delete_type=0 ";
|
|
|
|
|
log.error("updateEmployeesInfo.sql:{}", sql);
|
|
|
|
|
rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql);
|
|
|
|
|
log.error("updateEmployeesInfo.rs:{}", rs);
|
|
|
|
|
}
|
|
|
|
|
return rs;
|
|
|
|
|
}
|
|
|
|
|
private int calculateFullYears(LocalDate startDate, LocalDate endDate) {
|
|
|
|
|
return Period.between(startDate, endDate).getYears();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Double calculateYears(LocalDate startDate, LocalDate endDate) {
|
|
|
|
|
Period period = Period.between(startDate, endDate);
|
|
|
|
|
double years = period.getYears() + (period.getMonths() / 12.0) + (period.getDays() / 365.0);
|
|
|
|
|
return Math.round(years * 100.0) / 100.0; // 保留两位小数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|