统计订单总金额
This commit is contained in:
@@ -207,6 +207,12 @@ public class ShopOrderController extends BaseController {
|
||||
return fail("修复失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "统计订单总金额")
|
||||
@GetMapping("/total")
|
||||
public ApiResult<BigDecimal> total() {
|
||||
return success(shopOrderService.total());
|
||||
}
|
||||
|
||||
@Schema(description = "异步通知")
|
||||
@PostMapping("/notify/{tenantId}")
|
||||
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.shop.entity.ShopOrder;
|
||||
import com.gxwebsoft.shop.param.ShopOrderParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -41,4 +43,13 @@ public interface ShopOrderMapper extends BaseMapper<ShopOrder> {
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
void updateByOutTradeNo(@Param("param") ShopOrder order);
|
||||
|
||||
/**
|
||||
* 统计订单总金额
|
||||
* 只统计已支付的订单(pay_status = 1)且未删除的订单(deleted = 0)
|
||||
*
|
||||
* @return 订单总金额
|
||||
*/
|
||||
@Select("SELECT COALESCE(SUM(pay_price), 0) FROM shop_order WHERE pay_status = 1 AND deleted = 0 AND pay_price IS NOT NULL")
|
||||
BigDecimal selectTotalAmount();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.shop.entity.ShopOrder;
|
||||
import com.gxwebsoft.shop.param.ShopOrderParam;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,4 +48,11 @@ public interface ShopOrderService extends IService<ShopOrder> {
|
||||
Boolean queryOrderByOutTradeNo(ShopOrder shopOrder);
|
||||
|
||||
void updateByOutTradeNo(ShopOrder order);
|
||||
|
||||
/**
|
||||
* 统计订单总金额
|
||||
*
|
||||
* @return 订单总金额
|
||||
*/
|
||||
BigDecimal total();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.config.CertificateProperties;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
@@ -647,4 +648,23 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal total() {
|
||||
try {
|
||||
// 使用数据库聚合查询统计订单总金额,性能更高
|
||||
BigDecimal total = baseMapper.selectTotalAmount();
|
||||
|
||||
if (total == null) {
|
||||
total = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
log.info("统计订单总金额完成,总金额:{}", total);
|
||||
return total;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("统计订单总金额失败", e);
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user