Commit e889f6db by 孙喜旺

客户群统计修改

1 parent c9f40fbe
...@@ -95,14 +95,36 @@ public class PageHomeDataTask { ...@@ -95,14 +95,36 @@ public class PageHomeDataTask {
String today = DateUtil.today(); String today = DateUtil.today();
String yesterday = DateUtil.yesterday().toDateStr(); String yesterday = DateUtil.yesterday().toDateStr();
//客户统计 //客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(today,"day"); WePageCountDto nowData = weUserBehaviorDataService.getCountDataByDay(today,"day");
//客户群统计
WePageCountDto nowTimeGroupChatData = weGroupStatisticService.getCountDataByDay(today, "day");
if(nowTimeGroupChatData != null){
nowData.setChatCnt(nowTimeGroupChatData.getChatCnt());
nowData.setChatTotal(nowTimeGroupChatData.getChatTotal());
nowData.setChatHasMsg(nowTimeGroupChatData.getChatHasMsg());
nowData.setNewChatCnt(nowTimeGroupChatData.getNewChatCnt());
nowData.setNewMemberCnt(nowTimeGroupChatData.getNewMemberCnt());
nowData.setMemberTotal(nowTimeGroupChatData.getMemberTotal());
nowData.setMsgTotal(nowTimeGroupChatData.getMsgTotal());
}
/** /**
* 昨日 * 昨日
*/ */
//客户统计 //客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(yesterday,"day"); WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(yesterday,"day");
//客户群统计
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime); WePageCountDto lastGroupChatTime = weGroupStatisticService.getCountDataByDay(yesterday,"day");
if(lastGroupChatTime != null){
lastTime.setChatCnt(lastGroupChatTime.getChatCnt());
lastTime.setChatTotal(lastGroupChatTime.getChatTotal());
lastTime.setChatHasMsg(lastGroupChatTime.getChatHasMsg());
lastTime.setNewChatCnt(lastGroupChatTime.getNewChatCnt());
lastTime.setNewMemberCnt(lastGroupChatTime.getNewMemberCnt());
lastTime.setMemberTotal(lastGroupChatTime.getMemberTotal());
lastTime.setMsgTotal(lastGroupChatTime.getMsgTotal());
}
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(nowData, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery(); WePageStateQuery wePageStateQuery = new WePageStateQuery();
//获取15天前的时间 //获取15天前的时间
...@@ -110,6 +132,21 @@ public class PageHomeDataTask { ...@@ -110,6 +132,21 @@ public class PageHomeDataTask {
wePageStateQuery.setEndTime(today); wePageStateQuery.setEndTime(today);
wePageStateQuery.setFew(14); wePageStateQuery.setFew(14);
List<WePageCountDto> dayCountData = weUserBehaviorDataService.getDayCountData(wePageStateQuery); List<WePageCountDto> dayCountData = weUserBehaviorDataService.getDayCountData(wePageStateQuery);
List<WePageCountDto> dayGroupChatCountData = weGroupStatisticService.getDayCountData(wePageStateQuery);
for (WePageCountDto dayData : dayCountData) {
for (WePageCountDto dayGroupChatData : dayGroupChatCountData) {
if (dayData.getXTime().equals(dayGroupChatData.getXTime())){
dayData.setChatCnt(dayGroupChatData.getChatCnt());
dayData.setChatTotal(dayGroupChatData.getChatTotal());
dayData.setChatHasMsg(dayGroupChatData.getChatHasMsg());
dayData.setNewChatCnt(dayGroupChatData.getNewChatCnt());
dayData.setNewMemberCnt(dayGroupChatData.getNewMemberCnt());
dayData.setMemberTotal(dayGroupChatData.getMemberTotal());
dayData.setMsgTotal(dayGroupChatData.getMsgTotal());
break;
}
}
}
pageStaticData.setDataList(dayCountData); pageStaticData.setDataList(dayCountData);
return pageStaticData; return pageStaticData;
...@@ -121,17 +158,51 @@ public class PageHomeDataTask { ...@@ -121,17 +158,51 @@ public class PageHomeDataTask {
*/ */
//客户统计 //客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"week"); WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"week");
WePageCountDto nowTimeGroupChatData = weGroupStatisticService.getCountDataByDay(DateUtil.today(),"week");
if(nowTimeGroupChatData != null){
newTime.setChatCnt(nowTimeGroupChatData.getChatCnt());
newTime.setChatTotal(nowTimeGroupChatData.getChatTotal());
newTime.setChatHasMsg(nowTimeGroupChatData.getChatHasMsg());
newTime.setNewChatCnt(nowTimeGroupChatData.getNewChatCnt());
newTime.setNewMemberCnt(nowTimeGroupChatData.getNewMemberCnt());
newTime.setMemberTotal(nowTimeGroupChatData.getMemberTotal());
newTime.setMsgTotal(nowTimeGroupChatData.getMsgTotal());
}
/** /**
* 上周 * 上周
*/ */
//客户统计 //客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastWeek().toDateStr(),"week"); WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastWeek().toDateStr(),"week");
WePageCountDto lastTimeGroupChatData = weGroupStatisticService.getCountDataByDay(DateUtil.lastWeek().toDateStr(),"week");
if(lastTimeGroupChatData != null){
lastTime.setChatCnt(lastTimeGroupChatData.getChatCnt());
lastTime.setChatTotal(lastTimeGroupChatData.getChatTotal());
lastTime.setChatHasMsg(lastTimeGroupChatData.getChatHasMsg());
lastTime.setNewChatCnt(lastTimeGroupChatData.getNewChatCnt());
lastTime.setNewMemberCnt(lastTimeGroupChatData.getNewMemberCnt());
lastTime.setMemberTotal(lastTimeGroupChatData.getMemberTotal());
lastTime.setMsgTotal(lastTimeGroupChatData.getMsgTotal());
}
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime); WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery(); WePageStateQuery wePageStateQuery = new WePageStateQuery();
wePageStateQuery.setFew(5); wePageStateQuery.setFew(5);
List<WePageCountDto> weekCountData = weUserBehaviorDataService.getWeekCountData(wePageStateQuery); List<WePageCountDto> weekCountData = weUserBehaviorDataService.getWeekCountData(wePageStateQuery);
List<WePageCountDto> weekGroupChatCountData = weGroupStatisticService.getWeekCountData(wePageStateQuery);
for (WePageCountDto weekData : weekCountData) {
for (WePageCountDto weekGroupChatData : weekGroupChatCountData) {
if (weekData.getXTime().equals(weekGroupChatData.getXTime())){
weekData.setChatCnt(weekGroupChatData.getChatCnt());
weekData.setChatTotal(weekGroupChatData.getChatTotal());
weekData.setChatHasMsg(weekGroupChatData.getChatHasMsg());
weekData.setNewChatCnt(weekGroupChatData.getNewChatCnt());
weekData.setNewMemberCnt(weekGroupChatData.getNewMemberCnt());
weekData.setMemberTotal(weekGroupChatData.getMemberTotal());
weekData.setMsgTotal(weekGroupChatData.getMsgTotal());
break;
}
}
}
pageStaticData.setDataList(weekCountData); pageStaticData.setDataList(weekCountData);
return pageStaticData; return pageStaticData;
...@@ -139,21 +210,55 @@ public class PageHomeDataTask { ...@@ -139,21 +210,55 @@ public class PageHomeDataTask {
private WePageStaticDataDto.PageStaticData getMonthData(){ private WePageStaticDataDto.PageStaticData getMonthData(){
/** /**
* 本周 * 本月
*/ */
//客户统计 //客户统计
WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"month"); WePageCountDto newTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.today(),"month");
WePageCountDto nowTimeGroupChatData = weGroupStatisticService.getCountDataByDay(DateUtil.today(),"month");
if(nowTimeGroupChatData != null){
newTime.setChatCnt(nowTimeGroupChatData.getChatCnt());
newTime.setChatTotal(nowTimeGroupChatData.getChatTotal());
newTime.setChatHasMsg(nowTimeGroupChatData.getChatHasMsg());
newTime.setNewChatCnt(nowTimeGroupChatData.getNewChatCnt());
newTime.setNewMemberCnt(nowTimeGroupChatData.getNewMemberCnt());
newTime.setMemberTotal(nowTimeGroupChatData.getMemberTotal());
newTime.setMsgTotal(nowTimeGroupChatData.getMsgTotal());
}
/** /**
* 上周 * 上月
*/ */
//客户统计 //客户统计
WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastMonth().toDateStr(),"month"); WePageCountDto lastTime = weUserBehaviorDataService.getCountDataByDay(DateUtil.lastMonth().toDateStr(),"month");
WePageCountDto lastTimeGroupChatData = weGroupStatisticService.getCountDataByDay(DateUtil.lastMonth().toDateStr(),"month");
if(lastTimeGroupChatData != null){
lastTime.setChatCnt(lastTimeGroupChatData.getChatCnt());
lastTime.setChatTotal(lastTimeGroupChatData.getChatTotal());
lastTime.setChatHasMsg(lastTimeGroupChatData.getChatHasMsg());
lastTime.setNewChatCnt(lastTimeGroupChatData.getNewChatCnt());
lastTime.setNewMemberCnt(lastTimeGroupChatData.getNewMemberCnt());
lastTime.setMemberTotal(lastTimeGroupChatData.getMemberTotal());
lastTime.setMsgTotal(lastTimeGroupChatData.getMsgTotal());
}
WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime); WePageStaticDataDto.PageStaticData pageStaticData = setPageStaticData(newTime, lastTime);
WePageStateQuery wePageStateQuery = new WePageStateQuery(); WePageStateQuery wePageStateQuery = new WePageStateQuery();
wePageStateQuery.setFew(5); wePageStateQuery.setFew(5);
List<WePageCountDto> monthCountData = weUserBehaviorDataService.getMonthCountData(wePageStateQuery); List<WePageCountDto> monthCountData = weUserBehaviorDataService.getMonthCountData(wePageStateQuery);
List<WePageCountDto> monthGroupChatCountData = weGroupStatisticService.getMonthCountData(wePageStateQuery);
for (WePageCountDto monthData : monthCountData) {
for (WePageCountDto monthGroupChatData : monthGroupChatCountData) {
if (monthData.getXTime().equals(monthGroupChatData.getXTime())){
monthData.setChatCnt(monthGroupChatData.getChatCnt());
monthData.setChatTotal(monthGroupChatData.getChatTotal());
monthData.setChatHasMsg(monthGroupChatData.getChatHasMsg());
monthData.setNewChatCnt(monthGroupChatData.getNewChatCnt());
monthData.setNewMemberCnt(monthGroupChatData.getNewMemberCnt());
monthData.setMemberTotal(monthGroupChatData.getMemberTotal());
monthData.setMsgTotal(monthGroupChatData.getMsgTotal());
break;
}
}
}
pageStaticData.setDataList(monthCountData); pageStaticData.setDataList(monthCountData);
return pageStaticData; return pageStaticData;
...@@ -169,6 +274,8 @@ public class PageHomeDataTask { ...@@ -169,6 +274,8 @@ public class PageHomeDataTask {
pageStaticData.setNegativeFeedbackCntDiff(nowTime.getNegativeFeedbackCnt() - lastTime.getNegativeFeedbackCnt()); pageStaticData.setNegativeFeedbackCntDiff(nowTime.getNegativeFeedbackCnt() - lastTime.getNegativeFeedbackCnt());
pageStaticData.setNewContactCnt(nowTime.getNewContactCnt()); pageStaticData.setNewContactCnt(nowTime.getNewContactCnt());
pageStaticData.setNewContactCntDiff(nowTime.getNewContactCnt() - lastTime.getNewContactCnt()); pageStaticData.setNewContactCntDiff(nowTime.getNewContactCnt() - lastTime.getNewContactCnt());
pageStaticData.setNewMemberCnt(nowTime.getNewMemberCnt());
pageStaticData.setNewMemberCntDiff(nowTime.getNewMemberCnt() - lastTime.getNewMemberCnt());
return pageStaticData; return pageStaticData;
} }
......
...@@ -2,6 +2,11 @@ package com.linkwechat.wecom.mapper; ...@@ -2,6 +2,11 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeGroupStatistic; import com.linkwechat.wecom.domain.WeGroupStatistic;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 群聊数据统计数据 * 群聊数据统计数据
...@@ -11,5 +16,29 @@ Mapper接口 ...@@ -11,5 +16,29 @@ Mapper接口
* @date 2021-02-24 * @date 2021-02-24
*/ */
public interface WeGroupStatisticMapper extends BaseMapper<WeGroupStatistic> { public interface WeGroupStatisticMapper extends BaseMapper<WeGroupStatistic> {
/**
* 按日期查询当天数据统计结果
* @param dateTime
* @return WeUserBehaviorDataDto
*/
public WePageCountDto getCountDataByDay(@Param("dateTime") String dateTime, @Param("type") 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; ...@@ -2,6 +2,8 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeGroupStatistic; import com.linkwechat.wecom.domain.WeGroupStatistic;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import java.util.List; import java.util.List;
...@@ -18,4 +20,31 @@ public interface IWeGroupStatisticService extends IService<WeGroupStatistic> { ...@@ -18,4 +20,31 @@ public interface IWeGroupStatisticService extends IService<WeGroupStatistic> {
* 查询列表 * 查询列表
*/ */
List<WeGroupStatistic> queryList(WeGroupStatistic weGroupStatistic); List<WeGroupStatistic> queryList(WeGroupStatistic weGroupStatistic);
/**
* 按日期查询当天数据统计结果
* @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);
} }
package com.linkwechat.wecom.service.impl; package com.linkwechat.wecom.service.impl;
import com.linkwechat.wecom.domain.WeGroupStatistic; import com.linkwechat.wecom.domain.WeGroupStatistic;
import com.linkwechat.wecom.domain.dto.WePageCountDto;
import com.linkwechat.wecom.domain.query.WePageStateQuery;
import com.linkwechat.wecom.mapper.WeGroupStatisticMapper; import com.linkwechat.wecom.mapper.WeGroupStatisticMapper;
import com.linkwechat.wecom.service.IWeGroupStatisticService; import com.linkwechat.wecom.service.IWeGroupStatisticService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -54,4 +56,25 @@ public class WeGroupStatisticServiceImpl extends ServiceImpl<WeGroupStatisticMap ...@@ -54,4 +56,25 @@ public class WeGroupStatisticServiceImpl extends ServiceImpl<WeGroupStatisticMap
} }
return this.list(lqw); 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);
}
} }
...@@ -18,4 +18,146 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -18,4 +18,146 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<select id="getCountDataByDay" resultType="com.linkwechat.wecom.domain.dto.WePageCountDto">
select
date_format(stat_time, '%Y-%m-%d') as x_time,
IFNULL(sum(new_chat_cnt), 0) as new_chat_cnt,
IFNULL(sum(chat_total), 0) as chat_total,
IFNULL(sum(chat_has_msg), 0) as chat_has_msg,
IFNULL(sum(new_member_cnt), 0) as new_member_cnt,
IFNULL(sum(member_total), 0) as member_total,
IFNULL(sum(member_has_msg), 0) as member_has_msg,
IFNULL(sum(msg_total), 0) as msg_total
from we_group_statistic
<where>
<choose>
<when test="type !=null and type == 'day'">
date_format(stat_time, '%Y-%m-%d') = date_format(#{dateTime}, '%Y-%m-%d');
</when>
<when test="type !=null and type == 'week'">
YEARWEEK(date_format(stat_time,'%Y-%m-%d')) = YEARWEEK(date_format(#{dateTime}, '%Y-%m-%d'));
</when>
<when test="type !=null and type == 'month'">
DATE_FORMAT(stat_time,'%Y-%m') = 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(sum(new_chat_cnt), 0) as new_chat_cnt,
IFNULL(sum(chat_total), 0) as chat_total,
IFNULL(sum(chat_has_msg), 0) as chat_has_msg,
IFNULL(sum(new_member_cnt), 0) as new_member_cnt,
IFNULL(sum(member_total), 0) as member_total,
IFNULL(sum(member_has_msg), 0) as member_has_msg,
IFNULL(sum(msg_total), 0) as msg_total
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(wgs.new_chat_cnt, 0)) new_chat_cnt,
sum(ifnull(wgs.chat_total, 0)) chat_total,
sum(ifnull(wgs.chat_has_msg, 0)) chat_has_msg,
sum(ifnull(wgs.new_member_cnt, 0)) new_member_cnt,
sum(ifnull(wgs.member_total, 0)) member_total,
sum(ifnull(wgs.member_has_msg, 0)) member_has_msg,
sum(ifnull(wgs.msg_total, 0)) msg_total,
STR_TO_DATE(DATE_FORMAT(wgs.stat_time,'%Y-%m-%d'),'%Y-%m-%d') AS finish_date
FROM we_group_statistic wgs
where
STR_TO_DATE(DATE_FORMAT(wgs.stat_time,'%Y-%m-%d'),'%Y-%m-%d') &gt;= #{startTime}
AND STR_TO_DATE(DATE_FORMAT(wgs.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(sum(new_chat_cnt), 0) as new_chat_cnt,
IFNULL(sum(chat_total), 0) as chat_total,
IFNULL(sum(chat_has_msg), 0) as chat_has_msg,
IFNULL(sum(new_member_cnt), 0) as new_member_cnt,
IFNULL(sum(member_total), 0) as member_total,
IFNULL(sum(member_has_msg), 0) as member_has_msg,
IFNULL(sum(msg_total), 0) as msg_total
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(wgs.new_chat_cnt, 0)) new_chat_cnt,
sum(ifnull(wgs.chat_total, 0)) chat_total,
sum(ifnull(wgs.chat_has_msg, 0)) chat_has_msg,
sum(ifnull(wgs.new_member_cnt, 0)) new_member_cnt,
sum(ifnull(wgs.member_total, 0)) member_total,
sum(ifnull(wgs.member_has_msg, 0)) member_has_msg,
sum(ifnull(wgs.msg_total, 0)) msg_total,
yearweek(date_format(wgs.stat_time, '%Y-%m-%d')) as finish_date
from we_group_statistic wgs
where yearweek(date_format(wgs.stat_time, '%Y-%m-%d')) &gt;=
yearweek(date(date_sub(date_format(current_date, '%Y-%m-%d'), interval #{few} week)))
and yearweek(date_format(wgs.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(sum(new_chat_cnt), 0) as new_chat_cnt,
IFNULL(sum(chat_total), 0) as chat_total,
IFNULL(sum(chat_has_msg), 0) as chat_has_msg,
IFNULL(sum(new_member_cnt), 0) as new_member_cnt,
IFNULL(sum(member_total), 0) as member_total,
IFNULL(sum(member_has_msg), 0) as member_has_msg,
IFNULL(sum(msg_total), 0) as msg_total
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(wgs.new_chat_cnt, 0)) new_chat_cnt,
sum(ifnull(wgs.chat_total, 0)) chat_total,
sum(ifnull(wgs.chat_has_msg, 0)) chat_has_msg,
sum(ifnull(wgs.new_member_cnt, 0)) new_member_cnt,
sum(ifnull(wgs.member_total, 0)) member_total,
sum(ifnull(wgs.member_has_msg, 0)) member_has_msg,
sum(ifnull(wgs.msg_total, 0)) msg_total,
date_format(wgs.stat_time, '%Y-%m') as finish_date
from we_group_statistic wgs
where
str_to_date(date_format(wgs.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(wgs.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> </mapper>
\ No newline at end of file \ 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!