From 8bd52067aecd1ff1a755880ce7fc168a83936b3e Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Mon, 10 Mar 2025 17:16:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=86=99=E7=9C=9F?= =?UTF-8?q?=E9=A2=84=E7=BA=A6=E7=89=B9=E6=AE=8A=E4=BA=A7=E5=93=81=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/file/FileController.java | 2 +- .../controller/global/GlobalController.java | 136 ++++++++++++++++++ src/main/resources/application.yml | 2 +- 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/cultural/heritage/controller/global/GlobalController.java diff --git a/src/main/java/com/cultural/heritage/controller/file/FileController.java b/src/main/java/com/cultural/heritage/controller/file/FileController.java index 2af7b94..6b698cc 100644 --- a/src/main/java/com/cultural/heritage/controller/file/FileController.java +++ b/src/main/java/com/cultural/heritage/controller/file/FileController.java @@ -172,7 +172,7 @@ public class FileController { String fileSuffix = FileUtil.getSuffix(multipartFile.getOriginalFilename()); final long LIMIT = 30 * 1024 * 1024L; if (fileSize > LIMIT) { - throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件大小不能超过512K"); + throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件大小不能超过30MB"); } if (!Arrays.asList("jpeg", "jpg", "svg", "png", "webp", "JPG").contains(fileSuffix)) { throw new BusinessException(ErrorCode.PARAMS_ERROR, "文件类型错误"); diff --git a/src/main/java/com/cultural/heritage/controller/global/GlobalController.java b/src/main/java/com/cultural/heritage/controller/global/GlobalController.java new file mode 100644 index 0000000..5165650 --- /dev/null +++ b/src/main/java/com/cultural/heritage/controller/global/GlobalController.java @@ -0,0 +1,136 @@ +package com.cultural.heritage.controller.global; + +import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.cultural.heritage.annotation.AuthCheck; +import com.cultural.heritage.common.BaseResponse; +import com.cultural.heritage.common.ResultUtils; +import com.cultural.heritage.constant.OrderStatusConstant; +import com.cultural.heritage.constant.UserConstant; +import com.cultural.heritage.model.entity.AdvanceOrder; +import com.cultural.heritage.model.entity.Good; +import com.cultural.heritage.model.entity.Order; +import com.cultural.heritage.service.book.AdvanceOrderService; +import com.cultural.heritage.service.good.GoodService; +import com.cultural.heritage.service.order.OrderService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RestController +@RequestMapping("/global") +@Slf4j +@Tag(name = "获取全局数据接口") +public class GlobalController { + + + @Resource + private OrderService orderService; + + + @Resource + private AdvanceOrderService advanceOrderService; + + + @Resource + private GoodService goodService; + + + + /** + * Web端管理员查看全局数据 + * @return Map集合 + */ + @PostMapping("/queryAll") + @Operation(summary = "Web端管理员查看全局数据", description = "参数:无,权限:管理员(admin, boss),方法名:delAppointmentDateById") + @AuthCheck(mustRole = UserConstant.ADMIN_ROLE) + public BaseResponse> getDashboardData() { + + List orderStatusList = List.of(OrderStatusConstant.PENDING_SHIPMENT, OrderStatusConstant.PENDING_DELIVERY, OrderStatusConstant.TRANSACTION_SUCCESSFUL); + Map map = new HashMap<>(); + // 获取今天的开始时间和结束时间 + Date startOfDay = DateUtil.beginOfDay(new Date()); // 今天的开始时间(00:00:00) + Date endOfDay = DateUtil.endOfDay(new Date()); // 今天的结束时间(23:59:59) + + QueryWrapper orderQueryWrapper = new QueryWrapper<>(); + orderQueryWrapper.between("updateTime", startOfDay, endOfDay) + .and(wrapper -> wrapper.in("orderStatus", orderStatusList)); + + List orderList = orderService.list(orderQueryWrapper); + + List productOrderList = orderList.stream().filter(order -> order.getOrderType().equals("product")).toList(); + BigDecimal productTotalAmount = new BigDecimal("0.00"); + for (Order order : productOrderList) { + BigDecimal orderAmount = order.getTotalAmount(); + productTotalAmount = productTotalAmount.add(orderAmount); + } + map.put("今日实体类商品订单数", productOrderList.size()); + map.put("今日实体类商品订单营业额", productTotalAmount); + + + List serviceOrderList = orderList.stream().filter(order -> order.getOrderType().equals("service")).toList(); + BigDecimal serviceTotalAmount = new BigDecimal("0.00"); + for (Order order : serviceOrderList) { + BigDecimal orderAmount = order.getTotalAmount(); + serviceTotalAmount = serviceTotalAmount.add(orderAmount); + } + map.put("今日服务类商品订单数", serviceOrderList.size()); + map.put("今日实体类商品订单营业额", serviceTotalAmount); + + + QueryWrapper advanceOrderQueryWrapper = new QueryWrapper<>(); + orderQueryWrapper.between("updateTime", startOfDay, endOfDay) + .and(wrapper -> wrapper.eq("orderStatus", OrderStatusConstant.PENDING_SHIPMENT) + .or().eq("orderStatus", OrderStatusConstant.TRANSACTION_SUCCESSFUL)); + + List advanceOrderList = advanceOrderService.list(advanceOrderQueryWrapper); + BigDecimal advanceTotalAmount = new BigDecimal("0.00"); + for (AdvanceOrder advanceOrder : advanceOrderList) { + BigDecimal orderAmount = advanceOrder.getTotalAmount(); + advanceTotalAmount = advanceTotalAmount.add(orderAmount); + } + map.put("今日写真预约订单数", advanceOrderList.size()); + map.put("今日写真预约类订单营业额", advanceTotalAmount); + + // 获取所有待支付订单 + List pendingPaymentOrderList = orderList.stream().filter(order -> order.getOrderStatus().equals(OrderStatusConstant.PENDING_PAYMENT)).toList(); + // 获取待发货实体类订单 + List productPendingShipmentOrderList = orderList.stream().filter(order -> + order.getOrderStatus().equals(OrderStatusConstant.PENDING_SHIPMENT) + && order.getOrderType().equals("product")).toList(); + // 获取待消费服务类订单 + List servicePendingShipmentOrderList = orderList.stream().filter(order -> + order.getOrderStatus().equals(OrderStatusConstant.PENDING_SHIPMENT) + && order.getOrderType().equals("service")).toList(); + + map.put("所有待支付订单数量", pendingPaymentOrderList.size()); + map.put("实体类待发货订单", productPendingShipmentOrderList.size()); + map.put("服务类待消费订单", servicePendingShipmentOrderList.size()); + + // 获取待拍摄写真预约订单 + List pendingShipmentAdvanceOrderList = advanceOrderList.stream().filter(advanceOrder -> advanceOrder.getOrderStatus().equals(OrderStatusConstant.PENDING_SHIPMENT)).toList(); + map.put("写真预约类待拍摄订单", pendingShipmentAdvanceOrderList.size()); + + List goodList = goodService.list(); + List isShelvesGoodList = goodList.stream().filter(good -> good.getIsShelves() == 1).toList(); + List isNoShelvesGoodList = goodList.stream().filter(good -> good.getIsShelves() == 0).toList(); + + map.put("全部商品数量", goodList.size()); + map.put("全部已上架商品数量", isShelvesGoodList.size()); + map.put("全部已下架商品数量", isNoShelvesGoodList.size()); + + return ResultUtils.success(map); + } + + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c3f7a9e..44cd4a9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -53,7 +53,7 @@ spring: password: yuanteng servlet: multipart: - max-file-size: 50MB + max-file-size: 20MB springdoc: