统计订单总金额
This commit is contained in:
@@ -18,6 +18,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -74,4 +75,17 @@ public class BszxOrderController extends BaseController {
|
||||
return success(result);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "统计订单总金额")
|
||||
@GetMapping("/total")
|
||||
public ApiResult<BigDecimal> total() {
|
||||
try {
|
||||
BigDecimal totalAmount = bszxPayService.total();
|
||||
return success(totalAmount);
|
||||
} catch (Exception e) {
|
||||
// 异常时返回0,保持接口稳定性
|
||||
return success(BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.bszx.entity.BszxPay;
|
||||
import com.gxwebsoft.bszx.param.BszxPayParam;
|
||||
import com.gxwebsoft.project.entity.Project;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
@@ -48,4 +47,11 @@ public interface BszxPayService extends IService<BszxPay> {
|
||||
String generatePayCert(Integer id) throws Exception;
|
||||
|
||||
BigDecimal sumMoney(LambdaQueryWrapper<BszxPay> between);
|
||||
|
||||
/**
|
||||
* 统计捐款总金额
|
||||
*
|
||||
* @return 捐款总金额
|
||||
*/
|
||||
BigDecimal total();
|
||||
}
|
||||
|
||||
@@ -147,4 +147,23 @@ public class BszxPayServiceImpl extends ServiceImpl<BszxPayMapper, BszxPay> impl
|
||||
public BigDecimal sumMoney(LambdaQueryWrapper<BszxPay> wrapper) {
|
||||
return baseMapper.selectSumMoney(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal total() {
|
||||
try {
|
||||
// 使用数据库聚合查询统计捐款总金额,性能更高
|
||||
LambdaQueryWrapper<BszxPay> wrapper = new LambdaQueryWrapper<>();
|
||||
BigDecimal total = baseMapper.selectSumMoney(wrapper);
|
||||
|
||||
if (total == null) {
|
||||
total = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return total;
|
||||
|
||||
} catch (Exception e) {
|
||||
// 异常时返回0,确保接口稳定性
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
src/main/java/com/gxwebsoft/shop/enums/OrderStatusEnum.java
Normal file
32
src/main/java/com/gxwebsoft/shop/enums/OrderStatusEnum.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.gxwebsoft.shop.enums;
|
||||
|
||||
/**
|
||||
* 订单状态枚举
|
||||
*/
|
||||
public enum OrderStatusEnum {
|
||||
ALL(-1, "全部"),
|
||||
WAIT_PAY(0, "待支付"),
|
||||
WAIT_DELIVERY(1, "待发货"),
|
||||
WAIT_CONFIRM(2, "待核销"),
|
||||
WAIT_RECEIVE(3, "待收货"),
|
||||
WAIT_EVALUATE(4, "待评价"),
|
||||
COMPLETED(5, "已完成"),
|
||||
REFUNDED(6, "已退款"),
|
||||
DELETED(7, "已删除");
|
||||
|
||||
private final Integer code;
|
||||
private final String desc;
|
||||
|
||||
OrderStatusEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
@@ -249,4 +249,7 @@ public class ShopOrderParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean hasTakeGift;
|
||||
|
||||
@Schema(description = "订单状态筛选:-1全部,0待支付,1待发货,2待核销,3待收货,4待评价,5已完成,6已退款,7已删除")
|
||||
private Integer statusFilter;
|
||||
|
||||
}
|
||||
|
||||
56
src/test/java/com/gxwebsoft/bszx/BszxOrderTotalTest.java
Normal file
56
src/test/java/com/gxwebsoft/bszx/BszxOrderTotalTest.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.gxwebsoft.bszx;
|
||||
|
||||
import com.gxwebsoft.bszx.service.BszxPayService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 百色中学订单总金额统计测试
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-07-31
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
public class BszxOrderTotalTest {
|
||||
|
||||
@Resource
|
||||
private BszxPayService bszxPayService;
|
||||
|
||||
@Test
|
||||
void testBszxOrderTotal() {
|
||||
// 测试百色中学订单总金额统计
|
||||
BigDecimal total = bszxPayService.total();
|
||||
|
||||
// 验证返回值不为null
|
||||
assertNotNull(total, "百色中学订单总金额不应该为null");
|
||||
|
||||
// 验证返回值大于等于0
|
||||
assertTrue(total.compareTo(BigDecimal.ZERO) >= 0, "百色中学订单总金额应该大于等于0");
|
||||
|
||||
System.out.println("百色中学订单总金额统计结果:" + total);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBszxOrderTotalPerformance() {
|
||||
// 测试性能
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
BigDecimal total = bszxPayService.total();
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long duration = endTime - startTime;
|
||||
|
||||
System.out.println("百色中学订单总金额统计耗时:" + duration + "ms");
|
||||
System.out.println("统计结果:" + total);
|
||||
|
||||
// 验证查询时间在合理范围内(小于5秒)
|
||||
assertTrue(duration < 5000, "查询时间应该在5秒以内");
|
||||
}
|
||||
}
|
||||
56
src/test/java/com/gxwebsoft/shop/OrderTotalTest.java
Normal file
56
src/test/java/com/gxwebsoft/shop/OrderTotalTest.java
Normal file
@@ -0,0 +1,56 @@
|
||||
package com.gxwebsoft.shop;
|
||||
|
||||
import com.gxwebsoft.shop.service.ShopOrderService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 订单总金额统计测试
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2025-07-30
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("test")
|
||||
public class OrderTotalTest {
|
||||
|
||||
@Resource
|
||||
private ShopOrderService shopOrderService;
|
||||
|
||||
@Test
|
||||
void testOrderTotal() {
|
||||
// 测试订单总金额统计
|
||||
BigDecimal total = shopOrderService.total();
|
||||
|
||||
// 验证返回值不为null
|
||||
assertNotNull(total, "订单总金额不应该为null");
|
||||
|
||||
// 验证返回值大于等于0
|
||||
assertTrue(total.compareTo(BigDecimal.ZERO) >= 0, "订单总金额应该大于等于0");
|
||||
|
||||
System.out.println("订单总金额统计结果:" + total);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOrderTotalPerformance() {
|
||||
// 测试性能
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
BigDecimal total = shopOrderService.total();
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long duration = endTime - startTime;
|
||||
|
||||
System.out.println("订单总金额统计耗时:" + duration + "ms");
|
||||
System.out.println("统计结果:" + total);
|
||||
|
||||
// 验证查询时间在合理范围内(小于5秒)
|
||||
assertTrue(duration < 5000, "查询时间应该在5秒以内");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user