|
|
@@ -1,127 +0,0 @@
|
|
|
-package shop.alien.store.controller;
|
|
|
-
|
|
|
-import io.swagger.annotations.*;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.format.annotation.DateTimeFormat;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-import shop.alien.entity.result.R;
|
|
|
-import shop.alien.store.service.TrackEventService;
|
|
|
-
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 经营数据Controller
|
|
|
- *
|
|
|
- * @author system
|
|
|
- * @since 2026-01-14
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Api(tags = {"经营数据统计"})
|
|
|
-@ApiSort(21)
|
|
|
-@CrossOrigin
|
|
|
-@RestController
|
|
|
-@RequestMapping("/business")
|
|
|
-@RequiredArgsConstructor
|
|
|
-public class BusinessDataController {
|
|
|
-
|
|
|
- private final TrackEventService trackEventService;
|
|
|
-
|
|
|
- @ApiOperation("查询经营数据")
|
|
|
- @ApiOperationSupport(order = 1)
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "Integer", paramType = "query", required = true),
|
|
|
- @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "String", paramType = "query", required = false, example = "2026-01-08"),
|
|
|
- @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "String", paramType = "query", required = false, example = "2026-01-14"),
|
|
|
- @ApiImplicitParam(name = "category", value = "数据分类(TRAFFIC,INTERACTION,COUPON,VOUCHER,SERVICE,PRICE)", dataType = "String", paramType = "query", required = false)
|
|
|
- })
|
|
|
- @GetMapping("/data")
|
|
|
- public R<Map<String, Object>> getBusinessData(
|
|
|
- @RequestParam("storeId") Integer storeId,
|
|
|
- @RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
|
|
|
- @RequestParam(value = "endDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
|
|
|
- @RequestParam(value = "category", required = false) String category
|
|
|
- ) {
|
|
|
- log.info("查询经营数据: storeId={}, startDate={}, endDate={}, category={}",
|
|
|
- storeId, startDate, endDate, category);
|
|
|
-
|
|
|
- try {
|
|
|
- // 如果没有指定日期,默认查询最近7天的数据
|
|
|
- if (startDate == null || endDate == null) {
|
|
|
- Date now = new Date();
|
|
|
- if (endDate == null) {
|
|
|
- endDate = now;
|
|
|
- }
|
|
|
- if (startDate == null) {
|
|
|
- long sevenDaysAgo = endDate.getTime() - 7 * 24 * 60 * 60 * 1000L;
|
|
|
- startDate = new Date(sevenDaysAgo);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> data = trackEventService.getBusinessData(storeId, startDate, endDate, category);
|
|
|
- return R.data(data);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询经营数据失败", e);
|
|
|
- return R.fail("查询失败: " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("对比两个时间段的数据")
|
|
|
- @ApiOperationSupport(order = 2)
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "Integer", paramType = "query", required = true),
|
|
|
- @ApiImplicitParam(name = "startDate1", value = "时间段1开始日期", dataType = "String", paramType = "query", required = true, example = "2026-01-08"),
|
|
|
- @ApiImplicitParam(name = "endDate1", value = "时间段1结束日期", dataType = "String", paramType = "query", required = true, example = "2026-01-14"),
|
|
|
- @ApiImplicitParam(name = "startDate2", value = "时间段2开始日期", dataType = "String", paramType = "query", required = true, example = "2026-01-01"),
|
|
|
- @ApiImplicitParam(name = "endDate2", value = "时间段2结束日期", dataType = "String", paramType = "query", required = true, example = "2026-01-07")
|
|
|
- })
|
|
|
- @GetMapping("/data/compare")
|
|
|
- public R<Map<String, Object>> compareBusinessData(
|
|
|
- @RequestParam("storeId") Integer storeId,
|
|
|
- @RequestParam("startDate1") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate1,
|
|
|
- @RequestParam("endDate1") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate1,
|
|
|
- @RequestParam("startDate2") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate2,
|
|
|
- @RequestParam("endDate2") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate2
|
|
|
- ) {
|
|
|
- log.info("对比经营数据: storeId={}, period1=[{}, {}], period2=[{}, {}]",
|
|
|
- storeId, startDate1, endDate1, startDate2, endDate2);
|
|
|
-
|
|
|
- try {
|
|
|
- Map<String, Object> data = trackEventService.compareBusinessData(
|
|
|
- storeId, startDate1, endDate1, startDate2, endDate2);
|
|
|
- return R.data(data);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("对比经营数据失败", e);
|
|
|
- return R.fail("对比失败: " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation("查询历史数据")
|
|
|
- @ApiOperationSupport(order = 3)
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "Integer", paramType = "query", required = true),
|
|
|
- @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "String", paramType = "query", required = true, example = "2026-01-01"),
|
|
|
- @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "String", paramType = "query", required = true, example = "2026-01-31"),
|
|
|
- @ApiImplicitParam(name = "statType", value = "统计类型(DAILY,WEEKLY,MONTHLY)", dataType = "String", paramType = "query", required = false)
|
|
|
- })
|
|
|
- @GetMapping("/data/history")
|
|
|
- public R<Map<String, Object>> getHistoryData(
|
|
|
- @RequestParam("storeId") Integer storeId,
|
|
|
- @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
|
|
|
- @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
|
|
|
- @RequestParam(value = "statType", required = false, defaultValue = "DAILY") String statType
|
|
|
- ) {
|
|
|
- log.info("查询历史数据: storeId={}, startDate={}, endDate={}, statType={}",
|
|
|
- storeId, startDate, endDate, statType);
|
|
|
-
|
|
|
- try {
|
|
|
- // TODO: 从统计表中查询历史数据
|
|
|
- Map<String, Object> data = trackEventService.getBusinessData(storeId, startDate, endDate, null);
|
|
|
- return R.data(data);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("查询历史数据失败", e);
|
|
|
- return R.fail("查询失败: " + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-}
|