Browse Source

Merge branch 'dev-xym-update-attachment' into dev-xym-update-user

xueyiming 5 tháng trước cách đây
mục cha
commit
f0932772e8

+ 0 - 3
we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/constant/RedisConstant.java

@@ -9,7 +9,4 @@ public interface RedisConstant {
 
     //小程序保底视频key
     String GUARANTEED_MINI_PROGRAM_KEY = "guaranteed_mini_program_%s";
-
-    //小程序保底视频列表key
-    String GUARANTEED_MINI_PROGRAM_SET_KEY = "guaranteed_mini_program_set_%s";
 }

+ 20 - 24
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComHistoryDataJob.java

@@ -5,18 +5,13 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Lists;
 import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
 import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
-import com.tzld.piaoquan.wecom.common.enums.SourceEnum;
 import com.tzld.piaoquan.wecom.component.HttpPoolClient;
-import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
-import com.tzld.piaoquan.wecom.dao.mapper.StaffMapper;
-import com.tzld.piaoquan.wecom.dao.mapper.CorpMapper;
-import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
+import com.tzld.piaoquan.wecom.dao.mapper.*;
 import com.tzld.piaoquan.wecom.model.bo.ExternalUser;
 import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
 import com.tzld.piaoquan.wecom.model.bo.SendDetail;
 import com.tzld.piaoquan.wecom.model.bo.XxlJobParam;
 import com.tzld.piaoquan.wecom.model.po.*;
-import com.tzld.piaoquan.wecom.model.vo.GuaranteedParam;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
@@ -39,8 +34,6 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.MAX_VIDEO_NUM;
-import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_KEY;
-import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_SET_KEY;
 import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.*;
 import static com.tzld.piaoquan.wecom.common.enums.SourceEnum.HISTORICAL_TOP;
 import static com.tzld.piaoquan.wecom.common.enums.SourceEnum.MANUAL;
@@ -79,6 +72,9 @@ public class WeComHistoryDataJob {
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
 
+    @Autowired
+    private MessageAttachmentMapper messageAttachmentMapper;
+
 
     @XxlJob("saveHistoryMessageJob")
     public ReturnT<String> selectHistoryMessageByDay(String param) {
@@ -119,8 +115,6 @@ public class WeComHistoryDataJob {
         for (Corp corp : corps) {
             selectAlertHistoryMessage(xxlJobParam.getStartTime(), xxlJobParam.getEndTime(), corp.getId(), corp.getName());
         }
-        String key = String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, DateUtil.getThatDayDateString());
-        redisTemplate.delete(key);
         return ReturnT.SUCCESS;
     }
 
@@ -218,19 +212,19 @@ public class WeComHistoryDataJob {
                         messageAttachment.setType(MessageAttachmentTypeEnum.MINI_PROGRAM.getType());
                         messageAttachmentList.add(messageAttachment);
                     }
-                    List<String> userIdList = selectGroupMsgTask(msgId, corpId);
-                    if (CollectionUtils.isEmpty(userIdList)) {
+                    List<String> carrierIdList = selectGroupMsgTask(msgId, corpId);
+                    if (CollectionUtils.isEmpty(carrierIdList)) {
                         continue;
                     }
-                    for (String userId : userIdList) {
+                    for (String carrierId : carrierIdList) {
                         StaffExample example = new StaffExample();
-                        example.createCriteria().andCarrierIdEqualTo(userId);
+                        example.createCriteria().andCarrierIdEqualTo(carrierId);
                         List<Staff> staffList = staffMapper.selectByExample(example);
                         if (CollectionUtils.isEmpty(staffList)) {
-                            LarkRobotUtil.sendMessage("企微推送报警:userId不存在请检查 " + userId);
+                            LarkRobotUtil.sendMessage("企微推送报警:carrierId不存在请检查 " + carrierId);
                             continue;
                         }
-                        List<ExternalUser> externalUsers = selectGroupMsgSendResult(msgId, userId, corpId);
+                        List<ExternalUser> externalUsers = selectGroupMsgSendResult(msgId, carrierId, corpId);
                         if (CollectionUtils.isEmpty(externalUsers)) {
                             continue;
                         }
@@ -250,16 +244,16 @@ public class WeComHistoryDataJob {
         }
     }
 
-    private List<ExternalUser> selectGroupMsgSendResult(String msgId, String userId, Long corpId) throws IOException {
+    private List<ExternalUser> selectGroupMsgSendResult(String msgId, String carrierId, Long corpId) throws IOException {
         List<ExternalUser> resList = new ArrayList<>();
         String cursor = "";
         do {
-            String res = getGroupMsgSendResult(msgId, userId, cursor, corpId);
+            String res = getGroupMsgSendResult(msgId, carrierId, cursor, corpId);
             JSONObject jsonObject = JSONObject.parseObject(res);
             Integer errCode = jsonObject.getInteger("errcode");
             if (errCode != 0) {
                 String errmsg = jsonObject.getString("errmsg");
-                log.error("selectGroupMsgSendResult error msgId={} userId={} errCode={} errmsg={}", msgId, userId, errCode, errmsg);
+                log.error("selectGroupMsgSendResult error msgId={} carrierId={} errCode={} errmsg={}", msgId, carrierId, errCode, errmsg);
                 return resList;
             }
             JSONArray sendList = jsonObject.getJSONArray("send_list");
@@ -282,13 +276,13 @@ public class WeComHistoryDataJob {
         return resList;
     }
 
-    private String getGroupMsgSendResult(String msgId, String userId, String cursor, Long corpId) throws IOException {
+    private String getGroupMsgSendResult(String msgId, String carrierId, String cursor, Long corpId) throws IOException {
         String accessToken = accessTokenService.getWeComAccessToken(corpId);
         String url = POST_WE_COM_GROUP_MSG_SEND_RESULT
                 + "?access_token=" + accessToken;
         JSONObject param = new JSONObject();
         param.put("msgid", msgId);
-        param.put("userid", userId);
+        param.put("userid", carrierId);
         param.put("limit", 1000);
         if (StringUtils.isNotEmpty(cursor)) {
             param.put("cursor", cursor);
@@ -349,12 +343,14 @@ public class WeComHistoryDataJob {
         if (CollectionUtils.isEmpty(externalUsers) || CollectionUtils.isEmpty(miniprogramRecordList)) {
             return;
         }
-        String key = String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, DateUtil.getThatDayDateString());
-        Set<Long> guaranteedSet = (Set<Long>) redisTemplate.opsForValue().get(key);
-        if (CollectionUtils.isEmpty(guaranteedSet)) {
+        MessageAttachmentExample example = new MessageAttachmentExample();
+        example.createCriteria().andStaffIdEqualTo(staff.getId()).andSendTimeGreaterThan(DateUtil.getThatDayDate());
+        List<MessageAttachment> messageAttachments = messageAttachmentMapper.selectByExample(example);
+        if(CollectionUtils.isEmpty(messageAttachments)){
             LarkRobotUtil.sendMessage("获取保底set失败");
             return;
         }
+        Set<Long> guaranteedSet = messageAttachments.stream().map(MessageAttachment::getMiniprogramVideoId).collect(Collectors.toSet());
         Long sendTime = externalUsers.stream().map(ExternalUser::getSendTime).filter(Objects::nonNull).findFirst().orElse(null);
         List<HistoryMessage> historyMessageList = new ArrayList<>();
         for (ExternalUser externalUser : externalUsers) {

+ 1 - 1
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComMessageDataJob.java

@@ -117,7 +117,7 @@ public class WeComMessageDataJob {
             }
             for (Long videoId : videoParam.getVideoIds()) {
                 MessageAttachmentExample example = new MessageAttachmentExample();
-                example.createCriteria().andMiniprogramVideoIdEqualTo(videoId);
+                example.createCriteria().andMiniprogramVideoIdEqualTo(videoId).andStaffIdEqualTo(videoParam.getStaffId());
                 List<MessageAttachment> messageAttachmentList = messageAttachmentMapper.selectByExample(example);
                 if (CollectionUtils.isEmpty(messageAttachmentList)) {
                     LarkRobotUtil.sendMessage("保底视频不存在,请查看videoId=" + videoId);

+ 11 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/model/po/MessageAttachment.java

@@ -5,6 +5,8 @@ import java.util.Date;
 public class MessageAttachment {
     private Long id;
 
+    private Long staffId;
+
     private Integer type;
 
     private String url;
@@ -37,6 +39,14 @@ public class MessageAttachment {
         this.id = id;
     }
 
+    public Long getStaffId() {
+        return staffId;
+    }
+
+    public void setStaffId(Long staffId) {
+        this.staffId = staffId;
+    }
+
     public Integer getType() {
         return type;
     }
@@ -140,6 +150,7 @@ public class MessageAttachment {
         sb.append(" [");
         sb.append("Hash = ").append(hashCode());
         sb.append(", id=").append(id);
+        sb.append(", staffId=").append(staffId);
         sb.append(", type=").append(type);
         sb.append(", url=").append(url);
         sb.append(", title=").append(title);

+ 60 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/model/po/MessageAttachmentExample.java

@@ -176,6 +176,66 @@ public class MessageAttachmentExample {
             return (Criteria) this;
         }
 
+        public Criteria andStaffIdIsNull() {
+            addCriterion("staff_id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdIsNotNull() {
+            addCriterion("staff_id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdEqualTo(Long value) {
+            addCriterion("staff_id =", value, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdNotEqualTo(Long value) {
+            addCriterion("staff_id <>", value, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdGreaterThan(Long value) {
+            addCriterion("staff_id >", value, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdGreaterThanOrEqualTo(Long value) {
+            addCriterion("staff_id >=", value, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdLessThan(Long value) {
+            addCriterion("staff_id <", value, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdLessThanOrEqualTo(Long value) {
+            addCriterion("staff_id <=", value, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdIn(List<Long> values) {
+            addCriterion("staff_id in", values, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdNotIn(List<Long> values) {
+            addCriterion("staff_id not in", values, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdBetween(Long value1, Long value2) {
+            addCriterion("staff_id between", value1, value2, "staffId");
+            return (Criteria) this;
+        }
+
+        public Criteria andStaffIdNotBetween(Long value1, Long value2) {
+            addCriterion("staff_id not between", value1, value2, "staffId");
+            return (Criteria) this;
+        }
+
         public Criteria andTypeIsNull() {
             addCriterion("`type` is null");
             return (Criteria) this;

+ 18 - 4
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/MessageAttachmentServiceImpl.java

@@ -40,7 +40,6 @@ import static com.tzld.piaoquan.wecom.common.constant.MessageConstant.appid;
 import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_ADD_TENCENT;
 import static com.tzld.piaoquan.wecom.common.constant.OtherServerURL.POST_VIDEO_DETAIL_URL;
 import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_KEY;
-import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.GUARANTEED_MINI_PROGRAM_SET_KEY;
 import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.POST_WE_COM_MEDIA_UPLOAD;
 
 
@@ -50,6 +49,7 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
 
     @Autowired
     private HttpPoolClient httpPoolClient;
+
     @Autowired
     private AccessTokenService accessTokenService;
 
@@ -92,7 +92,8 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             videoIds.addAll(videoParam.getVideoIds());
         }
         Map<Long, VideoDetail> coverMap = getVideoDetail(videoIds);
-        List<MessageAttachment> messageAttachmentList = new ArrayList<>();
+        Map<Long, MessageAttachment> messageAttachmentMap = new HashMap<>();
+
         for (Long videoId : videoIds) {
             MessageAttachment messageAttachment = new MessageAttachment();
             VideoDetail videoDetail = coverMap.get(videoId);
@@ -105,13 +106,26 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             messageAttachment.setCover(videoDetail.getCover());
             messageAttachment.setTitle(videoDetail.getTitle());
             messageAttachment.setAppid(appid);
-            messageAttachmentList.add(messageAttachment);
+            messageAttachmentMap.put(videoId, messageAttachment);
+        }
+        List<MessageAttachment> messageAttachmentList = new ArrayList<>();
+        for (VideoParam videoParam : guaranteedParam.getVideoParamList()) {
+            if (videoParam.getStaffId() == 0) {
+                continue;
+            }
+            for (Long videoId : videoParam.getVideoIds()) {
+                MessageAttachment messageAttachment = messageAttachmentMap.get(videoId);
+                if (messageAttachment == null) {
+                    continue;
+                }
+                messageAttachment.setStaffId(videoParam.getStaffId());
+                messageAttachmentList.add(messageAttachment);
+            }
         }
         addMiniProgram(messageAttachmentList);
         String date = guaranteedParam.getDate();
         String key = String.format(GUARANTEED_MINI_PROGRAM_KEY, date);
         redisTemplate.opsForValue().set(key, guaranteedParam);
-        redisTemplate.opsForValue().set(String.format(GUARANTEED_MINI_PROGRAM_SET_KEY, date), videoIds);
         return CommonResponse.success();
     }
 

+ 22 - 7
we-com-server/src/main/resources/mapper/MessageAttachmentMapper.xml

@@ -3,6 +3,7 @@
 <mapper namespace="com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper">
   <resultMap id="BaseResultMap" type="com.tzld.piaoquan.wecom.model.po.MessageAttachment">
     <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="staff_id" jdbcType="BIGINT" property="staffId" />
     <result column="type" jdbcType="INTEGER" property="type" />
     <result column="url" jdbcType="VARCHAR" property="url" />
     <result column="title" jdbcType="VARCHAR" property="title" />
@@ -75,8 +76,8 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, `type`, url, title, `desc`, appid, page, cover, miniprogram_video_id, is_delete, 
-    send_time, create_time, update_time
+    id, staff_id, `type`, url, title, `desc`, appid, page, cover, miniprogram_video_id, 
+    is_delete, send_time, create_time, update_time
   </sql>
   <select id="selectByExample" parameterType="com.tzld.piaoquan.wecom.model.po.MessageAttachmentExample" resultMap="BaseResultMap">
     select
@@ -112,13 +113,13 @@
     </if>
   </delete>
   <insert id="insert" parameterType="com.tzld.piaoquan.wecom.model.po.MessageAttachment">
-    insert into we_com_message_attachment (id, `type`, url, 
-      title, `desc`, appid, 
+    insert into we_com_message_attachment (id, staff_id, `type`, 
+      url, title, `desc`, appid, 
       page, cover, miniprogram_video_id, 
       send_time, create_time,
       update_time)
-    values (#{id,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR}, 
-      #{title,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{appid,jdbcType=VARCHAR}, 
+    values (#{id,jdbcType=BIGINT}, #{staffId,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, 
+      #{url,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{appid,jdbcType=VARCHAR}, 
       #{page,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, #{miniprogramVideoId,jdbcType=BIGINT}, 
       #{sendTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP},
       #{updateTime,jdbcType=TIMESTAMP})
@@ -129,6 +130,9 @@
       <if test="id != null">
         id,
       </if>
+      <if test="staffId != null">
+        staff_id,
+      </if>
       <if test="type != null">
         `type`,
       </if>
@@ -170,6 +174,9 @@
       <if test="id != null">
         #{id,jdbcType=BIGINT},
       </if>
+      <if test="staffId != null">
+        #{staffId,jdbcType=BIGINT},
+      </if>
       <if test="type != null">
         #{type,jdbcType=INTEGER},
       </if>
@@ -220,6 +227,9 @@
       <if test="record.id != null">
         id = #{record.id,jdbcType=BIGINT},
       </if>
+      <if test="record.staffId != null">
+        staff_id = #{record.staffId,jdbcType=BIGINT},
+      </if>
       <if test="record.type != null">
         `type` = #{record.type,jdbcType=INTEGER},
       </if>
@@ -264,6 +274,7 @@
   <update id="updateByExample" parameterType="map">
     update we_com_message_attachment
     set id = #{record.id,jdbcType=BIGINT},
+      staff_id = #{record.staffId,jdbcType=BIGINT},
       `type` = #{record.type,jdbcType=INTEGER},
       url = #{record.url,jdbcType=VARCHAR},
       title = #{record.title,jdbcType=VARCHAR},
@@ -283,6 +294,9 @@
   <update id="updateByPrimaryKeySelective" parameterType="com.tzld.piaoquan.wecom.model.po.MessageAttachment">
     update we_com_message_attachment
     <set>
+      <if test="staffId != null">
+        staff_id = #{staffId,jdbcType=BIGINT},
+      </if>
       <if test="type != null">
         `type` = #{type,jdbcType=INTEGER},
       </if>
@@ -324,7 +338,8 @@
   </update>
   <update id="updateByPrimaryKey" parameterType="com.tzld.piaoquan.wecom.model.po.MessageAttachment">
     update we_com_message_attachment
-    set `type` = #{type,jdbcType=INTEGER},
+    set staff_id = #{staffId,jdbcType=BIGINT},
+      `type` = #{type,jdbcType=INTEGER},
       url = #{url,jdbcType=VARCHAR},
       title = #{title,jdbcType=VARCHAR},
       `desc` = #{desc,jdbcType=VARCHAR},

+ 3 - 3
we-com-server/src/main/resources/mybatis-generator-config.xml

@@ -27,7 +27,7 @@
         </commentGenerator>
 
         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
-                        connectionURL="jdbc:mysql://rm-bp1159bu17li9hi94.mysql.rds.aliyuncs.com:3306/piaoquan-crawler?useUnicode=true&amp;characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull&amp;useSSL=false"
+                        connectionURL="jdbc:mysql://rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com:3306/piaoquan-crawler?useUnicode=true&amp;characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull&amp;useSSL=false"
                         userId="crawler" password="crawler123456@">
         </jdbcConnection>
 
@@ -51,8 +51,8 @@
         </javaClientGenerator>
 
 <!--        <table tableName="we_com_alert_message" domainObjectName="AlertMessage" alias=""/>-->
-        <table tableName="we_com_history_message" domainObjectName="HistoryMessage" alias=""/>
-<!--        <table tableName="we_com_message_attachment" domainObjectName="MessageAttachment" alias=""/>-->
+<!--        <table tableName="we_com_history_message" domainObjectName="HistoryMessage" alias=""/>-->
+        <table tableName="we_com_message_attachment" domainObjectName="MessageAttachment" alias=""/>
 <!--        <table tableName="we_com_staff" domainObjectName="Staff" alias=""/>-->
 <!--        <table tableName="we_com_staff_with_user" domainObjectName="StaffWithUser" alias=""/>-->
 <!--        <table tableName="we_com_send_message" domainObjectName="SendMessage" alias=""/>-->