瀏覽代碼

修改用户更新

xueyiming 7 月之前
父節點
當前提交
b27c1f80ce

+ 2 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/dao/mapper/StaffWithUserMapper.java

@@ -31,4 +31,6 @@ public interface StaffWithUserMapper {
     int updateByPrimaryKey(StaffWithUser record);
 
     void insertList(@Param("list") List<StaffWithUser> list);
+
+    List<String> selectExternalUserIdByStaffId(@Param("staffId")Long staffId);
 }

+ 11 - 3
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComUserDataJob.java

@@ -16,6 +16,7 @@ import com.tzld.piaoquan.wecom.utils.LarkRobotUtil;
 import com.tzld.piaoquan.wecom.utils.page.Page;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -193,11 +194,18 @@ public class WeComUserDataJob {
                 }
                 List<Staff> staffList = staffMapper.selectByExample(staffExample);
                 for (Staff staff : staffList) {
-                    List<String> externalUserIds = getUserList(staff.getCarrierId(), corp.getId());
-                    if (CollectionUtils.isEmpty(externalUserIds)) {
+                    List<String> existExternalUserIds = getUserList(staff.getCarrierId(), corp.getId());
+                    List<String> allExternalUserIds = staffWithUserMapper.selectExternalUserIdByStaffId(staff.getId());
+                    allExternalUserIds.removeAll(existExternalUserIds);
+                    if (!CollectionUtils.isEmpty(allExternalUserIds)) {
+                        for (String delExternalUserId : allExternalUserIds) {
+                            userService.delStaffWithUser(delExternalUserId, staff.getCarrierId(), System.currentTimeMillis());
+                        }
+                    }
+                    if (CollectionUtils.isEmpty(existExternalUserIds)) {
                         continue;
                     }
-                    for (String externalUserId : externalUserIds) {
+                    for (String externalUserId : existExternalUserIds) {
                         userService.insertStaffWithUser(externalUserId, staff, corp.getId());
                     }
                 }

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

@@ -10,7 +10,7 @@ public interface UserService {
 
     void insertStaffWithUser(String externalUserId, Staff staff, Long corpId);
 
-    void delStaffWithUser(String externalUserId, String staffUserId, Long deleteTime);
+    void delStaffWithUser(String externalUserId, String carrierId, Long deleteTime);
 
     void delStaffWithUser(Long userId, Long staffId, Long deleteTime);
 }

+ 8 - 0
we-com-server/src/main/resources/mapper/StaffWithUserMapper.xml

@@ -265,4 +265,12 @@
       )
     </foreach>
   </insert>
+
+  <select id="selectExternalUserIdByStaffId" parameterType="java.lang.Long" resultMap="java.lang.String">
+    select external_user_id
+    from we_com_staff_with_user t1
+    left join we_com_user t2
+    on t1.user_id = t2.id
+    where t2.staff_id = #{staffId,jdbcType=BIGINT}
+  </select>
 </mapper>

+ 0 - 7
we-com-server/src/main/resources/mapper/UserMapper.xml

@@ -374,13 +374,6 @@
     where id = #{id,jdbcType=BIGINT}
   </update>
 
-
-    <select id="selectIdByExternalUserId3rdParty" parameterType="String" resultType="Long">
-        select id
-        from we_com_user
-        where external_user_id_3rd_party = #{externalUserId3rdParty}
-    </select>
-
     <select id="selectIdByExternalUserId" parameterType="String" resultType="Long">
         select id
         from we_com_user