|
|
@@ -50,6 +50,7 @@ import com.kingdee.eas.common.EASBizException;
|
|
|
|
|
|
import java.lang.String;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -148,8 +149,6 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
BeisenParamByPropertiesUtil beisenParamByProperties = new BeisenParamByPropertiesUtil("/server/properties/beisen/BeiSenConfig.properties");
|
|
|
Map<String, String> config = beisenParamByProperties.getConfig();
|
|
|
logger.error("config---" + config.size());
|
|
|
- // 员工
|
|
|
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
|
|
|
// 查询所有人的user用户
|
|
|
IUser iUser = UserFactory.getLocalInstance(ctx);
|
|
|
UserCollection userCollection = iUser.getUserCollection();
|
|
|
@@ -177,17 +176,19 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
PersonInfo person = personPositionInfo.getPerson();
|
|
|
// 入职ID
|
|
|
Object bsUserId = person.get("bsUserId");
|
|
|
+ Object beisenId = person.get("beisenId");
|
|
|
logger.error("bsUserId--" + bsUserId);
|
|
|
+ logger.error("beisenId--" + beisenId);
|
|
|
String originalId = URLEncoder.encode(person.getId().toString(), StandardCharsets.UTF_8.name());
|
|
|
String nCell = person.getNCell();
|
|
|
String name = person.getName();
|
|
|
msgMap.put("number", person.getNumber());
|
|
|
msgMap.put("name", name);
|
|
|
msgMap.put("originalId", originalId);
|
|
|
+ msgMap.put("bsUserId", bsUserId);
|
|
|
+ msgMap.put("beisenId", beisenId);
|
|
|
EmployeeTypeInfo employeeType = person.getEmployeeType();
|
|
|
- // 调用新增接口---禁用系统用户账号 状态1:在职 3:离职
|
|
|
EmployeeTypeEnum inServiceEnum = employeeType.getInService();
|
|
|
- Object beisenId = person.get("beisenId");
|
|
|
String email = person.getEmail();
|
|
|
if (StringUtils.isEmpty(email)) {
|
|
|
// throw new BOSException(person.getName() + "同步失败:邮箱不能为空,请维护!!");
|
|
|
@@ -211,12 +212,11 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
PositionInfo primaryPosition = personPositionInfo.getPrimaryPosition();
|
|
|
personJson.put(config.get("positionNumber"), primaryPosition.getNumber());// 岗位编码
|
|
|
personJson.put(config.get("positionName"), primaryPosition.getName());// 岗位名称
|
|
|
-
|
|
|
// 判断是否在北森存在 如果beisenId为空并且是在职状态需要再北森创建员工
|
|
|
if (beisenId == null) {
|
|
|
// 判断是否在职
|
|
|
if (inServiceEnum.getValue() == 2) {
|
|
|
- msgMap.put("message",person.getName() + "已离职无需同步北森!!");
|
|
|
+ msgMap.put("message", person.getName() + "已离职无需同步北森!!");
|
|
|
jsonArray.add(msgMap);
|
|
|
continue;
|
|
|
}
|
|
|
@@ -225,17 +225,62 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
logger.error("personJson--" + personJson);
|
|
|
JSONObject staffs = beisenApiClient.callApi(staffsPost, personJson);
|
|
|
if (!"200".equals(staffs.getString("code"))) {
|
|
|
- msgMap.put("message","创建员工信息失败,原因:" + staffs.get("message"));
|
|
|
+ msgMap.put("message", "创建员工信息失败,原因:" + staffs.get("message"));
|
|
|
jsonArray.add(msgMap);
|
|
|
continue;
|
|
|
}
|
|
|
String data = staffs.getString("data");
|
|
|
- person.put("beisenId", data);
|
|
|
- SelectorItemCollection personUpdSic = new SelectorItemCollection();
|
|
|
- personUpdSic.add("beisenId");
|
|
|
- iPerson.updatePartial(person, personUpdSic);
|
|
|
- msgMap.put("staffsMessage:", staffs.get("message"));
|
|
|
+ // 更新bsUserId
|
|
|
+ updatePersonBensenId(ctx, person, data);
|
|
|
+ msgMap.put("bsUserId", data);
|
|
|
+ msgMap.put("创建员工信息:", staffs.get("message"));
|
|
|
} else {
|
|
|
+ // 查询待入职人员信息 通过beisenId 入职员工ID获取入职记录guid和userId
|
|
|
+ Map<String, String> result = getGuid(config, beisenId);
|
|
|
+ logger.error("result--" + result);
|
|
|
+ if (result == null || result.isEmpty()) {
|
|
|
+ msgMap.put("message", "入职ID[" + beisenId + "]未查询到入职信息!");
|
|
|
+ jsonArray.add(msgMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String userId = result.get("userID");
|
|
|
+ // 判断userid是否等于shr员工信息维护的北森id,如果不等于通过bsUserId修改北森用户管理的外部Id
|
|
|
+ logger.error("bsUserId == null" + bsUserId == null);
|
|
|
+ if (bsUserId == null) {
|
|
|
+ bsUserId = userId;
|
|
|
+ }
|
|
|
+ logger.error(person.getName() + ":" + userId + "--" + bsUserId);
|
|
|
+ msgMap.put("userID", userId);
|
|
|
+ if (userId != bsUserId) {
|
|
|
+ updateBeisenOriginalIdByUserId(msgMap, config, bsUserId);
|
|
|
+ // 更新bsUserId
|
|
|
+ updatePersonBensenId(ctx, person, (String) bsUserId);
|
|
|
+ }
|
|
|
+ // 通过OriginalId更新员工信息
|
|
|
+ JSONObject udpatePersonJson = personJson;
|
|
|
+ // 删除用户名,不修改用户名
|
|
|
+ udpatePersonJson.remove("userName");
|
|
|
+ String putbyuserid = config.get("PUTBYUSERID") + "?userId=" + userId;
|
|
|
+ logger.error("putbyuserid--" + putbyuserid);
|
|
|
+ logger.error("udpatePersonJson--" + udpatePersonJson);
|
|
|
+ JSONObject updateStaffs = beisenApiClient.callPutApi(putbyuserid, udpatePersonJson);
|
|
|
+ msgMap.put("通过userId更新员工信息:", updateStaffs.get("message"));
|
|
|
+ // 更新bsUserId
|
|
|
+ updatePersonBensenId(ctx, person, userId);
|
|
|
+ // 更新待入职人员信息
|
|
|
+ if (beisenId != null) {
|
|
|
+ JSONObject updateStaffInfo = new JSONObject();
|
|
|
+ JSONObject staffInfos = new JSONObject();
|
|
|
+ staffInfos.put("id", beisenId);
|
|
|
+ staffInfos.put("name", name);
|
|
|
+ // staffInfos.put("email", email);
|
|
|
+ staffInfos.put("mobilePhone", nCell);
|
|
|
+ staffInfos.put("staffStatus", 1);
|
|
|
+ updateStaffInfo.put("staffInfos", staffInfos);
|
|
|
+ logger.error("updateStaffInfo--" + updateStaffInfo);
|
|
|
+ JSONObject updateStaffRet = beisenApiClient.callApi(config.get("UPDATESTAFFURL"), updateStaffInfo);
|
|
|
+ msgMap.put("更新待入职人员信息:", updateStaffRet.get("code"));
|
|
|
+ }
|
|
|
// 通过userId更新员工信息
|
|
|
if (inServiceEnum.getValue() == 2 || inServiceEnum.getValue() == 0) {
|
|
|
// 通过OriginalId设置员工离职
|
|
|
@@ -243,11 +288,8 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
logger.error("putSetdimission--" + putSetdimission);
|
|
|
JSONObject setdimission = beisenApiClient.callPutApi(putSetdimission, new JSONObject());
|
|
|
msgMap.put("通过OriginalId设置员工离职:", setdimission.get("message"));
|
|
|
- // 查询待入职人员信息 通过bsUserId 入职员工ID获取入职记录guid
|
|
|
- String guid = getGuid(config, bsUserId);
|
|
|
- logger.error("guid--" + guid);
|
|
|
// 入职管理设置离职
|
|
|
- String recruitOnBoardingPost = config.get("RECRUITONBOARDINGPOST") + "?entryId=" + guid;
|
|
|
+ String recruitOnBoardingPost = config.get("RECRUITONBOARDINGPOST") + "?entryId=" + result.get("guid");
|
|
|
logger.error("recruitOnBoardingPost--" + recruitOnBoardingPost);
|
|
|
JSONObject recruitOnBoarding = beisenApiClient.callApi(recruitOnBoardingPost, new JSONObject());
|
|
|
msgMap.put("入职单设置离职:", recruitOnBoarding.get("message"));
|
|
|
@@ -259,29 +301,6 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
JSONObject setinduction = beisenApiClient.callPutApi(putSetinduction, new JSONObject());
|
|
|
msgMap.put("设置员工在职:", setinduction.get("message"));
|
|
|
}
|
|
|
- // 通过OriginalId更新员工信息
|
|
|
- JSONObject udpatePersonJson = personJson;
|
|
|
- // 删除用户名,不修改用户名
|
|
|
- udpatePersonJson.remove("userName");
|
|
|
- String putByOriginalId = config.get("PUTBYORIGINALID") + "?originalId=" + originalId;
|
|
|
- logger.error("putByOriginalId--" + putByOriginalId);
|
|
|
- logger.error("udpatePersonJson--" + udpatePersonJson);
|
|
|
- JSONObject updateStaffs = beisenApiClient.callPutApi(putByOriginalId, udpatePersonJson);
|
|
|
- msgMap.put("通过OriginalId更新员工信息:", updateStaffs.get("message"));
|
|
|
- // 更新待入职人员信息
|
|
|
- if (bsUserId != null) {
|
|
|
- JSONObject updateStaffInfo = new JSONObject();
|
|
|
- JSONObject staffInfos = new JSONObject();
|
|
|
- staffInfos.put("id", bsUserId);
|
|
|
- staffInfos.put("name", name);
|
|
|
- staffInfos.put("email", email);
|
|
|
- staffInfos.put("mobilePhone", nCell);
|
|
|
- staffInfos.put("staffStatus", 1);
|
|
|
- updateStaffInfo.put("staffInfos", staffInfos);
|
|
|
- logger.error("updateStaffInfo--" + updateStaffInfo);
|
|
|
- JSONObject updateStaffRet = beisenApiClient.callApi(config.get("UPDATESTAFFURL"), updateStaffInfo);
|
|
|
- msgMap.put("更新待入职人员信息:", updateStaffRet.get("code"));
|
|
|
- }
|
|
|
}
|
|
|
jsonArray.add(msgMap);
|
|
|
}
|
|
|
@@ -295,31 +314,83 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 查询待入职人员信息 通过bsUserId 入职员工ID获取入职记录guid
|
|
|
+ * 通过bsUserId修改北森用户管理的外部Id
|
|
|
*
|
|
|
- * @param config
|
|
|
* @param bsUserId
|
|
|
+ */
|
|
|
+ public void updateBeisenOriginalIdByUserId(Map map, Map config, Object bsUserId) throws IOException {
|
|
|
+ String putbyuserid = config.get("PUTBYUSERID") + "?userId=" + bsUserId;
|
|
|
+ JSONObject udpatePersonJson = new JSONObject();
|
|
|
+ udpatePersonJson.put("originalId", "");
|
|
|
+ udpatePersonJson.put("email", "");
|
|
|
+ JSONObject json = beisenApiClient.callPutApi(putbyuserid, udpatePersonJson);
|
|
|
+ map.put("修改北森用户管理的外部Id:", json.get("message"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param person
|
|
|
+ * @throws BOSException
|
|
|
+ * @throws EASBizException
|
|
|
+ */
|
|
|
+ private static void updatePersonBensenId(Context ctx, PersonInfo person, String bsUserId) throws BOSException, EASBizException {
|
|
|
+ // 员工
|
|
|
+ IPerson iPerson = PersonFactory.getLocalInstance(ctx);
|
|
|
+ person.put("bsUserId", bsUserId);
|
|
|
+ SelectorItemCollection personUpdSic = new SelectorItemCollection();
|
|
|
+ personUpdSic.add("bsUserId");
|
|
|
+ iPerson.updatePartial(person, personUpdSic);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询待入职人员信息 通过beisenId 入职员工ID获取入职记录guid
|
|
|
+ *
|
|
|
+ * @param config
|
|
|
+ * @param beisenId
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getGuid(Map<String, String> config, Object bsUserId) throws IOException {
|
|
|
- String guid = null;
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
- jsonArray.add(bsUserId);
|
|
|
- JSONObject staffInfos = beisenApiClient.callApi(config.get("GETSTAFFINFOS"), jsonArray);
|
|
|
- logger.error("staffInfos--" + staffInfos);
|
|
|
- if (staffInfos.getInteger("code") == 200) {
|
|
|
- JSONArray data = staffInfos.getJSONArray("data");
|
|
|
- for (int i = 0; i < data.size(); i++) {
|
|
|
- JSONObject dataJson = data.getJSONObject(i);
|
|
|
- logger.error("dataJson--" + dataJson);
|
|
|
- JSONArray entryRecord = dataJson.getJSONArray("entryRecord");
|
|
|
- for (int j = 0; j < entryRecord.size(); j++) {
|
|
|
- JSONObject entry = entryRecord.getJSONObject(j);
|
|
|
- guid = entry.getString("id");
|
|
|
+ public Map getGuid(Map<String, String> config, Object beisenId) {
|
|
|
+ Map<String, String> result = null;
|
|
|
+ try {
|
|
|
+ result = new HashMap<>();
|
|
|
+ String guid = null;
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ jsonArray.add(beisenId);
|
|
|
+ JSONObject staffInfos = beisenApiClient.callApi(config.get("GETSTAFFINFOS"), jsonArray);
|
|
|
+ logger.error("staffInfos--" + staffInfos);
|
|
|
+ if (staffInfos.getInteger("code") == 200) {
|
|
|
+ JSONArray data = staffInfos.getJSONArray("data");
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject dataJson = data.getJSONObject(i);
|
|
|
+ logger.error("dataJson--" + dataJson);
|
|
|
+ // entryRecord 入职记录
|
|
|
+ JSONArray entryRecord = dataJson.getJSONArray("entryRecord");
|
|
|
+ for (int j = 0; j < entryRecord.size(); j++) {
|
|
|
+ JSONObject entry = entryRecord.getJSONObject(j);
|
|
|
+ if (entry.getInteger("status") == 1 || entry.getInteger("status") == 0) {
|
|
|
+ guid = entry.getString("id");
|
|
|
+ result.put("guid", guid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 任职记录
|
|
|
+ Long dataTime = 0l;
|
|
|
+ JSONArray employmentRecord = dataJson.getJSONArray("employmentRecord");
|
|
|
+ for (int q = 0; q < employmentRecord.size(); q++) {
|
|
|
+ JSONObject employment = employmentRecord.getJSONObject(q);
|
|
|
+ String entryDate = employment.getString("entryDate");
|
|
|
+ logger.debug("entryDate--" + entryDate);
|
|
|
+ // 处理entryDate为空的数据必须要保存一条数据,如果不为空则保存最新的一条数据
|
|
|
+ result.put("userID", employment.getString("userID"));
|
|
|
+ if (!StringUtils.isEmpty(entryDate) && DateTimeUtils.parseDate(entryDate).getTime() > dataTime) {
|
|
|
+ result.put("userID", employment.getString("userID"));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
}
|
|
|
- return guid;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -386,9 +457,8 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
sic.add("personDep.number");
|
|
|
sic.add("personDep.id");
|
|
|
sic.add("personDep.parent.id");
|
|
|
- sic.add("personDep.primaryPosition.name");
|
|
|
- sic.add("personDep.primaryPosition.number");
|
|
|
+ sic.add("primaryPosition.name");
|
|
|
+ sic.add("primaryPosition.number");
|
|
|
return sic;
|
|
|
}
|
|
|
-
|
|
|
}
|