/**
* 用户列表导出详情
*/
@ApiOperation("用户列表导出详情")
@GetMapping(value = "/userExport")
public ResultMessageVo userExport(Long id, HttpServletResponse response) {
return userService.userExport(id, response);
}
@Override
public ResultMessageVo userExport(Long id, HttpServletResponse response) {
String[] title = {"订单编号", "id", "金额", "手续费", "实际到账", "说明", "订单时间", "是否禁用启用"};
// 创建Excel工作部
HSSFWorkbook workbook = new HSSFWorkbook();
// 创建一个工作表sheet1
HSSFSheet sheet = workbook.createSheet();
workbook.setSheetName(0, "订单表");
// 创建第一行
HSSFRow row = sheet.createRow(0);
HSSFCell cell = null;
// 把第一行的excel数据插入,坐表头
for (int i = 0; i < title.length; i++) {
cell = row.createCell(i);
cell.setCellValue(title[i]);
}
// 这里是数据库里查出来的数据
// 第二处改点
List<OrderMo> orderMoList =
orderService.selectList(Wrappers.<OrderMo>query().lambda().eq(OrderMo::getId, id));
// 把数据一个一个添加到sheet1中
// 第三处改点 改掉list中的元素属性就可以了
for (int i = 1; i <= orderMoList.size(); i++) {
HSSFRow nexTrow = sheet.createRow(i);
HSSFCell cell1 = nexTrow.createCell(0);
cell1.setCellValue(orderMoList.get(i - 1).getOrderNo()); // list对象中第一个属性对应
cell1 = nexTrow.createCell(1);
cell1.setCellValue(orderMoList.get(i - 1).getId()); // list对象中第二个属性对应
cell1 = nexTrow.createCell(2);
cell1.setCellValue(String.valueOf(orderMoList.get(i - 1).getAmount())); // list对象中第三个属性对应
cell1 = nexTrow.createCell(3);
cell1.setCellValue(String.valueOf(orderMoList.get(i - 1).getUsedFee())); // list对象中第四个属性对应
cell1 = nexTrow.createCell(4);
cell1.setCellValue(String.valueOf(orderMoList.get(i - 1).getReAmount())); // list对象中第五个属性对应
cell1 = nexTrow.createCell(5);
cell1.setCellValue(orderMoList.get(i - 1).getRemark()); // list对象中第六个属性对应
cell1 = nexTrow.createCell(6);
cell1.setCellValue(
DateUtil.toString(orderMoList.get(i - 1).getCreateTime(), DateUtil.STANDARD_FORMAT));
cell1 = nexTrow.createCell(7);
if (orderMoList.get(i - 1).getDeleteFlag() == 0) {
cell1.setCellValue("启用");
} else {
cell1.setCellValue("禁用");
}
}
// 红包订单列表
String[] title4 = {"交易订单编号", "红包发送人地址", "红包接收人地址", "类型", "红包金额", "状态", "时间"};
HSSFSheet sheet4 = workbook.createSheet();
workbook.setSheetName(4, "红包订单列表");
HSSFRow row4 = sheet4.createRow(0);
HSSFCell cellRedOrder = null;
// 把第一行的excel数据插入,坐表头
for (int i = 0; i < title4.length; i++) {
cellRedOrder = row4.createCell(i);
cellRedOrder.setCellValue(title4[i]);
}
List<RedOrderMo> redOrderMos =
redOrderMapper.selectList(Wrappers.<redOrderMo>query().lambda().and(
wrapper -> wrapper.eq(redOrderMo::getFromId, id).or().eq(redOrderMo::getToId, id)));
for (int i = 1; i <= redOrderMos.size(); i++) {
HSSFRow nexTrow = sheet4.createRow(i);
HSSFCell cell1 = nexTrow.createCell(0);
cell1.setCellValue(redOrderMos.get(i - 1).getTranHash());
cell1 = nexTrow.createCell(1);
cell1.setCellValue(redOrderMos.get(i - 1).getFromAddress());
cell1 = nexTrow.createCell(2);
cell1.setCellValue(redOrderMos.get(i - 1).getToAddress());
cell1 = nexTrow.createCell(3);
if (id.equals(redOrderMos.get(i - 1).getFromId())) {
cell1.setCellValue("发送");
} else {
cell1.setCellValue("接收");
}
cell1 = nexTrow.createCell(4);
cell1.setCellValue(redOrderMos.get(i - 1).getAmount().stripTrailingZeros().toPlainString());
cell1 = nexTrow.createCell(5);
if (redOrderMos.get(i - 1).getStatus() == 0) {
cell1.setCellValue("未接收");
} else {
cell1.setCellValue("已接收");
}
cell1 = nexTrow.createCell(6);
cell1.setCellValue(
DateUtil.toString(redOrderMos.get(i - 1).getCreateTime(), DateUtil.STANDARD_FORMAT));
}
try {
response.setContentType("application/octet-stream");
String fname = "用户详情清单.xlsx";
response.setHeader("content-type", "application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fname, "UTF-8") + ";"
+ "filename*=utf-8''" + URLEncoder.encode(fname, "UTF-8"));// 设置文件名
OutputStream os = response.getOutputStream();
workbook.write(os);
os.flush();
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
return ResultUtil.success();
}