|
@@ -11,12 +11,14 @@ import com.malk.server.common.McException;
|
|
|
import com.malk.server.eiam.EiamApiResponse;
|
|
import com.malk.server.eiam.EiamApiResponse;
|
|
|
import com.malk.server.eiam.EiamConf;
|
|
import com.malk.server.eiam.EiamConf;
|
|
|
import com.malk.server.eiam.EiamCustomField;
|
|
import com.malk.server.eiam.EiamCustomField;
|
|
|
|
|
+import com.malk.server.eiam.EiamCustomFieldUpdate;
|
|
|
import com.malk.service.eiam.EiamClient_User;
|
|
import com.malk.service.eiam.EiamClient_User;
|
|
|
import com.malk.service.eiam.EiamService;
|
|
import com.malk.service.eiam.EiamService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -107,7 +109,7 @@ public class EiamLocalService {
|
|
|
|
|
|
|
|
private EiamBatchItemResult updateOne(String token, EiamUpdateUserItem item, int index) {
|
|
private EiamBatchItemResult updateOne(String token, EiamUpdateUserItem item, int index) {
|
|
|
EiamBatchStage stage = EiamBatchStage.VALIDATE;
|
|
EiamBatchStage stage = EiamBatchStage.VALIDATE;
|
|
|
- boolean patchCompleted = false;
|
|
|
|
|
|
|
+ boolean updateCompleted = false;
|
|
|
try {
|
|
try {
|
|
|
validateUpdateItem(item);
|
|
validateUpdateItem(item);
|
|
|
Map<String, Object> patchBody = updateBody(item);
|
|
Map<String, Object> patchBody = updateBody(item);
|
|
@@ -115,19 +117,26 @@ public class EiamLocalService {
|
|
|
stage = EiamBatchStage.PATCH_USER;
|
|
stage = EiamBatchStage.PATCH_USER;
|
|
|
assertEiamSuccess(eiamClientUser.patchUser(token, eiamConf.getInstanceId(),
|
|
assertEiamSuccess(eiamClientUser.patchUser(token, eiamConf.getInstanceId(),
|
|
|
eiamConf.getApplicationId(), item.getUserId(), patchBody));
|
|
eiamConf.getApplicationId(), item.getUserId(), patchBody));
|
|
|
- patchCompleted = true;
|
|
|
|
|
|
|
+ updateCompleted = true;
|
|
|
}
|
|
}
|
|
|
if (StringUtils.isNotBlank(item.getPrimaryOrganizationalUnitId())) {
|
|
if (StringUtils.isNotBlank(item.getPrimaryOrganizationalUnitId())) {
|
|
|
stage = EiamBatchStage.SET_PRIMARY_ORG;
|
|
stage = EiamBatchStage.SET_PRIMARY_ORG;
|
|
|
assertEiamSuccess(eiamClientUser.setUserPrimaryOrganizationalUnit(token,
|
|
assertEiamSuccess(eiamClientUser.setUserPrimaryOrganizationalUnit(token,
|
|
|
eiamConf.getInstanceId(), eiamConf.getApplicationId(), item.getUserId(),
|
|
eiamConf.getInstanceId(), eiamConf.getApplicationId(), item.getUserId(),
|
|
|
item.getPrimaryOrganizationalUnitId()));
|
|
item.getPrimaryOrganizationalUnitId()));
|
|
|
|
|
+ updateCompleted = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(item.getAdditionalOrganizationalUnitId())) {
|
|
|
|
|
+ stage = EiamBatchStage.ADD_ORG;
|
|
|
|
|
+ assertEiamSuccess(eiamClientUser.addUserToOrganizationalUnits(token,
|
|
|
|
|
+ eiamConf.getInstanceId(), eiamConf.getApplicationId(), item.getUserId(),
|
|
|
|
|
+ Collections.singletonList(item.getAdditionalOrganizationalUnitId())));
|
|
|
}
|
|
}
|
|
|
return success(index, item.getFormInstanceId(), userKey(item), item.getUserId());
|
|
return success(index, item.getFormInstanceId(), userKey(item), item.getUserId());
|
|
|
} catch (RuntimeException ex) {
|
|
} catch (RuntimeException ex) {
|
|
|
return failure(index, item == null ? null : item.getFormInstanceId(),
|
|
return failure(index, item == null ? null : item.getFormInstanceId(),
|
|
|
item == null ? null : userKey(item), item == null ? null : item.getUserId(),
|
|
item == null ? null : userKey(item), item == null ? null : item.getUserId(),
|
|
|
- stage, ex, patchCompleted && stage == EiamBatchStage.SET_PRIMARY_ORG);
|
|
|
|
|
|
|
+ stage, ex, updateCompleted);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -188,7 +197,7 @@ public class EiamLocalService {
|
|
|
if (StringUtils.isNotBlank(item.getEmail())) {
|
|
if (StringUtils.isNotBlank(item.getEmail())) {
|
|
|
body.put("emailVerified", false);
|
|
body.put("emailVerified", false);
|
|
|
}
|
|
}
|
|
|
- if (item.getCustomFields() != null) {
|
|
|
|
|
|
|
+ if (item.getCustomFields() != null && !item.getCustomFields().isEmpty()) {
|
|
|
body.put("customFields", item.getCustomFields());
|
|
body.put("customFields", item.getCustomFields());
|
|
|
}
|
|
}
|
|
|
return body;
|
|
return body;
|
|
@@ -230,11 +239,39 @@ public class EiamLocalService {
|
|
|
if (item == null || StringUtils.isBlank(item.getUserId())) {
|
|
if (item == null || StringUtils.isBlank(item.getUserId())) {
|
|
|
throw new McException("EIAM_ITEM_INVALID", "userId 不能为空");
|
|
throw new McException("EIAM_ITEM_INVALID", "userId 不能为空");
|
|
|
}
|
|
}
|
|
|
- if (updateBody(item).isEmpty() && StringUtils.isBlank(item.getPrimaryOrganizationalUnitId())) {
|
|
|
|
|
|
|
+ if (containsUpdateContent(item, BentelerYidaFormMapper.UPDATE_PHONE)
|
|
|
|
|
+ && StringUtils.isBlank(item.getPhoneNumber())) {
|
|
|
|
|
+ throw new McException("EIAM_ITEM_INVALID", "手机号不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (containsUpdateContent(item, BentelerYidaFormMapper.UPDATE_EMPLOYEE_NUMBER)) {
|
|
|
|
|
+ validateCustomFieldUpdate(item, "employee_id_number", "工号");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (containsUpdateContent(item, BentelerYidaFormMapper.UPDATE_JOB_TITLE)) {
|
|
|
|
|
+ validateCustomFieldUpdate(item, "job_title", "职位");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (updateBody(item).isEmpty() && StringUtils.isBlank(item.getPrimaryOrganizationalUnitId())
|
|
|
|
|
+ && StringUtils.isBlank(item.getAdditionalOrganizationalUnitId())) {
|
|
|
throw new McException("EIAM_ITEM_INVALID", "更新内容不能为空");
|
|
throw new McException("EIAM_ITEM_INVALID", "更新内容不能为空");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean containsUpdateContent(EiamUpdateUserItem item, String updateContent) {
|
|
|
|
|
+ return item.getUpdateContents() != null && item.getUpdateContents().contains(updateContent);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void validateCustomFieldUpdate(EiamUpdateUserItem item, String fieldName,
|
|
|
|
|
+ String displayName) {
|
|
|
|
|
+ if (item.getCustomFields() != null) {
|
|
|
|
|
+ for (EiamCustomFieldUpdate field : item.getCustomFields()) {
|
|
|
|
|
+ if (field != null && StringUtils.equals(fieldName, field.getFieldName())
|
|
|
|
|
+ && StringUtils.isNotBlank(field.getFieldValue())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new McException("EIAM_ITEM_INVALID", displayName + " 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void validateBatch(List<?> items) {
|
|
private void validateBatch(List<?> items) {
|
|
|
if (items == null || items.isEmpty()) {
|
|
if (items == null || items.isEmpty()) {
|
|
|
throw new McException("EIAM_BATCH_EMPTY", "items 不能为空");
|
|
throw new McException("EIAM_BATCH_EMPTY", "items 不能为空");
|