This commit is contained in:
lifenlong 2021-06-02 17:57:07 +08:00
commit b842daa609
5 changed files with 50 additions and 32 deletions

View File

@ -1,5 +1,7 @@
package cn.lili.modules.statistics.service; package cn.lili.modules.statistics.service;
import cn.lili.modules.statistics.model.dto.GoodsStatisticsQueryParam;
import cn.lili.modules.statistics.model.dto.StatisticsQueryParam;
import cn.lili.modules.statistics.model.vo.*; import cn.lili.modules.statistics.model.vo.*;
import java.util.List; import java.util.List;
@ -38,14 +40,14 @@ public interface IndexStatisticsService {
* *
* @return 热卖商品TOP10 * @return 热卖商品TOP10
*/ */
List<GoodsStatisticsDataVO> goodsStatisticsOfMonth(); List<GoodsStatisticsDataVO> goodsStatistics(GoodsStatisticsQueryParam statisticsQueryParam);
/** /**
* 查询热卖店铺TOP10 * 查询热卖店铺TOP10
* *
* @return 当月的热卖店铺TOP10 * @return 当月的热卖店铺TOP10
*/ */
List<StoreStatisticsDataVO> storeStatisticsOfMonth(); List<StoreStatisticsDataVO> storeStatistics(StatisticsQueryParam statisticsQueryParam);
} }

View File

@ -14,7 +14,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -45,8 +44,9 @@ public class GoodsStatisticsDataServiceImpl extends ServiceImpl<GoodsStatisticsD
queryWrapper.groupBy("goods_name"); queryWrapper.groupBy("goods_name");
queryWrapper.eq(!StringUtils.isEmpty(goodsStatisticsQueryParam.getStoreId()), "store_id", goodsStatisticsQueryParam.getStoreId()); queryWrapper.eq(!StringUtils.isEmpty(goodsStatisticsQueryParam.getStoreId()), "store_id", goodsStatisticsQueryParam.getStoreId());
//查询前一百条记录 //查询前X记录
Page page = new Page<GoodsStatisticsDataVO>(1, num); Page page = new Page<GoodsStatisticsDataVO>(1, num);
return goodsStatisticsDataMapper.getGoodsStatisticsData(page, queryWrapper); return goodsStatisticsDataMapper.getGoodsStatisticsData(page, queryWrapper);
} }
@ -68,10 +68,10 @@ public class GoodsStatisticsDataServiceImpl extends ServiceImpl<GoodsStatisticsD
queryWrapper.between("create_time", date[0], date[1]); queryWrapper.between("create_time", date[0], date[1]);
//判断是按照数量统计还是按照金额统计 //判断是按照数量统计还是按照金额统计
if (goodsStatisticsQueryParam.getType().equals(StatisticsQuery.NUM.name())) { if (goodsStatisticsQueryParam.getType().equals(StatisticsQuery.PRICE.name())) {
queryWrapper.orderByDesc("num");
} else {
queryWrapper.orderByDesc("price"); queryWrapper.orderByDesc("price");
} else {
queryWrapper.orderByDesc("num");
} }
//设置为付款查询 //设置为付款查询
queryWrapper.eq("flow_type", FlowTypeEnum.PAY.name()); queryWrapper.eq("flow_type", FlowTypeEnum.PAY.name());

View File

@ -19,9 +19,9 @@ import cn.lili.modules.statistics.mapper.StoreStatisticsDataMapper;
import cn.lili.modules.statistics.model.dto.GoodsStatisticsQueryParam; import cn.lili.modules.statistics.model.dto.GoodsStatisticsQueryParam;
import cn.lili.modules.statistics.model.dto.StatisticsQueryParam; import cn.lili.modules.statistics.model.dto.StatisticsQueryParam;
import cn.lili.modules.statistics.model.enums.SearchTypeEnum; import cn.lili.modules.statistics.model.enums.SearchTypeEnum;
import cn.lili.modules.statistics.model.enums.StatisticsQuery;
import cn.lili.modules.statistics.model.vo.*; import cn.lili.modules.statistics.model.vo.*;
import cn.lili.modules.statistics.service.*; import cn.lili.modules.statistics.service.*;
import cn.lili.modules.statistics.util.StatisticsDateUtil;
import cn.lili.modules.store.entity.enums.BillStatusEnum; import cn.lili.modules.store.entity.enums.BillStatusEnum;
import cn.lili.modules.store.service.BillService; import cn.lili.modules.store.service.BillService;
import cn.lili.modules.store.service.StoreService; import cn.lili.modules.store.service.StoreService;
@ -31,6 +31,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -234,20 +235,19 @@ public class IndexStatisticsServiceImpl implements IndexStatisticsService {
} }
@Override @Override
public List<GoodsStatisticsDataVO> goodsStatisticsOfMonth() { public List<GoodsStatisticsDataVO> goodsStatistics(GoodsStatisticsQueryParam statisticsQueryParam) {
//获取查询参数
GoodsStatisticsQueryParam goodsStatisticsQueryParam = getGoodsStatisticsQueryParam();
//查询商品 //查询商品
return goodsStatisticsDataService.getGoodsStatisticsData(goodsStatisticsQueryParam, 10); return goodsStatisticsDataService.getGoodsStatisticsData(statisticsQueryParam, 10);
} }
@Override @Override
public List<StoreStatisticsDataVO> storeStatisticsOfMonth() { public List<StoreStatisticsDataVO> storeStatistics(StatisticsQueryParam statisticsQueryParam) {
QueryWrapper queryWrapper = Wrappers.query(); QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.between("create_time", cn.hutool.core.date.DateUtil.beginOfYear(new DateTime()), Date[] dates = StatisticsDateUtil.getDateArray(statisticsQueryParam);
cn.hutool.core.date.DateUtil.endOfYear(new DateTime())); Date startTime = dates[0], endTime = dates[1];
queryWrapper.between("create_time", startTime, endTime);
queryWrapper.orderByDesc("price"); queryWrapper.orderByDesc("price");
@ -288,7 +288,6 @@ public class IndexStatisticsServiceImpl implements IndexStatisticsService {
if (UserContext.getCurrentUser().getRole().equals(UserEnums.STORE)) { if (UserContext.getCurrentUser().getRole().equals(UserEnums.STORE)) {
goodsStatisticsQueryParam.setStoreId(UserContext.getCurrentUser().getStoreId()); goodsStatisticsQueryParam.setStoreId(UserContext.getCurrentUser().getStoreId());
} }
goodsStatisticsQueryParam.setType(StatisticsQuery.PRICE.name());
DateTime dateTime = new DateTime(); DateTime dateTime = new DateTime();
goodsStatisticsQueryParam.setYear(dateTime.year()); goodsStatisticsQueryParam.setYear(dateTime.year());
goodsStatisticsQueryParam.setMonth(dateTime.monthBaseOne()); goodsStatisticsQueryParam.setMonth(dateTime.monthBaseOne());

View File

@ -4,14 +4,15 @@ import cn.hutool.core.date.DateUtil;
import cn.lili.modules.statistics.mapper.MemberStatisticsDataMapper; import cn.lili.modules.statistics.mapper.MemberStatisticsDataMapper;
import cn.lili.modules.statistics.model.dos.MemberStatisticsData; import cn.lili.modules.statistics.model.dos.MemberStatisticsData;
import cn.lili.modules.statistics.model.dto.StatisticsQueryParam; import cn.lili.modules.statistics.model.dto.StatisticsQueryParam;
import cn.lili.modules.statistics.model.enums.SearchTypeEnum;
import cn.lili.modules.statistics.service.MemberStatisticsDataService; import cn.lili.modules.statistics.service.MemberStatisticsDataService;
import cn.lili.modules.statistics.util.StatisticsDateUtil; import cn.lili.modules.statistics.util.StatisticsDateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -24,31 +25,26 @@ import java.util.List;
@Service @Service
public class MemberStatisticsDataServiceImpl extends ServiceImpl<MemberStatisticsDataMapper, MemberStatisticsData> implements MemberStatisticsDataService { public class MemberStatisticsDataServiceImpl extends ServiceImpl<MemberStatisticsDataMapper, MemberStatisticsData> implements MemberStatisticsDataService {
/**
* 会员统计
*/
@Autowired
private MemberStatisticsDataMapper memberStatisticsDataMapper;
@Override @Override
public Integer getMemberCount() { public Integer getMemberCount() {
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("disabled", true); queryWrapper.eq("disabled", true);
return memberStatisticsDataMapper.customSqlQuery(queryWrapper); return this.baseMapper.customSqlQuery(queryWrapper);
} }
@Override @Override
public Integer todayMemberNum() { public Integer todayMemberNum() {
QueryWrapper queryWrapper = Wrappers.query(); QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.gt("create_time", DateUtil.beginOfDay(new Date())); queryWrapper.gt("create_time", DateUtil.beginOfDay(new Date()));
return memberStatisticsDataMapper.customSqlQuery(queryWrapper); return this.baseMapper.customSqlQuery(queryWrapper);
} }
@Override @Override
public Integer memberCount(Date endTime) { public Integer memberCount(Date endTime) {
QueryWrapper queryWrapper = Wrappers.query(); QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.lt("create_time", endTime); queryWrapper.lt("create_time", endTime);
return memberStatisticsDataMapper.customSqlQuery(queryWrapper); return this.baseMapper.customSqlQuery(queryWrapper);
} }
@Override @Override
@ -56,20 +52,35 @@ public class MemberStatisticsDataServiceImpl extends ServiceImpl<MemberStatistic
QueryWrapper queryWrapper = Wrappers.query(); QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.ge("last_login_date", startTime); queryWrapper.ge("last_login_date", startTime);
return memberStatisticsDataMapper.customSqlQuery(queryWrapper); return this.baseMapper.customSqlQuery(queryWrapper);
} }
@Override @Override
public Integer newlyAdded(Date startTime, Date endTime) { public Integer newlyAdded(Date startTime, Date endTime) {
QueryWrapper queryWrapper = Wrappers.query(); QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.between("create_time", startTime, endTime); queryWrapper.between("create_time", startTime, endTime);
return memberStatisticsDataMapper.customSqlQuery(queryWrapper); return this.baseMapper.customSqlQuery(queryWrapper);
} }
@Override @Override
public List<MemberStatisticsData> statistics(StatisticsQueryParam statisticsQueryParam) { public List<MemberStatisticsData> statistics(StatisticsQueryParam statisticsQueryParam) {
Date[] dates = StatisticsDateUtil.getDateArray(statisticsQueryParam); Date[] dates = StatisticsDateUtil.getDateArray(statisticsQueryParam);
Date startTime = dates[0], endTime = dates[1]; Date startTime = dates[0], endTime = dates[1];
//如果统计今天则自行构造数据
if(statisticsQueryParam.getSearchType().equals(SearchTypeEnum.TODAY.name())){
//构建数据然后返回集合提供给前端展示
MemberStatisticsData memberStatisticsData = new MemberStatisticsData();
memberStatisticsData.setMemberCount(this.memberCount(endTime));
memberStatisticsData.setCreateDate(startTime);
memberStatisticsData.setActiveQuantity(this.activeQuantity(startTime));
memberStatisticsData.setNewlyAdded(this.newlyAdded(startTime, endTime));
List result = new ArrayList<MemberStatisticsData>();
result.add(memberStatisticsData);
return result;
}
QueryWrapper queryWrapper = Wrappers.query(); QueryWrapper queryWrapper = Wrappers.query();
queryWrapper.between("create_date", startTime, endTime); queryWrapper.between("create_date", startTime, endTime);

View File

@ -2,6 +2,9 @@ package cn.lili.controller.statistics;
import cn.lili.common.enums.ResultUtil; import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.ResultMessage; import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.statistics.model.dto.GoodsStatisticsQueryParam;
import cn.lili.modules.statistics.model.dto.StatisticsQueryParam;
import cn.lili.modules.statistics.model.enums.StatisticsQuery;
import cn.lili.modules.statistics.model.vo.GoodsStatisticsDataVO; import cn.lili.modules.statistics.model.vo.GoodsStatisticsDataVO;
import cn.lili.modules.statistics.model.vo.IndexNoticeVO; import cn.lili.modules.statistics.model.vo.IndexNoticeVO;
import cn.lili.modules.statistics.model.vo.IndexStatisticsVO; import cn.lili.modules.statistics.model.vo.IndexStatisticsVO;
@ -46,14 +49,17 @@ public class IndexStatisticsManagerController {
@ApiOperation(value = "获取首页查询热卖商品TOP10") @ApiOperation(value = "获取首页查询热卖商品TOP10")
@GetMapping("/goodsStatistics") @GetMapping("/goodsStatistics")
public ResultMessage<List<GoodsStatisticsDataVO>> goodsStatistics() { public ResultMessage<List<GoodsStatisticsDataVO>> goodsStatistics(GoodsStatisticsQueryParam goodsStatisticsQueryParam) {
return ResultUtil.data(indexStatisticsService.goodsStatisticsOfMonth());
//按照金额查询
goodsStatisticsQueryParam.setType(StatisticsQuery.PRICE.name());
return ResultUtil.data(indexStatisticsService.goodsStatistics(goodsStatisticsQueryParam));
} }
@ApiOperation(value = "获取首页查询热卖店铺TOP10") @ApiOperation(value = "获取首页查询热卖店铺TOP10")
@GetMapping("/storeStatistics") @GetMapping("/storeStatistics")
public ResultMessage<List<StoreStatisticsDataVO>> storeStatistics() { public ResultMessage<List<StoreStatisticsDataVO>> storeStatistics(StatisticsQueryParam statisticsQueryParam) {
return ResultUtil.data(indexStatisticsService.storeStatisticsOfMonth()); return ResultUtil.data(indexStatisticsService.storeStatistics(statisticsQueryParam));
} }
@ApiOperation(value = "通知提示信息") @ApiOperation(value = "通知提示信息")