package com.ssm.manage.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.jfinal.core.paragetter.BigDecimalGetter;
import com.jfinal.wxaapp.api.WxaTemplate;
import com.ssm.core.utils.StoreParaUtils;
import com.ssm.core.utils.StrComparatorUtils;
import com.ssm.manage.dao.SsmStoreStatisticDao;
import com.ssm.manage.entity.*;
import com.ssm.manage.extendEntity.*;
import com.ssm.manage.mapper.CourseListMemberInitMapper;
import com.ssm.manage.mapper.MemberInitStaffMapper;
import com.ssm.manage.query.*;
import com.ssm.manage.response.*;
import com.ssm.manage.service.*;
import com.ssm.manage.utils.BigDecimalUtils;
import com.ssm.manage.utils.Constant;
import com.ssm.manage.utils.DateUtils;
import com.ssm.manage.utils.StringUtils;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.StringEncoderComparator;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static java.util.Comparator.comparing;

@Service
@Slf4j
public class SsmStoreStatisticServiceImpl implements SsmStoreStatisticService {
    @Autowired
    private SsmAccountTradeRecordService ssmAccountTradeRecordService;

    @Autowired
    private SsmRechargeService ssmRechargeService;

    @Autowired
    private CourseListMemberInitMapper courseListMemberInitMapper;

    @Autowired
    private MemberInitStaffMapper memberInitStaffMapper;

    @Autowired
    private SsmDebtService ssmDebtService;
    @Autowired
    private SsmServiceOrdersService ssmServiceOrdersService;

    @Autowired
    private SsmCourseService ssmCourseService;
    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

    @Autowired
    private SsmPayService ssmPayService;
    @Autowired
    private SsmCardChangeService ssmCardChangeService;
    @Autowired
    private SsmCardChangeOutProjectService ssmCardChangeOutProjectService;

    @Autowired
    private SsmCardChangeInProjectService ssmCardChangeInProjectService;

    @Autowired
    private SsmRechargeTurnCourseService ssmRechargeTurnCourseService;

    @Autowired
    private SsmCoursePayListService ssmCoursePayListService;


    @Autowired
    private SsmRechargeTypeSevice ssmRechargeTypeSevice;

    @Autowired
    private SsmProjectService ssmProjectService;

    @Autowired
    private SsmCashService ssmCashService;

    @Autowired
    private SsmRepayService ssmRepayService;

    @Autowired
    private SsmRepayTradeService ssmRepayTradeService;

    @Autowired
    private SsmCourseAccountService  ssmCourseAccountService;

    @Autowired
    private SsmStoreStatisticService  ssmStoreStatisticService;

    @Autowired
    private SsmRefundRechargeService ssmRefundRechargeService;

    @Autowired
    private SsmRefundCourseService ssmRefundCourseService;
    @Autowired
    private SsmRefundOrderService ssmRefundOrderService;

    @Autowired
    private SsmRefundCashService ssmRefundCashService;

    @Autowired
    private SsmDocPromotionService ssmDocPromotionService;

    @Autowired
    private SsmBaseStaffService ssmBaseStaffService;

    @Autowired
    private SsmBaseGrouponCardService ssmBaseGrouponCardService;

    @Autowired
    private SsmStoreStatisticDao dao;

    @Override
    public List<MemberStatistic> selectMemberList(Long storeId, String dateStr) throws ParseException {
//        String dateStr = DateUtils.ymdFormat(date);
        Date date = DateUtils.ymParse(dateStr);
        AccountTradeRecordRequest accountTradeRecordRequest = new AccountTradeRecordRequest();
        accountTradeRecordRequest.setDate(dateStr);
        accountTradeRecordRequest.setInputDate(date);
        accountTradeRecordRequest.setStoreId(storeId);

        List<MemberStatistic> memberStatisticList = dao.selectMemberList(accountTradeRecordRequest);


        return memberStatisticList;
    }

    @Override
    public List<ProjectStatistic> selectProjectList(Long storeId, String dateStr, Integer type) throws ParseException {

        List<ProjectStatistic> list = new ArrayList<>();
        List<ProjectStatistic> projectStatisticList = new ArrayList<>();
//        String dateStr = DateUtils.ymdFormat(date);
        Date date = DateUtils.ymParse(dateStr);
        //当天购卡金额 当天服务金额
        if (type == 1 || type == 2) {
            AccountTradeRecordRequest accountTradeRecordRequest = new AccountTradeRecordRequest();
            accountTradeRecordRequest.setDate(dateStr);
            accountTradeRecordRequest.setInputDate(date);
            accountTradeRecordRequest.setStoreId(storeId);
            accountTradeRecordRequest.setType(type);
            projectStatisticList = dao.selectProjectList(accountTradeRecordRequest);
        }else {//截止当天项目结存金额
            CourseAccountRequest courseAccountRequest = new CourseAccountRequest();
            courseAccountRequest.setStoreId(storeId);
            courseAccountRequest.setCourseType("0");
            List<CourseAccount> courseAccountList = ssmCourseAccountService.selectList(courseAccountRequest);
            //对账户表通过项目进行分组
            Map<Long, List<CourseAccount>> map = courseAccountList.stream().collect(Collectors.groupingBy(CourseAccount::getCourseProjectId));
            //每个项目计算结存金额
            Iterator<Map.Entry<Long,List<CourseAccount>>> entryIterator = map.entrySet().iterator();
            while (entryIterator.hasNext()) {
                Map.Entry<Long, List<CourseAccount>> entry = entryIterator.next();
                List<CourseAccount> accounts = entry.getValue();
                BigDecimal projectStatisticMoney = BigDecimalUtils.bigDecimal("0");
                for (CourseAccount account : accounts) {
                    projectStatisticMoney = BigDecimalUtils.add(projectStatisticMoney,
                            BigDecimalUtils.div(BigDecimalUtils.multiply(BigDecimalUtils.bigDecimal(account.getCourseConsumeCount().toString()),account.getCourseProjectMoney()),
                            BigDecimalUtils.bigDecimal(account.getCourseCount().toString())));
                }
                ProjectStatistic projectStatistic = new ProjectStatistic();
                projectStatistic.setProjectId(entry.getKey());
                projectStatistic.setProjectName(accounts.get(0).getCourseProjectName());
                projectStatistic.setProjectStatisticMoney(projectStatisticMoney);
                projectStatisticList.add(projectStatistic);
            }
        }
        BigDecimal totalMoney = BigDecimalUtils.bigDecimal("0");
        for (ProjectStatistic projectStatistic : projectStatisticList) {
            totalMoney =  BigDecimalUtils.add(totalMoney, projectStatistic.getProjectStatisticMoney());
            list.add(projectStatistic);
        }
        BigDecimal totalRatio = BigDecimalUtils.bigDecimal("0");
        for (int i = 0; i < list.size(); i++) {
            ProjectStatistic projectStatistic = list.get(i);

            BigDecimal ratio = BigDecimalUtils.bigDecimal("0");
            if (i < list.size() - 1) {
                ratio = BigDecimalUtils.div(projectStatistic.getProjectStatisticMoney(), totalMoney);
                projectStatistic.setRatio(ratio);
                totalRatio = BigDecimalUtils.add(totalRatio, ratio);
            }else if ( i == list.size() - 1){//最后一次 1减去之前占比总和
                projectStatistic.setRatio(BigDecimalUtils.subtract(BigDecimalUtils.bigDecimal("1"),totalRatio));
            }

        }

        //降序排列
        list.sort(comparing(ProjectStatistic::getProjectStatisticMoney).reversed());
//        Collections.sort(list,new Comparator<ProjectStatistic>() {
//            @Override
//            public int compare(ProjectStatistic o1, ProjectStatistic o2) {
//                if(o1.getProjectStatisticMoney().compareTo(o2.getProjectStatisticMoney()) > 0) {
//                        return 1;
//
//                }
//                 return -1;
//            }
//        });

        return list;
    }

    @Override
    public List<ProjectStatistic> selectProjectList(Long storeId, String dateStr, Integer type,String endDate) throws ParseException {

        List<ProjectStatistic> list = new ArrayList<>();
        List<ProjectStatistic> projectStatisticList = new ArrayList<>();
//        String dateStr = DateUtils.ymdFormat(date);
        Date date = DateUtils.ymParse(dateStr);
        Date enddate = DateUtils.ymParse(endDate);
        //当天购卡金额 当天服务金额
        if (type == 1 || type == 2) {
            AccountTradeRecordRequest accountTradeRecordRequest = new AccountTradeRecordRequest();
            accountTradeRecordRequest.setDate(dateStr);
            accountTradeRecordRequest.setInputDate(date);
            accountTradeRecordRequest.setEndDate(enddate);
            accountTradeRecordRequest.setStoreId(storeId);
            accountTradeRecordRequest.setType(type);
            projectStatisticList = dao.selectProjectLists(accountTradeRecordRequest);
        }else {//截止当天项目结存金额
            CourseAccountRequest courseAccountRequest = new CourseAccountRequest();
            courseAccountRequest.setStoreId(storeId);
            courseAccountRequest.setCourseType("0");
            List<CourseAccount> courseAccountList = ssmCourseAccountService.selectList(courseAccountRequest);
            //对账户表通过项目进行分组
            Map<Long, List<CourseAccount>> map = courseAccountList.stream().collect(Collectors.groupingBy(CourseAccount::getCourseProjectId));
            //每个项目计算结存金额
            Iterator<Map.Entry<Long,List<CourseAccount>>> entryIterator = map.entrySet().iterator();
            while (entryIterator.hasNext()) {
                Map.Entry<Long, List<CourseAccount>> entry = entryIterator.next();
                List<CourseAccount> accounts = entry.getValue();
                BigDecimal projectStatisticMoney = BigDecimalUtils.bigDecimal("0");
                for (CourseAccount account : accounts) {
                    projectStatisticMoney = BigDecimalUtils.add(projectStatisticMoney,
                            BigDecimalUtils.div(BigDecimalUtils.multiply(BigDecimalUtils.bigDecimal(account.getCourseConsumeCount().toString()),account.getCourseProjectMoney()),
                            BigDecimalUtils.bigDecimal(account.getCourseCount().toString())));
                }
                ProjectStatistic projectStatistic = new ProjectStatistic();
                projectStatistic.setProjectId(entry.getKey());
                projectStatistic.setProjectName(accounts.get(0).getCourseProjectName());
                projectStatistic.setProjectStatisticMoney(projectStatisticMoney);
                projectStatisticList.add(projectStatistic);
            }
        }
        BigDecimal totalMoney = BigDecimalUtils.bigDecimal("0");
        for (ProjectStatistic projectStatistic : projectStatisticList) {
            totalMoney =  BigDecimalUtils.add(totalMoney, projectStatistic.getProjectStatisticMoney());
            list.add(projectStatistic);
        }
        BigDecimal totalRatio = BigDecimalUtils.bigDecimal("0");
        for (int i = 0; i < list.size(); i++) {
            ProjectStatistic projectStatistic = list.get(i);

            BigDecimal ratio = BigDecimalUtils.bigDecimal("0");
            if (i < list.size() - 1) {
                ratio = BigDecimalUtils.div(projectStatistic.getProjectStatisticMoney(), totalMoney);
                projectStatistic.setRatio(ratio);
                totalRatio = BigDecimalUtils.add(totalRatio, ratio);
            }else if ( i == list.size() - 1){//最后一次 1减去之前占比总和
                projectStatistic.setRatio(BigDecimalUtils.subtract(BigDecimalUtils.bigDecimal("1"),totalRatio));
            }

        }

        //降序排列
        list.sort(comparing(ProjectStatistic::getProjectStatisticMoney).reversed());
//        Collections.sort(list,new Comparator<ProjectStatistic>() {
//            @Override
//            public int compare(ProjectStatistic o1, ProjectStatistic o2) {
//                if(o1.getProjectStatisticMoney().compareTo(o2.getProjectStatisticMoney()) > 0) {
//                        return 1;
//
//                }
//                 return -1;
//            }
//        });

        return list;
    }


    @Override
    public List<StaffStatistic> selectMonthStaffList(Long storeId, Date date) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal recStatisticMoney =  BigDecimalUtils.bigDecimal("0");
        BigDecimal courseStatisticMoney =  BigDecimalUtils.bigDecimal("0");
        BigDecimal cashStatisticMoney =  BigDecimalUtils.bigDecimal("0");
        //转换时间为年月
        String dateStr = DateUtils.ymFormat(date);
        //查询充值业务员信息
        List<RechargeListResponse> recList = ssmRechargeService.selectList(storeId, dateStr, date);
        //查询疗程业务员信息
        List<CourseListResponse> courseList = ssmCourseService.selectList(storeId, dateStr, date);
        //查询服务单业务员信息
        List<CashListResponse> cashList = ssmCashService.selectList(storeId, dateStr, date);
        //查询还款单业务员信息
        List<RepayTradeResponse> recRepayLists = ssmRepayService.selectList(storeId, dateStr, Constant.doc_type_recharge);
        List<RepayTradeResponse> courseRepayLists = ssmRepayService.selectList(storeId, dateStr, Constant.doc_type_card_use);
        //查询充值退款单业务员
        List<RefundRechargeResponse> refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
        //查询疗程退款单业务员
        List<RefundCourseResponse> refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
        //查询收银退款单业务员
        List<RefundCashResponse> refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
        //查询促销单业务员
        List<DocPromotionResponse> promotionList = ssmDocPromotionService.selectList(storeId, dateStr);

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        recRepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseRepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long,List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()){
            Map.Entry<Long,List<AchiCommEntity>> entry = entryIterator.next();
            List<AchiCommEntity> list = entry.getValue();
            //充值 + 充值还款
            BigDecimal recMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //充值退款
            BigDecimal recRefundMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            recStatisticMoney = BigDecimalUtils.subtract(recMoney, recRefundMoney);
            //疗程 + 疗程还款
            BigDecimal courseMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //疗程退款
            BigDecimal courseRefundMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            courseStatisticMoney = BigDecimalUtils.subtract(courseMoney, courseRefundMoney);
            //收银
            BigDecimal cashMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //消费退
            BigDecimal cashRefundMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //促销
            BigDecimal promotionMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            cashStatisticMoney = BigDecimalUtils.subtract(cashMoney, cashRefundMoney);

            StaffStatistic staffStatistic = new StaffStatistic();
            staffStatistic.setStaffId(entry.getKey());
            staffStatistic.setStaffName(list.get(0).getSaleStaffName());
            staffStatistic.setBrandNumber(list.get(0).getBrandNumber());
            staffStatistic.setDate(date);
            staffStatistic.setRecStatisticMoney(recStatisticMoney);
            staffStatistic.setCourseStatisticMoney(courseStatisticMoney);
            staffStatistic.setCashStatisticMoney(cashStatisticMoney);
            staffStatistic.setPromotionStatisticMoney(promotionMoney);
            staffStatisticList.add(staffStatistic);
        }

        staffStatisticList.sort(comparing(StaffStatistic::getCashStatisticMoney).reversed());
        return staffStatisticList;
    }


    @Override
    public List<StaffStatistic> selectDayStaffList(Long storeId, Date date) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount =  BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount =  BigDecimalUtils.bigDecimal("0");
        //转换时间为年月
        String dateStr = DateUtils.ymdFormat(date);
        //查询充值业务员信息
        List<RechargeListResponse> recList = ssmRechargeService.selectList(storeId, dateStr, date);
        //查询疗程业务员信息
        List<CourseListResponse> courseList = ssmCourseService.selectList(storeId, dateStr, date);
        //查询服务单业务员信息
        List<CashListResponse> cashList = ssmCashService.selectList(storeId, dateStr, date);
        //查询还款单业务员信息
        List<RepayTradeResponse> RepayLists = ssmRepayService.selectList(storeId, dateStr, null);

        //查询充值退款单业务员
        List<RefundRechargeResponse> refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
        //查询疗程退款单业务员
        List<RefundCourseResponse> refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
        //查询收银退款单业务员
        List<RefundCashResponse> refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
        //查询促销单业务员
        List<DocPromotionResponse> promotionList = ssmDocPromotionService.selectList(storeId, dateStr);

        //查询加价转疗程
        List<CardChangeInProjectResponse> cardChangeLists = ssmCardChangeService.selectList(storeId,dateStr);
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateStr);
        List<BaseGrouponCardResponse> baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
        List<ServiceOrdersResponse> serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId,dateStr,date);

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        rechargeTurnCourses.forEach(rechargeTurnCoursesResponse -> rechargeTurnCoursesResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long,List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()){
            Map.Entry<Long,List<AchiCommEntity>> entry = entryIterator.next();
            List<AchiCommEntity> list = entry.getValue();
            //充值 + 充值还款 业绩
            //BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal recAchi = list.stream().filter(achiCommEntity -> (Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) || Constant.doc_type_repay.equals(achiCommEntity.getType()))).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //充值退款 业绩
            BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //疗程 + 疗程还款 业绩
            BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO,BigDecimal::add);
            //疗程退款 业绩
            BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //收银 业绩
            BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && !achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO,BigDecimal::add);

            //消费退 业绩
            BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //还款业绩
            BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //充值 + 充值还款 提成
            //BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal recComm = list.stream().filter(achiCommEntity -> (Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) || Constant.doc_type_repay.equals(achiCommEntity.getType()))).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //充值退款 提成
            BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //疗程 + 疗程还款 提成
            BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //疗程退款 提成
            BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //收银 提成
            BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO,BigDecimal::add);
            //消费退 提成
            BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //还款提成
            BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //促销业绩
            BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //促销提成
            BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //加价转疗程 业绩
            BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
            //加价转疗程 提成
            BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal courseChangeComm = BigDecimalUtils.add(courseChangeCashComm,courseChangeCardComm);

            //疗程转充值
            BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
            //团购卡业绩
            BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
            //团购卡提成
            BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


            achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                    BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(courseChangeCashAchi);
            commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                    BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm).add(courseChangeComm).add(rechargeTurnCourseComm);


            /*achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                    BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi,courseAchi),cashAchi),promotionAchi),recRefundAchi),courseRefundAchi),cashRefundAchi);
            commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                    BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm,courseComm),cashComm),promotionComm),recRefundComm),courseRefundComm),cashRefundComm);
            */StaffStatistic staffStatistic = new StaffStatistic();
            staffStatistic.setStaffId(entry.getKey());
            staffStatistic.setStaffName(list.get(0).getSaleStaffName());
            staffStatistic.setBrandNumber(list.get(0).getBrandNumber());
            staffStatistic.setDate(date);
            staffStatistic.setAchievementAmount(achievementAmount);
            staffStatistic.setCommissionAmount(commissionAmount);


            staffStatisticList.add(staffStatistic);
        }

        List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
        List<AchiCommEntity> totalList1 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
        //合并list
        cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
        while (entryIterator1.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();

                //业绩
                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardAchi = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardComm = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);


                /*achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(listByStaff.get(listByStaff.size()-1).getSaleStaffName());
                statistic.setBrandNumber(listByStaff.get(listByStaff.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(date);
                statistic.setAchievementAmount(CardAchi.negate());
                statistic.setCommissionAmount(CardComm.negate());
                /*statistic.setClassify(staffStatistic.getClassify());
                statistic.setStoreId(staffStatistic.getStoreId());*/

                staffStatisticList1.add(statistic);

            //}
        }

        for (StaffStatistic staffStatistics : staffStatisticList) {
            for (StaffStatistic statistic : staffStatisticList1) {
                if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
                    staffStatistics.setAchievementAmount(BigDecimalUtils.add(staffStatistics.getAchievementAmount(),statistic.getAchievementAmount()));
                    staffStatistics.setCommissionAmount(BigDecimalUtils.add(staffStatistics.getCommissionAmount(),statistic.getCommissionAmount()));
                    /*staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                    staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));*/
                }
            }
        }
        List<Long> longs = staffStatisticList.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
        List<StaffStatistic> collect = staffStatisticList1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

        for (StaffStatistic statistic : collect) {
            staffStatisticList.add(statistic);
        }



        List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
        List<AchiCommEntity> totalList2 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
        //合并list
        coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
        while (entryIterator2.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();


                //业绩
                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardAchi = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardComm = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);



                //总卡付提成
                /*BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(listByStaff.get(listByStaff.size()-1).getSaleStaffName());
                statistic.setBrandNumber(listByStaff.get(listByStaff.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(date);
                //statistic.setAchievementAmount(CardAchi);
                statistic.setCommissionAmount(CardComm.negate());
                //statistic.setCardAchi(CardAchi);
                //statistic.setCardComm(CardComm);

                staffStatisticList3.add(statistic);

            //}
        }

        for (StaffStatistic staffStatistics : staffStatisticList) {
            for (StaffStatistic statistic : staffStatisticList3) {
                if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
                    //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                    //staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                    staffStatistics.setCommissionAmount(BigDecimalUtils.add(staffStatistics.getCommissionAmount(),statistic.getCommissionAmount()));
                }
            }
        }
        List<Long> longs1 = staffStatisticList.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
        List<StaffStatistic> collect1 = staffStatisticList3.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

        for (StaffStatistic statistic : collect1) {
            staffStatisticList.add(statistic);
        }

        staffStatisticList.sort(comparing(StaffStatistic::getAchievementAmount).reversed());
        return staffStatisticList;
    }

    @Override
    public List<StaffStatistic> collectingSource(Long storeId, Date date) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount =  BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount =  BigDecimalUtils.bigDecimal("0");
        //转换时间为年月
        String dateStr = DateUtils.ymdFormat(date);
        //查询充值业务员信息
        List<RechargeListResponse> recList = ssmRechargeService.selectList(storeId, dateStr, date);
        //查询疗程业务员信息
        List<CourseListResponse> courseList = ssmCourseService.selectList(storeId, dateStr, date);
        //查询服务单业务员信息
        List<CashListResponse> cashList = ssmCashService.selectList(storeId, dateStr, date);
        //查询还款单业务员信息
        List<RepayTradeResponse> RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
        //查询促销单业务员
        List<DocPromotionResponse> promotionList = ssmDocPromotionService.selectList(storeId, dateStr);

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long,List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()){
            Map.Entry<Long,List<AchiCommEntity>> entry = entryIterator.next();
            List<AchiCommEntity> list = entry.getValue();
            //充值 + 充值还款 业绩
            BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //充值退款 业绩
            BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //疗程 + 疗程还款 业绩
            BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //疗程退款 业绩
            BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //收银 业绩
            BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //消费退 业绩
            BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //还款业绩
            BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //充值 + 充值还款 提成
            BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //充值退款 提成
            BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //疗程 + 疗程还款 提成
            BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //疗程退款 提成
            BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            //收银 提成
            BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //消费退 提成
            BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //还款提成
            BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //促销业绩
            BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            //促销提成
            BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);

            achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                    BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi,courseAchi),cashAchi),promotionAchi),recRefundAchi),courseRefundAchi),cashRefundAchi);
            commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                    BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm,courseComm),cashComm),promotionComm),recRefundComm),courseRefundComm),cashRefundComm);
            StaffStatistic staffStatistic = new StaffStatistic();
            staffStatistic.setStaffId(entry.getKey());
            staffStatistic.setStaffName(list.get(0).getSaleStaffName());
            staffStatistic.setBrandNumber(list.get(0).getBrandNumber());
            staffStatistic.setDate(date);
            staffStatistic.setAchievementAmount(achievementAmount);
            staffStatistic.setCommissionAmount(commissionAmount);
            staffStatisticList.add(staffStatistic);
        }

        staffStatisticList.sort(comparing(StaffStatistic::getAchievementAmount).reversed());
        return staffStatisticList;
    }


    @Override
    public List<StaffStatistic> achiCommList(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        int type = staffStatistic.getType();
        String dateStr = "";
        Date date = new Date();
        if (0 == type) {
            //上月
            date = DateUtils.diffMonth(new Date(), -1);
            dateStr = DateUtils.ymFormat(date);
        } else if (1 == type) {
            //昨日
            date = DateUtils.diffDay(new Date(), -1);
            dateStr = DateUtils.ymdFormat(date);
        } else if (2 == type) {
            //今日
            dateStr = DateUtils.ymdFormat(date);
        } else {
            //当月
            dateStr = DateUtils.ymFormat(date);
        }



        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()){
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String dateString = sdf.format(staffStatistic.getDate());

        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<RefundCashResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();

        //查询加价转疗程
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();
        List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();

        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId,dateStr);
            }else if ("9".equals(staffStatistic.getClassify())) {

                //疗程转充值
                rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateString);
            }else if ("10".equals(staffStatistic.getClassify())) {
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId, dateStr);
            }else if ("11".equals(staffStatistic.getClassify())) {
                //查询开房收银
                serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
            }
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        rechargeTurnCourses.forEach(rechargeTurnCoursesResponse -> rechargeTurnCoursesResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //加价转疗程 提成
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO,BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO,BigDecimal::add);
                    BigDecimal courseChangeComm = BigDecimalUtils.add(courseChangeCashComm,courseChangeCardComm);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);



                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), BigDecimalUtils.add(cashCardComm,cashCashComm)), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm).add(courseChangeComm).add(rechargeTurnCourseComm);;
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(0).getSaleStaffName());
                    statistic.setBrandNumber(list.get(0).getBrandNumber());
                    //按天查询用date
                    if (type == 1 || type == 2) {
                        statistic.setDate(date);
                    } else {
                        //按月查询 需按天进行分组 此时date用单据时间
                        statistic.setDate(list.get(0).getDocDate());
                    }

                    if (cashAchi == null) {
                        cashAchi = BigDecimal.ZERO;
                    }
                    BigDecimal achievementAmount1 = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(courseChangeCashAchi);
                    BigDecimal commissionAmount1 = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseCashComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm).add(courseChangeComm).add(rechargeTurnCourseComm);


                    statistic.setAchievementAmount(achievementAmount1);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    staffStatisticList.add(statistic);
                }
           }
        }


        if ("8".equals(staffStatistic.getClassify())){

            List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
            List<AchiCommEntity> totalList1 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
            //合并list
            cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
            while (entryIterator1.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                if (entry.getKey().equals(staffStatistic.getStaffId())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();

                    //业绩
                    //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchi = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardComm = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);


                /*achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(listByStaff.get(listByStaff.size()-1).getSaleStaffName());
                    statistic.setBrandNumber(listByStaff.get(listByStaff.size()-1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(date);
                    statistic.setAchievementAmount(CardAchi.negate());
                    statistic.setCommissionAmount(CardComm.negate());
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());

                    staffStatisticList1.add(statistic);
                }

                //}
            }

            for (StaffStatistic staffStatistics : staffStatisticList) {
                for (StaffStatistic statistic : staffStatisticList1) {
                    if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
                        staffStatistics.setAchievementAmount(BigDecimalUtils.add(staffStatistics.getAchievementAmount(),statistic.getAchievementAmount()));
                        staffStatistics.setCommissionAmount(BigDecimalUtils.add(staffStatistics.getCommissionAmount(),statistic.getCommissionAmount()));
                        staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                        staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
                    }
                }
            }
            List<Long> longs = staffStatisticList.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
            List<StaffStatistic> collect = staffStatisticList1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

            for (StaffStatistic statistic : collect) {
                staffStatisticList.add(statistic);
            }


        }
        if ("9".equals(staffStatistic.getClassify())){

            List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList2 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
            //合并list
            coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
            while (entryIterator2.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                if (entry.getKey().equals(staffStatistic.getStaffId())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();


                    //业绩
                    //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchi = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardComm = listByStaff.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //总卡付提成
                    /*BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(listByStaff.get(listByStaff.size()-1).getSaleStaffName());
                    statistic.setBrandNumber(listByStaff.get(listByStaff.size()-1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(date);
                    //statistic.setAchievementAmount(CardAchi);
                    statistic.setCommissionAmount(CardComm.negate());
                    //statistic.setCardAchi(CardAchi);
                    //statistic.setCardComm(CardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    staffStatisticList3.add(statistic);

                    //}
                }
            }

            for (StaffStatistic staffStatistics : staffStatisticList) {
                for (StaffStatistic statistic : staffStatisticList3) {
                    if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
                        //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                        //staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(),statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                        staffStatistics.setCommissionAmount(BigDecimalUtils.add(staffStatistics.getCommissionAmount(),statistic.getCommissionAmount()));
                    }
                }
            }
            List<Long> longs1 = staffStatisticList.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
            List<StaffStatistic> collect1 = staffStatisticList3.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

            for (StaffStatistic statistic : collect1) {
                staffStatisticList.add(statistic);
            }

        }



        staffStatisticList.sort(comparing(StaffStatistic::getDate).reversed());
        return staffStatisticList;
    }

    @Override
    public List<StaffStatistic> achiCommListRepay(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        int type = staffStatistic.getType();
        String dateStr = "";
        Date date = new Date();
        if (0 == type) {
            //上月
            date = DateUtils.diffMonth(new Date(), -1);
            dateStr = DateUtils.ymFormat(date);
        } else if (1 == type) {
            //昨日
            date = DateUtils.diffDay(new Date(), -1);
            dateStr = DateUtils.ymdFormat(date);
        } else if (2 == type) {
            //今日
            dateStr = DateUtils.ymdFormat(date);
        } else {
            //当月
            dateStr = DateUtils.ymFormat(date);
        }

        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()){
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }

        Long storeId = staffStatistic.getStoreId();

        List<RepayTradeResponse> RepayLists = new ArrayList<>();
            if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list

        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap.entrySet().iterator();
        List<AchiCommEntity> achiCommEntityList = new ArrayList<>();
        while (entryIterator1.hasNext()){
            Map.Entry<Long,List<AchiCommEntity>> entry = entryIterator1.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> value = entry.getValue();
                for (AchiCommEntity achiCommEntity : value) {
                    achiCommEntity.setTotalPerformance(achiCommEntity.getTotalPerformance().subtract(achiCommEntity.getCardAchi()));
                }
                achiCommEntityList = value;
            }
        }
        for (AchiCommEntity achiCommEntity : achiCommEntityList) {
            achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm()))));
            achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
            achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi()))));
            achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
            achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance()))));
            achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission()))));
            StaffStatistic staffStatistic1 = new StaffStatistic();
            staffStatistic1.setAchievementAmount(achiCommEntity.getTotalPerformance());
            staffStatistic1.setCommissionAmount(achiCommEntity.getTotalCommission());
            staffStatistic1.setClassify("3");
            staffStatistic1.setBrandNumber(achiCommEntity.getBrandNumber());
            staffStatistic1.setStaffId(achiCommEntity.getSaleStaffId());
            staffStatistic1.setStaffName(achiCommEntity.getSaleStaffName());//按天查询用date
            if (type == 1 || type == 2) {
                staffStatistic1.setDate(date);
            } else {
                //按月查询 需按天进行分组 此时date用单据时间
                staffStatistic1.setDate(achiCommEntity.getDocDate());
            }
            /*staffStatistic1.setStaffId(entry.getKey());
            staffStatistic1.setStaffName(list.get(0).getSaleStaffName());
            staffStatistic1.setBrandNumber(list.get(0).getBrandNumber());*/
            staffStatisticList.add(staffStatistic1);
        }
        List<StaffStatistic> outList = new ArrayList<>();
        BigDecimal reduce = staffStatisticList.stream().map(StaffStatistic::getAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal reduce1 = staffStatisticList.stream().map(StaffStatistic::getCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
        StaffStatistic statistic = new StaffStatistic();
        statistic.setClassify("3");
        if (staffStatisticList.size() != 0){
            statistic.setBrandNumber(staffStatisticList.get(staffStatisticList.size()-1).getBrandNumber());
            statistic.setStaffId(staffStatisticList.get(staffStatisticList.size()-1).getStaffId());
            statistic.setStaffName(staffStatisticList.get(staffStatisticList.size()-1).getStaffName());//按天查询用date
        }

        if (type == 1 || type == 2) {
            statistic.setDate(date);
        }
        statistic.setAchievementAmount(reduce);
        statistic.setCommissionAmount(reduce1);
        if (staffStatisticList.size() != 0){
            outList.add(statistic);
        }

        /*for (StaffStatistic statistic : staffStatisticList) {
            StaffStatistic staffStatistic1 = new StaffStatistic();
            staffStatistic1.setClassify("3");
            staffStatistic1.setBrandNumber(statistic.getBrandNumber());
            staffStatistic1.setStaffId(statistic.getStaffId());
            staffStatistic1.setStaffName(statistic.getStaffName());//按天查询用date
            if (type == 1 || type == 2) {
                staffStatistic1.setDate(date);
            } else {
                //按月查询 需按天进行分组 此时date用单据时间
                staffStatistic1.setDate(statistic.getDate());
            }
        }*/
        /*//计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(0).getSaleStaffName());
                    statistic.setBrandNumber(list.get(0).getBrandNumber());
                    //按天查询用date
                    if (type == 1 || type == 2) {
                        statistic.setDate(date);
                    } else {
                        //按月查询 需按天进行分组 此时date用单据时间
                        statistic.setDate(list.get(0).getDocDate());
                    }
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    staffStatisticList.add(statistic);
                }
            }
        }*/

        outList.sort(comparing(StaffStatistic::getDate).reversed());
        return outList;
    }

    @Override
    public List<StaffStatistic> achiCommListss(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getSelectDate();
        Date date = new Date();

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String dateString = sdf.format(staffStatistic.getDate());


        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()) {
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }

        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        //List<RefundCashResponse> refundCashList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
        List<BaseGrouponCardResponse> baseGrouponCardResponses = new ArrayList<>();
        List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            baseGrouponCardResponses = ssmBaseGrouponCardService.selectDates(storeId, dateStr);
            serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
            } else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            } else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            } else if ("9".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                //疗程转充值
                rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateString);
            }else if ("10".equals(staffStatistic.getClassify())) {
                //查询团购卡
                baseGrouponCardResponses = ssmBaseGrouponCardService.selectDates(storeId, dateStr);
            }else if ("11".equals(staffStatistic.getClassify())) {
                //查询开房收银
                serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
            }
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            List<CardChangeOutProject> collect = cardChangeList.getOutProjects().stream().filter(item -> item.getEntities() != null && item.getEntities().size() > 0).collect(Collectors.toList());
            collect.
                    forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                            .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        }
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        rechargeTurnCourses.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCardResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    BigDecimal promotionRepay = list.stream().filter(item -> item.getDocType().equals("promotion_card_use") && item.getOrderType().equals("promotion_card_use")&&item.getType().equals("card_repay")).map(achiCommEntity -> achiCommEntity.getCashAchi().multiply(achiCommEntity.getSaleRatio().divide(new BigDecimal("100")))).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal jjzlcCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal jjzlcCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银销卡
                    BigDecimal cashAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退
                    BigDecimal cashRefundComm1 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm1 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值卡付消费退
                    BigDecimal cashRefundCardComm1 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //疗程卡付消费退
                    BigDecimal cashRefundCardComm2 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    BigDecimal cashcxyj=new BigDecimal("0");
                    BigDecimal cashcxtc=new BigDecimal("0");
                    BigDecimal cardcxtc=new BigDecimal("0");
                    //todo
//                    if(list.get(0).getDocType().equals("promotion_card_use")&&list.get(0).getType().equals(Constant.doc_type_repay)){
//                        //促销还款业绩
//                         cashcxyj=cashcxyj.add(list.get(0).getCashAchi());
//                        //促销还款提成
//                        cashcxtc=cashcxtc.add(list.get(0).getCashComm());
//                        cardcxtc=cardcxtc.add(list.get(0).getCardComm());
//                    }
                    //todo
                    /*旧的疗程促销计算业绩和提成
                    //BigDecimal cashcxyj = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //促销还款提成
                    //BigDecimal cashcxtc = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //BigDecimal cardcxtc = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    */
                    //沐足技师卡付业绩与提成
                    BigDecimal CardFootMassageChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardFootMassageComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //沐足技师现付业绩与提成
                    BigDecimal footMassageChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal footMassageComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //推销业绩与提成
                    BigDecimal marketChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room_market.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal marketComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room_market.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    BigDecimal nTMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getNTMoney).reduce(BigDecimal.ZERO, BigDecimal::add);


                    BigDecimal cardchian=BigDecimal.valueOf(0);
                    BigDecimal cashchian=BigDecimal.valueOf(0);
                    for (AchiCommEntity a : list) {
                        if(Constant.doc_type_card_use.equals(a.getDocType())){
                            cardchian=cardchian.add(a.getCardAchi());
                            cashchian=cashchian.add(a.getCashAchi());
                        }
                    }
                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(courseChangeCashAchi).add(groupPurchaseChia).add(cashcxyj).add(footMassageChia);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(courseChangeComm).add(groupPurchaseComm).add(cashcxtc).add(footMassageComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia).add(cashcxyj).add(footMassageChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm).add(cashcxtc).add(footMassageComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm).add(repayCardComm);

                    if(staffStatistic.getClassify().equals("3")){
                        for (AchiCommEntity achiCommEntity : list) {
                            StaffStatistic statistic = new StaffStatistic();
                            if(achiCommEntity.getDocType().equals("card_recharge")){
                                statistic.setType(0);
                                statistic.setCzhkyj(achiCommEntity.getCashAchi());
                                statistic.setCzhktc(achiCommEntity.getCashComm().add(achiCommEntity.getCardComm()));
                            }else if(achiCommEntity.getDocType().equals("card_use") || achiCommEntity.getDocType().equals("card_change")){
                                statistic.setType(1);
                                statistic.setLchkyj(achiCommEntity.getCashAchi());
                                statistic.setLchktc(achiCommEntity.getCashComm().add(achiCommEntity.getCardComm()));
                            }else if(achiCommEntity.getDocType().equals("promotion_card_use")){
                                statistic.setType(2);
                                statistic.setCashcxyj(cashcxyj);
                                statistic.setCashcxtc(cashcxtc.add(cardcxtc));
                            }
                            statistic.setStaffId(entry.getKey());
                            statistic.setStaffName(list.get(0).getSaleStaffName());
                            statistic.setBrandNumber(list.get(0).getBrandNumber());
                            //按天查询用date
                            statistic.setDate(com.alibaba.excel.util.DateUtils.parseDate(dateStr));
                            statistic.setAchievementAmount(achievementAmount);
                            statistic.setCommissionAmount(commissionAmount);
                            statistic.setCashAchi(totalCashAchi);
                            statistic.setCardAchi(totalCardAchi);
                            statistic.setCashComm(totalCashComm);
                            statistic.setCardComm(totalCardComm);
                            statistic.setClassify(staffStatistic.getClassify());
                            statistic.setStoreId(staffStatistic.getStoreId());
                            statistic.setSylcxkyj(cashCardAchis);
                            statistic.setLcCardyj(cardchian);
                            statistic.setLcCashyj(cashchian);
                            statistic.setSyxfyj(cashCashAchi);
                            statistic.setXftlcczhjyj(cashRefundCardComm1.add(cashRefundCardComm2));
                            statistic.setSyczkfyj(CardAchis);
                            statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                            statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                            statistic.setGroupPurchaseChia(groupPurchaseChia);
                            statistic.setGroupPurchaseComm(groupPurchaseComm);

                            statistic.setFootMassageComm(footMassageComm);
                            statistic.setFootMassageChia(footMassageChia);
                            statistic.setCardFootMassageComm(CardFootMassageComm);
                            statistic.setCardFootMassageChia(CardFootMassageChia);
                            statistic.setMarketChia(marketChia);
                            statistic.setMarketComm(marketComm);
                            statistic.setNTMoney(nTMoney);
                            staffStatisticList.add(statistic);
                        }
                    }else{
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setCashcxyj(promotionCashAchi);
                        statistic.setCardcxyj(promotionCardAchi);
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(0).getSaleStaffName());
                        statistic.setBrandNumber(list.get(0).getBrandNumber());
                        //按天查询用date
                        statistic.setDate(com.alibaba.excel.util.DateUtils.parseDate(dateStr));
                        statistic.setAchievementAmount(achievementAmount);
                        statistic.setCommissionAmount(commissionAmount);
                        statistic.setCashAchi(totalCashAchi);
                        statistic.setCardAchi(totalCardAchi);
                        statistic.setCashComm(totalCashComm);
                        statistic.setCardComm(totalCardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setSylcxkyj(cashCardAchis);
                        statistic.setLcCardyj(cardchian);
                        statistic.setLcCashyj(cashchian);
                        statistic.setSyxfyj(cashCashAchi);
                        statistic.setXftlcczhjyj(cashRefundCardComm1.add(cashRefundCardComm2));
                        statistic.setSyczkfyj(CardAchis);
                        statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                        statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                        statistic.setGroupPurchaseChia(groupPurchaseChia);
                        statistic.setGroupPurchaseComm(groupPurchaseComm);

                        statistic.setFootMassageComm(footMassageComm);
                        statistic.setFootMassageChia(footMassageChia);
                        statistic.setCardFootMassageComm(CardFootMassageComm);
                        statistic.setCardFootMassageChia(CardFootMassageChia);
                        statistic.setMarketChia(marketChia);
                        statistic.setMarketComm(marketComm);
                        statistic.setNTMoney(nTMoney);
                        staffStatisticList.add(statistic);
                    }
                }
            }
        }

        staffStatisticList.sort(comparing(StaffStatistic::getDate).reversed());
        return staffStatisticList;
    }

    @Override
    public List<StaffStatistic> achiCommListsss(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getSelectDate();
        Date date = new Date();

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String dateString = sdf.format(staffStatistic.getDate());


        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()) {
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }

        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        //List<RefundCashResponse> refundCashList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();

        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

        recList = ssmRechargeService.selectList(storeId, dateStr, date);
        courseList = ssmCourseService.selectList(storeId, dateStr, date);
        cashList = ssmCashService.selectList(storeId, dateStr, date);
        RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
        refundRecList = ssmRefundRechargeService.selectListDept(storeId, dateStr);
        refundCourseList = ssmRefundCourseService.selectListDept(storeId, dateStr);
        //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
        refundCashList = ssmRefundCashService.selectListsDept(storeId, dateStr, date);
        promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
        //加价转疗程
        cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);

        //查询团购卡
        baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();

                    //充值 业绩
                    BigDecimal recharge = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardRepay = list.stream().filter(item->item.getType() !=null &&item.getType().equals(Constant.doc_type_repay)).map(x->x.getNTMoney()==null?BigDecimal.ZERO:x.getNTMoney()).reduce(BigDecimal.ZERO,BigDecimal::add);

                    //充值1 业绩
                    BigDecimal recharge1 = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null==achiCommEntity.getType()).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程
                    BigDecimal courseCard = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCash = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseTotal = courseCash;

                    //疗程促销
                    BigDecimal coursePromotionCard =  list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal coursePromotionCash =  list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal coursePromotionTotal = coursePromotionCard.add(coursePromotionCash);

                    //收银
                    BigDecimal cashierCash = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashierRecharge = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashierCard = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashierTotal = cashierCash.add(cashierRecharge).add(cashierCard);

//                    }
                    //还款
                    BigDecimal repaymentRecharge = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "recharge".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repaymentCourse = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "course".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repaymentTotal = repaymentRecharge.add(repaymentCourse);

                    //疗程促销还款
                    BigDecimal repaymentCourse1 = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //加价转疗程还款
                    BigDecimal repaymentCourse2 = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "card_change".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值退款
                    BigDecimal refundRechagre = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款
                    BigDecimal refundCourse = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    BigDecimal refundTotal = refundRechagre.add(refundCourse).add(cashRefundAchi);

                    //加价转疗程
                    BigDecimal jjzlcCard = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal jjzlcCash = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    staffStatistic1.setRecharge(recharge.add(groupPurchaseChia));
                    staffStatistic1.setRechargecar(recharge1.add(groupPurchaseChia).setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseCard(courseCard);
                    staffStatistic1.setCourseCash(courseCash);
                    staffStatistic1.setCourseTotal(courseTotal);
                    staffStatistic1.setCoursePromotionCard(coursePromotionCard);
                    staffStatistic1.setCoursePromotionCash(coursePromotionCash);
                    staffStatistic1.setCoursePromotionTotal(coursePromotionTotal);
                    staffStatistic1.setCoursePromotionTotal(coursePromotionTotal);
                    staffStatistic1.setCashierCard(cashierCard);
                    staffStatistic1.setCashierCash(cashierCash);
                    staffStatistic1.setCashierRecharge(cashierRecharge);
                    staffStatistic1.setCashierTotal(cashierTotal);
                    staffStatistic1.setRepaymentCourse(repaymentCourse);
                    staffStatistic1.setRepaymentRecharge(repaymentRecharge);
                    staffStatistic1.setRepaymentTotal(repaymentTotal);
                    staffStatistic1.setRefundTotal(refundTotal);
                    staffStatistic1.setRefundCourse(refundCourse);
                    staffStatistic1.setRefundRechagre(refundRechagre);
                    staffStatistic1.setRefundCash(cashRefundAchi);
                    staffStatistic1.setJjzlcCard(jjzlcCard);
                    staffStatistic1.setJjzlcCash(jjzlcCash);
                    staffStatistic1.setStartDate(stringListEntry.getKey());
                    staffStatistic1.setCourseRepay(repaymentCourse.add(repaymentCourse1.add(repaymentCourse2)));
                    staffStatistic1.setCourseCardRepay(courseCardRepay);
                    staffStatisticList.add(staffStatistic1);
                    /*--------------------------------------------------------------------------------------------------------*/

                }
            }
        }

        staffStatisticList.sort(comparing(StaffStatistic::getDate).reversed());
        return staffStatisticList;
    }

    private List<StaffStatistic> achiCommListsss1(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getSelectDate();
        Date date = new Date();

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String dateString = sdf.format(staffStatistic.getDate());
//        if (0 == type) {
//            //上月
//            date = DateUtils.diffMonth(new Date(), -1);
//            dateStr = DateUtils.ymFormat(date);
//        } else if (1 == type) {
//            //昨日
//            date = DateUtils.diffDay(new Date(), -1);
//            dateStr = DateUtils.ymdFormat(date);
//        } else if (2 == type) {
//            //今日
//            dateStr = DateUtils.ymdFormat(date);
//        } else {
//            //当月
//            dateStr = DateUtils.ymFormat(date);
//        }


        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()) {
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }

        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<RefundCashResponse> refundCashList = new ArrayList<>();
//        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();

        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

        recList = ssmRechargeService.selectList(storeId, dateStr, date);
        courseList = ssmCourseService.selectList(storeId, dateStr, date);
        cashList = ssmCashService.selectList(storeId, dateStr, date);
        RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
        refundRecList = ssmRefundRechargeService.selectListDept(storeId, dateStr);
        refundCourseList = ssmRefundCourseService.selectListDept(storeId, dateStr);
        refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
//        refundCashList = ssmRefundCashService.selectListsDept(storeId, dateStr, date);
        promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
        //加价转疗程
        cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);

        //查询团购卡
        baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            for (AchiCommEntity entity : cardChangeList.getEntities()) {
                entity.setChangeInPayMoney(cardChangeList.getChangeInPayMoney());
                entity.setChangeOutMoney(cardChangeList.getChangeOutMoney());
            }
        }

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            cardChangeList.getOutProjects().
                    forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                            .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        }
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();

                    //充值 业绩
                    BigDecimal recharge = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值1 业绩
                    BigDecimal recharge1 = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null==achiCommEntity.getType()).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程
                    BigDecimal courseCard = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCash = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseTotal = courseCash;

                    //疗程促销
                    BigDecimal coursePromotionCard =  list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal coursePromotionCash =  list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal coursePromotionTotal = coursePromotionCard.add(coursePromotionCash);

                    //收银
                    BigDecimal cashierCash = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashierRecharge = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashierCard = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashierTotal = cashierCash.add(cashierRecharge).add(cashierCard);

//                    for (AchiCommEntity achiCommEntity : list) {
//                        if(Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())){
//                            if(achiCommEntity.getOrderType().equals("card")){
//                                cashierCard = cashierCard.add(achiCommEntity.getCardAchi());
//                                System.out.println("--------------------");
//                            }
//                        }
//                    }
                    //还款
                    BigDecimal repaymentRecharge = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "recharge".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repaymentCourse = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "course".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repaymentTotal = repaymentRecharge.add(repaymentCourse);

                    //疗程促销还款
                    BigDecimal repaymentCourse1 = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //加价转疗程还款
                    BigDecimal repaymentCourse2 = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "card_change".equals(achiCommEntity.getOrderType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值退款
                    BigDecimal refundRechagre = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款
                    BigDecimal refundCourse = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    BigDecimal refundTotal = refundRechagre.add(refundCourse).add(cashRefundAchi);

                    //加价转疗程
                    BigDecimal jjzlcCard = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal jjzlcCash = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())&&!Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);

                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    staffStatistic1.setRecharge(recharge.add(groupPurchaseChia));
                    staffStatistic1.setRechargecar(recharge1.add(groupPurchaseChia).setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseCard(courseCard);
                    staffStatistic1.setCourseCash(courseCash);
                    staffStatistic1.setCourseTotal(courseTotal);
                    staffStatistic1.setCoursePromotionCard(coursePromotionCard);
                    staffStatistic1.setCoursePromotionCash(coursePromotionCash);
                    staffStatistic1.setCoursePromotionTotal(coursePromotionTotal);
                    staffStatistic1.setCoursePromotionTotal(coursePromotionTotal);
                    staffStatistic1.setCashierCard(cashierCard);
                    staffStatistic1.setCashierCash(cashierCash);
                    staffStatistic1.setCashierRecharge(cashierRecharge);
                    staffStatistic1.setCashierTotal(cashierTotal);
                    staffStatistic1.setRepaymentCourse(repaymentCourse);
                    staffStatistic1.setRepaymentRecharge(repaymentRecharge);
                    staffStatistic1.setRepaymentTotal(repaymentTotal);
                    staffStatistic1.setRefundTotal(refundTotal);
                    staffStatistic1.setRefundCourse(refundCourse);
                    staffStatistic1.setRefundRechagre(refundRechagre);
                    staffStatistic1.setRefundCash(cashRefundAchi);
                    staffStatistic1.setJjzlcCard(jjzlcCard);
                    staffStatistic1.setJjzlcCash(jjzlcCash);
                    staffStatistic1.setStartDate(stringListEntry.getKey());
                    staffStatistic1.setCourseRepay(repaymentCourse.add(repaymentCourse1.add(repaymentCourse2)));
                    staffStatisticList.add(staffStatistic1);
                    /*--------------------------------------------------------------------------------------------------------*/
                }
            }
        }

//        staffStatisticList.sort(comparing(StaffStatistic::getDate).reversed());
        return staffStatisticList;
    }

    @Override
    public List<List<AchiCommEntity>> achiCommListupgrade(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getSelectDate();
        Date date = new Date();
//        if (0 == type) {
//            //上月
//            date = DateUtils.diffMonth(new Date(), -1);
//            dateStr = DateUtils.ymFormat(date);
//        } else if (1 == type) {
//            //昨日
//            date = DateUtils.diffDay(new Date(), -1);
//            dateStr = DateUtils.ymdFormat(date);
//        } else if (2 == type) {
//            //今日
//            dateStr = DateUtils.ymdFormat(date);
//        } else {
//            //当月
//            dateStr = DateUtils.ymFormat(date);
//        }

        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()){
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }

        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<RefundCashResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(0).getSaleStaffName());
                    statistic.setBrandNumber(list.get(0).getBrandNumber());
                    //按天查询用date
                    statistic.setDate(com.alibaba.excel.util.DateUtils.parseDate(dateStr));
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    staffStatisticList.add(statistic);
                }
           }
        }

        staffStatisticList.sort(comparing(StaffStatistic::getDate).reversed());
        List<List<AchiCommEntity>> lists = new ArrayList<>();
        for (StaffStatistic statistic : staffStatisticList) {
            StaffStatistic staffStatistic1 = new StaffStatistic();
            staffStatistic1.setStoreId(storeId);
            staffStatistic1.setClassify(statistic.getClassify());
            staffStatistic1.setDate(statistic.getDate());
            staffStatistic1.setStaffId(statistic.getStaffId());
            List<AchiCommEntity> achiCommEntities = achiCommDetailList(staffStatistic1);
            for (AchiCommEntity achiCommEntity : achiCommEntities) {
                if ("0".equals(staffStatistic.getClassify())) {
                    //查询充值业务员信息
                    achiCommEntity.setOrderType("充值开卡");
                } else if ("1".equals(staffStatistic.getClassify())) {
                    //查询疗程业务员信息
                    achiCommEntity.setOrderType("疗程开卡");
                } else if ("2".equals(staffStatistic.getClassify())) {
                    //查询服务单业务员信息
                    achiCommEntity.setOrderType("服务单据");
                } else if ("3".equals(staffStatistic.getClassify())) {
                    //查询还款单业务员信息
                    achiCommEntity.setOrderType("还款单据");
                } else if ("4".equals(staffStatistic.getClassify())) {
                    //查询充值退款单业务员
                    achiCommEntity.setOrderType("充值退款");
                } else if ("5".equals(staffStatistic.getClassify())) {
                    //查询疗程退款单业务员
                    achiCommEntity.setOrderType("疗程退款");
                } else if ("6".equals(staffStatistic.getClassify())) {
                    //查询收银退款单业务员
                    achiCommEntity.setOrderType("收银退款");
                }else if ("7".equals(staffStatistic.getClassify())) {
                    //查询促销单业务员
                    achiCommEntity.setOrderType("促销单据");
                }
            }
            lists.add(achiCommEntities);
        }
        return lists;

    }

    @Override
    public List<StaffStatistic> achiCommLists(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        List<StaffStatistic> staffStatisticLists = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = dateFormat.parse(staffStatistic.getStartDate());

        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();
        List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);

            //疗程转充值
            rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateStr);

            //查询团购卡
            baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

            serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            }else if ("9".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                rechargeTurnCourses = ssmRechargeTurnCourseService.selectDate(storeId);
            }else if ("10".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
            }else if ("11".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                //查询团购卡
                serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
            }
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        rechargeTurnCourses.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //沐足技师卡付业绩与提成
                    BigDecimal CardFootMassageChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardFootMassageComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //沐足技师现付业绩与提成
                    BigDecimal footMassageChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal footMassageComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //推销业绩与提成
                    BigDecimal marketChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room_market.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal marketComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room_market.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(footMassageChia);
                    commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm).add(footMassageComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia).add(footMassageChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi).add(CardFootMassageChia);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm).add(footMassageComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm).add(CardFootMassageComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(0).getDocDate());
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());

                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                    statistic.setGroupPurchaseChia(groupPurchaseChia);
                    statistic.setGroupPurchaseComm(groupPurchaseComm);
                    statistic.setCooperationAchi(cooperationAchi);
                    BigDecimal repayProAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayProComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    statistic.setCourseOfTreatmentYJ(repayProAchi);
                    statistic.setCourseOfTreatmentTC(repayProComm);
                    staffStatisticList.add(statistic);
                }
            }
        }

        for (StaffStatistic statistic : staffStatisticList) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if(effectiveDate){
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                staffStatistic1.setDate(statistic.getDate());
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setStoreId(storeId);
                staffStatistic1.setClassify("0");
                List<StaffStatistic> staffStatistics = null;
                 staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setRechargeyj(BigDecimal.valueOf(0));
                statistic.setRechargeTC(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0){
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
                            statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("1");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                if(statistic.getCourseOfTreatmentYJ()==null){
                    statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
                }
                if(statistic.getCourseOfTreatmentTC()==null){

                    statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                }
//                statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
//                statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                statistic.setLcCardyj(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
                            statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("2");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setServeYJ(BigDecimal.valueOf(0));
                statistic.setServeTC(BigDecimal.valueOf(0));
                statistic.setSyxfyj(BigDecimal.valueOf(0));
                statistic.setSyczkfyj(BigDecimal.valueOf(0));
                statistic.setSylcxkyj(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
                            statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
                            //收银的现付总业绩
                            statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
                            statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
                            statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("4");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
                statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("5");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
                statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
                        }
                    }
                }
                statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
                statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));

                staffStatistics = null;
                staffStatistic1.setClassify("6");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
                statistic.setCashierRefundTC(BigDecimal.valueOf(0));
                statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
                            statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
                            statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
                        }
                    }
                }
                statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
                statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
                statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3,BigDecimal.ROUND_HALF_UP)));
                staffStatistics = null;
                staffStatistic1.setClassify("7");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setLeafletYJ(BigDecimal.valueOf(0));
                statistic.setLeafletTC(BigDecimal.valueOf(0));
                statistic.setCashcxyj(BigDecimal.valueOf(0));
                statistic.setCardcxyj(BigDecimal.valueOf(0));
                statistic.setCashcxtc(BigDecimal.valueOf(0));
                statistic.setCardcxtc(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
                            statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
                            statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("8");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setJjzlcyj(BigDecimal.valueOf(0));
                statistic.setJjzlctc(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(),BigDecimal.valueOf(0.00))));
                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(),staffStatistic2.getCardComm()),BigDecimal.valueOf(0.00))));
                            statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
                        }
                    }
                }

                staffStatistics = null;
                statistic.setNTMoney(BigDecimal.valueOf(0));
                staffStatistic1.setClassify("3");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0){
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            if(null == staffStatistic2.getCzhkyj()){
                                staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getCzhktc()){
                                staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getLchkyj()){
                                staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getLchktc()){
                                staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                            }

                            if(null == staffStatistic2.getLchkyj()){
                                staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getLchktc()){
                                staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getNTMoney()){
                                staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
                            }

                            //充值开卡
                            statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(),staffStatistic2.getCzhkyj()));
                            statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(),staffStatistic2.getCzhktc()));
                            //疗程开卡
                            statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(),staffStatistic2.getLchkyj()));
                            statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(),staffStatistic2.getLchktc()));

                            statistic.setNTMoney(BigDecimalUtils.add(statistic.getNTMoney(),staffStatistic2.getNTMoney()));

                            //促销开卡
                            if(staffStatistic2.getType()==2){
                                statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(),staffStatistic2.getCashcxyj()));
                                statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(),staffStatistic2.getCashcxtc()));
                            }
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("9");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
                statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            //todo
                            statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
                            statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("10");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
                statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
                            //充值开卡
                            statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(),staffStatistic2.getGroupPurchaseChia()));
                            statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(),staffStatistic2.getGroupPurchaseComm()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("11");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                BigDecimal decimal = BigDecimal.valueOf(0);
                statistic.setFootMassageComm(decimal);
                statistic.setFootMassageChia(decimal);
                statistic.setCardFootMassageComm(decimal);
                statistic.setCardFootMassageChia(decimal);
                statistic.setMarketChia(decimal);
                statistic.setMarketComm(decimal);
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
                            statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
                            statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
                            statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
                            statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
                            statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
                        }
                    }
                }


                //根据甲方要求，退款的单据业绩不加进总业绩里面
//                statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj()))));
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm().add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc())))))));
//                //退款业绩
//                statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
//                if(null == statistic.getSyxfyj()){
//                    statistic.setSyxfyj(BigDecimal.valueOf(0.00));
//                }
//                //总业绩
//                statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj())));
//                //扣减后业绩
//                statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
//                statistic.setTotaltc(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", statistic.getTotaltc()))));
//                staffStatisticLists.add(statistic);

                //根据甲方要求，退款的单据业绩不加进总业绩里面
                statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC())
                        .add(statistic.getServeTC().add(statistic.getTopUpRefundTC()
                                .add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC()
                                        .add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm())
                                        .add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm())
                                        .add(statistic.getCashcxtc().add(statistic.getMarketComm()
                                                .add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                //退款业绩
                statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
                if(null == statistic.getSyxfyj()){
                    statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                }
                //总业绩
                statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
                //扣减后业绩
                statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                staffStatisticLists.add(statistic);
            }
        }

        staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());

        /*四舍五入，保留2位，在最后的结果进行小数位切除，保证数据金额差距为0.01*/
        for (StaffStatistic aLong : staffStatisticLists) {
            aLong.setRechargeyj(aLong.getRechargeyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setCourseOfTreatmentYJ(BigDecimalUtils.add(aLong.getCourseOfTreatmentYJ(),aLong.getCashcxyj()).setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setLcCardyj(aLong.getLcCardyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setSyxfyj(aLong.getSyxfyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setSyczkfyj(aLong.getSyczkfyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setSylcxkyj(aLong.getSylcxkyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setTkyj(aLong.getTkyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setKjhyj(aLong.getKjhyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setCardcxyj(aLong.getCardcxyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setCashcxyj(aLong.getCashcxyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setXftlcczhjyj(aLong.getXftlcczhjyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setTotalyj(aLong.getTotalyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setTotaltc(aLong.getTotaltc().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setZyj(aLong.getZyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setGroupPurchaseChia(aLong.getGroupPurchaseChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setGroupPurchaseComm(aLong.getGroupPurchaseComm().setScale(2,BigDecimal.ROUND_HALF_UP));

            aLong.setRechargeTurnCourseChia(aLong.getRechargeTurnCourseChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setRechargeTurnCourseComm(aLong.getRechargeTurnCourseComm().setScale(2,BigDecimal.ROUND_HALF_UP));

            aLong.setFootMassageComm(aLong.getFootMassageComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setFootMassageChia(aLong.getFootMassageChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setCardFootMassageComm(aLong.getCardFootMassageComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setCardFootMassageChia(aLong.getCardFootMassageChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setMarketChia(aLong.getMarketChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setMarketComm(aLong.getMarketComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            aLong.setNTMoney(aLong.getNTMoney().setScale(2,BigDecimal.ROUND_HALF_UP));
        }


        List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
        List<AchiCommEntity> totalList1 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
        //合并list
        cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
        while (entryIterator1.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();
            //按天进行分组
            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                List<AchiCommEntity> list = stringListEntry.getValue();

                //业绩
                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(list.get(list.size()-1).getDocDate());
                statistic.setAchievementAmount(CardAchi);
                statistic.setCommissionAmount(CardComm);
                statistic.setCardAchi(CardAchi);
                statistic.setCardComm(CardComm);
                statistic.setClassify(staffStatistic.getClassify());
                statistic.setStoreId(staffStatistic.getStoreId());

                staffStatisticList1.add(statistic);
            }
            //}
        }

        for (StaffStatistic statistic : staffStatisticList1) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if (effectiveDate){
                staffStatisticList2.add(statistic);
            }
        }
        staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());

        Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
        //汇总后的集合

        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();

        List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
        while (entryIteratorsList1.hasNext()) {
            StaffStatistic staffStatistic1 = new StaffStatistic();

            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
            List<StaffStatistic> listByStaff = entry.getValue();
            for (StaffStatistic statistic : listByStaff) {
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setDate(statistic.getDate());
                staffStatistic1.setNTMoney(BigDecimalUtils.bigDecimal("0"));
                staffStatistic1.setStaffName(statistic.getStaffName());
                staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatisticsLs1.add(staffStatistic1);
            }

        }

        for (StaffStatistic staffStatistics : staffStatisticLists) {
            for (StaffStatistic statistic : staffStatisticsLs1) {
                /*Date date1 = staffStatistics.getDate();
                Date date2 = statistic.getDate();
                String s = DateUtils.YMDFormat(date1);
                String s1 = DateUtils.YMDFormat(date2);
                System.out.println(s);
                System.out.println(s1);*/
                if (staffStatistics.getStaffId().equals(statistic.getStaffId()) && DateUtils.YMDFormat(staffStatistics.getDate()).equals(DateUtils.YMDFormat(statistic.getDate()))){
                    staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                    //staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
                }
            }
        }
        if (staffStatisticLists.size() == 0){
            for (StaffStatistic statistic : staffStatisticsLs1) {
                if (staffStatistic.getStaffId().equals(statistic.getStaffId())){

                    staffStatisticLists.add(statistic);
                }
            }
        }


        //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
        List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
        List<AchiCommEntity> totalList2 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
        //合并list
        coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
        while (entryIterator2.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();
            //按天进行分组
            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                List<AchiCommEntity> list = stringListEntry.getValue();

                //业绩
                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(list.get(list.size()-1).getDocDate());
                statistic.setAchievementAmount(CardAchi);
                statistic.setCommissionAmount(CardComm);
                statistic.setCardAchi(CardAchi);
                statistic.setCardComm(CardComm);
                statistic.setClassify(staffStatistic.getClassify());
                statistic.setStoreId(staffStatistic.getStoreId());

                staffStatisticList3.add(statistic);
            }
            //}
        }
        for (StaffStatistic statistic : staffStatisticList3) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if (effectiveDate){
                staffStatisticList4.add(statistic);
            }
        }
        staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());

        Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
        //汇总后的集合

        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();

        List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();

        while (entryIteratorsList2.hasNext()) {

            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
            List<StaffStatistic> listByStaff = entry.getValue();
            for (StaffStatistic statistic : listByStaff) {
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setDate(statistic.getDate());
                staffStatistic1.setNTMoney(BigDecimalUtils.bigDecimal("0"));
                staffStatistic1.setStaffName(statistic.getStaffName());
                staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargeTurnCourseChia(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setZyj(BigDecimal.ZERO);
                staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatisticsLs2.add(staffStatistic1);
            }

        }

        for (StaffStatistic staffStatistics : staffStatisticLists) {
            for (StaffStatistic statistic : staffStatisticsLs2) {
                if (staffStatistics.getStaffId().equals(statistic.getStaffId()) && DateUtils.YMDFormat(staffStatistics.getDate()).equals(DateUtils.YMDFormat(statistic.getDate()))){
                    //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
//                    staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                    //staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
                }
            }
            BaseStaff baseStaff = ssmBaseStaffService.selectByPrimaryKey(staffStatistics.getStaffId());
            if(baseStaff!=null){
                staffStatistics.setBrandNumber(baseStaff.getBrandNumber());
                staffStatistics.setStaffName(baseStaff.getStaffName());
            }
        }
        if (staffStatisticLists.size() == 0){
            for (StaffStatistic statistic : staffStatisticsLs2) {
                if(statistic.getCooperationAchi()==null){
                    statistic.setCooperationAchi(BigDecimal.ZERO);
                }
                if(statistic.getTotalyj()==null){
                    statistic.setTotalyj(BigDecimal.ZERO);
                }
                statistic.setChia(statistic.getTotalyj().subtract(statistic.getCooperationAchi()));
                if (staffStatistic.getStaffId().equals(statistic.getStaffId())){

                    staffStatisticLists.add(statistic);
                }
            }
        }
        return staffStatisticLists;
    }
    @Override
    public List<StaffStatistic> achiCommListsgroup(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        List<StaffStatistic> staffStatisticLists = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = dateFormat.parse(staffStatistic.getStartDate());
        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();
        List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            //疗程转充值
            rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateStr);
            //查询团购卡
            baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

            //查询开房收银
            serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
        }
        else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            }else if("9".equals(staffStatistic.getClassify())){
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
            }
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            List<CardChangeOutProject> outProjects = cardChangeList.getOutProjects();
            List<CardChangeOutProject> collect = outProjects.stream().filter(item -> item.getEntities() != null && item.getEntities().size() > 0).collect(Collectors.toList());
            collect.
                    forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                            .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        }
        for (AchiCommEntity achiCommEntity : totalList) {
            achiCommEntity.setMoney(BigDecimal.ZERO);
        }
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        rechargeTurnCourses.forEach(rechargeTurnCoursesResponse -> rechargeTurnCoursesResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            for (AchiCommEntity entity : cardChangeList.getEntities()) {
                entity.setCardAchi(cardChangeList.getChangeOutMoney().multiply(entity.getSaleRatio()).divide(BigDecimal.valueOf(100)));
                entity.setCashAchi(cardChangeList.getChangeInPayMoney().multiply(entity.getSaleRatio()).divide(BigDecimal.valueOf(100)));
            }
        }
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();
            //按天进行分组
            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                List<AchiCommEntity> list = stringListEntry.getValue();
                //充值 + 充值还款 业绩
                BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //充值退款 业绩
                BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                //疗程 + 疗程还款 业绩
                BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                //加价转疗程 业绩
                BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //todo
                BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getCashAchi()==null?BigDecimal.valueOf(0):item.getCashAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);
                //todo
                BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getCardAchi()==null?BigDecimal.valueOf(0):item.getCardAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);

                //疗程退款 业绩
                BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                //收银 业绩
                BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                //消费退 业绩
                BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                //还款业绩
                BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                //促销业绩
                BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                //充值  提成
                BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //充值退款 提成
                BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                //疗程  提成
                BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                //疗程退款 提成
                BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                //收银 提成
                BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                //消费退 提成
                BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                //还款提成
                BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                //促销提成
                BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                //加价转疗程提成
                BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                //疗程转充值
                BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


                //团购卡业绩
                BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                //团购卡提成
                BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                //促销还款
                BigDecimal cooperationAchi = BigDecimalUtils.bigDecimal("0");
                for (AchiCommEntity achiCommEntity : list) {
                    for (CourseListResponse courseListResponse : courseList) {
                        if(achiCommEntity.getDocId()==courseListResponse.getId()){
                            for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                if(entry.getKey().equals(entity.getSaleStaffId())){
                                    cooperationAchi = cooperationAchi.add((courseListResponse.getCollectionCashAmount().subtract(courseListResponse.getAchievementAmount())).multiply(entity.getSaleRatio().divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)));
                                }
                            }
                        }
                    }
                }
//                BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                achievementAmount = BigDecimalUtils.subtract(
                        BigDecimalUtils.subtract(
                        BigDecimalUtils.subtract(
                        BigDecimalUtils.add(
                                BigDecimalUtils.add(
                                        BigDecimalUtils.add(
                                                recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                //总现付业绩
                BigDecimal totalCashAchi = BigDecimalUtils.add(
                        BigDecimalUtils.subtract(
                                BigDecimalUtils.subtract(
                                        BigDecimalUtils.subtract(
                        BigDecimalUtils.add(
                                BigDecimalUtils.add(
                                        BigDecimalUtils.add(
                                                recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(
                        BigDecimalUtils.add(
                                BigDecimalUtils.add(
                                        courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi)
                        .add(courseChangeCardAchi);
                //总现付提成
                BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(list.get(list.size()-1).getDocDate());
                statistic.setAchievementAmount(achievementAmount);
                statistic.setCommissionAmount(commissionAmount);
                statistic.setCashAchi(totalCashAchi);
                statistic.setCardAchi(totalCardAchi);
                statistic.setCashComm(totalCashComm);
                statistic.setCardComm(totalCardComm);
                statistic.setClassify(staffStatistic.getClassify());
                statistic.setStoreId(staffStatistic.getStoreId());

                statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                statistic.setCooperationAchi(cooperationAchi);
                staffStatisticList.add(statistic);
            }
            //}
        }

        for (StaffStatistic statistic : staffStatisticList) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if(effectiveDate){
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                staffStatistic1.setDate(statistic.getDate());
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setStoreId(storeId);
                staffStatistic1.setClassify("0");
                List<StaffStatistic> staffStatistics = null;
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setRechargeyj(BigDecimal.valueOf(0));
                statistic.setRechargeTC(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0){
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
                            statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("1");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
                statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                statistic.setLcCardyj(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
                            statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("2");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setServeYJ(BigDecimal.valueOf(0));
                statistic.setServeTC(BigDecimal.valueOf(0));
                statistic.setSyxfyj(BigDecimal.valueOf(0));
                statistic.setSyczkfyj(BigDecimal.valueOf(0));
                statistic.setSylcxkyj(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
                            statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
                            //收银的现付总业绩
                            statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
                            statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
                            statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("4");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
                statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("5");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
                statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
                        }
                    }
                }
                statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
                statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));

                staffStatistics = null;
                staffStatistic1.setClassify("6");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
                statistic.setCashierRefundTC(BigDecimal.valueOf(0));
                statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
                            statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
                            statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
                        }
                    }
                }
                statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
                statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
                statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3,BigDecimal.ROUND_HALF_UP)));

                staffStatistics = null;
                staffStatistic1.setClassify("7");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setLeafletYJ(BigDecimal.valueOf(0));
                statistic.setLeafletTC(BigDecimal.valueOf(0));
                statistic.setCashcxyj(BigDecimal.valueOf(0));
                statistic.setCardcxyj(BigDecimal.valueOf(0));
                statistic.setCashcxtc(BigDecimal.valueOf(0));
                statistic.setCardcxtc(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
                            statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
                            statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
                            statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("8");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setJjzlcyj(BigDecimal.valueOf(0));
                statistic.setJjzlctc(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(),BigDecimal.valueOf(0.00))));
                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(),staffStatistic2.getCardComm()),BigDecimal.valueOf(0.00))));
                            statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
                        }
                    }
                }

                staffStatistics = null;
                statistic.setNTMoney(BigDecimal.valueOf(0));
                staffStatistic1.setClassify("3");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0){
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            if(null == staffStatistic2.getCzhkyj()){
                                staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getCzhktc()){
                                staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getLchkyj()){
                                staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getLchktc()){
                                staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                            }
                            if(null == staffStatistic2.getNTMoney()){
                                staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
                            }
                            //充值开卡
                            statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(),staffStatistic2.getCzhkyj()));
                            statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(),staffStatistic2.getCzhktc()));
                            //疗程开卡
                            statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(),staffStatistic2.getLchkyj()));
                            statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(),staffStatistic2.getLchktc()));
                            //促销开卡
                            if(staffStatistic2.getType()==2){
                                statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(),staffStatistic2.getCashcxyj()));
                                statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(),staffStatistic2.getCashcxtc()));
                            }
                            statistic.setNTMoney(statistic.getNTMoney().add(staffStatistic2.getNTMoney()));
                        }
                    }
                }

                staffStatistics = null;
                staffStatistic1.setClassify("9");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
                statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
                            statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
                        }
                    }
                }


                staffStatistics = null;
                staffStatistic1.setClassify("10");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
                statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
                            statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(),staffStatistic2.getGroupPurchaseChia()));
                            statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(),staffStatistic2.getGroupPurchaseComm()));
                        }
                    }
                }
                staffStatistics = null;
                staffStatistic1.setClassify("11");
                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                BigDecimal decimal = BigDecimal.valueOf(0);
                statistic.setFootMassageComm(decimal);
                statistic.setFootMassageChia(decimal);
                statistic.setCardFootMassageComm(decimal);
                statistic.setCardFootMassageChia(decimal);
                statistic.setMarketChia(decimal);
                statistic.setMarketComm(decimal);
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0) {
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
                            statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
                            statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
                            statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
                            statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
                            statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
                        }
                    }
                }

                //根据甲方要求，退款的单据业绩不加进总业绩里面
                statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
                //todo 进行修改
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                //退款业绩
                statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
                if(null == statistic.getSyxfyj()){
                    statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                }
                //总业绩
                statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
                //扣减后业绩
                statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                statistic.setCooperationAchi(statistic.getCooperationAchi());

                staffStatisticLists.add(statistic);
            }
        }
        staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());

        Map<Long, List<StaffStatistic>> resultMaps = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
        //汇总后的集合
        List<StaffStatistic> staffStatisticsLs= new ArrayList<>();
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList = resultMaps.entrySet().iterator();
        while (entryIteratorsList.hasNext()) {
            StaffStatistic staffStatistic1 = new StaffStatistic();

            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList.next();
            List<StaffStatistic> listByStaff = entry.getValue();
            staffStatistic1.setStaffId(listByStaff.get(0).getStaffId());
            staffStatistic1.setStaffName(listByStaff.get(0).getStaffName());
            staffStatistic1.setBrandNumber(listByStaff.get(0).getBrandNumber());
            staffStatistic1.setCooperationAchi(listByStaff.get(0).getCooperationAchi());
            staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
            staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
            staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
            staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
            staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
            staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
            staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
            staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
            BigDecimal decimal = BigDecimal.valueOf(0);
            staffStatistic1.setFootMassageComm(decimal);
            staffStatistic1.setFootMassageChia(decimal);
            staffStatistic1.setCardFootMassageComm(decimal);
            staffStatistic1.setCardFootMassageChia(decimal);
            staffStatistic1.setMarketChia(decimal);
            staffStatistic1.setMarketComm(decimal);
            for (StaffStatistic statistic : listByStaff) {
                if(null == statistic.getRechargeyj()){
                    statistic.setRechargeyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getCourseOfTreatmentYJ()){
                    statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getLcCardyj()){
                    statistic.setLcCardyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getSyxfyj()){
                    statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getSyczkfyj()){
                    statistic.setSyczkfyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getSylcxkyj()){
                    statistic.setSylcxkyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getTkyj()){
                    statistic.setTkyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getKjhyj()){
                    statistic.setKjhyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getXftlcczhjyj()){
                    statistic.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getTotalyj()){
                    statistic.setTotalyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getTotaltc()){
                    statistic.setTotaltc(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getZyj()){
                    statistic.setZyj(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getRechargeTurnCourseChia()){
                    statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getRechargeTurnCourseComm()){
                    statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getGroupPurchaseChia()){
                    statistic.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getGroupPurchaseComm()){
                    statistic.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getFootMassageComm()){
                    statistic.setFootMassageComm(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getFootMassageChia()){
                    statistic.setFootMassageChia(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getCardFootMassageComm()){
                    statistic.setCardFootMassageComm(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getCardFootMassageChia()){
                    statistic.setCardFootMassageChia(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getMarketChia()){
                    statistic.setMarketChia(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getMarketComm()){
                    statistic.setMarketComm(BigDecimal.valueOf(0.00));
                }
                if(null == statistic.getNTMoney()){
                    statistic.setNTMoney(BigDecimal.valueOf(0.00));
                }
                staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().add(statistic.getRechargeyj()));
                staffStatistic1.setCourseOfTreatmentYJ(staffStatistic1.getCourseOfTreatmentYJ().add(statistic.getCourseOfTreatmentYJ()));
                staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().add(statistic.getLcCardyj()));
                staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().add(statistic.getSyxfyj()));
                staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().add(statistic.getSyczkfyj()));
                staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().add(statistic.getSylcxkyj()));
                staffStatistic1.setTkyj(staffStatistic1.getTkyj().add(statistic.getTkyj()));
                staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().add(statistic.getKjhyj()));
                staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().add(statistic.getCardcxyj()));
                staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().add(statistic.getCashcxyj()));
                staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().add(statistic.getXftlcczhjyj()));
                staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().add(statistic.getTotalyj()));
                staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getTotaltc()));
                staffStatistic1.setZyj(staffStatistic1.getZyj().add(statistic.getZyj()));
                staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getRechargeTurnCourseChia()));
                staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().add(statistic.getRechargeTurnCourseComm()));
                staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().add(statistic.getGroupPurchaseChia()));
                staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().add(statistic.getGroupPurchaseComm()));

                staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().add(statistic.getFootMassageComm()));
                staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().add(statistic.getFootMassageChia()));
                staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().add(statistic.getCardFootMassageComm()));
                staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().add(statistic.getCardFootMassageChia()));
                staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().add(statistic.getMarketChia()));
                staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().add(statistic.getMarketComm()));
                staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().add(statistic.getNTMoney()));
                staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi());
            }

            staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistic1.getCourseOfTreatmentYJ(),staffStatistic1.getCashcxyj()).setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setTkyj(staffStatistic1.getTkyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setZyj(staffStatistic1.getZyj().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().setScale(2,BigDecimal.ROUND_HALF_UP));


            staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().setScale(2,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().setScale(2,BigDecimal.ROUND_HALF_UP));

            BaseStaff baseStaff = new BaseStaff();
            baseStaff.setId(staffStatistic1.getStaffId());
            BaseStaff select = ssmBaseStaffService.selectOne(baseStaff);
            staffStatistic1.setBaseSalary(BigDecimal.valueOf(0));
            staffStatistic1.setTotalWages(BigDecimal.valueOf(0));
            //todo 空指针
            if(select!=null) {
                staffStatistic1.setBaseSalary(select.getBaseSalary());
                staffStatistic1.setTotalWages(select.getBaseSalary().add(staffStatistic1.getTotaltc()));
            }
            String format = String.format("%.2f", staffStatistic1.getTotaltc());
            staffStatistic1.setTotaltc(BigDecimal.valueOf(Double.valueOf(format)).setScale(2, BigDecimal.ROUND_HALF_UP));
            staffStatisticsLs.add(staffStatistic1);
        }


        List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
        List<AchiCommEntity> totalList1 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
        //合并list
        cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
        while (entryIterator1.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();
            //按天进行分组
            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                List<AchiCommEntity> list = stringListEntry.getValue();

                //业绩
                BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(list.get(list.size()-1).getDocDate());
                statistic.setAchievementAmount(CardAchi);
                statistic.setCommissionAmount(CardComm);
                statistic.setCardAchi(CardAchi);
                statistic.setCardComm(CardComm);
                statistic.setClassify(staffStatistic.getClassify());
                statistic.setStoreId(staffStatistic.getStoreId());
                statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                staffStatisticList1.add(statistic);
            }
            //}
        }

        for (StaffStatistic statistic : staffStatisticList1) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if (effectiveDate){
                staffStatisticList2.add(statistic);
            }
        }
        staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());

        Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
        //汇总后的集合

        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();

        List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
        while (entryIteratorsList1.hasNext()) {
            StaffStatistic staffStatistic1 = new StaffStatistic();

            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
            List<StaffStatistic> listByStaff = entry.getValue();
            for (StaffStatistic statistic : listByStaff) {

                staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                BigDecimal decimal = BigDecimal.valueOf(0);
                staffStatistic1.setFootMassageComm(decimal);
                staffStatistic1.setFootMassageChia(decimal);
                staffStatistic1.setCardFootMassageComm(decimal);
                staffStatistic1.setCardFootMassageChia(decimal);
                staffStatistic1.setMarketChia(decimal);
                staffStatistic1.setMarketComm(decimal);


                staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setStaffName(statistic.getStaffName());
                staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                staffStatisticsLs1.add(staffStatistic1);
            }

        }
        for (StaffStatistic staffStatistics : staffStatisticsLs) {
            for (StaffStatistic statistic : staffStatisticsLs1) {
                if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
                    staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                    staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
                }
            }
        }
        List<Long> longs = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
        List<StaffStatistic> collect = staffStatisticsLs1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

        for (StaffStatistic statistic : collect) {
            staffStatisticsLs.add(statistic);
        }



        //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
        List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
        List<AchiCommEntity> totalList2 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
        List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
        //合并list
        coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
        while (entryIterator2.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
            List<AchiCommEntity> listByStaff = entry.getValue();
            //按天进行分组
            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                List<AchiCommEntity> list = stringListEntry.getValue();

                //业绩
                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                StaffStatistic statistic = new StaffStatistic();
                statistic.setStaffId(entry.getKey());
                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
                //按天查询用date

                statistic.setDate(list.get(list.size()-1).getDocDate());
                statistic.setAchievementAmount(CardAchi);
                statistic.setCommissionAmount(CardComm);
                statistic.setCardAchi(CardAchi);
                statistic.setCardComm(CardComm);
                statistic.setClassify(staffStatistic.getClassify());
                statistic.setStoreId(staffStatistic.getStoreId());
                statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                staffStatisticList3.add(statistic);
            }
            //}
        }

        for (StaffStatistic statistic : staffStatisticList3) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if (effectiveDate){
                staffStatisticList4.add(statistic);
            }
        }
        staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());

        Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
        //汇总后的集合

        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();

        List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();
        while (entryIteratorsList2.hasNext()) {
            StaffStatistic staffStatistic1 = new StaffStatistic();

            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
            List<StaffStatistic> listByStaff = entry.getValue();
            for (StaffStatistic statistic : listByStaff) {

                staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                BigDecimal decimal = BigDecimal.valueOf(0);
                staffStatistic1.setFootMassageComm(decimal);
                staffStatistic1.setFootMassageChia(decimal);
                staffStatistic1.setCardFootMassageComm(decimal);
                staffStatistic1.setCardFootMassageChia(decimal);
                staffStatistic1.setMarketChia(decimal);
                staffStatistic1.setMarketComm(decimal);

                staffStatistic1.setStaffId(statistic.getStaffId());
                //staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setStaffName(statistic.getStaffName());
                staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargeTurnCourseChia(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setZyj(BigDecimalUtils.bigDecimal("0"));
                staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                staffStatisticsLs2.add(staffStatistic1);
            }

        }
        for (StaffStatistic staffStatistics : staffStatisticsLs) {
            for (StaffStatistic statistic : staffStatisticsLs2) {
                if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
                    //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                    staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                    //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
                    staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
                }
            }
//            staffStatistics.setCourseOfTreatmentYJ(staffStatistics.getCourseOfTreatmentYJ().add(
//                    (staffStatistics.getCardAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCardAchi())
//                    .add(staffStatistics.getCashAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCashAchi())));
        }
        List<Long> longs1 = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
        List<StaffStatistic> collect1 = staffStatisticsLs2.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

        for (StaffStatistic statistic : collect1) {
            staffStatisticsLs.add(statistic);
        }
        for (StaffStatistic staffStatisticsL : staffStatisticsLs) {
            BaseStaff baseStaff = ssmBaseStaffService.selectByPrimaryKey(staffStatisticsL.getStaffId());
            if(baseStaff!=null) {
                staffStatisticsL.setBrandNumber(baseStaff.getBrandNumber());
                staffStatisticsL.setStaffName(baseStaff.getStaffName());
            }
        }



        return staffStatisticsLs;
    }

    @Override
    public List<StaffStatistic> achiCommListsgroupByStoreList(StaffStatistic staffStatistic) throws ParseException, SmsException {
        //汇总后的集合
        List<StaffStatistic> staffStatisticsLs= new ArrayList<>();
        if(staffStatistic.getStoreIds()!=null && staffStatistic.getStoreIds().size()>0){
            for (Long storeIdNew : staffStatistic.getStoreIds()) {
                staffStatistic.setStoreId(storeIdNew);
                BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeIdNew);
                List<StaffStatistic> staffStatisticList = new ArrayList<>();
                List<StaffStatistic> staffStatisticLists = new ArrayList<>();

                BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
                BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
                //根据时间类别转换时间
                //int type = staffStatistic.getType();
                String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = dateFormat.parse(staffStatistic.getStartDate());
                Long storeId = staffStatistic.getStoreId();
                List<RechargeListResponse> recList = new ArrayList<>();
                List<CourseListResponse> courseList = new ArrayList<>();
                List<CashListResponse> cashList = new ArrayList<>();
                List<RepayTradeResponse> RepayLists = new ArrayList<>();
                List<RefundRechargeResponse> refundRecList = new ArrayList<>();
                List<RefundCourseResponse> refundCourseList = new ArrayList<>();
                List<CashListResponse> refundCashList = new ArrayList<>();
                List<DocPromotionResponse> promotionList = new ArrayList<>();
                List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
                List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
                List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();
                List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
                if (null == staffStatistic.getClassify()) {
                    recList = ssmRechargeService.selectList(storeId, dateStr, date);
                    courseList = ssmCourseService.selectList(storeId, dateStr, date);
                    cashList = ssmCashService.selectList(storeId, dateStr, date);
                    RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                    refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                    refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                    //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                    refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
                    promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                    //加价转疗程
                    cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                    //疗程转充值
                    rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId, dateStr);
                    //查询团购卡
                    baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId, dateStr);

                    //查询开房收银
                    serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
                } else {
                    if ("0".equals(staffStatistic.getClassify())) {
                        //查询充值业务员信息
                        recList = ssmRechargeService.selectList(storeId, dateStr, date);
                    } else if ("1".equals(staffStatistic.getClassify())) {
                        //查询疗程业务员信息
                        courseList = ssmCourseService.selectList(storeId, dateStr, date);
                    } else if ("2".equals(staffStatistic.getClassify())) {
                        //查询服务单业务员信息
                        cashList = ssmCashService.selectList(storeId, dateStr, date);
                    } else if ("3".equals(staffStatistic.getClassify())) {
                        //查询还款单业务员信息
                        RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                    } else if ("4".equals(staffStatistic.getClassify())) {
                        //查询充值退款单业务员
                        refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                    } else if ("5".equals(staffStatistic.getClassify())) {
                        //查询疗程退款单业务员
                        refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                    } else if ("6".equals(staffStatistic.getClassify())) {
                        //查询收银退款单业务员
                        //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                        refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
                    } else if ("7".equals(staffStatistic.getClassify())) {
                        //查询促销单业务员
                        promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                    } else if ("8".equals(staffStatistic.getClassify())) {
                        //查询加价转疗程单业务员
                        cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                    } else if ("9".equals(staffStatistic.getClassify())) {
                        //查询团购卡
                        baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId, dateStr);
                    }
                }
                List<AchiCommEntity> totalList = new ArrayList<>();
                //合并list
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    List<CardChangeOutProject> outProjects = cardChangeList.getOutProjects();
                    List<CardChangeOutProject> collect = outProjects.stream().filter(item -> item.getEntities() != null && item.getEntities().size() > 0).collect(Collectors.toList());
                    collect.
                            forEach(cardChangeOutProject -> cardChangeOutProject.getEntities()
                                    .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                }
                for (AchiCommEntity achiCommEntity : totalList) {
                    achiCommEntity.setMoney(BigDecimal.ZERO);
                }
                recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                rechargeTurnCourses.forEach(rechargeTurnCoursesResponse -> rechargeTurnCoursesResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
                //计算每个分组员工的业绩
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    for (AchiCommEntity entity : cardChangeList.getEntities()) {
                        entity.setCardAchi(cardChangeList.getChangeOutMoney().multiply(entity.getSaleRatio()).divide(BigDecimal.valueOf(100)));
                        entity.setCashAchi(cardChangeList.getChangeInPayMoney().multiply(entity.getSaleRatio()).divide(BigDecimal.valueOf(100)));
                    }
                }
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
                while (entryIterator.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {

                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();
                        //充值 + 充值还款 业绩
                        BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 业绩
                        BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程 + 疗程还款 业绩
                        BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //加价转疗程 业绩
                        BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //todo
                        BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCashAchi() == null ? BigDecimal.valueOf(0) : item.getCashAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //todo
                        BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCardAchi() == null ? BigDecimal.valueOf(0) : item.getCardAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 业绩
                        BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 业绩
                        BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                        //消费退 业绩
                        BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //还款业绩
                        BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销业绩
                        BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //充值  提成
                        BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 提成
                        BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程  提成
                        BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 提成
                        BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 提成
                        BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //消费退 提成
                        BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //还款提成
                        BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销提成
                        BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //加价转疗程提成
                        BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程转充值
                        BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


                        //团购卡业绩
                        BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //团购卡提成
                        BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销还款
                        BigDecimal cooperationAchi = BigDecimalUtils.bigDecimal("0");
                        for (AchiCommEntity achiCommEntity : list) {
                            for (CourseListResponse courseListResponse : courseList) {
                                if (achiCommEntity.getDocId() == courseListResponse.getId()) {
                                    for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                        if (entry.getKey().equals(entity.getSaleStaffId())) {
                                            cooperationAchi = cooperationAchi.add((courseListResponse.getCollectionCashAmount().subtract(courseListResponse.getAchievementAmount())).multiply(entity.getSaleRatio().divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_HALF_UP)));
                                        }
                                    }
                                }
                            }
                        }
//                BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                        achievementAmount = BigDecimalUtils.subtract(
                                BigDecimalUtils.subtract(
                                        BigDecimalUtils.subtract(
                                                BigDecimalUtils.add(
                                                        BigDecimalUtils.add(
                                                                BigDecimalUtils.add(
                                                                        recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                        commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                        //总现付业绩
                        BigDecimal totalCashAchi = BigDecimalUtils.add(
                                BigDecimalUtils.subtract(
                                        BigDecimalUtils.subtract(
                                                BigDecimalUtils.subtract(
                                                        BigDecimalUtils.add(
                                                                BigDecimalUtils.add(
                                                                        BigDecimalUtils.add(
                                                                                recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi), repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                        //总卡付业绩
                        BigDecimal totalCardAchi = BigDecimalUtils.subtract(
                                        BigDecimalUtils.add(
                                                BigDecimalUtils.add(
                                                        courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi)
                                .add(courseChangeCardAchi);
                        //总现付提成
                        BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                        //总卡付提成
                        BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                        statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                        //按天查询用date

                        statistic.setDate(list.get(list.size() - 1).getDocDate());
                        statistic.setLcCardyj(promotionCardAchi);
                        statistic.setAchievementAmount(achievementAmount);
                        statistic.setCommissionAmount(commissionAmount);
                        statistic.setCashAchi(totalCashAchi);
                        statistic.setCardAchi(totalCardAchi);
                        statistic.setCashComm(totalCashComm);
                        statistic.setCardComm(totalCardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());

                        statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                        statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                        statistic.setCooperationAchi(cooperationAchi);
                        BigDecimal repayProAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayProComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        statistic.setCourseOfTreatmentYJ(repayProAchi);
                        statistic.setCourseOfTreatmentTC(repayProComm);
                        staffStatisticList.add(statistic);
                    }
                    //}
                }

                for (StaffStatistic statistic : staffStatisticList) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        StaffStatistic staffStatistic1 = new StaffStatistic();
                        staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                        staffStatistic1.setDate(statistic.getDate());
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStoreId(storeId);
                        staffStatistic1.setClassify("0");
                        List<StaffStatistic> staffStatistics = null;
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setRechargeyj(BigDecimal.valueOf(0));
                        statistic.setRechargeTC(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("1");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        if(statistic.getCourseOfTreatmentYJ()==null){
                            statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
                        }
                        if(statistic.getCourseOfTreatmentTC()==null){

                            statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                        }
//                        statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
//                        statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                        if(statistic.getLcCardyj()==null) {
                            statistic.setLcCardyj(BigDecimal.valueOf(0));
                        }
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
                                    statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("2");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setServeYJ(BigDecimal.valueOf(0));
                        statistic.setServeTC(BigDecimal.valueOf(0));
                        statistic.setSyxfyj(BigDecimal.valueOf(0));
                        statistic.setSyczkfyj(BigDecimal.valueOf(0));
                        statistic.setSylcxkyj(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
                                    statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
                                    //收银的现付总业绩
                                    statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
                                    statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
                                    statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
                                }
                            }
                        }

                        staffStatistics = null;
                        staffStatistic1.setClassify("4");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
                        statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("5");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
                        statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
                                }
                            }
                        }
                        statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
                        statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));

                        staffStatistics = null;
                        staffStatistic1.setClassify("6");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
                        statistic.setCashierRefundTC(BigDecimal.valueOf(0));
                        statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
                                    statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
                                    statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
                                }
                            }
                        }
                        statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
                        statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
                        statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3,BigDecimal.ROUND_HALF_UP)));

                        staffStatistics = null;
                        staffStatistic1.setClassify("7");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setLeafletYJ(BigDecimal.valueOf(0));
                        statistic.setLeafletTC(BigDecimal.valueOf(0));
                        statistic.setCashcxyj(BigDecimal.valueOf(0));
                        statistic.setCardcxyj(BigDecimal.valueOf(0));
                        statistic.setCashcxtc(BigDecimal.valueOf(0));
                        statistic.setCardcxtc(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
                                    statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
                                    statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
                                }
                            }
                        }

                        staffStatistics = null;
                        staffStatistic1.setClassify("8");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setJjzlcyj(BigDecimal.valueOf(0));
                        statistic.setJjzlctc(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
                                    statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(), BigDecimal.valueOf(0.00))));
                                    statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(), staffStatistic2.getCardComm()), BigDecimal.valueOf(0.00))));
                                    statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
                                }
                            }
                        }

                        staffStatistics = null;
                        statistic.setNTMoney(BigDecimal.valueOf(0));
                        staffStatistic1.setClassify("3");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    if (null == staffStatistic2.getCzhkyj()) {
                                        staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getCzhktc()) {
                                        staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getLchkyj()) {
                                        staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getLchktc()) {
                                        staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getNTMoney()) {
                                        staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
                                    }
                                    //充值开卡
                                    statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getCzhkyj()));
                                    statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getCzhktc()));
                                    //疗程开卡
                                    statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(), staffStatistic2.getLchkyj()));
                                    statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(), staffStatistic2.getLchktc()));
                                    //促销开卡
                                    if (staffStatistic2.getType() == 2) {
                                        statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(), staffStatistic2.getCashcxyj()));
                                        statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(), staffStatistic2.getCashcxtc()));
                                    }
                                    statistic.setNTMoney(statistic.getNTMoney().add(staffStatistic2.getNTMoney()));
                                }
                            }
                        }

                        staffStatistics = null;
                        staffStatistic1.setClassify("9");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
                        statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
                                    statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
                                }
                            }
                        }


                        staffStatistics = null;
                        staffStatistic1.setClassify("10");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
                        statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
                                    statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getGroupPurchaseChia()));
                                    statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getGroupPurchaseComm()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("11");
                        staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                        BigDecimal decimal = BigDecimal.valueOf(0);
                        statistic.setFootMassageComm(decimal);
                        statistic.setFootMassageChia(decimal);
                        statistic.setCardFootMassageComm(decimal);
                        statistic.setCardFootMassageChia(decimal);
                        statistic.setMarketChia(decimal);
                        statistic.setMarketComm(decimal);
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
                                    statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
                                    statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
                                    statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
                                    statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
                                    statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
                                }
                            }
                        }

                        //根据甲方要求，退款的单据业绩不加进总业绩里面
                        statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
                        //todo 进行修改
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                        statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                        //退款业绩
                        statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
                        if (null == statistic.getSyxfyj()) {
                            statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                        }
                        //总业绩
                        statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
                        //扣减后业绩
                        statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                        statistic.setZyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                        statistic.setCooperationAchi(statistic.getCooperationAchi());

                        staffStatisticLists.add(statistic);
                    }
                }
                staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());

                Map<Long, List<StaffStatistic>> resultMaps = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));

                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList = resultMaps.entrySet().iterator();
                while (entryIteratorsList.hasNext()) {
                    StaffStatistic staffStatistic1 = new StaffStatistic();

                    Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    staffStatistic1.setStaffId(listByStaff.get(0).getStaffId());
                    staffStatistic1.setStaffName(listByStaff.get(0).getStaffName());
                    staffStatistic1.setBrandNumber(listByStaff.get(0).getBrandNumber());
                    staffStatistic1.setCooperationAchi(listByStaff.get(0).getCooperationAchi());
                    staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    if(staffStatistic1.getLcCardyj()==null) {
                        staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    staffStatistic1.setFootMassageComm(decimal);
                    staffStatistic1.setFootMassageChia(decimal);
                    staffStatistic1.setCardFootMassageComm(decimal);
                    staffStatistic1.setCardFootMassageChia(decimal);
                    staffStatistic1.setMarketChia(decimal);
                    staffStatistic1.setMarketComm(decimal);
                    for (StaffStatistic statistic : listByStaff) {
                        if (null == statistic.getRechargeyj()) {
                            statistic.setRechargeyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getCourseOfTreatmentYJ()) {
                            statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getLcCardyj()) {
                            statistic.setLcCardyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getSyxfyj()) {
                            statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getSyczkfyj()) {
                            statistic.setSyczkfyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getSylcxkyj()) {
                            statistic.setSylcxkyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getTkyj()) {
                            statistic.setTkyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getKjhyj()) {
                            statistic.setKjhyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getXftlcczhjyj()) {
                            statistic.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getTotalyj()) {
                            statistic.setTotalyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getTotaltc()) {
                            statistic.setTotaltc(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getZyj()) {
                            statistic.setZyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getRechargeTurnCourseChia()) {
                            statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getRechargeTurnCourseComm()) {
                            statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getGroupPurchaseChia()) {
                            statistic.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getGroupPurchaseComm()) {
                            statistic.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getFootMassageComm()) {
                            statistic.setFootMassageComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getFootMassageChia()) {
                            statistic.setFootMassageChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getCardFootMassageComm()) {
                            statistic.setCardFootMassageComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getCardFootMassageChia()) {
                            statistic.setCardFootMassageChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getMarketChia()) {
                            statistic.setMarketChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getMarketComm()) {
                            statistic.setMarketComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getNTMoney()) {
                            statistic.setNTMoney(BigDecimal.valueOf(0.00));
                        }
                        staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().add(statistic.getRechargeyj()));
                        staffStatistic1.setCourseOfTreatmentYJ(staffStatistic1.getCourseOfTreatmentYJ().add(statistic.getCourseOfTreatmentYJ()));
                        staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().add(statistic.getLcCardyj()));
                        staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().add(statistic.getSyxfyj()));
                        staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().add(statistic.getSyczkfyj()));
                        staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().add(statistic.getSylcxkyj()));
                        staffStatistic1.setTkyj(staffStatistic1.getTkyj().add(statistic.getTkyj()));
                        staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().add(statistic.getKjhyj()));
                        staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().add(statistic.getCardcxyj()));
                        staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().add(statistic.getCashcxyj()));
                        staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().add(statistic.getXftlcczhjyj()));
                        staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().add(statistic.getTotalyj()));
                        staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getTotaltc()));
                        staffStatistic1.setZyj(staffStatistic1.getZyj().add(statistic.getZyj()));
                        staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getRechargeTurnCourseChia()));
                        staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().add(statistic.getRechargeTurnCourseComm()));
                        staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().add(statistic.getGroupPurchaseChia()));
                        staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().add(statistic.getGroupPurchaseComm()));

                        staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().add(statistic.getFootMassageComm()));
                        staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().add(statistic.getFootMassageChia()));
                        staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().add(statistic.getCardFootMassageComm()));
                        staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().add(statistic.getCardFootMassageChia()));
                        staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().add(statistic.getMarketChia()));
                        staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().add(statistic.getMarketComm()));
                        staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().add(statistic.getNTMoney()));
                        staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi());
                    }

                    staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistic1.getCourseOfTreatmentYJ(), staffStatistic1.getCashcxyj()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTkyj(staffStatistic1.getTkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setZyj(staffStatistic1.getZyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().setScale(2, BigDecimal.ROUND_HALF_UP));


                    staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().setScale(2, BigDecimal.ROUND_HALF_UP));

                    BaseStaff baseStaff = new BaseStaff();
                    baseStaff.setId(staffStatistic1.getStaffId());
                    BaseStaff select = ssmBaseStaffService.selectOne(baseStaff);
                    staffStatistic1.setBaseSalary(BigDecimal.valueOf(0));
                    staffStatistic1.setTotalWages(BigDecimal.valueOf(0));
                    //todo 空指针
                    if (select != null) {
                        staffStatistic1.setBaseSalary(select.getBaseSalary());
                        staffStatistic1.setTotalWages(select.getBaseSalary().add(staffStatistic1.getTotaltc()));
                    }
                    String format = String.format("%.2f", staffStatistic1.getTotaltc());
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(Double.valueOf(format)).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setStoreName(baseStore.getStoreName());
                    staffStatistic1.setStoreNum(baseStore.getStoreNum());
                    staffStatisticsLs.add(staffStatistic1);
                }


                List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId, dateStr);
                List<AchiCommEntity> totalList1 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
                //合并list
                cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
                while (entryIterator1.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();

                        //业绩
                        BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                        statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                        //按天查询用date

                        statistic.setDate(list.get(list.size() - 1).getDocDate());
                        statistic.setAchievementAmount(CardAchi);
                        statistic.setCommissionAmount(CardComm);
                        statistic.setCardAchi(CardAchi);
                        statistic.setCardComm(CardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                        staffStatisticList1.add(statistic);
                    }
                    //}
                }

                for (StaffStatistic statistic : staffStatisticList1) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        staffStatisticList2.add(statistic);
                    }
                }
                staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());

                Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
                //汇总后的集合

                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();

                List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
                while (entryIteratorsList1.hasNext()) {

                    Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    for (StaffStatistic statistic : listByStaff) {
                        StaffStatistic staffStatistic1 = new StaffStatistic();

                        staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                        if(staffStatistic1.getLcCardyj()==null) {
                            staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                        }
                        staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                        BigDecimal decimal = BigDecimal.valueOf(0);
                        staffStatistic1.setFootMassageComm(decimal);
                        staffStatistic1.setFootMassageChia(decimal);
                        staffStatistic1.setCardFootMassageComm(decimal);
                        staffStatistic1.setCardFootMassageChia(decimal);
                        staffStatistic1.setMarketChia(decimal);
                        staffStatistic1.setMarketComm(decimal);


                        staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStaffName(statistic.getStaffName());
                        staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                        staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                        staffStatisticsLs1.add(staffStatistic1);
                    }

                }
                for (StaffStatistic staffStatistics : staffStatisticsLs) {
                    for (StaffStatistic statistic : staffStatisticsLs1) {
                        if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                            staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(), statistic.getCourseOfTreatmentYJ()));
                            staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(), statistic.getCourseOfTreatmentYJ()));
                            staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(), statistic.getCourseOfTreatmentYJ()));
                            staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                            staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                        }
                    }
                }
                List<Long> longs = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
                List<StaffStatistic> collect = staffStatisticsLs1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

                for (StaffStatistic statistic : collect) {
                    staffStatisticsLs.add(statistic);
                }


                //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
                List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
                List<AchiCommEntity> totalList2 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
                //合并list
                coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
                while (entryIterator2.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();

                        //业绩
                        //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                        statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                        //按天查询用date

                        statistic.setDate(list.get(list.size() - 1).getDocDate());
                        statistic.setAchievementAmount(CardAchi);
                        statistic.setCommissionAmount(CardComm);
                        statistic.setCardAchi(CardAchi);
                        statistic.setCardComm(CardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                        staffStatisticList3.add(statistic);
                    }
                    //}
                }

                for (StaffStatistic statistic : staffStatisticList3) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        staffStatisticList4.add(statistic);
                    }
                }
                staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());

                Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
                //汇总后的集合

                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();

                List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();
                while (entryIteratorsList2.hasNext()) {

                    Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    for (StaffStatistic statistic : listByStaff) {
                        StaffStatistic staffStatistic1 = new StaffStatistic();

                        staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                        if(staffStatistic1.getLcCardyj()==null) {
                            staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                        }
                        staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                        BigDecimal decimal = BigDecimal.valueOf(0);
                        staffStatistic1.setFootMassageComm(decimal);
                        staffStatistic1.setFootMassageChia(decimal);
                        staffStatistic1.setCardFootMassageComm(decimal);
                        staffStatistic1.setCardFootMassageChia(decimal);
                        staffStatistic1.setMarketChia(decimal);
                        staffStatistic1.setMarketComm(decimal);

                        staffStatistic1.setStaffId(statistic.getStaffId());
                        //staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStaffName(statistic.getStaffName());
                        staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                        //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setRechargeTurnCourseChia(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setZyj(BigDecimalUtils.bigDecimal("0"));
                        staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());

                        staffStatisticsLs2.add(staffStatistic1);
                    }

                }
                for (StaffStatistic staffStatistics : staffStatisticsLs) {

                    for (StaffStatistic statistic : staffStatisticsLs2) {
                        if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                            //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
//                            staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(), statistic.getRechargeTurnCourseChia()));
                            //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                            //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                            staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                            staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                        }
                    }
//            staffStatistics.setCourseOfTreatmentYJ(staffStatistics.getCourseOfTreatmentYJ().add(
//                    (staffStatistics.getCardAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCardAchi())
//                    .add(staffStatistics.getCashAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCashAchi())));
                }
                List<Long> longs1 = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
                List<StaffStatistic> collect1 = staffStatisticsLs2.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

                for (StaffStatistic statistic : collect1) {

                    staffStatisticsLs.add(statistic);
                }
            }
        }
        else {
            //-----------------
            BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(staffStatistic.getStoreId());
            List<StaffStatistic> staffStatisticList = new ArrayList<>();
            List<StaffStatistic> staffStatisticLists = new ArrayList<>();

            BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
            BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
            //根据时间类别转换时间
            //int type = staffStatistic.getType();
            String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = dateFormat.parse(staffStatistic.getStartDate());
            Long storeId = staffStatistic.getStoreId();
            List<RechargeListResponse> recList = new ArrayList<>();
            List<CourseListResponse> courseList = new ArrayList<>();
            List<CashListResponse> cashList = new ArrayList<>();
            List<RepayTradeResponse> RepayLists = new ArrayList<>();
            List<RefundRechargeResponse> refundRecList = new ArrayList<>();
            List<RefundCourseResponse> refundCourseList = new ArrayList<>();
            List<CashListResponse> refundCashList = new ArrayList<>();
            List<DocPromotionResponse> promotionList = new ArrayList<>();
            List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
            List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
            List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();
            List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
            if (null == staffStatistic.getClassify()) {
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
                cashList = ssmCashService.selectList(storeId, dateStr, date);
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                //加价转疗程
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                //疗程转充值
                rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId, dateStr);
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId, dateStr);

                //查询开房收银
                serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
            } else {
                if ("0".equals(staffStatistic.getClassify())) {
                    //查询充值业务员信息
                    recList = ssmRechargeService.selectList(storeId, dateStr, date);
                } else if ("1".equals(staffStatistic.getClassify())) {
                    //查询疗程业务员信息
                    courseList = ssmCourseService.selectList(storeId, dateStr, date);
                } else if ("2".equals(staffStatistic.getClassify())) {
                    //查询服务单业务员信息
                    cashList = ssmCashService.selectList(storeId, dateStr, date);
                } else if ("3".equals(staffStatistic.getClassify())) {
                    //查询还款单业务员信息
                    RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                } else if ("4".equals(staffStatistic.getClassify())) {
                    //查询充值退款单业务员
                    refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                } else if ("5".equals(staffStatistic.getClassify())) {
                    //查询疗程退款单业务员
                    refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                } else if ("6".equals(staffStatistic.getClassify())) {
                    //查询收银退款单业务员
                    //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                    refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
                } else if ("7".equals(staffStatistic.getClassify())) {
                    //查询促销单业务员
                    promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                } else if ("8".equals(staffStatistic.getClassify())) {
                    //查询加价转疗程单业务员
                    cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                } else if ("9".equals(staffStatistic.getClassify())) {
                    //查询团购卡
                    baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId, dateStr);
                }
            }
            List<AchiCommEntity> totalList = new ArrayList<>();
            //合并list
            for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                List<CardChangeOutProject> outProjects = cardChangeList.getOutProjects();
                List<CardChangeOutProject> collect = outProjects.stream().filter(item -> item.getEntities() != null && item.getEntities().size() > 0).collect(Collectors.toList());
                collect.
                        forEach(cardChangeOutProject -> cardChangeOutProject.getEntities()
                                .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            }
            for(AchiCommEntity achiCommEntity : totalList) {
                achiCommEntity.setMoney(BigDecimal.ZERO);
            }
            recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            rechargeTurnCourses.forEach(rechargeTurnCoursesResponse -> rechargeTurnCoursesResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                for (AchiCommEntity entity : cardChangeList.getEntities()) {
                    entity.setCardAchi(cardChangeList.getChangeOutMoney().multiply(entity.getSaleRatio()).divide(BigDecimal.valueOf(100)));
                    entity.setCashAchi(cardChangeList.getChangeInPayMoney().multiply(entity.getSaleRatio()).divide(BigDecimal.valueOf(100)));
                }
            }
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
            while (entryIterator.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //todo
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCashAchi() == null ? BigDecimal.valueOf(0) : item.getCashAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //todo
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCardAchi() == null ? BigDecimal.valueOf(0) : item.getCardAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销还款
                    BigDecimal cooperationAchi = BigDecimalUtils.bigDecimal("0");
                    for (AchiCommEntity achiCommEntity : list) {
                        for (CourseListResponse courseListResponse : courseList) {
                            if (achiCommEntity.getDocId() == courseListResponse.getId()) {
                                for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                    if (entry.getKey().equals(entity.getSaleStaffId())) {
                                        cooperationAchi = cooperationAchi.add((courseListResponse.getCollectionCashAmount().subtract(courseListResponse.getAchievementAmount())).multiply(entity.getSaleRatio().divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_HALF_UP)));
                                    }
                                }
                            }
                        }
                    }
//                BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    achievementAmount = BigDecimalUtils.subtract(
                            BigDecimalUtils.subtract(
                                    BigDecimalUtils.subtract(
                                            BigDecimalUtils.add(
                                                    BigDecimalUtils.add(
                                                            BigDecimalUtils.add(
                                                                    recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(
                            BigDecimalUtils.subtract(
                                    BigDecimalUtils.subtract(
                                            BigDecimalUtils.subtract(
                                                    BigDecimalUtils.add(
                                                            BigDecimalUtils.add(
                                                                    BigDecimalUtils.add(
                                                                            recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi), repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(
                                    BigDecimalUtils.add(
                                            BigDecimalUtils.add(
                                                    courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi)
                            .add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(list.size() - 1).getDocDate());
                    statistic.setLcCardyj(promotionCardAchi);
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());

                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                    statistic.setCooperationAchi(cooperationAchi);
                    BigDecimal repayProAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayProComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    statistic.setCourseOfTreatmentYJ(repayProAchi);
                    statistic.setCourseOfTreatmentTC(repayProComm);
                    staffStatisticList.add(statistic);
                }
                //}
            }

            for (StaffStatistic statistic : staffStatisticList) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                    staffStatistic1.setDate(statistic.getDate());
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStoreId(storeId);
                    staffStatistic1.setClassify("0");
                    List<StaffStatistic> staffStatistics = null;
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setRechargeyj(BigDecimal.valueOf(0));
                    statistic.setRechargeTC(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
                                statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("1");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    if(statistic.getCourseOfTreatmentYJ()==null){
                        statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
                    }
                    if(statistic.getCourseOfTreatmentTC()==null){

                        statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                    }
                    if(statistic.getLcCardyj()==null) {
                        statistic.setLcCardyj(BigDecimal.valueOf(0));
                    }
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
                                statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("2");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setServeYJ(BigDecimal.valueOf(0));
                    statistic.setServeTC(BigDecimal.valueOf(0));
                    statistic.setSyxfyj(BigDecimal.valueOf(0));
                    statistic.setSyczkfyj(BigDecimal.valueOf(0));
                    statistic.setSylcxkyj(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
                                statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
                                //收银的现付总业绩
                                statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
                                statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
                                statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
                            }
                        }
                    }

                    staffStatistics = null;
                    staffStatistic1.setClassify("4");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
                    statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("5");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
                    statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
                            }
                        }
                    }
                    statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
                    statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));

                    staffStatistics = null;
                    staffStatistic1.setClassify("6");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
                    statistic.setCashierRefundTC(BigDecimal.valueOf(0));
                    statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
                                statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
                                statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
                            }
                        }
                    }
                    statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
                    statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
                    statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3,BigDecimal.ROUND_HALF_UP)));

                    staffStatistics = null;
                    staffStatistic1.setClassify("7");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setLeafletYJ(BigDecimal.valueOf(0));
                    statistic.setLeafletTC(BigDecimal.valueOf(0));
                    statistic.setCashcxyj(BigDecimal.valueOf(0));
                    statistic.setCardcxyj(BigDecimal.valueOf(0));
                    statistic.setCashcxtc(BigDecimal.valueOf(0));
                    statistic.setCardcxtc(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
                                statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
                                statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
                            }
                        }
                    }

                    staffStatistics = null;
                    staffStatistic1.setClassify("8");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setJjzlcyj(BigDecimal.valueOf(0));
                    statistic.setJjzlctc(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
                                statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(), BigDecimal.valueOf(0.00))));
                                statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(), staffStatistic2.getCardComm()), BigDecimal.valueOf(0.00))));
                                statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
                            }
                        }
                    }

                    staffStatistics = null;
                    statistic.setNTMoney(BigDecimal.valueOf(0));
                    staffStatistic1.setClassify("3");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                if (null == staffStatistic2.getCzhkyj()) {
                                    staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getCzhktc()) {
                                    staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getLchkyj()) {
                                    staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getLchktc()) {
                                    staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getNTMoney()) {
                                    staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
                                }
                                //充值开卡
                                statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getCzhkyj()));
                                statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getCzhktc()));
                                //疗程开卡
                                statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(), staffStatistic2.getLchkyj()));
                                statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(), staffStatistic2.getLchktc()));
                                //促销开卡
                                if (staffStatistic2.getType() == 2) {
                                    statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(), staffStatistic2.getCashcxyj()));
                                    statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(), staffStatistic2.getCashcxtc()));
                                }
                                statistic.setNTMoney(statistic.getNTMoney().add(staffStatistic2.getNTMoney()));
                            }
                        }
                    }

                    staffStatistics = null;
                    staffStatistic1.setClassify("9");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
                    statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
                                statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
                            }
                        }
                    }


                    staffStatistics = null;
                    staffStatistic1.setClassify("10");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
                    statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
                                statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getGroupPurchaseChia()));
                                statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getGroupPurchaseComm()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("11");
                    staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    statistic.setFootMassageComm(decimal);
                    statistic.setFootMassageChia(decimal);
                    statistic.setCardFootMassageComm(decimal);
                    statistic.setCardFootMassageChia(decimal);
                    statistic.setMarketChia(decimal);
                    statistic.setMarketComm(decimal);
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
                                statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
                                statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
                                statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
                                statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
                                statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
                            }
                        }
                    }

                    //根据甲方要求，退款的单据业绩不加进总业绩里面
                    statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
                    //todo 进行修改
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                    statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                    //退款业绩
                    statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
                    if (null == statistic.getSyxfyj()) {
                        statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                    }
                    //总业绩

                    statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
                    //扣减后业绩
                    if(statistic.getTotalyj().compareTo(new BigDecimal("6000"))==0){
                        System.out.println(".....");
                    }
                    statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                    statistic.setZyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                    statistic.setCooperationAchi(statistic.getCooperationAchi());

                    staffStatisticLists.add(statistic);
                }
            }
            staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());

            Map<Long, List<StaffStatistic>> resultMaps = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));

            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList = resultMaps.entrySet().iterator();
            while (entryIteratorsList.hasNext()) {
                StaffStatistic staffStatistic1 = new StaffStatistic();

                Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                staffStatistic1.setStaffId(listByStaff.get(0).getStaffId());
                staffStatistic1.setStaffName(listByStaff.get(0).getStaffName());
                staffStatistic1.setBrandNumber(listByStaff.get(0).getBrandNumber());
                staffStatistic1.setCooperationAchi(listByStaff.get(0).getCooperationAchi());
                staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                if(staffStatistic1.getLcCardyj()==null) {
                    staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                }
                staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                BigDecimal decimal = BigDecimal.valueOf(0);
                staffStatistic1.setFootMassageComm(decimal);
                staffStatistic1.setFootMassageChia(decimal);
                staffStatistic1.setCardFootMassageComm(decimal);
                staffStatistic1.setCardFootMassageChia(decimal);
                staffStatistic1.setMarketChia(decimal);
                staffStatistic1.setMarketComm(decimal);
                for (StaffStatistic statistic : listByStaff) {
                    if (null == statistic.getRechargeyj()) {
                        statistic.setRechargeyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getCourseOfTreatmentYJ()) {
                        statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getLcCardyj()) {
                        statistic.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getSyxfyj()) {
                        statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getSyczkfyj()) {
                        statistic.setSyczkfyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getSylcxkyj()) {
                        statistic.setSylcxkyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getTkyj()) {
                        statistic.setTkyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getKjhyj()) {
                        statistic.setKjhyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getXftlcczhjyj()) {
                        statistic.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getTotalyj()) {
                        statistic.setTotalyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getTotaltc()) {
                        statistic.setTotaltc(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getZyj()) {
                        statistic.setZyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getRechargeTurnCourseChia()) {
                        statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getRechargeTurnCourseComm()) {
                        statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getGroupPurchaseChia()) {
                        statistic.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getGroupPurchaseComm()) {
                        statistic.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getFootMassageComm()) {
                        statistic.setFootMassageComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getFootMassageChia()) {
                        statistic.setFootMassageChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getCardFootMassageComm()) {
                        statistic.setCardFootMassageComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getCardFootMassageChia()) {
                        statistic.setCardFootMassageChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getMarketChia()) {
                        statistic.setMarketChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getMarketComm()) {
                        statistic.setMarketComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getNTMoney()) {
                        statistic.setNTMoney(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().add(statistic.getRechargeyj()));
                    staffStatistic1.setCourseOfTreatmentYJ(staffStatistic1.getCourseOfTreatmentYJ().add(statistic.getCourseOfTreatmentYJ()));
                    staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().add(statistic.getLcCardyj()));
                    staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().add(statistic.getSyxfyj()));
                    staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().add(statistic.getSyczkfyj()));
                    staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().add(statistic.getSylcxkyj()));
                    staffStatistic1.setTkyj(staffStatistic1.getTkyj().add(statistic.getTkyj()));
                    staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().add(statistic.getKjhyj()));
                    staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().add(statistic.getCardcxyj()));
                    staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().add(statistic.getCashcxyj()));
                    staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().add(statistic.getXftlcczhjyj()));
                    staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().add(statistic.getTotalyj()));
                    staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getTotaltc()));
                    staffStatistic1.setZyj(staffStatistic1.getZyj().add(statistic.getZyj()));
                    staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getRechargeTurnCourseChia()));
                    staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().add(statistic.getRechargeTurnCourseComm()));
                    staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().add(statistic.getGroupPurchaseChia()));
                    staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().add(statistic.getGroupPurchaseComm()));

                    staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().add(statistic.getFootMassageComm()));
                    staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().add(statistic.getFootMassageChia()));
                    staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().add(statistic.getCardFootMassageComm()));
                    staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().add(statistic.getCardFootMassageChia()));
                    staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().add(statistic.getMarketChia()));
                    staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().add(statistic.getMarketComm()));
                    staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().add(statistic.getNTMoney()));
                    staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi());
                }

                staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistic1.getCourseOfTreatmentYJ(), staffStatistic1.getCashcxyj()).setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTkyj(staffStatistic1.getTkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setZyj(staffStatistic1.getZyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().setScale(2, BigDecimal.ROUND_HALF_UP));


                staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().setScale(2, BigDecimal.ROUND_HALF_UP));

                BaseStaff baseStaff = new BaseStaff();
                baseStaff.setId(staffStatistic1.getStaffId());
                BaseStaff select = ssmBaseStaffService.selectOne(baseStaff);
                staffStatistic1.setBaseSalary(BigDecimal.valueOf(0));
                staffStatistic1.setTotalWages(BigDecimal.valueOf(0));
                //todo 空指针
                if (select != null) {
                    staffStatistic1.setBaseSalary(select.getBaseSalary());
                    staffStatistic1.setTotalWages(select.getBaseSalary().add(staffStatistic1.getTotaltc()));
                }
                String format = String.format("%.2f", staffStatistic1.getTotaltc());
                staffStatistic1.setTotaltc(BigDecimal.valueOf(Double.valueOf(format)).setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setStoreName(baseStore.getStoreName());
                staffStatistic1.setStoreNum(baseStore.getStoreNum());
                staffStatisticsLs.add(staffStatistic1);
            }


            List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList1 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
            //合并list
            cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
            while (entryIterator1.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();

                    //业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(list.size() - 1).getDocDate());
                    statistic.setAchievementAmount(CardAchi);
                    statistic.setCommissionAmount(CardComm);
                    statistic.setCardAchi(CardAchi);
                    statistic.setCardComm(CardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                    staffStatisticList1.add(statistic);
                }
                //}
            }

            for (StaffStatistic statistic : staffStatisticList1) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    staffStatisticList2.add(statistic);
                }
            }
            staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());

            Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
            //汇总后的集合

            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();

            List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
            while (entryIteratorsList1.hasNext()) {
                StaffStatistic staffStatistic1 = new StaffStatistic();

                Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                for (StaffStatistic statistic : listByStaff) {

                    staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    if(staffStatistic1.getLcCardyj()==null) {
                        staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    staffStatistic1.setFootMassageComm(decimal);
                    staffStatistic1.setFootMassageChia(decimal);
                    staffStatistic1.setCardFootMassageComm(decimal);
                    staffStatistic1.setCardFootMassageChia(decimal);
                    staffStatistic1.setMarketChia(decimal);
                    staffStatistic1.setMarketComm(decimal);


                    staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStaffName(statistic.getStaffName());
                    staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                    staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                    staffStatisticsLs1.add(staffStatistic1);
                }

            }
            for (StaffStatistic staffStatistics : staffStatisticsLs) {
                for (StaffStatistic statistic : staffStatisticsLs1) {
                    if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                        staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(), statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(), statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(), statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                        staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                    }
                }
            }
            List<Long> longs = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
            List<StaffStatistic> collect = staffStatisticsLs1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

            for (StaffStatistic statistic : collect) {
                staffStatisticsLs.add(statistic);
            }


            //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
            List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList2 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
            //合并list
            coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
            while (entryIterator2.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();

                    //业绩
                    //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(list.size() - 1).getDocDate());
                    statistic.setAchievementAmount(CardAchi);
                    statistic.setCommissionAmount(CardComm);
                    statistic.setCardAchi(CardAchi);
                    statistic.setCardComm(CardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                    staffStatisticList3.add(statistic);
                }
                //}
            }

            for (StaffStatistic statistic : staffStatisticList3) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    staffStatisticList4.add(statistic);
                }
            }
            staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());

            Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
            //汇总后的集合

            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();

            List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();
            while (entryIteratorsList2.hasNext()) {

                Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.ZERO);
                staffStatistic1.setTotaltc(BigDecimal.ZERO);
                staffStatistic1.setTotalWages(BigDecimal.ZERO);
                staffStatistic1.setCooperationAchi(BigDecimal.ZERO);
                for (StaffStatistic statistic : listByStaff) {

                    staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    if(staffStatistic1.getLcCardyj()==null) {
                        staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    staffStatistic1.setFootMassageComm(decimal);
                    staffStatistic1.setFootMassageChia(decimal);
                    staffStatistic1.setCardFootMassageComm(decimal);
                    staffStatistic1.setCardFootMassageChia(decimal);
                    staffStatistic1.setMarketChia(decimal);
                    staffStatistic1.setMarketComm(decimal);

                    staffStatistic1.setStaffId(statistic.getStaffId());
                    //staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStaffName(statistic.getStaffName());
                    staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                    //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP)));
                    //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setZyj(BigDecimalUtils.bigDecimal("0"));
                    staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP)));
                    staffStatistic1.setTotalWages(staffStatistic1.getTotalWages().add( statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP)));
                    staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().add( statistic.getCooperationAchi()==null?BigDecimal.ZERO:statistic.getCooperationAchi()));
                }
                staffStatisticsLs2.add(staffStatistic1);

            }
            for (StaffStatistic staffStatistics : staffStatisticsLs) {
                for (StaffStatistic statistic : staffStatisticsLs2) {
                    if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                        //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                        //todo 修改了疗程转充值
//                        staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(), statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                        staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                        staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                    }
                }
//            staffStatistics.setCourseOfTreatmentYJ(staffStatistics.getCourseOfTreatmentYJ().add(
//                    (staffStatistics.getCardAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCardAchi())
//                    .add(staffStatistics.getCashAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCashAchi())));
            }
            List<Long> longs1 = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
            List<StaffStatistic> collect1 = staffStatisticsLs2.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

            for (StaffStatistic statistic : collect1) {
                statistic.setStoreName(baseStore.getStoreName());
                staffStatisticsLs.add(statistic);
            }
        }
//        for (StaffStatistic staffStatisticsL : staffStatisticsLs) {
//            BaseStaff baseStaff = ssmBaseStaffService.selectByPrimaryKey(staffStatisticsL.getStaffId());
//            if (baseStaff != null) {
//                staffStatisticsL.setBrandNumber(baseStaff.getBrandNumber());
//                staffStatisticsL.setStaffName(baseStaff.getStaffName());
//            }
//        }
        return staffStatisticsLs;
    }

//    @Override
//    public List<StaffStatistic> achiCommListsgroup(StaffStatistic staffStatistic) throws ParseException, SmsException {
//        List<StaffStatistic> staffStatisticList = new ArrayList<>();
//        List<StaffStatistic> staffStatisticLists = new ArrayList<>();
//        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
//        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
//        //根据时间类别转换时间
//        //int type = staffStatistic.getType();
//        String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
////        if (0 == type) {
////            //上月
////            date = DateUtils.diffMonth(new Date(), -1);
////            dateStr = DateUtils.ymFormat(date);
////        } else if (1 == type) {
////            //昨日
////            date = DateUtils.diffDay(new Date(), -1);
////            dateStr = DateUtils.ymdFormat(date);
////        } else if (2 == type) {
////            //今日
////            dateStr = DateUtils.ymdFormat(date);
////        } else {
////            //当月
////            dateStr = DateUtils.ymFormat(date);
////        }
//
//        //分离查询时使用 否则按月查询分组时分出多个时间组
////        if (null != staffStatistic.getDate()){
////            date = staffStatistic.getDate();
////            dateStr = DateUtils.ymdFormat(date);
////        }
//
//        Long storeId = staffStatistic.getStoreId();
//        List<RechargeListResponse> recList = new ArrayList<>();
//        List<CourseListResponse> courseList = new ArrayList<>();
//        List<CashListResponse> cashList = new ArrayList<>();
//        List<RepayTradeResponse> RepayLists = new ArrayList<>();
//        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
//        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
//        List<CashListResponse> refundCashList = new ArrayList<>();
//        List<DocPromotionResponse> promotionList = new ArrayList<>();
//        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
//        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
//        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();
//        List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
//        if (null == staffStatistic.getClassify()) {
//            recList = ssmRechargeService.selectList(storeId, dateStr, date);
//            courseList = ssmCourseService.selectList(storeId, dateStr, date);
//            cashList = ssmCashService.selectList(storeId, dateStr, date);
//            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
//            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
//            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
//            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
//            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
//            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
//            //加价转疗程
//            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            //疗程转充值
//            rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateStr);
//            //查询团购卡
//            baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
//
//            //查询开房收银
//            serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
//        }
//        else {
//            if ("0".equals(staffStatistic.getClassify())) {
//                //查询充值业务员信息
//                recList = ssmRechargeService.selectList(storeId, dateStr, date);
//            } else if ("1".equals(staffStatistic.getClassify())) {
//                //查询疗程业务员信息
//                courseList = ssmCourseService.selectList(storeId, dateStr, date);
//            } else if ("2".equals(staffStatistic.getClassify())) {
//                //查询服务单业务员信息
//                cashList = ssmCashService.selectList(storeId, dateStr, date);
//            } else if ("3".equals(staffStatistic.getClassify())) {
//                //查询还款单业务员信息
//                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
//            } else if ("4".equals(staffStatistic.getClassify())) {
//                //查询充值退款单业务员
//                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
//            } else if ("5".equals(staffStatistic.getClassify())) {
//                //查询疗程退款单业务员
//                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
//            } else if ("6".equals(staffStatistic.getClassify())) {
//                //查询收银退款单业务员
//                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
//                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
//            }else if ("7".equals(staffStatistic.getClassify())) {
//                //查询促销单业务员
//                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
//            }else if ("8".equals(staffStatistic.getClassify())) {
//                //查询加价转疗程单业务员
//                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            }else if("9".equals(staffStatistic.getClassify())){
//                //查询团购卡
//                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
//            }
//        }
//        List<AchiCommEntity> totalList = new ArrayList<>();
//        //合并list
//        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        rechargeTurnCourses.forEach(rechargeTurnCoursesResponse -> rechargeTurnCoursesResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
//        //按员工ID进行分组
//        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//        //计算每个分组员工的业绩
//        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
//        while (entryIterator.hasNext()) {
//            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
//            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
//                List<AchiCommEntity> listByStaff = entry.getValue();
//                //按天进行分组
//                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
//                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
//                while (iterator.hasNext()) {
//                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
//                    List<AchiCommEntity> list = stringListEntry.getValue();
//                    //充值 + 充值还款 业绩
//                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    //充值退款 业绩
//                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //疗程 + 疗程还款 业绩
//                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //加价转疗程 业绩
//                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //疗程退款 业绩
//                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //收银 业绩
//                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//                    //消费退 业绩
//                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //还款业绩
//                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //促销业绩
//                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //充值  提成
//                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    //充值退款 提成
//                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //疗程  提成
//                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //疗程退款 提成
//                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //收银 提成
//                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //消费退 提成
//                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    //还款提成
//                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //促销提成
//                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //加价转疗程提成
//                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //疗程转充值
//                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//                    //团购卡业绩
//                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    //团购卡提成
//                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //促销还款
//
////                    BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity!=null).map(item->item.getMoney().subtract(item.getCardAchi()).subtract(item.getCashAchi())).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//
//                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
//                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
//                    commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
//                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
//                    //总现付业绩
//                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
//                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
//                    //总卡付业绩
//                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
//                    //总现付提成
//                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
//                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
//                    //总卡付提成
//                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
//                    StaffStatistic statistic = new StaffStatistic();
//                    statistic.setStaffId(entry.getKey());
//                    statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
//                    statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
//                    //按天查询用date
//
//                    statistic.setDate(list.get(list.size()-1).getDocDate());
//                    statistic.setAchievementAmount(achievementAmount);
//                    statistic.setCommissionAmount(commissionAmount);
//                    statistic.setCashAchi(totalCashAchi);
//                    statistic.setCardAchi(totalCardAchi);
//                    statistic.setCashComm(totalCashComm);
//                    statistic.setCardComm(totalCardComm);
//                    statistic.setClassify(staffStatistic.getClassify());
//                    statistic.setStoreId(staffStatistic.getStoreId());
//
//                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
//                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
//
//                    statistic.setCooperationAchi(cooperationAchi);
//                    staffStatisticList.add(statistic);
//                }
//            //}
//        }
//
//        for (StaffStatistic statistic : staffStatisticList) {
//            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
//            if(effectiveDate){
//                StaffStatistic staffStatistic1 = new StaffStatistic();
//                staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
//                staffStatistic1.setDate(statistic.getDate());
//                staffStatistic1.setStaffId(statistic.getStaffId());
//                staffStatistic1.setStoreId(storeId);
//                staffStatistic1.setClassify("0");
//                List<StaffStatistic> staffStatistics = null;
//                 staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setRechargeyj(BigDecimal.valueOf(0));
//                statistic.setRechargeTC(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0){
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
//                            statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
//                        }
//                    }
//                }
//                staffStatistics = null;
//                staffStatistic1.setClassify("1");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
//                statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
//                statistic.setLcCardyj(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
//                            statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
//                            statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
//                        }
//                    }
//                }
//                staffStatistics = null;
//                staffStatistic1.setClassify("2");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setServeYJ(BigDecimal.valueOf(0));
//                statistic.setServeTC(BigDecimal.valueOf(0));
//                statistic.setSyxfyj(BigDecimal.valueOf(0));
//                statistic.setSyczkfyj(BigDecimal.valueOf(0));
//                statistic.setSylcxkyj(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
//                            statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
//                            //收银的现付总业绩
//                            statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
//                            statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
//                            statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
//                        }
//                    }
//                }
//
//                staffStatistics = null;
//                staffStatistic1.setClassify("4");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
//                statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
//                            statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
//                        }
//                    }
//                }
//                staffStatistics = null;
//                staffStatistic1.setClassify("5");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
//                statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
//                            statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
//                        }
//                    }
//                }
//                statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
//                statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));
//
//                staffStatistics = null;
//                staffStatistic1.setClassify("6");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
//                statistic.setCashierRefundTC(BigDecimal.valueOf(0));
//                statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
//                            statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
//                            statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
//                        }
//                    }
//                }
//                statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
//                statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
//                statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3)));
//
//                staffStatistics = null;
//                staffStatistic1.setClassify("7");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setLeafletYJ(BigDecimal.valueOf(0));
//                statistic.setLeafletTC(BigDecimal.valueOf(0));
//                statistic.setCashcxyj(BigDecimal.valueOf(0));
//                statistic.setCardcxyj(BigDecimal.valueOf(0));
//                statistic.setCashcxtc(BigDecimal.valueOf(0));
//                statistic.setCardcxtc(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
//                            statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
//                            statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
//                            statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
//                        }
//                    }
//                }
//
//                staffStatistics = null;
//                staffStatistic1.setClassify("8");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setJjzlcyj(BigDecimal.valueOf(0));
//                statistic.setJjzlctc(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
////                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
////                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(),BigDecimal.valueOf(0.00))));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(),staffStatistic2.getCardComm()),BigDecimal.valueOf(0.00))));
//                            statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
//                        }
//                    }
//                }
//
//                staffStatistics = null;
//                statistic.setNTMoney(BigDecimal.valueOf(0));
//                staffStatistic1.setClassify("3");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0){
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            if(null == staffStatistic2.getCzhkyj()){
//                                staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
//                            }
//                            if(null == staffStatistic2.getCzhktc()){
//                                staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
//                            }
//                            if(null == staffStatistic2.getLchkyj()){
//                                staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
//                            }
//                            if(null == staffStatistic2.getLchktc()){
//                                staffStatistic2.setLchktc(BigDecimal.valueOf(0));
//                            }
//                            if(null == staffStatistic2.getNTMoney()){
//                                staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
//                            }
//                            //充值开卡
//                            statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(),staffStatistic2.getCzhkyj()));
//                            statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(),staffStatistic2.getCzhktc()));
//                            //疗程开卡
//                            statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(),staffStatistic2.getLchkyj()));
//                            statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(),staffStatistic2.getLchktc()));
//                            //促销开卡
//                            if(staffStatistic2.getType()==2){
//                                statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(),staffStatistic2.getCashcxyj()));
//                                statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(),staffStatistic2.getCashcxtc()));
//                            }
//                            statistic.setNTMoney(statistic.getNTMoney().add(staffStatistic2.getNTMoney()));
//                        }
//                    }
//                }
//
//                staffStatistics = null;
//                staffStatistic1.setClassify("9");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
//                statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
//                            statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
//                        }
//                    }
//                }
//
//
//                staffStatistics = null;
//                staffStatistic1.setClassify("10");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
//                statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
////                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
////                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
//                            statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(),staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(),staffStatistic2.getGroupPurchaseComm()));
//                        }
//                    }
//                }
//                staffStatistics = null;
//                staffStatistic1.setClassify("11");
//                staffStatistics = ssmStoreStatisticService.achiCommListss(staffStatistic1);
//                BigDecimal decimal = BigDecimal.valueOf(0);
//                statistic.setFootMassageComm(decimal);
//                statistic.setFootMassageChia(decimal);
//                statistic.setCardFootMassageComm(decimal);
//                statistic.setCardFootMassageChia(decimal);
//                statistic.setMarketChia(decimal);
//                statistic.setMarketComm(decimal);
//                if(staffStatistics!=null){
//                    if(staffStatistics.size()>0) {
//                        for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
//                            statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
//                            statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
//                            statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
//                            statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
//                            statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
//                        }
//                    }
//                }
//
//                //根据甲方要求，退款的单据业绩不加进总业绩里面
//                statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
//                //退款业绩
//                statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
//                if(null == statistic.getSyxfyj()){
//                    statistic.setSyxfyj(BigDecimal.valueOf(0.00));
//                }
//                //总业绩
//                statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
//                //扣减后业绩
//                statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
//                statistic.setCooperationAchi(statistic.getCooperationAchi());
//                staffStatisticLists.add(statistic);
//            }
//        }
//        staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());
//
//        Map<Long, List<StaffStatistic>> resultMaps = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
//        //汇总后的集合
//        List<StaffStatistic> staffStatisticsLs= new ArrayList<>();
//        //计算每个分组员工的业绩
//        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList = resultMaps.entrySet().iterator();
//        while (entryIteratorsList.hasNext()) {
//            StaffStatistic staffStatistic1 = new StaffStatistic();
//
//            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList.next();
//            List<StaffStatistic> listByStaff = entry.getValue();
//            staffStatistic1.setStaffId(listByStaff.get(0).getStaffId());
//            staffStatistic1.setStaffName(listByStaff.get(0).getStaffName());
//            staffStatistic1.setBrandNumber(listByStaff.get(0).getBrandNumber());
//            staffStatistic1.setCooperationAchi(listByStaff.get(0).getCooperationAchi());
//            staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
//            staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
//            staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
//            staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
//            staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
//            staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
//            staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
//            staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
//            BigDecimal decimal = BigDecimal.valueOf(0);
//            staffStatistic1.setFootMassageComm(decimal);
//            staffStatistic1.setFootMassageChia(decimal);
//            staffStatistic1.setCardFootMassageComm(decimal);
//            staffStatistic1.setCardFootMassageChia(decimal);
//            staffStatistic1.setMarketChia(decimal);
//            staffStatistic1.setMarketComm(decimal);
//            for (StaffStatistic statistic : listByStaff) {
//                if(null == statistic.getRechargeyj()){
//                    statistic.setRechargeyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getCourseOfTreatmentYJ()){
//                    statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getLcCardyj()){
//                    statistic.setLcCardyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getSyxfyj()){
//                    statistic.setSyxfyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getSyczkfyj()){
//                    statistic.setSyczkfyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getSylcxkyj()){
//                    statistic.setSylcxkyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getTkyj()){
//                    statistic.setTkyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getKjhyj()){
//                    statistic.setKjhyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getXftlcczhjyj()){
//                    statistic.setXftlcczhjyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getTotalyj()){
//                    statistic.setTotalyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getTotaltc()){
//                    statistic.setTotaltc(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getZyj()){
//                    statistic.setZyj(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getRechargeTurnCourseChia()){
//                    statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getRechargeTurnCourseComm()){
//                    statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getGroupPurchaseChia()){
//                    statistic.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getGroupPurchaseComm()){
//                    statistic.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getFootMassageComm()){
//                    statistic.setFootMassageComm(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getFootMassageChia()){
//                    statistic.setFootMassageChia(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getCardFootMassageComm()){
//                    statistic.setCardFootMassageComm(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getCardFootMassageChia()){
//                    statistic.setCardFootMassageChia(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getMarketChia()){
//                    statistic.setMarketChia(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getMarketComm()){
//                    statistic.setMarketComm(BigDecimal.valueOf(0.00));
//                }
//                if(null == statistic.getNTMoney()){
//                    statistic.setNTMoney(BigDecimal.valueOf(0.00));
//                }
//                staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().add(statistic.getRechargeyj()));
//                staffStatistic1.setCourseOfTreatmentYJ(staffStatistic1.getCourseOfTreatmentYJ().add(statistic.getCourseOfTreatmentYJ()));
//                staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().add(statistic.getLcCardyj()));
//                staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().add(statistic.getSyxfyj()));
//                staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().add(statistic.getSyczkfyj()));
//                staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().add(statistic.getSylcxkyj()));
//                staffStatistic1.setTkyj(staffStatistic1.getTkyj().add(statistic.getTkyj()));
//                staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().add(statistic.getKjhyj()));
//                staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().add(statistic.getCardcxyj()));
//                staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().add(statistic.getCashcxyj()));
//                staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().add(statistic.getXftlcczhjyj()));
//                staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().add(statistic.getTotalyj()));
//                staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getTotaltc()));
//                staffStatistic1.setZyj(staffStatistic1.getZyj().add(statistic.getZyj()));
//                staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getRechargeTurnCourseChia()));
//                staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().add(statistic.getRechargeTurnCourseComm()));
//                staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().add(statistic.getGroupPurchaseChia()));
//                staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().add(statistic.getGroupPurchaseComm()));
//
//                staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().add(statistic.getFootMassageComm()));
//                staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().add(statistic.getFootMassageChia()));
//                staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().add(statistic.getCardFootMassageComm()));
//                staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().add(statistic.getCardFootMassageChia()));
//                staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().add(statistic.getMarketChia()));
//                staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().add(statistic.getMarketComm()));
//                staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().add(statistic.getNTMoney()));
//                staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi());
//            }
//
//            staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistic1.getCourseOfTreatmentYJ(),staffStatistic1.getCashcxyj()).setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setTkyj(staffStatistic1.getTkyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setZyj(staffStatistic1.getZyj().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().setScale(2,BigDecimal.ROUND_HALF_UP));
//
//
//            staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().setScale(2,BigDecimal.ROUND_HALF_UP));
//
//            BaseStaff baseStaff = new BaseStaff();
//            baseStaff.setId(staffStatistic1.getStaffId());
//            BaseStaff select = ssmBaseStaffService.selectOne(baseStaff);
//            staffStatistic1.setBaseSalary(BigDecimal.valueOf(0));
//            staffStatistic1.setTotalWages(BigDecimal.valueOf(0));
//            staffStatistic1.setBaseSalary(select.getBaseSalary());
//            String format = String.format("%.2f", staffStatistic1.getTotaltc());
//            staffStatistic1.setTotaltc(BigDecimal.valueOf(Double.valueOf(format)).setScale(2,BigDecimal.ROUND_HALF_UP));
//            staffStatistic1.setTotalWages(select.getBaseSalary().add(staffStatistic1.getTotaltc()));
//            staffStatisticsLs.add(staffStatistic1);
//        }
//
//
//        List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
//        List<AchiCommEntity> totalList1 = new ArrayList<>();
//        List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
//        List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
//        //合并list
//        cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
//        //按员工ID进行分组
//        Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//        //计算每个分组员工的业绩
//        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
//        while (entryIterator1.hasNext()) {
//            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
//            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
//            List<AchiCommEntity> listByStaff = entry.getValue();
//            //按天进行分组
//            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
//            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
//            while (iterator.hasNext()) {
//                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
//                List<AchiCommEntity> list = stringListEntry.getValue();
//
//                //业绩
//                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
///*
//                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
//                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
//                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
//                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
//
//                //总卡付业绩
//                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
//
//                //总卡付提成
//                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
//                StaffStatistic statistic = new StaffStatistic();
//                statistic.setStaffId(entry.getKey());
//                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
//                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
//                //按天查询用date
//
//                statistic.setDate(list.get(list.size()-1).getDocDate());
//                statistic.setAchievementAmount(CardAchi);
//                statistic.setCommissionAmount(CardComm);
//                statistic.setCardAchi(CardAchi);
//                statistic.setCardComm(CardComm);
//                statistic.setClassify(staffStatistic.getClassify());
//                statistic.setStoreId(staffStatistic.getStoreId());
//                statistic.setCooperationAchi(staffStatistic.getCooperationAchi());
//
//                staffStatisticList1.add(statistic);
//            }
//            //}
//        }
//
//        for (StaffStatistic statistic : staffStatisticList1) {
//            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
//            if (effectiveDate){
//                staffStatisticList2.add(statistic);
//            }
//        }
//        staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());
//
//        Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
//        //汇总后的集合
//
//        //计算每个分组员工的业绩
//        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();
//
//        List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
//        while (entryIteratorsList1.hasNext()) {
//            StaffStatistic staffStatistic1 = new StaffStatistic();
//
//            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
//            List<StaffStatistic> listByStaff = entry.getValue();
//            for (StaffStatistic statistic : listByStaff) {
//
//                staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
//                staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
//                staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
//                staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
//                staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
//                staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
//                staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
//                BigDecimal decimal = BigDecimal.valueOf(0);
//                staffStatistic1.setFootMassageComm(decimal);
//                staffStatistic1.setFootMassageChia(decimal);
//                staffStatistic1.setCardFootMassageComm(decimal);
//                staffStatistic1.setCardFootMassageChia(decimal);
//                staffStatistic1.setMarketChia(decimal);
//                staffStatistic1.setMarketComm(decimal);
//
//
//                staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setStaffId(statistic.getStaffId());
//                staffStatistic1.setStaffName(statistic.getStaffName());
//                staffStatistic1.setBrandNumber(statistic.getBrandNumber());
//                staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
//                staffStatisticsLs1.add(staffStatistic1);
//            }
//
//        }
//        for (StaffStatistic staffStatistics : staffStatisticsLs) {
//            for (StaffStatistic statistic : staffStatisticsLs1) {
//                if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
//                    staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
//                    staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getCourseOfTreatmentYJ()));
//                    staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getCourseOfTreatmentYJ()));
//                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
//                    staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
//                }
//            }
//        }
//        List<Long> longs = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
//        List<StaffStatistic> collect = staffStatisticsLs1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());
//
//        for (StaffStatistic statistic : collect) {
//            staffStatisticsLs.add(statistic);
//        }
//
//
//
//        //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
//        List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
//        List<AchiCommEntity> totalList2 = new ArrayList<>();
//        List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
//        List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
//        //合并list
//        coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
//        //按员工ID进行分组
//        Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//        //计算每个分组员工的业绩
//        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
//        while (entryIterator2.hasNext()) {
//            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
//            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
//            List<AchiCommEntity> listByStaff = entry.getValue();
//            //按天进行分组
//            Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
//            Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
//            while (iterator.hasNext()) {
//                Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
//                List<AchiCommEntity> list = stringListEntry.getValue();
//
//                //业绩
//                //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
//
///*
//
//                //总卡付提成
//                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
//                StaffStatistic statistic = new StaffStatistic();
//                statistic.setStaffId(entry.getKey());
//                statistic.setStaffName(list.get(list.size()-1).getSaleStaffName());
//                statistic.setBrandNumber(list.get(list.size()-1).getBrandNumber());
//                //按天查询用date
//
//                statistic.setDate(list.get(list.size()-1).getDocDate());
//                statistic.setAchievementAmount(CardAchi);
//                statistic.setCommissionAmount(CardComm);
//                statistic.setCardAchi(CardAchi);
//                statistic.setCardComm(CardComm);
//                statistic.setClassify(staffStatistic.getClassify());
//                statistic.setStoreId(staffStatistic.getStoreId());
//                statistic.setCooperationAchi(staffStatistic.getCooperationAchi());
//
//                staffStatisticList3.add(statistic);
//            }
//            //}
//        }
//
//        for (StaffStatistic statistic : staffStatisticList3) {
//            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
//            if (effectiveDate){
//                staffStatisticList4.add(statistic);
//            }
//        }
//        staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());
//
//        Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
//        //汇总后的集合
//
//        //计算每个分组员工的业绩
//        Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();
//
//        List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();
//        while (entryIteratorsList2.hasNext()) {
//            StaffStatistic staffStatistic1 = new StaffStatistic();
//
//            Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
//            List<StaffStatistic> listByStaff = entry.getValue();
//            for (StaffStatistic statistic : listByStaff) {
//
//                staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
//                staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
//                staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
//                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
//                staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
//                staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
//                staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
//                staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
//                BigDecimal decimal = BigDecimal.valueOf(0);
//                staffStatistic1.setFootMassageComm(decimal);
//                staffStatistic1.setFootMassageChia(decimal);
//                staffStatistic1.setCardFootMassageComm(decimal);
//                staffStatistic1.setCardFootMassageChia(decimal);
//                staffStatistic1.setMarketChia(decimal);
//                staffStatistic1.setMarketComm(decimal);
//
//                staffStatistic1.setStaffId(statistic.getStaffId());
//                //staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setStaffId(statistic.getStaffId());
//                staffStatistic1.setStaffName(statistic.getStaffName());
//                staffStatistic1.setBrandNumber(statistic.getBrandNumber());
//                //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setRechargeTurnCourseChia(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setZyj(BigDecimalUtils.bigDecimal("0"));
//                staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
//                staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
//                staffStatisticsLs2.add(staffStatistic1);
//            }
//
//        }
//        for (StaffStatistic staffStatistics : staffStatisticsLs) {
//            for (StaffStatistic statistic : staffStatisticsLs2) {
//                if (staffStatistics.getStaffId().equals(statistic.getStaffId())){
//                    //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
//                    staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(),statistic.getRechargeTurnCourseChia()));
//                    //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
//                    //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
//                    staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(),statistic.getTotaltc()));
//                    staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(),statistic.getTotaltc()));
//                }
//            }
//        }
//        List<Long> longs1 = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
//        List<StaffStatistic> collect1 = staffStatisticsLs2.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());
//
//        for (StaffStatistic statistic : collect1) {
//            staffStatisticsLs.add(statistic);
//        }
//
//
//
//
//        return staffStatisticsLs;
//    }

    @Override
    public List<StaffStatistic> departmentPerformance(StaffStatistic staffStatistic) throws ParseException, SmsException {

        List<StaffStatistic> staffStatisticListss = new ArrayList<>();
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(staffStatistic.getStoreId());
        if(baseStore.getParentId()==null){
            BaseStore baseStore1 = new BaseStore();
            baseStore1.setParentId(baseStore.getId());
            List<BaseStore> select = ssmBaseStoreService.select(baseStore1);
            Collections.sort(select,new StrComparatorUtils<>("storeNum",false));
            for (BaseStore store : select) {
                staffStatistic.setStoreId(store.getId());
                List<StaffStatistic> staffStatisticList = new ArrayList<>();
                List<StaffStatistic> staffStatisticLists = new ArrayList<>();
                BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
                BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
                //根据时间类别转换时间
                //int type = staffStatistic.getType();
                String dateStr = staffStatistic.getStartDate().substring(0, 7);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = dateFormat.parse(staffStatistic.getStartDate());
//                Date date = new Date();
                Long storeId = staffStatistic.getStoreId();
                List<RechargeListResponse> recList = new ArrayList<>();
                List<CourseListResponse> courseList = new ArrayList<>();
                List<CashListResponse> cashList = new ArrayList<>();
                List<RepayTradeResponse> RepayLists = new ArrayList<>();
                List<RefundRechargeResponse> refundRecList = new ArrayList<>();
                List<RefundCourseResponse> refundCourseList = new ArrayList<>();
                List<CashListResponse> refundCashList = new ArrayList<>();
                List<DocPromotionResponse> promotionList = new ArrayList<>();
                List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
                List<CardChangeOutProjectResponse> cardOutList = new ArrayList<>();
                List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

                if (null == staffStatistic.getClassify()) {
                    recList = ssmRechargeService.selectList(storeId, dateStr, date);
                    courseList = ssmCourseService.selectList(storeId, dateStr, date);
                    cashList = ssmCashService.selectList(storeId, dateStr, date);
                    RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                    refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                    refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                    //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                    refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
                    promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                    //加价转疗程
                    cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            cardOutList = ssmCardChangeOutProjectService.selectListByStoreAndDate(storeId,dateStr);
                    //查询团购卡
                    baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

                }
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    for (AchiCommEntity entity : cardChangeList.getEntities()) {
                        entity.setChangeInPayMoney(cardChangeList.getChangeInPayMoney());
                        entity.setChangeOutMoney(cardChangeList.getChangeOutMoney());
                    }
                }

                List<AchiCommEntity> totalList = new ArrayList<>();
                //合并list
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    cardChangeList.getOutProjects().
                            forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                                    .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                }
                recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//                System.out.println(JSON.toJSONString(totalList));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
                while (entryIterator.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();
                        //充值 + 充值还款 业绩
                        BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 业绩
                        BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程 + 疗程还款 业绩
                        BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //加价转疗程 业绩
                        BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeInPayMoney()==null?BigDecimal.valueOf(0):item.getChangeInPayMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeOutMoney()==null?BigDecimal.valueOf(0):item.getChangeOutMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 业绩
                        BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 业绩
                        BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                        //消费退 业绩
                        BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //还款业绩
                        BigDecimal repayAchi = BigDecimal.valueOf(0);// list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销业绩
                        BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //充值  提成
                        BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 提成
                        BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程  提成
                        BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 提成
                        BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 提成
                        BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //消费退 提成
                        BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //还款提成
                        BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销提成
                        BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cooperationAomount = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO,BigDecimal::add);
                        //加价转疗程提成
                        BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程转充值
                        BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayMoney = list.stream().filter(item->item.getType().equals("card_repay")).map(x->x.getCashAchi().add(x.getCooperationAchi())).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //团购卡业绩
                        BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //团购卡提成
                        BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //还款合作方业绩
                        BigDecimal HKcooperateAmount = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(item->item.getCooperationAchi()==null?BigDecimal.valueOf(0):item.getCooperationAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);

                        achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(
                                        BigDecimalUtils.add(
                                                recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(courseChangeAchi);
                        commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                        //总现付业绩
                        BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                        //总卡付业绩
                        BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                        //总现付提成
                        BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                        //总卡付提成
                        BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm),promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                        //合作卡付
                        BigDecimal totalCardCoopAchi = list.stream().map(item->item.getCardCoopAchi()==null?BigDecimal.valueOf(0):item.getCardCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                        //合作现付
                        BigDecimal totalCashCoopAchi = list.stream().map(item->item.getCashCoopAchi()==null?BigDecimal.valueOf(0):item.getCashCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(0).getSaleStaffName());
                        statistic.setBrandNumber(list.get(0).getBrandNumber());
                        //按天查询用date
                        statistic.setAllAmount(courseChangeCashAchi);
                        statistic.setCooperationCardAmount(totalCardCoopAchi);
                        statistic.setCooperationAchi(totalCashCoopAchi);
                        statistic.setDate(list.get(0).getDocDate());
                        statistic.setAchievementAmount(achievementAmount);
                        statistic.setCommissionAmount(commissionAmount);
                        statistic.setCashAchi(totalCashAchi);
                        statistic.setCardAchi(totalCardAchi);
                        statistic.setCashComm(totalCashComm);
                        statistic.setCardComm(totalCardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setCashAmount(BigDecimal.valueOf(0));
                        statistic.setCardAmount(BigDecimal.valueOf(0));
//                    statistic.setCourseRepay(repayMoney);
//                    statistic.setAllAmount(cashAchi.add(cashCardAchi));
                        statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                        statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                        //疗程总共金额
//                    statistic.setAllAmount(list.stream().map(item->item.getMoney()).reduce(BigDecimal.ZERO,BigDecimal::add));
                        //现付总金额
                        for (AchiCommEntity achiCommEntity : list) {
                            for (CourseListResponse courseListResponse : courseList) {
                                if(achiCommEntity.getDocId()==courseListResponse.getId()){
                                    //todo
                                    for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                        if(statistic.getStaffId().equals(entity.getSaleStaffId())){
                                            statistic.setCashAmount(statistic.getCashAmount()
//                                                .add(courseListResponse.getCollectionCashAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                    .setScale(10,BigDecimal.ROUND_HALF_UP));
                                            statistic.setCardAmount(statistic.getCardAmount()
//                                                .add(courseListResponse.getCollectionRechargeAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                    .setScale(10,BigDecimal.ROUND_HALF_UP));
                                        }
                                    }
//                                statistic.setCooperationCardAmount();
//                                statistic.setCooperateAmount();
                                }
                            }
                        }
                        //卡付总金额
                        statistic.setHkCooperationAmount(HKcooperateAmount);
                        statistic.setCooperateAmount(cooperationAomount);
                        if(statistic.getHkCooperationAmount()==null){
                            statistic.setHkCooperationAmount(BigDecimal.ZERO);
                        }
                        staffStatisticList.add(statistic);
                    }
                    //}
                }
//                System.out.println(JSON.toJSONString(staffStatisticList));
                for (StaffStatistic statistic : staffStatisticList) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if(effectiveDate){
                        //查询充值业务员信息
                        StaffStatistic staffStatistic1 = new StaffStatistic();
                        staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                        staffStatistic1.setDate(statistic.getDate());
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStoreId(storeId);
                        List<StaffStatistic> staffStatistics = null;
                        staffStatistics = this.achiCommListsss1(staffStatistic1);
//                 staffStatistics = ssmStoreStatisticService.achiCommListsss(staffStatistic1);
                        statistic.setRecharge(BigDecimal.valueOf(0));
                        statistic.setRechargecar(BigDecimal.valueOf(0));
                        statistic.setCourseCard(BigDecimal.valueOf(0));
                        statistic.setCourseCash(BigDecimal.valueOf(0));
                        statistic.setCourseTotal(BigDecimal.valueOf(0));

                        statistic.setCourse(BigDecimal.valueOf(0));
                        statistic.setCourseSum(BigDecimal.valueOf(0));
                        statistic.setCourseRepay(BigDecimal.valueOf(0));

                        statistic.setCoursePromotionCard(BigDecimal.valueOf(0));
                        statistic.setCoursePromotionCash(BigDecimal.valueOf(0));
                        statistic.setCoursePromotionTotal(BigDecimal.valueOf(0));
                        statistic.setCashierCard(BigDecimal.valueOf(0));
                        statistic.setCashierCash(BigDecimal.valueOf(0));
                        statistic.setCashierRecharge(BigDecimal.valueOf(0));
                        statistic.setCashierTotal(BigDecimal.valueOf(0));
                        statistic.setRepaymentCourse(BigDecimal.valueOf(0));
                        statistic.setRepaymentRecharge(BigDecimal.valueOf(0));
                        statistic.setRepaymentTotal(BigDecimal.valueOf(0));
                        statistic.setRefundTotal(BigDecimal.valueOf(0));
                        statistic.setRefundCourse(BigDecimal.valueOf(0));
                        statistic.setRefundRechagre(BigDecimal.valueOf(0));
                        statistic.setRefundCash(BigDecimal.valueOf(0));
                        statistic.setJjzlcCard(BigDecimal.valueOf(0));
                        statistic.setJjzlcCash(BigDecimal.valueOf(0));
//                statistic.setCashAchi(BigDecimal.valueOf(0));
//                statistic.setCashAmount();
                        if(staffStatistics!=null){
                            if(staffStatistics.size()>0){
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setRecharge(statistic.getRecharge()
                                            .add(staffStatistic2.getRecharge())
                                    );
                                    statistic.setRechargecar(statistic.getRechargecar()
                                            .add(staffStatistic2.getRechargecar())
                                    );
//                            statistic.setCashAchi(staffStatistic.getCashAchi().add(staffStatistic2.getCashAchi()));
                                    statistic.setCourseCard(statistic.getCourseCard().add(staffStatistic2.getCourseCard()));
                                    statistic.setCourseCash(statistic.getCourseCash().add(staffStatistic2.getCourseCash()));
                                    statistic.setCourseTotal(statistic.getCourseTotal().add(staffStatistic2.getCourseTotal())
//                                    .add(statistic.getCashAchi()
//                                            .add(statistic.getCardAchi())
//                            )
                                    );
                                    statistic.setCoursePromotionCard(statistic.getCoursePromotionCard().add(staffStatistic2.getCoursePromotionCard()));
                                    statistic.setCoursePromotionCash(statistic.getCoursePromotionCash().add(staffStatistic2.getCoursePromotionCash()));
                                    statistic.setCoursePromotionTotal(statistic.getCoursePromotionTotal().add(staffStatistic2.getCoursePromotionTotal()));
                                    statistic.setCashierCard(statistic.getCashierCard().add(staffStatistic2.getCashierCard()));
                                    statistic.setCashierCash(statistic.getCashierCash().add(staffStatistic2.getCashierCash()));
                                    statistic.setCashierRecharge(statistic.getCashierRecharge().add(staffStatistic2.getCashierRecharge()));
                                    statistic.setCashierTotal(statistic.getCashierTotal().add(staffStatistic2.getCashierTotal()));
                                    statistic.setRepaymentCourse(statistic.getRepaymentCourse().add(staffStatistic2.getRepaymentCourse()));
                                    statistic.setRepaymentRecharge(statistic.getRepaymentRecharge().add(staffStatistic2.getRepaymentRecharge()));
                                    statistic.setRepaymentTotal(statistic.getRepaymentTotal().add(staffStatistic2.getRepaymentTotal()));
                                    statistic.setRefundTotal(statistic.getRefundTotal().add(staffStatistic2.getRefundTotal()));
                                    statistic.setRefundCourse(statistic.getRefundCourse().add(staffStatistic2.getRefundCourse()));
                                    statistic.setRefundRechagre(statistic.getRefundRechagre().add(staffStatistic2.getRefundRechagre()));
                                    statistic.setRefundCash(statistic.getRefundCash().add(staffStatistic2.getRefundCash()));
                                    statistic.setJjzlcCard(statistic.getJjzlcCard().add(staffStatistic2.getJjzlcCard()));
                                    statistic.setJjzlcCash(statistic.getJjzlcCash().add(staffStatistic2.getJjzlcCash()));
                                    //todo
                                    statistic.setCourse(statistic.getCourse().add(
                                                    //todo 加价转疗程的卡付是否算业绩
                                                    staffStatistic2.getJjzlcCard().add(
                                                            staffStatistic2.getJjzlcCash()
                                                                    .add(staffStatistic2.getCourseTotal()
                                                                            .add(staffStatistic2.getCoursePromotionTotal())))
                                            )
//                                    .add(statistic.getAllAmount())
                                    );
                                    statistic.setCourseRepay(statistic.getCourseRepay().add(staffStatistic2.getCourseRepay()));
                                    //todo
//                            statistic.setCashAmount();

                                }
                            }
                        }
                        BaseStaff baseStaff = new BaseStaff();
                        statistic.setCourseSum(statistic.getCourseSum().add(statistic.getCourseRepay().add(statistic.getCourse()))
//                                    .add(BigDecimal.valueOf(2))
                        );
                        baseStaff.setId(statistic.getStaffId());

                        BaseStaff baseStaff1 = ssmBaseStaffService.selectByPrimaryKey(baseStaff.getId());
                        //todo 空指针
                        if(baseStaff1!=null) {
                            statistic.setDeptName(baseStaff1.getDeptName());
                        }
                        staffStatisticLists.add(statistic);
                    }
                }
//        Map<Integer, List<StaffStatistic>> resultMapDept = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getDeptName));
//                System.out.println(JSON.toJSONString(staffStatisticLists));
                Map<Integer, List<StaffStatistic>> resultMapDept;
                final String[] message = {""};
                try{
                    resultMapDept = staffStatisticLists.stream().filter(item->item!=null).collect(Collectors.groupingBy(
                            item->{
                                if (item.getDeptName()==null){
                                    item.setDeptName(2);
                                    message[0] = item.getStaffName();
                                }return item.getDeptName();
                            }));
                }catch (NullPointerException e){
                    throw new SmsException(ResponseCode.MSG,"员工【"+message[0]+"】没有部门");
                }

                if(resultMapDept.get(0)==null){
                    resultMapDept.put(0,null);
                }
                if(resultMapDept.get(1)==null){
                    resultMapDept.put(1,null);
                }
                if(resultMapDept.get(2)==null){
                    resultMapDept.put(2,null);
                }
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Integer, List<StaffStatistic>>> entryIteratorDept = resultMapDept.entrySet().iterator();
                while (entryIteratorDept.hasNext()) {
                    Map.Entry<Integer, List<StaffStatistic>> entry = entryIteratorDept.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    if (entry.getKey() == 0) {
                        staffStatistic1.setDeptNames(store.getStoreNum() + "-美发部");
                    } else if (entry.getKey() == 1) {
                        staffStatistic1.setDeptNames(store.getStoreNum() + "-美容部");
                    } else if (entry.getKey() == 2) {
                        staffStatistic1.setDeptNames(store.getStoreNum() + "-其他部");
                    }
                    staffStatistic1.setDeptName(entry.getKey());
                    staffStatistic1.setRecharge(BigDecimal.valueOf(0));
                    staffStatistic1.setRechargecar(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseCard(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseCash(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setCoursePromotionCard(BigDecimal.valueOf(0));
                    staffStatistic1.setCoursePromotionCash(BigDecimal.valueOf(0));
                    staffStatistic1.setCoursePromotionTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierCard(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierCash(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierRecharge(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setRepaymentCourse(BigDecimal.valueOf(0));
                    staffStatistic1.setRepaymentRecharge(BigDecimal.valueOf(0));
                    staffStatistic1.setRepaymentTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundCourse(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundCash(BigDecimal.valueOf(0));
                    staffStatistic1.setJjzlcCard(BigDecimal.valueOf(0));
                    staffStatistic1.setJjzlcCash(BigDecimal.valueOf(0));

                    staffStatistic1.setCourse(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseSum(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseRepay(BigDecimal.valueOf(0));
                    staffStatistic1.setCardAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setAllAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCashAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCooperationCardAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCooperationAchi(BigDecimal.valueOf(0));
                    staffStatistic1.setCooperateAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setHkCooperationAmount(BigDecimal.valueOf(0));
                    if (listByStaff != null && listByStaff.size() > 0) {


                        for (StaffStatistic statistic : listByStaff) {
                            staffStatistic1.setRecharge(staffStatistic1.getRecharge().add(statistic.getRecharge()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setRechargecar(staffStatistic1.getRechargecar().add(statistic.getRechargecar()));
                            staffStatistic1.setCourseCard(staffStatistic1.getCourseCard().add(statistic.getCourseCard()));
                            staffStatistic1.setCourseCash(staffStatistic1.getCourseCash().add(statistic.getCourseCash()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCourseTotal(staffStatistic1.getCourseTotal().add(statistic.getCourseTotal()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCoursePromotionCard(staffStatistic1.getCoursePromotionCard().add(statistic.getCoursePromotionCard()));
                            staffStatistic1.setCoursePromotionCash(staffStatistic1.getCoursePromotionCash().add(statistic.getCoursePromotionCash()));
                            staffStatistic1.setCoursePromotionTotal(staffStatistic1.getCoursePromotionTotal().add(statistic.getCoursePromotionTotal()));
                            staffStatistic1.setCashierCard(staffStatistic1.getCashierCard().add(statistic.getCashierCard()));
                            staffStatistic1.setCashierCash(staffStatistic1.getCashierCash().add(statistic.getCashierCash()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCashierRecharge(staffStatistic1.getCashierRecharge().add(statistic.getCashierRecharge()));
                            staffStatistic1.setCashierTotal(staffStatistic1.getCashierTotal().add(statistic.getCashierTotal()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setRepaymentCourse(staffStatistic1.getRepaymentCourse().add(statistic.getRepaymentCourse()));
                            staffStatistic1.setRepaymentRecharge(staffStatistic1.getRepaymentRecharge().add(statistic.getRepaymentRecharge()));
                            staffStatistic1.setRepaymentTotal(staffStatistic1.getRepaymentTotal().add(statistic.getRepaymentTotal()));
                            staffStatistic1.setRefundTotal(staffStatistic1.getRefundTotal().add(statistic.getRefundTotal()));
                            staffStatistic1.setRefundCourse(staffStatistic1.getRefundCourse().add(statistic.getRefundCourse()));
                            staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().add(statistic.getRefundRechagre()));
                            staffStatistic1.setRefundCash(staffStatistic1.getRefundCash().add(statistic.getRefundCash()));
                            staffStatistic1.setJjzlcCard(staffStatistic1.getJjzlcCard().add(statistic.getJjzlcCard()));
                            staffStatistic1.setJjzlcCash(staffStatistic1.getJjzlcCash().add(statistic.getJjzlcCash()));
                            staffStatistic1.setCourse(staffStatistic1.getCourse().add(statistic.getCourse()).setScale(3, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().add(statistic.getCourseRepay()));
                            staffStatistic1.setCourseSum(staffStatistic1.getCourseSum().add(statistic.getCourseSum()).setScale(3, BigDecimal.ROUND_HALF_UP));
                            //
                            staffStatistic1.setHkCooperationAmount((statistic.getHkCooperationAmount() == null ? BigDecimal.valueOf(0) : statistic.getHkCooperationAmount()).add(staffStatistic1.getHkCooperationAmount() == null ? BigDecimal.valueOf(0) : staffStatistic1.getHkCooperationAmount()));
                            //
                            staffStatistic1.setCardAmount(staffStatistic1.getCardAmount().add(statistic.getCardAmount()));
//                staffStatistic1.setAllAmount(statistic.getAllAmount());
                            staffStatistic1.setCashAmount(staffStatistic1.getCashAmount().add(statistic.getCashAmount()));
                            staffStatistic1.setCooperateAmount(staffStatistic1.getCooperateAmount().add(statistic.getCooperateAmount() == null ? BigDecimal.valueOf(0) : statistic.getCooperateAmount())
//                        .add(statistic.getCashAmount()
//                                .subtract(statistic.getCourseCash()))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));//合作现付业绩
                            staffStatistic1.setCooperationCardAmount(staffStatistic1.getCooperationCardAmount().add(statistic.getCooperationCardAmount()));//合作现付业绩
                            staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().add(statistic.getCooperationAchi()));
                        }
                    }

//            staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).add(staffStatistic1.getRepaymentTotal()));
                    staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseYj(staffStatistic1.getCourseTotal().add(staffStatistic1.getRepaymentCourse()).add(staffStatistic1.getJjzlcCash()).add(staffStatistic1.getCoursePromotionTotal()).subtract(staffStatistic1.getRefundCourse()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCashYj(staffStatistic1.getCashierTotal().subtract(staffStatistic1.getRefundCash()).setScale(2, BigDecimal.ROUND_HALF_UP));

                    staffStatistic1.setRefundTotal(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundTotal()));
                    staffStatistic1.setRefundCourse(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCourse()));
                    staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundRechagre()));
                    staffStatistic1.setRefundCash(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCash()));
                    //扣减业绩
                    staffStatistic1.setCourse(staffStatistic1.getCourse().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay());
                    staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().negate());
//            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().subtract(staffStatistic1.getHkCooperationAmount()));
                    staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().subtract(staffStatistic1.getHkCooperationAmount()));
                    staffStatistic1.setCourseSum(staffStatistic1.getCourse().add(staffStatistic1.getCooperationAchi()
                            .add(staffStatistic1.getCourseRepay().add(staffStatistic1.getHkCooperationAmount()))
                    ));

                    staffStatisticListss.add(staffStatistic1);

                }
                }
        }
        else {
            List<StaffStatistic> staffStatisticList = new ArrayList<>();
            List<StaffStatistic> staffStatisticLists = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date = dateFormat.parse(staffStatistic.getStartDate());
        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<CardChangeOutProjectResponse> cardOutList = new ArrayList<>();
        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            cardOutList = ssmCardChangeOutProjectService.selectListByStoreAndDate(storeId,dateStr);
            //查询团购卡
            baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

        }
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            for (AchiCommEntity entity : cardChangeList.getEntities()) {
                entity.setChangeInPayMoney(cardChangeList.getChangeInPayMoney());
                entity.setChangeOutMoney(cardChangeList.getChangeOutMoney());
            }
        }

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                cardChangeList.getOutProjects().
                        forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                                .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        }
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//        System.out.println(JSON.toJSONString(totalList));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeInPayMoney()==null?BigDecimal.valueOf(0):item.getChangeInPayMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeOutMoney()==null?BigDecimal.valueOf(0):item.getChangeOutMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = BigDecimal.valueOf(0);// list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cooperationAomount = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO,BigDecimal::add);
                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayMoney = list.stream().filter(item->item.getType().equals("card_repay")).map(x->x.getCashAchi().add(x.getCooperationAchi())).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款合作方业绩
                    BigDecimal HKcooperateAmount = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(item->item.getCooperationAchi()==null?BigDecimal.valueOf(0):item.getCooperationAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);

                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(
                                    BigDecimalUtils.add(
                                            recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(courseChangeAchi);
                    commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm),promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                    //合作卡付
                    BigDecimal totalCardCoopAchi = list.stream().map(item->item.getCardCoopAchi()==null?BigDecimal.valueOf(0):item.getCardCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                    //合作现付
                    BigDecimal totalCashCoopAchi = list.stream().map(item->item.getCashCoopAchi()==null?BigDecimal.valueOf(0):item.getCashCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(0).getSaleStaffName());
                    statistic.setBrandNumber(list.get(0).getBrandNumber());
                    //按天查询用date
                    statistic.setAllAmount(courseChangeCashAchi);
                    statistic.setCooperationCardAmount(totalCardCoopAchi);
                    statistic.setCooperationAchi(totalCashCoopAchi);
                    statistic.setDate(list.get(0).getDocDate());
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCashAmount(BigDecimal.valueOf(0));
                    statistic.setCardAmount(BigDecimal.valueOf(0));
//                    statistic.setCourseRepay(repayMoney);
//                    statistic.setAllAmount(cashAchi.add(cashCardAchi));
                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                    //疗程总共金额
//                    statistic.setAllAmount(list.stream().map(item->item.getMoney()).reduce(BigDecimal.ZERO,BigDecimal::add));
                    //现付总金额
                    for (AchiCommEntity achiCommEntity : list) {
                        for (CourseListResponse courseListResponse : courseList) {
                            if(achiCommEntity.getDocId()==courseListResponse.getId()){
                                //todo
                                for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                    if(statistic.getStaffId().equals(entity.getSaleStaffId())){
                                        statistic.setCashAmount(statistic.getCashAmount()
//                                                .add(courseListResponse.getCollectionCashAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                .setScale(10,BigDecimal.ROUND_HALF_UP));
                                        statistic.setCardAmount(statistic.getCardAmount()
//                                                .add(courseListResponse.getCollectionRechargeAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                .setScale(10,BigDecimal.ROUND_HALF_UP));
                                    }
                                }
//                                statistic.setCooperationCardAmount();
//                                statistic.setCooperateAmount();
                            }
                        }
                    }
                    //卡付总金额
                    statistic.setHkCooperationAmount(HKcooperateAmount);
                    statistic.setCooperateAmount(cooperationAomount);
                    if(statistic.getHkCooperationAmount()==null){
                        statistic.setHkCooperationAmount(BigDecimal.ZERO);
                    }
                    staffStatisticList.add(statistic);
                }
            //}
        }
//        System.out.println(JSON.toJSONString(staffStatisticList));
        for (StaffStatistic statistic : staffStatisticList) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if(effectiveDate){
                //查询充值业务员信息
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                staffStatistic1.setDate(statistic.getDate());
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setStoreId(storeId);
                List<StaffStatistic> staffStatistics = null;
                 staffStatistics = this.achiCommListsss1(staffStatistic1);
//                 staffStatistics = ssmStoreStatisticService.achiCommListsss(staffStatistic1);
                statistic.setRecharge(BigDecimal.valueOf(0));
                statistic.setRechargecar(BigDecimal.valueOf(0));
                statistic.setCourseCard(BigDecimal.valueOf(0));
                statistic.setCourseCash(BigDecimal.valueOf(0));
                statistic.setCourseTotal(BigDecimal.valueOf(0));

                statistic.setCourse(BigDecimal.valueOf(0));
                statistic.setCourseSum(BigDecimal.valueOf(0));
                statistic.setCourseRepay(BigDecimal.valueOf(0));

                statistic.setCoursePromotionCard(BigDecimal.valueOf(0));
                statistic.setCoursePromotionCash(BigDecimal.valueOf(0));
                statistic.setCoursePromotionTotal(BigDecimal.valueOf(0));
                statistic.setCashierCard(BigDecimal.valueOf(0));
                statistic.setCashierCash(BigDecimal.valueOf(0));
                statistic.setCashierRecharge(BigDecimal.valueOf(0));
                statistic.setCashierTotal(BigDecimal.valueOf(0));
                statistic.setRepaymentCourse(BigDecimal.valueOf(0));
                statistic.setRepaymentRecharge(BigDecimal.valueOf(0));
                statistic.setRepaymentTotal(BigDecimal.valueOf(0));
                statistic.setRefundTotal(BigDecimal.valueOf(0));
                statistic.setRefundCourse(BigDecimal.valueOf(0));
                statistic.setRefundRechagre(BigDecimal.valueOf(0));
                statistic.setRefundCash(BigDecimal.valueOf(0));
                statistic.setJjzlcCard(BigDecimal.valueOf(0));
                statistic.setJjzlcCash(BigDecimal.valueOf(0));
//                statistic.setCashAchi(BigDecimal.valueOf(0));
//                statistic.setCashAmount();
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0){
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setRecharge(statistic.getRecharge()
                                    .add(staffStatistic2.getRecharge())
                            );
                            statistic.setRechargecar(statistic.getRechargecar()
                                    .add(staffStatistic2.getRechargecar())
                            );
//                            statistic.setCashAchi(staffStatistic.getCashAchi().add(staffStatistic2.getCashAchi()));
                            statistic.setCourseCard(statistic.getCourseCard().add(staffStatistic2.getCourseCard()));
                            statistic.setCourseCash(statistic.getCourseCash().add(staffStatistic2.getCourseCash()));
                            statistic.setCourseTotal(statistic.getCourseTotal().add(staffStatistic2.getCourseTotal())
//                                    .add(statistic.getCashAchi()
//                                            .add(statistic.getCardAchi())
//                            )
                            );
                            statistic.setCoursePromotionCard(statistic.getCoursePromotionCard().add(staffStatistic2.getCoursePromotionCard()));
                            statistic.setCoursePromotionCash(statistic.getCoursePromotionCash().add(staffStatistic2.getCoursePromotionCash()));
                            statistic.setCoursePromotionTotal(statistic.getCoursePromotionTotal().add(staffStatistic2.getCoursePromotionTotal()));
                            statistic.setCashierCard(statistic.getCashierCard().add(staffStatistic2.getCashierCard()));
                            statistic.setCashierCash(statistic.getCashierCash().add(staffStatistic2.getCashierCash()));
                            statistic.setCashierRecharge(statistic.getCashierRecharge().add(staffStatistic2.getCashierRecharge()));
                            statistic.setCashierTotal(statistic.getCashierTotal().add(staffStatistic2.getCashierTotal()));
                            statistic.setRepaymentCourse(statistic.getRepaymentCourse().add(staffStatistic2.getRepaymentCourse()));
                            statistic.setRepaymentRecharge(statistic.getRepaymentRecharge().add(staffStatistic2.getRepaymentRecharge()));
                            statistic.setRepaymentTotal(statistic.getRepaymentTotal().add(staffStatistic2.getRepaymentTotal()));
                            statistic.setRefundTotal(statistic.getRefundTotal().add(staffStatistic2.getRefundTotal()));
                            statistic.setRefundCourse(statistic.getRefundCourse().add(staffStatistic2.getRefundCourse()));
                            statistic.setRefundRechagre(statistic.getRefundRechagre().add(staffStatistic2.getRefundRechagre()));
                            statistic.setRefundCash(statistic.getRefundCash().add(staffStatistic2.getRefundCash()));
                            statistic.setJjzlcCard(statistic.getJjzlcCard().add(staffStatistic2.getJjzlcCard()));
                            statistic.setJjzlcCash(statistic.getJjzlcCash().add(staffStatistic2.getJjzlcCash()));
                            //todo
                            statistic.setCourse(statistic.getCourse().add(
                                    //todo 加价转疗程的卡付是否算业绩
                                            staffStatistic2.getJjzlcCard().add(
                                                    staffStatistic2.getJjzlcCash()
                                                    .add(staffStatistic2.getCourseTotal()
                                                            .add(staffStatistic2.getCoursePromotionTotal())))
                                    )
//                                    .add(statistic.getAllAmount())
                            );
                            statistic.setCourseRepay(statistic.getCourseRepay().add(staffStatistic2.getCourseRepay()));
                            //todo
//                            statistic.setCashAmount();

                        }
                    }
                }
                BaseStaff baseStaff = new BaseStaff();
                statistic.setCourseSum(statistic.getCourseSum().add(statistic.getCourseRepay().add(statistic.getCourse()))
//                                    .add(BigDecimal.valueOf(2))
                );
                baseStaff.setId(statistic.getStaffId());

                BaseStaff baseStaff1 = ssmBaseStaffService.selectByPrimaryKey(baseStaff.getId());
                //todo 空指针
                if(baseStaff1!=null) {
                    statistic.setDeptName(baseStaff1.getDeptName());
                }
                staffStatisticLists.add(statistic);
            }
        }
//        Map<Integer, List<StaffStatistic>> resultMapDept = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getDeptName));
//        System.out.println(JSON.toJSONString(staffStatisticLists));
        Map<Integer, List<StaffStatistic>> resultMapDept;
        final String[] message = {""};
        try{
            resultMapDept = staffStatisticLists.stream().filter(item->item!=null).collect(Collectors.groupingBy(
                    item->{
                        if (item.getDeptName()==null){
                            item.setDeptName(2);
                        message[0] = item.getStaffName();
                    }return item.getDeptName();
                    }));
        }catch (NullPointerException e){
            throw new SmsException(ResponseCode.MSG,"员工【"+message[0]+"】没有部门");
        }

        if(resultMapDept.get(0)==null){
            resultMapDept.put(0,null);
        }
        if(resultMapDept.get(1)==null){
            resultMapDept.put(1,null);
        }
        if(resultMapDept.get(2)==null){
            resultMapDept.put(2,null);
        }
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Integer, List<StaffStatistic>>> entryIteratorDept = resultMapDept.entrySet().iterator();
        while (entryIteratorDept.hasNext()) {
            Map.Entry<Integer, List<StaffStatistic>> entry = entryIteratorDept.next();
            List<StaffStatistic> listByStaff = entry.getValue();
            StaffStatistic staffStatistic1 = new StaffStatistic();
            if (entry.getKey() == 0) {
                staffStatistic1.setDeptNames(baseStore.getStoreNum() + "-美发部");
            } else if (entry.getKey() == 1) {
                staffStatistic1.setDeptNames(baseStore.getStoreNum() + "-美容部");
            } else if (entry.getKey() == 2) {
                staffStatistic1.setDeptNames(baseStore.getStoreNum() + "-其他部");
            }
            staffStatistic1.setDeptName(entry.getKey());
            staffStatistic1.setRecharge(BigDecimal.valueOf(0));
            staffStatistic1.setRechargecar(BigDecimal.valueOf(0));
            staffStatistic1.setCourseCard(BigDecimal.valueOf(0));
            staffStatistic1.setCourseCash(BigDecimal.valueOf(0));
            staffStatistic1.setCourseTotal(BigDecimal.valueOf(0));
            staffStatistic1.setCoursePromotionCard(BigDecimal.valueOf(0));
            staffStatistic1.setCoursePromotionCash(BigDecimal.valueOf(0));
            staffStatistic1.setCoursePromotionTotal(BigDecimal.valueOf(0));
            staffStatistic1.setCashierCard(BigDecimal.valueOf(0));
            staffStatistic1.setCashierCash(BigDecimal.valueOf(0));
            staffStatistic1.setCashierRecharge(BigDecimal.valueOf(0));
            staffStatistic1.setCashierTotal(BigDecimal.valueOf(0));
            staffStatistic1.setRepaymentCourse(BigDecimal.valueOf(0));
            staffStatistic1.setRepaymentRecharge(BigDecimal.valueOf(0));
            staffStatistic1.setRepaymentTotal(BigDecimal.valueOf(0));
            staffStatistic1.setRefundTotal(BigDecimal.valueOf(0));
            staffStatistic1.setRefundCourse(BigDecimal.valueOf(0));
            staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0));
            staffStatistic1.setRefundCash(BigDecimal.valueOf(0));
            staffStatistic1.setJjzlcCard(BigDecimal.valueOf(0));
            staffStatistic1.setJjzlcCash(BigDecimal.valueOf(0));

            staffStatistic1.setCourse(BigDecimal.valueOf(0));
            staffStatistic1.setCourseSum(BigDecimal.valueOf(0));
            staffStatistic1.setCourseRepay(BigDecimal.valueOf(0));
            staffStatistic1.setCardAmount(BigDecimal.valueOf(0));
            staffStatistic1.setAllAmount(BigDecimal.valueOf(0));
            staffStatistic1.setCashAmount(BigDecimal.valueOf(0));
            staffStatistic1.setCooperationCardAmount(BigDecimal.valueOf(0));
            staffStatistic1.setCooperationAchi(BigDecimal.valueOf(0));
            staffStatistic1.setCooperateAmount(BigDecimal.valueOf(0));
            staffStatistic1.setHkCooperationAmount(BigDecimal.valueOf(0));
            if(listByStaff!=null && listByStaff.size()>0){


            for (StaffStatistic statistic : listByStaff) {
                staffStatistic1.setRecharge(staffStatistic1.getRecharge().add(statistic.getRecharge()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargecar(staffStatistic1.getRechargecar().add(statistic.getRechargecar()));
                staffStatistic1.setCourseCard(staffStatistic1.getCourseCard().add(statistic.getCourseCard()));
                staffStatistic1.setCourseCash(staffStatistic1.getCourseCash().add(statistic.getCourseCash()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseTotal(staffStatistic1.getCourseTotal().add(statistic.getCourseTotal()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCoursePromotionCard(staffStatistic1.getCoursePromotionCard().add(statistic.getCoursePromotionCard()));
                staffStatistic1.setCoursePromotionCash(staffStatistic1.getCoursePromotionCash().add(statistic.getCoursePromotionCash()));
                staffStatistic1.setCoursePromotionTotal(staffStatistic1.getCoursePromotionTotal().add(statistic.getCoursePromotionTotal()));
                staffStatistic1.setCashierCard(staffStatistic1.getCashierCard().add(statistic.getCashierCard()));
                staffStatistic1.setCashierCash(staffStatistic1.getCashierCash().add(statistic.getCashierCash()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCashierRecharge(staffStatistic1.getCashierRecharge().add(statistic.getCashierRecharge()));
                staffStatistic1.setCashierTotal(staffStatistic1.getCashierTotal().add(statistic.getCashierTotal()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRepaymentCourse(staffStatistic1.getRepaymentCourse().add(statistic.getRepaymentCourse()));
                staffStatistic1.setRepaymentRecharge(staffStatistic1.getRepaymentRecharge().add(statistic.getRepaymentRecharge()));
                staffStatistic1.setRepaymentTotal(staffStatistic1.getRepaymentTotal().add(statistic.getRepaymentTotal()));
                staffStatistic1.setRefundTotal(staffStatistic1.getRefundTotal().add(statistic.getRefundTotal()));
                staffStatistic1.setRefundCourse(staffStatistic1.getRefundCourse().add(statistic.getRefundCourse()));
                staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().add(statistic.getRefundRechagre()));
                staffStatistic1.setRefundCash(staffStatistic1.getRefundCash().add(statistic.getRefundCash()));
                staffStatistic1.setJjzlcCard(staffStatistic1.getJjzlcCard().add(statistic.getJjzlcCard()));
                staffStatistic1.setJjzlcCash(staffStatistic1.getJjzlcCash().add(statistic.getJjzlcCash()));
                staffStatistic1.setCourse(staffStatistic1.getCourse().add(statistic.getCourse()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().add(statistic.getCourseRepay()));
                staffStatistic1.setCourseSum(staffStatistic1.getCourseSum().add(statistic.getCourseSum()).setScale(10,BigDecimal.ROUND_HALF_UP));
                //
                staffStatistic1.setHkCooperationAmount((statistic.getHkCooperationAmount()==null?BigDecimal.valueOf(0):statistic.getHkCooperationAmount()).add(staffStatistic1.getHkCooperationAmount()==null?BigDecimal.valueOf(0):staffStatistic1.getHkCooperationAmount()));
                //
                staffStatistic1.setCardAmount(staffStatistic1.getCardAmount().add(statistic.getCardAmount()));
//                staffStatistic1.setAllAmount(statistic.getAllAmount());
                staffStatistic1.setCashAmount(staffStatistic1.getCashAmount().add(statistic.getCashAmount()));
                staffStatistic1.setCooperateAmount(staffStatistic1.getCooperateAmount().add(statistic.getCooperateAmount()==null?BigDecimal.valueOf(0):statistic.getCooperateAmount())
//                        .add(statistic.getCashAmount()
//                                .subtract(statistic.getCourseCash()))
                        .setScale(10,BigDecimal.ROUND_HALF_UP));//合作现付业绩
                staffStatistic1.setCooperationCardAmount(staffStatistic1.getCooperationCardAmount().add(statistic.getCooperationCardAmount()));//合作现付业绩
                staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().add(statistic.getCooperationAchi()));
            }
            }

//            staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).add(staffStatistic1.getRepaymentTotal()));
            staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).setScale(10,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCourseYj(staffStatistic1.getCourseTotal().add(staffStatistic1.getRepaymentCourse()).add(staffStatistic1.getJjzlcCash()).add(staffStatistic1.getCoursePromotionTotal()).subtract(staffStatistic1.getRefundCourse()).setScale(10,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCashYj(staffStatistic1.getCashierTotal().subtract(staffStatistic1.getRefundCash()).setScale(10,BigDecimal.ROUND_HALF_UP));

            staffStatistic1.setRefundTotal(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundTotal()));
            staffStatistic1.setRefundCourse(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCourse()));
            staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundRechagre()));
            staffStatistic1.setRefundCash(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCash()));
            //扣减业绩
            staffStatistic1.setCourse(staffStatistic1.getCourse().setScale(10,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay());
            staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().negate());
//            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().subtract(staffStatistic1.getHkCooperationAmount()));
            staffStatistic1.setCooperationAchi((staffStatistic1.getCooperationAchi().subtract(staffStatistic1.getHkCooperationAmount())).setScale(10,BigDecimal.ROUND_HALF_UP));
            staffStatistic1.setCourseSum((staffStatistic1.getCourse().add(staffStatistic1.getCooperationAchi()
                    .add(staffStatistic1.getCourseRepay().add(staffStatistic1.getHkCooperationAmount())))
            ).setScale(2,BigDecimal.ROUND_HALF_UP));

            staffStatisticListss.add(staffStatistic1);


        }
        }
        return staffStatisticListss;
    }

    @Override
    public List<StaffStatistic> departmentPerformanceByStoreList(StaffStatistic staffStatistic) throws ParseException, SmsException {

        List<StaffStatistic> staffStatisticListss = new ArrayList<>();
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(staffStatistic.getStoreId());
        if(staffStatistic.getStoreIds()!=null && staffStatistic.getStoreIds().size()>0){
            BaseStore baseStore1 = new BaseStore();
            baseStore1.setParentId(baseStore.getId());
            List<BaseStore> select = ssmBaseStoreService.select(baseStore1);
            List<BaseStore> collect = select.stream().filter(item -> {
                for (Long storeId : staffStatistic.getStoreIds()) {
                    if (storeId == item.getId() || storeId.toString().equals(item.getId().toString())) {
                        return true;
                    }
                }
                return false;
            }).collect(Collectors.toList());
            Collections.sort(collect,new StrComparatorUtils<>("storeNum",false));
            for (BaseStore store : collect) {
                staffStatistic.setStoreId(store.getId());
                List<StaffStatistic> staffStatisticList = new ArrayList<>();
                List<StaffStatistic> staffStatisticLists = new ArrayList<>();
                BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
                BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
                //根据时间类别转换时间
                //int type = staffStatistic.getType();
                String dateStr = staffStatistic.getStartDate().substring(0, 7);
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = dateFormat.parse(staffStatistic.getStartDate());
//                Date date = new Date();
                Long storeId = staffStatistic.getStoreId();
                List<RechargeListResponse> recList = new ArrayList<>();
                List<CourseListResponse> courseList = new ArrayList<>();
                List<CashListResponse> cashList = new ArrayList<>();
                List<RepayTradeResponse> RepayLists = new ArrayList<>();
                List<RefundRechargeResponse> refundRecList = new ArrayList<>();
                List<RefundCourseResponse> refundCourseList = new ArrayList<>();
//                List<CashListResponse> refundCashList = new ArrayList<>();
                List<RefundCashResponse> refundCashList = new ArrayList<>();
                List<DocPromotionResponse> promotionList = new ArrayList<>();
                List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
                List<CardChangeOutProjectResponse> cardOutList = new ArrayList<>();
                List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

                if (null == staffStatistic.getClassify()) {
                    recList = ssmRechargeService.selectList(storeId, dateStr, date);
                    courseList = ssmCourseService.selectList(storeId, dateStr, date);
                    cashList = ssmCashService.selectList(storeId, dateStr, date);
                    RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                    refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                    refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                    refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
//                    refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
                    promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                    //加价转疗程
                    cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            cardOutList = ssmCardChangeOutProjectService.selectListByStoreAndDate(storeId,dateStr);
                    //查询团购卡
                    baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

                }
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    for (AchiCommEntity entity : cardChangeList.getEntities()) {
                        entity.setChangeInPayMoney(cardChangeList.getChangeInPayMoney());
                        entity.setChangeOutMoney(cardChangeList.getChangeOutMoney());
                    }
                }

                List<AchiCommEntity> totalList = new ArrayList<>();
                //合并list
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    cardChangeList.getOutProjects().
                            forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                                    .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                }
                recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//                System.out.println(JSON.toJSONString(totalList));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
                while (entryIterator.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();
                        //充值 + 充值还款 业绩
                        BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 业绩
                        BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程 + 疗程还款 业绩
                        BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardRepay = list.stream().filter(item->item.getType() !=null &&item.getType().equals(Constant.doc_type_repay)).map(x->x.getNTMoney()==null?BigDecimal.ZERO:x.getNTMoney()).reduce(BigDecimal.ZERO,BigDecimal::add);

                        //加价转疗程 业绩
                        BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeInPayMoney()==null?BigDecimal.valueOf(0):item.getChangeInPayMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeOutMoney()==null?BigDecimal.valueOf(0):item.getChangeOutMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 业绩
                        BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 业绩
                        BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                        //消费退 业绩
                        BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //还款业绩
                        BigDecimal repayAchi = BigDecimal.valueOf(0);// list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销业绩
                        BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //充值  提成
                        BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 提成
                        BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程  提成
                        BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 提成
                        BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 提成
                        BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //消费退 提成
                        BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //还款提成
                        BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销提成
                        BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cooperationAomount = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO,BigDecimal::add);
                        //加价转疗程提成
                        BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程转充值
                        BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayMoney = list.stream().filter(item->item.getType().equals("card_repay")).map(x->x.getCashAchi().add(x.getCooperationAchi())).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //团购卡业绩
                        BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //团购卡提成
                        BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //还款合作方业绩
                        BigDecimal HKcooperateAmount = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(item->item.getCooperationAchi()==null?BigDecimal.valueOf(0):item.getCooperationAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);

                        achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(
                                        BigDecimalUtils.add(
                                                recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(courseChangeAchi);
                        commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                        //总现付业绩
                        BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                        //总卡付业绩
                        BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                        //总现付提成
                        BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                        //总卡付提成
                        BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm),promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                        //合作卡付
                        BigDecimal totalCardCoopAchi = list.stream().map(item->item.getCardCoopAchi()==null?BigDecimal.valueOf(0):item.getCardCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                        //合作现付
                        BigDecimal totalCashCoopAchi = list.stream().map(item->item.getCashCoopAchi()==null?BigDecimal.valueOf(0):item.getCashCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(0).getSaleStaffName());
                        statistic.setBrandNumber(list.get(0).getBrandNumber());
                        //按天查询用date
                        statistic.setAllAmount(courseChangeCashAchi);
                        statistic.setCourseCardRepay(courseCardRepay);
                        statistic.setCooperationCardAmount(totalCardCoopAchi);
                        statistic.setCooperationAchi(totalCashCoopAchi);
                        statistic.setDate(list.get(0).getDocDate());
                        statistic.setAchievementAmount(achievementAmount);
                        statistic.setCommissionAmount(commissionAmount);
                        statistic.setCashAchi(totalCashAchi);
                        statistic.setCardAchi(totalCardAchi);
                        statistic.setCashComm(totalCashComm);
                        statistic.setCardComm(totalCardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setCashAmount(BigDecimal.valueOf(0));
                        statistic.setCardAmount(BigDecimal.valueOf(0));
//                    statistic.setCourseRepay(repayMoney);
//                    statistic.setAllAmount(cashAchi.add(cashCardAchi));
                        statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                        statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                        //疗程总共金额
//                    statistic.setAllAmount(list.stream().map(item->item.getMoney()).reduce(BigDecimal.ZERO,BigDecimal::add));
                        //现付总金额
                        for (AchiCommEntity achiCommEntity : list) {
                            for (CourseListResponse courseListResponse : courseList) {
                                if(achiCommEntity.getDocId()==courseListResponse.getId()){
                                    //todo
                                    for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                        if(statistic.getStaffId().equals(entity.getSaleStaffId())){
                                            statistic.setCashAmount(statistic.getCashAmount()
//                                                .add(courseListResponse.getCollectionCashAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                    .setScale(10,BigDecimal.ROUND_HALF_UP));
                                            statistic.setCardAmount(statistic.getCardAmount()
//                                                .add(courseListResponse.getCollectionRechargeAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                    .setScale(10,BigDecimal.ROUND_HALF_UP));
                                        }
                                    }
//                                statistic.setCooperationCardAmount();
//                                statistic.setCooperateAmount();
                                }
                            }
                        }
                        //卡付总金额
                        statistic.setHkCooperationAmount(HKcooperateAmount);
                        statistic.setCooperateAmount(cooperationAomount);
                        if(statistic.getHkCooperationAmount()==null){
                            statistic.setHkCooperationAmount(BigDecimal.ZERO);
                        }
                        staffStatisticList.add(statistic);
                    }
                    //}
                }
//                System.out.println(JSON.toJSONString(staffStatisticList));
                for (StaffStatistic statistic : staffStatisticList) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if(effectiveDate){
                        //查询充值业务员信息
                        StaffStatistic staffStatistic1 = new StaffStatistic();
                        staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                        staffStatistic1.setDate(statistic.getDate());
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStoreId(storeId);
                        List<StaffStatistic> staffStatistics = null;
                        staffStatistics = this.achiCommListsss1(staffStatistic1);
//                 staffStatistics = ssmStoreStatisticService.achiCommListsss(staffStatistic1);
                        statistic.setRecharge(BigDecimal.valueOf(0));
                        statistic.setRechargecar(BigDecimal.valueOf(0));
                        statistic.setCourseCard(BigDecimal.valueOf(0));
                        statistic.setCourseCash(BigDecimal.valueOf(0));
                        statistic.setCourseTotal(BigDecimal.valueOf(0));

                        statistic.setCourse(BigDecimal.valueOf(0));
                        statistic.setCourseSum(BigDecimal.valueOf(0));
                        statistic.setCourseRepay(BigDecimal.valueOf(0));

                        statistic.setCoursePromotionCard(BigDecimal.valueOf(0));
                        statistic.setCoursePromotionCash(BigDecimal.valueOf(0));
                        statistic.setCoursePromotionTotal(BigDecimal.valueOf(0));
                        statistic.setCashierCard(BigDecimal.valueOf(0));
                        statistic.setCashierCash(BigDecimal.valueOf(0));
                        statistic.setCashierRecharge(BigDecimal.valueOf(0));
                        statistic.setCashierTotal(BigDecimal.valueOf(0));
                        statistic.setRepaymentCourse(BigDecimal.valueOf(0));
                        statistic.setRepaymentRecharge(BigDecimal.valueOf(0));
                        statistic.setRepaymentTotal(BigDecimal.valueOf(0));
                        statistic.setRefundTotal(BigDecimal.valueOf(0));
                        statistic.setRefundCourse(BigDecimal.valueOf(0));
                        statistic.setRefundRechagre(BigDecimal.valueOf(0));
                        statistic.setRefundCash(BigDecimal.valueOf(0));
                        statistic.setJjzlcCard(BigDecimal.valueOf(0));
                        statistic.setJjzlcCash(BigDecimal.valueOf(0));
//                statistic.setCashAchi(BigDecimal.valueOf(0));
//                statistic.setCashAmount();
                        if(staffStatistics!=null){
                            if(staffStatistics.size()>0){
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setRecharge(statistic.getRecharge()
                                            .add(staffStatistic2.getRecharge())
                                    );
                                    statistic.setRechargecar(statistic.getRechargecar()
                                            .add(staffStatistic2.getRechargecar())
                                    );
//                            statistic.setCashAchi(staffStatistic.getCashAchi().add(staffStatistic2.getCashAchi()));
                                    statistic.setCourseCard(statistic.getCourseCard().add(staffStatistic2.getCourseCard()));
                                    statistic.setCourseCash(statistic.getCourseCash().add(staffStatistic2.getCourseCash()));
                                    statistic.setCourseTotal(statistic.getCourseTotal().add(staffStatistic2.getCourseTotal())
//                                    .add(statistic.getCashAchi()
//                                            .add(statistic.getCardAchi())
//                            )
                                    );
                                    statistic.setCoursePromotionCard(statistic.getCoursePromotionCard().add(staffStatistic2.getCoursePromotionCard()));
                                    statistic.setCoursePromotionCash(statistic.getCoursePromotionCash().add(staffStatistic2.getCoursePromotionCash()));
                                    statistic.setCoursePromotionTotal(statistic.getCoursePromotionTotal().add(staffStatistic2.getCoursePromotionTotal()));
                                    statistic.setCashierCard(statistic.getCashierCard().add(staffStatistic2.getCashierCard()));
                                    statistic.setCashierCash(statistic.getCashierCash().add(staffStatistic2.getCashierCash()));
                                    statistic.setCashierRecharge(statistic.getCashierRecharge().add(staffStatistic2.getCashierRecharge()));
                                    statistic.setCashierTotal(statistic.getCashierTotal().add(staffStatistic2.getCashierTotal()));
                                    statistic.setRepaymentCourse(statistic.getRepaymentCourse().add(staffStatistic2.getRepaymentCourse()));
                                    statistic.setRepaymentRecharge(statistic.getRepaymentRecharge().add(staffStatistic2.getRepaymentRecharge()));
                                    statistic.setRepaymentTotal(statistic.getRepaymentTotal().add(staffStatistic2.getRepaymentTotal()));
                                    statistic.setRefundTotal(statistic.getRefundTotal().add(staffStatistic2.getRefundTotal()));
                                    statistic.setRefundCourse(statistic.getRefundCourse().add(staffStatistic2.getRefundCourse()));
                                    statistic.setRefundRechagre(statistic.getRefundRechagre().add(staffStatistic2.getRefundRechagre()));
                                    statistic.setRefundCash(statistic.getRefundCash().add(staffStatistic2.getRefundCash()));
                                    statistic.setJjzlcCard(statistic.getJjzlcCard().add(staffStatistic2.getJjzlcCard()));
                                    statistic.setJjzlcCash(statistic.getJjzlcCash().add(staffStatistic2.getJjzlcCash()));
                                    //todo
                                    statistic.setCourse(statistic.getCourse().add(
                                                    //todo 加价转疗程的卡付是否算业绩
                                                    staffStatistic2.getJjzlcCard().add(
                                                            staffStatistic2.getJjzlcCash()
                                                                    .add(staffStatistic2.getCourseTotal()
                                                                            .add(staffStatistic2.getCoursePromotionTotal())))
                                            )
//                                    .add(statistic.getAllAmount())
                                    );
                                    statistic.setCourseRepay(statistic.getCourseRepay().add(staffStatistic2.getCourseRepay()));
                                    //todo
//                            statistic.setCashAmount();

                                }
                            }
                        }
                        BaseStaff baseStaff = new BaseStaff();
                        statistic.setCourseSum(statistic.getCourseSum().add(statistic.getCourseRepay().add(statistic.getCourse()))
//                                    .add(BigDecimal.valueOf(2))
                        );
                        baseStaff.setId(statistic.getStaffId());

                        BaseStaff baseStaff1 = ssmBaseStaffService.selectByPrimaryKey(baseStaff.getId());
                        //todo 空指针
                        if(baseStaff1!=null) {
                            statistic.setDeptName(baseStaff1.getDeptName());
                        }
                        staffStatisticLists.add(statistic);
                    }
                }
//        Map<Integer, List<StaffStatistic>> resultMapDept = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getDeptName));
//                System.out.println(JSON.toJSONString(staffStatisticLists));
                Map<Integer, List<StaffStatistic>> resultMapDept;
                final String[] message = {""};
                try{
                    resultMapDept = staffStatisticLists.stream().filter(item->item!=null).collect(Collectors.groupingBy(
                            item->{
                                if (item.getDeptName()==null){
                                    item.setDeptName(2);
                                    message[0] = item.getStaffName();
                                }return item.getDeptName();
                            }));
                }catch (NullPointerException e){
                    throw new SmsException(ResponseCode.MSG,"员工【"+message[0]+"】没有部门");
                }

                if(resultMapDept.get(0)==null){
                    resultMapDept.put(0,null);
                }
                if(resultMapDept.get(1)==null){
                    resultMapDept.put(1,null);
                }
                if(resultMapDept.get(2)==null){
                    resultMapDept.put(2,null);
                }
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Integer, List<StaffStatistic>>> entryIteratorDept = resultMapDept.entrySet().iterator();
                while (entryIteratorDept.hasNext()) {
                    Map.Entry<Integer, List<StaffStatistic>> entry = entryIteratorDept.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    if (entry.getKey() == 0) {
                        staffStatistic1.setDeptNames(store.getStoreNum() + "-美发部");
                    } else if (entry.getKey() == 1) {
                        staffStatistic1.setDeptNames(store.getStoreNum() + "-美容部");
                    } else if (entry.getKey() == 2) {
                        staffStatistic1.setDeptNames(store.getStoreNum() + "-其他部");
                    }
                    staffStatistic1.setDeptName(entry.getKey());
                    staffStatistic1.setRecharge(BigDecimal.valueOf(0));
                    staffStatistic1.setRechargecar(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseCard(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseCash(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setCoursePromotionCard(BigDecimal.valueOf(0));
                    staffStatistic1.setCoursePromotionCash(BigDecimal.valueOf(0));
                    staffStatistic1.setCoursePromotionTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierCard(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierCash(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierRecharge(BigDecimal.valueOf(0));
                    staffStatistic1.setCashierTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setRepaymentCourse(BigDecimal.valueOf(0));
                    staffStatistic1.setRepaymentRecharge(BigDecimal.valueOf(0));
                    staffStatistic1.setRepaymentTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundTotal(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundCourse(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0));
                    staffStatistic1.setRefundCash(BigDecimal.valueOf(0));
                    staffStatistic1.setJjzlcCard(BigDecimal.valueOf(0));
                    staffStatistic1.setJjzlcCash(BigDecimal.valueOf(0));

                    staffStatistic1.setCourse(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseSum(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseRepay(BigDecimal.valueOf(0));
                    staffStatistic1.setCardAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setAllAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCashAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCooperationCardAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCooperationAchi(BigDecimal.valueOf(0));
                    staffStatistic1.setCooperateAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setHkCooperationAmount(BigDecimal.valueOf(0));
                    staffStatistic1.setCourseCardRepay(BigDecimal.valueOf(0));
                    if (listByStaff != null && listByStaff.size() > 0) {


                        for (StaffStatistic statistic : listByStaff) {
                            staffStatistic1.setCourseCardRepay(staffStatistic1.getCourseCardRepay().add(statistic.getCourseCardRepay()));
                            staffStatistic1.setRecharge(staffStatistic1.getRecharge().add(statistic.getRecharge()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setRechargecar(staffStatistic1.getRechargecar().add(statistic.getRechargecar()));
                            staffStatistic1.setCourseCard(staffStatistic1.getCourseCard().add(statistic.getCourseCard()));
                            staffStatistic1.setCourseCash(staffStatistic1.getCourseCash().add(statistic.getCourseCash()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCourseTotal(staffStatistic1.getCourseTotal().add(statistic.getCourseTotal()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCoursePromotionCard(staffStatistic1.getCoursePromotionCard().add(statistic.getCoursePromotionCard()));
                            staffStatistic1.setCoursePromotionCash(staffStatistic1.getCoursePromotionCash().add(statistic.getCoursePromotionCash()));
                            staffStatistic1.setCoursePromotionTotal(staffStatistic1.getCoursePromotionTotal().add(statistic.getCoursePromotionTotal()));
                            staffStatistic1.setCashierCard(staffStatistic1.getCashierCard().add(statistic.getCashierCard()));
                            staffStatistic1.setCashierCash(staffStatistic1.getCashierCash().add(statistic.getCashierCash()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCashierRecharge(staffStatistic1.getCashierRecharge().add(statistic.getCashierRecharge()));
                            staffStatistic1.setCashierTotal(staffStatistic1.getCashierTotal().add(statistic.getCashierTotal()).setScale(10, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setRepaymentCourse(staffStatistic1.getRepaymentCourse().add(statistic.getRepaymentCourse()));
                            staffStatistic1.setRepaymentRecharge(staffStatistic1.getRepaymentRecharge().add(statistic.getRepaymentRecharge()));
                            staffStatistic1.setRepaymentTotal(staffStatistic1.getRepaymentTotal().add(statistic.getRepaymentTotal()));
                            staffStatistic1.setRefundTotal(staffStatistic1.getRefundTotal().add(statistic.getRefundTotal()));
                            staffStatistic1.setRefundCourse(staffStatistic1.getRefundCourse().add(statistic.getRefundCourse()));
                            staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().add(statistic.getRefundRechagre()));
                            staffStatistic1.setRefundCash(staffStatistic1.getRefundCash().add(statistic.getRefundCash()));
                            staffStatistic1.setJjzlcCard(staffStatistic1.getJjzlcCard().add(statistic.getJjzlcCard()));
                            staffStatistic1.setJjzlcCash(staffStatistic1.getJjzlcCash().add(statistic.getJjzlcCash()));
                            staffStatistic1.setCourse(staffStatistic1.getCourse().add(statistic.getCourse()).setScale(3, BigDecimal.ROUND_HALF_UP));
                            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().add(statistic.getCourseRepay()));
                            staffStatistic1.setCourseSum(staffStatistic1.getCourseSum().add(statistic.getCourseSum()).setScale(3, BigDecimal.ROUND_HALF_UP));
                            //
                            staffStatistic1.setHkCooperationAmount((statistic.getHkCooperationAmount() == null ? BigDecimal.valueOf(0) : statistic.getHkCooperationAmount()).add(staffStatistic1.getHkCooperationAmount() == null ? BigDecimal.valueOf(0) : staffStatistic1.getHkCooperationAmount()));
                            //
                            staffStatistic1.setCardAmount(staffStatistic1.getCardAmount().add(statistic.getCardAmount()));
//                staffStatistic1.setAllAmount(statistic.getAllAmount());
                            staffStatistic1.setCashAmount(staffStatistic1.getCashAmount().add(statistic.getCashAmount()));
                            staffStatistic1.setCooperateAmount(staffStatistic1.getCooperateAmount().add(statistic.getCooperateAmount() == null ? BigDecimal.valueOf(0) : statistic.getCooperateAmount())
//                        .add(statistic.getCashAmount()
//                                .subtract(statistic.getCourseCash()))
                                    .setScale(2, BigDecimal.ROUND_HALF_UP));//合作现付业绩
                            staffStatistic1.setCooperationCardAmount(staffStatistic1.getCooperationCardAmount().add(statistic.getCooperationCardAmount()));//合作现付业绩
                            staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().add(statistic.getCooperationAchi()));
                        }
                    }

//            staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).add(staffStatistic1.getRepaymentTotal()));
                    staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseYj(staffStatistic1.getCourseTotal().add(staffStatistic1.getRepaymentCourse()).add(staffStatistic1.getJjzlcCash()).add(staffStatistic1.getCoursePromotionTotal()).subtract(staffStatistic1.getRefundCourse()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCashYj(staffStatistic1.getCashierTotal().subtract(staffStatistic1.getRefundCash()).setScale(2, BigDecimal.ROUND_HALF_UP));

                    staffStatistic1.setRefundTotal(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundTotal()));
                    staffStatistic1.setRefundCourse(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCourse()));
                    staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundRechagre()));
                    staffStatistic1.setRefundCash(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCash()));
                    //扣减业绩
                    staffStatistic1.setCourse(staffStatistic1.getCourse().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay());
                    staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().negate());
//            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().subtract(staffStatistic1.getHkCooperationAmount()));
                    staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().subtract(staffStatistic1.getHkCooperationAmount()));
                    staffStatistic1.setCourseSum(staffStatistic1.getCourse().add(staffStatistic1.getCooperationAchi()
                            .add(staffStatistic1.getCourseRepay().add(staffStatistic1.getHkCooperationAmount()))
                    ));
                    staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().subtract(staffStatistic1.getCourseCardRepay()));
                    staffStatistic1.setCourseSum(staffStatistic1.getCourseSum().subtract(staffStatistic1.getCourseCardRepay()));
                    staffStatistic1.setCourseYj(staffStatistic1.getCourseYj().subtract(staffStatistic1.getCourseCardRepay()));
                    staffStatistic1.setRepaymentCourse(staffStatistic1.getRepaymentCourse().subtract(staffStatistic1.getCourseCardRepay()));
                    staffStatistic1.setRepaymentTotal(staffStatistic1.getRepaymentTotal().subtract(staffStatistic1.getCourseCardRepay()));
                    staffStatisticListss.add(staffStatistic1);

                }
            }
        }
        else {
            List<StaffStatistic> staffStatisticList = new ArrayList<>();
            List<StaffStatistic> staffStatisticLists = new ArrayList<>();
            BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
            BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
            //根据时间类别转换时间
            //int type = staffStatistic.getType();
            String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Date date = dateFormat.parse(staffStatistic.getStartDate());
            Long storeId = staffStatistic.getStoreId();
            List<RechargeListResponse> recList = new ArrayList<>();
            List<CourseListResponse> courseList = new ArrayList<>();
            List<CashListResponse> cashList = new ArrayList<>();
            List<RepayTradeResponse> RepayLists = new ArrayList<>();
            List<RefundRechargeResponse> refundRecList = new ArrayList<>();
            List<RefundCourseResponse> refundCourseList = new ArrayList<>();
//            List<CashListResponse> refundCashList = new ArrayList<>();
            List<RefundCashResponse> refundCashList = new ArrayList<>();
            List<DocPromotionResponse> promotionList = new ArrayList<>();
            List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
            List<CardChangeOutProjectResponse> cardOutList = new ArrayList<>();
            List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

            if (null == staffStatistic.getClassify()) {
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
                cashList = ssmCashService.selectList(storeId, dateStr, date);
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
//                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                //加价转疗程
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            cardOutList = ssmCardChangeOutProjectService.selectListByStoreAndDate(storeId,dateStr);
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

            }
            for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                for (AchiCommEntity entity : cardChangeList.getEntities()) {
                    entity.setChangeInPayMoney(cardChangeList.getChangeInPayMoney());
                    entity.setChangeOutMoney(cardChangeList.getChangeOutMoney());
                }
            }

            List<AchiCommEntity> totalList = new ArrayList<>();
            //合并list
            for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                cardChangeList.getOutProjects().
                        forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                                .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            }
            recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
//            System.out.println(JSON.toJSONString(totalList));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
            while (entryIterator.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardRepay = list.stream().filter(item->item.getType() !=null &&item.getType().equals(Constant.doc_type_repay)).map(x->x.getNTMoney()==null?BigDecimal.ZERO:x.getNTMoney()).reduce(BigDecimal.ZERO,BigDecimal::add);



                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeInPayMoney()==null?BigDecimal.valueOf(0):item.getChangeInPayMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item->item.getChangeOutMoney()==null?BigDecimal.valueOf(0):item.getChangeOutMoney()).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = BigDecimal.valueOf(0);// list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cooperationAomount = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO,BigDecimal::add);
                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    BigDecimal repayMoney = list.stream().filter(item->item.getType().equals("card_repay")).map(x->x.getCashAchi().add(x.getCooperationAchi())).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款合作方业绩
                    BigDecimal HKcooperateAmount = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(item->item.getCooperationAchi()==null?BigDecimal.valueOf(0):item.getCooperationAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);

                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(
                                    BigDecimalUtils.add(
                                            recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia).add(courseChangeAchi);
                    commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm),promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                    //合作卡付
                    BigDecimal totalCardCoopAchi = list.stream().map(item->item.getCardCoopAchi()==null?BigDecimal.valueOf(0):item.getCardCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                    //合作现付
                    BigDecimal totalCashCoopAchi = list.stream().map(item->item.getCashCoopAchi()==null?BigDecimal.valueOf(0):item.getCashCoopAchi()).reduce(BigDecimal.ZERO,BigDecimal::add);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(0).getSaleStaffName());
                    statistic.setBrandNumber(list.get(0).getBrandNumber());
                    //按天查询用date
                    statistic.setAllAmount(courseChangeCashAchi);
                    statistic.setCooperationCardAmount(totalCardCoopAchi);
                    statistic.setCooperationAchi(totalCashCoopAchi);
                    statistic.setDate(list.get(0).getDocDate());
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCashAmount(BigDecimal.valueOf(0));
                    statistic.setCardAmount(BigDecimal.valueOf(0));
                    statistic.setCourseCardRepay(courseCardRepay);
//                    statistic.setCourseRepay(repayMoney);
//                    statistic.setAllAmount(cashAchi.add(cashCardAchi));
                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                    //疗程总共金额
//                    statistic.setAllAmount(list.stream().map(item->item.getMoney()).reduce(BigDecimal.ZERO,BigDecimal::add));
                    //现付总金额
                    for (AchiCommEntity achiCommEntity : list) {
                        for (CourseListResponse courseListResponse : courseList) {
                            if(achiCommEntity.getDocId()==courseListResponse.getId()){
                                //todo
                                for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                    if(statistic.getStaffId().equals(entity.getSaleStaffId())){
                                        statistic.setCashAmount(statistic.getCashAmount()
//                                                .add(courseListResponse.getCollectionCashAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                .setScale(10,BigDecimal.ROUND_HALF_UP));
                                        statistic.setCardAmount(statistic.getCardAmount()
//                                                .add(courseListResponse.getCollectionRechargeAmount()
//                                                        .multiply(entity.getSaleRatio()
//                                                                .divide(BigDecimal.valueOf(100),10,BigDecimal.ROUND_HALF_UP)))
                                                .setScale(10,BigDecimal.ROUND_HALF_UP));
                                    }
                                }
//                                statistic.setCooperationCardAmount();
//                                statistic.setCooperateAmount();
                            }
                        }
                    }
                    //卡付总金额
                    statistic.setHkCooperationAmount(HKcooperateAmount);
                    statistic.setCooperateAmount(cooperationAomount);
                    if(statistic.getHkCooperationAmount()==null){
                        statistic.setHkCooperationAmount(BigDecimal.ZERO);
                    }
                    staffStatisticList.add(statistic);
                }
                //}
            }
//            System.out.println(JSON.toJSONString(staffStatisticList));
            for (StaffStatistic statistic : staffStatisticList) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if(effectiveDate){
                    //查询充值业务员信息
                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                    staffStatistic1.setDate(statistic.getDate());
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStoreId(storeId);
                    List<StaffStatistic> staffStatistics = null;
                    staffStatistics = this.achiCommListsss1(staffStatistic1);
//                 staffStatistics = ssmStoreStatisticService.achiCommListsss(staffStatistic1);
                    statistic.setRecharge(BigDecimal.valueOf(0));
                    statistic.setRechargecar(BigDecimal.valueOf(0));
                    statistic.setCourseCard(BigDecimal.valueOf(0));
                    statistic.setCourseCash(BigDecimal.valueOf(0));
                    statistic.setCourseTotal(BigDecimal.valueOf(0));

                    statistic.setCourse(BigDecimal.valueOf(0));
                    statistic.setCourseSum(BigDecimal.valueOf(0));
                    statistic.setCourseRepay(BigDecimal.valueOf(0));

                    statistic.setCoursePromotionCard(BigDecimal.valueOf(0));
                    statistic.setCoursePromotionCash(BigDecimal.valueOf(0));
                    statistic.setCoursePromotionTotal(BigDecimal.valueOf(0));
                    statistic.setCashierCard(BigDecimal.valueOf(0));
                    statistic.setCashierCash(BigDecimal.valueOf(0));
                    statistic.setCashierRecharge(BigDecimal.valueOf(0));
                    statistic.setCashierTotal(BigDecimal.valueOf(0));
                    statistic.setRepaymentCourse(BigDecimal.valueOf(0));
                    statistic.setRepaymentRecharge(BigDecimal.valueOf(0));
                    statistic.setRepaymentTotal(BigDecimal.valueOf(0));
                    statistic.setRefundTotal(BigDecimal.valueOf(0));
                    statistic.setRefundCourse(BigDecimal.valueOf(0));
                    statistic.setRefundRechagre(BigDecimal.valueOf(0));
                    statistic.setRefundCash(BigDecimal.valueOf(0));
                    statistic.setJjzlcCard(BigDecimal.valueOf(0));
                    statistic.setJjzlcCash(BigDecimal.valueOf(0));
//                statistic.setCashAchi(BigDecimal.valueOf(0));
//                statistic.setCashAmount();
                    if(staffStatistics!=null){
                        if(staffStatistics.size()>0){
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setRecharge(statistic.getRecharge()
                                        .add(staffStatistic2.getRecharge())
                                );
                                statistic.setRechargecar(statistic.getRechargecar()
                                        .add(staffStatistic2.getRechargecar())
                                );
//                            statistic.setCashAchi(staffStatistic.getCashAchi().add(staffStatistic2.getCashAchi()));
                                statistic.setCourseCard(statistic.getCourseCard().add(staffStatistic2.getCourseCard()));
                                statistic.setCourseCash(statistic.getCourseCash().add(staffStatistic2.getCourseCash()));
                                statistic.setCourseTotal(statistic.getCourseTotal().add(staffStatistic2.getCourseTotal())
//                                    .add(statistic.getCashAchi()
//                                            .add(statistic.getCardAchi())
//                            )
                                );
                                statistic.setCoursePromotionCard(statistic.getCoursePromotionCard().add(staffStatistic2.getCoursePromotionCard()));
                                statistic.setCoursePromotionCash(statistic.getCoursePromotionCash().add(staffStatistic2.getCoursePromotionCash()));
                                statistic.setCoursePromotionTotal(statistic.getCoursePromotionTotal().add(staffStatistic2.getCoursePromotionTotal()));
                                statistic.setCashierCard(statistic.getCashierCard().add(staffStatistic2.getCashierCard()));
                                statistic.setCashierCash(statistic.getCashierCash().add(staffStatistic2.getCashierCash()));
                                statistic.setCashierRecharge(statistic.getCashierRecharge().add(staffStatistic2.getCashierRecharge()));
                                statistic.setCashierTotal(statistic.getCashierTotal().add(staffStatistic2.getCashierTotal()));
                                statistic.setRepaymentCourse(statistic.getRepaymentCourse().add(staffStatistic2.getRepaymentCourse()));
                                statistic.setRepaymentRecharge(statistic.getRepaymentRecharge().add(staffStatistic2.getRepaymentRecharge()));
                                statistic.setRepaymentTotal(statistic.getRepaymentTotal().add(staffStatistic2.getRepaymentTotal()));
                                statistic.setRefundTotal(statistic.getRefundTotal().add(staffStatistic2.getRefundTotal()));
                                statistic.setRefundCourse(statistic.getRefundCourse().add(staffStatistic2.getRefundCourse()));
                                statistic.setRefundRechagre(statistic.getRefundRechagre().add(staffStatistic2.getRefundRechagre()));
                                statistic.setRefundCash(statistic.getRefundCash().add(staffStatistic2.getRefundCash()));
                                statistic.setJjzlcCard(statistic.getJjzlcCard().add(staffStatistic2.getJjzlcCard()));
                                statistic.setJjzlcCash(statistic.getJjzlcCash().add(staffStatistic2.getJjzlcCash()));
                                //todo
                                statistic.setCourse(statistic.getCourse()
//                                                .add(
//                                                //todo 加价转疗程的卡付是否算业绩
//                                                staffStatistic2.getJjzlcCard())
                                                        .add(staffStatistic2.getJjzlcCash())
                                                                .add(staffStatistic2.getCourseTotal()
                                                                        .add(staffStatistic2.getCoursePromotionTotal()))

//                                    .add(statistic.getAllAmount())
                                );
                                statistic.setCourseRepay(statistic.getCourseRepay().add(staffStatistic2.getCourseRepay()));
                                //todo
//                            statistic.setCashAmount();

                            }
                        }
                    }
                    BaseStaff baseStaff = new BaseStaff();
                    statistic.setCourseSum(statistic.getCourseSum().add(statistic.getCourseRepay().add(statistic.getCourse()))
//                                    .add(BigDecimal.valueOf(2))
                    );
                    baseStaff.setId(statistic.getStaffId());

                    BaseStaff baseStaff1 = ssmBaseStaffService.selectByPrimaryKey(baseStaff.getId());
                    //todo 空指针
                    if(baseStaff1!=null) {
                        statistic.setDeptName(baseStaff1.getDeptName());
                    }
                    staffStatisticLists.add(statistic);
                }
            }
//        Map<Integer, List<StaffStatistic>> resultMapDept = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getDeptName));
//            System.out.println(JSON.toJSONString(staffStatisticLists));
            Map<Integer, List<StaffStatistic>> resultMapDept;
            final String[] message = {""};
            try{
                resultMapDept = staffStatisticLists.stream().filter(item->item!=null).collect(Collectors.groupingBy(
                        item->{
                            if (item.getDeptName()==null){
                                item.setDeptName(2);
                                message[0] = item.getStaffName();
                            }return item.getDeptName();
                        }));
            }catch (NullPointerException e){
                throw new SmsException(ResponseCode.MSG,"员工【"+message[0]+"】没有部门");
            }

            if(resultMapDept.get(0)==null){
                resultMapDept.put(0,null);
            }
            if(resultMapDept.get(1)==null){
                resultMapDept.put(1,null);
            }
            if(resultMapDept.get(2)==null){
                resultMapDept.put(2,null);
            }
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Integer, List<StaffStatistic>>> entryIteratorDept = resultMapDept.entrySet().iterator();
            while (entryIteratorDept.hasNext()) {
                Map.Entry<Integer, List<StaffStatistic>> entry = entryIteratorDept.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                StaffStatistic staffStatistic1 = new StaffStatistic();
                if (entry.getKey() == 0) {
                    staffStatistic1.setDeptNames(baseStore.getStoreNum() + "-美发部");
                } else if (entry.getKey() == 1) {
                    staffStatistic1.setDeptNames(baseStore.getStoreNum() + "-美容部");
                } else if (entry.getKey() == 2) {
                    staffStatistic1.setDeptNames(baseStore.getStoreNum() + "-其他部");
                }
                staffStatistic1.setDeptName(entry.getKey());
                staffStatistic1.setRecharge(BigDecimal.valueOf(0));
                staffStatistic1.setRechargecar(BigDecimal.valueOf(0));
                staffStatistic1.setCourseCard(BigDecimal.valueOf(0));
                staffStatistic1.setCourseCash(BigDecimal.valueOf(0));
                staffStatistic1.setCourseTotal(BigDecimal.valueOf(0));
                staffStatistic1.setCoursePromotionCard(BigDecimal.valueOf(0));
                staffStatistic1.setCoursePromotionCash(BigDecimal.valueOf(0));
                staffStatistic1.setCoursePromotionTotal(BigDecimal.valueOf(0));
                staffStatistic1.setCashierCard(BigDecimal.valueOf(0));
                staffStatistic1.setCashierCash(BigDecimal.valueOf(0));
                staffStatistic1.setCashierRecharge(BigDecimal.valueOf(0));
                staffStatistic1.setCashierTotal(BigDecimal.valueOf(0));
                staffStatistic1.setRepaymentCourse(BigDecimal.valueOf(0));
                staffStatistic1.setRepaymentRecharge(BigDecimal.valueOf(0));
                staffStatistic1.setRepaymentTotal(BigDecimal.valueOf(0));
                staffStatistic1.setRefundTotal(BigDecimal.valueOf(0));
                staffStatistic1.setRefundCourse(BigDecimal.valueOf(0));
                staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0));
                staffStatistic1.setRefundCash(BigDecimal.valueOf(0));
                staffStatistic1.setJjzlcCard(BigDecimal.valueOf(0));
                staffStatistic1.setJjzlcCash(BigDecimal.valueOf(0));

                staffStatistic1.setCourse(BigDecimal.valueOf(0));
                staffStatistic1.setCourseSum(BigDecimal.valueOf(0));
                staffStatistic1.setCourseRepay(BigDecimal.valueOf(0));
                staffStatistic1.setCardAmount(BigDecimal.valueOf(0));
                staffStatistic1.setAllAmount(BigDecimal.valueOf(0));
                staffStatistic1.setCashAmount(BigDecimal.valueOf(0));
                staffStatistic1.setCooperationCardAmount(BigDecimal.valueOf(0));
                staffStatistic1.setCooperationAchi(BigDecimal.valueOf(0));
                staffStatistic1.setCooperateAmount(BigDecimal.valueOf(0));
                staffStatistic1.setHkCooperationAmount(BigDecimal.valueOf(0));
                staffStatistic1.setCourseCardRepay(BigDecimal.valueOf(0));
                if(listByStaff!=null && listByStaff.size()>0){


                    for (StaffStatistic statistic : listByStaff) {
                        staffStatistic1.setCourseCardRepay(staffStatistic1.getCourseCardRepay().add(statistic.getCourseCardRepay()));
                        staffStatistic1.setRecharge(staffStatistic1.getRecharge().add(statistic.getRecharge()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setRechargecar(staffStatistic1.getRechargecar().add(statistic.getRechargecar()));
                        staffStatistic1.setCourseCard(staffStatistic1.getCourseCard().add(statistic.getCourseCard()));
                        staffStatistic1.setCourseCash(staffStatistic1.getCourseCash().add(statistic.getCourseCash()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCourseTotal(staffStatistic1.getCourseTotal().add(statistic.getCourseTotal()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCoursePromotionCard(staffStatistic1.getCoursePromotionCard().add(statistic.getCoursePromotionCard()));
                        staffStatistic1.setCoursePromotionCash(staffStatistic1.getCoursePromotionCash().add(statistic.getCoursePromotionCash()));
                        staffStatistic1.setCoursePromotionTotal(staffStatistic1.getCoursePromotionTotal().add(statistic.getCoursePromotionTotal()));
                        staffStatistic1.setCashierCard(staffStatistic1.getCashierCard().add(statistic.getCashierCard()));
                        staffStatistic1.setCashierCash(staffStatistic1.getCashierCash().add(statistic.getCashierCash()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCashierRecharge(staffStatistic1.getCashierRecharge().add(statistic.getCashierRecharge()));
                        staffStatistic1.setCashierTotal(staffStatistic1.getCashierTotal().add(statistic.getCashierTotal()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setRepaymentCourse(staffStatistic1.getRepaymentCourse().add(statistic.getRepaymentCourse()));
                        staffStatistic1.setRepaymentRecharge(staffStatistic1.getRepaymentRecharge().add(statistic.getRepaymentRecharge()));
                        staffStatistic1.setRepaymentTotal(staffStatistic1.getRepaymentTotal().add(statistic.getRepaymentTotal()));
                        staffStatistic1.setRefundTotal(staffStatistic1.getRefundTotal().add(statistic.getRefundTotal()));
                        staffStatistic1.setRefundCourse(staffStatistic1.getRefundCourse().add(statistic.getRefundCourse()));
                        staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().add(statistic.getRefundRechagre()));
                        staffStatistic1.setRefundCash(staffStatistic1.getRefundCash().add(statistic.getRefundCash()));
                        staffStatistic1.setJjzlcCard(staffStatistic1.getJjzlcCard().add(statistic.getJjzlcCard()));
                        staffStatistic1.setJjzlcCash(staffStatistic1.getJjzlcCash().add(statistic.getJjzlcCash()));
                        staffStatistic1.setCourse(staffStatistic1.getCourse().add(statistic.getCourse()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().add(statistic.getCourseRepay()));
                        staffStatistic1.setCourseSum(staffStatistic1.getCourseSum().add(statistic.getCourseSum()).setScale(10,BigDecimal.ROUND_HALF_UP));
                        //
                        staffStatistic1.setHkCooperationAmount((statistic.getHkCooperationAmount()==null?BigDecimal.valueOf(0):statistic.getHkCooperationAmount()).add(staffStatistic1.getHkCooperationAmount()==null?BigDecimal.valueOf(0):staffStatistic1.getHkCooperationAmount()));
                        //
                        staffStatistic1.setCardAmount(staffStatistic1.getCardAmount().add(statistic.getCardAmount()));
//                staffStatistic1.setAllAmount(statistic.getAllAmount());
                        staffStatistic1.setCashAmount(staffStatistic1.getCashAmount().add(statistic.getCashAmount()));
                        staffStatistic1.setCooperateAmount(staffStatistic1.getCooperateAmount().add(statistic.getCooperateAmount()==null?BigDecimal.valueOf(0):statistic.getCooperateAmount())
//                        .add(statistic.getCashAmount()
//                                .subtract(statistic.getCourseCash()))
                                .setScale(10,BigDecimal.ROUND_HALF_UP));//合作现付业绩
                        staffStatistic1.setCooperationCardAmount(staffStatistic1.getCooperationCardAmount().add(statistic.getCooperationCardAmount()));//合作现付业绩
                        staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi().add(statistic.getCooperationAchi()));
                    }
                }

//            staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).add(staffStatistic1.getRepaymentTotal()));
                staffStatistic1.setCashReceipts(staffStatistic1.getRecharge().add(staffStatistic1.getCourseCash()).add(staffStatistic1.getCoursePromotionCash()).add(staffStatistic1.getCashierCash()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseYj(staffStatistic1.getCourseTotal().add(staffStatistic1.getRepaymentCourse()).add(staffStatistic1.getJjzlcCash()).add(staffStatistic1.getCoursePromotionTotal()).subtract(staffStatistic1.getRefundCourse()).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCashYj(staffStatistic1.getCashierTotal().subtract(staffStatistic1.getRefundCash()).setScale(10,BigDecimal.ROUND_HALF_UP));

                staffStatistic1.setRefundTotal(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundTotal()));
                staffStatistic1.setRefundCourse(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCourse()));
                staffStatistic1.setRefundRechagre(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundRechagre()));
                staffStatistic1.setRefundCash(BigDecimal.valueOf(0).subtract(staffStatistic1.getRefundCash()));
                //扣减业绩
                staffStatistic1.setCourse(staffStatistic1.getCourse().setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay());
                staffStatistic1.setRefundRechagre(staffStatistic1.getRefundRechagre().negate());
//            staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().subtract(staffStatistic1.getHkCooperationAmount()));
                staffStatistic1.setCooperationAchi((staffStatistic1.getCooperationAchi().subtract(staffStatistic1.getHkCooperationAmount())).setScale(10,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseSum((staffStatistic1.getCourse().add(staffStatistic1.getCooperationAchi()
                        .add(staffStatistic1.getCourseRepay().add(staffStatistic1.getHkCooperationAmount())))
                ).setScale(2,BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseRepay(staffStatistic1.getCourseRepay().subtract(staffStatistic1.getCourseCardRepay()));
                staffStatistic1.setCourseSum(staffStatistic1.getCourseSum().subtract(staffStatistic1.getCourseCardRepay()));
                staffStatistic1.setCourseYj(staffStatistic1.getCourseYj().subtract(staffStatistic1.getCourseCardRepay()));
                staffStatistic1.setRepaymentCourse(staffStatistic1.getRepaymentCourse().subtract(staffStatistic1.getCourseCardRepay()));
                staffStatistic1.setRepaymentTotal(staffStatistic1.getRepaymentTotal().subtract(staffStatistic1.getCourseCardRepay()));
                staffStatisticListss.add(staffStatistic1);


            }
        }
        return staffStatisticListss;
    }

    @Override
    public List<StaffStatistic> departmentPerformance2(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        List<StaffStatistic> staffStatisticLists = new ArrayList<>();
        List<StaffStatistic> staffStatisticListss = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(staffStatistic.getStartDate());
        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardRepay = list.stream().filter(item->item.getType() !=null &&item.getType().equals(Constant.doc_type_repay)).map(x->x.getNTMoney()==null?BigDecimal.ZERO:x.getNTMoney()).reduce(BigDecimal.ZERO,BigDecimal::add);


                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi);
                    commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(0).getSaleStaffName());
                    statistic.setBrandNumber(list.get(0).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(0).getDocDate());
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCourseCardRepay(courseCardRepay);
                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                    staffStatisticList.add(statistic);
                }
            //}
        }

        for (StaffStatistic statistic : staffStatisticList) {
            boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if(effectiveDate){
                //查询充值业务员信息
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                staffStatistic1.setDate(statistic.getDate());
                staffStatistic1.setStaffId(statistic.getStaffId());
                staffStatistic1.setStoreId(storeId);
                List<StaffStatistic> staffStatistics = null;
                 staffStatistics = ssmStoreStatisticService.achiCommListsss(staffStatistic1);
                statistic.setRecharge(BigDecimal.valueOf(0));
                statistic.setRechargecar(BigDecimal.valueOf(0));


                statistic.setCourseSum(BigDecimal.valueOf(0));
                statistic.setCourse(BigDecimal.valueOf(0));
                statistic.setCourseRepay(BigDecimal.valueOf(0));


                statistic.setCourseCard(BigDecimal.valueOf(0));
                statistic.setCourseCash(BigDecimal.valueOf(0));
                statistic.setCourseTotal(BigDecimal.valueOf(0));
                statistic.setCoursePromotionCard(BigDecimal.valueOf(0));
                statistic.setCoursePromotionCash(BigDecimal.valueOf(0));
                statistic.setCoursePromotionTotal(BigDecimal.valueOf(0));
                statistic.setCashierCard(BigDecimal.valueOf(0));
                statistic.setCashierCash(BigDecimal.valueOf(0));
                statistic.setCashierRecharge(BigDecimal.valueOf(0));
                statistic.setCashierTotal(BigDecimal.valueOf(0));
                statistic.setRepaymentCourse(BigDecimal.valueOf(0));
                statistic.setRepaymentRecharge(BigDecimal.valueOf(0));
                statistic.setRepaymentTotal(BigDecimal.valueOf(0));
                statistic.setRefundTotal(BigDecimal.valueOf(0));
                statistic.setRefundCourse(BigDecimal.valueOf(0));
                statistic.setRefundRechagre(BigDecimal.valueOf(0));
                statistic.setRefundCash(BigDecimal.valueOf(0));
                statistic.setJjzlcCard(BigDecimal.valueOf(0));
                statistic.setJjzlcCash(BigDecimal.valueOf(0));
                statistic.setCourseCardRepay(BigDecimal.valueOf(0));
                if(staffStatistics!=null){
                    if(staffStatistics.size()>0){
                        for (StaffStatistic staffStatistic2 : staffStatistics) {
                            statistic.setCourseCardRepay(statistic.getCourseCardRepay().add(staffStatistic2.getCourseCardRepay()));
                            statistic.setRecharge(statistic.getRecharge().add(staffStatistic2.getRecharge()));
                            statistic.setRechargecar(statistic.getRechargecar().add(staffStatistic2.getRechargecar()));
                            statistic.setCourseCard(statistic.getCourseCard().add(staffStatistic2.getCourseCard()));
                            statistic.setCourseCash(statistic.getCourseCash().add(staffStatistic2.getCourseCash()));
                            statistic.setCourseTotal(statistic.getCourseTotal().add(staffStatistic2.getCourseTotal()));
                            statistic.setCoursePromotionCard(statistic.getCoursePromotionCard().add(staffStatistic2.getCoursePromotionCard()));
                            statistic.setCoursePromotionCash(statistic.getCoursePromotionCash().add(staffStatistic2.getCoursePromotionCash()));
                            statistic.setCoursePromotionTotal(statistic.getCoursePromotionTotal().add(staffStatistic2.getCoursePromotionTotal()));
                            statistic.setCashierCard(statistic.getCashierCard().add(staffStatistic2.getCashierCard()));
                            statistic.setCashierCash(statistic.getCashierCash().add(staffStatistic2.getCashierCash()));
                            statistic.setCashierRecharge(statistic.getCashierRecharge().add(staffStatistic2.getCashierRecharge()));
                            statistic.setCashierTotal(statistic.getCashierTotal().add(staffStatistic2.getCashierTotal()));
                            statistic.setRepaymentCourse(statistic.getRepaymentCourse().add(staffStatistic2.getRepaymentCourse()));
                            statistic.setRepaymentRecharge(statistic.getRepaymentRecharge().add(staffStatistic2.getRepaymentRecharge()));
                            statistic.setRepaymentTotal(statistic.getRepaymentTotal().add(staffStatistic2.getRepaymentTotal()));
                            statistic.setRefundTotal(statistic.getRefundTotal().add(staffStatistic2.getRefundTotal()));
                            statistic.setRefundCourse(statistic.getRefundCourse().add(staffStatistic2.getRefundCourse()));
                            statistic.setRefundRechagre(statistic.getRefundRechagre().add(staffStatistic2.getRefundRechagre()));
                            statistic.setRefundCash(statistic.getRefundCash().add(staffStatistic2.getRefundCash()));
                            statistic.setJjzlcCard(statistic.getJjzlcCard().add(staffStatistic2.getJjzlcCard()));
                            statistic.setJjzlcCash(statistic.getJjzlcCash().add(staffStatistic2.getJjzlcCash()));

                            statistic.setCourse(statistic.getCourse().add(statistic.getJjzlcCard().add(statistic.getJjzlcCash().add(statistic.getCourseTotal().add(statistic.getCoursePromotionTotal())))));
                            statistic.setCourseRepay(statistic.getCourseRepay().add(staffStatistic2.getCourseRepay()));
                            statistic.setCourseSum(statistic.getCourseSum().add(statistic.getCourseRepay().add(statistic.getCourse())));
                        }
                    }
                }
                BaseStaff baseStaff = new BaseStaff();
                baseStaff.setId(statistic.getStaffId());

                BaseStaff baseStaff1 = ssmBaseStaffService.selectByPrimaryKey(baseStaff.getId());
                statistic.setDeptName(baseStaff1.getDeptName());
                if(statistic.getDeptName()==null || statistic.getDeptName().equals("")){
                    statistic.setDeptName(2);
                }
                statistic.setCourseRepay(statistic.getCourseRepay().subtract(statistic.getCourseCardRepay()));
                statistic.setCourseSum(statistic.getCourseSum().subtract(statistic.getCourseCardRepay()));
                statistic.setRepaymentCourse(statistic.getRepaymentCourse().subtract(statistic.getCourseCardRepay()));
                statistic.setRepaymentTotal(statistic.getRepaymentTotal().subtract(statistic.getCourseCardRepay()));
                staffStatisticLists.add(statistic);
            }
        }

        //按员工ID进行分组
        Map<Integer, List<StaffStatistic>> resultMapDept = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getDeptName));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Integer, List<StaffStatistic>>> entryIteratorDept = resultMapDept.entrySet().iterator();
        while (entryIteratorDept.hasNext()) {
            Map.Entry<Integer, List<StaffStatistic>> entry = entryIteratorDept.next();
            if(entry.getKey() == staffStatistic.getDeptName()){
                List<StaffStatistic> listByStaff = entry.getValue();
                StaffStatistic staffStatistic1 = new StaffStatistic();
                staffStatistic1.setDeptName(listByStaff.get(0).getDeptName());
                for (StaffStatistic statistic : listByStaff) {
                    if(listByStaff.get(0).getDeptName()==0){
                        statistic.setDeptNames("美发部");
                    }else  if(listByStaff.get(0).getDeptName()==1){
                        statistic.setDeptNames("美容部");
                    }else  if(listByStaff.get(0).getDeptName()==2){
                        statistic.setDeptNames("其他部");
                    }
                    staffStatisticListss.add(statistic);
                }



            }


        }
        return staffStatisticListss;
    }


    @Override
    public List<AchiCommEntity> achiCommDetailList(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<AchiCommEntity> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount =  BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount =  BigDecimalUtils.bigDecimal("0");

        Date date = staffStatistic.getDate();
        String dateStr = DateUtils.ymdFormat(date);
        //针对员工工资跳转业绩提成明细
        if (null != staffStatistic.getType()) {
            if (staffStatistic.getType() == 0) {
                //当月
                date = new Date();
                dateStr = DateUtils.ymFormat(date);
            } else if (staffStatistic.getType() == 1) {//上月
                date = DateUtils.diffMonth(new Date(), -1);
                dateStr = DateUtils.ymFormat(date);
            } else if (staffStatistic.getType() == 2) {//上上月
                date = DateUtils.diffMonth(new Date(), -2);
                dateStr = DateUtils.ymFormat(date);
            }
        }


        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();
        List<BaseGrouponCardResponse>  baseGrouponCardResponses = new ArrayList<>();
        List<ServiceOrdersResponse> serviceOrdersResponses = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);//充值卡
            courseList = ssmCourseService.selectList(storeId, dateStr, date);//疗程
            cashList = ssmCashService.selectList(storeId, dateStr, date);//收银
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);//还款
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);//充值退
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);//疗程退
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);//收银退
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);//促销
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);//加价转疗程
            //rechargeTurnCourses = ssmRechargeTurnCourseService.selectDate(storeId);
            rechargeTurnCourses = ssmRechargeTurnCourseService.selectDates(storeId,dateStr);
            baseGrouponCardResponses = ssmBaseGrouponCardService.selectDates(storeId,dateStr);//团购卡
            serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date); //查询开房收银
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCashAchi()));
                        entity.setCardAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCardAchi()));
                        entity.setCashComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCashComm()));
                        entity.setCardComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCardComm()));
                    }
                }
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            }else if ("9".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                rechargeTurnCourses = ssmRechargeTurnCourseService.selectDate(storeId);
            }else if ("10".equals(staffStatistic.getClassify())) {
                //查询团购卡
                baseGrouponCardResponses = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
            }else if ("11".equals(staffStatistic.getClassify())) {
                //查询团购卡
                serviceOrdersResponses = ssmServiceOrdersService.selectList(storeId, dateStr, date);
            }
        }
//        recList.forEach(rechargeListResponse ->);

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
            cardChangeList.getOutProjects().
                    forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                            .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        }
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        rechargeTurnCourses.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        baseGrouponCardResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        serviceOrdersResponses.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getAchiCommEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long,List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()){
            Map.Entry<Long,List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> value = entry.getValue();
                for (AchiCommEntity achiCommEntity : value) {//总业绩-卡付业绩（卡付业绩不算进总业绩）
                    achiCommEntity.setTotalPerformance(achiCommEntity.getTotalPerformance().subtract(achiCommEntity.getCardAchi()));
                }
                staffStatisticList = value;
            }
        }
        for (AchiCommEntity achiCommEntity : staffStatisticList) {
            achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm()))));
            achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
            achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi()))));
            achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
            achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance()))));
            achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission()))));
            if( achiCommEntity.getCooperationAchi()==null){
                achiCommEntity.setCooperationAchi(new BigDecimal("0"));
            }
            achiCommEntity.setCooperationAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCooperationAchi()))));
        }


        if (null == staffStatistic.getClassify() || "".equals(staffStatistic.getClassify())){
            List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
            List<AchiCommEntity> totalList1 = new ArrayList<>();

            //合并list
            cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
            while (entryIterator1.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {


                if (staffStatistic.getStaffId().equals(entry.getKey())){
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    for (AchiCommEntity achiCommEntity : listByStaff) {
                        achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm().negate()))));
                        //achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                        achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi().negate()))));
                        //achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                        achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance().negate()))));
                        achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission().negate()))));
                        if( achiCommEntity.getCooperationAchi()==null){
                            achiCommEntity.setCooperationAchi(new BigDecimal("0"));
                        }
                        achiCommEntity.setCooperationAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCooperationAchi()))));
                        staffStatisticList.add(achiCommEntity);
                    }
                }

                //}
            }

            List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList2 = new ArrayList<>();
            //合并list
            coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
            while (entryIterator2.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {

                if (staffStatistic.getStaffId().equals(entry.getKey())){
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    for (AchiCommEntity achiCommEntity : listByStaff) {
                        achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm().negate()))));
                        //achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                        achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi().negate()))));
                        //achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                        //achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance().negate()))));
                        achiCommEntity.setTotalPerformance(BigDecimal.ZERO);
                        achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission().negate()))));
                        if( achiCommEntity.getCooperationAchi()==null){
                            achiCommEntity.setCooperationAchi(new BigDecimal("0"));
                        }
                        achiCommEntity.setCooperationAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCooperationAchi()))));
                        staffStatisticList.add(achiCommEntity);
                    }
                }
            }
        }else if ("8".equals(staffStatistic.getClassify())){
            List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
            List<AchiCommEntity> totalList1 = new ArrayList<>();

            //合并list
            cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
            while (entryIterator1.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {


                if (staffStatistic.getStaffId().equals(entry.getKey())){
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    for (AchiCommEntity achiCommEntity : listByStaff) {
                        achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm().negate()))));
                        //achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                        achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi().negate()))));
                        //achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                        achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance().negate()))));
                        achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission().negate()))));
                        if( achiCommEntity.getCooperationAchi()==null){
                            achiCommEntity.setCooperationAchi(new BigDecimal("0"));
                        }
                        achiCommEntity.setCooperationAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCooperationAchi()))));
                        staffStatisticList.add(achiCommEntity);
                    }
                }

                //}
            }
        }else if ("9".equals(staffStatistic.getClassify())){
            List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList2 = new ArrayList<>();
            //合并list
            coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
            while (entryIterator2.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {

                if (staffStatistic.getStaffId().equals(entry.getKey())){
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    for (AchiCommEntity achiCommEntity : listByStaff) {
                        achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm().negate()))));
                        //achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                        achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi().negate()))));
                        //achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                        //achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance().negate()))));
                        achiCommEntity.setTotalPerformance(BigDecimal.ZERO);
                        achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission().negate()))));
                        if( achiCommEntity.getCooperationAchi()==null){
                            achiCommEntity.setCooperationAchi(new BigDecimal("0"));
                        }
                        achiCommEntity.setCooperationAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCooperationAchi()))));
                        staffStatisticList.add(achiCommEntity);
                    }
                }
            }
        }


        /*
        * List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
        List<AchiCommEntity> totalList1 = new ArrayList<>();

        //合并list
        cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
        while (entryIterator1.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
            //if (staffStatistic.getStaffId().equals(entry.getKey())) {


            if (staffStatistic.getStaffId().equals(entry.getKey())){
                List<AchiCommEntity> listByStaff = entry.getValue();
                for (AchiCommEntity achiCommEntity : listByStaff) {
                    achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm().negate()))));
                    //achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi().negate()))));
                    //achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                    achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance().negate()))));
                    achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission().negate()))));
                    staffStatisticList.add(achiCommEntity);
                }
            }

            //}
        }
        * */


        return staffStatisticList;
    }

    @Override
    public List<AchiCommEntity> departmentPerformance3(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<AchiCommEntity> staffStatisticList = new ArrayList<>();
        List<AchiCommEntity> staffStatisticLists = new ArrayList<>();
        BigDecimal achievementAmount =  BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount =  BigDecimalUtils.bigDecimal("0");

        Date date = staffStatistic.getDate();
        String dateStr = DateUtils.ymdFormat(date);
        //针对员工工资跳转业绩提成明细
        if (null != staffStatistic.getType()) {
            if (staffStatistic.getType() == 0) {
                //当月
                date = new Date();
                dateStr = DateUtils.ymFormat(date);
            } else if (staffStatistic.getType() == 1) {//上月
                date = DateUtils.diffMonth(new Date(), -1);
                dateStr = DateUtils.ymFormat(date);
            } else if (staffStatistic.getType() == 2) {//上上月
                date = DateUtils.diffMonth(new Date(), -2);
                dateStr = DateUtils.ymFormat(date);
            }
        }


        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<RefundRechargeResponse> refundRecList = new ArrayList<>();
        List<RefundCourseResponse> refundCourseList = new ArrayList<>();
        List<CashListResponse> refundCashList = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();

        List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

        if (null == staffStatistic.getClassify()) {
            recList = ssmRechargeService.selectList(storeId, dateStr, date);
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            //查询团购卡
            baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            } else if ("4".equals(staffStatistic.getClassify())) {
                //查询充值退款单业务员
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
            } else if ("5".equals(staffStatistic.getClassify())) {
                //查询疗程退款单业务员
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
            } else if ("6".equals(staffStatistic.getClassify())) {
                //查询收银退款单业务员
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCashAchi()));
                        entity.setCardAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCardAchi()));
                        entity.setCashComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCashComm()));
                        entity.setCardComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00),entity.getCardComm()));
                    }
                }
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            }else if ("10".equals(staffStatistic.getClassify())) {
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);
            }
        }
//        recList.forEach(rechargeListResponse ->);

        List<AchiCommEntity> totalList = new ArrayList<>();
        //合并list
        recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));

        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long,List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()){
            Map.Entry<Long,List<AchiCommEntity>> entry = entryIterator.next();
            BaseStaff baseStaff = new BaseStaff();
            baseStaff.setId(entry.getKey());
            BaseStaff baseStaff1 = ssmBaseStaffService.selectByPrimaryKey(baseStaff.getId());
            if (baseStaff1.getDeptName() == staffStatistic.getDeptName()) {
                List<AchiCommEntity> value = entry.getValue();
                for (AchiCommEntity achiCommEntity : value) {
                    achiCommEntity.setTotalPerformance(achiCommEntity.getTotalPerformance().subtract(achiCommEntity.getCardAchi()));
                }
                for (AchiCommEntity achiCommEntity : value) {
                    staffStatisticList.add(achiCommEntity);
                }
            }
        }
        for (AchiCommEntity achiCommEntity : staffStatisticList) {
            achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm()))));
            achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
            achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi()))));
            achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
            achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance()))));
            achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission()))));
        }

        return staffStatisticList;
    }

    @Override
    public List<AchiCommEntity> achiCommDetailLists(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<AchiCommEntity> staffStatisticLists = new ArrayList<>();

        if(staffStatistic.getStoreIds()!=null && staffStatistic.getStoreIds().size()>0) {
            for (Long storeId1 : staffStatistic.getStoreIds()) {
                staffStatistic.setStoreId(storeId1);
                List<AchiCommEntity> staffStatisticList = new ArrayList<>();
                List<AchiCommEntity> staffStatistics = new ArrayList<>();
                BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
                BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");

                Long storeId = staffStatistic.getStoreId();
                List<RechargeListResponse> recList = new ArrayList<>();
                List<CourseListResponse> courseList = new ArrayList<>();
                List<CashListResponse> cashList = new ArrayList<>();
                List<RepayTradeResponse> RepayLists = new ArrayList<>();
                List<RefundRechargeResponse> refundRecList = new ArrayList<>();
                List<RefundCourseResponse> refundCourseList = new ArrayList<>();
                List<CashListResponse> refundCashList = new ArrayList<>();
                List<DocPromotionResponse> promotionList = new ArrayList<>();
                List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
                List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();

                String dateStr = staffStatistic.getStartDate().substring(0, 7);
                String dateStr2 = staffStatistic.getEndDate().substring(0, 7);
                String dateStr3 = staffStatistic.getStartDate().substring(0, 10);
                String dateStr4 = staffStatistic.getEndDate().substring(0, 10);
                Long aLong = this.dayDiff(dateStr3, dateStr4);
                aLong =aLong+1;
                if (aLong > 0) {
                    Date d = DateUtils.ymdhmsString2DateTime(staffStatistic.getStartDate());
                    for (int i = 0; i < aLong; i++) {
                        //Date d = DateUtils.ymdhmsString2DateTime(staffStatistic.getStartDate());
//                        Date addAfterDate = addDay(d);
//                        d = addAfterDate;
                        Date addAfterDate = d;
                        if(i!=0){

                            addAfterDate = addDay(d);
                            d = addAfterDate;
                        }
                        String dateStr1 = DateUtils.ymdFormat(addAfterDate);
                        //System.out.println(s);
                        Date date = DateUtils.ymdString2Date(dateStr1);

                        if (null == staffStatistic.getClassify()) {
                            List<RechargeListResponse> recList1 = new ArrayList<>();
                            recList1 = ssmRechargeService.selectList(storeId, dateStr1, date);
                            for (RechargeListResponse cardChangeList : recList1) {
                                List<AchiCommEntity> entities = cardChangeList.getEntities();
                                for (AchiCommEntity entity : entities) {
                                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                    entity.setCardMoney(BigDecimal.valueOf(0));
                                    staffStatistics.add(entity);
                                }

                            }
                            List<CourseListResponse> courseList1 = new ArrayList<>();
                            courseList1 = ssmCourseService.selectList(storeId, dateStr1, date);
                            for (CourseListResponse cardChangeList : courseList1) {
                                List<AchiCommEntity> entities = cardChangeList.getEntities();
                                for (AchiCommEntity entity : entities) {
                                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                    staffStatistics.add(entity);
                                }
                            }
                            List<CashListResponse> cashList1 = new ArrayList<>();
                            cashList1 = ssmCashService.selectList(storeId, dateStr1, date);
                            for (CashListResponse cardChangeList : cashList1) {
                                List<AchiCommEntity> entities = cardChangeList.getEntities();
                                for (AchiCommEntity entity : entities) {
                                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                    staffStatistics.add(entity);
                                }
                            }
                            List<CashListResponse> refundCashList1 = new ArrayList<>();
                            refundCashList1 = ssmRefundCashService.selectLists(storeId, dateStr1, date);
                            for (CashListResponse cardChangeList : refundCashList1) {
                                List<AchiCommEntity> entities = cardChangeList.getEntities();
                                for (AchiCommEntity entity : entities) {
                                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                    staffStatistics.add(entity);
                                }
                            }
                        }

                    }
                } else {
                    Date date = DateUtils.ymdString2Date(dateStr3);
                    if (null == staffStatistic.getClassify()) {

                        recList = ssmRechargeService.selectList(storeId, dateStr3, date);
                        for (RechargeListResponse cardChangeList : recList) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(BigDecimal.valueOf(0));
                                staffStatistics.add(entity);
                            }

                        }

                        courseList = ssmCourseService.selectList(storeId, dateStr3, date);
                        for (CourseListResponse cardChangeList : courseList) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                staffStatistics.add(entity);
                            }
                        }

                        cashList = ssmCashService.selectList(storeId, dateStr3, date);
                        for (CashListResponse cardChangeList : cashList) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                staffStatistics.add(entity);
                            }
                        }

                        refundCashList = ssmRefundCashService.selectLists(storeId, dateStr3, date);
                        for (CashListResponse cardChangeList : refundCashList) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                staffStatistics.add(entity);
                            }
                        }
                    }
                }
                Date date = new Date();

                if (null == staffStatistic.getClassify()) {
            /*recList = ssmRechargeService.selectList(storeId, dateStr, date);
            for (RechargeListResponse cardChangeList : recList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(BigDecimal.valueOf(0));
                    staffStatistics.add(entity);
                }

            }
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            for (CourseListResponse cardChangeList : courseList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                    staffStatistics.add(entity);
                }
            }
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            for (CashListResponse cardChangeList : cashList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                    staffStatistics.add(entity);
                }
            }*/
                    RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                    for (RepayTradeResponse cardChangeList : RepayLists) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getPayMoney());
                            entity.setCardMoney(BigDecimal.valueOf(0));
                            staffStatistics.add(entity);
                        }
                    }
                    refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                    for (RefundRechargeResponse cardChangeList : refundRecList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getRecRefundMoney());
                            entity.setCardMoney(BigDecimal.valueOf(0));
                            staffStatistics.add(entity);
                        }
                    }

                    refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                    for (RefundCourseResponse cardChangeList : refundCourseList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getCourseRefundMoney());
                            entity.setCardMoney(BigDecimal.valueOf(0));
                            staffStatistics.add(entity);
                        }
                    }
                    //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            /*refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            for (CashListResponse cardChangeList : refundCashList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                    staffStatistics.add(entity);
                }
            }*/
                    promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                    for (DocPromotionResponse cardChangeList : promotionList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                            entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                            staffStatistics.add(entity);
                        }
                    }
                    //加价转疗程
                    cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                    for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getChangeInPayMoney());
                            entity.setCardMoney(cardChangeList.getChangeOutMoney());
                            staffStatistics.add(entity);
                        }
                    }

                    //加价转疗程
                    rechargeTurnCourses = ssmRechargeTurnCourseService.selectDate(storeId);
                    for (RechargeTurnCoursesResponse rechargeTurnCours : rechargeTurnCourses) {
                        List<AchiCommEntity> entities = rechargeTurnCours.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(BigDecimal.valueOf(0));
                            entity.setCardMoney(rechargeTurnCours.getRechargeInMoney());
                            staffStatistics.add(entity);
                        }
                    }
                } else {
                    if ("0".equals(staffStatistic.getClassify())) {
                        //查询充值业务员信息
                        recList = ssmRechargeService.selectList(storeId, dateStr, date);
                    } else if ("1".equals(staffStatistic.getClassify())) {
                        //查询疗程业务员信息
                        courseList = ssmCourseService.selectList(storeId, dateStr, date);
                    } else if ("2".equals(staffStatistic.getClassify())) {
                        //查询服务单业务员信息
                        cashList = ssmCashService.selectList(storeId, dateStr, date);
                    } else if ("3".equals(staffStatistic.getClassify())) {
                        //查询还款单业务员信息
                        RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                    } else if ("4".equals(staffStatistic.getClassify())) {
                        //查询充值退款单业务员
                        refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                    } else if ("5".equals(staffStatistic.getClassify())) {
                        //查询疗程退款单业务员
                        refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                    } else if ("6".equals(staffStatistic.getClassify())) {
                        //查询收银退款单业务员
                        //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                        refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
                        for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCashAchi()));
                                entity.setCardAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCardAchi()));
                                entity.setCashComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCashComm()));
                                entity.setCardComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCardComm()));
                            }
                        }
                    } else if ("7".equals(staffStatistic.getClassify())) {
                        //查询促销单业务员
                        promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                    } else if ("8".equals(staffStatistic.getClassify())) {
                        //查询加价转疗程单业务员
                        cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                    }
                }

                List<AchiCommEntity> list1 = new ArrayList<>();
                for (AchiCommEntity achiCommEntity : staffStatistics) {
                    if (achiCommEntity.getSaleStaffName().equals("凌寒枫")) {
                        list1.add(achiCommEntity);
                    }
                }

                List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId, dateStr);
                for (CardChangeOutProjectResponse changeOutProjectResponse : cardChangeOutLists) {
                    List<AchiCommEntity> entities = changeOutProjectResponse.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(BigDecimal.valueOf(0));
                        entity.setCardMoney(BigDecimal.valueOf(0));
                        entity.setTotalCommission(entity.getTotalCommission().negate());
                        staffStatistics.add(entity);
                    }

                }
                List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
                for (CoursePayListResponse coursePayListResponse : coursePayListResponses) {
                    List<AchiCommEntity> entities = coursePayListResponse.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(BigDecimal.valueOf(0));
                        entity.setCardMoney(BigDecimal.valueOf(0));
                        entity.setTotalCommission(entity.getTotalCommission().negate());
                        staffStatistics.add(entity);
                    }

                }

                for (AchiCommEntity achiCommEntity : staffStatistics) {
                    achiCommEntity.setTotalPerformance(achiCommEntity.getTotalPerformance().subtract(achiCommEntity.getCardAchi()));
                    staffStatisticList.add(achiCommEntity);
                }
                List<AchiCommEntity> list = new ArrayList<>();
                for (AchiCommEntity achiCommEntity : staffStatisticList) {
                    if (achiCommEntity.getSaleStaffName().equals("凌寒枫")) {
                        list.add(achiCommEntity);
                    }
                }
                for (AchiCommEntity achiCommEntity : staffStatisticList) {
                    achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm()))));
                    achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi()))));
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                    achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance()))));
                    achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission()))));
                    boolean effectiveDate = this.isEffectiveDate(achiCommEntity.getDocDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        staffStatisticLists.add(achiCommEntity);
                    }

                }
            }
        }
        else {
            List<AchiCommEntity> staffStatisticList = new ArrayList<>();
            List<AchiCommEntity> staffStatistics = new ArrayList<>();
            BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
            BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");

            Long storeId = staffStatistic.getStoreId();
            List<RechargeListResponse> recList = new ArrayList<>();
            List<CourseListResponse> courseList = new ArrayList<>();
            List<CashListResponse> cashList = new ArrayList<>();
            List<RepayTradeResponse> RepayLists = new ArrayList<>();
            List<RefundRechargeResponse> refundRecList = new ArrayList<>();
            List<RefundCourseResponse> refundCourseList = new ArrayList<>();
            List<CashListResponse> refundCashList = new ArrayList<>();
            List<DocPromotionResponse> promotionList = new ArrayList<>();
            List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
            List<RechargeTurnCoursesResponse> rechargeTurnCourses = new ArrayList<>();

            String dateStr = staffStatistic.getStartDate().substring(0, 7);
            String dateStr2 = staffStatistic.getEndDate().substring(0, 7);
            String dateStr3 = staffStatistic.getStartDate().substring(0, 10);
            String dateStr4 = staffStatistic.getEndDate().substring(0, 10);
            Long aLong = this.dayDiff(dateStr3, dateStr4);
            aLong =aLong+1;
            if (aLong > 0) {
                Date d = DateUtils.ymdhmsString2DateTime(staffStatistic.getStartDate());
                for (int i = 0; i < aLong; i++) {
                    //Date d = DateUtils.ymdhmsString2DateTime(staffStatistic.getStartDate());
                    Date addAfterDate = d;
                    if(i!=0){

                        addAfterDate = addDay(d);
                        d = addAfterDate;
                    }
                    String dateStr1 = DateUtils.ymdFormat(addAfterDate);
                    //System.out.println(s);
                    Date date = DateUtils.ymdString2Date(dateStr1);

                    if (null == staffStatistic.getClassify()) {
                        List<RechargeListResponse> recList1 = new ArrayList<>();
                        recList1 = ssmRechargeService.selectList(storeId, dateStr1, date);
                        for (RechargeListResponse cardChangeList : recList1) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(BigDecimal.valueOf(0));
                                staffStatistics.add(entity);
                            }

                        }
                        List<CourseListResponse> courseList1 = new ArrayList<>();
                        courseList1 = ssmCourseService.selectList(storeId, dateStr1, date);
                        for (CourseListResponse cardChangeList : courseList1) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                staffStatistics.add(entity);
                            }
                        }
                        List<CashListResponse> cashList1 = new ArrayList<>();
                        cashList1 = ssmCashService.selectList(storeId, dateStr1, date);
                        for (CashListResponse cardChangeList : cashList1) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                staffStatistics.add(entity);
                            }
                        }
                        List<CashListResponse> refundCashList1 = new ArrayList<>();
                        refundCashList1 = ssmRefundCashService.selectLists(storeId, dateStr1, date);
                        for (CashListResponse cardChangeList : refundCashList1) {
                            List<AchiCommEntity> entities = cardChangeList.getEntities();
                            for (AchiCommEntity entity : entities) {
                                entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                                entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                                staffStatistics.add(entity);
                            }
                        }
                    }

                }
            } else {
                Date date = DateUtils.ymdString2Date(dateStr3);
                if (null == staffStatistic.getClassify()) {

                    recList = ssmRechargeService.selectList(storeId, dateStr3, date);
                    for (RechargeListResponse cardChangeList : recList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                            entity.setCardMoney(BigDecimal.valueOf(0));
                            staffStatistics.add(entity);
                        }

                    }

                    courseList = ssmCourseService.selectList(storeId, dateStr3, date);
                    for (CourseListResponse cardChangeList : courseList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                            entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                            staffStatistics.add(entity);
                        }
                    }

                    cashList = ssmCashService.selectList(storeId, dateStr3, date);
                    for (CashListResponse cardChangeList : cashList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                            entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                            staffStatistics.add(entity);
                        }
                    }

                    refundCashList = ssmRefundCashService.selectLists(storeId, dateStr3, date);
                    for (CashListResponse cardChangeList : refundCashList) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                            entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                            staffStatistics.add(entity);
                        }
                    }
                }
            }
            Date date = new Date();

            if (null == staffStatistic.getClassify()) {
            /*recList = ssmRechargeService.selectList(storeId, dateStr, date);
            for (RechargeListResponse cardChangeList : recList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(BigDecimal.valueOf(0));
                    staffStatistics.add(entity);
                }

            }
            courseList = ssmCourseService.selectList(storeId, dateStr, date);
            for (CourseListResponse cardChangeList : courseList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                    staffStatistics.add(entity);
                }
            }
            cashList = ssmCashService.selectList(storeId, dateStr, date);
            for (CashListResponse cardChangeList : cashList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                    staffStatistics.add(entity);
                }
            }*/
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                for (RepayTradeResponse cardChangeList : RepayLists) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(cardChangeList.getPayMoney());
                        entity.setCardMoney(BigDecimal.valueOf(0));
                        staffStatistics.add(entity);
                    }
                }
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                for (RefundRechargeResponse cardChangeList : refundRecList) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(cardChangeList.getRecRefundMoney());
                        entity.setCardMoney(BigDecimal.valueOf(0));
                        staffStatistics.add(entity);
                    }
                }

                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                for (RefundCourseResponse cardChangeList : refundCourseList) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(cardChangeList.getCourseRefundMoney());
                        entity.setCardMoney(BigDecimal.valueOf(0));
                        staffStatistics.add(entity);
                    }
                }
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
            /*refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
            for (CashListResponse cardChangeList : refundCashList) {
                List<AchiCommEntity> entities = cardChangeList.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                    entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                    staffStatistics.add(entity);
                }
            }*/
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                for (DocPromotionResponse cardChangeList : promotionList) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(cardChangeList.getCollectionCashAmount());
                        entity.setCardMoney(cardChangeList.getCollectionRechargeAmount());
                        staffStatistics.add(entity);
                    }
                }
                //加价转疗程
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                    List<AchiCommEntity> entities = cardChangeList.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(cardChangeList.getChangeInPayMoney());
                        entity.setCardMoney(cardChangeList.getChangeOutMoney());
                        staffStatistics.add(entity);
                    }
                }

                //加价转疗程
                rechargeTurnCourses = ssmRechargeTurnCourseService.selectDate(storeId);
                for (RechargeTurnCoursesResponse rechargeTurnCours : rechargeTurnCourses) {
                    List<AchiCommEntity> entities = rechargeTurnCours.getEntities();
                    for (AchiCommEntity entity : entities) {
                        entity.setCashMoney(BigDecimal.valueOf(0));
                        entity.setCardMoney(rechargeTurnCours.getRechargeInMoney());
                        staffStatistics.add(entity);
                    }
                }
            } else {
                if ("0".equals(staffStatistic.getClassify())) {
                    //查询充值业务员信息
                    recList = ssmRechargeService.selectList(storeId, dateStr, date);
                } else if ("1".equals(staffStatistic.getClassify())) {
                    //查询疗程业务员信息
                    courseList = ssmCourseService.selectList(storeId, dateStr, date);
                } else if ("2".equals(staffStatistic.getClassify())) {
                    //查询服务单业务员信息
                    cashList = ssmCashService.selectList(storeId, dateStr, date);
                } else if ("3".equals(staffStatistic.getClassify())) {
                    //查询还款单业务员信息
                    RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                } else if ("4".equals(staffStatistic.getClassify())) {
                    //查询充值退款单业务员
                    refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                } else if ("5".equals(staffStatistic.getClassify())) {
                    //查询疗程退款单业务员
                    refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                } else if ("6".equals(staffStatistic.getClassify())) {
                    //查询收银退款单业务员
                    //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                    refundCashList = ssmRefundCashService.selectLists(storeId, dateStr, date);
                    for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                        List<AchiCommEntity> entities = cardChangeList.getEntities();
                        for (AchiCommEntity entity : entities) {
                            entity.setCashAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCashAchi()));
                            entity.setCardAchi(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCardAchi()));
                            entity.setCashComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCashComm()));
                            entity.setCardComm(BigDecimalUtils.subtract(BigDecimal.valueOf(0.00), entity.getCardComm()));
                        }
                    }
                } else if ("7".equals(staffStatistic.getClassify())) {
                    //查询促销单业务员
                    promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                } else if ("8".equals(staffStatistic.getClassify())) {
                    //查询加价转疗程单业务员
                    cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
                }
            }

            List<AchiCommEntity> list1 = new ArrayList<>();
            for (AchiCommEntity achiCommEntity : staffStatistics) {
                if (achiCommEntity.getSaleStaffName().equals("凌寒枫")) {
                    list1.add(achiCommEntity);
                }
            }

            List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId, dateStr);
            for (CardChangeOutProjectResponse changeOutProjectResponse : cardChangeOutLists) {
                List<AchiCommEntity> entities = changeOutProjectResponse.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(BigDecimal.valueOf(0));
                    entity.setCardMoney(BigDecimal.valueOf(0));
                    entity.setTotalCommission(entity.getTotalCommission().negate());
                    staffStatistics.add(entity);
                }

            }
            List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
            for (CoursePayListResponse coursePayListResponse : coursePayListResponses) {
                List<AchiCommEntity> entities = coursePayListResponse.getEntities();
                for (AchiCommEntity entity : entities) {
                    entity.setCashMoney(BigDecimal.valueOf(0));
                    entity.setCardMoney(BigDecimal.valueOf(0));
                    entity.setTotalCommission(entity.getTotalCommission().negate());
                    staffStatistics.add(entity);
                }

            }

            for (AchiCommEntity achiCommEntity : staffStatistics) {
                achiCommEntity.setTotalPerformance(achiCommEntity.getTotalPerformance().subtract(achiCommEntity.getCardAchi()));
                staffStatisticList.add(achiCommEntity);
            }
            List<AchiCommEntity> list = new ArrayList<>();
            for (AchiCommEntity achiCommEntity : staffStatisticList) {
                if (achiCommEntity.getSaleStaffName().equals("凌寒枫")) {
                    list.add(achiCommEntity);
                }
            }
            for (AchiCommEntity achiCommEntity : staffStatisticList) {
                achiCommEntity.setCardComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardComm()))));
                achiCommEntity.setCashComm(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashComm()))));
                achiCommEntity.setCardAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCardAchi()))));
                achiCommEntity.setCashAchi(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getCashAchi()))));
                achiCommEntity.setTotalPerformance(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalPerformance()))));
                achiCommEntity.setTotalCommission(BigDecimal.valueOf(Double.valueOf(String.format("%.2f", achiCommEntity.getTotalCommission()))));
                boolean effectiveDate = this.isEffectiveDate(achiCommEntity.getDocDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    staffStatisticLists.add(achiCommEntity);
                }

            }
        }

        return staffStatisticLists;
    }

    @Override
    public PaegList selectAbnormalOrder(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<AchiCommEntity> staffStatisticList = new ArrayList<>();
        List<AbnormalBill> abnormalBills = new ArrayList<>();
        List<AbnormalBill> abnormalBillList = new ArrayList<>();
        List<AbnormalBill> abnormalBillLists = new ArrayList<>();
        BigDecimal achievementAmount =  BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount =  BigDecimalUtils.bigDecimal("0");

//根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getStartDate().substring(0, 7);
        Date date = new Date();
//        if (0 == type) {
//            //上月
//            date = DateUtils.diffMonth(new Date(), -1);
//            dateStr = DateUtils.ymFormat(date);
//        } else if (1 == type) {
//            //昨日
//            date = DateUtils.diffDay(new Date(), -1);
//            dateStr = DateUtils.ymdFormat(date);
//        } else if (2 == type) {
//            //今日
//            dateStr = DateUtils.ymdFormat(date);
//        } else {
//            //当月
//            dateStr = DateUtils.ymFormat(date);
//        }

        //分离查询时使用 否则按月查询分组时分出多个时间组
//        if (null != staffStatistic.getDate()){
//            date = staffStatistic.getDate();
//            dateStr = DateUtils.ymdFormat(date);
//        }


        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCoursesResponses = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            //查询异常单
            recList = ssmRechargeService.selectListAbnormal(storeId, dateStr, date);
            courseList = ssmCourseService.selectListAbnormal(storeId, dateStr, date);
            cashList = ssmCashService.selectListAbnormal(storeId, dateStr, date);
            RepayLists = ssmRepayService.selectListAbnormal(storeId, dateStr, null);
            promotionList = ssmDocPromotionService.selectListAbnormal(storeId, dateStr);
            //加价转疗程
            cardChangeLists = ssmCardChangeService.selectListAbnormal(storeId, dateStr);
            //疗程转充值
            rechargeTurnCoursesResponses = ssmRechargeTurnCourseService.selectDate(storeId);
        } else {
            if ("0".equals(staffStatistic.getClassify())) {
                //查询充值业务员信息
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
            } else if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
            } else if ("2".equals(staffStatistic.getClassify())) {
                //查询服务单业务员信息
                cashList = ssmCashService.selectList(storeId, dateStr, date);
            } else if ("3".equals(staffStatistic.getClassify())) {
                //查询还款单业务员信息
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
            }else if ("7".equals(staffStatistic.getClassify())) {
                //查询促销单业务员
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
            }else if ("8".equals(staffStatistic.getClassify())) {
                //查询加价转疗程单业务员
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
            }
        }

        for (RechargeListResponse rechargeListResponse : recList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(rechargeListResponse.getErrorMessage());
            abnormalBill.setId(rechargeListResponse.getId());
            abnormalBill.setStatu(rechargeListResponse.getIsCancel());
            abnormalBill.setType(0);
            abnormalBill.setDocNum(rechargeListResponse.getRechargeNum());
            abnormalBill.setDate(rechargeListResponse.getRechargeDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(rechargeListResponse.getMemberName());
            abnormalBill.setMobilePhone(rechargeListResponse.getMobilePhone());
            abnormalBill.setMoney(rechargeListResponse.getCollectionAmount());
            abnormalBill.setCashMoney(rechargeListResponse.getCollectionCashAmount());
            abnormalBill.setDebtMoney(rechargeListResponse.getDebtMoney());
            abnormalBill.setStoreName(rechargeListResponse.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (CourseListResponse course : courseList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(course.getErrorMessage());
            abnormalBill.setId(course.getId());
            abnormalBill.setStatu(course.getIsCancel());
            abnormalBill.setType(1);
            abnormalBill.setDocNum(course.getCourseReatmentNum());
            abnormalBill.setDate(course.getDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(course.getMemberName());
            abnormalBill.setMobilePhone(course.getMobilePhone());
            abnormalBill.setMoney(course.getCourseReatmentAmount());
            abnormalBill.setCashMoney(course.getCollectionCashAmount());
            abnormalBill.setDebtMoney(course.getDebtMoney());
            abnormalBill.setStoreName(course.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (CashListResponse cash : cashList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(cash.getErrorMessage());
            abnormalBill.setProject(cash.getProject());

            abnormalBill.setId(cash.getId());
            abnormalBill.setStatu(cash.getIsCancel());
            abnormalBill.setType(2);
            abnormalBill.setDocNum(cash.getCashNum());
            abnormalBill.setDate(cash.getCashDate());
            if(cash.getCashNumber()==0){
                abnormalBill.setIfMember(1);
            }else{
                abnormalBill.setIfMember(0);
            }

            abnormalBill.setMemberName(cash.getMemberName());
            abnormalBill.setMobilePhone(cash.getMobilePhone());
            abnormalBill.setMoney(cash.getCollectionCashAmount().add(cash.getCollectionRechargeAmount()));
            abnormalBill.setCashMoney(cash.getCollectionCashAmount());
            abnormalBill.setDebtMoney(BigDecimal.valueOf(0));
            abnormalBill.setStoreName(cash.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (RepayTradeResponse Repay : RepayLists) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(Repay.getErrorMessage());
            abnormalBill.setId(Repay.getId());
            RepayList repayList = new RepayList();
            repayList.setRepayNum(Repay.getRepayNum());
            repayList.setStoreId(Repay.getStoreId());
            RepayList repayList1 = ssmRepayService.selectOne(repayList);
            abnormalBill.setStatu(repayList1.getIsCancel());
            abnormalBill.setType(3);
            abnormalBill.setDocNum(Repay.getRepayNum());
            abnormalBill.setDate(Repay.getRepayDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(Repay.getMemberName());
            abnormalBill.setMobilePhone(Repay.getMobilePhone());
            abnormalBill.setMoney(Repay.getPayMoney());
            abnormalBill.setCashMoney(Repay.getPayMoney());
            abnormalBill.setDebtMoney(Repay.getPayMoney());
            abnormalBill.setStoreName(Repay.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (DocPromotionResponse promotion : promotionList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(promotion.getErrorMessage());
            abnormalBill.setId(promotion.getId());
            abnormalBill.setStatu(promotion.getIsCancel());
            abnormalBill.setType(4);
            abnormalBill.setDocNum(promotion.getDocNum());
            abnormalBill.setDate(promotion.getDocDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(promotion.getMemberName());
            abnormalBill.setMobilePhone(promotion.getMobilePhone());
            abnormalBill.setMoney(promotion.getCollectionCashAmount().add(promotion.getCollectionRechargeAmount()));
            abnormalBill.setCashMoney(promotion.getCollectionCashAmount());
            abnormalBill.setDebtMoney(BigDecimal.valueOf(0));
            abnormalBill.setStoreName(promotion.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (CardChangeInProjectResponse changeInProject : cardChangeLists) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(changeInProject.getErrorMessage());
            abnormalBill.setId(changeInProject.getId());

            CardChangeList cardChangeList = new CardChangeList();
            cardChangeList.setDocNum(changeInProject.getDocNum());
            cardChangeList.setStoreId(changeInProject.getStoreId());
            CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
            abnormalBill.setStatu(cardChangeList1.getIsCancel());
            abnormalBill.setType(5);
            abnormalBill.setDocNum(changeInProject.getDocNum());
            abnormalBill.setDate(changeInProject.getDocDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(changeInProject.getMemberName());
            abnormalBill.setMobilePhone(changeInProject.getMobilePhone());
            abnormalBill.setMoney(changeInProject.getChangeInPayMoney().add(changeInProject.getChangeOutMoney()));
            abnormalBill.setCashMoney(changeInProject.getChangeInPayMoney());
            abnormalBill.setDebtMoney(changeInProject.getDebtMoney());
            abnormalBill.setStoreName(changeInProject.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (RechargeTurnCoursesResponse rechargeTurnCoursesResponse : rechargeTurnCoursesResponses) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(rechargeTurnCoursesResponse.getErrorMessage());
            abnormalBill.setId(rechargeTurnCoursesResponse.getId());

            CardChangeList cardChangeList = new CardChangeList();
            cardChangeList.setDocNum(rechargeTurnCoursesResponse.getDocNum());
            cardChangeList.setStoreId(rechargeTurnCoursesResponse.getStoreId());
            abnormalBill.setStatu(rechargeTurnCoursesResponse.getState());
            abnormalBill.setType(6);
            abnormalBill.setDocNum(rechargeTurnCoursesResponse.getDocNum());
            abnormalBill.setDate(rechargeTurnCoursesResponse.getDocDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(rechargeTurnCoursesResponse.getMemberName());
            abnormalBill.setMobilePhone(rechargeTurnCoursesResponse.getMobilePhone());
            abnormalBill.setMoney(rechargeTurnCoursesResponse.getRechargeInMoney());
            abnormalBill.setCashMoney(BigDecimalUtils.bigDecimal("0"));
            abnormalBill.setDebtMoney(BigDecimalUtils.bigDecimal("0"));
            abnormalBill.setStoreName(rechargeTurnCoursesResponse.getStoreName());
            abnormalBills.add(abnormalBill);
        }

        for (AbnormalBill abnormalBill : abnormalBills) {
            boolean effectiveDate = this.isEffectiveDate(abnormalBill.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if(effectiveDate){
                abnormalBillList.add(abnormalBill);
            }
        }
        PaegList paegList = new PaegList();
        paegList.setPageNum(staffStatistic.getPageNum());
        paegList.setPageSize(staffStatistic.getPageSize());
        if(null != staffStatistic.getMumberName() || null != staffStatistic.getMobilePhone() || null != staffStatistic.getDocNum()){
            for (AbnormalBill abnormalBill : abnormalBills)  {
                if(null != staffStatistic.getMumberName()){
                    Pattern pattern = Pattern.compile(staffStatistic.getMumberName());
                    Matcher matcher = pattern.matcher((abnormalBill).getMemberName());
                    if(matcher.find()){
                        abnormalBillLists.add(abnormalBill);
                    }
                }
                if(null != staffStatistic.getMobilePhone()){
                    Pattern pattern1 = Pattern.compile(staffStatistic.getMobilePhone());
                    Matcher matcher = pattern1.matcher((abnormalBill).getMobilePhone());
                    if(matcher.find()){
                        abnormalBillLists.add(abnormalBill);
                    }
                }
                if(null != staffStatistic.getDocNum()){
                    Pattern pattern2 = Pattern.compile(staffStatistic.getDocNum());
                    Matcher matcher = pattern2.matcher((abnormalBill).getDocNum());
                    if(matcher.find()){
                        abnormalBillLists.add(abnormalBill);
                    }
                }
            }
            paegList.setTotal(abnormalBillLists.size());
            List<AbnormalBill> page = page(abnormalBillLists, staffStatistic.getPageSize(), staffStatistic.getPageNum());
            paegList.setList(page);
            return paegList;
        }else{
            paegList.setTotal(abnormalBillList.size());
            List<AbnormalBill> page = page(abnormalBillList, staffStatistic.getPageSize(), staffStatistic.getPageNum());
            paegList.setList(page);
            return paegList;
        }



    }

    @Override
    public PaegList selectAbnormalOrderNew(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<AchiCommEntity> staffStatisticList = new ArrayList<>();
        List<AbnormalBill> abnormalBills = new ArrayList<>();
        List<AbnormalBill> abnormalBillList = new ArrayList<>();
        List<AbnormalBill> abnormalBillLists = new ArrayList<>();
        BigDecimal achievementAmount =  BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount =  BigDecimalUtils.bigDecimal("0");

        List<Long> lists = new ArrayList<>();
        if(staffStatistic.getSelectType()==0){
            lists=staffStatistic.getStoreList();
        }else{
            BaseStore baseStore1 = ssmBaseStoreService.selectByPrimaryKey(staffStatistic.getStoreId());
            if(null == baseStore1.getParentId()&&(staffStatistic.getStoreList().size()<0||staffStatistic.getStoreList()==null)){
                StoreRequest storeRequest = new StoreRequest();
                storeRequest.setId(staffStatistic.getStoreId());
                List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
                List<Long> collect = pagesorganizations.stream().map(BaseStores::getId).collect(Collectors.toList());
                lists=collect;
            }else{
                lists.add(staffStatistic.getStoreId());
            }
        }

//根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = dateFormat.parse(staffStatistic.getStartDate());
        Date endTime = dateFormat.parse(staffStatistic.getEndDate());
//        if (0 == type) {
//            //上月
//            date = DateUtils.diffMonth(new Date(), -1);
//            dateStr = DateUtils.ymFormat(date);
//        } else if (1 == type) {
//            //昨日
//            date = DateUtils.diffDay(new Date(), -1);
//            dateStr = DateUtils.ymdFormat(date);
//        } else if (2 == type) {
//            //今日
//            dateStr = DateUtils.ymdFormat(date);
//        } else {
//            //当月
//            dateStr = DateUtils.ymFormat(date);
//        }

        //分离查询时使用 否则按月查询分组时分出多个时间组
//        if (null != staffStatistic.getDate()){
//            date = staffStatistic.getDate();
//            dateStr = DateUtils.ymdFormat(date);
//        }


        Long storeId = staffStatistic.getStoreId();
        List<RechargeListResponse> recList = new ArrayList<>();
        List<CourseListResponse> courseList = new ArrayList<>();
        List<CashListResponse> cashList = new ArrayList<>();
        List<RepayTradeResponse> RepayLists = new ArrayList<>();
        List<DocPromotionResponse> promotionList = new ArrayList<>();
        List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
        List<RechargeTurnCoursesResponse> rechargeTurnCoursesResponses = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            //查询异常单
            for (Long list : lists) {
                recList.addAll(ssmRechargeService.selectListAbnormal(list, dateStr, date));
                courseList.addAll(ssmCourseService.selectListAbnormal(list, dateStr, date));
//                cashList.addAll(ssmCashService.selectListAbnormal(list, dateStr, date));
                cashList.addAll(ssmCashService.selectListAbnormalNew(list,date,endTime));
                RepayLists.addAll(ssmRepayService.selectListAbnormal(list, dateStr, null));
                promotionList.addAll(ssmDocPromotionService.selectListAbnormal(list, dateStr));
                //加价转疗程
                cardChangeLists.addAll(ssmCardChangeService.selectListAbnormal(list, dateStr));
                //疗程转充值
                rechargeTurnCoursesResponses.addAll(ssmRechargeTurnCourseService.selectDate(list));
            }
        }
        else {
            for (Long list : lists) { //门店ID
                if ("0".equals(staffStatistic.getClassify())) {
                    //查询充值业务员信息
                    recList.addAll(ssmRechargeService.selectList(list, dateStr, date));
                } else if ("1".equals(staffStatistic.getClassify())) {
                    //查询疗程业务员信息
                    courseList.addAll(ssmCourseService.selectList(list, dateStr, date));
                } else if ("2".equals(staffStatistic.getClassify())) {
                    //查询服务单业务员信息
                    cashList.addAll(ssmCashService.selectList(list, dateStr, date));
                } else if ("3".equals(staffStatistic.getClassify())) {
                    //查询还款单业务员信息
                    RepayLists.addAll(ssmRepayService.selectList(list, dateStr, null));
                }else if ("7".equals(staffStatistic.getClassify())) {
                    //查询促销单业务员
                    promotionList.addAll(ssmDocPromotionService.selectList(list, dateStr));
                }else if ("8".equals(staffStatistic.getClassify())) {
                    //查询加价转疗程单业务员
                    cardChangeLists.addAll(ssmCardChangeService.selectList(list, dateStr));
                }
            }
        }

        for (RechargeListResponse rechargeListResponse : recList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(rechargeListResponse.getErrorMessage());
            PayList payList = new PayList();
            payList.setDocId(rechargeListResponse.getRechargeNum());
            List<PayList> select = ssmPayService.select(payList);
            abnormalBill.setPayList(select);
            abnormalBill.setId(rechargeListResponse.getId());
            abnormalBill.setStatu(rechargeListResponse.getIsCancel());
            abnormalBill.setType(0);
            abnormalBill.setDocNum(rechargeListResponse.getRechargeNum());
            abnormalBill.setDate(rechargeListResponse.getRechargeDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(rechargeListResponse.getMemberName());
            abnormalBill.setMobilePhone(rechargeListResponse.getMobilePhone());
            abnormalBill.setMoney(rechargeListResponse.getCollectionAmount());
            abnormalBill.setCashMoney(rechargeListResponse.getCollectionCashAmount());
            abnormalBill.setDebtMoney(rechargeListResponse.getDebtMoney());
            abnormalBill.setStoreName(rechargeListResponse.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (CourseListResponse course : courseList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(course.getErrorMessage());
            PayList payList = new PayList();
            payList.setDocId(course.getCourseReatmentNum());
            List<PayList> select = ssmPayService.select(payList);
            abnormalBill.setPayList(select);
            abnormalBill.setProject(course.getProject());
            abnormalBill.setProject(course.getProject());
            abnormalBill.setId(course.getId());
            abnormalBill.setStatu(course.getIsCancel());
            abnormalBill.setType(1);
            abnormalBill.setDocNum(course.getCourseReatmentNum());
            abnormalBill.setDate(course.getDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(course.getMemberName());
            abnormalBill.setMobilePhone(course.getMobilePhone());
            abnormalBill.setMoney(course.getCourseReatmentAmount());
            abnormalBill.setCashMoney(course.getCollectionCashAmount());
            abnormalBill.setDebtMoney(course.getDebtMoney());
            abnormalBill.setStoreName(course.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (CashListResponse cash : cashList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(cash.getErrorMessage());
            abnormalBill.setProject(cash.getProject());
            abnormalBill.setId(cash.getId());
            abnormalBill.setStatu(cash.getIsCancel());
            abnormalBill.setType(2);
            abnormalBill.setDocNum(cash.getCashNum());
            abnormalBill.setDate(cash.getCashDate());
            if(cash.getCashNumber()==0){
                abnormalBill.setIfMember(1);
            }else{
                abnormalBill.setIfMember(0);
            }
            PayList payList = new PayList();
            payList.setDocId(cash.getCashNum());
            List<PayList> select = ssmPayService.select(payList);
            abnormalBill.setPayList(select);
            abnormalBill.setMemberName(cash.getMemberName());
            abnormalBill.setMobilePhone(cash.getMobilePhone());
            abnormalBill.setMoney(cash.getCollectionCashAmount().add(cash.getCollectionRechargeAmount()));
            abnormalBill.setCashMoney(cash.getCollectionCashAmount());
            abnormalBill.setDebtMoney(BigDecimal.valueOf(0));
            abnormalBill.setStoreName(cash.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (RepayTradeResponse Repay : RepayLists) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(Repay.getErrorMessage());
            if(Repay.getProject()!=null){
                abnormalBill.setProject(Repay.getProject());
            }
//            PayList payList = new PayList();
//            payList.setDocId(cash.getCashNum());
//            List<PayList> select = ssmPayService.select(payList);
//            abnormalBill.setPayList(select);
            abnormalBill.setId(Repay.getId());
            RepayList repayList = new RepayList();
            repayList.setRepayNum(Repay.getRepayNum());
            repayList.setStoreId(Repay.getStoreId());
            RepayList repayList1 = ssmRepayService.selectOne(repayList);
            abnormalBill.setStatu(repayList1.getIsCancel());
            abnormalBill.setType(3);
            abnormalBill.setDocNum(Repay.getRepayNum());
            abnormalBill.setDate(Repay.getRepayDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(Repay.getMemberName());
            abnormalBill.setMobilePhone(Repay.getMobilePhone());
            abnormalBill.setMoney(Repay.getPayMoney());
            abnormalBill.setCashMoney(Repay.getPayMoney());
            abnormalBill.setDebtMoney(Repay.getPayMoney());
            abnormalBill.setStoreName(Repay.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (DocPromotionResponse promotion : promotionList) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(promotion.getErrorMessage());
            PayList payList = new PayList();
            payList.setDocId(String.valueOf(promotion.getId()));
            List<PayList> select = ssmPayService.select(payList);
            abnormalBill.setPayList(select);
            abnormalBill.setId(promotion.getId());
            abnormalBill.setStatu(promotion.getIsCancel());
            abnormalBill.setType(4);
            abnormalBill.setDocNum(promotion.getDocNum());
            abnormalBill.setDate(promotion.getDocDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(promotion.getMemberName());
            abnormalBill.setMobilePhone(promotion.getMobilePhone());
            abnormalBill.setMoney(promotion.getCollectionCashAmount().add(promotion.getCollectionRechargeAmount()));
            abnormalBill.setCashMoney(promotion.getCollectionCashAmount());
            abnormalBill.setDebtMoney(BigDecimal.valueOf(0));
            abnormalBill.setStoreName(promotion.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (CardChangeInProjectResponse changeInProject : cardChangeLists) {

            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(changeInProject.getErrorMessage());
            PayList payList = new PayList();
            payList.setDocId(changeInProject.getDocNum());
            List<PayList> select = ssmPayService.select(payList);
            abnormalBill.setPayList(select);

            abnormalBill.setId(changeInProject.getId());
            abnormalBill.setProject(changeInProject.getProject());
            CardChangeList cardChangeList = new CardChangeList();
            cardChangeList.setDocNum(changeInProject.getDocNum());
            cardChangeList.setStoreId(changeInProject.getStoreId());
            CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
            abnormalBill.setStatu(cardChangeList1.getState());
            abnormalBill.setType(5);
            abnormalBill.setDocNum(changeInProject.getDocNum());
            abnormalBill.setDate(changeInProject.getDocDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(changeInProject.getMemberName());
            abnormalBill.setMobilePhone(changeInProject.getMobilePhone());
            abnormalBill.setMoney(changeInProject.getChangeInPayMoney().add(changeInProject.getChangeOutMoney()));
            abnormalBill.setCashMoney(changeInProject.getChangeInPayMoney());
            abnormalBill.setDebtMoney(changeInProject.getDebtMoney());
            abnormalBill.setStoreName(changeInProject.getStoreName());
            abnormalBills.add(abnormalBill);
        }
        for (RechargeTurnCoursesResponse rechargeTurnCoursesResponse : rechargeTurnCoursesResponses) {
            AbnormalBill abnormalBill = new AbnormalBill();
            abnormalBill.setErrorMessage(rechargeTurnCoursesResponse.getErrorMessage());
            abnormalBill.setId(rechargeTurnCoursesResponse.getId());

            CardChangeList cardChangeList = new CardChangeList();
            cardChangeList.setDocNum(rechargeTurnCoursesResponse.getDocNum());
            cardChangeList.setStoreId(rechargeTurnCoursesResponse.getStoreId());
            abnormalBill.setStatu(rechargeTurnCoursesResponse.getState());
            abnormalBill.setType(6);
            abnormalBill.setDocNum(rechargeTurnCoursesResponse.getDocNum());
            abnormalBill.setDate(rechargeTurnCoursesResponse.getDocDate());
            abnormalBill.setIfMember(0);
            abnormalBill.setMemberName(rechargeTurnCoursesResponse.getMemberName());
            abnormalBill.setMobilePhone(rechargeTurnCoursesResponse.getMobilePhone());
            abnormalBill.setMoney(rechargeTurnCoursesResponse.getRechargeInMoney());
            abnormalBill.setCashMoney(BigDecimalUtils.bigDecimal("0"));
            abnormalBill.setDebtMoney(BigDecimalUtils.bigDecimal("0"));
            abnormalBill.setStoreName(rechargeTurnCoursesResponse.getStoreName());
            abnormalBills.add(abnormalBill);
        }

        for (AbnormalBill abnormalBill : abnormalBills) {
            boolean effectiveDate = this.isEffectiveDate(abnormalBill.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
            if(effectiveDate){
                abnormalBillList.add(abnormalBill);
            }
        }
        PaegList paegList = new PaegList();
        paegList.setPageNum(staffStatistic.getPageNum());
        paegList.setPageSize(staffStatistic.getPageSize());
        if(null != staffStatistic.getMumberName() || null != staffStatistic.getMobilePhone() || null != staffStatistic.getDocNum()){
            for (AbnormalBill abnormalBill : abnormalBills)  {
                if(null != staffStatistic.getMumberName()){
                    Pattern pattern = Pattern.compile(staffStatistic.getMumberName());
                    Matcher matcher = pattern.matcher((abnormalBill).getMemberName());
                    if(matcher.find()){
                        abnormalBillLists.add(abnormalBill);
                    }
                }
                if(null != staffStatistic.getMobilePhone()){
                    Pattern pattern1 = Pattern.compile(staffStatistic.getMobilePhone());
                    Matcher matcher = pattern1.matcher((abnormalBill).getMobilePhone());
                    if(matcher.find()){
                        abnormalBillLists.add(abnormalBill);
                    }
                }
                if(null != staffStatistic.getDocNum()){
                    Pattern pattern2 = Pattern.compile(staffStatistic.getDocNum());
                    Matcher matcher = pattern2.matcher((abnormalBill).getDocNum());
                    if(matcher.find()){
                        abnormalBillLists.add(abnormalBill);
                    }
                }
            }
            paegList.setTotal(abnormalBillLists.size());
            List<AbnormalBill> page = page(abnormalBillLists, staffStatistic.getPageSize(), staffStatistic.getPageNum());
            paegList.setList(page);
            return paegList;
        }else{
            paegList.setTotal(abnormalBillList.size());
            List<AbnormalBill> page = page(abnormalBillList, staffStatistic.getPageSize(), staffStatistic.getPageNum());
            paegList.setList(page);
            return paegList;
        }



    }

    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return true;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 循环截取某页列表进行分页(List分页)
     * @param dataList 分页数据
     * @param pageSize  页面大小
     * @param currentPage   当前页面
     */
    public static List<AbnormalBill> page(List<AbnormalBill> dataList, int pageSize,int currentPage) {
        List<AbnormalBill> currentPageList = new ArrayList<>();
        if (dataList != null && dataList.size() > 0) {
            int currIdx = (currentPage > 1 ? (currentPage - 1) * pageSize : 0);
            for (int i = 0; i < pageSize && i < dataList.size() - currIdx; i++) {
                AbnormalBill data = dataList.get(currIdx + i);
                currentPageList.add(data);
            }
        }
        return currentPageList;
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public int ResultsRecalculation(StaffStatistic staffStatistic) throws ParseException, SmsException{
        int a=0;
//        Date date = staffStatistic.getDate();
//        String dateStr = DateUtils.ymdFormat(date);

        String dateStr = staffStatistic.getStartDate().substring(0, 7);
        Date date = new Date();
        //针对员工工资跳转业绩提成明细
        if (null != staffStatistic.getType()) {
            if (staffStatistic.getType() == 0) {
                //当月
                date = new Date();
                dateStr = DateUtils.ymFormat(date);
            } else if (staffStatistic.getType() == 1) {//上月
                date = DateUtils.diffMonth(new Date(), -1);
                dateStr = DateUtils.ymFormat(date);
            } else if (staffStatistic.getType() == 2) {//上上月
                date = DateUtils.diffMonth(new Date(), -2);
                dateStr = DateUtils.ymFormat(date);
            }
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startDate = sdf.parse(staffStatistic.getStartDate());
        Date endDate = sdf.parse(staffStatistic.getEndDate());
        Long storeId = staffStatistic.getStoreId();

        List<Integer> recalculationType = staffStatistic.getRecalculationType();
        for (Integer integer : recalculationType) {
            if(integer==0){
                List<RechargeListResponse> recList = ssmRechargeService.selectListchia(storeId, startDate);
                //重算充值
                for (RechargeListResponse rechargeListResponse : recList) {
                    boolean effectiveDate = this.isEffectiveDate(rechargeListResponse.getRechargeDate(), startDate, endDate);
                    if(effectiveDate){
                        RechargeType rechargeType = new RechargeType();
                        rechargeType.setId(rechargeListResponse.getRechargeTypeId());
                        RechargeType rechargeType1 = ssmRechargeTypeSevice.selectOne(rechargeType);
                        RechargeList rechargeList = new RechargeList();
                        BeanUtils.copyProperties(rechargeListResponse, rechargeList);
                        List<RechargeList> rechargeLists = ssmRechargeService.selectListSalem(rechargeList);
                        for (RechargeList list : rechargeLists) {
                            list.setTypeRatio(rechargeType1.getTypeRatio());
                            int i = ssmRechargeService.updateRatio(list);
                            if(i==0){
                                throw new SmsException(ResponseCode.MSG,"重算充值业绩提成异常");
                            }
                            a=a+i;
                        }
                    }
                }
            }
            else if (integer==1){
                List<CourseListResponse> courseList = ssmCourseService.selectListchia(storeId, startDate);
                //重算疗程
                for (CourseListResponse courseListResponse : courseList) {
                    boolean effectiveDate = this.isEffectiveDate(courseListResponse.getDate(), startDate, endDate);
                    if(effectiveDate){
                        BaseProject baseProject = new BaseProject();
                        baseProject.setId(courseListResponse.getProjctId());
                        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                        CourseList courseList1 = new CourseList();
                        BeanUtils.copyProperties(courseListResponse, courseList1);
                        CourseList courseList2 = ssmCourseService.selectOneS(courseList1);
                        PayList payList = new PayList();
                        payList.setType("card_use");
                        payList.setDocId(String.valueOf(courseListResponse.getId()));
                        List<PayList> payList1 = ssmPayService.select(payList);
                        List<RechargeAccountResponse> rechargeAccountResponses = this.setRechargeAccountList(courseList2);
                        courseList2.setSalesCommission(baseProject1.getSalesCommission());
                        courseList2.setCardSalesCommission(baseProject1.getCardSalesCommission());
                        courseList2.setCardSalesAchievement(baseProject1.getCardSalesAchievement());
                        courseList2.setSalesAchievement(baseProject1.getSalesAchievement());
                        CourseList courseList3 = this.setAchiComm(courseList2, rechargeAccountResponses, payList1);
                        if(baseProject1.getIsCooperation()!=null && baseProject1.getIsCooperation()==1){
                            if(baseProject1.getSmokeCommissionWay()!=null && baseProject1.getSmokeCommissionWay()==0){
                                courseList3.setIsCooperation(2);
                                courseList3.setBrokerage(baseProject1.getBrokerage()==null?BigDecimal.ZERO:baseProject1.getBrokerage());
                            }else if(baseProject1.getSmokeCommissionWay()!=null && baseProject1.getSmokeCommissionWay()==1){
                                courseList3.setIsCooperation(1);
                                courseList3.setBrokerage(baseProject1.getBrokerage()==null?BigDecimal.ZERO:baseProject1.getBrokerage());
                            }
                        }else {
                            courseList3.setIsCooperation(0);
                            courseList3.setBrokerage(BigDecimal.ZERO);
                        }
                        int i = ssmCourseService.updateOne(courseList3);
                        if(i==0){
                            throw new SmsException(ResponseCode.MSG,"重算疗程业绩提成异常");
                        }
                        a=a+i;
                    }
                }
            }
            else if (integer==2){
                //重算收银
                List<CashListResponse> cashList = ssmCashService.selectListchia(storeId, startDate,endDate);
                for (CashListResponse cashListResponse : cashList) {
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(cashListResponse.getProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                    CashList cashList1 = new CashList();
                    BeanUtils.copyProperties(cashListResponse, cashList1);
                    List<CashList> cashLists = ssmCashService.selectListSalem(cashList1);
                    for (CashList list : cashLists) {
                        list.setAchievementLarge(baseProject1.getAchievementLarge());
                        list.setAchievementZhonggong(baseProject1.getAchievementZhonggong());
                        list.setAchievementTechnician(baseProject1.getAchievementTechnician());
                        list.setAchievementSmall(baseProject1.getAchievementSmall());
                        list.setCommissionLarge(baseProject1.getCommissionLarge());
                        list.setCommissionZhonggong(baseProject1.getCommissionZhonggong());
                        list.setCommissionTechnician(baseProject1.getCommissionTechnician());
                        list.setCommissionSmall(baseProject1.getCommissionSmall());
                        list.setCardAchievementLarge(baseProject1.getCardAchievementLarge());
                        list.setCardAchievementZhonggong(baseProject1.getCardAchievementZhonggong());
                        list.setCardAchievementTechnician(baseProject1.getCardAchievementTechnician());
                        list.setCardAchievementSmall(baseProject1.getCardAchievementSmall());
                        list.setCardCommissionLarge(baseProject1.getCardCommissionLarge());
                        list.setCardCommissionZhonggong(baseProject1.getCardCommissionZhonggong());
                        list.setCardCommissionTechnician(baseProject1.getCardCommissionTechnician());
                        list.setCardCommissionSmall(baseProject1.getCardCommissionSmall());
                        int i = ssmCashService.updatechia(list);
                        if(i==0){
                            throw new SmsException(ResponseCode.MSG,"重算收银业绩提成异常");
                        }
                        a=a+i;
                    }

                }
            }
            else if (integer==3){
                //重算还款
                List<RepayTradeResponse> RepayLists = ssmRepayService.selectListchia(storeId,startDate,endDate);
                for (RepayTradeResponse repayList : RepayLists) {
                    if("card_recharge".equals(repayList.getDocType())){//充值
                        RechargeType rechargeType = new RechargeType();
                        rechargeType.setId(repayList.getTradeId());
                        RechargeType rechargeType1 = ssmRechargeTypeSevice.selectOne(rechargeType);
                        RepayTradeList repayTradeList = new RepayTradeList();
                        repayTradeList.setId(repayList.getId());
                        RepayTradeList select = ssmRepayTradeService.selectOne(repayTradeList);
                        select.setTypeRatio(rechargeType1.getTypeRatio());
                        select.setAchievementAmount(select.getPayMoney());
                        select.setCommissionAmount(select.getAchievementAmount().multiply(select.getTypeRatio()));
                        int i = ssmRepayTradeService.updateByPrimaryKey(select);
                        if(i==0){
                            throw new SmsException(ResponseCode.MSG,"重算充值还款业绩提成异常");
                        }
                        a=a+i;
                    }else if("card_use".equals(repayList.getDocType())){//疗程
                        BaseProject baseProject = new BaseProject();
                        baseProject.setId(repayList.getTradeId());
                        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                        RepayTradeList repayTradeList = new RepayTradeList();
                        repayTradeList.setId(repayList.getId());
                        RepayTradeList select = ssmRepayTradeService.selectOne(repayTradeList);
                        BaseProject project = ssmProjectService.selectByPrimaryKey(select.getTradeId());
                        BigDecimal achi = BigDecimal.ZERO;
                        BigDecimal cardAchi = BigDecimal.ZERO;
                        if(project.getIsCooperation()!=null && project.getIsCooperation()==1){
                                //比例
                                if(project.getSmokeCommissionWay()!=null && project.getSmokeCommissionWay()==1){
                                    achi = achi.add(select.getPayMoney().multiply(project.getBrokerage().divide(BigDecimal.valueOf(100))));
                                    cardAchi = cardAchi.add((select.getRepayMoney().subtract(select.getPayMoney())).multiply(project.getBrokerage().divide(BigDecimal.valueOf(100))));
                                }
                                if(project.getSmokeCommissionWay()!=null && project.getSmokeCommissionWay()==0){
                                    achi = achi.add(select.getPayMoney().multiply(project.getBrokerage().divide(project.getPrice().multiply(BigDecimal.valueOf(project.getMinumumTimes())),10,BigDecimal.ROUND_HALF_UP)));
                                    cardAchi = cardAchi.add((select.getRepayMoney().subtract(select.getPayMoney()))
                                            .multiply(project.getBrokerage().divide(project.getPrice().multiply(BigDecimal.valueOf(project.getMinumumTimes())),10,BigDecimal.ROUND_HALF_UP)));
                                }

                        }
                        select.setSalesAchievement(baseProject1.getSalesAchievement());
                        select.setSalesCommission(baseProject1.getSalesCommission());
                        select.setCardSalesAchievement(baseProject1.getCardSalesAchievement());
                        select.setCardSalesCommission(baseProject1.getCardSalesCommission());
                        select.setAchievementAmount((select.getPayMoney().multiply(select.getSalesAchievement())).subtract(achi));
                        select.setCommissionAmount((select.getAchievementAmount().multiply(select.getSalesCommission())).subtract(cardAchi));
                        int i = ssmRepayTradeService.updateByPrimaryKey(select);
                        if(i==0){
                            throw new SmsException(ResponseCode.MSG,"重算疗程还款业绩提成异常");
                        }
                        a=a+i;
                    }else{//促销疗程
                        //促销发布购买之后不允许修改提成，所以不存在重算
                    }
                }
            }
            else if (integer==4){
                //重算充值退
                List<RefundRechargeResponse> refundRecList = ssmRefundRechargeService.selectListchia(storeId, startDate,endDate);
                for (RefundRechargeResponse refundRechargeResponse : refundRecList) {
                    RechargeType rechargeType = new RechargeType();
                    rechargeType.setId(refundRechargeResponse.getRechargeTypeId());
                    RechargeType rechargeType1 = ssmRechargeTypeSevice.selectOne(rechargeType);
                    RefundRecharge refundRecharge = new RefundRecharge();
                    refundRecharge.setId(refundRechargeResponse.getId());
                    RefundRecharge refundRecharge1 = ssmRefundRechargeService.selectOne(refundRecharge);
                    refundRecharge1.setTypeRatio(rechargeType1.getTypeRatio());
                    refundRecharge1.setAchievementAmount(refundRecharge1.getRecRefundMoney());
                    refundRecharge1.setCommissionAmount(refundRecharge1.getAchievementAmount().multiply(refundRecharge1.getTypeRatio()));
                    int i = ssmRefundRechargeService.updateByPrimaryKey(refundRecharge1);
                    if(i==0){
                        throw new SmsException(ResponseCode.MSG,"重算充值退款业绩提成异常");
                    }
                    a=a+i;

                }
            }
            else if (integer==5){
                //重算疗程退
                List<RefundCourseResponse> refundCourseList = ssmRefundCourseService.selectListschia(storeId,startDate,endDate);
                for (RefundCourseResponse refundCourseResponse : refundCourseList) {
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(refundCourseResponse.getCourseProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                    RefundCourse refundCourse = new RefundCourse();
                    refundCourse.setId(refundCourseResponse.getId());
                    RefundCourse refundCourse1 = ssmRefundCourseService.selectOne(refundCourse);
                    refundCourse1.setSalesAchievement(baseProject1.getSalesAchievement());
                    refundCourse1.setSalesCommission(baseProject1.getSalesCommission());
                    refundCourse1.setCardSalesAchievement(baseProject1.getCardSalesAchievement());
                    refundCourse1.setCardSalesCommission(baseProject1.getCardSalesCommission());
                    //计算业绩和提成
                    if(baseProject1.getSalesAchievement().compareTo(BigDecimal.valueOf(1))==1){
                        refundCourse1.setAchievementAmount(baseProject1.getSalesAchievement());
                        if(baseProject1.getSalesCommission().compareTo(BigDecimal.valueOf(1))==1){
                            refundCourse1.setCommissionAmount(baseProject1.getSalesCommission());
                        }else{
                            refundCourse1.setCommissionAmount(baseProject1.getSalesCommission().multiply(refundCourse.getAchievementAmount()));
                        }
                    }else{
                        refundCourse1.setAchievementAmount(refundCourse1.getCourseRefundMoney().multiply(baseProject1.getSalesAchievement()));
                        if(baseProject1.getSalesCommission().compareTo(BigDecimal.valueOf(1))==1){
                            refundCourse1.setCommissionAmount(baseProject1.getSalesCommission());
                        }else{
                            refundCourse1.setCommissionAmount(baseProject1.getSalesCommission().multiply(refundCourse1.getAchievementAmount()));
                        }
                    }
//                    refundCourse1.setAchievementAmount(refundCourse1.getCourseRefundMoney().multiply(refundCourse1.getSalesAchievement()));
//                    refundCourse1.setCommissionAmount(refundCourse1.getAchievementAmount().multiply(refundCourse1.getSalesCommission()));
                    int i = ssmRefundCourseService.updateByPrimaryKey(refundCourse1);
                    if(i==0){
                        throw new SmsException(ResponseCode.MSG,"重算疗程退款业绩提成异常");
                    }
                    a=a+i;
                }
            }
            else if (integer==6){
                //重算消费退
                List<RefundCash> refundCashList = ssmRefundCashService.selectListschia(storeId,startDate,endDate);
                for (RefundCash cardChangeList : refundCashList) {
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(cardChangeList.getProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                    RefundCash refundCash = new RefundCash();
                    refundCash.setId(cardChangeList.getId());
                    RefundCash refundCash1 = ssmRefundCashService.selectOne(refundCash);
                    refundCash1.setAchievementLarge(baseProject1.getAchievementLarge());
                    refundCash1.setAchievementZhonggong(baseProject1.getAchievementZhonggong());
                    refundCash1.setAchievementTechnician(baseProject1.getAchievementTechnician());
                    refundCash1.setAchievementSmall(baseProject1.getAchievementSmall());
                    refundCash1.setCommissionLarge(baseProject1.getCommissionLarge());
                    refundCash1.setCommissionZhonggong(baseProject1.getCommissionZhonggong());
                    refundCash1.setCommissionTechnician(baseProject1.getCommissionTechnician());
                    refundCash1.setCommissionSmall(baseProject1.getCommissionSmall());
                    refundCash1.setCardAchievementLarge(baseProject1.getCardAchievementLarge());
                    refundCash1.setCardAchievementZhonggong(baseProject1.getCardAchievementZhonggong());
                    refundCash1.setCardAchievementTechnician(baseProject1.getCardAchievementTechnician());
                    refundCash1.setCardAchievementSmall(baseProject1.getCardAchievementSmall());
                    refundCash1.setCardCommissionLarge(baseProject1.getCardCommissionLarge());
                    refundCash1.setCardCommissionZhonggong(baseProject1.getCardCommissionZhonggong());
                    refundCash1.setCardCommissionTechnician(baseProject1.getCardCommissionTechnician());
                    refundCash1.setCardCommissionSmall(baseProject1.getCardCommissionSmall());
                    int i = ssmRefundCashService.updateByPrimaryKey(refundCash1);
                    if(i==0){
                        throw new SmsException(ResponseCode.MSG,"重算收银退款业绩提成异常");
                    }
                    a=a+i;
                }
            }
            else if (integer==7){
                //重算加价转疗程
                List<CardChangeInProject> cardChangeLists = ssmCardChangeService.selectListchia(storeId,startDate,endDate);
                for (CardChangeInProject cardChangeList : cardChangeLists) {
                    BaseProject baseProject = new BaseProject();
                    baseProject.setId(cardChangeList.getProjectId());
                    BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                    CardChangeInProject cardChangeInProject = new CardChangeInProject();
                    cardChangeInProject.setId(cardChangeList.getId());
                    CardChangeInProject cardChangeInProject1 = ssmCardChangeInProjectService.selectOne(cardChangeInProject);
                    cardChangeInProject1.setSalesAchievement(baseProject1.getSalesAchievement());
                    cardChangeInProject1.setSalesCommission(baseProject1.getSalesCommission());
                    cardChangeInProject1.setCardSalesAchievement(baseProject1.getCardSalesAchievement());
                    cardChangeInProject1.setCardSalesCommission(baseProject1.getCardSalesCommission());
                    cardChangeInProject1.setAchievementAmount(cardChangeInProject1.getChangeInPayMoney().multiply(cardChangeInProject1.getSalesAchievement()));
                    cardChangeInProject1.setCommissionAmount(cardChangeInProject1.getAchievementAmount().multiply(cardChangeInProject1.getSalesCommission()));
                    cardChangeInProject1.setCardAchievementAmount(cardChangeInProject1.getChangeOutMoney().multiply(cardChangeInProject1.getCardSalesAchievement()));
                    cardChangeInProject1.setCardCommissionAmount(cardChangeInProject1.getCardAchievementAmount().multiply(cardChangeInProject1.getCardSalesCommission()));
                    int i = ssmCardChangeInProjectService.updateByPrimaryKey(cardChangeInProject1);
                    if(i==0){
                        throw new SmsException(ResponseCode.MSG,"重算加价转疗程业绩提成异常");
                    }
                    a=a+i;
                }
            }
            else if (integer==8){
                //重算疗程转充值
                List<RechargeTurnCoursesResponse> rechargeTurnCourses = ssmRechargeTurnCourseService.selectDateschia(storeId,startDate,endDate);
                for (RechargeTurnCoursesResponse rechargeTurnCours : rechargeTurnCourses) {
                    RechargeType rechargeType = new RechargeType();
                    rechargeType.setId(rechargeTurnCours.getRechargeTypeId());
                    RechargeType rechargeType1 = ssmRechargeTypeSevice.selectOne(rechargeType);
                    RechargeTurnCourse rechargeTurnCourse1 = new RechargeTurnCourse();
                    rechargeTurnCourse1.setId(rechargeTurnCours.getId());
                    RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectOne(rechargeTurnCourse1);
                    CoursePayList coursePayList = new CoursePayList();
                    coursePayList.setDocNum(rechargeTurnCourse.getDocNum());
                    List<CoursePayList> coursePayLists = ssmCoursePayListService.select(coursePayList);
                    for (CoursePayList payList : coursePayLists) {
                        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(Long.valueOf(payList.getCourseProjectId()));
                        payList.setCardAchievementAmount(payList.getRollOffMoney().multiply(baseProject.getCardSalesAchievement()));
                        if(baseProject.getCardSalesCommission().compareTo(new BigDecimal("1"))==1){
                            payList.setCardCommissionAmount(baseProject.getCardSalesCommission());
                        }else {
                            payList.setCardCommissionAmount(payList.getCardAchievementAmount().multiply(baseProject.getCardSalesCommission()));
                        }
                        payList.setSalesCommission(baseProject.getSalesCommission());
                        payList.setSalesAchievement(baseProject.getSalesAchievement());
                        payList.setCardSalesCommission(baseProject.getCardSalesCommission());
                        payList.setCardSalesAchievement(baseProject.getCardSalesAchievement());
                        ssmCoursePayListService.updateByPrimaryKey(payList);
                    }
                    rechargeTurnCourse.setTypeRatio(rechargeType1.getTypeRatio());
                    int i = ssmRechargeTurnCourseService.updateByPrimaryKey(rechargeTurnCourse);
                    if(i==0){
                        throw new SmsException(ResponseCode.MSG,"重算加价转疗程业绩提成异常");
                    }
                    a=a+i;
                }
            }
            else if (integer==9){
                //重算团购卡业绩
                List<BaseGrouponCard> baseGrouponCards = ssmBaseGrouponCardService.selectDateschia(storeId, startDate, endDate);
                for (BaseGrouponCard baseGrouponCard : baseGrouponCards) {
                    RechargeType rechargeType = ssmRechargeTypeSevice.selectByPrimaryKey(baseGrouponCard.getRechargeTypeId());
                    baseGrouponCard.setTypeRatio(rechargeType.getTypeRatio());
                    int i = ssmBaseGrouponCardService.updateNotNull(baseGrouponCard);
                    if(i==0){
                        throw new SmsException(ResponseCode.MSG,"重算团购卡业绩异常");
                    }
                }
            }
            else if (integer==10){
                //会员初始化的进行重算
                CourseListRequest courseListRequest = new CourseListRequest();
                courseListRequest.setStoreId(storeId);
                courseListRequest.setStartTime(startDate);
                courseListRequest.setEndTime(endDate);
                List<CourseList> courseLists = courseListMemberInitMapper.selectPage(courseListRequest);
                if(courseLists!=null && courseLists.size()>0){
                    for (CourseList memberInitStaff : courseLists) {
                        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(memberInitStaff.getProjctId());
                        memberInitStaff.setSalesAchievement(baseProject.getSalesAchievement());
                        memberInitStaff.setSalesCommission(baseProject.getSalesCommission());
                        memberInitStaff.setCardSalesAchievement(baseProject.getCardSalesAchievement());
                        memberInitStaff.setCardSalesCommission(baseProject.getCardSalesCommission());
                        if(baseProject.getIsCooperation()!=null && baseProject.getIsCooperation()==1){
                            //判断是固定抽成还是比例 1是比例2是固定
                            if(baseProject.getSmokeCommissionWay()!=null && baseProject.getSmokeCommissionWay()==1){
                                memberInitStaff.setIsCooperation(1);
                                memberInitStaff.setBrokerage(baseProject.getBrokerage());
                            }else if(baseProject.getSmokeCommissionWay()!=null && baseProject.getSmokeCommissionWay()==0){
                                memberInitStaff.setIsCooperation(2);
                                memberInitStaff.setBrokerage(baseProject.getBrokerage());
                            }
                        }
                        CourseListMemberInit courseListMemberInit = new CourseListMemberInit();
                        BeanUtils.copyProperties(memberInitStaff,courseListMemberInit);
                        courseListMemberInitMapper.updateProjectAchi(courseListMemberInit);
                    }
                }
            }
        }
        return a;
    }

    /*
     * 疗程业绩
     * */
    public List<RechargeAccountResponse> setRechargeAccountList(CourseList courseList){
        List<RechargeAccountResponse> list = new ArrayList<>();
        AccountTradeRecordRequest accountTradeRecordRequest = new AccountTradeRecordRequest();
        accountTradeRecordRequest.setDocType(Constant.doc_type_card_use);
        accountTradeRecordRequest.setAccountType(Constant.account_type_recharge_consume);
        accountTradeRecordRequest.setDocId(courseList.getId());
        accountTradeRecordRequest.setInputDate(courseList.getDate());
        List<AccountTradeRecord> recordList = ssmAccountTradeRecordService.selectList(accountTradeRecordRequest);
        for (AccountTradeRecord accountTradeRecord : recordList) {
            RechargeAccountResponse rechargeAccountResponse = new RechargeAccountResponse();
//            RechargeAccount rechargeAccount = ssmRechargeAccountService.selectByPrimaryKey(accountTradeRecord.getAccountId());
//            BeanUtils.copyProperties(rechargeAccount,rechargeAccountResponse);
            rechargeAccountResponse.setCardRestMoney(accountTradeRecord.getAccountRestMoney());
            rechargeAccountResponse.setCardConsumeMoney(accountTradeRecord.getAccountConsumeMoney());
            rechargeAccountResponse.setCardGiftMoney(accountTradeRecord.getAccountGiftRestMoney());
            rechargeAccountResponse.setGiftConsumeMoney(accountTradeRecord.getAccountGiftConsumeMoney());
            rechargeAccountResponse.setSpendMoney(accountTradeRecord.getAccountSpendMoney());
            rechargeAccountResponse.setRechargeTypeName(accountTradeRecord.getAccountName());
            list.add(rechargeAccountResponse);
        }
        return list;
    }
    public CourseList setAchiComm(CourseList courseList, List<RechargeAccountResponse> rechargeAccountRequestList, List<PayList> payLists){
        //查询会员是否有积分
        StoreParament parament = StoreParaUtils.getStorePara(courseList.getStoreId(),Constant.member_integral);
        BaseProject project = ssmProjectService.selectByPrimaryKey(courseList.getProjctId());

        courseList.setSalesAchievement(project.getSalesAchievement());
        courseList.setSalesCommission(project.getSalesCommission());
        courseList.setCardSalesAchievement(project.getCardSalesAchievement());
        courseList.setCardSalesCommission(project.getCardSalesCommission());

        //合作项目抽佣比例
        //BigDecimal cooperationRatio = project.getBrokerage();

        BigDecimal cooperationCashAchi=new BigDecimal("0");//合作现付业绩
        BigDecimal cooperationRechargeAchi=new BigDecimal("0");//合作卡付业绩
        BigDecimal cashRechargeAchiSum=new BigDecimal("0");//合作总业绩
        //isCooperation 比例brokerage 1是比例 0是固定smokeCommissionWay
        if(project.getIsCooperation()==1){
            if(project.getSmokeCommissionWay()==1){//合作按比例
                //合作项目现付业绩
                cooperationCashAchi=cooperationCashAchi.add(project.getBrokerage().multiply(courseList.getCollectionCashAmount()));
                //合作项目卡付业绩
                cooperationRechargeAchi=cooperationRechargeAchi.add(project.getBrokerage().multiply(courseList.getCollectionRechargeAmount()));
            }else{//合作按固定
                //方法1：现付和卡付对比，取最大值先扣，不够再补上


                //方法2：卡付和现付/总付金额，获取现付和卡付的支付比例*合作项目固定金额
                BigDecimal sum=courseList.getCollectionCashAmount().add(courseList.getCollectionRechargeAmount());
                //（卡付（或现付）/总付款金额=卡付（或现付）比例）
                BigDecimal Cash=courseList.getCollectionCashAmount().divide(sum,10,BigDecimal.ROUND_HALF_UP);
                BigDecimal Recharge=courseList.getCollectionRechargeAmount().divide(sum,10,BigDecimal.ROUND_HALF_UP);
                cooperationCashAchi=cooperationCashAchi.add(project.getBrokerage().multiply(Cash).setScale(2,BigDecimal.ROUND_HALF_UP));
                cooperationRechargeAchi=cooperationRechargeAchi.add(project.getBrokerage().multiply(Recharge).setScale(2,BigDecimal.ROUND_HALF_UP));
            }
        }
        cashRechargeAchiSum=cashRechargeAchiSum.add(cooperationCashAchi).add(cooperationRechargeAchi).divide(new BigDecimal("100"));
        courseList.setCollectionCashAmount(courseList.getCollectionCashAmount().subtract(cooperationCashAchi));//业绩-合作项目现付业绩
        courseList.setCollectionRechargeAmount(courseList.getCollectionRechargeAmount().subtract(cooperationRechargeAchi));//业绩-合作项目卡付业绩


        BigDecimal times = com.ssm.core.utils.BigDecimalUtils.bigDecimal(courseList.getNumberTimes().toString());
        //现付销售业绩标准  >0 <1比率   >1固定金额
        BigDecimal achiRatio = courseList.getSalesAchievement();
        //现付销售提成标准  >0 <1比率   >1固定金额
        BigDecimal commRatio = courseList.getSalesCommission();
        //有积分
        if ("1".equals(parament.getParamentValue())){
            //查询积分支付是否计算业绩提成
            StoreParament storeParament = StoreParaUtils.getStorePara(courseList.getStoreId(),"integral");
            if (null != payLists && payLists.size() > 0 || com.ssm.core.utils.BigDecimalUtils.compareTo(courseList.getCollectionIntegralAmount(), com.ssm.core.utils.BigDecimalUtils.bigDecimal("0")) == 1 && project.getIsCooperation() == 0){
                //业绩比率
                if (com.ssm.core.utils.BigDecimalUtils.compareTo(achiRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                    courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(achiRatio, com.ssm.core.utils.BigDecimalUtils.add(courseList.getCollectionCashAmount(), courseList.getCollectionIntegralAmount())));
                }else {//业绩固定金额
                    courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(
                            com.ssm.core.utils.BigDecimalUtils.add(courseList.getCollectionCashAmount(), courseList.getCollectionIntegralAmount()), courseList.getAmount()), achiRatio), times));

                }
                //提成比率
                if (com.ssm.core.utils.BigDecimalUtils.compareTo(commRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                    courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(commRatio, courseList.getAchievementAmount()));
                }else {//提成固定金额
                    courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(
                            com.ssm.core.utils.BigDecimalUtils.add(courseList.getCollectionCashAmount(), courseList.getCollectionIntegralAmount()), courseList.getAmount()), commRatio), times));

                }
            }

            //合作项目计算业绩提成
            if (null != payLists && payLists.size() > 0 || com.ssm.core.utils.BigDecimalUtils.compareTo(courseList.getCollectionIntegralAmount(), com.ssm.core.utils.BigDecimalUtils.bigDecimal("0")) == 1 && project.getIsCooperation() == 1){

                //业绩比率
                if (com.ssm.core.utils.BigDecimalUtils.compareTo(achiRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                    if ("1".equals(storeParament.getParamentValue())) {
                        courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(achiRatio, com.ssm.core.utils.BigDecimalUtils.add(courseList.getCollectionCashAmount(), courseList.getCollectionIntegralAmount())));
                    }
                }else {//业绩固定金额
                    if ("1".equals(storeParament.getParamentValue())) {
                        courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(
                                com.ssm.core.utils.BigDecimalUtils.add(courseList.getCollectionCashAmount(), courseList.getCollectionIntegralAmount()), courseList.getAmount()), achiRatio), times));
                    }
                }
                //提成比率
                if (com.ssm.core.utils.BigDecimalUtils.compareTo(commRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                    courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(commRatio, courseList.getAchievementAmount()));
                }else {//提成固定金额
                    if ("1".equals(storeParament.getParamentValue())) {
                        courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(
                                com.ssm.core.utils.BigDecimalUtils.add(courseList.getCollectionCashAmount(), courseList.getCollectionIntegralAmount()), courseList.getAmount()), commRatio), times));
                    }
                }
            }
        }

        //无积分 或者不计算业绩提成
        if (null != payLists && payLists.size() > 0 && project.getIsCooperation() == 0) {
            //比率
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(achiRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(achiRatio, courseList.getCollectionCashAmount()));
            }else {//固定金额
                courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionCashAmount(), courseList.getAmount()), achiRatio), times));
            }
            //提成比率
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(commRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(commRatio, courseList.getAchievementAmount()));
            }else {//提成固定金额
                courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionCashAmount(), courseList.getAmount()), commRatio), times));
            }
        }

        //无积分 或者不计算业绩提成 合作项目
        if (null != payLists && payLists.size() > 0 && project.getIsCooperation() == 1) {
            //比率
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(achiRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(achiRatio, courseList.getCollectionCashAmount()));
            }else {//固定金额
                courseList.setAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionCashAmount(), courseList.getAmount()), achiRatio), times));
            }
            //提成比率
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(commRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(commRatio, courseList.getAchievementAmount()));
            }else {//提成固定金额
                courseList.setCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionCashAmount(), courseList.getAmount()), commRatio), times));
            }
        }
        if (null != rechargeAccountRequestList && rechargeAccountRequestList.size() > 0 && project.getIsCooperation() == 0){
            //卡付销售业绩标准  >0 <1比率   >=1固定金额
            BigDecimal cardAchiRatio = courseList.getCardSalesAchievement();
            //卡付销售提成标准  >0 <1比率   >=1固定金额
            BigDecimal cardCommRatio = courseList.getCardSalesCommission();
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(cardAchiRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1){
                courseList.setCardAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(cardAchiRatio,courseList.getCollectionRechargeAmount()));
            }else {
                courseList.setCardAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionRechargeAmount(),courseList.getCourseReatmentAmount()),cardAchiRatio), times));
            }
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(cardCommRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                courseList.setCardCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(cardCommRatio, courseList.getCardAchievementAmount()));

            }else {
                courseList.setCardCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionRechargeAmount(),courseList.getCourseReatmentAmount()),cardCommRatio), times));
            }
        }

        //充值卡付 合作项目
        if (null != rechargeAccountRequestList && rechargeAccountRequestList.size() > 0 && project.getIsCooperation() == 1){
            //卡付销售业绩标准  >0 <1比率   >=1固定金额
            BigDecimal cardAchiRatio = courseList.getCardSalesAchievement();
            //卡付销售提成标准  >0 <1比率   >=1固定金额
            BigDecimal cardCommRatio = courseList.getCardSalesCommission();
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(cardAchiRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1){
                courseList.setCardAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(cardAchiRatio, courseList.getCollectionRechargeAmount()));
            }else {
                courseList.setCardAchievementAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionRechargeAmount(),courseList.getCourseReatmentAmount()),cardAchiRatio), times));
            }
            if (com.ssm.core.utils.BigDecimalUtils.compareTo(cardCommRatio, com.ssm.core.utils.BigDecimalUtils.bigDecimal("1")) != 1) {
                courseList.setCardCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(cardCommRatio, courseList.getCardAchievementAmount()));

            }else {
                courseList.setCardCommissionAmount(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.multiply(com.ssm.core.utils.BigDecimalUtils.div(courseList.getCollectionRechargeAmount(),courseList.getCourseReatmentAmount()),cardCommRatio), times));
            }
        }

        return courseList;
    }

    @Override
    public PageInfo<RateContribution> selectRateContribution(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContribution> rateContributions = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        String[] splite = format.format(rateContribution.getEndDate()).split("-");
        Integer yeare = Integer.valueOf(splite[0]);
        Integer monthe = Integer.valueOf(splite[1]);
        String DateEnd = null;
        monthe++;
        if(monthe>12){
            monthe=1;
            yeare++;
        }
        if(monthe<10){
            DateEnd= yeare+"-0"+monthe;
        }else{
            DateEnd= yeare+"-"+monthe;
        }
        Date parse = format.parse(DateEnd);
        rateContribution.setEndDate(parse);
        //查询公司
        if(rateContribution.getSelectType()==0){
            StoreRequest storeRequest = new StoreRequest();
            storeRequest.setId(rateContribution.getStoreId());
            List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
            BaseStores baseStores = new BaseStores();
            baseStores = pagesorganizations.stream().filter(baseStores1 -> null == baseStores1.getParentId()).collect(Collectors.toList()).get(0);
            BaseProject baseProject = new BaseProject();
            baseProject.setStoreId(baseStores.getId());
            List<BaseProject> select = ssmProjectService.select(baseProject);


            for (BaseProject project : select) {
                //解析年月
                String[] split = format.format(rateContribution.getStartDate()).split("-");
                Integer year = Integer.valueOf(split[0]);
                Integer month = Integer.valueOf(split[1]);
                Date selectDate = null;
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
            //每一个门店
                List<RateContribution> rateContributionls = new ArrayList<>();
                while(selectDate.before(rateContribution.getEndDate())){
                    for (BaseStores pagesorganization : pagesorganizations) {
                        //检查每一个门店是否有引入该项目
                        baseProject.setStoreId(pagesorganization.getId());
                        baseProject.setProjectNum(project.getProjectNum());
                        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                        if(null != baseProject1){ // 有存在才需要计算
                            RateContribution rateContribution1 = new RateContribution();
                            rateContribution1.setAmount(BigDecimal.valueOf(0));
                            rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                            rateContribution1.setPriceMember(project.getPriceMember());
                            rateContribution1.setCountTC(BigDecimal.valueOf(0));
                            rateContribution1.setNumberTimes(0);
                            rateContribution1.setProjectNum(project.getProjectNum());
                            rateContribution1.setProjectName(project.getProjectName());



                            //先查询疗程
                            CourseList courseList = new CourseList();
                            courseList.setDate(selectDate);
                            courseList.setProjctId(baseProject1.getId());
                            courseList.setStoreId(pagesorganization.getId());
                            courseList.setIsCancel(0);
                            List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
                            for (CourseList list : courseList1) {
                                CourseRateContribution(list,null,null,null,null,rateContribution1);
                            }

                            //查询转入疗程
                            Example exampleInProject = new Example(CardChangeInProject.class);
                            Example.Criteria criteriaInProject = exampleInProject.createCriteria();
                            criteriaInProject.andEqualTo("storeId",pagesorganization.getId());
                            criteriaInProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                            criteriaInProject.andEqualTo("projectId",baseProject1.getId());
                            List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
                            for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
                                CardChangeList cardChangeList = new CardChangeList();
                                cardChangeList.setDocNum(cardChangeInProject.getDocNum());
                                cardChangeList.setStoreId(cardChangeInProject.getStoreId());
                                CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                                if(cardChangeList1.getState()==3){
                                    CourseRateContribution(null,cardChangeInProject,null,null,null,rateContribution1);
                                }
                            }

                            //查询转出疗程
                            Example exampleOutProject = new Example(CardChangeOutProject.class);
                            Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
                            criteriaOutProject.andEqualTo("storeId",pagesorganization.getId());
                            criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                            criteriaOutProject.andEqualTo("courseProjectId",baseProject1.getId());
                            List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
                            for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
                                CardChangeList cardChangeList = new CardChangeList();
                                cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
                                cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
                                CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                                if(cardChangeList1.getState()==3){
                                    CourseRateContribution(null,null,cardChangeOutProject,null,null,rateContribution1);
                                }
                            }


                            //查询疗程转充值卡
                            Example exampleTurnCourse = new Example(CoursePayList.class);
                            Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
                            criteriaTurnCourse.andEqualTo("storeId",pagesorganization.getId());
                            criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                            criteriaTurnCourse.andEqualTo("courseProjectId",baseProject1.getId());
                            List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
                            for (CoursePayList coursePayList : coursePayLists) {
                                RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
                                if(rechargeTurnCourse.getState()==0){
                                    CourseRateContribution(null,null,null,coursePayList,null,rateContribution1);
                                }
                            }
                            //疗程退

                            Example exampleRefundCourse = new Example(RefundCourse.class);
                            Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
                            criteriaRefundCourse.andEqualTo("storeId",pagesorganization.getId());
                            criteriaRefundCourse.andLike("refundNum","%"+format.format(selectDate).replace("-","")+"%");
                            criteriaRefundCourse.andEqualTo("courseProjectId",baseProject1.getId());
                            List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
                            for (RefundCourse refundCours : refundCourses) {
                                RefundOrderList refundOrderList = new RefundOrderList();
                                refundOrderList.setRefundNum(refundCours.getRefundNum());
                                refundOrderList.setStoreId(refundCours.getStoreId());
                                RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
                                if(refundOrderList1.getState()==3){
                                    CourseRateContribution(null,null,null,null,refundCours,rateContribution1);
                                }
                            }

                            rateContributionls.add(rateContribution1);
                        }
                    }
                    month++;
                    if(month>12){
                        month=1;
                        year++;
                    }
                    if(month<10){
                        selectDate= format.parse(year+"-0"+month);
                    }else{
                        selectDate= format.parse(year+"-"+month);
                    }
                }
                RateContribution rateContribution2 = new RateContribution();
                rateContribution2.setProjectNum(project.getProjectNum());
                rateContribution2.setProjectName(project.getProjectName());
                rateContribution2.setAmount(BigDecimal.valueOf(0));
                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setCountTC(BigDecimal.valueOf(0));
                rateContribution2.setNumberTimes(0);
                Integer collect = rateContributionls.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                BigDecimal reduce = rateContributionls.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal reduce1 = rateContributionls.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                rateContribution2.setNumberTimes(collect);
                rateContribution2.setAmount(reduce);
                rateContribution2.setCountTC(reduce1);
                rateContribution2.setStoreId(baseStores.getId());
                rateContribution2.setStoreName(baseStores.getStoreName());
                if(collect==0){
                    rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                }else{
                    rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                }
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setStoreIdType(0);
                rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                rateContributions.add(rateContribution2);
            }

            //循环每一个门店
            for (BaseStores pagesorganization : pagesorganizations) {
                if(null != pagesorganization.getParentId()){
                    BaseProject baseProject1 = new BaseProject();
                    baseProject1.setStoreId(pagesorganization.getId());
                    List<BaseProject> select1 = ssmProjectService.select(baseProject1);


                    for (BaseProject project : select1) {
                        BaseProject baseProject2 = new BaseProject();
                        baseProject2.setStoreId(baseStores.getId());
                        baseProject2.setProjectNum(project.getProjectNum());
                        List<BaseProject> select2 = ssmProjectService.select(baseProject2);
                        if(select2.size()==0){
                            //解析年月
                            String[] split = format.format(rateContribution.getStartDate()).split("-");
                            Integer year = Integer.valueOf(split[0]);
                            Integer month = Integer.valueOf(split[1]);
                            Date selectDate = null;
                            if(month<10){
                                selectDate= format.parse(year+"-0"+month);
                            }else{
                                selectDate= format.parse(year+"-"+month);
                            }
                            List<RateContribution> rateContributions1 = new ArrayList<>();
                            while (selectDate.before(rateContribution.getEndDate())){
                                RateContribution rateContribution1 = new RateContribution();
                                rateContribution1.setAmount(BigDecimal.valueOf(0));
                                rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                                rateContribution1.setPriceMember(project.getPriceMember());
                                rateContribution1.setCountTC(BigDecimal.valueOf(0));
                                rateContribution1.setNumberTimes(0);
                                rateContribution1.setProjectNum(project.getProjectNum());
                                rateContribution1.setProjectName(project.getProjectName());

                                //先查询疗程
                                CourseList courseList = new CourseList();
                                courseList.setDate(selectDate);
                                courseList.setProjctId(baseProject1.getId());
                                courseList.setStoreId(pagesorganization.getId());
                                courseList.setIsCancel(0);
                                List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
                                for (CourseList list : courseList1) {
                                    CourseRateContribution(list,null,null,null,null,rateContribution1);
                                }

                                //查询转入疗程
                                Example exampleInProject = new Example(CardChangeInProject.class);
                                Example.Criteria criteriaInProject = exampleInProject.createCriteria();
                                criteriaInProject.andEqualTo("storeId",pagesorganization.getId());
                                criteriaInProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                                criteriaInProject.andEqualTo("projectId",baseProject1.getId());
                                List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
                                for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
                                    CardChangeList cardChangeList = new CardChangeList();
                                    cardChangeList.setDocNum(cardChangeInProject.getDocNum());
                                    cardChangeList.setStoreId(cardChangeInProject.getStoreId());
                                    CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                                    if(cardChangeList1.getState()==3){
                                        CourseRateContribution(null,cardChangeInProject,null,null,null,rateContribution1);
                                    }
                                }

                                //查询转出疗程
                                Example exampleOutProject = new Example(CardChangeOutProject.class);
                                Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
                                criteriaOutProject.andEqualTo("storeId",pagesorganization.getId());
                                criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                                criteriaOutProject.andEqualTo("courseProjectId",baseProject1.getId());
                                List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
                                for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
                                    CardChangeList cardChangeList = new CardChangeList();
                                    cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
                                    cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
                                    CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                                    if(cardChangeList1.getState()==3){
                                        CourseRateContribution(null,null,cardChangeOutProject,null,null,rateContribution1);
                                    }
                                }


                                //查询疗程转充值卡
                                Example exampleTurnCourse = new Example(CoursePayList.class);
                                Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
                                criteriaTurnCourse.andEqualTo("storeId",pagesorganization.getId());
                                criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                                criteriaTurnCourse.andEqualTo("courseProjectId",baseProject1.getId());
                                List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
                                for (CoursePayList coursePayList : coursePayLists) {
                                    RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
                                    if(rechargeTurnCourse.getState()==0){
                                        CourseRateContribution(null,null,null,coursePayList,null,rateContribution1);
                                    }
                                }
                                //疗程退

                                Example exampleRefundCourse = new Example(RefundCourse.class);
                                Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
                                criteriaRefundCourse.andEqualTo("storeId",pagesorganization.getId());
                                criteriaRefundCourse.andLike("refundNum","%"+format.format(selectDate).replace("-","")+"%");
                                criteriaRefundCourse.andEqualTo("courseProjectId",baseProject1.getId());
                                List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
                                for (RefundCourse refundCours : refundCourses) {
                                    RefundOrderList refundOrderList = new RefundOrderList();
                                    refundOrderList.setRefundNum(refundCours.getRefundNum());
                                    refundOrderList.setStoreId(refundCours.getStoreId());
                                    RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
                                    if(refundOrderList1.getState()==3){
                                        CourseRateContribution(null,null,null,null,refundCours,rateContribution1);
                                    }
                                }
                                rateContributions1.add(rateContribution1);

                                month++;
                                if(month>12){
                                    month=1;
                                    year++;
                                }
                                if(month<10){
                                    selectDate= format.parse(year+"-0"+month);
                                }else{
                                    selectDate= format.parse(year+"-"+month);
                                }

                            }

                            RateContribution rateContribution2 = new RateContribution();
                            rateContribution2.setProjectNum(project.getProjectNum());
                            rateContribution2.setProjectName(project.getProjectName());
                            rateContribution2.setAmount(BigDecimal.valueOf(0));
                            rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                            rateContribution2.setPriceMember(project.getPriceMember());
                            rateContribution2.setCountTC(BigDecimal.valueOf(0));
                            rateContribution2.setNumberTimes(0);
                            Integer collect = rateContributions1.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                            BigDecimal reduce = rateContributions1.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                            BigDecimal reduce1 = rateContributions1.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                            rateContribution2.setNumberTimes(collect);
                            rateContribution2.setAmount(reduce);
                            rateContribution2.setCountTC(reduce1);
                            rateContribution2.setStoreId(pagesorganization.getId());
                            rateContribution2.setStoreName(pagesorganization.getStoreName());
                            if(collect==0){
                                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                            }else{
                                rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                            }
                            rateContribution2.setPriceMember(project.getPriceMember());
                            rateContribution2.setStoreIdType(1);
                            rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                            rateContributions.add(rateContribution2);
                        }
                    }
                }
            }
        }else{ //查询门店
            BaseProject baseProject1 = new BaseProject();
            baseProject1.setStoreId(rateContribution.getStoreId());
            List<BaseProject> select1 = ssmProjectService.select(baseProject1);
            for (BaseProject project : select1) {
                //解析年月
                String[] split = format.format(rateContribution.getStartDate()).split("-");
                Integer year = Integer.valueOf(split[0]);
                Integer month = Integer.valueOf(split[1]);
                Date selectDate = null;
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
                List<RateContribution> rateContributions1 = new ArrayList<>();
                while (selectDate.before(rateContribution.getEndDate())){
                    RateContribution rateContribution1 = new RateContribution();
                    rateContribution1.setAmount(BigDecimal.valueOf(0));
                    rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                    rateContribution1.setPriceMember(project.getPriceMember());
                    rateContribution1.setCountTC(BigDecimal.valueOf(0));
                    rateContribution1.setNumberTimes(0);
                    rateContribution1.setProjectNum(project.getProjectNum());
                    rateContribution1.setProjectName(project.getProjectName());

                    //先查询疗程
                    CourseList courseList = new CourseList();
                    courseList.setDate(selectDate);
                    courseList.setProjctId(project.getId());
                    courseList.setStoreId(rateContribution.getStoreId());
                    courseList.setIsCancel(0);
                    List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
                    for (CourseList list : courseList1) {
                        CourseRateContribution(list,null,null,null,null,rateContribution1);
                    }

                    //查询转入疗程
                    Example exampleInProject = new Example(CardChangeInProject.class);
                    Example.Criteria criteriaInProject = exampleInProject.createCriteria();
                    criteriaInProject.andEqualTo("storeId",rateContribution.getStoreId());
                    criteriaInProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                    criteriaInProject.andEqualTo("projectId",project.getId());
                    List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
                    for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
                        CardChangeList cardChangeList = new CardChangeList();
                        cardChangeList.setDocNum(cardChangeInProject.getDocNum());
                        cardChangeList.setStoreId(cardChangeInProject.getStoreId());
                        CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                        if(cardChangeList1.getState()==3){
                            CourseRateContribution(null,cardChangeInProject,null,null,null,rateContribution1);
                        }
                    }

                    //查询转出疗程
                    Example exampleOutProject = new Example(CardChangeOutProject.class);
                    Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
                    criteriaOutProject.andEqualTo("storeId",rateContribution.getStoreId());
                    criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                    criteriaOutProject.andEqualTo("courseProjectId",project.getId());
                    List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
                    for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
                        CardChangeList cardChangeList = new CardChangeList();
                        cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
                        cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
                        CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                        if(cardChangeList1.getState()==3){
                            CourseRateContribution(null,null,cardChangeOutProject,null,null,rateContribution1);
                        }
                    }


                    //查询疗程转充值卡
                    Example exampleTurnCourse = new Example(CoursePayList.class);
                    Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
                    criteriaTurnCourse.andEqualTo("storeId",rateContribution.getStoreId());
                    criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                    criteriaTurnCourse.andEqualTo("courseProjectId",project.getId());
                    List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
                    for (CoursePayList coursePayList : coursePayLists) {
                        RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
                        if(rechargeTurnCourse.getState()==0){
                            CourseRateContribution(null,null,null,coursePayList,null,rateContribution1);
                        }
                    }
                    //疗程退

                    Example exampleRefundCourse = new Example(RefundCourse.class);
                    Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
                    criteriaRefundCourse.andEqualTo("storeId",rateContribution.getStoreId());
                    criteriaRefundCourse.andLike("refundNum","%"+format.format(selectDate).replace("-","")+"%");
                    criteriaRefundCourse.andEqualTo("courseProjectId",project.getId());
                    List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
                    for (RefundCourse refundCours : refundCourses) {
                        RefundOrderList refundOrderList = new RefundOrderList();
                        refundOrderList.setRefundNum(refundCours.getRefundNum());
                        refundOrderList.setStoreId(refundCours.getStoreId());
                        RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
                        if(refundOrderList1.getState()==3){
                            CourseRateContribution(null,null,null,null,refundCours,rateContribution1);
                        }
                    }
                    rateContributions1.add(rateContribution1);

                    month++;
                    if(month>12){
                        month=1;
                        year++;
                    }
                    if(month<10){
                        selectDate= format.parse(year+"-0"+month);
                    }else{
                        selectDate= format.parse(year+"-"+month);
                    }

                }

                RateContribution rateContribution2 = new RateContribution();
                rateContribution2.setProjectNum(project.getProjectNum());
                rateContribution2.setProjectName(project.getProjectName());
                rateContribution2.setAmount(BigDecimal.valueOf(0));
                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setCountTC(BigDecimal.valueOf(0));
                rateContribution2.setNumberTimes(0);
                Integer collect = rateContributions1.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                BigDecimal reduce = rateContributions1.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal reduce1 = rateContributions1.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                rateContribution2.setNumberTimes(collect);
                rateContribution2.setAmount(reduce);
                rateContribution2.setCountTC(reduce1);
                if(collect==0){
                    rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                }else{
                    rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                }
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setStoreIdType(1);
                rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                BaseStore baseStore = new BaseStore();
                baseStore.setId(rateContribution.getStoreId());
                BaseStore baseStore1 = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());

                rateContribution2.setStoreId(baseStore1.getId());
                rateContribution2.setStoreName(baseStore1.getStoreName());
                rateContribution2.setStoreNum(baseStore1.getStoreNum());
                rateContributions.add(rateContribution2);
            }

        }
        List<RateContribution> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;
        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }
        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }
        if(pageSize>rateContributions.size()){
            pageSize= rateContributions.size();
        }

        if(rateContribution.getSorts()==0){
            rateContributions.sort(comparing(RateContribution::getAmount).reversed());
        }else{
            rateContributions.sort(comparing(RateContribution::getAmount));
        }

        List<RateContribution> rateContributions2 = rateContributions.subList(pageNum, pageSize);
        PageInfo<RateContribution> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributions.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContribution> selectRateContributionMx(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContribution> rateContributions = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");

        String[] splite = format.format(rateContribution.getEndDate()).split("-");
        Integer yeare = Integer.valueOf(splite[0]);
        Integer monthe = Integer.valueOf(splite[1]);
        String DateEnd = null;
        monthe++;
        if(monthe>12){
            monthe=1;
            yeare++;
        }
        if(monthe<10){
            DateEnd= yeare+"-0"+monthe;
        }else{
            DateEnd= yeare+"-"+monthe;
        }
        Date parse = format.parse(DateEnd);
        rateContribution.setEndDate(parse);

        if(rateContribution.getStoreIdType()==0){//总店项目
            StoreRequest storeRequest = new StoreRequest();
            storeRequest.setId(rateContribution.getStoreId());
            List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
            BaseProject baseProject = new BaseProject();
            baseProject.setProjectNum(rateContribution.getProjectNum());
            baseProject.setStoreId(rateContribution.getStoreId());
            baseProject = ssmProjectService.selectOne(baseProject);
            //每一个门店

            for (BaseStores pagesorganization : pagesorganizations) {
                List<RateContribution> rateContributionls = new ArrayList<>();
                BaseProject baseProjects = new BaseProject();
                baseProjects.setStoreId(pagesorganization.getId());
                baseProjects.setProjectNum(baseProject.getProjectNum());
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProjects);

                String[] split = format.format(rateContribution.getStartDate()).split("-");
                Integer year = Integer.valueOf(split[0]);
                Integer month = Integer.valueOf(split[1]);
                Date selectDate = null;
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
                while(selectDate.before(rateContribution.getEndDate())){
                    //检查每一个门店是否有引入该项目

                    if(null != baseProject1){ // 有存在才需要计算
                        RateContribution rateContribution1 = new RateContribution();
                        rateContribution1.setAmount(BigDecimal.valueOf(0));
                        rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                        rateContribution1.setPriceMember(baseProject1.getPriceMember());
                        rateContribution1.setCountTC(BigDecimal.valueOf(0));
                        rateContribution1.setNumberTimes(0);
                        rateContribution1.setProjectNum(baseProject1.getProjectNum());
                        rateContribution1.setProjectName(baseProject1.getProjectName());
                        rateContribution1.setStoreId(pagesorganization.getId());
                        rateContribution1.setStoreNum(pagesorganization.getStoreNum());
                        rateContribution1.setStoreName(pagesorganization.getStoreName());


                        //先查询疗程
                        CourseList courseList = new CourseList();
                        courseList.setDate(selectDate);
                        courseList.setProjctId(baseProject1.getId());
                        courseList.setStoreId(pagesorganization.getId());
                        courseList.setIsCancel(0);
                        List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
                        for (CourseList list : courseList1) {
                            CourseRateContribution(list,null,null,null,null,rateContribution1);
                        }

                        //查询转入疗程
                        Example exampleInProject = new Example(CardChangeInProject.class);
                        Example.Criteria criteriaInProject = exampleInProject.createCriteria();
                        criteriaInProject.andEqualTo("storeId",pagesorganization.getId());
                        criteriaInProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                        criteriaInProject.andEqualTo("projectId",baseProject1.getId());
                        List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
                        for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
                            CardChangeList cardChangeList = new CardChangeList();
                            cardChangeList.setDocNum(cardChangeInProject.getDocNum());
                            cardChangeList.setStoreId(cardChangeInProject.getStoreId());
                            CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                            if(cardChangeList1.getState()==3){
                                CourseRateContribution(null,cardChangeInProject,null,null,null,rateContribution1);
                            }
                        }

                        //查询转出疗程
                        Example exampleOutProject = new Example(CardChangeOutProject.class);
                        Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
                        criteriaOutProject.andEqualTo("storeId",pagesorganization.getId());
                        criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                        criteriaOutProject.andEqualTo("courseProjectId",baseProject1.getId());
                        List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
                        for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
                            CardChangeList cardChangeList = new CardChangeList();
                            cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
                            cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
                            CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                            if(cardChangeList1.getState()==3){
                                CourseRateContribution(null,null,cardChangeOutProject,null,null,rateContribution1);
                            }
                        }


                        //查询疗程转充值卡
                        Example exampleTurnCourse = new Example(CoursePayList.class);
                        Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
                        criteriaTurnCourse.andEqualTo("storeId",pagesorganization.getId());
                        criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                        criteriaTurnCourse.andEqualTo("courseProjectId",baseProject1.getId());
                        List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
                        for (CoursePayList coursePayList : coursePayLists) {
                            RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
                            if(rechargeTurnCourse.getState()==0){
                                CourseRateContribution(null,null,null,coursePayList,null,rateContribution1);
                            }
                        }
                        //疗程退

                        Example exampleRefundCourse = new Example(RefundCourse.class);
                        Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
                        criteriaRefundCourse.andEqualTo("storeId",pagesorganization.getId());
                        criteriaRefundCourse.andLike("refundNum","%"+format.format(selectDate).replace("-","")+"%");
                        criteriaRefundCourse.andEqualTo("courseProjectId",baseProject1.getId());
                        List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
                        for (RefundCourse refundCours : refundCourses) {
                            RefundOrderList refundOrderList = new RefundOrderList();
                            refundOrderList.setRefundNum(refundCours.getRefundNum());
                            refundOrderList.setStoreId(refundCours.getStoreId());
                            RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
                            if(refundOrderList1.getState()==3){
                                CourseRateContribution(null,null,null,null,refundCours,rateContribution1);
                            }
                        }
                        rateContributionls.add(rateContribution1);
                    }
                    month++;
                    if(month>12){
                        month=1;
                        year++;
                    }
                    if(month<10){
                        selectDate= format.parse(year+"-0"+month);
                    }else{
                        selectDate= format.parse(year+"-"+month);
                    }
                }

                if(null != baseProject1){
                    RateContribution rateContribution2 = new RateContribution();
                    rateContribution2.setProjectNum(baseProject1.getProjectNum());
                    rateContribution2.setProjectName(baseProject1.getProjectName());
                    rateContribution2.setAmount(BigDecimal.valueOf(0));
                    rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                    rateContribution2.setPriceMember(baseProject1.getPriceMember());
                    rateContribution2.setCountTC(BigDecimal.valueOf(0));
                    rateContribution2.setNumberTimes(0);
                    Integer collect = rateContributionls.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                    BigDecimal reduce = rateContributionls.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal reduce1 = rateContributionls.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                    rateContribution2.setNumberTimes(collect);
                    rateContribution2.setAmount(reduce);
                    rateContribution2.setCountTC(reduce1);
                    rateContribution2.setStoreId(pagesorganization.getId());
                    rateContribution2.setStoreName(pagesorganization.getStoreName());
                    rateContribution2.setStoreNum(pagesorganization.getStoreNum());
                    if(collect==0){
                        rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                    }else{
                        rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                    }
                    rateContribution2.setPriceMember(baseProject1.getPriceMember());
                    rateContribution2.setStoreIdType(0);
                    rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                    rateContributions.add(rateContribution2);
                }

            }


        }else{ //分店项目
            BaseProject baseProject = new BaseProject();
            baseProject.setStoreId(rateContribution.getStoreId());
            baseProject.setProjectNum(rateContribution.getProjectNum());
            BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);

            BaseStore baseStore = new BaseStore();
            baseStore.setId(rateContribution.getStoreId());
            baseStore = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());
            List<RateContribution> rateContributionls = new ArrayList<>();
            String[] split = format.format(rateContribution.getStartDate()).split("-");
            Integer year = Integer.valueOf(split[0]);
            Integer month = Integer.valueOf(split[1]);
            Date selectDate = null;
            if(month<10){
                selectDate= format.parse(year+"-0"+month);
            }else{
                selectDate= format.parse(year+"-"+month);
            }
            while(selectDate.before(rateContribution.getEndDate())){
                //检查每一个门店是否有引入该项目

                if(null != baseProject1){ // 有存在才需要计算
                    RateContribution rateContribution1 = new RateContribution();
                    rateContribution1.setAmount(BigDecimal.valueOf(0));
                    rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                    rateContribution1.setPriceMember(baseProject1.getPriceMember());
                    rateContribution1.setCountTC(BigDecimal.valueOf(0));
                    rateContribution1.setNumberTimes(0);
                    rateContribution1.setProjectNum(baseProject1.getProjectNum());
                    rateContribution1.setProjectName(baseProject1.getProjectName());
                    rateContribution1.setStoreId(baseStore.getId());
                    rateContribution1.setStoreNum(baseStore.getStoreNum());
                    rateContribution1.setStoreName(baseStore.getStoreName());


                    //先查询疗程
                    CourseList courseList = new CourseList();
                    courseList.setDate(selectDate);
                    courseList.setProjctId(baseProject1.getId());
                    courseList.setStoreId(baseStore.getId());
                    courseList.setIsCancel(0);
                    List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
                    for (CourseList list : courseList1) {
                        CourseRateContribution(list,null,null,null,null,rateContribution1);
                    }

                    //查询转入疗程
                    Example exampleInProject = new Example(CardChangeInProject.class);
                    Example.Criteria criteriaInProject = exampleInProject.createCriteria();
                    criteriaInProject.andEqualTo("storeId",baseStore.getId());
                    criteriaInProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                    criteriaInProject.andEqualTo("projectId",baseProject1.getId());
                    List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
                    for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
                        CardChangeList cardChangeList = new CardChangeList();
                        cardChangeList.setDocNum(cardChangeInProject.getDocNum());
                        cardChangeList.setStoreId(cardChangeInProject.getStoreId());
                        CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                        if(cardChangeList1.getState()==3){
                            CourseRateContribution(null,cardChangeInProject,null,null,null,rateContribution1);
                        }
                    }

                    //查询转出疗程
                    Example exampleOutProject = new Example(CardChangeOutProject.class);
                    Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
                    criteriaOutProject.andEqualTo("storeId",baseStore.getId());
                    criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                    criteriaOutProject.andEqualTo("courseProjectId",baseProject1.getId());
                    List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
                    for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
                        CardChangeList cardChangeList = new CardChangeList();
                        cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
                        cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
                        CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                        if(cardChangeList1.getState()==3){
                            CourseRateContribution(null,null,cardChangeOutProject,null,null,rateContribution1);
                        }
                    }


                    //查询疗程转充值卡
                    Example exampleTurnCourse = new Example(CoursePayList.class);
                    Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
                    criteriaTurnCourse.andEqualTo("storeId",baseStore.getId());
                    criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                    criteriaTurnCourse.andEqualTo("courseProjectId",baseProject1.getId());
                    List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
                    for (CoursePayList coursePayList : coursePayLists) {
                        RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
                        if(rechargeTurnCourse.getState()==0){
                            CourseRateContribution(null,null,null,coursePayList,null,rateContribution1);
                        }
                    }
                    //疗程退

                    Example exampleRefundCourse = new Example(RefundCourse.class);
                    Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
                    criteriaRefundCourse.andEqualTo("storeId",baseStore.getId());
                    criteriaRefundCourse.andLike("refundNum","%"+format.format(selectDate).replace("-","")+"%");
                    criteriaRefundCourse.andEqualTo("courseProjectId",baseProject1.getId());
                    List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
                    for (RefundCourse refundCours : refundCourses) {
                        RefundOrderList refundOrderList = new RefundOrderList();
                        refundOrderList.setRefundNum(refundCours.getRefundNum());
                        refundOrderList.setStoreId(refundCours.getStoreId());
                        RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
                        if(refundOrderList1.getState()==3){
                            CourseRateContribution(null,null,null,null,refundCours,rateContribution1);
                        }
                    }
                    rateContributionls.add(rateContribution1);
                }
                month++;
                if(month>12){
                    month=1;
                    year++;
                }
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
            }


            RateContribution rateContribution2 = new RateContribution();
            rateContribution2.setProjectNum(baseProject1.getProjectNum());
            rateContribution2.setProjectName(baseProject1.getProjectName());
            rateContribution2.setAmount(BigDecimal.valueOf(0));
            rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
            rateContribution2.setPriceMember(baseProject1.getPriceMember());
            rateContribution2.setCountTC(BigDecimal.valueOf(0));
            rateContribution2.setNumberTimes(0);
            Integer collect = rateContributionls.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
            BigDecimal reduce = rateContributionls.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce1 = rateContributionls.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
            rateContribution2.setNumberTimes(collect);
            rateContribution2.setAmount(reduce);
            rateContribution2.setCountTC(reduce1);
            rateContribution2.setStoreId(baseStore.getId());
            rateContribution2.setStoreName(baseStore.getStoreName());
            rateContribution2.setStoreNum(baseStore.getStoreNum());
            if(collect==0){
                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
            }else{
                rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
            }
            rateContribution2.setPriceMember(baseProject1.getPriceMember());
            rateContribution2.setStoreIdType(0);
            rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
            rateContributions.add(rateContribution2);
        }


        List<RateContribution> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;

        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }

        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }

        if(pageSize>rateContributions.size()){
            pageSize= rateContributions.size();
        }

        if(rateContribution.getSorts()==0){
            rateContributions.sort(comparing(RateContribution::getAmount).reversed());
        }else{
            rateContributions.sort(comparing(RateContribution::getAmount));
        }

        List<RateContribution> rateContributions2 = rateContributions.subList(pageNum, pageSize);
        PageInfo<RateContribution> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributions.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContribution> selectRateContributionMxs(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContribution> rateContributions = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        BaseProject baseProject = new BaseProject();
        baseProject.setStoreId(rateContribution.getStoreId());
        baseProject.setProjectNum(rateContribution.getProjectNum());
        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);

        String[] splite = format.format(rateContribution.getEndDate()).split("-");
        Integer yeare = Integer.valueOf(splite[0]);
        Integer monthe = Integer.valueOf(splite[1]);
        String DateEnd = null;
        monthe++;
        if(monthe>12){
            monthe=1;
            yeare++;
        }
        if(monthe<10){
            DateEnd= yeare+"-0"+monthe+"-01";
        }else{
            DateEnd= yeare+"-"+monthe+"-01";
        }
        Date parse = format.parse(DateEnd);
        rateContribution.setEndDate(parse);
        BaseStore baseStore = new BaseStore();
        baseStore.setId(rateContribution.getStoreId());
        baseStore = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());
        List<RateContribution> rateContributionls = new ArrayList<>();
        String[] split = format.format(rateContribution.getStartDate()).split("-");
        Integer year = Integer.valueOf(split[0]);
        Integer month = Integer.valueOf(split[1]);
        Integer day = Integer.valueOf(split[2]);
        Date selectDate = null;

        if(month<10){
            if(day<10){
                selectDate= format.parse(year+"-0"+month+"-0"+day);
            }else{
                selectDate= format.parse(year+"-0"+month+"-"+day);
            }
        }else{
            if(day<10){
                selectDate= format.parse(year+"-"+month+"-0"+day);
            }else{
                selectDate= format.parse(year+"-"+month+"-"+day);
            }
        }
        while(selectDate.before(rateContribution.getEndDate())){
            //检查每一个门店是否有引入该项目
            int a=0;
            if(null != baseProject1){ // 有存在才需要计算
                RateContribution rateContribution1 = new RateContribution();
                rateContribution1.setAmount(BigDecimal.valueOf(0));
                rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                rateContribution1.setPriceMember(baseProject1.getPriceMember());
                rateContribution1.setCountTC(BigDecimal.valueOf(0));
                rateContribution1.setNumberTimes(0);
                rateContribution1.setProjectNum(baseProject1.getProjectNum());
                rateContribution1.setProjectName(baseProject1.getProjectName());
                rateContribution1.setStoreId(baseStore.getId());
                rateContribution1.setStoreNum(baseStore.getStoreNum());
                rateContribution1.setStoreName(baseStore.getStoreName());


                //先查询疗程
                CourseList courseList = new CourseList();
                courseList.setDate(selectDate);
                courseList.setProjctId(baseProject1.getId());
                courseList.setStoreId(baseStore.getId());
                courseList.setCourseReatmentNum(format.format(selectDate).replace("-",""));
                courseList.setIsCancel(0);
                List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
                for (CourseList list : courseList1) {
                    a++;
                    CourseRateContribution(list,null,null,null,null,rateContribution1);
                }

                //查询转入疗程
                Example exampleInProject = new Example(CardChangeInProject.class);
                Example.Criteria criteriaInProject = exampleInProject.createCriteria();
                criteriaInProject.andEqualTo("storeId",baseStore.getId());
                criteriaInProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                criteriaInProject.andEqualTo("projectId",baseProject1.getId());
                List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
                for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
                    CardChangeList cardChangeList = new CardChangeList();
                    cardChangeList.setDocNum(cardChangeInProject.getDocNum());
                    cardChangeList.setStoreId(cardChangeInProject.getStoreId());
                    CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                    if(cardChangeList1.getState()==3){
                        a++;
                        CourseRateContribution(null,cardChangeInProject,null,null,null,rateContribution1);
                    }
                }

                //查询转出疗程
                Example exampleOutProject = new Example(CardChangeOutProject.class);
                Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
                criteriaOutProject.andEqualTo("storeId",baseStore.getId());
                criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                criteriaOutProject.andEqualTo("courseProjectId",baseProject1.getId());
                List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
                for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
                    CardChangeList cardChangeList = new CardChangeList();
                    cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
                    cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
                    CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
                    if(cardChangeList1.getState()==3){
                        a++;
                        CourseRateContribution(null,null,cardChangeOutProject,null,null,rateContribution1);
                    }
                }


                //查询疗程转充值卡
                Example exampleTurnCourse = new Example(CoursePayList.class);
                Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
                criteriaTurnCourse.andEqualTo("storeId",baseStore.getId());
                criteriaOutProject.andLike("docNum",format.format(selectDate).replace("-","")+"%");
                criteriaTurnCourse.andEqualTo("courseProjectId",baseProject1.getId());
                List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
                for (CoursePayList coursePayList : coursePayLists) {
                    RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
                    if(rechargeTurnCourse.getState()==0){
                        a++;
                        CourseRateContribution(null,null,null,coursePayList,null,rateContribution1);
                    }
                }
                //疗程退

                Example exampleRefundCourse = new Example(RefundCourse.class);
                Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
                criteriaRefundCourse.andEqualTo("storeId",baseStore.getId());
                criteriaRefundCourse.andLike("refundNum","%"+format.format(selectDate).replace("-","")+"%");
                criteriaRefundCourse.andEqualTo("courseProjectId",baseProject1.getId());
                List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
                for (RefundCourse refundCours : refundCourses) {
                    RefundOrderList refundOrderList = new RefundOrderList();
                    refundOrderList.setRefundNum(refundCours.getRefundNum());
                    refundOrderList.setStoreId(refundCours.getStoreId());
                    RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
                    if(refundOrderList1.getState()==3){
                        a++;
                        CourseRateContribution(null,null,null,null,refundCours,rateContribution1);
                    }
                }
                rateContribution1.setProjectNum(baseProject1.getProjectNum());
                rateContribution1.setProjectName(baseProject1.getProjectName());
                rateContribution1.setStoreId(baseStore.getId());
                rateContribution1.setStoreName(baseStore.getStoreName());
                rateContribution1.setStoreNum(baseStore.getStoreNum());
                if(rateContribution1.getAmount().compareTo(BigDecimal.valueOf(0))==1){
                    if(rateContribution1.getNumberTimes()>0){
                        rateContribution1.setSalesPrice(rateContribution1.getAmount().divide(BigDecimal.valueOf(rateContribution1.getNumberTimes()),2,BigDecimal.ROUND_HALF_UP));
                    }else{
                        rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                    }
                }else{
                    rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                }
                rateContribution1.setDate(format.format(selectDate));
                if(a>0){
                    rateContributions.add(rateContribution1);
                }
            }
            Calendar   calendar = new GregorianCalendar();
            calendar.setTime(selectDate);
            calendar.add(calendar.DATE,1); //把日期往后增加一天,整数  往后推,负数往前移动
            selectDate=calendar.getTime(); //这个时间就是日期往后推一天的结果
        }

        List<RateContribution> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;
        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }
        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }
        if(pageSize>rateContributions.size()){
            pageSize= rateContributions.size();
        }

        rateContributions.sort(comparing(RateContribution::getDate).reversed());

        List<RateContribution> rateContributions2 = rateContributions.subList(pageNum, pageSize);
        PageInfo<RateContribution> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributions.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContributionMx> rateContributionMxOrder(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContributionMx> rateContributionMxs = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        BaseProject baseProject = new BaseProject();
        baseProject.setProjectNum(rateContribution.getProjectNum());
        baseProject.setStoreId(rateContribution.getStoreId());
        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);

        BaseStore baseStore = new BaseStore();
        baseStore.setId(rateContribution.getStoreId());
        BaseStore baseStore1 = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());

        //先查询疗程
        CourseList courseList = new CourseList();
        courseList.setDate(format.parse(rateContribution.getDate()));
        courseList.setProjctId(baseProject1.getId());
        courseList.setStoreId(rateContribution.getStoreId());
        courseList.setCourseReatmentNum(rateContribution.getDate().replace("-",""));
        courseList.setIsCancel(0);
        List<CourseList> courseList1 = ssmCourseService.selectListSalem(courseList);
        for (CourseList list : courseList1) {
            RateContributionMx rateContributionMx1 = new RateContributionMx();
            rateContributionMx1.setProjectNum(baseProject1.getProjectNum());
            rateContributionMx1.setProjectId(baseProject1.getId().toString());
            rateContributionMx1.setProjectName(baseProject1.getProjectName());
            rateContributionMx1.setStoreId(baseStore1.getId());
            rateContributionMx1.setStoreNum(baseStore1.getStoreNum());
            rateContributionMx1.setStoreName(baseStore1.getStoreName());
            rateContributionMx1.setNumberTimes(list.getNumberTimes());
            rateContributionMx1.setAmount(list.getCollectionCashAmount().add(list.getCollectionRechargeAmount()));
            rateContributionMx1.setDocId(list.getId());
            rateContributionMx1.setDocNum(list.getCourseReatmentNum());
            rateContributionMx1.setDocType(0);
            rateContributionMx1.setDate(format.format(list.getDate()));
            rateContributionMx1.setPrice(list.getSalesPrice());
            rateContributionMxs.add(rateContributionMx1);
        }

        //查询转入疗程
        Example exampleInProject = new Example(CardChangeInProject.class);
        Example.Criteria criteriaInProject = exampleInProject.createCriteria();
        criteriaInProject.andEqualTo("storeId",baseStore.getId());
        criteriaInProject.andLike("docNum",rateContribution.getDate().replace("-","")+"%");
        criteriaInProject.andEqualTo("projectId",baseProject1.getId());
        List<CardChangeInProject> cardChangeInProjects = ssmCardChangeInProjectService.selectByExample(exampleInProject);
        for (CardChangeInProject cardChangeInProject : cardChangeInProjects) {
            RateContributionMx rateContributionMx1 = new RateContributionMx();
            rateContributionMx1.setProjectNum(baseProject1.getProjectNum());
            rateContributionMx1.setProjectId(baseProject1.getId().toString());
            rateContributionMx1.setProjectName(baseProject1.getProjectName());
            rateContributionMx1.setStoreId(baseStore1.getId());
            rateContributionMx1.setStoreNum(baseStore1.getStoreNum());
            rateContributionMx1.setStoreName(baseStore1.getStoreName());
            rateContributionMx1.setNumberTimes(cardChangeInProject.getChangeInTime());
            rateContributionMx1.setAmount(cardChangeInProject.getChangeInMoney());
            rateContributionMx1.setDocId(cardChangeInProject.getId());
            rateContributionMx1.setDocNum(cardChangeInProject.getDocNum());
            rateContributionMx1.setDocType(1);
            rateContributionMx1.setDate(format.format(cardChangeInProject.getDocDate()));
            rateContributionMx1.setPrice(cardChangeInProject.getChangeInMoney().divide(BigDecimal.valueOf(cardChangeInProject.getChangeInTime()),2,BigDecimal.ROUND_HALF_UP));
            rateContributionMxs.add(rateContributionMx1);
        }

        //查询转出疗程
        Example exampleOutProject = new Example(CardChangeOutProject.class);
        Example.Criteria criteriaOutProject = exampleOutProject.createCriteria();
        criteriaOutProject.andEqualTo("storeId",baseStore.getId());
        criteriaOutProject.andLike("docNum",rateContribution.getDate().replace("-","")+"%");
        criteriaOutProject.andEqualTo("courseProjectId",baseProject1.getId());
        List<CardChangeOutProject> cardChangeOutProjects = ssmCardChangeOutProjectService.selectByExample(exampleOutProject);
        for (CardChangeOutProject cardChangeOutProject : cardChangeOutProjects) {
            CardChangeList cardChangeList = new CardChangeList();
            cardChangeList.setDocNum(cardChangeOutProject.getDocNum());
            cardChangeList.setStoreId(cardChangeOutProject.getStoreId());
            CardChangeList cardChangeList1 = ssmCardChangeService.selectOne(cardChangeList);
            if(cardChangeList1.getIsCancel()==0){
                RateContributionMx rateContributionMx1 = new RateContributionMx();
                rateContributionMx1.setProjectNum(baseProject1.getProjectNum());
                rateContributionMx1.setProjectId(baseProject1.getId().toString());
                rateContributionMx1.setProjectName(baseProject1.getProjectName());
                rateContributionMx1.setStoreId(baseStore1.getId());
                rateContributionMx1.setStoreNum(baseStore1.getStoreNum());
                rateContributionMx1.setStoreName(baseStore1.getStoreName());
                rateContributionMx1.setNumberTimes(cardChangeOutProject.getChangeOutTime());
                rateContributionMx1.setAmount(cardChangeOutProject.getChangeOutMoney());
                rateContributionMx1.setDocId(cardChangeOutProject.getId());
                rateContributionMx1.setDocNum(cardChangeOutProject.getDocNum());
                rateContributionMx1.setDocType(2);
                rateContributionMx1.setDate(format.format(cardChangeOutProject.getDocDate()));
                rateContributionMx1.setPrice(cardChangeOutProject.getChangeOutMoney().divide(BigDecimal.valueOf(cardChangeOutProject.getChangeOutTime()),2,BigDecimal.ROUND_HALF_UP));
                rateContributionMxs.add(rateContributionMx1);
            }
        }


        //查询疗程转充值卡
        Example exampleTurnCourse = new Example(CoursePayList.class);
        Example.Criteria criteriaTurnCourse = exampleTurnCourse.createCriteria();
        criteriaTurnCourse.andEqualTo("storeId",baseStore.getId());
        criteriaOutProject.andLike("docNum",rateContribution.getDate().replace("-","")+"%");
        criteriaTurnCourse.andEqualTo("courseProjectId",baseProject1.getId());
        List<CoursePayList> coursePayLists = ssmCoursePayListService.selectByExample(exampleTurnCourse);
        for (CoursePayList coursePayList : coursePayLists) {
            RechargeTurnCourse rechargeTurnCourse = ssmRechargeTurnCourseService.selectByPrimaryKey(coursePayList.getRechargeTurnCourseId());
            if(rechargeTurnCourse.getState()==0){
                RateContributionMx rateContributionMx1 = new RateContributionMx();
                rateContributionMx1.setProjectNum(baseProject1.getProjectNum());
                rateContributionMx1.setProjectId(baseProject1.getId().toString());
                rateContributionMx1.setProjectName(baseProject1.getProjectName());
                rateContributionMx1.setStoreId(baseStore1.getId());
                rateContributionMx1.setStoreNum(baseStore1.getStoreNum());
                rateContributionMx1.setStoreName(baseStore1.getStoreName());
                rateContributionMx1.setNumberTimes(coursePayList.getRollOffCount());
                rateContributionMx1.setAmount(coursePayList.getRollOffMoney());
                rateContributionMx1.setDocId(coursePayList.getId());
                rateContributionMx1.setDocNum(coursePayList.getDocNum());
                rateContributionMx1.setDocType(3);
                rateContributionMx1.setDate(coursePayList.getDocNum().substring(0,8));
                rateContributionMx1.setPrice(coursePayList.getRollOffMoney().divide(BigDecimal.valueOf(coursePayList.getRollOffCount()),2,BigDecimal.ROUND_HALF_UP));
                rateContributionMxs.add(rateContributionMx1);
            }
        }
        //疗程退

        Example exampleRefundCourse = new Example(RefundCourse.class);
        Example.Criteria criteriaRefundCourse = exampleRefundCourse.createCriteria();
        criteriaRefundCourse.andEqualTo("storeId",baseStore.getId());
        criteriaRefundCourse.andLike("refundNum","%"+rateContribution.getDate().replace("-","")+"%");
        criteriaRefundCourse.andEqualTo("courseProjectId",baseProject1.getId());
        List<RefundCourse> refundCourses = ssmRefundCourseService.selectByExample(exampleRefundCourse);
        for (RefundCourse refundCours : refundCourses) {
            RefundOrderList refundOrderList = new RefundOrderList();
            refundOrderList.setRefundNum(refundCours.getRefundNum());
            refundOrderList.setStoreId(refundCours.getStoreId());
            RefundOrderList refundOrderList1 = ssmRefundOrderService.selectOne(refundOrderList);
            if(refundOrderList1.getState()==3){
                RateContributionMx rateContributionMx1 = new RateContributionMx();
                rateContributionMx1.setProjectNum(baseProject1.getProjectNum());
                rateContributionMx1.setProjectId(baseProject1.getId().toString());
                rateContributionMx1.setProjectName(baseProject1.getProjectName());
                rateContributionMx1.setStoreId(baseStore1.getId());
                rateContributionMx1.setStoreNum(baseStore1.getStoreNum());
                rateContributionMx1.setStoreName(baseStore1.getStoreName());
                rateContributionMx1.setNumberTimes(refundCours.getRefundNumber());
                rateContributionMx1.setAmount(refundCours.getCourseRefundMoney());
                rateContributionMx1.setDocId(refundCours.getId());
                rateContributionMx1.setDocNum(refundCours.getRefundNum());
                rateContributionMx1.setDocType(2);
                rateContributionMx1.setDate(format.format(refundCours.getRefundDate()));
                rateContributionMx1.setPrice(refundCours.getCourseRefundMoney().divide(BigDecimal.valueOf(refundCours.getRefundNumber()),2,BigDecimal.ROUND_HALF_UP));
                rateContributionMxs.add(rateContributionMx1);
            }
        }
        List<RateContributionMx> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;
        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }
        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }
        if(pageSize>rateContributionMxs.size()){
            pageSize= rateContributionMxs.size();
        }

        rateContributionMxs.sort(comparing(RateContributionMx::getDate).reversed());

        List<RateContributionMx> rateContributions2 = rateContributionMxs.subList(pageNum, pageSize);
        PageInfo<RateContributionMx> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributionMxs.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContribution> selectCashRateContribution(RateContribution rateContribution) throws ParseException, SmsException {

        List<RateContribution> rateContributions = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        String[] splite = format.format(rateContribution.getEndDate()).split("-");
        Integer yeare = Integer.valueOf(splite[0]);
        Integer monthe = Integer.valueOf(splite[1]);
        String DateEnd = null;
        monthe++;
        if(monthe>12){
            monthe=1;
            yeare++;
        }
        if(monthe<10){
            DateEnd= yeare+"-0"+monthe;
        }else{
            DateEnd= yeare+"-"+monthe;
        }
        Date parse = format.parse(DateEnd);
        rateContribution.setEndDate(parse);
        //查询公司
        if(rateContribution.getSelectType()==0){
            StoreRequest storeRequest = new StoreRequest();
            storeRequest.setId(rateContribution.getStoreId());
            List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
            BaseStores baseStores = new BaseStores();
            baseStores = pagesorganizations.stream().filter(baseStores1 -> null == baseStores1.getParentId()).collect(Collectors.toList()).get(0);
            BaseProject baseProject = new BaseProject();
            baseProject.setStoreId(baseStores.getId());
            List<BaseProject> select = ssmProjectService.select(baseProject);


            for (BaseProject project : select) {
                //解析年月
                String[] split = format.format(rateContribution.getStartDate()).split("-");
                Integer year = Integer.valueOf(split[0]);
                Integer month = Integer.valueOf(split[1]);
                Date selectDate = null;
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
                //每一个门店
                List<RateContribution> rateContributionls = new ArrayList<>();
                while(selectDate.before(rateContribution.getEndDate())){
                    for (BaseStores pagesorganization : pagesorganizations) {
                        //检查每一个门店是否有引入该项目
                        baseProject.setStoreId(pagesorganization.getId());
                        baseProject.setProjectNum(project.getProjectNum());
                        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);
                        if(null != baseProject1){ // 有存在才需要计算
                            RateContribution rateContribution1 = new RateContribution();
                            rateContribution1.setAmount(BigDecimal.valueOf(0));
                            rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                            rateContribution1.setPriceMember(project.getPriceMember());
                            rateContribution1.setCountTC(BigDecimal.valueOf(0));
                            rateContribution1.setNumberTimes(0);
                            rateContribution1.setProjectNum(project.getProjectNum());
                            rateContribution1.setProjectName(project.getProjectName());



                            //先查询疗程
                            CashList cashList = new CashList();
                            cashList.setCashDate(selectDate);
                            cashList.setStoreId(pagesorganization.getId());
                            cashList.setProjectId(baseProject1.getId());
                            cashList.setIsCancel(0);
                            List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
                            for (CashList list : cashLists) {
                                CashCourseRateContribution(list,rateContribution1);
                            }

                            rateContributionls.add(rateContribution1);
                        }
                    }
                    month++;
                    if(month>12){
                        month=1;
                        year++;
                    }
                    if(month<10){
                        selectDate= format.parse(year+"-0"+month);
                    }else{
                        selectDate= format.parse(year+"-"+month);
                    }
                }
                RateContribution rateContribution2 = new RateContribution();
                rateContribution2.setProjectNum(project.getProjectNum());
                rateContribution2.setProjectName(project.getProjectName());
                rateContribution2.setAmount(BigDecimal.valueOf(0));
                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setCountTC(BigDecimal.valueOf(0));
                rateContribution2.setNumberTimes(0);
                Integer collect = rateContributionls.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                BigDecimal reduce = rateContributionls.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal reduce1 = rateContributionls.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                rateContribution2.setNumberTimes(collect);
                rateContribution2.setAmount(reduce);
                rateContribution2.setCountTC(reduce1);
                rateContribution2.setStoreId(baseStores.getId());
                rateContribution2.setStoreName(baseStores.getStoreName());
                if(collect==0){
                    rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                }else{
                    rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                }
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setStoreIdType(0);
                rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                rateContributions.add(rateContribution2);
            }

            //循环每一个门店
            for (BaseStores pagesorganization : pagesorganizations) {
                if(null != pagesorganization.getParentId()){
                    BaseProject baseProject1 = new BaseProject();
                    baseProject1.setStoreId(pagesorganization.getId());
                    List<BaseProject> select1 = ssmProjectService.select(baseProject1);


                    for (BaseProject project : select1) {
                        BaseProject baseProject2 = new BaseProject();
                        baseProject2.setStoreId(baseStores.getId());
                        baseProject2.setProjectNum(project.getProjectNum());
                        List<BaseProject> select2 = ssmProjectService.select(baseProject2);
                        if(select2.size()==0){
                            //解析年月
                            String[] split = format.format(rateContribution.getStartDate()).split("-");
                            Integer year = Integer.valueOf(split[0]);
                            Integer month = Integer.valueOf(split[1]);
                            Date selectDate = null;
                            if(month<10){
                                selectDate= format.parse(year+"-0"+month);
                            }else{
                                selectDate= format.parse(year+"-"+month);
                            }
                            List<RateContribution> rateContributions1 = new ArrayList<>();
                            while (selectDate.before(rateContribution.getEndDate())){
                                RateContribution rateContribution1 = new RateContribution();
                                rateContribution1.setAmount(BigDecimal.valueOf(0));
                                rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                                rateContribution1.setPriceMember(project.getPriceMember());
                                rateContribution1.setCountTC(BigDecimal.valueOf(0));
                                rateContribution1.setNumberTimes(0);
                                rateContribution1.setProjectNum(project.getProjectNum());
                                rateContribution1.setProjectName(project.getProjectName());

                                //查询收银
                                CashList cashList = new CashList();
                                cashList.setCashDate(selectDate);
                                cashList.setStoreId(baseStores.getId());
                                cashList.setProjectId(project.getId());
                                cashList.setIsCancel(0);
                                List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
                                for (CashList list : cashLists) {
                                    CashCourseRateContribution(list,rateContribution1);
                                }

                                rateContributions1.add(rateContribution1);

                                month++;
                                if(month>12){
                                    month=1;
                                    year++;
                                }
                                if(month<10){
                                    selectDate= format.parse(year+"-0"+month);
                                }else{
                                    selectDate= format.parse(year+"-"+month);
                                }

                            }

                            RateContribution rateContribution2 = new RateContribution();
                            rateContribution2.setProjectNum(project.getProjectNum());
                            rateContribution2.setProjectName(project.getProjectName());
                            rateContribution2.setAmount(BigDecimal.valueOf(0));
                            rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                            rateContribution2.setPriceMember(project.getPriceMember());
                            rateContribution2.setCountTC(BigDecimal.valueOf(0));
                            rateContribution2.setNumberTimes(0);
                            Integer collect = rateContributions1.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                            BigDecimal reduce = rateContributions1.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                            BigDecimal reduce1 = rateContributions1.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                            rateContribution2.setNumberTimes(collect);
                            rateContribution2.setAmount(reduce);
                            rateContribution2.setCountTC(reduce1);
                            rateContribution2.setStoreId(pagesorganization.getId());
                            rateContribution2.setStoreName(pagesorganization.getStoreName());
                            if(collect==0){
                                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                            }else{
                                rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                            }
                            rateContribution2.setPriceMember(project.getPriceMember());
                            rateContribution2.setStoreIdType(1);
                            rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                            rateContributions.add(rateContribution2);
                        }
                    }
                }
            }
        }else{ //查询门店
            BaseProject baseProject1 = new BaseProject();
            baseProject1.setStoreId(rateContribution.getStoreId());
            List<BaseProject> select1 = ssmProjectService.select(baseProject1);
            for (BaseProject project : select1) {
                //解析年月
                String[] split = format.format(rateContribution.getStartDate()).split("-");
                Integer year = Integer.valueOf(split[0]);
                Integer month = Integer.valueOf(split[1]);
                Date selectDate = null;
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
                List<RateContribution> rateContributions1 = new ArrayList<>();
                while (selectDate.before(rateContribution.getEndDate())){
                    RateContribution rateContribution1 = new RateContribution();
                    rateContribution1.setAmount(BigDecimal.valueOf(0));
                    rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                    rateContribution1.setPriceMember(project.getPriceMember());
                    rateContribution1.setCountTC(BigDecimal.valueOf(0));
                    rateContribution1.setNumberTimes(0);
                    rateContribution1.setProjectNum(project.getProjectNum());
                    rateContribution1.setProjectName(project.getProjectName());

                    //查询收银
                    //查询收银
                    CashList cashList = new CashList();
                    cashList.setCashDate(selectDate);
                    cashList.setStoreId(rateContribution.getStoreId());
                    cashList.setProjectId(project.getId());
                    cashList.setIsCancel(0);
                    List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
                    for (CashList list : cashLists) {
                        CashCourseRateContribution(list,rateContribution1);
                    }

                    rateContributions1.add(rateContribution1);

                    month++;
                    if(month>12){
                        month=1;
                        year++;
                    }
                    if(month<10){
                        selectDate= format.parse(year+"-0"+month);
                    }else{
                        selectDate= format.parse(year+"-"+month);
                    }

                }

                RateContribution rateContribution2 = new RateContribution();
                rateContribution2.setProjectNum(project.getProjectNum());
                rateContribution2.setProjectName(project.getProjectName());
                rateContribution2.setAmount(BigDecimal.valueOf(0));
                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setCountTC(BigDecimal.valueOf(0));
                rateContribution2.setNumberTimes(0);
                Integer collect = rateContributions1.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                BigDecimal reduce = rateContributions1.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                BigDecimal reduce1 = rateContributions1.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                rateContribution2.setNumberTimes(collect);
                rateContribution2.setAmount(reduce);
                rateContribution2.setCountTC(reduce1);
                if(collect==0){
                    rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                }else{
                    rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                }
                rateContribution2.setPriceMember(project.getPriceMember());
                rateContribution2.setStoreIdType(1);
                rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                BaseStore baseStore = new BaseStore();
                baseStore.setId(rateContribution.getStoreId());
                BaseStore baseStore1 = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());

                rateContribution2.setStoreId(baseStore1.getId());
                rateContribution2.setStoreName(baseStore1.getStoreName());
                rateContribution2.setStoreNum(baseStore1.getStoreNum());
                rateContributions.add(rateContribution2);
            }

        }
        List<RateContribution> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;
        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }
        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }
        if(pageSize>rateContributions.size()){
            pageSize= rateContributions.size();
        }

        if(rateContribution.getSorts()==0){
            rateContributions.sort(comparing(RateContribution::getAmount).reversed());
        }else{
            rateContributions.sort(comparing(RateContribution::getAmount));
        }

        List<RateContribution> rateContributions2 = rateContributions.subList(pageNum, pageSize);
        PageInfo<RateContribution> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributions.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContribution> selectCashRateContributionMx(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContribution> rateContributions = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");

        String[] splite = format.format(rateContribution.getEndDate()).split("-");
        Integer yeare = Integer.valueOf(splite[0]);
        Integer monthe = Integer.valueOf(splite[1]);
        String DateEnd = null;
        monthe++;
        if(monthe>12){
            monthe=1;
            yeare++;
        }
        if(monthe<10){
            DateEnd= yeare+"-0"+monthe;
        }else{
            DateEnd= yeare+"-"+monthe;
        }
        Date parse = format.parse(DateEnd);
        rateContribution.setEndDate(parse);

        if(rateContribution.getStoreIdType()==0){//总店项目
            StoreRequest storeRequest = new StoreRequest();
            storeRequest.setId(rateContribution.getStoreId());
            List<BaseStores> pagesorganizations = ssmBaseStoreService.pagesorganizations(storeRequest);
            BaseProject baseProject = new BaseProject();
            baseProject.setProjectNum(rateContribution.getProjectNum());
            baseProject.setStoreId(rateContribution.getStoreId());
            baseProject = ssmProjectService.selectOne(baseProject);
            //每一个门店

            for (BaseStores pagesorganization : pagesorganizations) {
                List<RateContribution> rateContributionls = new ArrayList<>();
                BaseProject baseProjects = new BaseProject();
                baseProjects.setStoreId(pagesorganization.getId());
                baseProjects.setProjectNum(baseProject.getProjectNum());
                BaseProject baseProject1 = ssmProjectService.selectOne(baseProjects);

                String[] split = format.format(rateContribution.getStartDate()).split("-");
                Integer year = Integer.valueOf(split[0]);
                Integer month = Integer.valueOf(split[1]);
                Date selectDate = null;
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
                while(selectDate.before(rateContribution.getEndDate())){
                    //检查每一个门店是否有引入该项目

                    if(null != baseProject1){ // 有存在才需要计算
                        RateContribution rateContribution1 = new RateContribution();
                        rateContribution1.setAmount(BigDecimal.valueOf(0));
                        rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                        rateContribution1.setPriceMember(baseProject1.getPriceMember());
                        rateContribution1.setCountTC(BigDecimal.valueOf(0));
                        rateContribution1.setNumberTimes(0);
                        rateContribution1.setProjectNum(baseProject1.getProjectNum());
                        rateContribution1.setProjectName(baseProject1.getProjectName());
                        rateContribution1.setStoreId(pagesorganization.getId());
                        rateContribution1.setStoreNum(pagesorganization.getStoreNum());
                        rateContribution1.setStoreName(pagesorganization.getStoreName());


                        CashList cashList = new CashList();
                        cashList.setCashDate(selectDate);
                        cashList.setStoreId(pagesorganization.getId());
                        cashList.setProjectId(baseProject1.getId());
                        cashList.setIsCancel(0);
                        List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
                        for (CashList list : cashLists) {
                            CashCourseRateContribution(list,rateContribution1);
                        }
                        rateContributionls.add(rateContribution1);
                    }
                    month++;
                    if(month>12){
                        month=1;
                        year++;
                    }
                    if(month<10){
                        selectDate= format.parse(year+"-0"+month);
                    }else{
                        selectDate= format.parse(year+"-"+month);
                    }
                }

                if(null != baseProject1){
                    RateContribution rateContribution2 = new RateContribution();
                    rateContribution2.setProjectNum(baseProject1.getProjectNum());
                    rateContribution2.setProjectName(baseProject1.getProjectName());
                    rateContribution2.setAmount(BigDecimal.valueOf(0));
                    rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                    rateContribution2.setPriceMember(baseProject1.getPriceMember());
                    rateContribution2.setCountTC(BigDecimal.valueOf(0));
                    rateContribution2.setNumberTimes(0);
                    Integer collect = rateContributionls.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
                    BigDecimal reduce = rateContributionls.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal reduce1 = rateContributionls.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
                    rateContribution2.setNumberTimes(collect);
                    rateContribution2.setAmount(reduce);
                    rateContribution2.setCountTC(reduce1);
                    rateContribution2.setStoreId(pagesorganization.getId());
                    rateContribution2.setStoreName(pagesorganization.getStoreName());
                    rateContribution2.setStoreNum(pagesorganization.getStoreNum());
                    if(collect==0){
                        rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
                    }else{
                        rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
                    }
                    rateContribution2.setPriceMember(baseProject1.getPriceMember());
                    rateContribution2.setStoreIdType(0);
                    rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
                    rateContributions.add(rateContribution2);
                }

            }


        }else{ //分店项目
            BaseProject baseProject = new BaseProject();
            baseProject.setStoreId(rateContribution.getStoreId());
            baseProject.setProjectNum(rateContribution.getProjectNum());
            BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);

            BaseStore baseStore = new BaseStore();
            baseStore.setId(rateContribution.getStoreId());
            baseStore = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());
            List<RateContribution> rateContributionls = new ArrayList<>();
            String[] split = format.format(rateContribution.getStartDate()).split("-");
            Integer year = Integer.valueOf(split[0]);
            Integer month = Integer.valueOf(split[1]);
            Date selectDate = null;
            if(month<10){
                selectDate= format.parse(year+"-0"+month);
            }else{
                selectDate= format.parse(year+"-"+month);
            }
            while(selectDate.before(rateContribution.getEndDate())){
                //检查每一个门店是否有引入该项目

                if(null != baseProject1){ // 有存在才需要计算
                    RateContribution rateContribution1 = new RateContribution();
                    rateContribution1.setAmount(BigDecimal.valueOf(0));
                    rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                    rateContribution1.setPriceMember(baseProject1.getPriceMember());
                    rateContribution1.setCountTC(BigDecimal.valueOf(0));
                    rateContribution1.setNumberTimes(0);
                    rateContribution1.setProjectNum(baseProject1.getProjectNum());
                    rateContribution1.setProjectName(baseProject1.getProjectName());
                    rateContribution1.setStoreId(baseStore.getId());
                    rateContribution1.setStoreNum(baseStore.getStoreNum());
                    rateContribution1.setStoreName(baseStore.getStoreName());


                    CashList cashList = new CashList();
                    cashList.setCashDate(selectDate);
                    cashList.setStoreId(baseStore.getId());
                    cashList.setProjectId(baseProject1.getId());
                    cashList.setIsCancel(0);
                    List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
                    for (CashList list : cashLists) {
                        CashCourseRateContribution(list,rateContribution1);
                    }

                    rateContributionls.add(rateContribution1);
                }
                month++;
                if(month>12){
                    month=1;
                    year++;
                }
                if(month<10){
                    selectDate= format.parse(year+"-0"+month);
                }else{
                    selectDate= format.parse(year+"-"+month);
                }
            }


            RateContribution rateContribution2 = new RateContribution();
            rateContribution2.setProjectNum(baseProject1.getProjectNum());
            rateContribution2.setProjectName(baseProject1.getProjectName());
            rateContribution2.setAmount(BigDecimal.valueOf(0));
            rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
            rateContribution2.setPriceMember(baseProject1.getPriceMember());
            rateContribution2.setCountTC(BigDecimal.valueOf(0));
            rateContribution2.setNumberTimes(0);
            Integer collect = rateContributionls.stream().collect(Collectors.summingInt(RateContribution::getNumberTimes));
            BigDecimal reduce = rateContributionls.stream().map(RateContribution::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce1 = rateContributionls.stream().map(RateContribution::getCountTC).reduce(BigDecimal.ZERO, BigDecimal::add);
            rateContribution2.setNumberTimes(collect);
            rateContribution2.setAmount(reduce);
            rateContribution2.setCountTC(reduce1);
            rateContribution2.setStoreId(baseStore.getId());
            rateContribution2.setStoreName(baseStore.getStoreName());
            rateContribution2.setStoreNum(baseStore.getStoreNum());
            if(collect==0){
                rateContribution2.setSalesPrice(BigDecimal.valueOf(0));
            }else{
                rateContribution2.setSalesPrice(reduce.divide(BigDecimal.valueOf(collect),2,BigDecimal.ROUND_HALF_UP));
            }
            rateContribution2.setPriceMember(baseProject1.getPriceMember());
            rateContribution2.setStoreIdType(0);
            rateContribution2.setASingleDifference(rateContribution2.getPriceMember().subtract(rateContribution2.getSalesPrice()));
            rateContributions.add(rateContribution2);
        }


        List<RateContribution> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;

        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }

        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }

        if(pageSize>rateContributions.size()){
            pageSize= rateContributions.size();
        }

        if(rateContribution.getSorts()==0){
            rateContributions.sort(comparing(RateContribution::getAmount).reversed());
        }else{
            rateContributions.sort(comparing(RateContribution::getAmount));
        }

        List<RateContribution> rateContributions2 = rateContributions.subList(pageNum, pageSize);
        PageInfo<RateContribution> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributions.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContribution> selectCashRateContributionMxs(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContribution> rateContributions = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        BaseProject baseProject = new BaseProject();
        baseProject.setStoreId(rateContribution.getStoreId());
        baseProject.setProjectNum(rateContribution.getProjectNum());
        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);

        String[] splite = format.format(rateContribution.getEndDate()).split("-");
        Integer yeare = Integer.valueOf(splite[0]);
        Integer monthe = Integer.valueOf(splite[1]);
        String DateEnd = null;
        monthe++;
        if(monthe>12){
            monthe=1;
            yeare++;
        }
        if(monthe<10){
            DateEnd= yeare+"-0"+monthe+"-01";
        }else{
            DateEnd= yeare+"-"+monthe+"-01";
        }
        Date parse = format.parse(DateEnd);
        rateContribution.setEndDate(parse);
        BaseStore baseStore = new BaseStore();
        baseStore.setId(rateContribution.getStoreId());
        baseStore = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());
        List<RateContribution> rateContributionls = new ArrayList<>();
        String[] split = format.format(rateContribution.getStartDate()).split("-");
        Integer year = Integer.valueOf(split[0]);
        Integer month = Integer.valueOf(split[1]);
        Integer day = Integer.valueOf(split[2]);
        Date selectDate = null;

        if(month<10){
            if(day<10){
                selectDate= format.parse(year+"-0"+month+"-0"+day);
            }else{
                selectDate= format.parse(year+"-0"+month+"-"+day);
            }
        }else{
            if(day<10){
                selectDate= format.parse(year+"-"+month+"-0"+day);
            }else{
                selectDate= format.parse(year+"-"+month+"-"+day);
            }
        }
        while(selectDate.before(rateContribution.getEndDate())){
            //检查每一个门店是否有引入该项目
            int a=0;
            if(null != baseProject1){ // 有存在才需要计算
                RateContribution rateContribution1 = new RateContribution();
                rateContribution1.setAmount(BigDecimal.valueOf(0));
                rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                rateContribution1.setPriceMember(baseProject1.getPriceMember());
                rateContribution1.setCountTC(BigDecimal.valueOf(0));
                rateContribution1.setNumberTimes(0);
                rateContribution1.setProjectNum(baseProject1.getProjectNum());
                rateContribution1.setProjectName(baseProject1.getProjectName());
                rateContribution1.setStoreId(baseStore.getId());
                rateContribution1.setStoreNum(baseStore.getStoreNum());
                rateContribution1.setStoreName(baseStore.getStoreName());

                CashList cashList = new CashList();
                cashList.setCashDate(selectDate);
                cashList.setStoreId(baseStore.getId());
                cashList.setCashNum(format.format(selectDate).replace("-",""));
                cashList.setProjectId(baseProject1.getId());
                cashList.setIsCancel(0);
                List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
                for (CashList list : cashLists) {
                    a++;
                    CashCourseRateContribution(list,rateContribution1);
                }
                rateContribution1.setProjectNum(baseProject1.getProjectNum());
                rateContribution1.setProjectName(baseProject1.getProjectName());
                rateContribution1.setStoreId(baseStore.getId());
                rateContribution1.setStoreName(baseStore.getStoreName());
                rateContribution1.setStoreNum(baseStore.getStoreNum());
                if(rateContribution1.getAmount().compareTo(BigDecimal.valueOf(0))==1){
                    if(rateContribution1.getNumberTimes()>0){
                        rateContribution1.setSalesPrice(rateContribution1.getAmount().divide(BigDecimal.valueOf(rateContribution1.getNumberTimes()),2,BigDecimal.ROUND_HALF_UP));
                    }else{
                        rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                    }
                }else{
                    rateContribution1.setSalesPrice(BigDecimal.valueOf(0));
                }
                rateContribution1.setDate(format.format(selectDate));
                if(a>0){
                    rateContributions.add(rateContribution1);
                }
            }
            Calendar   calendar = new GregorianCalendar();
            calendar.setTime(selectDate);
            calendar.add(calendar.DATE,1); //把日期往后增加一天,整数  往后推,负数往前移动
            selectDate=calendar.getTime(); //这个时间就是日期往后推一天的结果
        }

        List<RateContribution> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;
        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }
        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }
        if(pageSize>rateContributions.size()){
            pageSize= rateContributions.size();
        }

        rateContributions.sort(comparing(RateContribution::getDate).reversed());

        List<RateContribution> rateContributions2 = rateContributions.subList(pageNum, pageSize);
        PageInfo<RateContribution> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributions.size());
        return objectPageInfo;
    }

    @Override
    public PageInfo<RateContributionMx> CashrateContributionMxOrder(RateContribution rateContribution) throws ParseException, SmsException {
        List<RateContributionMx> rateContributionMxs = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        BaseProject baseProject = new BaseProject();
        baseProject.setProjectNum(rateContribution.getProjectNum());
        baseProject.setStoreId(rateContribution.getStoreId());
        BaseProject baseProject1 = ssmProjectService.selectOne(baseProject);

        BaseStore baseStore = new BaseStore();
        baseStore.setId(rateContribution.getStoreId());
        BaseStore baseStore1 = ssmBaseStoreService.selectByPrimaryKey(baseStore.getId());

        CashList cashList = new CashList();
        cashList.setCashDate(format.parse(rateContribution.getDate()));
        cashList.setStoreId(rateContribution.getStoreId());
        cashList.setCashNum(rateContribution.getDate().replace("-",""));
        cashList.setProjectId(baseProject1.getId());
        cashList.setIsCancel(0);
        List<CashList> cashLists = ssmCashService.selectListSalem(cashList);
        for (CashList list : cashLists) {
            RateContributionMx rateContributionMx1 = new RateContributionMx();
            rateContributionMx1.setProjectNum(baseProject1.getProjectNum());
            rateContributionMx1.setProjectId(baseProject1.getId().toString());
            rateContributionMx1.setProjectName(baseProject1.getProjectName());
            rateContributionMx1.setStoreId(baseStore1.getId());
            rateContributionMx1.setStoreNum(baseStore1.getStoreNum());
            rateContributionMx1.setStoreName(baseStore1.getStoreName());
            rateContributionMx1.setNumberTimes(list.getNumberTimes());
            rateContributionMx1.setAmount(list.getCollectionCashAmount().add(list.getCollectionRechargeAmount()));
            rateContributionMx1.setDocId(list.getId());
            rateContributionMx1.setDocNum(list.getCashNum());
            rateContributionMx1.setDocType(0);
            rateContributionMx1.setDate(format.format(list.getCashDate()));
            rateContributionMx1.setPrice(list.getTransactionPrice());
            rateContributionMxs.add(rateContributionMx1);
        }


        List<RateContributionMx> rateContributions1 = new ArrayList<>();
        int pageNum = 0;
        int pageSize = 0;
        if(rateContribution.getPageNum()!=1){
            pageNum=(rateContribution.getPageNum()*rateContribution.getPageSize())-11;
        }
        if(pageNum==0){
            pageSize = rateContribution.getPageSize();
        }else{
            pageSize = (rateContribution.getPageNum()*rateContribution.getPageSize());
        }
        if(pageSize>rateContributionMxs.size()){
            pageSize= rateContributionMxs.size();
        }

        rateContributionMxs.sort(comparing(RateContributionMx::getDate).reversed());

        List<RateContributionMx> rateContributions2 = rateContributionMxs.subList(pageNum, pageSize);
        PageInfo<RateContributionMx> objectPageInfo = new PageInfo<>(rateContributions2);
        objectPageInfo.setTotal(rateContributionMxs.size());
        return objectPageInfo;
    }

    //计算疗程单据的单品贡献率
    public void CourseRateContribution(CourseList list,CardChangeInProject cardChangeInProject,CardChangeOutProject cardChangeOutProject,CoursePayList coursePayList,RefundCourse refundCourse,RateContribution rateContribution1){
        if(list != null ){
            rateContribution1.setNumberTimes(rateContribution1.getNumberTimes()+list.getNumberTimes());
            rateContribution1.setAmount(rateContribution1.getAmount().add(list.getCourseReatmentAmount()));

            //计算卡付提成
            if(list.getCollectionRechargeAmount().compareTo(BigDecimal.valueOf(0))==1){//存在卡付
                //判断是否为固定金额
                if(list.getCardSalesAchievement().compareTo(BigDecimal.valueOf(1))==1){//固定金额
                    BigDecimal multiply = list.getCollectionRechargeAmount().multiply(list.getCardSalesAchievement());
                    if(list.getCardSalesCommission().compareTo(BigDecimal.valueOf(1))==1){//固定金额
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(list.getCardSalesCommission()));
                    }else{
                        BigDecimal comm = BigDecimalUtils.multiply(multiply, list.getCardSalesCommission());
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(comm));
                    }
                }else{
                    if(list.getCardSalesCommission().compareTo(BigDecimal.valueOf(1))==1){//固定金额
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(list.getCardSalesCommission()));
                    }else{
                        BigDecimal comm = BigDecimalUtils.multiply(list.getCollectionRechargeAmount(), list.getCardSalesAchievement());
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(comm.multiply(list.getCardSalesCommission())));
                    }
                }

            }
            //计算现付提成
            if(list.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0))==1) {//存在现付
                //判断提成是否为固定金额
                if(list.getSalesCommission().compareTo(BigDecimal.valueOf(1))==1){
                    rateContribution1.setCountTC(rateContribution1.getCountTC().add(list.getSalesCommission()));
                }else{
                    //判断业绩是否为固定金额
                    if(list.getSalesAchievement().compareTo(BigDecimal.valueOf(1))==1){
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(list.getSalesAchievement().multiply(list.getSalesCommission())));
                    }else{
                        BigDecimal multiply = list.getCollectionCashAmount().multiply(list.getSalesAchievement());
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(multiply.multiply(list.getSalesCommission())));
                    }
                }
            }
        }else if(cardChangeInProject != null ){
            rateContribution1.setNumberTimes(rateContribution1.getNumberTimes()+cardChangeInProject.getChangeInTime());
            rateContribution1.setAmount(rateContribution1.getAmount().add(cardChangeInProject.getChangeInPayMoney().add(cardChangeInProject.getChangeOutMoney())));

            //计算卡付提成
            if(cardChangeInProject.getChangeOutMoney().compareTo(BigDecimal.valueOf(0))==1){//存在卡付
                //判断是否为固定金额
                if(cardChangeInProject.getCardSalesAchievement().compareTo(BigDecimal.valueOf(1))==1){//固定金额
                    BigDecimal multiply = cardChangeInProject.getChangeOutMoney().multiply(cardChangeInProject.getCardSalesAchievement());
                    if(cardChangeInProject.getCardSalesCommission().compareTo(BigDecimal.valueOf(1))==1){//固定金额
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(cardChangeInProject.getCardSalesCommission()));
                    }else{
                        BigDecimal comm = BigDecimalUtils.multiply(multiply, cardChangeInProject.getCardSalesCommission());
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(comm));
                    }
                }else{
                    if(cardChangeInProject.getCardSalesCommission().compareTo(BigDecimal.valueOf(1))==1){//固定金额
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(cardChangeInProject.getCardSalesCommission()));
                    }else{
                        BigDecimal comm = BigDecimalUtils.multiply(cardChangeInProject.getChangeOutMoney(), cardChangeInProject.getCardSalesAchievement());
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(comm.multiply(cardChangeInProject.getCardSalesCommission())));
                    }
                }
            }
            //计算现付提成
            if(cardChangeInProject.getChangeInPayMoney().compareTo(BigDecimal.valueOf(0))==1) {//存在现付
                //判断提成是否为固定金额
                if(cardChangeInProject.getSalesCommission().compareTo(BigDecimal.valueOf(1))==1){
                    rateContribution1.setCountTC(rateContribution1.getCountTC().add(cardChangeInProject.getSalesCommission()));
                }else{
                    //判断业绩是否为固定金额
                    if(cardChangeInProject.getSalesAchievement().compareTo(BigDecimal.valueOf(1))==1){
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(cardChangeInProject.getSalesAchievement().multiply(cardChangeInProject.getSalesCommission())));
                    }else{
                        BigDecimal multiply = cardChangeInProject.getChangeInPayMoney().multiply(cardChangeInProject.getSalesAchievement());
                        rateContribution1.setCountTC(rateContribution1.getCountTC().add(multiply.multiply(cardChangeInProject.getSalesCommission())));
                    }
                }
            }
        }else if(cardChangeOutProject != null ){
            rateContribution1.setNumberTimes(rateContribution1.getNumberTimes()-cardChangeOutProject.getChangeOutTime());
            rateContribution1.setAmount(rateContribution1.getAmount().subtract(cardChangeOutProject.getChangeOutMoney()));

        }else if(coursePayList != null ){
            rateContribution1.setNumberTimes(rateContribution1.getNumberTimes()-coursePayList.getRollOffCount());
            rateContribution1.setAmount(rateContribution1.getAmount().subtract(coursePayList.getRollOffMoney()));
        }else if(refundCourse != null ){
            rateContribution1.setNumberTimes(rateContribution1.getNumberTimes()-refundCourse.getRefundNumber());
            rateContribution1.setAmount(rateContribution1.getAmount().subtract(refundCourse.getCourseRefundMoney()));

            //计算现付提成
            if(refundCourse.getCourseRefundMoney().compareTo(BigDecimal.valueOf(0))==1) {//存在现付
                rateContribution1.setCountTC(rateContribution1.getCountTC().subtract(refundCourse.getCommissionAmount()));
            }
        }

    }

    //计算收银疗程单据单品贡献率
    public void CashCourseRateContribution(CashList cashList,RateContribution rateContribution1){
        rateContribution1.setNumberTimes(rateContribution1.getNumberTimes()+1);
        rateContribution1.setAmount(rateContribution1.getAmount().add(cashList.getCollectionRechargeAmount().add(cashList.getCollectionCashAmount())));
        //设置业务人员列表
        if(null == cashList.getCourseAccountId()){ //是非疗程卡包收银
            List<AchiCommEntity> achiCommLists = this.getAchiCommLists(cashList);
            BigDecimal reduce = achiCommLists.stream().map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce1 = achiCommLists.stream().map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
            rateContribution1.setCountTC(rateContribution1.getCountTC().add(reduce.add(reduce1)));
        }else{ //卡包收银
            List<AchiCommEntity> achiCommListsCard = this.getAchiCommListsCard(cashList);
            BigDecimal reduce = achiCommListsCard.stream().map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
            BigDecimal reduce1 = achiCommListsCard.stream().map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
            rateContribution1.setCountTC(rateContribution1.getCountTC().add(reduce.add(reduce1)));
        }

    }

    //升级后修改的新业绩提成算法
    public List<AchiCommEntity> getAchiCommLists(CashList cashList){
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
        //减掉固定金额业绩的单据总金额
//        BigDecimal totalMeony = cashList.getCashAmount();
        BigDecimal totalMeony = cashList.getCollectionCashAmount().add(cashList.getCollectionRechargeAmount());
        BigDecimal GDtotalMeony = cashList.getCollectionCashAmount().add(cashList.getCollectionRechargeAmount());
        //减掉固定金额业绩的单据现付金额
        BigDecimal achievementMeony = cashList.getCollectionCashAmount();
        //减掉固定金额业绩的单据卡付金额
        BigDecimal cardMeony = cashList.getCollectionRechargeAmount();
//        BigDecimal bigDecimal = BigDecimal.valueOf(Double.valueOf(cashList.getCollectionAmount()));
//        BigDecimal cardMeony =bigDecimal.subtract(cashList.getCollectionCashAmount());

        //存在卡付，也存在现付
        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1){
            //判断大工是否存在
            if(null != cashList.getServiceLargeOneStaffId() || null != cashList.getServiceLargeTwoStaffId() || null != cashList.getServiceLargeThreeStaffId()){
                //判断卡付和现付是否同时存在
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1 &&cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementLarge(), cashList.getAchievementLarge());
                    achievementMeony= BigDecimalUtils.subtract(achievementMeony,fixedAmount.get("cash"));
                    cardMeony= BigDecimalUtils.subtract(cardMeony,fixedAmount.get("card"));

                    totalMeony= BigDecimalUtils.subtract(totalMeony,fixedAmount.get("total"));
                }else{
                    //判断现付业绩是否为固定金额
                    if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementLarge());


                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementLarge());
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementLarge());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementLarge());
                    }
                }

            }

            //判断中工是否存在
            if(null != cashList.getServiceZhonggongOneStaffId() || null != cashList.getServiceZhonggongTwoStaffId() || null != cashList.getServiceZhonggongThreeStaffId()){
                //判断卡付和现付是否同时存在
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1 &&cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                    HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementZhonggong(), cashList.getAchievementZhonggong());
                    achievementMeony = BigDecimalUtils.subtract(achievementMeony, fixedAmount.get("cash"));
                    cardMeony = BigDecimalUtils.subtract(cardMeony, fixedAmount.get("card"));

                    totalMeony = BigDecimalUtils.subtract(totalMeony, fixedAmount.get("total"));
                }else{
                    if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementZhonggong());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementZhonggong());
                    }
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementZhonggong());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementZhonggong());
                    }
                }
            }

            //判断小工（技师）是否存在
            if(null != cashList.getServiceTechnicianOneStaffId() || null != cashList.getServiceTechnicianTwoStaffId() || null != cashList.getServiceTechnicianThreeStaffId()){
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1 && cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                    HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementTechnician(), cashList.getAchievementTechnician());
                    achievementMeony = BigDecimalUtils.subtract(achievementMeony, fixedAmount.get("cash"));
                    cardMeony = BigDecimalUtils.subtract(cardMeony, fixedAmount.get("card"));

                    totalMeony = BigDecimalUtils.subtract(totalMeony, fixedAmount.get("total"));
                }else{
                    if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementTechnician());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementTechnician());
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementTechnician());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementTechnician());
                    }
                }
            }

            //判断助理是否存在
            if(null != cashList.getServiceSmallOneStaffId() || null != cashList.getServiceSmallTwoStaffId() || null != cashList.getServiceSmallThreeStaffId()){
                if( cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1 && cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                    HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementSmall(), cashList.getAchievementSmall());
                    achievementMeony = BigDecimalUtils.subtract(achievementMeony, fixedAmount.get("cash"));
                    cardMeony = BigDecimalUtils.subtract(cardMeony, fixedAmount.get("card"));

                    totalMeony = BigDecimalUtils.subtract(totalMeony, fixedAmount.get("total"));
                }else{
                    if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementSmall());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementSmall());
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                        cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementSmall());
                        totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementSmall());
                    }
                }


            }

            //大工1编码
            if (null != cashList.getServiceLargeOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));

                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
                achiCommEntity.setSaleAchievementAmount(cashList.getAchievementLarge());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
                        BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementLarge(), cashList.getAchievementLarge());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony,cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                        }
                    }
                }

                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);
//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
//                    BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工2编码
            if (null != cashList.getServiceLargeTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                //判断现付业绩是否为固定金额
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementLarge(), cashList.getAchievementLarge());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工3编码
            if (null != cashList.getServiceLargeThreeStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                //判断现付业绩是否为固定金额
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementLarge(), cashList.getAchievementLarge());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionLarge(), cashList.getCommissionLarge());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);


//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工1编码
            if (null != cashList.getServiceZhonggongOneStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(
                        BigDecimalUtils.add(
                                BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                                BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementZhonggong(), cashList.getAchievementZhonggong());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(
//                    BigDecimalUtils.add(
//                        BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                            BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工2编码
            if (null != cashList.getServiceZhonggongTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementZhonggong(), cashList.getAchievementZhonggong());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工3编码
            if (null != cashList.getServiceZhonggongThreeStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementZhonggong(), cashList.getAchievementZhonggong());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionZhonggong(), cashList.getCommissionZhonggong());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);



//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //技师1编码
            if (null != cashList.getServiceTechnicianOneStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementTechnician(), cashList.getAchievementTechnician());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

                entities.add(achiCommEntity);
            }
            //技师2编码
            if (null != cashList.getServiceTechnicianTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementTechnician(), cashList.getAchievementTechnician());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //技师3编码
            if (null != cashList.getServiceTechnicianThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));


                //判断现付业绩是否为固定金额
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementTechnician(), cashList.getAchievementTechnician());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionTechnician(), cashList.getCommissionTechnician());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理1编码
            if (null != cashList.getServiceSmallOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementSmall(), cashList.getAchievementSmall());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理2编码
            if (null != cashList.getServiceSmallTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));

                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementSmall(), cashList.getAchievementSmall());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理3编码
            if (null != cashList.getServiceSmallThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));

                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));


                //判断现付业绩是否为固定金额
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardAchievementSmall(), cashList.getAchievementSmall());
                        achiCommEntity.setCashAchi(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }else{
                        achiCommEntity.setCashAchi(cashList.getAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }

                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }

                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }

                    }else{
                        //卡付业绩比例计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCashComm(fixedAmount.get("cash").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }
                    //判断卡付业绩是否为固定金额
                    if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //卡付业绩按固定金额计算
                        //计算卡付业绩
                        if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                            HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                            achiCommEntity.setCardAchi(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }else{
                            achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }
                    }else{
                        //卡付业绩百分比计算
                        achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        //计算卡付提成
                        //判断卡付提成是否为固定金额
                        if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                            //提成按固定金额算
                            if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1 && cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1 &&cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {
                                HashMap<String, BigDecimal> fixedAmount = this.getFixedAmount(cardMeony, cashList.getCollectionCashAmount(), cashList.getCardCommissionSmall(), cashList.getCommissionSmall());
                                achiCommEntity.setCardComm(fixedAmount.get("card").multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }else{
                                achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                            }
                        }else{
                            //提成按百分百
                            achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                        }
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
        }else if(cardMeony.compareTo(BigDecimal.valueOf(0)) == 1){//只有卡付
            //判断大工是否存在
            if(null != cashList.getServiceLargeOneStaffId() || null != cashList.getServiceLargeTwoStaffId() || null != cashList.getServiceLargeThreeStaffId()){
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementLarge());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementLarge());
                }
            }

            //判断中工是否存在
            if(null != cashList.getServiceZhonggongOneStaffId() || null != cashList.getServiceZhonggongTwoStaffId() || null != cashList.getServiceZhonggongThreeStaffId()){
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementZhonggong());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementZhonggong());
                }
            }

            //判断小工（技师）是否存在
            if(null != cashList.getServiceTechnicianOneStaffId() || null != cashList.getServiceTechnicianTwoStaffId() || null != cashList.getServiceTechnicianThreeStaffId()){
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementTechnician());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementTechnician());
                }
            }

            //判断助理是否存在
            if(null != cashList.getServiceSmallOneStaffId() || null != cashList.getServiceSmallTwoStaffId() || null != cashList.getServiceSmallThreeStaffId()){
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementSmall());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getCardAchievementSmall());
                }
            }

            //大工1编码
            if (null != cashList.getServiceLargeOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
                achiCommEntity.setSaleAchievementAmount(cashList.getAchievementLarge());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
                        BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }
                }

                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);
//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
//                    BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工2编码
            if (null != cashList.getServiceLargeTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));

                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工3编码
            if (null != cashList.getServiceLargeThreeStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);


//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工1编码
            if (null != cashList.getServiceZhonggongOneStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(
                        BigDecimalUtils.add(
                                BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                                BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(
//                    BigDecimalUtils.add(
//                        BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                            BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工2编码
            if (null != cashList.getServiceZhonggongTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工3编码
            if (null != cashList.getServiceZhonggongThreeStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);



//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //技师1编码
            if (null != cashList.getServiceTechnicianOneStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

                entities.add(achiCommEntity);
            }
            //技师2编码
            if (null != cashList.getServiceTechnicianTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //技师3编码
            if (null != cashList.getServiceTechnicianThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));


                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理1编码
            if (null != cashList.getServiceSmallOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理2编码
            if (null != cashList.getServiceSmallTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理3编码
            if (null != cashList.getServiceSmallThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));


                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
        }else if(cashList.getCollectionCashAmount().compareTo(BigDecimal.valueOf(0)) == 1) {//只有现付
            //判断大工是否存在
            if(null != cashList.getServiceLargeOneStaffId() || null != cashList.getServiceLargeTwoStaffId() || null != cashList.getServiceLargeThreeStaffId()){
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementLarge());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementLarge());
                }
            }

            //判断中工是否存在
            if(null != cashList.getServiceZhonggongOneStaffId() || null != cashList.getServiceZhonggongTwoStaffId() || null != cashList.getServiceZhonggongThreeStaffId()){
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementZhonggong());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementZhonggong());
                }
            }

            //判断小工（技师）是否存在
            if(null != cashList.getServiceTechnicianOneStaffId() || null != cashList.getServiceTechnicianTwoStaffId() || null != cashList.getServiceTechnicianThreeStaffId()){
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementTechnician());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementTechnician());
                }
            }

            //判断助理是否存在
            if(null != cashList.getServiceSmallOneStaffId() || null != cashList.getServiceSmallTwoStaffId() || null != cashList.getServiceSmallThreeStaffId()){
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    achievementMeony= BigDecimalUtils.subtract(achievementMeony,cashList.getAchievementSmall());
                    totalMeony= BigDecimalUtils.subtract(totalMeony,cashList.getAchievementSmall());
                }
            }

            //大工1编码
            if (null != cashList.getServiceLargeOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
                achiCommEntity.setSaleAchievementAmount(cashList.getAchievementLarge());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
                        BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }
                }

                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);
//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
//                    BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工2编码
            if (null != cashList.getServiceLargeTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                //判断现付业绩是否为固定金额
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工3编码
            if (null != cashList.getServiceLargeThreeStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                //判断现付业绩是否为固定金额
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }
                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionLarge()),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);


//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工1编码
            if (null != cashList.getServiceZhonggongOneStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(
                        BigDecimalUtils.add(
                                BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                                BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                //判断现付业绩是否为固定金额
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }

                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(
//                    BigDecimalUtils.add(
//                        BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                            BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工2编码
            if (null != cashList.getServiceZhonggongTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }

                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工3编码
            if (null != cashList.getServiceZhonggongThreeStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionZhonggong()),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }

                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);



//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //技师1编码
            if (null != cashList.getServiceTechnicianOneStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }

                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

                entities.add(achiCommEntity);
            }
            //技师2编码
            if (null != cashList.getServiceTechnicianTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }

                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //技师3编码
            if (null != cashList.getServiceTechnicianThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));


                //判断现付业绩是否为固定金额
                if(cashList.getAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionTechnician()),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }

                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理1编码
            if (null != cashList.getServiceSmallOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理2编码
            if (null != cashList.getServiceSmallTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }

                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理3编码
            if (null != cashList.getServiceSmallThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(GDtotalMeony);
//                achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));


                //判断现付业绩是否为固定金额
                if(cashList.getAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){ //=计算固定金额
                    //计算现付业绩
                    //判断是否存在卡付和现付并且卡付业绩也是固定金额
                    achiCommEntity.setCashAchi(cashList.getAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));


                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }


                }else{ //计算百分百
                    //计算现付业绩
                    achiCommEntity.setCashAchi(BigDecimalUtils.multiply(achievementMeony,cashList.getAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算现付提成
                    //判断现付提成是否为百分百还是固定金额
                    if(cashList.getCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1) {//a大于b//业绩提成比例> 1=固定金额
                        //判断是否存在卡付和现付并且卡付提出也是固定金额
                        achiCommEntity.setCashComm(cashList.getCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }else{//百分百
                        achiCommEntity.setCashComm(BigDecimalUtils.multiply(BigDecimalUtils.multiply(achiCommEntity.getCashAchi(),cashList.getCommissionSmall()),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }

                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
        }



        return entities;
    }

    //升级后修改的新疗程消费业绩提成算法
    public List<AchiCommEntity> getAchiCommListsCard(CashList cashList){
        List<AchiCommEntity> entities = new ArrayList<>();
        BigDecimal hundredBD = com.ssm.manage.utils.BigDecimalUtils.bigDecimal("100");
        //减掉固定金额业绩的单据总金额
        BigDecimal totalMeony = cashList.getAmount();
        //减掉固定金额业绩的单据卡付金额
        BigDecimal bigDecimal = BigDecimal.valueOf(Double.valueOf(cashList.getCollectionAmount()));
        BigDecimal cardMeony =totalMeony;
//        BigDecimal cardMeony =bigDecimal.subtract(cashList.getCollectionCashAmount());

        //存在卡付，也存在现付
        if(cashList.getCashAmount().compareTo(BigDecimal.valueOf(0)) == 1){//只有卡付
            //判断大工是否存在
            if(null != cashList.getServiceLargeOneStaffId() || null != cashList.getServiceLargeTwoStaffId() || null != cashList.getServiceLargeThreeStaffId()){
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementLarge());
                }
            }

            //判断中工是否存在
            if(null != cashList.getServiceZhonggongOneStaffId() || null != cashList.getServiceZhonggongTwoStaffId() || null != cashList.getServiceZhonggongThreeStaffId()){
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementZhonggong());
                }
            }

            //判断小工（技师）是否存在
            if(null != cashList.getServiceTechnicianOneStaffId() || null != cashList.getServiceTechnicianTwoStaffId() || null != cashList.getServiceTechnicianThreeStaffId()){
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementTechnician());
                }
            }

            //判断助理是否存在
            if(null != cashList.getServiceSmallOneStaffId() || null != cashList.getServiceSmallTwoStaffId() || null != cashList.getServiceSmallThreeStaffId()){
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){//a大于b//业绩提成比例> 1=固定金额
                    cardMeony= BigDecimalUtils.subtract(cardMeony,cashList.getCardAchievementSmall());
                }
            }

            //大工1编码
            if (null != cashList.getServiceLargeOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
                achiCommEntity.setSaleAchievementAmount(cashList.getAchievementLarge());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
                        BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
                    }
                }

                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);
//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(
//                    BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工2编码
            if (null != cashList.getServiceLargeTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //大工3编码
            if (null != cashList.getServiceLargeThreeStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionLarge().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionLarge().multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionLarge()).multiply(BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);


//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getLargeThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceLargeThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceLargeThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceLargeThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceLargeThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardLargeAchievementAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardLargeCommissionAmount(),BigDecimalUtils.div(cashList.getServiceLargeThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工1编码
            if (null != cashList.getServiceZhonggongOneStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(
                        BigDecimalUtils.add(
                                BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
                                BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
                                        BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongOneNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongOneStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongOneStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongOneIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongOneRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(
//                    BigDecimalUtils.add(
//                        BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)),
//                            BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),
//                            BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongOneRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工2编码
            if (null != cashList.getServiceZhonggongTwoStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //  achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);

//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongTwoNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongTwoStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongTwoStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongTwoIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongTwoRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongTwoRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //中工3编码
            if (null != cashList.getServiceZhonggongThreeStaffId()){


                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));

                //判断现付业绩是否为固定金额
                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionZhonggong().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionZhonggong().multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionZhonggong()).multiply(BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));
                entities.add(achiCommEntity);



//            AchiCommEntity achiCommEntity = new AchiCommEntity();
//            achiCommEntity.setDocNum(cashList.getCashNum());
//            achiCommEntity.setDocType(Constant.doc_type_store_cash);
//            achiCommEntity.setDocDate(cashList.getCashDate());
//            achiCommEntity.setTradeName(cashList.getProjectName());
//            achiCommEntity.setBrandNumber(cashList.getZhonggongThreeNumber());
//            achiCommEntity.setSaleStaffId(cashList.getServiceZhonggongThreeStaffId());
//            achiCommEntity.setSaleStaffName(cashList.getServiceZhonggongThreeStaffName());
//            achiCommEntity.setSaleIdentityCard(cashList.getServiceZhonggongThreeIdentityCard());
//            achiCommEntity.setSaleRatio(cashList.getServiceZhonggongThreeRatio());
//            achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)),
//                    BigDecimalUtils.multiply(cashList.getCardZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD))));
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getZhonggongAchievementAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getZhonggongCommissionAmount(),BigDecimalUtils.div(cashList.getServiceZhonggongThreeRatio(),hundredBD)));
//            entities.add(achiCommEntity);
            }
            //技师1编码
            if (null != cashList.getServiceTechnicianOneStaffId()){

                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianOneRatio(),hundredBD)));
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

                entities.add(achiCommEntity);
            }
            //技师2编码
            if (null != cashList.getServiceTechnicianTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //技师3编码
            if (null != cashList.getServiceTechnicianThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getTechnicianThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceTechnicianThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceTechnicianThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceTechnicianThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceTechnicianThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD))));


                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionTechnician().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionTechnician().multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionTechnician()).multiply(BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardTechnicianAchievementAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardTechnicianCommissionAmount(),BigDecimalUtils.div(cashList.getServiceTechnicianThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理1编码
            if (null != cashList.getServiceSmallOneStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallOneNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallOneStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallOneStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallOneIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallOneRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallOneRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理2编码
            if (null != cashList.getServiceSmallTwoStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallTwoNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallTwoStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallTwoStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallTwoIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallTwoRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD))));

                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallTwoRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
            //助理3编码
            if (null != cashList.getServiceSmallThreeStaffId()){
                AchiCommEntity achiCommEntity = new AchiCommEntity();
                achiCommEntity.setMoney(cashList.getAmount());
                //achiCommEntity.setMoney(cashList.getCashAmount());
                achiCommEntity.setMemberNum(String.valueOf(cashList.getMemberId()));
                achiCommEntity.setMemberName(cashList.getMemberName());
                achiCommEntity.setProjectId(String.valueOf(cashList.getProjectId()));
                achiCommEntity.setDocNum(cashList.getCashNum());
                achiCommEntity.setDocType(Constant.doc_type_store_cash);
                achiCommEntity.setOrderType("card");
                achiCommEntity.setDocDate(cashList.getCashDate());
                achiCommEntity.setTradeName(cashList.getProjectName());
                achiCommEntity.setBrandNumber(cashList.getSmallThreeNumber());
                achiCommEntity.setSaleStaffId(cashList.getServiceSmallThreeStaffId());
                achiCommEntity.setSaleStaffName(cashList.getServiceSmallThreeStaffName());
                achiCommEntity.setSaleIdentityCard(cashList.getServiceSmallThreeIdentityCard());
                achiCommEntity.setSaleRatio(cashList.getServiceSmallThreeRatio());
                achiCommEntity.setSaleAchievementAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));
                achiCommEntity.setSaleCommissionAmount(BigDecimalUtils.add(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)),
                        BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD))));


                //判断卡付业绩是否为固定金额
                if(cashList.getCardAchievementSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                    //卡付业绩按固定金额计算
                    //计算卡付业绩
                    achiCommEntity.setCardAchi(cashList.getCardAchievementSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }

                }else{
                    //卡付业绩比例计算
                    achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cardMeony,cashList.getCardAchievementSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));

                    //计算卡付提成
                    //判断卡付提成是否为固定金额
                    if(cashList.getCardCommissionSmall().compareTo(BigDecimal.valueOf(1)) == 1){
                        //提成按固定金额算
                        achiCommEntity.setCardComm(cashList.getCardCommissionSmall().multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }else{
                        //提成按百分百
                        achiCommEntity.setCardComm(BigDecimalUtils.multiply(achiCommEntity.getCardAchi(),cashList.getCardCommissionSmall()).multiply(BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                    }
                }
                if(null == achiCommEntity.getCashAchi()){
                    achiCommEntity.setCashAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardAchi() ){
                    achiCommEntity.setCardAchi(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCashComm()){
                    achiCommEntity.setCashComm(BigDecimal.valueOf(0));
                }
                if(null == achiCommEntity.getCardComm()){
                    achiCommEntity.setCardComm(BigDecimal.valueOf(0));
                }
                achiCommEntity.setTotalPerformance(BigDecimalUtils.add(achiCommEntity.getCashAchi(),achiCommEntity.getCardAchi()));
                achiCommEntity.setTotalCommission(BigDecimalUtils.add(achiCommEntity.getCashComm(),achiCommEntity.getCardComm()));

//            achiCommEntity.setCashAchi(BigDecimalUtils.multiply(cashList.getSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCashComm(BigDecimalUtils.multiply(cashList.getSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardAchi(BigDecimalUtils.multiply(cashList.getCardSmallAchievementAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
//            achiCommEntity.setCardComm(BigDecimalUtils.multiply(cashList.getCardSmallCommissionAmount(),BigDecimalUtils.div(cashList.getServiceSmallThreeRatio(),hundredBD)));
                entities.add(achiCommEntity);
            }
        }



        return entities;
    }


    @Override
    public List<ProjectLists> selectProjectLists(ProjectListsRequest projectListsRequest) throws ParseException {
        List<ProjectLists> list=dao.selectProjectLists1(projectListsRequest);
        BigDecimal totalMoney = BigDecimalUtils.bigDecimal("0");
        for(ProjectLists projectLists:list){
            totalMoney =  BigDecimalUtils.add(totalMoney, projectLists.getCountMoney());
        }
        List<ProjectLists> list1=new ArrayList<>();
        for(ProjectLists projectLists:list){
            projectLists.setAvgMoney(BigDecimalUtils.div(projectLists.getCountMoney(),totalMoney));
            list1.add(projectLists);
        }
        return list1;
    }


    @Override
    public List<ProjectLists> selectProjectLists2(ProjectListsRequest projectListsRequest) throws ParseException {
        List<ProjectLists> list=new ArrayList<>();
        List<ProjectLists> lists=new ArrayList<>();
        for(Long StoreId:projectListsRequest.getStoreId()){
            //是否使用有效期
            StoreParament parament = StoreParaUtils.getStorePara(StoreId, Constant.allow_valid);
            if(parament.getParamentValue().equals("1")){
                //控制有效期
                projectListsRequest.setAllowValid("end_time>now() or end_time is null");
                list=dao.selectProjectLists2(StoreId,projectListsRequest.getAllowValid());
            }else{
                list=dao.selectProjectLists2(StoreId,projectListsRequest.getAllowValid());
            }
            for(ProjectLists projectLists:list){
                lists.add(projectLists);
            }
        }

        BigDecimal totalMoney = BigDecimalUtils.bigDecimal("0");
        for(ProjectLists projectLists:lists){
            totalMoney =  BigDecimalUtils.add(totalMoney, projectLists.getCountMoney());
        }
        List<ProjectLists> list1=new ArrayList<>();

        for(ProjectLists projectLists:lists){
            projectLists.setAvgMoney(BigDecimalUtils.div(projectLists.getCountMoney(),totalMoney));
            BaseProject baseProject1 = new BaseProject();
            baseProject1.setId(projectLists.getTradeId());
            BaseProject baseProject = ssmProjectService.selectOne(baseProject1);
            Date unifiedDue=null;
            if(baseProject.getUnifiedDue()!=null || "".equals(baseProject.getUnifiedDue())){
                 unifiedDue=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(baseProject.getUnifiedDue());
                if(unifiedDue.after(new Date())){
                    list1.add(projectLists);
                }
            }
            if(unifiedDue==null){
                list1.add(projectLists);
            }
        }
        return list1;
    }

    @Override
    public List<ProjectLists> selectProjectLists3(ProjectListsRequest projectListsRequest) throws ParseException {
        List<ProjectLists> list=dao.selectProjectLists3(projectListsRequest);
        BigDecimal totalMoney = BigDecimalUtils.bigDecimal("0");
        for(ProjectLists projectLists:list){
            totalMoney =  BigDecimalUtils.add(totalMoney, projectLists.getCountMoney());
        }
        List<ProjectLists> list1=new ArrayList<>();
        for(ProjectLists projectLists:list){
            projectLists.setAvgMoney(BigDecimalUtils.div(projectLists.getCountMoney(),totalMoney));
            list1.add(projectLists);
        }
        return list1;
    }




    private HashMap<String, BigDecimal> getFixedAmount(BigDecimal CardAmount,BigDecimal CashAmount,BigDecimal Cardyj,BigDecimal Cashyj ){

        HashMap<String, BigDecimal> map = new HashMap<>();
        //卡付业绩
        BigDecimal multiply = com.ssm.core.utils.BigDecimalUtils.multiply(CardAmount.divide(CardAmount.add(CashAmount),10,BigDecimal.ROUND_HALF_UP), Cardyj);
        //现付业绩
        BigDecimal multiplys = com.ssm.core.utils.BigDecimalUtils.multiply(CashAmount.divide(CardAmount.add(CashAmount),10,BigDecimal.ROUND_HALF_UP), Cashyj);

        //总的业绩
        BigDecimal add = multiply.add(multiplys);
        map.put("card",multiply);
        map.put("cash",multiplys);
        map.put("total",add);
        return map;

    };


    public static Long dayDiff(String date1, String date2){

        DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        Long num = null;
        try {
            Date star = dft.parse(date1);//开始时间
            Date endDay=dft.parse(date2);//结束时间
            Long starTime=star.getTime();
            Long endTime=endDay.getTime();
            num=endTime-starTime;//时间戳相差的毫秒数
            num = num/24/60/60/1000;
            System.out.println("相差天数为："+num/24/60/60/1000);//除以一天的毫秒数
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return num;
    }

    public static Date addDay(Date date1){
        // 获取当前时间
        //Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date1);
        // 把日期往后增加一天,整数  往后推,负数往前移动
        calendar.add(Calendar.DATE, 1);
        // 这个时间就是日期往后推一天的结果
        date1 = calendar.getTime();
        return date1;
    }

    @Override
    public List<StaffStatistic> departmentPerformanceNew(StaffStatistic staffStatistic) throws SmsException, ParseException {
            List<StaffStatistic> staffStatisticList = new ArrayList<>();
            List<StaffStatistic> staffStatisticLists = new ArrayList<>();
            List<StaffStatistic> staffStatisticListss = new ArrayList<>();
            BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
            BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
            //根据时间类别转换时间
            //int type = staffStatistic.getType();
            String dateStr = staffStatistic.getStartDate().substring(0, 7);
            Date date = new Date();
//        if (0 == type) {
//            //上月
//            date = DateUtils.diffMonth(new Date(), -1);
//            dateStr = DateUtils.ymFormat(date);
//        } else if (1 == type) {
//            //昨日
//            date = DateUtils.diffDay(new Date(), -1);
//            dateStr = DateUtils.ymdFormat(date);
//        } else if (2 == type) {
//            //今日
//            dateStr = DateUtils.ymdFormat(date);
//        } else {
//            //当月
//            dateStr = DateUtils.ymFormat(date);
//        }

            //分离查询时使用 否则按月查询分组时分出多个时间组
//        if (null != staffStatistic.getDate()){
//            date = staffStatistic.getDate();
//            dateStr = DateUtils.ymdFormat(date);
//        }

            Long storeId = staffStatistic.getStoreId();
            List<RechargeListResponse> recList = new ArrayList<>();
            List<CourseListResponse> courseList = new ArrayList<>();
            List<CashListResponse> cashList = new ArrayList<>();
            List<RepayTradeResponse> RepayLists = new ArrayList<>();
            List<RefundRechargeResponse> refundRecList = new ArrayList<>();
            List<RefundCourseResponse> refundCourseList = new ArrayList<>();
            List<CashListResponse> refundCashList = new ArrayList<>();
            List<DocPromotionResponse> promotionList = new ArrayList<>();
            List<CardChangeInProjectResponse> cardChangeLists = new ArrayList<>();
            List<CardChangeOutProjectResponse> cardOutList = new ArrayList<>();
            List<BaseGrouponCardResponse> baseGrouponCards = new ArrayList<>();

            if (null == staffStatistic.getClassify()) {
                recList = ssmRechargeService.selectList(storeId, dateStr, date);
                courseList = ssmCourseService.selectList(storeId, dateStr, date);
                cashList = ssmCashService.selectList(storeId, dateStr, date);
                RepayLists = ssmRepayService.selectList(storeId, dateStr, null);
                refundRecList = ssmRefundRechargeService.selectList(storeId, dateStr);
                refundCourseList = ssmRefundCourseService.selectList(storeId, dateStr);
                //refundCashList = ssmRefundCashService.selectList(storeId, dateStr);
                refundCashList = ssmRefundCashService.selectLists(storeId, dateStr,date);
                promotionList = ssmDocPromotionService.selectList(storeId, dateStr);
                //加价转疗程
                cardChangeLists = ssmCardChangeService.selectList(storeId, dateStr);
//            cardOutList = ssmCardChangeOutProjectService.selectListByStoreAndDate(storeId,dateStr);
                //查询团购卡
                baseGrouponCards = ssmBaseGrouponCardService.selectDates(storeId,dateStr);

            }
            for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                for (AchiCommEntity entity : cardChangeList.getEntities()) {
                    entity.setChangeInPayMoney(cardChangeList.getChangeInPayMoney());
                    entity.setChangeOutMoney(cardChangeList.getChangeOutMoney());
                }
            }

            List<AchiCommEntity> totalList = new ArrayList<>();
            //合并list
            for (CardChangeInProjectResponse cardChangeList : cardChangeLists) {
                cardChangeList.getOutProjects().
                        forEach(cardChangeOutProject ->  cardChangeOutProject.getEntities()
                                .stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            }
            recList.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            cashList.forEach(cashListResponse -> cashListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            RepayLists.forEach(repayTradeResponse -> repayTradeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundRecList.forEach(refundRechargeResponse -> refundRechargeResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundCourseList.forEach(refundCourseResponse -> refundCourseResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            refundCashList.forEach(refundCashResponse -> refundCashResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            promotionList.forEach(docPromotionResponse -> docPromotionResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            cardChangeLists.forEach(cardChangeInProjectResponse -> cardChangeInProjectResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            baseGrouponCards.forEach(baseGrouponCardResponse -> baseGrouponCardResponse.getStaffLists().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            for (AchiCommEntity achiCommEntity : totalList) {
                BaseStaff baseStaff = ssmBaseStaffService.selectByPrimaryKey(achiCommEntity.getSaleStaffId());
                achiCommEntity.setDetpName(baseStaff.getDeptName());
            }
        Map<Integer, List<AchiCommEntity>> deptAchi = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getDetpName));
        Iterator<Map.Entry<Integer, List<AchiCommEntity>>> iterator = deptAchi.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Integer, List<AchiCommEntity>> next = iterator.next();
            List<AchiCommEntity> achiCommEntities = next.getValue();
            StaffStatistic statistic = new StaffStatistic();
            statistic.setDeptName(next.getKey());
            statistic.setRecharge(BigDecimal.valueOf(0));
            statistic.setRechargecar(BigDecimal.valueOf(0));
            statistic.setCourseCard(BigDecimal.valueOf(0));
            statistic.setCourseCash(BigDecimal.valueOf(0));
            statistic.setCourseTotal(BigDecimal.valueOf(0));
            statistic.setCoursePromotionCard(BigDecimal.valueOf(0));
            statistic.setCoursePromotionCash(BigDecimal.valueOf(0));
            statistic.setCoursePromotionTotal(BigDecimal.valueOf(0));
            statistic.setCashierCard(BigDecimal.valueOf(0));
            statistic.setCashierCash(BigDecimal.valueOf(0));
            statistic.setCashierRecharge(BigDecimal.valueOf(0));
            statistic.setCashierTotal(BigDecimal.valueOf(0));
            statistic.setRepaymentCourse(BigDecimal.valueOf(0));
            statistic.setRepaymentRecharge(BigDecimal.valueOf(0));
            statistic.setRepaymentTotal(BigDecimal.valueOf(0));
            statistic.setRefundTotal(BigDecimal.valueOf(0));
            statistic.setRefundCourse(BigDecimal.valueOf(0));
            statistic.setRefundRechagre(BigDecimal.valueOf(0));
            statistic.setRefundCash(BigDecimal.valueOf(0));
            statistic.setJjzlcCard(BigDecimal.valueOf(0));
            statistic.setJjzlcCash(BigDecimal.valueOf(0));

            statistic.setCourse(BigDecimal.valueOf(0));
            statistic.setCourseSum(BigDecimal.valueOf(0));
            statistic.setCourseRepay(BigDecimal.valueOf(0));
            statistic.setCardAmount(BigDecimal.valueOf(0));
            statistic.setAllAmount(BigDecimal.valueOf(0));
            statistic.setCashAmount(BigDecimal.valueOf(0));
            statistic.setCooperationCardAmount(BigDecimal.valueOf(0));
            statistic.setCooperateAmount(BigDecimal.valueOf(0));
            statistic.setHkCooperationAmount(BigDecimal.valueOf(0));
            for (AchiCommEntity achiCommEntity : achiCommEntities) {

            }
        }
        return staffStatisticListss;
        }

        @Autowired
        private SsmCollectionTypeService ssmCollectionTypeService;
    @Autowired
    private SsmSysRoleStoreService ssmSysRoleStoreService;
    @Override
    public List<StoreByDayResponse> storeByDayDailys(StoreDailyRequest storeDailyRequest) {
        List<StoreByDayResponse> storeByDayResponses = new ArrayList<>();
        //查询所有支付方式
        List<BaseCollectionType> payType = ssmCollectionTypeService.selectAll();


/**
 * 角色
 */

        List<Long> storeIds1 = new ArrayList<>();
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeDailyRequest.getStoreId());
        if(baseStore.getParentId()==null) {
            SysRoleStoreRequest sysStoreRole = new SysRoleStoreRequest();
            sysStoreRole.setRoleId(storeDailyRequest.getRoleId());
            PageInfo<SysRoleStore> sysRoleStorePageInfo = ssmSysRoleStoreService.selectPage(sysStoreRole);
            storeIds1 = sysRoleStorePageInfo.getList().stream().map( item -> item.getStoreId()).collect(Collectors.toList());
        }
        if(storeIds1==null || storeIds1.size()==0) {
            storeIds1.add(storeDailyRequest.getStoreId());

        }


        //查询当前门店和旗下所有的子门店
        List<BaseStore> baseStoreList = ssmBaseStoreService.selectChildren(storeDailyRequest.getStoreId());
        List<Long> longList = baseStoreList.stream().map(item -> item.getId()).collect(Collectors.toList());
        List<Long> storeIds = storeIds1.stream().filter(item ->  longList.contains(item)).collect(Collectors.toList());
        storeDailyRequest.setStoreIds(storeIds);
//        List<Long> storeIds = baseStoreList.stream().map(BaseStore::getId).collect(Collectors.toList());

//        storeIds.add(storeDailyRequest.getStoreId());
        //查询所有支付金额和明细
        storeDailyRequest.setDate(storeDailyRequest.getStartTime());
        List<PayListVo> payListList = ssmPayService.selectByDay(storeDailyRequest.getTab(),storeIds,storeDailyRequest.getStartTime(),storeDailyRequest.getEndTime());

        //查询充值总金额
        storeDailyRequest.setStoreIds(storeIds);
        List<RechargeVo> rechargeList = ssmRechargeService.selectByDay(storeDailyRequest);
        //查询疗程
        List<CourseDayVo> courseList = ssmCourseService.selectByDay(storeDailyRequest);
        //查询疗程合作方业绩
        List<CourseDayVo> courseCooperationList = ssmCourseService.selectCourseCoopation(storeDailyRequest);
        //查询收银
        List<CashDayVo> cashList = ssmCashService.selectByDay(storeDailyRequest);
        //查询还款
        List<DebtDayVo> debtList = ssmDebtService.selectByDay(storeIds,storeDailyRequest.getStartTime(),storeDailyRequest.getEndTime());
        //查询加价转疗程
        List<CardChangeDayVo> cardChangeList = ssmCardChangeService.selectByDay(storeIds,storeDailyRequest.getStartTime(),storeDailyRequest.getEndTime());
        //查询疗程促销
        List<PromotionDayVo> promotionList = ssmDocPromotionService.selectByDay(storeIds,storeDailyRequest.getStartTime(),storeDailyRequest.getEndTime());
        //查询退款
        List<RefundDayVo> refundList = ssmRefundOrderService.selectByDay(storeIds,storeDailyRequest.getStartTime(),storeDailyRequest.getEndTime());
        //查询疗程转充值
        RechargeTurnCourse rechargeTurnCourse = new RechargeTurnCourse();
        rechargeTurnCourse.setDocDate(storeDailyRequest.getStartTime());
        rechargeTurnCourse.setStartTime(storeDailyRequest.getStartTime());
        rechargeTurnCourse.setEndTime(storeDailyRequest.getEndTime());
        List<RechargeTurnCourse> rechargeTurnCourses = ssmRechargeTurnCourseService.selectFKJByDate(rechargeTurnCourse);
        List<String> rechargeTurnCoursesDocNum = rechargeTurnCourses.stream().map(item -> item.getDocNum()).collect(Collectors.toList());
        List<CoursePayList> coursePayListList = null;
        if(rechargeTurnCoursesDocNum!=null && rechargeTurnCoursesDocNum.size()>0){
            coursePayListList = ssmCoursePayListService.selectCourseTurnRecharge(rechargeTurnCoursesDocNum);
        }
        for (Long storeId : storeIds) {
            StoreByDayResponse response = new StoreByDayResponse();
            //根据日期进行过滤
            List<CashDayVo> cash = cashList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<RechargeVo> recharge = rechargeList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<CourseDayVo> course = courseList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<CourseDayVo> courseCooperation = courseCooperationList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<DebtDayVo> debt = debtList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<CardChangeDayVo> cardChange = cardChangeList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<PromotionDayVo> promotion = promotionList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<RefundDayVo> refund = refundList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<PayListVo> paylist = payListList.stream().filter(item -> item.getStoreId() == storeId || item.getStoreId().equals(storeId)).collect(Collectors.toList());
            List<BaseStore> store = baseStoreList.stream().filter(item -> item.getId() == storeId || item.getId().equals(storeId)).collect(Collectors.toList());
            //设置疗程转充值
            response.setCourseTurnRechargeIn(BigDecimal.ZERO);
            response.setCourseTurnRechargeOut(BigDecimal.ZERO);
            if(rechargeTurnCourses!=null && rechargeTurnCourses.size()>0){

                List<RechargeTurnCourse> rechargeTurnCourseList = rechargeTurnCourses.stream().filter(item -> item.getStoreId() == storeId || storeId.equals(item.getStoreId())).collect(Collectors.toList());
                response.setCourseTurnRechargeIn((rechargeTurnCourseList==null||rechargeTurnCourseList.size()==0)?BigDecimal.ZERO:rechargeTurnCourseList.stream().map(item->item.getRechargeInMoney()).reduce(BigDecimal.ZERO,BigDecimal::add));
            }
            if(coursePayListList!=null && coursePayListList.size()>0){
                List<CoursePayList> coursePayList = coursePayListList.stream().filter(item -> item.getStoreId() == storeId || storeId.equals(item.getStoreId())).collect(Collectors.toList());
                response.setCourseTurnRechargeOut((coursePayList==null||coursePayList.size()==0)?BigDecimal.ZERO:coursePayList.stream().map(item->item.getRollOffMoney()).reduce(BigDecimal.ZERO,BigDecimal::add));
            }
            //查询团购卡单数和团购金额
            storeDailyRequest.setStoreId(storeId);
            StoreDaily grouponTuan = ssmRechargeService.grouponTuanNew(storeDailyRequest);
            //门店id
            response.setStoreId(store.get(0).getId());
            //门店名字
            response.setStoreName(store.get(0).getStoreName());
            //门店编码
            response.setStoreNum(store.get(0).getStoreNum());
            //日期
            response.setDate(storeDailyRequest.getStartTime());

            //疗程单数
            response.setCourseRows((course==null || course.size()==0 )?0:course.stream().map(CourseDayVo::getCourseRows).reduce(0,(x1,x2)->x1+x2));
            //收银单数
            response.setCashRows((cash==null|| cash.size()==0)?0:cash.stream().map(CashDayVo::getCashRows).reduce(0,(x1,x2)->x1+x2));
            //充值单数
            response.setRechargeRows((recharge==null || recharge.size()==0 )?0:recharge.stream().map(RechargeVo::getRechargeRows).reduce(0,(x1,x2)->x1+x2));
            //总客单数
            response.setAllRows(response.getCourseRows()+response.getCashRows()+response.getRechargeRows());

            //收银总人数
            response.setAllCashNumber((cash==null|| cash.size()==0)?0:cash.stream().map(item->item.getWomanNumber()+item.getManNumber()).reduce(0,(x1,x2)->x1+x2));
            //收银男客
            response.setCashManNumber((cash==null|| cash.size()==0)?0:cash.stream().map(CashDayVo::getManNumber).reduce(0,(x1,x2)->x1+x2));
            //收银女客
            response.setCashWomanNumber((cash==null|| cash.size()==0)?0:cash.stream().map(CashDayVo::getWomanNumber).reduce(0,(x1,x2)->x1+x2));

            //总卡付金额
            response.setAllCardAmount((cash==null|| cash.size()==0)?BigDecimal.ZERO:cash.stream().map(item->item.getCollectionRechargeAmount().add(item.getCourseMoney())).reduce(BigDecimal.ZERO,BigDecimal::add));
            //还款总金额
            response.setAllRepayAmount((debt==null || debt.size()==0)?BigDecimal.ZERO:debt.stream().map(item->item.getCardRepayMoney().add(item.getRechargeRepayMoney())).reduce(BigDecimal.ZERO,BigDecimal::add));
            //疗程总金额
            response.setAllCourseAmount((course==null || course.size()==0 )?BigDecimal.ZERO:course.stream().map(item->item.getCourseReatmentAmount()
                    //充值卡不算业绩
//                    .add(item.getCollectionRechargeAmount())
            ).reduce(BigDecimal.ZERO,BigDecimal::add));
            response.setAllCourseAmount(response.getAllCourseAmount().add((promotion==null||promotion.size()==0)?BigDecimal.ZERO:promotion.stream().map(item->item.getCollectionCashAmount()
                    //充值卡不算业绩
//                    .add(item.getCollectionRechargeAmount())
            ).reduce(BigDecimal.ZERO,BigDecimal::add)));

            response.setAllCourseAmount(response.getAllCourseAmount().add((cardChange==null||cardChange.size()==0)?BigDecimal.ZERO:cardChange.stream().map(CardChangeDayVo::getChangeInPayMoney).reduce(BigDecimal.ZERO,BigDecimal::add)));

            //疗程实收金额
            response.setCourseCashAmount((course==null || course.size()==0 )?BigDecimal.ZERO:course.stream().map(CourseDayVo::getCourseReatmentAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
            response.setCourseCashAmount(response.getCourseCashAmount().add((cardChange==null||cardChange.size()==0)?BigDecimal.ZERO:cardChange.stream().map(CardChangeDayVo::getChangeInPayMoney).reduce(BigDecimal.ZERO,BigDecimal::add)));
            response.setCourseCashAmount(response.getCourseCashAmount().add((promotion==null||promotion.size()==0)?BigDecimal.ZERO:promotion.stream().map(item->item.getCollectionCashAmount()).reduce(BigDecimal.ZERO,BigDecimal::add)));
            //疗程充值卡付金额
            response.setCourseRechargeAmount((course==null || course.size()==0 )?BigDecimal.ZERO:course.stream().map(CourseDayVo::getCollectionRechargeAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
            response.setCourseRechargeAmount(response.getCourseRechargeAmount().add((promotion==null||promotion.size()==0)?BigDecimal.ZERO:promotion.stream().map(item->item.getCollectionRechargeAmount()).reduce(BigDecimal.ZERO,BigDecimal::add)));

            //疗程还款金额
            response.setCourseRepayAmount((debt==null || debt.size()==0 )?BigDecimal.ZERO:debt.stream().map(DebtDayVo::getCardRepayMoney).reduce(BigDecimal.ZERO,BigDecimal::add));

            //疗程欠款金额
            response.setCourseDebtAmount((course==null || course.size()==0 )?BigDecimal.ZERO:course.stream().map(CourseDayVo::getDebtMoney).reduce(BigDecimal.ZERO,BigDecimal::add));

            //疗程卡付金额
            response.setCourseCardAmount((cash==null || cash.size()==0 )?BigDecimal.ZERO:cash.stream().map(CashDayVo::getCourseMoney).reduce(BigDecimal.ZERO,BigDecimal::add));


            //充值总金额
            response.setRechargeAmount((recharge==null || recharge.size()==0 )?BigDecimal.ZERO:recharge.stream().map(RechargeVo::getCollectionAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
            response.setRechargeAmount(response.getRechargeAmount().add(grouponTuan==null?BigDecimal.ZERO:grouponTuan.getGrouponMoney()));

            //充值实收总金额
            response.setAllRechargeAmount((recharge==null || recharge.size()==0 )?BigDecimal.ZERO:recharge.stream().map(RechargeVo::getCollectionAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
            response.setAllRechargeAmount(response.getAllRechargeAmount().add(grouponTuan==null?BigDecimal.ZERO:grouponTuan.getGrouponMoney()));

            //充值还款金额
            response.setRechargeRepayAmount((debt==null || debt.size()==0 )?BigDecimal.ZERO:debt.stream().map(DebtDayVo::getRechargeRepayMoney).reduce(BigDecimal.ZERO,BigDecimal::add));

            //充值欠款金额
            response.setRechargeDebtAmount((recharge==null || recharge.size()==0)?BigDecimal.ZERO:recharge.stream().map(RechargeVo::getDebtMoney).reduce(BigDecimal.ZERO,BigDecimal::add));

            //充值卡付金额
            response.setRechargeCashAmount((cash==null|| cash.size()==0)?BigDecimal.ZERO:cash.stream().map(CashDayVo::getCollectionRechargeAmount).reduce(BigDecimal.ZERO,BigDecimal::add));

            //公司实业绩
            response.setCashAmount((cash==null|| cash.size()==0)?BigDecimal.ZERO:cash.stream().map(CashDayVo::getCollectionCashAmount).reduce(BigDecimal.ZERO,BigDecimal::add));

            //退款总额
            response.setRefundAmount((refund==null||refund.size()==0 )?BigDecimal.ZERO:refund.stream().map(RefundDayVo::getRefundMoney).reduce(BigDecimal.ZERO,BigDecimal::add));
            //实收总业绩
            response.setAllCashAchi((paylist==null||paylist.size()==0)?BigDecimal.ZERO:paylist.stream().map(PayListVo::getPayMoneyAmount).reduce(BigDecimal.ZERO,BigDecimal::add));

//            response.setAllCashAchi(response.getAllCashAchi().add(grouponTuan==null?BigDecimal.ZERO:grouponTuan.getGrouponMoney()));

            response.setCashAchi((courseCooperation==null||courseCooperation.size()==0)?BigDecimal.ZERO:courseCooperation.stream().map(CourseDayVo::getCashCooperation).reduce(BigDecimal.ZERO,BigDecimal::add));
            response.setStoreCashAchi(response.getAllCashAchi().subtract(response.getCashAchi()));
            List<PayListVo> payListVos = new ArrayList<>();
            for (BaseCollectionType collectionType : payType) {
                PayListVo payListVo = new PayListVo();
                payListVo.setPayName(collectionType.getCollectionTypeName());
                if(paylist!=null && paylist.size()>0){
                    List<PayListVo> collect = paylist.stream().filter(item -> item.getPayId() == collectionType.getId() || item.getPayId().equals(collectionType.getId())).collect(Collectors.toList());
                    payListVo.setPayMoneyAmount((collect==null||collect.size()==0)?BigDecimal.ZERO:collect.stream().map(PayListVo::getPayMoneyAmount).reduce(BigDecimal.ZERO,BigDecimal::add));
                }else {
                    payListVo.setPayMoneyAmount(BigDecimal.ZERO);
                }
                payListVos.add(payListVo);
            }
            response.setPayLists(payListVos);

            //实际营业额
            BigDecimal cashMoney  =(cash==null|| cash.size()==0)?BigDecimal.ZERO:cash.stream().map(CashDayVo::getCollectionCashAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            BigDecimal rechargeMoney = (recharge==null || recharge.size()==0)?BigDecimal.ZERO:recharge.stream().map(RechargeVo::getCollectionAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
            response.setAllAmount(response.getCourseCashAmount().add(cashMoney).add(rechargeMoney).add(response.getCourseRepayAmount()).add(response.getRechargeRepayAmount()));

            response.setAllAmount(response.getAllAmount().add(grouponTuan==null?BigDecimal.ZERO:grouponTuan.getGrouponMoney()));
            response.setRechargeAmount(response.getRechargeAmount().add(response.getRechargeRepayAmount()));
            response.setAllCourseAmount(response.getAllCourseAmount().add(response.getCourseRepayAmount())
//                    .subtract(response.getCourseCardAmount())
            );
            response.setAllCardAmount(response.getCourseCardAmount().add(response.getRechargeCashAmount()));


            storeByDayResponses.add(response);
        }
        return storeByDayResponses;
    }


    private List<AchiCommEntity> getAllCashList(StaffStatistic staffStatistic){
        CashListRequest cashListRequest = new CashListRequest();
        //设置门店id
        cashListRequest.setStoreId(staffStatistic.getStoreId());
        //设置日期
        Map<String, Date> dateMap = getStartAndEndTiem(staffStatistic);
        cashListRequest.setStartTime(dateMap.get("startTime"));
        cashListRequest.setEndTime(dateMap.get("endTime"));
        //设置日期获取当前查的表
        cashListRequest.setCashDate(dateMap.get("startTime"));
        List<CashList> cashLists = ssmCashService.getAllCashList(cashListRequest);
        List<AchiCommEntity> entities = new ArrayList<>();
        for (CashList cashList : cashLists) {
            CashListResponse cashListResponse = new CashListResponse();
            BeanUtils.copyProperties(cashList, cashListResponse);
            //设置业务人员列表
            if(null == cashList.getCourseAccountId()){ //是非疗程卡包收银
//                entities.addAll(this.getAchiCommLists(cashList,cashListResponse));

                for (AchiCommEntity entity : entities) {
                    entity.setOrderType("");
                }
            }else{ //卡包收银
//                entities.addAll( this.getAchiCommListsCard(cashList,cashListResponse));
            }


            for (AchiCommEntity entity : entities) {
                entity.setDocId(cashList.getId());
                if(cashList.getCashNum().equals(entity.getDocNum())){
                    entity.setProjectId(cashList.getProjectNum());
                    //entity.setMemberNum(cashList.getProjectNum());
                    if(null == entity.getMemberName()){
                        entity.setMemberName(cashList.getMemberName());
                    }
                    if(null == entity.getMoney()){
                        entity.setMoney(cashList.getPriceMember());
                    }


                }
            }

        }
        return entities;
    }

    private Map<String,Date> getStartAndEndTiem(StaffStatistic staffStatistic){
        Map<String,Date> map =  new HashMap<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat();
        Date startTime;
        Date endTime;
        try {
            startTime = dateFormat.parse(staffStatistic.getStartDate());
            map.put("startTime",startTime);
            endTime = dateFormat.parse(staffStatistic.getEndDate());
            map.put("endTime",endTime);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        return map;
    }

    @Override
    public List<StaffStatistic> memberInitStaff(StaffStatistic staffStatistic) throws ParseException, SmsException {
        //汇总后的集合
        List<StaffStatistic> staffStatisticsLs= new ArrayList<>();
        if(staffStatistic.getStoreIds()!=null && staffStatistic.getStoreIds().size()>0){
            for (Long storeIdNew : staffStatistic.getStoreIds()) {
                staffStatistic.setStoreId(storeIdNew);
                BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(storeIdNew);
                List<StaffStatistic> staffStatisticList = new ArrayList<>();
                List<StaffStatistic> staffStatisticLists = new ArrayList<>();

                BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
                BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
                //根据时间类别转换时间
                //int type = staffStatistic.getType();
                String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = dateFormat.parse(staffStatistic.getStartDate());
                Long storeId = staffStatistic.getStoreId();
                List<CourseListResponse> courseList = new ArrayList<>();
                if (null == staffStatistic.getClassify()) {
                    courseList = ssmCourseService.memberInitStaff(storeId, dateStr, date);
                } else {
                    if ("1".equals(staffStatistic.getClassify())) {
                        //查询疗程业务员信息
                        courseList = ssmCourseService.memberInitStaff(storeId, dateStr, date);
                    }
                }
                List<AchiCommEntity> totalList = new ArrayList<>();
                //合并list
                courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
                while (entryIterator.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {

                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();
                        //充值 + 充值还款 业绩
                        BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 业绩
                        BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程 + 疗程还款 业绩
                        BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //加价转疗程 业绩
                        BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //todo
                        BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCashAchi() == null ? BigDecimal.valueOf(0) : item.getCashAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //todo
                        BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCardAchi() == null ? BigDecimal.valueOf(0) : item.getCardAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 业绩
                        BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 业绩
                        BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                        //消费退 业绩
                        BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //还款业绩
                        BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销业绩
                        BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //充值  提成
                        BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //充值退款 提成
                        BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程  提成
                        BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程退款 提成
                        BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //收银 提成
                        BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //消费退 提成
                        BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //还款提成
                        BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销提成
                        BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //加价转疗程提成
                        BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //疗程转充值
                        BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


                        //团购卡业绩
                        BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //团购卡提成
                        BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                        //促销还款
                        BigDecimal cooperationAchi = BigDecimalUtils.bigDecimal("0");
                        for (AchiCommEntity achiCommEntity : list) {
                            for (CourseListResponse courseListResponse : courseList) {
                                if (achiCommEntity.getDocId() == courseListResponse.getId()) {
                                    for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                        if (entry.getKey().equals(entity.getSaleStaffId())) {
                                            cooperationAchi = cooperationAchi.add((courseListResponse.getCollectionCashAmount().subtract(courseListResponse.getAchievementAmount())).multiply(entity.getSaleRatio().divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_HALF_UP)));
                                        }
                                    }
                                }
                            }
                        }
//                BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                        achievementAmount = BigDecimalUtils.subtract(
                                BigDecimalUtils.subtract(
                                        BigDecimalUtils.subtract(
                                                BigDecimalUtils.add(
                                                        BigDecimalUtils.add(
                                                                BigDecimalUtils.add(
                                                                        recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                        commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                        //总现付业绩
                        BigDecimal totalCashAchi = BigDecimalUtils.add(
                                BigDecimalUtils.subtract(
                                        BigDecimalUtils.subtract(
                                                BigDecimalUtils.subtract(
                                                        BigDecimalUtils.add(
                                                                BigDecimalUtils.add(
                                                                        BigDecimalUtils.add(
                                                                                recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi), repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                        //总卡付业绩
                        BigDecimal totalCardAchi = BigDecimalUtils.subtract(
                                        BigDecimalUtils.add(
                                                BigDecimalUtils.add(
                                                        courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi)
                                .add(courseChangeCardAchi);
                        //总现付提成
                        BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                                BigDecimalUtils.add(BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                        //总卡付提成
                        BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                        statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                        //按天查询用date

                        statistic.setDate(list.get(list.size() - 1).getDocDate());
                        statistic.setLcCardyj(promotionCardAchi);
                        statistic.setAchievementAmount(achievementAmount);
                        statistic.setCommissionAmount(commissionAmount);
                        statistic.setCashAchi(totalCashAchi);
                        statistic.setCardAchi(totalCardAchi);
                        statistic.setCashComm(totalCashComm);
                        statistic.setCardComm(totalCardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());

                        statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                        statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                        statistic.setCooperationAchi(cooperationAchi);
                        BigDecimal repayProAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal repayProComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        statistic.setCourseOfTreatmentYJ(repayProAchi);
                        statistic.setCourseOfTreatmentTC(repayProComm);
                        staffStatisticList.add(statistic);
                    }
                    //}
                }

                for (StaffStatistic statistic : staffStatisticList) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        StaffStatistic staffStatistic1 = new StaffStatistic();
                        staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                        staffStatistic1.setDate(statistic.getDate());
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStoreId(storeId);
                        staffStatistic1.setClassify("0");
                        List<StaffStatistic> staffStatistics = null;
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setRechargeyj(BigDecimal.valueOf(0));
                        statistic.setRechargeTC(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("1");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        if(statistic.getCourseOfTreatmentYJ()==null){
                            statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
                        }
                        if(statistic.getCourseOfTreatmentTC()==null){

                            statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                        }
//                        statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
//                        statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                        if(statistic.getLcCardyj()==null) {
                            statistic.setLcCardyj(BigDecimal.valueOf(0));
                        }
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
                                    statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("2");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setServeYJ(BigDecimal.valueOf(0));
                        statistic.setServeTC(BigDecimal.valueOf(0));
                        statistic.setSyxfyj(BigDecimal.valueOf(0));
                        statistic.setSyczkfyj(BigDecimal.valueOf(0));
                        statistic.setSylcxkyj(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
                                    statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
                                    //收银的现付总业绩
                                    statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
                                    statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
                                    statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
                                }
                            }
                        }

                        staffStatistics = null;
                        staffStatistic1.setClassify("4");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
                        statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("5");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
                        statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
                                }
                            }
                        }
                        statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
                        statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));

                        staffStatistics = null;
                        staffStatistic1.setClassify("6");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
                        statistic.setCashierRefundTC(BigDecimal.valueOf(0));
                        statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
                                    statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
                                    statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
                                }
                            }
                        }
                        statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
                        statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
                        statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3,BigDecimal.ROUND_HALF_UP)));

                        staffStatistics = null;
                        staffStatistic1.setClassify("7");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setLeafletYJ(BigDecimal.valueOf(0));
                        statistic.setLeafletTC(BigDecimal.valueOf(0));
                        statistic.setCashcxyj(BigDecimal.valueOf(0));
                        statistic.setCardcxyj(BigDecimal.valueOf(0));
                        statistic.setCashcxtc(BigDecimal.valueOf(0));
                        statistic.setCardcxtc(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
                                    statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
                                    statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
                                    statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
                                }
                            }
                        }

                        staffStatistics = null;
                        staffStatistic1.setClassify("8");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setJjzlcyj(BigDecimal.valueOf(0));
                        statistic.setJjzlctc(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
                                    statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(), BigDecimal.valueOf(0.00))));
                                    statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(), staffStatistic2.getCardComm()), BigDecimal.valueOf(0.00))));
                                    statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
                                }
                            }
                        }

                        staffStatistics = null;
                        statistic.setNTMoney(BigDecimal.valueOf(0));
                        staffStatistic1.setClassify("3");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    if (null == staffStatistic2.getCzhkyj()) {
                                        staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getCzhktc()) {
                                        staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getLchkyj()) {
                                        staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getLchktc()) {
                                        staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                                    }
                                    if (null == staffStatistic2.getNTMoney()) {
                                        staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
                                    }
                                    //充值开卡
                                    statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getCzhkyj()));
                                    statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getCzhktc()));
                                    //疗程开卡
                                    statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(), staffStatistic2.getLchkyj()));
                                    statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(), staffStatistic2.getLchktc()));
                                    //促销开卡
                                    if (staffStatistic2.getType() == 2) {
                                        statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(), staffStatistic2.getCashcxyj()));
                                        statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(), staffStatistic2.getCashcxtc()));
                                    }
                                    statistic.setNTMoney(statistic.getNTMoney().add(staffStatistic2.getNTMoney()));
                                }
                            }
                        }

                        staffStatistics = null;
                        staffStatistic1.setClassify("9");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
                        statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
                                    statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
                                }
                            }
                        }


                        staffStatistics = null;
                        staffStatistic1.setClassify("10");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
                        statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
                                    statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getGroupPurchaseChia()));
                                    statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getGroupPurchaseComm()));
                                }
                            }
                        }
                        staffStatistics = null;
                        staffStatistic1.setClassify("11");
                        staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                        BigDecimal decimal = BigDecimal.valueOf(0);
                        statistic.setFootMassageComm(decimal);
                        statistic.setFootMassageChia(decimal);
                        statistic.setCardFootMassageComm(decimal);
                        statistic.setCardFootMassageChia(decimal);
                        statistic.setMarketChia(decimal);
                        statistic.setMarketComm(decimal);
                        if (staffStatistics != null) {
                            if (staffStatistics.size() > 0) {
                                for (StaffStatistic staffStatistic2 : staffStatistics) {
                                    statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
                                    statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
                                    statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
                                    statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
                                    statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
                                    statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
                                }
                            }
                        }

                        //根据甲方要求，退款的单据业绩不加进总业绩里面
                        statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
                        //todo 进行修改
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                        statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                        //退款业绩
                        statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
                        if (null == statistic.getSyxfyj()) {
                            statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                        }
                        //总业绩
                        statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
                        //扣减后业绩
                        statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                        statistic.setZyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                        statistic.setCooperationAchi(statistic.getCooperationAchi());

                        staffStatisticLists.add(statistic);
                    }
                }
                staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());

                Map<Long, List<StaffStatistic>> resultMaps = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));

                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList = resultMaps.entrySet().iterator();
                while (entryIteratorsList.hasNext()) {
                    StaffStatistic staffStatistic1 = new StaffStatistic();

                    Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    staffStatistic1.setStaffId(listByStaff.get(0).getStaffId());
                    staffStatistic1.setStaffName(listByStaff.get(0).getStaffName());
                    staffStatistic1.setBrandNumber(listByStaff.get(0).getBrandNumber());
                    staffStatistic1.setCooperationAchi(listByStaff.get(0).getCooperationAchi());
                    staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    if(staffStatistic1.getLcCardyj()==null) {
                        staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    staffStatistic1.setFootMassageComm(decimal);
                    staffStatistic1.setFootMassageChia(decimal);
                    staffStatistic1.setCardFootMassageComm(decimal);
                    staffStatistic1.setCardFootMassageChia(decimal);
                    staffStatistic1.setMarketChia(decimal);
                    staffStatistic1.setMarketComm(decimal);
                    for (StaffStatistic statistic : listByStaff) {
                        if (null == statistic.getRechargeyj()) {
                            statistic.setRechargeyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getCourseOfTreatmentYJ()) {
                            statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getLcCardyj()) {
                            statistic.setLcCardyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getSyxfyj()) {
                            statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getSyczkfyj()) {
                            statistic.setSyczkfyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getSylcxkyj()) {
                            statistic.setSylcxkyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getTkyj()) {
                            statistic.setTkyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getKjhyj()) {
                            statistic.setKjhyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getXftlcczhjyj()) {
                            statistic.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getTotalyj()) {
                            statistic.setTotalyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getTotaltc()) {
                            statistic.setTotaltc(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getZyj()) {
                            statistic.setZyj(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getRechargeTurnCourseChia()) {
                            statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getRechargeTurnCourseComm()) {
                            statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getGroupPurchaseChia()) {
                            statistic.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getGroupPurchaseComm()) {
                            statistic.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getFootMassageComm()) {
                            statistic.setFootMassageComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getFootMassageChia()) {
                            statistic.setFootMassageChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getCardFootMassageComm()) {
                            statistic.setCardFootMassageComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getCardFootMassageChia()) {
                            statistic.setCardFootMassageChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getMarketChia()) {
                            statistic.setMarketChia(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getMarketComm()) {
                            statistic.setMarketComm(BigDecimal.valueOf(0.00));
                        }
                        if (null == statistic.getNTMoney()) {
                            statistic.setNTMoney(BigDecimal.valueOf(0.00));
                        }
                        staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().add(statistic.getRechargeyj()));
                        staffStatistic1.setCourseOfTreatmentYJ(staffStatistic1.getCourseOfTreatmentYJ().add(statistic.getCourseOfTreatmentYJ()));
                        staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().add(statistic.getLcCardyj()));
                        staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().add(statistic.getSyxfyj()));
                        staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().add(statistic.getSyczkfyj()));
                        staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().add(statistic.getSylcxkyj()));
                        staffStatistic1.setTkyj(staffStatistic1.getTkyj().add(statistic.getTkyj()));
                        staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().add(statistic.getKjhyj()));
                        staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().add(statistic.getCardcxyj()));
                        staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().add(statistic.getCashcxyj()));
                        staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().add(statistic.getXftlcczhjyj()));
                        staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().add(statistic.getTotalyj()));
                        staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getTotaltc()));
                        staffStatistic1.setZyj(staffStatistic1.getZyj().add(statistic.getZyj()));
                        staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getRechargeTurnCourseChia()));
                        staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().add(statistic.getRechargeTurnCourseComm()));
                        staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().add(statistic.getGroupPurchaseChia()));
                        staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().add(statistic.getGroupPurchaseComm()));

                        staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().add(statistic.getFootMassageComm()));
                        staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().add(statistic.getFootMassageChia()));
                        staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().add(statistic.getCardFootMassageComm()));
                        staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().add(statistic.getCardFootMassageChia()));
                        staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().add(statistic.getMarketChia()));
                        staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().add(statistic.getMarketComm()));
                        staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().add(statistic.getNTMoney()));
                        staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi());
                    }

                    staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistic1.getCourseOfTreatmentYJ(), staffStatistic1.getCashcxyj()).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTkyj(staffStatistic1.getTkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setZyj(staffStatistic1.getZyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().setScale(2, BigDecimal.ROUND_HALF_UP));


                    staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().setScale(2, BigDecimal.ROUND_HALF_UP));

                    BaseStaff baseStaff = new BaseStaff();
                    baseStaff.setId(staffStatistic1.getStaffId());
                    BaseStaff select = ssmBaseStaffService.selectOne(baseStaff);
                    staffStatistic1.setBaseSalary(BigDecimal.valueOf(0));
                    staffStatistic1.setTotalWages(BigDecimal.valueOf(0));
                    //todo 空指针
                    if (select != null) {
                        staffStatistic1.setBaseSalary(select.getBaseSalary());
                        staffStatistic1.setTotalWages(select.getBaseSalary().add(staffStatistic1.getTotaltc()));
                    }
                    String format = String.format("%.2f", staffStatistic1.getTotaltc());
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(Double.valueOf(format)).setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setStoreName(baseStore.getStoreName());
                    staffStatistic1.setStoreNum(baseStore.getStoreNum());
                    staffStatisticsLs.add(staffStatistic1);
                }


                List<AchiCommEntity> totalList1 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
                //合并list
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
                while (entryIterator1.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();

                        //业绩
                        BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                        statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                        //按天查询用date

                        statistic.setDate(list.get(list.size() - 1).getDocDate());
                        statistic.setAchievementAmount(CardAchi);
                        statistic.setCommissionAmount(CardComm);
                        statistic.setCardAchi(CardAchi);
                        statistic.setCardComm(CardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                        staffStatisticList1.add(statistic);
                    }
                    //}
                }

                for (StaffStatistic statistic : staffStatisticList1) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        staffStatisticList2.add(statistic);
                    }
                }
                staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());

                Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
                //汇总后的集合

                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();

                List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
                while (entryIteratorsList1.hasNext()) {
                    StaffStatistic staffStatistic1 = new StaffStatistic();

                    Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    for (StaffStatistic statistic : listByStaff) {

                        staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                        if(staffStatistic1.getLcCardyj()==null) {
                            staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                        }
                        staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                        BigDecimal decimal = BigDecimal.valueOf(0);
                        staffStatistic1.setFootMassageComm(decimal);
                        staffStatistic1.setFootMassageChia(decimal);
                        staffStatistic1.setCardFootMassageComm(decimal);
                        staffStatistic1.setCardFootMassageChia(decimal);
                        staffStatistic1.setMarketChia(decimal);
                        staffStatistic1.setMarketComm(decimal);


                        staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStaffName(statistic.getStaffName());
                        staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                        staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                        staffStatisticsLs1.add(staffStatistic1);
                    }

                }
                for (StaffStatistic staffStatistics : staffStatisticsLs) {
                    for (StaffStatistic statistic : staffStatisticsLs1) {
                        if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                            staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(), statistic.getCourseOfTreatmentYJ()));
                            staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(), statistic.getCourseOfTreatmentYJ()));
                            staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(), statistic.getCourseOfTreatmentYJ()));
                            staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                            staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                        }
                    }
                }
                List<Long> longs = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
                List<StaffStatistic> collect = staffStatisticsLs1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

                for (StaffStatistic statistic : collect) {
                    staffStatisticsLs.add(statistic);
                }


                //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
                List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
                List<AchiCommEntity> totalList2 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
                List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
                //合并list
                coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
                //按员工ID进行分组
                Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
                while (entryIterator2.hasNext()) {
                    Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                    //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                    List<AchiCommEntity> listByStaff = entry.getValue();
                    //按天进行分组
                    Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                    Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                    while (iterator.hasNext()) {
                        Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                        List<AchiCommEntity> list = stringListEntry.getValue();

                        //业绩
                        //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                        //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                        BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                        statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                        //按天查询用date

                        statistic.setDate(list.get(list.size() - 1).getDocDate());
                        statistic.setAchievementAmount(CardAchi);
                        statistic.setCommissionAmount(CardComm);
                        statistic.setCardAchi(CardAchi);
                        statistic.setCardComm(CardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                        staffStatisticList3.add(statistic);
                    }
                    //}
                }

                for (StaffStatistic statistic : staffStatisticList3) {
                    boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                    if (effectiveDate) {
                        staffStatisticList4.add(statistic);
                    }
                }
                staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());

                Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
                //汇总后的集合

                //计算每个分组员工的业绩
                Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();

                List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();
                while (entryIteratorsList2.hasNext()) {
                    StaffStatistic staffStatistic1 = new StaffStatistic();

                    Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
                    List<StaffStatistic> listByStaff = entry.getValue();
                    for (StaffStatistic statistic : listByStaff) {

                        staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                        if(staffStatistic1.getLcCardyj()==null) {
                            staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                        }
                        staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                        staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                        staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                        BigDecimal decimal = BigDecimal.valueOf(0);
                        staffStatistic1.setFootMassageComm(decimal);
                        staffStatistic1.setFootMassageChia(decimal);
                        staffStatistic1.setCardFootMassageComm(decimal);
                        staffStatistic1.setCardFootMassageChia(decimal);
                        staffStatistic1.setMarketChia(decimal);
                        staffStatistic1.setMarketComm(decimal);

                        staffStatistic1.setStaffId(statistic.getStaffId());
                        //staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setStaffId(statistic.getStaffId());
                        staffStatistic1.setStaffName(statistic.getStaffName());
                        staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                        //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setRechargeTurnCourseChia(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setZyj(BigDecimalUtils.bigDecimal("0"));
                        staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                        staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());

                        staffStatisticsLs2.add(staffStatistic1);
                    }

                }
                for (StaffStatistic staffStatistics : staffStatisticsLs) {

                    for (StaffStatistic statistic : staffStatisticsLs2) {
                        if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                            //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
//                            staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(), statistic.getRechargeTurnCourseChia()));
                            //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                            //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                            staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                            staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                        }
                    }
//            staffStatistics.setCourseOfTreatmentYJ(staffStatistics.getCourseOfTreatmentYJ().add(
//                    (staffStatistics.getCardAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCardAchi())
//                    .add(staffStatistics.getCashAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCashAchi())));
                }
                List<Long> longs1 = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
                List<StaffStatistic> collect1 = staffStatisticsLs2.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

                for (StaffStatistic statistic : collect1) {

                    staffStatisticsLs.add(statistic);
                }
            }
        }
        else {
            //-----------------
            BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(staffStatistic.getStoreId());
            List<StaffStatistic> staffStatisticList = new ArrayList<>();
            List<StaffStatistic> staffStatisticLists = new ArrayList<>();

            BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
            BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
            //根据时间类别转换时间
            //int type = staffStatistic.getType();
            String dateStr = staffStatistic.getStartDate().substring(0, 7);
//        Date date = new Date();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = dateFormat.parse(staffStatistic.getStartDate());
            Long storeId = staffStatistic.getStoreId();
            List<CourseListResponse> courseList = new ArrayList<>();
            if (null == staffStatistic.getClassify()) {
                courseList = ssmCourseService.memberInitStaff(storeId, dateStr, date);
            } else {
               if ("1".equals(staffStatistic.getClassify())) {
                    //查询疗程业务员信息
                    courseList = ssmCourseService.memberInitStaff(storeId, dateStr, date);
                }
            }
            List<AchiCommEntity> totalList = new ArrayList<>();
            courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
            while (entryIterator.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //todo
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCashAchi() == null ? BigDecimal.valueOf(0) : item.getCashAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //todo
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(item -> item.getCardAchi() == null ? BigDecimal.valueOf(0) : item.getCardAchi()).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销还款
                    BigDecimal cooperationAchi = BigDecimalUtils.bigDecimal("0");
                    for (AchiCommEntity achiCommEntity : list) {
                        for (CourseListResponse courseListResponse : courseList) {
                            if (achiCommEntity.getDocId() == courseListResponse.getId()) {
                                for (AchiCommEntity entity : courseListResponse.getEntities()) {
                                    if (entry.getKey().equals(entity.getSaleStaffId())) {
                                        cooperationAchi = cooperationAchi.add((courseListResponse.getCollectionCashAmount().subtract(courseListResponse.getAchievementAmount())).multiply(entity.getSaleRatio().divide(BigDecimal.valueOf(100), 10, BigDecimal.ROUND_HALF_UP)));
                                    }
                                }
                            }
                        }
                    }
//                BigDecimal cooperationAchi = list.stream().filter(achiCommEntity -> achiCommEntity.getCooperationAchi()!=null).map(AchiCommEntity::getCooperationAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    achievementAmount = BigDecimalUtils.subtract(
                            BigDecimalUtils.subtract(
                                    BigDecimalUtils.subtract(
                                            BigDecimalUtils.add(
                                                    BigDecimalUtils.add(
                                                            BigDecimalUtils.add(
                                                                    recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(
                            BigDecimalUtils.subtract(
                                    BigDecimalUtils.subtract(
                                            BigDecimalUtils.subtract(
                                                    BigDecimalUtils.add(
                                                            BigDecimalUtils.add(
                                                                    BigDecimalUtils.add(
                                                                            recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi), repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(
                                    BigDecimalUtils.add(
                                            BigDecimalUtils.add(
                                                    courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi)
                            .add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(list.size() - 1).getDocDate());
                    statistic.setLcCardyj(promotionCardAchi);
                    statistic.setAchievementAmount(achievementAmount);
                    statistic.setCommissionAmount(commissionAmount);
                    statistic.setCashAchi(totalCashAchi);
                    statistic.setCardAchi(totalCardAchi);
                    statistic.setCashComm(totalCashComm);
                    statistic.setCardComm(totalCardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());

                    statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                    statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                    statistic.setCooperationAchi(cooperationAchi);
                    BigDecimal repayProAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayProComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && achiCommEntity.getDocType().equals("promotion_card_use")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    statistic.setCourseOfTreatmentYJ(repayProAchi);
                    statistic.setCourseOfTreatmentTC(repayProComm);
                    staffStatisticList.add(statistic);
                }
                //}
            }

            for (StaffStatistic statistic : staffStatisticList) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    StaffStatistic staffStatistic1 = new StaffStatistic();
                    staffStatistic1.setSelectDate(String.valueOf(statistic.getDate()));
                    staffStatistic1.setDate(statistic.getDate());
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStoreId(storeId);
                    staffStatistic1.setClassify("0");
                    List<StaffStatistic> staffStatistics = null;
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setRechargeyj(BigDecimal.valueOf(0));
                    statistic.setRechargeTC(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setRechargeyj(statistic.getRechargeyj().add(staffStatistic2.getAchievementAmount()));
                                statistic.setRechargeTC(statistic.getRechargeTC().add(staffStatistic2.getCommissionAmount()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("1");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    if(statistic.getCourseOfTreatmentYJ()==null){
                        statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0));
                    }
                    if(statistic.getCourseOfTreatmentTC()==null){

                        statistic.setCourseOfTreatmentTC(BigDecimal.valueOf(0));
                    }
                    if(statistic.getLcCardyj()==null) {
                        statistic.setLcCardyj(BigDecimal.valueOf(0));
                    }
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setCourseOfTreatmentTC(statistic.getCourseOfTreatmentTC().add(staffStatistic2.getCommissionAmount()));
                                statistic.setLcCardyj(statistic.getLcCardyj().add(staffStatistic2.getLcCardyj()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("2");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setServeYJ(BigDecimal.valueOf(0));
                    statistic.setServeTC(BigDecimal.valueOf(0));
                    statistic.setSyxfyj(BigDecimal.valueOf(0));
                    statistic.setSyczkfyj(BigDecimal.valueOf(0));
                    statistic.setSylcxkyj(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setServeYJ(statistic.getServeYJ().add(staffStatistic2.getCashAchi().add(staffStatistic2.getCardAchi())));
                                statistic.setServeTC(statistic.getServeTC().add(staffStatistic2.getCashComm().add(staffStatistic2.getCardComm())));
                                //收银的现付总业绩
                                statistic.setSyxfyj(statistic.getSyxfyj().add(staffStatistic2.getSyxfyj()));
                                statistic.setSyczkfyj(statistic.getSyczkfyj().add(staffStatistic2.getSyczkfyj()));
                                statistic.setSylcxkyj(statistic.getSylcxkyj().add(staffStatistic2.getSylcxkyj()));
                            }
                        }
                    }

                    staffStatistics = null;
                    staffStatistic1.setClassify("4");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setTopUpRefundYJ(BigDecimal.valueOf(0));
                    statistic.setTopUpRefundTC(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setTopUpRefundYJ(statistic.getTopUpRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setTopUpRefundTC(statistic.getTopUpRefundTC().add(staffStatistic2.getCommissionAmount()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("5");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setACourseOfRefundYJ(BigDecimal.valueOf(0));
                    statistic.setACourseOfRefundTC(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setACourseOfRefundYJ(statistic.getACourseOfRefundYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setACourseOfRefundTC(statistic.getACourseOfRefundTC().add(staffStatistic2.getCommissionAmount()));
                            }
                        }
                    }
                    statistic.setACourseOfRefundYJ(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundYJ()));
                    statistic.setACourseOfRefundTC(BigDecimalUtils.bigDecimal("0").subtract(statistic.getACourseOfRefundTC()));

                    staffStatistics = null;
                    staffStatistic1.setClassify("6");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setCashierRefundYJ(BigDecimal.valueOf(0));
                    statistic.setCashierRefundTC(BigDecimal.valueOf(0));
                    statistic.setXftlcczhjyj(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setCashierRefundYJ(statistic.getCashierRefundYJ().add(staffStatistic2.getCashAchi().abs().add(staffStatistic2.getCardAchi().abs())));
                                statistic.setCashierRefundTC(statistic.getCashierRefundTC().add(staffStatistic2.getCashComm().abs().add(staffStatistic2.getCardComm().abs())));
                                statistic.setXftlcczhjyj(staffStatistic2.getXftlcczhjyj().abs().add(statistic.getXftlcczhjyj().abs()));
                            }
                        }
                    }
                    statistic.setCashierRefundYJ(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundYJ()));
                    statistic.setCashierRefundTC(BigDecimal.valueOf(0).subtract(statistic.getCashierRefundTC()));
                    statistic.setXftlcczhjyj(BigDecimal.valueOf(0).subtract(statistic.getXftlcczhjyj().setScale(3,BigDecimal.ROUND_HALF_UP)));

                    staffStatistics = null;
                    staffStatistic1.setClassify("7");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setLeafletYJ(BigDecimal.valueOf(0));
                    statistic.setLeafletTC(BigDecimal.valueOf(0));
                    statistic.setCashcxyj(BigDecimal.valueOf(0));
                    statistic.setCardcxyj(BigDecimal.valueOf(0));
                    statistic.setCashcxtc(BigDecimal.valueOf(0));
                    statistic.setCardcxtc(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setLeafletYJ(statistic.getLeafletYJ().add(staffStatistic2.getAchievementAmount()));
                                statistic.setLeafletTC(statistic.getLeafletTC().add(staffStatistic2.getCommissionAmount()));
                                statistic.setCashcxyj(statistic.getCashcxyj().add(staffStatistic2.getCashcxyj()));
                                statistic.setCardcxyj(statistic.getCardcxyj().add(staffStatistic2.getCardcxyj()));
                            }
                        }
                    }

                    staffStatistics = null;
                    staffStatistic1.setClassify("8");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setJjzlcyj(BigDecimal.valueOf(0));
                    statistic.setJjzlctc(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(statistic.getCashAchi(),statistic.getCardAchi())));
//                            statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(statistic.getCashComm(),statistic.getCardComm())));
                                statistic.setJjzlcyj(statistic.getJjzlcyj().add(BigDecimalUtils.add(staffStatistic2.getCashAchi(), BigDecimal.valueOf(0.00))));
                                statistic.setJjzlctc(statistic.getJjzlctc().add(BigDecimalUtils.add(BigDecimalUtils.add(staffStatistic2.getCashComm(), staffStatistic2.getCardComm()), BigDecimal.valueOf(0.00))));
                                statistic.setCourseOfTreatmentYJ(statistic.getCourseOfTreatmentYJ().add(staffStatistic2.getCashAchi()));
                            }
                        }
                    }

                    staffStatistics = null;
                    statistic.setNTMoney(BigDecimal.valueOf(0));
                    staffStatistic1.setClassify("3");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                if (null == staffStatistic2.getCzhkyj()) {
                                    staffStatistic2.setCzhkyj(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getCzhktc()) {
                                    staffStatistic2.setCzhktc(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getLchkyj()) {
                                    staffStatistic2.setLchkyj(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getLchktc()) {
                                    staffStatistic2.setLchktc(BigDecimal.valueOf(0));
                                }
                                if (null == staffStatistic2.getNTMoney()) {
                                    staffStatistic2.setNTMoney(BigDecimal.valueOf(0));
                                }
                                //充值开卡
                                statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getCzhkyj()));
                                statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getCzhktc()));
                                //疗程开卡
                                statistic.setCourseOfTreatmentYJ(BigDecimalUtils.add(statistic.getCourseOfTreatmentYJ(), staffStatistic2.getLchkyj()));
                                statistic.setCourseOfTreatmentTC(BigDecimalUtils.add(statistic.getCourseOfTreatmentTC(), staffStatistic2.getLchktc()));
                                //促销开卡
                                if (staffStatistic2.getType() == 2) {
                                    statistic.setCashcxyj(BigDecimalUtils.add(statistic.getCashcxyj(), staffStatistic2.getCashcxyj()));
                                    statistic.setCashcxtc(BigDecimalUtils.add(statistic.getCashcxtc(), staffStatistic2.getCashcxtc()));
                                }
                                statistic.setNTMoney(statistic.getNTMoney().add(staffStatistic2.getNTMoney()));
                            }
                        }
                    }

                    staffStatistics = null;
                    staffStatistic1.setClassify("9");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0));
                    statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setRechargeTurnCourseChia(statistic.getRechargeTurnCourseChia().add(staffStatistic2.getRechargeTurnCourseChia()));
                                statistic.setRechargeTurnCourseComm(statistic.getRechargeTurnCourseComm().add(staffStatistic2.getRechargeTurnCourseComm()));
                            }
                        }
                    }


                    staffStatistics = null;
                    staffStatistic1.setClassify("10");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    statistic.setGroupPurchaseChia(BigDecimal.valueOf(0));
                    statistic.setGroupPurchaseComm(BigDecimal.valueOf(0));
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
//                            statistic.setGroupPurchaseChia(statistic.getGroupPurchaseChia().add(staffStatistic2.getGroupPurchaseChia()));
//                            statistic.setGroupPurchaseComm(statistic.getGroupPurchaseComm().add(staffStatistic2.getGroupPurchaseComm()));
                                statistic.setRechargeyj(BigDecimalUtils.add(statistic.getRechargeyj(), staffStatistic2.getGroupPurchaseChia()));
                                statistic.setRechargeTC(BigDecimalUtils.add(statistic.getRechargeTC(), staffStatistic2.getGroupPurchaseComm()));
                            }
                        }
                    }
                    staffStatistics = null;
                    staffStatistic1.setClassify("11");
                    staffStatistics = ssmStoreStatisticService.couseListMemberInitStaff(staffStatistic1);
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    statistic.setFootMassageComm(decimal);
                    statistic.setFootMassageChia(decimal);
                    statistic.setCardFootMassageComm(decimal);
                    statistic.setCardFootMassageChia(decimal);
                    statistic.setMarketChia(decimal);
                    statistic.setMarketComm(decimal);
                    if (staffStatistics != null) {
                        if (staffStatistics.size() > 0) {
                            for (StaffStatistic staffStatistic2 : staffStatistics) {
                                statistic.setFootMassageComm(statistic.getFootMassageComm().add(staffStatistic2.getFootMassageComm()));
                                statistic.setFootMassageChia(statistic.getFootMassageChia().add(staffStatistic2.getFootMassageChia()));
                                statistic.setCardFootMassageComm(statistic.getCardFootMassageComm().add(staffStatistic2.getCardFootMassageComm()));
                                statistic.setCardFootMassageChia(statistic.getCardFootMassageChia().add(staffStatistic2.getCardFootMassageChia()));
                                statistic.setMarketChia(statistic.getMarketChia().add(staffStatistic2.getMarketChia()));
                                statistic.setMarketComm(statistic.getMarketComm().add(staffStatistic2.getMarketComm()));
                            }
                        }
                    }

                    //根据甲方要求，退款的单据业绩不加进总业绩里面
                    statistic.setTotalyj(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getServeYJ().add(statistic.getLeafletYJ().add(statistic.getJjzlcyj()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia().add(statistic.getCardFootMassageChia())))))));
                    //todo 进行修改
//                statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                    statistic.setTotaltc(statistic.getRechargeTC().add(statistic.getCourseOfTreatmentTC()).add(statistic.getServeTC().add(statistic.getTopUpRefundTC().add(statistic.getACourseOfRefundTC().add(statistic.getLeafletTC().add(statistic.getJjzlctc()).add(statistic.getRechargeTurnCourseComm()).add(statistic.getCashierRefundTC()).add(statistic.getGroupPurchaseComm()).add(statistic.getCashcxtc().add(statistic.getMarketComm().add(statistic.getFootMassageComm().add(statistic.getCardFootMassageComm())))))))));
                    //退款业绩
                    statistic.setTkyj(statistic.getCashierRefundYJ().add(statistic.getACourseOfRefundYJ().add(statistic.getTopUpRefundYJ())));
                    if (null == statistic.getSyxfyj()) {
                        statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                    }
                    //总业绩

                    statistic.setZyj(statistic.getSyxfyj().add(statistic.getRechargeyj().add(statistic.getCourseOfTreatmentYJ()).add(statistic.getGroupPurchaseChia()).add(statistic.getCashcxyj().add(statistic.getMarketChia().add(statistic.getFootMassageChia())))));
                    //扣减后业绩
                    if(statistic.getTotalyj().compareTo(new BigDecimal("6000"))==0){
                        System.out.println(".....");
                    }
                    statistic.setKjhyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                    statistic.setZyj(statistic.getZyj().subtract(statistic.getTkyj().abs()));
                    statistic.setCooperationAchi(statistic.getCooperationAchi());

                    staffStatisticLists.add(statistic);
                }
            }
            staffStatisticLists.sort(comparing(StaffStatistic::getDate).reversed());

            Map<Long, List<StaffStatistic>> resultMaps = staffStatisticLists.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));

            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList = resultMaps.entrySet().iterator();
            while (entryIteratorsList.hasNext()) {
                StaffStatistic staffStatistic1 = new StaffStatistic();

                Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                staffStatistic1.setStaffId(listByStaff.get(0).getStaffId());
                staffStatistic1.setStaffName(listByStaff.get(0).getStaffName());
                staffStatistic1.setBrandNumber(listByStaff.get(0).getBrandNumber());
                staffStatistic1.setCooperationAchi(listByStaff.get(0).getCooperationAchi());
                staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                if(staffStatistic1.getLcCardyj()==null) {
                    staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                }
                staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                BigDecimal decimal = BigDecimal.valueOf(0);
                staffStatistic1.setFootMassageComm(decimal);
                staffStatistic1.setFootMassageChia(decimal);
                staffStatistic1.setCardFootMassageComm(decimal);
                staffStatistic1.setCardFootMassageChia(decimal);
                staffStatistic1.setMarketChia(decimal);
                staffStatistic1.setMarketComm(decimal);
                for (StaffStatistic statistic : listByStaff) {
                    if (null == statistic.getRechargeyj()) {
                        statistic.setRechargeyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getCourseOfTreatmentYJ()) {
                        statistic.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getLcCardyj()) {
                        statistic.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getSyxfyj()) {
                        statistic.setSyxfyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getSyczkfyj()) {
                        statistic.setSyczkfyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getSylcxkyj()) {
                        statistic.setSylcxkyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getTkyj()) {
                        statistic.setTkyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getKjhyj()) {
                        statistic.setKjhyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getXftlcczhjyj()) {
                        statistic.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getTotalyj()) {
                        statistic.setTotalyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getTotaltc()) {
                        statistic.setTotaltc(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getZyj()) {
                        statistic.setZyj(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getRechargeTurnCourseChia()) {
                        statistic.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getRechargeTurnCourseComm()) {
                        statistic.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getGroupPurchaseChia()) {
                        statistic.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getGroupPurchaseComm()) {
                        statistic.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getFootMassageComm()) {
                        statistic.setFootMassageComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getFootMassageChia()) {
                        statistic.setFootMassageChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getCardFootMassageComm()) {
                        statistic.setCardFootMassageComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getCardFootMassageChia()) {
                        statistic.setCardFootMassageChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getMarketChia()) {
                        statistic.setMarketChia(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getMarketComm()) {
                        statistic.setMarketComm(BigDecimal.valueOf(0.00));
                    }
                    if (null == statistic.getNTMoney()) {
                        statistic.setNTMoney(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().add(statistic.getRechargeyj()));
                    staffStatistic1.setCourseOfTreatmentYJ(staffStatistic1.getCourseOfTreatmentYJ().add(statistic.getCourseOfTreatmentYJ()));
                    staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().add(statistic.getLcCardyj()));
                    staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().add(statistic.getSyxfyj()));
                    staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().add(statistic.getSyczkfyj()));
                    staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().add(statistic.getSylcxkyj()));
                    staffStatistic1.setTkyj(staffStatistic1.getTkyj().add(statistic.getTkyj()));
                    staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().add(statistic.getKjhyj()));
                    staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().add(statistic.getCardcxyj()));
                    staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().add(statistic.getCashcxyj()));
                    staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().add(statistic.getXftlcczhjyj()));
                    staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().add(statistic.getTotalyj()));
                    staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().add(statistic.getTotaltc()));
                    staffStatistic1.setZyj(staffStatistic1.getZyj().add(statistic.getZyj()));
                    staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().add(statistic.getRechargeTurnCourseChia()));
                    staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().add(statistic.getRechargeTurnCourseComm()));
                    staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().add(statistic.getGroupPurchaseChia()));
                    staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().add(statistic.getGroupPurchaseComm()));

                    staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().add(statistic.getFootMassageComm()));
                    staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().add(statistic.getFootMassageChia()));
                    staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().add(statistic.getCardFootMassageComm()));
                    staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().add(statistic.getCardFootMassageChia()));
                    staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().add(statistic.getMarketChia()));
                    staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().add(statistic.getMarketComm()));
                    staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().add(statistic.getNTMoney()));
                    staffStatistic1.setCooperationAchi(staffStatistic1.getCooperationAchi());
                }

                staffStatistic1.setRechargeyj(staffStatistic1.getRechargeyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistic1.getCourseOfTreatmentYJ(), staffStatistic1.getCashcxyj()).setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setLcCardyj(staffStatistic1.getLcCardyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setSyxfyj(staffStatistic1.getSyxfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setSyczkfyj(staffStatistic1.getSyczkfyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setSylcxkyj(staffStatistic1.getSylcxkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTkyj(staffStatistic1.getTkyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setKjhyj(staffStatistic1.getKjhyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCardcxyj(staffStatistic1.getCardcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCashcxyj(staffStatistic1.getCashcxyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setXftlcczhjyj(staffStatistic1.getXftlcczhjyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotalyj(staffStatistic1.getTotalyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setTotaltc(staffStatistic1.getTotaltc().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setZyj(staffStatistic1.getZyj().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargeTurnCourseChia(staffStatistic1.getRechargeTurnCourseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setRechargeTurnCourseComm(staffStatistic1.getRechargeTurnCourseComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setGroupPurchaseChia(staffStatistic1.getGroupPurchaseChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setGroupPurchaseComm(staffStatistic1.getGroupPurchaseComm().setScale(2, BigDecimal.ROUND_HALF_UP));


                staffStatistic1.setFootMassageComm(staffStatistic1.getFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setFootMassageChia(staffStatistic1.getFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCardFootMassageComm(staffStatistic1.getCardFootMassageComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setCardFootMassageChia(staffStatistic1.getCardFootMassageChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setMarketChia(staffStatistic1.getMarketChia().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setMarketComm(staffStatistic1.getMarketComm().setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setNTMoney(staffStatistic1.getNTMoney().setScale(2, BigDecimal.ROUND_HALF_UP));

                BaseStaff baseStaff = new BaseStaff();
                baseStaff.setId(staffStatistic1.getStaffId());
                BaseStaff select = ssmBaseStaffService.selectOne(baseStaff);
                staffStatistic1.setBaseSalary(BigDecimal.valueOf(0));
                staffStatistic1.setTotalWages(BigDecimal.valueOf(0));
                //todo 空指针
                if (select != null) {
                    staffStatistic1.setBaseSalary(select.getBaseSalary());
                    staffStatistic1.setTotalWages(select.getBaseSalary().add(staffStatistic1.getTotaltc()));
                }
                String format = String.format("%.2f", staffStatistic1.getTotaltc());
                staffStatistic1.setTotaltc(BigDecimal.valueOf(Double.valueOf(format)).setScale(2, BigDecimal.ROUND_HALF_UP));
                staffStatistic1.setStoreName(baseStore.getStoreName());
                staffStatistic1.setStoreNum(baseStore.getStoreNum());
                staffStatisticsLs.add(staffStatistic1);
            }


            List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList1 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList1 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList2 = new ArrayList<>();
            //合并list
            cardChangeOutLists.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList1)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap1 = totalList1.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator1 = resultMap1.entrySet().iterator();
            while (entryIterator1.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator1.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();

                    //业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*
                achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(groupPurchaseChia);
                commissionAmount =BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                        BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(groupPurchaseComm);

                //总卡付业绩
                BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(list.size() - 1).getDocDate());
                    statistic.setAchievementAmount(CardAchi);
                    statistic.setCommissionAmount(CardComm);
                    statistic.setCardAchi(CardAchi);
                    statistic.setCardComm(CardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                    staffStatisticList1.add(statistic);
                }
                //}
            }

            for (StaffStatistic statistic : staffStatisticList1) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    staffStatisticList2.add(statistic);
                }
            }
            staffStatisticList2.sort(comparing(StaffStatistic::getDate).reversed());

            Map<Long, List<StaffStatistic>> resultMaps1 = staffStatisticList2.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
            //汇总后的集合

            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList1 = resultMaps1.entrySet().iterator();

            List<StaffStatistic> staffStatisticsLs1 = new ArrayList<>();
            while (entryIteratorsList1.hasNext()) {
                StaffStatistic staffStatistic1 = new StaffStatistic();

                Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList1.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                for (StaffStatistic statistic : listByStaff) {

                    staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    if(staffStatistic1.getLcCardyj()==null) {
                        staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    staffStatistic1.setFootMassageComm(decimal);
                    staffStatistic1.setFootMassageChia(decimal);
                    staffStatistic1.setCardFootMassageComm(decimal);
                    staffStatistic1.setCardFootMassageChia(decimal);
                    staffStatistic1.setMarketChia(decimal);
                    staffStatistic1.setMarketComm(decimal);


                    staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStaffName(statistic.getStaffName());
                    staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                    staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                    staffStatisticsLs1.add(staffStatistic1);
                }

            }
            for (StaffStatistic staffStatistics : staffStatisticsLs) {
                for (StaffStatistic statistic : staffStatisticsLs1) {
                    if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                        staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(), statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(), statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(), statistic.getCourseOfTreatmentYJ()));
                        staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                        staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                    }
                }
            }
            List<Long> longs = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
            List<StaffStatistic> collect = staffStatisticsLs1.stream().filter(s -> !longs.contains(s.getStaffId())).collect(Collectors.toList());

            for (StaffStatistic statistic : collect) {
                staffStatisticsLs.add(statistic);
            }


            //List<CardChangeOutProjectResponse> cardChangeOutLists = ssmCardChangeService.selectOutList(storeId,dateStr);
            List<CoursePayListResponse> coursePayListResponses = ssmCoursePayListService.selectOutList(storeId, dateStr);
            List<AchiCommEntity> totalList2 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList3 = new ArrayList<>();
            List<StaffStatistic> staffStatisticList4 = new ArrayList<>();
            //合并list
            coursePayListResponses.forEach(rechargeListResponse -> rechargeListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList2)));
            //按员工ID进行分组
            Map<Long, List<AchiCommEntity>> resultMap2 = totalList2.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator2 = resultMap2.entrySet().iterator();
            while (entryIterator2.hasNext()) {
                Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator2.next();
                //if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate()).substring(0, 10)));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();

                    //业绩
                    //BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

/*

                //总卡付提成
                BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm);*/
                    StaffStatistic statistic = new StaffStatistic();
                    statistic.setStaffId(entry.getKey());
                    statistic.setStaffName(list.get(list.size() - 1).getSaleStaffName());
                    statistic.setBrandNumber(list.get(list.size() - 1).getBrandNumber());
                    //按天查询用date

                    statistic.setDate(list.get(list.size() - 1).getDocDate());
                    statistic.setAchievementAmount(CardAchi);
                    statistic.setCommissionAmount(CardComm);
                    statistic.setCardAchi(CardAchi);
                    statistic.setCardComm(CardComm);
                    statistic.setClassify(staffStatistic.getClassify());
                    statistic.setStoreId(staffStatistic.getStoreId());
                    statistic.setCooperationAchi(staffStatistic.getCooperationAchi());

                    staffStatisticList3.add(statistic);
                }
                //}
            }

            for (StaffStatistic statistic : staffStatisticList3) {
                boolean effectiveDate = this.isEffectiveDate(statistic.getDate(), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getStartDate()), com.alibaba.excel.util.DateUtils.parseDate(staffStatistic.getEndDate()));
                if (effectiveDate) {
                    staffStatisticList4.add(statistic);
                }
            }
            staffStatisticList4.sort(comparing(StaffStatistic::getDate).reversed());

            Map<Long, List<StaffStatistic>> resultMaps2 = staffStatisticList4.stream().collect(Collectors.groupingBy(StaffStatistic::getStaffId));
            //汇总后的集合

            //计算每个分组员工的业绩
            Iterator<Map.Entry<Long, List<StaffStatistic>>> entryIteratorsList2 = resultMaps2.entrySet().iterator();

            List<StaffStatistic> staffStatisticsLs2 = new ArrayList<>();
            while (entryIteratorsList2.hasNext()) {
                StaffStatistic staffStatistic1 = new StaffStatistic();

                Map.Entry<Long, List<StaffStatistic>> entry = entryIteratorsList2.next();
                List<StaffStatistic> listByStaff = entry.getValue();
                for (StaffStatistic statistic : listByStaff) {

                    staffStatistic1.setRechargeyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCourseOfTreatmentYJ(BigDecimal.valueOf(0.00));
                    if(staffStatistic1.getLcCardyj()==null) {
                        staffStatistic1.setLcCardyj(BigDecimal.valueOf(0.00));
                    }
                    staffStatistic1.setSyxfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSyczkfyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setSylcxkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTkyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setKjhyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setXftlcczhjyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotalyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setTotaltc(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCardcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setCashcxyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setZyj(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setRechargeTurnCourseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseChia(BigDecimal.valueOf(0.00));
                    staffStatistic1.setGroupPurchaseComm(BigDecimal.valueOf(0.00));
                    staffStatistic1.setNTMoney(BigDecimal.valueOf(0.00));
                    BigDecimal decimal = BigDecimal.valueOf(0);
                    staffStatistic1.setFootMassageComm(decimal);
                    staffStatistic1.setFootMassageChia(decimal);
                    staffStatistic1.setCardFootMassageComm(decimal);
                    staffStatistic1.setCardFootMassageChia(decimal);
                    staffStatistic1.setMarketChia(decimal);
                    staffStatistic1.setMarketComm(decimal);

                    staffStatistic1.setStaffId(statistic.getStaffId());
                    //staffStatistic1.setKjhyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setStaffId(statistic.getStaffId());
                    staffStatistic1.setStaffName(statistic.getStaffName());
                    staffStatistic1.setBrandNumber(statistic.getBrandNumber());
                    //staffStatistic1.setCourseOfTreatmentYJ(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setRechargeTurnCourseChia(statistic.getCardAchi().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    //staffStatistic1.setZyj(statistic.getCardAchi().negate().setScale(2,BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setZyj(BigDecimalUtils.bigDecimal("0"));
                    staffStatistic1.setTotaltc(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setTotalWages(statistic.getCardComm().negate().setScale(2, BigDecimal.ROUND_HALF_UP));
                    staffStatistic1.setCooperationAchi(statistic.getCooperationAchi());
                    staffStatisticsLs2.add(staffStatistic1);
                }

            }
            for (StaffStatistic staffStatistics : staffStatisticsLs) {
                for (StaffStatistic statistic : staffStatisticsLs2) {
                    if (staffStatistics.getStaffId().equals(statistic.getStaffId())) {
                        //staffStatistics.setCourseOfTreatmentYJ(BigDecimalUtils.add(staffStatistics.getCourseOfTreatmentYJ(),statistic.getCourseOfTreatmentYJ()));
                        //todo 修改了疗程转充值
//                        staffStatistics.setRechargeTurnCourseChia(BigDecimalUtils.add(staffStatistics.getRechargeTurnCourseChia(), statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setKjhyj(BigDecimalUtils.add(staffStatistics.getKjhyj(),statistic.getRechargeTurnCourseChia()));
                        //staffStatistics.setZyj(BigDecimalUtils.add(staffStatistics.getZyj(),statistic.getRechargeTurnCourseChia()));
                        staffStatistics.setTotaltc(BigDecimalUtils.add(staffStatistics.getTotaltc(), statistic.getTotaltc()));
                        staffStatistics.setTotalWages(BigDecimalUtils.add(staffStatistics.getTotalWages(), statistic.getTotaltc()));
                    }
                }
//            staffStatistics.setCourseOfTreatmentYJ(staffStatistics.getCourseOfTreatmentYJ().add(
//                    (staffStatistics.getCardAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCardAchi())
//                    .add(staffStatistics.getCashAchi()==null?BigDecimal.valueOf(0):staffStatistics.getCashAchi())));
            }
            List<Long> longs1 = staffStatisticsLs.stream().map(StaffStatistic::getStaffId).collect(Collectors.toList());
            List<StaffStatistic> collect1 = staffStatisticsLs2.stream().filter(s -> !longs1.contains(s.getStaffId())).collect(Collectors.toList());

            for (StaffStatistic statistic : collect1) {
                statistic.setStoreName(baseStore.getStoreName());
                staffStatisticsLs.add(statistic);
            }
        }
        return staffStatisticsLs;
    }

    @Override
    public List<StaffStatistic> couseListMemberInitStaff(StaffStatistic staffStatistic) throws ParseException, SmsException {
        List<StaffStatistic> staffStatisticList = new ArrayList<>();
        BigDecimal achievementAmount = BigDecimalUtils.bigDecimal("0");
        BigDecimal commissionAmount = BigDecimalUtils.bigDecimal("0");
        //根据时间类别转换时间
        //int type = staffStatistic.getType();
        String dateStr = staffStatistic.getSelectDate();
        Date date = new Date();

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String dateString = sdf.format(staffStatistic.getDate());


        //分离查询时使用 否则按月查询分组时分出多个时间组
        if (null != staffStatistic.getDate()) {
            date = staffStatistic.getDate();
            dateStr = DateUtils.ymdFormat(date);
        }

        Long storeId = staffStatistic.getStoreId();
        List<CourseListResponse> courseList = new ArrayList<>();
        if (null == staffStatistic.getClassify()) {
            courseList = ssmCourseService.memberInitStaff(storeId, dateStr, date);
        } else {
            if ("1".equals(staffStatistic.getClassify())) {
                //查询疗程业务员信息
                courseList = ssmCourseService.memberInitStaff(storeId, dateStr, date);
            }
        }
        List<AchiCommEntity> totalList = new ArrayList<>();
        courseList.forEach(courseListResponse -> courseListResponse.getEntities().stream().sequential().collect(Collectors.toCollection(() -> totalList)));
        //按员工ID进行分组
        Map<Long, List<AchiCommEntity>> resultMap = totalList.stream().collect(Collectors.groupingBy(AchiCommEntity::getSaleStaffId));
        //计算每个分组员工的业绩
        Iterator<Map.Entry<Long, List<AchiCommEntity>>> entryIterator = resultMap.entrySet().iterator();
        while (entryIterator.hasNext()) {
            Map.Entry<Long, List<AchiCommEntity>> entry = entryIterator.next();
            if (staffStatistic.getStaffId().equals(entry.getKey())) {
                List<AchiCommEntity> listByStaff = entry.getValue();
                //按天进行分组
                Map<String, List<AchiCommEntity>> daysMap = listByStaff.stream().collect(Collectors.groupingBy(achiCommEntity -> DateUtils.ymdFormat(achiCommEntity.getDocDate())));
                Iterator<Map.Entry<String, List<AchiCommEntity>>> iterator = daysMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<String, List<AchiCommEntity>> stringListEntry = iterator.next();
                    List<AchiCommEntity> list = stringListEntry.getValue();
                    BigDecimal promotionRepay = list.stream().filter(item -> item.getDocType().equals("promotion_card_use") && item.getOrderType().equals("promotion_card_use")&&item.getType().equals("card_repay")).map(achiCommEntity -> achiCommEntity.getCashAchi().multiply(achiCommEntity.getSaleRatio().divide(new BigDecimal("100")))).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值 + 充值还款 业绩
                    BigDecimal recAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 业绩
                    BigDecimal recRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程 + 疗程还款 业绩
                    BigDecimal courseAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程 业绩
                    BigDecimal courseChangeAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);


                    //疗程退款 业绩
                    BigDecimal courseRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 业绩
                    BigDecimal cashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 业绩
                    BigDecimal cashRefundAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //还款业绩
                    BigDecimal repayAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销业绩
                    BigDecimal promotionAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //充值  提成
                    BigDecimal recComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值退款 提成
                    BigDecimal recRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_recharge.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程  提成
                    BigDecimal courseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType()) && null == achiCommEntity.getType()).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_use.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程退款 提成
                    BigDecimal courseRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银 提成
                    BigDecimal cashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退 提成
                    BigDecimal cashRefundComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //还款提成
                    BigDecimal repayComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal repayCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //促销提成
                    BigDecimal promotionComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal promotionCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_promotion.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //加价转疗程提成
                    BigDecimal courseChangeComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCashComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal courseChangeCardComm = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal jjzlcCashAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal jjzlcCardAchi = list.stream().filter(achiCommEntity -> Constant.doc_type_card_change.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //收银销卡
                    BigDecimal cashAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getSaleAchievementAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCashAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashCardAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardAchis = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //消费退
                    BigDecimal cashRefundComm1 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getSaleCommissionAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal cashRefundCashComm1 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //充值卡付消费退
                    BigDecimal cashRefundCardComm1 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("")).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //疗程卡付消费退
                    BigDecimal cashRefundCardComm2 = list.stream().filter(achiCommEntity -> Constant.doc_type_refund_cash.equals(achiCommEntity.getDocType()) && achiCommEntity.getOrderType().equals("card")).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //疗程转充值
                    BigDecimal rechargeTurnCourseChia = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal rechargeTurnCourseComm = list.stream().filter(achiCommEntity -> Constant.doc_type_recharge_turn_course.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    //团购卡业绩
                    BigDecimal groupPurchaseChia = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //团购卡提成
                    BigDecimal groupPurchaseComm = list.stream().filter(achiCommEntity -> Constant.account_type_recharge_groupon.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    BigDecimal cashcxyj=new BigDecimal("0");
                    BigDecimal cashcxtc=new BigDecimal("0");
                    BigDecimal cardcxtc=new BigDecimal("0");
                    //todo
//                    if(list.get(0).getDocType().equals("promotion_card_use")&&list.get(0).getType().equals(Constant.doc_type_repay)){
//                        //促销还款业绩
//                         cashcxyj=cashcxyj.add(list.get(0).getCashAchi());
//                        //促销还款提成
//                        cashcxtc=cashcxtc.add(list.get(0).getCashComm());
//                        cardcxtc=cardcxtc.add(list.get(0).getCardComm());
//                    }
                    //todo
                    /*旧的疗程促销计算业绩和提成
                    //BigDecimal cashcxyj = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //促销还款提成
                    //BigDecimal cashcxtc = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //BigDecimal cardcxtc = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType()) && "promotion_card_use".equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    */
                    //沐足技师卡付业绩与提成
                    BigDecimal CardFootMassageChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal CardFootMassageComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCardComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //沐足技师现付业绩与提成
                    BigDecimal footMassageChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashAchi).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal footMassageComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getCashComm).reduce(BigDecimal.ZERO, BigDecimal::add);
                    //推销业绩与提成
                    BigDecimal marketChia = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room_market.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalPerformance).reduce(BigDecimal.ZERO, BigDecimal::add);
                    BigDecimal marketComm = list.stream().filter(achiCommEntity -> Constant.doc_type_store_cash_room_market.equals(achiCommEntity.getDocType())).map(AchiCommEntity::getTotalCommission).reduce(BigDecimal.ZERO, BigDecimal::add);

                    BigDecimal nTMoney = list.stream().filter(achiCommEntity -> Constant.doc_type_repay.equals(achiCommEntity.getType())).map(AchiCommEntity::getNTMoney).reduce(BigDecimal.ZERO, BigDecimal::add);


                    BigDecimal cardchian=BigDecimal.valueOf(0);
                    BigDecimal cashchian=BigDecimal.valueOf(0);
                    for (AchiCommEntity a : list) {
                        if(Constant.doc_type_card_use.equals(a.getDocType())){
                            cardchian=cardchian.add(a.getCardAchi());
                            cashchian=cashchian.add(a.getCashAchi());
                        }
                    }
                    /*
                    * achievementAmount = BigDecimalUtils.subtract(
                    * BigDecimalUtils.subtract(
                    * BigDecimalUtils.subtract(
                            BigDecimalUtils.add(
                            * BigDecimalUtils.add(
                            * BigDecimalUtils.add(recAchi, courseCashAchi),
                            *  cashAchi),
                            * promotionAchi),
                            *  recRefundAchi),
                            *  courseRefundAchi),
                            * cashRefundAchi)
                            * .add(courseChangeCashAchi)
                            * .add(groupPurchaseChia)
                            * .add(cashcxyj)
                            * .add(footMassageChia);
                    * */
                    achievementAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashAchi), promotionAchi), recRefundAchi), courseRefundAchi), cashRefundAchi).add(courseChangeCashAchi).add(groupPurchaseChia).add(cashcxyj).add(footMassageChia);
                    commissionAmount = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recComm, courseComm), cashComm), promotionComm), recRefundComm), courseRefundComm), cashRefundComm).add(courseChangeComm).add(groupPurchaseComm).add(cashcxtc).add(footMassageComm);
                    //总现付业绩
                    BigDecimal totalCashAchi = BigDecimalUtils.add(BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add(BigDecimalUtils.add(BigDecimalUtils.add(recAchi, courseCashAchi), cashCashAchi), promotionCashAchi), recRefundAchi), courseRefundAchi), cashRefundCashAchi),repayAchi).add(courseChangeCashAchi).add(groupPurchaseChia).add(cashcxyj).add(footMassageChia);
                    //总卡付业绩
                    BigDecimal totalCardAchi = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardAchi, cashCardAchi), promotionCardAchi), cashRefundCardAchi).add(courseChangeCardAchi);
                    //总现付提成
                    BigDecimal totalCashComm = BigDecimalUtils.subtract(BigDecimalUtils.subtract(BigDecimalUtils.subtract(
                            BigDecimalUtils.add( BigDecimalUtils.add(courseCashComm, cashCashComm), promotionCashComm), recRefundComm), courseRefundComm), cashRefundCashComm).add(courseChangeCashComm).add(groupPurchaseComm).add(cashcxtc).add(footMassageComm);
                    //总卡付提成
                    BigDecimal totalCardComm = BigDecimalUtils.subtract(BigDecimalUtils.add(BigDecimalUtils.add(courseCardComm, cashCardComm), promotionCardComm), cashRefundCardComm).add(courseChangeCardComm).add(repayCardComm);

                    if(staffStatistic.getClassify().equals("3")){
                        for (AchiCommEntity achiCommEntity : list) {
                            StaffStatistic statistic = new StaffStatistic();
                            if(achiCommEntity.getDocType().equals("card_recharge")){
                                statistic.setType(0);
                                statistic.setCzhkyj(achiCommEntity.getCashAchi());
                                statistic.setCzhktc(achiCommEntity.getCashComm().add(achiCommEntity.getCardComm()));
                            }else if(achiCommEntity.getDocType().equals("card_use") || achiCommEntity.getDocType().equals("card_change")){
                                statistic.setType(1);
                                statistic.setLchkyj(achiCommEntity.getCashAchi());
                                statistic.setLchktc(achiCommEntity.getCashComm().add(achiCommEntity.getCardComm()));
                            }else if(achiCommEntity.getDocType().equals("promotion_card_use")){
                                statistic.setType(2);
                                statistic.setCashcxyj(cashcxyj);
                                statistic.setCashcxtc(cashcxtc.add(cardcxtc));
                            }
                            statistic.setStaffId(entry.getKey());
                            statistic.setStaffName(list.get(0).getSaleStaffName());
                            statistic.setBrandNumber(list.get(0).getBrandNumber());
                            //按天查询用date
                            statistic.setDate(com.alibaba.excel.util.DateUtils.parseDate(dateStr));
                            statistic.setAchievementAmount(achievementAmount);
                            statistic.setCommissionAmount(commissionAmount);
                            statistic.setCashAchi(totalCashAchi);
                            statistic.setCardAchi(totalCardAchi);
                            statistic.setCashComm(totalCashComm);
                            statistic.setCardComm(totalCardComm);
                            statistic.setClassify(staffStatistic.getClassify());
                            statistic.setStoreId(staffStatistic.getStoreId());
                            statistic.setSylcxkyj(cashCardAchis);
                            statistic.setLcCardyj(cardchian);
                            statistic.setLcCashyj(cashchian);
                            statistic.setSyxfyj(cashCashAchi);
                            statistic.setXftlcczhjyj(cashRefundCardComm1.add(cashRefundCardComm2));
                            statistic.setSyczkfyj(CardAchis);
                            statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                            statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                            statistic.setGroupPurchaseChia(groupPurchaseChia);
                            statistic.setGroupPurchaseComm(groupPurchaseComm);

                            statistic.setFootMassageComm(footMassageComm);
                            statistic.setFootMassageChia(footMassageChia);
                            statistic.setCardFootMassageComm(CardFootMassageComm);
                            statistic.setCardFootMassageChia(CardFootMassageChia);
                            statistic.setMarketChia(marketChia);
                            statistic.setMarketComm(marketComm);
                            statistic.setNTMoney(nTMoney);
                            staffStatisticList.add(statistic);
                        }
                    }else{
                        StaffStatistic statistic = new StaffStatistic();
                        statistic.setCashcxyj(promotionCashAchi);
                        statistic.setCardcxyj(promotionCardAchi);
                        statistic.setStaffId(entry.getKey());
                        statistic.setStaffName(list.get(0).getSaleStaffName());
                        statistic.setBrandNumber(list.get(0).getBrandNumber());
                        //按天查询用date
                        statistic.setDate(com.alibaba.excel.util.DateUtils.parseDate(dateStr));
                        statistic.setAchievementAmount(achievementAmount);
                        statistic.setCommissionAmount(commissionAmount);
                        statistic.setCashAchi(totalCashAchi);
                        statistic.setCardAchi(totalCardAchi);
                        statistic.setCashComm(totalCashComm);
                        statistic.setCardComm(totalCardComm);
                        statistic.setClassify(staffStatistic.getClassify());
                        statistic.setStoreId(staffStatistic.getStoreId());
                        statistic.setSylcxkyj(cashCardAchis);
                        statistic.setLcCardyj(cardchian);
                        statistic.setLcCashyj(cashchian);
                        statistic.setSyxfyj(cashCashAchi);
                        statistic.setXftlcczhjyj(cashRefundCardComm1.add(cashRefundCardComm2));
                        statistic.setSyczkfyj(CardAchis);
                        statistic.setRechargeTurnCourseChia(rechargeTurnCourseChia);
                        statistic.setRechargeTurnCourseComm(rechargeTurnCourseComm);
                        statistic.setGroupPurchaseChia(groupPurchaseChia);
                        statistic.setGroupPurchaseComm(groupPurchaseComm);

                        statistic.setFootMassageComm(footMassageComm);
                        statistic.setFootMassageChia(footMassageChia);
                        statistic.setCardFootMassageComm(CardFootMassageComm);
                        statistic.setCardFootMassageChia(CardFootMassageChia);
                        statistic.setMarketChia(marketChia);
                        statistic.setMarketComm(marketComm);
                        statistic.setNTMoney(nTMoney);
                        staffStatisticList.add(statistic);
                    }
                }
            }
        }

        staffStatisticList.sort(comparing(StaffStatistic::getDate).reversed());
        return staffStatisticList;
    }

}
