|
@@ -9,11 +9,8 @@ import com.idiot.operationbackend.support.Constants;
|
|
|
import com.idiot.operationbackend.support.CustomException;
|
|
|
import com.idiot.operationbackend.support.JsonResult;
|
|
|
import com.idiot.operationbackend.util.JwtTokenUtil;
|
|
|
-import com.idiot.operationbackend.vo.ArticleStatData;
|
|
|
-import com.idiot.operationbackend.vo.GeneralStatData;
|
|
|
+import com.idiot.operationbackend.vo.*;
|
|
|
|
|
|
-import com.idiot.operationbackend.vo.NumberStatData;
|
|
|
-import com.idiot.operationbackend.vo.RemainStatData;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.slf4j.Logger;
|
|
@@ -30,6 +27,7 @@ import java.time.Instant;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collector;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.idiot.operationbackend.support.Constants.calcRate;
|
|
@@ -248,6 +246,31 @@ public class IndexController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @GetMapping("/interactMsg/{accountId}")
|
|
|
+ @ApiOperation(value = "查询单个公众号--互动消息")
|
|
|
+ public ResponseEntity<JsonResult<Map<String,Object>>> getFansInteractMsg(@RequestHeader String token,
|
|
|
+ @PathVariable String accountId,
|
|
|
+ @RequestParam String startDate,
|
|
|
+ @RequestParam String endDate) {
|
|
|
+ String userId = JwtTokenUtil.getUserId(token);
|
|
|
+ if (!checkDate(startDate,endDate)){
|
|
|
+ throw new CustomException(500,"请选择查询时间!");
|
|
|
+ }
|
|
|
+ Map<String,Object> map = new HashMap<>(2);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}互动消息,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
+ List<FansActionStat> fansActionStats = actionStatService.queryFansActionStat(accountId,startDate,endDate);
|
|
|
+ long start = Constants.toLocalDateTime(startDate).toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ long end = Constants.toLocalDateTime(endDate).toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
+ // 时段统计
|
|
|
+ List<InteractMsgStatData> list = statInteractMsgDataTime(fansActionStats,start,end);
|
|
|
+ map.put("list",list);
|
|
|
+ // 类型统计
|
|
|
+ Map<Integer,Long> type = countStatDataType(fansActionStats);
|
|
|
+ map.put("type",type);
|
|
|
+ logger.info("用户:{}查询首页单个公众号:{}互动消息,startDate:{},endDate:{} --->start",userId,accountId,startDate,endDate);
|
|
|
+ return ResponseEntity.ok(JsonResult.success(map));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -282,7 +305,7 @@ public class IndexController {
|
|
|
LocalDateTime endLocalDate = endDate.plusDays(1).atTime(Constants.DEFAULT_TIME);
|
|
|
List<FansActionStat> fansActionStats = actionStatService.queryFansActionStat(accountId,startLocalDate,endLocalDate);
|
|
|
if (CollectionUtils.isEmpty(fansActionStats)) {
|
|
|
- throw new CustomException(500,"暂无数据!");
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
|
long start = startLocalDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
|
long end = endLocalDate.toEpochSecond(Constants.DEFAULT_ZONE);
|
|
@@ -290,6 +313,7 @@ public class IndexController {
|
|
|
GeneralStatData statData = null;
|
|
|
List<FansActionStat> tempStatList = null;
|
|
|
while (start<=end){
|
|
|
+ // 划分成不同时间段
|
|
|
long finalStart = start;
|
|
|
long finalDisValue = disValue;
|
|
|
tempStatList = fansActionStats.stream()
|
|
@@ -329,8 +353,8 @@ public class IndexController {
|
|
|
*/
|
|
|
private GeneralStatData countStatData (List<FansActionStat> fansActionStats, long start, long end, String type) {
|
|
|
|
|
|
- LocalDateTime startDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(start),Constants.DEFAULT_ZONE);
|
|
|
- LocalDateTime endDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(end),Constants.DEFAULT_ZONE);
|
|
|
+ LocalDateTime startDateTime = LocalDateTime.ofEpochSecond(start,0,Constants.DEFAULT_ZONE);
|
|
|
+ LocalDateTime endDateTime = LocalDateTime.ofEpochSecond(end,0,Constants.DEFAULT_ZONE);
|
|
|
GeneralStatData statData = new GeneralStatData();
|
|
|
long newNum = 0;
|
|
|
long cancelNum = 0;
|
|
@@ -463,5 +487,82 @@ public class IndexController {
|
|
|
return articleStatData;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 统计 时段 互动消息
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 17:06 2020/9/17
|
|
|
+ * @param fansActionStats
|
|
|
+ * @param start
|
|
|
+ * @param end
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private List<InteractMsgStatData> statInteractMsgDataTime(List<FansActionStat> fansActionStats,long start,long end){
|
|
|
+ long disValue = 7200;
|
|
|
+ List<InteractMsgStatData> statDataList = new ArrayList<>();
|
|
|
+ InteractMsgStatData statData = null;
|
|
|
+ List<FansActionStat> tempStatList = null;
|
|
|
+ while (start<=end){
|
|
|
+ long finalStart = start;
|
|
|
+ tempStatList = fansActionStats.stream()
|
|
|
+ .filter(e->e.getCreateTime() >= finalStart && e.getCreateTime()<= finalStart + disValue)
|
|
|
+ .sorted(Comparator.comparingLong(FansActionStat::getCreateTime))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ statData = countStatDataTime(tempStatList,finalStart,finalStart+disValue);
|
|
|
+ statDataList.add(statData);
|
|
|
+ start += disValue;
|
|
|
+ }
|
|
|
+ return statDataList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计 时段粉丝互动消息
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 16:45 2020/9/16
|
|
|
+ * @param fansActionStats
|
|
|
+ * @param start
|
|
|
+ * @param end
|
|
|
+ * @return com.idiot.operationbackend.vo.StatData
|
|
|
+ */
|
|
|
+ private InteractMsgStatData countStatDataTime (List<FansActionStat> fansActionStats, long start, long end) {
|
|
|
+
|
|
|
+ LocalDateTime startDateTime = LocalDateTime.ofEpochSecond(start,0,Constants.DEFAULT_ZONE);
|
|
|
+ LocalDateTime endDateTime = LocalDateTime.ofEpochSecond(end,0,Constants.DEFAULT_ZONE);
|
|
|
+ InteractMsgStatData statData = new InteractMsgStatData();
|
|
|
+ long unSubscribe = 0;
|
|
|
+ long subscribe = 0;
|
|
|
+ long scan = 0;
|
|
|
+ long menu = 0;
|
|
|
+ if (!CollectionUtils.isEmpty(fansActionStats)) {
|
|
|
+ subscribe = fansActionStats.parallelStream().filter(e->Constants.SUBSCRIBE == e.getAction()).count();
|
|
|
+ unSubscribe = fansActionStats.parallelStream().filter(e->Constants.CANCEL == e.getAction()).count();
|
|
|
+ scan = fansActionStats.parallelStream().filter(e->Constants.SCAN == e.getAction()).count();
|
|
|
+ menu = fansActionStats.parallelStream().filter(e->Constants.MENU == e.getAction()).count();
|
|
|
+ }
|
|
|
+ String label = String.format("%s:%s-%s:%s",startDateTime.getHour(),"00",endDateTime.getHour(),"00");
|
|
|
+ statData.setDateLabel(label);
|
|
|
+ statData.setMenu(menu);
|
|
|
+ statData.setScan(scan);
|
|
|
+ statData.setSubscribe(subscribe);
|
|
|
+ statData.setUnSubscribe(unSubscribe);
|
|
|
+ statData.setTotal(unSubscribe+subscribe+scan+menu);
|
|
|
+ return statData;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 统计类型 粉丝互动消息
|
|
|
+ * @author wangxiao
|
|
|
+ * @date 17:35 2020/9/17
|
|
|
+ * @param fansActionStats
|
|
|
+ * @return java.util.Map<java.lang.Integer,java.lang.Long>
|
|
|
+ */
|
|
|
+ private Map<Integer,Long> countStatDataType (List<FansActionStat> fansActionStats) {
|
|
|
+ return fansActionStats.stream().collect(Collectors.groupingBy(FansActionStat::getAction,Collectors.counting()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|