xueyiming пре 8 месеци
родитељ
комит
8da21ba76f

+ 14 - 12
we-com-server/src/main/java/com/tzld/piaoquan/wecom/controller/WeComController.java

@@ -106,19 +106,21 @@ public class WeComController {
 
             Map suiteMap = WxUtil.transferXmlToMap(suiteXml);
             log.info("suiteMap = {}", JSONObject.toJSONString(suiteMap));
-            String changeType = (String) suiteMap.get("ChangeType");
-            if (StringUtils.isNotEmpty(changeType) && changeType.equals("add_external_contact")) {
-                String userId = (String) suiteMap.get("UserID");
-                String externalUserId = (String) suiteMap.get("ExternalUserID");
-                log.info("addStaffWithUser userId={} externalUserId={}", userId, externalUserId);
-//                userService.addStaffWithUser(externalUserId, userId);
-            }
-
-            if (StringUtils.isNotEmpty(changeType) && changeType.equals("del_follow_user")) {
-                String userId = (String) suiteMap.get("UserID");
-                String externalUserId = (String) suiteMap.get("ExternalUserID");
-                log.info("delStaffWithUser userId={} externalUserId={}", userId, externalUserId);
+            if (suiteMap != null) {
+                String changeType = (String) suiteMap.get("ChangeType");
+                if (StringUtils.isNotEmpty(changeType) && changeType.equals("add_external_contact")) {
+                    String userId = (String) suiteMap.get("UserID");
+                    String externalUserId = (String) suiteMap.get("ExternalUserID");
+                    log.info("addStaffWithUser userId={} externalUserId={}", userId, externalUserId);
 //                userService.addStaffWithUser(externalUserId, userId);
+                }
+
+                if (StringUtils.isNotEmpty(changeType) && changeType.equals("del_follow_user")) {
+                    String userId = (String) suiteMap.get("UserID");
+                    String externalUserId = (String) suiteMap.get("ExternalUserID");
+                    log.info("delStaffWithUser userId={} externalUserId={}", userId, externalUserId);
+//                userService.delStaffWithUser(externalUserId, userId);
+                }
             }
 
 

+ 49 - 10
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/UserServiceImpl.java

@@ -39,18 +39,11 @@ public class UserServiceImpl implements UserService {
     @Autowired
     private StaffMapper staffMapper;
 
-    public void addStaffWithUser(String externalUserId, String staffUserId) {
-        if (StringUtils.isEmpty(externalUserId) || StringUtils.isEmpty(staffUserId)) {
+    public void addStaffWithUser(String externalUserId, String carrierId) {
+        if (StringUtils.isEmpty(externalUserId) || StringUtils.isEmpty(carrierId)) {
             return;
         }
-        StaffExample example = new StaffExample();
-        example.createCriteria().andCarrierIdEqualTo(staffUserId);
-        List<Staff> staffList = staffMapper.selectByExample(example);
-        if (CollectionUtils.isEmpty(staffList)) {
-            log.error("addUserWithStaff staff empty staffUserId={}", staffUserId);
-            return;
-        }
-        Staff staff = staffList.get(0);
+        Staff staff = getStaff(carrierId);
 //        insertStaffWithUser(externalUserId, staff);
     }
 
@@ -140,6 +133,52 @@ public class UserServiceImpl implements UserService {
         }
     }
 
+    @Override
+    public void delStaffWithUser(String externalUserId, String carrierId) {
+        if (StringUtils.isEmpty(externalUserId) || StringUtils.isEmpty(carrierId)) {
+            return;
+        }
+        Staff staff = getStaff(carrierId);
+        if (staff == null) {
+            return;
+        }
+        User user = getUser(externalUserId);
+        if (user == null) {
+            return;
+        }
+        StaffWithUserExample example = new StaffWithUserExample();
+        example.createCriteria().andStaffIdEqualTo(staff.getId()).andUserIdEqualTo(user.getId());
+        List<StaffWithUser> staffWithUserList = staffWithUserMapper.selectByExample(example);
+        if (CollectionUtils.isEmpty(staffWithUserList) || staffWithUserList.get(0).getIsDelete() == 1) {
+            return;
+        }
+        StaffWithUser staffWithUser = staffWithUserList.get(0);
+        staffWithUser.setIsDelete(1);
+        staffWithUserMapper.updateByPrimaryKeySelective(staffWithUser);
+    }
+
+    private Staff getStaff(String carrierId) {
+        StaffExample example = new StaffExample();
+        example.createCriteria().andCarrierIdEqualTo(carrierId);
+        List<Staff> staffList = staffMapper.selectByExample(example);
+        if (CollectionUtils.isEmpty(staffList)) {
+            log.error("getStaff staff empty carrierId={}", carrierId);
+            return null;
+        }
+        return staffList.get(0);
+    }
+
+    private User getUser(String externalUserId) {
+        UserExample userExample = new UserExample();
+        userExample.createCriteria().andExternalUserIdEqualTo(externalUserId);
+        List<User> userList = userMapper.selectByExample(userExample);
+        if (CollectionUtils.isEmpty(userList)) {
+            log.error("getUser user empty externalUserId={}", externalUserId);
+            return null;
+        }
+        return userList.get(0);
+    }
+
 
     public JSONObject getUserDetail(String externalUserId) throws IOException {
         String weComAccessToken = accessTokenService.getWeComAccessToken();

+ 2 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/UserService.java

@@ -9,4 +9,6 @@ public interface UserService {
     void addStaffWithUser(String externalUserId, String staffUserId);
 
     void insertStaffWithUser(String externalUserId, Staff staff);
+
+    void delStaffWithUser(String externalUserId, String staffUserId);
 }