Merge branch 'refs/heads/gyj' into test

# Conflicts:
#	eladmin-system/src/main/java/cn/ysk/cashier/repository/order/TbOrderDetailRepository.java
#	eladmin-system/src/main/java/cn/ysk/cashier/service/impl/SummaryServiceImpl.java
This commit is contained in:
GYJ 2024-08-15 17:31:07 +08:00
commit fa566a7057
7 changed files with 184 additions and 76 deletions

View File

@ -1,5 +1,6 @@
package cn.ysk.cashier.controller.shop;
import cn.ysk.cashier.annotation.rest.AnonymousPostMapping;
import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.service.SummaryService;
import cn.ysk.cashier.vo.TbOrderPayCountVo;

View File

@ -67,6 +67,7 @@ public class SummaryController {
}
@PostMapping("/table/download")
@AnonymousPostMapping
private void downloadShopSummaryTable(HttpServletResponse response, @RequestBody ShopTableSeleInfoDto exportRequest) throws IOException {
summaryService.downloadTableSeleInfo(exportRequest, response);
}

View File

@ -5,6 +5,7 @@ import cn.ysk.cashier.pojo.order.TbOrderDetail;
import cn.ysk.cashier.vo.TbOrderPayCountVo;
import cn.ysk.cashier.vo.TbOrderSaleVO;
import cn.ysk.cashier.vo.TbOrderSalesCountByDayVo;
import cn.ysk.cashier.vo.TbOrderSalesCountByTable;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@ -115,6 +116,19 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
"ORDER BY salesNum DESC")
List<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Query(value = "SELECT " +
"new cn.ysk.cashier.vo.TbOrderSaleVO(oi.orderNo, od.num, od.price, od.status)\n" +
"FROM\n" +
"TbOrderInfo oi\n" +
"LEFT JOIN TbOrderDetail od ON oi.id = od.orderId \n" +
"WHERE\n" +
"od.shopId = :shopId \n" +
"AND ( od.status = 'closed' OR od.status = 'refund' ) \n" +
"AND od.createTime > :startTime \n" +
"AND od.createTime < :endTime \n" +
"AND (:productId is null or od.productId = :productId)\n" +
"AND (:productSkuId is null or od.productSkuId = :productSkuId)")
List<TbOrderSaleVO> querySaleOrderInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productId") Integer productId, @Param("productSkuId") Integer productSkuId, @Param("shopId") Integer shopId);
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
"COALESCE(CAST(SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as long),0), " +
@ -165,4 +179,26 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByTable(" +
"info.productName, info.productSkuName, cate.name, unit.name,info.price," +
"SUM(CASE WHEN orders.orderType!='return' THEN info.num ELSE 0 END) as salesNum, " +
"SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END), " +
"SUM(info.num), " +
"SUM(CASE WHEN orders.orderType!='return' THEN info.priceAmount ELSE 0 END), " +
"SUM(CASE WHEN orders.orderType='return' THEN info.priceAmount ELSE 0 END), " +
"info.productId, " +
"info.productSkuId," +
"orders.tableId ) " +
"FROM TbOrderInfo orders " +
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
"LEFT JOIN TbProduct pro ON info.productId = pro.id " +
"LEFT JOIN TbShopUnit unit ON unit.id = pro.unitId " +
"LEFT JOIN TbShopCategory cate ON cate.id = pro.categoryId " +
"WHERE info.shopId = :shopId " +
"AND info.createTime > :startTime AND info.createTime < :endTime " +
"AND (info.status = 'closed' OR info.status = 'refund') " +
"GROUP BY info.productId, info.productSkuId, orders.tableId " +
"ORDER BY salesNum DESC")
List<TbOrderSalesCountByTable> queryTbOrderSalesCountByTable(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
}

View File

@ -189,6 +189,7 @@ public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Intege
"info.id," +
"info.shopId," +
"info.tableId," +
"table.qrcode," +
"table.name," +
"table.areaId," +
"area.name," +

View File

@ -1,5 +1,6 @@
package cn.ysk.cashier.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.dto.shop.ShopTableSeleInfoDto;
import cn.ysk.cashier.enums.PayTypeEnum;
@ -22,6 +23,7 @@ import cn.ysk.cashier.vo.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@ -70,6 +72,8 @@ public class SummaryServiceImpl implements SummaryService {
@Resource
TbShopAreaRepository tbShopAreaRepository;
@Autowired
private TbOrderDetailRepository tbOrderDetailRepository;
private final TbOrderInfoMapper orderInfoMapper;
@ -369,7 +373,7 @@ public class SummaryServiceImpl implements SummaryService {
@Override
public <T> Page<T> selectSummaryByDay(ShopSummaryDto summaryDto, Integer page, Integer size) {
Pageable pageable = PageRequest.of(page, size);
if(StringUtils.isBlank(summaryDto.getCateId())){
if (StringUtils.isBlank(summaryDto.getCateId())) {
summaryDto.setCateId(null);
}
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
@ -403,19 +407,18 @@ public class SummaryServiceImpl implements SummaryService {
summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
summaryDto.setEndTime(new Date());
}
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable);
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime(), pageable);
}
}
@Override
public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException {
// List<Map<String, Object>> list = new ArrayList<>();
ConcurrentLinkedQueue<Map<String, Object>> list = new ConcurrentLinkedQueue();
if(StringUtils.isBlank(summaryDto.getCateId())){
List<Map<String, Object>> list = new ArrayList<>();
if (StringUtils.isBlank(summaryDto.getCateId())) {
summaryDto.setCateId(null);
}
List<Integer> mergeRowIndex = Collections.synchronizedList(new ArrayList<>());
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
@ -440,67 +443,24 @@ public class SummaryServiceImpl implements SummaryService {
summaryDto.setEndTime(new Date());
}
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository
.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
ArrayList<Integer> skuIds = new ArrayList<>();
for (TbOrderSalesCountByDayVo tbOrderSalesCountByDayVo : tbOrderSalesCountByDayVos) {
if (tbOrderSalesCountByDayVo.getProductSkuId() != null) {
skuIds.add(tbOrderSalesCountByDayVo.getProductSkuId());
}
}
HashMap<String, List<TbOrderSaleVO>> saleOrderMap = new HashMap<>();
if (!skuIds.isEmpty()) {
List<TbOrderSaleVO> tbOrderSaleVOS = orderInfoMapper.selectAllSaleInfo(new Timestamp(summaryDto.getStartTime().getTime()),
new Timestamp(summaryDto.getEndTime().getTime()), skuIds, Integer.valueOf(summaryDto.getShopId()));
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
List<TbOrderSaleVO> orderSaleVOS = saleOrderMap.get(tbOrderSaleVO.getSkuId().toString());
if (orderSaleVOS == null) {
orderSaleVOS = new ArrayList<>();
}
orderSaleVOS.add(tbOrderSaleVO);
saleOrderMap.put(tbOrderSaleVO.getSkuId().toString(), orderSaleVOS);
}
}
.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getCateId(), summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
tbOrderSalesCountByDayVos.forEach(all -> {
List<TbOrderSaleVO> tbOrderSaleVOS = saleOrderMap.get(all.getProductSkuId().toString());
if (tbOrderSaleVOS == null) {
return;
}
// List<TbOrderSaleVO> tbOrderSaleVOS = detailRepository.querySaleOrderInfo(new Timestamp(summaryDto.getStartTime().getTime()),
// new Timestamp(summaryDto.getEndTime().getTime()), all.getProductId(), all.getProductSkuId(), Integer.valueOf(summaryDto.getShopId()));
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", all.getCateName());
map.put("商品名称", all.getProductName());
map.put("单 位", all.getUnitName());
map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName());
map.put("销 售 额", all.getSalesAmount());
map.put("销 量", all.getSalesNum());
map.put("单 价", all.getPrice());
map.put("退 单 量", all.getRefNum());
map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO)==0?all.getRefAmount():"-"+all.getRefAmount());
map.put("总 量", all.getNum()-all.getRefNum());
map.put("订单编号", tbOrderSaleVO.getOrderNo());
map.put("售出数量", tbOrderSaleVO.getNum());
list.add(map);
}
if (!tbOrderSaleVOS.isEmpty()) {
if (mergeRowIndex.isEmpty()) {
mergeRowIndex.add(tbOrderSaleVOS.size());
}else {
mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tbOrderSaleVOS.size());
}
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", all.getCateName());
map.put("商品名称", all.getProductName());
map.put("单 位", all.getUnitName());
map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName());
map.put("单 价", all.getPrice());
map.put("销 售 额", all.getSalesAmount());
map.put("退 单 额", all.getRefAmount().compareTo(BigDecimal.ZERO) == 0 ? all.getRefAmount() : "-" + all.getRefAmount());
map.put("总 销 量", all.getNum() - all.getRefNum());
map.put("实际销量", all.getSalesNum());
map.put("退 单 量", all.getRefNum());
list.add(map);
});
}
FileUtil.downloadExcelAndMerge(list, 10, response, mergeRowIndex);
FileUtil.downloadExcel(list, response);
}
@Override
@ -516,7 +476,7 @@ public class SummaryServiceImpl implements SummaryService {
endTime = new Date();
}
TbOrderPayCountVo payCount = tbOrderInfoRepository.queryOrderPayCount(shopId, start, end);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, null,start, end);
TbOrderPayCountVo refCount = tbOrderInfoRepository.queryTbOrderRefund(shopId, null, start, end);
payCount.setPayAmount(new BigDecimal(payCount.getPayAmount().toString()).subtract(new BigDecimal(refCount.getPayAmount().toString())));
payCount.setIcon("el-icon-coin");
list.add(payCount);
@ -528,8 +488,8 @@ public class SummaryServiceImpl implements SummaryService {
list.add(refCount);
TbOrderSalesCountByDayVo numCount = detailRepository.queryTbOrderSalesCount(Integer.valueOf(shopId), startTime, endTime);
TbOrderPayCountVo salesNum =new TbOrderPayCountVo("el-icon-goods","销售量","0",numCount.getSalesNum()-numCount.getRefNum());
TbOrderPayCountVo refNum =new TbOrderPayCountVo("el-icon-goods","退单量","0",numCount.getRefNum());
TbOrderPayCountVo salesNum = new TbOrderPayCountVo("el-icon-goods", "销售量", "0", numCount.getSalesNum() - numCount.getRefNum());
TbOrderPayCountVo refNum = new TbOrderPayCountVo("el-icon-goods", "退单量", "0", numCount.getRefNum());
list.add(salesNum);
list.add(refNum);
return list;
@ -594,20 +554,62 @@ public class SummaryServiceImpl implements SummaryService {
List<ShopTableSaleInfoVo> infoVos = selectSummaryTable(shopTableSeleInfoDto.getShopId(), shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime());
List<TbOrderSalesCountByTable> countByTables = tbOrderDetailRepository.queryTbOrderSalesCountByTable(shopTableSeleInfoDto.getShopId(), shopTableSeleInfoDto.getStartTime(), shopTableSeleInfoDto.getEndTime());
Map<String, List<TbOrderSalesCountByTable>> countByTableMap = countByTables.stream()
.collect(Collectors.groupingBy(TbOrderSalesCountByTable::getTableId));
List<Map<String, Object>> list = new ArrayList<>();
ArrayList<Integer> mergeRowIndex = new ArrayList<>();
for (ShopTableSaleInfoVo all : infoVos) {
Map<String, Object> map = new LinkedHashMap<>();
List<TbOrderSalesCountByTable> tables = countByTableMap.get(all.getTableCode());
if (tables == null) {
continue;
}
map.put("开始时间", shopTableSeleInfoDto.getStartTime());
map.put("结束时间", shopTableSeleInfoDto.getEndTime());
map.put("区域名称", all.getAreaName());
map.put("桌台名称", all.getTableName());
map.put("订单数量", all.getOrderCount());
map.put("销售额", all.getOrderAmount());
for (TbOrderSalesCountByTable table : tables) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("开始时间", shopTableSeleInfoDto.getStartTime());
map.put("结束时间", shopTableSeleInfoDto.getEndTime());
map.put("区域名称", all.getAreaName());
map.put("桌台名称", all.getTableName());
map.put("商品分类", table.getCateName());
map.put("商品名称", table.getProductName());
map.put("单位", table.getUnitName());
map.put("商品规格", table.getProductSkuName());
map.put("销量", table.getSalesNum());
map.put("销售额", table.getSalesAmount());
// map.put("订单数量", all.getOrderCount());
// map.put("销售额", all.getOrderAmount());
// map.put("商品名称", table.getProductName());
// map.put("销售数量", table.getSalesNum());
list.add(map);
}
list.add(map);
// Map<String, Object> map = new LinkedHashMap<>();
//
// map.put("开始时间", shopTableSeleInfoDto.getStartTime());
// map.put("结束时间", shopTableSeleInfoDto.getEndTime());
// map.put("区域名称", all.getAreaName());
// map.put("桌台名称", all.getTableName());
// map.put("订单数量", all.getOrderCount());
// map.put("销售额", all.getOrderAmount());
//
// list.add(map);
if (!tables.isEmpty()) {
if (mergeRowIndex.isEmpty()) {
mergeRowIndex.add(tables.size());
}else {
mergeRowIndex.add(mergeRowIndex.get(mergeRowIndex.size() - 1) + tables.size());
}
}
}
FileUtil.downloadExcel(list, response);
// FileUtil.downloadExcel(list, response);
FileUtil.downloadExcelAndMerge(list, 4, response, mergeRowIndex);
}
}

View File

@ -13,6 +13,8 @@ public class ShopTableSaleInfoVo {
private Object tableId;
private String tableCode;
private Object tableName;
private Object areaId;
@ -24,11 +26,12 @@ public class ShopTableSaleInfoVo {
private Object orderAmount;
public ShopTableSaleInfoVo(Integer id, Object shopId, Object tableId, Object tableName,
public ShopTableSaleInfoVo(Integer id, Object shopId, Object tableId, String tableCode, Object tableName,
Object areaId, Object areaName, Object orderCount, Object orderAmount) {
this.id = id;
this.shopId = shopId;
this.tableId = tableId;
this.tableCode = tableCode;
this.tableName = tableName;
this.areaId = areaId;
this.areaName = areaName;

View File

@ -0,0 +1,64 @@
package cn.ysk.cashier.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author GYJ
*/
@Data
public class TbOrderSalesCountByTable {
private String productName;
private String productSkuName;
private String cateName;
private String unitName;
private BigDecimal price;
private Long salesNum;
private Long refNum;
private BigDecimal salesAmount;
private BigDecimal refAmount;
private Long num;
private Integer productId;
private Integer productSkuId;
private String tableId;
public TbOrderSalesCountByTable(String productName, String productSkuName, String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) {
this.productName = productName;
this.productSkuName = productSkuName;
this.cateName = cateName;
this.unitName = unitName;
this.price = price;
this.salesNum = salesNum;
this.refNum = refNum;
this.salesAmount = salesAmount;
this.refAmount = refAmount;
this.num = num;
count();
}
public TbOrderSalesCountByTable(String productName, String productSkuName, String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount,
Integer productId, Integer productSkuId, String tableId) {
this.productName = productName;
this.productSkuName = productSkuName;
this.cateName = cateName;
this.unitName = unitName;
this.price = price;
this.salesNum = salesNum;
this.refNum = refNum;
this.salesAmount = salesAmount;
this.refAmount = refAmount;
this.num = num;
this.productId = productId;
this.productSkuId = productSkuId;
this.tableId = tableId;
count();
}
public void count(){
salesNum=salesNum-refNum;
salesAmount=salesAmount.subtract(refAmount);
}
}