异常响应
订单管理 查询支付统计
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package cn.ysk.cashier.config;
|
||||
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.utils.FastJsonUtils;
|
||||
import cn.ysk.cashier.utils.SpringContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -11,8 +10,6 @@ import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -26,8 +23,6 @@ import java.util.Map;
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AppApiMethodAspect {
|
||||
|
||||
// @Pointcut("execution(public * cn.ysk.cashier.controller.*.*(..))")
|
||||
@Pointcut("execution(public * (" +
|
||||
"cn.ysk.cashier.controller.* " +
|
||||
"|| cn.ysk.cashier.controller.*.* " +
|
||||
@@ -62,13 +57,7 @@ public class AppApiMethodAspect {
|
||||
FastJsonUtils.toJSONString(result)
|
||||
);
|
||||
return result;
|
||||
} catch (BadRequestException e) {
|
||||
log.error("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
|
||||
, req.getMethod(), req.getRequestURL(), req.getRemoteAddr(),
|
||||
FastJsonUtils.toJSONString(params),
|
||||
e);
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
|
||||
} catch (Throwable e) {
|
||||
} catch (RuntimeException e) {
|
||||
if (StringUtils.isBlank(e.getMessage())) {
|
||||
log.error("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
|
||||
, req.getMethod(), req.getRequestURL(), req.getRemoteAddr(),
|
||||
@@ -80,8 +69,19 @@ public class AppApiMethodAspect {
|
||||
FastJsonUtils.toJSONString(params),
|
||||
e.getMessage());
|
||||
}
|
||||
ResponseEntity<String> body = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
|
||||
return body;
|
||||
throw e;
|
||||
} catch (Error e) {
|
||||
log.error("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
|
||||
, req.getMethod(), req.getRequestURL(), req.getRemoteAddr(),
|
||||
FastJsonUtils.toJSONString(params),
|
||||
e);
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
log.error("\n>>>>>>{} {}\n>>>>>>{}\n>>>>>>Request: {}\n>>>>>>Exception: {}"
|
||||
, req.getMethod(), req.getRequestURL(), req.getRemoteAddr(),
|
||||
FastJsonUtils.toJSONString(params),
|
||||
e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,22 @@ 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.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
@@ -57,6 +61,13 @@ public class TbOrderInfoController {
|
||||
return new ResponseEntity<>(tbOrderInfoService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/payCount")
|
||||
@Log("通过shopId查询支付统计")
|
||||
@ApiOperation("通过shopId查询支付统计")
|
||||
public List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId){
|
||||
return tbOrderInfoService.queryTbOrderPayCount(shopId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Log("通过Id查询订单")
|
||||
@ApiOperation("通过Id查询订单")
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.TbOrderInfo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author lyf
|
||||
* @date 2024-03-02
|
||||
**/
|
||||
public interface TbOrderPayCountRepository extends JpaRepository<TbOrderInfo, Integer> {
|
||||
|
||||
@Query("SELECT new cn.ysk.cashier.vo.TbOrderPayCountVo(info.payType, SUM(info.amount)) " +
|
||||
"FROM TbOrderInfo info " +
|
||||
"WHERE info.shopId = :shopId " +
|
||||
"GROUP BY info.payType")
|
||||
List<TbOrderPayCountVo> queryTbOrderPayCount(@Param("shopId")String shopId);
|
||||
}
|
||||
@@ -22,9 +22,11 @@ import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderPayCountRepository;
|
||||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.TbOrderInfoVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -38,9 +40,9 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
* @website https://eladmin.vip
|
||||
* @description 服务实现
|
||||
* @author lyf
|
||||
* @date 2024-03-02
|
||||
**/
|
||||
@Service
|
||||
@@ -51,6 +53,9 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||
private final TbOrderInfoMapper tbOrderInfoMapper;
|
||||
|
||||
private final TbOrderDetailRepository tbOrderDetailRepository;
|
||||
|
||||
private final TbOrderPayCountRepository tbOrderPayCountRepository;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(TbOrderInfoQueryCriteria criteria, Pageable pageable) {
|
||||
Page<TbOrderInfo> page = tbOrderInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||
@@ -65,6 +70,11 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||
return PageUtil.toPage(orderInfoVoList, page.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId) {
|
||||
return tbOrderPayCountRepository.queryTbOrderPayCount(shopId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderInfoDto> queryAll(TbOrderInfoQueryCriteria criteria) {
|
||||
List<TbOrderInfoDto> dto = tbOrderInfoMapper.toDto(tbOrderInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
||||
|
||||
@@ -15,14 +15,16 @@
|
||||
*/
|
||||
package cn.ysk.cashier.service.order;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
@@ -40,6 +42,13 @@ public interface TbOrderInfoService {
|
||||
*/
|
||||
Map<String,Object> queryAll(TbOrderInfoQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 根据支付类型统计
|
||||
* @param shopId shopId
|
||||
* @return TbOrderPayCountVo
|
||||
*/
|
||||
List<TbOrderPayCountVo> queryTbOrderPayCount(String shopId);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package cn.ysk.cashier.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
@Data
|
||||
public class TbOrderPayCountVo{
|
||||
private String payType;
|
||||
private BigDecimal payAmount;
|
||||
|
||||
// 构造函数,参数名需要与查询中的别名一致
|
||||
public TbOrderPayCountVo(String payType, BigDecimal payAmount) {
|
||||
this.payType = payType;
|
||||
this.payAmount = payAmount;
|
||||
}
|
||||
|
||||
// Getter和Setter方法
|
||||
public String getPayType() {
|
||||
return payType;
|
||||
}
|
||||
|
||||
public void setPayType(String payType) {
|
||||
this.payType = payType;
|
||||
}
|
||||
|
||||
public BigDecimal getPayAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
|
||||
public void setPayAmount(BigDecimal payAmount) {
|
||||
this.payAmount = payAmount;
|
||||
}
|
||||
|
||||
// toString方法,用于简单的打印信息,可根据需要添加
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TbOrderPayCountVo{" +
|
||||
"payType='" + payType + '\'' +
|
||||
", payAmount=" + payAmount +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user