This commit is contained in:
2025-11-22 14:02:20 +08:00
parent 98a04f8fbe
commit 381ae80eeb
59 changed files with 1930 additions and 1817 deletions

View File

@@ -1,54 +0,0 @@
//package com.czg.controller.admin;
//
//import com.czg.account.dto.ShopShareDTO;
//import com.czg.account.service.ShopShareService;
//import com.czg.account.vo.ShopShareRecordVO;
//import com.czg.account.vo.ShopShareVO;
//import com.czg.annotation.SaAdminCheckPermission;
//import com.czg.resp.CzgResult;
//import com.czg.sa.StpKit;
//import com.mybatisflex.core.paginate.Page;
//import jakarta.annotation.Resource;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
///**
// * 小程序分享奖励管理
// * @author Administrator
// */
//@RestController
//@RequestMapping("/admin/shopShare")
//public class ShopShareController {
// @Resource
// private ShopShareService shopShareService;
//
// /**
// * 获取分享奖励配置
// */
// @SaAdminCheckPermission(value = "shopShare:list", name = "分享好友信息")
// @GetMapping
// public CzgResult<ShopShareVO> get() {
// return CzgResult.success(shopShareService.get(StpKit.USER.getShopId()));
// }
//
// /**
// * 修改分享奖励配置
// */
// @SaAdminCheckPermission(value = "shopShare:add", name = "分享好友信息添加")
// @PostMapping
// public CzgResult<Boolean> add(@RequestBody @Validated ShopShareDTO shopShareDTO) {
// return CzgResult.success(shopShareService.add(StpKit.USER.getShopId(), shopShareDTO));
// }
//
// /**
// * 分享奖励记录
// * @param key 邀请人/被邀请人手机号或昵称
// * @param status 0 非新用户 1 未领取 2 已领取 3 已使用 不传递为全部
// * @return 分页数据
// */
// @SaAdminCheckPermission(value = "shopShare:record", name = "分享邀请记录")
// @GetMapping("/record")
// public CzgResult<Page<ShopShareRecordVO>> record(String key, Integer status) {
// return CzgResult.success(shopShareService.recordPage(StpKit.USER.getShopId(), key, status));
// }
//}

View File

@@ -1,24 +0,0 @@
package com.czg.controller.admin;
import com.czg.account.service.ShopProdStatisticService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Administrator
*/
@RestController
@RequestMapping("/admin/statistic")
public class ShopStatisticController {
@Resource
private ShopProdStatisticService shopProdStatisticService;
@GetMapping("/prod")
public CzgResult<?> getProduct(String name, String categoryId, String startTime, String endTime) {
return CzgResult.success(shopProdStatisticService.pageInfo(StpKit.USER.getShopId(), name, categoryId, startTime, endTime));
}
}

View File

@@ -176,7 +176,7 @@ public class OrderPayController {
/**
* 获取订单状态
* unpaid-待支付;in-production 制作中;wait-out 待取餐;;done-订单完成;refunding-申请退单;refund-退单;part-refund 部分退单;cancelled-取消订单
* unpaid-待支付;in-production 制作中;wait_out 待取餐;;done-订单完成;refunding-申请退单;refund-退单;part_refund 部分退单;cancelled-取消订单
*/
@GetMapping("/queryOrderStatus")
public CzgResult<String> queryOrderStatus(Long orderId) {

View File

@@ -0,0 +1,41 @@
package com.czg.controller;
import com.czg.task.StatisticTask;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
/**
* @author ww
* @description
*/
@RestController
@RequestMapping("/task")
public class StatisticTaskController {
@Resource
private StatisticTask statisticTask;
/**
* 基础统计
*
* @param date 日期yyyy-MM-dd
*/
@GetMapping("/base")
public String baseStatistic(@RequestParam LocalDate date, @RequestParam Long shopId, @RequestParam String type) {
if ("order".equals(type)) {
statisticTask.statisticAndInsertOrder(shopId, date);
} else if ("prod".equals(type)) {
statisticTask.statisticAndInsertProd(shopId, date);
} else if ("table".equals(type)) {
statisticTask.statisticAndInsertTable(shopId, date);
} else {
return "未知错误";
}
return "success";
}
}

View File

@@ -1,27 +1,29 @@
package com.czg.controller.admin;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.param.DataSummaryProductSaleParam;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.DataSummaryTradeParam;
import com.czg.order.service.DataSummaryService;
import com.czg.order.vo.DataSummaryDateAmountVo;
import com.czg.order.vo.DataSummaryPayTypeVo;
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
import com.czg.order.service.ShopOrderStatisticService;
import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.vo.CountPayTypeVo;
import com.czg.order.vo.TotalVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
import com.czg.utils.AssertUtil;
import com.czg.validator.ValidatorUtil;
import com.czg.validator.group.DefaultGroup;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 数据统计
*
@@ -33,22 +35,31 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/admin/data/summary")
public class DataSummaryController {
private final DataSummaryService dataSummaryService;
@Resource
private RedisService redisService;
@Resource
private ShopOrderStatisticService orderStatisticService;
@Resource
private ShopProdStatisticService prodStatisticService;
/**
* 营业板块-上半部分
*/
@GetMapping("trade")
@OperationLog("营业板块-上半部分")
// @SaStaffCheckPermission("yun_xu_cha_kan_jing_ying_shu_ju")
@SaAdminCheckPermission(value = "dataSummary:trade", name = "营业板块-上半部分")
public CzgResult<ShopOrderStatistic> getTradeData(DataSummaryTradeParam param) {
Boolean hasKey = redisService.hasKey("task:statistic:date:");
if (hasKey) {
return CzgResult.failure("数据统计任务正在运行中,请稍后再试");
}
ValidatorUtil.validateEntity(param, DefaultGroup.class);
Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) {
param.setShopId(shopId);
}
ShopOrderStatistic data = dataSummaryService.getArchiveTradeData(param);
ShopOrderStatistic data = orderStatisticService.getArchiveTradeData(param.getShopId(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
return CzgResult.success(data);
}
@@ -57,15 +68,14 @@ public class DataSummaryController {
*/
@GetMapping("productSaleDate")
@OperationLog("商品销售-右下")
// @SaStaffCheckPermission("yun_xu_cha_kan_jing_ying_shu_ju")
@SaAdminCheckPermission(value = "dataSummary:productSaleData", name = "商品销售-右下")
public CzgResult<Page<DataSummaryProductSaleRankingVo>> getProductSaleData(DataSummaryProductSaleParam param) {
public CzgResult<List<ShopProdStatistic>> getProductSaleData(DataSummaryTradeParam param) {
ValidatorUtil.validateEntity(param, DefaultGroup.class);
Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) {
param.setShopId(shopId);
}
Page<DataSummaryProductSaleRankingVo> data = dataSummaryService.getProductSaleRankingPage(param);
List<ShopProdStatistic> data = prodStatisticService.getArchiveTradeDataBy20(param.getShopId(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
return CzgResult.success(data);
}
@@ -77,32 +87,30 @@ public class DataSummaryController {
*/
@GetMapping("dateAmount")
@OperationLog("销售趋势柱状图 左下")
// @SaStaffCheckPermission("yun_xu_cha_kan_jing_ying_shu_ju")
@SaAdminCheckPermission(value = "dataSummary:dateAmount", name = "销售趋势柱状图 左下")
public CzgResult<DataSummaryDateAmountVo> getDateAmount(@RequestParam Integer day, @RequestParam(required = false) Long shopId) {
public CzgResult<List<TotalVo>> getDateAmount(@RequestParam Integer day, @RequestParam(required = false) Long shopId) {
AssertUtil.isNull(day, "天数不能为空");
if (shopId == null) {
shopId = StpKit.USER.getShopId();
}
DataSummaryDateAmountVo data = dataSummaryService.getSummaryAmountData(shopId, day);
List<TotalVo> data = orderStatisticService.getDateAmount(shopId, day);
return CzgResult.success(data);
}
/**
* 支付占比饼图 左下
*
* @param day 天数
* @param day 天数
* @param shopId 店铺id
*/
@GetMapping("datePayType")
@OperationLog("支付占比饼图 左下")
// @SaStaffCheckPermission("yun_xu_cha_kan_jing_ying_shu_ju")
@SaAdminCheckPermission(value = "dataSummary:datePayType", name = "支付占比饼图 左下2")
public CzgResult<DataSummaryPayTypeVo> shopSummaryPayType(@RequestParam Integer day, @RequestParam(required = false) Long shopId) {
public CzgResult<List<CountPayTypeVo>> shopSummaryPayType(@RequestParam Integer day, @RequestParam(required = false) Long shopId) {
if (shopId == null) {
shopId = StpKit.USER.getShopId(0L);
shopId = StpKit.USER.getShopId();
}
DataSummaryPayTypeVo data = dataSummaryService.getSummaryPayTypeData(shopId, day);
List<CountPayTypeVo> data = orderStatisticService.getSummaryPayTypeData(shopId, day);
return CzgResult.success(data);
}
}

View File

@@ -1,14 +1,13 @@
package com.czg.controller.admin;
import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.SaleSummaryService;
import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.order.vo.SaleSummaryInfoVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
@@ -28,7 +27,8 @@ import java.util.List;
@RestController
@RequestMapping("/admin/sale/summary")
public class SaleSummaryController {
private final SaleSummaryService saleSummaryService;
@Resource
private ShopProdStatisticService prodStatisticService;
/**
* 统计
@@ -37,11 +37,12 @@ public class SaleSummaryController {
@OperationLog("统计")
//@SaAdminCheckPermission("saleSummary:count")
public CzgResult<SaleSummaryCountVo> summaryCount(SaleSummaryCountParam param) {
Long shopId = StpKit.USER.getShopId(0L);
Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) {
param.setShopId(shopId);
}
SaleSummaryCountVo data = saleSummaryService.summaryCount(param);
SaleSummaryCountVo data = prodStatisticService.summaryCount(
param.getShopId(), param.getProductName(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
return CzgResult.success(data);
}
@@ -51,28 +52,14 @@ public class SaleSummaryController {
@GetMapping("page")
@OperationLog("分页")
//@SaAdminCheckPermission("saleSummary:page")
public CzgResult<Page<SaleSummaryInfoVo>> summaryPage(SaleSummaryCountParam param) {
Long shopId = StpKit.USER.getShopId(0L);
public CzgResult<List<ShopProdStatistic>> summaryPage(SaleSummaryCountParam param) {
Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) {
param.setShopId(shopId);
}
Page<SaleSummaryInfoVo> page = saleSummaryService.summaryPage(param);
return CzgResult.success(page);
}
/**
* 导出
*/
@ResponseExcel(name = "销售统计明细")
@GetMapping("/export")
@OperationLog("导出")
//@SaAdminCheckPermission("saleSummary:export")
public List<SaleSummaryInfoVo> summaryExport(SaleSummaryCountParam param) {
Long shopId = StpKit.USER.getShopId(0L);
if (param.getShopId() == null) {
param.setShopId(shopId);
}
return saleSummaryService.summaryList(param);
List<ShopProdStatistic> list = prodStatisticService.getArchiveTradeData(
param.getShopId(),param.getProductName(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
return CzgResult.success(list);
}
}

View File

@@ -3,13 +3,16 @@ package com.czg.controller.admin;
import com.czg.handel.ExcelMergeHandler;
import com.czg.handel.TableRefundCellHandel;
import com.czg.log.annotation.OperationLog;
import com.czg.order.entity.ShopTableOrderStatistic;
import com.czg.order.param.DataSummaryTradeParam;
import com.czg.order.param.TableSummaryParam;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.order.service.TableSummaryService;
import com.czg.order.vo.TableSummaryExportVo;
import com.czg.order.vo.TableSummaryInfoVo;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -29,19 +32,22 @@ import java.util.List;
public class TableSummaryController {
private final TableSummaryService tableSummaryService;
@Resource
private ShopTableOrderStatisticService tableOrderStatisticService;
/**
* 统计
*/
@GetMapping("list")
@OperationLog("统计")
//@SaAdminCheckPermission("tableSummary:list")
public CzgResult<List<TableSummaryInfoVo>> summaryList(TableSummaryParam param) {
Long shopId = StpKit.USER.getShopId(0L);
public CzgResult<List<ShopTableOrderStatistic>> summaryList(DataSummaryTradeParam param) {
Long shopId = StpKit.USER.getShopId();
if (param.getShopId() == null) {
param.setShopId(shopId);
}
List<TableSummaryInfoVo> data = tableSummaryService.summaryList(param);
return CzgResult.success(data);
List<ShopTableOrderStatistic> archiveTradeData = tableOrderStatisticService.getArchiveTradeData(param.getShopId(), param.getRangeType(), param.getBeginDate(), param.getEndDate());
return CzgResult.success(archiveTradeData);
}
/**

View File

@@ -1,21 +1,14 @@
package com.czg.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.entity.ShopTableOrderStatistic;
import com.czg.account.service.ShopInfoService;
import com.czg.order.service.ShopOrderStatisticService;
import com.czg.order.service.ShopProdStatisticService;
import com.czg.order.service.ShopTableOrderStatisticService;
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
import com.czg.service.order.mapper.ShopProdStatisticMapper;
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.DbChain;
import com.czg.service.RedisService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -28,87 +21,73 @@ import java.util.List;
@Component
@Slf4j
public class StatisticTask {
@DubboReference
private ShopInfoService shopInfoService;
@Resource
private ShopOrderStatisticService orderStatisticService;
@Resource
private RedisService redisService;
@Resource
private ShopTableOrderStatisticService shopTableOrderStatisticService;
@Resource
private ShopProdStatisticService shopProdStatisticService;
@Resource
private ShopOrderStatisticService shopOrderStatisticService;
@Resource
private ShopOrderStatisticMapper shopOrderStatisticMapper;
@Resource
private ShopProdStatisticMapper shopProdStatisticMapper;
@Resource
private ShopTableOrderStatisticMapper shopTableOrderStatisticMapper;
//每天 00点15分 执行 开始统计数据
@Scheduled(cron = "0 15 0 * * ? ")
public void run() {
log.info("统计数据,定时任务执行");
long start = System.currentTimeMillis();
// 获取前一天
LocalDate yesterday = LocalDate.now().minusDays(1);
baseStatistic(yesterday);
log.info("统计数据,定时任务执行完毕,耗时:{}ms", start - System.currentTimeMillis());
}
/**
* 基础统计
*
* @param dateTime 日期时间
* @param date 日期yyyy-MM-dd
*/
private void baseStatistic(DateTime dateTime) {
try {
shopOrderStatisticService.statistic(dateTime);
} catch (Exception e) {
log.error("统计订单数据失败", e);
private void baseStatistic(LocalDate date) {
List<Long> shopIdList = shopInfoService.getShopIdList();
if (CollUtil.isEmpty(shopIdList)) {
return;
}
try {
shopProdStatisticService.statistic(dateTime);
} catch (Exception e) {
log.error("统计商品数据失败", e);
redisService.set("task:statistic:date:", "");
for (Long shopId : shopIdList) {
statisticAndInsertOrder(shopId, date);
statisticAndInsertProd(shopId, date);
statisticAndInsertTable(shopId, date);
}
redisService.del("task:statistic:date:");
}
public void statisticAndInsertOrder(Long shopId, LocalDate date) {
try {
shopTableOrderStatisticService.statistic(dateTime);
orderStatisticService.statisticAndInsert(shopId, date);
} catch (Exception e) {
log.error("统计桌台数据失败", e);
log.error("统计订单数据失败店铺id:{},日期:{}", shopId, date, e);
}
}
// @Scheduled(cron = "1/6 * * * * ? ")
@Scheduled(cron = "0 0 8 * * ?")
public void run() {
long start = System.currentTimeMillis();
log.info("定时任务执行,开始统计数据");
// 获取前一天
DateTime yesterday = DateUtil.yesterday();
baseStatistic(yesterday);
log.info("定时任务执行完毕,耗时:{}ms", start - System.currentTimeMillis());
}
@Scheduled(cron = "0 0,15,30,45 * * * ? ")
public void run2() {
long start = System.currentTimeMillis();
log.info("定时任务2执行开始统计数据");
// 获取当天
DateTime today = DateUtil.date();
baseStatistic(today);
log.info("定时任务2执行完毕耗时:{}ms", start - System.currentTimeMillis());
}
/**
* 统计历史数据
*/
public void statisticHistoryData() {
// 指定开始日期
LocalDate startDate = LocalDate.of(2024, 3, 1);
// 指定结束日期
LocalDate endDate = LocalDate.now();
List<Long> shopIdList = DbChain.table("tb_shop_info").select("id").objListAs(Long.class);
List<List<Long>> split = CollUtil.split(shopIdList, 10);
// 1.清除历史统计的数据
for (List<Long> splitIdList : split) {
splitIdList.parallelStream().forEach(shopId -> {
shopOrderStatisticMapper.deleteByQuery(QueryWrapper.create().eq(ShopOrderStatistic::getShopId, shopId));
shopProdStatisticMapper.deleteByQuery(QueryWrapper.create().eq(ShopProdStatistic::getShopId, shopId));
shopTableOrderStatisticMapper.deleteByQuery(QueryWrapper.create().eq(ShopTableOrderStatistic::getShopId, shopId));
});
public void statisticAndInsertProd(Long shopId, LocalDate date) {
try {
shopProdStatisticService.statisticAndInsert(shopId, date);
} catch (Exception e) {
log.error("统计商品数据失败店铺id:{},日期:{}", shopId, date, e);
}
// 2.开始从2024-3-1开始统计数据
startDate.datesUntil(endDate.plusDays(1)).forEach(date -> {
System.out.println(date.toString());
DateTime dateTime = DateUtil.parseDate(date.toString());
System.out.println(dateTime);
baseStatistic(dateTime);
});
}
public void statisticAndInsertTable(Long shopId, LocalDate date) {
try {
shopTableOrderStatisticService.statisticAndInsert(shopId, date);
} catch (Exception e) {
log.error("统计桌台数据失败店铺id:{},日期:{}", shopId, date, e);
}
}
}