Browse Source

增加律师商家端我的页面接口

ldz 1 week ago
parent
commit
9ad1872093

+ 75 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LawyerDashboardVO.java

@@ -0,0 +1,75 @@
+package shop.alien.entity.store.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 律师仪表板数据VO
+ * 包含律师个人信息、订单统计和收益统计
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@ApiModel(value = "LawyerDashboardVO对象", description = "律师仪表板数据VO")
+public class LawyerDashboardVO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    // ========== 律师基本信息 ==========
+    @ApiModelProperty(value = "律师ID")
+    private Integer lawyerId;
+
+    @ApiModelProperty(value = "律师姓名")
+    private String name;
+
+    @ApiModelProperty(value = "律师头像")
+    private String avatar;
+
+    @ApiModelProperty(value = "服务领域(多个用逗号分隔)")
+    private String serviceFields;
+
+    // ========== 性能指标 ==========
+    @ApiModelProperty(value = "本月订单量")
+    private Integer monthOrderCount;
+
+    @ApiModelProperty(value = "总订单量")
+    private Integer totalOrderCount;
+
+    @ApiModelProperty(value = "本月收益(元)")
+    private BigDecimal monthRevenue;
+
+    @ApiModelProperty(value = "总收益(元)")
+    private BigDecimal totalRevenue;
+
+    // ========== 订单信息 ==========
+    @ApiModelProperty(value = "进行中订单统计")
+    private OrderStatusInfo inProgressOrder;
+
+    @ApiModelProperty(value = "待接单订单统计")
+    private OrderStatusInfo pendingAcceptOrder;
+
+    @ApiModelProperty(value = "已退款订单统计")
+    private OrderStatusInfo refundedOrder;
+
+    /**
+     * 订单状态信息内部类
+     */
+    @Data
+    @ApiModel(value = "OrderStatusInfo对象", description = "订单状态信息")
+    public static class OrderStatusInfo implements Serializable {
+
+        private static final long serialVersionUID = 1L;
+
+        @ApiModelProperty(value = "订单总数")
+        private Integer orderCount;
+
+        @ApiModelProperty(value = "金额合计(元)")
+        private BigDecimal totalAmount;
+    }
+}
+

+ 1 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/OrderRevenueVO.java

@@ -45,3 +45,4 @@ public class OrderRevenueVO implements Serializable {
 }
 
 
+

+ 16 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/controller/LawyerStatisticsController.java

@@ -5,6 +5,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.vo.LawyerDashboardVO;
 import shop.alien.entity.store.vo.LawyerOrderStatisticsVO;
 import shop.alien.lawyer.service.LawyerStatisticsService;
 
@@ -39,5 +40,20 @@ public class LawyerStatisticsController {
         }
         return lawyerStatisticsService.getOrderStatistics(lawyerUserId);
     }
+
+    @ApiOperation("获取律师仪表板数据(包含个人信息、订单统计和收益统计)")
+    @ApiOperationSupport(order = 2)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "lawyerUserId", value = "律师用户ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getLawyerDashboard")
+    public R<LawyerDashboardVO> getLawyerDashboard(@RequestParam(value = "lawyerUserId", required = true) Integer lawyerUserId) {
+        log.info("LawyerStatisticsController.getLawyerDashboard?lawyerUserId={}", lawyerUserId);
+        if (lawyerUserId == null || lawyerUserId <= 0) {
+            log.warn("获取律师仪表板数据失败:律师用户ID为空或无效");
+            return R.fail("律师用户ID不能为空");
+        }
+        return lawyerStatisticsService.getLawyerDashboard(lawyerUserId);
+    }
 }
 

+ 9 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/service/LawyerStatisticsService.java

@@ -1,6 +1,7 @@
 package shop.alien.lawyer.service;
 
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.vo.LawyerDashboardVO;
 import shop.alien.entity.store.vo.LawyerOrderStatisticsVO;
 
 /**
@@ -18,5 +19,13 @@ public interface LawyerStatisticsService {
      * @return 订单统计数据
      */
     R<LawyerOrderStatisticsVO> getOrderStatistics(Integer lawyerUserId);
+
+    /**
+     * 获取律师仪表板数据(包含个人信息、订单统计和收益统计)
+     *
+     * @param lawyerUserId 律师用户ID
+     * @return 仪表板数据
+     */
+    R<LawyerDashboardVO> getLawyerDashboard(Integer lawyerUserId);
 }
 

+ 121 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerStatisticsServiceImpl.java

@@ -4,8 +4,11 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import shop.alien.entity.result.R;
+import shop.alien.entity.store.LawyerUser;
+import shop.alien.entity.store.vo.LawyerDashboardVO;
 import shop.alien.entity.store.vo.LawyerOrderStatisticsVO;
 import shop.alien.lawyer.service.LawyerStatisticsService;
+import shop.alien.lawyer.service.LawyerUserService;
 import shop.alien.mapper.LawyerConsultationOrderMapper;
 
 import java.math.BigDecimal;
@@ -28,6 +31,7 @@ import java.util.Map;
 public class LawyerStatisticsServiceImpl implements LawyerStatisticsService {
 
     private final LawyerConsultationOrderMapper lawyerConsultationOrderMapper;
+    private final LawyerUserService lawyerUserService;
 
     /**
      * 金额单位转换:分转元
@@ -268,5 +272,122 @@ public class LawyerStatisticsServiceImpl implements LawyerStatisticsService {
         log.warn("无法将对象转换为Long,value={}, type={}", value, value.getClass().getName());
         return 0L;
     }
+
+    @Override
+    public R<LawyerDashboardVO> getLawyerDashboard(Integer lawyerUserId) {
+        log.info("获取律师仪表板数据开始,lawyerUserId={}", lawyerUserId);
+
+        // 参数校验
+        if (lawyerUserId == null || lawyerUserId <= 0) {
+            log.warn("获取律师仪表板数据失败:律师用户ID为空或无效,lawyerUserId={}", lawyerUserId);
+            return R.fail("律师用户ID不能为空");
+        }
+
+        try {
+            LawyerDashboardVO dashboard = new LawyerDashboardVO();
+
+            // 获取律师基本信息
+            LawyerUser lawyer = lawyerUserService.getById(lawyerUserId);
+            if (lawyer == null || lawyer.getDeleteFlag() == 1) {
+                log.warn("获取律师仪表板数据失败:律师不存在,lawyerUserId={}", lawyerUserId);
+                return R.fail("律师不存在");
+            }
+
+            // 设置律师基本信息
+            dashboard.setLawyerId(lawyer.getId());
+            dashboard.setName(lawyer.getName() != null ? lawyer.getName() : "");
+            dashboard.setAvatar(lawyer.getHeadImg() != null ? lawyer.getHeadImg() : "");
+            dashboard.setServiceFields(lawyer.getSpecialtyFields() != null ? lawyer.getSpecialtyFields() : "");
+
+            // 统计本月数据
+            buildMonthStatisticsForDashboard(dashboard, lawyerUserId);
+
+            // 统计总数据
+            buildTotalStatisticsForDashboard(dashboard, lawyerUserId);
+
+            // 统计进行中订单
+            dashboard.setInProgressOrder(buildOrderStatusInfo(
+                    lawyerConsultationOrderMapper.getInProgressStatistics(lawyerUserId)));
+
+            // 统计待接单订单
+            dashboard.setPendingAcceptOrder(buildOrderStatusInfo(
+                    lawyerConsultationOrderMapper.getPendingAcceptStatistics(lawyerUserId)));
+
+            // 统计已退款订单
+            dashboard.setRefundedOrder(buildOrderStatusInfo(
+                    lawyerConsultationOrderMapper.getRefundedStatistics(lawyerUserId)));
+
+            log.info("获取律师仪表板数据成功,lawyerUserId={}, name={}, monthOrderCount={}, monthRevenue={}, "
+                            + "totalOrderCount={}, totalRevenue={}",
+                    lawyerUserId, dashboard.getName(), dashboard.getMonthOrderCount(), dashboard.getMonthRevenue(),
+                    dashboard.getTotalOrderCount(), dashboard.getTotalRevenue());
+
+            return R.data(dashboard);
+        } catch (RuntimeException e) {
+            log.error("获取律师仪表板数据异常,lawyerUserId={}", lawyerUserId, e);
+            return R.fail("获取仪表板数据失败:" + e.getMessage());
+        }
+    }
+
+    /**
+     * 构建本月统计数据(用于仪表板)
+     *
+     * @param dashboard   仪表板对象
+     * @param lawyerUserId 律师用户ID
+     */
+    private void buildMonthStatisticsForDashboard(LawyerDashboardVO dashboard, Integer lawyerUserId) {
+        String[] timeRange = getCurrentMonthTimeRange();
+        Map<String, Object> monthStats = lawyerConsultationOrderMapper.getMonthStatistics(
+                lawyerUserId, timeRange[0], timeRange[1]);
+
+        if (monthStats != null) {
+            dashboard.setMonthOrderCount(getIntegerValue(monthStats.get(KEY_MONTH_ORDER_COUNT)));
+            Long monthRevenueFen = getLongValue(monthStats.get(KEY_MONTH_REVENUE));
+            dashboard.setMonthRevenue(convertFenToYuan(monthRevenueFen));
+        } else {
+            dashboard.setMonthOrderCount(0);
+            dashboard.setMonthRevenue(BigDecimal.ZERO);
+        }
+    }
+
+    /**
+     * 构建总统计数据(用于仪表板)
+     *
+     * @param dashboard   仪表板对象
+     * @param lawyerUserId 律师用户ID
+     */
+    private void buildTotalStatisticsForDashboard(LawyerDashboardVO dashboard, Integer lawyerUserId) {
+        Map<String, Object> totalStats = lawyerConsultationOrderMapper.getTotalStatistics(lawyerUserId);
+
+        if (totalStats != null) {
+            dashboard.setTotalOrderCount(getIntegerValue(totalStats.get(KEY_TOTAL_ORDER_COUNT)));
+            Long totalRevenueFen = getLongValue(totalStats.get(KEY_TOTAL_REVENUE));
+            dashboard.setTotalRevenue(convertFenToYuan(totalRevenueFen));
+        } else {
+            dashboard.setTotalOrderCount(0);
+            dashboard.setTotalRevenue(BigDecimal.ZERO);
+        }
+    }
+
+    /**
+     * 构建订单状态信息(用于仪表板)
+     *
+     * @param statsMap 统计数据Map
+     * @return 订单状态信息对象
+     */
+    private LawyerDashboardVO.OrderStatusInfo buildOrderStatusInfo(Map<String, Object> statsMap) {
+        LawyerDashboardVO.OrderStatusInfo orderStatusInfo = new LawyerDashboardVO.OrderStatusInfo();
+
+        if (statsMap != null) {
+            orderStatusInfo.setOrderCount(getIntegerValue(statsMap.get(KEY_ORDER_COUNT)));
+            Long amountFen = getLongValue(statsMap.get(KEY_TOTAL_AMOUNT));
+            orderStatusInfo.setTotalAmount(convertFenToYuan(amountFen));
+        } else {
+            orderStatusInfo.setOrderCount(0);
+            orderStatusInfo.setTotalAmount(BigDecimal.ZERO);
+        }
+
+        return orderStatusInfo;
+    }
 }