Browse Source

增加企微发消息实验定时任务

xueyiming 3 months ago
parent
commit
f3de4df897

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

@@ -1,10 +1,8 @@
 package com.tzld.piaoquan.growth.common.dao.mapper;
 
-import com.tzld.piaoquan.growth.common.model.po.SendMessage;
 import com.tzld.piaoquan.growth.common.model.po.SpecialSendMessage;
 import com.tzld.piaoquan.growth.common.model.po.SpecialSendMessageExample;
 
-import java.util.Date;
 import java.util.List;
 
 import org.apache.ibatis.annotations.Mapper;

+ 11 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/po/SpecialSendMessage.java

@@ -11,6 +11,8 @@ public class SpecialSendMessage {
 
     private Integer group;
 
+    private String content;
+
     private String attachmentIds;
 
     private Integer isSend;
@@ -51,6 +53,14 @@ public class SpecialSendMessage {
         this.group = group;
     }
 
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+
     public String getAttachmentIds() {
         return attachmentIds;
     }
@@ -93,6 +103,7 @@ public class SpecialSendMessage {
         sb.append(", staffId=").append(staffId);
         sb.append(", userId=").append(userId);
         sb.append(", group=").append(group);
+        sb.append(", content=").append(content);
         sb.append(", attachmentIds=").append(attachmentIds);
         sb.append(", isSend=").append(isSend);
         sb.append(", createTime=").append(createTime);

+ 70 - 0
common-module/src/main/java/com/tzld/piaoquan/growth/common/model/po/SpecialSendMessageExample.java

@@ -357,6 +357,76 @@ public class SpecialSendMessageExample {
             return (Criteria) this;
         }
 
+        public Criteria andContentIsNull() {
+            addCriterion("content is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentIsNotNull() {
+            addCriterion("content is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentEqualTo(String value) {
+            addCriterion("content =", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentNotEqualTo(String value) {
+            addCriterion("content <>", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentGreaterThan(String value) {
+            addCriterion("content >", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentGreaterThanOrEqualTo(String value) {
+            addCriterion("content >=", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLessThan(String value) {
+            addCriterion("content <", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLessThanOrEqualTo(String value) {
+            addCriterion("content <=", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentLike(String value) {
+            addCriterion("content like", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentNotLike(String value) {
+            addCriterion("content not like", value, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentIn(List<String> values) {
+            addCriterion("content in", values, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentNotIn(List<String> values) {
+            addCriterion("content not in", values, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentBetween(String value1, String value2) {
+            addCriterion("content between", value1, value2, "content");
+            return (Criteria) this;
+        }
+
+        public Criteria andContentNotBetween(String value1, String value2) {
+            addCriterion("content not between", value1, value2, "content");
+            return (Criteria) this;
+        }
+
         public Criteria andAttachmentIdsIsNull() {
             addCriterion("attachment_ids is null");
             return (Criteria) this;

+ 22 - 7
common-module/src/main/resources/mapper/SpecialSendMessageMapper.xml

@@ -6,6 +6,7 @@
         <result column="staff_id" jdbcType="BIGINT" property="staffId"/>
         <result column="user_id" jdbcType="BIGINT" property="userId"/>
         <result column="group" jdbcType="INTEGER" property="group"/>
+        <result column="content" jdbcType="VARCHAR" property="content"/>
         <result column="attachment_ids" jdbcType="VARCHAR" property="attachmentIds"/>
         <result column="is_send" jdbcType="INTEGER" property="isSend"/>
         <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
@@ -73,7 +74,7 @@
     </sql>
     <sql id="Base_Column_List">
         id
-        , staff_id, user_id, `group`, attachment_ids, is_send, create_time, update_time
+        , staff_id, user_id, `group`, content, attachment_ids, is_send, create_time, update_time
     </sql>
     <select id="selectByExample" parameterType="com.tzld.piaoquan.growth.common.model.po.SpecialSendMessageExample"
             resultMap="BaseResultMap">
@@ -112,11 +113,11 @@
     </delete>
     <insert id="insert" parameterType="com.tzld.piaoquan.growth.common.model.po.SpecialSendMessage">
         insert into we_com_special_send_message (id, staff_id, user_id,
-                                                 `group`, attachment_ids, is_send,
-                                                 create_time, update_time)
+                                                 `group`, content, attachment_ids,
+                                                 is_send, create_time, update_time)
         values (#{id,jdbcType=BIGINT}, #{staffId,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT},
-                #{group,jdbcType=INTEGER}, #{attachmentIds,jdbcType=VARCHAR}, #{isSend,jdbcType=INTEGER},
-                #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
+                #{group,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, #{attachmentIds,jdbcType=VARCHAR},
+                #{isSend,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
     </insert>
     <insert id="insertSelective" parameterType="com.tzld.piaoquan.growth.common.model.po.SpecialSendMessage">
         insert into we_com_special_send_message
@@ -133,6 +134,9 @@
             <if test="group != null">
                 `group`,
             </if>
+            <if test="content != null">
+                content,
+            </if>
             <if test="attachmentIds != null">
                 attachment_ids,
             </if>
@@ -159,6 +163,9 @@
             <if test="group != null">
                 #{group,jdbcType=INTEGER},
             </if>
+            <if test="content != null">
+                #{content,jdbcType=VARCHAR},
+            </if>
             <if test="attachmentIds != null">
                 #{attachmentIds,jdbcType=VARCHAR},
             </if>
@@ -195,6 +202,9 @@
             <if test="record.group != null">
                 `group` = #{record.group,jdbcType=INTEGER},
             </if>
+            <if test="record.content != null">
+                content = #{record.content,jdbcType=VARCHAR},
+            </if>
             <if test="record.attachmentIds != null">
                 attachment_ids = #{record.attachmentIds,jdbcType=VARCHAR},
             </if>
@@ -218,6 +228,7 @@
         staff_id = #{record.staffId,jdbcType=BIGINT},
         user_id = #{record.userId,jdbcType=BIGINT},
         `group` = #{record.group,jdbcType=INTEGER},
+        content = #{record.content,jdbcType=VARCHAR},
         attachment_ids = #{record.attachmentIds,jdbcType=VARCHAR},
         is_send = #{record.isSend,jdbcType=INTEGER},
         create_time = #{record.createTime,jdbcType=TIMESTAMP},
@@ -239,6 +250,9 @@
             <if test="group != null">
                 `group` = #{group,jdbcType=INTEGER},
             </if>
+            <if test="content != null">
+                content = #{content,jdbcType=VARCHAR},
+            </if>
             <if test="attachmentIds != null">
                 attachment_ids = #{attachmentIds,jdbcType=VARCHAR},
             </if>
@@ -259,6 +273,7 @@
         set staff_id       = #{staffId,jdbcType=BIGINT},
             user_id        = #{userId,jdbcType=BIGINT},
             `group`        = #{group,jdbcType=INTEGER},
+            content        = #{content,jdbcType=VARCHAR},
             attachment_ids = #{attachmentIds,jdbcType=VARCHAR},
             is_send        = #{isSend,jdbcType=INTEGER},
             create_time    = #{createTime,jdbcType=TIMESTAMP},
@@ -267,10 +282,10 @@
     </update>
 
     <select id="getGroupList" resultMap="BaseResultMap">
-        select staff_id, `group`
+        select staff_id, `group`, content, attachment_ids
         from we_com_special_send_message
         where is_send = 0
-        group by staff_id, `group`
+        group by staff_id, `group`, content, attachment_ids
     </select>
 
     <select id="selectExternalUserId" resultType="java.lang.String">

+ 2 - 21
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComMessageDataJob.java

@@ -273,27 +273,6 @@ public class WeComMessageDataJob {
         return ReturnT.SUCCESS;
     }
 
-
-    public void specialAssembleSendMessage(Long staffId, Integer pageNum, Integer pageSize, byte groupMsgDisabled) {
-        List<Long> staffIds = new ArrayList<>();
-        staffIds.add(staffId);
-        init(staffIds);
-        List<WeComUser> weComUserList = weComUserMapper.selectUserList(staffId, groupMsgDisabled, (pageNum - 1) * pageSize, pageSize);
-        //落库逻辑
-        List<SendMessage> allSeneMessageList = new ArrayList<>();
-        for (WeComUser weComUser : weComUserList) {
-            List<SendMessage> sendMessageList = getSendMessage(weComUser, staffIds, 1L);
-            if (CollectionUtils.isEmpty(sendMessageList)) {
-                continue;
-            }
-            allSeneMessageList.addAll(sendMessageList);
-        }
-        sendMessageMapper.insertList(allSeneMessageList);
-
-        //组装好当天要发送的消息后  记录时间
-        saveGuaranteedVideoIdList(staffIds);
-    }
-
     private void saveGuaranteedVideoIdList(List<Long> staffIds) {
         GuaranteedParam guaranteedParam = messageAttachmentService.getGuaranteedVideo(DateUtil.getThatDayDateString());
         if (guaranteedParam == null || CollectionUtils.isEmpty(guaranteedParam.getVideoParamList())) {
@@ -592,6 +571,8 @@ public class WeComMessageDataJob {
         }
         return true;
     }
+
+
     @XxlJob("existGuaranteesJob")
     public ReturnT<String> existGuarantees(String param) {
         //保底视频获取

+ 28 - 9
offline-module/src/main/java/com/tzld/piaoquan/offline/job/WeComSpecialDataJob.java

@@ -13,13 +13,16 @@ import com.tzld.piaoquan.growth.common.model.po.*;
 import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
 import com.tzld.piaoquan.growth.common.service.MessageService;
 import com.tzld.piaoquan.growth.common.utils.ToolUtils;
+import com.xxl.job.core.handler.annotation.XxlJob;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
 import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
 
 
 @Component
@@ -40,14 +43,12 @@ public class WeComSpecialDataJob {
     @Autowired
     private MessageAttachmentService messageAttachmentService;
 
-    Map<String, String> pageMap = new HashMap<>();
     //发送小程序标题限制字节数
     private static final int MAX_BYTES = 64;
 
 
-
     public void specialAssembleSendMessage(Long staffId, Integer pageNum, Integer pageSize,
-                                           byte groupMsgDisabled, List<Long> attachmentIds) {
+                                           byte groupMsgDisabled, List<Long> attachmentIds, String content) {
         List<WeComUser> weComUserList = weComUserMapper.selectUserList(staffId, groupMsgDisabled, (pageNum - 1) * pageSize, pageSize);
         //落库逻辑
         for (WeComUser weComUser : weComUserList) {
@@ -56,14 +57,32 @@ public class WeComSpecialDataJob {
             specialSendMessage.setUserId(weComUser.getId());
             specialSendMessage.setGroup(pageNum);
             specialSendMessage.setAttachmentIds(JSONObject.toJSONString(attachmentIds));
+            specialSendMessage.setContent(content);
             specialSendMessageMapper.insertSelective(specialSendMessage);
         }
     }
 
+    @XxlJob("sendSpecialPushMessageJob")
+    public void sendSpecialPushMessage() {
+        List<SpecialSendMessage> groupList = specialSendMessageMapper.getGroupList();
+        for (SpecialSendMessage specialSendMessage : groupList) {
+            List<String> externalUserIds = specialSendMessageMapper.selectExternalUserId(specialSendMessage.getStaffId(), specialSendMessage.getGroup());
+            boolean flag = specialPushMessage(externalUserIds, specialSendMessage);
+            if (flag) {
+                SpecialSendMessage updateSpecialSendMessage = new SpecialSendMessage();
+                updateSpecialSendMessage.setIsSend(1);
+                SpecialSendMessageExample example = new SpecialSendMessageExample();
+                example.createCriteria()
+                        .andStaffIdEqualTo(specialSendMessage.getStaffId())
+                        .andGroupEqualTo(specialSendMessage.getGroup())
+                        .andContentEqualTo(specialSendMessage.getContent())
+                        .andAttachmentIdsEqualTo(specialSendMessage.getAttachmentIds());
+                specialSendMessageMapper.updateByExampleSelective(updateSpecialSendMessage, example);
+            }
+        }
+    }
 
-
-    private boolean specialPushMessage(List<String> sendUserList, SpecialSendMessage specialSendMessage,
-                                       String content) {
+    private boolean specialPushMessage(List<String> sendUserList, SpecialSendMessage specialSendMessage) {
         List<JSONObject> pushList = new ArrayList<>();
         StaffExample staffExample = new StaffExample();
         staffExample.createCriteria().andIdEqualTo(specialSendMessage.getStaffId());
@@ -72,8 +91,8 @@ public class WeComSpecialDataJob {
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("chat_type", "single");
         JSONObject text = new JSONObject();
-        if (StringUtils.isNotEmpty(content)) {
-            text.put("content", content);
+        if (StringUtils.isNotEmpty(specialSendMessage.getContent())) {
+            text.put("content", specialSendMessage.getContent());
         } else {
             text.put("content", messageService.getMessageText());
         }