|
|
@@ -59,6 +59,7 @@ import java.util.*;
|
|
|
public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonToBeisenFacadeControllerBean {
|
|
|
private static Logger logger = Logger.getLogger(SyncPersonToBeisenFacadeControllerBean.class);
|
|
|
private BeisenApiClient beisenApiClient = null;
|
|
|
+ private static final String BESON_CONFIG_PATH = "/server/properties/beisen/BeiSenConfig.properties";
|
|
|
|
|
|
public SyncPersonToBeisenFacadeControllerBean() {
|
|
|
beisenApiClient = BeisenApiClient.getInstance();
|
|
|
@@ -146,7 +147,7 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
filterItems.add(new FilterItemInfo("person", personIds, CompareType.INCLUDE));
|
|
|
}
|
|
|
try {
|
|
|
- BeisenParamByPropertiesUtil beisenParamByProperties = new BeisenParamByPropertiesUtil("/server/properties/beisen/BeiSenConfig.properties");
|
|
|
+ BeisenParamByPropertiesUtil beisenParamByProperties = new BeisenParamByPropertiesUtil(BESON_CONFIG_PATH);
|
|
|
Map<String, String> config = beisenParamByProperties.getConfig();
|
|
|
logger.error("config---" + config.size());
|
|
|
// 查询所有人的user用户
|
|
|
@@ -171,12 +172,19 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
}
|
|
|
for (int i = 0; i < personPositionCollection.size(); i++) {
|
|
|
Map msgMap = new HashMap();
|
|
|
- JSONObject personJson = new JSONObject();
|
|
|
PersonPositionInfo personPositionInfo = personPositionCollection.get(i);
|
|
|
PersonInfo person = personPositionInfo.getPerson();
|
|
|
- // 入职ID
|
|
|
- Object bsUserId = person.get("bsUserId");
|
|
|
- Object beisenId = person.get("beisenId");
|
|
|
+ String email = person.getEmail();
|
|
|
+ if (StringUtils.isEmpty(email)) {
|
|
|
+ // throw new BOSException(person.getName() + "同步失败:邮箱不能为空,请维护!!");
|
|
|
+ msgMap.put("message", person.getName() + "同步失败:邮箱不能为空,请维护!!");
|
|
|
+ jsonArray.add(msgMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Object bsUserId = person.get("bsUserId"); // 用户ID
|
|
|
+ Object beisenId = person.get("beisenId");// 入职单基本信息ID
|
|
|
logger.error("bsUserId--" + bsUserId);
|
|
|
logger.error("beisenId--" + beisenId);
|
|
|
String originalId = URLEncoder.encode(person.getId().toString(), StandardCharsets.UTF_8.name());
|
|
|
@@ -187,53 +195,57 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
msgMap.put("originalId", originalId);
|
|
|
msgMap.put("bsUserId", bsUserId);
|
|
|
msgMap.put("beisenId", beisenId);
|
|
|
- EmployeeTypeInfo employeeType = person.getEmployeeType();
|
|
|
- EmployeeTypeEnum inServiceEnum = employeeType.getInService();
|
|
|
- String email = person.getEmail();
|
|
|
- if (StringUtils.isEmpty(email)) {
|
|
|
- // throw new BOSException(person.getName() + "同步失败:邮箱不能为空,请维护!!");
|
|
|
- msgMap.put("message", person.getName() + "同步失败:邮箱不能为空,请维护!!");
|
|
|
- jsonArray.add(msgMap);
|
|
|
- continue;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject personJson = new JSONObject();
|
|
|
+ // 基本信息
|
|
|
personJson.put("email", email);// 邮箱
|
|
|
personJson.put("userName", email);// 用户名
|
|
|
personJson.put("name", name);// 姓名
|
|
|
personJson.put("originalId", person.getId().toString());// 来源方用户ID
|
|
|
- // 来源(创建更新必填字段) 员工创建时的业务来源。0:其他;1:平台;2:测评;3:招聘;4:360;5:自由注册;6:Tita;7:Tita移动端;1001:PeopleSoft
|
|
|
- personJson.put("origin", 1);
|
|
|
personJson.put("mobile", nCell);// 手机号
|
|
|
+ // 用工信息
|
|
|
+ EmployeeTypeInfo employeeType = person.getEmployeeType();
|
|
|
+ EmployeeTypeEnum inServiceEnum = employeeType.getInService();
|
|
|
+ personJson.put("origin", 1);// 1:平台
|
|
|
personJson.put(config.get("EMPLOYEETYPENUMBER"), employeeType.getNumber());// 用工关系状态
|
|
|
+ // 组织信息
|
|
|
AdminOrgUnitInfo personDep = personPositionInfo.getPersonDep();
|
|
|
personJson.put("departmentOriginalId", personDep.getId());// 部门外部标识
|
|
|
personJson.put(config.get("HIREDATE"), DateTimeUtils.format(person.getHireDate()));// 入职日期
|
|
|
+ // 上级信息
|
|
|
Object lineManagerOriginalId = personParentMap.get(personId) == null ? null : URLEncoder.encode(personParentMap.get(personId).toString(), StandardCharsets.UTF_8.name());
|
|
|
personJson.put(config.get("lineManagerOriginalId"), lineManagerOriginalId);// 直线上级外部标识
|
|
|
+ // 岗位信息
|
|
|
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() + "已离职无需同步北森!!");
|
|
|
- jsonArray.add(msgMap);
|
|
|
- continue;
|
|
|
- }
|
|
|
- // 创建员工信息
|
|
|
- String staffsPost = config.get("STAFFSPOST");
|
|
|
- logger.error("personJson--" + personJson);
|
|
|
- JSONObject staffs = beisenApiClient.callApi(staffsPost, personJson);
|
|
|
- if (!"200".equals(staffs.getString("code"))) {
|
|
|
- msgMap.put("message", "创建员工信息失败,原因:" + staffs.get("message"));
|
|
|
- jsonArray.add(msgMap);
|
|
|
- continue;
|
|
|
+ if (bsUserId == null) {
|
|
|
+ // 判断是否在职
|
|
|
+ if (inServiceEnum.getValue() == 2) {
|
|
|
+ msgMap.put("message", person.getName() + "已离职无需同步北森!!");
|
|
|
+ jsonArray.add(msgMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 创建员工信息
|
|
|
+ String staffsPost = config.get("STAFFSPOST");
|
|
|
+ logger.error("personJson--" + personJson);
|
|
|
+ JSONObject staffs = beisenApiClient.callApi(staffsPost, personJson);
|
|
|
+ if (!"200".equals(staffs.getString("code"))) {
|
|
|
+ msgMap.put("message", "创建员工信息失败,原因:" + staffs.get("message"));
|
|
|
+ jsonArray.add(msgMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String data = staffs.getString("data");
|
|
|
+ // 更新bsUserId
|
|
|
+ updatePersonBensenId(ctx, person, data);
|
|
|
+ msgMap.put("bsUserId", data);
|
|
|
+ msgMap.put("创建员工信息:", staffs.get("message"));
|
|
|
+ } else {
|
|
|
+ updatePersonInfoInBeisen(personJson, config, (String) bsUserId, msgMap);
|
|
|
}
|
|
|
- String data = staffs.getString("data");
|
|
|
- // 更新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);
|
|
|
@@ -256,15 +268,7 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
// 更新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"));
|
|
|
+ updatePersonInfoInBeisen(personJson, config, userId, msgMap);
|
|
|
// 更新bsUserId
|
|
|
updatePersonBensenId(ctx, person, userId);
|
|
|
// 更新待入职人员信息
|
|
|
@@ -313,6 +317,19 @@ public class SyncPersonToBeisenFacadeControllerBean extends AbstractSyncPersonTo
|
|
|
logger.error("jsonArray--" + jsonArray);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新北森中的人员信息
|
|
|
+ */
|
|
|
+ private void updatePersonInfoInBeisen(JSONObject personJson, Map<String, String> config, String userId, Map msgMap) throws IOException {
|
|
|
+ // 删除用户名,不修改用户名
|
|
|
+ personJson.remove("userName");
|
|
|
+ String putbyuserid = config.get("PUTBYUSERID") + "?userId=" + userId;
|
|
|
+ logger.error("putbyuserid--" + putbyuserid);
|
|
|
+ logger.error("personJson--" + personJson);
|
|
|
+ JSONObject updateStaffs = beisenApiClient.callPutApi(putbyuserid, personJson);
|
|
|
+ msgMap.put("通过userId更新员工信息:", updateStaffs.get("message"));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通过bsUserId修改北森用户管理的外部Id
|
|
|
*
|