diff --git a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/EmployeeRelationServiceImpl.java b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/EmployeeRelationServiceImpl.java index ac1ea65..a62e093 100644 --- a/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/EmployeeRelationServiceImpl.java +++ b/jcl-hrmorganization/secondev-jcl-hrmorganization/src/main/java/com/weaver/seconddev/jcl/organization/service/impl/EmployeeRelationServiceImpl.java @@ -35,11 +35,15 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.SimpleDateFormat; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; +import static com.weaver.inc.common.util.TimeUtil.DATE_FORMATTER; + @Service public class EmployeeRelationServiceImpl implements EmployeeRelationService { @@ -896,6 +900,12 @@ public class EmployeeRelationServiceImpl implements EmployeeRelationService { resultList.addAll(transferInfoNew); } } + convertHireDatesRobust(resultList); + /** + * 相关id转化为名称 + */ + transformname(resultList); + return resultList; } @@ -993,4 +1003,135 @@ public class EmployeeRelationServiceImpl implements EmployeeRelationService { log.error("queryTransferInfo.recordList:{}", recordList); return recordList; } + + /** + * 更健壮的版本,可以处理String类型的时间戳 + */ + private void convertHireDatesRobust(List> resultList) { + if (resultList == null) { + return; + } + + resultList.forEach(map -> { + if (map.containsKey("hiredate")) { + Object hiredateValue = map.get("hiredate"); + + try { + // 尝试处理Long类型的时间戳 + if (hiredateValue instanceof Long) { + Long timestamp = (Long) hiredateValue; + LocalDateTime dateTime = LocalDateTime.ofInstant( + Instant.ofEpochMilli(timestamp), + ZoneId.systemDefault()); + map.put("hiredate", dateTime.format(DATE_FORMATTER)); + } + // 尝试处理String类型的时间戳 + else if (hiredateValue instanceof String) { + String dateStr = (String) hiredateValue; + try { + // 尝试解析为Long + Long timestamp = Long.parseLong(dateStr); + LocalDateTime dateTime = LocalDateTime.ofInstant( + Instant.ofEpochMilli(timestamp), + ZoneId.systemDefault()); + map.put("hiredate", dateTime.format(DATE_FORMATTER)); + } catch (NumberFormatException e) { + // 不是时间戳格式,假设已经是正确格式,不做处理 + } + } + } catch (Exception e) { + // 处理异常情况 + e.printStackTrace(); + } + } + }); + } + + /** + * 查询员工类型名称 + */ + private String getYglxmc(String id){ + String name = ""; + String sql = "select yglxmc from uf_jcl_yglx where delete_type = 0 and id = " + id; + log.error("getYglxmc.sql:{}", sql); + Map rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql); + List> recordList = databaseUtils.getDataSourceList(rs); + log.error("getYglxmc.recordList:{}", recordList); + if(CollectionUtils.isEmpty(recordList)){ + name = String.valueOf(recordList.get(0).get("yglxmc")); + } + return name; + } + + /** + * 查询公司或部门 + */ + private String getDepartmentName(String deptid){ + String name = ""; + String sql = "select name from eteams.department where delete_type = 0 and id = " + deptid; + log.error("getDepartmentName.sql:{}", sql); + Map rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql); + List> recordList = databaseUtils.getDataSourceList(rs); + log.error("getDepartmentName.recordList:{}", recordList); + if(CollectionUtils.isEmpty(recordList)){ + name = String.valueOf(recordList.get(0).get("name")); + } + return name; + } + + /** + * 查询岗位 + */ + private String getPositionName(String positionid){ + String name = ""; + String sql = "select name from eteams.position where delete_type = 0 and id = " + positionid; + log.error("getPositionName.sql:{}", sql); + Map rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql); + List> recordList = databaseUtils.getDataSourceList(rs); + log.error("getPositionName.recordList:{}", recordList); + if(CollectionUtils.isEmpty(recordList)){ + name = String.valueOf(recordList.get(0).get("name")); + } + return name; + } + + /** + * 查询上级 + */ + private String getUsername(String empid){ + String name = ""; + String sql = "select username from eteams.employee where delete_type = 0 and id = " + empid; + log.error("getUsername.sql:{}", sql); + Map rs = databaseUtils.execute("LOGIC", "weaver-ebuilder-form-service", sql); + List> recordList = databaseUtils.getDataSourceList(rs); + log.error("getUsername.recordList:{}", recordList); + if(CollectionUtils.isEmpty(recordList)){ + name = String.valueOf(recordList.get(0).get("username")); + } + return name; + } + + /** + * 人员信息id转化为名称 + */ + private void transformname (List> resultList){ + for (Map map : resultList) { + String yglx = String.valueOf(map.get("yglx")); + String subcompany = String.valueOf(map.get("subcompany")); + String department = String.valueOf(map.get("department")); + String position = String.valueOf(map.get("position")); + String superior = String.valueOf(map.get("superior")); + String yglxmc = getYglxmc(yglx); + String subcompanyName = getDepartmentName(subcompany); + String departmentName = getDepartmentName(department); + String positionName = getPositionName(position); + String username = getUsername(superior); + map.put("yglx",yglxmc); + map.put("subcompany",subcompanyName); + map.put("department",departmentName); + map.put("position",positionName); + map.put("superior",username); + } + } + }