package com.gree.mall.manager.logic.material.report;

import cn.hutool.core.collection.CollectionUtil;
import com.gree.mall.manager.bean.ExcelData;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.bean.material.report.*;
import com.gree.mall.manager.commonmapper.MaterialMapper;
import com.gree.mall.manager.enums.IsYesNoEnum;
import com.gree.mall.manager.enums.base.BaseEnum;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.plus.entity.AdminModule;
import com.gree.mall.manager.plus.entity.AdminUserModuleRela;
import com.gree.mall.manager.plus.service.AdminModuleService;
import com.gree.mall.manager.plus.service.AdminUserModuleRelaService;
import com.gree.mall.manager.utils.DateUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
public class ReportLogic {

    private final CommonLogic commonLogic;
    private final MaterialMapper materialMapper;
    private final AdminModuleService adminModuleService;
    private final AdminUserModuleRelaService adminUserModuleRelaService;


    public List<MaterialSalesSumBean> workerBuySum(String startTime, String endTime, String month, String websitId,
                                                   String workerMobile, String workerId, String workerName) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        if (StringUtils.isNotBlank(month)) {
            String[] monthDateTime = computeMonthDateTime(month);
            startTime = monthDateTime[0];
            endTime = monthDateTime[1];
        }
        return materialMapper.workerBuySum(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
            Date startMonth = DateUtils.getStartMonth();
            return DateUtils.formatDate(startMonth);
        }), Optional.ofNullable(endTime).orElseGet(() -> {
            Date endMonth = DateUtils.getEndMonth();
            return DateUtils.formatDate(endMonth);
        }), websits, websitId, workerMobile, workerId, workerName);
    }

    private String[] computeMonthDateTime(String month) throws RemoteServiceException {
        try {
            String startDate = String.format("%s-01 00:00:00", month);
            Date date = DateUtils.parseDate(startDate);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
            String endDate = DateUtils.formatDate1(cal.getTime()) + " 23:59:59";
            return new String[] { startDate, endDate };
        } catch (ParseException e) {
            log.error("computeMonthDateTime() 月份转换出错", e);
            throw new RemoteServiceException("月份转换出错");
        }
    }

    public List<MaterialSalesSumDetailBean> workerBuySumDetail(String startTime, String endTime, String month,
                                                               String websitId, String workerMobile) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        if (StringUtils.isNotBlank(month)) {
            String[] monthDateTime = computeMonthDateTime(month);
            startTime = monthDateTime[0];
            endTime = monthDateTime[1];
        }
        return materialMapper.workerBuyDetail(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
            Date startMonth = DateUtils.getStartMonth();
            return DateUtils.formatDate(startMonth);
        }), Optional.ofNullable(endTime).orElseGet(() -> {
            Date endMonth = DateUtils.getEndMonth();
            return DateUtils.formatDate(endMonth);
        }), websits, websitId, workerMobile);
    }

    public ExcelData workerBuySumExport(List<MaterialSalesSumBean> beanList) {
        String[] titles = new String[]{"网点编码", "网点名称","工程师手机","工程师编号","工程师名称", "合计销售金额",
                "现金销售金额", "通联销售金额", "现金支付次数", "通联次数", "退货金额"};
        List<List<Object>> rows = new ArrayList<>();
        for (MaterialSalesSumBean bean : beanList) {
            List<Object> row = new ArrayList<>();
            row.add(bean.getWebsitId());
            row.add(bean.getWebsitName());
            row.add(bean.getWorkerMobile());
            row.add(bean.getWorkerId());
            row.add(bean.getWorkerName());
            row.add(bean.getTotalSaleValue());
            row.add(bean.getCashSaleValue());
            row.add(bean.getAllinpaySaleValue());
            row.add(bean.getCash());
            row.add(bean.getAllinpay());
            row.add(bean.getRetValue());
            rows.add(row);
        }
        ExcelData excelData = new ExcelData();
        excelData.setRows(rows);
        excelData.setTitles(Arrays.asList(titles));
        return excelData;
    }

    public List<MaterialSalesSumDetailBean> workerBuySumDetail(String startTime, String endTime, String month,
                                                               String websitId, String workerMobile, String workerId,
                                                               String workerName) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        if (StringUtils.isNotBlank(month)) {
            String[] monthDateTime = computeMonthDateTime(month);
            startTime = monthDateTime[0];
            endTime = monthDateTime[1];
        }
        return materialMapper.workerBuySumDetail(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
            Date startMonth = DateUtils.getStartMonth();
            return DateUtils.formatDate(startMonth);
        }), Optional.ofNullable(endTime).orElseGet(() -> {
            Date endMonth = DateUtils.getEndMonth();
            return DateUtils.formatDate(endMonth);
        }), websits, websitId, workerMobile, workerId, workerName);
    }

    public ExcelData workerBuySumDetailExport(List<MaterialSalesSumDetailBean> beanList) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        ExcelData excelData = new ExcelData();
        if (Objects.isNull(beanList) || beanList.size() == 0) {
            excelData.setName("数据为空");
            return excelData;
        }
        String[] titles = new String[]{"网点编码","网点名称", "支付状态", "工程师手机","工程师编号","工程师名称",
                "商品名称", "类别名称", "销售数量", "总销售额", "总进价额", "单位转换系数", "转换数"};
        List<List<Object>> rows = new ArrayList<>();
        String curWebsitId = beanList.get(0).getWebsitId();
        String curWebsitName = beanList.get(0).getWebsitName();
        String curPayFlag = BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, beanList.get(0).getPayFlag()).getRemark();
        String curMobile = beanList.get(0).getWorkerMobile();
        String curWorkerId = beanList.get(0).getWorkerId();
        String curWorkerName = beanList.get(0).getWorkerName();
        BigDecimal curSumSalesQty = new BigDecimal(0);
        BigDecimal curSumSalesValue = new BigDecimal(0);
        BigDecimal curSumCostValue = new BigDecimal(0);
        for (MaterialSalesSumDetailBean item : beanList) {
            // 如果当前遍历手机和上一次遍历不一致 插入合计行
            if (!curMobile.equals(item.getWorkerMobile())) {
                rows.add(addBuySumRow(curWebsitId, curWebsitName, curPayFlag, curMobile, curWorkerId, curWorkerName, curSumSalesQty, curSumSalesValue, curSumCostValue));
                curWebsitId = item.getWebsitId();
                curWebsitName = item.getWebsitName();
                curPayFlag = BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, item.getPayFlag()).getRemark();
                curMobile = item.getWorkerMobile();
                curWorkerId = item.getWorkerId();
                curWorkerName = item.getWorkerName();
                curSumSalesQty = new BigDecimal(0);
                curSumSalesValue = new BigDecimal(0);
                curSumCostValue = new BigDecimal(0);
            }
            List<Object> row = new ArrayList<>();
            row.add(item.getWebsitId());
            row.add(item.getWebsitName());
            row.add(BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, item.getPayFlag()).getRemark());
            row.add(item.getWorkerMobile());
            row.add(item.getWorkerId());
            row.add(item.getWorkerName());
            row.add(item.getGoodsName());
            row.add(item.getGoodsCategoryName());
            row.add(item.getSalesQty());
            row.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
            if (!adminUser.getType().equals(0) || this.checkIsExistsRole(adminUser)) {
//                row.add(item.getCost());
                row.add(item.getCostValue());
                curSumCostValue = curSumCostValue.add(item.getCostValue());
            } else {
//                row.add(new BigDecimal("0"));
                row.add(new BigDecimal("0"));
            }
            row.add(item.getGoodsSalesConvertQty());
            row.add(item.getConvertQty());

            rows.add(row);
            curSumSalesQty = curSumSalesQty.add(item.getSalesQty());
            curSumSalesValue = curSumSalesValue.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
        }

        rows.add(addBuySumRow(curWebsitId, curWebsitName, curPayFlag, curMobile, curWorkerId, curWorkerName, curSumSalesQty, curSumSalesValue, curSumCostValue));

        excelData.setRows(rows);
        excelData.setTitles(Arrays.asList(titles));
        return excelData;
    }

    /**
     * 返回销售汇总合计行
     */
    private List<Object> addBuySumRow(String curWebsitId, String curWebsitName, String curPayFlag, String curMobile,
                                      String curWorkerId, String curWorkerName,
                                      BigDecimal curSumSaleQty, BigDecimal curSumSaleValue, BigDecimal curSumCostValue) {
        List<Object> sumRow = new ArrayList();
        sumRow.add(curWebsitId);
        sumRow.add(curWebsitName);
        sumRow.add(curPayFlag);
        sumRow.add(curMobile);
        sumRow.add(curWorkerId);
        sumRow.add(curWorkerName);
        sumRow.add("");
        sumRow.add("小计：");
        sumRow.add(curSumSaleQty.setScale(2, BigDecimal.ROUND_HALF_UP));
        sumRow.add(curSumSaleValue.setScale(2, BigDecimal.ROUND_HALF_UP));
        sumRow.add(curSumCostValue.setScale(2, BigDecimal.ROUND_HALF_UP));
        return sumRow;
    }

    /**
     * 导出汇总销售明细
     * @param startTime
     * @param endTime
     * @param month
     * @param websitId
     * @param workerMobile
     * @param workerId
     * @param workerName
     * @return
     */
    public List<MaterialSalesSumDetailBean> sumBuyDetail(String startTime, String endTime, String month, String websitId, String workerMobile, String workerId, String workerName) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        if (StringUtils.isNotBlank(month)) {
            String[] monthDateTime = computeMonthDateTime(month);
            startTime = monthDateTime[0];
            endTime = monthDateTime[1];
        }
        return materialMapper.sumBuyDetail(adminUser.getCompanyWechatId(), Optional.ofNullable(startTime).orElseGet(() -> {
            Date startMonth = DateUtils.getStartMonth();
            return DateUtils.formatDate(startMonth);
        }), Optional.ofNullable(endTime).orElseGet(() -> {
            Date endMonth = DateUtils.getEndMonth();
            return DateUtils.formatDate(endMonth);
        }), websits, websitId, workerMobile, workerId, workerName);
    }

    public ExcelData sumBuyDetailExport(List<MaterialSalesSumDetailBean> beanList) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        String[] titles = new String[]{"网点编码","网点名称", "支付状态", "商品名称", "类别名称", "规格",
                "销售数量", "总销售额", "总进价额", "销售利润", "单位转换系数", "转换数"};
        List<List<Object>> rows = new ArrayList<>();
        BigDecimal sumSaleQty = new BigDecimal(0);
        BigDecimal sumSaleValue = new BigDecimal(0);
        BigDecimal sumCostValue = new BigDecimal(0);
        BigDecimal sumProfitValue = new BigDecimal(0);
        for (MaterialSalesSumDetailBean item : beanList) {
            List<Object> row = new ArrayList<>();
            row.add(item.getWebsitId());
            row.add(item.getWebsitName());
            row.add(BaseEnum.keyToEnumNotNull(IsYesNoEnum.class, item.getPayFlag()).getRemark());
            row.add(item.getGoodsName());
            row.add(item.getGoodsCategoryName());
            row.add(item.getGoodsSpecification());
            row.add(item.getSalesQty());
            row.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
            if (!adminUser.getType().equals(0) || this.checkIsExistsRole(adminUser)) {
                row.add(item.getCostValue());
                row.add(item.getSaleAmount().subtract(item.getCostValue()));
                sumCostValue = sumCostValue.add(item.getCostValue());
                sumProfitValue = sumProfitValue.add(item.getSaleAmount().subtract(item.getCostValue()));
            } else {
                row.add(new BigDecimal("0"));
                row.add(new BigDecimal("0"));
                sumProfitValue = sumProfitValue.add(new BigDecimal("0"));
            }
            row.add(item.getGoodsSalesConvertQty());
            row.add(item.getConvertQty());

            rows.add(row);
            sumSaleQty = sumSaleQty.add(item.getSalesQty());
            sumSaleValue = sumSaleValue.add(item.getSaleAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
        }
        List<Object> row = new ArrayList();
        row.add("");
        row.add("");
        row.add("");
        row.add("");
        row.add("");
        row.add("");
        row.add("");
        row.add("合计：");
        row.add(sumSaleQty);
        row.add(sumSaleValue);
        row.add(sumCostValue);
        row.add(sumProfitValue);
        rows.add(row);
        ExcelData excelData = new ExcelData();
        excelData.setRows(rows);
        excelData.setTitles(Arrays.asList(titles));
        return excelData;
    }

    private boolean checkIsExistsRole(AdminUserCom adminUser) {
        final AdminModule module = adminModuleService.lambdaQuery()
                .eq(AdminModule::getCode, "query-cost")
                .one();
        if (Objects.isNull(module)) {
            return false;
        }
        return adminUserModuleRelaService.lambdaQuery()
                .eq(AdminUserModuleRela::getAdminRoleId, adminUser.getRoleId())
                .eq(AdminUserModuleRela::getAdminModuleId, module.getModuleId())
                .count() > 0;
    }

    /**
     * 采购商品汇总
     * @param startTime
     * @param endTime
     * @param websitId
     * @param isSum
     * @return
     */
    public List<PurchaseDetailBean> purchaseGoodsSum(String startTime, String endTime, String websitId, boolean isSum) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        return materialMapper.purchaseGoodsSum(adminUser.getCompanyWechatId(), startTime, endTime, websits, websitId, isSum);
    }

    public ExcelData purchaseGoodsSumExport(List<PurchaseDetailBean> purchaseDetailBeanList, List<PurchaseDetailBean> purchaseDetailSumBeanList) {
        String[] titles = new String[]{"网点编码","网点名称","供应商名称","商品名称","类别名称"
                , "验收数量", "验收赠品数量", "验收金额"};
        List<List<Object>> rows = new ArrayList<>();
        if (CollectionUtil.isEmpty(purchaseDetailBeanList)) {
            ExcelData excelData = new ExcelData();
            excelData.setTitles(Collections.singletonList("暂无内容"));
            return excelData;
        }
        String curShopId = purchaseDetailBeanList.get(0).getWebsitId();

        for (PurchaseDetailBean bean : purchaseDetailBeanList) {
            // 如果当前遍历网点编号和上一次遍历不一致 插入合计行
            if (!curShopId.equals(bean.getWebsitId())) {
                rows.add(addPurchaseSumRow(curShopId, purchaseDetailSumBeanList));
                curShopId = bean.getWebsitId();
            }
            List<Object> row = new ArrayList<>();
            row.add(bean.getWebsitId());
            row.add(bean.getWebsitName());
            row.add(bean.getVenderName());
            row.add(bean.getGoodsName());
            row.add(bean.getGoodsCategoryName());
//            row.add(bean.getPurchaseQty());
            row.add(bean.getRecQty());
            row.add(bean.getRecGiftQty());
            row.add(bean.getCostValue());
            rows.add(row);
        }
        rows.add(addPurchaseSumRow(curShopId, purchaseDetailSumBeanList));
        ExcelData excelData = new ExcelData();
        excelData.setRows(rows);
        excelData.setTitles(Arrays.asList(titles));
        return excelData;
    }

    private List<Object> addPurchaseSumRow(String curShopId, List<PurchaseDetailBean> purchaseDetailSumBeanList) {
        List<Object> sumRow = new ArrayList();
        PurchaseDetailBean bean = purchaseDetailSumBeanList.stream()
                .filter(purchaseDetailBean -> purchaseDetailBean.getWebsitId().equals(curShopId))
                .collect(Collectors.toList()).get(0);
        sumRow.add(bean.getWebsitId());
        sumRow.add(bean.getWebsitName());
        sumRow.add("");
        sumRow.add("");
        sumRow.add(bean.getGoodsCategoryName());
//        sumRow.add(bean.getPurchaseQty());
        sumRow.add(bean.getRecQty());
        sumRow.add(bean.getRecGiftQty());
        sumRow.add(bean.getCostValue());
        return sumRow;
    }

    /**
     * 月度辅材采购类别
     * @param websitId
     * @param month
     * @return
     */
    public List<PurchaseCategoryBean> purchaseCategorySum(String websitId, String month) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        String[] monthDateTime = computeMonthDateTime(month);
        String startDate = monthDateTime[0];
        String endDate = monthDateTime[1];
        // 查询网点采购汇总数据
        List<PurchaseCategoryBean> websitePurchaseSumList = materialMapper.getMonthSummaryData(adminUser.getCompanyWechatId(), websits, websitId, startDate, endDate);

        // 查询网点上个月结存金额
        List<WebsiteStockValSumBean> websiteStockValSumList = materialMapper.getLastMonthStockSumVal(adminUser.getCompanyWechatId(), websits, websitId, startDate);

        Map<String, PurchaseCategoryBean> websitePurchaseSumMap = websitePurchaseSumList.stream()
                .collect(Collectors.toMap(PurchaseCategoryBean::getWebsitId, Function.identity()));

        // 网点采购汇总数据注入上个月结存金额
        websiteStockValSumList.forEach(obj -> {
            PurchaseCategoryBean websitePurchaseSum = websitePurchaseSumMap.get(obj.getWebsitId());
            if (Objects.nonNull(websitePurchaseSum)) {
                websitePurchaseSum.setLastMonthVal(obj.getLastMonthVal());
            }
        });

        websitePurchaseSumList = new ArrayList<>(websitePurchaseSumMap.values());

        return websitePurchaseSumList;
    }

    public ExcelData purchaseCategorySumExport(List<PurchaseCategoryBean> purchaseCategoryBeanList) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        String[] titles = new String[]{"年月","辅材网点编号","辅材网点名称","铜管(公斤)","铜管总价","保温棉(条)","保温棉总价"
                ,"电缆(米)","电缆总价","支架(付)","支架总价","冷媒(罐)","冷媒总价","开关","开关总价"
                ,"包扎带","包扎带总价","连接器","连接器总价","双壁热缩套管","双壁热缩套管总价","清洗工具","清洗工具总价","管槽","管槽总价"
                ,"热水器","热水器总价","总采购金额","上月库存金额"};
        List<List<Object>> rows = new ArrayList<>();
        for (PurchaseCategoryBean bean : purchaseCategoryBeanList) {
            List<Object> row = new ArrayList<>();
            row.add(bean.getYearMonth());
            row.add(bean.getWebsitId());
            row.add(bean.getWebsitName());
            row.add(bean.getTgQty());
            row.add(bean.getTgVal());
            row.add(bean.getBwmQty());
            row.add(bean.getBwmVal());
            row.add(bean.getDlQty());
            row.add(bean.getDlVal());
            row.add(bean.getZjQty());
            row.add(bean.getZjVal());
            row.add(bean.getLmQty());
            row.add(bean.getLmVal());
            row.add(bean.getKgQty());
            row.add(bean.getKgVal());
            row.add(bean.getBzdQty());
            row.add(bean.getBzdVal());
            row.add(bean.getLjqQty());
            row.add(bean.getLjqVal());
            row.add(bean.getRsgQty());
            row.add(bean.getRsgVal());
            row.add(bean.getQxggQty());
            row.add(bean.getQxggVal());
            row.add(bean.getGcQty());
            row.add(bean.getGcVal());
            row.add(bean.getYsqQty());
            row.add(bean.getYsqVal());
            row.add(bean.getTgVal().add(bean.getBwmVal()).add(bean.getDlVal()).add(bean.getZjVal())
                    .add(bean.getLmVal()).add(bean.getKgVal()).add(bean.getBzdVal()).add(bean.getLjqVal())
                    .add(bean.getRsgVal()).add(bean.getQxggVal()).add(bean.getGcVal()));
            row.add(bean.getLastMonthVal());
            rows.add(row);
        }
        ExcelData excelData = new ExcelData();
        excelData.setRows(rows);
        excelData.setTitles(Arrays.asList(titles));
        return excelData;
    }

    public List<WorkerPurchaseCategoryBean> workerPurchaseCategorySum(String websitId, String month) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        List<String> websits = adminUser.getAdminWebsitIds();
        if (CollectionUtil.isEmpty(websits)
                || (StringUtils.isNotBlank(websitId) && !websits.contains(websitId))) {
            return new ArrayList<>();
        }
        String[] monthDateTime = computeMonthDateTime(month);
        String startDate = monthDateTime[0];
        String endDate = monthDateTime[1];
        List<WorkerPurchaseCategoryBean> monthSummaryData = materialMapper.getWorkerMonthSummaryData(adminUser.getCompanyWechatId(), startDate, endDate);

        return monthSummaryData;
    }

    public ExcelData workerPurchaseCategorySumExport(List<WorkerPurchaseCategoryBean> workerPurchaseCategoryBeanList) {
        String[] titles = new String[]{"年月","网点编号","网点名称","师傅编号", "师傅名称","铜管(公斤)","铜管(米)","铜管总价"
                ,"保温棉(条)","保温棉总价","电缆(米)","电缆总价","支架(付)","支架总价","冷媒(罐)","冷媒总价","开关","开关总价","包扎带"
                ,"包扎带总价","连接器","连接器总价","双壁热缩套管","双壁热缩套管总价","清洗工具","清洗工具总价","管槽","管槽总价","热水器"
                ,"热水器总价","总采购金额"
                ,"师傅当月剩余库存金额"};
        List<List<Object>> rows = new ArrayList<>();
        for (WorkerPurchaseCategoryBean bean : workerPurchaseCategoryBeanList) {
            List<Object> row = new ArrayList<>();
            row.add(bean.getYearMonth());
            row.add(bean.getWebsitId());
            row.add(bean.getWebsitName());
            row.add(bean.getWorkerId());
            row.add(bean.getWorkerName());
            row.add(bean.getTgQty());
            row.add(bean.getTgConvertQty());
            row.add(bean.getTgVal());
            row.add(bean.getBwmQty());
            row.add(bean.getBwmVal());
            row.add(bean.getDlQty());
            row.add(bean.getDlVal());
            row.add(bean.getZjQty());
            row.add(bean.getZjVal());
            row.add(bean.getLmQty());
            row.add(bean.getLmVal());
            row.add(bean.getKgQty());
            row.add(bean.getKgVal());
            row.add(bean.getBzdQty());
            row.add(bean.getBzdVal());
            row.add(bean.getLjqQty());
            row.add(bean.getLjqVal());
            row.add(bean.getRsgQty());
            row.add(bean.getRsgVal());
            row.add(bean.getQxggQty());
            row.add(bean.getQxggVal());
            row.add(bean.getGcQty());
            row.add(bean.getGcVal());
            row.add(bean.getYsqQty());
            row.add(bean.getYsqVal());
            row.add(bean.getTgVal().add(bean.getBwmVal()).add(bean.getDlVal()).add(bean.getZjVal()).add(bean.getLmVal())
                    .add(bean.getWjVal()).add(bean.getJtVal()).add(bean.getKgVal()).add(bean.getBzdVal())
                    .add(bean.getLjqVal()).add(bean.getRsgVal())
                    .add(bean.getQxggVal()).add(bean.getGcVal()).add(bean.getYsqVal()));
            row.add(bean.getWorkerGoodsPrice());
            rows.add(row);
        }
        ExcelData excelData = new ExcelData();
        excelData.setRows(rows);
        excelData.setTitles(Arrays.asList(titles));
        return excelData;
    }
}
