diff --git a/src/com/engine/hzzx/entity/Department.java b/src/com/engine/hzzx/entity/Department.java new file mode 100644 index 0000000..f0091d5 --- /dev/null +++ b/src/com/engine/hzzx/entity/Department.java @@ -0,0 +1,16 @@ +package com.engine.hzzx.entity; + +import lombok.Data; + +/** + * @author:dxfeng + * @createTime: 2025/03/13 + * @version: 1.0 + */ +@Data +public class Department { + private String name; + private String shortName; + private String code; + private String oId; +} diff --git a/src/com/engine/hzzx/entity/Employee.java b/src/com/engine/hzzx/entity/Employee.java new file mode 100644 index 0000000..3ce9a4b --- /dev/null +++ b/src/com/engine/hzzx/entity/Employee.java @@ -0,0 +1,77 @@ +package com.engine.hzzx.entity; + +/** + * @author:dxfeng + * @createTime: 2025/03/13 + * @version: 1.0 + */ + +import lombok.Data; + +import java.util.Date; + +@Data +public class Employee { + private String lastSchool; + private String modifiedTime; + private String nation; + private long userID; + private String major; + private String applicantIdV6; + private String createdTime; + private int applicantId; + private Date certificateValidityTerm; + private int nationality; + private int sourceType; + private String name; + private boolean stdIsDeleted; + private int gender; + private String iDType; + private String backupMail; + private String certificateStartDate; + private String businessModifiedTime; + private long businessModifiedBy; + private String _Name; + private String educationLevel; + private long modifiedBy; + private String email; + private String objectId; + private String politicalStatus; + private long createdBy; + private int age; + private String departmentCode; + private String positionCode; + + @Override + public String toString() { + return "Employee{" + + "lastSchool='" + lastSchool + '\'' + + ", modifiedTime='" + modifiedTime + '\'' + + ", nation='" + nation + '\'' + + ", userID=" + userID + + ", major='" + major + '\'' + + ", applicantIdV6='" + applicantIdV6 + '\'' + + ", createdTime='" + createdTime + '\'' + + ", applicantId=" + applicantId + + ", certificateValidityTerm=" + certificateValidityTerm + + ", nationality=" + nationality + + ", sourceType=" + sourceType + + ", name='" + name + '\'' + + ", stdIsDeleted=" + stdIsDeleted + + ", gender=" + gender + + ", iDType='" + iDType + '\'' + + ", backupMail='" + backupMail + '\'' + + ", certificateStartDate='" + certificateStartDate + '\'' + + ", businessModifiedTime='" + businessModifiedTime + '\'' + + ", businessModifiedBy=" + businessModifiedBy + + ", _Name='" + _Name + '\'' + + ", educationLevel='" + educationLevel + '\'' + + ", modifiedBy=" + modifiedBy + + ", email='" + email + '\'' + + ", objectId='" + objectId + '\'' + + ", politicalStatus='" + politicalStatus + '\'' + + ", createdBy=" + createdBy + + ", age=" + age + + '}'; + } +} diff --git a/src/com/engine/hzzx/entity/Position.java b/src/com/engine/hzzx/entity/Position.java new file mode 100644 index 0000000..d06b972 --- /dev/null +++ b/src/com/engine/hzzx/entity/Position.java @@ -0,0 +1,15 @@ +package com.engine.hzzx.entity; + +import lombok.Data; + +/** + * @author:dxfeng + * @createTime: 2025/03/13 + * @version: 1.0 + */ +@Data +public class Position { + private String name; + private String code; + private String oId; +} diff --git a/src/weaver/interfaces/hzzx/cronjob/SyncBeiSenInfoJob.java b/src/weaver/interfaces/hzzx/cronjob/SyncBeiSenInfoJob.java new file mode 100644 index 0000000..a2ae238 --- /dev/null +++ b/src/weaver/interfaces/hzzx/cronjob/SyncBeiSenInfoJob.java @@ -0,0 +1,229 @@ +package weaver.interfaces.hzzx.cronjob; + +import cn.hutool.http.HttpRequest; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.engine.hzzx.entity.Department; +import com.engine.hzzx.entity.Employee; +import com.engine.hzzx.entity.Position; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.interfaces.schedule.BaseCronJob; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author:dxfeng + * @createTime: 2025/03/12 + * @version: 1.0 + */ +public class SyncBeiSenInfoJob extends BaseCronJob { + private static final String TOKEN_URL = "https://openapi.italent.cn/token"; + private static final String GET_EMPLOYMENT_URL = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/GetByTimeWindow"; + private static final String GET_DEPARTMENT_URL = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Organization/GetByIds"; + private static final String GET_POSITION_URL = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Position/GetByOIds"; + + private static final String APP_KEY = "EE7D602509E04A59AE5DEFF0841F6A1C"; + private static final String APP_SECRET = "F5229D9D83BF45DEBFA1EF8DAC13C0339D0074419CFE45FA8BAC2A0B9D170798"; + + + RecordSet rs = new RecordSet(); + + @Override + public void execute() { + String accessToken = getToken(); + // 获取近两天的数据 + String startTime = DateUtil.getYesterday() + "T00:00:00"; + String stopTime = DateUtil.getCurrentDate() + "T23:59:59"; + int[] empStatus = {1}; + int[] employType = {0}; + int[] internshipType = {2}; + List employeeList = new ArrayList<>(); + getPendingEmployment(startTime, stopTime, empStatus, employType, accessToken, "", employeeList); + + if (CollectionUtils.isNotEmpty(employeeList)) { + // 遍历待入职信息,插入数据库 + for (Employee employee : employeeList) { + rs.writeLog("遍历待入职信息", employee.toString()); + + } + } + + List internshipList = new ArrayList<>(); + getPendingEmployment(startTime, stopTime, empStatus, internshipType, accessToken, "", internshipList); + if (CollectionUtils.isNotEmpty(internshipList)) { + // 遍历实习生信息,插入数据库 + for (Employee employee : internshipList) { + rs.writeLog("遍历实习生信息", employee.toString()); + } + } + + + } + + /** + * 获取待入职信息 + * + * @param startTime + * @param stopTime + * @param empStatus + * @param accessToken + * @param scrollId + * @param employeeList + * @return + */ + private String getPendingEmployment(String startTime, String stopTime, int[] empStatus, int[] employType, String accessToken, String scrollId, List employeeList) { + JSONObject json = new JSONObject(); + json.put("startTime", startTime); + json.put("stopTime", stopTime); + json.put("empStatus", empStatus); + json.put("employType", employType); + if (StringUtils.isNotBlank(scrollId)) { + json.put("scrollId", scrollId); + } + rs.writeLog("GetByTimeWindow,入参", json.toString()); + String response = HttpRequest.post(GET_EMPLOYMENT_URL) + .header("Authorization", "Bearer " + accessToken) + .body(json.toString()) + .contentType("application/json") + .execute() + .body(); + rs.writeLog("GetByTimeWindow,返参", response); + JSONObject jsonObject = JSONObject.parseObject(response); + + String code = jsonObject.getString("code"); + if (!"200".equals(code)) { + throw new RuntimeException("GetByTimeWindow接口调用失败"); + } + scrollId = jsonObject.getString("scrollId"); + JSONArray data = jsonObject.getJSONArray("data"); + if (data.size() == 0) { + return ""; + } + + for (int i = 0; i < data.size(); i++) { + JSONObject dataObject = data.getJSONObject(i); + JSONObject employeeInfo = dataObject.getJSONObject("employeeInfo"); + JSONObject recordInfo = dataObject.getJSONObject("recordInfo"); + String oIdDepartment = recordInfo.getString("oIdDepartment"); + String oIdJobPosition = recordInfo.getString("oIdJobPosition"); + Department department = getDepartment(oIdDepartment, accessToken); + Position position = getPosition(oIdJobPosition, accessToken); + + Employee employeeObject = JSONObject.parseObject(employeeInfo.toJSONString(), Employee.class); + if (null != department) { + employeeObject.setDepartmentCode(department.getCode()); + } + if (null != position) { + employeeObject.setPositionCode(position.getCode()); + } + employeeList.add(employeeObject); + } + return getPendingEmployment(startTime, stopTime, empStatus, employType, accessToken, scrollId, employeeList); + } + + /** + * 获取access_token + * + * @return + */ + private String getToken() { + JSONObject json = new JSONObject(); + json.put("grant_type", "client_credentials"); + json.put("app_key", APP_KEY); + json.put("app_secret", APP_SECRET); + rs.writeLog("获取token,入参", json.toString()); + String response = HttpRequest.post(TOKEN_URL) + .body(json.toString()) + .contentType("application/json") + .execute() + .body(); + rs.writeLog("获取token,返参", response); + JSONObject jsonObject = JSONObject.parseObject(response); + + String accessToken = jsonObject.getString("access_token"); + if (StringUtils.isBlank(accessToken)) { + throw new RuntimeException("获取token失败"); + } + return accessToken; + } + + + /** + * 获取部门信息 + * + * @param oId + * @param accessToken + * @return + */ + private Department getDepartment(String oId, String accessToken) { + JSONObject json = new JSONObject(); + json.put("oIds", new String[]{oId}); + rs.writeLog("GET_DEPARTMENT_URL,入参", json.toString()); + String response = HttpRequest.post(GET_DEPARTMENT_URL) + .header("Authorization", "Bearer " + accessToken) + .body(json.toString()) + .contentType("application/json") + .execute() + .body(); + rs.writeLog("GET_DEPARTMENT_URL,返参", response); + JSONObject jsonObject = JSONObject.parseObject(response); + + String code = jsonObject.getString("code"); + if (!"200".equals(code)) { + throw new RuntimeException("GET_DEPARTMENT_URL接口调用失败"); + } + JSONArray data = jsonObject.getJSONArray("data"); + if (data.size() == 0) { + return null; + } + Department department = new Department(); + JSONObject dataObject = data.getJSONObject(0); + department.setOId(dataObject.getString("oId")); + department.setName(dataObject.getString("name")); + department.setShortName(dataObject.getString("shortName")); + return department; + + } + + /** + * 获取职位信息 + * + * @param oId + * @param accessToken + * @return + */ + private Position getPosition(String oId, String accessToken) { + JSONObject json = new JSONObject(); + json.put("oIds", new String[]{oId}); + rs.writeLog("GET_POSITION_URL,入参", json.toString()); + String response = HttpRequest.post(GET_POSITION_URL) + .header("Authorization", "Bearer " + accessToken) + .body(json.toString()) + .contentType("application/json") + .execute() + .body(); + rs.writeLog("GET_POSITION_URL,返参", response); + JSONObject jsonObject = JSONObject.parseObject(response); + + String code = jsonObject.getString("code"); + if (!"200".equals(code)) { + throw new RuntimeException("GET_POSITION_URL接口调用失败"); + } + JSONArray data = jsonObject.getJSONArray("data"); + if (data.size() == 0) { + return null; + } + JSONObject dataObject = data.getJSONObject(0); + + Position position = new Position(); + position.setOId(dataObject.getString("oId")); + position.setName(dataObject.getString("name")); + position.setCode(dataObject.getString("code")); + return position; + + } +}