liupeng vor 4 Jahren
Ursprung
Commit
79e05bbab0

+ 1 - 1
code/sapparent/sapservice/src/main/java/org/fouram/core/plugin/weixin/cp/util/WXCpUserUtil.java

@@ -181,6 +181,6 @@ public class WXCpUserUtil {
 	}
 	}
 
 
 	public static void main(String[] args) throws WxErrorException {
 	public static void main(String[] args) throws WxErrorException {
-		System.out.println(listAllUser().size());
+		System.out.println(listAllUser());
 	}
 	}
 }
 }

+ 10 - 0
code/sapparent/sapservice/src/main/java/org/fouram/core/util/StringUtil.java

@@ -24,4 +24,14 @@ public class StringUtil {
 		}
 		}
 		return str;
 		return str;
 	}
 	}
+	
+	public static boolean equals(String s1, String s2) {
+		if(s1 == null){
+			s1 = "";
+		}
+		if(s2 == null){
+			s2 = "";
+		}
+		return s1.equals(s2);
+	}
 }
 }

+ 2 - 0
code/sapparent/sapservice/src/main/java/org/fouram/entity/WxUser.java

@@ -20,6 +20,8 @@ public class WxUser implements Serializable {
 	private String userId;
 	private String userId;
 	private String email;
 	private String email;
 	private String name;
 	private String name;
+	private String mobile;
+	private String telephone;
 	private Long departId;
 	private Long departId;
 	private Long firstDepartId;
 	private Long firstDepartId;
 	private String firstDepartName;
 	private String firstDepartName;

+ 1 - 0
code/sapparent/sapservice/src/main/java/org/fouram/enums/SapUserResultEnum.java

@@ -7,6 +7,7 @@ public enum SapUserResultEnum {
 	SENSITIVE("SENSITIVE", "敏感数据"), 
 	SENSITIVE("SENSITIVE", "敏感数据"), 
 	ENTRY("ENTRY", "入职"),
 	ENTRY("ENTRY", "入职"),
 	LEAVE("LEAVE", "离职"),
 	LEAVE("LEAVE", "离职"),
+	NON_EXISTENT("NON_EXISTENT", "企业微信不存在"),
 	BLACKLIST("BLACKLIST", "黑名单"),
 	BLACKLIST("BLACKLIST", "黑名单"),
 	GARBAGE("GARBAGE", "垃圾数据"),
 	GARBAGE("GARBAGE", "垃圾数据"),
 	INGORE("INGORE", "忽略不操作");
 	INGORE("INGORE", "忽略不操作");

+ 1 - 1
code/sapparent/sapservice/src/main/java/org/fouram/mapper/WxUserMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="WxUserMapper">
 <mapper namespace="WxUserMapper">
 	<select id="selectById" resultType="WxUser">
 	<select id="selectById" resultType="WxUser">
-		select * from wx_user where userId=#{userId}
+		select * from wx_user where (userId=#{userId} or userId=#{email}) and delFlag=0
 	</select>
 	</select>
 
 
 	<insert id="save">
 	<insert id="save">

+ 36 - 38
code/sapparent/sapservice/src/main/java/org/fouram/service/SapUserService.java

@@ -30,6 +30,7 @@ import org.springframework.stereotype.Service;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Lists;
 
 
+import jodd.util.StringUtil;
 import me.chanjar.weixin.cp.bean.WxCpUser;
 import me.chanjar.weixin.cp.bean.WxCpUser;
 
 
 @Service
 @Service
@@ -95,38 +96,36 @@ public class SapUserService extends BaseService {
 			if (sapUserDb == null) {
 			if (sapUserDb == null) {
 				this.saveSapUser(sapUser);
 				this.saveSapUser(sapUser);
 			} else {
 			} else {
-				if (sapUserDb.toString().equals(sapUser.toString())) {
-					// 用户数据没变,result保留SUCCESS,不用重复同步
-					this.updateDelFlag(sapUser.getUserId(), DelFlagEnum.ENABLE);
-				} else {
-					this.updateSapUser(sapUser);
-				}
-			}
-
-			// 验证sap是否为垃圾数据
-			sapUserDb = this.selectByUserId(sapUser.getUserId());
-			String checkResult = checkUserGarbageOrBlacklist(sapUserDb);
-			if (StringUtils.isNotBlank(checkResult)) {
-				updateResultByUserId(checkResult, sapUserDb.getUserId());
+				this.updateSapUser(sapUser);
 			}
 			}
 		}
 		}
-		// 更新所有无效数据为LEAVE
-		this.updateResultByDelFlag(SapUserResultEnum.LEAVE, DelFlagEnum.UNABLE);
 	}
 	}
 
 
-	/**
-	 * 判断是不是垃圾数据或者黑名单
-	 * 
-	 * @param sapUser
-	 * @return
-	 * @throws Exception
-	 */
-	public String checkUserGarbageOrBlacklist(SapUser sapUser) throws Exception {
+	public String getCheckResultByWx(SapUser sapUser) throws Exception {
 		if (Tools.isEmpty(sapUser.getPersonId()) || Tools.isEmpty(sapUser.getFirstOrgName())
 		if (Tools.isEmpty(sapUser.getPersonId()) || Tools.isEmpty(sapUser.getFirstOrgName())
 				|| WebConstants.INGORE_PERSONIDS.contains("," + sapUser.getPersonId() + ",")) {
 				|| WebConstants.INGORE_PERSONIDS.contains("," + sapUser.getPersonId() + ",")) {
 			return SapUserResultEnum.GARBAGE.getCode();
 			return SapUserResultEnum.GARBAGE.getCode();
 		} else if (sapBlacklistService.findByUserId(sapUser.getPersonId()) != null) {
 		} else if (sapBlacklistService.findByUserId(sapUser.getPersonId()) != null) {
 			return SapUserResultEnum.BLACKLIST.getCode();
 			return SapUserResultEnum.BLACKLIST.getCode();
+		} else {
+			WxUser wxUser = wxUserService.selectById(sapUser.getPersonId(), sapUser.getEmail());
+			if (wxUser == null) {
+				return SapUserResultEnum.ENTRY.getCode();
+			} else {
+				if (!wxUser.getPosition().equals(sapUser.getPosition()) || !wxUserService
+						.getFullDepartName(sapUser.getPersonId()).equals(getFullOrgName(sapUser.getPersonId()))) {
+					return SapUserResultEnum.SENSITIVE.getCode();
+				} else { // 因为上面已经验证过敏感数据,这次判断其他数据是否修改过 就可以
+					// name+mobile+email+telephone
+					if ((StringUtil.equals(wxUser.getEmail(), sapUser.getEmail())
+							|| StringUtil.equals(wxUser.getUserId(), sapUser.getEmail()))
+							&& StringUtil.equals(wxUser.getMobile(), sapUser.getMobile())
+							&& StringUtil.equals(wxUser.getName(), sapUser.getName())
+							&& StringUtil.equals(wxUser.getTelephone(), sapUser.getBusinessPhone())) {
+						return SapUserResultEnum.SUCCESS.getCode();
+					}
+				}
+			}
 		}
 		}
 		return null;
 		return null;
 	}
 	}
@@ -137,25 +136,24 @@ public class SapUserService extends BaseService {
 	 * @throws Exception
 	 * @throws Exception
 	 */
 	 */
 	public void updateAbnormalResult() throws Exception {
 	public void updateAbnormalResult() throws Exception {
+		// 查询NORMAL有效数据,判断异常,入职,没变化
 		List<SapUser> normalList = selectPrimaryListByResult(SapUserResultEnum.NORMAL.getCode());
 		List<SapUser> normalList = selectPrimaryListByResult(SapUserResultEnum.NORMAL.getCode());
-		SapUserResultEnum resultEnum = null;
 		for (SapUser sapUser : normalList) {
 		for (SapUser sapUser : normalList) {
-			resultEnum = checkSensitiveOrEntryData(sapUser);
-			if (resultEnum != null) {
-				this.updateResultByPersonId(resultEnum.getCode(), sapUser.getPersonId());
+			String checkResult = getCheckResultByWx(sapUser);
+			if (StringUtils.isNotBlank(checkResult)) {
+				updateResultByUserId(checkResult, sapUser.getUserId());
 			}
 			}
 		}
 		}
-	}
-
-	private SapUserResultEnum checkSensitiveOrEntryData(SapUser sapUser) throws Exception {
-		WxUser wxUser = wxUserService.selectById(sapUser.getPersonId());
-		if (wxUser == null) {
-			return SapUserResultEnum.ENTRY;
-		} else if (!wxUser.getPosition().equals(sapUser.getPosition()) || !wxUserService
-				.getFullDepartName(sapUser.getPersonId()).equals(getFullOrgName(sapUser.getPersonId()))) {
-			return SapUserResultEnum.SENSITIVE;
+		// 查询UNABLE数据,判断已不存在或离职
+		List<SapUser> unableList = selectPrimaryListByDelFlag(DelFlagEnum.UNABLE.getCode());
+		for (SapUser sapUser : unableList) {
+			WxUser wxUser = wxUserService.selectById(sapUser.getPersonId(), sapUser.getEmail());
+			if(wxUser != null) {
+				updateResultByUserId(SapUserResultEnum.LEAVE.getCode(), sapUser.getUserId());
+			} else {
+				updateResultByUserId(SapUserResultEnum.NON_EXISTENT.getCode(), sapUser.getUserId());
+			}
 		}
 		}
-		return null;
 	}
 	}
 
 
 	/**
 	/**
@@ -310,7 +308,7 @@ public class SapUserService extends BaseService {
 			sapUser.setDepartList(departList);
 			sapUser.setDepartList(departList);
 			sapUser.setSapPosition(sapUser.getPosition());
 			sapUser.setSapPosition(sapUser.getPosition());
 			sapUser.setSapFullDepart(getFullOrgName(sapUser.getPersonId()));
 			sapUser.setSapFullDepart(getFullOrgName(sapUser.getPersonId()));
-			WxUser wxUser = wxUserService.selectById(sapUser.getPersonId());
+			WxUser wxUser = wxUserService.selectById(sapUser.getPersonId(), sapUser.getEmail());
 			if (wxUser != null) {
 			if (wxUser != null) {
 				sapUser.setWxPosition(wxUser.getPosition());
 				sapUser.setWxPosition(wxUser.getPosition());
 				sapUser.setWxFullDepart(wxUserService.getFullDepartName(sapUser.getPersonId()));
 				sapUser.setWxFullDepart(wxUserService.getFullDepartName(sapUser.getPersonId()));

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

@@ -44,9 +44,9 @@ public class SyncSapUserToWxService extends BaseService {
 		WebConstants.CACHE.put(WebConstants.CACHE_SYNC_SAP, DateUtil.getTime());
 		WebConstants.CACHE.put(WebConstants.CACHE_SYNC_SAP, DateUtil.getTime());
 		// 更新所有数据无效
 		// 更新所有数据无效
 		sapUserService.updateAllDelFlag(DelFlagEnum.UNABLE.getCode());
 		sapUserService.updateAllDelFlag(DelFlagEnum.UNABLE.getCode());
-		// 保存SAP用户数据-数据没变化的result状态保持不变
+		// 保存SAP用户数据
 		sapUserService.saveOrUpdateSapUsers();
 		sapUserService.saveOrUpdateSapUsers();
-		// 更新异常情况,敏感数据、入职
+		// 更新异常情况,敏感数据、入职
 		sapUserService.updateAbnormalResult();
 		sapUserService.updateAbnormalResult();
 		// 更新用户头像
 		// 更新用户头像
 		sapUserService.updateAvatars();
 		sapUserService.updateAvatars();

+ 6 - 3
code/sapparent/sapservice/src/main/java/org/fouram/service/WxUserService.java

@@ -47,7 +47,9 @@ public class WxUserService extends BaseService {
 				wxUser.setSecondDepartId(departs.get(1).getId());
 				wxUser.setSecondDepartId(departs.get(1).getId());
 			}
 			}
 			wxUser.setPosition(user.getPosition());
 			wxUser.setPosition(user.getPosition());
-			dbUser = selectById(userId);
+			wxUser.setMobile(user.getMobile());
+			wxUser.setTelephone(user.getTelephone());
+			dbUser = selectById(userId, userId);
 			if (dbUser == null) {
 			if (dbUser == null) {
 				save("WxUserMapper.save", wxUser);
 				save("WxUserMapper.save", wxUser);
 			} else {
 			} else {
@@ -94,8 +96,9 @@ public class WxUserService extends BaseService {
 		return (List<WxUserDepart>) findList("WxUserMapper.selectWxUserDepartsByUserId", userId);
 		return (List<WxUserDepart>) findList("WxUserMapper.selectWxUserDepartsByUserId", userId);
 	}
 	}
 
 
-	public WxUser selectById(String userId) throws Exception {
-		return (WxUser) findObject("WxUserMapper.selectById", userId);
+	public WxUser selectById(String userId, String email) throws Exception {
+		WxUser param = WxUser.builder().userId(userId).email(email).build();
+		return (WxUser) findObject("WxUserMapper.selectById", param);
 	}
 	}
 
 
 	private List<WxDepart> getParentDepartMap(Long departId) throws Exception {
 	private List<WxDepart> getParentDepartMap(Long departId) throws Exception {