Преглед изворни кода

历史任务修改,发送接口填写

xueyiming пре 7 месеци
родитељ
комит
3ffa41bf24
16 измењених фајлова са 263 додато и 61 уклоњено
  1. 0 2
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/constant/MiniprogramConstant.java
  2. 9 0
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/constant/TimeConstant.java
  3. 20 0
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/enums/TimeEnum.java
  4. 4 4
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/dao/mapper/HistoryMessageMapper.java
  5. 15 10
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComHistoryDataJob.java
  6. 73 3
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComMessageDataJob.java
  7. 2 7
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComUserDataJob.java
  8. 8 9
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/HistoryMessageServiceImpl.java
  9. 6 4
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/MessageAttachmentServiceImpl.java
  10. 32 0
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/MessageServiceImpl.java
  11. 5 1
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/UserServiceImpl.java
  12. 8 0
      we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/MessageService.java
  13. 8 7
      we-com-server/src/main/resources/mapper/HistoryMessageMapper.xml
  14. 2 2
      we-com-server/src/main/resources/mapper/MessageAttachmentMapper.xml
  15. 12 12
      we-com-server/src/main/resources/mapper/UserMapper.xml
  16. 59 0
      we-com-server/src/main/resources/mybatis-generator-config.xml

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

@@ -6,6 +6,4 @@ public interface MiniprogramConstant {
 
 
     String GUARANTEED_MINIPROGRAM_KEY = "guaranteed_miniprogram_list";
     String GUARANTEED_MINIPROGRAM_KEY = "guaranteed_miniprogram_list";
 
 
-    int max_length = 20;
-
 }
 }

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

@@ -0,0 +1,9 @@
+package com.tzld.piaoquan.wecom.common.constant;
+
+public interface TimeConstant {
+
+    Integer MINUTE = 60;
+    Integer HOUR = 60 * 60;
+    Integer DAY = 60 * 60 * 24;
+
+}

+ 20 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/common/enums/TimeEnum.java

@@ -0,0 +1,20 @@
+package com.tzld.piaoquan.wecom.common.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum TimeEnum {
+
+    SECOND(1, "秒"),
+    MINUTE(60, "分"),
+    HOUR(60 * 60, "小时"),
+    DAY(60 * 60 * 24, "天");
+
+    final Integer time;
+    final String desc;
+
+    TimeEnum(Integer time, String desc) {
+        this.time = time;
+        this.desc = desc;
+    }
+}

+ 4 - 4
we-com-server/src/main/java/com/tzld/piaoquan/wecom/dao/mapper/HistoryMessageMapper.java

@@ -2,11 +2,12 @@ package com.tzld.piaoquan.wecom.dao.mapper;
 
 
 import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessageExample;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessageExample;
-import java.util.List;
-
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.stereotype.Repository;
 
 
+import java.util.List;
+
+
 @Repository
 @Repository
 public interface HistoryMessageMapper {
 public interface HistoryMessageMapper {
     long countByExample(HistoryMessageExample example);
     long countByExample(HistoryMessageExample example);
@@ -31,6 +32,5 @@ public interface HistoryMessageMapper {
 
 
     int updateByPrimaryKey(HistoryMessage record);
     int updateByPrimaryKey(HistoryMessage record);
 
 
-    int insertList(@Param("list") List<HistoryMessage> list);
-
+    void insertList(@Param("list") List<HistoryMessage> list);
 }
 }

+ 15 - 10
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComHistoryDataJob.java

@@ -2,10 +2,13 @@ package com.tzld.piaoquan.wecom.job;
 
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.wecom.common.constant.TimeConstant;
 import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
 import com.tzld.piaoquan.wecom.common.enums.MessageAttachmentTypeEnum;
+import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
 import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
 import com.tzld.piaoquan.wecom.model.bo.MiniprogramRecord;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
+import com.tzld.piaoquan.wecom.model.po.HistoryMessageExample;
 import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
 import com.tzld.piaoquan.wecom.model.po.MessageAttachment;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.AccessTokenService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
@@ -13,6 +16,7 @@ import com.tzld.piaoquan.wecom.service.MessageAttachmentService;
 import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
 import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
 import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
 import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
 import com.tzld.piaoquan.wecom.utils.MiniprogramUtil;
 import com.tzld.piaoquan.wecom.utils.MiniprogramUtil;
+import com.tzld.piaoquan.wecom.utils.page.Page;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
@@ -39,6 +43,9 @@ public class WeComHistoryDataJob {
     @Autowired
     @Autowired
     private UserMapper userMapper;
     private UserMapper userMapper;
 
 
+    @Autowired
+    private HistoryMessageMapper historyMessageMapper;
+
     @Autowired
     @Autowired
     private HistoryMessageService historyMessageService;
     private HistoryMessageService historyMessageService;
 
 
@@ -46,15 +53,14 @@ public class WeComHistoryDataJob {
     private MessageAttachmentService messageAttachmentService;
     private MessageAttachmentService messageAttachmentService;
 
 
     public void selectHistoryMessageByDay() {
     public void selectHistoryMessageByDay() {
-        long startTime = 1722268800L;
-//        long endTime = System.currentTimeMillis() / 1000;
-        long endTime = 1726934399L;
-        for (; startTime < endTime; startTime += 60 * 60 * 24) {
-            if(startTime + 60 * 60 * 24 < endTime){
-                selectHistoryMessage(startTime, startTime + 60 * 60 * 24);
-            }else {
-                selectHistoryMessage(startTime, endTime);
-            }
+        HistoryMessageExample example = new HistoryMessageExample();
+        example.setOrderByClause("create_time desc");
+        example.setPage(new Page<>(1, 1));
+        List<HistoryMessage> historyMessages = historyMessageMapper.selectByExample(example);
+        long startTime = historyMessages.get(0).getCreateTime().getTime() / 1000;
+        long endTime = System.currentTimeMillis() / 1000;
+        for (; startTime < endTime; startTime += TimeConstant.DAY) {
+            selectHistoryMessage(startTime, Math.min(startTime + TimeConstant.DAY, endTime));
         }
         }
     }
     }
 
 
@@ -115,7 +121,6 @@ public class WeComHistoryDataJob {
                 }
                 }
             }
             }
         } catch (IOException e) {
         } catch (IOException e) {
-            //TODO 记录异常日志 记录起止时间和页数 startTime endTime i
             e.printStackTrace();
             e.printStackTrace();
         }
         }
     }
     }

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

@@ -1,7 +1,9 @@
 package com.tzld.piaoquan.wecom.job;
 package com.tzld.piaoquan.wecom.job;
 
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyun.odps.data.Record;
 import com.aliyun.odps.data.Record;
+import com.google.common.collect.Lists;
 import com.tzld.piaoquan.wecom.common.constant.MiniprogramConstant;
 import com.tzld.piaoquan.wecom.common.constant.MiniprogramConstant;
 import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.MessageAttachmentMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
@@ -12,6 +14,7 @@ import com.tzld.piaoquan.wecom.model.po.User;
 import com.tzld.piaoquan.wecom.model.po.UserExample;
 import com.tzld.piaoquan.wecom.model.po.UserExample;
 import com.tzld.piaoquan.wecom.utils.DateUtil;
 import com.tzld.piaoquan.wecom.utils.DateUtil;
 import com.tzld.piaoquan.wecom.utils.OdpsUtil;
 import com.tzld.piaoquan.wecom.utils.OdpsUtil;
+import com.tzld.piaoquan.wecom.utils.page.Page;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
@@ -39,7 +42,9 @@ public class WeComMessageDataJob {
 
 
     //初始化操作
     //初始化操作
     void init() {
     void init() {
-        String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", DateUtil.getBeforeDayDateString());
+//        String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", DateUtil.getBeforeDayDateString());
+        String sql = String.format("SELECT * FROM loghubods.history_good_video_can_push_user_list where dt = %s;", "20240922");
+
         List<Record> recordList = OdpsUtil.getOdpsData(sql);
         List<Record> recordList = OdpsUtil.getOdpsData(sql);
         if (CollectionUtils.isEmpty(recordList)) {
         if (CollectionUtils.isEmpty(recordList)) {
             return;
             return;
@@ -54,7 +59,8 @@ public class WeComMessageDataJob {
             list.add(pushMessage);
             list.add(pushMessage);
         }
         }
         goodList = list;
         goodList = list;
-        List<Long> saveVideoIds = Objects.requireNonNull(redisTemplate.opsForList().range(MiniprogramConstant.GUARANTEED_MINIPROGRAM_KEY, 0, 2)).stream().map(o -> (Long) o).collect(Collectors.toList());
+        List<Long> saveVideoIds = Objects.requireNonNull(redisTemplate.opsForList().range(MiniprogramConstant.GUARANTEED_MINIPROGRAM_KEY, 0, 2))
+                .stream().map(o -> (Integer) o).map(String::valueOf).map(Long::parseLong).collect(Collectors.toList());
         if (CollectionUtils.isEmpty(saveVideoIds)) {
         if (CollectionUtils.isEmpty(saveVideoIds)) {
             throw new RuntimeException("保底数据为空");
             throw new RuntimeException("保底数据为空");
         }
         }
@@ -72,8 +78,32 @@ public class WeComMessageDataJob {
         saveList = saveVideoIds;
         saveList = saveVideoIds;
     }
     }
 
 
-    public void assemble(){
+    public void assemble() {
+        init();
+        Map<String, List<String>> res = new HashMap<>();
         UserExample example = new UserExample();
         UserExample example = new UserExample();
+        long count = userMapper.countByExample(example);
+        int page = 1;
+        int pageSize = 1000;
+        long totalPageSize = count / pageSize + 1;
+        for (; page <= totalPageSize; page++) {
+            example.setPage(new Page<>(page, pageSize));
+            List<User> userList = userMapper.selectByExample(example);
+            if (CollectionUtils.isEmpty(userList)) {
+                continue;
+            }
+            for (User user : userList) {
+                String pushKey = getPushKey(user);
+                if (res.containsKey(pushKey)) {
+                    res.get(pushKey).add(user.getExternalUserId3rdParty());
+                } else {
+                    res.put(pushKey, Lists.newArrayList(user.getExternalUserId3rdParty()));
+                }
+            }
+        }
+
+        System.out.println(res.size());
+        pushMessage(res);
     }
     }
 
 
 
 
@@ -110,4 +140,44 @@ public class WeComMessageDataJob {
         }
         }
         return key.toString();
         return key.toString();
     }
     }
+
+    public void pushMessage(Map<String, List<String>> map) {
+        List<JSONObject> pushList = new ArrayList<>();
+        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("name", "群发名称");
+            JSONArray attachments = new JSONArray();
+            List<Long> videoIdList = Arrays.stream(entry.getKey().split("_")).map(Long::parseLong).collect(Collectors.toList());
+            for (Long videoId : videoIdList) {
+                JSONObject attachment = new JSONObject();
+                attachment.put("msgtype", "miniprogram");
+                MessageAttachmentExample example = new MessageAttachmentExample();
+                example.createCriteria().andMiniprogramVideoIdEqualTo(videoId);
+                List<MessageAttachment> messageAttachmentList = messageAttachmentMapper.selectByExample(example);
+                if (CollectionUtils.isEmpty(messageAttachmentList)) {
+                    throw new RuntimeException("附件信息查询异常");
+                }
+                MessageAttachment messageAttachment = messageAttachmentList.get(0);
+                JSONObject miniprogram = new JSONObject();
+                miniprogram.put("appid", messageAttachment.getAppid());
+                miniprogram.put("title", messageAttachment.getTitle());
+                miniprogram.put("page", messageAttachment.getPage());
+                miniprogram.put("cover", messageAttachment.getCover());
+                attachment.put("miniprogram", miniprogram);
+                attachments.add(attachment);
+            }
+            jsonObject.put("attachments", attachments);
+            List<List<String>> lists = Lists.partition(entry.getValue(), 10000);
+            for (List<String> list : lists) {
+                JSONObject newJSONObject = new JSONObject();
+                newJSONObject.putAll(jsonObject);
+                JSONObject staff_eu_list = new JSONObject();
+                staff_eu_list.put("staff_ext_id", "员工id");
+                staff_eu_list.put("eu_ext_ids", list);
+                newJSONObject.put("staff_eu_list", staff_eu_list);
+                pushList.add(newJSONObject);
+            }
+        }
+        System.out.println(pushList.get(0));
+    }
 }
 }

+ 2 - 7
we-com-server/src/main/java/com/tzld/piaoquan/wecom/job/WeComUserDataJob.java

@@ -46,7 +46,6 @@ public class WeComUserDataJob {
             int sum = 0;
             int sum = 0;
             for (int i = 0; i < page; i++) {
             for (int i = 0; i < page; i++) {
                 String res = getUser(size, i * size, 1720540800L, endTime);
                 String res = getUser(size, i * size, 1720540800L, endTime);
-                //TODO 记录查询数据 info日志
                 if (ObjectUtils.isEmpty(res)) {
                 if (ObjectUtils.isEmpty(res)) {
                     continue;
                     continue;
                 }
                 }
@@ -64,14 +63,12 @@ public class WeComUserDataJob {
                 userMapper.insertList(userList);
                 userMapper.insertList(userList);
                 if (jsonArray.size() < size) {
                 if (jsonArray.size() < size) {
                     if (total > sum) {
                     if (total > sum) {
-                        //TODO 输出异常  插入数量不足
                         System.out.println("插入数量不足");
                         System.out.println("插入数量不足");
                     }
                     }
                     break;
                     break;
                 }
                 }
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
-            //TODO 记录异常日志
             e.printStackTrace();
             e.printStackTrace();
         }
         }
     }
     }
@@ -94,7 +91,7 @@ public class WeComUserDataJob {
     public void updateUser() {
     public void updateUser() {
         try {
         try {
             Long endTime = System.currentTimeMillis() / 1000;
             Long endTime = System.currentTimeMillis() / 1000;
-            Long startTime = endTime - 60 * 60;
+            Long startTime = 1726822290L;
             Integer total = getUpdateUserTotal(startTime, endTime);
             Integer total = getUpdateUserTotal(startTime, endTime);
             if (total == null || total == 0) {
             if (total == null || total == 0) {
                 return;
                 return;
@@ -102,8 +99,7 @@ public class WeComUserDataJob {
             int page = total / size + 1;
             int page = total / size + 1;
             int sum = 0;
             int sum = 0;
             for (int i = 0; i < page; i++) {
             for (int i = 0; i < page; i++) {
-                String res = getUpdateUser(size, i * size, 1726821389L, endTime);
-                //TODO 记录查询数据 info日志
+                String res = getUpdateUser(size, i * size, startTime, endTime);
                 if (ObjectUtils.isEmpty(res)) {
                 if (ObjectUtils.isEmpty(res)) {
                     continue;
                     continue;
                 }
                 }
@@ -136,7 +132,6 @@ public class WeComUserDataJob {
                 }
                 }
             }
             }
         } catch (IOException e) {
         } catch (IOException e) {
-            //TODO 记录异常日志
             e.printStackTrace();
             e.printStackTrace();
         }
         }
     }
     }

+ 8 - 9
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/HistoryMessageServiceImpl.java

@@ -1,10 +1,12 @@
 package com.tzld.piaoquan.wecom.service.Impl;
 package com.tzld.piaoquan.wecom.service.Impl;
 
 
+import com.google.common.collect.Lists;
 import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.HistoryMessageMapper;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
 import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import com.tzld.piaoquan.wecom.service.HistoryMessageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -16,15 +18,12 @@ public class HistoryMessageServiceImpl implements HistoryMessageService {
 
 
     @Override
     @Override
     public void batchInsertHistoryMessage(List<HistoryMessage> historyMessageList) {
     public void batchInsertHistoryMessage(List<HistoryMessage> historyMessageList) {
-        //处理异常  保证大部分数据处理成功
-        try {
-            int insert = historyMessageMapper.insertList(historyMessageList);
-            if (insert <= 0) {
-                //TODO 记录异常日志
-            }
-        } catch (Exception e) {
-            //TODO 输出异常信息 记录插入失败信息 historyMessage
-            e.printStackTrace();
+        if (CollectionUtils.isEmpty(historyMessageList)) {
+            return;
+        }
+        List<List<HistoryMessage>> partition = Lists.partition(historyMessageList, 1000);
+        for (List<HistoryMessage> historyMessages : partition) {
+            historyMessageMapper.insertList(historyMessages);
         }
         }
     }
     }
 }
 }

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

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.List;
 
 
 import static com.tzld.piaoquan.wecom.common.constant.MiniprogramConstant.*;
 import static com.tzld.piaoquan.wecom.common.constant.MiniprogramConstant.*;
@@ -80,9 +81,10 @@ public class MessageAttachmentServiceImpl implements MessageAttachmentService {
             videoList.add(videoId);
             videoList.add(videoId);
         }
         }
         addMiniprogram(messageAttachmentList);
         addMiniprogram(messageAttachmentList);
-        redisTemplate.opsForList().leftPushAll(GUARANTEED_MINIPROGRAM_KEY, videoList);
-        //保底数据只保留部分
-        redisTemplate.opsForList().trim(GUARANTEED_MINIPROGRAM_KEY, 0, max_length);
-
+        redisTemplate.delete(GUARANTEED_MINIPROGRAM_KEY);
+        Collections.reverse(videoList);
+        for (Long video : videoList){
+            redisTemplate.opsForList().leftPush(GUARANTEED_MINIPROGRAM_KEY, video);
+        }
     }
     }
 }
 }

+ 32 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/MessageServiceImpl.java

@@ -0,0 +1,32 @@
+package com.tzld.piaoquan.wecom.service.Impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.wecom.service.AccessTokenService;
+import com.tzld.piaoquan.wecom.service.MessageService;
+import com.tzld.piaoquan.wecom.utils.HttpClientUtil;
+import com.tzld.piaoquan.wecom.utils.HttpPoolClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+
+@Service
+public class MessageServiceImpl implements MessageService {
+
+    private static final HttpPoolClient httpPoolClientDefault = HttpClientUtil.create(30000, 30000, 2000, 5000, 5, 30000);
+
+    private final String POST_MESSAGE_PUSH_URL = "https://open.weibanzhushou.com/open-api/group_msg/add";
+
+    @Autowired
+    private AccessTokenService accessTokenService;
+
+    public void pushMessage(JSONObject jsonObject) {
+        try {
+            String accessToken = accessTokenService.getAccessToken();
+            jsonObject.put("access_token", accessToken);
+            httpPoolClientDefault.postJson(POST_MESSAGE_PUSH_URL, jsonObject.toJSONString());
+        }catch (IOException e){
+            e.printStackTrace();
+        }
+    }
+}

+ 5 - 1
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/Impl/UserServiceImpl.java

@@ -1,9 +1,14 @@
 package com.tzld.piaoquan.wecom.service.Impl;
 package com.tzld.piaoquan.wecom.service.Impl;
 
 
+import com.google.common.collect.Lists;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
 import com.tzld.piaoquan.wecom.dao.mapper.UserMapper;
+import com.tzld.piaoquan.wecom.model.po.HistoryMessage;
 import com.tzld.piaoquan.wecom.service.UserService;
 import com.tzld.piaoquan.wecom.service.UserService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
 
 
 @Service
 @Service
 public class UserServiceImpl implements UserService {
 public class UserServiceImpl implements UserService {
@@ -14,6 +19,5 @@ public class UserServiceImpl implements UserService {
     @Override
     @Override
     public Long getIdByExternalUserId3rdParty(String externalUserId3rdParty) {
     public Long getIdByExternalUserId3rdParty(String externalUserId3rdParty) {
         return userMapper.selectIdByExternalUserId3rdParty(externalUserId3rdParty);
         return userMapper.selectIdByExternalUserId3rdParty(externalUserId3rdParty);
-
     }
     }
 }
 }

+ 8 - 0
we-com-server/src/main/java/com/tzld/piaoquan/wecom/service/MessageService.java

@@ -0,0 +1,8 @@
+package com.tzld.piaoquan.wecom.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface MessageService {
+
+    void pushMessage(JSONObject jsonObject);
+}

+ 8 - 7
we-com-server/src/main/resources/mapper/HistoryMessageMapper.xml

@@ -255,14 +255,15 @@
      create_time
      create_time
     )
     )
     values
     values
-    <foreach collection="list" item="historyMessage" separator=",">
+    <foreach collection="list" item="item" separator=",">
       (
       (
-       #{userId,jdbcType=BIGINT},
-       #{videoId,jdbcType=BIGINT},
-       #{attachmentIdx,jdbcType=INTEGER},
-       #{messageId,jdbcType=BIGINT},
-       #{sendTime,jdbcType=TIMESTAMP},
-       #{createTime,jdbcType=TIMESTAMP})
+       #{item.userId,jdbcType=BIGINT},
+       #{item.videoId,jdbcType=BIGINT},
+       #{item.attachmentIdx,jdbcType=INTEGER},
+       #{item.messageId,jdbcType=BIGINT},
+       #{item.sendTime,jdbcType=TIMESTAMP},
+       #{item.createTime,jdbcType=TIMESTAMP}
+      )
     </foreach>
     </foreach>
   </insert>
   </insert>
 
 

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

@@ -114,12 +114,12 @@
     insert into we_com_message_attachment (id, `type`, url, 
     insert into we_com_message_attachment (id, `type`, url, 
       title, `desc`, appid, 
       title, `desc`, appid, 
       page, cover, miniprogram_video_id, 
       page, cover, miniprogram_video_id, 
-      is_delete, create_time, update_time
+      create_time, update_time
       )
       )
     values (#{id,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR}, 
     values (#{id,jdbcType=BIGINT}, #{type,jdbcType=INTEGER}, #{url,jdbcType=VARCHAR}, 
       #{title,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{appid,jdbcType=VARCHAR}, 
       #{title,jdbcType=VARCHAR}, #{desc,jdbcType=VARCHAR}, #{appid,jdbcType=VARCHAR}, 
       #{page,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, #{miniprogramVideoId,jdbcType=BIGINT}, 
       #{page,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, #{miniprogramVideoId,jdbcType=BIGINT}, 
-      #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
+      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
       )
       )
   </insert>
   </insert>
   <insert id="insertSelective" parameterType="com.tzld.piaoquan.wecom.model.po.MessageAttachment">
   <insert id="insertSelective" parameterType="com.tzld.piaoquan.wecom.model.po.MessageAttachment">

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

@@ -363,19 +363,19 @@
      update_time
      update_time
     )
     )
     values
     values
-    <foreach collection="list" item="user" separator=",">
+    <foreach collection="list" item="item" separator=",">
       (
       (
-       #{externalUserId,jdbcType=VARCHAR},
-       #{unionId,jdbcType=VARCHAR},
-       #{externalUserId3rdParty,jdbcType=VARCHAR},
-       #{type,jdbcType=INTEGER},
-       #{name,jdbcType=VARCHAR},
-       #{avatar,jdbcType=VARCHAR},
-       #{gender,jdbcType=INTEGER},
-       #{createdAt,jdbcType=BIGINT},
-       #{updatedAt,jdbcType=BIGINT},
-       #{createTime,jdbcType=TIMESTAMP},
-       #{updateTime,jdbcType=TIMESTAMP}
+       #{item.externalUserId,jdbcType=VARCHAR},
+       #{item.unionId,jdbcType=VARCHAR},
+       #{item.externalUserId3rdParty,jdbcType=VARCHAR},
+       #{item.type,jdbcType=INTEGER},
+       #{item.name,jdbcType=VARCHAR},
+       #{item.avatar,jdbcType=VARCHAR},
+       #{item.gender,jdbcType=INTEGER},
+       #{item.createdAt,jdbcType=BIGINT},
+       #{item.updatedAt,jdbcType=BIGINT},
+       #{item.createTime,jdbcType=TIMESTAMP},
+       #{item.updateTime,jdbcType=TIMESTAMP}
       )
       )
     </foreach>
     </foreach>
   </insert>
   </insert>

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

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE generatorConfiguration
+        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<!-- 配置生成器 -->
+<generatorConfiguration>
+    <context id="mysql" defaultModelType="flat">
+        <property name="autoDelimitKeywords" value="true"/>
+        <!-- 生成的Java文件的编码 -->
+        <property name="javaFileEncoding" value="UTF-8"/>
+        <!-- 格式化java代码 -->
+        <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
+        <!-- 格式化XML代码 -->
+        <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>
+        <!-- beginningDelimiter和endingDelimiter:指明数据库的用于标记数据库对象名的符号,比如ORACLE就是双引号,MYSQL默认是`反引号; -->
+        <property name="beginningDelimiter" value="`"/>
+        <property name="endingDelimiter" value="`"/>
+
+        <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
+        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>
+        <plugin type="com.tzld.piaoquan.wecom.dao.generator.PaginationPlugin"/>
+
+        <commentGenerator>
+<!--            <property name="addRemarkComments" value="true"/>-->
+            <property name="suppressDate" value="true"/>
+            <property name="suppressAllComments" value="true"/>
+        </commentGenerator>
+
+        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
+                        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>
+
+        <javaTypeResolver type="org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl">
+            <property name="forceBigDecimals" value="false"/>
+        </javaTypeResolver>
+
+        <javaModelGenerator targetPackage="com.tzld.piaoquan.wecom.model.po" targetProject="/Users/shimeng/Desktop/project/we-com-manage/we-com-server/src/main/java">
+            <property name="constructorBased" value="false"/>
+            <property name="enableSubPackages" value="true"/>
+            <property name="immutable" value="false"/>
+        </javaModelGenerator>
+
+        <sqlMapGenerator targetPackage="mapper" targetProject="/Users/shimeng/Desktop/project/we-com-manage/we-com-server/src/main/resources">
+            <property name="enableSubPackages" value="true"/>
+        </sqlMapGenerator>
+
+        <javaClientGenerator targetPackage="com.tzld.piaoquan.wecom.dao.mapper" type="XMLMAPPER"
+                             targetProject="/Users/shimeng/Desktop/project/we-com-manage/we-com-server/src/main/java">
+            <property name="enableSubPackages" value="true"/>
+        </javaClientGenerator>
+
+<!--        <table tableName="we_com_user" domainObjectName="User" alias=""/>-->
+        <table tableName="we_com_history_message" domainObjectName="HistoryMessage" alias=""/>
+        <table tableName="we_com_message_attachment" domainObjectName="MessageAttachment" alias=""/>
+
+    </context>
+
+</generatorConfiguration>