数据报表
This commit is contained in:
parent
a11b7ebd2e
commit
05e1acaef2
|
|
@ -0,0 +1,59 @@
|
|||
package cn.ysk.cashier.controller.shop;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.service.SummaryService;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/summary/day")
|
||||
public class SummaryByDayController {
|
||||
@Autowired
|
||||
private SummaryService summaryService;
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "download")
|
||||
public void exportTbOrderInfo(HttpServletResponse response,
|
||||
@RequestParam String shopId,
|
||||
@RequestParam(required = false) Integer type,
|
||||
@RequestParam(required = false) Long startTime,
|
||||
@RequestParam(required = false) Long endTime) throws IOException {
|
||||
summaryService.download(type, shopId, startTime, endTime,response);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping
|
||||
public Page<T> shopSummary(@RequestParam String shopId,
|
||||
@RequestParam(required = false) Integer type,
|
||||
@RequestParam(required = false) Long startTime,
|
||||
@RequestParam(required = false) Long endTime,
|
||||
@RequestParam(required = false, defaultValue = "0") Integer page,
|
||||
@RequestParam(required = false, defaultValue = "10") Integer size) {
|
||||
return summaryService.selectSummaryByDay(type, shopId, startTime, endTime, page, size);
|
||||
}
|
||||
|
||||
@GetMapping(value = "count")
|
||||
public List<TbOrderPayCountVo> summaryCount(@RequestParam String shopId,
|
||||
@RequestParam(required = false) Long startTime,
|
||||
@RequestParam(required = false) Long endTime) {
|
||||
return summaryService.summaryCount(shopId, startTime, endTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,11 +16,18 @@
|
|||
package cn.ysk.cashier.repository.order;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import cn.ysk.cashier.vo.TbOrderSalesCountByDayVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
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.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -32,4 +39,44 @@ public interface TbOrderDetailRepository extends JpaRepository<TbOrderDetail, In
|
|||
|
||||
@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," +
|
||||
"SUM( CASE WHEN info.status = 'closed' THEN info.num ELSE 0 END )," +
|
||||
"SUM( CASE WHEN info.status = 'refund' THEN info.num ELSE 0 END )," +
|
||||
"SUM( info.num )) " +
|
||||
"FROM TbOrderDetail info " +
|
||||
"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 " +
|
||||
"ORDER BY info.productId DESC")
|
||||
Page<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId, @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 )," +
|
||||
"SUM( CASE WHEN info.status = 'refund' THEN info.num ELSE 0 END )," +
|
||||
"SUM( info.num )) " +
|
||||
"FROM TbOrderDetail info " +
|
||||
"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 " +
|
||||
"ORDER BY info.productId DESC")
|
||||
List<TbOrderSalesCountByDayVo> queryTbOrderSalesCountByDay(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(" +
|
||||
"info.status," +
|
||||
"SUM( info.num )) " +
|
||||
"FROM TbOrderDetail info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.createTime > :startTime AND info.createTime < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund')) " +
|
||||
"GROUP BY info.status")
|
||||
List<TbOrderPayCountVo> queryTbOrderSalesCount(@Param("shopId") Integer shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);
|
||||
|
||||
}
|
||||
|
|
@ -17,8 +17,11 @@ package cn.ysk.cashier.repository.order;
|
|||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.repository.mapping.CountPayTypeMapping;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountByDayVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
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.Query;
|
||||
|
|
@ -54,4 +57,44 @@ public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Intege
|
|||
|
||||
@Query("SELECT count(1) FROM TbOrderInfo WHERE source = :source AND shopId=:shopId")
|
||||
int isRefund(@Param("source")Integer source,@Param("shopId") String shopId);
|
||||
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountByDayVo(" +
|
||||
"info.tradeDay," +
|
||||
"SUM( CASE WHEN info.payType = 'scanCode' THEN info.orderAmount ELSE 0 END )," +
|
||||
"SUM( CASE WHEN info.payType = 'wx_lite' THEN info.orderAmount ELSE 0 END )," +
|
||||
"SUM( CASE WHEN info.payType = 'cash' THEN info.orderAmount ELSE 0 END )," +
|
||||
"SUM( info.orderAmount)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.createdAt > :startTime AND info.createdAt < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund' AND info.orderType != 'return' )) " +
|
||||
"GROUP BY info.tradeDay " +
|
||||
"ORDER BY info.tradeDay DESC")
|
||||
Page<TbOrderPayCountByDayVo> queryTbOrderPayCountByDay(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime, Pageable pageable);
|
||||
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountByDayVo(" +
|
||||
"info.tradeDay," +
|
||||
"SUM( CASE WHEN info.payType = 'scanCode' THEN info.orderAmount ELSE 0 END )," +
|
||||
"SUM( CASE WHEN info.payType = 'wx_lite' THEN info.orderAmount ELSE 0 END )," +
|
||||
"SUM( CASE WHEN info.payType = 'cash' THEN info.orderAmount ELSE 0 END )," +
|
||||
"SUM( info.orderAmount)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.createdAt > :startTime AND info.createdAt < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund' AND info.orderType != 'return' )) " +
|
||||
"GROUP BY info.tradeDay " +
|
||||
"ORDER BY info.tradeDay DESC")
|
||||
List<TbOrderPayCountByDayVo> queryTbOrderPayCountByDay(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(" +
|
||||
"'总金额'," +
|
||||
"SUM( info.orderAmount)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.createdAt > :startTime AND info.createdAt < :endTime " +
|
||||
"AND ((info.status = 'closed') OR ( info.status ='refund' AND info.orderType != 'return' )) ")
|
||||
TbOrderPayCountVo queryOrderPayCount(@Param("shopId") String shopId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
package cn.ysk.cashier.service;
|
||||
|
||||
import cn.ysk.cashier.repository.mapping.SumDateMapping;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -20,4 +23,15 @@ public interface SummaryService {
|
|||
Map<String,Object> selectSummaryProduct(Integer shopId, Integer day,Integer page,Integer size);
|
||||
|
||||
Map<String,Object> selectSummaryPayType(Integer shopId, Integer day);
|
||||
|
||||
<T> Page<T> selectSummaryByDay(Integer type, String shopId, Long startTime, Long endTime, Integer page, Integer size);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(Integer type, String shopId, Long startTime, Long endTime, HttpServletResponse response) throws IOException;
|
||||
|
||||
List<TbOrderPayCountVo> summaryCount(String shopId, Long startTime, Long endTime);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,26 +5,31 @@ import cn.ysk.cashier.exception.BadRequestException;
|
|||
import cn.ysk.cashier.repository.ShopUserDutyDetailRepository;
|
||||
import cn.ysk.cashier.repository.ShopUserDutyRepository;
|
||||
import cn.ysk.cashier.repository.TbTokenRepository;
|
||||
import cn.ysk.cashier.repository.mapping.CountPayTypeMapping;
|
||||
import cn.ysk.cashier.repository.mapping.SumDateMapping;
|
||||
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopUserRepository;
|
||||
import cn.ysk.cashier.service.SummaryService;
|
||||
import cn.ysk.cashier.utils.DateUtil;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import cn.ysk.cashier.vo.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.persistence.Tuple;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
|
|
@ -37,27 +42,31 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
private TbShopUserRepository tbShopUserRepository;
|
||||
@Resource
|
||||
private TbOrderInfoRepository tbOrderInfoRepository;
|
||||
@Resource
|
||||
private TbOrderDetailRepository detailRepository;
|
||||
|
||||
@Resource
|
||||
private TbTokenRepository tbTokenRepository;
|
||||
|
||||
@Override
|
||||
public SummaryVO selectSummary(Integer shopId) {
|
||||
SummaryVO summaryVO = new SummaryVO();
|
||||
//支付笔数
|
||||
Tuple result = shopUserDutyRepository.sumByShopId(shopId);
|
||||
summaryVO.setPaymentsNumber(result.get(0, Long.class) == null?0L : result.get(0, Long.class));
|
||||
summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null? new BigDecimal("0") : result.get(1, BigDecimal.class));
|
||||
if (summaryVO.getPaymentsNumber() == 0){
|
||||
summaryVO.setPaymentsNumber(result.get(0, Long.class) == null ? 0L : result.get(0, Long.class));
|
||||
summaryVO.setTotalSales(result.get(1, BigDecimal.class) == null ? new BigDecimal("0") : result.get(1, BigDecimal.class));
|
||||
if (summaryVO.getPaymentsNumber() == 0) {
|
||||
summaryVO.setAverageSales(new BigDecimal("0"));
|
||||
}else {
|
||||
} else {
|
||||
summaryVO.setAverageSales(summaryVO.getTotalSales().divide(new BigDecimal(summaryVO.getPaymentsNumber()), 2, RoundingMode.DOWN));
|
||||
}
|
||||
//用户数
|
||||
Tuple count = tbShopUserRepository.searchByCount(shopId.toString());
|
||||
summaryVO.setTotalUser(count==null?0L:count.get(0, Long.class));
|
||||
summaryVO.setTotalUser(count == null ? 0L : count.get(0, Long.class));
|
||||
//支付笔数柱形图
|
||||
List<Object[]> objects = shopUserDutyRepository.sumByDateOrderNum(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountDateVO> countDateList = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
for (Object[] o : objects) {
|
||||
CountDateVO countDateVO = new CountDateVO();
|
||||
countDateVO.setCount((BigDecimal) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
|
|
@ -67,7 +76,7 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
Map<String, CountDateVO> dataMap = new HashMap<>();
|
||||
for (CountDateVO entry : countDateList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigDecimal countOrder = entry.getCount();
|
||||
BigDecimal countOrder = entry.getCount();
|
||||
dataMap.put(tradeDay, new CountDateVO(tradeDay, countOrder));
|
||||
}
|
||||
// 获取今天的日期
|
||||
|
|
@ -90,15 +99,15 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
// 将SumDateVO对象添加到列表中
|
||||
countDateLists.add(countDateVO);
|
||||
}
|
||||
countDateLists.sort((a,b)->a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
countDateLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
summaryVO.setCountDateList(countDateLists);
|
||||
//访问量
|
||||
Tuple tuple = tbTokenRepository.countByAccountId(shopId);
|
||||
summaryVO.setTotalVisits(tuple == null?0L:tuple.get(0, Long.class));
|
||||
summaryVO.setTotalVisits(tuple == null ? 0L : tuple.get(0, Long.class));
|
||||
//访问量柱状图
|
||||
List<Object[]> objectsVisits = tbTokenRepository.countByMonth(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountVisitsVO> visitsList = new ArrayList<>();
|
||||
for (Object[] o :objectsVisits){
|
||||
for (Object[] o : objectsVisits) {
|
||||
CountVisitsVO countDateVO = new CountVisitsVO();
|
||||
countDateVO.setCount((BigInteger) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
|
|
@ -108,7 +117,7 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
Map<String, CountVisitsVO> dataVisitsMap = new HashMap<>();
|
||||
for (CountVisitsVO entry : visitsList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigInteger countOrder = entry.getCount();
|
||||
BigInteger countOrder = entry.getCount();
|
||||
dataVisitsMap.put(tradeDay, new CountVisitsVO(tradeDay, countOrder));
|
||||
}
|
||||
// 转换为字符串
|
||||
|
|
@ -127,25 +136,25 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
// 将SumDateVO对象添加到列表中
|
||||
countVisitsLists.add(countDateVO);
|
||||
}
|
||||
countVisitsLists.sort((a,b)->a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
countVisitsLists.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
summaryVO.setVisitsCountList(countVisitsLists);
|
||||
return summaryVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryDate(Integer shopId, Integer day) {
|
||||
public Map<String, Object> selectSummaryDate(Integer shopId, Integer day) {
|
||||
Date startTime = new Date();
|
||||
Date endTime = new Date();
|
||||
if (day == 7){
|
||||
if (day == 7) {
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 30){
|
||||
} else if (day == 30) {
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 360){
|
||||
} else if (day == 360) {
|
||||
startTime = DateUtil.getBeginDayOfYear();
|
||||
endTime = DateUtil.getDateOneYearAgo();
|
||||
}else if (day ==1){
|
||||
} else if (day == 1) {
|
||||
startTime = DateUtil.getDayBegin();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}
|
||||
|
|
@ -153,7 +162,7 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
Tuple tuple = shopUserDutyDetailRepository.searchByDutyIdSum(shopId, startTime, endTime);
|
||||
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyGroup(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountDateVO> numList = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
for (Object[] o : objects) {
|
||||
CountDateVO countDateVO = new CountDateVO();
|
||||
countDateVO.setCount((BigDecimal) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
|
|
@ -161,80 +170,81 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
}
|
||||
List<Object[]> objects1 = shopUserDutyDetailRepository.searchByGroup(shopId, DateUtil.getDate30DaysAgo(), DateUtil.getDayEnd());
|
||||
List<CountDateVO> amountList = new ArrayList<>();
|
||||
for (Object[] o :objects1) {
|
||||
for (Object[] o : objects1) {
|
||||
CountDateVO countDateVO = new CountDateVO();
|
||||
countDateVO.setCount((BigDecimal) o[0]);
|
||||
countDateVO.setTradeDay((String) o[1]);
|
||||
amountList.add(countDateVO);
|
||||
}
|
||||
map.put("productCount",tuple == null? 0:tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum",tuple == null?0:tuple.get(1, BigDecimal.class));
|
||||
map.put("numList",numList);
|
||||
map.put("amountList",amountList);
|
||||
map.put("productCount", tuple == null ? 0 : tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum", tuple == null ? 0 : tuple.get(1, BigDecimal.class));
|
||||
map.put("numList", numList);
|
||||
map.put("amountList", amountList);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryProduct(Integer shopId, Integer day,Integer currentPage, Integer currentSize){
|
||||
public Map<String, Object> selectSummaryProduct(Integer shopId, Integer day, Integer currentPage, Integer currentSize) {
|
||||
//根据时间商品排行
|
||||
currentPage = (currentPage - 1) * currentSize;
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
Date startTime ;
|
||||
Date endTime ;
|
||||
if (day == 7){
|
||||
Date startTime;
|
||||
Date endTime;
|
||||
if (day == 7) {
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 30){
|
||||
} else if (day == 30) {
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 360){
|
||||
} else if (day == 360) {
|
||||
startTime = DateUtil.getBeginDayOfYear();
|
||||
endTime = DateUtil.getEndDayOfYear();
|
||||
}else if (day ==1){
|
||||
} else if (day == 1) {
|
||||
startTime = DateUtil.getDayBegin();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
} else {
|
||||
throw new BadRequestException("日期有误");
|
||||
}
|
||||
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId,startTime,endTime,currentPage,currentSize);
|
||||
List<Object[]> objects = shopUserDutyDetailRepository.searchByDutyId(shopId, startTime, endTime, currentPage, currentSize);
|
||||
List<ProductExtVO> list = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
for (Object[] o : objects) {
|
||||
ProductExtVO productVO = new ProductExtVO();
|
||||
productVO.setProductId((BigInteger) o[0]);
|
||||
productVO.setProductName((String) o[1]);
|
||||
productVO.setProductNum((BigDecimal)o[2]);
|
||||
productVO.setAmount((BigDecimal)o[3]);
|
||||
productVO.setProductNum((BigDecimal) o[2]);
|
||||
productVO.setAmount((BigDecimal) o[3]);
|
||||
list.add(productVO);
|
||||
}
|
||||
//汇总数据
|
||||
Tuple tuple = shopUserDutyDetailRepository.searchByDutyIdSum(shopId, startTime, endTime);
|
||||
//分页数据
|
||||
Tuple tuple1 = shopUserDutyDetailRepository.searchCount(shopId, startTime, endTime);
|
||||
map.put("productCount",tuple == null? 0:tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum",tuple == null? 0:tuple.get(1, BigDecimal.class));
|
||||
map.put("totalProduct",list);
|
||||
map.put("total",tuple1 == null?0:tuple1.get(0, BigInteger.class));
|
||||
map.put("productCount", tuple == null ? 0 : tuple.get(0, BigDecimal.class));
|
||||
map.put("productSum", tuple == null ? 0 : tuple.get(1, BigDecimal.class));
|
||||
map.put("totalProduct", list);
|
||||
map.put("total", tuple1 == null ? 0 : tuple1.get(0, BigInteger.class));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryAmount(Integer shopId, Integer day){
|
||||
public Map<String, Object> selectSummaryAmount(Integer shopId, Integer day) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
Date startTime ;
|
||||
Date endTime ;
|
||||
if (day == 7){
|
||||
Date startTime;
|
||||
Date endTime;
|
||||
if (day == 7) {
|
||||
startTime = DateUtil.getDate7DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else if (day == 30){
|
||||
} else if (day == 30) {
|
||||
startTime = DateUtil.getDate30DaysAgo();
|
||||
endTime = DateUtil.getDayEnd();
|
||||
}else {
|
||||
} else {
|
||||
throw new BadRequestException("日期有误");
|
||||
}
|
||||
|
||||
List<Object[]> objects = shopUserDutyRepository.sumByDate(shopId, startTime, endTime);
|
||||
//根据时间的销量
|
||||
List<SumDateVO> sumDateVOList = new ArrayList<>();
|
||||
for (Object[] o :objects) {
|
||||
for (Object[] o : objects) {
|
||||
SumDateVO sumDateVO = new SumDateVO();
|
||||
sumDateVO.setAmount((BigDecimal) o[0]);
|
||||
sumDateVO.setTradeDay((String) o[1]);
|
||||
|
|
@ -244,7 +254,7 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
Map<String, SumDateVO> dataMap = new HashMap<>();
|
||||
for (SumDateVO entry : sumDateVOList) {
|
||||
String tradeDay = entry.getTradeDay();
|
||||
BigDecimal amount = entry.getAmount();
|
||||
BigDecimal amount = entry.getAmount();
|
||||
dataMap.put(tradeDay, new SumDateVO(tradeDay, amount));
|
||||
}
|
||||
// 获取今天的日期
|
||||
|
|
@ -269,8 +279,8 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
}
|
||||
|
||||
|
||||
sumDateList.sort((a,b)->a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
map.put("total",sumDateList);
|
||||
sumDateList.sort((a, b) -> a.getTradeDay().compareTo(b.getTradeDay()));
|
||||
map.put("total", sumDateList);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
@ -278,40 +288,137 @@ public class SummaryServiceImpl implements SummaryService {
|
|||
public Map<String, Object> selectSummaryToday(Integer shopId) {
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
Tuple tuple = shopUserDutyRepository.sumByShopIdToday(shopId, DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
map.put("paymentsNumberToday", tuple == null?0L : tuple.get(0, Long.class));
|
||||
map.put("totalSalesToday", tuple == null? new BigDecimal("0") : tuple.get(1, BigDecimal.class));
|
||||
map.put("paymentsNumberToday", tuple == null ? 0L : tuple.get(0, Long.class));
|
||||
map.put("totalSalesToday", tuple == null ? new BigDecimal("0") : tuple.get(1, BigDecimal.class));
|
||||
Tuple tuple1 = tbShopUserRepository.searchByCountToday(shopId.toString(), DateUtil.getTodayStartTimestamp(), DateUtil.getTodayEndTimestamp());
|
||||
map.put("userToday", tuple1.get(0, Long.class));
|
||||
Tuple tupleToday = tbTokenRepository.countByAccountId(shopId, DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
map.put("totalVisitsToday",tupleToday == null?0:tupleToday.get(0,Long.class));
|
||||
map.put("totalVisitsToday", tupleToday == null ? 0 : tupleToday.get(0, Long.class));
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> selectSummaryPayType(Integer shopId, Integer day){
|
||||
Long startTime ;
|
||||
Long endTime ;
|
||||
if (day == 7){
|
||||
public Map<String, Object> selectSummaryPayType(Integer shopId, Integer day) {
|
||||
Long startTime;
|
||||
Long endTime;
|
||||
if (day == 7) {
|
||||
startTime = DateUtil.getSevenDaysAgoInMilliseconds();
|
||||
endTime = DateUtil.getTodayEndTimestamp();
|
||||
}else if (day == 30){
|
||||
} else if (day == 30) {
|
||||
startTime = DateUtil.getThirtyDaysAgoInMilliseconds();
|
||||
endTime = DateUtil.getTodayEndTimestamp();
|
||||
}else if (day == 360){
|
||||
} else if (day == 360) {
|
||||
startTime = DateUtil.getBeginningOfYearInMilliseconds();
|
||||
endTime = DateUtil.getEndOfYearInMilliseconds();
|
||||
}else {
|
||||
} else {
|
||||
throw new BadRequestException("日期有误");
|
||||
}
|
||||
List<Object[]> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString(),startTime,endTime);
|
||||
List<Object[]> countPayTypeMappings = tbOrderInfoRepository.countByShopId(shopId.toString(), startTime, endTime);
|
||||
List<CountPayTypeVO> countPayTypeVOList = new ArrayList<>();
|
||||
for (Object[] o :countPayTypeMappings) {
|
||||
for (Object[] o : countPayTypeMappings) {
|
||||
CountPayTypeVO countPayTypeVO = new CountPayTypeVO();
|
||||
countPayTypeVO.setCount((BigInteger) o[0]);
|
||||
countPayTypeVO.setPayType(PayTypeEnum.getCodeByName((String) o[1]));
|
||||
countPayTypeVOList.add(countPayTypeVO);
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("countPayType",countPayTypeVOList);
|
||||
map.put("countPayType", countPayTypeVOList);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Page<T> selectSummaryByDay(Integer type, String shopId, Long startTime, Long endTime, 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();
|
||||
}
|
||||
return (Page<T>) tbOrderInfoRepository.queryTbOrderPayCountByDay(shopId, startTime, endTime, 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));
|
||||
}
|
||||
return (Page<T>) detailRepository.queryTbOrderSalesCountByDay(Integer.valueOf(shopId), start, end, 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 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
public class TbOrderPayCountByDayVo {
|
||||
|
||||
private String tradeDay;
|
||||
private Object scanCode;
|
||||
private Object wxLite;
|
||||
private Object cash;
|
||||
private BigDecimal total;
|
||||
|
||||
public String getTradeDay() {
|
||||
return tradeDay;
|
||||
}
|
||||
|
||||
public void setTradeDay(String tradeDay) {
|
||||
this.tradeDay = tradeDay;
|
||||
}
|
||||
|
||||
public Object getScanCode() {
|
||||
return scanCode;
|
||||
}
|
||||
|
||||
public void setScanCode(Object scanCode) {
|
||||
this.scanCode = scanCode;
|
||||
}
|
||||
|
||||
public Object getWxLite() {
|
||||
return wxLite;
|
||||
}
|
||||
|
||||
public void setWxLite(Object wxLite) {
|
||||
this.wxLite = wxLite;
|
||||
}
|
||||
|
||||
public Object getCash() {
|
||||
return cash;
|
||||
}
|
||||
|
||||
public void setCash(Object cash) {
|
||||
this.cash = cash;
|
||||
}
|
||||
|
||||
public BigDecimal getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(BigDecimal total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public TbOrderPayCountByDayVo(String tradeDay, Object scanCode, Object wxLite, Object cash, BigDecimal total) {
|
||||
this.tradeDay = tradeDay;
|
||||
this.scanCode = scanCode;
|
||||
this.wxLite = wxLite;
|
||||
this.cash = cash;
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,10 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
|
||||
public class TbOrderPayCountVo{
|
||||
private String icon;
|
||||
private String payType;
|
||||
private BigDecimal payAmount;
|
||||
private Object payAmount;
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
|
|
@ -25,28 +22,16 @@ public class TbOrderPayCountVo{
|
|||
this.payType = payType;
|
||||
}
|
||||
|
||||
public BigDecimal getPayAmount() {
|
||||
public Object getPayAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
|
||||
public void setPayAmount(BigDecimal payAmount) {
|
||||
public void setPayAmount(Object payAmount) {
|
||||
this.payAmount = payAmount;
|
||||
}
|
||||
|
||||
public TbOrderPayCountVo() {
|
||||
}
|
||||
|
||||
public TbOrderPayCountVo(String payType, BigDecimal payAmount) {
|
||||
public TbOrderPayCountVo(String payType, Object payAmount) {
|
||||
this.payType = payType;
|
||||
this.payAmount = payAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringJoiner(", ", TbOrderPayCountVo.class.getSimpleName() + "[", "]")
|
||||
.add("icon='" + icon + "'")
|
||||
.add("payType='" + payType + "'")
|
||||
.add("payAmount=" + payAmount)
|
||||
.toString();
|
||||
this.payAmount=payAmount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
|
||||
public class TbOrderSalesCountByDayVo {
|
||||
|
||||
private String productName;
|
||||
private String productSkuName;
|
||||
|
||||
private Long salesNum;
|
||||
private Long refNum;
|
||||
private Long num;
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getProductSkuName() {
|
||||
return productSkuName;
|
||||
}
|
||||
|
||||
public void setProductSkuName(String productSkuName) {
|
||||
this.productSkuName = productSkuName;
|
||||
}
|
||||
|
||||
public Long getSalesNum() {
|
||||
return salesNum;
|
||||
}
|
||||
|
||||
public void setSalesNum(Long salesNum) {
|
||||
this.salesNum = salesNum;
|
||||
}
|
||||
|
||||
public Long getRefNum() {
|
||||
return refNum;
|
||||
}
|
||||
|
||||
public void setRefNum(Long refNum) {
|
||||
this.refNum = refNum;
|
||||
}
|
||||
|
||||
public Long getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(Long num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public TbOrderSalesCountByDayVo(String productName, String productSkuName, Long salesNum, Long refNum, Long num) {
|
||||
this.productName = productName;
|
||||
this.productSkuName = productSkuName;
|
||||
this.salesNum = salesNum;
|
||||
this.refNum = refNum;
|
||||
this.num = num;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue