支付统计 增加时间筛选

This commit is contained in:
wangw 2024-04-03 15:26:47 +08:00
parent 2cea30c8a0
commit 34610aace9
6 changed files with 44 additions and 17 deletions

View File

@ -19,7 +19,6 @@ import cn.hutool.core.lang.Assert;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig; import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import io.lettuce.core.RedisClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,8 +26,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties; import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
@ -39,13 +36,13 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer;
import reactor.util.annotation.Nullable; import reactor.util.annotation.Nullable;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;

View File

@ -18,13 +18,13 @@ package cn.ysk.cashier.controller.order;
import cn.ysk.cashier.annotation.Log; import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.order.TbOrderInfoDto; import cn.ysk.cashier.dto.order.TbOrderInfoDto;
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria; import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
import cn.ysk.cashier.pojo.order.TbOrderInfo; import cn.ysk.cashier.pojo.order.TbOrderInfo;
import cn.ysk.cashier.service.order.TbOrderInfoService; import cn.ysk.cashier.service.order.TbOrderInfoService;
import cn.ysk.cashier.vo.TbOrderPayCountVo; import cn.ysk.cashier.vo.TbOrderPayCountVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -61,11 +61,11 @@ public class TbOrderInfoController {
return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK); return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK);
} }
@GetMapping("/payCount") @PostMapping("/payCount")
@Log("通过shopId查询支付统计") @Log("通过shopId查询支付统计")
@ApiOperation("通过shopId查询支付统计") @ApiOperation("通过shopId查询支付统计")
public List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId){ public List<TbOrderPayCountVo> queryTbOrderPayCount(@RequestBody TbPayCountQueryCriteria criteria){
return tbOrderInfoService.queryTbOrderPayCount(shopId); return tbOrderInfoService.queryTbOrderPayCount(criteria);
} }
@GetMapping("/{id}") @GetMapping("/{id}")

View File

@ -0,0 +1,11 @@
package cn.ysk.cashier.dto.order;
import lombok.Data;
import java.util.List;
@Data
public class TbPayCountQueryCriteria {
private String shopId;
private List<Long> createdAt;
}

View File

@ -32,19 +32,21 @@ import java.util.List;
* @date 2024-03-02 * @date 2024-03-02
**/ **/
public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Integer>, JpaSpecificationExecutor<TbOrderInfo> { public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Integer>, JpaSpecificationExecutor<TbOrderInfo> {
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(info.payType, SUM(info.orderAmount)) " + @Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(info.payType, SUM(info.orderAmount)) " +
"FROM TbOrderInfo info " + "FROM TbOrderInfo info " +
"WHERE info.shopId = :shopId " + "WHERE info.shopId = :shopId " +
"AND info.createdAt>:start AND info.createdAt<:end " +
"AND ((info.status = 'closed') OR (info.status = 'refund' AND info.orderType != 'return')) " + "AND ((info.status = 'closed') OR (info.status = 'refund' AND info.orderType != 'return')) " +
"GROUP BY info.payType") "GROUP BY info.payType")
List<TbOrderPayCountVo> queryTbOrderPayCount(@Param("shopId")String shopId); List<TbOrderPayCountVo> queryTbOrderPayCount(@Param("shopId")String shopId, @Param("start") Long start, @Param("end") Long end);
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo('refund', SUM(info.orderAmount)) " + @Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo('refund', SUM(info.orderAmount)) " +
"FROM TbOrderInfo info " + "FROM TbOrderInfo info " +
"WHERE info.shopId = :shopId " + "WHERE info.shopId = :shopId " +
"AND info.status = 'refund' AND info.orderType = 'return'") "AND info.status = 'refund' AND info.orderType = 'return' " +
TbOrderPayCountVo queryTbOrderRefund(@Param("shopId")String shopId); "AND info.createdAt>:start AND info.createdAt<:end")
TbOrderPayCountVo queryTbOrderRefund(@Param("shopId")String shopId, @Param("start") Long start, @Param("end") Long end);
@Query(value = "SELECT COUNT(1) ,pay_type AS payType FROM tb_order_info Where shop_id = :shopId AND " + @Query(value = "SELECT COUNT(1) ,pay_type AS payType FROM tb_order_info Where shop_id = :shopId AND " +
" created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type" ,nativeQuery = true) " created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type" ,nativeQuery = true)

View File

@ -17,6 +17,7 @@ package cn.ysk.cashier.service.impl.order;
import cn.ysk.cashier.dto.order.TbOrderInfoDto; import cn.ysk.cashier.dto.order.TbOrderInfoDto;
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria; import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
import cn.ysk.cashier.mapper.order.TbOrderInfoMapper; import cn.ysk.cashier.mapper.order.TbOrderInfoMapper;
import cn.ysk.cashier.pojo.TbShopPayType; import cn.ysk.cashier.pojo.TbShopPayType;
import cn.ysk.cashier.pojo.order.TbOrderDetail; import cn.ysk.cashier.pojo.order.TbOrderDetail;
@ -35,11 +36,13 @@ import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.*; import org.springframework.data.domain.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -101,12 +104,25 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
} }
@Override @Override
public List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId) { public List<TbOrderPayCountVo> queryTbOrderPayCount(TbPayCountQueryCriteria criteria) {
List<TbOrderPayCountVo> result = new ArrayList<>(); List<TbOrderPayCountVo> result = new ArrayList<>();
List<TbOrderPayCountVo> payCountVoList = tbOrderInfoRepository.queryTbOrderPayCount(shopId); List<Long> createdAt = criteria.getCreatedAt();
// 指定时间例如2024年1月1日 00:00:00
Long start = 1704038400000L;
Long end = Instant.now().toEpochMilli();
if (!CollectionUtils.isEmpty(createdAt)) {
if (createdAt.get(0) > createdAt.get(1)) {
start=createdAt.get(1);
end=createdAt.get(0);
}else {
start=createdAt.get(0);
end=createdAt.get(1);
}
}
List<TbOrderPayCountVo> payCountVoList = tbOrderInfoRepository.queryTbOrderPayCount(criteria.getShopId(), start, end);
for (TbOrderPayCountVo payCount : payCountVoList) { for (TbOrderPayCountVo payCount : payCountVoList) {
if (StringUtils.isNotBlank(payCount.getPayType())) { if (StringUtils.isNotBlank(payCount.getPayType())) {
TbShopPayType byPayType = payTypeRepository.findByPayType(payCount.getPayType(), shopId); TbShopPayType byPayType = payTypeRepository.findByPayType(payCount.getPayType(), criteria.getShopId());
if (byPayType != null) { if (byPayType != null) {
payCount.setPayType(byPayType.getPayName()); payCount.setPayType(byPayType.getPayName());
payCount.setIcon(byPayType.getIcon()); payCount.setIcon(byPayType.getIcon());
@ -118,7 +134,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
result.add(payCount); result.add(payCount);
} }
} }
TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(shopId); TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(criteria.getShopId(), start, end);
if (payRufund != null) { if (payRufund != null) {
payRufund.setPayType("退单"); payRufund.setPayType("退单");
payRufund.setIcon("https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240319/5741608662244b878762c61bb37c95c9.png"); payRufund.setIcon("https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240319/5741608662244b878762c61bb37c95c9.png");

View File

@ -17,6 +17,7 @@ package cn.ysk.cashier.service.order;
import cn.ysk.cashier.dto.order.TbOrderInfoDto; import cn.ysk.cashier.dto.order.TbOrderInfoDto;
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria; import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
import cn.ysk.cashier.pojo.order.TbOrderInfo; import cn.ysk.cashier.pojo.order.TbOrderInfo;
import cn.ysk.cashier.vo.TbOrderPayCountVo; import cn.ysk.cashier.vo.TbOrderPayCountVo;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -46,7 +47,7 @@ public interface TbOrderInfoService {
* @param shopId shopId * @param shopId shopId
* @return TbOrderPayCountVo * @return TbOrderPayCountVo
*/ */
List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId); List<TbOrderPayCountVo> queryTbOrderPayCount(TbPayCountQueryCriteria shopId);
/** /**
* 查询所有数据不分页 * 查询所有数据不分页