|
@@ -0,0 +1,127 @@
|
|
|
+package cn.nosum.wx.cp.controller;
|
|
|
+
|
|
|
+import cn.nosum.wx.cp.api.WxCpExternalContactService;
|
|
|
+import cn.nosum.wx.cp.api.WxCpService;
|
|
|
+import cn.nosum.wx.cp.config.WxCpConfiguration;
|
|
|
+import cn.nosum.wx.cp.entity.external.WxCpUserExternalGroupChatStatistic;
|
|
|
+import cn.nosum.wx.cp.entity.external.WxCpUserExternalUserBehaviorStatistic;
|
|
|
+import cn.nosum.wx.cp.vo.ExtStatisticVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 外部联系人控制层.
|
|
|
+ *
|
|
|
+ * @author Young
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/ext/contact")
|
|
|
+public class ExtContactController {
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @RequestMapping("/get_user_behavior_data")
|
|
|
+ public List<WxCpUserExternalUserBehaviorStatistic> getUserBehaviorData(Integer appId) {
|
|
|
+ String[] strings = getUserList().toArray(new String[getUserList().size()]);
|
|
|
+ List<WxCpUserExternalUserBehaviorStatistic> result = new ArrayList<>();
|
|
|
+ getLocalDateTimeList().forEach(obj -> {
|
|
|
+ WxCpExternalContactService externalContactService = WxCpConfiguration.getCpService(appId).getExternalContactService();
|
|
|
+ Date startTime = convertDate(obj);
|
|
|
+ Date endTime = convertDate(obj);
|
|
|
+ WxCpUserExternalUserBehaviorStatistic userBehaviorStatistic = externalContactService.getUserBehaviorStatistic(startTime, endTime, strings, null);
|
|
|
+ result.add(userBehaviorStatistic);
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ @RequestMapping("/statistic_group_by_day")
|
|
|
+ public List<ExtStatisticVO> statisticGroupByDay(Integer appId) {
|
|
|
+ List<ExtStatisticVO> extStatisticVOList = new ArrayList<>();
|
|
|
+ WxCpExternalContactService externalContactService = WxCpConfiguration.getCpService(appId).getExternalContactService();
|
|
|
+ getLocalDateTimeList().forEach(obj -> {
|
|
|
+ Date startTime = convertDate(obj);
|
|
|
+ WxCpUserExternalGroupChatStatistic groupChatStatistic = externalContactService.getGroupChatStatistic(startTime, 2, 0, 0, 1000, null, null);
|
|
|
+ ExtStatisticVO statisticVO = new ExtStatisticVO();
|
|
|
+ statisticVO.setDateTime(startTime.getTime() / 1000);
|
|
|
+ statisticVO.setWxCpUserExternalGroupChatStatistic(groupChatStatistic);
|
|
|
+ extStatisticVOList.add(statisticVO);
|
|
|
+ });
|
|
|
+ return extStatisticVOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<LocalDateTime> getLocalDateTimeList() {
|
|
|
+ List<LocalDateTime> dateTimeList = new ArrayList<>();
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-07-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-07-15 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-08-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-08-15 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-09-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-09-15 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-09-28 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-10-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-10-15 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ dateTimeList.add(LocalDateTime.parse("2021-10-20 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
+ return dateTimeList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> getUserList() {
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
+ userIds.add("011850");
|
|
|
+ userIds.add("012292");
|
|
|
+ userIds.add("011232");
|
|
|
+ userIds.add("010957");
|
|
|
+ userIds.add("006965");
|
|
|
+ userIds.add("014169");
|
|
|
+ userIds.add("014188");
|
|
|
+ userIds.add("004783");
|
|
|
+ userIds.add("011223");
|
|
|
+ userIds.add("014124");
|
|
|
+ userIds.add("004784");
|
|
|
+ userIds.add("004945");
|
|
|
+ userIds.add("011835");
|
|
|
+ userIds.add("011590");
|
|
|
+ userIds.add("004041");
|
|
|
+ userIds.add("014117");
|
|
|
+ userIds.add("010918");
|
|
|
+ userIds.add("011837");
|
|
|
+ userIds.add("012947");
|
|
|
+ userIds.add("006823");
|
|
|
+ userIds.add("014139");
|
|
|
+ userIds.add("015920");
|
|
|
+ userIds.add("012688");
|
|
|
+ userIds.add("014133");
|
|
|
+ userIds.add("011831");
|
|
|
+ userIds.add("012293");
|
|
|
+ userIds.add("004793");
|
|
|
+ userIds.add("012294");
|
|
|
+ userIds.add("014113");
|
|
|
+ userIds.add("011842");
|
|
|
+ userIds.add("011987");
|
|
|
+ userIds.add("013628");
|
|
|
+ userIds.add("012857");
|
|
|
+ userIds.add("004778");
|
|
|
+ userIds.add("004810");
|
|
|
+ userIds.add("005963");
|
|
|
+ return userIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 LocalDateTime 转 Date.
|
|
|
+ *
|
|
|
+ * @param dateTime LocalDatetime
|
|
|
+ * @return Date
|
|
|
+ */
|
|
|
+ public static Date convertDate(LocalDateTime dateTime) {
|
|
|
+ return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ }
|
|
|
+}
|