118 lines
4.9 KiB
Java
118 lines
4.9 KiB
Java
package com.designhub.controller;
|
|
|
|
import com.designhub.common.Result;
|
|
import com.designhub.service.AnalyticsService;
|
|
import com.designhub.util.JwtUtil;
|
|
import com.designhub.vo.DeductionDetailVO;
|
|
import com.designhub.vo.DemandStatisticsVO;
|
|
import com.designhub.vo.DesignerPerformanceVO;
|
|
import com.designhub.vo.DimensionAnalysisVO;
|
|
import com.designhub.vo.ProcessEfficiencyVO;
|
|
import com.designhub.vo.WarningTaskVO;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 数据分析Controller
|
|
*/
|
|
@Slf4j
|
|
@Tag(name = "数据分析", description = "数据分析相关API")
|
|
@RestController
|
|
@RequestMapping("/api/analytics")
|
|
@RequiredArgsConstructor
|
|
public class AnalyticsController {
|
|
|
|
private final AnalyticsService analyticsService;
|
|
private final JwtUtil jwtUtil;
|
|
|
|
@Operation(summary = "获取需求统计数据(根据角色返回不同维度的数据)")
|
|
@GetMapping("/demand-statistics")
|
|
public Result<DemandStatisticsVO> getDemandStatistics(
|
|
@RequestHeader("Authorization") String authHeader,
|
|
@RequestParam(required = false, defaultValue = "month") String dateRange,
|
|
@RequestParam(required = false) Long deptId,
|
|
@RequestParam(required = false) Long userId,
|
|
@RequestParam(required = false) String month // 新增:指定月份,格式 yyyy-MM
|
|
) {
|
|
// 从token获取当前用户ID
|
|
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
|
Long currentUserId = jwtUtil.getUserIdFromToken(token);
|
|
|
|
log.info("获取需求统计数据: currentUserId={}, dateRange={}, deptId={}, userId={}, month={}",
|
|
currentUserId, dateRange, deptId, userId, month);
|
|
|
|
return Result.success(analyticsService.getDemandStatistics(currentUserId, dateRange, deptId, userId, month));
|
|
}
|
|
|
|
@Operation(summary = "获取设计师绩效数据")
|
|
@GetMapping("/designer-performance")
|
|
public Result<DesignerPerformanceVO> getDesignerPerformance(
|
|
@RequestHeader("Authorization") String authHeader,
|
|
@RequestParam(required = false) String month, // 指定月份,格式 yyyy-MM
|
|
@RequestParam(required = false) Long deptId // 指定部门
|
|
) {
|
|
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
|
Long currentUserId = jwtUtil.getUserIdFromToken(token);
|
|
|
|
log.info("获取设计师绩效数据: currentUserId={}, month={}, deptId={}", currentUserId, month, deptId);
|
|
|
|
return Result.success(analyticsService.getDesignerPerformance(currentUserId, month, deptId));
|
|
}
|
|
|
|
@Operation(summary = "获取流程效率数据")
|
|
@GetMapping("/process-efficiency")
|
|
public Result<ProcessEfficiencyVO> getProcessEfficiency(
|
|
@RequestHeader("Authorization") String authHeader,
|
|
@RequestParam(required = false) String month // 指定月份,格式 yyyy-MM
|
|
) {
|
|
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
|
Long currentUserId = jwtUtil.getUserIdFromToken(token);
|
|
|
|
log.info("获取流程效率数据: currentUserId={}, month={}", currentUserId, month);
|
|
|
|
return Result.success(analyticsService.getProcessEfficiency(currentUserId, month));
|
|
}
|
|
|
|
@Operation(summary = "获取预警任务列表")
|
|
@GetMapping("/warnings")
|
|
public Result<List<WarningTaskVO>> getWarningTasks(
|
|
@RequestHeader("Authorization") String authHeader
|
|
) {
|
|
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
|
Long currentUserId = jwtUtil.getUserIdFromToken(token);
|
|
|
|
log.info("获取预警任务列表: currentUserId={}", currentUserId);
|
|
|
|
return Result.success(analyticsService.getWarningTasks(currentUserId));
|
|
}
|
|
|
|
@Operation(summary = "获取设计师扣分明细")
|
|
@GetMapping("/designer-deduction-details")
|
|
public Result<DeductionDetailVO> getDesignerDeductionDetails(
|
|
@RequestHeader("Authorization") String authHeader,
|
|
@RequestParam Long userId,
|
|
@RequestParam(required = false) String month
|
|
) {
|
|
log.info("获取设计师扣分明细: userId={}, month={}", userId, month);
|
|
|
|
return Result.success(analyticsService.getDesignerDeductionDetails(userId, month));
|
|
}
|
|
|
|
@Operation(summary = "获取多维度分析数据(类目/品牌/部门/平台)")
|
|
@GetMapping("/dimension-analysis")
|
|
public Result<DimensionAnalysisVO> getDimensionAnalysis(
|
|
@RequestParam(required = false, defaultValue = "month") String dateRange,
|
|
@RequestParam(required = false) String month
|
|
) {
|
|
log.info("获取多维度分析数据: dateRange={}, month={}", dateRange, month);
|
|
|
|
return Result.success(analyticsService.getDimensionAnalysis(dateRange, month));
|
|
}
|
|
}
|
|
|