Преглед на файлове

增加批量添加接口

xueyiming преди 4 месеца
родител
ревизия
4db7c04cf4

+ 3 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/dao/mapper/AttachmentWithMsgResultMapper.java

@@ -4,6 +4,7 @@ import com.tzld.piaoquan.growth.common.model.po.AttachmentWithMsgResult;
 import com.tzld.piaoquan.growth.common.model.po.AttachmentWithMsgResultExample;
 import java.util.List;
 
+import com.tzld.piaoquan.growth.common.model.po.HistoryMessage;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
@@ -32,4 +33,6 @@ public interface AttachmentWithMsgResultMapper {
     int updateByPrimaryKeySelective(AttachmentWithMsgResult record);
 
     int updateByPrimaryKey(AttachmentWithMsgResult record);
+
+    void insertList(@Param("list") List<AttachmentWithMsgResult> list);
 }

+ 15 - 0
common-module/src/main/resources/mapper/AttachmentWithMsgResultMapper.xml

@@ -211,4 +211,19 @@
       update_time = #{updateTime,jdbcType=TIMESTAMP}
     where id = #{id,jdbcType=BIGINT}
   </update>
+
+  <insert id="insertList" parameterType="java.util.List">
+      insert IGNORE into we_com_attachment_with_msg_result
+      (
+      attachment_id,
+      msg_result_id
+      )
+      values
+      <foreach collection="list" item="item" separator=",">
+          (
+          #{item.attachmentId,jdbcType=BIGINT},
+          #{item.msgResultId,jdbcType=BIGINT}
+          )
+      </foreach>
+  </insert>
 </mapper>

+ 9 - 13
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComHistoryDataJob.java

@@ -493,23 +493,19 @@ public class WeComHistoryDataJob {
         if (CollectionUtils.isEmpty(attachmentIds) || CollectionUtils.isEmpty(sendMsgResultIds)) {
             return;
         }
+        List<AttachmentWithMsgResult> list = new ArrayList<>();
         for (Long attachmentId : attachmentIds) {
             for (Long sendMsgResultId : sendMsgResultIds) {
-                AttachmentWithMsgResultExample example = new AttachmentWithMsgResultExample();
-                example.createCriteria().andAttachmentIdEqualTo(attachmentId).andMsgResultIdEqualTo(sendMsgResultId);
-                long l = attachmentWithMsgResultMapper.countByExample(example);
-                if (l == 0) {
-                    try {
-                        AttachmentWithMsgResult attachmentWithMsgResult = new AttachmentWithMsgResult();
-                        attachmentWithMsgResult.setAttachmentId(attachmentId);
-                        attachmentWithMsgResult.setMsgResultId(sendMsgResultId);
-                        attachmentWithMsgResultMapper.insertSelective(attachmentWithMsgResult);
-                    } catch (Exception e) {
-                        log.error("insert error", e);
-                    }
-                }
+                AttachmentWithMsgResult attachmentWithMsgResult = new AttachmentWithMsgResult();
+                attachmentWithMsgResult.setAttachmentId(attachmentId);
+                attachmentWithMsgResult.setMsgResultId(sendMsgResultId);
+                list.add(attachmentWithMsgResult);
             }
         }
+        List<List<AttachmentWithMsgResult>> partition = Lists.partition(list, 2000);
+        for (List<AttachmentWithMsgResult> AttachmentWithMsgResults : partition) {
+            attachmentWithMsgResultMapper.insertList(AttachmentWithMsgResults);
+        }
     }
 
     private String getGroupMsgList(Long startTime, Long endTime, String cursor, Long corpId) throws IOException {