ConversationContentTask.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.kede.common.task;
  2. import com.kede.wechat.bo.InputChatMsg;
  3. import com.kede.wechat.service.ConversationContentService;
  4. import org.springframework.scheduling.annotation.Scheduled;
  5. import org.springframework.stereotype.Component;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.bind.annotation.RequestMethod;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import javax.annotation.Resource;
  10. import java.sql.SQLOutput;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.StringJoiner;
  14. @Component
  15. @RestController
  16. public class ConversationContentTask {
  17. @Resource
  18. private ConversationContentService conversationContentService;
  19. /**
  20. * 获取企业微信聊天记录
  21. */
  22. // @Scheduled(cron = "0 0/5 * * * ?")
  23. @RequestMapping(value ="/open/pushMsg", method = RequestMethod.GET)
  24. public void pushMsg() {
  25. Integer pageSeq = 0;
  26. Integer pageEnd = 100;
  27. Integer pageLimit = 100;
  28. Integer count = 0;
  29. //循环获取数据,每次100条,count不足100条时最后一次循序
  30. // while (count < pageLimit) {
  31. pageEnd=3;
  32. Map<String, Object> map = conversationContentService.getChatData(pageSeq, pageEnd);
  33. List<InputChatMsg> list = (List<InputChatMsg>) map.get("list");
  34. pushChatMsg(list);
  35. // if (map == null) {
  36. // break;
  37. // }
  38. // if ((int)map.get("total")<100) {
  39. // break;
  40. // }
  41. // pageSeq= pageSeq + pageLimit+1;
  42. // pageEnd = pageEnd + pageLimit;
  43. // }
  44. }
  45. private void pushChatMsg(List<InputChatMsg> list) {
  46. for (InputChatMsg chatMsg : list) {
  47. System.out.println(chatMsg);
  48. String from = chatMsg.getFrom();
  49. String chatName = conversationContentService.getChatName(from);
  50. System.out.println("from"+chatName);
  51. String tolist = chatMsg.getTolist();
  52. //用逗号分割
  53. String[] tolistArr = tolist.split(",");
  54. for (String tolistName : tolistArr) {
  55. String tolistName1 = conversationContentService.getChatName(tolistName);
  56. System.out.println("toList="+tolistName1);
  57. }
  58. }
  59. }
  60. }