|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|
|
|
|