支付统计 增加时间筛选
This commit is contained in:
parent
2cea30c8a0
commit
34610aace9
|
|
@ -19,7 +19,6 @@ import cn.hutool.core.lang.Assert;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.ParserConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import io.lettuce.core.RedisClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
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.ConditionalOnMissingBean;
|
||||
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.annotation.CachingConfigurerSupport;
|
||||
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.data.redis.cache.RedisCacheConfiguration;
|
||||
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.core.RedisOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import reactor.util.annotation.Nullable;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ package cn.ysk.cashier.controller.order;
|
|||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
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.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
|
@ -61,11 +61,11 @@ public class TbOrderInfoController {
|
|||
return new ResponseEntity<>(tbOrderInfoService.queryAllPage(criteria),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/payCount")
|
||||
@PostMapping("/payCount")
|
||||
@Log("通过shopId查询支付统计")
|
||||
@ApiOperation("通过shopId查询支付统计")
|
||||
public List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId){
|
||||
return tbOrderInfoService.queryTbOrderPayCount(shopId);
|
||||
public List<TbOrderPayCountVo> queryTbOrderPayCount(@RequestBody TbPayCountQueryCriteria criteria){
|
||||
return tbOrderInfoService.queryTbOrderPayCount(criteria);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -32,19 +32,21 @@ import java.util.List;
|
|||
* @date 2024-03-02
|
||||
**/
|
||||
public interface TbOrderInfoRepository extends JpaRepository<TbOrderInfo, Integer>, JpaSpecificationExecutor<TbOrderInfo> {
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(info.payType, SUM(info.orderAmount)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.createdAt>:start AND info.createdAt<:end " +
|
||||
"AND ((info.status = 'closed') OR (info.status = 'refund' AND info.orderType != 'return')) " +
|
||||
"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)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"AND info.status = 'refund' AND info.orderType = 'return'")
|
||||
TbOrderPayCountVo queryTbOrderRefund(@Param("shopId")String shopId);
|
||||
"AND info.status = 'refund' AND info.orderType = 'return' " +
|
||||
"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 " +
|
||||
" created_at BETWEEN :startTime AND :endTime AND status='closed'AND order_type <>'return' GROUP BY pay_type" ,nativeQuery = true)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package cn.ysk.cashier.service.impl.order;
|
|||
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
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.pojo.TbShopPayType;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
|
|
@ -35,11 +36,13 @@ import org.springframework.beans.BeanUtils;
|
|||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -101,12 +104,25 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId) {
|
||||
public List<TbOrderPayCountVo> queryTbOrderPayCount(TbPayCountQueryCriteria criteria) {
|
||||
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) {
|
||||
if (StringUtils.isNotBlank(payCount.getPayType())) {
|
||||
TbShopPayType byPayType = payTypeRepository.findByPayType(payCount.getPayType(), shopId);
|
||||
TbShopPayType byPayType = payTypeRepository.findByPayType(payCount.getPayType(), criteria.getShopId());
|
||||
if (byPayType != null) {
|
||||
payCount.setPayType(byPayType.getPayName());
|
||||
payCount.setIcon(byPayType.getIcon());
|
||||
|
|
@ -118,7 +134,7 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
|||
result.add(payCount);
|
||||
}
|
||||
}
|
||||
TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(shopId);
|
||||
TbOrderPayCountVo payRufund = tbOrderInfoRepository.queryTbOrderRefund(criteria.getShopId(), start, end);
|
||||
if (payRufund != null) {
|
||||
payRufund.setPayType("退单");
|
||||
payRufund.setIcon("https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240319/5741608662244b878762c61bb37c95c9.png");
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package cn.ysk.cashier.service.order;
|
|||
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
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.vo.TbOrderPayCountVo;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
|
@ -46,7 +47,7 @@ public interface TbOrderInfoService {
|
|||
* @param shopId shopId
|
||||
* @return TbOrderPayCountVo
|
||||
*/
|
||||
List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId);
|
||||
List<TbOrderPayCountVo> queryTbOrderPayCount(TbPayCountQueryCriteria shopId);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
|
|
|
|||
Loading…
Reference in New Issue