湖分统计查询导出

This commit is contained in:
wuchunlei
2025-04-24 17:23:04 +08:00
parent 6728333b59
commit cfe8a58a75
5 changed files with 72 additions and 148 deletions

View File

@@ -1,12 +1,9 @@
package com.peanut.modules.master.controller;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.excel.ContributionStatQuery;
import com.peanut.common.excel.CustomMergeStrategy;
import com.peanut.common.utils.R;
import com.peanut.modules.book.entity.SysDictDataEntity;
import com.peanut.modules.common.entity.MyUserEntity;
@@ -16,19 +13,20 @@ import com.peanut.modules.master.service.UserContributionService;
import com.peanut.modules.sys.service.SysDictDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
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 javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 湖分管理
@@ -173,8 +171,13 @@ public class UserContributionController {
level = "0.5星";
}
contribution.setLevel(level);
List<UserContribution> cs = contributionService.list(new LambdaQueryWrapper<UserContribution>()
.eq(UserContribution::getUserId,contribution.getUserId()));
MPJLambdaWrapper<UserContribution> mw = new MPJLambdaWrapper();
mw.leftJoin(SysDictDataEntity.class,SysDictDataEntity::getDictType,UserContribution::getType);
mw.selectAll(UserContribution.class);
mw.selectAs(SysDictDataEntity::getDictValue,"typeInfo");
mw.eq(UserContribution::getUserId,contribution.getUserId());
mw.eq(SysDictDataEntity::getDictLabel,"userContributionLabel");
List<UserContribution> cs = contributionService.list(mw);
if(params.containsKey("startTime")&&StringUtils.isNotEmpty(params.get("startTime").toString())){
BigDecimal statQueryScore = BigDecimal.ZERO;
for (UserContribution c:cs) {
@@ -192,38 +195,71 @@ public class UserContributionController {
}
@RequestMapping("/exportContributionStatQuery")
public void exportContributionStatQuery(HttpServletResponse response,@RequestBody Map<String, Object> params) throws Exception{
public void exportContributionStatQuery(HttpServletResponse response,@RequestBody Map<String, Object> params) throws Exception {
String fileName = "湖分统计查询.xlsx";
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName );
List<ContributionStatQuery> dataList = new ArrayList();
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
OutputStream outputStream = response.getOutputStream();
List<UserContribution> list = getStatQueryData(params).getRecords();
int i=0;
for (UserContribution userContribution:list) {
i++;
for (UserContribution c:userContribution.getContributions()){
ContributionStatQuery data = new ContributionStatQuery();
data.setNo(i);
data.setLevel(userContribution.getLevel());
data.setUserName(userContribution.getUserName());
data.setUserTel(userContribution.getUserTel());
data.setScore(userContribution.getScore());
SysDictDataEntity sysDictDataEntity = sysDictDataService.getOne(new LambdaQueryWrapper<SysDictDataEntity>()
.eq(SysDictDataEntity::getDictLabel,"userContributionLabel")
.eq(SysDictDataEntity::getDictType,c.getType()));
data.setContribution(sysDictDataEntity.getDictValue()+"-"+c.getDetail()+"("+c.getScore()+"分)");
dataList.add(data);
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
Row headerRow = sheet.createRow(0);// 创建表头行
Cell headerCell0 = headerRow.createCell(0);
headerCell0.setCellValue("序号");
Cell headerCell2 = headerRow.createCell(1);
headerCell2.setCellValue("姓名");
Cell headerCell3 = headerRow.createCell(2);
headerCell3.setCellValue("电话");
sheet.setColumnWidth(2,15*256);
Cell headerCell1 = headerRow.createCell(3);
headerCell1.setCellValue("星级");
Cell headerCell4 = headerRow.createCell(4);
headerCell4.setCellValue("湖分");
Cell headerCell5 = headerRow.createCell(5);
headerCell5.setCellValue("明细");
sheet.setColumnWidth(5,60*256);
// 填充数据
int no = 1;
int startI = 1;
int i = 1;
for (UserContribution userContribution : list) {
for (UserContribution c : userContribution.getContributions()) {
Row dataRow = sheet.createRow(i);
Cell dataCell0 = dataRow.createCell(0);
dataCell0.setCellStyle(cellStyle);
dataCell0.setCellValue(no);
Cell dataCell2 = dataRow.createCell(1);
dataCell2.setCellStyle(cellStyle);
dataCell2.setCellValue(userContribution.getUserName());
Cell dataCell3 = dataRow.createCell(2);
dataCell3.setCellStyle(cellStyle);
dataCell3.setCellValue(userContribution.getUserTel());
Cell dataCell1 = dataRow.createCell(3);
dataCell1.setCellStyle(cellStyle);
dataCell1.setCellValue(userContribution.getLevel());
Cell dataCell4 = dataRow.createCell(4);
dataCell4.setCellStyle(cellStyle);
dataCell4.setCellValue(userContribution.getScore().toString());
Cell dataCell5 = dataRow.createCell(5);
dataCell5.setCellValue(c.getTypeInfo() + "-" + c.getDetail() + "(" + c.getScore() + "分)");
i++;
}
// 合并单元格
sheet.addMergedRegion(new CellRangeAddress(startI, i+1, 0, 0));
sheet.addMergedRegion(new CellRangeAddress(startI, i+1, 1, 1));
sheet.addMergedRegion(new CellRangeAddress(startI, i+1, 2, 2));
sheet.addMergedRegion(new CellRangeAddress(startI, i+1, 3, 3));
sheet.addMergedRegion(new CellRangeAddress(startI, i+1, 4, 4));
startI = i+2;
no++;
}
EasyExcel.write(response.getOutputStream(), ContributionStatQuery.class)
.registerWriteHandler(new CustomMergeStrategy(dataList.stream().map(o -> o.getNo()+"").collect(Collectors.toList()), 0))
.registerWriteHandler(new CustomMergeStrategy(dataList.stream().map(o -> o.getUserName()).collect(Collectors.toList()), 2))
.registerWriteHandler(new CustomMergeStrategy(dataList.stream().map(o -> o.getUserTel()).collect(Collectors.toList()), 3))
.registerWriteHandler(new CustomMergeStrategy(dataList.stream().map(o -> o.getScore().toString()).collect(Collectors.toList()), 5))
.sheet("湖分统计查询")
.doWrite(dataList);
workbook.write(outputStream);
outputStream.close();
}
@RequestMapping("/saveUserContribution")