vip、天医币、实物订单报表

This commit is contained in:
wuchunlei
2025-09-19 16:48:52 +08:00
parent fc15ffa30d
commit 2135bcb9fc
14 changed files with 398 additions and 99 deletions

View File

@@ -0,0 +1,250 @@
package com.peanut.modules.master.controller;
import com.peanut.common.utils.R;
import com.peanut.modules.common.service.BuyOrderService;
import com.peanut.modules.common.service.TransactionDetailsService;
import com.peanut.modules.common.service.UserVipLogService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
/**
* 报表管理
*/
@Slf4j
@RestController("masterStatistics")
@RequestMapping("master/statistics")
public class StatisticsController {
@Autowired
private UserVipLogService userVipLogService;
@Autowired
private BuyOrderService buyOrderService;
@Autowired
private TransactionDetailsService transactionDetailsService;
@RequestMapping("/getTransactionDetailsTotal")
public R getTransactionDetailsTotal(@RequestBody Map<String, Object> params) {
List<Map<String,Object>> list = transactionDetailsService.getTransactionDetailsTotal(params.get("date").toString());
return R.ok().put("total", list);
}
//导出实物订单明细
@RequestMapping("/getTransactionDetailsInfo")
public void getTransactionDetailsInfo(HttpServletResponse response, @RequestBody Map<String,Object> params){
List<Map<String,Object>> maps = transactionDetailsService.getTransactionDetailsInfo(params.get("date").toString());
XSSFWorkbook wb = new XSSFWorkbook();
//创建一张表
Sheet sheet = wb.createSheet("天医币明细");
//创建第一行起始为0
Row titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("时间");
titleRow.createCell(1).setCellValue("姓名");
titleRow.createCell(2).setCellValue("电话");
titleRow.createCell(3).setCellValue("类型");
titleRow.createCell(4).setCellValue("支付方式");
titleRow.createCell(5).setCellValue("订单编号");
titleRow.createCell(6).setCellValue("变动金额");
titleRow.createCell(7).setCellValue("备注");
titleRow.createCell(8).setCellValue("商品类型");
titleRow.createCell(9).setCellValue("商品名称");
//序号默认为1
int cell = 1;
//遍历
for (Map<String,Object> map : maps) {
Row row = sheet.createRow(cell);
row.createCell(0).setCellValue(map.get("createTime").toString());
row.createCell(1).setCellValue(map.get("name").toString());
row.createCell(2).setCellValue(map.get("tel").toString());
row.createCell(3).setCellValue(map.get("type").toString());
row.createCell(4).setCellValue(map.get("payType").toString());
row.createCell(5).setCellValue(map.get("orderSn").toString());
row.createCell(6).setCellValue(map.get("changeAmount").toString());
row.createCell(7).setCellValue(map.get("note").toString());
row.createCell(8).setCellValue(map.get("goodsType").toString());
row.createCell(9).setCellValue(map.get("productName").toString());
//序号自增
cell++;
}
String fileName = "天医币明细.xlsx";
OutputStream outputStream =null;
try {
//文件名编码格式
fileName = URLEncoder.encode(fileName,"UTF-8");
//设置ContentType请求信息格式
response.setContentType("application/vnd.ms-excel");
//设置标头
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
outputStream = response.getOutputStream();
wb.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequestMapping("/getPhysicalBuyOrderInfoTotal")
public R getPhysicalBuyOrderInfoTotal(@RequestBody Map<String, Object> params) {
List<Map<String,Object>> list = buyOrderService.getPhysicalBuyOrderTotal(params.get("date").toString());
return R.ok().put("total", list);
}
//导出实物订单明细
@RequestMapping("/exportPhysicalBuyOrderInfo")
public void exportPhysicalBuyOrderInfo(HttpServletResponse response, @RequestBody Map<String,Object> params){
List<Map<String,Object>> maps = buyOrderService.exportPhysicalBuyOrderInfo(params.get("date").toString());
XSSFWorkbook wb = new XSSFWorkbook();
//创建一张表
Sheet sheet = wb.createSheet("实物订单明细");
//创建第一行起始为0
Row titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("时间");
titleRow.createCell(1).setCellValue("姓名");
titleRow.createCell(2).setCellValue("电话");
titleRow.createCell(3).setCellValue("订单号");
titleRow.createCell(4).setCellValue("订单状态");
titleRow.createCell(5).setCellValue("支付方式");
titleRow.createCell(6).setCellValue("订单金额");
titleRow.createCell(7).setCellValue("实物金额");
titleRow.createCell(8).setCellValue("商品名称");
//序号默认为1
int cell = 1;
//遍历
for (Map<String,Object> map : maps) {
Row row = sheet.createRow(cell);
row.createCell(0).setCellValue(map.get("createTime").toString());
row.createCell(1).setCellValue(map.get("name").toString());
row.createCell(2).setCellValue(map.get("tel").toString());
row.createCell(3).setCellValue(map.get("orderSn").toString());
row.createCell(4).setCellValue(map.get("orderStatus").toString());
row.createCell(5).setCellValue(map.get("payType").toString());
row.createCell(6).setCellValue(map.get("orderPrice").toString());
row.createCell(7).setCellValue(map.get("price").toString());
row.createCell(8).setCellValue(map.get("productName").toString());
//序号自增
cell++;
}
String fileName = "实物订单明细.xlsx";
OutputStream outputStream =null;
try {
//文件名编码格式
fileName = URLEncoder.encode(fileName,"UTF-8");
//设置ContentType请求信息格式
response.setContentType("application/vnd.ms-excel");
//设置标头
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
outputStream = response.getOutputStream();
wb.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequestMapping("/getUserVipLogInfoTotal")
public R getUserVipLogInfoTotal(@RequestBody Map<String, Object> params) {
Map<String,Object> map = userVipLogService.getUserVipLogInfoTotal(params.get("date").toString());
return R.ok().put("total", map);
}
//导出vip记录明细
@RequestMapping("/exportUserVipLogInfo")
public void exportUserVipLogInfo(HttpServletResponse response, @RequestBody Map<String,Object> params){
List<Map<String,Object>> maps = userVipLogService.getUserVipLogInfo(params.get("date").toString());
XSSFWorkbook wb = new XSSFWorkbook();
//创建一张表
Sheet sheet = wb.createSheet("vip记录明细");
//创建第一行起始为0
Row titleRow = sheet.createRow(0);
titleRow.createCell(0).setCellValue("姓名");
titleRow.createCell(1).setCellValue("电话");
titleRow.createCell(2).setCellValue("VIP类型");
titleRow.createCell(3).setCellValue("开始时间");
titleRow.createCell(4).setCellValue("结束时间");
titleRow.createCell(5).setCellValue("订单号");
titleRow.createCell(6).setCellValue("支付方式");
titleRow.createCell(7).setCellValue("备注");
titleRow.createCell(8).setCellValue("金额");
titleRow.createCell(9).setCellValue("总天数");
titleRow.createCell(10).setCellValue("每日摊销");
titleRow.createCell(11).setCellValue("已摊销天数");
titleRow.createCell(12).setCellValue("当月摊销天数");
titleRow.createCell(13).setCellValue("未摊销天数");
titleRow.createCell(14).setCellValue("已摊销金额");
titleRow.createCell(15).setCellValue("当月摊销金额");
titleRow.createCell(16).setCellValue("剩余摊销金额");
//序号默认为1
int cell = 1;
//遍历
for (Map<String,Object> map : maps) {
Row row = sheet.createRow(cell);
row.createCell(0).setCellValue(map.get("name").toString());
row.createCell(1).setCellValue(map.get("tel").toString());
row.createCell(2).setCellValue(map.get("type").toString());
row.createCell(3).setCellValue(map.get("startTime").toString());
row.createCell(4).setCellValue(map.get("endTime").toString());
row.createCell(5).setCellValue(map.get("orderSn").toString());
row.createCell(6).setCellValue(map.get("payType").toString());
row.createCell(7).setCellValue(map.get("remark").toString());
row.createCell(8).setCellValue(map.get("fee").toString());
row.createCell(9).setCellValue(map.get("totalDays").toString());
row.createCell(10).setCellValue(map.get("dayAmount").toString());
row.createCell(11).setCellValue(map.get("alreadyDays").toString());
row.createCell(12).setCellValue(map.get("currentDays").toString());
row.createCell(13).setCellValue(map.get("notyetDays").toString());
row.createCell(14).setCellValue(map.get("alreadyTanxiao").toString());
row.createCell(15).setCellValue(map.get("currentTanxiao").toString());
row.createCell(16).setCellValue(map.get("notyetTanxiao").toString());
//序号自增
cell++;
}
String fileName = "vip记录明细.xlsx";
OutputStream outputStream =null;
try {
//文件名编码格式
fileName = URLEncoder.encode(fileName,"UTF-8");
//设置ContentType请求信息格式
response.setContentType("application/vnd.ms-excel");
//设置标头
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
outputStream = response.getOutputStream();
wb.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}