台桌统计报表

This commit is contained in:
Tankaikai
2025-04-02 13:25:56 +08:00
parent 6eb0a765c1
commit 84b7ac9e39
12 changed files with 314 additions and 38 deletions

View File

@@ -2,17 +2,17 @@ package com.czg.controller;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.account.service.MemberPointsService;
import com.czg.entity.CzgBaseRespParams;
import com.czg.mq.PrintMqListener;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.ShopOrderStatisticService;
import com.czg.task.StatisticTask;
import com.czg.utils.AssertUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
/**
* @author ww
@@ -30,18 +30,26 @@ public class NotifyController {
@Resource
private StatisticTask statisticTask;
@DubboReference
private MemberPointsService pointsService;
@RequestMapping("/payCallBack")
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams){
JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "支付回调数据为空");
log.info("支付回调数据为:{}", czg);
orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg);
@Resource
private ShopOrderStatisticService shopOrderStatisticService;
@GetMapping("/payCallBack")
public String notifyCallBack() {
shopOrderStatisticService.statistic();
//JSONObject czg = CzgPayUtils.getCzg(respParams);
//AssertUtil.isNull(czg, "支付回调数据为空");
//log.info("支付回调数据为:{}", czg);
//orderInfoService.payCallBackOrder(czg.getString("mchOrderNo"), czg);
return SUCCESS;
}
@RequestMapping("/refundCallBack")
public String refundCallBack(@RequestBody CzgBaseRespParams respParams){
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "退款回调数据为空");
log.info("退款回调数据为:{}", czg);
@@ -51,6 +59,7 @@ public class NotifyController {
@Resource
private PrintMqListener printMqListener;
@RequestMapping("/test")
public void test(@RequestParam String id) {
printMqListener.orderPrint(id);

View File

@@ -0,0 +1,151 @@
package com.czg.handel;
import cn.idev.excel.metadata.Head;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.write.handler.CellWriteHandler;
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
import cn.idev.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import java.util.List;
/**
* @author tankaikai
* @since 2025-04-01 18:41
*/
public class ExcelMergeHandler implements CellWriteHandler {
// 要合并的列索引数组
private int[] mergeColumnIndex = {0, 1, 2, 9, 10};
// 合并开始的行索引
private int mergeRowIndex = 1;
public ExcelMergeHandler() {
}
/**
* 构造函数
*
* @param mergeRowIndex 合并开始的行索引
* @param mergeColumnIndex 要合并的列索引数组
*/
public ExcelMergeHandler(int mergeRowIndex, int[] mergeColumnIndex) {
this.mergeRowIndex = mergeRowIndex;
this.mergeColumnIndex = mergeColumnIndex;
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
// 当前行索引
int curRowIndex = cell.getRowIndex();
// 当前列索引
int curColIndex = cell.getColumnIndex();
// 如果当前行大于合并开始行且当前列在需要合并的列中
if (curRowIndex > mergeRowIndex && isMergeColumn(curColIndex)) {
// 进行合并操作
mergeWithPrevRow(writeSheetHolder, cell, curRowIndex, curColIndex);
}
}
/**
* 检查当前列是否在需要合并的列中
*
* @param curColIndex 当前列索引
* @return 如果是需要合并的列返回true否则返回false
*/
private boolean isMergeColumn(int curColIndex) {
for (int columnIndex : mergeColumnIndex) {
if (curColIndex == columnIndex) {
return true;
}
}
return false;
}
/**
* 当前单元格向上合并
*
* @param writeSheetHolder 当前工作表持有者
* @param cell 当前单元格
* @param curRowIndex 当前行索引
* @param curColIndex 当前列索引
*/
private void mergeWithPrevRow(WriteSheetHolder writeSheetHolder, Cell cell, int curRowIndex, int curColIndex) {
// 获取当前单元格的数据
Object curData = getCellData(cell);
// 获取前一个单元格的数据
Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex);
Object preData = getCellData(preCell);
// 判断当前单元格和前一个单元格的数据以及主键是否相同
if (curData.equals(preData) && isSamePrimaryKey(cell, curRowIndex)) {
// 获取工作表
Sheet sheet = writeSheetHolder.getSheet();
// 合并单元格
mergeCells(sheet, curRowIndex, curColIndex);
CellStyle style = preCell.getCellStyle();
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
preCell.setCellStyle(style);
}
}
/**
* 获取单元格的数据
*
* @param cell 单元格
* @return 单元格数据
*/
private Object getCellData(Cell cell) {
return cell.getCellType() == CellType.STRING ? cell.getStringCellValue() : cell.getNumericCellValue();
}
/**
* 判断当前单元格和前一个单元格的主键是否相同
*
* @param cell 当前单元格
* @param curRowIndex 当前行索引
* @return 如果主键相同返回true否则返回false
*/
private boolean isSamePrimaryKey(Cell cell, int curRowIndex) {
String currentPrimaryKey = cell.getRow().getCell(0).getStringCellValue();
String previousPrimaryKey = cell.getSheet().getRow(curRowIndex - 1).getCell(0).getStringCellValue();
return currentPrimaryKey.equals(previousPrimaryKey);
}
/**
* 合并单元格
*
* @param sheet 工作表
* @param curRowIndex 当前行索引
* @param curColIndex 当前列索引
*/
private void mergeCells(Sheet sheet, int curRowIndex, int curColIndex) {
// 获取已合并的区域
List<CellRangeAddress> mergeRegions = sheet.getMergedRegions();
boolean isMerged = false;
// 检查前一个单元格是否已经被合并
for (int i = 0; i < mergeRegions.size() && !isMerged; i++) {
CellRangeAddress cellRangeAddr = mergeRegions.get(i);
if (cellRangeAddr.isInRange(curRowIndex - 1, curColIndex)) {
sheet.removeMergedRegion(i);
cellRangeAddr.setLastRow(curRowIndex);
sheet.addMergedRegion(cellRangeAddr);
isMerged = true;
}
}
// 如果前一个单元格未被合并,则新增合并区域
if (!isMerged) {
CellRangeAddress cellRangeAddress = new CellRangeAddress(curRowIndex - 1, curRowIndex, curColIndex, curColIndex);
sheet.addMergedRegion(cellRangeAddress);
}
}
}

View File

@@ -0,0 +1,55 @@
package com.czg.handel;
import cn.hutool.core.util.ArrayUtil;
import cn.idev.excel.metadata.Head;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.write.handler.CellWriteHandler;
import cn.idev.excel.write.metadata.holder.WriteSheetHolder;
import cn.idev.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.*;
import java.util.List;
/**
* 台桌统计退单单元格处理器
*
* @author tankaikai
* @since 2025-04-02 09:50
*/
public class TableRefundCellHandel implements CellWriteHandler {
// 要处理的列索引数组
private int[] yellowColumnIndex = {11, 12};
public TableRefundCellHandel() {
}
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<WriteCellData<?>> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
// 当前行索引
int curRowIndex = cell.getRowIndex();
// 当前列索引
int curColIndex = cell.getColumnIndex();
if (curRowIndex == 0) {
return;
}
// 如果是指定要处理的列,则要进行加黄操作
if (ArrayUtil.contains(yellowColumnIndex, curColIndex)) {
Cell preCell = cell.getSheet().getRow(curRowIndex - 1).getCell(curColIndex);
if (preCell.getCellType() == CellType.NUMERIC) {
if (preCell.getNumericCellValue() < 0) {
//System.out.println("设置黄色背景:" + curRowIndex + "行," + curColIndex + "列" + preCell.getNumericCellValue());
CellStyle style = preCell.getSheet().getWorkbook().createCellStyle();
style.cloneStyleFrom(preCell.getCellStyle());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
// 设置水平居中
style.setAlignment(HorizontalAlignment.CENTER);
// 设置垂直居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
preCell.setCellStyle(style);
}
}
}
}
}

View File

@@ -27,8 +27,8 @@ public class StatisticTask {
long start = System.currentTimeMillis();
log.info("定时任务执行,开始统计数据");
shopOrderStatisticService.statistic();
shopProdStatisticService.statistic();
shopTableOrderStatisticService.statistic();
//shopProdStatisticService.statistic();
//shopTableOrderStatisticService.statistic();
log.info("定时任务执行完毕,耗时:{}ms", start - System.currentTimeMillis());
}
}

View File

@@ -1,5 +1,7 @@
server:
port: 9200
servlet:
context-path: /order
spring:
application: