package com.gree.mall.manager.logic.count;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.bean.count.*;
import com.gree.mall.manager.bean.workorder.MaterialPeiJianCount;
import com.gree.mall.manager.commonmapper.CountMapper;
import com.gree.mall.manager.enums.*;
import com.gree.mall.manager.enums.engin.EnginPayManageStatusEnum;
import com.gree.mall.manager.enums.material.*;
import com.gree.mall.manager.enums.workorder.SourceChannelEnum;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.plus.entity.*;
import com.gree.mall.manager.plus.service.*;
import com.gree.mall.manager.utils.CommonUtils;
import com.gree.mall.manager.utils.DateUtils;
import com.gree.mall.manager.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.java2d.pipe.SpanShapeRenderer;

import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CountLogic {

    @Autowired
    CommonLogic commonLogic;
    @Autowired
    OrderInfoService orderInfoService;
    @Autowired
    OrderRefundService orderRefundService;
    @Autowired
    OrderShareService orderShareService;
    @Autowired
    UserService userService;
    @Autowired
    CountMapper countMapper;
    @Autowired
    UserVisitService userVisitService;

    @Autowired
    RpMaterialOrderService rpMaterialOrderService;

    @Autowired
    RpProjectRepairService rpProjectRepairService;

    @Autowired
    PgIncreService pgIncreService;

    @Autowired
    PgIncreOrderService pgIncreOrderService;

    @Autowired
    PgOrderBaseService pgOrderBaseService;

    @Autowired
    WebsitGoodsService websitGoodsService;

    @Autowired
    WebsitNormChargeService websitNormChargeService;

    @Autowired
    WebsitVenderService websitVenderService;

    @Autowired
    WebsitPurchaseService websitPurchaseService;

    @Autowired
    WebsitPurchaseRetService websitPurchaseRetService;


    @Autowired
    WebsitPriceUpdService websitPriceUpdService;

    @Autowired
    WebsitSalesService websitSalesService;

    @Autowired
    WebsitSalesRetService websitSalesRetService;

    @Autowired
    WebsitPartsRetService websitPartsRetService;

    @Autowired
    SettlementOrderService settlementOrderService;

    @Autowired
    WebsitSalesManagerService websitSalesManagerService;

    @Autowired
    SettlementOrderManualService settlementOrderManualService;

    @Autowired
    WithdrawalOrderService withdrawalOrderService;

    @Autowired
    WebsitGoodsAloneService websitGoodsAloneService;

    @Autowired
    EnginPayManageService enginPayManageService;

    @Autowired
    WorkerGoodsService workerGoodsService;

    @Autowired
    WebsitVenderGoodsService websitVenderGoodsService;

    @Autowired
    WebsitPurchaseAdjustmentService websitPurchaseAdjustmentService;

    @Autowired
    WebsitPartsNewInRecordService websitPartsNewInRecordService;

    @Autowired
    WebsitPartsSalesService websitPartsSalesService;

    @Autowired
    WebsitPartsNewRefundManageService websitPartsNewRefundManageService;

    @Autowired
    WebsitPartsOldRefundManageService websitPartsOldRefundManageService;

    @Autowired
    WebsitPartsChangeSalesService websitPartsChangeSalesService;

    /**
     * 概况统计
     */
    public CountBean info(HttpServletRequest request){
        AdminUserCom adminUser = commonLogic.getAdminUser(request);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //累计售出商品数量，已售中商品数量，待发货订单数量，维权中订单数量，今日订单数，昨日订单数，今日收益，昨日收益
        CountBean countBean = countMapper.countInfo(adminUser.getCompanyWechatIds());
        //今日访客
        Integer todayVisit = countMapper.countVisit(sdf.format(DateUtils.getStartTime()),sdf.format(DateUtils.getEndTime()),adminUser.getCompanyWechatIds());
        //昨日访客
        Integer yestodayVisit = countMapper.countVisit(sdf.format(DateUtils.getBeginDayOfYesterday()),sdf.format(DateUtils.getEndDayOfYesterDay()),adminUser.getCompanyWechatIds());
        //查询待结算金额
        List<OrderShare> list = orderShareService.lambdaQuery()
                .eq(OrderShare::getStatus, OrderShareStatusEnum.ING.toString())
                .in(CollectionUtils.isNotEmpty(adminUser.getCompanyWechatIds()),OrderShare::getCompanyWechatId,adminUser.getCompanyWechatIds())
                //.//in(CollectionUtils.isNotEmpty(adminUser.getAdminWebsitIds()),OrderShare::getWebsitId,adminUser.getAdminWebsitIds())
                .list();
        BigDecimal totalShareAmount = list.stream().map(OrderShare::getAmount).reduce(BigDecimal::add).orElse(new BigDecimal(0));
        countBean.setOrderShareAmount(totalShareAmount);
        countBean.setTodayVisit(todayVisit);
        countBean.setYestodayVisit(yestodayVisit);
        return countBean;
    }


    /**
     * 商品销售排行
     */
    public List<GoodsRankBean> countGoodsRank(Integer flag,HttpServletRequest request){

        AdminUserCom adminUserCom = commonLogic.getAdminUser(request);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //默认今天
        Date startTime = this.getStartTime(flag);
        Date endTime = this.getEndTime(flag);
        List<GoodsRankBean> goodsRankBeans = countMapper.countGoodsRank(sdf.format(startTime), sdf.format(endTime),
                adminUserCom.getCompanyWechatIds(),adminUserCom.getAdminWebsitIds());
        return goodsRankBeans;
    }


    /**
     * 交易概述
     */
    public CountOrderBean order(String type,Integer flag,HttpServletRequest request){
        AdminUserCom adminUserCom = commonLogic.getAdminUser(request);
        //默认今天
        Date startTime = this.getStartTime(flag);
        Date endTime = this.getEndTime(flag);
        CountOrderBean countOrderBean = countMapper.countSaleOrder(DateUtils.formatDate(startTime), DateUtils.formatDate(endTime), type,
                adminUserCom.getCompanyWechatIds(),adminUserCom.getAdminWebsitIds());
        //各时段统计
        List<OrderInfo> list = orderInfoService.lambdaQuery()
                .in(CollectionUtils.isNotEmpty(adminUserCom.getCompanyWechatIds()),OrderInfo::getCompanyWechatId,adminUserCom.getCompanyWechatIds())
                .notIn(OrderInfo::getOrderStatus,Arrays.asList(OrderStatusEnum.CLOSE.toString(),OrderStatusEnum.NOPAY.toString(),OrderStatusEnum.TIMEOUT.toString()))
                .between(OrderInfo::getCreateTime, startTime, endTime).list();
        SimpleDateFormat hh = new SimpleDateFormat("HH");
        SimpleDateFormat dd = new SimpleDateFormat("dd");
        int[] day = new int[24];
        int[] week = new int[7];
        int[] month = new int[DateUtils.DateSubOfDay(DateUtils.getEndMonth(), DateUtils.getStartMonth()) + 1];
        for(OrderInfo orderInfo : list) {
            Date time = orderInfo.getCreateTime();
            if (flag == 1 || flag == 2) {
                int index = Integer.parseInt(hh.format(time));
                //天  按24小时维度 0-23
                day[index]++;
            }
            if (flag == 3) {
                int index = DateUtils.DateSubOfDay(time,startTime);
                //7天 按天维度 日不是从0号开始，所以-1
                week[index]++;
            }
            if (flag == 4) {
                int index = Integer.parseInt(dd.format(time));
                //月 按天维度 日不是从0号开始，所以-1
                month[index-1]++;
            }
        }
        if(flag == 1 || flag== 2) {
            countOrderBean.setCountAry(day);
            countOrderBean.setX(new String[24]);
        }
        if(flag == 3) {
            countOrderBean.setCountAry(week);
            countOrderBean.setX(getX(7,null));
        }
        if(flag == 4) {
            countOrderBean.setCountAry(month);
            countOrderBean.setX(getX(DateUtils.DateSubOfDay(DateUtils.getEndMonth(), DateUtils.getStartMonth()) + 1,DateUtils.getEndMonth()));
        }

        return countOrderBean;
    }


    /**
     * 师傅的销售金额统计
     */
    public List<Map<String,Object>> queryWorkAmount(String startTime,String endTime,HttpServletRequest request){
        AdminUserCom adminUser = commonLogic.getAdminUser(request);
        List<Map<String, Object>> maps = countMapper.countWorkAmount(startTime, endTime,adminUser.getCompanyWechatIds());
        return maps;
    }


    /**
     * 网点的销售金额统计
     */
    public WebsitSaleCountBean queryWebsitAmount(List<String> websitNumbers){
        //当月
        Map<String, Object> map = countMapper.countWebsitAmount(DateUtils.formatDate(DateUtils.getStartMonth()),DateUtils.formatDate(DateUtils.getEndMonth()),websitNumbers);
        //当日
        Map<String, Object> map2 = countMapper.countWebsitAmount(DateUtils.formatDate(DateUtils.getStartTime()),DateUtils.formatDate(DateUtils.getEndTime()),websitNumbers);

        WebsitSaleCountBean bean = new WebsitSaleCountBean();
        bean.setMonthNum((Integer)map.get("num"));
        bean.setMonthAmount(new BigDecimal(map.get("amount").toString()));
        bean.setDayNum((Integer)map2.get("num"));
        bean.setDayAmount(new BigDecimal(map2.get("amount").toString()));
        return bean;
    }



    private Date getStartTime(Integer flag){
        Date startTime = DateUtils.getStartTime();
        //昨天
        if(flag == 2){
            startTime = DateUtils.getTimeByDay(DateUtils.getStartTime(),-1);
        }
        //最近7天
        if(flag == 3 ){
            startTime = DateUtils.getTimeByDay(startTime,-6);
        }
        //本月
        if(flag == 4){
            startTime = DateUtils.getStartMonth();
        }
        return startTime;
    }

    private Date getEndTime(Integer flag){
        Date endTime = DateUtils.getEndTime();
        //昨天
        if(flag == 2){
            endTime =  DateUtils.getStartTime();
        }
        //最近7天
        if(flag == 3 ){
            endTime = DateUtils.getStartTime();
        }
        //本月
        if(flag == 4){
            endTime = DateUtils.getEndMonth();
        }
        return endTime;
    }


    private static String[] getX(int dayNum,Date date){
        if(date == null){
            date = new Date();
        }
        String[] x = new String[dayNum];
        for(int i = 0 ;i <dayNum;i++){
            Date timeByDay = DateUtils.getTimeByDay(date,i-dayNum+1);
            x[i] = DateUtils.formatDate1(timeByDay);
        }
        return x;
    }


    public RepairProjectCount repairProject(HttpServletRequest request) {
        AdminUserCom adminUser = commonLogic.getAdminUser();

        List<RpMaterialOrder> list = rpMaterialOrderService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), RpMaterialOrder::getWebsitId,adminUser.getAdminWebsitIds())
                .select(RpMaterialOrder::getExamineStatus, RpMaterialOrder::getOrderId,RpMaterialOrder::getIsAllFee).list();

        List<RpProjectRepair> rpProjectRepairList = rpProjectRepairService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getCompanyWechatIds()), RpProjectRepair::getCompanyWechatId, adminUser.getCompanyWechatIds())
                .select(RpProjectRepair::getStartTime,RpProjectRepair::getEndTime,RpProjectRepair::getId)
                .list();


        RepairProjectCount repairProjectCount = new RepairProjectCount();

        repairProjectCount.setAllProjectNum(rpProjectRepairList.size());
        repairProjectCount.setOnProjectNum(Convert.toInt(rpProjectRepairList.stream().filter(item -> item.getEndTime().after(new Date())).count()));
        repairProjectCount.setEndProjectNum(Convert.toInt(rpProjectRepairList.stream().filter(item -> item.getEndTime().before(new Date())).count()));

        repairProjectCount.setNoPriceWaitNum(Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.NO.getKey())
            && item.getExamineStatus().equals(MaterialExamineStatusEnum.WAIT.getKey())
        ).count()));

        repairProjectCount.setNoPriceOKNum(Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.NO.getKey())
                && item.getExamineStatus().equals(MaterialExamineStatusEnum.OK.getKey())
        ).count()));

        repairProjectCount.setNoPriceFailNum((Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.NO.getKey())
                && item.getExamineStatus().equals(MaterialExamineStatusEnum.FAIL.getKey())
        ).count())));


        repairProjectCount.setNoPriceNoNum((Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.NO.getKey())
                && item.getExamineStatus().equals(MaterialExamineStatusEnum.NO.getKey())
        ).count())));

        repairProjectCount.setNoPriceNoPaidNum((Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.NO.getKey())
                && item.getExamineStatus().equals(MaterialExamineStatusEnum.PAID.getKey())
        ).count())));


        repairProjectCount.setNoPricePaidNum((Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.NO.getKey())
                && item.getExamineStatus().equals(MaterialExamineStatusEnum.NO_PAID.getKey())
        ).count())));


        repairProjectCount.setPriceOrderNum((Convert.toInt(list.stream().filter(item -> item.getIsAllFee().equals(IsYesNoEnum.YES.getKey())
        ).count())));

        return repairProjectCount;

    }

    public IncreCount increCount(String startTime,String endTime,HttpServletRequest request) {

        AdminUserCom adminUser = commonLogic.getAdminUser();

        List<PgIncre> pgIncreList = pgIncreService.lambdaQuery().in(!CollectionUtils.isEmpty(adminUser.getCompanyWechatIds()), PgIncre::getCompanyWechatId, adminUser.getCompanyWechatIds())
                .select(PgIncre::getStatus, PgIncre::getId).list();

        IncreCount increCount = new IncreCount();

        increCount.setAllIncreNum(pgIncreList.size());
        increCount.setOnIncreNum(Convert.toInt(pgIncreList.stream().filter(item -> item.getStatus()).count()));
        increCount.setOffIncreNum(Convert.toInt(pgIncreList.stream().filter(item -> !item.getStatus()).count()));

        List<PgOrderBase> pgOrderBaseList = pgOrderBaseService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getCompanyWechatIds()), PgOrderBase::getCompanyWechatId, adminUser.getCompanyWechatIds())
                .ne(PgOrderBase::getPgIncreId,"")
                .select(PgOrderBase::getId, PgOrderBase::getOrderStatus).list();

        increCount.setLpOrderNumber(pgOrderBaseList.size());


        List<PgIncreOrder> pgIncreOrderList = pgIncreOrderService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), PgIncreOrder::getWebsitId, adminUser.getAdminWebsitIds())
                .select(PgIncreOrder::getId, PgIncreOrder::getPayStatus, PgIncreOrder::getOrderChannel, PgIncreOrder::getFlag,PgIncreOrder::getRefundNo,PgIncreOrder::getServiceEndTime)
                .list();

        increCount.setWaitLineNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.SELF.getKey())
            && item.getFlag().equals(ExamineStatusEnum.WAIT.getKey())
        ).count()));

        increCount.setOkLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.SELF.getKey())
                && item.getFlag().equals(ExamineStatusEnum.OK.getKey())
        ).count()));

        increCount.setFailLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.SELF.getKey())
                && item.getFlag().equals(ExamineStatusEnum.FAIL.getKey())
        ).count()));


        increCount.setPaidOnLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.ONLINE.getKey())
                && item.getPayStatus().equals(PayStatusEnum.PAID.getKey())
        ).count()));

        increCount.setWaitOnLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.ONLINE.getKey())
                && item.getPayStatus().equals(PayStatusEnum.WAIT.getKey())
        ).count()));


        increCount.setRefundOnLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.ONLINE.getKey())
                && !StringUtil.isEmpty(item.getRefundNo())
        ).count()));

        increCount.setEndOnLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.ONLINE.getKey())
                && item.getServiceEndTime() != null && item.getPayStatus().equals(PayStatusEnum.PAID.getKey()) && StringUtil.isEmpty(item.getRefundNo())
                && item.getServiceEndTime().before(new Date())
        ).count()));

        increCount.setCancelOnLineOrderNum(Convert.toInt(pgIncreOrderList.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.ONLINE.getKey())
                && item.getPayStatus().equals(PayStatusEnum.CANCEL.getKey())
        ).count()));


        Date startBe = StringUtil.isEmpty(startTime)  ? DateUtil.beginOfDay(DateUtil.offsetDay(new Date(),-14)):DateUtil.parse(startTime);
        Date endBe =  StringUtil.isEmpty(endTime) ?  DateUtil.endOfDay(new Date()):DateUtil.parse(endTime);

        List<PgIncreOrder> pgIncreOrders = pgIncreOrderService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), PgIncreOrder::getWebsitId, adminUser.getAdminWebsitIds())
                .between(PgIncreOrder::getCreateTime,startBe,endBe)
                .select(PgIncreOrder::getId, PgIncreOrder::getPayStatus, PgIncreOrder::getOrderChannel, PgIncreOrder::getFlag,PgIncreOrder::getRefundNo,
                        PgIncreOrder::getServiceEndTime,PgIncreOrder::getCreateTime)
                .list();

        List<Integer> onLineList = new ArrayList<>();
        List<Integer> lineList = new ArrayList<>();

        Integer integer = 0;


        while (true){

            DateTime dateTime = DateUtil.offsetDay(startBe, integer);
            long lineCount = pgIncreOrders.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.SELF.getKey())
                    && item.getCreateTime().after(dateTime) && item.getCreateTime().before(DateUtil.endOfDay(dateTime))).count();


            long onLineCount = pgIncreOrders.stream().filter(item -> item.getOrderChannel().equals(SourceChannelEnum.ONLINE.getKey())
                    && item.getCreateTime().after(dateTime) && item.getCreateTime().before(DateUtil.endOfDay(dateTime))).count();

            integer++;

            onLineList.add(Convert.toInt(onLineCount));
            lineList.add(Convert.toInt(lineCount));

            if (DateUtil.beginOfDay(DateUtil.offsetDay(startBe,integer)).after(endBe)) {
                break;
            }
        }

        increCount.setOnLineList(onLineList);
        increCount.setLineList(lineList);

        return increCount;

    }

    public MaterialCount materialCount(HttpServletRequest request) {
        AdminUserCom adminUser = commonLogic.getAdminUser();

        MaterialCount materialCount = new MaterialCount();

        List<WebsitGoods> websitGoods = websitGoodsService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getCompanyWechatIds()), WebsitGoods::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitGoods::getGoodsId, WebsitGoods::getStatus, WebsitGoods::getGoodsType).list();


        List<WebsitNormCharge> websitNormCharges = websitNormChargeService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getCompanyWechatIds()), WebsitNormCharge::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitNormCharge::getNormId, WebsitNormCharge::getStatus, WebsitNormCharge::getNormType).list();


        materialCount.setAllmGoodsNum(
               Convert.toInt(websitGoods.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey())
                ).count())
        );

        materialCount.setOnMGoodsNum(
                Convert.toInt(websitGoods.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey())
                        && item.getStatus().equals(StateEnum.ON.getKey())
                ).count())
        );

        materialCount.setOffMGoodsNum(
                Convert.toInt(websitGoods.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey())
                        && item.getStatus().equals(StateEnum.OFF.getKey())
                ).count())
        );


        materialCount.setAllmChargeGoodsNum(
                Convert.toInt(websitNormCharges.stream()
                .count())
        );

        materialCount.setOnmChargeGoodsNum(
                Convert.toInt(websitNormCharges.stream().filter(item ->
                         item.getStatus().equals(StateEnum.ON.getKey())
                ).count())
        );

        materialCount.setOffmChargeGoodsNum(
                Convert.toInt(websitNormCharges.stream().filter(item ->
                         item.getStatus().equals(StateEnum.OFF.getKey())
                ).count())
        );




        List<WebsitVender> websitVenders = websitVenderService.lambdaQuery()
                .in(!StringUtil.isEmpty(adminUser.getCompanyWechatId()), WebsitVender::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitVender::getStatus, WebsitVender::getVenderId).list();

        materialCount.setAllVendNum(
                Convert.toInt(websitVenders.size())
        );

        materialCount.setOnVendNum(
                Convert.toInt(websitVenders.stream().filter(item ->
                        item.getStatus().equals(StateEnum.ON.getKey())
                ).count())
        );

        materialCount.setOffVendNum(
                Convert.toInt(websitVenders.stream().filter(item ->
                        item.getStatus().equals(StateEnum.OFF.getKey())
                ).count())
        );


        List<WorkerGoods> workerGoodsList = workerGoodsService.lambdaQuery()
                .in(!StringUtil.isEmpty(adminUser.getCompanyWechatId()), WorkerGoods::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WorkerGoods::getStatus, WorkerGoods::getGoodsId).list();

        materialCount.setAllmWorkerGoodsNum(
                Convert.toInt(workerGoodsList.stream().count())
        );

        materialCount.setOnmWorkerGoodsNum(
                Convert.toInt(workerGoodsList.stream().filter(item ->
                        item.getStatus().equals(StateEnum.ON.getKey())
                ).count())
        );

        materialCount.setOffmWorkerGoodsNum(
                Convert.toInt(workerGoodsList.stream().filter(item ->
                        item.getStatus().equals(StateEnum.OFF.getKey())
                ).count())
        );


        List<WebsitVenderGoods> websitVenderGoods = websitVenderGoodsService.lambdaQuery()
                .in(!StringUtil.isEmpty(adminUser.getCompanyWechatId()), WebsitVenderGoods::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitVenderGoods::getStatus, WebsitVenderGoods::getVenderId).list();


        materialCount.setAllPNum(
                Convert.toInt(websitVenderGoods.stream().count())
        );

        materialCount.setSavePNum(
                Convert.toInt(websitVenderGoods.stream().filter(item ->
                        item.getStatus().equals(ExamineStatusEnum.SAVE.getKey())
                ).count())
        );

        materialCount.setOnPNum(
                Convert.toInt(websitVenderGoods.stream().filter(item ->
                        item.getStatus().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );


        List<WebsitPurchase> websitPurchaseList = websitPurchaseService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPurchase::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPurchase::getIsRecheck, WebsitPurchase::getPurchaseId,WebsitPurchase::getFlag).list();


        List<String> flags = new ArrayList<>();
        flags.add(ExamineStatusEnum.SUBMIT.getKey());
        flags.add(ExamineStatusEnum.OK.getKey());

        materialCount.setWebsitCheckNum(
                Convert.toInt(websitPurchaseList.stream().filter(item -> flags.contains(item.getFlag()
                )).count())
        );

        materialCount.setWebsitCheckNeverNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flags.contains(item.getFlag())
                        && item.getIsRecheck().equals(IsYesNoEnum.NO.getKey())

                ).count())
        );

        materialCount.setWebsitCheckYesNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flags.contains(item.getFlag())
                                && item.getIsRecheck().equals(IsYesNoEnum.YES.getKey())

                ).count())
        );


        List<String> flagsApply = new ArrayList<>();
        flagsApply.add(ExamineStatusEnum.SUBMIT.getKey());
        flagsApply.add(ExamineStatusEnum.SAVE.getKey());


        materialCount.setWebsitApplySaveNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flagsApply.contains(item.getFlag()) &&
                        item.getIsRecheck().equals(IsYesNoEnum.NO.getKey())).count())
        );

        materialCount.setWebsitApplySumbitNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flagsApply.contains(item.getFlag()) &&
                        item.getIsRecheck().equals(IsYesNoEnum.NO.getKey())
                                && item.getFlag().equals(ExamineStatusEnum.SUBMIT.getKey())
                ).count())
        );



        materialCount.setWebsitApplyCancelNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flagsApply.contains(item.getFlag()) &&
                        item.getIsRecheck().equals(IsYesNoEnum.NO.getKey())
                                && item.getFlag().equals(PartsOrderStatusEnum.CANCEL.getKey())
                ).count())
        );

        materialCount.setWebsitApplyOkNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flagsApply.contains(item.getFlag()) &&
                        item.getIsRecheck().equals(IsYesNoEnum.NO.getKey())
                        && item.getFlag().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );


        materialCount.setWebsitApplyFailNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        flagsApply.contains(item.getFlag()) &&
                        item.getIsRecheck().equals(IsYesNoEnum.NO.getKey())
                                && item.getFlag().equals(ExamineStatusEnum.FAIL.getKey())
                ).count())
        );


        materialCount.setWebsitOrderSaveNum(
                Convert.toInt(websitPurchaseList.stream().filter(item -> item.getIsRecheck().equals(IsYesNoEnum.YES.getKey())
                        && item.getFlag().equals(ExamineStatusEnum.SAVE.getKey())).count())
        );

        materialCount.setWebsitOrderSumbitNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        item.getIsRecheck().equals(IsYesNoEnum.YES.getKey())
                                && item.getFlag().equals(ExamineStatusEnum.SUBMIT.getKey())
                ).count())
        );



        materialCount.setWebsitOrderCancelNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        item.getIsRecheck().equals(IsYesNoEnum.YES.getKey())
                                && item.getFlag().equals(PartsOrderStatusEnum.CANCEL.getKey())
                ).count())
        );

        materialCount.setWebsitOrderOkNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        item.getIsRecheck().equals(IsYesNoEnum.YES.getKey())
                                && item.getFlag().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );


        materialCount.setWebsitOrderFailNum(
                Convert.toInt(websitPurchaseList.stream().filter(item ->
                        item.getIsRecheck().equals(IsYesNoEnum.YES.getKey())
                                && item.getFlag().equals(ExamineStatusEnum.FAIL.getKey())
                ).count())
        );


        List<WebsitPurchaseAdjustment> websitPurchaseAdjustments = websitPurchaseAdjustmentService.lambdaQuery()
                .in(!StringUtil.isEmpty(adminUser.getCompanyWechatId()), WebsitPurchaseAdjustment::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitPurchaseAdjustment::getFlag, WebsitPurchaseAdjustment::getPurchaseAdjustmentId).list();

        materialCount.setWebsitAdjustmentSaveNum(
                Convert.toInt(websitPurchaseAdjustments.stream().filter(item -> item.getFlag().equals(ExamineStatusEnum.SAVE.getKey())).count())
        );

        materialCount.setWebsitAdjustmentSumbitNum(
                Convert.toInt(websitPurchaseAdjustments.stream().filter(item ->
                                 item.getFlag().equals(ExamineStatusEnum.SUBMIT.getKey())
                ).count())
        );


        materialCount.setWebsitAdjustmentCancelNum(
                Convert.toInt(websitPurchaseAdjustments.stream().filter(item ->
                        item.getFlag().equals(PartsOrderStatusEnum.CANCEL.getKey())
                ).count())
        );

        materialCount.setWebsitAdjustmentOkNum(
                Convert.toInt(websitPurchaseAdjustments.stream().filter(item ->
                        item.getFlag().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );


        materialCount.setWebsitAdjustmentFailNum(
                Convert.toInt(websitPurchaseAdjustments.stream().filter(item ->
                        item.getFlag().equals(ExamineStatusEnum.FAIL.getKey())
                ).count())
        );

        List<SettlementOrder> settlementOrderList = settlementOrderService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), SettlementOrder::getWebsitId, adminUser.getAdminWebsitIds())
                .select(SettlementOrder::getStatus, SettlementOrder::getSettlementOrderId).list();



        materialCount.setSettlementOrderWait(
                Convert.toInt(settlementOrderList.stream().filter(item ->
                        item.getStatus().equals(ExamineStatusEnum.WAIT.getKey())
                ).count())
        );
        materialCount.setSettlementOrderOk(
                Convert.toInt(settlementOrderList.stream().filter(item ->
                        item.getStatus().equals(SettlementStatusNewEnum.OK.getKey())
                ).count())
        );
        materialCount.setSettlementOrderYc(
                Convert.toInt(settlementOrderList.stream().filter(item ->
                        item.getStatus().equals(SettlementStatusNewEnum.YC.getKey())
                ).count())
        );
        materialCount.setSettlementOrderLine(
                Convert.toInt(settlementOrderList.stream().filter(item ->
                        item.getStatus().equals(SettlementStatusNewEnum.LINE.getKey())
                ).count())
        );




        List<WebsitPriceUpd> websitPriceUpds = websitPriceUpdService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPriceUpd::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPriceUpd::getFlag, WebsitPriceUpd::getSheetId, WebsitPriceUpd::getGoodsType).list();

        materialCount.setSavePriceUpdNum(
                Convert.toInt(websitPriceUpds.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.SAVE.getKey())
                ).count())
        );


        materialCount.setOkPriceUpdNum(
                Convert.toInt(websitPriceUpds.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );

        List<WebsitSales> websitSales = websitSalesService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitSales::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitSales::getFlag, WebsitSales::getSalesId, WebsitSales::getGoodsType).list();


        materialCount.setSaveSalesNum(
                Convert.toInt(websitSales.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.SAVE.getKey())
                ).count())
        );


        materialCount.setSubmitSalesNum(
                Convert.toInt(websitSales.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.SUBMIT.getKey())
                ).count())
        );

        materialCount.setPayNoTakeSalesNum(
                Convert.toInt(websitSales.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(MaterialSalesFlagEnum.PAY_NOT_TAKE.getKey())
                ).count())
        );

        materialCount.setPaytakeSalesNum(
                Convert.toInt(websitSales.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(MaterialSalesFlagEnum.PAY_TAKE.getKey())
                ).count())
        );

        materialCount.setCancelSalesNum(
                Convert.toInt(websitSales.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(MaterialSalesFlagEnum.CANCEL.getKey())
                ).count())
        );


        List<WebsitSalesRet> websitSalesRets = websitSalesRetService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitSalesRet::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitSalesRet::getRetState, WebsitSalesRet::getSalesId, WebsitSalesRet::getGoodsType).list();


        materialCount.setSaveSalesRetNum(
                Convert.toInt(websitSalesRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getRetState().equals(ExamineStatusEnum.SAVE.getKey())
                ).count())
        );

        materialCount.setSubmitSalesRetNum(
                Convert.toInt(websitSalesRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getRetState().equals(ExamineStatusEnum.SUBMIT.getKey())
                ).count())
        );

        materialCount.setOkSalesRetNum(
                Convert.toInt(websitSalesRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getRetState().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );

        materialCount.setWaitSalesRetNum(
                Convert.toInt(websitSalesRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getRetState().equals(ExamineStatusEnum.WAIT.getKey())
                ).count())
        );

        List<WebsitPurchaseRet> websitPurchaseRets = websitPurchaseRetService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPurchaseRet::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPurchaseRet::getFlag, WebsitPurchaseRet::getPurchaseId, WebsitPurchaseRet::getGoodsType).list();

        materialCount.setSavePurchaseRetNum(
                Convert.toInt(websitPurchaseRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.SAVE.getKey())
                ).count())
        );

        materialCount.setOkPurchaseRetNum(
                Convert.toInt(websitPurchaseRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.OK.getKey())
                ).count())
        );

        materialCount.setFailPurchaseRetNum(
                Convert.toInt(websitPurchaseRets.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.M.getKey()) &&
                        item.getFlag().equals(ExamineStatusEnum.FAIL.getKey())
                ).count())
        );


        return materialCount;
    }

    public MaterialPeiJianCount MaterialPeiJianCount(HttpServletRequest request) {

        AdminUserCom adminUser = commonLogic.getAdminUser();

        MaterialPeiJianCount materialPeiJianCount = new MaterialPeiJianCount();

        List<WebsitGoods> websitGoods = websitGoodsService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getCompanyWechatIds()), WebsitGoods::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitGoods::getGoodsId, WebsitGoods::getStatus, WebsitGoods::getGoodsType).list();

        materialPeiJianCount.setAllpGoodsNum(
                Convert.toInt(websitGoods.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey())
                ).count())
        );

        materialPeiJianCount.setOnPGoodsNum(
                Convert.toInt(websitGoods.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey())
                        && item.getStatus().equals(StateEnum.ON.getKey())
                ).count())
        );

        materialPeiJianCount.setOffPGoodsNum(
                Convert.toInt(websitGoods.stream().filter(item -> item.getGoodsType().equals(WebsitGoodsTypeEnum.P.getKey())
                        && item.getStatus().equals(StateEnum.OFF.getKey())
                ).count())
        );


        List<WebsitPartsNewInRecord> websitPartsNewInRecords = websitPartsNewInRecordService.lambdaQuery()
                .in(!StringUtil.isEmpty(adminUser.getCompanyWechatId()), WebsitPartsNewInRecord::getCompanyWechatId, adminUser.getCompanyWechatId())
                .select(WebsitPartsNewInRecord::getGoodsId, WebsitPartsNewInRecord::getStatus).list();

        materialPeiJianCount.setCheckPNum(
                Convert.toInt(websitPartsNewInRecords.stream().count())
        );

        materialPeiJianCount.setCheckNeverPNum(
                Convert.toInt(websitPartsNewInRecords.stream().filter(item -> item.getStatus().equals(PartsCheckStatusEnum.WAIT_CHECK.getKey())
                ).count())
        );

        materialPeiJianCount.setCheckYesPNum(
                Convert.toInt(websitPartsNewInRecords.stream().filter(item -> item.getStatus().equals(PartsCheckStatusEnum.CHECKED.getKey())
                ).count())
        );


        List<WebsitPartsSales> websitPartsSales = websitPartsSalesService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPartsSales::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPartsSales::getPartsWebsitId, WebsitPartsSales::getStatus).list();

        materialPeiJianCount.setSaveSalesPNum(
                Convert.toInt(websitPartsSales.stream().filter(item -> item.getStatus().equals(PartsOrderStatusEnum.SAVE.getKey())).count())
        );

        materialPeiJianCount.setSubmitSalesPgNum(
                Convert.toInt(websitPartsSales.stream().filter(item -> item.getStatus().equals(PartsOrderStatusEnum.SUBMIT.getKey())
                ).count())
        );

        materialPeiJianCount.setPayNoTakeSalesPgNum(
                Convert.toInt(websitPartsSales.stream().filter(item -> item.getStatus().equals(PartsOrderStatusEnum.PAYED.getKey())
                ).count())
        );

        materialPeiJianCount.setOkTakeSalesPgNum(
                Convert.toInt(websitPartsSales.stream().filter(item -> item.getStatus().equals(PartsOrderStatusEnum.END.getKey())
                ).count())
        );


        materialPeiJianCount.setCancelTakeSalesPgNum(
                Convert.toInt(websitPartsSales.stream().filter(item -> item.getStatus().equals(PartsOrderStatusEnum.CANCEL.getKey())
                ).count())
        );

        materialPeiJianCount.setYcSalesPgNum(
                Convert.toInt(websitPartsSales.stream().filter(item -> item.getStatus().equals(PartsOrderStatusEnum.EXCEPTION.getKey())
                ).count())
        );


        List<WebsitPartsNewRefundManage> websitPartsNewRefundManages = websitPartsNewRefundManageService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPartsNewRefundManage::getReceiveWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPartsNewRefundManage::getFlag, WebsitPartsNewRefundManage::getReceivePartsWebsitId).list();


        materialPeiJianCount.setBcNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SAVE.getKey())).count())
        );

        materialPeiJianCount.setTjNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SUBMIT.getKey())
                ).count())
        );

        materialPeiJianCount.setBhNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REJECT.getKey())
                ).count())
        );


        materialPeiJianCount.setTgNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.AGREE.getKey())
                ).count())
        );

        materialPeiJianCount.setDfhNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.WAIT_REVIEW.getKey())
                ).count())
        );

        materialPeiJianCount.setYfhkNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REVIEWED.getKey())
                ).count())
        );

        materialPeiJianCount.setWwfhNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.NOTREFUND.getKey())
                ).count())
        );

        materialPeiJianCount.setYyfhNewNum(
                Convert.toInt(websitPartsNewRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REFUNDED.getKey())
                ).count())
        );

        List<WebsitPartsOldRefundManage> websitPartsOldRefundManages = websitPartsOldRefundManageService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPartsOldRefundManage::getReceiveWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPartsOldRefundManage::getFlag, WebsitPartsOldRefundManage::getReceiveWebsitId,WebsitPartsOldRefundManage::getRepairFlag).list();



        materialPeiJianCount.setBcOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SAVE.getKey())
                        && item.getRepairFlag().equals("INNER")

                ).count())
        );

        materialPeiJianCount.setTjOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SUBMIT.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );

        materialPeiJianCount.setBhOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REJECT.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );


        materialPeiJianCount.setTgOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.AGREE.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );

        materialPeiJianCount.setDfhOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.WAIT_REVIEW.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );

        materialPeiJianCount.setYfhkOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REVIEWED.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );

        materialPeiJianCount.setWwfhOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.NOTREFUND.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );

        materialPeiJianCount.setYyfhOldNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REFUNDED.getKey())
                        && item.getRepairFlag().equals("INNER")
                ).count())
        );


        List<WebsitPartsChangeSales> websitPartsChangeSales = websitPartsChangeSalesService.lambdaQuery()
                .in(!CollectionUtils.isEmpty(adminUser.getAdminWebsitIds()), WebsitPartsChangeSales::getWebsitId, adminUser.getAdminWebsitIds())
                .select(WebsitPartsChangeSales::getFlag, WebsitPartsChangeSales::getSalesId).list();


        materialPeiJianCount.setBcNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SAVE.getKey())).count())
        );

        materialPeiJianCount.setTjNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SUBMIT.getKey())
                ).count())
        );

        materialPeiJianCount.setBhNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REJECT.getKey())
                ).count())
        );


        materialPeiJianCount.setTgNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.AGREE.getKey())
                ).count())
        );

        materialPeiJianCount.setDfhNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.WAIT_REVIEW.getKey())
                ).count())
        );

        materialPeiJianCount.setYfhkNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REVIEWED.getKey())
                ).count())
        );

        materialPeiJianCount.setWwfhNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.NOTREFUND.getKey())
                ).count())
        );

        materialPeiJianCount.setYyfhNewSaleNum(
                Convert.toInt(websitPartsChangeSales.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REFUNDED.getKey())
                ).count())
        );




        materialPeiJianCount.setBcNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SAVE.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")

                ).count())
        );

        materialPeiJianCount.setTjNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.SUBMIT.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );

        materialPeiJianCount.setBhNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REJECT.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );


        materialPeiJianCount.setTgNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.AGREE.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );

        materialPeiJianCount.setDfhNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.WAIT_REVIEW.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );

        materialPeiJianCount.setYfhkNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REVIEWED.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );

        materialPeiJianCount.setWwfhNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.NOTREFUND.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );

        materialPeiJianCount.setYyfhNewInnerNum(
                Convert.toInt(websitPartsOldRefundManages.stream().filter(item -> item.getFlag().equals(PartsOrderFlagEnum.REFUNDED.getKey())
                        && item.getRepairFlag().equals("OUTSIDE")
                ).count())
        );


        return materialPeiJianCount;
    }
}
