Commit 6d320b00 by 淡漠

首页统计

1 parent 66fb584c
package com.linkwechat.quartz.task;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.wecom.domain.WeCorpAccount;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.dto.WePageStaticDataDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import com.linkwechat.wecom.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -38,8 +42,13 @@ public class PageHomeDataTask {
private IWeGroupMemberService weGroupMemberService;
@Autowired
private RedisCache redisCache;
private IWeUserBehaviorDataService weUserBehaviorDataService;
@Autowired
private IWeGroupStatisticService weGroupStatisticService;
@Autowired
private RedisCache redisCache;
public void getCorpBasicData(){
//查询当前使用企业
......@@ -64,7 +73,97 @@ public class PageHomeDataTask {
public void getCorpRealTimeData(){
//今日
//发起申请数
WePageStaticDataDto wePageStaticDataDto = new WePageStaticDataDto();
//今天
wePageStaticDataDto.setToday(getTodayData());
wePageStaticDataDto.setWeek(getWeekData());
wePageStaticDataDto.setMonth(getMonthData());
wePageStaticDataDto.setUpdateTime(DateUtil.now());
redisCache.setCacheObject("getCorpRealTimeData",wePageStaticDataDto);
}
private WePageStaticDataDto.PageStaticData getTodayData(){
/**
* 今日
*/
String today = DateUtil.today();
String yesterday = DateUtil.yesterday().toDateStr();
//客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(today,"d");
/**
* 昨日
*/
//客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(yesterday,"d");
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery();
//获取15天前的时间
wePageStateQuery.setStartTime(DateUtil.offsetDay(new Date(), -15).toDateStr());
wePageStateQuery.setEndTime(today);
wePageStateQuery.setFew(14);
List<WePageCountDto> dayCountData = weUserBehaviorDataService.getDayCountData(wePageStateQuery);
pageStaticData.setDataList(dayCountData);
return pageStaticData;
}
private WePageStaticDataDto.PageStaticData getWeekData(){
/**
* 本周
*/
//客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"w");
/**
* 上周
*/
//客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastWeek().toDateStr(),"w");
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery();
wePageStateQuery.setFew(5);
List<WePageCountDto> weekCountData = weUserBehaviorDataService.getWeekCountData(wePageStateQuery);
pageStaticData.setDataList(weekCountData);
return pageStaticData;
}
private WePageStaticDataDto.PageStaticData getMonthData(){
/**
* 本周
*/
//客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"m");
/**
* 上周
*/
//客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastMonth().toDateStr(),"m");
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery();
wePageStateQuery.setFew(5);
List<WePageCountDto> monthCountData = weUserBehaviorDataService.getMonthCountData(wePageStateQuery);
pageStaticData.setDataList(monthCountData);
return pageStaticData;
}
private WePageStaticDataDto.PageStaticData setPageStaticData(WePageCountDto nowTime,WePageCountDto lastTime){
WePageStaticDataDto.PageStaticData pageStaticData = new WePageStaticDataDto.PageStaticData();
pageStaticData.setNewApplyCnt(nowTime.getNewApplyCnt());
pageStaticData.setNewApplyCntDiff(nowTime.getNewApplyCnt() - lastTime.getNewApplyCnt());
pageStaticData.setNegativeFeedbackCnt(nowTime.getNegativeFeedbackCnt());
pageStaticData.setNegativeFeedbackCntDiff(nowTime.getNegativeFeedbackCnt() - lastTime.getNegativeFeedbackCnt());
pageStaticData.setNewContactCnt(nowTime.getNewContactCnt());
pageStaticData.setNewContactCntDiff(nowTime.getNewContactCnt() - lastTime.getNewContactCnt());
return pageStaticData;
}
}
......@@ -76,7 +76,7 @@ public class WeUserBehaviorData implements Serializable {
* 已回复聊天占比,浮点型,客户主动发起聊天后,成员在一个自然日内有回复过消息的聊天数/客户主动发起的聊天数比例,不包括群聊,仅在确有聊天时返回
*/
@Excel(name = "已回复聊天占比,浮点型,客户主动发起聊天后,成员在一个自然日内有回复过消息的聊天数/客户主动发起的聊天数比例,不包括群聊,仅在确有聊天时返回")
private Long replyPercentage;
private Float replyPercentage;
/**
* 平均首次回复时长
......
package com.linkwechat.wecom.domain.dto;
import lombok.Data;
/**
* @author danmo
* @description
* @date 2021/2/25 11:21
**/
@Data
public class WePageCountDto {
/**
* 日期
*/
private String xTime;
/**
* 发起申请数
*/
private Integer newApplyCnt;
/**
* 新增客户数,成员新添加的客户数量
*/
private Integer newContactCnt;
/**
* 聊天总数, 成员有主动发送过消息的单聊总数
*/
private Integer chatCnt;
/**
* 发送消息数,成员在单聊中发送的消息总数
*/
private Integer messageCnt;
/**
* 已回复聊天占比,浮点型,客户主动发起聊天后,成员在一个自然日内有回复过消息的聊天数/客户主动发起的聊天数比例,不包括群聊,仅在确有聊天时返回
*/
private Float replyPercentage;
/**
* 平均首次回复时长
*/
private Integer avgReplyTime;
/**
* 删除/拉黑成员的客户数,即将成员删除或加入黑名单的客户数
*/
private Long negativeFeedbackCnt;
/**
* 新增客户群数量
*/
private Integer newChatCnt;
/**
* 截至当天客户群总数量
*/
private Integer chatTotal;
/**
* 截至当天有发过消息的客户群数量
*/
private Integer chatHasMsg;
/**
* 客户群新增群人数
*/
private Integer newMemberCnt;
/**
* 截至当天客户群总人数
*/
private Integer memberTotal;
/**
* 截至当天有发过消息的群成员数
*/
private Integer memberHasMsg;
/**
* 截至当天客户群消息总数
*/
private Integer msgTotal;
}
package com.linkwechat.wecom.domain.dto;
import lombok.Data;
import java.util.List;
/**
* @author danmo
* @description
* @date 2021/2/25 11:21
**/
@Data
public class WePageStaticDataDto {
/**
* 更新时间
*/
private String updateTime;
private PageStaticData today;
private PageStaticData week;
private PageStaticData month;
@Data
public static class PageStaticData{
//发起申请数
private Integer newApplyCnt;
//发起申请数差值
private Integer newApplyCntDiff;
//新增客户数
private Integer newContactCnt;
//新增客户数差值
private Integer newContactCntDiff;
//群新增人数
private Integer newMemberCnt;
//群新增人数差值
private Integer newMemberCntDiff;
//流失客户数
private Long negativeFeedbackCnt;
//流失客户数差值
private Long negativeFeedbackCntDiff;
//图表数据
private List<WePageCountDto> dataList;
}
}
package com.linkwechat.wecom.domain.query;
import lombok.Data;
/**
* @author danmo
* @description
* @date 2021/2/25 11:21
**/
@Data
public class WePageStateQuery {
/**
* 日期间隔
*/
private Integer few;
/**
* 日期
*/
private String dateTime;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
}
......@@ -2,6 +2,10 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeUserBehaviorData;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import java.util.List;
/**
* 联系客户统计数据 Mapper接口
......@@ -11,4 +15,30 @@ import com.linkwechat.wecom.domain.WeUserBehaviorData;
*/
public interface WeUserBehaviorDataMapper extends BaseMapper<WeUserBehaviorData> {
/**
* 按日期查询当天数据统计结果
* @param dateTime
* @return WeUserBehaviorDataDto
*/
public WePageCountDto getCountDataByDay(String dateTime,String type);
/**
* 按天维度查询数据统计
* @param wePageStateQuery 入参
* @return List<WeUserBehaviorDataDto>
*/
public List<WePageCountDto> getDayCountData(WePageStateQuery wePageStateQuery);
/**
* 按周维度查询数据统计
* @param wePageStateQuery 入参
* @return List<WeUserBehaviorDataDto>
*/
public List<WePageCountDto> getWeekCountData(WePageStateQuery wePageStateQuery);
/**
* 按月维度查询数据统计
* @param wePageStateQuery 入参
* @return List<WeUserBehaviorDataDto>
*/
public List<WePageCountDto> getMonthCountData(WePageStateQuery wePageStateQuery);
}
......@@ -2,6 +2,8 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeUserBehaviorData;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import java.util.List;
......@@ -17,4 +19,31 @@ public interface IWeUserBehaviorDataService extends IService<WeUserBehaviorData>
* 查询列表
*/
List<WeUserBehaviorData> queryList(WeUserBehaviorData weUserBehaviorData);
/**
* 按日期查询当天数据统计结果
* @param dateTime
* @return WeUserBehaviorDataDto
*/
WePageCountDto getCountDataByDay(String dateTime,String type);
/**
* 按天维度查询数据统计
* @param wePageStateQuery 入参
* @return List<WeUserBehaviorDataDto>
*/
List<WePageCountDto> getDayCountData(WePageStateQuery wePageStateQuery);
/**
* 按周维度查询数据统计
* @param wePageStateQuery 入参
* @return List<WeUserBehaviorDataDto>
*/
List<WePageCountDto> getWeekCountData(WePageStateQuery wePageStateQuery);
/**
* 按月维度查询数据统计
* @param wePageStateQuery 入参
* @return List<WeUserBehaviorDataDto>
*/
List<WePageCountDto> getMonthCountData(WePageStateQuery wePageStateQuery);
}
......@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.wecom.domain.WeUserBehaviorData;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import com.linkwechat.wecom.mapper.WeUserBehaviorDataMapper;
import com.linkwechat.wecom.service.IWeUserBehaviorDataService;
import org.apache.commons.lang3.StringUtils;
......@@ -52,4 +54,24 @@ public class WeUserBehaviorDataServiceImpl extends ServiceImpl<WeUserBehaviorDat
}
return this.list(lqw);
}
@Override
public WePageCountDto getCountDataByDay(String dateTime,String type) {
return this.baseMapper.getCountDataByDay(dateTime,type);
}
@Override
public List<WePageCountDto> getDayCountData(WePageStateQuery wePageStateQuery) {
return this.baseMapper.getDayCountData(wePageStateQuery);
}
@Override
public List<WePageCountDto> getWeekCountData(WePageStateQuery wePageStateQuery) {
return this.baseMapper.getWeekCountData(wePageStateQuery);
}
@Override
public List<WePageCountDto> getMonthCountData(WePageStateQuery wePageStateQuery) {
return this.baseMapper.getMonthCountData(wePageStateQuery);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeUserBehaviorDataMapper">
<resultMap type="WeUserBehaviorData" id="WeUserBehaviorDataResult">
<result property="id" column="id" />
<result property="userId" column="user_id" />
<result property="statTime" column="stat_time" />
<result property="newApplyCnt" column="new_apply_cnt" />
<result property="newContactCnt" column="new_contact_cnt" />
<result property="chatCnt" column="chat_cnt" />
<result property="messageCnt" column="message_cnt" />
<result property="replyPercentage" column="reply_percentage" />
<result property="avgReplyTime" column="avg_reply_time" />
<result property="negativeFeedbackCnt" column="negative_feedback_cnt" />
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="statTime" column="stat_time"/>
<result property="newApplyCnt" column="new_apply_cnt"/>
<result property="newContactCnt" column="new_contact_cnt"/>
<result property="chatCnt" column="chat_cnt"/>
<result property="messageCnt" column="message_cnt"/>
<result property="replyPercentage" column="reply_percentage"/>
<result property="avgReplyTime" column="avg_reply_time"/>
<result property="negativeFeedbackCnt" column="negative_feedback_cnt"/>
</resultMap>
<select id="getCountDataByDay" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select
date_format(stat_time, '%Y-%m-%d') as x_time
sum(new_apply_cnt) as new_apply_cnt,
sum(new_contact_cnt) as new_contact_cnt
sum(chat_cnt) as chat_cnt
sum(new_contact_cnt) as message_cnt
sum(new_contact_cnt) as reply_percentage
sum(new_contact_cnt) as avg_reply_time
sum(new_contact_cnt) as negative_feedback_cnt
from we_user_behavior_data
<where>
<choose>
<when test="type !=null and type == 'd'">
date_format(stat_time, '%Y-%m-%d') = date_format(#{dateTime}, '%Y-%m-%d');
</when>
<when test="type !=null and type == 'w'">
YEARWEEK(date_format(stat_time,'%Y-%m-%d')) = YEARWEEK(date_format(#{dateTime}, '%Y-%m-%d')});
</when>
<when test="type !=null and type == 'm'">
DATE_FORMAT(date_format(stat_time,'%Y-%m')) = DATE_FORMAT(date_format(#{dateTime}, '%Y-%m'));
</when>
<!--查询今年-->
<otherwise>
YEAR(stat_time) = YEAR(#{dateTime});
</otherwise>
</choose>
</where>
</select>
<select id="getDayCountData" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
SELECT
tbl._date AS x_time,
IFNULL(tbr.new_apply_cnt,0) as new_apply_cnt,
IFNULL(tbr.new_contact_cnt,0) as new_contact_cnt,
IFNULL(tbr.chat_cnt,0) as chat_cnt,
IFNULL(tbr.message_cnt,0) as message_cnt,
IFNULL(tbr.reply_percentage,0) as reply_percentage,
IFNULL(tbr.avg_reply_time,0) as avg_reply_time,
IFNULL(tbr.negative_feedback_cnt,0) as negative_feedback_cnt
FROM (SELECT (@s:=@s+1) AS _index,STR_TO_DATE(DATE(DATE_SUB(CURRENT_DATE,INTERVAL @s DAY)),'%Y-%m-%d') AS _date
FROM information_schema.CHARACTER_SETS,(SELECT @s:=-1) AS init WHERE
@s &lt; #{few}
ORDER BY _date) AS tbl
LEFT JOIN(SELECT
sum(ifnull(wubd.new_apply_cnt, 0)) new_apply_cnt,
sum(ifnull(wubd.new_contact_cnt, 0)) new_contact_cnt,
sum(ifnull(wubd.chat_cnt, 0)) chat_cnt,
sum(ifnull(wubd.message_cnt, 0)) message_cnt,
sum(ifnull(wubd.reply_percentage, 0)) reply_percentage,
sum(ifnull(wubd.avg_reply_time, 0)) avg_reply_time,
sum(ifnull(wubd.negative_feedback_cnt, 0)) negative_feedback_cnt,
STR_TO_DATE(DATE_FORMAT(wubd.stat_time,'%Y-%m-%d'),'%Y-%m-%d') AS finish_date
FROM we_user_behavior_data wubd
where
STR_TO_DATE(DATE_FORMAT(wubd.stat_time,'%Y-%m-%d'),'%Y-%m-%d') &gt;= #{startTime}
AND STR_TO_DATE(DATE_FORMAT(wubd.stat_time,'%Y-%m-%d'),'%Y-%m-%d') &lt;= #{endTime}
GROUP BY finish_date
ORDER BY finish_date
) AS tbr ON tbl._date = tbr.finish_date GROUP BY tbl._date;
</select>
<select id="getWeekCountData" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select CONCAT(left(tbl._date,4),'年',right(tbl._date,2),'周') as x_time,
IFNULL(tbr.new_apply_cnt,0) as new_apply_cnt,
IFNULL(tbr.new_contact_cnt,0) as new_contact_cnt,
IFNULL(tbr.chat_cnt,0) as chat_cnt,
IFNULL(tbr.message_cnt,0) as message_cnt,
IFNULL(tbr.reply_percentage,0) as reply_percentage,
IFNULL(tbr.avg_reply_time,0) as avg_reply_time,
IFNULL(tbr.negative_feedback_cnt,0) as negative_feedback_cnt
from (select (@s := @s + 1) as _index,
yearweek(date(date_sub(date_format(current_date, '%Y-%m-%d'), interval @s week))) as _date
from information_schema.character_sets,
(select @s := -1) as init
where @s &lt; #{few}
order by _date)
as tbl
left join(select
sum(ifnull(wubd.new_apply_cnt, 0)) new_apply_cnt,
sum(ifnull(wubd.new_contact_cnt, 0)) new_contact_cnt,
sum(ifnull(wubd.chat_cnt, 0)) chat_cnt,
sum(ifnull(wubd.message_cnt, 0)) message_cnt,
sum(ifnull(wubd.reply_percentage, 0)) reply_percentage,
sum(ifnull(wubd.avg_reply_time, 0)) avg_reply_time,
sum(ifnull(wubd.negative_feedback_cnt, 0)) negative_feedback_cnt,
yearweek(date_format(wubd.stat_time, '%Y-%m-%d')) as finish_date
from we_user_behavior_data wubd
where yearweek(date_format(wubd.stat_time, '%Y-%m-%d')) &gt;=
yearweek(date(date_sub(date_format(current_date, '%Y-%m-%d'), interval #{few} week)))
and yearweek(date_format(wubd.stat_time, '%Y-%m-%d')) &lt;=
yearweek(date_format(current_date, '%Y-%m-%d'))
group by finish_date
order by finish_date
) as tbr on tbl._date = tbr.finish_date
group by tbl._date;
</select>
<select id="getMonthCountData" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select tbl._date as x_time,
IFNULL(tbr.new_apply_cnt,0) as new_apply_cnt,
IFNULL(tbr.new_contact_cnt,0) as new_contact_cnt,
IFNULL(tbr.chat_cnt,0) as chat_cnt,
IFNULL(tbr.message_cnt,0) as message_cnt,
IFNULL(tbr.reply_percentage,0) as reply_percentage,
IFNULL(tbr.avg_reply_time,0) as avg_reply_time,
IFNULL(tbr.negative_feedback_cnt,0) as negative_feedback_cnt
from (select (@s := @s + 1) as _index, date_format(date_sub(current_date, interval @s month), '%Y-%m') as _date
from information_schema.character_sets,
(select @s := -1) as init
where @s &lt; #{few}
order by _date) as tbl
left join(select
sum(ifnull(wubd.new_apply_cnt, 0)) new_apply_cnt,
sum(ifnull(wubd.new_contact_cnt, 0)) new_contact_cnt,
sum(ifnull(wubd.chat_cnt, 0)) chat_cnt,
sum(ifnull(wubd.message_cnt, 0)) message_cnt,
sum(ifnull(wubd.reply_percentage, 0)) reply_percentage,
sum(ifnull(wubd.avg_reply_time, 0)) avg_reply_time,
sum(ifnull(wubd.negative_feedback_cnt, 0)) negative_feedback_cnt,
date_format(wubd.stat_time, '%Y-%m') as finish_date
from we_user_behavior_data wubd
where
str_to_date(date_format(wubd.stat_time, '%Y-%m'), '%Y-%m') &gt;=
str_to_date(date_format(date_sub(current_date, interval #{few} month), '%Y-%m'), '%Y-%m')
and str_to_date(date_format(wubd.stat_time, '%Y-%m'), '%Y-%m') &lt;=
str_to_date(date_format(current_date, '%Y-%m'), '%Y-%m')
group by finish_date
order by finish_date
) as tbr on tbl._date = tbr.finish_date
group by tbl._date;
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!