liupeng 4 years ago
parent
commit
c5dc584b0a

+ 22 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/SapEmpTermination.java

@@ -0,0 +1,22 @@
+package org.fouram.entity;
+
+import java.io.Serializable;
+
+import org.apache.ibatis.type.Alias;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Alias(value = "SapEmpTermination")
+public class SapEmpTermination implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+	private String userId;
+	private String endDate;
+}

+ 20 - 0
code/sapparent/sapservice/src/main/java/org/fouram/mapper/SapEmpTerminationMapper.xml

@@ -0,0 +1,20 @@
+<?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="SapEmpTerminationMapper">
+
+	<insert id="save">
+		insert into sap_emp_termination(userId,endDate) 
+		values (#{userId},#{endDate})
+	</insert>
+	
+	<select id="selectOneByPersonId" resultType="SapEmpTermination">
+		select * from sap_emp_termination where userId=#{userId}
+	</select>
+	
+	<update id="updateAllUserEndDate">
+		update sap_user a, sap_emp_termination b 
+		set a.endDate = b.endDate
+		where a.userId = b.userId and a.endDate is null
+	</update>
+	
+</mapper>

+ 17 - 12
code/sapparent/sapservice/src/main/java/org/fouram/service/SapEmpTerminationService.java

@@ -1,18 +1,15 @@
 package org.fouram.service;
 
 import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
 
 import org.fouram.core.base.service.BaseService;
 import org.fouram.core.base.service.RequestService;
 import org.fouram.core.util.JsonNodeUtil;
-import org.fouram.entity.SapUser;
+import org.fouram.entity.SapEmpTermination;
 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 SapEmpTerminationService extends BaseService {
@@ -20,20 +17,28 @@ public class SapEmpTerminationService extends BaseService {
 	@Autowired
 	private RequestService requestService;
 
-	public void setEndDate(List<SapUser> sapUsers) {
-		String url = "https://api15.sapsf.cn/odata/v2/EmpEmploymentTermination?$filter=userId in %s&$format=json";
-		url = String.format(url, getUserIds(sapUsers));
+	public void saveSapData() throws Exception {
+		String url = "https://api15.sapsf.cn/odata/v2/EmpEmploymentTermination?$format=json";
 		JsonNode node = requestService.getForObject(url, getHttpHeaders());
-		Map<String, String> map = Maps.newHashMap();
 		if (node != null) {
 			Iterator<JsonNode> iterator = node.get("d").get("results").elements();
 			while (iterator.hasNext()) {
 				JsonNode userNode = iterator.next();
-				map.put(JsonNodeUtil.getValue(userNode, "userId"), JsonNodeUtil.getValue(userNode, "endDate"));
+				String userId = JsonNodeUtil.getValue(userNode, "userId");
+				String endDate = JsonNodeUtil.getValue(userNode, "endDate");
+				if(selectOneByUserId(userId) == null) {
+					SapEmpTermination entity = SapEmpTermination.builder().userId(userId).endDate(endDate).build();
+					save("SapEmpTerminationMapper.save", entity);
+				}
 			}
 		}
-		for (SapUser sapUser : sapUsers) {
-			sapUser.setEndDate(map.get(sapUser.getUserId()));
-		}
+	}
+
+	public SapEmpTermination selectOneByUserId(String personId) throws Exception {
+		return (SapEmpTermination) findObject("SapEmpTerminationMapper.selectOneByUserId", personId);
+	}
+
+	public void updateAllUserEndDate() throws Exception {
+		update("SapEmpTerminationMapper.updateAllUserEndDate", null);
 	}
 }

+ 3 - 2
code/sapparent/sapservice/src/main/java/org/fouram/service/SapUserService.java

@@ -127,8 +127,6 @@ public class SapUserService extends BaseService {
 		sapEmpEmploymentService.setEmpInfo(sapUsers);
 		// PerNationalId->userId/cardType
 		sapPerNationalIdService.setCardInfo(sapUsers);
-		// EmpEmploymentTermination->endDate
-		sapEmpTerminationService.setEndDate(sapUsers);
 		// 更新用户
 		SapUser sapUserDb = null;
 		SapUser sapUser = null;
@@ -148,6 +146,9 @@ public class SapUserService extends BaseService {
 				this.updateSapUser(sapUser);
 			}
 		}
+		// EmpEmploymentTermination
+		sapEmpTerminationService.saveSapData();
+		sapEmpTerminationService.updateAllUserEndDate();
 	}
 
 	public String getCheckResultByWx(SapUser sapUser) throws Exception {