数据报表

This commit is contained in:
2024-04-08 11:33:44 +08:00
parent 05e1acaef2
commit 8cbe957833
5 changed files with 202 additions and 67 deletions

View File

@@ -1,11 +1,13 @@
package cn.ysk.cashier.service;
import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.vo.SummaryVO;
import cn.ysk.cashier.vo.TbOrderPayCountVo;
import org.springframework.data.domain.Page;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -24,14 +26,16 @@ public interface SummaryService {
Map<String,Object> selectSummaryPayType(Integer shopId, Integer day);
<T> Page<T> selectSummaryByDay(Integer type, String shopId, Long startTime, Long endTime, Integer page, Integer size);
<T> Page<T> selectSummaryByDay(ShopSummaryDto summaryDto, Integer page, Integer size);
/**
* 导出数据
* @param response /
* @throws IOException /
*/
void download(Integer type, String shopId, Long startTime, Long endTime, HttpServletResponse response) throws IOException;
// void download(Integer type, String shopId, Long startTime, Long endTime, HttpServletResponse response) throws IOException;
void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException;
List<TbOrderPayCountVo> summaryCount(String shopId, Long startTime, Long endTime);
// List<TbOrderPayCountVo> summaryCount(String shopId, Long startTime, Long endTime);
List<TbOrderPayCountVo> summaryCount(String shopId, Date startTime, Date endTime);
}

View File

@@ -1,5 +1,6 @@
package cn.ysk.cashier.service.impl;
import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.enums.PayTypeEnum;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
@@ -326,38 +327,100 @@ public class SummaryServiceImpl implements SummaryService {
return map;
}
// @Override
// public <T> Page<T> selectSummaryByDay(ShopSummaryDto summaryDto, Integer page, Integer size) {
// Pageable pageable = PageRequest.of(page, size);
// if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
// if (summaryDto.getStartTime() == null || summaryDto.getEndTime() == null) {
// summaryDto.setStartTime(1704038400000L);
// summaryDto.setEndTime(Instant.now().toEpochMilli());
// }
// return (Page<T>) tbOrderInfoRepository.queryTbOrderPayCountByDay(summaryDto.getShopId(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable);
// } else {//销量
// Date end = null;
// Date start = null;
// if (summaryDto.getStartTime() == null || summaryDto.getEndTime() == null) {
// start = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
// end = new Date();
// } else {
// start = DateUtil.toDate(DateUtil.fromTimeStamp(summaryDto.getStartTime()));
// end = DateUtil.toDate(DateUtil.fromTimeStamp(summaryDto.getEndTime()));
// }
// return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), start, end, pageable);
// }
// }
@Override
public <T> Page<T> selectSummaryByDay(Integer type, String shopId, Long startTime, Long endTime, Integer page, Integer size) {
public <T> Page<T> selectSummaryByDay(ShopSummaryDto summaryDto, Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size);
if (type != null && type == 1) {//金额
if (startTime == null || endTime == null) {
startTime = 1704038400000L;
endTime = Instant.now().toEpochMilli();
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
if (summaryDto.getStartTime() != null && summaryDto.getEndTime() != null) {
start = summaryDto.getStartTime().getTime();
end = summaryDto.getEndTime().getTime();
}
return (Page<T>) tbOrderInfoRepository.queryTbOrderPayCountByDay(shopId, startTime, endTime, pageable);
return (Page<T>) tbOrderInfoRepository.queryTbOrderPayCountByDay(summaryDto.getShopId(), start, end, pageable);
} else {//销量
Date end = null;
Date start = null;
if (startTime == null || endTime == null) {
start = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
end = new Date();
} else {
start = DateUtil.toDate(DateUtil.fromTimeStamp(startTime));
end = DateUtil.toDate(DateUtil.fromTimeStamp(endTime));
if (summaryDto.getStartTime() == null || summaryDto.getEndTime() == null) {
summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
summaryDto.setEndTime(new Date());
}
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(shopId), start, end, pageable);
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable);
}
}
// @Override
// public void download(Integer type, String shopId, Long startTime, Long endTime, HttpServletResponse response) throws IOException {
// List<Map<String, Object>> list = new ArrayList<>();
// if (type != null && type == 1) {//金额
// if (startTime == null || endTime == null) {
// startTime = 1704038400000L;
// endTime = Instant.now().toEpochMilli();
// }
// List<TbOrderPayCountByDayVo> tbOrderPayCountByDayVos = tbOrderInfoRepository.queryTbOrderPayCountByDay(shopId, startTime, endTime);
// for (TbOrderPayCountByDayVo all : tbOrderPayCountByDayVos) {
// Map<String, Object> map = new LinkedHashMap<>();
// map.put("现金", all.getCash());
// map.put("扫码支付", all.getScanCode());
// map.put("微信小程序支付", all.getWxLite());
// map.put("总金额", all.getTotal());
// map.put("日期", all.getTradeDay());
// list.add(map);
// }
// } else {//销量
// Date end = null;
// Date start = null;
// if (startTime == null || endTime == null) {
// start = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
// end = new Date();
// } else {
// start = DateUtil.toDate(DateUtil.fromTimeStamp(startTime));
// end = DateUtil.toDate(DateUtil.fromTimeStamp(endTime));
// }
// List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(shopId), start, end);
// for (TbOrderSalesCountByDayVo all : tbOrderSalesCountByDayVos) {
// Map<String, Object> map = new LinkedHashMap<>();
// map.put("商品名称", all.getProductName());
// map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName());
// map.put("销量", all.getSalesNum());
// map.put("退单量", all.getRefNum());
// map.put("总量", all.getNum());
// list.add(map);
// }
// }
// FileUtil.downloadExcel(list, response);
// }
@Override
public void download(Integer type, String shopId, Long startTime, Long endTime, HttpServletResponse response) throws IOException {
public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
if (type != null && type == 1) {//金额
if (startTime == null || endTime == null) {
startTime = 1704038400000L;
endTime = Instant.now().toEpochMilli();
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
if (summaryDto.getStartTime() != null && summaryDto.getEndTime() != null) {
start = summaryDto.getStartTime().getTime();
end = summaryDto.getEndTime().getTime();
}
List<TbOrderPayCountByDayVo> tbOrderPayCountByDayVos = tbOrderInfoRepository.queryTbOrderPayCountByDay(shopId, startTime, endTime);
List<TbOrderPayCountByDayVo> tbOrderPayCountByDayVos = tbOrderInfoRepository.queryTbOrderPayCountByDay(summaryDto.getShopId(), start, end);
for (TbOrderPayCountByDayVo all : tbOrderPayCountByDayVos) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("现金", all.getCash());
@@ -368,16 +431,11 @@ public class SummaryServiceImpl implements SummaryService {
list.add(map);
}
} else {//销量
Date end = null;
Date start = null;
if (startTime == null || endTime == null) {
start = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
end = new Date();
} else {
start = DateUtil.toDate(DateUtil.fromTimeStamp(startTime));
end = DateUtil.toDate(DateUtil.fromTimeStamp(endTime));
if (summaryDto.getStartTime() == null || summaryDto.getEndTime() == null) {
summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
summaryDto.setEndTime(new Date());
}
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(shopId), start, end);
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getStartTime(), summaryDto.getEndTime());
for (TbOrderSalesCountByDayVo all : tbOrderSalesCountByDayVos) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品名称", all.getProductName());
@@ -391,26 +449,55 @@ public class SummaryServiceImpl implements SummaryService {
FileUtil.downloadExcel(list, response);
}
// @Override
// public List<TbOrderPayCountVo> summaryCount(String shopId, Long startTime, Long endTime) {
// List<TbOrderPayCountVo> list = new ArrayList<>();
// Date end = null;
// Date start = null;
// if (startTime == null || endTime == null) {
// startTime = 1704038400000L;
// endTime = Instant.now().toEpochMilli();
// start = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
// end = new Date();
// } else {//销量
// start = DateUtil.toDate(DateUtil.fromTimeStamp(startTime));
// end = DateUtil.toDate(DateUtil.fromTimeStamp(endTime));
// }
// TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, startTime, endTime);
// list.add(payCount);
// TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, startTime, endTime);
// refCount.setPayType("退款金额");
// list.add(refCount);
// List<TbOrderPayCountVo> tbOrderPayCountVos = detailRepository.queryTbOrderSalesCount(Integer.valueOf(shopId), start, end);
// for (TbOrderPayCountVo tbOrderPayCountVo : tbOrderPayCountVos) {
// if (tbOrderPayCountVo.getPayType().equals("closed")) {
// tbOrderPayCountVo.setPayType("销售量");
// } else if (tbOrderPayCountVo.getPayType().equals("refund")) {
// tbOrderPayCountVo.setPayType("退单量");
// }
// list.add(tbOrderPayCountVo);
// }
// return list;
// }
@Override
public List<TbOrderPayCountVo> summaryCount(String shopId, Long startTime, Long endTime) {
public List<TbOrderPayCountVo> summaryCount(String shopId, Date startTime, Date endTime) {
List<TbOrderPayCountVo> list = new ArrayList<>();
Date end = null;
Date start = null;
if (startTime == null || endTime == null) {
startTime = 1704038400000L;
endTime = Instant.now().toEpochMilli();
start = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
end = new Date();
} else {//销量
start = DateUtil.toDate(DateUtil.fromTimeStamp(startTime));
end = DateUtil.toDate(DateUtil.fromTimeStamp(endTime));
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
if (startTime != null || endTime != null) {
start = startTime.getTime();
end = endTime.getTime();
} else {
startTime = DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L));
endTime = new Date();
}
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, startTime, endTime);
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, start, end);
list.add(payCount);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, startTime, endTime);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, start, end);
refCount.setPayType("退款金额");
list.add(refCount);
List<TbOrderPayCountVo> tbOrderPayCountVos = detailRepository.queryTbOrderSalesCount(Integer.valueOf(shopId), start, end);
List<TbOrderPayCountVo> tbOrderPayCountVos = detailRepository.queryTbOrderSalesCount(Integer.valueOf(shopId), startTime, endTime);
for (TbOrderPayCountVo tbOrderPayCountVo : tbOrderPayCountVos) {
if (tbOrderPayCountVo.getPayType().equals("closed")) {
tbOrderPayCountVo.setPayType("销售量");