|
@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.yami.shop.bean.model.*;
|
|
import com.yami.shop.bean.model.*;
|
|
|
|
|
+import com.yami.shop.bean.po.EnterpriseUserPo;
|
|
|
|
|
+import com.yami.shop.bean.vo.EnterpriseUserVo;
|
|
|
import com.yami.shop.bean.vo.PointsRechargeVO;
|
|
import com.yami.shop.bean.vo.PointsRechargeVO;
|
|
|
import com.yami.shop.common.exception.GlobalException;
|
|
import com.yami.shop.common.exception.GlobalException;
|
|
|
import com.yami.shop.common.util.CommonUtils;
|
|
import com.yami.shop.common.util.CommonUtils;
|
|
@@ -15,8 +17,15 @@ import com.yami.shop.dao.*;
|
|
|
import com.yami.shop.service.PointsFailureRecordService;
|
|
import com.yami.shop.service.PointsFailureRecordService;
|
|
|
import com.yami.shop.service.PointsRechargeService;
|
|
import com.yami.shop.service.PointsRechargeService;
|
|
|
import com.yami.shop.service.PointsRecordService;
|
|
import com.yami.shop.service.PointsRecordService;
|
|
|
|
|
+import com.yami.shop.utils.ExportUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
@@ -212,4 +221,126 @@ public class PointsRechargeServiceImpl extends ServiceImpl<PointsRechargeMapper,
|
|
|
|
|
|
|
|
return page;
|
|
return page;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导出积分
|
|
|
|
|
+ * @param pointsRecharge
|
|
|
|
|
+ * @param response
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void export(PointsRecharge pointsRecharge, HttpServletResponse response) {
|
|
|
|
|
+ List<PointsRecharge> enterpriseUserVos= pointsRechargeMapper.selectList(new LambdaQueryWrapper<PointsRecharge>()
|
|
|
|
|
+ .in(PointsRecharge::getChannelId,pointsRecharge.getChannelIdList())
|
|
|
|
|
+ .eq(ObjectUtils.isNotEmpty(pointsRecharge.getUserPhone()),PointsRecharge::getUserPhone,pointsRecharge.getUserPhone())
|
|
|
|
|
+ .orderByDesc(PointsRecharge::getCreateTime));
|
|
|
|
|
+ if (enterpriseUserVos.isEmpty()){
|
|
|
|
|
+ throw new GlobalException("该次导出未查询到数据,不允许导出");
|
|
|
|
|
+ }
|
|
|
|
|
+ exportNormalOrders(enterpriseUserVos,response,"积分列表");
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 导出正常订单数据到Excel(直接输出到HttpServletResponse)
|
|
|
|
|
+ */
|
|
|
|
|
+ public void exportNormalOrders(List<PointsRecharge> orderList,
|
|
|
|
|
+ HttpServletResponse response,
|
|
|
|
|
+ String fileName) {
|
|
|
|
|
+ // 设置响应头
|
|
|
|
|
+ ExportUtils.setupResponse(response, fileName);
|
|
|
|
|
+
|
|
|
|
|
+ try (Workbook workbook = new XSSFWorkbook()) {
|
|
|
|
|
+ // 创建Sheet
|
|
|
|
|
+ Sheet sheet = workbook.createSheet("积分列表");
|
|
|
|
|
+
|
|
|
|
|
+ // 设置列宽
|
|
|
|
|
+ setupColumnWidth(sheet);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建表头样式
|
|
|
|
|
+ CellStyle headerStyle = ExportUtils.createHeaderStyle(workbook);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建数据样式
|
|
|
|
|
+ CellStyle dataStyle = ExportUtils.createDataStyle(workbook);
|
|
|
|
|
+ CellStyle numberStyle = ExportUtils.createNumberStyle(workbook);
|
|
|
|
|
+ CellStyle dateStyle = ExportUtils.createDateStyle(workbook);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ String[] headers = {
|
|
|
|
|
+ "序号","所属企业", "员工姓名", "员工手机号", "充值积分", "过期时间",
|
|
|
|
|
+ "创建时间"
|
|
|
|
|
+ };
|
|
|
|
|
+ // 创建合并单元格的表头
|
|
|
|
|
+ ExportUtils.createMergedHeader(sheet, headerStyle,"积分列表");
|
|
|
|
|
+
|
|
|
|
|
+ // 创建列标题行
|
|
|
|
|
+ ExportUtils.createColumnHeaders(sheet, headerStyle,headers);
|
|
|
|
|
+
|
|
|
|
|
+ // 填充数据
|
|
|
|
|
+ fillOrderData(sheet, orderList, dataStyle, numberStyle, dateStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 写入响应流
|
|
|
|
|
+ workbook.write(response.getOutputStream());
|
|
|
|
|
+ response.getOutputStream().flush();
|
|
|
|
|
+
|
|
|
|
|
+ log.info("订单导出成功,文件:{},记录数:{}", fileName, orderList.size());
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("订单导出失败", e);
|
|
|
|
|
+ throw new RuntimeException("导出失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置列宽
|
|
|
|
|
+ */
|
|
|
|
|
+ private void setupColumnWidth(Sheet sheet) {
|
|
|
|
|
+ // 根据模板设置列宽(单位:1/256字符宽度)
|
|
|
|
|
+ sheet.setColumnWidth(0, 12 * 256); // 序号
|
|
|
|
|
+ sheet.setColumnWidth(1, 12 * 256); // 所属企业
|
|
|
|
|
+ sheet.setColumnWidth(2, 18 * 256); // 员工姓名
|
|
|
|
|
+ sheet.setColumnWidth(3, 18 * 256); // 员工手机号
|
|
|
|
|
+ sheet.setColumnWidth(4, 10 * 256); // 充值积分
|
|
|
|
|
+ sheet.setColumnWidth(5, 8 * 256); // 过期时间
|
|
|
|
|
+ sheet.setColumnWidth(6, 25 * 256); // 创建时间
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 填充订单数据
|
|
|
|
|
+ */
|
|
|
|
|
+ private void fillOrderData(Sheet sheet, List<PointsRecharge> orderList,
|
|
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
|
|
|
|
|
+ int rowNum = 2; // 从第3行开始(0-based索引)
|
|
|
|
|
+ int indexNum= 1; //序号
|
|
|
|
|
+ for (PointsRecharge enterpriseUserVo : orderList) {
|
|
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
|
|
+ row.setHeightInPoints(18);
|
|
|
|
|
+ // 序号
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 0,0,0, indexNum, dataStyle);
|
|
|
|
|
+ fillOrderRowData(sheet,row, enterpriseUserVo, dataStyle, numberStyle, dateStyle);
|
|
|
|
|
+ indexNum++;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 填充单行订单数据
|
|
|
|
|
+ */
|
|
|
|
|
+ private void fillOrderRowData(Sheet sheet,Row row, PointsRecharge orderRefundVo,
|
|
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
|
|
|
|
|
+ // 所属企业
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 1,0,0, orderRefundVo.getChannelName(), dataStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 员工姓名
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 2,0,0, orderRefundVo.getUserName(), dateStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 员工手机号
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 3,0,0, orderRefundVo.getUserPhone(), dateStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 充值积分
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 4,0,0,orderRefundVo.getPoints(), numberStyle);
|
|
|
|
|
+
|
|
|
|
|
+ // 过期时间
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 5,0,0, ExportUtils.formatDate(orderRefundVo.getCreateTime()), dateStyle);
|
|
|
|
|
+ // 创建时间
|
|
|
|
|
+ ExportUtils.createCell(sheet,row, 6,0,0, ExportUtils.formatDate(orderRefundVo.getExpiryDate()), dateStyle);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|