|
|
@@ -23,6 +23,7 @@ import com.yami.shop.bean.event.ReceiptOrderEvent;
|
|
|
import com.yami.shop.bean.model.*;
|
|
|
import com.yami.shop.bean.param.*;
|
|
|
import com.yami.shop.bean.pay.RefundInfoDto;
|
|
|
+import com.yami.shop.bean.vo.OrderRefundSkuVo;
|
|
|
import com.yami.shop.bean.vo.OrderRefundVo;
|
|
|
import com.yami.shop.common.config.Constant;
|
|
|
import com.yami.shop.common.enums.PayType;
|
|
|
@@ -34,15 +35,22 @@ import com.yami.shop.common.util.hb.HBR;
|
|
|
import com.yami.shop.dao.*;
|
|
|
import com.yami.shop.service.*;
|
|
|
import com.yami.shop.service.hb.impl.HBOrderService;
|
|
|
+import com.yami.shop.utils.ExportUtils;
|
|
|
import com.yami.shop.utils.HBSignUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import ma.glasnost.orika.MapperFacade;
|
|
|
+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.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -56,7 +64,7 @@ public class OrderRefundServiceImpl extends ServiceImpl<OrderRefundMapper, Order
|
|
|
private final OrderRefundMapper orderRefundMapper;
|
|
|
|
|
|
private final OrderRefundRecordMapper orderRefundRecordMapper;
|
|
|
-
|
|
|
+ private final OrderRefundSkuMapper orderRefundskuMapper;
|
|
|
private final OrderService orderService;
|
|
|
private final ProductService productService;
|
|
|
private final SkuService skuService;
|
|
|
@@ -1294,6 +1302,242 @@ public class OrderRefundServiceImpl extends ServiceImpl<OrderRefundMapper, Order
|
|
|
public OrderRefundVo selectInfoById(Long refundId) {
|
|
|
return orderRefundMapper.selectInfoById(refundId);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 导出正常订单
|
|
|
+ * @param orderRefund
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void export(OrderRefundStaisticsParam orderRefund, HttpServletResponse response) {
|
|
|
+
|
|
|
+ List<OrderRefundVo> orderRefundList= orderRefundMapper.findOrderRefund(orderRefund);
|
|
|
+ for (OrderRefundVo record : orderRefundList) {
|
|
|
+ record.setOrderRefundSkuList(orderRefundskuMapper.selectByRefundId(record.getRefundId()));
|
|
|
+ }
|
|
|
+ if (orderRefundList.isEmpty()){
|
|
|
+ throw new GlobalException("该次导出未查询到数据,不允许导出");
|
|
|
+ }
|
|
|
+ exportNormalOrders(orderRefundList,response,"退款订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出正常订单数据到Excel(直接输出到HttpServletResponse)
|
|
|
+ */
|
|
|
+ public void exportNormalOrders(List<OrderRefundVo> 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); // 订单类型
|
|
|
+ sheet.setColumnWidth(7, 20 * 256); // 退款商品名称
|
|
|
+ sheet.setColumnWidth(8, 10 * 256); // 规格
|
|
|
+ sheet.setColumnWidth(9, 8 * 256); // 购买单价(元)
|
|
|
+ sheet.setColumnWidth(10, 10 * 256); // 退款数量
|
|
|
+ sheet.setColumnWidth(11, 12 * 256); // 小计(元)
|
|
|
+ sheet.setColumnWidth(12, 12 * 256); // 退款商品总数量
|
|
|
+ sheet.setColumnWidth(13, 8 * 256); // 退款总金额(元)
|
|
|
+ sheet.setColumnWidth(14, 12 * 256); // 退还现金(元)
|
|
|
+ sheet.setColumnWidth(15, 10 * 256); // 退还积分(元)
|
|
|
+ sheet.setColumnWidth(16, 15 * 256); // 退还积分中过期积分(分)
|
|
|
+ sheet.setColumnWidth(17, 15 * 256); // 所属企业
|
|
|
+ sheet.setColumnWidth(18, 10 * 256); // 买家姓名
|
|
|
+ sheet.setColumnWidth(19, 15 * 256); // 买家电话
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充订单数据
|
|
|
+ */
|
|
|
+ private void fillOrderData(Sheet sheet, List<OrderRefundVo> orderList,
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
|
|
|
+ int rowNum = 2; // 从第3行开始(0-based索引)
|
|
|
+ int indexNum= 1; //序号
|
|
|
+ for (OrderRefundVo orderRefundVo : orderList) {
|
|
|
+ Row row = sheet.createRow(rowNum++);
|
|
|
+ row.setHeightInPoints(18);
|
|
|
+ // 序号
|
|
|
+ ExportUtils.createCell(sheet,row, 0,orderRefundVo.getOrderRefundSkuList().size(),rowNum, indexNum, dataStyle);
|
|
|
+ fillOrderRowData(sheet,rowNum,row, orderRefundVo, dataStyle, numberStyle, dateStyle);
|
|
|
+ rowNum+=orderRefundVo.getOrderRefundSkuList().size()-1;
|
|
|
+ indexNum++;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 填充单行订单数据
|
|
|
+ */
|
|
|
+ private void fillOrderRowData(Sheet sheet,int rowNum,Row row, OrderRefundVo orderRefundVo,
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle, CellStyle dateStyle) {
|
|
|
+
|
|
|
+ // 订单编号
|
|
|
+ ExportUtils.createCell(sheet,row, 1,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getOrderNumber(), dataStyle);
|
|
|
+
|
|
|
+ // 退款编号
|
|
|
+ ExportUtils.createCell(sheet,row, 2,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getRefundSn(), dateStyle);
|
|
|
+
|
|
|
+ // 申请时间
|
|
|
+ ExportUtils.createCell(sheet,row, 3,orderRefundVo.getOrderRefundSkuList().size(),rowNum, ExportUtils.formatDate(orderRefundVo.getApplyTime()), dateStyle);
|
|
|
+
|
|
|
+ // 申请方式
|
|
|
+ ExportUtils.createCell(sheet,row, 4,orderRefundVo.getOrderRefundSkuList().size(),rowNum,getApplyType(orderRefundVo.getApplyType()), dataStyle);
|
|
|
+
|
|
|
+ // 售后状态
|
|
|
+ ExportUtils.createCell(sheet,row, 5,orderRefundVo.getOrderRefundSkuList().size(),rowNum, getReturnMoneySts(orderRefundVo.getReturnMoneySts()), dataStyle);
|
|
|
+ // 订单类型
|
|
|
+ ExportUtils.createCell(sheet,row, 6,orderRefundVo.getOrderRefundSkuList().size(),rowNum, getDvyType(orderRefundVo.getDvyType()), dataStyle);
|
|
|
+ // 商品明细行(每个订单项一行)
|
|
|
+ fillOrderItems(sheet, rowNum, row, orderRefundVo, dataStyle, numberStyle);
|
|
|
+
|
|
|
+ // 退款商品总数量
|
|
|
+ ExportUtils.createCell(sheet,row, 12,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getGoodsNum(), numberStyle);
|
|
|
+
|
|
|
+ // 退款总金额(元)
|
|
|
+ ExportUtils.createCell(sheet,row, 13,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getRefundTotalMoney(), numberStyle);
|
|
|
+
|
|
|
+ // 退还现金(元)
|
|
|
+ ExportUtils.createCell(sheet,row, 14,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getRefundAmount(), numberStyle);
|
|
|
+
|
|
|
+ // 退还积分(元)
|
|
|
+ ExportUtils.createCell(sheet,row,15,orderRefundVo.getOrderRefundSkuList().size(),rowNum,"-"+(orderRefundVo.getOffsetPoints()==null?0:Arith.div(Double.valueOf(orderRefundVo.getOffsetPoints()), 100)), numberStyle);
|
|
|
+
|
|
|
+ // 退还积分中过期积分(分)
|
|
|
+ ExportUtils.createCell(sheet,row, 16,orderRefundVo.getOrderRefundSkuList().size(),rowNum, (orderRefundVo.getRefundExpiredScore()==null?0:orderRefundVo.getRefundExpiredScore()), numberStyle);
|
|
|
+
|
|
|
+ // 所属企业
|
|
|
+ ExportUtils.createCell(sheet,row, 17,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getChannelName(), dataStyle);
|
|
|
+
|
|
|
+ // 买家姓名
|
|
|
+ ExportUtils.createCell(sheet,row, 18,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getReceiver(), dataStyle);
|
|
|
+
|
|
|
+ // 买家电话
|
|
|
+ ExportUtils.createCell(sheet,row, 19,orderRefundVo.getOrderRefundSkuList().size(),rowNum, orderRefundVo.getBuyerMobile(), dataStyle);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 填充订单项明细
|
|
|
+ */
|
|
|
+ private void fillOrderItems(Sheet sheet, int rowNum, Row row, OrderRefundVo orderRefundVo,
|
|
|
+ CellStyle dataStyle, CellStyle numberStyle) {
|
|
|
+ int itemSize = orderRefundVo.getOrderRefundSkuList().size();
|
|
|
+
|
|
|
+ for (int i = 0; i < itemSize; i++) {
|
|
|
+ Row currentRow = (i < 1) ? row : sheet.createRow(rowNum + (i-1));
|
|
|
+ OrderRefundSkuVo orderRefundSkuVo = orderRefundVo.getOrderRefundSkuList().get(i);
|
|
|
+ // 退款商品名称
|
|
|
+ ExportUtils.createCell(sheet, currentRow, 7, 0, rowNum, orderRefundSkuVo.getProdName(), dataStyle);
|
|
|
+
|
|
|
+ // 规格
|
|
|
+ ExportUtils.createCell(sheet, currentRow, 8, 0, rowNum, orderRefundSkuVo.getSpec(), dataStyle);
|
|
|
+
|
|
|
+ // 购买单价(元)
|
|
|
+ ExportUtils.createCell(sheet, currentRow, 9, 0, rowNum, orderRefundSkuVo.getSkuPrice(), numberStyle);
|
|
|
+
|
|
|
+ // 退款数量
|
|
|
+ ExportUtils.createCell(sheet, currentRow, 10, 0, rowNum, orderRefundSkuVo.getProductCount(), dataStyle);
|
|
|
+
|
|
|
+ // 小计(元)
|
|
|
+ ExportUtils.createCell(sheet, currentRow, 11, 0, rowNum,(Arith.multiply(orderRefundSkuVo.getProductCount(),orderRefundSkuVo.getSkuPrice(),2)), numberStyle);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *海博订单状态
|
|
|
+ * @param status
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getReturnMoneySts(Integer status) {
|
|
|
+ switch (status) {
|
|
|
+ case 10: return "待审核";
|
|
|
+ case 20: return "处理中";
|
|
|
+ case 30: return "驳回退款";
|
|
|
+ case 40: return "撤销退款";
|
|
|
+ case 60: return "待退货(一审同意)";
|
|
|
+ case 65: return "待确认收货(二审待审核)";
|
|
|
+ case 70: return "退款完成";
|
|
|
+ default: return "未知状态";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 订单类型
|
|
|
+ * @param dvyType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getDvyType(Integer dvyType) {
|
|
|
+ switch (dvyType) {
|
|
|
+ case 1: return "快递";
|
|
|
+ case 2: return "自提";
|
|
|
+ case 3: return "及时配送";
|
|
|
+ default: return "未知类型";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 订单类型
|
|
|
+ * @param applyType
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getApplyType(Integer applyType) {
|
|
|
+ switch (applyType) {
|
|
|
+ case 1: return "仅退款";
|
|
|
+ case 2: return "退货退款";
|
|
|
+ case 5: return "差价退款";
|
|
|
+ default: return "未知类型";
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|