首页 数据统计
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.dto.BaseQueryDto;
|
||||
import cn.ysk.cashier.dto.ShopSummaryDto;
|
||||
import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto;
|
||||
import cn.ysk.cashier.vo.ShopTableSaleInfoVo;
|
||||
@@ -17,8 +18,9 @@ import java.util.Map;
|
||||
* @author lyf
|
||||
*/
|
||||
public interface SummaryService {
|
||||
SummaryVO selectSummary(Integer shop);
|
||||
Map<String,Object> trade(BaseQueryDto param);
|
||||
|
||||
// SummaryVO selectSummary(Integer shop);
|
||||
Map<String,Object> selectSummaryDate(Integer shopId, Integer day);
|
||||
|
||||
Map<String,Object> selectSummaryToday(Integer shopId);
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package cn.ysk.cashier.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.ysk.cashier.dto.ShopSummaryDto;
|
||||
import cn.ysk.cashier.dto.BaseQueryDto;
|
||||
import cn.ysk.cashier.dto.shop.ShopTableSaleInfoDto;
|
||||
import cn.ysk.cashier.enums.PayTypeEnum;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopUserFlowMapper;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
||||
import cn.ysk.cashier.repository.TbTokenRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopTableRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
|
||||
import cn.ysk.cashier.service.SummaryService;
|
||||
import cn.ysk.cashier.utils.DateUtil;
|
||||
@@ -56,106 +60,160 @@ public class SummaryServiceImpl implements SummaryService {
|
||||
@Resource
|
||||
private TbTokenRepository tbTokenRepository;
|
||||
|
||||
@Autowired
|
||||
private TbShopUserFlowMapper tbShopUserFlowMapper;
|
||||
@Resource
|
||||
private TbShopUserFlowService tbShopUserFlowService;
|
||||
|
||||
@Autowired
|
||||
private TbOrderDetailRepository tbOrderDetailRepository;
|
||||
private final TbShopTableRepository tbShopTableRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public SummaryVO selectSummary(Integer shopId) {
|
||||
SummaryVO summaryVO = new SummaryVO();
|
||||
//支付笔数,
|
||||
Tuple result = tbOrderInfoRepository.countByShopId(shopId.toString());
|
||||
summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class));
|
||||
summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class));
|
||||
if (summaryVO.getPaymentsNumber() == 0) {
|
||||
summaryVO.setAverageSales(new BigDecimal("0"));
|
||||
} else {
|
||||
summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN));
|
||||
public Map<String, Object> trade(BaseQueryDto param) {
|
||||
if (ObjectUtil.isNull(param.getShopId())) {
|
||||
throw new BadRequestException("参数不合法");
|
||||
}
|
||||
//用户数
|
||||
Tuple count = tbShopUserRepository.searchByCount(shopId.toString());
|
||||
summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class));
|
||||
//支付笔数柱形图
|
||||
List<Object[]> objects = tbOrderInfoRepository.sumByDateOrderNum(shopId.toString(), DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountDateVO> countDateList = new ArrayList<>();
|
||||
for (Object[] o : objects) {
|
||||
CountDateVO countDateVO = new CountDateVO();
|
||||
BigInteger integers = (BigInteger) o[0];
|
||||
countDateVO.setCount(new BigDecimal(integers.toString()));
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
countDateList.add(countDateVO);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Map<String, Object> sale = new HashMap<>();
|
||||
Map<String, Object> vip = new HashMap<>();
|
||||
Map<String, Object> count = new HashMap<>();
|
||||
//订单 销售金额 saleAmount /订单数 saleNum /优惠金额 saveAmount /优惠笔数 saveNum
|
||||
Map<String, Object> orderMap = tbOrderInfoRepository.tradeIndex(param.getShopId(), param.getStartTime().getTime(), param.getEndTime().getTime());
|
||||
//退款金额
|
||||
BigDecimal refundAmount = tbOrderInfoRepository.tradeIndexRefund(param.getShopId(), param.getStartTime().getTime(), param.getEndTime().getTime());
|
||||
|
||||
//会员 充值金额 inAmount /退款金额 outAmount /会员消费金额 useAmount /会员消费笔数 useNum
|
||||
Map<String, Object> flowMap = tbShopUserFlowMapper.tradeIndexFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime()));
|
||||
// 新增会员数
|
||||
Integer newFlow = tbShopUserFlowMapper.tradeIndexNewFlow(param.getShopId(), DateUtil.getStrTime(param.getStartTime()), DateUtil.getStrTime(param.getEndTime()));
|
||||
//台桌数
|
||||
int tables = tbShopTableRepository.countAllByShopId(param.getShopId());
|
||||
sale.put("totalSaleAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount));//总金额
|
||||
sale.put("incomeAmount", new BigDecimal(orderMap.get("saleAmount").toString()).add(new BigDecimal(flowMap.get("inAmount").toString())));//实收
|
||||
sale.put("refundAmount", refundAmount);//销售退款金额
|
||||
sale.put("inAmount", flowMap.get("inAmount"));//会员充值金额
|
||||
sale.put("outAmount", flowMap.get("outAmount"));//会员退款金额
|
||||
result.put("sale",sale);
|
||||
vip.put("useAmount", flowMap.get("useAmount"));//会员消费金额
|
||||
vip.put("newFlow",newFlow);//新增会员数
|
||||
vip.put("useNum",flowMap.get("useNum"));//会员消费笔数
|
||||
result.put("vip",vip);
|
||||
BigDecimal saleAmount = new BigDecimal(orderMap.get("saleAmount").toString()).add(refundAmount);
|
||||
//客单价
|
||||
if(saleAmount.compareTo(BigDecimal.ZERO) == 0){
|
||||
count.put("unitPrice",BigDecimal.ZERO);
|
||||
}else {
|
||||
count.put("unitPrice",saleAmount.divide(new BigDecimal(orderMap.get("saleNum").toString()),2,RoundingMode.DOWN));
|
||||
}
|
||||
//填充日期
|
||||
Map<String, CountDateVO> dataMap = new HashMap<>();
|
||||
for (CountDateVO entry : countDateList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigDecimal countOrder = entry.getCount();
|
||||
dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder));
|
||||
BigDecimal saleNum = new BigDecimal(orderMap.get("saleNum").toString());
|
||||
if(saleNum.compareTo(BigDecimal.ZERO) == 0){
|
||||
count.put("turnoverRate",BigDecimal.ZERO);//翻台率
|
||||
}else {
|
||||
count.put("turnoverRate",saleNum.divide(new BigDecimal(tables),2,RoundingMode.DOWN));//翻台率
|
||||
}
|
||||
// 获取今天的日期
|
||||
LocalDate today = LocalDate.now();
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
// 转换为字符串
|
||||
List<CountDateVO> countDateLists = new ArrayList<>();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
LocalDate tradeDayLocalDate = today.minusDays(i);
|
||||
String tradeDayString = tradeDayLocalDate.format(formatter);
|
||||
CountDateVO countDateVO;
|
||||
// 检查数据Map中是否存在该日期的数据
|
||||
if (dataMap.containsKey(tradeDayString)) {
|
||||
countDateVO = dataMap.get(tradeDayString);
|
||||
} else {
|
||||
// 如果不存在,则创建新的SumDateVO对象,amount设为0
|
||||
countDateVO = new CountDateVO(tradeDayString, BigDecimal.ZERO);
|
||||
}
|
||||
// 将SumDateVO对象添加到列表中
|
||||
countDateLists.add(countDateVO);
|
||||
}
|
||||
countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
summaryVO.setCountDateList(countDateLists);
|
||||
//访问量
|
||||
Tuple tuple = tbTokenRepository.countByAccountId(shopId);
|
||||
summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class));
|
||||
//访问量柱状图
|
||||
List<Object[]> objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountVisitsVO> visitsList = new ArrayList<>();
|
||||
for (Object[] o : objectsVisits) {
|
||||
CountVisitsVO countDateVO = new CountVisitsVO();
|
||||
countDateVO.setCount((BigInteger) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
visitsList.add(countDateVO);
|
||||
}
|
||||
//填充日期
|
||||
Map<String, CountVisitsVO> dataVisitsMap = new HashMap<>();
|
||||
for (CountVisitsVO entry : visitsList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigInteger countOrder = entry.getCount();
|
||||
dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder));
|
||||
}
|
||||
// 转换为字符串
|
||||
List<CountVisitsVO> countVisitsLists = new ArrayList<>();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
LocalDate tradeDayLocalDate = today.minusDays(i);
|
||||
String tradeDayString = tradeDayLocalDate.format(formatter);
|
||||
CountVisitsVO countDateVO;
|
||||
// 检查数据Map中是否存在该日期的数据
|
||||
if (dataVisitsMap.containsKey(tradeDayString)) {
|
||||
countDateVO = dataVisitsMap.get(tradeDayString);
|
||||
} else {
|
||||
// 如果不存在,则创建新的SumDateVO对象,amount设为0
|
||||
countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO);
|
||||
}
|
||||
// 将SumDateVO对象添加到列表中
|
||||
countVisitsLists.add(countDateVO);
|
||||
}
|
||||
countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
summaryVO.setVisitsCountList(countVisitsLists);
|
||||
return summaryVO;
|
||||
count.put("saveAmount",orderMap.get("saveAmount"));//优惠金额
|
||||
count.put("saveNum",orderMap.get("saveNum"));//优惠单数
|
||||
result.put("count",count);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// @Override
|
||||
// public SummaryVO selectSummary(Integer shopId) {
|
||||
// SummaryVO summaryVO = new SummaryVO();
|
||||
// //支付笔数,
|
||||
// Tuple result = tbOrderInfoRepository.countByShopId(shopId.toString());
|
||||
// summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class));
|
||||
// summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class));
|
||||
// if (summaryVO.getPaymentsNumber() == 0) {
|
||||
// summaryVO.setAverageSales(new BigDecimal("0"));
|
||||
// } else {
|
||||
// summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN));
|
||||
// }
|
||||
// //用户数
|
||||
// Tuple count = tbShopUserRepository.searchByCount(shopId.toString());
|
||||
// summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class));
|
||||
// //支付笔数柱形图
|
||||
// List<Object[]> objects = tbOrderInfoRepository.sumByDateOrderNum(shopId.toString(), DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
// List<CountDateVO> countDateList = new ArrayList<>();
|
||||
// for (Object[] o : objects) {
|
||||
// CountDateVO countDateVO = new CountDateVO();
|
||||
// BigInteger integers = (BigInteger) o[0];
|
||||
// countDateVO.setCount(new BigDecimal(integers.toString()));
|
||||
// countDateVO.setTradeDay((String) o[1]);
|
||||
// countDateList.add(countDateVO);
|
||||
// }
|
||||
// //填充日期
|
||||
// Map<String, CountDateVO> dataMap = new HashMap<>();
|
||||
// for (CountDateVO entry : countDateList) {
|
||||
// String tradeDay = entry.getTradeDay();
|
||||
// BigDecimal countOrder = entry.getCount();
|
||||
// dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder));
|
||||
// }
|
||||
// // 获取今天的日期
|
||||
// LocalDate today = LocalDate.now();
|
||||
// // 定义日期格式
|
||||
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
// // 转换为字符串
|
||||
// List<CountDateVO> countDateLists = new ArrayList<>();
|
||||
// for (int i = 0; i < 30; i++) {
|
||||
// LocalDate tradeDayLocalDate = today.minusDays(i);
|
||||
// String tradeDayString = tradeDayLocalDate.format(formatter);
|
||||
// CountDateVO countDateVO;
|
||||
// // 检查数据Map中是否存在该日期的数据
|
||||
// if (dataMap.containsKey(tradeDayString)) {
|
||||
// countDateVO = dataMap.get(tradeDayString);
|
||||
// } else {
|
||||
// // 如果不存在,则创建新的SumDateVO对象,amount设为0
|
||||
// countDateVO = new CountDateVO(tradeDayString, BigDecimal.ZERO);
|
||||
// }
|
||||
// // 将SumDateVO对象添加到列表中
|
||||
// countDateLists.add(countDateVO);
|
||||
// }
|
||||
// countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
// summaryVO.setCountDateList(countDateLists);
|
||||
// //访问量
|
||||
// Tuple tuple = tbTokenRepository.countByAccountId(shopId);
|
||||
// summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class));
|
||||
// //访问量柱状图
|
||||
// List<Object[]> objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
// List<CountVisitsVO> visitsList = new ArrayList<>();
|
||||
// for (Object[] o : objectsVisits) {
|
||||
// CountVisitsVO countDateVO = new CountVisitsVO();
|
||||
// countDateVO.setCount((BigInteger) o[0]);
|
||||
// countDateVO.setTradeDay((String) o[1]);
|
||||
// visitsList.add(countDateVO);
|
||||
// }
|
||||
// //填充日期
|
||||
// Map<String, CountVisitsVO> dataVisitsMap = new HashMap<>();
|
||||
// for (CountVisitsVO entry : visitsList) {
|
||||
// String tradeDay = entry.getTradeDay();
|
||||
// BigInteger countOrder = entry.getCount();
|
||||
// dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder));
|
||||
// }
|
||||
// // 转换为字符串
|
||||
// List<CountVisitsVO> countVisitsLists = new ArrayList<>();
|
||||
// for (int i = 0; i < 30; i++) {
|
||||
// LocalDate tradeDayLocalDate = today.minusDays(i);
|
||||
// String tradeDayString = tradeDayLocalDate.format(formatter);
|
||||
// CountVisitsVO countDateVO;
|
||||
// // 检查数据Map中是否存在该日期的数据
|
||||
// if (dataVisitsMap.containsKey(tradeDayString)) {
|
||||
// countDateVO = dataVisitsMap.get(tradeDayString);
|
||||
// } else {
|
||||
// // 如果不存在,则创建新的SumDateVO对象,amount设为0
|
||||
// countDateVO = new CountVisitsVO(tradeDayString, BigInteger.ZERO);
|
||||
// }
|
||||
// // 将SumDateVO对象添加到列表中
|
||||
// countVisitsLists.add(countDateVO);
|
||||
// }
|
||||
// countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
// summaryVO.setVisitsCountList(countVisitsLists);
|
||||
// return summaryVO;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Map<String, Object> selectSummaryDate(Integer shopId, Integer day) {
|
||||
Date startTime = new Date();
|
||||
|
||||
Reference in New Issue
Block a user