1.数据报表导出cpu拉高问题修复

This commit is contained in:
2024-08-13 10:59:27 +08:00
parent fd5b79d6ec
commit e53037232f
6 changed files with 78 additions and 22 deletions

View File

@@ -0,0 +1,37 @@
package cn.ysk.cashier.mybatis.mapper;
import cn.ysk.cashier.mybatis.entity.TbMShopUser;
import cn.ysk.cashier.pojo.order.TbOrderInfo;
import cn.ysk.cashier.vo.TbOrderSaleVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
public interface TbOrderInfoMapper extends BaseMapper<TbOrderInfo> {
@Select("<script>" +
" SELECT \n" +
" oi.order_no, \n" +
" od.num, \n" +
" od.price, \n" +
" od.status, od.product_sku_id skuId \n" +
" FROM \n" +
" tb_order_info oi \n" +
" LEFT JOIN \n" +
" tb_order_detail od ON oi.id = od.order_id \n" +
" WHERE \n" +
" od.shop_id = #{shopId} \n" +
" AND (od.status = 'closed' OR od.status = 'refund') \n" +
" AND od.create_time > #{startTime} \n" +
" AND od.create_time &lt; #{endTime} \n" +
" AND (od.product_sku_id IN \n" +
" <foreach item=\"productSkuId\" collection=\"productSkuIds\" open=\"(\" separator=\",\" close=\")\"> \n" +
" #{productSkuId} \n" +
" </foreach> \n" +
" ) " +
"</script>")
List<TbOrderSaleVO> selectAllSaleInfo(@Param("startTime") Timestamp startTime, @Param("endTime") Timestamp endTime, @Param("productSkuIds") List<Integer> productSkuIds, @Param("shopId") Integer shopId);
}

View File

@@ -102,19 +102,6 @@ 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 (:productId 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), " +

View File

@@ -4,6 +4,7 @@ import cn.ysk.cashier.dto.ShopSummaryDto;
import cn.ysk.cashier.dto.shop.ShopTableSeleInfoDto;
import cn.ysk.cashier.enums.PayTypeEnum;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.mybatis.mapper.TbOrderInfoMapper;
import cn.ysk.cashier.mybatis.service.TbShopUserFlowService;
import cn.ysk.cashier.pojo.shop.TbShopTable;
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
@@ -39,6 +40,7 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -68,6 +70,7 @@ public class SummaryServiceImpl implements SummaryService {
@Resource
TbShopAreaRepository tbShopAreaRepository;
private final TbOrderInfoMapper orderInfoMapper;
@Override
@@ -407,13 +410,12 @@ public class SummaryServiceImpl implements SummaryService {
@Override
public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
// ConcurrentLinkedQueue<Map<String, Object>> list = new ConcurrentLinkedQueue();
// List<Map<String, Object>> list = new ArrayList<>();
ConcurrentLinkedQueue<Map<String, Object>> list = new ConcurrentLinkedQueue();
if(StringUtils.isBlank(summaryDto.getCateId())){
summaryDto.setCateId(null);
}
ArrayList<Integer> mergeRowIndex = new ArrayList<>();
List<Integer> mergeRowIndex = Collections.synchronizedList(new ArrayList<>());
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
@@ -439,9 +441,35 @@ public class SummaryServiceImpl implements SummaryService {
}
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository
.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
tbOrderSalesCountByDayVos.forEach(all -> {
List<TbOrderSaleVO> tbOrderSaleVOS = detailRepository.querySaleOrderInfo(new Timestamp(summaryDto.getStartTime().getTime()),
new Timestamp(summaryDto.getEndTime().getTime()), all.getProductId(), all.getProductSkuId(), Integer.valueOf(summaryDto.getShopId()));
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);
}
}
tbOrderSalesCountByDayVos.parallelStream().forEach(all -> {
List<TbOrderSaleVO> tbOrderSaleVOS = saleOrderMap.get(all.getProductSkuId().toString());
if (tbOrderSaleVOS == null) {
return;
}
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("商品分类", all.getCateName());

View File

@@ -14,4 +14,5 @@ public class TbOrderSaleVO {
private Integer num;
private BigDecimal price;
private String status;
private Integer skuId;
}

View File

@@ -134,7 +134,8 @@ public class TbOrderSalesCountByDayVo {
count();
}
public TbOrderSalesCountByDayVo(String productName, String productSkuName, String cateName,String unitName,BigDecimal price,
public TbOrderSalesCountByDayVo(String productName, String productSkuName,
String cateName,String unitName,BigDecimal price,
Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount, Integer productId, Integer productSkuId) {
this.productName = productName;
this.productSkuName = productSkuName;
@@ -153,6 +154,7 @@ public class TbOrderSalesCountByDayVo {
public void count(){
salesNum=salesNum-refNum;
salesAmount=salesAmount.subtract(refAmount);