wangyunpeng 3 giorni fa
parent
commit
f251d0b3c2

+ 9 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/wecom/thirdpart/ext/ThirdPartWeComMapperExt.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ext;
 
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoom;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoomUser;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaffUser;
 import org.apache.ibatis.annotations.Param;
@@ -10,9 +11,17 @@ public interface ThirdPartWeComMapperExt {
 
     void batchInsertThirdPartWeComRoomUser(@Param("records") List<ThirdPartWeComRoomUser> records);
 
+    void batchUpdateThirdPartWeComRoomUser(@Param("records") List<ThirdPartWeComRoomUser> records);
+
     void batchInsertThirdPartWeComStaffUser(@Param("records") List<ThirdPartWeComStaffUser> saveList);
 
+    void batchUpdateThirdPartWeComStaffUser(@Param("records") List<ThirdPartWeComStaffUser> saveList);
+
     List<ThirdPartWeComStaffUser> getNoGroupStaffUserList(@Param("thirdStaffId") Long thirdStaffId);
 
     void setRoomUserQuitTime(@Param("thirdRoomId") String thirdRoomId, @Param("deleteList") List<Long> deleteList, @Param("quitTime") Long quitTime);
+
+    void batchInsertThirdPartWeComRoom(@Param("records") List<ThirdPartWeComRoom> partition);
+
+    void batchUpdateThirdPartWeComRoom(@Param("records") List<ThirdPartWeComRoom> partition);
 }

+ 48 - 7
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComUserDetailJob.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.api.job.wecom.thirdpart;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.TypeReference;
+import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import com.tzld.piaoquan.api.component.WeComThirdPartyApiClient;
 import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComRoomMapper;
@@ -113,6 +114,7 @@ public class WeComUserDetailJob {
         Map<Long, ThirdPartWeComStaffUser> existUserMap = existUserList.stream()
                 .collect(Collectors.toMap(ThirdPartWeComStaffUser::getUserId, user -> user));
         List<ThirdPartWeComStaffUser> saveList = new ArrayList<>();
+        List<ThirdPartWeComStaffUser> updateList = new ArrayList<>();
         for (ExternalContactsResponse.ContactItem contactItem : contactItemList) {
             if (existUserIdList.contains(contactItem.getUser_id())) {
                 //0 互相删除 8主动删除拉黑  2049被删除  其他的都是好友
@@ -147,7 +149,8 @@ public class WeComUserDetailJob {
                 existUser.setSeq(contactItem.getSeq());
                 existUser.setStatus(contactItem.getStatus());
 
-                staffUserMapper.updateByPrimaryKeySelective(existUser);
+                //staffUserMapper.updateByPrimaryKeySelective(existUser);
+                updateList.add(existUser);
             } else {
                 ThirdPartWeComStaffUser staffUser = new ThirdPartWeComStaffUser();
                 staffUser.setThirdStaffId(thirdStaffId);
@@ -179,7 +182,16 @@ public class WeComUserDetailJob {
             }
         }
         if (CollectionUtils.isNotEmpty(saveList)) {
-            thirdPartWeComMapperExt.batchInsertThirdPartWeComStaffUser(saveList);
+            List<List<ThirdPartWeComStaffUser>> partitionList = Lists.partition(saveList, 500);
+            for (List<ThirdPartWeComStaffUser> partition : partitionList) {
+                thirdPartWeComMapperExt.batchInsertThirdPartWeComStaffUser(partition);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(updateList)) {
+            List<List<ThirdPartWeComStaffUser>> partitionList = Lists.partition(updateList, 200);
+            for (List<ThirdPartWeComStaffUser> partition : partitionList) {
+                thirdPartWeComMapperExt.batchUpdateThirdPartWeComStaffUser(partition);
+            }
         }
     }
 
@@ -217,6 +229,8 @@ public class WeComUserDetailJob {
         List<ThirdPartWeComRoom> roomList = thirdPartyService.getStaffRoomList(staff.getId());
         Map<String, ThirdPartWeComRoom> roomMap = roomList.stream()
                 .collect(Collectors.toMap(ThirdPartWeComRoom::getThirdRoomId, room -> room));
+        List<ThirdPartWeComRoom> saveList = new ArrayList<>();
+        List<ThirdPartWeComRoom> updateList = new ArrayList<>();
         for (GetChatroomMembersResponse.RoomInfo roomInfo : roomInfoList) {
             String roomId = roomInfo.getRoom_id();
             ThirdPartWeComRoom roomDetail = roomMap.get(roomId);
@@ -234,7 +248,8 @@ public class WeComUserDetailJob {
                 roomDetail.setRoomCreateTime(roomInfo.getCreate_time());
                 roomDetail.setCreateTime(new Date());
                 roomDetail.setUpdateTime(new Date());
-                roomMapper.insertSelective(roomDetail);
+                //roomMapper.insertSelective(roomDetail);
+                saveList.add(roomDetail);
             } else {
                 roomDetail.setRoomUrl(roomInfo.getRoomurl());
                 roomDetail.setThirdRoomId(roomInfo.getRoom_id());
@@ -251,9 +266,24 @@ public class WeComUserDetailJob {
                         roomDetail.setSendStatus(1);
                     }
                 }
-                roomMapper.updateByPrimaryKeySelective(roomDetail);
+                //roomMapper.updateByPrimaryKeySelective(roomDetail);
+                updateList.add(roomDetail);
             }
-            syncRoomUserList(staff.getThirdUuid(), roomDetail.getThirdRoomId());
+        }
+        if (CollectionUtils.isNotEmpty(saveList)) {
+            List<List<ThirdPartWeComRoom>> partitionList = Lists.partition(saveList, 500);
+            for (List<ThirdPartWeComRoom> partition : partitionList) {
+                thirdPartWeComMapperExt.batchInsertThirdPartWeComRoom(partition);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(updateList)) {
+            List<List<ThirdPartWeComRoom>> partitionList = Lists.partition(updateList, 200);
+            for (List<ThirdPartWeComRoom> partition : partitionList) {
+                thirdPartWeComMapperExt.batchUpdateThirdPartWeComRoom(partition);
+            }
+        }
+        for (GetChatroomMembersResponse.RoomInfo roomInfo : roomInfoList) {
+            syncRoomUserList(staff.getThirdUuid(), roomInfo.getRoom_id());
         }
         List<String> roomIds = roomInfoList.stream().map(GetChatroomMembersResponse.RoomInfo::getRoom_id).collect(Collectors.toList());
         roomList.removeIf(room -> roomIds.contains(room.getThirdRoomId()));
@@ -276,6 +306,7 @@ public class WeComUserDetailJob {
                 .collect(Collectors.toMap(ThirdPartWeComRoomUser::getUin, roomUser -> roomUser, (a, b) -> a));
 
         List<ThirdPartWeComRoomUser> saveList = new ArrayList<>();
+        List<ThirdPartWeComRoomUser> updateList = new ArrayList<>();
         for (GetRoomUserListResponse.Member user : userList) {
             if (existUserIdList.contains(user.getUin())) {
                 ThirdPartWeComRoomUser existUser = existUserMap.get(user.getUin());
@@ -298,7 +329,8 @@ public class WeComUserDetailJob {
                 existUser.setInviteUserId(user.getInvite_user_id());
                 existUser.setCorpId(user.getCorp_id());
 
-                roomUserMapper.updateByPrimaryKeySelective(existUser);
+                //roomUserMapper.updateByPrimaryKeySelective(existUser);
+                updateList.add(existUser);
             } else {
                 ThirdPartWeComRoomUser roomUser = new ThirdPartWeComRoomUser();
                 roomUser.setThirdRoomId(thirdRoomId);
@@ -327,7 +359,16 @@ public class WeComUserDetailJob {
             }
         }
         if (CollectionUtils.isNotEmpty(saveList)) {
-            thirdPartWeComMapperExt.batchInsertThirdPartWeComRoomUser(saveList);
+            List<List<ThirdPartWeComRoomUser>> partitionList = Lists.partition(saveList, 500);
+            for (List<ThirdPartWeComRoomUser> partition : partitionList) {
+                thirdPartWeComMapperExt.batchInsertThirdPartWeComRoomUser(partition);
+            }
+        }
+        if (CollectionUtils.isNotEmpty(updateList)) {
+            List<List<ThirdPartWeComRoomUser>> partitionList = Lists.partition(updateList, 200);
+            for (List<ThirdPartWeComRoomUser> partition : partitionList) {
+                thirdPartWeComMapperExt.batchUpdateThirdPartWeComRoomUser(partition);
+            }
         }
         // 删除不存在的用户
         List<Long> deleteList = existUserList.stream()

+ 276 - 0
api-module/src/main/resources/mapper/wecom/thirdpart/ext/ThirdPartWeComMapperExt.xml

@@ -15,6 +15,76 @@
         </foreach>
     </insert>
 
+    <update id="batchUpdateThirdPartWeComRoomUser">
+        update third_part_we_com_room_user
+        <trim prefix="set" suffixOverrides=",">
+            <trim prefix="sex = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.sex}
+                </foreach>
+            </trim>
+            <trim prefix="mobile = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.mobile}
+                </foreach>
+            </trim>
+            <trim prefix="acctid = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.acctid}
+                </foreach>
+            </trim>
+            <trim prefix="avatar = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.avatar}
+                </foreach>
+            </trim>
+            <trim prefix="english_name = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.englishName}
+                </foreach>
+            </trim>
+            <trim prefix="realname = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.realname}
+                </foreach>
+            </trim>
+            <trim prefix="room_notes = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.roomNotes}
+                </foreach>
+            </trim>
+            <trim prefix="quit_time = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.quitTime}
+                </foreach>
+            </trim>
+            <trim prefix="nickname = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.nickname}
+                </foreach>
+            </trim>
+            <trim prefix="room_nickname = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.roomNickname}
+                </foreach>
+            </trim>
+            <trim prefix="position = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.position}
+                </foreach>
+            </trim>
+            <trim prefix="update_time = case" suffix="end">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.updateTime}
+                </foreach>
+            </trim>
+        </trim>
+        where id in
+        <foreach collection="records" item="item" open="(" close=")" separator=",">
+            #{item.id}
+        </foreach>
+    </update>
+
     <insert id="batchInsertThirdPartWeComStaffUser">
         insert into third_part_we_com_staff_user (id, third_staff_id, add_customer_time, remove_customer_time, unionid,
         sex, mobile, company_remark, acctid, avatar, `source`, english_name,
@@ -30,6 +100,126 @@
         </foreach>
     </insert>
 
+    <update id="batchUpdateThirdPartWeComStaffUser">
+        update third_part_we_com_staff_user
+        <trim prefix="set" suffixOverrides=",">
+            <trim prefix="add_customer_time = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.addCustomerTime}
+                </foreach>
+            </trim>
+            <trim prefix="remove_customer_time = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.removeCustomerTime}
+                </foreach>
+            </trim>
+            <trim prefix="unionid = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.unionid}
+                </foreach>
+            </trim>
+            <trim prefix="sex = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.sex}
+                </foreach>
+            </trim>
+            <trim prefix="mobile = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.mobile}
+                </foreach>
+            </trim>
+            <trim prefix="company_remark = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.companyRemark}
+                </foreach>
+            </trim>
+            <trim prefix="acctid = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.acctid}
+                </foreach>
+            </trim>
+            <trim prefix="avatar = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.avatar}
+                </foreach>
+            </trim>
+            <trim prefix="source = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.source}
+                </foreach>
+            </trim>
+            <trim prefix="english_name = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.englishName}
+                </foreach>
+            </trim>
+            <trim prefix="remark_phone = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.remarkPhone}
+                </foreach>
+            </trim>
+            <trim prefix="realname = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.realname}
+                </foreach>
+            </trim>
+            <trim prefix="real_remarks = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.realRemarks}
+                </foreach>
+            </trim>
+            <trim prefix="labelid = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.labelid}
+                </foreach>
+            </trim>
+            <trim prefix="user_id = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.userId}
+                </foreach>
+            </trim>
+            <trim prefix="nickname = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.nickname}
+                </foreach>
+            </trim>
+            <trim prefix="`position` = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.position}
+                </foreach>
+            </trim>
+            <trim prefix="corp_id = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.corpId}
+                </foreach>
+            </trim>
+            <trim prefix="remarks = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.remarks}
+                </foreach>
+            </trim>
+            <trim prefix="seq = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.seq}
+                </foreach>
+            </trim>
+            <trim prefix="status = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.status}
+                </foreach>
+            </trim>
+            <trim prefix="update_time = case" suffix="end">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.updateTime}
+                </foreach>
+            </trim>
+        </trim>
+        where id in
+        <foreach collection="records" item="item" open="(" close=")" separator=",">
+            #{item.id}
+        </foreach>
+    </update>
+
     <select id="getNoGroupStaffUserList"
             resultType="com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaffUser">
         select staff_user.*
@@ -55,4 +245,90 @@
         </foreach>
     </update>
 
+    <insert id="batchInsertThirdPartWeComRoom">
+        insert into third_part_we_com_room (id, corp_id, staff_id, third_room_id, third_create_user_id, member_count,
+        `name`, room_url, room_create_time, add_user_status, send_status, send_time, is_delete, create_time, update_time)
+        values
+        <foreach collection="records" item="item" separator=",">
+            (#{item.id}, #{item.corpId}, #{item.staffId}, #{item.thirdRoomId}, #{item.thirdCreateUserId},
+             #{item.memberCount}, #{item.name}, #{item.roomUrl}, #{item.roomCreateTime}, #{item.addUserStatus},
+             #{item.sendStatus}, #{item.sendTime}, #{item.isDelete}, #{item.createTime}, #{item.updateTime})
+        </foreach>
+    </insert>
+
+    <update id="batchUpdateThirdPartWeComRoom">
+        update third_part_we_com_room
+        <trim prefix="set" suffixOverrides=",">
+            <trim prefix="corp_id = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.corpId}
+                </foreach>
+            </trim>
+            <trim prefix="staff_id = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.staffId}
+                </foreach>
+            </trim>
+            <trim prefix="third_room_id = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.thirdRoomId}
+                </foreach>
+            </trim>
+            <trim prefix="third_create_user_id = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.thirdCreateUserId}
+                </foreach>
+            </trim>
+            <trim prefix="member_count = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.memberCount}
+                </foreach>
+            </trim>
+            <trim prefix="`name` = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.name}
+                </foreach>
+            </trim>
+            <trim prefix="room_url = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.roomUrl}
+                </foreach>
+            </trim>
+            <trim prefix="room_create_time = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.roomCreateTime}
+                </foreach>
+            </trim>
+            <trim prefix="add_user_status = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.addUserStatus}
+                </foreach>
+            </trim>
+            <trim prefix="send_status = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.sendStatus}
+                </foreach>
+            </trim>
+            <trim prefix="send_time = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.sendTime}
+                </foreach>
+            </trim>
+            <trim prefix="is_delete = case" suffix="end,">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.isDelete}
+                </foreach>
+            </trim>
+            <trim prefix="update_time = case" suffix="end">
+                <foreach collection="records" item="item">
+                    when id = #{item.id} then #{item.updateTime}
+                </foreach>
+            </trim>
+        </trim>
+        where id in
+        <foreach collection="records" item="item" open="(" close=")" separator=",">
+            #{item.id}
+        </foreach>
+    </update>
+
 </mapper>