|
@@ -1,81 +1,85 @@
|
|
-package org.fouram.service;
|
|
|
|
-
|
|
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-
|
|
|
|
-import org.fouram.constants.WebConstants;
|
|
|
|
-import org.fouram.core.base.service.BaseService;
|
|
|
|
-import org.fouram.core.base.service.RequestService;
|
|
|
|
-import org.fouram.core.util.JsonNodeUtil;
|
|
|
|
-import org.fouram.entity.SapEmpJob;
|
|
|
|
-import org.fouram.entity.SapUser;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
-import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
-import com.google.common.collect.Maps;
|
|
|
|
-
|
|
|
|
-@Service
|
|
|
|
-public class SapEmpJobService extends BaseService {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private RequestService requestService;
|
|
|
|
-
|
|
|
|
- public void setPosition(List<SapUser> sapUsers) {
|
|
|
|
- String url = "https://api15.sapsf.cn/odata/v2/EmpJob?$filter=userId in %s&$format=json";
|
|
|
|
- url = String.format(url, getUserIds(sapUsers));
|
|
|
|
- JsonNode node = requestService.getForObject(url, getHttpHeaders());
|
|
|
|
- Map<String, String> jobTitleMap = Maps.newHashMap();
|
|
|
|
- if (node != null) {
|
|
|
|
- Iterator<JsonNode> iterator = node.get("d").get("results").elements();
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
- JsonNode userNode = iterator.next();
|
|
|
|
- String userId = JsonNodeUtil.getValue(userNode, "userId");
|
|
|
|
- String jobTitle = JsonNodeUtil.getValue(userNode, "jobTitle");
|
|
|
|
- jobTitleMap.put(userId, jobTitle);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- for (SapUser sapUser : sapUsers) {
|
|
|
|
- sapUser.setPosition(jobTitleMap.get(sapUser.getUserId()));
|
|
|
|
- sapUser.setFormatPosition(formatPosition(sapUser.getPosition()));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void saveSapData() throws Exception {
|
|
|
|
- delete("SapEmpJobMapper.deleteAll", null);
|
|
|
|
-
|
|
|
|
- String url = "https://api15.sapsf.cn/odata/v2/EmpJob?$format=json"
|
|
|
|
- + "&$expand=positionNav,companyNav,businessUnitNav,divisionNav,departmentNav,customString19Nav,locationNav,jobCodeNav";
|
|
|
|
- JsonNode node = requestService.getForObject(url, getHttpHeaders());
|
|
|
|
- if (node != null) {
|
|
|
|
- Iterator<JsonNode> iterator = node.get("d").get("results").elements();
|
|
|
|
- while (iterator.hasNext()) {
|
|
|
|
- JsonNode userNode = iterator.next();
|
|
|
|
- String userId = JsonNodeUtil.getValue(userNode, "userId");
|
|
|
|
- String positionName = JsonNodeUtil.getValue(userNode, "positionNav", "externalName_zh_CN");// 职位
|
|
|
|
- String positionEntryDate = JsonNodeUtil.getValue(userNode, "positionEntryDate");// 就职日期
|
|
|
|
- String companyName = JsonNodeUtil.getValue(userNode, "companyNav", "name");// 公司
|
|
|
|
- String businessUnitName = JsonNodeUtil.getValue(userNode, "businessUnitNav", "name");// 业务单元
|
|
|
|
- String divisionName = JsonNodeUtil.getValue(userNode, "divisionNav", "name");// 部门
|
|
|
|
- String departmentName = JsonNodeUtil.getValue(userNode, "departmentNav", "name");// 团队
|
|
|
|
- String teamName = JsonNodeUtil.getValue(userNode, "customString19Nav", "externalName_zh_CN");// 小组
|
|
|
|
- String location = JsonNodeUtil.getValue(userNode, "location");// 工作地点
|
|
|
|
- String locationName = JsonNodeUtil.getValue(userNode, "locationNav", "name");// 工作地点
|
|
|
|
- String managerId = JsonNodeUtil.getValue(userNode, "managerId");// 直线经理
|
|
|
|
- String managerName = WebConstants.NAME_MAP.get(managerId);// 直线经理
|
|
|
|
- String jobCodeName = JsonNodeUtil.getValue(userNode, "jobCodeNav", "name");// 职务分类
|
|
|
|
- String jobTitle = JsonNodeUtil.getValue(userNode, "jobTitle");// 标准职务名称
|
|
|
|
- String rank = getLabelValue(JsonNodeUtil.getValue(userNode, "customString2"));// 职级
|
|
|
|
- String managementOrNot = getLabelValue(JsonNodeUtil.getValue(userNode, "customString4"));// 是否管理层
|
|
|
|
- SapEmpJob entity = SapEmpJob.builder().userId(userId).positionName(positionName)
|
|
|
|
- .positionEntryDate(positionEntryDate).companyName(companyName)
|
|
|
|
- .businessUnitName(businessUnitName).divisionName(divisionName).departmentName(departmentName)
|
|
|
|
- .teamName(teamName).location(location).locationName(locationName).managerId(managerId)
|
|
|
|
- .managerName(managerName).jobCodeName(jobCodeName).jobTitle(jobTitle).rank(rank)
|
|
|
|
- .managementOrNot(managementOrNot).build();
|
|
|
|
- save("SapEmpJobMapper.save", entity);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+package org.fouram.service;
|
|
|
|
+
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import org.fouram.constants.WebConstants;
|
|
|
|
+import org.fouram.core.base.service.BaseService;
|
|
|
|
+import org.fouram.core.base.service.RequestService;
|
|
|
|
+import org.fouram.core.util.JsonNodeUtil;
|
|
|
|
+import org.fouram.entity.SapEmpJob;
|
|
|
|
+import org.fouram.entity.SapUser;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class SapEmpJobService extends BaseService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RequestService requestService;
|
|
|
|
+
|
|
|
|
+ public void setPosition(List<SapUser> sapUsers) {
|
|
|
|
+ String url = "https://api15.sapsf.cn/odata/v2/EmpJob?$filter=userId in %s&$format=json";
|
|
|
|
+ url = String.format(url, getUserIds(sapUsers));
|
|
|
|
+ JsonNode node = requestService.getForObject(url, getHttpHeaders());
|
|
|
|
+ Map<String, String> jobTitleMap = Maps.newHashMap();
|
|
|
|
+ if (node != null) {
|
|
|
|
+ Iterator<JsonNode> iterator = node.get("d").get("results").elements();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ JsonNode userNode = iterator.next();
|
|
|
|
+ String userId = JsonNodeUtil.getValue(userNode, "userId");
|
|
|
|
+ String jobTitle = JsonNodeUtil.getValue(userNode, "jobTitle");
|
|
|
|
+ jobTitleMap.put(userId, jobTitle);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (SapUser sapUser : sapUsers) {
|
|
|
|
+ sapUser.setPosition(jobTitleMap.get(sapUser.getUserId()));
|
|
|
|
+ sapUser.setFormatPosition(formatPosition(sapUser.getPosition()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void saveSapData() throws Exception {
|
|
|
|
+ delete("SapEmpJobMapper.deleteAll", null);
|
|
|
|
+
|
|
|
|
+ String url = "https://api15.sapsf.cn/odata/v2/EmpJob?$format=json"
|
|
|
|
+ + "&$expand=positionNav,companyNav,businessUnitNav,divisionNav,departmentNav,customString19Nav,locationNav,jobCodeNav";
|
|
|
|
+ JsonNode node = requestService.getForObject(url, getHttpHeaders());
|
|
|
|
+ if (node != null) {
|
|
|
|
+ Iterator<JsonNode> iterator = node.get("d").get("results").elements();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ JsonNode userNode = iterator.next();
|
|
|
|
+ String userId = JsonNodeUtil.getValue(userNode, "userId");
|
|
|
|
+ String positionName = JsonNodeUtil.getValue(userNode, "positionNav", "externalName_zh_CN");// 职位
|
|
|
|
+ String positionEntryDate = JsonNodeUtil.getValue(userNode, "positionEntryDate");// 就职日期
|
|
|
|
+ String companyName = JsonNodeUtil.getValue(userNode, "companyNav", "name");// 公司
|
|
|
|
+ String businessUnitName = JsonNodeUtil.getValue(userNode, "businessUnitNav", "name");// 业务单元
|
|
|
|
+ String divisionName = JsonNodeUtil.getValue(userNode, "divisionNav", "name");// 部门
|
|
|
|
+ String departmentName = JsonNodeUtil.getValue(userNode, "departmentNav", "name");// 团队
|
|
|
|
+ String teamName = JsonNodeUtil.getValue(userNode, "customString19Nav", "externalName_zh_CN");// 小组
|
|
|
|
+ String location = JsonNodeUtil.getValue(userNode, "location");// 工作地点
|
|
|
|
+ String locationName = JsonNodeUtil.getValue(userNode, "locationNav", "name");// 工作地点
|
|
|
|
+ String managerId = JsonNodeUtil.getValue(userNode, "managerId");// 直线经理
|
|
|
|
+ String managerName = WebConstants.NAME_MAP.get(managerId);// 直线经理
|
|
|
|
+ String jobCodeName = JsonNodeUtil.getValue(userNode, "jobCodeNav", "name");// 职务分类
|
|
|
|
+ String jobTitle = JsonNodeUtil.getValue(userNode, "jobTitle");// 标准职务名称
|
|
|
|
+ String rank = getLabelValue(JsonNodeUtil.getValue(userNode, "customString2"));// 职级
|
|
|
|
+ String managementOrNot = getLabelValue(JsonNodeUtil.getValue(userNode, "customString4"));// 是否管理层
|
|
|
|
+ SapEmpJob entity = SapEmpJob.builder().userId(userId).positionName(positionName)
|
|
|
|
+ .positionEntryDate(positionEntryDate).companyName(companyName)
|
|
|
|
+ .businessUnitName(businessUnitName).divisionName(divisionName).departmentName(departmentName)
|
|
|
|
+ .teamName(teamName).location(location).locationName(locationName).managerId(managerId)
|
|
|
|
+ .managerName(managerName).jobCodeName(jobCodeName).jobTitle(jobTitle).rank(rank)
|
|
|
|
+ .managementOrNot(managementOrNot).build();
|
|
|
|
+ save("SapEmpJobMapper.save", entity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public SapEmpJob selectOneByPersonId(String personId) throws Exception {
|
|
|
|
+ return (SapEmpJob) findObject("SapEmpJobMapper.selectOneByPersonId", personId);
|
|
|
|
+ }
|
|
|
|
+}
|