数据报表销量导出修改
This commit is contained in:
parent
4f7a387349
commit
556b0338de
|
|
@ -36,7 +36,6 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
/**
|
||||
* File工具类,扩展 hutool 工具包
|
||||
|
|
@ -233,13 +232,14 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
|||
IoUtil.close(out);
|
||||
}
|
||||
|
||||
public static void downloadExcelAndMerge(ConcurrentLinkedQueue<Map<String, Object>> list, int colSize, HttpServletResponse response, ArrayList<Integer> mergeRowIndex) throws IOException {
|
||||
public static void downloadExcelAndMerge(List<Map<String, Object>> list, int colSize, HttpServletResponse response, ArrayList<Integer> mergeRowIndex) throws IOException {
|
||||
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx";
|
||||
File file = new File(tempPath);
|
||||
BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||
|
||||
// 合并单元格后的标题行,使用默认标题样式.
|
||||
for (int i = 0; i < mergeRowIndex.size(); i++) {
|
||||
System.out.println(i);
|
||||
for (int i1 = 0; i1 < colSize; i1++) {
|
||||
writer.merge(i == 0 ? 0 : mergeRowIndex.get(i - 1) + 1, mergeRowIndex.get(i), i1, i1, "", true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 代码生成模块 -->
|
||||
<dependency>
|
||||
<groupId>cn.ysk.cashier</groupId>
|
||||
|
|
@ -39,6 +40,11 @@
|
|||
<version>2.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>5.2.1</version>
|
||||
</dependency>
|
||||
<!-- Spring boot websocket -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import org.springframework.data.jpa.repository.Query;
|
|||
|
||||
|
||||
import javax.persistence.Tuple;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -78,13 +80,14 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
|
|||
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
|
||||
"info.productId, info.productSkuId," +
|
||||
"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)) " +
|
||||
"SUM(CASE WHEN orders.orderType='return' THEN info.priceAmount ELSE 0 END), " +
|
||||
"info.productId, " +
|
||||
"info.productSkuId ) " +
|
||||
"FROM TbOrderInfo orders " +
|
||||
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
|
||||
"LEFT JOIN TbProduct pro ON info.productId = pro.id " +
|
||||
|
|
@ -99,6 +102,20 @@ 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), " +
|
||||
"COALESCE(CAST(SUM(CASE WHEN orders.orderType='return' THEN info.num ELSE 0 END) as long),0))" +
|
||||
|
|
@ -147,19 +164,5 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
|
|||
List<Integer> findOrderIdsByProductNameLike(@Param("productName") String productName, @Param("shop_id") String shopId,
|
||||
@Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query(value = "SELECT\n" +
|
||||
"od.num,\n" +
|
||||
"od.price AS price,\n" +
|
||||
"od.status, oi.orderNo \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 oi.createdAt > :startTime \n" +
|
||||
"AND oi.createdAt < :endTime \n" +
|
||||
"AND od.productId = :productId\n" +
|
||||
"AND od.productSkuId = :productSkuId")
|
||||
List<TbOrderSaleVO> querySaleOrderInfo(Date startTime, Date endTime, Integer productId, Integer productSkuId, String shopId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
|||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
|
@ -404,8 +405,8 @@ 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);
|
||||
}
|
||||
|
|
@ -436,9 +437,9 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
}
|
||||
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository
|
||||
.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
|
||||
tbOrderSalesCountByDayVos.stream().parallel().forEach(all -> {
|
||||
List<TbOrderSaleVO> tbOrderSaleVOS = detailRepository.querySaleOrderInfo(summaryDto.getStartTime(),
|
||||
summaryDto.getEndTime(), all.getProductId(), all.getProductSkuId(), summaryDto.getShopId());
|
||||
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()));
|
||||
for (TbOrderSaleVO tbOrderSaleVO : tbOrderSaleVOS) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("商品分类", all.getCateName());
|
||||
|
|
|
|||
|
|
@ -134,6 +134,25 @@ public class TbOrderSalesCountByDayVo {
|
|||
count();
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
count();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void count(){
|
||||
salesNum=salesNum-refNum;
|
||||
salesAmount=salesAmount.subtract(refAmount);
|
||||
|
|
|
|||
Loading…
Reference in New Issue