package cn.pluss.platform.export;

import cn.pluss.platform.mapper.BillStatisticsMapper;
import cn.pluss.platform.util.excel.ComplexExcelUtil;
import cn.pluss.platform.util.excel.model.Cell;
import cn.pluss.platform.util.excel.model.Row;
import cn.pluss.platform.vo.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Djh
 */
@Service
public class BillStatisticsServiceImpl implements BillStatisticsService {

    @Resource
    private BillStatisticsMapper billStatisticsMapper;

    @Override
    public XSSFWorkbook createBillStatisticsSheet(XSSFWorkbook workbook, String merchantCode, Date startDate, Date endDate) {
        if (workbook == null) {
            workbook = new XSSFWorkbook();
        }

        List<BillStatisticsVO> data = billStatisticsMapper.selectBillStatistics(merchantCode, startDate, endDate);
        ComplexExcelUtil.addData(workbook, "交易账单统计", data, new ComplexExcelUtil.Transformer<BillStatisticsVO>() {
            @Override
            public Row getHeader(XSSFWorkbook workbook, List<BillStatisticsVO> dataList) {
                List<Cell> cellList = new ArrayList<>();
                Cell cell = new Cell("账单名称", 0, 0);
                cellList.add(cell);
                cell = new Cell("起始时间", 1, 0);
                cellList.add(cell);
                cell = new Cell("截止时间", 2, 0);
                cellList.add(cell);
                cell = new Cell("结算类型", 3, 0);
                cellList.add(cell);
                cell = new Cell("收款方式", 4, 0);
                cellList.add(cell);
                cell = new Cell("订单笔数", 5, 0);
                cellList.add(cell);
                cell = new Cell("退款笔数", 6, 0);
                cellList.add(cell);
                cell = new Cell("实收金额", 7, 0);
                cellList.add(cell);
                cell = new Cell("优惠金额", 8, 0);
                cellList.add(cell);
                cell = new Cell("活动补贴", 9, 0);
                cellList.add(cell);
                cell = new Cell("手续费", 10, 0);
                cellList.add(cell);
                cell = new Cell("实际到账", 11, 0);
                cellList.add(cell);

                return new Row(cellList, 0, 0);
            }

            @Override
            public Row getRow(XSSFWorkbook workbook, BillStatisticsVO billStatisticsVO, int scaleCol, int scaleRow, int position) {
                int moveX = 0, moveY = 0;
                List<Cell> cellList = new ArrayList<>();
                // 账单名称
                Cell cell = new Cell(billStatisticsVO.getBillName(), moveX, moveY, 1, 4);
                moveX++;
                cellList.add(cell);
                // 起始时间
                cell = new Cell(billStatisticsVO.getStartDate(), moveX, moveY, 1, 4);
                moveX++;
                cellList.add(cell);
                // 截止时间
                cell = new Cell(billStatisticsVO.getEndDate(), moveX, moveY, 1, 4);
                moveX++;
                cellList.add(cell);
                // 结算类型
                cell = new Cell(billStatisticsVO.getMerchantChannelType(), moveX, moveY, 1, 4);
                moveX++;
                cellList.add(cell);
                // 收款方式
                // 微信
                cell = new Cell("微信", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell("支付宝", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell("银联", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell("总计", moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 订单笔数
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 退款笔数
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxRefundOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliRefundOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankRefundOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllRefundOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 实收金额
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);

                // 总计
                cell = new Cell(billStatisticsVO.getAllInMoney(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 优惠金额
                // 微信
                moveY = 0;
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 活动补贴
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxSubsidy(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliSubsidy(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankSubsidy(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllSubsidy(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 手续费
                // 微信
                moveY = 0;
                billStatisticsVO.setWxServiceCharge(billStatisticsVO.getWxInMoney().subtract(billStatisticsVO.getWxInAccount()));
                cell = new Cell(billStatisticsVO.getWxServiceCharge(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                billStatisticsVO.setAliServiceCharge(billStatisticsVO.getAliInMoney().subtract(billStatisticsVO.getAliInAccount()));
                cell = new Cell(billStatisticsVO.getAliServiceCharge(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                billStatisticsVO.setBankServiceCharge(billStatisticsVO.getBankInMoney().subtract(billStatisticsVO.getBankInAccount()));
                cell = new Cell(billStatisticsVO.getBankServiceCharge(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                billStatisticsVO.setAllServiceCharge(billStatisticsVO.getAllInMoney().subtract(billStatisticsVO.getAllInAccount()));
                cell = new Cell(billStatisticsVO.getAllServiceCharge(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 实际到账
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllInAccount(), moveX, moveY, 1, 1);
                cellList.add(cell);

                return new Row(cellList, scaleCol, scaleRow);
            }
        });

        return workbook;
    }

    @Override
    public XSSFWorkbook createBillListSheet(XSSFWorkbook workbook, String merchantCode, Date startDate, Date endDate) {
        if (workbook == null) {
            workbook = new XSSFWorkbook();
        }

        List<MerchantOrderExportVO> data = billStatisticsMapper.selectBillList(merchantCode, startDate, endDate);
        ComplexExcelUtil.addData(workbook, "交易账单明细", data, new ComplexExcelUtil.Transformer<MerchantOrderExportVO>() {
            @Override
            public Row getHeader(XSSFWorkbook workbook, List<MerchantOrderExportVO> dataList) {
                List<Cell> cellList = new ArrayList<>();
                Cell cell = new Cell("订单号", 0, 0);
                cellList.add(cell);
                cell = new Cell("第三方订单号", 1, 0);
                cellList.add(cell);
                cell = new Cell("退款订单号", 2, 0);
                cellList.add(cell);
                cell = new Cell("收款方式", 3, 0);
                cellList.add(cell);
                cell = new Cell("交易类型", 4, 0);
                cellList.add(cell);
                cell = new Cell("实收金额", 5, 0);
                cellList.add(cell);
                cell = new Cell("退款金额", 6, 0);
                cellList.add(cell);
                cell = new Cell("优惠金额", 7, 0);
                cellList.add(cell);
                cell = new Cell("活动补贴", 8, 0);
                cellList.add(cell);
                cell = new Cell("手续费", 9, 0);
                cellList.add(cell);
                cell = new Cell("实际到账", 10, 0);
                cellList.add(cell);
                cell = new Cell("收银员", 11, 0);
                cellList.add(cell);
                cell = new Cell("备注", 12, 0);
                cellList.add(cell);
                cell = new Cell("创建时间", 13, 0);
                cellList.add(cell);
                cell = new Cell("付款时间", 14, 0);
                cellList.add(cell);

                return new Row(cellList, 0, 0);
            }

            @Override
            public Row getRow(XSSFWorkbook workbook, MerchantOrderExportVO item, int scaleCol, int scaleRow, int position) {
                List<Cell> cellList = new ArrayList<>();
                cellList.add(new Cell(item.getOrderNumber(), 0, 0));
                cellList.add(new Cell(item.getThirdOrderNo(), 1, 0));
                cellList.add(new Cell(item.getRefundNo(), 2, 0));
                cellList.add(new Cell(item.getPayType(), 3, 0));
                cellList.add(new Cell(item.getOrderTypeDesc(), 4, 0));
                cellList.add(new Cell(item.getConsumeFee(), 5, 0));
                cellList.add(new Cell(item.getRefundFee(), 6, 0));
                cellList.add(new Cell(BigDecimal.ZERO, 7, 0));
                cellList.add(new Cell(item.getSubsidy(), 8, 0));
                cellList.add(new Cell(item.getServiceCharge(), 9, 0));
                cellList.add(new Cell(item.getEnterFee(), 10, 0));
                cellList.add(new Cell(item.getStaffName(), 11, 0));
                cellList.add(new Cell(item.getRemark(), 12, 0));
                cellList.add(new Cell(item.getCreateDt(), 13, 0));
                cellList.add(new Cell(item.getTransDt(), 14, 0));

                return new Row(cellList, scaleCol, scaleRow);
            }
        });

        return workbook;
    }

    @Override
    public XSSFWorkbook createMemberBillStatisticsSheet(XSSFWorkbook workbook, String merchantCode, Date startDate, Date endDate) {
        if (workbook == null) {
            workbook = new XSSFWorkbook();
        }

        List<MemberOrderStatisticsVO> data = billStatisticsMapper.selectMemberBillStatistics(merchantCode, startDate, endDate);
        // 此处对没有会员卡余额的记录进行处理
        for (int i = data.size() - 1; i >= 0; i--) {
            MemberOrderStatisticsVO item = data.get(i);
            if (i == data.size() - 1) {
                continue;
            }

            MemberOrderStatisticsVO itemNext = data.get(i + 1);
            if (item.getMemberBalance() == null) {
                item.setMemberBalance(itemNext.getMemberBalance());
            }
        }

        ComplexExcelUtil.addData(workbook, "会员账单统计", data, new ComplexExcelUtil.Transformer<MemberOrderStatisticsVO>() {
            @Override
            public Row getHeader(XSSFWorkbook workbook, List<MemberOrderStatisticsVO> dataList) {
                List<Cell> cellList = new ArrayList<>();
                Cell cell = new Cell("账单名称", 0, 0);
                cellList.add(cell);
                cell = new Cell("起始时间", 1, 0);
                cellList.add(cell);
                cell = new Cell("截止时间", 2, 0);
                cellList.add(cell);
                cell = new Cell("交易类型", 3, 0);
                cellList.add(cell);
                cell = new Cell("交易方式", 4, 0);
                cellList.add(cell);
                cell = new Cell("结算类型", 5, 0);
                cellList.add(cell);
                cell = new Cell("笔数", 6, 0);
                cellList.add(cell);
                cell = new Cell("充值/消费金额", 7, 0);
                cellList.add(cell);
                cell = new Cell("赠送/消费返金额", 8, 0);
                cellList.add(cell);
                cell = new Cell("会员卡总余额", 9, 0);
                cellList.add(cell);

                return new Row(cellList, 0, 0);
            }

            @Override
            public Row getRow(XSSFWorkbook workbook, MemberOrderStatisticsVO item, int scaleCol, int scaleRow, int position) {
                int moveX = 0, moveY = 0;
                List<Cell> cellList = new ArrayList<>();
                // 账单名称
                Cell cell = new Cell(item.getBillName(), moveX, moveY, 1, 6);
                moveX++;
                cellList.add(cell);
                // 起始时间
                cell = new Cell(item.getStartDate(), moveX, moveY, 1, 6);
                moveX++;
                cellList.add(cell);
                // 截止时间
                cell = new Cell(item.getEndDate(), moveX, moveY, 1, 6);
                moveX++;
                cellList.add(cell);
                // 交易类型
                // 充值
                cell = new Cell("充值", moveX, moveY, 1, 5);
                moveY += 5;
                cellList.add(cell);
                // 消费
                cell = new Cell("消费", moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);

                moveY = 0;
                // 交易方式
                // 微信
                cell = new Cell("微信", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell("支付宝", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell("银联", moveX, moveY, 1, 1);
                cellList.add(cell);
                moveY++;
                // 现金
                cell = new Cell("现金", moveX, moveY, 1, 1);
                cellList.add(cell);
                moveY++;
                // 总计
                cell = new Cell("总计", moveX, moveY, 1, 1);
                cellList.add(cell);
                moveY++;
                // 会员卡
                cell = new Cell("会员卡", moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                moveY = 0;
                // 结算类型
                // 备付金
                cell = new Cell(item.getMerchantChannelType(), moveX, moveY, 1, 3);
                cellList.add(cell);
                moveY += 3;

                cell = new Cell("现金", moveX, moveY, 1, 3);
                cellList.add(cell);
                moveX++;


                // 订单笔数
                // 微信
                moveY = 0;
                cell = new Cell(item.getWxOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(item.getAliOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(item.getBankOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(item.getInCashRechargeOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveY++;
                // 总计
                cell = new Cell(item.getRechargeOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveY++;
                // 会员卡
                cell = new Cell(item.getConsumeOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 充值/消费金额
                // 微信
                moveY = 0;
                cell = new Cell(item.getWxRechargeSum(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(item.getAliRechargeSum(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(item.getBankRechargeSum(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(item.getInCashRechargeSum(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(item.getRechargeSum(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveY++;
                // 会员卡
                cell = new Cell(item.getConsumeSum(), moveX, moveY);
                cellList.add(cell);
                moveX++;

                // 赠送/消费返金额
                // 微信
                moveY = 0;
                cell = new Cell(item.getWxGiveMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(item.getAliGiveMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(item.getBankGiveMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(item.getInCashRechargeGiveMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(item.getRechargeGiveMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(item.getConsumeGiveMoney(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 会员卡总余额
                // 微信
                moveY = 0;
                cell = new Cell(item.getMemberBalance() == null? "-": item.getMemberBalance(), moveX, moveY, 1, 6);
                cellList.add(cell);

                return new Row(cellList, scaleCol, scaleRow);
            }
        });

        return workbook;
    }

    @Override
    public XSSFWorkbook createMemberBillListSheet(XSSFWorkbook workbook, String merchantCode, Date startDate, Date endDate) {
        if (workbook == null) {
            workbook = new XSSFWorkbook();
        }

        List<MemberOrderVO> data = billStatisticsMapper.selectMemberBillList(merchantCode, startDate, endDate);
        ComplexExcelUtil.addData(workbook, "会员账单明细", data, new ComplexExcelUtil.Transformer<MemberOrderVO>() {
            @Override
            public Row getHeader(XSSFWorkbook workbook, List<MemberOrderVO> dataList) {
                List<Cell> cellList = new ArrayList<>();
                Cell cell = new Cell("订单号", 0, 0);
                cellList.add(cell);
                cell = new Cell("第三方订单号", 1, 0);
                cellList.add(cell);
                cell = new Cell("会员名称", 2, 0);
                cellList.add(cell);
                cell = new Cell("会员手机号", 3, 0);
                cellList.add(cell);
                cell = new Cell("收款方式", 4, 0);
                cellList.add(cell);
                cell = new Cell("交易类型", 5, 0);
                cellList.add(cell);
                cell = new Cell("充值/消费金额", 6, 0);
                cellList.add(cell);
                cell = new Cell("手续费", 7, 0);
                cellList.add(cell);
                cell = new Cell("现金到账", 8, 0);
                cellList.add(cell);
                cell = new Cell("银行卡到账", 9, 0);
                cellList.add(cell);
                cell = new Cell("赠送金额", 10, 0);
                cellList.add(cell);
                cell = new Cell("剩余金额", 11, 0);
                cellList.add(cell);
                cell = new Cell("收银员", 12, 0);
                cellList.add(cell);
                cell = new Cell("备注", 13, 0);
                cellList.add(cell);
                cell = new Cell("创建时间", 14, 0);
                cellList.add(cell);
                cell = new Cell("付款时间", 15, 0);
                cellList.add(cell);

                return new Row(cellList, 0, 0);
            }

            @Override
            public Row getRow(XSSFWorkbook workbook, MemberOrderVO item, int scaleCol, int scaleRow, int position) {
                int moveX = 0, moveY = 0;
                List<Cell> cellList = new ArrayList<>();
                // 订单号
                Cell cell = new Cell(item.getOrderNumber(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 第三方订单号
                cell = new Cell(item.getThirdOrderNo(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 会员名称
                cell = new Cell(item.getNickName(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 会员手机号
                cell = new Cell(item.getPhone(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 收款方式
                cell = new Cell(item.getPayType(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 交易类型
                cell = new Cell(item.getOrderType(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 充值金额
                cell = new Cell(item.getOrderFee(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 手续费
                cell = new Cell(item.getServiceRecharge(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 现金到账
                cell = new Cell(item.getInCashMoney(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 银行卡到账
                cell = new Cell(item.getCardMoney(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
//                // 消费金额
//                cell = new Cell(item.getConsumeFee(), moveX, moveY, 1, 1);
//                moveX++;
//                cellList.add(cell);
                // 赠送金额
                cell = new Cell(item.getGiveMoney(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 剩余金额
                cell = new Cell(item.getMemberBalance(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 收银员
                cell = new Cell(item.getStaffName(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 备注
                cell = new Cell(item.getRemark(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 生成时间
                cell = new Cell(item.getCreateDt(), moveX, moveY, 1, 1);
                moveX++;
                cellList.add(cell);
                // 付款时间
                cell = new Cell(item.getTransDt(), moveX, moveY, 1, 1);
                cellList.add(cell);

                return new Row(cellList, scaleCol, scaleRow);
            }
        });

        return workbook;
    }

    @Override
    public XSSFWorkbook createStaffBillStatisticsSheet(XSSFWorkbook workbook, String merchantCode, Date startDate, Date endDate) {
        if (workbook == null) {
            workbook = new XSSFWorkbook();
        }

        List<BillStatisticsVO> data = billStatisticsMapper.selectStaffBillStatistics(merchantCode, startDate, endDate);
        ComplexExcelUtil.addData(workbook, "员工账单统计", data, new ComplexExcelUtil.Transformer<BillStatisticsVO>() {
            @Override
            public Row getHeader(XSSFWorkbook workbook, List<BillStatisticsVO> dataList) {
                List<Cell> cellList = new ArrayList<>();
                Cell cell = new Cell("账单名称", 0, 0);
                cellList.add(cell);
                cell = new Cell("起始时间", 1, 0);
                cellList.add(cell);
                cell = new Cell("截止时间", 2, 0);
                cellList.add(cell);
                cell = new Cell("结算类型", 3, 0);
                cellList.add(cell);
                cell = new Cell("收款方式", 4, 0);
                cellList.add(cell);
                cell = new Cell("订单笔数", 5, 0);
                cellList.add(cell);
                cell = new Cell("退款笔数", 6, 0);
                cellList.add(cell);
                cell = new Cell("实收金额", 7, 0);
                cellList.add(cell);
                cell = new Cell("优惠金额", 8, 0);
                cellList.add(cell);
                cell = new Cell("活动补贴", 9, 0);
                cellList.add(cell);
                cell = new Cell("手续费", 10, 0);
                cellList.add(cell);
                cell = new Cell("实际到账", 11, 0);
                cellList.add(cell);

                return new Row(cellList, 0, 0);
            }

            @Override
            public Row getRow(XSSFWorkbook workbook, BillStatisticsVO billStatisticsVO, int scaleCol, int scaleRow, int position) {
                int moveX = 0, moveY = 0;
                List<Cell> cellList = new ArrayList<>();
                // 账单名称
                Cell cell = new Cell(billStatisticsVO.getBillName(), moveX, moveY, 1, 5);
                moveX++;
                cellList.add(cell);
                // 起始时间
                cell = new Cell(billStatisticsVO.getStartDate(), moveX, moveY, 1, 5);
                moveX++;
                cellList.add(cell);
                // 截止时间
                cell = new Cell(billStatisticsVO.getEndDate(), moveX, moveY, 1, 5);
                moveX++;
                cellList.add(cell);
                // 结算类型
                // 备付金
                cell = new Cell(billStatisticsVO.getMerchantChannelType(), moveX, moveY, 1, 3);
                moveY += 3;
                cellList.add(cell);
                // 空
                cell = new Cell("", moveX, moveY, 1, 2);
                moveX++;
                cellList.add(cell);


                // 收款方式
                moveY = 0;
                // 微信
                cell = new Cell("微信", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell("支付宝", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell("银联", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell("现金", moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell("总计", moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 订单笔数
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(billStatisticsVO.getInCashOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 退款笔数
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxRefundOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliRefundOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankRefundOrderCount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(0, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllRefundOrderCount(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 实收金额
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(billStatisticsVO.getInCashInMoney(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllInMoney(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 优惠金额
                // 微信
                moveY = 0;
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 活动补贴
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxSubsidy(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliSubsidy(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankSubsidy(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllSubsidy(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 手续费
                // 微信
                moveY = 0;
                billStatisticsVO.setWxServiceCharge(billStatisticsVO.getWxInMoney().subtract(billStatisticsVO.getWxInAccount()));
                cell = new Cell(billStatisticsVO.getWxServiceCharge(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                billStatisticsVO.setAliServiceCharge(billStatisticsVO.getAliInMoney().subtract(billStatisticsVO.getAliInAccount()));
                cell = new Cell(billStatisticsVO.getAliServiceCharge(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                billStatisticsVO.setBankServiceCharge(billStatisticsVO.getBankInMoney().subtract(billStatisticsVO.getBankInAccount()));
                cell = new Cell(billStatisticsVO.getBankServiceCharge(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(BigDecimal.ZERO, moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                billStatisticsVO.setAllServiceCharge(billStatisticsVO.getAllInMoney().subtract(billStatisticsVO.getAllInAccount()));
                cell = new Cell(billStatisticsVO.getAllServiceCharge(), moveX, moveY, 1, 1);
                cellList.add(cell);
                moveX++;

                // 实际到账
                // 微信
                moveY = 0;
                cell = new Cell(billStatisticsVO.getWxInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 支付宝
                cell = new Cell(billStatisticsVO.getAliInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 银联
                cell = new Cell(billStatisticsVO.getBankInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 现金
                cell = new Cell(billStatisticsVO.getInCashInAccount(), moveX, moveY, 1, 1);
                moveY++;
                cellList.add(cell);
                // 总计
                cell = new Cell(billStatisticsVO.getAllInAccount(), moveX, moveY, 1, 1);
                cellList.add(cell);

                return new Row(cellList, scaleCol, scaleRow);
            }
        });

        return workbook;
    }
}
