数据报表-销量 增加销售金额 退款金额
This commit is contained in:
parent
6c30aa2abd
commit
d8b92aadf9
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.dto;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
|
@ -7,12 +8,20 @@ public class ShopSummaryDto {
|
|||
private String shopId;
|
||||
private String proName;
|
||||
private Integer type;
|
||||
private Integer cateId;
|
||||
private String cateId;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date startTime;
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endTime;
|
||||
|
||||
public String getCateId() {
|
||||
return cateId;
|
||||
}
|
||||
|
||||
public void setCateId(String cateId) {
|
||||
this.cateId = cateId;
|
||||
}
|
||||
|
||||
public String getShopId() {
|
||||
return shopId;
|
||||
}
|
||||
|
|
@ -26,7 +35,9 @@ public class ShopSummaryDto {
|
|||
}
|
||||
|
||||
public void setProName(String proName) {
|
||||
this.proName = proName;
|
||||
if(StringUtils.isNotBlank(proName)){
|
||||
this.proName = proName;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
|
|
@ -37,14 +48,6 @@ public class ShopSummaryDto {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public Integer getCateId() {
|
||||
return cateId;
|
||||
}
|
||||
|
||||
public void setCateId(Integer cateId) {
|
||||
this.cateId = cateId;
|
||||
}
|
||||
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,3 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.repository.order;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
|
|
@ -23,11 +8,11 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
|
||||
import javax.persistence.Tuple;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -38,43 +23,56 @@ import java.util.List;
|
|||
**/
|
||||
public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, Integer>, JpaSpecificationExecutor<TbOrderDetail> {
|
||||
|
||||
|
||||
@Query(value = "update tb_order_detail set status = 'closed' where order_id = :orderId and status='unpaid'",nativeQuery = true)
|
||||
@Modifying
|
||||
void updateToClosed(@Param("orderId") Integer orderId);
|
||||
|
||||
@Query("SELECT cart FROM TbOrderDetail cart WHERE cart.orderId = :orderId")
|
||||
List<TbOrderDetail> searchDetailByOrderId(@Param("orderId")Integer orderId);
|
||||
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
|
||||
"info.productName," +
|
||||
"info.productSkuName," +
|
||||
"cate.name as cateName,"+
|
||||
"SUM( CASE WHEN info.status = 'closed' THEN info.num ELSE 0 END ) as salesNum," +
|
||||
"SUM( CASE WHEN info.status = 'refund' THEN info.num ELSE 0 END )," +
|
||||
"SUM( info.num )) " +
|
||||
"FROM TbOrderDetail info " +
|
||||
"LEFT JOIN TbProduct pro on info.productId=pro.id " +
|
||||
"LEFT JOIN TbShopCategory cate on cate.id=pro.categoryId " +
|
||||
"info.productName, info.productSkuName, cate.name, " +
|
||||
"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)) " +
|
||||
"FROM TbOrderInfo orders " +
|
||||
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
|
||||
"LEFT JOIN TbProduct pro ON info.productId = pro.id " +
|
||||
"LEFT JOIN TbShopCategory cate ON cate.id = pro.categoryId " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND (pro.categoryId = IFNULL(:cateId, pro.categoryId))" +
|
||||
"AND (info.productName = IFNULL(:proName, info.productName))" +
|
||||
"AND (:cateId IS NULL OR pro.categoryId = :cateId) " +
|
||||
"AND (:proName IS NULL OR info.productName LIKE %:proName%) " +
|
||||
"AND info.createTime > :startTime AND info.createTime < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund')) " +
|
||||
"GROUP BY info.productId,info.productSkuId " +
|
||||
"AND (info.status = 'closed' OR info.status = 'refund') " +
|
||||
"GROUP BY info.productId, info.productSkuId " +
|
||||
"ORDER BY salesNum DESC")
|
||||
Page<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")Integer cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime, Pageable pageable);
|
||||
Page<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime, Pageable pageable);
|
||||
|
||||
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderSalesCountByDayVo(" +
|
||||
"info.productName," +
|
||||
"info.productSkuName," +
|
||||
"SUM( CASE WHEN info.status = 'closed' THEN info.num ELSE 0 END ) as salesNum," +
|
||||
"SUM( CASE WHEN info.status = 'refund' THEN info.num ELSE 0 END )," +
|
||||
"SUM( info.num )) " +
|
||||
"FROM TbOrderDetail info " +
|
||||
"info.productName, info.productSkuName, cate.name, " +
|
||||
"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)) " +
|
||||
"FROM TbOrderInfo orders " +
|
||||
"LEFT JOIN TbOrderDetail info on orders.id=info.orderId " +
|
||||
"LEFT JOIN TbProduct pro ON info.productId = pro.id " +
|
||||
"LEFT JOIN TbShopCategory cate ON cate.id = pro.categoryId " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND (:cateId IS NULL OR pro.categoryId = :cateId) " +
|
||||
"AND (:proName IS NULL OR info.productName LIKE %:proName%) " +
|
||||
"AND info.createTime > :startTime AND info.createTime < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund')) " +
|
||||
"GROUP BY info.productId,info.productSkuId " +
|
||||
"AND (info.status = 'closed' OR info.status = 'refund') " +
|
||||
"GROUP BY info.productId, info.productSkuId " +
|
||||
"ORDER BY salesNum DESC")
|
||||
List<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
List<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId,@Param("cateId")String cateId,@Param("proName")String proName, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(" +
|
||||
"info.status," +
|
||||
|
|
|
|||
|
|
@ -347,6 +347,9 @@ 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())){
|
||||
summaryDto.setCateId(null);
|
||||
}
|
||||
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
|
||||
Long start = 1704038400000L;
|
||||
Long end = Instant.now().toEpochMilli();
|
||||
|
|
@ -368,6 +371,9 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
@Override
|
||||
public void download(ShopSummaryDto summaryDto, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
if(StringUtils.isBlank(summaryDto.getCateId())){
|
||||
summaryDto.setCateId(null);
|
||||
}
|
||||
if (summaryDto.getType() != null && summaryDto.getType() == 1) {//金额
|
||||
Long start = 1704038400000L;
|
||||
Long end = Instant.now().toEpochMilli();
|
||||
|
|
@ -390,15 +396,17 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
summaryDto.setStartTime(DateUtil.toDate(DateUtil.fromTimeStamp(1704038400L)));
|
||||
summaryDto.setEndTime(new Date());
|
||||
}
|
||||
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()), summaryDto.getStartTime(), summaryDto.getEndTime());
|
||||
List<TbOrderSalesCountByDayVo> tbOrderSalesCountByDayVos = detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(summaryDto.getShopId()),summaryDto.getCateId(),summaryDto.getProName(), summaryDto.getStartTime(), summaryDto.getEndTime());
|
||||
for (TbOrderSalesCountByDayVo all : tbOrderSalesCountByDayVos) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("商品名称", all.getProductName());
|
||||
map.put("商品分类", all.getCateName());
|
||||
map.put("商品名称", all.getProductName());
|
||||
map.put("商品规格", StringUtils.isBlank(all.getProductSkuName()) ? "" : all.getProductSkuName());
|
||||
map.put("销量", all.getSalesNum());
|
||||
map.put("销 量", all.getSalesNum());
|
||||
map.put("退单量", all.getRefNum());
|
||||
map.put("总量", all.getNum());
|
||||
map.put("销售额", all.getSalesAmount());
|
||||
map.put("退单额", all.getRefAmount());
|
||||
map.put("总 量", all.getNum());
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
|
||||
public class TbOrderSalesCountByDayVo {
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class TbOrderSalesCountByDayVo {
|
||||
private String productName;
|
||||
private String productSkuName;
|
||||
private String cateName;
|
||||
private Long salesNum;
|
||||
private Long refNum;
|
||||
private BigDecimal salesAmount;
|
||||
private BigDecimal refAmount;
|
||||
private Long num;
|
||||
|
||||
public String getProductName() {
|
||||
|
|
@ -58,6 +61,22 @@ public class TbOrderSalesCountByDayVo {
|
|||
this.num = num;
|
||||
}
|
||||
|
||||
public BigDecimal getSalesAmount() {
|
||||
return salesAmount;
|
||||
}
|
||||
|
||||
public void setSalesAmount(BigDecimal salesAmount) {
|
||||
this.salesAmount = salesAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getRefAmount() {
|
||||
return refAmount;
|
||||
}
|
||||
|
||||
public void setRefAmount(BigDecimal refAmount) {
|
||||
this.refAmount = refAmount;
|
||||
}
|
||||
|
||||
public TbOrderSalesCountByDayVo(String productName, String productSkuName, Long salesNum, Long refNum, Long num) {
|
||||
this.productName = productName;
|
||||
this.productSkuName = productSkuName;
|
||||
|
|
@ -74,4 +93,15 @@ public class TbOrderSalesCountByDayVo {
|
|||
this.refNum = refNum;
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public TbOrderSalesCountByDayVo(String productName, String productSkuName, String cateName, Long salesNum, Long refNum, Long num, BigDecimal salesAmount, BigDecimal refAmount) {
|
||||
this.productName = productName;
|
||||
this.productSkuName = productSkuName;
|
||||
this.cateName = cateName;
|
||||
this.salesNum = salesNum;
|
||||
this.refNum = refNum;
|
||||
this.salesAmount = salesAmount;
|
||||
this.refAmount = refAmount;
|
||||
this.num = num;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue