liupeng 4 years ago
parent
commit
aa154c9c1a

+ 18 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapPerPersonalMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="SapPerPersonalMapper">
+
+	<insert id="save">
+		insert into sap_per_personal(personId,firstName,lastName,displayName,
+			formalName,nationality,gender,maritalStatus,firstNameAlt1,
+			lastNameAlt1,firstNameAlt2,lastNameAlt2) 
+		values (#{personId},#{firstName},#{lastName},#{displayName},
+			#{formalName},#{nationality},#{gender},#{maritalStatus},#{firstNameAlt1},
+			#{lastNameAlt1},#{firstNameAlt2},#{lastNameAlt2})
+	</insert>
+	
+	<select id="selectOneByPersonId" resultType="SapPerPersonal">
+		select * from sap_per_personal where personId=#{personId}
+	</select>
+	
+</mapper>

+ 48 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/SapPerPersonalService.java

@@ -0,0 +1,48 @@
+package org.fouram.service;
+
+import java.util.Iterator;
+
+import org.fouram.core.base.service.BaseService;
+import org.fouram.core.util.JsonNodeUtil;
+import org.fouram.entity.SapPerPersonal;
+import org.springframework.stereotype.Service;
+
+import com.fasterxml.jackson.databind.JsonNode;
+
+@Service
+public class SapPerPersonalService extends BaseService {
+
+	public void saveSapData() throws Exception {
+		String url = "https://api15.sapsf.cn/odata/v2/PerPersonal?$format=json";
+		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 personId = JsonNodeUtil.getValue(userNode, "personIdExternal");
+				if (selectOneByPersonId(personId) == null) {
+					String firstName = JsonNodeUtil.getValue(userNode, "firstName");// 名字
+					String lastName = JsonNodeUtil.getValue(userNode, "lastName");// 姓氏
+					String displayName = JsonNodeUtil.getValue(userNode, "displayName");// 英文全名
+					String formalName = JsonNodeUtil.getValue(userNode, "formalName");// 全名
+					String nationality = JsonNodeUtil.getValue(userNode, "nationality");// 国籍
+					String gender = JsonNodeUtil.getValue(userNode, "gender");// 性别
+					String maritalStatus = getLabelValue(JsonNodeUtil.getValue(userNode, "maritalStatus"));// 婚姻状况
+					String firstNameAlt1 = JsonNodeUtil.getValue(userNode, "firstNameAlt1");// 英文名
+					String lastNameAlt1 = JsonNodeUtil.getValue(userNode, "lastNameAlt1");// 英文姓
+					String firstNameAlt2 = JsonNodeUtil.getValue(userNode, "firstNameAlt2");// 拼音名
+					String lastNameAlt2 = JsonNodeUtil.getValue(userNode, "lastNameAlt2");// 拼音姓
+					SapPerPersonal entity = SapPerPersonal.builder().personId(personId).firstName(firstName)
+							.lastName(lastName).displayName(displayName).formalName(formalName).nationality(nationality)
+							.gender(gender).maritalStatus(maritalStatus).firstNameAlt1(firstNameAlt1)
+							.lastNameAlt1(lastNameAlt1).firstNameAlt2(firstNameAlt2).lastNameAlt2(lastNameAlt2).build();
+					save("SapPerPersonalMapper.save", entity);
+				}
+			}
+		}
+	}
+
+	public SapPerPersonal selectOneByPersonId(String personId) throws Exception {
+		return (SapPerPersonal) findObject("SapPerPersonalMapper.selectOneByPersonId", personId);
+	}
+}

+ 4 - 0
code/sapparent/sapservice/src/main/java/org/fouram/service/SyncUploadService.java

@@ -14,6 +14,8 @@ public class SyncUploadService extends BaseService {
 	@Autowired
 	private SapContractService contractService;
 	@Autowired
+	private SapPerPersonalService personalService; 
+	@Autowired
 	private SapPerGlobalInfoCHNService globalInfoCHNService;
 	@Autowired
 	private SapPerPersonRelationshipService relationshipService;
@@ -29,5 +31,7 @@ public class SyncUploadService extends BaseService {
 		contractService.saveSapData();
 		// 家属信息
 		relationshipService.saveSapData();
+		// 个人信息
+		personalService.saveSapData();
 	}
 }